<?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.order.mapper.TbOrderMapper">
    
    <resultMap type="TbOrder" id="TbOrderResult">
        <result property="id"    column="id"    />
        <result property="orderNumber"    column="order_number"    />
        <result property="orderType"    column="order_type"    />
        <result property="assetTotalOriginalValue"    column="asset_total_original_value"    />
        <result property="assetTotalNetValue"    column="asset_total_net_value"    />
        <result property="applicationDate"    column="application_date"    />
        <result property="applicationDepartment"    column="application_department"    />
        <result property="adjustmentAssetNumber"    column="adjustment_asset_number"    />
        <result property="adjustmentOriginalAssetInfo"    column="adjustment_original_asset_info"    />
        <result property="allocationCallOutDepartment"    column="allocation_call_out_department"    />
        <result property="allocationCallOutBy"    column="allocation_call_out_by"    />
        <result property="allocationCallOutDate"    column="allocation_call_out_date"    />
        <result property="allocationCallInDepartment"    column="allocation_call_in_department"    />
        <result property="allocationCallInBy"    column="allocation_call_in_by"    />
        <result property="allocationCallInDate"    column="allocation_call_in_date"    />
        <result property="lendDepartment"    column="lend_department"    />
        <result property="lendBySponsor"    column="lend_by_sponsor"    />
        <result property="lendPassingUnit"    column="lend_passing_unit"    />
        <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="selectTbOrderVo">
        select id, order_number, order_type, asset_total_original_value, asset_total_net_value, application_date, application_department, adjustment_asset_number, adjustment_original_asset_info, allocation_call_out_department, allocation_call_out_by, allocation_call_out_date, allocation_call_in_department, allocation_call_in_by, allocation_call_in_date, lend_department, lend_by_sponsor, lend_passing_unit, reason, prepared_by, prepared_department, corporation, record_status from tb_order
    </sql>

    <select id="selectTbOrderList" parameterType="TbOrder" resultMap="TbOrderResult">
        <include refid="selectTbOrderVo"/>
        <where>  
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="orderType != null "> and order_type = #{orderType}</if>
            <if test="applicationDate != null "> and application_date = #{applicationDate}</if>
            <if test="applicationDepartment != null  and applicationDepartment != ''"> and application_department = #{applicationDepartment}</if>
            <if test="adjustmentAssetNumber != null  and adjustmentAssetNumber != ''"> and adjustment_asset_number = #{adjustmentAssetNumber}</if>
            <if test="allocationCallOutDepartment != null  and allocationCallOutDepartment != ''"> and allocation_call_out_department = #{allocationCallOutDepartment}</if>
            <if test="allocationCallOutBy != null  and allocationCallOutBy != ''"> and allocation_call_out_by = #{allocationCallOutBy}</if>
            <if test="allocationCallOutDate != null "> and allocation_call_out_date = #{allocationCallOutDate}</if>
            <if test="allocationCallInDepartment != null  and allocationCallInDepartment != ''"> and allocation_call_in_department = #{allocationCallInDepartment}</if>
            <if test="allocationCallInBy != null  and allocationCallInBy != ''"> and allocation_call_in_by = #{allocationCallInBy}</if>
            <if test="allocationCallInDate != null "> and allocation_call_in_date = #{allocationCallInDate}</if>
            <if test="lendDepartment != null  and lendDepartment != ''"> and lend_department = #{lendDepartment}</if>
            <if test="lendBySponsor != null  and lendBySponsor != ''"> and lend_by_sponsor = #{lendBySponsor}</if>
            <if test="lendPassingUnit != null  and lendPassingUnit != ''"> and lend_passing_unit = #{lendPassingUnit}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</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="selectTbOrderById" parameterType="Long" resultMap="TbOrderResult">
        <include refid="selectTbOrderVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbOrder" parameterType="TbOrder" useGeneratedKeys="true" keyProperty="id">
        insert into tb_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number,</if>
            <if test="orderType != null">order_type,</if>
            <if test="assetTotalOriginalValue != null and assetTotalOriginalValue != ''">asset_total_original_value,</if>
            <if test="assetTotalNetValue != null and assetTotalNetValue != ''">asset_total_net_value,</if>
            <if test="applicationDate != null">application_date,</if>
            <if test="applicationDepartment != null">application_department,</if>
            <if test="adjustmentAssetNumber != null">adjustment_asset_number,</if>
            <if test="adjustmentOriginalAssetInfo != null">adjustment_original_asset_info,</if>
            <if test="allocationCallOutDepartment != null">allocation_call_out_department,</if>
            <if test="allocationCallOutBy != null">allocation_call_out_by,</if>
            <if test="allocationCallOutDate != null">allocation_call_out_date,</if>
            <if test="allocationCallInDepartment != null">allocation_call_in_department,</if>
            <if test="allocationCallInBy != null">allocation_call_in_by,</if>
            <if test="allocationCallInDate != null">allocation_call_in_date,</if>
            <if test="lendDepartment != null">lend_department,</if>
            <if test="lendBySponsor != null">lend_by_sponsor,</if>
            <if test="lendPassingUnit != null">lend_passing_unit,</if>
            <if test="reason != null">reason,</if>
            <if test="preparedBy != null and preparedBy != ''">prepared_by,</if>
            <if test="preparedDepartment != null and preparedDepartment != ''">prepared_department,</if>
            <if test="corporation != null and corporation != ''">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="orderType != null">#{orderType},</if>
            <if test="assetTotalOriginalValue != null and assetTotalOriginalValue != ''">#{assetTotalOriginalValue},</if>
            <if test="assetTotalNetValue != null and assetTotalNetValue != ''">#{assetTotalNetValue},</if>
            <if test="applicationDate != null">#{applicationDate},</if>
            <if test="applicationDepartment != null">#{applicationDepartment},</if>
            <if test="adjustmentAssetNumber != null">#{adjustmentAssetNumber},</if>
            <if test="adjustmentOriginalAssetInfo != null">#{adjustmentOriginalAssetInfo},</if>
            <if test="allocationCallOutDepartment != null">#{allocationCallOutDepartment},</if>
            <if test="allocationCallOutBy != null">#{allocationCallOutBy},</if>
            <if test="allocationCallOutDate != null">#{allocationCallOutDate},</if>
            <if test="allocationCallInDepartment != null">#{allocationCallInDepartment},</if>
            <if test="allocationCallInBy != null">#{allocationCallInBy},</if>
            <if test="allocationCallInDate != null">#{allocationCallInDate},</if>
            <if test="lendDepartment != null">#{lendDepartment},</if>
            <if test="lendBySponsor != null">#{lendBySponsor},</if>
            <if test="lendPassingUnit != null">#{lendPassingUnit},</if>
            <if test="reason != null">#{reason},</if>
            <if test="preparedBy != null and preparedBy != ''">#{preparedBy},</if>
            <if test="preparedDepartment != null and preparedDepartment != ''">#{preparedDepartment},</if>
            <if test="corporation != null and corporation != ''">#{corporation},</if>
            <if test="recordStatus != null">#{recordStatus},</if>
         </trim>
    </insert>

    <update id="updateTbOrder" parameterType="TbOrder">
        update tb_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="assetTotalOriginalValue != null and assetTotalOriginalValue != ''">asset_total_original_value = #{assetTotalOriginalValue},</if>
            <if test="assetTotalNetValue != null and assetTotalNetValue != ''">asset_total_net_value = #{assetTotalNetValue},</if>
            <if test="applicationDate != null">application_date = #{applicationDate},</if>
            <if test="applicationDepartment != null">application_department = #{applicationDepartment},</if>
            <if test="adjustmentAssetNumber != null">adjustment_asset_number = #{adjustmentAssetNumber},</if>
            <if test="adjustmentOriginalAssetInfo != null">adjustment_original_asset_info = #{adjustmentOriginalAssetInfo},</if>
            <if test="allocationCallOutDepartment != null">allocation_call_out_department = #{allocationCallOutDepartment},</if>
            <if test="allocationCallOutBy != null">allocation_call_out_by = #{allocationCallOutBy},</if>
            <if test="allocationCallOutDate != null">allocation_call_out_date = #{allocationCallOutDate},</if>
            <if test="allocationCallInDepartment != null">allocation_call_in_department = #{allocationCallInDepartment},</if>
            <if test="allocationCallInBy != null">allocation_call_in_by = #{allocationCallInBy},</if>
            <if test="allocationCallInDate != null">allocation_call_in_date = #{allocationCallInDate},</if>
            <if test="lendDepartment != null">lend_department = #{lendDepartment},</if>
            <if test="lendBySponsor != null">lend_by_sponsor = #{lendBySponsor},</if>
            <if test="lendPassingUnit != null">lend_passing_unit = #{lendPassingUnit},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="preparedBy != null and preparedBy != ''">prepared_by = #{preparedBy},</if>
            <if test="preparedDepartment != null and preparedDepartment != ''">prepared_department = #{preparedDepartment},</if>
            <if test="corporation != null and corporation != ''">corporation = #{corporation},</if>
            <if test="recordStatus != null">record_status = #{recordStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbOrderById" parameterType="Long">
        delete from tb_order where id = #{id}
    </delete>

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