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

    <delete id="deleteByWaveId">
        DELETE FROM wms_wave_bill_d WHERE WAVE_ID = #{waveId}
    </delete>

    <resultMap id="BillAndItemVO" type="com.prolog.cs.biz.outbound.model.vo.check.BillAndItemVO">
        <result column="MANUFACTURER_LOT_NUM" property="manufactureLotNum"/>
        <result column="consignor_id" property="consignorId"/>
        <result column="CUST_PERSON" property="clientName"/>
        <result column="bill_code" property="billCode"/>
        <result column="BILL_GROUP_ID" property="billGroupId"/>
    </resultMap>

    <select id="getBillItemInfo" resultMap="BillAndItemVO">
        SELECT
        bill.src_code as bill_code,
        bill.id as bill_id,
        billd.item_specs ,
        billd.item_category_code,
        billd.MANUFACTURER ,
        billd.MANUFACTURER_LOT_NUM ,
        bill.consignor_id,
        bill.BILL_GROUP_ID,
        omsbill.consignorname ,
        omsbill.CUST_PERSON,
        billd.item_name,
        billd.item_id,
        billd.item_code,
        billd.ITEM_HEALTH_IS_DOUBLE,
        bill.SHIPPER_ID,
        bill.type
        FROM WMS_WAVE_BILL_D billd
        LEFT JOIN WMS_WAVE_BILL bill ON bill.id = billd.BILL_ID
        LEFT JOIN OMS_DO_BILL_H omsbill ON omsbill.BILLID = bill.SRC_ID
        where 1=1
        <if test="itemCode != null and itemCode != ''">
            and billd.item_code = #{itemCode}
        </if>
        <if test="billGroupId != null and billGroupId != ''">
            and bill.BILL_GROUP_ID = #{billGroupId}
        </if>
        <if test="billDId != null and billDId != ''">
            and billd.id = #{billDId}
        </if>
    </select>

    <select id="needDoubleCheck" resultType="java.lang.Boolean">
        SELECT
        CASE ITEM_HEALTH_IS_DOUBLE
        WHEN '01' THEN 1
        WHEN '1' THEN 1
        ELSE 0
        END doubleCheck
        FROM WMS_WAVE_BILL_D billd
        where item_code = #{itemCode} and rownum=1
    </select>
    <select id="getBillDForRedCheck" resultType="com.prolog.cs.biz.outbound.model.entity.WaveBillDDO">
        SELECT
        billd.*
        FROM
        WMS_WAVE_BILL_D billd
        LEFT JOIN WMS_WAVE_BILL bill ON bill.id = billd.BILL_ID
        WHERE
        bill.BILL_GROUP_ID = #{billGroupID}
        AND billd.ITEM_CODE = #{itemCode}
        AND billd.PIECE_QTY > #{qty}
    </select>

</mapper>