<?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.cim.idm.dao.FgStockInDao">
<!--    更新入库标记-->
    <update id="updateBsMesShipped" parameterType="java.util.List">
        UPDATE BS_MES_SHIPPED T
        SET
        T.RECEIVE_FLAG = 'Y',
        T.RECEIVETIME = SYSDATE
        WHERE
        T.LOTNAME IN
        <foreach item="box" index="index" collection="boxList" open="(" separator="," close=")">
            #{box.materialPackingName}
        </foreach>
    </update>

<!--    获取所有待入库的信息-->
    <select id="getBoxList"
            resultType="com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking" parameterType="java.util.List">
        SELECT
        T.LOTNAME MATERIALPACKINGNAME,
        T.LOTNAME LKMATERIALPACKINGNAME,
        T.QTY MATERIALQUANTITY,
        T.QTY SUBPACKINGQUANTITY,
        T.QTY MaterialCreateQuantity,
        T.RECEIVE_FLAG mesReceiveFlag,
        'SDK' siteName,
        CASE
        WHEN T.PACKINGGRADE IS NULL THEN 'PREOQA'
        ELSE 'END'
        END AS oqaResultState,
        CASE
        WHEN T.PACKINGGRADE IS NOT NULL THEN T.PACKINGGRADE
        ELSE NULL
        END AS oqaResult,
        T.PACKINGGRADE packingGrade,
        'Released' packingState,
        'Created' stockState,
        'Created' oldStockState,
        'N' holdState,
        'Box' materialPackingType,
        T.DURABLETYPE durableType,
        #{erpFactory} ERPFactory,
        #{erpLocation} ERPLOCATION,
        #{locationName} LOCATIONNAME,
        T.AREA areaName,
        NVL(T.MAKEDATE, SYSDATE ) MAKEDATE ,
        NVL(T.MAKEDATE, SYSDATE ) + NVL(M3.EXPIRATIONDAY, '9999') expiringDate,
        SYSDATE ReceiveTime,
        #{user} ReceiveUser,
        T.REQUESTNAME productOrder,
        T.CAREER_ASSISTANCE ,
        M3.MATERIALSPECTYPE ,
        T.BUSINESS_UNIT,
        T.SALESPERSON,
        T.UNIT,
        T.REQUESTNAME,
        T.PRODUCTSPECNAME MATERIALSPECNAME,
        SS.SPECNAME ,
        T.SDK_ID ,
        T.AREA ,
        T.SHIPUSER ,
        T.PACKINGGRADEDETAIL ,
        T.SHIPTIME ,
        M3.MATERIALTYPE ,
        T.PHASE,
        T.GXID,
        T.CHARGE,
        T.SDK_ID truegg,
        T.MJPC,
        T.MATERIALSPECTYPE
        FROM
        BS_MES_SHIPPED T
        LEFT JOIN SDK_SPEC SS ON
        T.SDK_ID = SS.SDK_ID
        LEFT JOIN MATERIALSPEC M3 ON
        T.PRODUCTSPECNAME = M3.MATERIALSPECNAME
        WHERE
        (T.RECEIVE_FLAG IS NULL
        OR T.RECEIVE_FLAG !='Y')
        AND T.LOTNAME IN
        <foreach item="box" index="index" collection="boxList" open="(" separator="," close=")">
            #{box.materialPackingName}
        </foreach>
    </select>

    <select id="getBoxPacking"
            resultType="com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking" parameterType="java.util.List">
        SELECT MATERIALPACKINGNAME FROM MATERIALPACKING m WHERE MATERIALPACKINGNAME = #{materialPackingName}
    </select>

</mapper>