yanghb
2024-04-15 6bc25b33e90d45904d1843e927fa709dfeb51d7f
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?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.stylefeng.roses.kernel.system.modular.user.mapper.SysUserMapper">
 
    <!--用户列表sql-->
    <sql id="user_list_mysql">
        select
        suser.user_id as userId,
        suser.account as account,
        suser.nick_name as nickName,
        suser.real_name as realName,
        suser.avatar as avatar,
        suser.birthday as birthday,
        suser.sex as sex,
        suser.email as email,
        suser.phone as phone,
        suser.tel as tel,
        suser.status_flag as statusFlag,
        suorg.org_id as orgId,
        suorg.position_id as positionId,
        hpos.position_name as positionName,
        hrorg.org_name as orgName,
        suser.customer_ids as customerIds,
        suser.ware_house_ids AS wareHouseIds,
        suser.remark AS remark,
        suser.wx_open_id AS wxOpenId
        from sys_user suser
        left join sys_user_org suorg on suser.user_id = suorg.user_id
        left join hr_position hpos on suorg.position_id = hpos.position_id
        left join hr_organization hrorg on suorg.org_id = hrorg.org_id
        <where>
            <if test="sysUserRequest.nickName != null and sysUserRequest.nickName != ''">
                and suser.nick_name like concat('%',#{sysUserRequest.nickName},'%')
            </if>
            <if test="sysUserRequest.realName != null and sysUserRequest.realName != ''">
                and suser.real_name like concat('%',#{sysUserRequest.realName},'%')
            </if>
            <if test="sysUserRequest.account != null and sysUserRequest.account != ''">
                and suser.account like concat('%',#{sysUserRequest.account},'%')
            </if>
            <if test="sysUserRequest.statusFlag != null and sysUserRequest.statusFlag != ''">
                and suser.status_flag like concat('%',#{sysUserRequest.statusFlag},'%')
            </if>
            <if test="sysUserRequest.orgId != null and sysUserRequest.orgId != ''">
                and suorg.org_id in (select org_id from hr_organization where org_pids like CONCAT('%$[',#{sysUserRequest.orgId},'$]%') escape '$' or org_id=#{sysUserRequest.orgId} )
            </if>
            <if test="sysUserRequest.scopeOrgIds != null and sysUserRequest.scopeOrgIds.size() > 0">
                and suorg.org_id in
                <foreach  item="item" collection="sysUserRequest.scopeOrgIds" index="index"  open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="sysUserRequest.userScopeIds != null and sysUserRequest.userScopeIds.size() > 0">
                and suser.user_id in
                <foreach  item="item" collection="sysUserRequest.userScopeIds" index="index"  open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="sysUserRequest.customerList != null and sysUserRequest.customerList.size() > 0">
                and
                <foreach  item="item" collection="sysUserRequest.customerList" index="index"  open="(" separator="or" close=")">
                    FIND_IN_SET(#{item},suser.customer_ids)
                </foreach>
            </if>
            <if test="sysUserRequest.wareHouseList != null and sysUserRequest.wareHouseList.size() > 0">
                and
                <foreach  item="item" collection="sysUserRequest.wareHouseList" index="index"  open="(" separator="or" close=")">
                   FIND_IN_SET( #{item},suser.ware_house_ids)
                </foreach>
            </if>
            and suser.del_flag = 'N'
            order by suser.create_time desc
        </where>
    </sql>
 
    <!--用户列表 oracle版本-->
    <sql id="user_list_oracle">
        select
        suser.user_id as userId,
        suser.account as account,
        suser.nick_name as nickName,
        suser.real_name as realName,
        suser.avatar as avatar,
        suser.birthday as birthday,
        suser.sex as sex,
        suser.email as email,
        suser.phone as phone,
        suser.tel as tel,
        suser.status_flag as statusFlag,
        suorg.org_id as orgId,
        suorg.position_id as positionId,
        hpos.position_name as positionName,
        hrorg.org_name as orgName,
        suser.customer_ids as customerIds,
        suser.ware_house_ids AS wareHouseIds
        from sys_user suser
        left join sys_user_org suorg on suser.user_id = suorg.user_id
        left join hr_position hpos on suorg.position_id = hpos.position_id
        left join hr_organization hrorg on suorg.org_id = hrorg.org_id
        <where>
            <if test="sysUserRequest.nickName != null and sysUserRequest.nickName != ''">
                and suser.nick_name  like '%' || #{sysUserRequest.nickName} || '%'
            </if>
            <if test="sysUserRequest.realName != null and sysUserRequest.realName != ''">
                and suser.real_name  like '%' || #{sysUserRequest.realName} || '%'
            </if>
            <if test="sysUserRequest.account != null and sysUserRequest.account != ''">
                and suser.account  like '%' || #{sysUserRequest.account} || '%'
            </if>
            <if test="sysUserRequest.statusFlag != null and sysUserRequest.statusFlag != ''">
                and suser.status_flag  like '%' || #{sysUserRequest.statusFlag} || '%'
            </if>
            <if test="sysUserRequest.orgId != null and sysUserRequest.orgId != ''">
                and suorg.org_id in(select org_id from hr_organization where org_pids  like '%' || #{sysUserRequest.orgId} || '%' or org_id = #{sysUserRequest.orgId})
            </if>
            and suser.del_flag = 'N'
            order by suser.create_time desc
        </where>
    </sql>
 
 
    <!--获取用户分页列表-->
    <select id="findUserPage" resultType="cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserDTO">
        <include refid="user_list_mysql"></include>
    </select>
 
    <sql id="select_user_org_customer">
        SELECT
            suser.user_id AS userId,
            suser.account AS account,
            suser.nick_name AS nickName,
            suser.real_name AS realName,
            suser.avatar AS avatar,
            suser.birthday AS birthday,
            suser.sex AS sex,
            suser.email AS email,
            suser.phone AS phone,
            suser.tel AS tel,
            suser.status_flag AS statusFlag,
            suorg.org_id AS orgId,
            hrorg.org_name AS orgName,
            cu.worker_no,
            cu.work_status,
            cu.post_types,
            cu.post_ids
        FROM
            sys_user suser
        LEFT JOIN sys_user_org suorg ON suser.user_id = suorg.user_id
        LEFT JOIN hr_organization hrorg ON suorg.org_id = hrorg.org_id
        LEFT JOIN toc_customer cu ON cu.sys_user_id = suser.user_id
    </sql>
    <select id="getWorkerPage" resultType="cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserDTO">
        <include refid="select_user_org_customer" />
        <where>
            cu.user_type = 1 AND suser.del_flag = 'N'
            <if test="req.nickName != null and req.nickName != ''">
                and suser.nick_name LIKE CONCAT('%', #{req.nickName}, '%')
            </if>
            <if test="req.realName != null and req.realName != ''">
                and suser.real_name LIKE CONCAT('%', #{req.realName}, '%')
            </if>
            <if test="req.phone != null and req.phone != ''">
                and suser.phone LIKE CONCAT('%', #{req.phone}, '%')
            </if>
            <if test="req.statusFlag != null and req.statusFlag != ''">
                and suser.status_flag = #{req.statusFlag}
            </if>
            <if test="req.orgId != null and req.orgId != ''">
                and suorg.org_id in(select org_id from hr_organization where org_pids LIKE CONCAT('%', #{req.orgId}, '%') or org_id = #{req.orgId})
            </if>
            <if test="req.postType != null and req.postType != -1">
                AND FIND_IN_SET ( #{req.postType}, cu.post_types )
            </if>
            <if test="req.postId != null and req.postId != -1">
                AND FIND_IN_SET ( #{req.postId}, cu.post_ids )
            </if>
            ORDER BY suser.create_time DESC
        </where>
    </select>
    <select id="getWorkerDetail" resultType="cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserDTO">
        <include refid="select_user_org_customer" />
        <where>
            <if test="userId != null">
                AND suser.user_id = #{userId}
            </if>
        </where>
    </select>
 
    <!--获取用户列表-->
    <select id="findUserList" resultType="cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserDTO">
        <include refid="user_list_mysql"></include>
    </select>
 
</mapper>