<?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.zbf.system.mapper.TckXnOrderdetailBakMapper">

    <resultMap type="TckXnOrderdetailBak" id="TckXnOrderdetailBakResult">
        <result property="id"    column="id"    />
        <result property="orderId"    column="order_id"    />
        <result property="businessId"    column="business_id"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="locationId"    column="location_id"    />
        <result property="specification"    column="specification"    />
        <result property="unit"    column="unit"    />
        <result property="storageId"    column="storage_id"    />
        <result property="storageShortName"    column="storage_short_name"    />
        <result property="shelvesNum"    column="shelves_num"    />
        <result property="goodsNum"    column="goods_num"    />
        <result property="callShelvesNum"    column="call_shelves_num"    />
        <result property="remark"    column="remark"    />
        <result property="price"    column="price"    />
        <result property="goodsTypeId"    column="goods_type_id"    />
        <result property="providerId"    column="provider_id"    />
        <result property="recoil"    column="recoil"    />
        <result property="storageAreaId"    column="storage_area_id"    />
        <result property="pickNum"    column="pick_num"    />
        <result property="trNum"    column="tr_num"    />
        <result property="barcode"    column="barcode"    />
        <result property="status"    column="status"    />
        <result property="toLoc"    column="to_loc"    />
        <result property="confirmStatus"    column="confirm_status"    />
        <result property="expiryDate"    column="expiry_date"    />
        <result property="stockNum"    column="stock_num"    />
        <result property="taskId"    column="task_id"    />
        <result property="updateTime"    column="update_time"    />
        <result property="abc"    column="abc"    />
        <result property="levelType"    column="level_type"    />
        <result property="applicant"    column="applicant"    />
        <result property="supplier"    column="supplier"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="deliveryId"    column="delivery_id"    />
        <result property="ckType"    column="ck_type"    />
        <result property="orderType"    column="order_type"    />
        <result property="ctl"    column="ctl"    />
        <result property="toMoney"    column="to_money"    />
        <result property="batchNo"    column="batch_no"    />
        <result property="original"    column="original"    />
        <result property="goodsTo"    column="goods_to"    />
        <result property="auditMan"    column="audit_man"    />
        <result property="rejectReason"    column="reject_reason"    />
        <result property="auditDate"    column="audit_date"    />
    </resultMap>

    <sql id="selectTckOrderdetailBakVo">
        select id, order_id, business_id, goods_id, goods_name, location_id, specification, unit, storage_id,storage_short_name, shelves_num, goods_num, call_shelves_num, remark, price, goods_type_id, provider_id, recoil, storage_area_id, pick_num, tr_num, barcode, status, to_loc, confirm_status, expiry_date, stock_num, task_id, update_time,abc,level_type, applicant, supplier, create_time, create_by, update_by ,to_money,delivery_id,ck_type,order_type,ctl,batch_no,original,goods_to,audit_man, audit_date, reject_reason   from t_ck_xn_orderdetail_bak
    </sql>

    <select id="selectTckOrderdetailBakList" parameterType="TckXnOrderdetailBak" resultMap="TckXnOrderdetailBakResult">
        <include refid="selectTckOrderdetailBakVo"/>
        <where>
                        <if test="orderId != null  and orderId != ''"> and order_id like concat('%', #{orderId}, '%')</if>
                        <if test="businessId != null  and businessId != ''"> and business_id like concat('%', #{businessId}, '%')</if>
                        <if test="goodsId != null  and goodsId != ''"> and goods_id like concat('%', #{goodsId}, '%')</if>
                        <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
                        <if test="locationId != null  and locationId != ''"> and location_id like concat('%', #{locationId}, '%')</if>
                        <if test="specification != null  and specification != ''"> and specification like concat('%', #{specification}, '%')</if>
                        <if test="unit != null  and unit != ''"> and unit like concat('%', #{unit}, '%')</if>
                        <if test="storageId != null  and storageId != ''"> and storage_id like concat('%', #{storageId}, '%')</if>
                        <if test="storageShortName != null  and storageShortName != ''"> and storage_short_name like concat('%', #{storageShortName}, '%')</if>
                        <if test="shelvesNum != null "> and shelves_num like concat('%', #{shelvesNum}, '%')</if>
                        <if test="goodsNum != null "> and goods_num like concat('%', #{goodsNum}, '%')</if>
                        <if test="callShelvesNum != null "> and call_shelves_num like concat('%', #{callShelvesNum}, '%')</if>
                        <if test="price != null "> and price like concat('%', #{price}, '%')</if>
                        <if test="goodsTypeId != null  and goodsTypeId != ''"> and goods_type_id = #{goodsTypeId}</if>
                        <if test="providerId != null  and providerId != ''"> and provider_id = #{providerId}</if>
                        <if test="recoil != null  and recoil != ''"> and recoil = #{recoil}</if>
                        <if test="storageAreaId != null  and storageAreaId != ''"> and storage_area_id = #{storageAreaId}</if>
                        <if test="pickNum != null "> and pick_num = #{pickNum}</if>
                        <if test="trNum != null "> and tr_num = #{trNum}</if>
                        <if test="barcode != null  and barcode != ''"> and barcode = #{barcode}</if>
                        <if test="status != null  and status != ''"> and status = #{status}</if>
                        <if test="toLoc != null  and toLoc != ''"> and to_loc = #{toLoc}</if>
                        <if test="confirmStatus != null  and confirmStatus != ''"> and confirm_status = #{confirmStatus}</if>
                        <if test="expiryDate != null "> and expiry_date = #{expiryDate}</if>
                        <if test="stockNum != null "> and stock_num = #{stockNum}</if>
                        <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
                        <if test="abc != null  and abc != ''"> and abc = #{abc}</if>
                        <if test="levelType != null  and levelType != ''"> and level_type = #{levelType}</if>
                        <if test="supplier != null  and supplier != ''"> and supplier = #{supplier}</if>
                        <if test="applicant != null  and applicant != ''"> and applicant = #{applicant}</if>
                        <if test="deliveryId != null "> and delivery_id = #{deliveryId}</if>
                        <if test="ckType != null  and ckType != ''"> and ck_type = #{ckType}</if>
                        <if test="orderType != null  and orderType != ''"> and order_type = #{orderType}</if>
                        <if test="startTime != null and endTime != ''">
                            and create_time BETWEEN #{startTime} AND #{endTime}
                        </if>
                        <if test="ctl != null  and ctl != ''"> and ctl = #{ctl}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectTMiStockList" parameterType="TckXnOrderdetailBak" resultMap="TckXnOrderdetailBakResult">
        <include refid="selectTckOrderdetailBakVo"/>
        <where>
            <if test="orderId != null  and orderId != ''"> and order_id like concat('%', #{orderId}, '%')</if>
            <if test="businessId != null  and businessId != ''"> and business_id like concat('%', #{businessId}, '%')</if>
            <if test="goodsId != null  and goodsId != ''"> and goods_id like concat('%', #{goodsId}, '%')</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="locationId != null  and locationId != ''"> and location_id like concat('%', #{locationId}, '%')</if>
            <if test="specification != null  and specification != ''"> and specification like concat('%', #{specification}, '%')</if>
            <if test="unit != null  and unit != ''"> and unit like concat('%', #{unit}, '%')</if>
            <if test="storageId != null  and storageId != ''"> and storage_id like concat('%', #{storageId}, '%')</if>
            <if test="storageShortName != null  and storageShortName != ''"> and storage_short_name like concat('%', #{storageShortName}, '%')</if>
            <if test="shelvesNum != null "> and shelves_num like concat('%', #{shelvesNum}, '%')</if>
            <if test="goodsNum != null "> and goods_num like concat('%', #{goodsNum}, '%')</if>
            <if test="callShelvesNum != null "> and call_shelves_num like concat('%', #{callShelvesNum}, '%')</if>
            <if test="price != null "> and price like concat('%', #{price}, '%')</if>
            <if test="goodsTypeId != null  and goodsTypeId != ''"> and goods_type_id = #{goodsTypeId}</if>
            <if test="providerId != null  and providerId != ''"> and provider_id = #{providerId}</if>
            <if test="recoil != null  and recoil != ''"> and recoil = #{recoil}</if>
            <if test="storageAreaId != null  and storageAreaId != ''"> and storage_area_id = #{storageAreaId}</if>
            <if test="pickNum != null "> and pick_num = #{pickNum}</if>
            <if test="trNum != null "> and tr_num = #{trNum}</if>
            <if test="barcode != null  and barcode != ''"> and barcode = #{barcode}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="toLoc != null  and toLoc != ''"> and to_loc = #{toLoc}</if>
            <if test="confirmStatus != null  and confirmStatus != ''"> and confirm_status = #{confirmStatus}</if>
            <if test="expiryDate != null "> and expiry_date = #{expiryDate}</if>
            <if test="stockNum != null "> and stock_num = #{stockNum}</if>
            <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
            <if test="abc != null  and abc != ''"> and abc = #{abc}</if>
            <if test="levelType != null  and levelType != ''"> and level_type = #{levelType}</if>
            <if test="supplier != null  and supplier != ''"> and supplier = #{supplier}</if>
            <if test="applicant != null  and applicant != ''"> and applicant = #{applicant}</if>
            <if test="deliveryId != null "> and delivery_id = #{deliveryId}</if>
            <if test="ckType != null  and ckType != ''"> and ck_type = #{ckType}</if>
            <if test="orderType != null  and orderType != ''"> and order_type = #{orderType}</if>
            <if test="startTime != null and endTime != ''">
                and create_time BETWEEN #{startTime} AND #{endTime}
            </if>
            <if test="ctl != null  and ctl != ''"> and ctl = #{ctl}</if>
        </where>

    </select>

    <select id="selectTckOrderdetailBakById" parameterType="String" resultMap="TckXnOrderdetailBakResult">
            <include refid="selectTckOrderdetailBakVo"/>
            where id = #{id}
    </select>


    <insert id="insertTckOrderdetailBak" parameterType="TckXnOrderdetailBak">
        insert into t_ck_xn_orderdetail_bak
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,</if>
                    <if test="orderId != null and orderId != ''">order_id,</if>
                    <if test="businessId != null">business_id,</if>
                    <if test="goodsId != null">goods_id,</if>
                    <if test="goodsName != null">goods_name,</if>
                    <if test="locationId != null">location_id,</if>
                    <if test="specification != null">specification,</if>
                    <if test="unit != null">unit,</if>
                    <if test="storageId != null">storage_id,</if>
                    <if test="storageShortName != null">storage_short_name,</if>
                    <if test="shelvesNum != null">shelves_num,</if>
                    <if test="goodsNum != null">goods_num,</if>
                    <if test="callShelvesNum != null">call_shelves_num,</if>
                    <if test="remark != null">remark,</if>
                    <if test="price != null">price,</if>
                    <if test="goodsTypeId != null">goods_type_id,</if>
                    <if test="providerId != null">provider_id,</if>
                    <if test="recoil != null">recoil,</if>
                    <if test="storageAreaId != null">storage_area_id,</if>
                    <if test="pickNum != null">pick_num,</if>
                    <if test="trNum != null">tr_num,</if>
                    <if test="barcode != null">barcode,</if>
                    <if test="status != null">status,</if>
                    <if test="toLoc != null">to_loc,</if>
                    <if test="confirmStatus != null">confirm_status,</if>
                    <if test="expiryDate != null">expiry_date,</if>
                    <if test="stockNum != null">stock_num,</if>
                    <if test="taskId != null">task_id,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="abc != null">abc,</if>
                    <if test="levelType != null">level_type,</if>
                    <if test="supplier != null">supplier,</if>
                    <if test="applicant != null">applicant,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="updateBy != null">update_by,</if>
                    <if test="deliveryId != null">delivery_id,</if>
                    <if test="ckType != null">ck_type,</if>
                    <if test="orderType != null">order_type,</if>
                    <if test="ctl != null">ctl,</if>
                    <if test="toMoney != null">to_money,</if>
                    <if test="batchNo != null">batch_no,</if>
                    <if test="original != null">original,</if>
                    <if test="goodsTo != null">goods_to,</if>
                    <if test="auditMan != null">audit_man,</if>
                    <if test="auditDate != null">audit_date,</if>
                    <if test="rejectReason != null">reject_reason,</if>
            </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},</if>
                    <if test="orderId != null and orderId != ''">#{orderId},</if>
                    <if test="businessId != null">#{businessId},</if>
                    <if test="goodsId != null">#{goodsId},</if>
                    <if test="goodsName != null">#{goodsName},</if>
                    <if test="locationId != null">#{locationId},</if>
                    <if test="specification != null">#{specification},</if>
                    <if test="unit != null">#{unit},</if>
                    <if test="storageId != null">#{storageId},</if>
                    <if test="storageShortName != null">#{storageShortName},</if>
                    <if test="shelvesNum != null">#{shelvesNum},</if>
                    <if test="goodsNum != null">#{goodsNum},</if>
                    <if test="callShelvesNum != null">#{callShelvesNum},</if>
                    <if test="remark != null">#{remark},</if>
                    <if test="price != null">#{price},</if>
                    <if test="goodsTypeId != null">#{goodsTypeId},</if>
                    <if test="providerId != null">#{providerId},</if>
                    <if test="recoil != null">#{recoil},</if>
                    <if test="storageAreaId != null">#{storageAreaId},</if>
                    <if test="pickNum != null">#{pickNum},</if>
                    <if test="trNum != null">#{trNum},</if>
                    <if test="barcode != null">#{barcode},</if>
                    <if test="status != null">#{status},</if>
                    <if test="toLoc != null">#{toLoc},</if>
                    <if test="confirmStatus != null">#{confirmStatus},</if>
                    <if test="expiryDate != null">#{expiryDate},</if>
                    <if test="stockNum != null">#{stockNum},</if>
                    <if test="taskId != null">#{taskId},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="abc != null">#{abc},</if>
                    <if test="levelType != null">#{levelType},</if>
                    <if test="supplier != null">#{supplier},</if>
                    <if test="applicant != null">#{applicant},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="updateBy != null">#{updateBy},</if>
                    <if test="deliveryId != null">#{deliveryId},</if>
                    <if test="ckType != null">#{ckType},</if>
                    <if test="orderType != null">#{orderType},</if>
                    <if test="ctl != null">#{ctl},</if>
                    <if test="toMoney != null">#{toMoney},</if>
                    <if test="batchNo != null">#{batchNo},</if>
                    <if test="original != null">#{original},</if>
                    <if test="goodsTo != null">#{goodsTo},</if>
                    <if test="auditMan != null">#{auditMan},</if>
                    <if test="auditDate != null">#{auditDate},</if>
                    <if test="rejectReason != null">#{rejectReason},</if>
            </trim>
    </insert>

    <update id="updateTckOrderdetailBak" parameterType="TckXnOrderdetailBak">
        update t_ck_xn_orderdetail_bak
        <trim prefix="SET" suffixOverrides=",">
                    <if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
                    <if test="businessId != null">business_id = #{businessId},</if>
                    <if test="goodsId != null">goods_id = #{goodsId},</if>
                    <if test="goodsName != null">goods_name = #{goodsName},</if>
                    <if test="locationId != null">location_id = #{locationId},</if>
                    <if test="specification != null">specification = #{specification},</if>
                    <if test="unit != null">unit = #{unit},</if>
                    <if test="storageId != null">storage_id = #{storageId},</if>
                    <if test="storageShortName != null">storage_short_name = #{storageShortName},</if>
                    <if test="shelvesNum != null">shelves_num = #{shelvesNum},</if>
                    <if test="goodsNum != null">goods_num = #{goodsNum},</if>
                    <if test="callShelvesNum != null">call_shelves_num = #{callShelvesNum},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="price != null">price = #{price},</if>
                    <if test="goodsTypeId != null">goods_type_id = #{goodsTypeId},</if>
                    <if test="providerId != null">provider_id = #{providerId},</if>
                    <if test="recoil != null">recoil = #{recoil},</if>
                    <if test="storageAreaId != null">storage_area_id = #{storageAreaId},</if>
                    <if test="pickNum != null">pick_num = #{pickNum},</if>
                    <if test="trNum != null">tr_num = #{trNum},</if>
                    <if test="barcode != null">barcode = #{barcode},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="toLoc != null">to_loc = #{toLoc},</if>
                    <if test="confirmStatus != null">confirm_status = #{confirmStatus},</if>
                    <if test="expiryDate != null">expiry_date = #{expiryDate},</if>
                    <if test="stockNum != null">stock_num = #{stockNum},</if>
                    <if test="taskId != null">task_id = #{taskId},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="abc != null">abc = #{abc},</if>
                    <if test="levelType != null">level_type = #{levelType},</if>
                    <if test="supplier != null">supplier = #{supplier},</if>
                    <if test="applicant != null">applicant = #{applicant},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="deliveryId != null">delivery_id = #{deliveryId},</if>
                    <if test="ckType != null">ck_type = #{ckType},</if>
                    <if test="orderType != null">order_type = #{orderType},</if>
                    <if test="ctl != null">ctl = #{ctl},</if>
                    <if test="toMoney != null">to_money = #{toMoney},</if>
                    <if test="batchNo != null">batch_no = #{batchNo},</if>
                    <if test="original != null">original = #{original},</if>
                    <if test="goodsTo != null">goods_to = #{goodsTo},</if>
                    <if test="auditMan != null">audit_man = #{auditMan},</if>
                    <if test="auditDate != null">audit_date = #{auditDate},</if>
                    <if test="rejectReason != null">reject_reason = #{deptId},</if>
            </trim>
        where id = #{id}
    </update>

    <update id="enableTckOrderdetailBakByIds" parameterType="String">
        update t_ck_xn_orderdetail_bak set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTckOrderdetailBakByIds" parameterType="String">
        update t_ck_xn_orderdetail_bak set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTckOrderdetailBakById" parameterType="String">
        delete from t_ck_xn_orderdetail_bak  where id = #{id}
    </delete>

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