邱宇豪
2023-11-10 c7f12c87e3a3e459281750d4387e8310b4aa460a
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
<?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.secure.modules.biz.exam.mapper.ExamRecordMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.record_id as recordId,
        t.end_time as endTime,
        t.exam_id as examId,
        t.is_finish as isFinish,
        t.score as score,
        t.start_time as startTime,
        t.user_id as userId,
        t.que_count as queCount
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                <if test="endTime!=null">
                    t.end_time = #{endTime} AND
                </if>
                <if test="examId!=null and examId!=''">
                    t.exam_id = #{examId} AND
                </if>
                <if test="isFinish!=null">
                    t.is_finish = #{isFinish} AND
                </if>
                <if test="score!=null">
                    t.score = #{score} AND
                </if>
                <if test="startTime!=null">
                    t.start_time = #{startTime} AND
                </if>
                <if test="userId!=null and userId!=''">
                    t.user_id = #{userId} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.secure.modules.biz.exam.entity.ExamRecord">
        select <include refid="Base_Column_List" />
        from t_exam_record t
        where t.record_id=#{recordId}
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from t_exam_record
        where record_id=#{recordId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.secure.modules.biz.exam.entity.ExamRecord">
        SELECT
        <include refid="Base_Column_List" />
        from t_exam_record t
        <include refid="condition_query" />
    </select>
 
    <select id="recordList" resultType="com.thhy.secure.modules.biz.exam.entity.ExamRecordListVo">
        select * from (select e.exam_name as examName,su.real_name as realName,t.start_time as
        startTime,TIMESTAMPDIFF(SECOND,t.start_time,t.end_time) as diff,
        t.score,(t.score&gt;=e.qualified_score) as pass,
        (select GROUP_CONCAT(sg.group_name) as group_name from sys_group_user sgu left join sys_group sg on sg.group_id
        = sgu.group_id where sgu.user_id = spu.user_id group by sgu.user_id) as groupName
        ,(select GROUP_CONCAT(sgu.group_id) as groupIds from sys_group_user sgu where sgu.user_id = spu.user_id group by
        sgu.user_id) as groupIds
        from t_exam_record t
        left join t_exam e on e.exam_id = t.exam_id
        left join sys_users su on su.user_id = t.user_id
        left join sys_plat_user spu on spu.user_id = su.plat_id
        left join sys_depart_user sdu on sdu.user_id = spu.user_id
        where t.is_finish = 1 and t.exam_id = #{examId}
        <if test="examResult != null">
            <if test="examResult == 1">
                <!--合格-->
                AND t.score &gt;= e.qualified_score
            </if>
            <if test="examResult == 0">
                AND t.score &lt; e.qualified_score
            </if>
        </if>
        <if test="startTime != null">
            AND DATE(t.start_time) &gt;= DATE(#{startTime})
        </if>
        <if test="endTime != null">
            AND DATE(t.start_time) &lt;= DATE(#{endTime})
        </if>
        <if test="departId != null and departId !=''">
            AND sdu.depart_id = #{departId}
        </if>
        <if test="realName !=null and realName !=''">
            AND spu.real_name LIKE concat('%',#{realName},'%')
        </if>
        ) a
        <if test="groupId != null and groupId !=''">
            where a.groupIds LIKE concat('%',#{groupId},'%')
        </if>
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.secure.modules.biz.exam.entity.ExamRecord">
        SELECT
        <include refid="Base_Column_List" />
        from t_exam_record t
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into t_exam_record
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="endTime != null">
                end_time,
            </if>
            <if test="examId != null">
                exam_id,
            </if>
            <if test="isFinish != null">
                is_finish,
            </if>
            <if test="recordId != null">
                record_id,
            </if>
            <if test="score != null">
                score,
            </if>
            <if test="startTime != null">
                start_time,
            </if>
            <if test="userId != null">
                user_id,
            </if>
            <if test="queCount != null">
                que_count,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="endTime != null">
                #{endTime},
            </if>
            <if test="examId != null">
                #{examId},
            </if>
            <if test="isFinish != null">
                #{isFinish},
            </if>
            <if test="recordId != null">
                #{recordId},
            </if>
            <if test="score != null">
                #{score},
            </if>
            <if test="startTime != null">
                #{startTime},
            </if>
            <if test="userId != null">
                #{userId},
            </if>
            <if test="queCount != null">
                #{queCount},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update t_exam_record
        <set>
            <if test="endTime != null">
                end_time=#{endTime},
            </if>
            <if test="examId != null">
                exam_id=#{examId},
            </if>
            <if test="isFinish != null">
                is_finish=#{isFinish},
            </if>
            <if test="score != null">
                score=#{score},
            </if>
            <if test="startTime != null">
                start_time=#{startTime},
            </if>
            <if test="userId != null">
                user_id=#{userId},
            </if>
        </set>
        where record_id=#{recordId}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update t_exam_record
        SET is_use = 0
        where record_id=#{recordId}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from t_exam_record
        where record_id=#{recordId}
    </delete>
 
    <update id="ExamFinish">
        update t_exam_record set is_finish = 1,score = #{score},end_time = sysdate() where record_id=#{recordId}
    </update>
 
    <select id="countByExam" resultType="int">
        select count(DISTINCT er.user_id)
        from t_exam_record er
        left join t_exam e on e.exam_id = er.exam_id
        where er.exam_id = #{examId} and er.is_finish = 1
        <if test="isPass != null">
            and er.score &gt;= e.qualified_score
        </if>
    </select>
 
    <select id="planUserCountByExam" resultType="int">
        select count(DISTINCT ppu.user_id) as count
        from t_exam e
            left join t_secure_train st on e.train_id = st.secure_id
            left join t_secure_group tsg on tsg.secure_id = st.secure_id
            left join sys_plat_position_user ppu on ppu.position_id = tsg.group_id
            left join sys_plat_user spu on spu.user_id = ppu.user_id
        where e.exam_id = #{examId} and spu.user_id is not null
    </select>
 
</mapper>