张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
<?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.ExamReAnswerMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.id as id,
        t.answer_id as answerId,
        t.create_time as createTime,
        t.exam_id as examId,
        t.que_id as queId,
        t.record_id as recordId
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                <if test="answerId!=null and answerId!=''">
                    t.answer_id = #{answerId} AND
                </if>
                <if test="createTime!=null">
                    t.create_time = #{createTime} AND
                </if>
                <if test="examId!=null and examId!=''">
                    t.exam_id = #{examId} AND
                </if>
                <if test="queId!=null and queId!=''">
                    t.que_id = #{queId} AND
                </if>
                <if test="recordId!=null and recordId!=''">
                    t.record_id = #{recordId} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.secure.modules.biz.exam.entity.ExamReAnswer">
        select <include refid="Base_Column_List" />
        from t_exam_re_answer t
        where t.id=#{id}
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from t_exam_re_answer
        where id=#{id}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.secure.modules.biz.exam.entity.ExamReAnswer">
        SELECT
        <include refid="Base_Column_List" />
        from t_exam_re_answer t
        <include refid="condition_query" />
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.secure.modules.biz.exam.entity.ExamReAnswer">
        SELECT
        <include refid="Base_Column_List" />
        from t_exam_re_answer t
    </select>
 
    <select id="countByRecordId" resultType="int">
        select count(id) from t_exam_re_answer where record_id = #{recordId}
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into t_exam_re_answer
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="answerId != null">
                answer_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="examId != null">
                exam_id,
            </if>
            <if test="id != null">
                id,
            </if>
            <if test="queId != null">
                que_id,
            </if>
            <if test="recordId != null">
                record_id,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="answerId != null">
                #{answerId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="examId != null">
                #{examId},
            </if>
            <if test="id != null">
                #{id},
            </if>
            <if test="queId != null">
                #{queId},
            </if>
            <if test="recordId != null">
                #{recordId},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update t_exam_re_answer
        <set>
            <if test="answerId != null">
                answer_id=#{answerId},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="examId != null">
                exam_id=#{examId},
            </if>
            <if test="queId != null">
                que_id=#{queId},
            </if>
            <if test="recordId != null">
                record_id=#{recordId},
            </if>
        </set>
        where id=#{id}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update t_exam_re_answer
        SET is_use = 0
        where id=#{id}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from t_exam_re_answer
        where id=#{id}
    </delete>
 
    <select id="examScoreCul" resultType="double">
        select case when b.totalScore is NULL then 0 else b.totalScore end as totalScore from (select sum(a.score) as totalScore from (
             select era.record_id,era.que_id,q.score,GROUP_CONCAT(ta.ans_id order by ta.sort) as answerIds,(select GROUP_CONCAT(ans_id order by sort) from t_answer where is_right = 1 and que_id = era.que_id group by que_id) as rightAnswerIds
             from t_exam_re_answer era
                      left join t_answer ta on era.answer_id = ta.ans_id
                      left join t_question q on q.que_id = era.que_id
             where era.record_id = #{recordId}
             group by era.record_id,era.que_id
         ) a where a.answerIds = a.rightAnswerIds) b
    </select>
 
</mapper>