<?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.ktg.iscs.mapper.IsJobTicketLocksetMapper">

    <resultMap type="IsJobTicketLockset" id="IsJobTicketLocksetResult">
        <result property="recordId"    column="record_id"    />
        <result property="jobTicketId"    column="job_ticket_id"    />
        <result property="pointId"    column="point_id"    />
        <result property="locksetId"    column="lockset_id"    />
        <result property="fromHardwareId"    column="from_hardware_id"    />
        <result property="toHardwareId"    column="to_hardware_id"    />
        <result property="locksetStatus"    column="lockset_status"    />
        <result property="collectTime"    column="collect_time"    />
        <result property="giveBackTime"    column="give_back_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
        <result property="locksetTypeId"    column="lockset_type_id"    />
    </resultMap>

    <sql id="selectIsJobTicketLocksetVo">
        select * from is_job_ticket_lockset
    </sql>

    <select id="selectIsJobTicketLocksetList" parameterType="IsJobTicketLockset" resultMap="IsJobTicketLocksetResult">
        <include refid="selectIsJobTicketLocksetVo"/>
        <where>
            <if test="jobTicketId != null "> and job_ticket_id = #{jobTicketId}</if>
            <if test="pointId != null "> and point_id = #{pointId}</if>
            <if test="locksetId != null "> and lockset_id = #{locksetId}</if>
            <if test="fromHardwareId != null "> and from_hardware_id = #{fromHardwareId}</if>
            <if test="toHardwareId != null "> and to_hardware_id = #{toHardwareId}</if>
            <if test="locksetStatus != null  and locksetStatus != ''"> and lockset_status = #{locksetStatus}</if>
            <if test="collectTime != null "> and collect_time = #{collectTime}</if>
            <if test="giveBackTime != null "> and give_back_time = #{giveBackTime}</if>
        </where>
    </select>

    <select id="selectIsJobTicketLocksetByRecordId" parameterType="Long" resultMap="IsJobTicketLocksetResult">
        <include refid="selectIsJobTicketLocksetVo"/>
        where record_id = #{recordId}
    </select>

    <insert id="insertIsJobTicketLockset" parameterType="IsJobTicketLockset" useGeneratedKeys="true" keyProperty="recordId">
        insert into is_job_ticket_lockset
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="jobTicketId != null">job_ticket_id,</if>
            <if test="pointId != null">point_id,</if>
            <if test="locksetId != null">lockset_id,</if>
            <if test="fromHardwareId != null">from_hardware_id,</if>
            <if test="toHardwareId != null">to_hardware_id,</if>
            <if test="locksetStatus != null">lockset_status,</if>
            <if test="collectTime != null">collect_time,</if>
            <if test="giveBackTime != null">give_back_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
            <if test="locksetTypeId != null">lockset_type_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="jobTicketId != null">#{jobTicketId},</if>
            <if test="pointId != null">#{pointId},</if>
            <if test="locksetId != null">#{locksetId},</if>
            <if test="fromHardwareId != null">#{fromHardwareId},</if>
            <if test="toHardwareId != null">#{toHardwareId},</if>
            <if test="locksetStatus != null">#{locksetStatus},</if>
            <if test="collectTime != null">#{collectTime},</if>
            <if test="giveBackTime != null">#{giveBackTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="locksetTypeId != null">#{locksetTypeId},</if>
         </trim>
    </insert>

    <update id="updateIsJobTicketLockset" parameterType="IsJobTicketLockset">
        update is_job_ticket_lockset
        <trim prefix="SET" suffixOverrides=",">
            <if test="jobTicketId != null">job_ticket_id = #{jobTicketId},</if>
            <if test="pointId != null">point_id = #{pointId},</if>
            <if test="locksetId != null">lockset_id = #{locksetId},</if>
            <if test="fromHardwareId != null">from_hardware_id = #{fromHardwareId},</if>
            <if test="toHardwareId != null">to_hardware_id = #{toHardwareId},</if>
            <if test="locksetStatus != null">lockset_status = #{locksetStatus},</if>
            <if test="collectTime != null">collect_time = #{collectTime},</if>
            <if test="giveBackTime != null">give_back_time = #{giveBackTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="locksetTypeId != null">lockset_type_id = #{locksetTypeId},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteIsJobTicketLocksetByRecordId" parameterType="Long">
        delete from is_job_ticket_lockset where record_id = #{recordId}
    </delete>

    <delete id="deleteIsJobTicketLocksetByRecordIds" parameterType="String">
        delete from is_job_ticket_lockset where record_id in
        <foreach item="recordId" collection="array" open="(" separator="," close=")">
            #{recordId}
        </foreach>
    </delete>

    <select id="getListByTicketId" resultType="com.ktg.iscs.domain.vo.ticketLockset.IsJobTicketLocksetVO">
        SELECT
            j.*,
            l.lockset_name
        FROM
            is_job_ticket_lockset j
                LEFT JOIN is_lockset l ON j.lockset_id = l.lockset_id
        WHERE
            j.job_ticket_id = #{ticketId}
        ORDER BY
            j.record_id ASC
    </select>

</mapper>
