<?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.TbAssetAllocationMapper">
    
    <resultMap type="TbAssetAllocation" id="TbAssetAllocationResult">
        <result property="id"    column="id"    />
        <result property="orderNumber"    column="order_number"    />
        <result property="callOutDepartment"    column="call_out_department"    />
        <result property="callOutBy"    column="call_out_by"    />
        <result property="callOutDate"    column="call_out_date"    />
        <result property="callInDepartment"    column="call_in_department"    />
        <result property="callInBy"    column="call_in_by"    />
        <result property="callInDate"    column="call_in_date"    />
        <result property="assetTotalOriginalValue"    column="asset_total_original_value"    />
        <result property="assetTotalNetValue"    column="asset_total_net_value"    />
        <result property="reason"    column="reason"    />
        <result property="preparedBy"    column="prepared_by"    />
        <result property="preparedDepartment"    column="prepared_department"    />
        <result property="corporation"    column="corporation"    />
        <result property="recordStatus"    column="record_status"    />
    </resultMap>

    <sql id="selectTbAssetAllocationVo">
        select id, order_number, call_out_department, call_out_by, call_out_date, call_in_department, call_in_by, call_in_date, asset_total_original_value, asset_total_net_value, reason, prepared_by, prepared_department, corporation, record_status from tb_asset_allocation
    </sql>

    <select id="selectTbAssetAllocationList" parameterType="TbAssetAllocation" resultMap="TbAssetAllocationResult">
        <include refid="selectTbAssetAllocationVo"/>
        <where>  
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="callOutDepartment != null  and callOutDepartment != ''"> and call_out_department = #{callOutDepartment}</if>
            <if test="callOutBy != null  and callOutBy != ''"> and call_out_by = #{callOutBy}</if>
            <if test="callOutDate != null "> and call_out_date = #{callOutDate}</if>
            <if test="callInDepartment != null  and callInDepartment != ''"> and call_in_department = #{callInDepartment}</if>
            <if test="callInBy != null  and callInBy != ''"> and call_in_by = #{callInBy}</if>
            <if test="callInDate != null "> and call_in_date = #{callInDate}</if>
            <if test="preparedBy != null  and preparedBy != ''"> and prepared_by = #{preparedBy}</if>
            <if test="preparedDepartment != null  and preparedDepartment != ''"> and prepared_department = #{preparedDepartment}</if>
            <if test="corporation != null  and corporation != ''"> and corporation = #{corporation}</if>
            <if test="recordStatus != null "> and record_status = #{recordStatus}</if>
        </where>
    </select>
    
    <select id="selectTbAssetAllocationById" parameterType="Long" resultMap="TbAssetAllocationResult">
        <include refid="selectTbAssetAllocationVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbAssetAllocation" parameterType="TbAssetAllocation" useGeneratedKeys="true" keyProperty="id">
        insert into tb_asset_allocation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number,</if>
            <if test="callOutDepartment != null">call_out_department,</if>
            <if test="callOutBy != null">call_out_by,</if>
            <if test="callOutDate != null">call_out_date,</if>
            <if test="callInDepartment != null">call_in_department,</if>
            <if test="callInBy != null">call_in_by,</if>
            <if test="callInDate != null">call_in_date,</if>
            <if test="assetTotalOriginalValue != null">asset_total_original_value,</if>
            <if test="assetTotalNetValue != null">asset_total_net_value,</if>
            <if test="reason != null">reason,</if>
            <if test="preparedBy != null and preparedBy != ''">prepared_by,</if>
            <if test="preparedDepartment != null">prepared_department,</if>
            <if test="corporation != null">corporation,</if>
            <if test="recordStatus != null">record_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">#{orderNumber},</if>
            <if test="callOutDepartment != null">#{callOutDepartment},</if>
            <if test="callOutBy != null">#{callOutBy},</if>
            <if test="callOutDate != null">#{callOutDate},</if>
            <if test="callInDepartment != null">#{callInDepartment},</if>
            <if test="callInBy != null">#{callInBy},</if>
            <if test="callInDate != null">#{callInDate},</if>
            <if test="assetTotalOriginalValue != null">#{assetTotalOriginalValue},</if>
            <if test="assetTotalNetValue != null">#{assetTotalNetValue},</if>
            <if test="reason != null">#{reason},</if>
            <if test="preparedBy != null and preparedBy != ''">#{preparedBy},</if>
            <if test="preparedDepartment != null">#{preparedDepartment},</if>
            <if test="corporation != null">#{corporation},</if>
            <if test="recordStatus != null">#{recordStatus},</if>
         </trim>
    </insert>

    <update id="updateTbAssetAllocation" parameterType="TbAssetAllocation">
        update tb_asset_allocation
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
            <if test="callOutDepartment != null">call_out_department = #{callOutDepartment},</if>
            <if test="callOutBy != null">call_out_by = #{callOutBy},</if>
            <if test="callOutDate != null">call_out_date = #{callOutDate},</if>
            <if test="callInDepartment != null">call_in_department = #{callInDepartment},</if>
            <if test="callInBy != null">call_in_by = #{callInBy},</if>
            <if test="callInDate != null">call_in_date = #{callInDate},</if>
            <if test="assetTotalOriginalValue != null">asset_total_original_value = #{assetTotalOriginalValue},</if>
            <if test="assetTotalNetValue != null">asset_total_net_value = #{assetTotalNetValue},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="preparedBy != null and preparedBy != ''">prepared_by = #{preparedBy},</if>
            <if test="preparedDepartment != null">prepared_department = #{preparedDepartment},</if>
            <if test="corporation != null">corporation = #{corporation},</if>
            <if test="recordStatus != null">record_status = #{recordStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbAssetAllocationById" parameterType="Long">
        delete from tb_asset_allocation where id = #{id}
    </delete>

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