<?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.basic.mapper.BmStorageLogMapper">
    <resultMap type="com.bonus.common.biz.domain.BmStorageLog" id="BmStorageLogResult">
        <result property="id"    column="id"    />
        <result property="modelTitle"    column="model_title"    />
        <result property="method"    column="method"    />
        <result property="typeId"    column="type_id"    />
        <result property="preStoreNum"    column="pre_store_num"    />
        <result property="inNum"    column="in_num"    />
        <result property="outNum"    column="out_num"    />
        <result property="backNum"    column="back_num"    />
        <result property="passNum"    column="pass_num"    />
        <result property="repairNum"    column="repair_num"    />
        <result property="scrapNum"    column="scrap_num"    />
        <result property="postStoreNum"    column="post_store_num"    />
        <result property="taskId"    column="task_id"    />
        <result property="agreementId"    column="agreement_id"    />
        <result property="manageType"    column="manage_type"    />
        <result property="typeName"    column="type_name"    />
        <result property="typeModelName"    column="type_model_name"    />
        <result property="resultCode"    column="result_code"    />
        <result property="resultMsg"    column="result_msg"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
        <result property="jsonResult"    column="json_result"    />
        <result property="creator"    column="creator"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBmStorageLogVo">
        select id, model_title, method, type_id, pre_store_num, in_num, out_num, back_num, pass_num, repair_num, scrap_num, post_store_num, task_id, agreement_id, manage_type, type_name, type_model_name, result_code, result_msg, remark, status, json_result, creator, create_time, update_time from bm_storage_log
    </sql>
    
    <select id="selectBmStorageLogById" parameterType="Long" resultMap="BmStorageLogResult">
        <include refid="selectBmStorageLogVo"/>
        where id = #{id}
    </select>

    <select id="selectBmStorageLogList" resultType="com.bonus.common.biz.domain.BmStorageLog">
        SELECT
        id as id, model_title as modelTitle, method as method, type_id as typeId, pre_store_num as preStoreNum,
        in_num as inNum, out_num as outNum, back_num as backNum,
        pass_num as passNum, repair_num as repairNum,
        scrap_num as scrapNum, post_store_num as postStoreNum, task_id as taskId, agreement_id as agreementId,
        manage_type as manageType, type_name as typeName,
        type_model_name as typeModelName, result_code as resultCode,
        result_msg as resultMsg, remark as remark, status as status, json_result as jsonResult, creator as creator,
        create_time as createTime
        FROM
        bm_storage_log
        <where>
            <if test="modelTitle != null and modelTitle != ''">
                and model_title like concat('%', #{modelTitle}, '%')
            </if>
            <if test="typeName != null and typeName != ''">
                and type_name like concat('%', #{typeName}, '%')
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <insert id="insertBmStorageLog" parameterType="com.bonus.common.biz.domain.BmStorageLog" useGeneratedKeys="true" keyProperty="id">
        insert into bm_storage_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelTitle != null">model_title,</if>
            <if test="method != null">method,</if>
            <if test="typeId != null">type_id,</if>
            <if test="preStoreNum != null">pre_store_num,</if>
            <if test="inNum != null">in_num,</if>
            <if test="outNum != null">out_num,</if>
            <if test="backNum != null">back_num,</if>
            <if test="passNum != null">pass_num,</if>
            <if test="repairNum != null">repair_num,</if>
            <if test="scrapNum != null">scrap_num,</if>
            <if test="postStoreNum != null">post_store_num,</if>
            <if test="taskId != null">task_id,</if>
            <if test="agreementId != null">agreement_id,</if>
            <if test="manageType != null">manage_type,</if>
            <if test="typeName != null">type_name,</if>
            <if test="typeModelName != null">type_model_name,</if>
            <if test="resultCode != null">result_code,</if>
            <if test="resultMsg != null and resultMsg != ''">result_msg,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</if>
            <if test="jsonResult != null">json_result,</if>
            <if test="creator != null">creator,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="modelTitle != null">#{modelTitle},</if>
            <if test="method != null">#{method},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="preStoreNum != null">#{preStoreNum},</if>
            <if test="inNum != null">#{inNum},</if>
            <if test="outNum != null">#{outNum},</if>
            <if test="backNum != null">#{backNum},</if>
            <if test="passNum != null">#{passNum},</if>
            <if test="repairNum != null">#{repairNum},</if>
            <if test="scrapNum != null">#{scrapNum},</if>
            <if test="postStoreNum != null">#{postStoreNum},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="agreementId != null">#{agreementId},</if>
            <if test="manageType != null">#{manageType},</if>
            <if test="typeName != null">#{typeName},</if>
            <if test="typeModelName != null">#{typeModelName},</if>
            <if test="resultCode != null">#{resultCode},</if>
            <if test="resultMsg != null and resultMsg != ''">#{resultMsg},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</if>
            <if test="jsonResult != null">#{jsonResult},</if>
            <if test="creator != null">#{creator},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="com.bonus.common.biz.domain.BmStorageLog" useGeneratedKeys="true">
        insert into bm_storage_log (model_title, `method`, task_id, type_id,
        create_time, creator, remark, manage_type,
        type_name, type_model_name, pre_store_num, in_num, out_num,
        back_num, pass_num, repair_num, agreement_id,
        scrap_num, `status`, post_store_num, result_code, result_msg, json_result
        ) values
        <foreach item="item" index="index" collection="list" separator=",">
            (
            #{item.modelTitle}, #{item.method}, #{item.taskId}, #{item.typeId},
            now(), #{item.creator}, #{item.remark}, #{item.manageType},#{item.typeName},
             #{item.typeModelName}, #{item.preStoreNum}, #{item.inNum},#{item.outNum},
            #{item.backNum},  #{item.passNum}, #{item.repairNum}, #{item.agreementId},
            #{item.scrapNum}, #{item.status}, #{item.postStoreNum},
            #{item.resultCode}, #{item.resultMsg}, #{item.jsonResult}
            )
        </foreach>
    </insert>

    <update id="updateBmStorageLog" parameterType="com.bonus.common.biz.domain.BmStorageLog">
        update bm_storage_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="modelTitle != null">model_title = #{modelTitle},</if>
            <if test="method != null">method = #{method},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="preStoreNum != null">pre_store_num = #{preStoreNum},</if>
            <if test="inNum != null">in_num = #{inNum},</if>
            <if test="outNum != null">out_num = #{outNum},</if>
            <if test="backNum != null">back_num = #{backNum},</if>
            <if test="passNum != null">pass_num = #{passNum},</if>
            <if test="repairNum != null">repair_num = #{repairNum},</if>
            <if test="scrapNum != null">scrap_num = #{scrapNum},</if>
            <if test="postStoreNum != null">post_store_num = #{postStoreNum},</if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="agreementId != null">agreement_id = #{agreementId},</if>
            <if test="manageType != null">manage_type = #{manageType},</if>
            <if test="typeName != null">type_name = #{typeName},</if>
            <if test="typeModelName != null">type_model_name = #{typeModelName},</if>
            <if test="resultCode != null">result_code = #{resultCode},</if>
            <if test="resultMsg != null and resultMsg != ''">result_msg = #{resultMsg},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</if>
            <if test="jsonResult != null">json_result = #{jsonResult},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBmStorageLogById" parameterType="Long">
        delete from bm_storage_log where id = #{id}
    </delete>

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