<?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.lz.modules.equipment.dao.EquipmentFlowRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.equipment.entity.EquipmentFlowRecord">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="brand_name" property="brandName"/>
        <result column="spec_type" property="specType"/>
        <result column="change_type" property="changeType"/>
        <result column="user" property="user"/>
        <result column="original_user" property="originalUser"/>
        <result column="record_user" property="recordUser"/>
        <result column="equipment_id" property="equipmentId"/>
        <result column="user_id" property="userId"/>
        <result column="record_user_id" property="recordUserId"/>
        <result column="gmt_outbound" property="gmtOutbound"/>
        <result column="gmt_inbound" property="gmtInbound"/>
        <result column="buy_amount" property="buyAmount"/>
        <result column="sale_amount" property="saleAmount"/>
        <result column="mark" property="mark"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, brand_name AS brandName, spec_type AS specType, change_type AS changeType, user AS user, original_user AS originalUser, record_user AS recordUser, equipment_id AS equipmentId, user_id AS userId, record_user_id AS recordUserId, gmt_outbound AS gmtOutbound, gmt_inbound AS gmtInbound, buy_amount AS buyAmount, sale_amount AS saleAmount, mark AS mark
    </sql>




    <select id="selectEquipmentFlowRecordById" resultType="EquipmentFlowRecord" >
        select * from equipment_flow_record  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertEquipmentFlowRecord" parameterType="EquipmentFlowRecord" useGeneratedKeys="true" keyProperty="id" >
        insert into equipment_flow_record(
            <if test="brandName != null">brand_name, </if>
            <if test="specType != null">spec_type, </if>
            <if test="changeType != null">change_type, </if>
            <if test="user != null">user, </if>
            <if test="originalUser != null">original_user, </if>
            <if test="recordUser != null">record_user, </if>
            <if test="equipmentId != null">equipment_id, </if>
            <if test="userId != null">user_id, </if>
            <if test="recordUserId != null">record_user_id, </if>
            <if test="gmtOutbound != null">gmt_outbound, </if>
            <if test="gmtInbound != null">gmt_inbound, </if>
            <if test="buyAmount != null">buy_amount, </if>
            <if test="saleAmount != null">sale_amount, </if>
            <if test="mark != null">mark, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="brandName != null">#{ brandName}, </if>
            <if test="specType != null">#{ specType}, </if>
            <if test="changeType != null">#{ changeType}, </if>
            <if test="user != null">#{ user}, </if>
            <if test="originalUser != null">#{ originalUser}, </if>
            <if test="recordUser != null">#{ recordUser}, </if>
            <if test="equipmentId != null">#{ equipmentId}, </if>
            <if test="userId != null">#{ userId}, </if>
            <if test="recordUserId != null">#{ recordUserId}, </if>
            <if test="gmtOutbound != null">#{ gmtOutbound}, </if>
            <if test="gmtInbound != null">#{ gmtInbound}, </if>
            <if test="buyAmount != null">#{ buyAmount}, </if>
            <if test="saleAmount != null">#{ saleAmount}, </if>
            <if test="mark != null">#{ mark}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateEquipmentFlowRecordById" parameterType="EquipmentFlowRecord" >
        update
            equipment_flow_record
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="brandName != null">brand_name = #{brandName},</if>
            <if test="specType != null">spec_type = #{specType},</if>
            <if test="changeType != null">change_type = #{changeType},</if>
            <if test="user != null">user = #{user},</if>
            <if test="originalUser != null">original_user = #{originalUser},</if>
            <if test="recordUser != null">record_user = #{recordUser},</if>
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="recordUserId != null">record_user_id = #{recordUserId},</if>
            <if test="gmtOutbound != null">gmt_outbound = #{gmtOutbound},</if>
            <if test="gmtInbound != null">gmt_inbound = #{gmtInbound},</if>
            <if test="buyAmount != null">buy_amount = #{buyAmount},</if>
            <if test="saleAmount != null">sale_amount = #{saleAmount},</if>
            <if test="mark != null">mark = #{mark}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverEquipmentFlowRecordById" parameterType="EquipmentFlowRecord" >
        update
            equipment_flow_record    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            brand_name = #{brandName},
            spec_type = #{specType},
            change_type = #{changeType},
            user = #{user},
            original_user = #{originalUser},
            record_user = #{recordUser},
            equipment_id = #{equipmentId},
            user_id = #{userId},
            record_user_id = #{recordUserId},
            gmt_outbound = #{gmtOutbound},
            gmt_inbound = #{gmtInbound},
            buy_amount = #{buyAmount},
            sale_amount = #{saleAmount},
            mark = #{mark}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteEquipmentFlowRecordById" parameterType="java.lang.Long">
        update equipment_flow_record set is_delete = 1 where id=#{id} limit 1  
    </update>

</mapper>

