<?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.DmsInspectRouteDetailMapper">

    <resultMap type="DmsInspectRouteDetail" id="DmsInspectRouteDetailResult">
        <result property="routeDetailId"    column="route_detail_id"    />
        <result property="inspectRouteId"    column="inspect_route_id"    />
        <result property="lineStep"    column="line_step"    />
        <result property="deviceId"    column="device_id"    />
        <result property="inspectStandard"    column="inspect_standard"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="remark"    />
        <result property="deviceName"    column="device_name"    />
        <result property="standardName"    column="standard_name"    />
    </resultMap>

    <sql id="selectDmsInspectRouteDetailVo">
        select route_detail_id, inspect_route_id, line_step, device_id, inspect_standard, is_flag, remark from dms_inspect_route_detail
    </sql>

    <select id="selectDmsInspectRouteDetailList" parameterType="DmsInspectRouteDetail" resultMap="DmsInspectRouteDetailResult">
        <include refid="selectDmsInspectRouteDetailVo"/>
        <where>
            <if test="inspectRouteId != null "> and inspect_route_id = #{inspectRouteId}</if>
            <if test="lineStep != null "> and line_step = #{lineStep}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="inspectStandard != null  and inspectStandard != ''"> and inspect_standard = #{inspectStandard}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsInspectRouteDetailByRouteDetailId" parameterType="Long" resultMap="DmsInspectRouteDetailResult">
        <include refid="selectDmsInspectRouteDetailVo"/>
        where route_detail_id = #{routeDetailId}
    </select>

    <insert id="insertDmsInspectRouteDetail" parameterType="DmsInspectRouteDetail" useGeneratedKeys="true" keyProperty="routeDetailId">
        insert into dms_inspect_route_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inspectRouteId != null">inspect_route_id,</if>
            <if test="lineStep != null">line_step,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="inspectStandard != null">inspect_standard,</if>
            <if test="isFlag != null and isFlag != ''">is_flag,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inspectRouteId != null">#{inspectRouteId},</if>
            <if test="lineStep != null">#{lineStep},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="inspectStandard != null">#{inspectStandard},</if>
            <if test="isFlag != null and isFlag != ''">#{isFlag},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateDmsInspectRouteDetail" parameterType="DmsInspectRouteDetail">
        update dms_inspect_route_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="inspectRouteId != null">inspect_route_id = #{inspectRouteId},</if>
            <if test="lineStep != null">line_step = #{lineStep},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="inspectStandard != null">inspect_standard = #{inspectStandard},</if>
            <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where route_detail_id = #{routeDetailId}
    </update>

    <delete id="deleteDmsInspectRouteDetailByRouteDetailId" parameterType="Long">
        delete from dms_inspect_route_detail where route_detail_id = #{routeDetailId}
    </delete>

    <delete id="deleteDmsInspectRouteDetailByRouteDetailIds" parameterType="String">
        delete from dms_inspect_route_detail where route_detail_id in
        <foreach item="routeDetailId" collection="array" open="(" separator="," close=")">
            #{routeDetailId}
        </foreach>
    </delete>

    <select id="selectInspectRouteListByInspectRouteId" parameterType="Long" resultMap="DmsInspectRouteDetailResult">
     select a.route_detail_id, a.inspect_route_id, a.line_step, a.device_id, a.inspect_standard,
     a.is_flag, a.remark,b.device_name,c.standard_name
     from dms_inspect_route_detail a
     left join dms_base_device_ledger b on a.device_id = b.device_id
     left join dms_base_inspect_standard c on a.inspect_standard = c.inspect_standard_id
    where a.inspect_route_id = #{inspectRouteId}
    </select>
</mapper>
