<?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.prolog.upcloud.base.wh.operate.dao.WmsMoveDMapper">
    <resultMap id="BaseResultMap" type="com.prolog.upcloud.base.wh.operate.model.WmsMoveD">
        <id column="MOVE_LINE_ID" jdbcType="VARCHAR" property="moveLineId"/>
        <result column="MOVE_HEADER_ID" jdbcType="VARCHAR" property="moveHeaderId"/>
        <result column="OUT_LOCATOR_ID" jdbcType="VARCHAR" property="outLocatorId"/>
        <result column="OUT_CONTAINER_CODE" jdbcType="VARCHAR" property="outContainerCode"/>
        <result column="OUT_CONTAINER_CODE" jdbcType="VARCHAR" property="outContainerCode"/>
        <result column="IN_LOCATOR_ID" jdbcType="VARCHAR" property="inLocatorId"/>
        <result column="IN_CONTAINER_CODE" jdbcType="VARCHAR" property="inContainerCode"/>
        <result column="OUT_GOODS_CASE_CODE" jdbcType="VARCHAR" property="outGoodsCaseCode"/>
        <result column="IN_GOODS_CASE_CODE" jdbcType="VARCHAR" property="inGoodsCaseCode"/>
        <result column="ITEM_ID" jdbcType="VARCHAR" property="itemId"/>
        <result column="UOM" jdbcType="VARCHAR" property="uom"/>
        <result column="BATCH_ID" jdbcType="VARCHAR" property="batchId"/>
        <result column="BATCH_NUM" jdbcType="VARCHAR" property="batchNum"/>
        <result column="CONVERSION_RATE" jdbcType="DECIMAL" property="conversionRate"/>
        <result column="QUANTITY" jdbcType="DECIMAL" property="quantity"/>
        <result column="PIECE_QUANTITY" jdbcType="DECIMAL" property="pieceQuantity"/>
        <result column="GMT_CREATE" jdbcType="TIMESTAMP" property="gmtCreate"/>
        <result column="CREATOR" jdbcType="VARCHAR" property="creator"/>
        <result column="CREATOR_NAME" jdbcType="VARCHAR" property="creatorName"/>
        <result column="GMT_MODIFIED" jdbcType="TIMESTAMP" property="gmtModified"/>
        <result column="MODIFIER" jdbcType="VARCHAR" property="modifier"/>
        <result column="MODIFIER_NAME" jdbcType="VARCHAR" property="modifierName"/>
        <result column="COMMENTS" jdbcType="VARCHAR" property="comments"/>
        <result column="WAREHOUSE_WORKER_ID" jdbcType="VARCHAR" property="warehouseWorkerId"/>
        <result column="ENTERPRISE_ID" jdbcType="VARCHAR" property="enterpriseId"/>
        <result column="REASON" jdbcType="VARCHAR" property="reason"/>
        <result column="LINE_NUM" jdbcType="DECIMAL" property="lineNum"/>
        <result column="STATUS" jdbcType="VARCHAR" property="status"/>
        <result column="ODD_PIECE_QUANTITY" jdbcType="DECIMAL" property="oddPieceQuantity"/>
        <result column="CASE_CONVERSION_RATE" jdbcType="DECIMAL" property="caseConversionRate"/>
        <result column="IN_STOCK_STATUS" jdbcType="VARCHAR" property="inStockStatus"/>
        <result column="OUT_STOCK_STATUS" jdbcType="VARCHAR" property="outStockStatus"/>
    </resultMap>
    <sql id="Base_Column_List">
        MOVE_LINE_ID, MOVE_HEADER_ID, OUT_LOCATOR_ID, OUT_CONTAINER_CODE, IN_LOCATOR_ID,
    IN_CONTAINER_CODE, OUT_GOODS_CASE_CODE, IN_GOODS_CASE_CODE, ITEM_ID, UOM, BATCH_ID,
    BATCH_NUM, CONVERSION_RATE, QUANTITY, PIECE_QUANTITY, GMT_CREATE, CREATOR, CREATOR_NAME,
    GMT_MODIFIED, MODIFIER, MODIFIER_NAME, COMMENTS, WAREHOUSE_WORKER_ID, ENTERPRISE_ID,
    REASON, LINE_NUM, STATUS,ODD_PIECE_QUANTITY,CASE_CONVERSION_RATE,IN_STOCK_STATUS,OUT_STOCK_STATUS
    </sql>

    <update id="updateStatusByHeaderId">
        update WMS_MOVE_D
        set STATUS = #{status,jdbcType=VARCHAR}
        where MOVE_HEADER_ID = #{moveHeaderId,jdbcType=VARCHAR}
    </update>

    <select id="getUncomfirmContainerNum" resultType="int">
        select count(1) from wms_move_d t where t.`status`=#{status}
        and t.move_line_id not in
        <foreach collection="moveLineIds" item="lineid" open="(" close=")" separator=",">
            #{lineid}
        </foreach>
        and t.out_container_code is not null
        and t.out_container_code = #{outcontainercode}
    </select>

    <update id="updateEisFinishFlag">
         update wms_move_d t set t.eis_finish_flag ='Y' where
        t.MOVE_LINE_ID in
        <foreach collection="moveLineIds" item="lineid" open="(" close=")" separator=",">
            #{lineid}
        </foreach>
    </update>

    <select id="selectMoveDInfoList" resultType="com.prolog.upcloud.base.wh.operate.vo.MoveDListVO">
        select
            h.MOVE_HEADER_ID,
            h.AUTO_BILL_NUM,
            h.CARGO_OWNER_ID,
            h.WAREHOUSE_ID,
            h.CUSTOM_BILL_NUM,
            h.MOVE_BILL_TYPE,
            h.SUB_BILL_TYPE,
             d.quantity,
             d.line_num lineNum,
             d.bill_id billId,
             d.bill_no billNo,
             d.line_id lineId,
             d.unqualified_reason unqualifiedReason,
            d.manufacturer_lot_num manufacturerLotNum,
            d.MOVE_IN_BLDG,
            d.MOVE_OUT_BLDG,
            h.MOVE_DATE,
            d.MOVE_LINE_ID,
            d.OUT_LOCATOR_ID,
            d.OUT_GOODS_CASE_CODE,
            d.OUT_CONTAINER_CODE,
            d.IN_LOCATOR_ID,
            d.IN_CONTAINER_CODE,
            d.IN_GOODS_CASE_CODE,
            d.ITEM_ID,
            d.UOM,
            d.BATCH_ID,
            d.BATCH_NUM,
            d.CONVERSION_RATE,
            d.QUANTITY CASE_QUANTITY,
            d.PIECE_QUANTITY,
            d.ODD_PIECE_QUANTITY,
            d.CASE_CONVERSION_RATE,
            d.REASON,
            d.WAREHOUSE_WORKER_ID,
            d.STATUS,
            d.GMT_CREATE,
            d.CREATOR,
            d.CREATOR_NAME,
            d.GMT_MODIFIED,
            d.MODIFIER,
            d.MODIFIER_NAME,d.IN_STOCK_STATUS,d.OUT_STOCK_STATUS,
            d.ERP_REASON,d.ERP_PLAN_QUANTITY,d.COMMENTS,
            d.BILL_ID,d.BILL_NO,d.LINE_ID,
            d.batch_production_date,
            d.batch_expired_date,
            d.eis_finish_flag
        from WMS_MOVE_D d
        inner join WMS_MOVE_H h on d.MOVE_HEADER_ID = h.MOVE_HEADER_ID
        <where>
            h.ENTERPRISE_ID = #{enterpriseId}
            <if test="query.moveHeaderId != null and query.moveHeaderId != ''">
                and h.MOVE_HEADER_ID = #{query.moveHeaderId}
            </if>
            <if test="query.cargoOwnerId != null and query.cargoOwnerId != ''">
                and h.CARGO_OWNER_ID = #{query.cargoOwnerId}
            </if>
            <if test="query.warehouseId != null and query.warehouseId != ''">
                and h.WAREHOUSE_ID = #{query.warehouseId}
            </if>
            <if test="query.moveBillType != null and query.moveBillType != ''">
                and h.move_bill_type = #{query.moveBillType}
            </if>
            <if test="query.subBillType !=null and query.subBillType != ''">
                and h.sub_bill_type = #{query.subBillType}
            </if>
            <if test="query.moveInBldg !=null and query.moveInBldg != ''">
                and d.MOVE_IN_BLDG = #{query.moveInBldg}
            </if>
            <if test="query.outlocatorcode !=null and query.outlocatorcode != ''">
                and d.out_locator_id = #{query.outlocatorid}
            </if>

            <if test="query.outcontainercode !=null and query.outcontainercode != ''">
                and d.out_container_code = #{query.outcontainercode}
            </if>
            <if test="query.outgoodscasecode !=null and query.outgoodscasecode != ''">
                and d.out_goods_case_code = #{query.outgoodscasecode}
            </if>
            <if test="query.moveOutBldg !=null and query.moveOutBldg != ''">
                and d.MOVE_OUT_BLDG = #{query.moveOutBldg}
            </if>
            <if test="query.autoBillNum !=null and query.autoBillNum != ''">
                and h.AUTO_BILL_NUM = #{query.autoBillNum}
            </if>
            <if test="query.warehouseWorkerId !=null and query.warehouseWorkerId != ''">
                and d.WAREHOUSE_WORKER_ID = #{query.warehouseWorkerId}
            </if>
            <if test="query.start != null">
                and h.MOVE_DATE >= #{query.start}
            </if>
            <if test="query.end != null">
                and h.MOVE_DATE &lt;= #{query.end}
            </if>
            <if test="query.statusList != null">
                and d.status in
                <foreach collection="query.statusList" item="status" open="(" close=")" separator=",">
                    #{status}
                </foreach>
            </if>
            <if test="query.moveLineIds != null">
                and d.MOVE_LINE_ID in
                <foreach collection="query.moveLineIds" item="moveLineId" open="(" close=")" separator=",">
                    #{moveLineId}
                </foreach>
            </if>
        </where>
        order by move_date desc
    </select>

</mapper>
