<?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.zehong.system.mapper.TWorkSupervisionMapper">
    
    <resultMap type="TWorkSupervision" id="TWorkSupervisionResult">
        <result property="supervisionId"    column="supervision_id"    />
        <result property="type"    column="type"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="status"    column="status"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
    </resultMap>

    <sql id="selectTWorkSupervisionVo">
        select supervision_id, type, title, content, status, image_url, file_url, create_time, create_by from t_work_supervision
    </sql>

    <select id="selectTWorkSupervisionList" parameterType="TWorkSupervision" resultMap="TWorkSupervisionResult">
        <include refid="selectTWorkSupervisionVo"/>
        <where>  
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectTWorkSupervisionById" parameterType="Long" resultMap="TWorkSupervisionResult">
        <include refid="selectTWorkSupervisionVo"/>
        where supervision_id = #{supervisionId}
    </select>
        
    <insert id="insertTWorkSupervision" parameterType="TWorkSupervision" useGeneratedKeys="true" keyProperty="supervisionId">
        insert into t_work_supervision
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null and type != ''">type,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="status != null">status,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null and type != ''">#{type},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="status != null">#{status},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
         </trim>
    </insert>

    <update id="updateTWorkSupervision" parameterType="TWorkSupervision">
        update t_work_supervision
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="status != null">status = #{status},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
        </trim>
        where supervision_id = #{supervisionId}
    </update>

    <delete id="deleteTWorkSupervisionById" parameterType="Long">
        delete from t_work_supervision where supervision_id = #{supervisionId}
    </delete>

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