<?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.cs.biz.outbound.dao.BarcodeHMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.prolog.cs.biz.outbound.model.entity.BarcodeHDO">
        <!-- id -->
        <id column="ID" property="id"/>
        <!-- 类型（0-拼箱码 1-整件拣选码） -->
        <result column="TYPE" property="type"/>
        <!-- 条码 -->
        <result column="BARCODE" property="barcode"/>
        <!-- 拼箱编号 -->
        <result column="LCL_NO" property="lclNo"/>
        <!-- 订单编号 -->
        <!-- 状态（0-未打印，1-已打印） -->
        <result column="STATUS" property="status"/>
        <!-- 仓库id -->
        <result column="WAREHOUSE_ID" property="warehouseId"/>
        <!-- 企业id -->
        <result column="ENTERPRISE_ID" property="enterpriseId"/>
        <!-- 创建日期 -->
        <result column="GMT_CREATE" property="gmtCreate"/>
        <!-- 创建人 -->
        <result column="CREATOR" property="creator"/>
        <!-- CREATED_NAME -->
        <result column="CREATOR_NAME" property="creatorName"/>
        <!-- 最后修改日期 -->
        <result column="GMT_MODIFIED" property="gmtModified"/>
        <!-- 最后修改人 -->
        <result column="MODIFIER" property="modifier"/>
        <!-- LAST_UPDATED_NAME -->
        <result column="MODIFIER_NAME" property="modifierName"/>
        <!-- 订单id -->
        <result column="bill_group_id" property="billGroupId"/>
        <!-- 容器编码 -->
        <result column="CONTAINER_CODE" property="containerCode"/>
        <!-- 复核台编号 -->
        <result column="STATION_CODE" property="stationCode"/>
        <!-- 打印次数 -->
        <result column="PRINT_COUNT" property="printCount"/>
        <!-- 打印人 -->
        <result column="PRINT_NAME" property="printName"/>
        <!-- 打印时间 -->
        <result column="PRINT_DATE" property="printDate"/>
        <!-- 复核状态： 0-未复核，1-已索取，5-已复核 -->
        <result column="CHECK_STATUS" property="checkStatus"/>
        <!-- 复核人ID/索取人ID -->
        <result column="CHECKER_ID" property="checkerId"/>
        <!-- 复核人工号/索取人工 -->
        <result column="CHECKER_NO" property="checkerNo"/>
        <!-- 复核人名称/索取人名称 -->
        <result column="CHECKER_NAME" property="checkerName"/>
        <!-- 复核人ID-2 -->
        <result column="CHECKER_ID_2" property="checkerId2"/>
        <!-- 复核人工号-2 -->
        <result column="CHECKER_NO_2" property="checkerNo2"/>
        <!-- 复核人名称-2 -->
        <result column="CHECKER_NAME_2" property="checkerName2"/>
        <!-- 复核时间/索取时间 -->
        <result column="CHECK_TIME" property="checkTime"/>
        <!-- 复核时间-2 -->
        <result column="CHECK_TIME_2" property="checkTime2"/>
        <!-- 整件商品监管码 -->
        <result column="SUPERVISE_CODE" property="superviseCode"/>
        <!-- 建筑物名称 -->
        <result column="BLDG_NAME" property="bldgName"/>
        <!-- 建筑物id -->
        <result column="BLDG_ID" property="bldgId"/>
        <result column="is_merged" property="isMerged"/>
        <result column="merged_code" property="mergedCode"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.ID,
        t.TYPE,
        t.BARCODE,
        t.LCL_NO,
        t.STATUS,
        t.WAREHOUSE_ID,
        t.ENTERPRISE_ID,
        t.GMT_CREATE,
        t.CREATOR,
        t.CREATOR_NAME,
        t.GMT_MODIFIED,
        t.MODIFIER,
        t.MODIFIER_NAME,
        t.bill_group_id,
        t.CONTAINER_CODE,
        t.STATION_CODE,
        t.PRINT_COUNT,
        t.PRINT_NAME,
        t.PRINT_DATE,
        t.CHECK_STATUS,
        t.CHECKER_ID,
        t.CHECKER_NO,
        t.CHECKER_NAME,
        t.CHECKER_ID_2,
        t.CHECKER_NO_2,
        t.CHECKER_NAME_2,
        t.CHECK_TIME,
        t.CHECK_TIME_2,
        t.SUPERVISE_CODE,
        t.BLDG_NAME,
        t.is_merged,
        t.merged_code,
        t.BLDG_ID
    </sql>

    <!-- 通用查询语句(数据库comment中含有?则不显示字段注释)) -->
    <sql id="Base_Where_List">

        <!-- id查询 -->
        <if test="params.containsKey('id')">
            AND t.ID = #{params.id}
        </if>


        <!-- 类型（0-拼箱码 1-整件拣选码）查询 -->
        <if test="params.type != null and params.type != ''">
            AND t.TYPE = #{params.type}
        </if>


        <!-- 类型（0-拼箱码 1-整件拣选码）模糊查询 -->
        <if test="params.typeLike != null and params.typeLike != ''">
            AND t.TYPE LIKE '%' || #{params.typeLike} || '%'
        </if>


        <!-- 条码查询 -->
        <if test="params.barcode != null and params.barcode != ''">
            AND t.BARCODE = #{params.barcode}
        </if>


        <!-- 条码模糊查询 -->
        <if test="params.barcodeLike != null and params.barcodeLike != ''">
            AND t.BARCODE LIKE '%' || #{params.barcodeLike} || '%'
        </if>


        <!-- 拼箱编号查询 -->
        <if test="params.lclNo != null and params.lclNo != ''">
            AND t.LCL_NO = #{params.lclNo}
        </if>


        <!-- 状态（0-未打印，1-已打印）查询 -->
        <if test="params.status != null and params.status != ''">
            AND t.STATUS = #{params.status}
        </if>


        <!-- 仓库id查询 -->
        <if test="params.warehouseId != null and params.warehouseId != ''">
            AND t.WAREHOUSE_ID = #{params.warehouseId}
        </if>


        <!-- 仓库id模糊查询 -->
        <if test="params.warehouseIdLike != null and params.warehouseIdLike != ''">
            AND t.WAREHOUSE_ID LIKE '%' || #{params.warehouseIdLike} || '%'
        </if>


        <!-- 企业id查询 -->
        <if test="params.enterpriseId != null and params.enterpriseId != ''">
            AND t.ENTERPRISE_ID = #{params.enterpriseId}
        </if>


        <!-- 企业id模糊查询 -->
        <if test="params.enterpriseIdLike != null and params.enterpriseIdLike != ''">
            AND t.ENTERPRISE_ID LIKE '%' || #{params.enterpriseIdLike} || '%'
        </if>


        <!-- 创建日期开始时间查询 -->
        <if test="params.gmtCreateStart != null and params.gmtCreateStart != ''">
            AND t.GMT_CREATE &gt;= to_date(#{params.gmtCreateStart}, 'yyyy-mm-dd HH24:MI:SS')
        </if>

        <!-- 创建日期结束时间查询 -->
        <if test="params.gmtCreateEnd != null and params.gmtCreateEnd != ''">
            AND t.GMT_CREATE &lt;= to_date(#{params.gmtCreateEnd}, 'yyyy-mm-dd HH24:MI:SS')
        </if>


        <!-- 创建人查询 -->
        <if test="params.creator != null and params.creator != ''">
            AND t.CREATOR = #{params.creator}
        </if>


        <!-- 创建人模糊查询 -->
        <if test="params.creatorLike != null and params.creatorLike != ''">
            AND t.CREATOR LIKE '%' || #{params.creatorLike} || '%'
        </if>


        <!-- CREATED_NAME查询 -->
        <if test="params.creatorName != null and params.creatorName != ''">
            AND t.CREATOR_NAME = #{params.creatorName}
        </if>


        <!-- CREATED_NAME模糊查询 -->
        <if test="params.creatorNameLike != null and params.creatorNameLike != ''">
            AND t.CREATOR_NAME LIKE '%' || #{params.creatorNameLike} || '%'
        </if>

        <!-- 最后修改日期开始时间查询 -->
        <if test="params.gmtModifiedStart != null and params.gmtModifiedStart != ''">
            AND t.GMT_MODIFIED &gt;= to_date(#{params.gmtModifiedStart}, 'yyyy-mm-dd HH24:MI:SS')
        </if>

        <!-- 最后修改日期结束时间查询 -->
        <if test="params.gmtModifiedEnd != null and params.gmtModifiedEnd != ''">
            AND t.GMT_MODIFIED &lt;= to_date(#{params.gmtModifiedEnd}, 'yyyy-mm-dd HH24:MI:SS')
        </if>


        <!-- 最后修改人查询 -->
        <if test="params.modifier != null and params.modifier != ''">
            AND t.MODIFIER = #{params.modifier}
        </if>

        <!-- 最后修改人模糊查询 -->
        <if test="params.modifierLike != null and params.modifierLike != ''">
            AND t.MODIFIER LIKE '%' || #{params.modifierLike} || '%'
        </if>


        <!-- LAST_UPDATED_NAME查询 -->
        <if test="params.modifierName != null and params.modifierName != ''">
            AND t.MODIFIER_NAME = #{params.modifierName}
        </if>

        <!-- LAST_UPDATED_NAME模糊查询 -->
        <if test="params.modifierNameLike != null and params.modifierNameLike != ''">
            AND t.MODIFIER_NAME LIKE '%' || #{params.modifierNameLike} || '%'
        </if>


        <!-- 订单id查询 -->
        <if test="params.billId != null and params.billId != ''">
            AND t.BILL_ID = #{params.billId}
        </if>

        <!-- 订单id模糊查询 -->
        <if test="params.billIdLike != null and params.billIdLike != ''">
            AND t.BILL_ID LIKE '%' || #{params.billIdLike} || '%'
        </if>


        <!-- 容器编码查询 -->
        <if test="params.containerCode != null and params.containerCode != ''">
            AND t.CONTAINER_CODE = #{params.containerCode}
        </if>

        <!-- 容器编码模糊查询 -->
        <if test="params.containerCodeLike != null and params.containerCodeLike != ''">
            AND t.CONTAINER_CODE LIKE '%' || #{params.containerCodeLike} || '%'
        </if>


        <!-- 复核台编号查询 -->
        <if test="params.stationCode != null and params.stationCode != ''">
            AND t.STATION_CODE = #{params.stationCode}
        </if>

        <!-- 复核台编号模糊查询 -->
        <if test="params.stationCodeLike != null and params.stationCodeLike != ''">
            AND t.STATION_CODE LIKE '%' || #{params.stationCodeLike} || '%'
        </if>


        <!-- 打印次数查询 -->
        <if test="params.printCount != null and params.printCount != ''">
            AND t.PRINT_COUNT = #{params.printCount}
        </if>

        <!-- 打印人查询 -->
        <if test="params.printName != null and params.printName != ''">
            AND t.PRINT_NAME = #{params.printName}
        </if>

        <!-- 打印人模糊查询 -->
        <if test="params.printNameLike != null and params.printNameLike != ''">
            AND t.PRINT_NAME LIKE '%' || #{params.printNameLike} || '%'
        </if>

        <!-- 打印时间开始时间查询 -->
        <if test="params.printDateStart != null and params.printDateStart != ''">
            AND t.PRINT_DATE &gt;= to_date(#{params.printDateStart}, 'yyyy-mm-dd HH24:MI:SS')
        </if>

        <!-- 打印时间结束时间查询 -->
        <if test="params.printDateEnd != null and params.printDateEnd != ''">
            AND t.PRINT_DATE &lt;= to_date(#{params.printDateEnd}, 'yyyy-mm-dd HH24:MI:SS')
        </if>

        <!-- 复核状态： 0-未复核，1-已索取，5-已复核查询 -->
        <if test="params.checkStatus != null and params.checkStatus != ''">
            AND t.CHECK_STATUS = #{params.checkStatus}
        </if>

        <!-- 复核人ID/索取人ID查询 -->
        <if test="params.checkerId != null and params.checkerId != ''">
            AND t.CHECKER_ID = #{params.checkerId}
        </if>

        <!-- 复核人ID/索取人ID模糊查询 -->
        <if test="params.checkerIdLike != null and params.checkerIdLike != ''">
            AND t.CHECKER_ID LIKE '%' || #{params.checkerIdLike} || '%'
        </if>

        <!-- 复核人工号/索取人工查询 -->
        <if test="params.checkerNo != null and params.checkerNo != ''">
            AND t.CHECKER_NO = #{params.checkerNo}
        </if>

        <!-- 复核人工号/索取人工模糊查询 -->
        <if test="params.checkerNoLike != null and params.checkerNoLike != ''">
            AND t.CHECKER_NO LIKE '%' || #{params.checkerNoLike} || '%'
        </if>

        <!-- 复核人名称/索取人名称查询 -->
        <if test="params.checkerName != null and params.checkerName != ''">
            AND t.CHECKER_NAME = #{params.checkerName}
        </if>

        <!-- 复核人名称/索取人名称模糊查询 -->
        <if test="params.checkerNameLike != null and params.checkerNameLike != ''">
            AND t.CHECKER_NAME LIKE '%' || #{params.checkerNameLike} || '%'
        </if>


        <!-- 复核人ID-2查询 -->
        <if test="params.checkerId2 != null and params.checkerId2 != ''">
            AND t.CHECKER_ID_2 = #{params.checkerId2}
        </if>

        <!-- 复核人ID-2模糊查询 -->
        <if test="params.checkerId2Like != null and params.checkerId2Like != ''">
            AND t.CHECKER_ID_2 LIKE '%' || #{params.checkerId2Like} || '%'
        </if>

        <!-- 复核人工号-2查询 -->
        <if test="params.checkerNo2 != null and params.checkerNo2 != ''">
            AND t.CHECKER_NO_2 = #{params.checkerNo2}
        </if>

        <!-- 复核人工号-2模糊查询 -->
        <if test="params.checkerNo2Like != null and params.checkerNo2Like != ''">
            AND t.CHECKER_NO_2 LIKE '%' || #{params.checkerNo2Like} || '%'
        </if>

        <!-- 复核人名称-2查询 -->
        <if test="params.checkerName2 != null and params.checkerName2 != ''">
            AND t.CHECKER_NAME_2 = #{params.checkerName2}
        </if>

        <!-- 复核人名称-2模糊查询 -->
        <if test="params.checkerName2Like != null and params.checkerName2Like != ''">
            AND t.CHECKER_NAME_2 LIKE '%' || #{params.checkerName2Like} || '%'
        </if>

        <!-- 复核时间/索取时间开始时间查询 -->
        <if test="params.checkTimeStart != null and params.checkTimeStart != ''">
            AND t.CHECK_TIME &gt;= to_date(#{params.checkTimeStart}, 'yyyy-mm-dd HH24:MI:SS')
        </if>

        <!-- 复核时间/索取时间结束时间查询 -->
        <if test="params.checkTimeEnd != null and params.checkTimeEnd != ''">
            AND t.CHECK_TIME &lt;= to_date(#{params.checkTimeEnd}, 'yyyy-mm-dd HH24:MI:SS')
        </if>

        <!-- 复核时间-2开始时间查询 -->
        <if test="params.checkTime2Start != null and params.checkTime2Start != ''">
            AND t.CHECK_TIME_2 &gt;= to_date(#{params.checkTime2Start}, 'yyyy-mm-dd HH24:MI:SS')
        </if>

        <!-- 复核时间-2结束时间查询 -->
        <if test="params.checkTime2End != null and params.checkTime2End != ''">
            AND t.CHECK_TIME_2 &lt;= to_date(#{params.checkTime2End}, 'yyyy-mm-dd HH24:MI:SS')
        </if>


        <!-- 整件商品监管码查询 -->
        <if test="params.superviseCode != null and params.superviseCode != ''">
            AND t.SUPERVISE_CODE = #{params.superviseCode}
        </if>

        <!-- 整件商品监管码模糊查询 -->
        <if test="params.superviseCodeLike != null and params.superviseCodeLike != ''">
            AND t.SUPERVISE_CODE LIKE '%' || #{params.superviseCodeLike} || '%'
        </if>


        <!-- 建筑物名称查询 -->
        <if test="params.bldgName != null and params.bldgName != ''">
            AND t.BLDG_NAME = #{params.bldgName}
        </if>


        <!-- 建筑物名称模糊查询 -->
        <if test="params.bldgNameLike != null and params.bldgNameLike != ''">
            AND t.BLDG_NAME LIKE '%' || #{params.bldgNameLike} || '%'
        </if>


        <!-- 建筑物id查询 -->
        <if test="params.bldgId != null and params.bldgId != ''">
            AND t.BLDG_ID = #{params.bldgId}
        </if>


        <!-- 建筑物id模糊查询 -->
        <if test="params.bldgIdLike != null and params.bldgIdLike != ''">
            AND t.BLDG_ID LIKE '%' || #{params.bldgIdLike} || '%'
        </if>

    </sql>
    <!--

        &lt;!&ndash; BarcodeHVO查询语句 &ndash;&gt;
        <select id="queryBarcodeHVOByParams" parameterType="java.util.Map"
                resultType="com.prolog.cs.biz.outbound.vo.LcLSecondVO">
            SELECT
            <include refid="Base_Column_List"/>
            FROM WMS_BARCODE_H t
            <where>
                <include refid="Base_Where_List"/>
            </where>
        </select>
    -->


    <update id="updateCheckStatus">
        update WMS_BARCODE_H
        set check_status = '0'
        where bill_group_id= #{billGroupId} and station_code= #{stationCode}
    </update>
    
    <update id="updateMergedLcl">
        update WMS_BARCODE_H
        set is_merged = 1,
        merged_code = #{mergedCode}
        where 1=1
        <if test="ids != null and ids.size()>0">
            and id in
            <foreach collection="ids" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </update>

    <select id="getLclNo" resultType="com.prolog.cs.biz.outbound.model.entity.BarcodeHDO">
        select
            h.id,
            h.type,
            h.barcode,
            h.bill_group_id,
            h.lcl_no,
            h.container_code ,
            h.status,
            h.warehouse_id,
            h.station_code
        from WMS_BARCODE_H h
        <if test="checkerNo != null and checkerNo != ''">
            inner join WMS_BARCODE_D bd on bd.barcode_id=h.id
            inner join WMS_PICK_TASK_D d on d.pick_task_d_id=bd.WMS_PICK_TASK_D_ID
        </if>
        where lcl_no is not null
        <if test="stationCode != null and stationCode != ''">
            and station_code = #{stationCode}
        </if>
        <if test="status != null and status != ''">
            and status = #{status}
        </if>
        <if test="billGroupId != null and billGroupId != ''">
            and bill_group_id = #{billGroupId}
        </if>
        <if test="checkerNo != null and checkerNo != ''">
            and d.CHECKER_NO= #{checkerNo}
        </if>
        ORDER BY LCL_NO DESC
    </select>

    <select id="query" resultType="com.prolog.cs.biz.outbound.model.vo.LcLSecondVO">
        SELECT
        distinct
        BILL.WAVE_ID,
        bill.code as billCode,
        BILL.contact_name,
        BILL.contact_tel,
        BILL.consignor_id ,
        BILL.receive_address,
        BILL.sale_branch_name ,
        BILL.payment_day_type,
        BILL.SHIPPER_CODE,
        BILL.SHIPPER_NAME,
        <include refid="Base_Column_List"/>
        FROM WMS_BARCODE_H t
        LEFT JOIN WMS_WAVE_BILL bill ON bill.BILL_GROUP_ID = t.bill_group_id
        where 1=1
        <if test="barcode != null and barcode != ''">
            and t.barcode = #{barcode}
        </if>
        <if test="waveId != null and waveId != ''">
            and bill.wave_id = #{waveId}
        </if>
        <if test="saleBranchName != null and saleBranchName != ''">
            and bill.sale_branch_name = #{saleBranchName}
        </if>
        <if test=" warehouseId!= null and warehouseId != ''">
            and bill.warehouse_id = #{warehouseId }
        </if>
        ORDER BY bill.CONTACT_NAME ,bill.CONTACT_TEL
    </select>
    <select id="getByIds" resultType="com.prolog.cs.biz.outbound.model.vo.LcLSecondVO">
        SELECT
        BILL.WAVE_ID,
        BILL.contact_name,
        BILL.contact_tel,
        BILL.consignor_id ,
        BILL.receive_address,
        BILL.sale_branch_name ,
        BILL.payment_day_type,
        <include refid="Base_Column_List"/>
        FROM WMS_BARCODE_H t
        LEFT JOIN WMS_WAVE_BILL bill ON bill.id = t.bill_group_id
        where 1=1
        <if test="ids != null and ids.size()>0">
            and t.id in
            <foreach collection="ids" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

    <select id="getOmsBillIds" resultType="java.lang.String">
       select distinct n.src_id from WMS_WAVE_BILL n join wms_wave_bill_d m on n.id = m.bill_id where m.merged_bill_id =#{srcCode} and n.ENTERPRISE_ID=#{enterpriseId}
    </select>

    <select id="getOmsBillNos" resultType="java.lang.String">
        select distinct n.src_code from WMS_WAVE_BILL n join wms_wave_bill_d m on n.id = m.bill_id where m.merged_bill_id =#{srcCode} and n.ENTERPRISE_ID=#{enterpriseId}
    </select>

    <update id="updatePickTaskHStatus">
        UPDATE
            WMS_PICK_TASK_H
        set STATUS='10'
        where status='2'
            and PICK_TASK_TYPE='0'
        <if test="warehouseId != null and warehouseId != ''">
            and WAREHOUSE_ID= #{warehouseId}
        </if>
            and PICK_TASK_ID in (
                SELECT
                    c.PICK_TASK_ID
                from WMS_BARCODE_H a,WMS_BARCODE_D b,WMS_PICK_TASK_D c
                where a.id=b.BARCODE_ID
                    and b.WMS_PICK_TASK_D_ID=c.PICK_TASK_D_ID
                    and a.BARCODE=#{barcode}
                    and a.ENTERPRISE_ID=#{enterpriseId}
                    and a.type='1'
                <if test="warehouseId != null and warehouseId != ''">
                    and a.WAREHOUSE_ID= #{warehouseId}
                </if>)
    </update>

    <select id="getBillIdByWave" resultType="java.lang.String">
        select distinct src_id from WMS_WAVE_BILL where WAVE_ID =#{waveId} and WAREHOUSE_ID=#{warehouseId}
        and (status is null or status &lt;&gt; 'POSITION_ERROR')
    </select>

    <delete id="deleteBarcodeHNoExistD">
        delete WMS_BARCODE_H h
        where bill_group_id= #{billGroupId} and station_code= #{stationCode}
        and not exists (select 1 from WMS_BARCODE_D d where h.id=d.BARCODE_ID)
    </delete>

    <select id="listOmsBill" resultType="com.prolog.cs.biz.outbound.model.OmsDoBillHDO">
        SELECT
            *
        FROM
            oms_do_bill_h h
        LEFT JOIN oms_do_bill_d d ON h.billid = d.billid
        LEFT JOIN wms_wave_bill w ON w.src_id = h.billid
        WHERE w.billid IN(
            SELECT billid FROM WMS_BARCODE_H a,wms_wave_bill b WHERE a.bill_group_id = b.BILL_GROUP_ID
            WHERE a.warehouse_id = #{warehouseId}
            AND a.bill_group_id IN
        <foreach collection="billGroupIds" separator="," index="index" item="item" close=")" open="(">
            #{item}
        </foreach>
        );
    </select>

    <select id="getLclNoV2" resultType="com.prolog.cs.biz.outbound.model.entity.BarcodeHDO">
        select
            distinct h.id,
            h.type,
            h.barcode,
            h.bill_group_id,
            h.lcl_no,
            h.container_code ,
            h.status,
            h.warehouse_id,
            h.station_code
        from WMS_BARCODE_H h
        where lcl_no is not null
        <if test="checkerNo != null and checkerNo != ''">
            and not EXISTS (select 1 from WMS_BARCODE_D bd
            inner JOIN WMS_PICK_TASK_D d ON d.barcode_d_id = bd.id where d.CHECKER_NO &lt;&gt; #{checkerNo} and bd.barcode_id = h.id )
        </if>
        <if test="stationCode != null and stationCode != ''">
            and station_code = #{stationCode}
        </if>
        <if test="status != null and status != ''">
            and status = #{status}
        </if>
        <if test="billGroupId != null and billGroupId != ''">
            and bill_group_id = #{billGroupId}
        </if>
    </select>
    <select id="getLclByStation" resultType="com.prolog.cs.biz.outbound.model.entity.BarcodeHDO">
        SELECT distinct h.* FROM WMS_BARCODE_H h
        LEFT JOIN WMS_BARCODE_D d ON h.id = d.barcode_id
        LEFT JOIN WMS_PICK_TASK_D pd ON pd.pick_task_d_id = d.wms_pick_task_d_id
        LEFT JOIN WMS_PICK_TASK_H ph ON pd.pick_task_id = ph.pick_task_id
        WHERE ph.pick_task_id IN(SELECT pick_task_id FROM WMS_PICK_TASK_H WHERE station_code = #{stationCode} AND bill_id = #{billId}) AND h.status = 0
    </select>

    <select id="getUsingByPickTaskId" resultType="com.prolog.cs.biz.outbound.model.entity.BarcodeHDO">
        SELECT DISTINCT
            h.*
        FROM WMS_BARCODE_H h
        WHERE h.id IN (
            SELECT
                barcode_id
            FROM WMS_BARCODE_D d
        <!-- 拼箱与pick_task_d的关联方式是barcode_d_id-->
            WHERE d.id IN ( SELECT barcode_d_id FROM WMS_PICK_TASK_D pd WHERE pd.barcode_d_id = d.id AND pd.pick_task_id = #{pickTaskId})
            )
        AND h.STATUS = 0
    </select>
    <!-- 查询当前picktaskh下是否有未打印的拼箱 -->
    <select id="getUnPrintByPickTaskId" resultType="com.prolog.cs.biz.outbound.model.entity.BarcodeHDO">
        SELECT DISTINCT
            h.*
        FROM WMS_BARCODE_H h
        WHERE h.id IN (
            SELECT
                barcode_id
            FROM WMS_BARCODE_D d
            <!-- 拼箱与pick_task_d的关联方式是barcode_d_id-->
            WHERE d.id IN ( SELECT barcode_d_id FROM WMS_PICK_TASK_D pd WHERE pd.barcode_d_id = d.id AND pd.pick_task_id = #{pickTaskId})
            AND (d.print_cnt is null OR d.print_cnt &lt; 1)
        ) OR h.status = 0
    </select>
    <select id="ListDataByLclNo" resultType="com.prolog.cs.biz.outbound.model.dto.LclPrintDataDto">
        SELECT
            DISTINCT
            a.id,
            b.lcl_no lclNo,
            (SELECT GROUP_CONCAT(STAGE_CODE) FROM WMS_WORK_STAGE_RUNTIME WHERE BILL_GROUP_ID = h.BILL_GROUP_ID) workStageCode,
            obh.line_name lineName,
            obh.shippercode shipperCode,
            obh.shippername shipperName,
            obh.ship_line_id shipLineId,
            obh.receive_address receiveAddress,
            obh.cust_person custPerson,
            obh.cust_person_tel custPersonTel,
            obh.remark,
            obh.billno,
            obh.salesperson_name salespersonName,
            h.station_code stationCode,
            IFNULL(d.checker_name_2, d.checker_name) checkerName,
            b.gmt_create gmtCreate,
            IFNULL(a.print_cnt, 0) printCnt
        FROM
            WMS_BARCODE_D a
        LEFT JOIN wms_pick_task_d d ON a.id = d.barcode_d_id
        LEFT JOIN wms_pick_task_h h on d.pick_task_id = h.pick_task_id
        LEFT JOIN wms_wave_storage s on d.WAVE_STORAGE_ID = s.id
        LEFT JOIN WMS_WAVE_BILL_D m on m.ID = s.BILL_D_ID
        LEFT JOIN WMS_WAVE_BILL n on m.bill_id = n.id
        LEFT JOIN OMS_DO_BILL_H obh on obh.BILLID = n.src_id
        LEFT JOIN WMS_BARCODE_H b ON a.barcode_id = b.id
        WHERE obh.BILLNO = #{billNo}
        <if test="ids != null and ids.size() > 0">
            AND b.lcl_no IN
            <foreach collection="ids" close=")" index="index" item="item" open="(" separator=",">
                #{item}
            </foreach>
        </if>

        ORDER BY d.PICK_TASK_ID asc
    </select>
    <update id="updateStatuts">
        UPDATE
            WMS_BARCODE_H
        SET status = 1
        WHERE id IN
        <foreach collection="ids" open="(" close=")" separator="," item="item" index="index">
            #{item}
        </foreach>
    </update>
    <update id="updateCheckStatus2EndByBillNo">
        update wms_barcode_h set check_status = 6 where bill_group_id = #{billNo}
    </update>
    <update id="updaPushCount">
        update wms_barcode_h set tms_push_count = ifnull(tms_push_count,0) + 1 where bill_group_id = #{billNo}
    </update>

    <select id="getUnConfirmContainerCnt" resultType="integer">
        SELECT COUNT(*) FROM wms_pick_task_h h
        WHERE h.bill_group_id = #{billGroupId}
        AND h.container_code != #{containerCode}
        <if test="stationCode != null and stationCode != ''">
            and h.station_code = #{stationCode}
        </if>
        <if test="stationCode == null">
            and h.station_code = '-1'
        </if>
        AND h.status != 10
        AND h.container_code IS NOT NULL
    </select>

    <select id="getEndBoxContainer" resultType="integer">
        SELECT COUNT(*) FROM wms_pick_task_h h
        WHERE h.bill_group_id = #{billGroupId}
        AND h.container_code != #{containerCode}
        <if test="stationCode != null and stationCode != ''">
            and h.station_code = #{stationCode}
        </if>
        AND h.status != 10
        AND h.pick_task_type = 1
    </select>
    <select id="getMaxBarcode" resultType="java.lang.String">
        SELECT MAX(barcode) from wms_barcode_h where barcode_type = '0'
    </select>
    <select id="getlblPkgDTOS" resultType="com.prolog.cs.biz.outbound.model.dto.check.OuterLblPkgDTO">
        SELECT
            h.barcode,
            h.type,
            h.check_status as checkStatus,
            sum( d.qty ) as qty
        FROM
            wms_barcode_h h
            JOIN wms_barcode_d d ON h.id = d.barcode_id
        WHERE
            h.bill_group_id = #{billGroupId}
            and h.warehouse_id = #{warehouseId}
            and h.bldg_id = #{bldgId}
            and d.qty is not null
            and h.barcode is not null
            and d.qty > 0
          AND (h.cancel_flag <![CDATA[ <> ]]> '1' OR h.cancel_flag IS NULL)
--             and (h.is_merged = 0 or h.is_merged is null)
            and not exists (
            select 1 from wms_pick_task_d wptd where wptd.pick_task_d_id  = d.wms_pick_task_d_id and wptd.flow_status <![CDATA[ < ]]> 3
            )
        GROUP BY
            h.barcode,
            h.type
        order by h.barcode asc
    </select>
    <select id="queryByBillGroupIds" resultType="map">
        SELECT
        h.barcode as barCode,
        h.bill_group_id as billGroupId,
        t2.shippername as shipperName
        FROM
        wms_barcode_h h
        left join oms_do_bill_h t2 on h.bill_group_id=t2.billid
        WHERE h.bill_group_id in
        <foreach collection="billGroupIds" open="(" close=")" separator="," item="item" index="index">
            #{item}
        </foreach>
    </select>

    <!--<select id="getPushPackageList" resultType="com.prolog.cs.biz.outbound.model.dto.BillPackageDTO">-->
        <!--SELECT distinct bh.id barcodeId,bh.barcode, bh.check_time_2 checkTime2, bh.checker_name checkerName, bh.lcl_no lclNo, bh.check_status checkStatus-->
             <!--, oh.p_enterprisename enterpriseName, oh.p_enterpriseid enterpriseId, oh.billno, oh.billid, oh.consignorcode-->
             <!--, oh.consignorname, oh.ship_bill_no shipBillNo, oh.consignorid, wd.volume, wd.height,bh.weight-->
        <!--FROM wms_pick_task_d pd-->
                 <!--LEFT JOIN wms_barcode_h bh ON bh.bill_group_id = pd.src_id-->
                 <!--LEFT JOIN oms_do_bill_h oh ON oh.billno = pd.src_id-->
                 <!--LEFT JOIN wms_wave_bill_d wd on wd.id = pd.bill_d_id and oh.billno = wd.merged_bill_id-->
        <!--WHERE pd.flow_status = 7 and bh.check_status <![CDATA[<]]> 6-->
        <!--and bh.bill_group_id  not in (select wptd.src_id  from wms_pick_task_d wptd where wptd.flow_status <![CDATA[<]]> 7 and wptd.src_id is not null )-->
        <!--and (bh.cancel_flag != '1' or bh.cancel_flag is null)-->
        <!--ORDER BY check_time_2 ASC-->
    <!--</select>-->

    <select id="getPushPackageList" resultType="com.prolog.cs.biz.outbound.model.dto.BillPackageDTO">
        select bh.id barcodeId,bh.barcode, bh.check_time_2 checkTime2, bh.checker_name_2 checkerName, bh.lcl_no lclNo, bh.check_status checkStatus
        , oh.p_enterprisename enterpriseName, oh.p_enterpriseid enterpriseId, oh.billno, oh.billid, oh.consignorcode
        , oh.consignorname, oh.ship_bill_no shipBillNo, oh.consignorid,bh.weight,0 as volume,0 as height
        from wms_barcode_h bh join oms_do_bill_h oh on bh.bill_group_id = oh.billid
        where  1=1
        and  bh.check_status <![CDATA[<]]> 6
        and bh.bill_group_id  not in (select wptd.src_id  from wms_pick_task_d wptd where wptd.flow_status <![CDATA[<]]> 7 and wptd.src_id is not null )
        and bh.bill_group_id  not in (select wpth.bill_group_id  from wms_pick_task_h wpth where wpth.status <![CDATA[<]]>10  )
        and (bh.cancel_flag != '1' or bh.cancel_flag is null)
        and (bh.tms_push_count is null or bh.tms_push_count <![CDATA[ <= ]]> 3)
        ORDER BY check_time_2 ASC,bh.tms_push_count asc ;
    </select>

    <select id="selectBybillNoACancelflag" resultType="com.prolog.cs.biz.outbound.model.vo.check.BarCodeDVO">
        select d.wms_pick_task_d_id as pickTaskDId, h.cancel_flag as cancelFlag, h.barcode
        from wms_barcode_h h
                 left join
             wms_barcode_d d
        on h.id = d.barcode_id
        where h.bill_group_id = #{billNo}
    </select>

    <select id="getByBillPickComplete" resultType="com.prolog.cs.biz.outbound.model.entity.BarcodeHDO">
        select
           distinct wbh.*
        from
            wms_barcode_h wbh
        join wms_barcode_d wbd on
            wbd.barcode_id = wbh.id
        join wms_pick_task_d wptd on
            wptd.pick_task_d_id = wbd.wms_pick_task_d_id
        where
            wptd.src_code = #{billno}
            and wbh.bill_group_id = #{billno}
            and wptd.flow_status >= 3
            and wptd.pick_qty is not null
            and (wbh.cancel_flag is null or wbh.cancel_flag != '1')
    </select>

</mapper>