<?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.ruoyi.change.mapper.TbAssetAllocationDetailMapper">
    
    <resultMap type="TbAssetAllocationDetail" id="TbAssetAllocationDetailResult">
        <result property="id"    column="id"    />
        <result property="allocationOrderNumber"    column="allocation_order_number"    />
        <result property="assetNumber"    column="asset_number"    />
        <result property="oldResponsiblePerson"    column="old_responsible_person"    />
        <result property="oldLocationNumber"    column="old_location_number"    />
        <result property="newResponsiblePerson"    column="new_responsible_person"    />
        <result property="newLocationNumber"    column="new_location_number"    />
    </resultMap>

    <sql id="selectTbAssetAllocationDetailVo">
        select id, allocation_order_number, asset_number, old_responsible_person, old_location_number, new_responsible_person, new_location_number from tb_asset_allocation_detail
    </sql>

    <select id="selectTbAssetAllocationDetailList" parameterType="TbAssetAllocationDetail" resultMap="TbAssetAllocationDetailResult">
        <include refid="selectTbAssetAllocationDetailVo"/>
        <where>  
            <if test="allocationOrderNumber != null  and allocationOrderNumber != ''"> and allocation_order_number = #{allocationOrderNumber}</if>
            <if test="assetNumber != null  and assetNumber != ''"> and asset_number = #{assetNumber}</if>
            <if test="oldResponsiblePerson != null  and oldResponsiblePerson != ''"> and old_responsible_person = #{oldResponsiblePerson}</if>
            <if test="oldLocationNumber != null  and oldLocationNumber != ''"> and old_location_number = #{oldLocationNumber}</if>
            <if test="newResponsiblePerson != null  and newResponsiblePerson != ''"> and new_responsible_person = #{newResponsiblePerson}</if>
            <if test="newLocationNumber != null  and newLocationNumber != ''"> and new_location_number = #{newLocationNumber}</if>
        </where>
    </select>
    
    <select id="selectTbAssetAllocationDetailById" parameterType="Long" resultMap="TbAssetAllocationDetailResult">
        <include refid="selectTbAssetAllocationDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbAssetAllocationDetail" parameterType="TbAssetAllocationDetail" useGeneratedKeys="true" keyProperty="id">
        insert into tb_asset_allocation_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="allocationOrderNumber != null and allocationOrderNumber != ''">allocation_order_number,</if>
            <if test="assetNumber != null and assetNumber != ''">asset_number,</if>
            <if test="oldResponsiblePerson != null">old_responsible_person,</if>
            <if test="oldLocationNumber != null">old_location_number,</if>
            <if test="newResponsiblePerson != null">new_responsible_person,</if>
            <if test="newLocationNumber != null">new_location_number,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="allocationOrderNumber != null and allocationOrderNumber != ''">#{allocationOrderNumber},</if>
            <if test="assetNumber != null and assetNumber != ''">#{assetNumber},</if>
            <if test="oldResponsiblePerson != null">#{oldResponsiblePerson},</if>
            <if test="oldLocationNumber != null">#{oldLocationNumber},</if>
            <if test="newResponsiblePerson != null">#{newResponsiblePerson},</if>
            <if test="newLocationNumber != null">#{newLocationNumber},</if>
         </trim>
    </insert>

    <update id="updateTbAssetAllocationDetail" parameterType="TbAssetAllocationDetail">
        update tb_asset_allocation_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="allocationOrderNumber != null and allocationOrderNumber != ''">allocation_order_number = #{allocationOrderNumber},</if>
            <if test="assetNumber != null and assetNumber != ''">asset_number = #{assetNumber},</if>
            <if test="oldResponsiblePerson != null">old_responsible_person = #{oldResponsiblePerson},</if>
            <if test="oldLocationNumber != null">old_location_number = #{oldLocationNumber},</if>
            <if test="newResponsiblePerson != null">new_responsible_person = #{newResponsiblePerson},</if>
            <if test="newLocationNumber != null">new_location_number = #{newLocationNumber},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbAssetAllocationDetailById" parameterType="Long">
        delete from tb_asset_allocation_detail where id = #{id}
    </delete>

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