龚焕茏
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
<?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.QuestionSubjectMapper">
    <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.QuestionSubject">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="subject_id" jdbcType="INTEGER" property="subjectId"/>
        <result column="question_id" jdbcType="INTEGER" property="questionId"/>
        <result column="deleted" jdbcType="INTEGER" property="deleted"/>
        <result column="sub_name" jdbcType="VARCHAR" property="subName"/>
    </resultMap>
 
    <sql id="Base_Column_List">
        id, subject_id,question_id,deleted
    </sql>
 
 
    <delete id="removes" parameterType="java.lang.Integer">
        delete from t_question_subject
        where id in
        <foreach item="id" collection="ids" open="(" separator=","
                 close=")">
            #{id}
        </foreach>
    </delete>
 
    <delete id="removeQuestionId" parameterType="java.lang.Integer">
        delete from t_question_subject
        where question_id = #{questionId}
    </delete>
 
    <select id="getQuestion" resultMap="BaseResultMap">
        select qs.*,s.name as subName
            from t_question_subject qs
            left join t_subject s on qs.subject_id = s.id
        where question_id = #{id} and qs.deleted = 0 and s.deleted = 0
    </select>
 
    <insert id="saves" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        insert into t_question_subject(id,subject_id,question_id,deleted)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.id},#{item.subjectId},#{item.questionId},#{item.deleted})
        </foreach>
    </insert>
 
    <delete id="removeSubjectId" parameterType="java.lang.Integer">
        delete from t_question_subject
        where subject_id = #{subjectId}
    </delete>
 
    <select id="getSubject" resultMap="BaseResultMap">
        select qs.*,s.name as subName
        from t_question_subject qs
                 left join t_subject s on qs.subject_id = s.id
        where subject_id = #{id} and qs.deleted = 0 and s.deleted = 0
    </select>
 
    <select id="countQuestionNum" resultType="integer">
        SELECT
               count(distinct tqs.question_id)
        FROM
             t_question_subject tqs
                INNER JOIN t_question tq ON tq.id = tqs.question_id <if test="questionType != -99">AND tq.question_type = #{questionType}</if>
        WHERE
            tqs.subject_id IN <foreach collection="subjects" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach>
 
    </select>
 
    <select id="getRandomQuestionId" resultType="com.mindskip.xzs.domain.vo.QuestionVO">
        SELECT
            distinct
            tq.id,
            tq.question_type as questionType,
            tq.difficult,
            ttc.content as contentJson,
            tq.correct
        FROM
             t_question_subject tqs
                 INNER JOIN t_question tq ON tqs.question_id = tq.id AND tq.deleted = 0
                                                 <if test="questionType != null and questionType != -99">
                                                     AND tq.question_type = #{questionType}
                                                 </if>
                                                 AND tqs.subject_id IN <foreach collection="subjectIds" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach>
                 INNER JOIN t_text_content ttc ON tq.info_text_content_id = ttc.id
        ORDER BY
             RAND() LIMIT #{questionNum}
    </select>
 
    <select id="questionsBySubjectIds" resultType="integer">
        SELECT
               question_id
        FROM
             t_question_subject
        <where>
            subject_id IN <foreach collection="subjectIds" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach>
        </where>
        ORDER BY
            id DESC
    </select>
 
    <select id="questionsBySubjectId" resultType="integer">
        SELECT
            tqs.question_id, ttc.content
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId}
                INNER JOIN t_text_content ttc ON ttc.id = tq.info_text_content_id
        ORDER BY
            tqs.id DESC
    </select>
 
    <select id="questionsBySubjectIdAndQuestionType" resultType="integer">
        SELECT
            tqs.question_id, ttc.content
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId} AND tq.question_type = #{questionType}
                INNER JOIN t_text_content ttc ON ttc.id = tq.info_text_content_id
        ORDER BY
            tqs.id DESC
    </select>
 
    <select id="bySubjectId" resultType="com.mindskip.xzs.domain.vo.QuestionVO">
        SELECT
           tq.id,
           tq.question_type,
           tq.correct,
           ttc.content as contentJson
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId}
                INNER JOIN t_text_content ttc ON ttc.id = tq.info_text_content_id
        ORDER BY
            tq.id DESC
    </select>
 
    <select id="bySubjectIdAndQuestionType" resultType="com.mindskip.xzs.domain.vo.QuestionVO">
        SELECT
            tq.id,
            tq.question_type,
            tq.correct,
            ttc.content as contentJson
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId} AND tq.question_type = #{questionType}
                INNER JOIN t_text_content ttc ON ttc.id = tq.info_text_content_id
        ORDER BY
            tq.id DESC
    </select>
 
    <select id="getSubjectBySubjectIds" resultType="com.mindskip.xzs.domain.QuestionSubject">
        select qs.*,s.name as subName
        from t_question_subject qs
                 left join t_subject s on qs.subject_id = s.id
        where qs.deleted = 0 and s.deleted = 0
        <if test="subjectIds != null and subjectIds.length > 0">
            and qs.subject_id in
            <foreach collection="subjectIds" item="subjectId" open="(" separator="," close=")">
                #{subjectId}
            </foreach>
        </if>
    </select>
 
</mapper>