<?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.hw.dms.mapper.DmsInspectInstanceDetailMapper">

    <resultMap type="DmsInspectInstanceDetail" id="DmsInspectInstanceDetailResult">
        <result property="instanceDetailId"    column="instance_detail_id"    />
        <result property="inspectInstanceId"    column="inspect_instance_id"    />
        <result property="lineStep"    column="line_step"    />
        <result property="realLineStep"    column="real_line_step"    />
        <result property="deviceId"    column="device_id"    />
        <result property="instanceDetailStatus"    column="instance_detail_status"    />
        <result property="inspectStandard"    column="inspect_standard"    />
        <result property="inspectDesc"    column="inspect_desc"    />
        <result property="inspectStatus"    column="inspect_status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
    </resultMap>

    <sql id="selectDmsInspectInstanceDetailVo">
        select instance_detail_id, inspect_instance_id, line_step, real_line_step, device_id, instance_detail_status, inspect_standard, inspect_desc, inspect_value, inspect_status, create_by, create_time, update_by, update_time from dms_inspect_instance_detail
    </sql>

    <select id="selectDmsInspectInstanceDetailList" parameterType="DmsInspectInstanceDetail" resultMap="DmsInspectInstanceDetailResult">
        <include refid="selectDmsInspectInstanceDetailVo"/>
        <where>
            <if test="inspectInstanceId != null "> and inspect_instance_id = #{inspectInstanceId}</if>
            <if test="lineStep != null "> and line_step = #{lineStep}</if>
            <if test="realLineStep != null "> and real_line_step = #{realLineStep}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="instanceDetailStatus != null  and instanceDetailStatus != ''"> and instance_detail_status = #{instanceDetailStatus}</if>
            <if test="inspectStandard != null  and inspectStandard != ''"> and inspect_standard = #{inspectStandard}</if>
            <if test="inspectDesc != null  and inspectDesc != ''"> and inspect_desc = #{inspectDesc}</if>
            <if test="inspectStatus != null  and inspectStatus != ''"> and inspect_status = #{inspectStatus}</if>
        </where>
    </select>

    <select id="selectDmsInspectInstanceDetailByInstanceDetailId" parameterType="Long" resultMap="DmsInspectInstanceDetailResult">
        <include refid="selectDmsInspectInstanceDetailVo"/>
        where instance_detail_id = #{instanceDetailId}
    </select>

    <insert id="insertDmsInspectInstanceDetail" parameterType="DmsInspectInstanceDetail" useGeneratedKeys="true" keyProperty="instanceDetailId">
        insert into dms_inspect_instance_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inspectInstanceId != null">inspect_instance_id,</if>
            <if test="lineStep != null">line_step,</if>
            <if test="realLineStep != null">real_line_step,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="instanceDetailStatus != null">instance_detail_status,</if>
            <if test="inspectStandard != null">inspect_standard,</if>
            <if test="inspectDesc != null">inspect_desc,</if>
            <if test="inspectStatus != null">inspect_status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inspectInstanceId != null">#{inspectInstanceId},</if>
            <if test="lineStep != null">#{lineStep},</if>
            <if test="realLineStep != null">#{realLineStep},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="instanceDetailStatus != null">#{instanceDetailStatus},</if>
            <if test="inspectStandard != null">#{inspectStandard},</if>
            <if test="inspectDesc != null">#{inspectDesc},</if>
            <if test="inspectStatus != null">#{inspectStatus},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDmsInspectInstanceDetail" parameterType="DmsInspectInstanceDetail">
        update dms_inspect_instance_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="inspectInstanceId != null">inspect_instance_id = #{inspectInstanceId},</if>
            <if test="lineStep != null">line_step = #{lineStep},</if>
            <if test="realLineStep != null">real_line_step = #{realLineStep},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="instanceDetailStatus != null">instance_detail_status = #{instanceDetailStatus},</if>
            <if test="inspectStandard != null">inspect_standard = #{inspectStandard},</if>
            <if test="inspectDesc != null">inspect_desc = #{inspectDesc},</if>
            <if test="inspectStatus != null">inspect_status = #{inspectStatus},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where instance_detail_id = #{instanceDetailId}
    </update>

    <delete id="deleteDmsInspectInstanceDetailByInstanceDetailId" parameterType="Long">
        delete from dms_inspect_instance_detail where instance_detail_id = #{instanceDetailId}
    </delete>

    <delete id="deleteDmsInspectInstanceDetailByInstanceDetailIds" parameterType="String">
        delete from dms_inspect_instance_detail where instance_detail_id in
        <foreach item="instanceDetailId" collection="array" open="(" separator="," close=")">
            #{instanceDetailId}
        </foreach>
    </delete>







    <sql id="selectDmsInspectInstanceDetailJoinVo">
        select diid.instance_detail_id, diid.inspect_instance_id, diid.line_step, diid.real_line_step, diid.device_id, diid.instance_detail_status,
               diid.inspect_standard, diid.inspect_desc, diid.inspect_status,dbdl.device_code,dbdl.device_name
               from dms_inspect_instance_detail diid left join dms_base_device_ledger dbdl on diid.device_id=dbdl.device_id
    </sql>

    <select id="selectDmsInspectInstanceDetailJoinList" parameterType="DmsInspectInstanceDetail" resultMap="DmsInspectInstanceDetailResult">
        <include refid="selectDmsInspectInstanceDetailJoinVo"/>
        <where>
            <if test="deviceCode != null  and deviceCode != ''"> and dbdl.device_code = #{deviceCode}</if>
            <if test="inspectInstanceId != null "> and diid.inspect_instance_id = #{inspectInstanceId}</if>
            <if test="lineStep != null "> and diid.line_step = #{lineStep}</if>
            <if test="realLineStep != null "> and diid.real_line_step = #{realLineStep}</if>
            <if test="deviceId != null "> and diid.device_id = #{deviceId}</if>
            <if test="instanceDetailStatus != null  and instanceDetailStatus != ''"> and diid.instance_detail_status = #{instanceDetailStatus}</if>
            <if test="inspectStandard != null  and inspectStandard != ''"> and diid.inspect_standard = #{inspectStandard}</if>
            <if test="inspectStatus != null  and inspectStatus != ''"> and diid.inspect_status = #{inspectStatus}</if>
        </where>
    </select>

    <select id="selectDmsInspectInstanceDetailByUI" resultMap="DmsInspectInstanceDetailResult">
        <include refid="selectDmsInspectInstanceDetailJoinVo"/>
        where diid.inspect_instance_id = #{inspectInstanceId} and dbdl.device_code = #{deviceCode}
        limit 1
    </select>
</mapper>
