linzhijie
2021-03-11 c33914ba0a98c823c4b4d7da21cdd476906c9924
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
<?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.ots.project.exam.mapper.SysUserPaperMapper">
    
    <resultMap type="SysUserPaper" id="SysUserPaperResult">
        <result property="userId"    column="user_id"    />
        <result property="prodId"    column="prod_id"    />
        <result property="prodName"    column="prodName"    />
        <result property="reportTemplateId"    column="report_template_id"    />
    </resultMap>
 
    <sql id="selectSysUserPaperVo">
        SELECT t.user_id, t.prod_id, p.name prodName ,t.report_template_id FROM sys_user_paper t ,t_exam_paper p
    </sql>
 
    <select id="selectSysUserPaperList" parameterType="SysUserPaper" resultMap="SysUserPaperResult">
        <include refid="selectSysUserPaperVo"/>
        <where>
            t.prod_id = p.id AND p.deleted IN(0,1)
            <if test="userId != null  and userId != ''"> and t.user_id = #{userId}</if>
            <if test="prodId != null  and prodId != ''"> and t.prod_id = #{prodId}</if>
            <if test="prodName != null  and prodName != ''"> and p.prodName = #{prodName}</if>
        </where>
    </select>
    
    <select id="selectSysUserPaperById" parameterType="Long" resultMap="SysUserPaperResult">
        <include refid="selectSysUserPaperVo"/>
        where t.user_id = #{userId} and t.prod_id = p.id AND p.deleted IN(0,1)
    </select>
        
    <insert id="insertSysUserPaper" parameterType="SysUserPaper">
        insert into sys_user_paper
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null ">user_id,</if>
            <if test="prodId != null ">prod_id,</if>
            <if test="reportTemplateId != null ">report_template_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null ">#{userId},</if>
            <if test="prodId != null ">#{prodId},</if>
            <if test="reportTemplateId != null ">#{reportTemplateId},</if>
         </trim>
    </insert>
 
    <update id="updateSysUserPaper" parameterType="SysUserPaper">
        update sys_user_paper
        <trim prefix="SET" suffixOverrides=",">
            <if test="prodId != null ">prod_id = #{prodId},</if>
            <if test="reportTemplateId != null ">prod_id = #{reportTemplateId},</if>
        </trim>
        where user_id = #{userId}
    </update>
 
    <delete id="deleteSysUserPaperById" parameterType="Long">
        delete from sys_user_paper where user_id = #{userId}
    </delete>
 
    <delete id="deleteSysUserPaperByIds" parameterType="String">
        delete from sys_user_paper where user_id in 
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
    
</mapper>