k94314517
2025-05-19 cdd6551b190b981b807a3b95e9635c559ccc769d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?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.doumee.dao.system.SystemUserMapper">
 
  <!-- 查询用户列表 -->
  <resultMap id="SystemUserListVO" type="com.doumee.dao.system.vo.SystemUserListVO" autoMapping="true">
    <id column="ID" property="id"/>
    <association property="createUserInfo" javaType="com.doumee.dao.system.model.SystemUser">
      <result column="CREATE_USER_ID" property="id"/>
      <result column="CREATE_USER_NAME" property="username"/>
    </association>
    <association property="updateUserInfo" javaType="com.doumee.dao.system.model.SystemUser">
      <result column="UPDATE_USER_ID" property="id"/>
      <result column="UPDATE_USER_NAME" property="username"/>
    </association>
  </resultMap>
  <select id="selectManageList" parameterType="com.doumee.dao.system.dto.QuerySystemUserDTO" resultMap="SystemUserListVO">
    SELECT
      DISTINCT
      usr.*,
    case when cd.HEAD_ID = usr.ID then 1 else 0 end headStatus ,
    cd.ID AS companyDepartmentId, cd.`NAME_PATH` AS companyDepartmentPathName, cd.`ID_PATH` AS companyDepartmentPathId,
      create_user.ID CREATE_USER_ID, create_user.`USERNAME` CREATE_USER_NAME,
      update_user.ID UPDETE_USER_ID, update_user.`USERNAME` UPDATE_USER_NAME,
    c.NAME as companyName,
    ( select count(1) from company_permission cp where cp.USER_ID = usr.id and cp.TYPE = 1 and cp.ISDELETED = 0  ) as authNum,
    case when c.USERNAME = usr.USERNAME then 1  else 0 end isAdmin
    FROM `SYSTEM_USER` usr
    LEFT JOIN `SYSTEM_USER` create_user ON create_user.ID = usr.CREATE_USER
    LEFT JOIN `SYSTEM_USER` update_user ON update_user.ID = usr.UPDATE_USER
    LEFT JOIN `SYSTEM_POSITION_USER` spu ON spu.USER_ID = usr.ID AND spu.DELETED = 0
    LEFT JOIN Company c ON usr.COMPANY_ID = c.id
    LEFT JOIN company_department cd ON usr.DEPARTMENT_ID = cd.id
    <where>
      usr.DELETED = 0
      <if test="dto.companyDepartmentId != null">
        AND   FIND_IN_SET(#{dto.companyDepartmentId},REPLACE(cd.ID_PATH,'/',','))
      </if>
 
      <if test="dto.positionId != null">
        AND spu.POSITION_ID = #{dto.positionId}
      </if>
      <if test="dto.type != null">
        AND usr.TYPE = #{dto.type}
      </if>
      <if test="dto.status != null">
        AND usr.STATUS = #{dto.status}
      </if>
      <if test="dto.keyword != null and dto.keyword != ''">
        AND ( usr.`USERNAME` LIKE CONCAT('%', #{dto.keyword}, '%')  or usr.`REALNAME` LIKE CONCAT('%', #{dto.keyword}, '%') )
      </if>
 
      <if test="dto.companyDepartmentPathName != null and dto.companyDepartmentPathName != ''">
        AND ( cd.`NAME_PATH` LIKE CONCAT('%', #{dto.companyDepartmentPathName}, '%') )
      </if>
      <if test="dto.companyId != null">
        AND usr.COMPANY_ID = #{dto.companyId}
      </if>
      <if test="dto.username != null and dto.username != ''">
        AND usr.`USERNAME` LIKE CONCAT('%', #{dto.username}, '%')
      </if>
      <if test="dto.realname != null and dto.realname != ''">
        AND usr.`REALNAME` LIKE CONCAT('%', #{dto.realname}, '%')
      </if>
      <if test="dto.companyName != null and dto.companyName != ''">
        AND c.`NAME` LIKE CONCAT('%', #{dto.companyName}, '%')
      </if>
 
      <if test="dto.mobile != null and dto.mobile != ''">
        AND usr.`MOBILE` LIKE CONCAT('%', #{dto.mobile}, '%')
      </if>
      <if test="dto.typeList != null and dto.typeList.size()>0">
        AND usr.`type` in <foreach collection="dto.typeList" item="item" open="(" separator="," close=")">#{item}</foreach>
      </if>
    </where>
    ${orderByClause}
  </select>
 
  <select id="selectAllManagerList" parameterType="com.doumee.dao.system.dto.QuerySystemUserDTO"
          resultType="com.doumee.dao.system.vo.SystemUserDetailVO">
    SELECT
      usr.*
      <if test="dto.type == 1 or dto.type == 2  or dto.type == 4">
        ,
        company.id as companyId,
        company.name as companyName,
        company.CREDIT_CODE as creditCode,
        company.AREA_ID as companyAreaId,
        company.CITY_ID as companyCityId,
        company.LEGAL_PERSON as legalPerson,
        company.LINK_NAME as linkName,
        company.LINK_PHONE as linkPhone,
        company.CREATE_DATE as createDate
      </if>
    FROM `SYSTEM_USER` usr
    <if test="dto.type == 1 or dto.type == 2  or dto.type == 4">
      LEFT JOIN `company` company  ON company.id = usr.COMPANY_ID
    </if>
    <if test="dto.provinceId != null">
      LEFT JOIN `areas` areas   ON areas.id = usr.city_id
    </if>
 
    <where>
      usr.DELETED = 0
      <if test="dto.provinceId != null">
        and areas.parent_id=#{dto.provinceId }
      </if>
      <if test="dto.username !=null and dto.username!=''">
        AND usr.`USERNAME` LIKE CONCAT('%', #{dto.username}, '%')
      </if>
      <if test="dto.cityId != null and dto.cityId != ''">
        AND usr.`CITY_ID` = #{dto.cityId}
      </if>
      <if test="dto.areaId != null and dto.areaId != ''" >
        AND usr.`AREA_ID` = #{dto.areaId}
      </if>
      <if test="dto.typeList != null and dto.typeList.size() > 0">
        AND usr.`type` in <foreach collection="dto.typeList" item="item" open="(" separator="," close=")">#{item}</foreach>
      </if>
    </where>
    ${orderByClause}
  </select>
 
</mapper>