heheng
7 天以前 eb71761e48cc18972b64d1e0abc1e34a3d8bc546
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
<?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.ExPaperStudentMapper">
    <resultMap type="com.gkhy.exam.system.domain.ExPaperStudent" id="ExPaperStudentResult">
        <result property="id"       column="id"       />
        <result property="paperId"    column="paper_id"    />
        <result property="studentId"     column="student_id"     />
        <result property="score"     column="score"     />
        <result property="passed"     column="passed"     />
        <result property="useTime"     column="use_time"     />
        <result property="state"     column="state"     />
        <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="createName"         column="create_name"          />
        <association property="student" javaType="com.gkhy.exam.system.domain.ExStudent" resultMap="exStudentResult" />
        <association property="examPaper" javaType="com.gkhy.exam.system.domain.ExExamPaper" resultMap="exExamPaperResult" />
        <collection property="questions" ofType="com.gkhy.exam.system.domain.ExQuestion" select="getQuestionByPaperId" column="{paperId=paper_id,studentId=student_id,state=state}"/>
     </resultMap>
 
 
    <resultMap type="com.gkhy.exam.system.domain.ExPaperStudent" id="SimplePaperStudentResult">
        <result property="id"       column="id"       />
        <result property="paperId"    column="paper_id"    />
        <result property="studentId"     column="student_id"     />
        <result property="score"     column="score"     />
        <result property="passed"     column="passed"     />
        <result property="useTime"     column="use_time"     />
        <result property="startTime"     column="start_time"     />
        <result property="state"     column="state"     />
        <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="createName"         column="create_name"          />
        <result property="companyId"         column="company_id"          />
        <result property="companyName"         column="company_name"          />
        <association property="student" javaType="com.gkhy.exam.system.domain.ExStudent" resultMap="exStudentResult" />
        <association property="examPaper" javaType="com.gkhy.exam.system.domain.ExExamPaper" resultMap="exExamPaperResult" />
    </resultMap>
 
    <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"          />
        <association property="studentAnswer" javaType="com.gkhy.exam.system.domain.ExStudentAnswer" resultMap="studentAnswerResult" />
    </resultMap>
 
    <resultMap id="studentAnswerResult" type="com.gkhy.exam.system.domain.ExStudentAnswer">
        <result property="id"       column="answer_id"       />
        <result property="paperId"       column="answer_paper_id"       />
        <result property="studentId"       column="answer_student_id"       />
        <result property="questionId"       column="answer_question_id"       />
        <result property="answer"       column="answer_answer"       />
        <result property="passed"       column="answer_passed"       />
        <result property="score"       column="answer_score"       />
    </resultMap>
 
    <resultMap id="exExamPaperResult" type="com.gkhy.exam.system.domain.ExExamPaper">
        <result property="id"       column="paper_id"       />
        <result property="code"       column="paper_code"       />
        <result property="name"       column="paper_name"       />
        <result property="categoryName"       column="category_name"       />
        <result property="limited"       column="limited"       />
        <result property="limitTime"       column="limit_time"       />
        <result property="deadline"       column="deadline"       />
        <result property="singleNum"       column="single_num"       />
        <result property="multiNum"       column="multi_num"       />
        <result property="judgeNum"       column="judge_num"       />
        <result property="easyNum"       column="easy_num"       />
        <result property="singleScore"       column="single_score"       />
        <result property="multiScore"       column="multi_score"       />
        <result property="judgeScore"       column="judge_score"       />
        <result property="easyScore"       column="easy_score"       />
    </resultMap>
 
    <resultMap id="exStudentResult" type="com.gkhy.exam.system.domain.ExStudent">
        <result property="id"       column="student_id"       />
        <result property="name"       column="student_name"       />
        <result property="phone"       column="student_phone"       />
    </resultMap>
 
    <insert id="batchInsert">
        insert into ex_paper_student(paper_id,student_id,create_id) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.paperId},#{item.studentId},#{item.createId})
        </foreach>
    </insert>
 
    <update id="batchUpdateComplete">
        update ex_paper_student set completed=#{completed}
        where id in
        <foreach collection="paperStudentIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>
 
    <select id="countByPaperId" resultType="java.lang.Integer">
        select count(1) from ex_paper_student where paper_id=#{paperId}
    </select>
 
    <select id="selectCountByPaperStudentId" resultType="java.lang.Integer">
        select count(1) from ex_paper_student where paper_id=#{paperId} and student_id=#{studentId}
    </select>
 
    <select id="selectPaperStudentList" resultMap="SimplePaperStudentResult">
        select a.*,e.name as create_name,b.phone as student_phone,b.name as student_name,c.name as paper_name,c.code as paper_code,c.limited,c.limit_time,c.deadline,d.name as category_name
        <if test="studentId!=null">
        ,(select question_id from ex_student_answer where paper_id=a.paper_id and student_id=#{studentId} order by id desc limit 1) as question_id
        </if>
        from ex_paper_student a
        left join ex_student b on a.student_id=b.id
        left join ex_exam_paper c on c.id=a.paper_id
        left join sys_category d on d.id=c.category_id
        left join sys_user e on e.id =a.create_id
        <where>
            and c.del_flag=0
            <if test="paperId!=null">
                and a.paper_id=#{paperId}
            </if>
            <if test="studentName!=null and studentName!=''">
                and b.name like concat('%',#{studentName},'%')
            </if>
            <if test="studentPhone!=null and studentPhone!=''">
                and b.phone like concat('%',#{studentPhone},'%')
            </if>
            <if test="studentId!=null">
                and a.student_id = #{studentId}
            </if>
            <if test="state!=null">
                and a.state = #{state}
            </if>
        </where>
        order by a.passed desc,a.id desc
    </select>
 
    <select id="selectPaperStudentById" resultMap="ExPaperStudentResult">
        select a.*,b.id as student_id,b.phone as student_phone,b.name as student_name,c.name as paper_name,c.single_num,c.multi_num,c.judge_num,c.easy_num,c.single_score,c.multi_score,c.judge_score,c.easy_score from ex_paper_student a
        left join ex_student b on a.student_id=b.id
        left join ex_exam_paper c on c.id=a.paper_id
        where a.id=#{paperStudentId}
    </select>
 
    <select id="selectSimplePaperStudentById" resultMap="SimplePaperStudentResult">
        select a.*,b.id as student_id,b.phone as student_phone,b.name as student_name,c.name as paper_name from ex_paper_student a
        left join ex_student b on a.student_id=b.id
        left join ex_exam_paper c on c.id=a.paper_id
        where a.id=#{paperStudentId}
    </select>
 
    <select id="selectByPaperStudentId" resultType="com.gkhy.exam.system.domain.ExPaperStudent">
        select a.*,b.id as student_id,b.phone as student_phone,b.name as student_name from ex_paper_student a
        left join ex_student b on a.student_id=b.id
        left join ex_exam_paper c on c.id=a.paper_id
        where a.paper_id=#{paperId} and a.student_id=#{studentId}
    </select>
 
    <select id="getQuestionByPaperId" resultMap="ExQuestionResult">
        select a.id,a.question_type,a.bank_id,a.company_id,a.status,
               <if test="state!=null and state!=0">
               a.answer,c.passed as answer_passed,c.score as answer_score,
               </if>
               a.title,a.privatize,a.content,
               c.id as answer_id,c.paper_id as answer_paper_id,c.student_id as answer_student_id,c.question_id as answer_question_id,c.answer as answer_answer
 
        from ex_question a
        inner join ex_paper_question b on a.id=b.question_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 desc
    </select>
 
    <select id="selectByStudentId" resultMap="SimplePaperStudentResult">
        select a.*,b.name as paper_name,c.id as company_id,c.name as company_name from ex_paper_student a
        left join ex_exam_paper b on b.id=a.paper_id
        left join sys_company c on c.id=b.company_id
    </select>
 
    <select id="selectNoCompleteStudent" resultMap="SimplePaperStudentResult">
        select a.*, b.name as paper_name,b.limited,b.limit_time,b.deadline,b.single_num,b.multi_num,b.judge_num,b.easy_num
        from ex_paper_student a
        inner join ex_exam_paper b on b.id=a.paper_id
        where a.state=0 limit #{startIndex},#{pageSize}
    </select>
</mapper>