<?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.TSpecialWorkPermitMapper">
    
    <resultMap type="TSpecialWorkPermit" id="TSpecialWorkPermitResult">
        <result property="specialWorkPermitId"    column="special_work_permit_id"    />
        <result property="workPermitId"    column="work_permit_id"    />
        <result property="licenceNum"    column="licence_num"    />
        <result property="specialWorkType"    column="special_work_type"    />
        <result property="specialWorkData"    column="special_work_data"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTSpecialWorkPermitVo">
        select special_work_permit_id, work_permit_id, licence_num, special_work_type, special_work_data, is_del, create_time, update_time, remarks from t_special_work_permit
    </sql>

    <select id="selectTSpecialWorkPermitList" parameterType="TSpecialWorkPermit" resultMap="TSpecialWorkPermitResult">
        <include refid="selectTSpecialWorkPermitVo"/>
        <where>  
            <if test="workPermitId != null "> and work_permit_id = #{workPermitId}</if>
            <if test="licenceNum != null  and licenceNum != ''"> and licence_num = #{licenceNum}</if>
            <if test="specialWorkType != null  and specialWorkType != ''"> and special_work_type = #{specialWorkType}</if>
            <if test="specialWorkData != null  and specialWorkData != ''"> and special_work_data = #{specialWorkData}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            AND is_del = '0'
        </where>
    </select>
    
    <select id="selectTSpecialWorkPermitById" parameterType="Long" resultMap="TSpecialWorkPermitResult">
        <include refid="selectTSpecialWorkPermitVo"/>
        where special_work_permit_id = #{specialWorkPermitId}
    </select>
        
    <insert id="insertTSpecialWorkPermit" parameterType="TSpecialWorkPermit" useGeneratedKeys="true" keyProperty="specialWorkPermitId">
        insert into t_special_work_permit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workPermitId != null">work_permit_id,</if>
            <if test="licenceNum != null">licence_num,</if>
            <if test="specialWorkType != null">special_work_type,</if>
            <if test="specialWorkData != null">special_work_data,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workPermitId != null">#{workPermitId},</if>
            <if test="licenceNum != null">#{licenceNum},</if>
            <if test="specialWorkType != null">#{specialWorkType},</if>
            <if test="specialWorkData != null">#{specialWorkData},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTSpecialWorkPermit" parameterType="TSpecialWorkPermit">
        update t_special_work_permit
        <trim prefix="SET" suffixOverrides=",">
            <if test="workPermitId != null">work_permit_id = #{workPermitId},</if>
            <if test="licenceNum != null">licence_num = #{licenceNum},</if>
            <if test="specialWorkType != null">special_work_type = #{specialWorkType},</if>
            <if test="specialWorkData != null">special_work_data = #{specialWorkData},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where special_work_permit_id = #{specialWorkPermitId}
    </update>

    <delete id="deleteTSpecialWorkPermitById" parameterType="Long">
        delete from t_special_work_permit where special_work_permit_id = #{specialWorkPermitId}
    </delete>

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