干燥机配套车间生产管理系统/云平台服务端
zhuguifei
2024-11-29 339515558253d776769dc2e2560bbb4a0450c989
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?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="org.jeecg.modules.system.mapper.SysUserMapper">
 
    <!-- 根据用户名查询 -->
    <select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
        select * from  sys_user  where username = #{username} and del_flag = 0
    </select>
 
    <!-- 根据部门Id查询 -->
    <select id="getUserByDepId" resultType="org.jeecg.modules.system.entity.SysUser">
        select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_depart where dep_id=#{departId})
        <if test="username!=null and username!=''">
            and username = #{username}
        </if>
    </select>
 
    <!-- 查询用户的所属部门名称信息 -->
    <select id="getDepNamesByUserIds" resultType="org.jeecg.modules.system.vo.SysUserDepVo">
        select d.depart_name,ud.user_id from sys_user_depart ud,sys_depart d where d.id = ud.dep_id and ud.user_id in
        <foreach collection="userIds" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!-- 通过多个部门IDS,查询部门下的用户信息 -->
    <select id="getUserByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
        select * from sys_user where del_flag = 0
        <if test="departIds!=null  and departIds.size()>0">
            and id in (select user_id from sys_user_depart where dep_id in
            <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
            )
        </if>
        <if test="username!=null and username!=''">
            and username = #{username}
        </if>
    </select>
 
    <!-- 根据角色Id查询 -->
    <select id="getUserByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
        select * from sys_user where del_flag = 0 and id in (select user_id from sys_user_role where role_id=#{roleId})
        <if test="username!=null and username!=''">
            and username = #{username}
        </if>
    </select>
    
    <!--  修改用户部门code -->
    <update id="updateUserDepart">
        UPDATE sys_user SET
        <if test="orgCode!=null and loginTenantId!=null">
             org_code = #{orgCode}
            ,login_tenant_id = #{loginTenantId}
        </if>
        <if test="orgCode==null and loginTenantId!=null">
            login_tenant_id = #{loginTenantId}
        </if>
        <if test="orgCode!=null and loginTenantId==null">
            org_code = #{orgCode}
        </if>
        where username = #{username}
    </update>
 
    <!-- 根据手机号查询 -->
    <select id="getUserByPhone"  resultType="org.jeecg.modules.system.entity.SysUser">
        select * from  sys_user  where phone = #{phone} and del_flag = 0
    </select>
    
    <!-- 根据邮箱查询用户信息 -->
    <select id="getUserByEmail" resultType="org.jeecg.modules.system.entity.SysUser">
    select * from  sys_user  where email = #{email} and del_flag = 0
    </select>
 
    <!-- SQL片段:getUserByOrgCode 的 FROM 和 WHERE 部分 -->
    <sql id="getUserByOrgCodeFromSql">
        FROM
        sys_depart
        INNER JOIN sys_user_depart ON sys_user_depart.dep_id = sys_depart.id
        INNER JOIN sys_user ON sys_user.id = sys_user_depart.user_id
        WHERE
        <if test="orgCode == null">
            <bind name="bindOrgCode" value="'%'"/>
        </if>
        <if test="orgCode != null">
            <bind name="bindOrgCode" value="orgCode+'%'"/>
        </if>
        sys_user.del_flag = 0 AND sys_depart.org_code LIKE #{bindOrgCode}
 
        <if test="userParams != null">
            <if test="userParams.realname != null and userParams.realname != ''">
                AND sys_user.realname LIKE concat(concat('%',#{userParams.realname}),'%')
            </if>
            <if test="userParams.workNo != null and userParams.workNo != ''">
                AND sys_user.work_no LIKE concat(concat('%',#{userParams.workNo}),'%')
            </if>
        </if>
    </sql>
 
    <!-- 根据 orgCode 查询用户,包括子部门下的用户 -->
    <select id="getUserByOrgCode" resultType="org.jeecg.modules.system.model.SysUserSysDepartModel">
        SELECT
            sys_user.id AS id,
            sys_user.realname AS realname,
            sys_user.avatar AS avatar,
            sys_user.sex AS sex,
            sys_user.birthday AS birthday,
            sys_user.work_no AS workNo,
            sys_user.post AS post,
            sys_user.telephone AS telephone,
            sys_user.email AS email,
            sys_user.phone AS phone,
            sys_depart.id AS departId,
            sys_depart.depart_name AS departName
        <include refid="getUserByOrgCodeFromSql"/>
        ORDER BY
            sys_depart.org_code ASC
    </select>
 
    <!-- 查询 getUserByOrgCode 的总数-->
    <select id="getUserByOrgCodeTotal" resultType="java.lang.Integer">
        SELECT COUNT(1) <include refid="getUserByOrgCodeFromSql"/>
    </select>
 
    <!-- 批量删除角色的与用户关系-->
    <update id="deleteBathRoleUserRelation">
        delete from sys_user_role
        where role_id in
        <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <!-- 批量删除角色的与权限关系-->
    <update id="deleteBathRolePermissionRelation">
        delete from sys_role_permission
        where role_id in
        <foreach item="id" collection="roleIdArray" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
 
    <!-- 查询被逻辑删除的用户 -->
    <select id="selectLogicDeleted" resultType="org.jeecg.modules.system.entity.SysUser">
        SELECT * FROM sys_user ${ew.customSqlSegment}
    </select>
 
    <!-- 更新被逻辑删除的用户 -->
    <update id="revertLogicDeleted">
        UPDATE
            sys_user
        SET
            del_flag = 0,
            update_by = #{entity.updateBy},
            update_time = #{entity.updateTime}
        WHERE
            del_flag = 1
            AND id IN
            <foreach collection="userIds" item="userId" open="(" close=")" separator="," >
                #{userId}
            </foreach>
    </update>
 
    <!-- 彻底删除被逻辑删除的用户 -->
    <delete id="deleteLogicDeleted">
        DELETE FROM sys_user WHERE del_flag = 1 AND id IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator="," >
            #{userId}
        </foreach>
    </delete>
 
    <!-- 更新空字符串为null -->
    <update id="updateNullByEmptyString">
        UPDATE sys_user
        <if test="fieldName == 'email'">
            SET email = NULL WHERE email = ''
        </if>
        <if test="fieldName == 'phone'">
            SET phone = NULL WHERE phone = ''
        </if>
    </update>
 
    <!-- 通过多个部门IDS,查询部门下的用户信息 -->
    <select id="queryByDepIds" resultType="org.jeecg.modules.system.entity.SysUser">
        select * from sys_user where del_flag = 0
        <if test="departIds!=null  and departIds.size()>0">
            and id in (select user_id from sys_user_depart where dep_id in
            <foreach collection="departIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
            )
        </if>
        <if test="username!=null and username!=''">
            and username != #{username}
        </if>
    </select>
 
    <!--根据角色查询用户-->
    <select id="selectUserListByRoleId" resultType="org.jeecg.modules.system.entity.SysUser">
        select DISTINCT a.* from sys_user a
        left join sys_user_role ur on ur.user_id = a.id
        where
        a.del_flag = 0 and a.status = 1
        and a.username!='_reserve_user_external'
        and ur.role_id=#{roleId}
        <if test="keyword!=null and keyword!=''">
            <bind name="bindKeyword" value="'%'+keyword+'%'"/>
            and (a.username like #{bindKeyword} or a.realname like #{bindKeyword})
        </if>
 
        <if test="tenantId!=null">
            and a.id in (
                select user_id from sys_user_tenant where tenant_id = #{tenantId} and status = '1'
            )
        </if>
    </select>
 
    <!--获取租户下的用户离职列表信息-->
    <select id="getTenantQuitList" resultType="org.jeecg.modules.system.entity.SysUser">
        select su.id,su.username,su.realname,su.sex from sys_user su
        join sys_user_tenant sut on sut.user_id = su.id and sut.status = '2'
        where
        su.status = 1
        and su.del_flag = 0
        <if test="tenantId != 0">
            and sut.tenant_id = #{tenantId}
        </if>
    </select>
    
  <!--更新刪除状态和离职状态-->
  <update id="updateStatusAndFlag">
    UPDATE
    sys_user
    SET
    del_flag = 0,
    update_by = #{sysUser.updateBy},
    update_time = #{sysUser.updateTime},
    status = 1
    WHERE
    del_flag = 1
    AND id IN
    <foreach collection="userIds" item="userId" open="(" close=")" separator="," >
      #{userId}
    </foreach>
  </update>
</mapper>