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

    <resultMap type="DmsBaseDeviceInstall" id="DmsBaseDeviceInstallResult">
        <result property="deviceInstallId"    column="device_install_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="installPosition"    column="install_position"    />
        <result property="installTime"    column="install_time"    />
        <result property="installPersion"    column="install_persion"    />
        <result property="workOrder"    column="work_order"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectDmsBaseDeviceInstallVo">
        select device_install_id, device_id, install_position, install_time, install_persion, work_order, remark, create_time, create_by, update_time, update_by from dms_base_device_install
    </sql>

    <select id="selectDmsBaseDeviceInstallList" parameterType="DmsBaseDeviceInstall" resultMap="DmsBaseDeviceInstallResult">
        select a.device_install_id, a.device_id, a.install_position, a.install_time, a.install_persion, a.work_order, a.remark, a.create_time, a.create_by, a.update_time, a.update_by
        from dms_base_device_install a
        left join dms_base_device_ledger b on a.device_id = b.device_id
        <where>
            <if test="deviceId != null "> and a.device_id = #{deviceId}</if>
            <if test="installPosition != null  and installPosition != ''"> and a.install_position = #{installPosition}</if>
            <if test="installTime != null "> and a.install_time = #{installTime}</if>
            <if test="installPersion != null  and installPersion != ''"> and a.install_persion = #{installPersion}</if>
            <if test="workOrder != null  and workOrder != ''"> and a.work_order = #{workOrder}</if>
            <if test="deviceName != null  and deviceName != ''"> and b.device_name like concat('%', #{deviceName},'%')</if>
        </where>
    </select>

    <select id="selectDmsBaseDeviceInstallByDeviceInstallId" parameterType="Long" resultMap="DmsBaseDeviceInstallResult">
        <include refid="selectDmsBaseDeviceInstallVo"/>
        where device_install_id = #{deviceInstallId}
    </select>

    <insert id="insertDmsBaseDeviceInstall" parameterType="DmsBaseDeviceInstall" useGeneratedKeys="true" keyProperty="deviceInstallId">
        insert into dms_base_device_install
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="installPosition != null">install_position,</if>
            <if test="installTime != null">install_time,</if>
            <if test="installPersion != null">install_persion,</if>
            <if test="workOrder != null">work_order,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="installPosition != null">#{installPosition},</if>
            <if test="installTime != null">#{installTime},</if>
            <if test="installPersion != null">#{installPersion},</if>
            <if test="workOrder != null">#{workOrder},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateDmsBaseDeviceInstall" parameterType="DmsBaseDeviceInstall">
        update dms_base_device_install
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="installPosition != null">install_position = #{installPosition},</if>
            <if test="installTime != null">install_time = #{installTime},</if>
            <if test="installPersion != null">install_persion = #{installPersion},</if>
            <if test="workOrder != null">work_order = #{workOrder},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where device_install_id = #{deviceInstallId}
    </update>

    <delete id="deleteDmsBaseDeviceInstallByDeviceInstallId" parameterType="Long">
        delete from dms_base_device_install where device_install_id = #{deviceInstallId}
    </delete>

    <delete id="deleteDmsBaseDeviceInstallByDeviceInstallIds" parameterType="String">
        delete from dms_base_device_install where device_install_id in
        <foreach item="deviceInstallId" collection="array" open="(" separator="," close=")">
            #{deviceInstallId}
        </foreach>
    </delete>
</mapper>
