龚焕茏
2024-07-03 3ec909b27b3eba956aa9d00cc7a94c179bd04bbf
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
<?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.mindskip.xzs.repository.UserMapper">
  <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.User">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="user_uuid" jdbcType="VARCHAR" property="userUuid" />
    <result column="user_name" jdbcType="VARCHAR" property="userName" />
    <result column="password" jdbcType="VARCHAR" property="password" />
    <result column="real_name" jdbcType="VARCHAR" property="realName" />
    <result column="age" jdbcType="INTEGER" property="age" />
    <result column="sex" jdbcType="INTEGER" property="sex" />
    <result column="birth_day" jdbcType="TIMESTAMP" property="birthDay" />
    <result column="user_level" jdbcType="INTEGER" property="userLevel" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="role" jdbcType="INTEGER" property="role" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="image_path" jdbcType="VARCHAR" property="imagePath" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
    <result column="last_active_time" jdbcType="TIMESTAMP" property="lastActiveTime" />
    <result column="deleted" jdbcType="BIT" property="deleted" />
    <result column="wx_open_id" jdbcType="VARCHAR" property="wxOpenId" />
  </resultMap>
  <sql id="Base_Column_List">
    id, user_uuid, user_name, password, real_name, age, sex, birth_day, user_level, phone,
    role, status, image_path, create_time, modify_time, last_active_time, deleted, wx_open_id, `condition`
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.mindskip.xzs.domain.User" useGeneratedKeys="true" keyProperty="id">
    insert into t_user (id, user_uuid, user_name,
      password, real_name, age,
      sex, birth_day, user_level,
      phone, role, status,
      image_path, create_time, modify_time,
      last_active_time, deleted, wx_open_id
      )
    values (#{id,jdbcType=INTEGER}, #{userUuid,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
      #{password,jdbcType=VARCHAR}, #{realName,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER},
      #{sex,jdbcType=INTEGER}, #{birthDay,jdbcType=TIMESTAMP}, #{userLevel,jdbcType=INTEGER},
      #{phone,jdbcType=VARCHAR}, #{role,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
      #{imagePath,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP},
      #{lastActiveTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}, #{wxOpenId,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.mindskip.xzs.domain.User" useGeneratedKeys="true" keyProperty="id">
    insert into t_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="userUuid != null">
        user_uuid,
      </if>
      <if test="userName != null">
        user_name,
      </if>
      <if test="password != null">
        password,
      </if>
      <if test="realName != null">
        real_name,
      </if>
      <if test="age != null">
        age,
      </if>
      <if test="sex != null">
        sex,
      </if>
      <if test="birthDay != null">
        birth_day,
      </if>
      <if test="userLevel != null">
        user_level,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="role != null">
        role,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="imagePath != null">
        image_path,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="modifyTime != null">
        modify_time,
      </if>
      <if test="lastActiveTime != null">
        last_active_time,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
      <if test="wxOpenId != null">
        wx_open_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userUuid != null">
        #{userUuid,jdbcType=VARCHAR},
      </if>
      <if test="userName != null">
        #{userName,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="realName != null">
        #{realName,jdbcType=VARCHAR},
      </if>
      <if test="age != null">
        #{age,jdbcType=INTEGER},
      </if>
      <if test="sex != null">
        #{sex,jdbcType=INTEGER},
      </if>
      <if test="birthDay != null">
        #{birthDay,jdbcType=TIMESTAMP},
      </if>
      <if test="userLevel != null">
        #{userLevel,jdbcType=INTEGER},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="role != null">
        #{role,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="imagePath != null">
        #{imagePath,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyTime != null">
        #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastActiveTime != null">
        #{lastActiveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=BIT},
      </if>
      <if test="wxOpenId != null">
        #{wxOpenId,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.mindskip.xzs.domain.User">
    update t_user
    <set>
      <if test="userUuid != null">
        user_uuid = #{userUuid,jdbcType=VARCHAR},
      </if>
      <if test="userName != null">
        user_name = #{userName,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        password = #{password,jdbcType=VARCHAR},
      </if>
      <if test="realName != null">
        real_name = #{realName,jdbcType=VARCHAR},
      </if>
      <if test="age != null">
        age = #{age,jdbcType=INTEGER},
      </if>
      <if test="sex != null">
        sex = #{sex,jdbcType=INTEGER},
      </if>
      <if test="birthDay != null">
        birth_day = #{birthDay,jdbcType=TIMESTAMP},
      </if>
      <if test="userLevel != null">
        user_level = #{userLevel,jdbcType=INTEGER},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="role != null">
        role = #{role,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="imagePath != null">
        image_path = #{imagePath,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyTime != null">
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastActiveTime != null">
        last_active_time = #{lastActiveTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=BIT},
      </if>
      <if test="wxOpenId != null">
        wx_open_id = #{wxOpenId,jdbcType=VARCHAR},
      </if>
      <if test="deptAdmin != null">
        dept_admin = #{deptAdmin},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.mindskip.xzs.domain.User">
    update t_user
    set user_uuid = #{userUuid,jdbcType=VARCHAR},
      user_name = #{userName,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      real_name = #{realName,jdbcType=VARCHAR},
      age = #{age,jdbcType=INTEGER},
      sex = #{sex,jdbcType=INTEGER},
      birth_day = #{birthDay,jdbcType=TIMESTAMP},
      user_level = #{userLevel,jdbcType=INTEGER},
      phone = #{phone,jdbcType=VARCHAR},
      role = #{role,jdbcType=INTEGER},
      status = #{status,jdbcType=INTEGER},
      image_path = #{imagePath,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      last_active_time = #{lastActiveTime,jdbcType=TIMESTAMP},
      deleted = #{deleted,jdbcType=BIT},
      wx_open_id = #{wxOpenId,jdbcType=VARCHAR},
      dept_admin = #{deptAdmin}
    where id = #{id,jdbcType=INTEGER}
  </update>
 
 
    <select id="getAllUser" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user where deleted=0
    </select>
 
    <select id="getUserByLevel" resultMap="BaseResultMap">
        select id,
               real_name
        from t_user
        where deleted = 0
          and user_level = #{userLevel}
    </select>
 
  <select id="getUserById" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from t_user
    where id=#{value} and status = 1 and deleted = 0 and (`condition` = 0 or `condition` is null)
  </select>
 
    <select id="getUserByUserName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_name=#{value} limit 1
    </select>
 
    <select id="getUserByRealName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and real_name = #{realName}
    </select>
 
    <select id="getUserByUserNamePwd" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_name=#{username} and password=#{pwd} limit 1
    </select>
 
    <select id="getUserByUuid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and user_uuid=#{value,jdbcType=VARCHAR}
    </select>
 
 
    <select id="userPageList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_user
        <where>
            and deleted=0
            <if test="name != null and name != ''">
                and real_name like concat('%',#{name},'%')
            </if>
        </where>
        ORDER BY id
        <if test="offset != null and limit != null ">
            <bind name="patternAdd" value="limit*offset"/>
            limit #{limit} OFFSET #{offset}
        </if>
    </select>
 
 
    <select id="userPageCount" resultType="java.lang.Integer">
        select count(*) from t_user
        <where>
            and deleted=0
            <if test="name != null and name != ''">
                and real_name like concat('%', #{name}, '%')
            </if>
        </where>
    </select>
 
 
    <select id="userPage" resultType="com.mindskip.xzs.viewmodel.admin.user.UserResponseVM" parameterType="com.mindskip.xzs.viewmodel.admin.user.UserPageRequestVM">
        SELECT
        a.*,
        c.result as departmentExamineResult,
        d.result as conditionExamineResult
        FROM t_user a
        LEFT JOIN t_user_department b ON a.id = b.user_id
        LEFT JOIN t_department_examine c ON a.id = c.user_id AND c.deleted = 0 AND c.result = 0
        LEFT JOIN t_user_condition_examine d ON a.id = d.user_id AND d.deleted = 0 AND d.result = 0
        WHERE
            a.deleted=0
            <if test="departmentId != null and departmentId.size() > 0">
                AND b.department_id IN <foreach collection="departmentId" item="item" open="(" separator="," close=")"> #{item} </foreach>
            </if>
            <if test="userName != null and userName != ''">
                AND real_name LIKE concat('%',#{userName},'%')
            </if>
            <if test="roles != null and roles.size() > 0">
                AND role IN <foreach collection="roles" item="item" open="(" separator="," close=")"> #{item} </foreach>
            </if>
        GROUP BY a.id
    </select>
 
 
    <insert id="insertUser" parameterType="com.mindskip.xzs.domain.User"
            useGeneratedKeys="true" keyProperty="id">
        insert into t_user
            (user_uuid, user_name, password, real_name, age, last_active_time)
        values (#{userUuid,jdbcType=VARCHAR}, #{userName}, #{password}, #{realName}, #{age}, #{lastActiveTime})
    </insert>
 
    <insert id="insertUsers" parameterType="java.util.List"
            useGeneratedKeys="true" keyProperty="id">
        insert into t_user
        (user_uuid,user_name,password,real_name,last_active_time,role,status,user_level,deleted)
        values
        <foreach collection="list" item="item"
                 separator=",">
            (#{item.userUuid,jdbcType=VARCHAR},#{item.userName,jdbcType=VARCHAR},#{item.password,jdbcType=VARCHAR},#{item.realName,jdbcType=VARCHAR},
            #{item.lastActiveTime},#{item.role},#{item.status},#{item.userLevel},0)
        </foreach>
    </insert>
 
 
    <update id="updateUser" parameterType="com.mindskip.xzs.domain.User">
        update t_user
        <set>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="age != null">age = #{age},</if>
            <if test="lastActiveTime != null">last_active_time = #{lastActiveTime},</if>
        </set>
        where id = #{id}
    </update>
 
 
    <update id="updateUsersAge">
        update t_user set age = #{age} where id in
        <foreach item="id" collection="idslist" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </update>
 
 
    <delete id="deleteUsersByIds">
        delete from t_user where id in
        <foreach item="id" collection="list" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </delete>
 
    <select id="selectAllCount" resultType="java.lang.Integer">
        SELECT count(*)
        from t_user
        where deleted = 0
    </select>
 
 
    <select id="selectByUserName" resultType="com.mindskip.xzs.domain.other.KeyValue">
        SELECT id as value,user_name as name
        from t_user
        where deleted=0
          and user_name like concat('%'
            , #{value}
            , '%')
            limit 5
    </select>
 
 
    <select id="selectByIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where id in
        <foreach item="id" collection="list" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </select>
 
 
    <select id="selectByWxOpenId" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        where deleted=0 and wx_open_id = #{wxOpenId}
        limit 1
    </select>
 
    <select id="selectByIdName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_user
        <where>
            and deleted=0 and id = #{id}
            <if test="userName != null and userName != ''">
                and user_name like concat('%',#{userName},"%")
            </if>
        </where>
    </select>
 
 
  <update id="updateDeptAdmin">
    UPDATE t_user_department SET dept_admin = #{deptAdmin}
    <where>
      <if test="ids != null and ids.size > 0">
        AND user_id in
        <foreach collection="ids" open="(" separator="," close=")" item="id">
          #{id}
        </foreach>
      </if>
      AND department_id = #{deptId}
    </where>
  </update>
 
  <update id="setStatus">
      UPDATE t_user
      SET `condition` = #{condition}
      WHERE id = #{id}
        AND deleted = 0
  </update>
 
    <update id="clearDeptAdmin">
        update
            t_user_department set dept_admin = 0
        WHERE
              user_id IN <foreach collection="userIds" open="(" separator="," close=")" item="id">#{id}</foreach>
          AND dept_admin = 1 AND department_id = #{deptId}
    </update>
 
    <select id="getUserByDept" resultType="com.mindskip.xzs.domain.ExamPaperAnswer">
        SELECT
        tu.id as createUser, tu.real_name as userName, count(tepa.id) as counts
        FROM
        t_user tu INNER JOIN t_user_department tud ON tu.id = tud.user_id AND tu.deleted = 0
        LEFT JOIN t_exam_paper_answer tepa ON tepa.create_user = tu.id
        <where>
            <if test="query.deptId != null and query.deptId.size() > 0">
                AND tud.department_id in <foreach collection="query.deptId" item="deptId" open="(" separator="," close=")"> #{deptId} </foreach>
            </if>
            <if test="query.start != null and query.end != null">
                AND tepa.create_time between #{query.start} and #{query.end}
            </if>
        </where>
        group by
        createUser, userName
        ORDER BY
        tu.id desc
    </select>
 
    <select id="getUserByExam" resultType="com.mindskip.xzs.domain.User">
        <![CDATA[
        SELECT
        DISTINCT d.*
        FROM t_exam_paper a
        left join t_exam_paper_user b on a.id = b.exam_paper_id and b.deleted = 0
        left join t_exam_paper_answer c on a.id = c.exam_paper_id and c.create_user = b.user_id
        left join t_user d on b.user_id = d.id
        WHERE a.id = #{id}
        and (c.id is null or (user_score / paper_score) < 0.6)
        and b.user_id = #{createUser}
        ]]>
    </select>
 
 
    <update id="updateUserDeptAdmin">
        update t_user set role = -1 where id in
        <foreach collection="adminIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
 
    <update id="cancelUserDeptAdmin">
        update t_user set role = 1 where id in(
            select user_id from t_user_department where department_id = #{id} and user_id not in
            <foreach collection="adminIds" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
             and user_id not in
            (select user_id from t_user_department where dept_admin = 1 and user_id in
            (select user_id from t_user_department where department_id = #{id} and user_id not in
           <foreach collection="adminIds" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        )))
    </update>
 
    <select id="getDeptAdminIds" resultType="java.lang.Integer" parameterType="java.lang.Integer">
        select department_id from t_user_department where dept_admin = 1 and user_id = #{id}
    </select>
 
    <select id="getDeptAdmins" resultType="com.mindskip.xzs.domain.Department" parameterType="java.lang.Integer">
        <if test="id != null">
        select a.id, a.name from t_department a inner join t_user_department b on a.id = b.department_id where a.deleted = 0 and b.dept_admin = 1 and b.user_id = #{id} order by a.id desc
        </if>
        <if test="id == null">
        select a.id, a.name from t_department a where a.deleted = 0 order by a.id desc
        </if>
    </select>
 
    <select id="getUserByExamByTemplateId" resultType="com.mindskip.xzs.domain.User" parameterType="com.mindskip.xzs.domain.ExamPaper">
        select *
        from t_user
        where id in
             (select user_id from t_exam_templates_user WHERE templates_id = #{id} and user_id not in
             (SELECT create_user from t_exam_paper_answer where (user_score / paper_score) > 0.6 and (invalid = 0 or invalid is null) and exam_paper_id in
             (select exam_paper_id from t_exam_templates_user_count WHERE exam_templates_id = #{id})))
        and id = #{createUser}
    </select>
 
    <select id="getDeptIds" resultType="integer">
        SELECT department_id FROM t_user_department WHERE user_id = #{userId} AND dept_admin != 1
    </select>
 
</mapper>