<?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.TbAssetOrderMapper">
    
    <resultMap type="TbAssetOrder" id="TbAssetOrderResult">
        <result property="id"    column="id"    />
        <result property="orderNumber"    column="order_number"    />
        <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="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"    />
        <result property="orderType"    column="order_type"    />
    </resultMap>

    <sql id="selectTbAssetOrderVo">
        select id, order_number, asset_total_original_value, asset_total_net_value, application_date, application_department, reason, prepared_by, prepared_department, corporation, record_status, order_type from tb_asset_order
    </sql>

    <select id="selectTbAssetOrderList" parameterType="TbAssetOrder" resultMap="TbAssetOrderResult">
        <include refid="selectTbAssetOrderVo"/>
        <where>  
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="assetTotalOriginalValue != null  and assetTotalOriginalValue != ''"> and asset_total_original_value = #{assetTotalOriginalValue}</if>
            <if test="assetTotalNetValue != null  and assetTotalNetValue != ''"> and asset_total_net_value = #{assetTotalNetValue}</if>
            <if test="applicationDate != null "> and application_date = #{applicationDate}</if>
            <if test="applicationDepartment != null  and applicationDepartment != ''"> and application_department = #{applicationDepartment}</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>
            <if test="orderType != null "> and order_type = #{orderType}</if>
        </where>
    </select>
    
    <select id="selectTbAssetOrderById" parameterType="Long" resultMap="TbAssetOrderResult">
        <include refid="selectTbAssetOrderVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbAssetOrder" parameterType="TbAssetOrder" useGeneratedKeys="true" keyProperty="id">
        insert into tb_asset_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number,</if>
            <if test="assetTotalOriginalValue != null">asset_total_original_value,</if>
            <if test="assetTotalNetValue != null">asset_total_net_value,</if>
            <if test="applicationDate != null">application_date,</if>
            <if test="applicationDepartment != null">application_department,</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>
            <if test="orderType != null">order_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">#{orderNumber},</if>
            <if test="assetTotalOriginalValue != null">#{assetTotalOriginalValue},</if>
            <if test="assetTotalNetValue != null">#{assetTotalNetValue},</if>
            <if test="applicationDate != null">#{applicationDate},</if>
            <if test="applicationDepartment != null">#{applicationDepartment},</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>
            <if test="orderType != null">#{orderType},</if>
         </trim>
    </insert>

    <update id="updateTbAssetOrder" parameterType="TbAssetOrder">
        update tb_asset_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
            <if test="assetTotalOriginalValue != null">asset_total_original_value = #{assetTotalOriginalValue},</if>
            <if test="assetTotalNetValue != null">asset_total_net_value = #{assetTotalNetValue},</if>
            <if test="applicationDate != null">application_date = #{applicationDate},</if>
            <if test="applicationDepartment != null">application_department = #{applicationDepartment},</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>
            <if test="orderType != null">order_type = #{orderType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbAssetOrderById" parameterType="Long">
        delete from tb_asset_order where id = #{id}
    </delete>

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