智慧保安后台管理-外网
Administrator
2022-06-20 3313278404a469d4d9f4608d2cb9d5792eb0cf75
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
<?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.springblade.modules.exam.mapper.ExamPaperMapper">
 
    <resultMap id="PagerSubject" type="org.springblade.modules.exam.vo.ExamPaperSubjectVO"
               autoMapping="true">
        <id property="id" column="id"/>
        <collection property="examExaminationSubjects" javaType="java.util.List"
                    ofType="org.springblade.modules.exam.entity.ExamExaminationSubject" autoMapping="true">
            <id property="id" column="tid"/>
            <association property="examSubjectChoices" javaType="org.springblade.modules.exam.entity.ExamSubjectChoices"
                         resultMap="brakesResult" autoMapping="true">
            </association>
        </collection>
    </resultMap>
 
    <resultMap id="PagerSubjectAnswer" type="org.springblade.modules.exam.vo.ExamPaperSubjectVO"
               autoMapping="true">
        <id property="id" column="id"/>
        <collection property="examExaminationSubjects" javaType="java.util.List"
                    ofType="org.springblade.modules.exam.entity.ExamExaminationSubject" autoMapping="true">
            <id property="id" column="tid"/>
            <association property="examSubjectChoices" javaType="org.springblade.modules.exam.entity.ExamSubjectChoices"
                         autoMapping="true">
                <id property="id" column="sid"/>
            </association>
        </collection>
    </resultMap>
 
    <resultMap id="brakesResult" type="org.springblade.modules.exam.vo.ExamSubjectChoicesVO">
        <id property="id" column="sid"/>
        <id property="categoryId" column="category_id"/>
        <id property="subjectName" column="subject_name"/>
        <id property="choicesType" column="choices_type"/>
        <id property="score" column="score"/>
        <id property="analysis" column="analysis"/>
        <id property="level" column="level"/>
        <id property="creator" column="creator"/>
        <id property="createDate" column="create_date"/>
        <id property="modifier" column="modifier"/>
        <id property="modifyDate" column="modify_date"/>
        <id property="delFlag" column="del_flag"/>
        <id property="applicationCode" column="application_code"/>
        <id property="tenantCode" column="tenant_code"/>
    </resultMap>
 
    <resultMap id="RandomResult" type="org.springblade.modules.exam.vo.ExamSubjectChoicesVO">
        <id property="id" column="id"/>
        <id property="categoryId" column="category_id"/>
        <id property="subjectName" column="subject_name"/>
        <id property="choicesType" column="choices_type"/>
        <id property="score" column="score"/>
        <id property="answer" column=""/>
        <id property="analysis" column="analysis"/>
        <id property="level" column="level"/>
        <id property="creator" column="creator"/>
        <id property="createDate" column="create_date"/>
        <id property="modifier" column="modifier"/>
        <id property="modifyDate" column="modify_date"/>
        <id property="delFlag" column="del_flag"/>
        <id property="applicationCode" column="application_code"/>
        <id property="tenantCode" column="tenant_code"/>
    </resultMap>
 
    <select id="queryPagerSubject" resultMap="PagerSubject">
        SELECT
        sj.*,
        tm.id tid,
        tmxq.id as sid,tmxq.*
        FROM
        ksxt_exam sj
        LEFT JOIN exam_examination_subject tm ON sj.id = tm.examination_id
        LEFT JOIN exam_subject_choices tmxq ON tm.subject_id = tmxq.id
        WHERE
        1 = 1
        <if test="paper.id !=null">
            and sj.id = #{paper.id}
        </if>
    </select>
 
    <select id="queryRandomSubject" resultMap="RandomResult" >
        SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 0 ORDER BY RAND( ) LIMIT 25 ) a UNION ALL
        SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 1 ORDER BY RAND( ) LIMIT 10 ) b UNION ALL
        SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 2 ORDER BY RAND( ) LIMIT 20 ) c UNION ALL
        SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 3 ORDER BY RAND( ) LIMIT 5 ) d
    </select>
 
    <select id="selectExamPaperPages" resultType="org.springblade.modules.exam.vo.ExamPaperVO">
        SELECT
            *
        FROM
            (SELECT
                sj.*,
                ( SELECT CASE WHEN COUNT ( * ) > 0 THEN 1 ELSE 0 END FROM sys_apply WHERE user_id = 11 ) AS show
            FROM
                ksxt_exam sj ) as s
        WHERE
            show = 1
    </select>
 
 
    <select id="selectExamPaperPage" resultType="org.springblade.modules.exam.vo.ExamPaperVO">
        SELECT
            ke.*,
            bu.real_name realName,
            bd.dept_name deptName,
            bu1.real_name confirmUserName
        FROM
            ksxt_exam ke
        left join
            blade_user bu
        on
            ke.creator = bu.id
        left join
            blade_dept bd
        on
            bd.id = bu.dept_id
        left join
            blade_user bu1
        on
            ke.confirm_user = bu1.id
        where
        1=1
        <if test="paper.examType!=null and paper.examType!=''">
            and exam_type = #{paper.examType}
        </if>
        <if test="paper.examName!=null and paper.examName!=''">
            and exam_name like concat('%',#{paper.examName},'%')
        </if>
        <if test="paper.deptId!=null and paper.deptId!=''">
            and bd.id = #{paper.deptId}
        </if>
        <if test="paper.deptName!=null and paper.deptName!=''">
            and bd.dept_name like concat('%',#{paper.deptName},'%')
        </if>
        <if test="paper.examTime!=null and paper.examTime!=''">
            and date_format(ke.start_time,'%Y-%m-%d') = #{paper.examTime}
        </if>
        <if test="paper.auditStatus!=null and paper.auditStatus!=''">
            and audit_status = #{paper.auditStatus}
        </if>
        order by ke.start_time desc,ke.id desc
    </select>
 
    <select id="PagerSubject" resultMap="PagerSubjectAnswer">
        SELECT
        sj.*,
        tm.id tid,
        tmxq.id as sid,tmxq.*
        FROM
        ksxt_exam sj
        LEFT JOIN exam_examination_subject tm ON sj.id = tm.examination_id
        LEFT JOIN exam_subject_choices tmxq ON tm.subject_id = tmxq.id
        WHERE
        1 = 1
        <if test="paper.id !=null">
            and sj.id = #{paper.id}
        </if>
    </select>
 
    <!--自定义树-->
    <select id="selectExamPaperPageTree" resultType="org.springblade.modules.exam.entity.ExamPaper">
        select id,exam_name examName from ksxt_exam
        where
        1=1
        <if test="paper.examName!=null and paper.examName!=''">
            and exam_name like concat('%', #{paper.examName},'%')
        </if>
        <if test="paper.examType!=null">
            and exam_type = #{paper.examType}
        </if>
    </select>
 
    <delete id="UnbindSubject">
       delete from exam_examination_subject where examination_id = #{paperid} and subject_id = #{subjectid}
    </delete>
 
    <!--查询考试人员考试信息-->
<!--    <select id="getExamDetail" resultType="org.springblade.modules.exam.vo.ExamPaperVO">-->
<!--        (select-->
<!--            ke.id,ke.exam_name examName,ke.start_time startTime,ke.end_time endTime,ke.exam_type examType,-->
<!--            sa.candidate_no candidateNo,sa.id applyId,-->
<!--            bu.real_name realName,bu.sex,bu.cardid idCardNo-->
<!--        from-->
<!--            ksxt_exam ke-->
<!--        left join-->
<!--            sys_apply sa-->
<!--        on-->
<!--            sa.exam_id = ke.id-->
<!--        left join-->
<!--            blade_user bu-->
<!--        on-->
<!--            bu.id = sa.user_id-->
<!--        where sa.user_id = #{userId}-->
<!--        and is_apply = 1-->
<!--        and is_exam = 1-->
<!--        and sa.apply_status = 2-->
<!--        )-->
 
<!--        union all-->
 
<!--        (select-->
<!--            ke.id,ke.exam_name examName,ke.start_time startTime,ke.end_time endTime,ke.exam_type examType,-->
<!--            str.candidate_no candidateNo,str.id applyId,-->
<!--            bu.real_name realName,bu.sex,bu.cardid idCardNo-->
<!--        from-->
<!--            ksxt_exam ke-->
<!--        left join-->
<!--            sys_training_registration str-->
<!--        on-->
<!--            str.train_exam_id = ke.id-->
<!--        left join-->
<!--            blade_user bu-->
<!--        on-->
<!--            bu.id = str.user_id-->
<!--        where str.user_id = #{userId}-->
<!--        and bu.is_train = 1-->
<!--        and (str.is_exam = 1 or str.is_exam = 3)-->
<!--        and ke.audit_status = 1-->
<!--        and str.cancel = 1-->
<!--        and str.audit_status = 1-->
<!--        )-->
<!--    </select>    、-->
 
    <!--查询考试人员考试信息-->
    <select id="getExamDetail" resultType="org.springblade.modules.exam.vo.ExamPaperVO">
        select
            ke.id,ke.exam_name examName,ke.start_time startTime,ke.end_time endTime,ke.exam_type examType,
            str.candidate_no candidateNo,str.id applyId,str.is_exam isExam,
            bu.real_name realName,bu.sex,bu.cardid idCardNo,
            es.exam_time examStartTime,es.id scoreId
        from
            ksxt_exam ke
        left join
            sys_training_registration str
        on
            str.train_exam_id = ke.id
        left join
            blade_user bu
        on
            bu.id = str.user_id
        left join
            exam_score es
        on
        es.apply_id = str.id
        where str.user_id = #{examPaper.userId}
        and bu.is_train = 1
        and (str.is_exam = 1 or str.is_exam = 3)
        and ke.audit_status = 1
        and str.cancel = 1
        and str.audit_status = 1
        and ke.start_time &lt;= now() and ke.end_time &gt; now()
        order by str.id desc
    </select>
 
    <!--查询是当前前缀已生成准考证号码最大的一位-->
    <select id="getCandidateNoCount" resultType="java.lang.Integer">
        select ifnull(max(0+RIGHT(candidate_no,4)),0) from sys_training_registration
        where candidate_no like concat('%', #{result},'%')
    </select>
 
    <!--查询当前考试已报名的人员培训报名数据集合-->
    <select id="getTrainList" resultType="org.springblade.modules.training.entity.TrainingRegistration">
        SELECT
        str.id,str.user_id userId,str.candidate_no candidateNo
        FROM
        sys_training_registration str
        left join
        ksxt_exam ke
        on
        ke.id = str.train_exam_id
        left join
        blade_user bu
        on
        bu.id = str.user_id
        where 1=1
        and bu.is_train = 1
        and str.is_exam = 1
        and str.cancel = 1
        and str.train_exam_id = #{id}
    </select>
 
    <!--使用考试名称匹配考试信息-->
    <select id="getExamInfoByExamName" resultType="org.springblade.modules.exam.entity.ExamPaper">
        SELECT
            *
        FROM
            ksxt_exam
        where exam_name like concat('%', #{examName},'%')
    </select>
 
    <!--查询当前考试的报名人员数量-->
    <select id="getApplyNumber" resultType="java.lang.Integer">
        select count(*) from sys_apply
        where
        exam_id = #{examPaper.id}
        and apply_status = 2
    </select>
 
    <!--查询当前考试的报名人员数量,模拟考试-->
    <select id="getTrainNumber" resultType="java.lang.Integer">
        select count(*) from sys_training_registration str
        left join
            blade_user bu
        on
            bu.id = str.user_id
        where
            1=1
        and train_exam_id = #{examPaper.id}
    </select>
 
    <!--根据用户id查询报名信息-->
    <select id="getApplyDetail" resultType="org.springblade.modules.apply.entity.Apply">
        (select
            sa.id as id
        from
            sys_apply sa
        left join
            blade_user bu
        on
            bu.id = sa.user_id
        where sa.user_id = #{userId}
        and is_apply = 1
        and is_exam = 1
        and sa.apply_status = 2
        )
 
        union all
 
        (select
            str.id as id
        from
            sys_training_registration str
        left join
            blade_user bu
        on
            bu.id = str.user_id
        where str.user_id = #{userId}
        and bu.is_train = 1
        and is_exam = 1
        and str.cancel = 1
        )
    </select>
 
    <!--查询当前人员当前考试的考试题目信息-->
    <select id="getExaminationSubjectList" resultType="org.springblade.modules.exam.vo.ExamSubjectChoicesVO">
        SELECT
            esc.id,esc.category_id,esc.subject_name,esc.choices_type,esc.score,esc.level
        FROM
            exam_subject_choices esc
        left join
        exam_examination_subject ees
        on
        esc.id = ees.subject_id
        where 1=1
        and ees.examination_id = #{examPaper.scoreId}
    </select>
 
    <!--批量新增考生考题信息-->
    <insert id="insertBatch" parameterType="java.util.List">
        insert into exam_examination_subject
        (examination_id,category_id,subject_id)
        values
        <foreach collection="list" index="index" item="item" separator=",">
            (
                #{item.examinationId},
                #{item.categoryId},
                #{item.subjectId}
            )
        </foreach>
    </insert>
 
    <!--查询当前考试的报名人员数量,模拟考试-->
    <select id="getExamNumber" resultType="java.lang.Integer">
        select count(*) from sys_training_registration str
        left join
            blade_user bu
        on
            bu.id = str.user_id
        where
            1=1
        and train_exam_id = #{examPaper.id}
        and (is_exam = 2 or is_exam = 3)
        and cancel = 1
    </select>
 
    <!--考试查询统计-->
<!--    <select id="getExamStatistics" resultType="org.springblade.modules.exam.vo.ExamStatisticsVO">-->
<!--        SELECt-->
<!--        ke.id,ke.start_time startTime,ke.end_time endTime,bd.dept_name schoolName,-->
<!--        ifnull(a.c,0) znum,-->
<!--        ifnull(b.c,0) yknum,-->
<!--        ifnull(c.c,0) qknum,-->
<!--        ifnull(d.c,0) ycnum,-->
<!--        ifnull(e.c,0) qxnum-->
<!--        from ksxt_exam ke-->
<!--        left join (select count(*) c,train_exam_id from sys_training_registration GROUP BY train_exam_id) a on a.train_exam_id = ke.id-->
<!--        left join (select count(*) c,train_exam_id from sys_training_registration where 1=1 and (is_exam = 2 or is_exam = 3)  GROUP BY train_exam_id) b on b.train_exam_id = ke.id-->
<!--        left join (select count(*) c,train_exam_id from sys_training_registration str left join blade_user bu on bu.id = str.user_id where 1=1 and is_exam = 4 and cancel =2 or (is_exam=1 and cancel =1) and bu.examination_type!=1 GROUP BY train_exam_id) c on c.train_exam_id = ke.id-->
<!--        left join (select count(*) c,train_exam_id from sys_training_registration str left join blade_user bu on bu.id = str.user_id where 1=1 and cancel =1 and is_exam = 1 and bu.examination_type = 1 GROUP BY train_exam_id) d on d.train_exam_id = ke.id-->
<!--        left join (select count(*) c,train_exam_id from sys_training_registration where 1=1 and is_exam = 1 and cancel =2 GROUP BY train_exam_id) e on e.train_exam_id = ke.id-->
<!--        left join blade_user bu2 on bu2.id = ke.creator-->
<!--        left join blade_dept bd on bd.id = bu2.dept_id-->
<!--        where 1=1-->
<!--        and ke.audit_status = 1-->
<!--        <if test="examPaper.schoolName!=null and examPaper.schoolName!=''">-->
<!--            and bd.dept_name like concat('%',#{examPaper.schoolName},'%')-->
<!--        </if>-->
<!--        <if test="examPaper.examTime!=null and examPaper.examTime!=''">-->
<!--            and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.examTime}-->
<!--        </if>-->
<!--        order by ke.id desc-->
<!--    </select>    -->
 
    <!--考试查询统计,按天,培训学校分组-->
    <select id="getExamStatistics" resultType="org.springblade.modules.exam.vo.ExamStatisticsVO">
        SELECt
        si.enterpriseName schoolName,
        a.time startTime,
        a.training_unit_id trainUnitId,
        ifnull(a.c,0) znum,
        ifnull(b.c,0) yknum,
        ifnull(f.c,0) zznum,
        ifnull(c.c,0) qknum,
        ifnull(d.c,0) ycnum,
        ifnull(e.c,0) qxnum
        from
        (select date_format(ke.start_time,'%Y-%m-%d') time,str.training_unit_id,count(*) c from sys_training_registration str left join ksxt_exam ke on ke.id = str.train_exam_id where 1=1 and ke.audit_status =1 GROUP BY date_format(ke.start_time,'%Y-%m-%d'),str.training_unit_id ) a
        left join
        (select count(*) c,date_format(ke.start_time,'%Y-%m-%d') time,str.training_unit_id from sys_training_registration str left join ksxt_exam ke on ke.id = str.train_exam_id where 1=1 and ke.audit_status =1 and (is_exam = 2 or is_exam = 3) GROUP BY date_format(ke.start_time,'%Y-%m-%d'),str.training_unit_id ) b
        on a.time = b.time and a.training_unit_id = b.training_unit_id
        left join
        (select count(*) c,date_format(ke.start_time,'%Y-%m-%d') time,str.training_unit_id from sys_training_registration str left join ksxt_exam ke on ke.id = str.train_exam_id where 1=1 and ke.audit_status =1 and is_exam = 5 GROUP BY date_format(ke.start_time,'%Y-%m-%d'),str.training_unit_id ) f
        on a.time = f.time and a.training_unit_id = f.training_unit_id
        left join
        (select count(*) c,date_format(ke.start_time,'%Y-%m-%d') time,str.training_unit_id from sys_training_registration str left join ksxt_exam ke on ke.id = str.train_exam_id left join blade_user bu on bu.id = str.user_id where 1=1 and is_exam = 4 GROUP BY date_format(ke.start_time,'%Y-%m-%d'),str.training_unit_id ) c
        on a.time = c.time and a.training_unit_id = c.training_unit_id
        left join
        (select count(*) c,date_format(ke.start_time,'%Y-%m-%d') time,str.training_unit_id from sys_training_registration str left join ksxt_exam ke on ke.id = str.train_exam_id left join blade_user bu on bu.id = str.user_id where 1=1 and cancel =1 and is_exam = 1 and bu.examination_type = 1 GROUP BY date_format(ke.start_time,'%Y-%m-%d'),str.training_unit_id ) d
        on a.time = d.time and a.training_unit_id = d.training_unit_id
        left join
        (select count(*) c,date_format(ke.start_time,'%Y-%m-%d') time,str.training_unit_id from sys_training_registration str left join ksxt_exam ke on ke.id = str.train_exam_id where 1=1 and is_exam = 1 and cancel =2 GROUP BY date_format(ke.start_time,'%Y-%m-%d'),str.training_unit_id ) e
        on a.time = e.time and a.training_unit_id = e.training_unit_id
        left join sys_information si on si.departmentid = a.training_unit_id
        where 1=1
        <if test="examPaper.schoolName!=null and examPaper.schoolName!=''">
            and si.enterpriseName like concat('%',#{examPaper.schoolName},'%')
        </if>
        <if test="examPaper.examTime!=null and examPaper.examTime!=''">
            and a.time = #{examPaper.examTime}
        </if>
        order by a.time desc,si.enterpriseName desc
    </select>
 
    <!--根据考试id 统计查询考试信息-->
    <select id="getExamInfoByExamId" resultType="org.springblade.modules.exam.vo.ExamStatisticsVO">
        select
        a.dept_id id,
        bd.dept_name deptName,
        ifnull(a.c,0) znum,
        ifnull(b.c,0) qknum,
        ifnull(d.c,0) ycnum,
        ifnull(c.c,0) yknum from
        (select bu.dept_id,count(*) c from sys_training_registration str left join blade_user bu on bu.id = str.user_id left join ksxt_exam ke on ke.id = str.train_exam_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.startTime} GROUP BY bu.dept_id) a
        left join blade_dept bd on a.dept_id = bd.id
        left join (select bu.dept_id,count(*) c from sys_training_registration str left join blade_user bu on bu.id = str.user_id left join ksxt_exam ke on ke.id = str.train_exam_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.startTime} and cancel =1 and is_exam = 1 and bu.examination_type = 1 GROUP BY bu.dept_id) d on d.dept_id = a.dept_id
        left join (select bu.dept_id,count(*) c from sys_training_registration str left join blade_user bu on bu.id = str.user_id left join ksxt_exam ke on ke.id = str.train_exam_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.startTime} and is_exam = 4 GROUP BY bu.dept_id) b on b.dept_id = a.dept_id
        left join (select bu.dept_id,count(*) c from exam_score es left join blade_user bu on bu.id = es.user_id left join ksxt_exam ke on ke.id = es.exam_id left join sys_training_registration str on str.id = es.apply_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.startTime} and es.theory_grade &gt;= 60 GROUP BY bu.dept_id) c on c.dept_id = a.dept_id
    </select>
 
    <!--根据考试id 统计查询考试信息-->
    <select id="getExamInfoByExamIdList" resultType="org.springblade.modules.exam.vo.ExamStatisticsVO">
        select (@i:=@i+1) no,aa.*  from (
        select
        bd.dept_name deptName,
        ifnull(a.c,0) znum,
        ifnull(b.c,0) qknum,
        ifnull(d.c,0) ycnum,
        ifnull(c.c,0) yknum from
        (select bu.dept_id,count(*) c from sys_training_registration str left join blade_user bu on bu.id = str.user_id left join ksxt_exam ke on ke.id = str.train_exam_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.examDate} GROUP BY bu.dept_id) a
        left join blade_dept bd on a.dept_id = bd.id
        left join (select bu.dept_id,count(*) c from sys_training_registration str left join blade_user bu on bu.id = str.user_id left join ksxt_exam ke on ke.id = str.train_exam_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.examDate} and cancel =1 and is_exam = 1 and bu.examination_type = 1 GROUP BY bu.dept_id) d on d.dept_id = a.dept_id
        left join (select bu.dept_id,count(*) c from sys_training_registration str left join blade_user bu on bu.id = str.user_id left join ksxt_exam ke on ke.id = str.train_exam_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.examDate} and is_exam = 4 GROUP BY bu.dept_id) b on b.dept_id = a.dept_id
        left join (select bu.dept_id,count(*) c from exam_score es left join blade_user bu on bu.id = es.user_id left join ksxt_exam ke on ke.id = es.exam_id left join sys_training_registration str on str.id = es.apply_id where str.training_unit_id = #{examPaper.trainUnitId} and date_format(ke.start_time,'%Y-%m-%d') = #{examPaper.examDate} and es.theory_grade &gt;= 60 GROUP BY bu.dept_id) c on c.dept_id = a.dept_id
        ) aa,(select @i:=0) bb
    </select>
 
    <!--导出-按条件查询成绩数据-模拟考试-->
    <select id="getExamScoreList" resultType="org.springblade.modules.exam.vo.ExamScoreVO">
        select (@i:=@i+1) no,aa.* from (
        SELECT
        bu.real_name securityName,
        bd.dept_name companyName,
        es.theory_grade theoryGrade,es.learn_grade learnGrade,es.all_grade allGrade,
        case when es.qualified=0 then "合格"
        when es.qualified=1 then "不合格"
        when es.qualified=2 then "暂未录入实操成绩"
        when es.qualified=3 then "缺考"
        else "" end as sortName
        from
        exam_score es
        left join
        ksxt_exam ke
        on
        ke.id = es.exam_id
        left join
        blade_user bu
        on
        es.user_id = bu.id
        left join
        blade_dept bd
        on
        bd.id = bu.dept_id
        left join
        sys_training_registration str
        on
        str.id = es.apply_id
        where
        1=1
        and (str.is_exam = 2 or str.is_exam = 3 or str.is_exam = 4 or str.is_exam = 5)
        <if test="examScore.trainUnitId!=null">
            and str.training_unit_id = #{examScore.trainUnitId}
        </if>
        <if test="examScore.isExam!=null and  examScore.isExam!=''">
            and str.is_exam = #{examScore.isExam}
        </if>
        <if test="examScore.examType!=null and  examScore.examType!=''">
            and ke.exam_type = #{examScore.examType}
        </if>
        <if test="examScore.examDate!=null  and examScore.examDate!=''">
            and date_format(ke.start_time,'%Y-%m-%d') = #{examScore.examDate}
        </if>
        order by es.id desc
        ) aa,(select @i:=0) bb
    </select>
 
    <!--ExamSubjectChoicesInfoMap 多表联查 一对多查询 -->
    <resultMap id="ExamSubjectChoicesInfoMap" type="org.springblade.modules.exam.vo.ExamSubjectChoicesVO">
        <id property="id" column="id"/>
        <id property="categoryId" column="category_id"/>
        <id property="subjectName" column="subject_name"/>
        <id property="choicesType" column="choices_type"/>
        <id property="answer" column="answer"/>
        <id property="score" column="score"/>
        <id property="level" column="level"/>
        <result column="id" property="id"/>
        <collection property="examSubjectOptions" javaType="java.util.List" ofType="org.springblade.modules.exam.entity.ExamSubjectOption" autoMapping="true">
            <id property="id" column="eso_id"/>
        </collection>
    </resultMap>
 
    <!--已缴费人员题目查询-->
    <select id="queryRandomSubjectList" resultMap="ExamSubjectChoicesInfoMap">
        select
        esc.id,esc.category_id,esc.subject_name,esc.choices_type,esc.score,esc.answer,
        eso.id eso_id,eso.subject_choices_id,eso.option_name,eso.option_content,eso.creator,
        eso.create_date,eso.modifier,eso.modify_date,eso.del_flag,eso.application_code,eso.tenant_code
        from (
            select
            id,
            category_id,
            subject_name,
            choices_type,
            score,
            answer,
            analysis,
            tktype
            from (
            select * from exam_subject_choices
            where id in
            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
            ) a ORDER BY RAND() LIMIT #{number}
        ) esc
        left join
        exam_subject_option eso
        on
        esc.id = eso.subject_choices_id
    </select>
 
    <!--模拟考试随机抽题-->
    <select id="simulateQueryRandomSubjectList" resultMap="ExamSubjectChoicesInfoMap">
        SELECT
            esc.id,
            esc.category_id,
            esc.subject_name,
            esc.choices_type,
            esc.score,
            esc.answer,
            eso.id eso_id,
            eso.subject_choices_id,
            eso.option_name,
            eso.option_content,
            eso.creator,
            eso.create_date,
            eso.modifier,
            eso.modify_date,
            eso.del_flag,
            eso.application_code,
            eso.tenant_code
        FROM
            (
                SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 0 ORDER BY RAND( ) LIMIT 25 ) a UNION ALL
                SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 1 ORDER BY RAND( ) LIMIT 10 ) b UNION ALL
                SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 2 ORDER BY RAND( ) LIMIT 20 ) c UNION ALL
                SELECT * FROM ( SELECT * FROM exam_subject_choices WHERE choices_type = 3 ORDER BY RAND( ) LIMIT 5 ) d
            ) esc
            LEFT JOIN exam_subject_option eso ON esc.id = eso.subject_choices_id
            order by esc.choices_type
    </select>
 
 
</mapper>