<?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.shinsoft.sto.mapper.PickRecordMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.PickRecord">
        <result column="ID" property="id"/>
        <result column="PROCESS_INSTANCE_ID" property="processInstanceId"/>
        <result column="PROCESS_INSTANCE_STATUS" property="processInstanceStatus"/>
        <result column="ADD_ID" property="addId"/>
        <result column="ADD_CODE" property="addCode"/>
        <result column="ADD_NAME" property="addName"/>
        <result column="ADD_DEPT_ID" property="addDeptId"/>
        <result column="ADD_DEPT_CODE" property="addDeptCode"/>
        <result column="ADD_DEPT_NAME" property="addDeptName"/>
        <result column="ADD_TIME" property="addTime"/>
        <result column="MODIFY_ID" property="modifyId"/>
        <result column="MODIFY_CODE" property="modifyCode"/>
        <result column="MODIFY_NAME" property="modifyName"/>
        <result column="MODIFY_TIME" property="modifyTime"/>
        <result column="CANCEL_ID" property="cancelId"/>
        <result column="CANCEL_CODE" property="cancelCode"/>
        <result column="CANCEL_NAME" property="cancelName"/>
        <result column="CANCEL_TIME" property="cancelTime"/>
        <result column="CANCEL_FLAG" property="cancelFlag"/>
        <result column="BELONG_ID" property="belongId"/>
        <result column="COMP_CD" property="compCd"/>
        <result column="DEPT_CD" property="deptCd"/>
        <result column="ITEM_CD" property="itemCd"/>
        <result column="ITEM_NM" property="itemNm"/>
        <result column="ITEM_TYPE" property="itemType"/>
        <result column="PICK_RECORD_NO" property="pickRecordNo"/>
        <result column="QTY" property="qty"/>
        <result column="UOM" property="uom"/>
        <result column="STORE_CD" property="storeCd"/>
        <result column="AREA_CD" property="areaCd"/>
        <result column="STACK_CD" property="stackCd"/>
        <result column="PICK_TYPE" property="pickType"/>
        <result column="QTY_WET" property="qtyWet"/>
        <result column="PICK_DATE" property="pickDate"/>
        <result column="PUR_ORD_NO" property="purOrdNo"/>
        <result column="PUR_ORD_LN" property="purOrdLn"/>
        <result column="TRADE_PARTNER_ID" property="tradePartnerId"/>
        <result column="TRADE_PARTNER_CODE" property="tradePartnerCode"/>
        <result column="TRADE_PARTNER_NAME" property="tradePartnerName"/>
        <result column="REMARKS" property="remarks"/>
        <result column="CONTR_NO" property="contrNo"/>
        <result column="CONTR_LINE_NO" property="contrLineNo"/>
    </resultMap>


    <select id="queryList" resultType="com.shinsoft.sto.model.PickRecord">
        SELECT REC.* ,
               CON.STORE_NM storeNm,
               CON.STORE_TYPE storeType
        FROM STO_PICK_RECORD REC
                 LEFT JOIN STO_CONFIG CON ON REC.STORE_CD = CON.STORE_CD AND CON.CANCEL_FLAG = '0'
        WHERE REC.CANCEL_FLAG = '0'
            <if test="map.pickRecordNo != null and map.pickRecordNo !=''">
                and rec.PICK_RECORD_NO like '%'||#{map.pickRecordNo}||'%'
            </if>
            <if test="map.storeNm != null and map.storeNm !=''">
                and con.store_nm like '%'||#{map.storeNm}||'%'
            </if>
            <if test="map.itemNm != null and map.itemNm !=''">
                and rec.item_nm like '%'||#{map.itemNm}||'%'
            </if>
        order by REC.ADD_TIME DESC
    </select>

    <select id="getMax">
        SELECT MAX(TO_NUMBER(SUBSTR(PICK_RECORD_NO, -4))) code
        from STO_PICK_RECORD
        where PICK_DATE between
                  TO_DATE(#{startDate}, 'YYYY-MM-DD HH24:MI:SS')
                  and TO_DATE(#{endDate}, 'YYYY-MM-DD HH24:MI:SS')

    </select>
</mapper>
