<?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.WmsMoveHMapper">
    <resultMap id="BaseResultMap" type="com.prolog.upcloud.base.wh.operate.model.WmsMoveH">
        <id column="MOVE_HEADER_ID" jdbcType="VARCHAR" property="moveHeaderId"/>
        <result column="ENTERPRISE_ID" jdbcType="VARCHAR" property="enterpriseId"/>
        <result column="DC_ID" jdbcType="VARCHAR" property="dcId"/>
        <result column="WAREHOUSE_ID" jdbcType="VARCHAR" property="warehouseId"/>
        <result column="AUTO_BILL_NUM" jdbcType="VARCHAR" property="autoBillNum"/>
        <result column="CUSTOM_BILL_NUM" jdbcType="VARCHAR" property="customBillNum"/>
        <result column="MOVE_BILL_TYPE" jdbcType="VARCHAR" property="moveBillType"/>
        <result column="MOVE_IN_BLDG" jdbcType="VARCHAR" property="moveInBldg"/>
        <result column="MOVE_OUT_BLDG" jdbcType="VARCHAR" property="moveOutBldg"/>
        <result column="STATUS" jdbcType="VARCHAR" property="status"/>
        <result column="MOVE_DATE" jdbcType="TIMESTAMP" property="moveDate"/>
        <result column="IS_PLAN_MOVE" jdbcType="DECIMAL" property="isPlanMove"/>
        <result column="PICK_BILL_ID" jdbcType="VARCHAR" property="pickBillId"/>
        <result column="ACCESS_LEVEL" jdbcType="CHAR" property="accessLevel"/>
        <result column="PRINT_COUNT" jdbcType="DECIMAL" property="printCount"/>
        <result column="PRINT_DATE" jdbcType="TIMESTAMP" property="printDate"/>
        <result column="PRINTED_BY" jdbcType="VARCHAR" property="printedBy"/>
        <result column="PRINTED_NAME" jdbcType="VARCHAR" property="printedName"/>
        <result column="ATTRIBUTE1" jdbcType="VARCHAR" property="attribute1"/>
        <result column="ATTRIBUTE2" jdbcType="VARCHAR" property="attribute2"/>
        <result column="ATTRIBUTE3" jdbcType="VARCHAR" property="attribute3"/>
        <result column="ATTRIBUTE4" jdbcType="VARCHAR" property="attribute4"/>
        <result column="ATTRIBUTE5" jdbcType="VARCHAR" property="attribute5"/>
        <result column="COMMENTS" jdbcType="VARCHAR" property="comments"/>
        <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"/>
    </resultMap>
    <select id="getMoveDoneByLineBill" resultType="com.prolog.upcloud.base.wh.operate.vo.MoveSyncInfoVO">
        select H.MOVE_HEADER_ID,
        H.MOVE_BILL_TYPE,
        H.SUB_BILL_TYPE,
        H.WAREHOUSE_ID,
        H.CARGO_OWNER_ID,
        H.ENTERPRISE_ID,
        H.AUTO_BILL_NUM,
        H.MOVE_DATE,
        D.MOVE_LINE_ID,
        D.MANUFACTURER_LOT_NUM,
        D.ITEM_ID,
        D.LINE_NUM,
        D.IN_STOCK_STATUS,
        D.OUT_STOCK_STATUS,
        D.BILL_ID,
        D.BILL_NO,
        D.LINE_ID,
        D.REASON,
        D.BATCH_PRODUCTION_DATE,
        D.BATCH_EXPIRED_DATE,
        D.BATCH_PRODUCTION_DATE_SHOW,
        D.BATCH_EXPIRED_DATE_SHOW,
        D.PIECE_QUANTITY as ODD_PIECE_QUANTITY,
        D.MOVE_OUT_BLDG,
        D.MOVE_IN_BLDG,
        D.BATCH_ID,
        D.BATCH_NUM,
        D.out_locator_id,
        D.in_locator_id
        from WMS_MOVE_H h
        INNER JOIN WMS_MOVE_D D ON H.MOVE_HEADER_ID = D.MOVE_HEADER_ID
        where
        h.ENTERPRISE_ID =#{enterpriseId} and h.MOVE_BILL_TYPE = #{moveBillType} and h.SUB_BILL_TYPE=#{subBillType} AND
        exists(select 1 from WMS_MOVE_D d1 where d1.MOVE_HEADER_ID = h.MOVE_HEADER_ID and d1.MOVE_LINE_ID IN
        <foreach collection="moveLineIds" open="(" close=")" item="id" separator=",">
            #{id}
        </foreach>
        )
        <if test="statusList!=null and statusList.length >0">
        and not exists(select 1 from WMS_MOVE_D d2 where d2.MOVE_HEADER_ID = h.MOVE_HEADER_ID and d2.STATUS in
        <foreach collection="statusList" open="(" close=")" item="status" separator=",">
            #{status}
        </foreach>
            )
        </if>

    </select>

    <select id="getMoveSyncInfoList" resultType="com.prolog.upcloud.base.wh.operate.vo.MoveSyncInfoVO">
        SELECT H.MOVE_HEADER_ID,
        H.MOVE_BILL_TYPE,
        H.SUB_BILL_TYPE,
        H.WAREHOUSE_ID,
        H.CARGO_OWNER_ID,
        H.ENTERPRISE_ID,
        H.AUTO_BILL_NUM,
        D.MANUFACTURER_LOT_NUM,
        D.BILL_ID ERP_BILL_ID,
        D.LINE_ID ERP_LINE_ID,
        D.QUANTITY
        FROM WMS_MOVE_H H
        INNER JOIN (
        SELECT MOVE_HEADER_ID,MANUFACTURER_LOT_NUM, BILL_ID, LINE_ID, SUM(QUANTITY) QUANTITY
        FROM WMS_MOVE_D
        GROUP BY MOVE_HEADER_ID,MANUFACTURER_LOT_NUM, BILL_ID, LINE_ID) D ON H.MOVE_HEADER_ID = D.MOVE_HEADER_ID
        WHERE H.SUB_BILL_TYPE = 1 AND H.MOVE_HEADER_ID IN
        <foreach collection="headerIds" open="(" close=")" item="headerId" separator=",">
            #{headerId}
        </foreach>
    </select>
</mapper>
