<?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.TCkOrdersMapper">

    <resultMap type="TCkOrders" id="TCkOrdersResult">
            <result property="id"    column="id"    />
            <result property="orderId"    column="order_id"    />
            <result property="deliveryId"    column="delivery_id"    />
            <result property="storageId"    column="storage_id"    />
            <result property="storageAreaId"    column="storage_area_id"    />
            <result property="ckType"    column="ck_type"    />
            <result property="deliveryMethod"    column="delivery_method"    />
            <result property="remark"    column="remark"    />
            <result property="status"    column="status"    />
            <result property="createBy"    column="create_by"    />
            <result property="isAudit"    column="is_audit"    />
            <result property="auditMan"    column="audit_man"    />
            <result property="auditDate"    column="audit_date"    />
            <result property="rejectReason"    column="reject_reason"    />
            <result property="orderSource"    column="order_source"    />
            <result property="outStand"    column="out_stand"    />
            <result property="orderType"    column="order_type"    />
            <result property="confirmStatus"    column="confirm_status"    />
            <result property="recordPerson"    column="record_person"    />
            <result property="applicant"    column="applicant"    />
            <result property="recordDate"    column="record_date"    />
            <result property="productId"    column="product_id"    />
            <result property="stationId"    column="station_id"    />
            <result property="taskId"    column="task_id"    />
            <result property="orderDate"    column="order_date"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateTime"    column="update_time"    />
            <result property="updateBy"    column="update_by"    />
            <result property="deptId"    column="dept_id"    />
            <result property="code"    column="code"    />
            <result property="errMsg"    column="err_msg"    />
            <result property="instanceId"    column="instance_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="why"    column="why"    />
    </resultMap>

        <resultMap id="TCkOrdersTCkOrderdetailResult" type="TCkOrders" extends="TCkOrdersResult">
            <collection property="tckOrderdetailList" notNullColumn="sub_id" javaType="java.util.List" resultMap="TCkOrderdetailResult" />
        </resultMap>

        <resultMap type="TCkOrderdetail" id="TCkOrderdetailResult">
                <result property="id"    column="sub_id"    />
                <result property="orderId"    column="sub_order_id"    />
                <result property="businessId"    column="sub_business_id"    />
                <result property="goodsId"    column="sub_goods_id"    />
                <result property="goodsName"    column="sub_goods_name"    />
                <result property="locationId"    column="sub_location_id"    />
                <result property="specification"    column="sub_specification"    />
                <result property="unit"    column="sub_unit"    />
                <result property="storageId"    column="sub_storage_id"    />
                <result property="storageShortName"   column="sub_storage_short_name"/>
                <result property="shelvesNum"    column="sub_shelves_num"    />
                <result property="goodsNum"    column="sub_goods_num"    />
                <result property="callShelvesNum"    column="sub_call_shelves_num"    />
                <result property="remark"    column="sub_remark"    />
                <result property="price"    column="sub_price"    />
                <result property="goodsTypeId"    column="sub_goods_type_id"    />
                <result property="providerId"    column="sub_provider_id"    />
                <result property="recoil"    column="sub_recoil"    />
                <result property="storageAreaId"    column="sub_storage_area_id"    />
                <result property="pickNum"    column="sub_pick_num"    />
                <result property="trNum"    column="sub_tr_num"    />
                <result property="barcode"    column="sub_barcode"    />
                <result property="status"    column="sub_status"    />
                <result property="toLoc"    column="sub_to_loc"    />
                <result property="confirmStatus"    column="sub_confirm_status"    />
                <result property="expiryDate"    column="sub_expiry_date"    />
                <result property="stockNum"    column="sub_stock_num"    />
                <result property="taskId"    column="sub_task_id"    />
                <result property="updateTime"    column="sub_update_time"    />
                <result property="abc"    column="sub_abc"    />
                <result property="levelType"    column="sub_level_type"    />
                <result property="applicant"    column="sub_applicant"    />
                <result property="supplier"    column="sub_supplier"    />
                <result property="createTime"    column="sub_create_time"    />
                <result property="createBy"    column="sub_create_by"    />
                <result property="updateBy"    column="sub_update_by"    />
                <result property="deliveryId"    column="sub_delivery_id"    />
                <result property="ckType"    column="sub_ck_type"    />
                <result property="orderType"    column="sub_order_type"    />
                <result property="ctl"    column="sub_ctl"    />
                <result property="toMoney"    column="sub_to_money"    />
                <result property="batchNo"    column="sub_batch_no"    />
                <result property="original"    column="sub_original"    />
                <result property="goodsTo"    column="sub_goods_to"    />

        </resultMap>

    <sql id="selectTCkOrdersVo">
        select id, order_id,delivery_id,why,dept_name, storage_short_name,storage_id, storage_area_id, ck_type, delivery_method, remark, status, create_by, is_audit, audit_man, audit_date,reject_reason, order_source, out_stand, order_type, confirm_status, record_person, applicant, record_date, product_id, station_id, task_id, order_date, create_time, update_time, update_by,dept_id,is_avg_exec,code,err_msg,instance_id from t_ck_orders d
    </sql>
    <select id="get" parameterType="TCkOrders" resultMap="TCkOrdersResult">
        <include refid="selectTCkOrdersVo"/>
        where id = #{id}
    </select>
    <select id="queryTotalCallShelvesNum" parameterType="TCkOrderdetail" resultType="java.lang.Long">
        select sum(b.call_shelves_num)
        from t_ck_orders a left  join  t_ck_orderdetail b on b.order_id = a.id
        <where>
            a.is_audit &lt;&gt; '0'
            <if test="storageId != null and storageId != ''">
                and b.storage_id = #{storageId}
            </if>
            <if test="goodsId != null and goodsId != ''">
                and b.goods_id = #{goodsId}
            </if>
            <if test="ctl != null and ctl != ''">
                and b.ctl = #{ctl}
            </if>
           and  (a.remark IS NULL OR a.remark = 'agree')
        </where>
    </select>
    <select id="selectTCkOrdersList" parameterType="TCkOrders" resultMap="TCkOrdersResult">
        <include refid="selectTCkOrdersVo"/>
        <where>
            <if test="orderId != null  and orderId != ''"> and order_id like concat('%', #{orderId}, '%')</if>
            <if test="deliveryId != null  and deliveryId != ''"> and delivery_id like concat('%', #{deliveryId}, '%') </if>
            <if test="storageId != null  and storageId != ''"> and storage_id = #{storageId}</if>
            <if test="storageAreaId != null  and storageAreaId != ''"> and storage_area_id = #{storageAreaId}</if>
            <if test="ckType != null  and ckType != ''"> and ck_type = #{ckType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="auditMan != null  and auditMan != ''"> and audit_man = #{auditMan}</if>
            <if test="isAudit != null  and isAudit != ''"> and is_audit = #{isAudit}</if>
            <if test="applicant != null  and applicant != ''"> and applicant = #{applicant}</if>
            <if test="confirmStatus != null  and confirmStatus != ''"> and confirm_status = #{confirmStatus}</if>
            <if test="storageShortName != null  and storageShortName != ''"> and storage_short_name = #{storageShortName}</if>
            ${params.dataScope}
        </where>
        order by create_time desc
    </select>

    <select id="exportTCkOrdersList" parameterType="TCkOrders" resultMap="TCkOrdersTCkOrderdetailResult">
        select a.id, a.order_id,a.delivery_id, a.storage_id, a.storage_area_id, a.ck_type, a.delivery_method, a.remark, a.status, a.create_by, a.is_audit, a.audit_man, a.audit_date,a.reject_reason, a.order_source, a.out_stand, a.order_type, a.confirm_status, a.record_person, a.applicant, a.record_date, a.product_id, a.station_id, a.task_id, a.order_date, a.create_time, a.update_time, a.update_by,a.dept_id,a.is_avg_exec,a.code,a.err_msg,a.instance_id,
               b.id as sub_id, b.order_id as sub_order_id, b.ctl as sub_ctl, b.business_id as sub_business_id, b.goods_id as sub_goods_id, b.goods_name as sub_goods_name, b.location_id as sub_location_id, b.specification as sub_specification, b.unit as sub_unit, b.storage_id as sub_storage_id,b.storage_short_name as sub_storage_short_name, b.shelves_num as sub_shelves_num, b.goods_num as sub_goods_num, b.call_shelves_num as sub_call_shelves_num, b.remark as sub_remark, b.price as sub_price, b.goods_type_id as sub_goods_type_id, b.provider_id as sub_provider_id, b.recoil as sub_recoil, b.storage_area_id as sub_storage_area_id, b.pick_num as sub_pick_num, b.tr_num as sub_tr_num, b.barcode as sub_barcode, b.status as sub_status, b.to_loc as sub_to_loc, b.confirm_status as sub_confirm_status, b.expiry_date as sub_expiry_date, b.stock_num as sub_stock_num, b.task_id as sub_task_id, b.update_time as sub_update_time,b.abc as sub_abc,b.level_type as sub_level_type,
               b.supplier as sub_supplier,b.applicant as sub_applicant,b.create_time as sub_create_time,b.create_by  as sub_create_by,b.update_by as sub_update_by,b.create_time as sub_create_time,b.delivery_id as sub_delivery_id,b.ck_type as sub_ck_type,b.order_type as sub_order_type,b.ctl as sub_ctl, b.to_money as sub_to_money,b.batch_no as sub_batch_no,b.original as sub_original,b.goods_to as sub_goods_to
          from t_ck_orders a
               left join t_ck_orderdetail b on b.order_id = a.id
        <where>
            <if test="orderId != null  and orderId != ''"> and a.order_id like concat('%', #{orderId}, '%')</if>
            <if test="deliveryId != null  and deliveryId != ''"> and a.delivery_id = #{deliveryId}</if>
            <if test="storageId != null  and storageId != ''"> and a.storage_id = #{storageId}</if>
            <if test="storageAreaId != null  and storageAreaId != ''"> and a.storage_area_id = #{storageAreaId}</if>
            <if test="ckType != null  and ckType != ''"> and a.ck_type = #{ckType}</if>
            <if test="status != null  and status != ''"> and a.status = #{status}</if>
            <if test="auditMan != null  and auditMan != ''"> and a.audit_man = #{auditMan}</if>
            <if test="isAudit != null  and isAudit != ''"> and a.is_audit = #{isAudit}</if>
            ${params.dataScope}
        </where>
    </select>

    <select id="selectTCkOrdersById" parameterType="String" resultMap="TCkOrdersTCkOrderdetailResult">
            select a.id, a.order_id,a.delivery_id, a.storage_id, a.storage_area_id, a.ck_type, a.delivery_method, a.remark, a.status, a.create_by, a.is_audit, a.audit_man, a.audit_date,a.reject_reason, a.order_source, a.out_stand, a.order_type, a.confirm_status, a.record_person, a.applicant, a.record_date, a.product_id, a.station_id, a.task_id, a.order_date, a.create_time, a.update_time, a.update_by,a.dept_id,a.is_avg_exec,a.code,a.err_msg,a.instance_id,
 b.id as sub_id, b.order_id as sub_order_id, b.ctl as sub_ctl, b.storage_short_name as sub_storage_short_name, b.business_id as sub_business_id, b.goods_id as sub_goods_id, b.goods_name as sub_goods_name, b.location_id as sub_location_id, b.specification as sub_specification, b.unit as sub_unit, b.storage_id as sub_storage_id, b.shelves_num as sub_shelves_num, b.goods_num as sub_goods_num, b.call_shelves_num as sub_call_shelves_num, b.remark as sub_remark, b.price as sub_price, b.goods_type_id as sub_goods_type_id, b.provider_id as sub_provider_id, b.recoil as sub_recoil, b.storage_area_id as sub_storage_area_id, b.pick_num as sub_pick_num, b.tr_num as sub_tr_num, b.barcode as sub_barcode, b.status as sub_status, b.to_loc as sub_to_loc, b.confirm_status as sub_confirm_status, b.expiry_date as sub_expiry_date, b.stock_num as sub_stock_num, b.task_id as sub_task_id, b.update_time as sub_update_time,b.abc as sub_abc,b.level_type as sub_level_type,
            b.supplier as sub_supplier,b.applicant as sub_applicant,b.create_time as sub_create_time,b.create_by  as sub_create_by,b.update_by as sub_update_by,b.create_time as sub_create_time,b.delivery_id as sub_delivery_id,b.ck_type as sub_ck_type,b.order_type as sub_order_type,b.ctl as sub_ctl, b.to_money as sub_to_money,b.batch_no as sub_batch_no,b.original as sub_original,b.goods_to as sub_goods_to
            from t_ck_orders a
            left join t_ck_orderdetail b on b.order_id = a.id
            where a.id = #{id}
    </select>



    <select id="selectOnes" parameterType="String" resultMap="TCkOrdersTCkOrderdetailResult">
        select a.id, a.order_id,a.delivery_id, a.storage_id, a.storage_area_id, a.ck_type, a.delivery_method, a.remark, a.status, a.create_by, a.is_audit, a.audit_man, a.audit_date,a.reject_reason, a.order_source, a.out_stand, a.order_type, a.confirm_status, a.record_person, a.applicant, a.record_date, a.product_id, a.station_id, a.task_id, a.order_date, a.create_time, a.update_time, a.update_by,a.dept_id,a.is_avg_exec,a.code,a.err_msg,a.instance_id,
               b.id as sub_id, b.order_id as sub_order_id, b.ctl as sub_ctl, b.business_id as sub_business_id, b.storage_short_name as sub_storage_short_name, b.goods_id as sub_goods_id, b.goods_name as sub_goods_name, b.location_id as sub_location_id, b.specification as sub_specification, b.unit as sub_unit, b.storage_id as sub_storage_id, b.shelves_num as sub_shelves_num, b.goods_num as sub_goods_num, b.call_shelves_num as sub_call_shelves_num, b.remark as sub_remark, b.price as sub_price, b.goods_type_id as sub_goods_type_id, b.provider_id as sub_provider_id, b.recoil as sub_recoil, b.storage_area_id as sub_storage_area_id, b.pick_num as sub_pick_num, b.tr_num as sub_tr_num, b.barcode as sub_barcode, b.status as sub_status, b.to_loc as sub_to_loc, b.confirm_status as sub_confirm_status, b.expiry_date as sub_expiry_date, b.stock_num as sub_stock_num, b.task_id as sub_task_id, b.update_time as sub_update_time,b.abc as sub_abc,b.level_type as sub_level_type,
               b.supplier as sub_supplier,b.applicant as sub_applicant,b.create_time as sub_create_time,b.create_by  as sub_create_by,b.update_by as sub_update_by,b.create_time as sub_create_time,b.delivery_id as sub_delivery_id,b.ck_type as sub_ck_type,b.order_type as sub_order_type,b.ctl as sub_ctl, b.to_money as sub_to_money,b.batch_no as sub_batch_no,b.original as sub_original,b.goods_to as sub_goods_to
        from t_ck_orders a
                 left join t_ck_orderdetail b on b.order_id = a.id
        where a.id = #{id}
    </select>

    <select id="selectTCkOrdersByOrderId" parameterType="String" resultMap="TCkOrdersTCkOrderdetailResult">
        select a.id, a.order_id,a.delivery_id, a.storage_id, a.storage_area_id, a.ck_type, a.delivery_method, a.remark, a.status, a.create_by, a.is_audit, a.audit_man, a.audit_date,a.reject_reason, a.order_source, a.out_stand, a.order_type, a.confirm_status, a.record_person, a.applicant, a.record_date, a.product_id, a.station_id, a.task_id, a.order_date, a.create_time, a.update_time, a.update_by,a.dept_id,a.is_avg_exec,a.code,a.err_msg,a.instance_id,
b.id as sub_id, b.order_id as sub_order_id, b.ctl as sub_ctl,b.storage_short_name as sub_storage_short_name, b.business_id as sub_business_id, b.goods_id as sub_goods_id, b.goods_name as sub_goods_name, b.location_id as sub_location_id, b.specification as sub_specification, b.unit as sub_unit, b.storage_id as sub_storage_id, b.shelves_num as sub_shelves_num, b.goods_num as sub_goods_num, b.call_shelves_num as sub_call_shelves_num, b.remark as sub_remark, b.price as sub_price, b.goods_type_id as sub_goods_type_id, b.provider_id as sub_provider_id, b.recoil as sub_recoil, b.storage_area_id as sub_storage_area_id, b.pick_num as sub_pick_num, b.tr_num as sub_tr_num, b.barcode as sub_barcode, b.status as sub_status, b.to_loc as sub_to_loc, b.confirm_status as sub_confirm_status, b.expiry_date as sub_expiry_date, b.stock_num as sub_stock_num, b.task_id as sub_task_id, b.update_time as sub_update_time,b.abc as sub_abc,b.level_type as sub_level_type,
        b.supplier as sub_supplier,b.applicant as sub_applicant,b.create_time as sub_create_time,b.create_by  as sub_create_by,b.update_by as sub_update_by,b.create_time as sub_create_time,b.delivery_id as sub_delivery_id,b.ck_type as sub_ck_type,b.order_type as sub_order_type,b.ctl as sub_ctl, b.to_money as sub_to_money,b.batch_no as sub_batch_no,b.original as sub_original,b.goods_to as sub_goods_to
        from t_ck_orders a
        left join t_ck_orderdetail b on b.order_id = a.id and b.shelves_num != b.pick_num
        where a.order_id = #{id}
</select>

<select id="selectTCkOrdersByDeliveryId" parameterType="String" resultMap="TCkOrdersTCkOrderdetailResult">
    select a.id, a.order_id,a.delivery_id, a.storage_id, a.storage_area_id, a.ck_type, a.delivery_method, a.remark, a.status, a.create_by, a.is_audit, a.audit_man, a.audit_date,a.reject_reason, a.order_source, a.out_stand, a.order_type, a.confirm_status, a.record_person, a.applicant, a.record_date, a.product_id, a.station_id, a.task_id, a.order_date, a.create_time, a.update_time, a.update_by,a.dept_id,a.is_avg_exec,a.code,a.err_msg,a.instance_id,
b.id as sub_id, b.order_id as sub_order_id, b.ctl as sub_ctl,b.storage_short_name as sub_storage_short_name, b.business_id as sub_business_id, b.goods_id as sub_goods_id, b.goods_name as sub_goods_name, b.location_id as sub_location_id, b.specification as sub_specification, b.unit as sub_unit, b.storage_id as sub_storage_id, b.shelves_num as sub_shelves_num, b.goods_num as sub_goods_num, b.call_shelves_num as sub_call_shelves_num, b.remark as sub_remark, b.price as sub_price, b.goods_type_id as sub_goods_type_id, b.provider_id as sub_provider_id, b.recoil as sub_recoil, b.storage_area_id as sub_storage_area_id, b.pick_num as sub_pick_num, b.tr_num as sub_tr_num, b.barcode as sub_barcode, b.status as sub_status, b.to_loc as sub_to_loc, b.confirm_status as sub_confirm_status, b.expiry_date as sub_expiry_date, b.stock_num as sub_stock_num, b.task_id as sub_task_id, b.update_time as sub_update_time,b.abc as sub_abc,b.level_type as sub_level_type,
    b.supplier as sub_supplier,b.applicant as sub_applicant,b.create_time as sub_create_time,b.create_by  as sub_create_by,b.update_by as sub_update_by,b.create_time as sub_create_time,b.delivery_id as sub_delivery_id,b.ck_type as sub_ck_type,b.order_type as sub_order_type,b.ctl as sub_ctl, b.to_money as sub_to_money,b.batch_no as sub_batch_no,b.original as sub_original,b.goods_to as sub_goods_to
    from t_ck_orders a
    left join t_ck_orderdetail b on b.order_id = a.id
    where a.delivery_id = #{id}
</select>

    <insert id="insertTCkOrders" parameterType="TCkOrders">
        insert into t_ck_orders
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,</if>
                    <if test="orderId != null and orderId != ''">order_id,</if>
                    <if test="deliveryId != null">delivery_id,</if>
                    <if test="storageId != null">storage_id,</if>
                    <if test="storageAreaId != null">storage_area_id,</if>
                    <if test="ckType != null">ck_type,</if>
                    <if test="deliveryMethod != null">delivery_method,</if>
                    <if test="remark != null">remark,</if>
                    <if test="status != null">status,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="isAudit != null">is_audit,</if>
                    <if test="auditMan != null">audit_man,</if>
                    <if test="auditDate != null">audit_date,</if>
                    <if test="rejectReason != null">reject_reason,,</if>
                    <if test="orderSource != null">order_source,</if>
                    <if test="outStand != null">out_stand,</if>
                    <if test="orderType != null">order_type,</if>
                    <if test="confirmStatus != null">confirm_status,</if>
                    <if test="recordPerson != null">record_person,</if>
                    <if test="applicant != null">applicant,</if>
                    <if test="recordDate != null">record_date,</if>
                    <if test="productId != null">product_id,</if>
                    <if test="stationId != null">station_id,</if>
                    <if test="taskId != null">task_id,</if>
                    <if test="orderDate != null">order_date,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="updateBy != null">update_by,</if>
                    <if test="deptId != null">dept_id,</if>
                    <if test="isAvgExec != null">is_avg_exec,</if>
                    <if test="code != null">code,</if>
                    <if test="errMsg != null">err_msg,</if>
                    <if test="instanceId != null">instance_id,</if>
                    <if test="deptName != null">dept_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},</if>
                    <if test="orderId != null and orderId != ''">#{orderId},</if>
                    <if test="deliveryId != null">#{deliveryId},</if>
                    <if test="storageId != null">#{storageId},</if>
                    <if test="storageAreaId != null">#{storageAreaId},</if>
                    <if test="ckType != null">#{ckType},</if>
                    <if test="deliveryMethod != null">#{deliveryMethod},</if>
                    <if test="remark != null">#{remark},</if>
                    <if test="status != null">#{status},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="isAudit != null">#{isAudit},</if>
                    <if test="auditMan != null">#{auditMan},</if>
                    <if test="auditDate != null">#{auditDate},</if>
                    <if test="rejectReason != null">#{rejectReason},</if>
                    <if test="orderSource != null">#{orderSource},</if>
                    <if test="outStand != null">#{outStand},</if>
                    <if test="orderType != null">#{orderType},</if>
                    <if test="confirmStatus != null">#{confirmStatus},</if>
                    <if test="recordPerson != null">#{recordPerson},</if>
                    <if test="applicant != null">#{applicant},</if>
                    <if test="recordDate != null">#{recordDate},</if>
                    <if test="productId != null">#{productId},</if>
                    <if test="stationId != null">#{stationId},</if>
                    <if test="taskId != null">#{taskId},</if>
                    <if test="orderDate != null">#{orderDate},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="updateBy != null">#{updateBy},</if>
                    <if test="deptId != null">#{deptId},</if>
                    <if test="isAvgExec != null">#{isAvgExec},</if>
                    <if test="code != null">#{code},</if>
                    <if test="errMsg != null">#{errMsg},</if>
                    <if test="instanceId != null">#{instanceId},</if>
                    <if test="deptName != null">#{deptName},</if>
        </trim>
    </insert>

    <update id="updateTCkOrders" parameterType="TCkOrders">
        update t_ck_orders
        <trim prefix="SET" suffixOverrides=",">
                    <if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
                    <if test="deliveryId != null">delivery_id = #{deliveryId},</if>
                    <if test="storageId != null">storage_id = #{storageId},</if>
                    <if test="storageAreaId != null">storage_area_id = #{storageAreaId},</if>
                    <if test="ckType != null">ck_type = #{ckType},</if>
                    <if test="deliveryMethod != null">delivery_method = #{deliveryMethod},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="isAudit != null">is_audit = #{isAudit},</if>
                    <if test="auditMan != null">audit_man = #{auditMan},</if>
                    <if test="auditDate != null">audit_date = #{auditDate},</if>
                    <if test="rejectReason != null">reject_reason = #{rejectReason},</if>
                    <if test="orderSource != null">order_source = #{orderSource},</if>
                    <if test="outStand != null">out_stand = #{outStand},</if>
                    <if test="orderType != null">order_type = #{orderType},</if>
                    <if test="confirmStatus != null">confirm_status = #{confirmStatus},</if>
                    <if test="recordPerson != null">record_person = #{recordPerson},</if>
                    <if test="applicant != null">applicant = #{applicant},</if>
                    <if test="recordDate != null">record_date = #{recordDate},</if>
                    <if test="productId != null">product_id = #{productId},</if>
                    <if test="stationId != null">station_id = #{stationId},</if>
                    <if test="taskId != null">task_id = #{taskId},</if>
                    <if test="orderDate != null">order_date = #{orderDate},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="deptId != null">dept_id = #{deptId},</if>
                    <if test="isAvgExec != null">is_avg_exec = #{isAvgExec},</if>
                    <if test="code != null">code = #{code},</if>
                    <if test="errMsg != null">err_msg = #{errMsg},</if>
                    <if test="instanceId != null">instance_id = #{instanceId},</if>
            <if test="why != null">why = #{why},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTCkOrdersByIds" parameterType="String">
        update t_ck_orders set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTCkOrdersByIds" parameterType="String">
        update t_ck_orders set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="auditTCkOrdersByIds" parameterType="String">
        update t_ck_orders set is_audit=1, audit_man=#{auditMan}, audit_date=#{auditDate} where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <delete id="deleteTCkOrdersById" parameterType="String">
        delete from t_ck_orders  where id = #{id}
    </delete>

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

        <delete id="deleteTCkOrderdetailByOrderIds" parameterType="String">
            delete from t_ck_orderdetail where order_id in
            <foreach item="orderId" collection="array" open="(" separator="," close=")">
                #{orderId}
            </foreach>
        </delete>

        <delete id="deleteTCkOrderdetailByOrderId" parameterType="String">
            delete from t_ck_orderdetail where order_id = #{orderId}
        </delete>

        <insert id="batchTCkOrderdetail">
            insert into t_ck_orderdetail( id, order_id, business_id, goods_id, goods_name, location_id, specification, unit, storage_id, 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,supplier,applicant,create_time,create_by,update_by,delivery_id,ck_type,order_type,ctl,to_money,batch_no,original,goods_to) values
            <foreach item="item" index="index" collection="list" separator=",">
                ( #{item.id}, #{item.orderId}, #{item.businessId}, #{item.goodsId}, #{item.goodsName}, #{item.locationId}, #{item.specification}, #{item.unit}, #{item.storageId}, #{item.shelvesNum}, #{item.goodsNum}, #{item.callShelvesNum}, #{item.remark}, #{item.price}, #{item.goodsTypeId}, #{item.providerId}, #{item.recoil}, #{item.storageAreaId}, #{item.pickNum}, #{item.trNum}, #{item.barcode}, #{item.status}, #{item.toLoc}, #{item.confirmStatus}, #{item.expiryDate}, #{item.stockNum}, #{item.taskId}, #{item.updateTime}, #{item.abc}, #{item.levelType},#{item.supplier},#{item.applicant},#{item.createTime},#{item.createBy},#{item.updateBy},#{item.deliveryId},#{item.ckType},#{item.orderType},#{item.ctl},#{item.toMoney},#{item.batchNo},#{item.original},#{item.goodsTo})
            </foreach>
        </insert>
    <update id="updateConfirmStatus" parameterType="TCkOrders">
        update t_ck_orders set confirm_status = #{confirmStatus} where id = #{id}
    </update>
    <update id="updateResultCode" parameterType="TCkOrders">
        update t_ck_orders set code = #{code},err_msg=#{errMsg} where order_id = #{id}
    </update>
    <select id="homeCount" parameterType="TCkOrders" resultType="int">
        SELECT COUNT(*)
        FROM t_ck_orders d
        <where>
            ${params.dataScope}
        </where>

    </select>
</mapper>
