<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "倒垛">
<query id = "FrmStuffStow.doQueryStow" desc = "查询倒垛实绩">
<![CDATA[
SELECT 
       GROUD_NO,
       SUM(ACT_COUNT)ACT_COUNT,
       SUM(ACT_WEIGHT)ACT_WEIGHT,
       SUM(ACT_LEN)ACT_LEN,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       PLINE_CODE,
       PLINE_NAME,
       BELONG_CODE,
       BELONG_NAME,
       MAX(TO_CHAR(STOW_TIME, 'YYYY-MM-DD HH24:MI:SS')) STOW_TIME,
       LOCATION_NO,
       MEMO,
       PRODUCT_FLAG,
       MAT_STATUS,
       STOVE_NO,
       FLAG_STOVE_NO,
       LOT_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       CAST_NO,
       CCMID,
       SAMPLE_FLAG,
       CUTTING_FLAG,
       CUTTING_NUM,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       JUDGE_GRADECODE,
       JUDGE_GRADENAME,
       JUDGE_STD_CODE,
       JUDGE_STD_NAME,
       ACT_DIMATER,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_FIX_NUM,
       ACT_FIX_LEN
 FROM YDM_GP_STOWLIST
 WHERE T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
 ]]>
</query>
<query id="FrmStuffStow.queryStow" desc="查询当前料位信息">
	<![CDATA[
	 SELECT max(t.storage_no) as storage_no, t.LOCATION_NO,sum(a.ACT_COUNT) as ACT_COUNT
		FROM ydm_gp_buttress t
		,mat_gp_m a
		where 
		t.mat_no=a.mat_no
		and t.storage_no=?
		and t.JUDGE_STOVE_NO=?
		and t.BATCH_NO=?
		and t.GROUD_NO=?
		and t.location_no like '%'||?||'%'
		group by t.LOCATION_NO
		order by t.LOCATION_NO asc
	]]>
	</query>
	<query id = "FrmStuffStow.getLocationNo" desc = "加载该仓库下所有料位号">
	SELECT T.LOCATION_NO,T.LOCATION_NO FROM YDM_BS_LOCATION T WHERE T.STORAGE_NO = ?
	</query>
	<query id = "FrmStuffStow.doAddLocationNo" desc = "倒垛操作">
	<![CDATA[
	DECLARE
  V_stow_SQE ydm_gp_stowlist.stow_sqe%TYPE := NULL; --倒垛流水
  V_TIME     ydm_gp_stowlist.create_time%TYPE := SYSDATE;
BEGIN
  FOR MYROW IN (SELECT T.*,
                       S.STORAGE_NO,
                       S.LOCATION_NO,
                       S.STORAGE_ATTR,
                       S.STORAGE_ATTR_NAME,
                       S.STORAGE_TYPE_NO,
                       S.STORAGE_TYPE_NAME,
                       s.LARY_NO,
                       s.LOC_NO
                  FROM MAT_GP_M T, YDM_GP_BUTTRESS S
                 WHERE T.MAT_NO = S.MAT_NO
                   AND T.STOVE_NO = ?
                   AND T.JUDGE_STOVE_NO = ?
                   AND T.BATCH_NO = ?
                   AND T.GROUD_NO = ?
                   AND S.STORAGE_NO = ?
                   AND S.LOCATION_NO= ?
                   AND ROWNUM < ?
                 ORDER BY T.MAT_NO DESC) LOOP
    select myrow.mat_no || LPAD(NVL(MAX(SUBSTR(stow_sqe, length(stow_sqe)-4)), 0) + 1, 4, 0) stow_sqe
      into V_stow_SQE
      from ydm_gp_stowlist t
     where MAT_NO = myrow.mat_no;
     INSERT INTO YDM_GP_STOWLIST(
        groud_no,
        act_count,
        ACT_WEIGHT,
        PRO_ORDER_NO,
        PRO_ORDER_ID,
        PLINE_CODE,
        PLINE_NAME,
        BELONG_CODE,
        BELONG_NAME,
        
        STOW_TIME,
        STOW_BC,
        STOW_BZ,
        LOCATION_NO,
        LARY_NO,
        LOC_NO,
        OLD_LOCATION_NO,
        OLD_LARY_NO,
        OLD_LOC_NO,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        MANAGEMENT_NO,
        MANAGEMENT_NAME,
        STORAGE_ATTR,
        STORAGE_ATTR_NAME,
        STORAGE_TYPE_NO,
        STORAGE_TYPE_NAME,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        STOW_SQE,
        MAT_NO,
        PRODUCT_FLAG,
        MAT_STATUS,
        STOVE_NO,
        FLAG_STOVE_NO,
        LOT_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        CAST_NO,
        CCMID,
        SAMPLE_FLAG,
        CUTTING_FLAG,
        CUTTING_NUM,
        MATERIAL_NO,
        MATERIAL_NAME,
        PRODUCCODE,
        PRODUCNAME,
        JUDGE_GRADECODE,
        JUDGE_GRADENAME,
        JUDGE_STD_CODE,
        JUDGE_STD_NAME,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_FIX_NUM,
        ACT_FIX_LEN)
 VALUES( 
        myrow.groud_no,
        myrow.act_count,
        myrow.ACT_WEIGHT,
        myrow.PRO_ORDER_NO,
        myrow.PRO_ORDER_ID,
        myrow.PLINE_CODE,
        myrow.PLINE_NAME,
        myrow.BELONG_CODE,
        myrow.BELONG_NAME,
        
        v_time,
        ?,
        ?,
        ?,
        ?,
        ?,
        myrow.location_no,
        myrow.lary_no,
        myrow.loc_no,
        ?,
        ?,
        ?,
        ?,
        myrow.STORAGE_ATTR,
        myrow.STORAGE_ATTR_NAME,
        myrow.STORAGE_TYPE_NO,
        myrow.STORAGE_TYPE_NAME,
        myrow.MEMO,
        ?,
        v_time,
        V_stow_SQE,
        myrow.MAT_NO,
        myrow.PRODUCT_FLAG,
        myrow.MAT_STATUS,
        myrow.STOVE_NO,
        myrow.FLAG_STOVE_NO,
        myrow.LOT_NO,
        myrow.JUDGE_STOVE_NO,
        myrow.BATCH_NO,
        myrow.CAST_NO,
        myrow.CCMID,
        myrow.SAMPLE_FLAG,
        myrow.CUTTING_FLAG,
        myrow.CUTTING_NUM,
        myrow.MATERIAL_NO,
        myrow.MATERIAL_NAME,
        myrow.PRODUCCODE,
        myrow.PRODUCNAME,
        myrow.JUDGE_GRADECODE,
        myrow.JUDGE_GRADENAME,
        myrow.JUDGE_STD_CODE,
        myrow.JUDGE_STD_NAME,
        myrow.ACT_DIMATER,
        myrow.ACT_HEIGHT,
        myrow.ACT_LEN,
        myrow.ACT_LEN_MIN,
        myrow.ACT_LEN_MAX,
        myrow.ACT_FIX_NUM,
        myrow.ACT_FIX_LEN);
    update YDM_GP_BUTTRESS T set t.location_no = ?,t.lary_no=?,t.loc_no = ? WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
	]]>
	</query>
</queryMap>