<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.ibs.dashboard.mapper.LscjSysuserMapper">
    
    <resultMap type="LscjSysuser" id="LscjSysuserResult">
        <result property="orgId"    column="org_id"    />
        <result property="level"    column="level"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="id"    column="id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectLscjSysuserVo">
        select id, org_id, level, user_id, user_name,create_time from lscj_sysuser
    </sql>

    <select id="selectLscjSysuserList" parameterType="LscjSysuser" resultMap="LscjSysuserResult">
        select id, org_id, user_id, user_name,create_time,
        case when level = '总行' then 0 when level = '支行' then 1 when level = '网点' then 2 when level = '客户经理' then 3 else level end as level
        from lscj_sysuser
        <where>  
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="orgId != null "> and belong_dept_id= #{orgId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="startTime !=null ">and create_time &gt;= #{startTime}</if>
            <if test="endTime !=null ">and create_time &lt;= #{endTime}</if>
            <if test="level != null "> and level = #{level}</if>
        </where>
        order by create_time desc
        limit #{size}  offset #{num}
    </select>


    <select id="selectLscjSysuserListCount" parameterType="LscjSysuser" resultType="Integer">
        select count(0) from lscj_sysuser
        <where>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="orgId != null "> and belong_dept_id= #{orgId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="startTime !=null ">and create_time &gt;= #{startTime}</if>
            <if test="endTime !=null ">and create_time &lt;= #{endTime}</if>
            <if test="level != null "> and level = #{level}</if>
        </where>
    </select>
    <select id="selectLscjSysuserByOrgId" parameterType="String" resultMap="LscjSysuserResult">
        <include refid="selectLscjSysuserVo"/>
        where org_id = #{orgId}
    </select>

    <insert id="insertLscjSysuser" parameterType="LscjSysuser">
        insert into lscj_sysuser
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="orgId != null">org_id,</if>
            <if test="level != null">level,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="belongDeptId !=null">belong_dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="orgId != null">#{orgId},</if>
            <if test="level != null">#{level},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="belongDeptId !=null">#{belongDeptId},</if>
         </trim>
    </insert>

    <update id="updateLscjSysuser" parameterType="LscjSysuser">
        update lscj_sysuser
        <trim prefix="SET" suffixOverrides=",">
            <if test="level != null">level = #{level},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id} and org_id = #{orgId}
    </update>


    <delete id="deleteLscjSysuserByIds" parameterType="String">
        delete from lscj_sysuser where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>