fuliqi
2024-10-17 8546b3d285af4235a0ef615a0c6e89486ae2c806
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
<?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.ycl.jxkg.mapper.ExamMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ycl.jxkg.domain.vo.ExamVO">
        <result column="exam_name" property="examName" />
        <result column="exam_paper_id" property="examPaperId" />
        <result column="classes_id" property="classesId" />
        <result column="exam_paper_type" property="examPaperType" />
        <result column="exam_place" property="examPlace" />
        <result column="status" property="status" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="create_time" property="createTime" />
        <result column="teacher_id" property="teacherId" />
        <result column="class_name" property="className" />
        <result column="name" property="examPaperName" />
        <result column="isContinue" property="isContinue" />
        <result column="submitStatus" property="submitStatus" />
    </resultMap>
 
    <select id="getById" resultMap="BaseResultMap">
        SELECT
            TE.exam_name,
            TE.exam_paper_id,
            TE.classes_id,
            TE.exam_paper_type,
            TE.exam_place,
            TE.status,
            TE.start_time,
            TE.end_time,
            TE.create_time,
            TE.teacher_id,
            TE.id
        FROM
            t_exam TE
        WHERE
            TE.id = #{id} AND TE.deleted = 0
    </select>
 
 
    <select id="getPage" resultMap="BaseResultMap">
        SELECT
            TE.exam_name,
            TE.exam_paper_id,
            TE.classes_id,
            TE.exam_paper_type,
            TE.exam_place,
            TE.status,
            TE.start_time,
            TE.end_time,
            TE.create_time,
            TE.teacher_id,
            TE.id,
            TC.class_name,
            TEP.name
        FROM
            t_exam TE
                INNER JOIN t_user TU ON TU.id = TE.teacher_id AND TU.deleted = 0 AND TU.id = #{userId}
                LEFT JOIN t_classes TC ON TC.id = TE.classes_id AND TC.deleted = 0
                LEFT JOIN t_exam_paper TEP ON TEP.id = TE.exam_paper_id AND TEP.deleted = 0
        WHERE
            TE.deleted = 0
            <if test="query.examName != null and query.examName != ''">
                AND TE.exam_name like concat('%', #{query.examName}, '%')
            </if>
            <if test="query.classesId != null">
                AND TE.classes_id = #{query.classesId}
            </if>
        ORDER BY
            TE.create_time DESC
    </select>
 
 
    <select id="studentPage" resultMap="BaseResultMap">
        SELECT
            TE.exam_name,
            TE.exam_paper_id,
            TE.classes_id,
            TE.exam_paper_type,
            TE.exam_place,
            TE.status,
            IF(TE.status != 'not_start', IF(TE.status = 'ing', 2, 1), 0) as orderc,
            TE.start_time,
            TE.end_time,
            TE.create_time,
            TE.teacher_id,
            TE.id,
            TC.class_name,
            TEP.name,
            TEST.status as submitStatus,
            (SELECT IF(COUNT(*) > 0, true, false) FROM t_exam_submit_temp WHERE user_id = #{userId} AND status = 'temp') as isContinue
        FROM
            t_exam TE
        INNER JOIN t_classes TC ON TC.id = TE.classes_id AND TC.deleted = 0 AND TC.status = 'normal'
        INNER JOIN t_classes_user TCU ON TC.id = TCU.classes_id  And TCU.deleted = 0 AND TC.deleted = 0 AND TCU.user_id = #{userId}
        INNER JOIN t_exam_paper TEP ON TEP.id = TE.exam_paper_id AND TEP.deleted = 0
        LEFT JOIN t_exam_submit_temp TEST ON TEST.exam_id = TE.id
        WHERE
            TE.deleted = 0 and (TEST.deleted =0 or TEST.deleted is null)
            <if test="query.examName != null and query.examName != ''">
                AND TE.exam_name like concat('%', #{query.examName}, '%')
            </if>
            <if test="query.status != null and query.status != ''">
                AND TE.status = #{query.status}
            </if>
        ORDER BY FIELD(TE.status, 'ing', 'not_start', 'finished'), orderc, TE.create_time DESC
    </select>
 
</mapper>