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

    <resultMap type="DmsBaseDeviceDebugging" id="DmsBaseDeviceDebuggingResult">
        <result property="deviceDebuggingId"    column="device_debugging_id"    />
        <result property="workOrder"    column="work_order"    />
        <result property="deviceId"    column="device_id"    />
        <result property="status"    column="status"    />
        <result property="debugTime"    column="debug_time"    />
        <result property="remark"    column="remark"    />
        <result property="debugPerson"    column="debug_person"    />
        <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="selectDmsBaseDeviceDebuggingVo">
        select device_debugging_id, work_order, device_id, status, debug_time, remark, debug_person, create_time, create_by, update_time, update_by from dms_base_device_debugging
    </sql>

    <select id="selectDmsBaseDeviceDebuggingList" parameterType="DmsBaseDeviceDebugging" resultMap="DmsBaseDeviceDebuggingResult">
        select a.device_debugging_id, a.work_order, a.device_id, a.status, a.debug_time, a.remark, a.debug_person, a.create_time, a.create_by, a.update_time, a.update_by
        from dms_base_device_debugging a
        left join dms_base_device_ledger b on a.device_id = b.device_id
        <where>
            <if test="workOrder != null  and workOrder != ''"> and a.work_order like concat( '%',#{workOrder} ,'%')</if>
            <if test="deviceId != null "> and a.device_id = #{deviceId}</if>
            <if test="status != null "> and a.status = #{status}</if>
            <if test="params.beginTime != null and params.endTime != null">and a.debug_time between #{params.beginTime} and #{params.endTime} </if>
            <if test="debugPerson != null  and debugPerson != ''"> and a.debug_person = #{debugPerson}</if>
            <if test="deviceName != null  and deviceName != ''"> and b.device_name like concat('%', #{deviceName},'%')</if>
        </where>
    </select>

    <select id="selectDmsBaseDeviceDebuggingByDeviceDebuggingId" parameterType="Long" resultMap="DmsBaseDeviceDebuggingResult">
        <include refid="selectDmsBaseDeviceDebuggingVo"/>
        where device_debugging_id = #{deviceDebuggingId}
    </select>

    <insert id="insertDmsBaseDeviceDebugging" parameterType="DmsBaseDeviceDebugging" useGeneratedKeys="true" keyProperty="deviceDebuggingId">
        insert into dms_base_device_debugging
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workOrder != null">work_order,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="status != null">status,</if>
            <if test="debugTime != null">debug_time,</if>
            <if test="remark != null">remark,</if>
            <if test="debugPerson != null">debug_person,</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="workOrder != null">#{workOrder},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="status != null">#{status},</if>
            <if test="debugTime != null">#{debugTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="debugPerson != null">#{debugPerson},</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="updateDmsBaseDeviceDebugging" parameterType="DmsBaseDeviceDebugging">
        update dms_base_device_debugging
        <trim prefix="SET" suffixOverrides=",">
            <if test="workOrder != null">work_order = #{workOrder},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="debugTime != null">debug_time = #{debugTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="debugPerson != null">debug_person = #{debugPerson},</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_debugging_id = #{deviceDebuggingId}
    </update>

    <delete id="deleteDmsBaseDeviceDebuggingByDeviceDebuggingId" parameterType="Long">
        delete from dms_base_device_debugging where device_debugging_id = #{deviceDebuggingId}
    </delete>

    <delete id="deleteDmsBaseDeviceDebuggingByDeviceDebuggingIds" parameterType="String">
        delete from dms_base_device_debugging where device_debugging_id in
        <foreach item="deviceDebuggingId" collection="array" open="(" separator="," close=")">
            #{deviceDebuggingId}
        </foreach>
    </delete>
</mapper>
