<?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.TSpecialWorkPermitSignMapper">
    
    <resultMap type="TSpecialWorkPermitSign" id="TSpecialWorkPermitSignResult">
        <result property="signId"    column="sign_id"    />
        <result property="permitId"    column="permit_id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="staffType"    column="staff_type"    />
        <result property="signName"    column="sign_name"    />
        <result property="opinion"    column="opinion"    />
        <result property="signDate"    column="sign_date"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTSpecialWorkPermitSignVo">
        select sign_id, permit_id, staff_id, staff_type, sign_name, opinion, sign_date, create_time from t_special_work_permit_sign
    </sql>

    <select id="selectTSpecialWorkPermitSignList" parameterType="TSpecialWorkPermitSign" resultMap="TSpecialWorkPermitSignResult">
        <include refid="selectTSpecialWorkPermitSignVo"/>
        <where>  
            <if test="permitId != null "> and permit_id = #{permitId}</if>
            <if test="staffId != null "> and staff_id = #{staffId}</if>
            <if test="staffType != null  and staffType != ''"> and staff_type = #{staffType}</if>
            <if test="signName != null  and signName != ''"> and sign_name like concat('%', #{signName}, '%')</if>
            <if test="opinion != null  and opinion != ''"> and opinion = #{opinion}</if>
            <if test="signDate != null  and signDate != ''"> and sign_date = #{signDate}</if>
        </where>
    </select>
    
    <select id="selectTSpecialWorkPermitSignById" parameterType="Long" resultMap="TSpecialWorkPermitSignResult">
        <include refid="selectTSpecialWorkPermitSignVo"/>
        where sign_id = #{signId}
    </select>
        
    <insert id="insertTSpecialWorkPermitSign" parameterType="TSpecialWorkPermitSign">
        insert into t_special_work_permit_sign
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="signId != null">sign_id,</if>
            <if test="permitId != null">permit_id,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="staffType != null">staff_type,</if>
            <if test="signName != null">sign_name,</if>
            <if test="opinion != null">opinion,</if>
            <if test="signDate != null">sign_date,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="signId != null">#{signId},</if>
            <if test="permitId != null">#{permitId},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="staffType != null">#{staffType},</if>
            <if test="signName != null">#{signName},</if>
            <if test="opinion != null">#{opinion},</if>
            <if test="signDate != null">#{signDate},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTSpecialWorkPermitSign" parameterType="TSpecialWorkPermitSign">
        update t_special_work_permit_sign
        <trim prefix="SET" suffixOverrides=",">
            <if test="permitId != null">permit_id = #{permitId},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="staffType != null">staff_type = #{staffType},</if>
            <if test="signName != null">sign_name = #{signName},</if>
            <if test="opinion != null">opinion = #{opinion},</if>
            <if test="signDate != null">sign_date = #{signDate},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where sign_id = #{signId}
    </update>

    <delete id="deleteTSpecialWorkPermitSignById" parameterType="Long">
        delete from t_special_work_permit_sign where sign_id = #{signId}
    </delete>

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