“djh”
5 天以前 99132a43bf344f2aafdd9894b0762d2eedd9767b
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
<?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"          />
        <result property="bankName"         column="bank_name"          />
        <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>
    <insert id="saveBatch">
        INSERT INTO
        `train_exam`.`ex_question`
        ( `question_type`, `bank_id`, `company_id`, `status`, `answer`, `title`, `content`, `privatize`, `create_time`,
         `create_by`, `update_time`, `update_by`, `remark`, `version`)
        VALUES
        <foreach collection="exQuestions" item="question" separator=",">
            (#{question.questionType}, #{question.bankId}, #{question.companyId}, #{question.status}, #{question.answer},
             #{question.title}, #{question.content}, #{question.privatize}, #{question.createTime}, #{question.createBy},
             #{question.updateTime}, #{question.updateBy}, #{question.remark}, #{question.version})
        </foreach>
    </insert>
 
 
    <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 a.id,a.question_type, a.bank_id, a.status, a.company_id,a.title,a.privatize,b.name as bank_name from ex_question a
        left join ex_question_bank b on b.id=a.bank_id
        <where>
            <if test="title!=null and title!=''">
                and a.title like concat(#{title},"%")
            </if>
            <if test="bankId!=null">
                and a.bank_id=#{bankId}
            </if>
            <if test="companyId!=null">
                and (a.company_id=#{companyId} or a.privatize=1)
            </if>
            <if test="questionType!=null">
                and a.question_type=#{questionType}
            </if>
<!--            <if test="privatize!=null">-->
<!--                and 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}
        order by a.question_type asc,a.id asc
    </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>
        ORDER BY FIELD(a.id, <foreach collection="questionIds" item="questionId" separator=",">#{questionId}</foreach>)
    </select>
 
    <select id="getPaperQuestionList" resultType="java.util.Map">
        select a.id
             <if test="viewType==1">
                ,
                 case when c.answer is null then 0
                 else 1
                 end as state
             </if>
            <if test="viewType==2">
                <if test="state!=0">
                    ,c.passed
                </if>
            </if>
        from ex_question a
        inner join ex_paper_question b on b.question_id=a.id
        left join ex_student_answer c on c.question_id=a.id and c.student_id=#{studentId} and c.paper_id=#{paperId}
        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="state!=0">
                   ,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" 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="state!=0">
            ,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>
        ORDER BY FIELD(a.id, <foreach collection="questionIds" item="questionId" separator=",">#{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} and b.passed=0
        order by a.question_type asc,a.id asc
    </select>
 
    <select id="selectByQuestionId" resultType="com.gkhy.exam.system.domain.ExQuestion">
        select a.*,b.name as bank_name from ex_question a
        left join ex_question_bank b on b.id=a.bank_id
        where a.id=#{questionId}
    </select>
 
    <select id="selectQuestionByPaperId" resultType="com.gkhy.exam.system.domain.ExQuestion"
            parameterType="java.lang.Long">
        select a.* from ex_question a
        inner join ex_paper_question b on b.question_id=a.id
        where b.paper_id=#{paperId}
    </select>
 
 
</mapper>