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

    <resultMap type="DmsBaseTransferInfo" id="DmsBaseTransferInfoResult">
        <result property="transferInfoId"    column="transfer_info_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="devicePosition"    column="device_position"    />
        <result property="devicePositionNew"    column="device_position_new"    />
        <result property="devicePositionOperator"    column="device_position_operator"    />
        <result property="devicePositionReason"    column="device_position_reason"    />
        <result property="deviceTransferTime"    column="device_transfer_time"    />
        <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="selectDmsBaseTransferInfoVo">
        select transfer_info_id, device_id, device_position, device_position_new, device_position_operator, device_position_reason, device_transfer_time, remark, create_time, create_by, update_time, update_by from dms_base_transfer_info
    </sql>

    <select id="selectDmsBaseTransferInfoList" parameterType="DmsBaseTransferInfo" resultMap="DmsBaseTransferInfoResult">
        select a.transfer_info_id, a.device_id, a.device_position, a.device_position_new, a.device_position_operator, a.device_position_reason, a.device_transfer_time, a.remark, a.create_time, a.create_by, a.update_time, a.update_by
        from dms_base_transfer_info 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="devicePosition != null  and devicePosition != ''"> and a.device_position like concat('%',#{devicePosition},'%') </if>
            <if test="devicePositionNew != null  and devicePositionNew != ''"> and a.device_position_new like concat('%',#{devicePositionNew},'%') </if>
            <if test="devicePositionOperator != null  and devicePositionOperator != ''"> and a.device_position_operator = #{devicePositionOperator}</if>
            <if test="devicePositionReason != null  and devicePositionReason != ''"> and a.device_position_reason = #{devicePositionReason}</if>
            <if test="params.beginTime != null and params.endTime !=null"> and a.device_transfer_time between #{params.beginTime} and #{params.endTime}</if>
            <if test="deviceName != null "> and b.device_name like concat('%', #{deviceName},'%')</if>
        </where>
    </select>

    <select id="selectDmsBaseTransferInfoByTransferInfoId" parameterType="Long" resultMap="DmsBaseTransferInfoResult">
        <include refid="selectDmsBaseTransferInfoVo"/>
        where transfer_info_id = #{transferInfoId}
    </select>

    <insert id="insertDmsBaseTransferInfo" parameterType="DmsBaseTransferInfo" useGeneratedKeys="true" keyProperty="transferInfoId">
        insert into dms_base_transfer_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="devicePosition != null">device_position,</if>
            <if test="devicePositionNew != null">device_position_new,</if>
            <if test="devicePositionOperator != null">device_position_operator,</if>
            <if test="devicePositionReason != null">device_position_reason,</if>
            <if test="deviceTransferTime != null">device_transfer_time,</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="devicePosition != null">#{devicePosition},</if>
            <if test="devicePositionNew != null">#{devicePositionNew},</if>
            <if test="devicePositionOperator != null">#{devicePositionOperator},</if>
            <if test="devicePositionReason != null">#{devicePositionReason},</if>
            <if test="deviceTransferTime != null">#{deviceTransferTime},</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="updateDmsBaseTransferInfo" parameterType="DmsBaseTransferInfo">
        update dms_base_transfer_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="devicePosition != null">device_position = #{devicePosition},</if>
            <if test="devicePositionNew != null">device_position_new = #{devicePositionNew},</if>
            <if test="devicePositionOperator != null">device_position_operator = #{devicePositionOperator},</if>
            <if test="devicePositionReason != null">device_position_reason = #{devicePositionReason},</if>
            <if test="deviceTransferTime != null">device_transfer_time = #{deviceTransferTime},</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 transfer_info_id = #{transferInfoId}
    </update>

    <delete id="deleteDmsBaseTransferInfoByTransferInfoId" parameterType="Long">
        delete from dms_base_transfer_info where transfer_info_id = #{transferInfoId}
    </delete>

    <delete id="deleteDmsBaseTransferInfoByTransferInfoIds" parameterType="String">
        delete from dms_base_transfer_info where transfer_info_id in
        <foreach item="transferInfoId" collection="array" open="(" separator="," close=")">
            #{transferInfoId}
        </foreach>
    </delete>
</mapper>
