WorkReportMapper.xml 4.23 KB
<?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.trash.report.mapper.WorkReportMapper">
    
    <resultMap type="WorkReport" id="WorkReportResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="writer"    column="writer"    />
        <result property="writeTime"    column="write_time"    />
        <result property="reportContent"    column="report_content"    />
        <result property="type"    column="type"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="attachmentLink"    column="attachment_link"    />
        
    </resultMap>

    <sql id="selectWorkReportVo">
        select id, title, writer, write_time, report_content,type,start_time,end_time,create_by,create_time,attachment_link from work_report
    </sql>

    <select id="selectWorkReportList" parameterType="WorkReport" resultMap="WorkReportResult">
        <include refid="selectWorkReportVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
        </where>
    </select>
    
    <select id="selectWorkReportById" parameterType="Long" resultMap="WorkReportResult">
        <include refid="selectWorkReportVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWorkReport" parameterType="WorkReport" useGeneratedKeys="true" keyProperty="id">
        insert into work_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="writer != null and writer != ''">writer,</if>
            <if test="writeTime != null">write_time,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="reportContent != null ">report_content,</if>
            <if test="createBy != ''">create_by,</if>
            <if test="attachmentLink!= null">attachment_link,</if>
            create_time,
            type,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="writer != null and writer != ''">#{writer},</if>
            <if test="writeTime != null">#{writeTime},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="reportContent != null ">#{reportContent},</if>
            <if test="createBy != ''">#{createBy},</if>
            <if test="attachmentLink!= null ">#{attachmentLink},</if>
            NOW(),
            #{type}
         </trim>
    </insert>

    <update id="updateWorkReport" parameterType="WorkReport">
        update work_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="writer != null and writer != ''">writer = #{writer},</if>
            <if test="writeTime != null">write_time = #{writeTime},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="reportContent != null ">report_content = #{reportContent},</if>
            <if test="attachmentLink!= null ">attachment_link = #{attachmentLink},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWorkReportById" parameterType="Long">
        delete from work_report where id = #{id}
    </delete>

    <delete id="deleteWorkReportByIds" parameterType="String">
        delete from work_report where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>