<?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.WmsReplenishDMapper">
    <select id="selectReplenishList" resultType="com.prolog.upcloud.base.wh.operate.vo.ReplenishListVO">
        select H.SOURCE_TYPE,
        H.WAREHOUSE_ID,
        H.BILL_TYPE,
        H.AUTO_BILL_NUM,H.CUSTOM_BILL_NUM,
        H.BUSINESS_TYPE,
        H.HEADER_ID,
        D.DETAIL_ID,
        D.ENTERPRISE_ID,
        D.CARGO_OWNER_ID,
        D.LINE_NUM,
        D.STATUS,
        D.ITEM_ID,
        D.ITEM_CODE,
        D.WH_AREA_CATEGORY,
        D.WH_AREA_ID,
        D.WH_AREA_CODE,
        D.WH_LOCATOR_ID,
        D.WH_LOCATOR_CODE,
        D.BATCH_ID,
        D.BATCH_NUM,
        D.MANUFACTURER_LOT_NUM,
        D.BATCH_PRODUCTION_DATE,
        D.BATCH_EXPIRED_DATE,
        D.UOM,
        D.CONVERSION_RATE,
        D.QUANTITY,
        D.PIECE_QUANTITY,
        D.TO_WH_AREA_CATEGORY,
        D.TO_WH_AREA_ID,
        D.TO_WH_AREA_CODE,
        D.TO_WH_LOCATOR_ID,
        D.TO_WH_LOCATOR_CODE,
        D.OMS_BILL_NO,D.ERP_SRC_ID,H.HEADER_ID ERP_SRC_NO,D.ERP_SRC_LINE_ID
        from WMS_REPLENISH_H H
        INNER JOIN WMS_REPLENISH_D D on H.HEADER_ID = D.HEADER_ID
        WHERE D.type=0 and WAREHOUSE_ID = #{query.warehouseId}
        and H.ENTERPRISE_ID= #{enterpriseId}
        <if test="query.detailId !='' and query.detailId != null">
            AND DETAIL_ID = #{query.detailId}
        </if>
        <if test="query.cargoOwnerId !='' and query.cargoOwnerId != null">
            AND CARGO_OWNER_ID = #{query.cargoOwnerId}
        </if>
        <if test="query.businessType !='' and query.businessType != null">
            AND BUSINESS_TYPE = #{query.businessType}
        </if>
        <if test="query.autoBillNum !='' and query.autoBillNum != null">
            AND AUTO_BILL_NUM = #{query.autoBillNum}
        </if>
        <if test="query.status !='' and query.status != null">
            AND STATUS = #{query.status}
        </if>
        <if test="query.omsBillNo !='' and query.omsBillNo != null">
            AND OMS_BILL_NO like CONCAT(CONCAT('%',#{query.omsBillNo}),'%')
        </if>
        <if test="query.erpSrcId !='' and query.erpSrcId != null">
            AND ERP_SRC_ID like CONCAT(CONCAT('%',#{query.erpSrcId}),'%')
        </if>
        <if test="query.erpSrcNo !='' and query.erpSrcNo != null">
            AND H.HEADER_ID like CONCAT(CONCAT('%',#{query.erpSrcNo}),'%')
        </if>
        <if test="query.erpSrcLineId !='' and query.erpSrcLineId != null">
            AND ERP_SRC_LINE_ID like CONCAT(CONCAT('%',#{query.erpSrcLineId}),'%')
        </if>
        order by H.GMT_CREATE,D.LINE_NUM DESC
    </select>
</mapper>
