kongzy
2024-07-05 14821e28286d773ad5ff2c13510e39c5eb117daf
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
<?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="completed"     column="completed"     />
        <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="singleQuestions" ofType="com.gkhy.exam.system.domain.ExQuestion" select="getQuestionByPaperId" column="{paperId=paper_id,studentId=student_id,completed=completed,questionType=1}"/>
        <collection property="multiQuestions" ofType="com.gkhy.exam.system.domain.ExQuestion" select="getQuestionByPaperId" column="{paperId=paper_id,studentId=student_id,completed=completed,questionType=2}"/>
        <collection property="judgeQuestions" ofType="com.gkhy.exam.system.domain.ExQuestion" select="getQuestionByPaperId" column="{paperId=paper_id,studentId=student_id,completed=completed,questionType=3}"/>
    </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="completed"     column="completed"     />
        <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" />
    </resultMap>
 
    <resultMap type="com.gkhy.exam.system.domain.ExQuestion" id="ExQuestionResult">
        <result property="id"       column="id"       />
        <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"       />
    </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"       />
    </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) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.paperId},#{item.studentId})
        </foreach>
    </insert>
 
    <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.id as paper_id,c.code as paper_code,d.name as category_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
        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>
        </where>
        order by 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 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" resultType="com.gkhy.exam.system.domain.ExQuestion">
        select a.id,a.question_type,a.bank_id,a.company_id,a.status,
               <if test="completed!=null and completed=1">
               a.answer,
               </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,
                <if test="completed!=null and completed=1">
               c.passed as answer_passed
                </if>
        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} and a.question_type=#{questionType}
    </select>
</mapper>