kongzy
2024-06-24 4910e41f81a85c03a9dfc83f8ec9c1e71c123d49
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
<?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.gkhy.exam.system.mapper.ExQuestionMapper">
    <resultMap type="com.gkhy.exam.system.domain.ExQuestion" id="ExQuestionResult">
        <result property="id"       column="id"       />
        <result property="questionType"    column="question_type"    />
        <result property="bankId"     column="bank_id"     />
        <result property="status"         column="status"          />
        <result property="companyId"         column="company_id"          />
        <result property="status"         column="status"          />
        <result property="answer"         column="answer"          />
        <result property="title"         column="title"          />
        <result property="privatize"         column="privatize"          />
        <result property="content"         column="content"          />
        <result property="version"         column="version"          />
        <result property="createBy"       column="create_by"       />
        <result property="createTime"     column="create_time"     />
        <result property="updateBy"       column="update_by"       />
        <result property="updateTime"     column="update_time"     />
        <result property="remark"         column="remark"          />
        <association property="exExerciseAnswer" javaType="com.gkhy.exam.system.domain.ExExerciseAnswer" resultMap="ExerciseAnswerResult" />
        <association property="studentAnswer" javaType="com.gkhy.exam.system.domain.ExStudentAnswer" resultMap="StudentAnswerResult" />
    </resultMap>
 
    <resultMap id="ExerciseAnswerResult" type="com.gkhy.exam.system.domain.ExExerciseAnswer">
        <id     property="id"       column="exercise_answer_id"        />
        <result property="bankId"     column="bank_id"      />
        <result property="studentId"     column="student_id"      />
        <result property="questionId"     column="question_id"      />
        <result property="answer"     column="exercise_answer"      />
        <result property="passed"     column="exercise_passed"      />
    </resultMap>
 
    <resultMap id="StudentAnswerResult" type="com.gkhy.exam.system.domain.ExStudentAnswer">
        <id     property="id"       column="student_answer_id"        />
        <result property="paperId"     column="paper_id"      />
        <result property="studentId"     column="student_id"      />
        <result property="questionId"     column="question_id"      />
        <result property="answer"     column="student_answer"      />
        <result property="passed"     column="student_passed"      />
    </resultMap>
 
    <sql id="selectQuestionVo">
        select id, question_type, bank_id, status, company_id,answer,title,privatize,content,version, create_by, create_time, update_by, update_time, remark
        from ex_course
    </sql>
 
 
    <select id="selectCountByBankId" resultType="integer">
        select count(1) from ex_question where bank_id=#{bankId} and question_type=#{questionType} and (company_id=#{companyId} or privatize=1)
    </select>
 
    <select id="selectQuestionWithLimit" resultType="com.gkhy.exam.system.domain.ExQuestion">
        select id,title from ex_question where bank_id=#{bankId} and question_type=#{questionType} and (company_id=#{companyId} or privatize=1) limit #{startIndex},{questionCount}
    </select>
 
    <select id="selectRandomQuestion" resultType="com.gkhy.exam.system.domain.ExQuestion">
        select id,title from ex_question where bank_id=#{bankId} and question_type=#{questionType} and (company_id=#{companyId} or privatize=1) order by RAND()
        limit {questionCount}
    </select>
 
    <select id="selectQuestionList" resultType="com.gkhy.exam.system.domain.ExQuestion">
        select id,question_type, bank_id, status, company_id,answer,title,privatize from ex_question
        <where>
            <if test="title!=null and title!=''">
            title like concat(#{title},"%")
            </if>
            <if test="bankId!=null">
                bank_id=#{bankId}
            </if>
            <if test="companyId!=null">
                company_id=#{companyId}
            </if>
            <if test="questionType!=null">
                question_type=#{questionType}
            </if>
            <if test="privatize!=null">
                privatize=#{privatize}
            </if>
        </where>
        order by id desc
    </select>
 
    <select id="getExerciseQuestionList" resultType="java.util.Map">
        select a.id,b.passed from ex_question a
        left join ex_exercise_answer b on b.question_id=a.id and b.student_id=#{studentId}
        where a.bank_id=#{bankId}
        <if test="exerciseType=2">
            order by a.question_type asc,a.id asc
        </if>
        <if test="exerciseType=1">
            order by a.id asc
        </if>
    </select>
 
    <select id="getExeriseQuestionById" resultMap="ExQuestionResult">
        select a.*,b.id as exercise_id, b.answer as exercise_answer,b.question_id,b.student_id,b.passed as exercise_passed from ex_question a
        left join ex_exercise_answer b on b.question_id=a.id and b.student_id=#{studentId}
        where a.id=#{questionId}
    </select>
 
    <select id="getExeriseQuestionByIds" resultMap="ExQuestionResult">
        select a.*,b.id as exercise_answer_id, b.answer as exercise_answer,b.question_id,b.student_id,b.passed as exercise_passed from ex_question a
        left join ex_exercise_answer b on b.question_id=a.id and b.student_id=#{studentId}
        where a.id in
        <foreach collection="questionIds" item="questionId" open="(" separator="," close=")">
            #{questionId}
        </foreach>
    </select>
 
    <select id="getPaperQuestionList" resultType="java.util.Map">
        select a.id
             <if test="completed=1">
             ,c.passed
             </if>
        from ex_question a
        inner join ex_paper_question b on b.question_id=a.id
        <if test="completed=1">
        left join ex_student_answer c on c.question_id=a.id and c.student_id=#{studentId} and c.paper_id=#{paperId}
        </if>
        where b.paper_id=#{paperId}
        order by a.question_type asc,a.id asc
    </select>
 
    <select id="getPaperQuestionById" resultMap="ExQuestionResult">
        select a.id,a.question_type,a.bank_id,a.company_id,a.title,a.content,a.privatize,
               b.id as student_answer_id, b.answer as student_answer,b.question_id,b.student_id
               <if test="completed=1">
                   ,a.answer,b.passed as student_passed
               </if>
        from ex_question a
        left join ex_student_answer b on b.question_id=a.id and b.student_id=#{studentId} and b.paper_id=#{paperId}
        where a.id=#{questionId}
    </select>
 
    <select id="getPaperQuestionByIds" resultType="com.gkhy.exam.system.domain.ExQuestion">
        select a.id,a.question_type,a.bank_id,a.company_id,a.title,a.content,a.privatize,
        b.id as student_answer_id, b.answer as student_answer,b.question_id,b.student_id
        <if test="completed=1">
            ,a.answer,b.passed as student_passed
        </if>
        from ex_question a
        left join ex_student_answer b on b.question_id=a.id and b.student_id=#{studentId} and b.paper_id=#{paperId}
        where a.id in
        <foreach collection="questionIds" item="questionId" open="(" separator="," close=")">
            #{questionId}
        </foreach>
    </select>
 
    <select id="getExerciseErrorQuestionList" resultType="java.lang.Long">
        select a.id from ex_question a
        inner join ex_exercise_answer b on b.question_id=a.id
        where a.bank_id=#{bankId} and b.student_id=#{studentId}
        order by a.question_type asc,a.id asc
    </select>
 
 
</mapper>