<?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.bonus.material.task.mapper.TmTaskStorageAnalyzeMapper">
    <resultMap type="com.bonus.material.task.domain.TmTaskStorageAnalyze" id="TmTaskStorageAnalyzeResult">
        <result property="id"    column="id"    />
        <result property="calDate"    column="cal_date"    />
        <result property="typeId"    column="type_id"    />
        <result property="preStorageNum"    column="pre_storage_num"    />
        <result property="inputSum"    column="input_sum"    />
        <result property="outputSum"    column="output_sum"    />
        <result property="currentStroageNum"    column="current_stroage_num"    />
        <result property="storageNumDiff"    column="storage_num_diff"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTmTaskStorageAnalyzeVo">
        select id, cal_date, type_id, pre_storage_num, input_sum, output_sum, current_stroage_num, storage_num_diff, create_by, create_time, update_by, update_time, remark from tm_task_storage_analyze
    </sql>

    <select id="selectTmTaskStorageAnalyzeList" parameterType="com.bonus.material.task.domain.TmTaskStorageAnalyze" resultMap="TmTaskStorageAnalyzeResult">
        <include refid="selectTmTaskStorageAnalyzeVo"/>
        <where>  
            <if test="calDate != null "> and cal_date = #{calDate}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="preStorageNum != null "> and pre_storage_num = #{preStorageNum}</if>
            <if test="inputSum != null "> and input_sum = #{inputSum}</if>
            <if test="outputSum != null "> and output_sum = #{outputSum}</if>
            <if test="currentStroageNum != null "> and current_stroage_num = #{currentStroageNum}</if>
            <if test="storageNumDiff != null "> and storage_num_diff = #{storageNumDiff}</if>
        </where>
    </select>
    
    <select id="selectTmTaskStorageAnalyzeById" parameterType="Long" resultMap="TmTaskStorageAnalyzeResult">
        <include refid="selectTmTaskStorageAnalyzeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTmTaskStorageAnalyze" parameterType="com.bonus.material.task.domain.TmTaskStorageAnalyze" useGeneratedKeys="true" keyProperty="id">
        insert into tm_task_storage_analyze
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="calDate != null">cal_date,</if>
            <if test="typeId != null">type_id,</if>
            <if test="preStorageNum != null">pre_storage_num,</if>
            <if test="inputSum != null">input_sum,</if>
            <if test="outputSum != null">output_sum,</if>
            <if test="currentStroageNum != null">current_stroage_num,</if>
            <if test="storageNumDiff != null">storage_num_diff,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="calDate != null">#{calDate},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="preStorageNum != null">#{preStorageNum},</if>
            <if test="inputSum != null">#{inputSum},</if>
            <if test="outputSum != null">#{outputSum},</if>
            <if test="currentStroageNum != null">#{currentStroageNum},</if>
            <if test="storageNumDiff != null">#{storageNumDiff},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTmTaskStorageAnalyze" parameterType="com.bonus.material.task.domain.TmTaskStorageAnalyze">
        update tm_task_storage_analyze
        <trim prefix="SET" suffixOverrides=",">
            <if test="calDate != null">cal_date = #{calDate},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="preStorageNum != null">pre_storage_num = #{preStorageNum},</if>
            <if test="inputSum != null">input_sum = #{inputSum},</if>
            <if test="outputSum != null">output_sum = #{outputSum},</if>
            <if test="currentStroageNum != null">current_stroage_num = #{currentStroageNum},</if>
            <if test="storageNumDiff != null">storage_num_diff = #{storageNumDiff},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTmTaskStorageAnalyzeById" parameterType="Long">
        delete from tm_task_storage_analyze where id = #{id}
    </delete>

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