UserMapper.xml 13.5 KB
<?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="cn.com.glsx.shield.modules.mapper.UserMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.shield.modules.entity.User">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="username" jdbcType="VARCHAR" property="username"/>
        <result column="account" jdbcType="VARCHAR" property="account"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="phone_number" jdbcType="VARCHAR" property="phoneNumber"/>
        <result column="portrait" jdbcType="VARCHAR" property="portrait"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="gender" jdbcType="INTEGER" property="gender"/>
        <result column="position_" jdbcType="VARCHAR" property="position"/>
        <result column="tenant_id" jdbcType="INTEGER" property="tenantId"/>
        <result column="department_id" jdbcType="INTEGER" property="departmentId"/>
        <result column="superior_id" jdbcType="INTEGER" property="superiorId"/>
        <result column="salt" jdbcType="VARCHAR" property="salt"/>
        <result column="enable_status" jdbcType="INTEGER" property="enableStatus"/>
        <result column="global_type" jdbcType="TINYINT" property="globalType"/>
        <result column="local_type" jdbcType="TINYINT" property="localType"/>
        <result column="special_login" jdbcType="TINYINT" property="specialLogin"/>
        <result column="special_mark" jdbcType="VARCHAR" property="specialMark"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        , username, account, `password`, phone_number,
        portrait, email, gender, position, salt, tenant_id, department_id,
        superior_id, global_type, local_type, del_flag, enable_status,
        created_date, created_by, updated_date, updated_by
    </sql>

    <select id="selectById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where id = #{id}
        and del_flag = 0
    </select>

    <select id="selectAllNotDel" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user where del_flag = 0
    </select>

    <select id="selectByIds" resultMap="BaseResultMap">
        select *
        from t_user
        where del_flag = 0
        and id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

    <select id="selectByTenantId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where del_flag = 0
        and tenant_id = #{tenantId}
    </select>

    <select id="selectByTenantIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where del_flag = 0
        and tenant_id in
        <foreach collection="tenantIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <select id="selectByDepartmentId" resultMap="BaseResultMap">
        select *
        from t_user
        where department_id = #{departmentId}
          and del_flag = 0
    </select>

    <select id="selectUserOrgModelById" resultType="cn.com.glsx.usercenter.api.dto.tree.OrgModel">
        select tu.id                                orgId,
               tu.department_id                     parentId,
               1                                    depth,
               tu.tenant_id                         tenantId,
               concat(tu.account, '/', tu.username) orgName,
               0                                    isRoot,
               'u'                                  type,
               0                                    orderNum
        from t_user tu
        where tu.id = #{id}
          and del_flag = 0
    </select>

    <select id="selectUserOrgModels" resultType="cn.com.glsx.usercenter.api.dto.tree.OrgModel">
        select tu.id orgId,
        tu.department_id parentId,
        1 depth,
        tu.tenant_id tenantId,
        concat(tu.account, '/', tu.username) orgName,
        0 isRoot,
        'u' type,
        tu.id orderNum
        from t_user tu
        where del_flag = 0
        and department_id in
        <foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
            #{departmentId}
        </foreach>
        <if test="userIds != null and userIds.size() > 0">
            and tu.id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        order by tu.id desc
    </select>

    <select id="selectByDepartmentIds" resultMap="BaseResultMap">
        select *
        from t_user
        where del_flag = 0
        and department_id in
        <foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
            #{departmentId}
        </foreach>
    </select>

    <select id="selectExcludeUserIdByDepartmentId" resultMap="BaseResultMap">
        select *
        from t_user
        where del_flag = 0
          and department_id = #{departmentId}
          and id <![CDATA[ <> ]]> #{userId}
    </select>

    <select id="countByAccount" resultType="java.lang.Integer">
        select count(account)
        from t_user
        where account = #{account}
          and del_flag = 0
    </select>

    <select id="selectByAccount" resultMap="BaseResultMap">
        select *
        from t_user
        where account = #{account}
          and del_flag = 0
    </select>

    <select id="countByAccountAndTenantId" resultType="java.lang.Integer">
        select count(account)
        from t_user
        where account = #{account}
          and tenant_id = #{tenantId}
          and del_flag = 0
    </select>

    <select id="selectByAccountAndTenantId" resultMap="BaseResultMap">
        select *
        from t_user
        where account = #{account}
          and tenant_id = #{tenantId}
          and del_flag = 0
    </select>

    <select id="selectByUsername" resultMap="BaseResultMap">
        select *
        from t_user
        where username = #{username}
          and del_flag = 0
    </select>

    <select id="search" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user where del_flag = 0
        <if test="searchField != null and searchField !=''">
            and (
            account like CONCAT('%',#{searchField},'%')
            or
            phone_number like CONCAT('%',#{searchField},'%')
            or
            username like CONCAT('%',#{searchField},'%')
            or
            id = #{searchField}
            )
        </if>
        <if test="userId != null">
            and id = #{userId}
        </if>
        <if test="userStatus != null">
            and enable_status = #{userStatus}
        </if>
        <if test="tenantIds != null and tenantIds.size() > 0">
            and tenant_id in
            <foreach collection="tenantIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="departmentIds != null and departmentIds.size() > 0">
            and department_id in
            <foreach collection="departmentIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="userIds != null and userIds.size() > 0">
            and id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        order by id desc
    </select>

    <update id="logicDeleteById">
        update t_user
        set del_flag = -1
        where id = #{id}
    </update>

    <update id="updatePassword">
        update t_user
        set password = #{password}
        where id = #{id}
    </update>

    <select id="countByCriterial" parameterType="cn.com.glsx.shield.modules.model.param.UserBO"
            resultType="java.lang.Integer">
        select count(*) from t_user
        where del_flag = 0
        <if test="departmentId != null">
            and department_id = #{departmentId}
        </if>
        <if test="departmentIds != null and departmentIds.size() > 0">
            and department_id in
            <foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
                #{departmentId}
            </foreach>
        </if>
    </select>

    <select id="countDepartmentsUser" resultType="cn.com.glsx.shield.modules.model.view.DepartmentCount">
        select department_id as departmentId, count(*) as userNumber from t_user
        where del_flag = 0
        <if test="departmentIds != null and departmentIds.size() > 0">
            and department_id in
            <foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
                #{departmentId}
            </foreach>
        </if>
        group by department_id
    </select>

    <select id="selectDepartmentsSubordinate" resultType="cn.com.glsx.shield.modules.entity.User">
        select tu.id id,
        tu.account account,
        tu.username username,
        tu.department_id departmentId,
        tu.superior_id superiorId,
        tu.phone_number phoneNumber,
        tu.local_type localType,
        tu.enable_status enableStatus,
        tu.created_date createdDate
        from t_user tu, t_user_path tup
        where tu.del_flag = 0 and tup.del_flag = 0
        and tu.id = tup.sub_id
        <if test="userId != null">
            and tup.superior_id = #{userId}
        </if>
        <if test="userStatus != null">
            and tu.enable_status = #{userStatus}
        </if>
        <if test="userIds != null and userIds.size() > 0">
            and tu.id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="departmentIds != null and departmentIds.size() > 0">
            and tu.department_id in
            <foreach collection="departmentIds" separator="," close=")" open="(" item="item">
                #{item}
            </foreach>
        </if>
        <if test="searchField != null">
            and (
            tu.account like CONCAT('%',#{searchField},'%')
            or
            tu.phone_number like CONCAT('%',#{searchField},'%')
            or
            tu.username like CONCAT('%',#{searchField},'%')
            )
        </if>
    </select>

    <select id="selectUsersByCondition" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user tu
        where del_flag = 0
        <if test="account != null and account !=''">
            and tu.account like CONCAT('%',#{account},'%')
        </if>
        <if test="username != null and username !=''">
            and tu.username like CONCAT('%',#{username},'%')
        </if>
        <if test="orgIds != null and orgIds.size() > 0">
            and tu.department_id in
            <foreach collection="orgIds" separator="," close=")" open="(" item="item">
                #{item}
            </foreach>
        </if>
        <if test="userIds != null and userIds.size() > 0">
            and tu.id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="selectSuperiorUserById" resultMap="BaseResultMap">
        select tu.*
        from t_user tu
                 left join t_user tu2 on tu2.superior_id = tu.id
        where tu2.id = #{id}
    </select>

    <select id="selectSuperiorUserByIds" resultType="cn.com.glsx.usercenter.api.dto.response.User">
        select tu.id, tu.department_id orgId, tu.username, tu.account, tu2.id mid
        from t_user tu
        left join t_user tu2 on tu2.superior_id = tu.id
        where tu.del_flag = 0 and tu2.del_flag = 0
        and tu2.id in
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <select id="selectByRelUserIds" resultType="cn.com.glsx.usercenter.api.dto.response.CUser">
        select tcu.id userId, tu.id relUserId, tu.account, tu.username, tcula2.avatar
        from t_user tu
        left join t_cust_user tcu on tu.id = tcu.rel_user_id
        left join t_cust_user_auth_rel tcuar on tcu.id = tcuar.user_id and tcuar.auth_type = 'local'
        left join t_cust_user_local_auth tcula on tcuar.auth_id = tcula.id
        left join t_cust_user_local_account tcula2 on tcuar.auth_id = tcula2.auth_id
        where tu.del_flag = 0
        and tu.id in
        <foreach collection="relUserIds" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <update id="saveUIDById">
        update t_user
        set special_mark = #{specialMark}
        where id = #{id}
    </update>

    <update id="resetUIDById">
        update t_user
        set special_mark = null
        where id = #{id}
    </update>
</mapper>