linzhijie
2021-03-11 c33914ba0a98c823c4b4d7da21cdd476906c9924
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
<?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.ots.project.exam.mapper.TQuestionMapper">
 
    <resultMap type="TQuestion" id="TQuestionResult">
        <result property="id" column="id"/>
        <result property="questionType" column="question_type"/>
        <result property="levelId" column="level_id"/>
        <result property="levelName" column="level_name"/>
        <result property="subjectId" column="subject_id"/>
        <result property="langType" column="lang_type"/>
        <result property="score" column="score"/>
        <result property="gradeLevel" column="grade_level"/>
        <result property="difficult" column="difficult"/>
        <result property="correct" column="correct"/>
        <result property="infoTextContentId" column="info_text_content_id"/>
        <result property="createUser" column="create_user"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="deleted" column="deleted"/>
        <result property="subjectName" column="subject_name"/>
        <result property="permanentId" column="permanent_id"/>
        <result property="questionTemplateId" column="question_template_id"/>
        <result property="template" column="template"/>
    </resultMap>
 
    <sql id="Base_Column_List">
    id, question_type, subject_id,lang_type, score, grade_level, difficult, correct, info_text_content_id,
    create_user, status, create_time, deleted, permanent_id, template
    </sql>
 
    <sql id="selectTQuestionVo">
        select id, question_type,lang_type, subject_id, score, grade_level, difficult, correct, info_text_content_id, create_user, status, create_time, deleted, template from t_question
    </sql>
 
    <sql id="selectTQuestioAndTTextContent">
        select tq.id, tq.question_type, tq.lang_type,tq.subject_id, tq.score, tq.grade_level, tq.difficult, tq.correct, tq.info_text_content_id, tq.create_user, tq.status, tq.create_time, tq.deleted, tt.content content, tel.level_name level_name, tel.id level_id, tq.permanent_id permanent_id, tel.question_template_id question_template_id, tq.template from t_question tq,t_text_content tt, t_exam_level tel
    </sql>
 
    <select id="selectTQuestionList" parameterType="TQuestion" resultMap="TQuestionResult">
        <include refid="selectTQuestioAndTTextContent"/>
        <where>
            tq.info_text_content_id = tt.id and tq.level_id = tel.id and tq.deleted in(0,1)
            <if test="levelName != null ">and tel.level_name like concat('%', #{levelName}, '%')</if>
            <if test="title != null and title !=''">and tt.content like concat('%', #{title}, '%')</if>
            <if test="levelId != null ">and tel.id = #{levelId}</if>
            <if test="uuid != null and uuid !=''">and tq.id = #{uuid}</if>
            <if test="questionTemplateId != null and questionTemplateId !=''">and tel.question_template_id = #{questionTemplateId}</if>
            <if test="template != null and template !=''">and tq.template = #{template}</if>
        </where>
        order by tq.create_time desc
    </select>
 
    <select id="selectTQuestionsForProductAddQuestion" parameterType="TQuestion" resultMap="TQuestionResult">
        <include refid="selectTQuestioAndTTextContent"/>
        <where>
            tq.info_text_content_id = tt.id and tq.level_id = tel.id and tq.deleted in(0,1)
            <if test="levelName != null ">and tel.level_name like concat('%', #{levelName}, '%')</if>
            <if test="title != null and title !=''">and tt.content like concat('%', #{title}, '%')</if>
            <if test="levelId != null ">and tel.id = #{levelId}</if>
            <if test="questionTemplateId != null and questionTemplateId !=''">and (tel.question_template_id = #{questionTemplateId} or tq.template = #{questionTemplateId} )</if>
            <if test="questionTemplateId == null or questionTemplateId ==''">and  ifnull(tq.template, "") != 'job_title' </if>
            <if test="template != null and template !=''">and tq.template = #{template}</if>
        </where>
        order by tq.create_time asc
    </select>
 
    <select id="selectTQuestionById" parameterType="Long" resultMap="TQuestionResult">
        <include refid="selectTQuestioAndTTextContent"/>
        where tq.id = #{id} and tq.info_text_content_id = tt.id and tel.id = tq.level_id
        order by tq.create_time desc
    </select>
 
    <select id="selectTQuestionByPermanentId" parameterType="String" resultMap="TQuestionResult">
        <include refid="selectTQuestioAndTTextContent"/>
        where tq.permanent_id = #{permanentId} and tq.info_text_content_id = tt.id and tel.id = tq.level_id and tq.deleted in(0, 1)
        order by tq.create_time asc
    </select>
 
    <select id="selectTQuestionByIds" parameterType="Long" resultMap="TQuestionResult">
        <include refid="selectTQuestioAndTTextContent"/>
        where  tq.info_text_content_id = tt.id and tel.id = tq.level_id and tq.id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        order by tq.create_time desc
    </select>
 
    <select id="selectTQuestionScore" parameterType="Integer" resultMap="TQuestionResult">
        SELECT sum(q.score) score from t_question q,t_text_content ttc
        where q.info_text_content_id = ttc.id and q.id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <insert id="insertTQuestion" parameterType="TQuestion" useGeneratedKeys="true" keyProperty="id">
        insert into t_question
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="questionType != null ">question_type,</if>
            <if test="levelId != null ">level_id,</if>
            <if test="subjectId != null ">subject_id,</if>
            <if test="score != null ">score,</if>
            <if test="langType != null ">lang_type,</if>
            <if test="gradeLevel != null ">grade_level,</if>
            <if test="difficult != null ">difficult,</if>
            <if test="correct != null  and correct != ''">correct,</if>
            <if test="infoTextContentId != null ">info_text_content_id,</if>
            <if test="createUser != null ">create_user,</if>
            <if test="status != null ">status,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="deleted != null ">deleted,</if>
            <if test="permanentId != null ">permanent_id,</if>
            <if test="lastId != null ">last_id,</if>
            <if test="template != null ">template,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="questionType != null ">#{questionType},</if>
            <if test="levelId != null ">#{levelId},</if>
            <if test="subjectId != null ">#{subjectId},</if>
            <if test="score != null ">#{score},</if>
            <if test="langType != null ">#{langType},</if>
            <if test="gradeLevel != null ">#{gradeLevel},</if>
            <if test="difficult != null ">#{difficult},</if>
            <if test="correct != null  and correct != ''">#{correct},</if>
            <if test="infoTextContentId != null ">#{infoTextContentId},</if>
            <if test="createUser != null ">#{createUser},</if>
            <if test="status != null ">#{status},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="deleted != null ">#{deleted},</if>
            <if test="permanentId != null ">#{permanentId},</if>
            <if test="lastId != null ">#{lastId},</if>
            <if test="template != null ">#{template},</if>
        </trim>
    </insert>
 
    <update id="updateTQuestion" parameterType="TQuestion">
        update t_question
        <trim prefix="SET" suffixOverrides=",">
            <if test="questionType != null ">question_type = #{questionType},</if>
            <if test="subjectId != null ">subject_id = #{subjectId},</if>
            <if test="score != null ">score = #{score},</if>
            <if test="langType != null ">lang_type = #{langType},</if>
            <if test="gradeLevel != null ">grade_level = #{gradeLevel},</if>
            <if test="difficult != null ">difficult = #{difficult},</if>
            <if test="correct != null  and correct != ''">correct = #{correct},</if>
            <if test="infoTextContentId != null ">info_text_content_id = #{infoTextContentId},</if>
            <if test="createUser != null ">create_user = #{createUser},</if>
            <if test="status != null ">status = #{status},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="deleted != null ">deleted = #{deleted},</if>
            <if test="permanentId != null ">permanent_id = #{permanentId},</if>
            <if test="template != null ">template = #{template},</if>
        </trim>
        <where>
            id = #{id}
        </where>
    </update>
 
 
    <update id="updateTQuestionByPermanentId" parameterType="TQuestion">
        update t_question
        <trim prefix="SET" suffixOverrides=",">
            <if test="questionType != null ">question_type = #{questionType},</if>
            <if test="subjectId != null ">subject_id = #{subjectId},</if>
            <if test="score != null ">score = #{score},</if>
            <if test="langType != null ">lang_type = #{langType},</if>
            <if test="gradeLevel != null ">grade_level = #{gradeLevel},</if>
            <if test="difficult != null ">difficult = #{difficult},</if>
            <if test="correct != null  and correct != ''">correct = #{correct},</if>
            <if test="infoTextContentId != null ">info_text_content_id = #{infoTextContentId},</if>
            <if test="createUser != null ">create_user = #{createUser},</if>
            <if test="status != null ">status = #{status},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="deleted != null ">deleted = #{deleted},</if>
            <if test="permanentId != null ">permanent_id = #{permanentId},</if>
        </trim>
        <where>
            permanent_id = #{permanentId}
            <if test="langType != null ">and lang_type = #{langType}</if>
        </where>
    </update>
 
    <delete id="deleteTQuestionById" parameterType="Long">
        delete from t_question where id = #{id}
    </delete>
 
    <delete id="deleteTQuestionByIds" parameterType="String">
        delete from t_question where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <delete id="updateQuetionByDelete" parameterType="String">
        update t_question set deleted = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
    <select id="selectByIds" resultMap="TQuestionResult">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_question where id in
        <foreach item="id" collection="ids" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="selectTQuestionByPermanentIds" parameterType="Long" resultMap="TQuestionResult">
        <include refid="selectTQuestioAndTTextContent"/>
        where tq.deleted = 1 and tq.info_text_content_id = tt.id and tel.id = tq.level_id and tq.permanent_id in
        <foreach item="permanentId" collection="list" open="(" separator="," close=")">
            #{permanentId}
        </foreach>
        order by tq.create_time desc
    </select>
 
</mapper>