张晓波
2023-10-30 1b3a14a25d8f5013158ef2842e9be0e24240f2b5
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?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.thhy.usercore.modules.sys.sysusers.mapper.SysUsersMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        user_id as userId,
        username as username,
        password as password,
        real_name as realName,
        telphone as telphone,
        photo_url as photoUrl,
        create_user as createUser,
        create_time as createTime,
        is_use as isUse,
        sex as sex,
        email as email,
        version as version,
        sub_admin as subAdmin,
        is_plat as isPlat,
        plat_id as platId,
        is_app as isApp
    </sql>
 
    <!-- 排除密码列 -->
    <sql id="Without_Pass_Column_List">
        user_id as userId,
        username as username,
        real_name as realName,
        telphone as telphone,
        photo_url as photoUrl,
        create_user as createUser,
        create_time as createTime,
        is_use as isUse,
        sex as sex,
        email as email,
        version as version
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND " >
                is_use = 1 AND
                <if test="username!=null and username!=''">
                    username LIKE  concat('%',#{username},'%') AND
                </if>
                <if test="realName!=null and realName!=''">
                    real_name = #{realName} AND
                </if>
                <if test="telphone!=null and telphone!=''">
                    telphone LIKE concat('%',#{telphone},'%') AND
                </if>
                <if test="createTime!=null">
                    create_time = #{createTime} AND
                </if>
                <!--<if test="isUse!=null">
                    is_use = #{isUse} AND
                </if>-->
                <if test="sex!=null">
                    sex = #{sex} AND
                </if>
                <if test="email!=null and email!=''">
                    email = #{email} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
        select <include refid="Base_Column_List" />
        from sys_users where user_id = #{userId}
    </select>
 
    <select id="queryByPhone" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
        select <include refid="Base_Column_List" />
        from sys_users where telphone = #{telphone}
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from sys_users where user_id = #{userId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
        SELECT
        <include refid="Without_Pass_Column_List" />
        from sys_users
        <where>
            <trim suffixOverrides=" AND " >
                is_use = 1 AND
                <if test="username!=null and username!=''">
                    username LIKE  concat('%',#{username},'%') AND
                </if>
                <if test="realName!=null and realName!=''">
                    real_name = #{realName} AND
                </if>
                <if test="telphone!=null and telphone!=''">
                    telphone LIKE concat('%',#{telphone},'%') AND
                </if>
                <if test="createTime!=null">
                    create_time = #{createTime} AND
                </if>
                <!--<if test="isUse!=null">
                    is_use = #{isUse} AND
                </if>-->
                <if test="sex!=null">
                    sex = #{sex} AND
                </if>
                <if test="email!=null and email!=''">
                    email = #{email} AND
                </if>
            </trim>
        </where>
        order by create_time desc
    </select>
 
    <!--查询列表-->
    <select id="findListWithAccess" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
        SELECT
        su.user_id as userId,
        su.username as username,
        su.real_name as realName,
        su.telphone as telphone,
        su.photo_url as photoUrl,
        su.create_user as createUser,
        su.create_time as createTime,
        su.is_use as isUse,
        su.sex as sex,
        su.email as email,
        su.version as version
        from sys_users su
        left join sys_plat_user spu on spu.user_id = su.plat_id
        left join sys_depart_user sdu on spu.user_id = sdu.user_id
        left join sys_com_depart scd on scd.depart_id = sdu.depart_id
        left join sys_com_su scs on scs.user_id = su.user_id
        left join sys_plat_position_user ppu on ppu.user_id = spu.user_id
        left join sys_position sp on sp.pos_id = ppu.position_id
        <where>
            <trim suffixOverrides=" AND " >
                su.is_use = 1 AND (scd.company_id = #{companyId} or scs.company_id = #{companyId} or sp.company_id = #{companyId}) AND
                <if test="username!=null and username!=''">
                    su.username LIKE  concat('%',#{username},'%') AND
                </if>
                <if test="realName!=null and realName!=''">
                    su.real_name = #{realName} AND
                </if>
                <if test="telphone!=null and telphone!=''">
                    su.telphone LIKE concat('%',#{telphone},'%') AND
                </if>
                <if test="createTime!=null">
                    su.create_time = #{createTime} AND
                </if>
                <!--<if test="isUse!=null">
                    is_use = #{isUse} AND
                </if>-->
                <if test="sex!=null">
                    su.sex = #{sex} AND
                </if>
                <if test="email!=null and email!=''">
                    su.email = #{email} AND
                </if>
            </trim>
        </where>
        order by su.create_time desc
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into sys_users
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="userId != null">
            user_id,
            </if>
            <if test="username != null">
            username,
            </if>
            <if test="password != null">
            password,
            </if>
            <if test="realName != null">
            real_name,
            </if>
            <if test="telphone != null">
            telphone,
            </if>
            <if test="photoUrl != null">
            photo_url,
            </if>
            <if test="createUser != null">
            create_user,
            </if>
            <if test="createTime != null">
            create_time,
            </if>
            <if test="isUse != null">
            is_use,
            </if>
            <if test="sex != null">
            sex,
            </if>
            <if test="email != null">
            email,
            </if>
            <if test="isPlat != null">
                is_plat,
            </if>
            <if test="subAdmin != null">
                sub_admin,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="userId != null">
            #{userId},
            </if>
            <if test="username != null">
            #{username},
            </if>
            <if test="password != null">
            #{password},
            </if>
            <if test="realName != null">
            #{realName},
            </if>
            <if test="telphone != null">
            #{telphone},
            </if>
            <if test="photoUrl != null">
            #{photoUrl},
            </if>
            <if test="createUser != null">
            #{createUser},
            </if>
            <if test="createTime != null">
            #{createTime},
            </if>
            <if test="isUse != null">
            #{isUse},
            </if>
            <if test="sex != null">
            #{sex},
            </if>
            <if test="email != null">
            #{email},
            </if>
            <if test="isPlat != null">
                #{isPlat},
            </if>
            <if test="subAdmin != null">
                #{subAdmin},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update sys_users
        <set>
            version = version+1,
            <if test="username != null">
                username=#{username},
            </if>
            <if test="password != null">
                password=#{password},
            </if>
            <if test="realName != null">
                real_name=#{realName},
            </if>
            <if test="telphone != null">
                telphone=#{telphone},
            </if>
            <if test="photoUrl != null">
                photo_url=#{photoUrl},
            </if>
            <if test="createUser != null">
                create_user=#{createUser},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="isUse != null">
                is_use=#{isUse},
            </if>
            <if test="sex != null">
                sex=#{sex},
            </if>
            <if test="email != null">
                email=#{email},
            </if>
        </set>
        where user_id=#{userId}
    </update>
 
    <!--更新操作-->
    <update id="deletelogic">
        update sys_users
        SET is_use = 0
        where user_id=#{id}
    </update>
 
    <!--根据ID删除-->
    <!--<delete id="deleteById">
        Delete from sys_users where id = #{id}
    </delete>-->
 
    <!--<select id="login" resultType="boolean" parameterType="SysUserDto">
        SELECT CASE WHEN count(user_id) = 1 THEN true else false end as isExist
        FROM sys_users
        WHERE (username = #{username} OR email = #{email} OR telphone = #{telphone}) AND password = #{password}
          AND sys_users.is_use = 1
    </select>-->
 
    <select id="queryByUsername" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
        SELECT
            su.user_id as userId,
            su.username as username,
            su.real_name as realName,
            su.password,
            su.telphone as telphone,
            su.photo_url as photoUrl,
            su.create_user as createUser,
            su.create_time as createTime,
            su.is_use as isUse,
            su.sex as sex,
            su.email as email,
            su.sub_admin as subAdmin,
            su.is_plat as isPlat
        FROM sys_users su
        WHERE (su.username = #{username} OR su.email = #{username} OR su.telphone = #{username})
          AND su.is_use = 1
    </select>
 
    <select id="queryByUsernameIsPlat" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
        SELECT
            su.user_id as userId,
            su.username as username,
            su.real_name as realName,
            su.password,
            su.telphone as telphone,
            su.photo_url as photoUrl,
            su.create_user as createUser,
            su.create_time as createTime,
            su.is_use as isUse,
            su.sex as sex,
            su.email as email,
            su.sub_admin as subAdmin,
            su.is_plat as isPlat,
            su.plat_id as platId,
            spu.user_type as userType
        FROM sys_users su
        left join sys_plat_user spu on spu.user_id = su.plat_id
        WHERE (su.username = #{username} OR su.email = #{username} OR su.telphone = #{username})
          AND su.is_use = 1 and is_plat = 1
    </select>
 
    <select id="queryUserUrls" resultType="string">
        select su.url_path as urlpath
        from sys_user_role sur
                 left join sys_roles sr on sr.role_id = sur.role_id
                 left join sys_role_url srurl on srurl.role_id = sur.role_id
                 left join sys_url su on su.url_id = srurl.url_id
        where sur.user_id = #{userId} and sur.is_use = 1
    </select>
 
    <select id="queryUserButtons" resultType="string">
        select GROUP_CONCAT(sb.button_html_id)
        from sys_user_role sur
                 left join sys_role_button srb on srb.role_id = sur.role_id
                 left join sys_button sb on sb.button_id = srb.button_id
        where sur.user_id = #{userId} and sur.is_use = 1
        GROUP BY user_id
    </select>
 
    <update id="updateUserPass">
        update sys_users
        set password = #{password}
        where user_id = #{userId}
    </update>
 
    <select id="queryCompanyByComAdmin" resultType="hashmap">
        select sc.company_id as companyId,sc.company_name as companyName
        from sys_com_su scs
                 left join sys_company sc on sc.company_id = scs.company_id
        where scs.user_id = #{userId}
    </select>
 
    <select id="queryCompanyByUser" resultType="hashmap">
        select sc.company_id as companyId,
               sc.company_name as companyName
        from sys_com_depart scd
                 left join sys_company sc on sc.company_id = scd.company_id
        where scd.depart_id = (
            select depart_id
            from sys_depart_user du
                     left join sys_plat_user spu on spu.user_id = du.user_id
                     left join sys_users su on su.plat_id = spu.user_id
            where su.user_id = #{userId} limit 1)
    </select>
 
    <select id="queryCompanyByPosition" resultType="hashmap">
        select sc.company_id as companyId,sc.company_name as companyName
        from sys_plat_position_user ppu
                 left join sys_users su on su.plat_id = ppu.user_id
                 left join sys_position sp on sp.pos_id = ppu.position_id
                 left join sys_company sc on sc.company_id = sp.company_id
        where su.user_id = #{userId}
        limit 1
    </select>
 
    <!--插入操作-->
    <insert id="insertCompanyUser" parameterType="com.thhy.usercore.modules.sys.sysusers.entity.CompanySu">
        insert into sys_com_su
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="id != null">
                id,
            </if>
            <if test="companyId != null">
                company_id,
            </if>
            <if test="userId != null">
                user_id,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="id != null">
                #{id},
            </if>
            <if test="companyId != null">
                #{companyId},
            </if>
            <if test="userId != null">
                #{userId},
            </if>
        </trim>
    </insert>
 
    <select id="queryPlatUser" resultType="com.thhy.usercore.modules.sys.sysusers.entity.PlatUserVo">
        select user_type as userType from sys_plat_user where user_id = #{userId}
    </select>
 
    <update id="nologin">
        update sys_plat_user set is_login = 2 where user_id = #{platId}
    </update>
 
    <delete id="deleteApplyHistory">
        delete from t_user_apply_history where plat_user_id = #{platId} or user_id = #{platId}
    </delete>
</mapper>