<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "上料">

<query id = "FrmFeedLoad.doQueryData" desc = "查询">
<![CDATA[
   SELECT T.ID,
       T.SEQ,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.LOT_NO,
       T.CONTRACT_NO,
       T.IMP_PROCESS,
       T.PLINE_CODE,
       T.STATUS,
       T.PRODUCER,
       T.PROCESS_STATUS,
       T.DB_LENGTH,
       T.DB_HEIGHT,
       T.ROLL_LENGTH,
       T.SAW_NUM,
       T.TARGET_LENGTH,
       T.FINISH_USER,
       T.TARGET_LIABRARY,
       T.VARIETIES,
       T.PIPE_SIZE,
       T.BUCKLE_TYPE,
       T.LENGTH_RANGE,
       T.ROLL_STANDRAD,
       T.PIPE_SECTION,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.STEEL_STANDRAD,
       T.TARGET,
       T.BRANCH,
       T.TON,
       T.CUT_TARGET,
       T.CUT_LENGTH,
       T.CUT_WEIGHT,
       T.DB_NUM,
       TO_CHAR(T.START_TIME, 'YYYY-MM-DD HH24:MI:SS') START_TIME,
       TO_CHAR(T.END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       TO_CHAR(T.TOM, 'YYYY-MM-DD HH24:MI:SS') TOM,
       TO_CHAR(T.TOC, 'YYYY-MM-DD HH24:MI:SS') TOC,
       T.NODE_STATUS,
       T.CUT_HEAD_LENGTHP,
       T.CUT_TRAIL_LENGTHP,
       T.CONTROL_THICKP,
       T.OFFLINE_FLAG,
       T.IS_BATCH,
       TO_CHAR(T.OFFLINE_DATE, 'YYYY-MM-DD HH24:MI:SS') OFFLINE_DATE,
       T.CUT_TYPE,
       T.ROLLING_STATUS,
       T.PRODUCE_STANDRAD,
       T.SIMPLE_PROCESS,
       T.BACK_LINE_FLAG,
       T.BACK_PLAN_FLAG,
       T.FEED_SEQ,
       TO_CHAR(T.FEED_TIME, 'YYYY-MM-DD HH24:MI:SS') FEED_TIME,
       T.LOT_SEQ,
       T.FEED_HEAT_NO,
       T.LENGTHCP,
       T.CUT_HEAD_LENGTHA,
       T.CUT_TRAIL_LENGTHA,
       T.ORDER_LENGTHA,
       T.HOT_CHECK_FLAG,
       T.BACK_SLAB_FLAG,
       TO_CHAR(T.BACK_SLAB_TIME, 'YYYY-MM-DD HH24:MI:SS') BACK_SLAB_TIME,
       T.BATCH_MAX,
       T.CODE_SAMPLE_FLAG,
       T.VARIETIES_CODE,
       T.PIPE_SIZE_CODE,
       T.BUCKLE_TYPE_CODE,
       T.ROLL_STANDRAD_CODE,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.CHECK_NO,
       T.ORD_LN_DLY_PK,
       T.PRT_FLAG,
       T.PRO_PLAN_ID,
       
       T2.FEED_ROW_NO,
       T2.DB_NUM,
       T2.MAT_HEIGHT,
       T2.MAT_TOTAL_HEIGHT,
       T2.FEED_NUM,
       T2.FEED_LENGTH,
       T2.USE_LENGTH,
       T2.SAW_FALG,
       T2.COL_MODE,
       TO_CHAR(T2.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       T2.COL_USER,
       T2.COL_SHIFT,
       T2.COL_GROUP,
       T2.NON_USE_LENGTH,
       T2.SCRAP_DBNUM,
       T2.SCRAP_FEEDNUM,
       T2.QUALIFIED_NUM,
       T2.CHANGE_NUM,
       T2.FEED_NUM_PLAN

  FROM MIL_PLAN T, MIL_FEED_PLAN T2
 WHERE 1 = 1
   AND T.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
   AND T.LOT_NO = T2.LOT_NO
   AND T.PLINE_CODE = T2.PLINE_CODE
   AND T.STATUS = '00'
   AND T.JUDGE_STOVE_NO || '&' LIKE ('%' || ? || '%')
   AND T.LOT_NO || '&' LIKE ('%' || ? || '%')
   AND T.PLINE_CODE || '&' LIKE ('%' || ? || '%')
   AND T.FEED_TIME BETWEEN TO_DATE('" || ?|| "','YYYY-MM-DD HH24:MI:SS')
   AND TO_DATE('" || ? || "','YYYY-MM-DD HH24:MI:SS')
   
   
]]>
</query>

<query id = "FrmFeedLoad.doQueryData2" desc = "查询">
<![CDATA[
 select T.HEAT_PLAN_NO,
       t.PASS_NAME,
       T.BAL_YEAR_MONTH,
       T.PRO_MONTH,
       T.CREATE_NAME,
       T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_NO,
       T.ZY_BATCH_ID,
       T.INWL_DESC,
       T.OUTWL_DESC,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.PLINE_CODE,
       T.DIAMETER,
       T.LEN_GP_SINGLE,
       --T1.HEAT_PLAN_SQE,
       T.LEN_GP_SINGLE * MAX(T1.CUT_NUM_GP) LEN_GP,
       MAX(T1.CUT_NUM_GP) CUT_NUM_GP,
       T.GRADENAME,
       T.PROD_STANDARD,
       SUM(T1.PLAN_INDOUBLE_NUM) PLAN_INDOUBLE_NUM,
       SUM(T1.PLAN_INDOUBLE_WT) PLAN_INDOUBLE_WT,
       SUM(T1.PLAN_INDOUBLE_NUM * T1.CUT_NUM_GP) DBZ,
       T.AIMWALLTHICK,
       -- T.OUTPUT_STANDARD,
       DECODE(T.DECISION, 'A', T.OUTPUT_STANDARD, T.PROD_STANDARD) OUTPUT_STANDARD,
       T.PROCESS_DESC_C,
       T.CRAFT_FILE_NO,
       T.ROLL_LENGTH,
       T.DIAMETER_MANDREL,
       T.OUTNUM_CUT,
       T.PRODUCNAME,
       T.STEELNAME,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.OUTDIAMETER_ZG,
       T.WALLTHICK_ZG,
       T.MODEL_DESC,
       DECODE(T.IF_MONITOR, '0', '不监制', '1', '监制') IF_MONITOR,
       T.PRO_PLAN_ID,
       T.gx_plan_no,
       T.DECISION,
       
       T.GOWHERE_NAME,
       DECODE(T.OUTS_BILLET_FL, '0', '自炼', '外购坯') OUTS_BILLET_FL,
       DECODE(T.GPTYPE, '1', '铸坯', '2', '锻坯') GPTYPE,
       MAX(T1.JUGDE_APPLY_CODE) JUGDE_APPLY_CODE,
       T.FEED_HEAT_NO,
       T2.FINISH_USER,
       T2.TOM CREATE_TIME,
       T2.CUT_TARGET,
       T2.CUT_LENGTH,
       T2.CUT_WEIGHT,
       DECODE(T2.TYPE, '0', '正常计划', '1', '试轧料') TYPE1,
       NVL(SUM(T1.REAL_INDOUBLE_NUM), 0) REAL_INDOUBLE_NUM,
       ROW_NUMBER() OVER(PARTITION BY T.ZY_BATCH_ID ORDER BY T.FEED_HEAT_NO) RN
  from PLN_ZY_ZG_M t, PLN_ZY_ZG_C T1, MIL_PLAN T2, PLN_ORDER_ZG_S S
 where t.heat_plan_no = t1.heat_plan_no(+)
   and T.FEED_HEAT_NO = REGEXP_REPLACE(T2.JUDGE_STOVE_NO, '-.*', '')
       --SUBSTR(T2.JUDGE_STOVE_NO, 1, DECODE(T.PLINE_CODE, 'C072', 9, 6))
   AND T.PRO_PLAN_ID = T2.PRO_PLAN_ID
   AND T.GX_PLAN_NO = T2.GX_PLAN_NO
   AND SUBSTR(T2.JUDGE_STOVE_NO,-2) = '01'
   AND T.PRO_PLAN_ID = S.PRO_PLAN_ID(+)
   AND T.GX_PLAN_NO = S.GX_PLAN_NO(+)
   AND T.HEAT_PLAN_NO = T2.ID
   AND T2.BACK_SLAB_FLAG <> '2' 
   #SomeThing#
 GROUP BY T.HEAT_PLAN_NO,
          t.PASS_NAME,
          T.BAL_YEAR_MONTH,
          T.PRO_MONTH,
          T.CREATE_NAME,
          T.ORDER_NO,
          T.ORDER_SEQ,
          T.ZY_BATCH_ID,
          T.INWL_DESC,
          T.OUTWL_DESC,
          T.STOVE_NO,
          T.JUDGE_STOVE_NO,
          T.PLINE_CODE,
          T.DIAMETER,
          T.LEN_GP_SINGLE,
          T.LEN_GP_SINGLE,
          T.GRADENAME,
          T.PROD_STANDARD,
          T.AIMWALLTHICK,
          T.OUTPUT_STANDARD,
          T.PROD_STANDARD,
          T.PROCESS_DESC_C,
          T.CRAFT_FILE_NO,
          T.ROLL_LENGTH,
          T.DIAMETER_MANDREL,
          T.OUTNUM_CUT,
          T.PRODUCNAME,
          T.STEELNAME,
          T.OUTDIAMETER,
          T.WALLTHICK,
          T.OUTDIAMETER_ZG,
          T.WALLTHICK_ZG,
          T.MODEL_DESC,
          T.IF_MONITOR,
          T.PRO_PLAN_ID,
          T.gx_plan_no,
          T.DECISION,
          T.GOWHERE_NAME,
          T.OUTS_BILLET_FL,
          T.GPTYPE,
          T.FEED_HEAT_NO,
          S.GX_PRO_SEQ,
          T2.FINISH_USER,
          T2.TOM,
          T2.CUT_TARGET,
          T2.CUT_LENGTH,
          T2.CUT_WEIGHT,
          T2.TYPE
 ORDER BY T.ZY_BATCH_ID,TO_NUMBER(S.GX_PRO_SEQ) ASC, RN, T.JUDGE_STOVE_NO

]]>
</query>

<query id = "FrmFeedLoad.doQueryApplyData" desc = "查询判定信息">
<![CDATA[
   select T.JUDGE_STOVE_NO,
       T.STOVE_NO,
       (SELECT NVL(MIN(E.CUT_NUM), 1) CUT_NUM
          FROM PLN_STEELFOR_ORD E
         WHERE E.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO) CUT_NUM,
       T.ACT_DIMATER,
       T.ACT_LEN,
       T.STEEL_STANDRAD,
       T.STD_NAME,
       T.PRO_ORDER_NO,
       T.JUDGE_RESULT_TIME,
       T.ACT_COUNT,
       DECODE(T.ACT_WEIGHT, '', T.ACT_THEORY_WEIGHT, T.ACT_WEIGHT) ACT_WEIGHT,
       T.JUDGE_MAKER,
       T.JUDGE_MEMO,
       (SELECT MAX(M.REMARKS)
          FROM STL_LG_SURFACE_M M
         WHERE M.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
           AND M.PRO_PLAN_ID = T.PRO_PLAN_ID
           AND M.GX_PLAN_NO = T.GX_PLAN_NO
           AND M.SEQUENCENO = T.SEQUENCENO
           AND M.FURNACENO = T.FURNACENO) REMARKS,
       T.JUDGE_RESULT,
       DECODE(T.INSTANCY_FLAG, '0', '无', '1', '紧急放行') INSTANCY_FLAG
  from QCM_GP_JUDGE_APPLY t
 WHERE T.JUGDE_APPLY_CODE || T.JUGDE_APPLY_SQE = ?
   AND T.JUDGE_STOVE_NO = ?
]]>
</query>

<query id = "FrmFeedLoad.doQueryResultData" desc = "查询上料实绩信息">
<![CDATA[
    SELECT 
       T.FEED_ROW_NO,
       T.SEQ,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.PLINE_CODE,
       T.DB_NUM,
       T.MAT_HEIGHT,
       T.MAT_TOTAL_HEIGHT,
       T.FEED_NUM,
       T.FEED_LENGTH,
       T.USE_LENGTH,
       T.CUT_TARGET,
       T.CUT_LENGTH,
       T.CUT_WEIGHT,
       T.SAW_FALG,
       T.REMARK,
       T.COL_MODE,
       TO_CHAR(T.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       T.COL_USER,
       T.COL_SHIFT,
       T.COL_GROUP,
       T.DB_LENGTH,
       T.NON_USE_LENGTH,
       T.PIPE_SECTION,
       T.SCRAP_DBNUM,
       T.SCRAP_FEEDNUM,
       T.DB_HEIGHT,
       T.QUALIFIED_NUM,
       T.CHANGE_NUM,
       T.FEED_NUM_PLAN,
       T.ACT_CUT_LENGTH,
       T.ACT_CUT_WEIGHT
 FROM MIL_FEED_PLAN_RESULT T
 WHERE 1 = 1
   AND T.JUDGE_STOVE_NO = ? 
   AND T.LOT_NO = ? 
   AND T.PLINE_CODE = ? 
   
]]>
</query>

<query id = "FrmFeedLoad.doQueryMatData" desc = "查询上料行信息">
<![CDATA[
 select 'True' CHK,
       T.JUDGE_STOVE_NO,
       T.FEED_HEAT_NO,
       T.HEAT_PLAN_SQE,
       T.JUGDE_APPLY_CODE,
       T.PLAN_INDOUBLE_NUM ACT_COUNT,
       T.PLAN_INDOUBLE_NUM,
       T.PLAN_INDOUBLE_WT,
       T.REAL_INDOUBLE_NUM,
       T.REAL_INDOUBLE_WT,
       T.LEN_GP_SINGLE,
       T.WT_GP_SINGLE,
       T.CUT_NUM_GP,
       T.CUT_TARGET,
       T.CUT_LENGTH,
       T.CUT_WEIGHT,
       T.LENGTH_M,
       T.WEIGHT_M,
       T1.INWL_DESC,
       T1.ORDER_NO || '/' || T1.ORDER_SEQ ORDER_NO,
       T2.FEED_LENGTH
  from PLN_ZY_ZG_C t, PLN_ZY_ZG_M T1, MIL_FEED_PLAN T2
 WHERE T.HEAT_PLAN_NO = T1.HEAT_PLAN_NO
   AND T.HEAT_PLAN_SQE = T2.FEED_ROW_NO(+)
   and t.feed_heat_no =
       SUBSTR(T2.JUDGE_STOVE_NO, 1, DECODE(T.PLINE_CODE, 'C072', 9, 6))
   AND T.HEAT_PLAN_NO = ?
   AND T.PLINE_CODE = ?
   AND T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
 ORDER BY T.FEED_HEAT_NO,
          T.LENGTH_M_OLD,
          T.PLAN_INDOUBLE_WT,
          T.PLAN_INDOUBLE_NUM
]]>
</query>

<query id = "FrmFeedLoad.doQueryMatDataAfter" desc = "已上料：查询库存信息">
<![CDATA[
select T.JUDGE_STOVE_NO,
       MAX(T2.FEED_HEAT_NO) FEED_HEAT_NO,
       T.FIX_NUM,
       t.JUDGE_RESULT_CODE,
       (select c.basename
          from com_base_info c
         where c.basecode = t.JUDGE_RESULT_CODE) JUDGE_RESULT_NAME,
       T2.WEIGHT_M,
       MAX(T.MATERIAL_NAME) MATERIAL_NAME,
       MAX(T.ACT_LEN) ACT_LEN,
       MAX(T.FIX_LEN) FIX_LEN,
       T.JUGDE_APPLY_CODE,
       MAX(T.ORDER_NO) || MAX(T.ORDER_SEQ) ORDER_NO,
       MAX(T.OLD_STD_NAME) OLD_STD_NAME,
       MAX(T1.STORAGE_NO) STORAGE_NO,
       MAX(T1.LOCATION_NAME) LOCATION_NO,
       0 ACT_COUNT,
       0 ACT_WEIGHT,
       COUNT(1) ACT_COUNT2,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT2,
       MAX(DECODE(T2.REAL_INDOUBLE_NUM,
                  0,
                  T2.PLAN_INDOUBLE_NUM,
                  '',
                  T2.PLAN_INDOUBLE_NUM,
                  T2.REAL_INDOUBLE_NUM)) PLAN_INDOUBLE_NUM,
       MAX(DECODE(T2.REAL_INDOUBLE_WT,
                  0,
                  T2.PLAN_INDOUBLE_WT,
                  '',
                  T2.PLAN_INDOUBLE_WT,
                  T2.REAL_INDOUBLE_WT)) PLAN_INDOUBLE_WT
  from MAT_GP_M_HISTORY t, YDM_GP_BUTTRESS T1, PLN_ZY_ZG_C T2
 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO(+)
   AND T.MAT_NO = T1.MAT_NO(+)
   AND T.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
   AND T.FIX_NUM = T2.CUT_NUM_GP
   AND T.JUGDE_APPLY_CODE = T2.JUGDE_APPLY_CODE
   AND T.HANGING_FLAG = '1'
   AND T2.HEAT_PLAN_NO = ?
   AND T2.PLINE_CODE = ?
   AND T.PRO_PLAN_ID_ZG = ?
   AND T.GX_PLAN_NO_ZG = ?
 GROUP BY T.JUDGE_STOVE_NO,
          T.FIX_NUM,
          T2.WEIGHT_M,
          t.JUDGE_RESULT_CODE,
          T.JUGDE_APPLY_CODE

]]>
</query>

<query id = "FrmFeedLoad.doQueryMatData2" desc = "未上料:查询库存信息">
<![CDATA[
 select T.JUDGE_STOVE_NO,
       T.ACT_LEN,
       T.FIX_NUM,
       T.FIX_LEN,
       DECODE(T.BACK_FLAG, '0', '正常', '1', '回炉坯', '2', '套尺坯') BACK_FLAG,
       t.JUDGE_RESULT_CODE,
       (select c.basename
          from com_base_info c
         where c.basecode = t.JUDGE_RESULT_CODE) JUDGE_RESULT_NAME,
       
       T.JUGDE_APPLY_CODE,
       (select s.storage_name
          from ydm_bs_storage s
         where s.storage_no = t1.storage_no) STORAGE_NO,
       T1.LOCATION_NAME LOCATION_NO,
       COUNT(1) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT
  from MAT_GP_M t, YDM_GP_BUTTRESS T1
 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
   AND T.MAT_NO = T1.MAT_NO
      --AND T.HANGING_FLAG = '1'
   AND T.JUDGE_STOVE_NO = ?
   AND T.PRO_PLAN_ID_ZG = ?
   AND T.GX_PLAN_NO_ZG = ?
 GROUP BY T.JUDGE_STOVE_NO,
          T.ACT_LEN,
          T.FIX_NUM,
          T.FIX_LEN,
          T.BACK_FLAG,
          T.JUGDE_APPLY_CODE,
          t.JUDGE_RESULT_CODE,
          t1.storage_no,
          T1.LOCATION_NAME
  ORDER BY T.ACT_LEN, ACT_WEIGHT, ACT_COUNT
]]>
</query>

<query id = "FrmFeedLoad.doQueryMatDataAfter2" desc = "已上料:查询库存信息">
<![CDATA[
  select T.JUDGE_STOVE_NO,
       T.ACT_LEN,
       T.FIX_NUM,
       T.FIX_LEN,
       t.JUDGE_RESULT_CODE,
       (select c.basename
          from com_base_info c
         where c.basecode = t.JUDGE_RESULT_CODE) JUDGE_RESULT_NAME,
       
       T.JUGDE_APPLY_CODE,
       (select s.storage_name
          from ydm_bs_storage s
         where s.storage_no = t1.storage_no) STORAGE_NO,
       T1.LOCATION_NAME LOCATION_NO,
       COUNT(1) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT
  from Mat_Gp_m_History t, ydm_gp_outlist T1
 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
   AND T.MAT_NO = T1.MAT_NO
   and t1.outstock_type_name = '投料出库'
      --AND T.HANGING_FLAG = '1'
   AND T.JUDGE_STOVE_NO = ?
   AND T.PRO_PLAN_ID_ZG = ?
   AND T.GX_PLAN_NO_ZG = ?
 GROUP BY T.JUDGE_STOVE_NO,
          T.ACT_LEN,
          T.FIX_NUM,
          T.FIX_LEN,
          T.JUGDE_APPLY_CODE,
          t.JUDGE_RESULT_CODE,
          t1.storage_no,
          T1.LOCATION_NAME
  
]]>
</query>

<query id = "FrmFeedLoad.doQueryResultDataByFeedRowNo" desc = "根据上料行feedRowNo查询些上料行是否已存在">
<![CDATA[
   select COUNT(1) COUNT
  from MIL_FEED_PLAN_RESULT t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.FEED_ROW_NO = ?
   AND T.PLINE_CODE = ?
]]>
</query>


<query id = "FrmFeedLoad.add" desc = "新增">
<![CDATA[
	 INSERT INTO MIL_FEED_PLAN_RESULT(
        FEED_ROW_NO,
        SEQ,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        PLINE_CODE,
        DB_NUM,
        MAT_HEIGHT,
        MAT_TOTAL_HEIGHT,
        FEED_NUM,
        FEED_LENGTH,
        USE_LENGTH,
        CUT_TARGET,
        CUT_LENGTH,
        CUT_WEIGHT,
        SAW_FALG,
        REMARK,
        COL_MODE,
        COL_TIME,
        COL_USER,
        COL_SHIFT,
        COL_GROUP,
        DB_LENGTH,
        NON_USE_LENGTH,
        PIPE_SECTION,
        SCRAP_DBNUM,
        SCRAP_FEEDNUM,
        DB_HEIGHT,
        QUALIFIED_NUM,
        CHANGE_NUM,
        FEED_NUM_PLAN,
        ACT_CUT_LENGTH,
        ACT_CUT_WEIGHT)
 VALUES( 
        '#FEED_ROW_NO#',
        '#SEQ#',
        '#LOT_NO#',
        '#STOVE_NO#',
        '#JUDGE_STOVE_NO#',
        '#PLINE_CODE#',
        '#DB_NUM#',
        '#MAT_HEIGHT#',
        '#MAT_TOTAL_HEIGHT#',
        '#FEED_NUM#',
        '#FEED_LENGTH#',
        '#USE_LENGTH#',
        '#CUT_TARGET#',
        '#CUT_LENGTH#',
        '#CUT_WEIGHT#',
        '#SAW_FALG#',
        '#REMARK#',
        '#COL_MODE#',
        SYSDATE,
        '#COL_USER#',
        '#COL_SHIFT#',
        '#COL_GROUP#',
        '#DB_LENGTH#',
        '#NON_USE_LENGTH#',
        '#PIPE_SECTION#',
        '#SCRAP_DBNUM#',
        '#SCRAP_FEEDNUM#',
        '#DB_HEIGHT#',
        '#QUALIFIED_NUM#',
        '#CHANGE_NUM#',
        '#FEED_NUM_PLAN#',
        '#ACT_CUT_LENGTH#',
        '#ACT_CUT_WEIGHT#')
]]>
</query>

<query id = "FrmFeedLoad.delete" desc = "删除">
<![CDATA[
  delete from MIL_FEED_PLAN_RESULT t
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.FEED_ROW_NO = ?
   AND T.PLINE_CODE = ?
]]>
</query>

<query id = "FrmFeedLoad.SelectStatus" desc = "查询生产状态">
<![CDATA[
   SELECT COUNT(1) ACOUNT
   FROM MIL_PLAN T, MIL_FEED_PLAN T1
  WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
    AND T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
    AND T.PRO_PLAN_ID = ?
    AND T.GX_PLAN_NO = ?
    AND T.PLINE_CODE = ?
    AND (T.STATUS <> '00' OR T1.SAW_FALG <> '0')
]]>
</query>

<query id = "FrmFeedLoad.SelectSyncFlag" desc = "查询财务系统同步状态">
<![CDATA[
SELECT T.*
  FROM PLN_ZY_ZG_M T1, FMIS_GP_OUTLIST T
 WHERE T1.IS_LOAD = '1'
   AND T1.HEAT_PLAN_NO = ?
   AND T.OUTSTOCK_TYPE_CODE = '800809'
   AND T1.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO
   AND T1.PRO_PLAN_ID = T.PRO_PLAN_ID_ZG
   AND T1.GX_PLAN_NO = T.GX_PLAN_NO_ZG
]]>
</query>

<query id = "FrmFeedLoad.deleteFmis" desc = "删除财务系统接口数据">
<![CDATA[
DELETE FROM FMIS_GP_OUTLIST T
    WHERE T.SYNC_FLAG = '0'
      AND T.JUDGE_STOVE_NO = ?
      AND T.PRO_PLAN_ID_ZG = ?
      AND T.GX_PLAN_NO_ZG = ?
      AND T.OUTSTOCK_TYPE_CODE = '800809'
]]>
</query>

<query id = "FrmFeedLoad.SelectGetSample" desc = "查询是否取样">
<![CDATA[
  SELECT COUNT(1) ACOUNT
  FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
   AND T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.PLINE_CODE = ?
   AND T.GET_SAMPLE_SHIFT IS NOT NULL
]]>
</query>

<query id = "FrmFeedLoad.SelectKCZS" desc = "查询库存支数">
<![CDATA[
select COUNT(1) ACT_COUNT
  from MAT_GP_M t, YDM_GP_BUTTRESS T1
 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
   AND T.MAT_NO = T1.MAT_NO
   AND T.HANGING_FLAG = '1'
   AND T.JUDGE_STOVE_NO = ?
   AND T.PRO_PLAN_ID_ZG = ?
   AND T.GX_PLAN_NO_ZG = ?
   AND T.ACT_LEN = ?
   AND NVL(T.JUGDE_APPLY_CODE, '/') = NVL(?, '/')
]]>
</query>

<query id = "FrmFeedLoad.SelectTCZS" desc = "查询套尺原炉号没上料，套尺不能上料">
<![CDATA[
SELECT COUNT(1) ACT_COUNT
  FROM MAT_GP_M M
 WHERE M.MAT_NO IN
       (select T.MAT_NO_OLD
          from MAT_GP_M t, YDM_GP_BUTTRESS T1
         WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
           AND T.MAT_NO = T1.MAT_NO
           AND T.HANGING_FLAG = '1'
           AND T.BACK_FLAG = '2'
           AND T.JUDGE_STOVE_NO = ?
           AND T.PRO_PLAN_ID_ZG = ?
           AND T.GX_PLAN_NO_ZG = ?
           AND T.ACT_LEN = ?
           AND NVL(T.JUGDE_APPLY_CODE, '/') = NVL(?, '/'))
]]>
</query>

<query id = "FrmFeedLoad.SelectMilPlanIsHave" desc = "查询轧管炉号是否已生产">
<![CDATA[
select COUNT(1) ACOUNT,
       B.PLINE_NAME,
       TO_CHAR(T.END_TIME, 'YYYY-MM-DD') END_TIME
  from MIL_FEEDSAW_RESULT t, COM_BASE_PLINE B
 WHERE T.PLINE_CODE = B.PLINE_CODE
   AND T.JUDGE_STOVE_NO = ? || '-01'
 GROUP BY T.END_TIME, B.PLINE_NAME
]]>
</query>

<query id = "FrmFeedLoad.SelectApplyStatus" desc = "查询送判状态 ">
<![CDATA[
select sum(ACOUNT) ACOUNT
  from (select COUNT(1) ACOUNT
          from QCM_GP_JUDGE_APPLY t
         WHERE T.IS_FLAG = '0'
           AND (T.JUDGE_RESULT_CODE IN ('40740701', '40740706') OR
               T.INSTANCY_FLAG = '1')
           AND NVL(T.JUGDE_APPLY_CODE || T.JUGDE_APPLY_SQE, '/') =
               NVL(?, '/')
           AND T.JUDGE_STOVE_NO = ?
        
        UNION ALL
        
        select count(1) ACOUNT
          from MAT_GP_M t
         where (t.judge_result_code in ('40740701', '40740702', '40740706') or
               t.instancy_flag = '1')
           and t.judge_stove_no = ?)

]]>
</query>

<query id = "FrmFeedLoad.updateState" desc = "修改轧管计划表状态">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_PRO_PLAN_ID    MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_PLAN.GX_PLAN_NO%TYPE := ?;
  V_PLINE_CODE     MIL_PLAN.PLINE_CODE%TYPE := ?;

BEGIN
  update mil_plan t
     set t.IS_LOAD   = '1',
         t.col_shift = ?,
         t.col_group = ?,
         t.col_user  = ?,
         t.col_time  = sysdate,
         t.START_TIME = sysdate,
         t.USER_ID   = ?,
         t.DB_NUM    = ?,
         t.BRANCH    = ?,
         t.TON       = ?,
         BAL_YEAR_MONTH = ?
   where REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO
     and t.pro_plan_id = V_PRO_PLAN_ID
     and t.gx_plan_no = V_GX_PLAN_NO
     and t.pline_code = V_PLINE_CODE;

  update PLN_ZY_ZG_M t
     set t.IS_LOAD = '1', t.PLANSTATUS = '20'
   where t.Feed_Heat_No = V_JUDGE_STOVE_NO
     and t.pro_plan_id = V_PRO_PLAN_ID
     and t.gx_plan_no = V_GX_PLAN_NO
     and t.pline_code = V_PLINE_CODE;
     
      FOR MYROW IN (SELECT *
                  FROM PLN_ZY_ZG_C T
                 WHERE t.Feed_Heat_No = V_JUDGE_STOVE_NO
                   AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO = V_GX_PLAN_NO
                   AND T.REAL_INDOUBLE_NUM = 0) LOOP
  
    --复制数据到历史表
    insert into MIL_FEED_PLAN_HISTORY
      select *
        from MIL_FEED_PLAN F
       where F.FEED_ROW_NO = MYROW.HEAT_PLAN_SQE;
  
    --删除上料行表记录
    DELETE FROM MIL_FEED_PLAN F WHERE F.FEED_ROW_NO = MYROW.HEAT_PLAN_SQE;
  
  END LOOP;
END;
]]>
</query>

<query id = "FrmFeedLoad.updateZGC" desc = "修改轧管计划表上料支、吨">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO   MAT_GP_M.JUDGE_STOVE_NO%TYPE := ?;
  V_JUGDE_APPLY_CODE MAT_GP_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_ACT_COUNT        PLN_ZY_ZG_C.REAL_INDOUBLE_NUM%TYPE := ?;
  V_FIX_NUM          MAT_GP_M.FIX_NUM%TYPE := ?;
  V_PRO_PLAN_ID      MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO       MIL_PLAN.GX_PLAN_NO%TYPE := ?;
  V_HEAT_PLAN_SQE    PLN_ZY_ZG_C.HEAT_PLAN_SQE%TYPE := ?;
  V_CUT_LENGTH       PLN_ZY_ZG_C.CUT_LENGTH%TYPE := ?;

BEGIN

  FOR MYROW IN (SELECT *
                  FROM PLN_ZY_ZG_C T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND NVL(T.JUGDE_APPLY_CODE, '/') =
                       NVL(V_JUGDE_APPLY_CODE, '/')
                   AND T.CUT_NUM_GP = V_FIX_NUM
                   AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO = V_GX_PLAN_NO
                   AND T.HEAT_PLAN_SQE = V_HEAT_PLAN_SQE) LOOP
  
    update PLN_ZY_ZG_C t
       set t.REAL_INDOUBLE_NUM = V_ACT_COUNT,
           t.REAL_INDOUBLE_WT =
           (SELECT SUM(DECODE(A.ACT_WEIGHT,
                              '',
                              A.ACT_THEORY_WEIGHT,
                              A.ACT_WEIGHT))
              FROM MAT_GP_M_HISTORY A
             WHERE A.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
               AND A.PRO_PLAN_ID_ZG = MYROW.PRO_PLAN_ID
               AND A.GX_PLAN_NO_ZG = MYROW.GX_PLAN_NO
               AND A.ACT_LEN = MYROW.LENGTH_M_OLD
               AND A.BACK_FLAG NOT IN ('1', '3')
               AND NVL(A.CUT_YU_LONG, 0) = NVL(V_CUT_LENGTH, 0)
               AND NVL(A.JUGDE_APPLY_CODE, '/') =
                   NVL(MYROW.JUGDE_APPLY_CODE, '/')) -
           DECODE(T.CUT_TARGET, '套尺', T.CUT_WEIGHT * V_ACT_COUNT,'回库', T.CUT_WEIGHT * V_ACT_COUNT, 0)
     where t.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO
       AND T.HEAT_PLAN_SQE = MYROW.HEAT_PLAN_SQE;
  
    UPDATE MIL_FEED_PLAN T
       SET T.FEED_NUM         = V_ACT_COUNT,
           T.FEED_NUM_PLAN    = V_ACT_COUNT,
           T.MAT_TOTAL_HEIGHT =
           (SELECT t1.REAL_INDOUBLE_WT
              FROM PLN_ZY_ZG_C T1
             WHERE T1.HEAT_PLAN_SQE = T.FEED_ROW_NO),
           T.QUALIFIED_NUM    = T.DB_NUM * V_ACT_COUNT
     WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = MYROW.FEED_HEAT_NO
       AND T.DB_NUM = V_FIX_NUM
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.FEED_ROW_NO = MYROW.HEAT_PLAN_SQE;
  
  END LOOP;
END;

]]>
</query>

<query id = "FrmFeedLoad.updateZGCTH" desc = "修改轧管计划表上料支、吨(天淮)">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO   MAT_GP_M.JUDGE_STOVE_NO%TYPE := ?;
  V_JUGDE_APPLY_CODE MAT_GP_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_ACT_COUNT        PLN_ZY_ZG_C.REAL_INDOUBLE_NUM%TYPE := ?;
  V_FIX_NUM          MAT_GP_M.FIX_NUM%TYPE := ?;
  V_PRO_PLAN_ID      MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO       MIL_PLAN.GX_PLAN_NO%TYPE := ?;
  V_HEAT_PLAN_SQE    PLN_ZY_ZG_C.HEAT_PLAN_SQE%TYPE := ?;

BEGIN

  FOR MYROW IN (SELECT *
                  FROM PLN_ZY_ZG_C T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND NVL(T.JUGDE_APPLY_CODE, '/') =
                       NVL(V_JUGDE_APPLY_CODE, '/')
                   AND T.CUT_NUM_GP = V_FIX_NUM
                   AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO = V_GX_PLAN_NO
                   AND T.HEAT_PLAN_SQE = V_HEAT_PLAN_SQE) LOOP
  
    update PLN_ZY_ZG_C t
       set t.REAL_INDOUBLE_NUM = V_ACT_COUNT,
           t.REAL_INDOUBLE_WT  = ROUND(V_ACT_COUNT * MYROW.PLAN_INDOUBLE_WT /
                                       MYROW.PLAN_INDOUBLE_NUM,
                                       3)
    
     where t.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO
       AND T.HEAT_PLAN_SQE = MYROW.HEAT_PLAN_SQE;
  
    UPDATE MIL_FEED_PLAN T
       SET T.FEED_NUM         = V_ACT_COUNT,
           T.FEED_NUM_PLAN    = V_ACT_COUNT,
           T.MAT_TOTAL_HEIGHT = ROUND(V_ACT_COUNT * MYROW.PLAN_INDOUBLE_WT /
                                      MYROW.PLAN_INDOUBLE_NUM,
                                      3),
           T.QUALIFIED_NUM    = T.DB_NUM * V_ACT_COUNT
     WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = MYROW.FEED_HEAT_NO
       AND T.DB_NUM = V_FIX_NUM
       AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
       AND T.GX_PLAN_NO = V_GX_PLAN_NO
       AND T.FEED_ROW_NO = MYROW.HEAT_PLAN_SQE;
  
  END LOOP;
END;

]]>
</query>

<query id = "FrmFeedLoad.updateStateBack" desc = "修改轧管计划表状态">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_PRO_PLAN_ID    MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO     MIL_PLAN.GX_PLAN_NO%TYPE := ?;
  V_PLINE_CODE     MIL_PLAN.PLINE_CODE%TYPE := ?;

BEGIN
  update mil_plan t
     set t.IS_LOAD = '0', T.FEED_TIME = '', T.START_TIME = '',T.IS_BATCH ='0'
   where t.judge_stove_no = V_JUDGE_STOVE_NO || '-01'
     and t.pro_plan_id = V_PRO_PLAN_ID
     and t.gx_plan_no = V_GX_PLAN_NO
     and t.pline_code = V_PLINE_CODE;

  update PLN_ZY_ZG_M t
     set t.IS_LOAD = '0', t.PLANSTATUS = '10'
   where t.Feed_Heat_No = V_JUDGE_STOVE_NO
     and t.pro_plan_id = V_PRO_PLAN_ID
     and t.gx_plan_no = V_GX_PLAN_NO
     and t.pline_code = V_PLINE_CODE;

  update PLN_ZY_ZG_C t
     set t.REAL_INDOUBLE_NUM = 0, t.REAL_INDOUBLE_WT = 0.0
   where t.HEAT_PLAN_NO =
         (select m.heat_plan_no
            from PLN_ZY_ZG_M m
           where m.Feed_Heat_No = V_JUDGE_STOVE_NO
             and m.pro_plan_id = V_PRO_PLAN_ID
             and m.gx_plan_no = V_GX_PLAN_NO
             and m.pline_code = V_PLINE_CODE);

  FOR MYROW IN (SELECT *
                  FROM MIL_FEED_PLAN_HISTORY T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO || '-01'
                   AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO = V_GX_PLAN_NO) LOOP
  
    --复制数据到上料行表
    insert into MIL_FEED_PLAN
      select *
        from MIL_FEED_PLAN_HISTORY F
       where F.FEED_ROW_NO = MYROW.Feed_Row_No;
  
    --删除历史表
    DELETE FROM MIL_FEED_PLAN_HISTORY F
     WHERE F.FEED_ROW_NO = MYROW.Feed_Row_No;
  
  END LOOP;
END;

]]>
</query>

<query id = "FrmFeedLoad.node" desc = "上料确认">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO   YDM_GP_OUTLIST.JUDGE_STOVE_NO%TYPE := ?; --管坯判定炉号
  V_JUGDE_APPLY_CODE MAT_GP_M.JUGDE_APPLY_CODE%TYPE := ?; --判定单号
  V_ACT_COUNT        MAT_GP_M.ACT_LEN%TYPE := ?; --实际上料支
  V_FIX_NUM          MAT_GP_M.FIX_NUM%TYPE := ?; --倍尺数
  V_PLINE_CODE       PLN_ZY_ZG_M.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID      PLN_ZY_ZG_M.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO       PLN_ZY_ZG_M.GX_PLAN_NO%TYPE := ?;
  V_FEED_LENGTH      MIL_FEED_PLAN.FEED_LENGTH%TYPE := ?; --上料长度
  V_OUTSTOCK_PLAN_NO YDM_GP_OUTLIST.OUTSTOCK_PLAN_NO%TYPE := ?; --轧管炉计划ID
  V_OUTSTOCK_DOC_OA  YDM_GP_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  V_OUTSTOCK_DOC_CQ  YDM_GP_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  V_OUTSTOCK_DOC_HO  YDM_GP_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  --V_OUTSTOCK_TIME    YDM_GP_OUTLIST.CREATE_TIME%TYPE := TO_DATE(V_TIME,'YYYY-MM-DD hh24:mi:ss');
  V_BATHYEAR      MAT_GP_M.BAL_YEAR_MONTH%TYPE := ?;
  V_KY            PLN_ZY_ZG_M.PLINE_CODE%TYPE := ?; --1是跨月，空是没跨月
  V_OUT_BC        YDM_GP_OUTLIST.OUT_BC%TYPE := ?; --出库班次
  V_OUT_BZ        YDM_GP_OUTLIST.OUT_BZ%TYPE := ?; --出库班组
  V_CREATE_NAME   YDM_GP_OUTLIST.CREATE_NAME%TYPE := ?; --出库人
  V_TIME          YDM_GP_OUTLIST.MATERIAL_NAME%TYPE := ?;
  V_OUTSTOCK_TIME YDM_GP_OUTLIST.CREATE_TIME%TYPE := TO_DATE(V_TIME,
                                                             'YYYY-MM-DD hh24:mi:ss');
  V_PLINE_NAME    COM_BASE_PLINE.PLINE_NAME%TYPE := NULL;
  V_ICOUNT        NUMBER := 1;

  V_CUT_TARGET        PLN_ZY_ZG_C.CUT_TARGET%TYPE := ?; --切损去向
  V_CUT_LENGTH        PLN_ZY_ZG_C.CUT_LENGTH%TYPE := ?; --切损长度
  V_CUT_WEIGHT        PLN_ZY_ZG_C.CUT_WEIGHT%TYPE := ?; --切损重量
  V_PLAN_INDOUBLE_NUM PLN_ZY_ZG_C.PLAN_INDOUBLE_NUM%TYPE := ?; --计划上料支
  V_MAT_NO            MAT_GP_M.MAT_NO%TYPE := NULL; --材料号
  V_INSTOCK_DOC       YDM_GP_INLIST.INSTOCK_DOC%TYPE := NULL; --入库单编号
  V_STORAGE_NO        YDM_GP_BUTTRESS.STORAGE_NO%TYPE := NULL; --仓库代码
  V_LOCATION_NO       YDM_GP_BUTTRESS.LOCATION_NO%TYPE := NULL; --库位代码
  V_LOCATION_NAME     YDM_GP_BUTTRESS.LOCATION_NAME%TYPE := NULL; --库位名称
  V_ZY_BATCH_ID       PLN_ZY_ZG_M.ZY_BATCH_ID%TYPE := NULL; --生产批号

BEGIN
  SELECT T.ZY_BATCH_ID
    INTO V_ZY_BATCH_ID
    FROM PLN_ZY_ZG_M T
   WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.PRO_PLAN_ID = V_PRO_PLAN_ID
     AND T.GX_PLAN_NO = V_GX_PLAN_NO
     AND ROWNUM = 1;
  --生成 投料出库单编号
  SELECT 'OA' ||
         TO_CHAR(TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'), 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) DI
    INTO V_OUTSTOCK_DOC_OA
    FROM YDM_GP_OUTLIST T
   WHERE T.OUTSTOCK_DOC LIKE
         'OA' ||
         TO_CHAR(TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'), 'YYMMDD') ||
         '_____'
     and t.outstock_type_code = '800801';

  --生成 产权出库单编号
  SELECT 'CQ' ||
         TO_CHAR(TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'), 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) DI
    INTO V_OUTSTOCK_DOC_CQ
    FROM YDM_GP_OUTLIST T
   WHERE T.OUTSTOCK_DOC LIKE
         'CQ' ||
         TO_CHAR(TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'), 'YYMMDD') ||
         '_____'
     and t.outstock_type_code = '800809';

  --生成 出库红冲单编号
  SELECT 'HO' ||
         TO_CHAR(TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'), 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) DI
    INTO V_OUTSTOCK_DOC_HO
    FROM YDM_GP_OUTLIST T
   WHERE T.OUTSTOCK_DOC LIKE
         'HO' ||
         TO_CHAR(TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'), 'YYMMDD') ||
         '_____'
     and t.outstock_type_code = '800806';

  --产线名称
  SELECT B.PLINE_NAME
    INTO V_PLINE_NAME
    FROM COM_BASE_PLINE B
   WHERE B.PLINE_CODE = V_PLINE_CODE;

  --生成 返库入库单编号
  SELECT 'FK' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 9)), 0) + 1, 5, 0) DI
    INTO V_INSTOCK_DOC
    FROM YDM_GP_INLIST T
   WHERE T.INSTOCK_DOC LIKE 'FK' ||
         TO_CHAR(TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'),
                                    'YYMMDD') || '_____'
     AND T.INSTOCK_TYPE_CODE = '800710';

  --仓库代码
  SELECT DECODE(V_PLINE_CODE,
                'C008',
                'TCC7',
                'C009',
                'TCC5',
                'C010',
                'TCC6',
                'C017',
                'TCC8',
                'C072',
                'TTH1'),
         DECODE(V_PLINE_CODE,
                'C008',
                'TCC710101',
                'C009',
                'TCC510104',
                'C010',
                'TCC611202',
                'C017',
                'TCC811502',
                'C072',
                (select T1.LOCATION_NO
                   from MAT_GP_M t, YDM_BS_LOCATION T1
                  WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                    AND T.PRO_PLAN_ID_ZG = V_PRO_PLAN_ID
                    AND T.GX_PLAN_NO_ZG = V_GX_PLAN_NO
                    AND T1.STORAGE_NO = 'TTH1'
                    AND T1.LOCATION_NAME LIKE 'ST' || T.DIMATER || 'A'
                    AND ROWNUM = 1)),
         DECODE(V_PLINE_CODE,
                'C008',
                '回库料架1-1',
                'C009',
                '管坯库A区四号料架',
                'C010',
                '虚拟库位',
                'C017',
                '虚拟库位一号',
                'C072',
                (select T1.LOCATION_NAME
                   from MAT_GP_M t, YDM_BS_LOCATION T1
                  WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                    AND T.PRO_PLAN_ID_ZG = V_PRO_PLAN_ID
                    AND T.GX_PLAN_NO_ZG = V_GX_PLAN_NO
                    AND T1.STORAGE_NO = 'TTH1'
                    AND T1.LOCATION_NAME LIKE 'ST' || T.DIMATER || 'A'
                    AND ROWNUM = 1))
    INTO V_STORAGE_NO, V_LOCATION_NO, V_LOCATION_NAME
    FROM DUAL;

  FOR MYROW IN (SELECT T.*,
                       --T2.BATCH_NO,
                       T2.STORAGE_NO,
                       T2.LOCATION_NO,
                       T2.LARY_NO,
                       T2.LOC_NO,
                       T2.STORAGE_ATTR,
                       T2.STORAGE_ATTR_NAME,
                       T2.STORAGE_TYPE_NO,
                       T2.STORAGE_TYPE_NAME,
                       T2.DEPARTMENT_CODE,
                       T2.DEPARTMENT_DESC,
                       T2.MANAGEMENT_NO,
                       T2.MANAGEMENT_NAME
                  FROM MAT_GP_M T, YDM_GP_BUTTRESS T2
                 WHERE T.MAT_NO = T2.MAT_NO
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND NVL(T.JUGDE_APPLY_CODE, '/') =
                       NVL(V_JUGDE_APPLY_CODE, '/')
                   AND T.ACT_LEN = V_FEED_LENGTH
                   AND T.PRO_PLAN_ID_ZG = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO_ZG = V_GX_PLAN_NO
                 #Something#
                   AND ROWNUM <= V_ACT_COUNT
                 ORDER BY T.MAT_NO DESC) LOOP
    --套尺不写出库记录        
    IF (MYROW.IS_SETFOOT = '0') THEN
      --新增投料出库实绩表记录
      INSERT INTO YDM_GP_OUTLIST
        (OUTSTOCK_SQE,
         OUTSTOCK_PLAN_NO,
         OUTSTOCK_DOC,
         OUTSTOCK_TYPE_CODE,
         OUTSTOCK_TYPE_NAME,
         /*ICCAR_NO,
         VEHICLE_NO,*/
         MAT_NO,
         PRODUCT_FLAG,
         MAT_STATUS,
         STOVE_NO,
         FLAG_STOVE_NO,
         JUDGE_STOVE_NO,
         CAST_NO,
         CCMID,
         MATERIAL_NO,
         MATERIAL_NAME,
         GRADECODE,
         GRADENAME,
         STD_CODE,
         STD_NAME,
         DIMATER,
         HEIGHT,
         ACT_LEN,
         FIX_NUM,
         FIX_LEN,
         ACT_COUNT,
         ACT_WEIGHT,
         ACT_THEORY_WEIGHT,
         PONDER_NO,
         PONDER_GROSS_WT,
         PLINE_CODE,
         PLINE_NAME,
         PRO_ORDER_NO,
         ORDER_NO,
         ORDER_SEQ,
         ORDER_SEQ_NO,
         ORD_PK,
         ORD_LN_PK,
         ORD_LN_DLY_PK,
         BELONG_CODE,
         BELONG_NAME,
         BAR_CODE,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         LOC_NO,
         DEPARTMENT_CODE,
         DEPARTMENT_DESC,
         MANAGEMENT_NO,
         MANAGEMENT_NAME,
         /* TAR_STORAGE_NO,
         TAR_LOCATION_NO,
         TAR_LARY_NO,
         TAR_LOC_NO,
         TAR_DEPARTMENT_CODE,
         TAR_DEPARTMENT_DESC,
         TAR_MANAGEMENT_NO,
         TAR_MANAGEMENT_NAME,*/
         --TAR_REC_FLAG,
         
         RPO_TIME,
         PRO_BC,
         PRO_BZ,
         BAL_YEAR_MONTH,
         
         OUTSTOCK_TIME,
         
         STORAGE_ATTR,
         STORAGE_ATTR_NAME,
         STORAGE_TYPE_NO,
         STORAGE_TYPE_NAME,
         --HAND_FLAG,
         --VALIDFLAG,
         MEMO,
         CREATE_NAME,
         CREATE_TIME,
         UPDATE_NAME,
         UPDATE_TIME,
         /*DELETE_NAME,
         DELETE_TIME,*/
         GROUD_NO,
         /* SEND_NUM,
         RECEIV_NO,
         RECEIV_NM,*/
         --M_BILL_NO,
         PRINT_STOVE_NO,
         PRO_PLAN_ID_ZG,
         GX_PLAN_NO_ZG,
         OUT_BC,
         OUT_BZ,
         MAT_GOWHERE_CODE,
         MAT_GOWHERE_NAME,
         SUPPLY_UNIT_CODE,
         SUPPLY_UNIT,
         LOT_NO,
         SOURE_CODE,
         SOURE_NAME,
         IS_DEALER,
         BACK_FLAG)
      VALUES
        (V_OUTSTOCK_DOC_OA || LPAD(V_ICOUNT, 4, 0),
         V_OUTSTOCK_PLAN_NO,
         V_OUTSTOCK_DOC_OA,
         '800801',
         '投料出库',
         /* MYROW.ICCAR_NO,
         MYROW.VEHICLE_NO,*/
         MYROW.MAT_NO,
         MYROW.PRODUCT_FLAG,
         MYROW.MAT_STATUS,
         MYROW.STOVE_NO,
         MYROW.FLAG_STOVE_NO,
         MYROW.JUDGE_STOVE_NO,
         MYROW.CAST_NO,
         MYROW.CCMID,
         MYROW.MATERIAL_NO,
         MYROW.MATERIAL_NAME,
         MYROW.GRADECODE,
         MYROW.GRADENAME,
         MYROW.STD_CODE,
         MYROW.STD_NAME,
         MYROW.DIMATER,
         MYROW.HEIGHT,
         MYROW.ACT_LEN,
         MYROW.FIX_NUM,
         MYROW.FIX_LEN,
         MYROW.ACT_COUNT,
         MYROW.ACT_WEIGHT,
         MYROW.ACT_THEORY_WEIGHT,
         MYROW.PONDER_NO,
         MYROW.PONDER_GROSS_WT,
         MYROW.PLINE_CODE,
         MYROW.PLINE_NAME,
         MYROW.PRO_ORDER_NO,
         MYROW.ORDER_NO,
         MYROW.ORDER_SEQ,
         MYROW.ORDER_SEQ_NO,
         MYROW.ORD_PK,
         MYROW.ORD_LN_PK,
         MYROW.ORD_LN_DLY_PK,
         MYROW.BELONG_CODE,
         MYROW.BELONG_NAME,
         MYROW.BAR_CODE,
         MYROW.STORAGE_NO,
         MYROW.LOCATION_NO,
         MYROW.LARY_NO,
         MYROW.LOC_NO,
         MYROW.DEPARTMENT_CODE,
         MYROW.DEPARTMENT_DESC,
         MYROW.MANAGEMENT_NO,
         MYROW.MANAGEMENT_NAME,
         /* MYROW.TAR_STORAGE_NO,
         MYROW.TAR_LOCATION_NO,
         MYROW.TAR_LARY_NO,
         MYROW.TAR_LOC_NO,
         MYROW.TAR_DEPARTMENT_CODE,
         MYROW.TAR_DEPARTMENT_DESC,
         MYROW.TAR_MANAGEMENT_NO,
         MYROW.TAR_MANAGEMENT_NAME,*/
         --MYROW.TAR_REC_FLAG,
         
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         MYROW.PRO_BC,
         MYROW.PRO_BZ,
         V_BATHYEAR,
         
         V_OUTSTOCK_TIME,
         
         MYROW.STORAGE_ATTR,
         MYROW.STORAGE_ATTR_NAME,
         MYROW.STORAGE_TYPE_NO,
         MYROW.STORAGE_TYPE_NAME,
         
         MYROW.MEMO,
         V_CREATE_NAME,
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         V_CREATE_NAME,
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         
         MYROW.GROUD_NO,
         /*MYROW.SEND_NUM,
         MYROW.RECEIV_NO,
         MYROW.RECEIV_NM,*/
         --MYROW.M_BILL_NO,
         MYROW.PRINT_STOVE_NO,
         V_PRO_PLAN_ID,
         V_GX_PLAN_NO,
         V_OUT_BC,
         V_OUT_BZ,
         V_PLINE_CODE,
         V_PLINE_NAME,
         MYROW.SUPPLY_UNIT_CODE,
         MYROW.SUPPLY_UNIT,
         V_ZY_BATCH_ID,
         MYROW.SOURE_CODE,
         MYROW.SOURE_NAME,
         MYROW.IS_DEALER,
         MYROW.BACK_FLAG);
    
      --新增产权出库实绩表记录
      INSERT INTO YDM_GP_OUTLIST
        (OUTSTOCK_SQE,
         OUTSTOCK_PLAN_NO,
         OUTSTOCK_DOC,
         OUTSTOCK_TYPE_CODE,
         OUTSTOCK_TYPE_NAME,
         /*ICCAR_NO,
         VEHICLE_NO,*/
         MAT_NO,
         PRODUCT_FLAG,
         MAT_STATUS,
         STOVE_NO,
         FLAG_STOVE_NO,
         JUDGE_STOVE_NO,
         CAST_NO,
         CCMID,
         MATERIAL_NO,
         MATERIAL_NAME,
         GRADECODE,
         GRADENAME,
         STD_CODE,
         STD_NAME,
         DIMATER,
         HEIGHT,
         ACT_LEN,
         FIX_NUM,
         FIX_LEN,
         ACT_COUNT,
         ACT_WEIGHT,
         ACT_THEORY_WEIGHT,
         PONDER_NO,
         PONDER_GROSS_WT,
         PLINE_CODE,
         PLINE_NAME,
         PRO_ORDER_NO,
         ORDER_NO,
         ORDER_SEQ,
         ORDER_SEQ_NO,
         ORD_PK,
         ORD_LN_PK,
         ORD_LN_DLY_PK,
         BELONG_CODE,
         BELONG_NAME,
         BAR_CODE,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         LOC_NO,
         DEPARTMENT_CODE,
         DEPARTMENT_DESC,
         MANAGEMENT_NO,
         MANAGEMENT_NAME,
         /* TAR_STORAGE_NO,
         TAR_LOCATION_NO,
         TAR_LARY_NO,
         TAR_LOC_NO,
         TAR_DEPARTMENT_CODE,
         TAR_DEPARTMENT_DESC,
         TAR_MANAGEMENT_NO,
         TAR_MANAGEMENT_NAME,*/
         --TAR_REC_FLAG,
         
         RPO_TIME,
         PRO_BC,
         PRO_BZ,
         BAL_YEAR_MONTH,
         
         OUTSTOCK_TIME,
         
         STORAGE_ATTR,
         STORAGE_ATTR_NAME,
         STORAGE_TYPE_NO,
         STORAGE_TYPE_NAME,
         --HAND_FLAG,
         --VALIDFLAG,
         MEMO,
         CREATE_NAME,
         CREATE_TIME,
         UPDATE_NAME,
         UPDATE_TIME,
         /*DELETE_NAME,
         DELETE_TIME,*/
         GROUD_NO,
         /* SEND_NUM,
         RECEIV_NO,
         RECEIV_NM,*/
         --M_BILL_NO,
         PRINT_STOVE_NO,
         PRO_PLAN_ID_ZG,
         GX_PLAN_NO_ZG,
         MAT_GOWHERE_CODE,
         MAT_GOWHERE_NAME,
         SUPPLY_UNIT_CODE,
         SUPPLY_UNIT,
         LOT_NO,
         SOURE_CODE,
         SOURE_NAME,
         IS_DEALER,
         BACK_FLAG)
      VALUES
        (V_OUTSTOCK_DOC_CQ || LPAD(V_ICOUNT, 4, 0),
         V_OUTSTOCK_PLAN_NO,
         V_OUTSTOCK_DOC_CQ,
         '800809',
         '产权出库',
         /* MYROW.ICCAR_NO,
         MYROW.VEHICLE_NO,*/
         MYROW.MAT_NO,
         MYROW.PRODUCT_FLAG,
         MYROW.MAT_STATUS,
         MYROW.STOVE_NO,
         MYROW.FLAG_STOVE_NO,
         MYROW.JUDGE_STOVE_NO,
         MYROW.CAST_NO,
         MYROW.CCMID,
         MYROW.MATERIAL_NO,
         MYROW.MATERIAL_NAME,
         MYROW.GRADECODE,
         MYROW.GRADENAME,
         MYROW.STD_CODE,
         MYROW.STD_NAME,
         MYROW.DIMATER,
         MYROW.HEIGHT,
         MYROW.ACT_LEN,
         MYROW.FIX_NUM,
         MYROW.FIX_LEN,
         MYROW.ACT_COUNT,
         MYROW.ACT_WEIGHT,
         MYROW.ACT_THEORY_WEIGHT,
         MYROW.PONDER_NO,
         MYROW.PONDER_GROSS_WT,
         MYROW.PLINE_CODE,
         MYROW.PLINE_NAME,
         MYROW.PRO_ORDER_NO,
         MYROW.ORDER_NO,
         MYROW.ORDER_SEQ,
         MYROW.ORDER_SEQ_NO,
         MYROW.ORD_PK,
         MYROW.ORD_LN_PK,
         MYROW.ORD_LN_DLY_PK,
         MYROW.BELONG_CODE,
         MYROW.BELONG_NAME,
         MYROW.BAR_CODE,
         MYROW.STORAGE_NO,
         MYROW.LOCATION_NO,
         MYROW.LARY_NO,
         MYROW.LOC_NO,
         MYROW.DEPARTMENT_CODE,
         MYROW.DEPARTMENT_DESC,
         MYROW.MANAGEMENT_NO,
         MYROW.MANAGEMENT_NAME,
         /* MYROW.TAR_STORAGE_NO,
         MYROW.TAR_LOCATION_NO,
         MYROW.TAR_LARY_NO,
         MYROW.TAR_LOC_NO,
         MYROW.TAR_DEPARTMENT_CODE,
         MYROW.TAR_DEPARTMENT_DESC,
         MYROW.TAR_MANAGEMENT_NO,
         MYROW.TAR_MANAGEMENT_NAME,*/
         --MYROW.TAR_REC_FLAG,
         
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         MYROW.PRO_BC,
         MYROW.PRO_BZ,
         V_BATHYEAR,
         --2022年换炼钢炉号规则，部分数据处理
         --CASE WHEN SUBSTR(MYROW.JUDGE_STOVE_NO, 2, 1) = '2' AND
         --MYROW.SUPPLY_UNIT_CODE = '120501' AND
         --TO_CHAR(SYSDATE, 'YYYY') = '2021' THEN '202201' ELSE V_BATHYEAR END,
         
         V_OUTSTOCK_TIME,
         
         MYROW.STORAGE_ATTR,
         MYROW.STORAGE_ATTR_NAME,
         MYROW.STORAGE_TYPE_NO,
         MYROW.STORAGE_TYPE_NAME,
         
         MYROW.MEMO,
         V_CREATE_NAME,
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         V_CREATE_NAME,
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         
         MYROW.GROUD_NO,
         /*MYROW.SEND_NUM,
         MYROW.RECEIV_NO,
         MYROW.RECEIV_NM,*/
         --MYROW.M_BILL_NO,
         MYROW.PRINT_STOVE_NO,
         V_PRO_PLAN_ID,
         V_GX_PLAN_NO,
         V_PLINE_CODE,
         V_PLINE_NAME,
         MYROW.SUPPLY_UNIT_CODE,
         MYROW.SUPPLY_UNIT,
         V_ZY_BATCH_ID,
         MYROW.SOURE_CODE,
         MYROW.SOURE_NAME,
         MYROW.IS_DEALER,
         MYROW.BACK_FLAG);
    END IF;
  
    --复制数据到历史表
    insert into MAT_GP_M_HISTORY
      select * from MAT_GP_M t where t.mat_no = MYROW.MAT_NO;
  
    --删除物料主表记录
    DELETE FROM MAT_GP_M T WHERE T.MAT_NO = MYROW.MAT_NO;
  
    --删除位置表记录
    DELETE FROM YDM_GP_BUTTRESS T2 WHERE T2.MAT_NO = MYROW.MAT_NO;
  
    --切损去向是回库的，插入材料表、位置表、入库表数据
    IF V_CUT_TARGET = '回库' THEN
      --生成材料号
      SELECT V_JUDGE_STOVE_NO ||
             LPAD(NVL(MAX(SUBSTR(T2.MAT_NO, LENGTH(T2.MAT_NO) - 2)), 0) + 1,
                  3,
                  0) MAT_NO
        INTO V_MAT_NO
        FROM (SELECT MAX(SUBSTR(T.MAT_NO, LENGTH(T.MAT_NO) - 2)) MAT_NO
                FROM MAT_GP_M T
               WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
              UNION ALL
              SELECT MAX(SUBSTR(T1.MAT_NO, LENGTH(T1.MAT_NO) - 2)) MAT_NO
                FROM YDM_GP_OUTLIST T1
               WHERE T1.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
              UNION ALL
              SELECT MAX(SUBSTR(T3.MAT_NO, LENGTH(T3.MAT_NO) - 2)) MAT_NO
                FROM MAT_GP_M_HISTORY T3
               WHERE T3.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO) T2;
    
      --复制数据到物料主表
      insert into MAT_GP_M
        select * from MAT_GP_M_HISTORY t where t.mat_no = MYROW.MAT_NO;
    
      update MAT_GP_M t
         set t.mat_no            = V_MAT_NO,
             T.MAT_STATUS = CASE
                              WHEN MYROW.INSTANCY_FLAG = '1' AND
                                   MYROW.JUDGE_RESULT_CODE IS NULL THEN
                               '80150101'
                              ELSE
                               '80150102'
                            END,
             T.HANGING_FLAG      = '0',
             T.HEAT_PLAN_NO_NEXT = '',
             T.PRO_PLAN_ID_ZG    = '',
             T.GX_PLAN_NO_ZG     = '',
             T.FIX_NUM           = 1,
             T.FIX_LEN           = V_CUT_LENGTH,
             T.ACT_LEN           = V_CUT_LENGTH,
             T.ACT_WEIGHT        = V_CUT_WEIGHT,
             T.ACT_THEORY_WEIGHT = V_CUT_WEIGHT,
             T.CREATE_NAME       = V_CREATE_NAME,
             T.CREATE_TIME       = TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'),
             T.INSTOCK_TIME      = TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'),
             T.LK_FLAG           = '0',
             --T.INSTANCY_FLAG     = '0',
             T.CUT_YU_LONG   = 0,
             T.BACK_FLAG     = DECODE(MYROW.BACK_FLAG,
                                      '1',
                                      '1',
                                      '3',
                                      '3',
                                      '2'),
             T.ORDER_NO      = '',
             T.ORDER_SEQ     = '',
             T.ORDER_SEQ_NO  = '',
             T.ORD_PK        = '',
             T.ORD_LN_PK     = '',
             T.ORD_LN_DLY_PK = ''
       WHERE T.MAT_NO = MYROW.MAT_NO;
    
      --插入位置表
      INSERT INTO YDM_GP_BUTTRESS
        (MAT_NO,
         JUDGE_STOVE_NO,
         STOVE_NO,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         STORAGE_ATTR,
         STORAGE_ATTR_NAME,
         STORAGE_TYPE_NO,
         STORAGE_TYPE_NAME,
         /*DEPARTMENT_CODE,
         DEPARTMENT_DESC,
         MANAGEMENT_NO,
         MANAGEMENT_NAME,*/
         CREATE_NAME,
         CREATE_TIME,
         LOCATION_NAME)
      VALUES
        (V_MAT_NO,
         MYROW.JUDGE_STOVE_NO,
         MYROW.STOVE_NO,
         V_STORAGE_NO,
         V_LOCATION_NO,
         1,
         '800302',
         '投料库',
         '800201',
         '管坯',
         /*V_DEPARTMENT_CODE,
         V_DEPARTMENT_DESC,
         V_DEPARTMENT_CODE,
         V_DEPARTMENT_DESC,*/
         V_CREATE_NAME,
         TO_DATE(V_TIME, 'YYYY-MM-DD hh24:mi:ss'),
         V_LOCATION_NAME);
    
      --插入红冲出库记录
      INSERT INTO YDM_GP_OUTLIST
        (OUTSTOCK_SQE,
         OUTSTOCK_PLAN_NO,
         OUTSTOCK_DOC,
         OUTSTOCK_TYPE_CODE,
         OUTSTOCK_TYPE_NAME,
         /*ICCAR_NO,
         VEHICLE_NO,*/
         MAT_NO,
         PRODUCT_FLAG,
         MAT_STATUS,
         STOVE_NO,
         FLAG_STOVE_NO,
         JUDGE_STOVE_NO,
         CAST_NO,
         CCMID,
         MATERIAL_NO,
         MATERIAL_NAME,
         GRADECODE,
         GRADENAME,
         STD_CODE,
         STD_NAME,
         DIMATER,
         HEIGHT,
         ACT_LEN,
         FIX_NUM,
         FIX_LEN,
         ACT_COUNT,
         ACT_WEIGHT,
         ACT_THEORY_WEIGHT,
         PONDER_NO,
         PONDER_GROSS_WT,
         PLINE_CODE,
         PLINE_NAME,
         PRO_ORDER_NO,
         ORDER_NO,
         ORDER_SEQ,
         ORDER_SEQ_NO,
         ORD_PK,
         ORD_LN_PK,
         ORD_LN_DLY_PK,
         BELONG_CODE,
         BELONG_NAME,
         BAR_CODE,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         LOC_NO,
         DEPARTMENT_CODE,
         DEPARTMENT_DESC,
         MANAGEMENT_NO,
         MANAGEMENT_NAME,
         
         RPO_TIME,
         PRO_BC,
         PRO_BZ,
         BAL_YEAR_MONTH,
         
         OUTSTOCK_TIME,
         
         STORAGE_ATTR,
         STORAGE_ATTR_NAME,
         STORAGE_TYPE_NO,
         STORAGE_TYPE_NAME,
         
         MEMO,
         CREATE_NAME,
         CREATE_TIME,
         UPDATE_NAME,
         UPDATE_TIME,
         
         GROUD_NO,
         PRINT_STOVE_NO,
         PRO_PLAN_ID_ZG,
         GX_PLAN_NO_ZG,
         MAT_GOWHERE_CODE,
         MAT_GOWHERE_NAME,
         SUPPLY_UNIT_CODE,
         SUPPLY_UNIT,
         SOURE_CODE,
         SOURE_NAME,
         LOT_NO,
         IS_DEALER,
         BACK_FLAG)
      VALUES
        (V_OUTSTOCK_DOC_HO || LPAD(V_ICOUNT, 4, 0),
         V_OUTSTOCK_PLAN_NO,
         V_OUTSTOCK_DOC_HO,
         '800806',
         '出库红冲',
         
         V_MAT_NO,
         MYROW.PRODUCT_FLAG,
         MYROW.MAT_STATUS,
         MYROW.STOVE_NO,
         MYROW.FLAG_STOVE_NO,
         MYROW.JUDGE_STOVE_NO,
         MYROW.CAST_NO,
         MYROW.CCMID,
         MYROW.MATERIAL_NO,
         MYROW.MATERIAL_NAME,
         MYROW.GRADECODE,
         MYROW.GRADENAME,
         MYROW.STD_CODE,
         MYROW.STD_NAME,
         MYROW.DIMATER,
         MYROW.HEIGHT,
         V_CUT_LENGTH,
         1,
         V_CUT_LENGTH,
         -1,
         --ROUND(-V_CUT_WEIGHT / V_PLAN_INDOUBLE_NUM, 3),
         --ROUND(-V_CUT_WEIGHT / V_PLAN_INDOUBLE_NUM, 3),
         -V_CUT_WEIGHT,
         -V_CUT_WEIGHT,
         MYROW.PONDER_NO,
         MYROW.PONDER_GROSS_WT,
         MYROW.PLINE_CODE,
         MYROW.PLINE_NAME,
         MYROW.PRO_ORDER_NO,
         MYROW.ORDER_NO,
         MYROW.ORDER_SEQ,
         MYROW.ORDER_SEQ_NO,
         MYROW.ORD_PK,
         MYROW.ORD_LN_PK,
         MYROW.ORD_LN_DLY_PK,
         MYROW.BELONG_CODE,
         MYROW.BELONG_NAME,
         MYROW.BAR_CODE,
         MYROW.STORAGE_NO,
         MYROW.LOCATION_NO,
         MYROW.LARY_NO,
         MYROW.LOC_NO,
         MYROW.DEPARTMENT_CODE,
         MYROW.DEPARTMENT_DESC,
         MYROW.MANAGEMENT_NO,
         MYROW.MANAGEMENT_NAME,
         
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         MYROW.PRO_BC,
         MYROW.PRO_BZ,
         V_BATHYEAR,
         
         V_OUTSTOCK_TIME,
         
         MYROW.STORAGE_ATTR,
         MYROW.STORAGE_ATTR_NAME,
         MYROW.STORAGE_TYPE_NO,
         MYROW.STORAGE_TYPE_NAME,
         
         MYROW.MEMO,
         V_CREATE_NAME,
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         V_CREATE_NAME,
         TO_DATE(V_TIME, 'yyyy-MM-dd HH24:mi:ss'),
         
         MYROW.GROUD_NO,
         /*MYROW.SEND_NUM,
         MYROW.RECEIV_NO,
         MYROW.RECEIV_NM,*/
         --MYROW.M_BILL_NO,
         MYROW.PRINT_STOVE_NO,
         '',
         '',
         V_PLINE_CODE,
         V_PLINE_NAME,
         MYROW.SUPPLY_UNIT_CODE,
         MYROW.SUPPLY_UNIT,
         MYROW.SOURE_CODE,
         MYROW.SOURE_NAME,
         V_ZY_BATCH_ID,
         MYROW.IS_DEALER,
         '2');
    
    END IF;
  
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;

]]>
</query>


<query id = "FrmFeedLoad.nodeBack" desc = "上料回退">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO   MAT_GP_M.JUDGE_STOVE_NO%TYPE := ?;
  V_JUGDE_APPLY_CODE MAT_GP_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_ACT_COUNT        PLN_ZY_ZG_C.REAL_INDOUBLE_NUM%TYPE := ?;
  V_FIX_NUM          MAT_GP_M.FIX_NUM%TYPE := ?;
  V_PLINE_CODE       MAT_GP_M.PLINE_CODE%TYPE := ?;
  V_PRO_PLAN_ID      MIL_PLAN.PRO_PLAN_ID%TYPE := ?;
  V_GX_PLAN_NO       MIL_PLAN.GX_PLAN_NO%TYPE := ?;
  V_FEED_LENGTH      MIL_FEED_PLAN.FEED_LENGTH%TYPE := ?;

  V_CUT_TARGET PLN_ZY_ZG_C.CUT_TARGET%TYPE := ?; --切损去向
  V_CUT_LENGTH PLN_ZY_ZG_C.CUT_LENGTH%TYPE := ?; --切损长度
  V_CUT_WEIGHT PLN_ZY_ZG_C.CUT_WEIGHT%TYPE := ?; --切损重量

  V_LOCATION_NO   YDM_GP_BUTTRESS.LOCATION_NO%TYPE := NULL;
  V_LOCATION_NAME YDM_GP_BUTTRESS.LOCATION_NAME%TYPE := NULL;

BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM YDM_GP_OUTLIST T
                 WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                      --AND T.PLINE_CODE = V_PLINE_CODE
                   AND T.OUTSTOCK_TYPE_NAME = '投料出库'
                   AND T.PRO_PLAN_ID_ZG = V_PRO_PLAN_ID
                   AND T.GX_PLAN_NO_ZG = V_GX_PLAN_NO) LOOP
  
    --恢复位置表记录
    INSERT INTO YDM_GP_BUTTRESS
      (MAT_NO,
       --LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       LOC_NO,
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       GROUD_NO,
       LOCATION_NAME)
    VALUES
      (MYROW.MAT_NO,
       --MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.STORAGE_NO,
       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.DEPARTMENT_CODE,
       MYROW.DEPARTMENT_DESC,
       MYROW.MANAGEMENT_NO,
       MYROW.MANAGEMENT_NAME,
       MYROW.FIX_NUM,
       (SELECT L.LOCATION_NAME
          FROM YDM_BS_LOCATION L
         WHERE L.LOCATION_NO = MYROW.LOCATION_NO));
  
    DELETE FROM YDM_GP_OUTLIST T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.OUTSTOCK_TYPE_CODE IN ('800801', '800809');
  
  END LOOP;

  FOR MYROW2 IN (SELECT *
                   FROM MAT_GP_M_HISTORY T
                  WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                    AND NVL(T.JUGDE_APPLY_CODE, '/') =
                        NVL(V_JUGDE_APPLY_CODE, '/')
                    AND T.ACT_LEN = V_FEED_LENGTH
                    AND T.PRO_PLAN_ID_ZG = V_PRO_PLAN_ID
                    AND T.GX_PLAN_NO_ZG = V_GX_PLAN_NO
                    AND ROWNUM <= V_ACT_COUNT
                  ORDER BY T.MAT_NO) LOOP
    --套尺
    IF MYROW2.IS_SETFOOT = '1' THEN
      select L.LOCATION_NO, L.LOCATION_NAME
        INTO V_LOCATION_NO, V_LOCATION_NAME
        from YDM_BS_LOCATION L
       WHERE L.STORAGE_NO = 'TTH1'
         AND L.LOCATION_NAME = 'ST' || MYROW2.DIMATER || 'A';
      INSERT INTO YDM_GP_BUTTRESS
        (MAT_NO,
         --LOT_NO,
         STOVE_NO,
         JUDGE_STOVE_NO,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         LOC_NO,
         
         MANAGEMENT_NO,
         MANAGEMENT_NAME,
         GROUD_NO,
         LOCATION_NAME)
      VALUES
        (MYROW2.MAT_NO,
         --MYROW.LOT_NO,
         MYROW2.STOVE_NO,
         MYROW2.JUDGE_STOVE_NO,
         'TTH1',
         V_LOCATION_NO,
         '',
         '',
         MYROW2.MATERIAL_NO,
         MYROW2.MATERIAL_NAME,
         MYROW2.FIX_NUM,
         V_LOCATION_NAME);
    END IF;
    --复制数据到物料主表
    insert into MAT_GP_M
      select * from MAT_GP_M_HISTORY t where t.mat_no = MYROW2.MAT_NO;
  
    --删除历史表记录
    DELETE FROM MAT_GP_M_HISTORY T WHERE T.MAT_NO = MYROW2.MAT_NO;
  
  END LOOP;

  --改材料表挂料状态
  UPDATE MAT_GP_M T
     SET T.HANGING_FLAG = '1'
   where T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND NVL(T.JUGDE_APPLY_CODE, '/') = NVL(V_JUGDE_APPLY_CODE, '/')
     AND T.ACT_LEN = V_FEED_LENGTH
     AND T.PRO_PLAN_ID_ZG = V_PRO_PLAN_ID
     AND T.GX_PLAN_NO_ZG = V_GX_PLAN_NO;

  --删除自动返库的数据
  IF V_CUT_TARGET = '回库' THEN
    FOR MYROW3 IN (SELECT *
                     FROM YDM_GP_OUTLIST T
                    WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                      AND T.MAT_GOWHERE_CODE = V_PLINE_CODE
                      AND T.ACT_LEN = V_CUT_LENGTH
                      AND T.OUTSTOCK_TYPE_CODE = '800806'
                    ORDER BY T.MAT_NO) LOOP
    
      DELETE FROM MAT_GP_M T WHERE T.MAT_NO = MYROW3.MAT_NO;
      DELETE FROM YDM_GP_BUTTRESS T WHERE T.MAT_NO = MYROW3.MAT_NO;
      DELETE FROM YDM_GP_OUTLIST T
       WHERE T.OUTSTOCK_TYPE_CODE = '800806'
         AND T.MAT_NO = MYROW3.MAT_NO;
    END LOOP;
  END IF;
END;

]]>
</query>

<query id = "FrmFeedLoad.deletePortMil" desc = "上料回退:删除进程表管号队列">
<![CDATA[
DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.PLAN_ID = ?
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(GX_PLAN_NO, '/') = NVL(?, '/')
]]>
</query>

<query id = "FrmFeedLoad.SelectBalYearMonth" desc = "上料回退:判断是否已结转">
<![CDATA[
SELECT T.BAL_YEAR_MONTH,
       (select MAX(T.BAL_YEAR_MONTH) from YDM_GP_INITIAL t) BAL_YEAR_MONTH2
  FROM MIL_PLAN T
 WHERE T.ID = ?
]]>
</query>

<query id = "FrmFeedLoad.updateBatchNo" desc = "C的把性能批号默认： 检验委托号 +999">
<![CDATA[
declare
  V_Plan_Id        port_mil_batch_sample_result.Plan_Id%type := ?;
  V_Judge_Stove_No port_mil_batch_sample_result.Judge_Stove_No%type := ?;
  V_Pline_Code     port_mil_batch_sample_result.Pline_Code%type := ?;
  V_Pro_Plan_Id    port_mil_batch_sample_result.Pro_Plan_Id%type := ?;
  V_Gx_Plan_No     port_mil_batch_sample_result.Gx_Plan_No%type := ?;

  V_Check_No_Short com_base_pline.Check_No_Short%type := null;
begin

  SELECT C.CHECK_NO_SHORT
    INTO V_Check_No_Short
    FROM COM_BASE_PLINE C
   WHERE C.PLINE_CODE = V_Pline_Code;

  UPDATE port_mil_batch_sample_result T
     SET T.BATCH_NO = V_Check_No_Short || '999'
   WHERE T.PLAN_ID = V_Plan_Id
     AND T.JUDGE_STOVE_NO = V_Judge_Stove_No
     AND T.PLINE_CODE = V_Pline_Code
     AND T.PRO_PLAN_ID = V_Pro_Plan_Id
     AND T.GX_PLAN_NO = V_Gx_Plan_No;

  UPDATE MIL_PLAN T
     SET T.IS_BATCH = '1'
   WHERE T.ID = V_Plan_Id
     AND T.JUDGE_STOVE_NO = V_Judge_Stove_No
     AND T.PLINE_CODE = V_Pline_Code
     AND T.PRO_PLAN_ID = V_Pro_Plan_Id
     AND T.GX_PLAN_NO = V_Gx_Plan_No;
end;
]]>
</query>

<query id = "FeedResult.selectLoadTime" desc= "查询上料时间">
	<![CDATA[
	SELECT TO_CHAR(MIN(T.COL_TIME), 'YYYY-MM-DD HH24:MI:SS') loadTime,
       SUM(B.FEED_NUM_PLAN * B.DB_NUM) * MAX(T.SAW_NUM) YJZ,
       TO_CHAR(0.98 * (SUM(B.MAT_TOTAL_HEIGHT) - SUM(NVL(B.CUT_WEIGHT, 0))),
               'FM99990.000') YJD
  FROM MIL_PLAN T, MIL_FEED_PLAN B
 WHERE REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = REGEXP_REPLACE(?, '-.*', '')
   AND T.ID = ?
   AND T.PRO_PLAN_ID = B.PRO_PLAN_ID
   AND T.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO
   ]]>
	</query>
	
	<query id = "FeedResult.UpdateTmsDemandMLoadTime" desc = "更新运输需求上料时间">
<![CDATA[
DECLARE
  V_JUDGE_STOVE_NO TMS_DEMAND_M.HEAT_NO%type := REGEXP_REPLACE(?, '-.*', '');
  V_CURRENT_JOB_NO TMS_DEMAND_M.CURRENT_JOB_NO%type := ?;
  V_LOAD_TIME      TMS_DEMAND_M.CREATE_NAME%type := ?;
  V_DEMAND_QTY_VAL TMS_DEMAND_M.DEMAND_QTY_VAL%type := ?;
  V_DEMAND_WT_VAL  TMS_DEMAND_M.DEMAND_WT_VAL%type := ?;
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM TMS_DEMAND_M T
                 WHERE T.HEAT_NO = V_JUDGE_STOVE_NO
                   AND T.CURRENT_JOB_NO = V_CURRENT_JOB_NO
                   AND T.TRAN_CLASS_CODE = 'XX'
                 ORDER BY T.CREATE_TIME DESC) LOOP
    UPDATE TMS_DEMAND_M T
       SET T.LOAD_TIME      = TO_DATE(V_LOAD_TIME, 'YYYY-MM-DD HH24:MI:SS'),
           T.DEMAND_QTY_VAL = V_DEMAND_QTY_VAL,
           T.DEMAND_WT_VAL  = V_DEMAND_WT_VAL
     WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
  END LOOP;
END;
       ]]>
</query>

<query id = "FrmFeedLoad.deleteProcess" desc= "进程表多余数据清理">
	<![CDATA[
	DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.PLAN_ID = ?
   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') =
       REGEXP_REPLACE(?, '-.*', '')
   ]]>
	</query>

</queryMap>