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

    <resultMap type="TMiStock" id="TMiStockResult">
        <result property="id" column="id"/>
        <result property="storageId" column="storage_id"/>
        <result property="storageAreaId" column="storage_area_id"/>
        <result property="locationId" column="location_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="shelvesNum" column="shelves_num"/>
        <result property="remark" column="remark"/>
        <result property="version" column="version"/>
        <result property="storageMode" column="storage_mode"/>
        <result property="providerId" column="provider_id"/>
        <result property="productionDate" column="production_date"/>
        <result property="wareDate" column="ware_date"/>
        <result property="doctNumber" column="doct_number"/>
        <result property="goodsVolume" column="goods_volume"/>
        <result property="occupyNum" column="occupy_num"/>
        <result property="noticeId" column="notice_id"/>
        <result property="oriBill" column="ori_bill"/>
        <result property="ctl" column="ctl"/>
        <result property="barcode" column="barcode"/>
        <result property="wgh" column="wgh"/>
        <result property="high" column="high"/>
        <result property="goodsName" column="goods_name"/>
        <result property="status" column="status"/>
        <result property="customerId" column="customer_id"/>
        <result property="batchNo" column="batch_no"/>
        <result property="dueDate" column="due_date"/>
        <result property="checkDate" column="check_date"/>
        <result property="standard" column="standard"/>
        <result property="flag" column="flag"/>
        <result property="mark" column="mark"/>
        <result property="orderNum" column="order_num"/>
        <result property="problem" column="problem"/>
        <result property="price" column="price"/>
        <result property="packingNum" column="packing_num"/>
        <result property="boxType" column="box_type"/>
        <result property="scaleUnit" column="scale_unit"/>
        <result property="goodsSku" column="goods_sku"/>
        <result property="factoryId" column="factory_id"/>
        <result property="salesOrderNo" column="sales_order_no"/>
        <result property="salesOrderNumber" column="sales_order_number"/>
        <result property="supplier" column="supplier"/>
        <result property="onOrder" column="on_order"/>
        <result property="recordPerson" column="record_person"/>
        <result property="lotId" column="lot_id"/>
        <result property="decid" column="decid"/>
        <result property="unit" column="unit"/>
        <result property="specification" column="specification"/>
        <result property="goodsAge" column="goods_age"/>
        <result property="arraMount" column="arra_mount"/>
        <result property="recoil" column="recoil"/>
        <result property="operatorId" column="operator_id"/>
        <result property="operateDate" column="operate_date"/>
        <result property="purchaseId" column="purchase_id"/>
        <result property="applicant" column="applicant"/>
        <result property="respDept" column="resp_dept"/>
        <result property="planDate" column="plan_date"/>
        <result property="planTime" column="plan_time"/>
        <result property="needCycle" column="need_cycle"/>
        <result property="needType" column="need_type"/>
        <result property="goodsTypeId" column="goods_type_id"/>
        <result property="brand" column="brand"/>
        <result property="totalMoney" column="total_money"/>
        <result property="expiryDate" column="expiry_date"/>
        <result property="providerName" column="provider_name"/>
        <result property="receiver" column="receiver"/>
        <result property="needDept" column="need_dept"/>
        <result property="purchaseDept" column="purchase_dept"/>
        <result property="produclotId" column="produclot_id"/>
        <result property="receiverDept" column="receiver_dept"/>
        <result property="receivingArea" column="receiving_area"/>
        <result property="packageId" column="package_id"/>
        <result property="useType" column="use_type"/>
        <result property="telephone" column="telephone"/>
        <result property="totalVolume" column="total_volume"/>
        <result property="totalRoughWeight" column="total_rough_weight"/>
        <result property="totalNetWeigh" column="total_net_weigh"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="defaultStorageAreaId" column="default_storage_area_id"/>
        <result property="qualityInspecStatus" column="quality_inspec_status"/>
        <result property="periodUnit" column="period_unit"/>
        <result property="period" column="period"/>
        <result property="reportTime" column="report_time"/>
        <result property="consignment" column="consignment"/>
        <result property="deptId" column="dept_id"/>
        <result property="abc"    column="abc"    />
        <result property="levelType"    column="level_type"    />
        <result property="isFreeze"    column="is_freeze"    />
        <result property="storageShortName"    column="storage_short_name"    />
        <result property="needPerson"    column="need_person"    />
        <result property="needTel"    column="need_tel"    />
    </resultMap>

    <sql id="selectTMiStockVo">
        select id,
               storage_id,
               storage_area_id,
               location_id,
               goods_id,
               shelves_num,
               remark,
               version,
               storage_mode,
               provider_id,
               production_date,
               ware_date,
               doct_number,
               goods_volume,
               occupy_num,
               notice_id,
               ori_bill,
               ctl,
               barcode,
               wgh,
               high,
               goods_name,
               status,
               customer_id,
               batch_no,
               due_date,
               check_date,
               standard,
               flag,
               mark,
               order_num,
               problem,
               price,
               packing_num,
               box_type,
               scale_unit,
               goods_sku,
               factory_id,
               sales_order_no,
               sales_order_number,
               supplier,
               on_order,
               record_person,
               lot_id,
               decid,
               unit,
               specification,
               goods_age,
               arra_mount,
               recoil,
               operator_id,
               operate_date,
               purchase_id,
               applicant,
               resp_dept,
               plan_date,
               plan_time,
               need_cycle,
               need_type,
               goods_type_id,
               brand,
               total_money,
               expiry_date,
               provider_name,
               receiver,
               need_dept,
               purchase_dept,
               produclot_id,
               receiver_dept,
               receiving_area,
               package_id,
               use_type,
               telephone,
               total_volume,
               total_rough_weight,
               total_net_weigh,
               create_time,
               update_time,
               create_by,
               update_by,
               default_storage_area_id,
               quality_inspec_status,
               period_unit,
               period,
               report_time,
               consignment,
               dept_id,
               abc,
               level_type,
               is_freeze,
               storage_short_name,
               frost_man,
               need_person,
               need_tel
        from t_mi_stock d
    </sql>


    <select id="selectTMiStockList" parameterType="TMiStock" resultMap="TMiStockResult">
        <include refid="selectTMiStockVo"/>
        <where>
            <if test="storageAreaId != null and storageAreaId != ''">
                and storage_area_id like concat('%', #{storageAreaId}, '%')
            </if>
            <if test="locationId != null and locationId != ''">
                and location_id like concat('%', #{locationId}, '%')
            </if>
            <if test="goodsId != null and goodsId != ''">
                and goods_id like concat('%', #{goodsId}, '%')
            </if>

            <if test="productionDate != null">
                and production_date = #{productionDate}
            </if>
            <if test="startTime != null and endTime != ''">
                and ware_date BETWEEN #{startTime} AND #{endTime}
            </if>

            <if test="ctl != null and ctl != ''">
                and ctl like concat('%', #{ctl}, '%')
            </if>
            <if test="barcode != null and barcode != ''">
                and barcode like concat('%', #{barcode}, '%')
            </if>

            <if test="goodsName != null and goodsName != ''">
                and goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="status != null and status != ''">
                and status like concat('%', #{status}, '%')
            </if>

            <if test="levelType!=null and levelType!=''">
                and level_type= #{levelType}
            </if>

            <if test="specification != null and specification != ''">
                and specification like concat('%', #{specification}, '%')
            </if>

            <if test="recoil != null and recoil != ''">
                and recoil like concat('%', #{recoil}, '%')
            </if>

            <if test="applicant != null and applicant != ''">
                and applicant like concat('%', #{applicant}, '%')
            </if>

            <if test="needDept != null and needDept != ''">
                and need_dept like concat('%', #{needDept}, '%')
            </if>

            <if test="needPerson != null and needPerson != ''">
                and need_person like concat('%', #{needPerson}, '%')
            </if>


            <if test="salesOrderNumber != null and salesOrderNumber != ''">
                and sales_order_number like concat('%', #{salesOrderNumber}, '%')
            </if>
            <if test="useType != null and useType != ''">
                and use_type like concat('%', #{useType}, '%')
            </if>
            <if test="noticeId != null and noticeId != ''">
                and notice_id like concat('%', #{noticeId}, '%')
            </if>
            <if test="unit != null and unit != ''">
                and unit = #{unit}
            </if>
            <if test="price != null and price != ''">
                and price = #{price}
            </if>
            <if test="totalMoney != null and totalMoney != ''">
                and total_money = #{totalMoney}
            </if>






            <if test="isFreeze != null and isFreeze != ''">
                and is_freeze  = #{isFreeze}
            </if>
            <if test="overdueDate != null and overdueDate != ''">
                and ware_date &lt;= str_to_date(#{overdueDate},'%Y-%m-%d')
            </if>
            <choose>
                <when test="storageList != null and storageList.size > 0">
                    and storage_id in
                    <foreach item="storageId" collection="storageList" open="(" separator="," close=")">
                        #{storageId}
                    </foreach>
                </when>
                <when test="storageId != null and storageId != ''">
                    and storage_id = #{storageId}
                </when>
            </choose>
        </where>
        ORDER BY ware_date DESC
    </select>

    <select id="selectTMiStockById" parameterType="Long" resultMap="TMiStockResult">
        <include refid="selectTMiStockVo"/>
        where id = #{id}
    </select>

    <insert id="insertTMiStock" parameterType="TMiStock">
        insert into t_mi_stock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="storageId != null">storage_id,</if>
            <if test="storageAreaId != null">storage_area_id,</if>
            <if test="locationId != null">location_id,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="shelvesNum != null">shelves_num,</if>
            <if test="remark != null">remark,</if>
            <if test="version != null">version,</if>
            <if test="storageMode != null">storage_mode,</if>
            <if test="providerId != null">provider_id,</if>
            <if test="productionDate != null">production_date,</if>
            <if test="wareDate != null">ware_date,</if>
            <if test="doctNumber != null">doct_number,</if>
            <if test="goodsVolume != null">goods_volume,</if>
            <if test="occupyNum != null">occupy_num,</if>
            <if test="noticeId != null">notice_id,</if>
            <if test="oriBill != null">ori_bill,</if>
            <if test="ctl != null">ctl,</if>
            <if test="barcode != null">barcode,</if>
            <if test="wgh != null">wgh,</if>
            <if test="high != null">high,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="status != null">status,</if>
            <if test="customerId != null">customer_id,</if>
            <if test="batchNo != null">batch_no,</if>
            <if test="dueDate != null">due_date,</if>
            <if test="checkDate != null">check_date,</if>
            <if test="standard != null">standard,</if>
            <if test="flag != null">flag,</if>
            <if test="mark != null">mark,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="problem != null">problem,</if>
            <if test="price != null">price,</if>
            <if test="packingNum != null">packing_num,</if>
            <if test="boxType != null">box_type,</if>
            <if test="scaleUnit != null">scale_unit,</if>
            <if test="goodsSku != null">goods_sku,</if>
            <if test="factoryId != null">factory_id,</if>
            <if test="salesOrderNo != null">sales_order_no,</if>
            <if test="salesOrderNumber != null">sales_order_number,</if>
            <if test="supplier != null">supplier,</if>
            <if test="onOrder != null">on_order,</if>
            <if test="recordPerson != null">record_person,</if>
            <if test="lotId != null">lot_id,</if>
            <if test="decid != null">decid,</if>
            <if test="unit != null">unit,</if>
            <if test="specification != null">specification,</if>
            <if test="goodsAge != null">goods_age,</if>
            <if test="arraMount != null">arra_mount,</if>
            <if test="recoil != null">recoil,</if>
            <if test="operatorId != null">operator_id,</if>
            <if test="operateDate != null">operate_date,</if>
            <if test="purchaseId != null">purchase_id,</if>
            <if test="applicant != null">applicant,</if>
            <if test="respDept != null">resp_dept,</if>
            <if test="planDate != null">plan_date,</if>
            <if test="planTime != null">plan_time,</if>
            <if test="needCycle != null">need_cycle,</if>
            <if test="needType != null">need_type,</if>
            <if test="goodsTypeId != null">goods_type_id,</if>
            <if test="brand != null">brand,</if>
            <if test="totalMoney != null">total_money,</if>
            <if test="expiryDate != null">expiry_date,</if>
            <if test="providerName != null">provider_name,</if>
            <if test="receiver != null">receiver,</if>
            <if test="needDept != null">need_dept,</if>
            <if test="purchaseDept != null">purchase_dept,</if>
            <if test="produclotId != null">produclot_id,</if>
            <if test="receiverDept != null">receiver_dept,</if>
            <if test="receivingArea != null">receiving_area,</if>
            <if test="packageId != null">package_id,</if>
            <if test="useType != null">use_type,</if>
            <if test="telephone != null">telephone,</if>
            <if test="totalVolume != null">total_volume,</if>
            <if test="totalRoughWeight != null">total_rough_weight,</if>
            <if test="totalNetWeigh != null">total_net_weigh,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="defaultStorageAreaId != null">default_storage_area_id,</if>
            <if test="qualityInspecStatus != null">quality_inspec_status,</if>
            <if test="periodUnit != null">period_unit,</if>
            <if test="period != null">period,</if>
            <if test="reportTime != null">report_time,</if>
            <if test="consignment != null">consignment,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="abc != null">abc,</if>
            <if test="levelType != null">level_type,</if>
            <if test="isFreeze != null">is_freeze,</if>
            <if test="storageShortName != null">storage_short_name,</if>
            <if test="original != null">original,</if>
            <if test="needPerson != null">need_person,</if>
            <if test="needTel != null">need_tel,</if>
            <if test="rfidTid != null">rfid_Tid,</if>
            <if test="rfidEpc != null">rfid_epc,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="storageId != null">#{storageId},</if>
            <if test="storageAreaId != null">#{storageAreaId},</if>
            <if test="locationId != null">#{locationId},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="shelvesNum != null">#{shelvesNum},</if>
            <if test="remark != null">#{remark},</if>
            <if test="version != null">#{version},</if>
            <if test="storageMode != null">#{storageMode},</if>
            <if test="providerId != null">#{providerId},</if>
            <if test="productionDate != null">#{productionDate},</if>
            <if test="wareDate != null">#{wareDate},</if>
            <if test="doctNumber != null">#{doctNumber},</if>
            <if test="goodsVolume != null">#{goodsVolume},</if>
            <if test="occupyNum != null">#{occupyNum},</if>
            <if test="noticeId != null">#{noticeId},</if>
            <if test="oriBill != null">#{oriBill},</if>
            <if test="ctl != null">#{ctl},</if>
            <if test="barcode != null">#{barcode},</if>
            <if test="wgh != null">#{wgh},</if>
            <if test="high != null">#{high},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="status != null">#{status},</if>
            <if test="customerId != null">#{customerId},</if>
            <if test="batchNo != null">#{batchNo},</if>
            <if test="dueDate != null">#{dueDate},</if>
            <if test="checkDate != null">#{checkDate},</if>
            <if test="standard != null">#{standard},</if>
            <if test="flag != null">#{flag},</if>
            <if test="mark != null">#{mark},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="problem != null">#{problem},</if>
            <if test="price != null">#{price},</if>
            <if test="packingNum != null">#{packingNum},</if>
            <if test="boxType != null">#{boxType},</if>
            <if test="scaleUnit != null">#{scaleUnit},</if>
            <if test="goodsSku != null">#{goodsSku},</if>
            <if test="factoryId != null">#{factoryId},</if>
            <if test="salesOrderNo != null">#{salesOrderNo},</if>
            <if test="salesOrderNumber != null">#{salesOrderNumber},</if>
            <if test="supplier != null">#{supplier},</if>
            <if test="onOrder != null">#{onOrder},</if>
            <if test="recordPerson != null">#{recordPerson},</if>
            <if test="lotId != null">#{lotId},</if>
            <if test="decid != null">#{decid},</if>
            <if test="unit != null">#{unit},</if>
            <if test="specification != null">#{specification},</if>
            <if test="goodsAge != null">#{goodsAge},</if>
            <if test="arraMount != null">#{arraMount},</if>
            <if test="recoil != null">#{recoil},</if>
            <if test="operatorId != null">#{operatorId},</if>
            <if test="operateDate != null">#{operateDate},</if>
            <if test="purchaseId != null">#{purchaseId},</if>
            <if test="applicant != null">#{applicant},</if>
            <if test="respDept != null">#{respDept},</if>
            <if test="planDate != null">#{planDate},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="needCycle != null">#{needCycle},</if>
            <if test="needType != null">#{needType},</if>
            <if test="goodsTypeId != null">#{goodsTypeId},</if>
            <if test="brand != null">#{brand},</if>
            <if test="totalMoney != null">#{totalMoney},</if>
            <if test="expiryDate != null">#{expiryDate},</if>
            <if test="providerName != null">#{providerName},</if>
            <if test="receiver != null">#{receiver},</if>
            <if test="needDept != null">#{needDept},</if>
            <if test="purchaseDept != null">#{purchaseDept},</if>
            <if test="produclotId != null">#{produclotId},</if>
            <if test="receiverDept != null">#{receiverDept},</if>
            <if test="receivingArea != null">#{receivingArea},</if>
            <if test="packageId != null">#{packageId},</if>
            <if test="useType != null">#{useType},</if>
            <if test="telephone != null">#{telephone},</if>
            <if test="totalVolume != null">#{totalVolume},</if>
            <if test="totalRoughWeight != null">#{totalRoughWeight},</if>
            <if test="totalNetWeigh != null">#{totalNetWeigh},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="defaultStorageAreaId != null">#{defaultStorageAreaId},</if>
            <if test="qualityInspecStatus != null">#{qualityInspecStatus},</if>
            <if test="periodUnit != null">#{periodUnit},</if>
            <if test="period != null">#{period},</if>
            <if test="reportTime != null">#{reportTime},</if>
            <if test="consignment != null">#{consignment},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="abc != null">#{abc},</if>
            <if test="levelType != null">#{levelType},</if>
            <if test="isFreeze != null">#{isFreeze},</if>
            <if test="storageShortName != null">#{storageShortName},</if>
            <if test="original != null">#{original},</if>
            <if test="needPerson != null">#{needPerson},</if>
            <if test="needTel != null">#{needTel},</if>
            <if test="rfidTid != null">#{rfidTid},</if>
            <if test="rfidEpc != null">#{rfidEpc},</if>
        </trim>
    </insert>

    <update id="updateTMiStock" parameterType="TMiStock">
        update t_mi_stock
        <trim prefix="SET" suffixOverrides=",">
            <if test="storageId != null">storage_id = #{storageId},</if>
            <if test="storageAreaId != null">storage_area_id = #{storageAreaId},</if>
            <if test="locationId != null">location_id = #{locationId},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="shelvesNum != null">shelves_num = #{shelvesNum},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="version != null">version = #{version},</if>
            <if test="storageMode != null">storage_mode = #{storageMode},</if>
            <if test="providerId != null">provider_id = #{providerId},</if>
            <if test="productionDate != null">production_date = #{productionDate},</if>
            <if test="wareDate != null">ware_date = #{wareDate},</if>
            <if test="doctNumber != null">doct_number = #{doctNumber},</if>
            <if test="goodsVolume != null">goods_volume = #{goodsVolume},</if>
            <if test="occupyNum != null">occupy_num = #{occupyNum},</if>
            <if test="noticeId != null">notice_id = #{noticeId},</if>
            <if test="oriBill != null">ori_bill = #{oriBill},</if>
            <if test="ctl != null">ctl = #{ctl},</if>
            <if test="barcode != null">barcode = #{barcode},</if>
            <if test="wgh != null">wgh = #{wgh},</if>
            <if test="high != null">high = #{high},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="customerId != null">customer_id = #{customerId},</if>
            <if test="batchNo != null">batch_no = #{batchNo},</if>
            <if test="dueDate != null">due_date = #{dueDate},</if>
            <if test="checkDate != null">check_date = #{checkDate},</if>
            <if test="standard != null">standard = #{standard},</if>
            <if test="flag != null">flag = #{flag},</if>
            <if test="mark != null">mark = #{mark},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="problem != null">problem = #{problem},</if>
            <if test="price != null">price = #{price},</if>
            <if test="packingNum != null">packing_num = #{packingNum},</if>
            <if test="boxType != null">box_type = #{boxType},</if>
            <if test="scaleUnit != null">scale_unit = #{scaleUnit},</if>
            <if test="goodsSku != null">goods_sku = #{goodsSku},</if>
            <if test="factoryId != null">factory_id = #{factoryId},</if>
            <if test="salesOrderNo != null">sales_order_no = #{salesOrderNo},</if>
            <if test="salesOrderNumber != null">sales_order_number = #{salesOrderNumber},</if>
            <if test="supplier != null">supplier = #{supplier},</if>
            <if test="onOrder != null">on_order = #{onOrder},</if>
            <if test="recordPerson != null">record_person = #{recordPerson},</if>
            <if test="lotId != null">lot_id = #{lotId},</if>
            <if test="decid != null">decid = #{decid},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="specification != null">specification = #{specification},</if>
            <if test="goodsAge != null">goods_age = #{goodsAge},</if>
            <if test="arraMount != null">arra_mount = #{arraMount},</if>
            <if test="recoil != null">recoil = #{recoil},</if>
            <if test="operatorId != null">operator_id = #{operatorId},</if>
            <if test="operateDate != null">operate_date = #{operateDate},</if>
            <if test="purchaseId != null">purchase_id = #{purchaseId},</if>
            <if test="applicant != null">applicant = #{applicant},</if>
            <if test="respDept != null">resp_dept = #{respDept},</if>
            <if test="planDate != null">plan_date = #{planDate},</if>
            <if test="planTime != null">plan_time = #{planTime},</if>
            <if test="needCycle != null">need_cycle = #{needCycle},</if>
            <if test="needType != null">need_type = #{needType},</if>
            <if test="goodsTypeId != null">goods_type_id = #{goodsTypeId},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="totalMoney != null">total_money = #{totalMoney},</if>
            <if test="expiryDate != null">expiry_date = #{expiryDate},</if>
            <if test="providerName != null">provider_name = #{providerName},</if>
            <if test="receiver != null">receiver = #{receiver},</if>
            <if test="needDept != null">need_dept = #{needDept},</if>
            <if test="purchaseDept != null">purchase_dept = #{purchaseDept},</if>
            <if test="produclotId != null">produclot_id = #{produclotId},</if>
            <if test="receiverDept != null">receiver_dept = #{receiverDept},</if>
            <if test="receivingArea != null">receiving_area = #{receivingArea},</if>
            <if test="packageId != null">package_id = #{packageId},</if>
            <if test="useType != null">use_type = #{useType},</if>
            <if test="telephone != null">telephone = #{telephone},</if>
            <if test="totalVolume != null">total_volume = #{totalVolume},</if>
            <if test="totalRoughWeight != null">total_rough_weight = #{totalRoughWeight},</if>
            <if test="totalNetWeigh != null">total_net_weigh = #{totalNetWeigh},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="defaultStorageAreaId != null">default_storage_area_id = #{defaultStorageAreaId},</if>
            <if test="qualityInspecStatus != null">quality_inspec_status = #{qualityInspecStatus},</if>
            <if test="periodUnit != null">period_unit = #{periodUnit},</if>
            <if test="period != null">period = #{period},</if>
            <if test="reportTime != null">report_time = #{reportTime},</if>
            <if test="consignment != null">consignment = #{consignment},</if>
            <if test="deptId != null">deptId = #{deptId},</if>
            <if test="abc != null">abc = #{abc},</if>
            <if test="levelType != null">level_type = #{levelType},</if>
            <if test="isFreeze != null">is_freeze = #{isFreeze},</if>
            <if test="storageShortName != null">storage_short_name = #{storageShortName},</if>
            <if test="needPerson != null">need_person = #{needPerson},</if>
            <if test="needTel != null">need_tel = #{needTel},</if>
            </trim>
        where id = #{id}
    </update>

    <select id="selectTMiStockListByGoodsId" parameterType="TMiStock" resultMap="TMiStockResult">
        <include refid="selectTMiStockVo"/>
        <where>
            goods_id = #{goodsId}
            AND status = '0'
            AND ctl = #{ctl}
            <choose>
                <when test="storageList != null and storageList.size > 0">
                    AND storage_id IN
                    <foreach item="storageId" collection="storageList" open="(" separator="," close=")">
                        #{storageId}
                    </foreach>
                </when>
                <when test="storageId != null and storageId != ''">
                    AND storage_id = #{storageId}
                </when>
            </choose>
        </where>
        ORDER BY ware_date ASC
    </select>


    <update id="enableTMiStockByIds" parameterType="String">
        update t_mi_stock set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTMiStockByIds" parameterType="String">
        update t_mi_stock set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="updateShelvesNum" parameterType="TMiStock">
        update t_mi_stock
        <trim prefix="SET" suffixOverrides=",">
            <if test="shelvesNum != null">shelves_num = #{shelvesNum},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        <where>
            <if test="storageId != null  and storageId != ''">and storage_id = #{storageId}</if>
            <if test="ctl != null  and ctl != ''">and ctl = #{ctl}</if>
            <if test="locationId != null  and locationId != ''">and location_id = #{locationId}</if>
            <if test="goodsId != null  and goodsId != ''">and goods_id = #{goodsId}</if>
            <if test="id != null  and id != ''">and id = #{id}</if>
        </where>

    </update>

    <delete id="deleteTMiStockById" parameterType="Long">
        delete from t_mi_stock  where id = #{id}
    </delete>

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




    <delete id="deleteStockByCtlAndLocationId" parameterType="TMiStock">
        delete from t_mi_stock where
            storage_id = #{storageId}
                                 and location_id = #{locationId}
                                 and UPPER(ctl) = UPPER(#{ctl})
                                 and status = #{status}

    </delete>

    <update id="updateSts" parameterType="TMiStock">
        update t_mi_stock set status = #{status}
        <where>
            location_id = #{locationId}
            <if test="storageId != null  and storageId != ''">and storage_id = #{storageId}</if>
        </where>
    </update>
    <update id="updateLocation" parameterType="TMiStock">
        update t_mi_stock
        set status = #{status},
            location_id = #{locationId}
        where
            storage_id = #{storageId} and
            location_id = #{locationId}
    </update>
    <select id="inventoryStatisticsGoods" parameterType="TMiStock" resultMap="TMiStockResult">
        SELECT
        goods_id,
        storage_id,
        goods_name,
        unit,
        ctl,
        status,
        is_freeze,
        storage_short_name,
        level_type,
        price,
        total_money,
        IFNULL(specification,'') AS specification,
        recoil,
        goods_type_id,
        provider_id,
        location_id,
        occupy_num,
        level_type,
        sales_order_number,
        SUM(shelves_num) AS shelves_num
        FROM t_mi_stock
        <where>
            <choose>
                <when test="storageList != null and storageList.size > 0">
                    AND storage_id IN
                    <foreach item="storageId" collection="storageList" open="(" separator="," close=")">
                        #{storageId}
                    </foreach>
                </when>
                <when test="storageId != null and storageId != ''">AND storage_id = #{storageId}</when>
            </choose>
            <if test="locationId != null and locationId != ''">AND location_id LIKE CONCAT('%', #{locationId}, '%')</if>
            <if test="goodsName != null and goodsName != ''">AND goods_name LIKE CONCAT('%', #{goodsName}, '%')</if>
            <if test="goodsId != null and goodsId != ''">AND goods_id =#{goodsId}</if>
            <if test="ctl != null and ctl != ''">AND ctl LIKE CONCAT('%', #{ctl}, '%')</if>
            <if test="specification != null and specification != ''">AND specification LIKE CONCAT('%', #{specification}, '%')</if>
            <if test="recoil != null and recoil != ''">AND recoil LIKE CONCAT('%', #{recoil}, '%')</if>
            <if test="levelType != null and levelType != ''">AND level_type LIKE CONCAT('%', #{levelType}, '%')</if>
            <!-- Ensure both ctl and location_id are not empty before applying this condition -->
<!--            <if test="ctl != null and ctl != '' and locationId != null and locationId != ''">-->
<!--                AND ctl = #{ctl} AND location_id = #{locationId}-->
<!--            </if>-->
        </where>
        GROUP BY goods_id, goods_name, unit, IFNULL(specification,''), recoil, goods_type_id, provider_id, storage_id,storage_short_name, location_id,price,total_money,ctl,status,is_freeze,occupy_num,storage_short_name,level_type,sales_order_number
        ORDER BY goods_id
    </select>


    <select id="selectPanGoodsList" parameterType="TMiStock" resultMap="TMiStockResult">
        select goods_id
        , goods_name
        , location_id
        , ctl
        , sum(shelves_num) as shelves_num
        ,storage_short_name
        ,id
        from t_mi_stock
        <where>
            <choose>
                <when test="storageList != null  and storageList.size > 0">
                    and storage_id in
                    <foreach item="storageId" collection="storageList" open="(" separator="," close=")">
                        #{storageId}
                    </foreach>
                </when>
                <when test="storageId != null  and storageId != ''">and storage_id = #{storageId}</when>
            </choose>
            <if test="locationId != null  and locationId != ''">and location_id = #{locationId}</if>
            <if test="goodsId != null  and goodsId != ''">and goods_id = #{goodsId}</if>
        </where>
        group by goods_id, goods_name, location_id, ctl,storage_short_name,id
    </select>

    <select id="selectGroup" parameterType="TMiStock" resultMap="TMiStockResult">
        select storage_id,storage_short_name
         from t_mi_stock group by storage_id,storage_short_name
    </select>


    <select id="selectPanTimeLocation" parameterType="String" resultType="String">
        select location_id
        from t_ongoodsshelf_bak
        where ondate = #{queryDate}
        union
        select location_id
        from t_ck_pickingwavegoods_bak
        where ware_date = #{queryDate}
    </select>

    <update id="changeLocation" parameterType="TMiStockUpdate">
        update t_mi_stock
        set location_id = #{toLoc},
            update_time = #{updateTime},
            update_by = #{updateBy}
        where id = #{id}
    </update>

    <update id="changeCtlNo" parameterType="TMiStockUpdate">
        update t_mi_stock
        set ctl = #{toCtlNo},
            update_time = #{updateTime},
            update_by = #{updateBy}
        where ctl = #{fromCtlNo}
    </update>

    <update id="updateTMiStockSplitCtl" parameterType="TMiStock">
        update t_mi_stock
        set ctl = #{ctl},
            update_time = #{updateTime},
            update_by = #{updateBy}
        where id = #{id}
    </update>

    <update id="updateTMiStockNum" parameterType="TMiStock">
        update t_mi_stock
        set shelves_num = #{shelvesNum}
        where id = #{id}
    </update>
</mapper>
