龚焕茏
2024-07-16 219cf838792ab0d50dd042d0fb8c60dd3a1e76f8
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
<?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.mindskip.xzs.repository.ExamTemplatesMapper">
    <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.ExamTemplates">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="paper_type" jdbcType="VARCHAR" property="paperType"/>
        <result column="suggest_time" jdbcType="VARCHAR" property="suggestTime"/>
        <result column="title_name" jdbcType="VARCHAR" property="titleName"/>
        <result column="ctime" jdbcType="TIMESTAMP" property="ctime"/>
        <result column="status" jdbcType="VARCHAR" property="status"/>
        <result column="menu_ids" jdbcType="VARCHAR" property="menuIds"/>
        <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
        <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
    </resultMap>
 
    <sql id="Base_Column_List">
        id
        , name, paper_type, suggest_time, title_name, ctime, status, menu_ids,start_time,end_time, dept_id
    </sql>
 
    <insert id="add" parameterType="com.mindskip.xzs.domain.ExamTemplates" useGeneratedKeys="true" keyProperty="id">
        insert into t_exam_templates (name, paper_type, dept_id, suggest_time, title_name, ctime, status, menu_ids,start_time,end_time,create_user)
        values (#{name}, #{paperType}, #{deptId}, #{suggestTime}, #{titleName}, #{ctime}, #{status}, #{menuIds},#{startTime},#{endTime}, #{createUser})
    </insert>
 
    <select id="getTime" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_exam_templates where status is null
        order by ctime desc
        limit 1
    </select>
 
    <select id="gets" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.domain.vo.ExamTemplatesVO">
        select
        DISTINCT  e.id
        , e.name, e.paper_type, e.suggest_time, e.title_name, e.ctime, e.status, e.menu_ids,e.start_time,e.end_time,e.ctime
        from t_exam_templates e
        inner join t_exam_templates_user u on e.id = u.templates_id
        <where>
            <if test="status != null">
                and e.status = 0
            </if>
            <if test="status == null">
                and e.status is null
            </if>
            <if test="userId != null">
                and u.user_id = #{userId}
            </if>
            <if test="now !=null">
                and #{now} between e.start_time and e.end_time
            </if>
        </where>
    </select>
 
    <select id="getByadmins" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.domain.vo.ExamTemplatesVO">
        select
        DISTINCT  e.id
        , e.name, e.paper_type, e.suggest_time, e.title_name, e.ctime, e.status, e.menu_ids,e.start_time,e.end_time, e.create_user
        from t_exam_templates e
        left join t_exam_templates_user u on e.id = u.templates_id
        LEFT JOIN t_exam_templates_subject ts ON e.id = ts.templates_id
        LEFT JOIN t_subject s ON ts.subject_id = s.id
        LEFT JOIN t_user_department tud ON e.create_user = tud.user_id
        <where>
            <if test="status != null">
                and e.status = 0
            </if>
            <if test="status == null">
                and e.status is null
            </if>
            <if test="userId != null">
                and u.user_id = #{userId}
            </if>
            <if test="deptId != null and deptId.size() > 0">
                and tud.department_id in <foreach collection="deptId" item="item" separator="," open="(" close=")"> #{item} </foreach>
            </if>
            <if test="name != null and name != ''">
                and INSTR(e.name, #{name})
            </if>
            <if test="subjectId != null and subjectId.length > 0">
                and s.id in <foreach collection="subjectId" item="item" separator="," open="(" close=")"> #{item} </foreach>
            </if>
            <if test="period != null and period.size() > 0">
                and e.ctime between #{period[0]} and #{period[1]}
            </if>
            <if test="now !=null">
                and #{now} between e.start_time and e.end_time
            </if>
        </where>
        GROUP BY e.id
    </select>
 
    <select id="getById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_exam_templates where id = #{id}
    </select>
 
    <select id="getByName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_exam_templates where name = #{name}/
    </select>
 
    <delete id="removeById" parameterType="java.lang.Integer">
        delete from t_exam_templates
        where id = #{id}
    </delete>
 
</mapper>