<?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.aucma.dms.mapper.DmsInspectProjectDeviceMapper">
    
    <resultMap type="DmsInspectProjectDevice" id="DmsInspectProjectDeviceResult">
        <result property="inspectProjectId"    column="inspect_project_id"    />
        <result property="targetType"    column="target_type"    />
        <result property="targetId"    column="target_id"    />
    </resultMap>

    <sql id="selectDmsInspectProjectDeviceVo">
        select inspect_project_id, target_type, target_id from dms_inspect_project_device
    </sql>

    <select id="selectDmsInspectProjectDeviceList" parameterType="DmsInspectProjectDevice" resultMap="DmsInspectProjectDeviceResult">
        <include refid="selectDmsInspectProjectDeviceVo"/>
        <where>
            <if test="targetId != null "> and target_id = #{targetId}</if>
            <if test="targetType != null  and targetType != ''"> and target_type = #{targetType}</if>
        </where>
    </select>
    
    <select id="selectDmsInspectProjectDeviceByInspectProjectId" parameterType="Long" resultMap="DmsInspectProjectDeviceResult">
        <include refid="selectDmsInspectProjectDeviceVo"/>
        where inspect_project_id = #{inspectProjectId}
    </select>
        
    <insert id="insertDmsInspectProjectDevice" parameterType="DmsInspectProjectDevice">
        insert into dms_inspect_project_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inspectProjectId != null">inspect_project_id,</if>
            <if test="targetType != null">target_type,</if>
            <if test="targetId != null">target_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inspectProjectId != null">#{inspectProjectId},</if>
            <if test="targetType != null">#{targetType},</if>
            <if test="targetId != null">#{targetId},</if>
         </trim>
    </insert>

    <update id="updateDmsInspectProjectDevice" parameterType="DmsInspectProjectDevice">
        update dms_inspect_project_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="targetType != null">target_type = #{targetType},</if>
            <if test="targetId != null">target_id = #{targetId},</if>
        </trim>
        where inspect_project_id = #{inspectProjectId}
    </update>

    <delete id="deleteDmsInspectProjectDeviceByInspectProjectId" parameterType="Long">
        delete from dms_inspect_project_device where inspect_project_id = #{inspectProjectId}
    </delete>

    <delete id="deleteDmsInspectProjectDeviceByInspectProjectIds" parameterType="String">
        delete from dms_inspect_project_device where inspect_project_id in 
        <foreach item="inspectProjectId" collection="array" open="(" separator="," close=")">
            #{inspectProjectId}
        </foreach>
    </delete>
</mapper>