<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "镦拔扩交库管理">
<query id = "FrmVrpInStore.querySinglePlan" desc = "查询镦拔扩炉计划">
 SELECT 
       T.HEAT_PLAN_NO,
       T.GX_PRO_SEQ,
       T.ZY_BATCH_ID,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.PLANSTATUS,
       DECODE(T.PER_STATUS,'00','上料开始','10','旋扩开始','20','均整开始','30','定径开始','40','表检开始','50','测量开始','60','交库开始') PER_STATUS,
       DECODE(T.BESIDE_STATUS,'00','上料结炉','10','旋扩结炉','20','均整结炉','30','定径结炉','40','表检结炉','50','测量结炉','60','交库结炉')BESIDE_STATUS,
       T.UPPER_HEATPLAN_ID,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PROCESS_CODE_C,
       T.PROCESS_DESC_C,
       T.UPPER_PROCESS_CODE,
       T.NEXT_PROCESS_CODE,
       T.GOWHERE_CODE,
       T.GOWHERE_NAME,
       T.PROD_STANDARD,
       T.OUTPUT_STANDARD,
       T.ISENDGX,
       T.IF_MATCH_ODD,
       T.IF_DO_HEAT_PLAN,
       T.ORDER_SOURCE,
       T.ORD_LN_DLY_PK,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.REQ_BL_ID,
       T.IF_EXPORT,
       T.PRIORITY,
       T.PRIORITY_MEMO,
       T.PRO_MONTH,
       T.PRO_DAY,
       T.BAL_YEAR_MONTH,
       T.IF_MONITOR,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.BOM,
       T.WHOLE_BACKLOG,
       T.WHOLE_BACKLOG_DESC,
       T.STATION_ROAD,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.CRAFT_FILE_NO,
       T.CRAFT_FILE_MAN,
       T.CRAFT_SEQ,
       T.SEC_CRAFT_FILE_NO,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.OUTDIAMETER_IN,
       T.WALLTHICK_IN,
       T.LENGTH_IN,
       T.LENGTHMAX_IN,
       T.LENGTHMIN_IN,
       T.OUTNUM_CUT,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.AIMLENGTH,
       T.AIMLENGTH_MAX,
       T.AIMLENGTH_MIN,
       T.LEN_CUTHEAD,
       T.LEN_CUTEND,
       T.PLN_INSINGLE_NUM,
       T.PLN_INSINGLE_WT,
       T.PLN_INDOUBLE_NUM,
       T.PLN_INDOUBLE_WT,
       T.PLN_OUTSINGLE_NUM,
       T.PLN_OUTSINGLE_W,
       T.PLN_OUTDOUBLE_NUM,
       T.PLN_OUTDOUBLE_W,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T.DOWNMAN,
       TO_CHAR(T.DOWNTIME, 'YYYY-MM-DD HH24:MI:SS') DOWNTIME,
       T.INDEX_SEQ,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.DECISION,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.IF_PRODUCT,
       T.FEED_HEAT_NO,
       T.ACT_LEN_CUTHEAD,
       T.ACT_LEN_CUTEND,
       T.FLAG_STOVE_NO
 FROM PLN_ZY_DBK_M T
 WHERE 1 =1 
</query>
<query id = "FrmVrpInStore.doQueryInList" desc = "查询入库实绩">
SELECT T.INSTOCK_DOC,
       T.LOT_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       TO_CHAR(T.ACT_LEN_MIN, 'FM999990.00') AS ACT_LEN_MIN,
       TO_CHAR(T.ACT_LEN_MAX, 'FM999990.00') AS ACT_LEN_MAX,
       SUM(T.ACT_COUNT) AS ACT_COUNT,
       TO_CHAR(SUM(T.ACT_WEIGHT), 'FM999999990.000') AS ACT_WEIGHT,
       T.ACT_LEN,
       T.BELONG_CODE,
       T.BELONG_NAME,
       T.STORAGE_NO,
       T.MEMO,
       T.CREATE_NAME,
       MAX(TO_CHAR(T.INSTOCK_TIME, 'YYYY-MM-DD HH24:MI:SS')) AS INSTOCK_TIME,
       MAX(TO_CHAR(T.IN_TIME_F, 'YYYY-MM-DD')) AS IN_TIME_F,
       TO_CHAR(TO_DATE(T.BAL_YEAR_MONTH, 'YYYY-MM'), 'YYYY-MM') AS BAL_YEAR_MONTH,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.JUDGE_STD_CODE,
       T.JUDGE_STD_NAME,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       DECODE(T.PRODUCT_FLAG,
              '801401',
              '在制品',
              '801402',
              '成品',
              '801403',
              '商品') PRODUCT_FLAG,
       T.MAT_STATUS,
       T.PIPMEMO,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       DECODE(B.STORAGE_NO,NULL,'已倒运','未倒运') STATUS
  FROM YDM_BC_INLIST T  LEFT JOIN ( SELECT M.MAT_NO,B.STORAGE_NO,M.PLINE_CODE
    FROM MAT_BC_M M, YDM_BC_BUTTRESS B, COM_BASE_PLINE C
    WHERE M.MAT_NO = B.MAT_NO
    AND B.STORAGE_NO = C.OUT_REPOSITORY
    AND M.PLINE_CODE = C.PLINE_CODE) B ON T.MAT_NO = B.MAT_NO AND T.PLINE_CODE = B.PLINE_CODE
 WHERE T.INSTOCK_TYPE_CODE = '800701'
   AND T.HAND_FLAG = '0'
   AND T.QCM_STAUS = '00'
   AND T.SUBCONTRACT_NO IS NULL
</query>
<query id = "FrmVrpInStore.doQueryVrpRack" desc = "查询管号队列信息">
SELECT T.HEAT_PLAN_NO,
       T.JUDGE_STOVE_NO,
       T.FLAG_STOVE_NO,
       T.BATCH_NO,
       T.GROUP_NO,
       SUM(T.ACT_COUNT) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT,
       DECODE(T.IS_SAMPLE_PIPE,'0','非样管','1','样管')IS_SAMPLE_PIPE,
       T.PHY_BATCH_NO,
       T.PHY_BATCH_NO NEW_PHY_BATCH_NO,
       T.ACT_LEN
  FROM PORT_VRP_BATCH_SAMPLE_RESULT T
 WHERE T.HEAT_PLAN_NO = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.MAT_STATUS = '00'
   AND T.INSTORE_FLAG = '0'
 GROUP BY T.HEAT_PLAN_NO,
          T.JUDGE_STOVE_NO,
          T.FLAG_STOVE_NO,
          T.BATCH_NO,
       	  T.GROUP_NO,
          T.IS_SAMPLE_PIPE,
          T.PHY_BATCH_NO,
          T.ACT_LEN
</query>
<query id = "FrmVrpInStore.doQueryStausRack" desc = "查询指定炉批支数">
SELECT NVL(SUM(S.ACT_COUNT),'0')ACOUNT
  FROM PORT_VRP_BATCH_SAMPLE_RESULT S
 WHERE S.MAT_STATUS = '00'
   AND S.INSTORE_FLAG = '0'
   AND S.HEAT_PLAN_NO = ?
   AND S.JUDGE_STOVE_NO = ?
   AND NVL(S.PHY_BATCH_NO,'/') = NVL(?,'/')
   AND S.IS_SAMPLE_PIPE = ?
</query>
<query id = "FrmVrpInStore.SelectApplyNo" desc = "查询申请判定表数据">
SELECT COUNT(*) COUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.PROCESS_CODE = 'E'
</query>
<query id = "FrmVrpInStore.SelectApplyNoF" desc = "查询申请判定表数据">
SELECT COUNT(*) COUNT
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.PROCESS_CODE = 'F'
</query>

<query id = "FrmVrpInStore.selectOrdPk" desc = "查询ordPk">
SELECT T.ORD_PK,T.ORD_LN_PK FROM SLM_ORDER_LINE_DELIVERY T WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
</query>


<query id = "FrmVrpInStore.doQueryStausRackWgt" desc = "查询指定炉批下支数重量">
<![CDATA[
SELECT NVL(SUM(ACT_WEIGHT),'0') ACT_WEIGHT
  FROM (SELECT S.ACT_WEIGHT
          FROM PORT_VRP_BATCH_SAMPLE_RESULT S
         WHERE S.MAT_STATUS = '00'
           AND S.INSTORE_FLAG = '0'
           AND S.HEAT_PLAN_NO = ?
           AND S.JUDGE_STOVE_NO = ?
           AND NVL(S.PHY_BATCH_NO,'/') = NVL(?,'/')
           AND S.IS_SAMPLE_PIPE = ?
         ORDER BY S.MAT_NO ASC)
 WHERE ROWNUM <= ?
 ]]>
</query>
<query id = "FrmVrpInStore.getInListDoc" desc = "生成入库单号">
SELECT 'IA' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, 9)), 0) + 1, 5, 0) INSTOCK_DOC
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_TYPE_CODE = ?
     AND TRUNC(T.CREATE_TIME) =
         TRUNC(SYSDATE)
</query>

    <query id="FrmVrpInStore.getInListDoc1" desc="生成入库单号">
        <![CDATA[
		  SELECT 'IA' || TO_CHAR(SYSDATE, 'YYMMDD')  ||
         LPAD(NVL(MAX(TO_NUMBER(SUBSTR(INSTOCK_DOC, LENGTH(INSTOCK_DOC) - 4))),
                  0) + 1,
              5,
              '0') INSTOCK_DOC
    FROM  YDM_BC_INLIST
   WHERE INSTOCK_DOC LIKE 'IA' || TO_CHAR(SYSDATE, 'YYMMDD')  || '_____'
			]]>
    </query>

<query id = "creatGroup.selectMilInStore" desc = "查询是否已存在满足的组号">
	<![CDATA[
	SELECT T.BATCH_GROUD_NO
  FROM MIL_INSTORE T
 WHERE T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND ? >= T.ACT_LEN_MIN
   AND ? <= T.ACT_LEN_MAX
   AND T.PROCESS_CODE = ?
   ]]>
	</query>
	<query id = "FrmVrpInStore.queryGroupNo" desc = "查询同炉同批组号">
       SELECT LPAD(NVL(MAX(T.BATCH_GROUD_NO), 0)+1,3,0)BATCH_GROUD_NO FROM MAT_BC_M T WHERE T.JUDGE_STOVE_NO = ? AND T.BATCH_NO = ?
       </query>
       <query id = "creatGroup.InsertMilInStore" desc = "新增组号记录">
	 INSERT INTO MIL_INSTORE(
        INSTORE_ID,
        JUDGE_STOVE_NO,
        BATCH_NO,
        SAMPLE_FLAG,
        TEST_STAUS,
        SURFACE_STAUS,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        BATCH_GROUD_NO,
        PROCESS_CODE)
 VALUES( 
        ?,
        ?,
        ?,
        '',
        ?,
        ?,
        ?,
        ?,
        ?,
        ?)
	</query>
	<query id ="FrmVrpInStore.querySendSql" desc = "查询入库单号流水号">
SELECT ? ||
       LPAD(NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 3)), 0) + 1,
            4,
            0) INSTOCK_SQE
  FROM YDM_BC_INLIST T
 WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
   AND T.INSTOCK_DOC = ?
   </query>
   <query id = "FrmVrpInStore.insertMatBcM" desc = "交库">
   <![CDATA[
   DECLARE
  V_INSTOCK_SQE YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_ICOUNT      NUMBER := 1;
  V_ICOUNT1     NUMBER := 1;
BEGIN
  SELECT NVL(MAX(SUBSTR(T.INSTOCK_SQE, LENGTH(T.INSTOCK_SQE) - 3)), 0) + 1
    INTO V_ICOUNT
    FROM YDM_BC_INLIST T
   WHERE T.INSTOCK_DOC LIKE '#INSTOCK_DOC#' || '%';
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_VRP_BATCH_SAMPLE_RESULT T
                         WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
                           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.PHY_BATCH_NO = '#PHY_BATCH_NO#'
                           AND T.IS_SAMPLE_PIPE = '#IS_SAMPLE_PIPE#'
                           AND T.MAT_STATUS = '00'
                           AND T.INSTORE_FLAG = '0'
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
  
    SELECT COUNT(1)
      INTO V_ICOUNT1
      FROM YDM_BC_BUTTRESS_BACK
     WHERE MAT_NO = MYROW.MAT_NO
       AND PLINE_CODE = MYROW.PLINE_CODE;
  
    IF (V_ICOUNT1 = 0) THEN
      INSERT INTO YDM_BC_BUTTRESS
        (MAT_NO,
         JUDGE_STOVE_NO,
         BATCH_NO,
         BATCH_GROUD_NO,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         CREATE_NAME,
         CREATE_TIME,
         PLINE_CODE)
      VALUES
        (MYROW.MAT_NO,
         MYROW.JUDGE_STOVE_NO,
         MYROW.PHY_BATCH_NO,
         '#BATCH_GROUD_NO#',
         '#STORAGE_NO#',
         '#LOCATION_NO#',
         '#LARY_NO#',
         '#CREATE_NAME#',
         TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
         MYROW.PLINE_CODE);
    
    ELSE
      INSERT INTO YDM_BC_BUTTRESS
        (MAT_NO,
         JUDGE_STOVE_NO,
         BATCH_NO,
         BATCH_GROUD_NO,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         LOC_NO,
         STORAGE_ATTR,
         STORAGE_ATTR_NAME,
         STORAGE_TYPE_NO,
         STORAGE_TYPE_NAME,
         MANAGEMENT_NO,
         MANAGEMENT_NAME,
         MEMO,
         CREATE_NAME,
         CREATE_TIME,
         UPDATE_NAME,
         UPDATE_TIME,
         DELETE_NAME,
         DELETE_TIME,
         DEPARTMENT_CODE,
         DEPARTMENT_DESC,
         PLINE_CODE)
        SELECT MYROW.MAT_NO,
               MYROW.JUDGE_STOVE_NO,
               MYROW.PHY_BATCH_NO,
               '#BATCH_GROUD_NO#',
               STORAGE_NO,
               LOCATION_NO,
               LARY_NO,
               LOC_NO,
               STORAGE_ATTR,
               STORAGE_ATTR_NAME,
               STORAGE_TYPE_NO,
               STORAGE_TYPE_NAME,
               MANAGEMENT_NO,
               MANAGEMENT_NAME,
               MEMO,
               CREATE_NAME,
               CREATE_TIME,
               UPDATE_NAME,
               UPDATE_TIME,
               DELETE_NAME,
               DELETE_TIME,
               DEPARTMENT_CODE,
               DEPARTMENT_DESC,
               PLINE_CODE
          FROM YDM_BC_BUTTRESS_BACK
         WHERE MAT_NO = MYROW.MAT_NO
           AND PLINE_CODE = MYROW.PLINE_CODE;
    END IF;
  
    INSERT INTO MAT_BC_M
      (MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       SAMPLE_FLAG,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STEELCODE,
       STEELNAME,
       GRADECODE,
       GRADENAME,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       STD_CODE,
       STD_NAME,
       STD_STYLE,
       STD_STYLE_DESC,
       PRO_ORDER_NO,
       PRO_ORDER_ID,
       PROCESS_CDOE,
       PROCESS_DESC,
       NEXT_PROCESS_CDOE,
       NEXT_PROCESS_DESC,
       PLINE_CODE,
       PLINE_NAME,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       MAT_GOWHERE_CODE,
       MAT_GOWHERE_NAME,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       BAL_YEAR_MONTH,
       JUDGE_STD_DES,
       QCM_STAUS,
       HEAT_PLAN_NO,
       GX_PLAN_NO,
       CRAF_NO,
       CRAFT_SEQ,
       ORD_LN_DLY_PK,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       TARGET,
       FLAG_STOVE_NO_ZG,
       CIC,
       HEAT_PLAN_NO_OLD,
       ORD_PK,
       ORD_LN_PK,
       IS_DEALER)
    VALUES
      (MYROW.MAT_NO,
       '#PRODUCT_FLAG#',
       '#MAT_STATUS#',
       MYROW.LOT_NO,
       MYROW.STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.PHY_BATCH_NO,
       '#BATCH_GROUD_NO#',
       MYROW.IS_SAMPLE_PIPE,
       '#MATERIAL_NO#',
       '#MATERIAL_NAME#',
       '#PRODUCCODE#',
       '#PRODUCNAME#',
       '#STEELCODE#',
       '#STEELNAME#',
       '#GRADECODE#',
       '#GRADENAME#',
       '#SPEC_CODE#',
       '#SPEC_NAME#',
       '#MODEL_CODE#',
       '#MODEL_DESC#',
       '#STD_CODE#',
       '#STD_NAME#',
       '#STD_STYLE#',
       '#STD_STYLE_DESC#',
       '#PRO_ORDER_NO#',
       '#PRO_ORDER_ID#',
       '#PROCESS_CDOE#',
       '#PROCESS_DESC#',
       '#NEXT_PROCESS_CDOE#',
       '#NEXT_PROCESS_DESC#',
       '#PLINE_CODE#',
       '#PLINE_NAME#',
       '#MAT_ORIGIN_CODE#',
       '#MAT_ORIGIN_NAME#',
       '#ACT_DIMATER#',
       '#ACT_HEIGHT#',
       MYROW.ACT_LEN,
       '#ACT_LEN_MIN#',
       '#ACT_LEN_MAX#',
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_WEIGHT,
       '#BELONG_CODE#',
       '#BELONG_NAME#',
       '#MAT_GOWHERE_CODE#',
       '#MAT_GOWHERE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       '#BAL_YEAR_MONTH#',
       '#JUDGE_STD_NAME#',
       '#QCM_STAUS#',
       '#HEAT_PLAN_NO#',
       '#GX_PLAN_NO#',
       '#CRAF_NO#',
       '#CRAFT_SEQ#',
       '#ORD_LN_DLY_PK#',
       '#ORDER_NO#',
       '#ORDER_SEQ#',
       '#ORDER_SEQ_NO#',
       '#TARGET#',
       '#FLAG_STOVE_NO_ZG#',
       '#CIC#',
       '#HEAT_PLAN_NO_OLD#',
       '#ORD_PK#',
       '#ORD_LN_PK#',
       (SELECT DECODE(H.ORDER_TYP, '120108', '1','120107','2', '0')
          FROM SLM_ORDER_HEAD H
         WHERE H.ORD_PK = '#ORD_PK#'));
  
    V_INSTOCK_SQE := '#INSTOCK_DOC#' || LPAD(V_ICOUNT, 4, 0);
    INSERT INTO YDM_BC_INLIST
      (INSTOCK_SQE,
       INSTOCK_DOC,
       INSTOCK_TYPE_CODE,
       INSTOCK_TYPE_NAME,
       MAT_NO,
       LOT_NO,
       STOVE_NO,
       JUDGE_STOVE_NO,
       BATCH_NO,
       BATCH_GROUD_NO,
       MATERIAL_NO,
       MATERIAL_NAME,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       GRADECODE,
       GRADENAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       SPEC_CODE,
       SPEC_NAME,
       MODEL_CODE,
       MODEL_DESC,
       PRO_ORDER_NO,
       PLINE_CODE,
       PLINE_NAME,
       ACT_DIMATER,
       ACT_HEIGHT,
       ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       BELONG_CODE,
       BELONG_NAME,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       INSTOCK_TIME,
       CREATE_NAME,
       CREATE_TIME,
       PRODUCT_FLAG,
       MAT_STATUS,
       JUDGE_STD_NAME,
       JUDGE_STD_CODE,
       IN_TIME_F,
       BAL_YEAR_MONTH,
       MAT_ORIGIN_CODE,
       MAT_ORIGIN_NAME,
       QCM_STAUS,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       ORD_LN_DLY_PK,
       IN_BC,
       IN_BZ)
      SELECT V_INSTOCK_SQE,
             '#INSTOCK_DOC#',
             '#INSTOCK_TYPE_CODE#',
             '#INSTOCK_TYPE_NAME#',
             MYROW.MAT_NO,
             MYROW.LOT_NO,
             MYROW.STOVE_NO,
             MYROW.JUDGE_STOVE_NO,
             MYROW.PHY_BATCH_NO,
             '#BATCH_GROUD_NO#',
             '#MATERIAL_NO#',
             '#MATERIAL_NAME#',
             '#PRODUCCODE#',
             '#PRODUCNAME#',
             '#STD_CODE#',
             '#STD_NAME#',
             '#GRADECODE#',
             '#GRADENAME#',
             '#STEELCODE#',
             '#STEELNAME#',
             '#STD_STYLE#',
             '#STD_STYLE_DESC#',
             '#SPEC_CODE#',
             '#SPEC_NAME#',
             '#MODEL_CODE#',
             '#MODEL_DESC#',
             '#PRO_ORDER_NO#',
             '#PLINE_CODE#',
             '#PLINE_NAME#',
             '#ACT_DIMATER#',
             '#ACT_HEIGHT#',
             MYROW.ACT_LEN,
             '#ACT_LEN_MIN#',
             '#ACT_LEN_MAX#',
             MYROW.ACT_COUNT,
             MYROW.ACT_WEIGHT,
             MYROW.ACT_WEIGHT,
             '#BELONG_CODE#',
             '#BELONG_NAME#',
             STORAGE_NO,
             LOCATION_NO,
             LARY_NO,
             TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
             '#CREATE_NAME#',
             TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
             '#PRODUCT_FLAG#',
             '#MAT_STATUS#',
             '#JUDGE_STD_NAME#',
             '#JUDGE_STD_CODE#',
             TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
             '#BAL_YEAR_MONTH#',
             '#MAT_ORIGIN_CODE#',
             '#MAT_ORIGIN_NAME#',
             '#QCM_STAUS#',
             '#PRO_ORDER_ID#',
             '#GX_PLAN_NO#',
             '#ORD_LN_DLY_PK#',
             '#IN_BC#',
             '#IN_BZ#'
        FROM YDM_BC_BUTTRESS
       WHERE MAT_NO = MYROW.MAT_NO;
  
    UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
       SET T.INSTORE_FLAG = '1'
     WHERE T.MAT_NO = MYROW.MAT_NO;
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;
   ]]>
   </query>
   <query id = "FrmVrpInStore.insertInStore" desc = "插入下线实绩表">
  DECLARE
  V_COUNT     NUMBER := 0;
  V_RESULT_NO VRP_INSTORE_RESULT.RESULT_NO%TYPE := NULL;
BEGIN
  SELECT COUNT(1)
    INTO V_COUNT
    FROM VRP_INSTORE_RESULT S
   WHERE S.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
  IF (V_COUNT > 0) THEN
    UPDATE VRP_INSTORE_RESULT T
       SET T.PRO_NUM = TO_NUMBER(T.PRO_NUM) + TO_NUMBER('#PRO_NUM#'),
           T.PRO_WT  = TO_NUMBER(T.PRO_WT) + TO_NUMBER('#PRO_WT#')
     WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
       AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
  ELSE
    SELECT '#PLINE_CODE#'|| TO_CHAR(SYSDATE, 'YYMMDD') ||
           LPAD(NVL(MAX(SUBSTR(T.RESULT_NO, LENGTH(T.RESULT_NO) - 4)), 0) + 1,
                5,
                0) INTO V_RESULT_NO
      FROM VRP_INSTORE_RESULT T
     WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE);
    INSERT INTO VRP_INSTORE_RESULT
      (RESULT_NO,
       HEAT_PLAN_NO,
       ZY_BATCH_ID,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       PLINE_CODE,
       PLINE_NAME,
       PRO_NUM,
       PRO_WT,
       CREATE_NAME,
       CREATE_TIME,
       COL_SHIFT,
       COL_GROUP,
       JUDGE_STOVE_NO)
    VALUES
      (V_RESULT_NO,
       '#HEAT_PLAN_NO#',
       '#ZY_BATCH_ID#',
       '#PRO_PLAN_ID#',
       '#GX_PLAN_NO#',
       '#PLINE_CODE#',
       '#PLINE_NAME#',
       '#PRO_NUM#',
       '#PRO_WT#',
       '#CREATE_NAME#',
       SYSDATE,
       '#COL_SHIFT#',
       '#COL_GROUP#',
       '#JUDGE_STOVE_NO#');
  END IF;
END;
   </query>
   <query id = "FrmVrpInStore.insertVrpComInfo" desc = "插入公共信息表">
   DECLARE
  V_VRP_STATION_CODE VRP_COM_INFO.PLINE_CODE%TYPE := NULL;
  V_RESULT_NO        VRP_COM_INFO.RESULT_NO%TYPE := NULL;
BEGIN
  IF ('#PLINE_CODE#' = 'C013') THEN
    V_VRP_STATION_CODE := '650605';
  ELSIF ('#PLINE_CODE#' = 'C014') THEN
    V_VRP_STATION_CODE := '650505';
  ELSIF ('#PLINE_CODE#' = 'C018') THEN
    V_VRP_STATION_CODE := '650107';
  ELSIF ('#PLINE_CODE#' = 'C021') THEN
    V_VRP_STATION_CODE := '650405';
  ELSIF ('#PLINE_CODE#' = 'C070') THEN
    V_VRP_STATION_CODE := '650705';
  END IF;
  SELECT '#PLINE_CODE#' || V_VRP_STATION_CODE || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.RESULT_NO, LENGTH(T.RESULT_NO) - 5)), 0) + 1,
              6,
              0)
    INTO V_RESULT_NO
    FROM VRP_COM_INFO T
   WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE);
   
   INSERT INTO VRP_COM_INFO(
        RESULT_NO,
        HEAT_PLAN_NO,
        STATION_CODE,
        STATION_DESC,
        PLINE_CODE,
        PLINE_NAME,
        ZY_BATCH_ID,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        IF_MONITOR_DBK,
        PRDCR_NO,
        MONITORDEMAND,
        CRAFT_FILE_NO,
        CRAFT_FILE_MAN,
        CRAFT_SEQ,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        LEN,
        DIMATER,
        PLN_LEN,
        PLN_LEN_MIN,
        PLN_LEN_MAX,
        HEIGHT,
        LEN_MIN,
        LEN_MAX,
        LEN_CUT_HEAD,
        LEN_CUT_END,
        ACT_SPEC_CODE,
        ACT_SPEC_NAME,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        PLN_SPEC_CODE,
        PLN_SPEC_NAME,
        PLN_DIMATER,
        PLN_HEIGHT,
        ACT_MATERIAL_NO,
        ACT_MATERIAL_NAME,
        IN_WL_ID,
        IN_WL_DESC,
        PRO_NUM,
        PRO_WT,
        STATION_STATUS,
        RRO_TIME,
        RRO_TIME_NU,
        PRO_USER,
        PRO_SHIFT,
        PRO_GROUP,
        CREATE_TIME,
        COL_OPERATOR,
        PRO_YEAR_MONTH_DAY,
        BAL_YEAR_MONTH,
        INSTOCK_DOC)
 VALUES( 
        V_RESULT_NO,
        '#HEAT_PLAN_NO#',
        V_VRP_STATION_CODE,
        '交库',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#ZY_BATCH_ID#',
        '#PRO_PLAN_ID#',
        '#GX_PLAN_NO#',
        '#IF_MONITOR_DBK#',
        '#PRDCR_NO#',
        '#MONITORDEMAND#',
        '#CRAFT_FILE_NO#',
        '#CRAFT_FILE_MAN#',
        '#CRAFT_SEQ#',
        '#JUDGE_STOVE_NO#',
        '#BATCH_NO#',
        '#BATCH_GROUD_NO#',
        '#GRADECODE#',
        '#GRADENAME#',
        '#STEELCODE#',
        '#STEELNAME#',
        '#SPEC_CODE#',
        '#SPEC_NAME#',
        '#LEN#',
        '#DIMATER#',
        '#PLN_LEN#',
        '#PLN_LEN_MIN#',
        '#PLN_LEN_MAX#',
        '#HEIGHT#',
        '#LEN_MIN#',
        '#LEN_MAX#',
        '#LEN_CUT_HEAD#',
        '#LEN_CUT_END#',
        '#ACT_SPEC_CODE#',
        '#ACT_SPEC_NAME#',
        '#ACT_DIMATER#',
        '#ACT_HEIGHT#',
        '#ACT_LEN#',
        '#ACT_LEN_MIN#',
        '#ACT_LEN_MAX#',
        '#PLN_SPEC_CODE#',
        '#PLN_SPEC_NAME#',
        '#PLN_DIMATER#',
        '#PLN_HEIGHT#',
        '#ACT_MATERIAL_NO#',
        '#ACT_MATERIAL_NAME#',
        '#IN_WL_ID#',
        '#IN_WL_DESC#',
        '#PRO_NUM#',
        '#PRO_WT#',
        '#STATION_STATUS#',
        TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#RRO_TIME_NU#',
        '#PRO_USER#',
        '#PRO_SHIFT#',
        '#PRO_GROUP#',
        TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#COL_OPERATOR#',
        '#PRO_YEAR_MONTH_DAY#',
        '#BAL_YEAR_MONTH#',
        '#INSTOCK_DOC#');
END;
   </query>

    <query id = "FrmVrpInStore.insertVrpComInfo2" desc = "插入公共信息表">
        DECLARE
        V_VRP_STATION_CODE VRP_COM_INFO.Station_Code%TYPE := NULL;
        V_RESULT_NO        VRP_COM_INFO.RESULT_NO%TYPE := NULL;
        BEGIN
        FOR MYROW IN (SELECT PLINE_CODE,
        PLINE_NAME,
        LOT_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        CREATE_NAME,
        PRO_BC,
        PRO_BZ,
        BAL_YEAR_MONTH,
        INSTOCK_DOC,
        SUM(T.ACT_COUNT) ACT_COUNT,
        SUM(T.ACT_WEIGHT) ACT_WEIGHT,
        ACT_LEN
        FROM YDM_BC_INLIST T
        WHERE T.INSTOCK_DOC = ?
        GROUP BY PLINE_CODE,
        PLINE_NAME,
        LOT_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        ACT_HEIGHT,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        CREATE_NAME,
        PRO_BC,
        PRO_BZ,
        BAL_YEAR_MONTH,
        INSTOCK_DOC
        ) LOOP

        V_VRP_STATION_CODE := '650705';

        SELECT MYROW.PLINE_CODE  || V_VRP_STATION_CODE || TO_CHAR(SYSDATE, 'YYMMDD') ||
        LPAD(NVL(MAX(SUBSTR(T.RESULT_NO, LENGTH(T.RESULT_NO) - 5)), 0) + 1,
        6,
        0)
        INTO V_RESULT_NO
        FROM VRP_COM_INFO T
        WHERE RESULT_NO LIKE  MYROW.PLINE_CODE  || V_VRP_STATION_CODE || TO_CHAR(SYSDATE, 'YYMMDD') || '______';

        INSERT INTO VRP_COM_INFO(
        RESULT_NO,
        HEAT_PLAN_NO,
        STATION_CODE,
        STATION_DESC,
        PLINE_CODE,
        PLINE_NAME,
        ZY_BATCH_ID,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        PRDCR_NO,
        MONITORDEMAND,
        CRAFT_FILE_NO,
        CRAFT_FILE_MAN,
        CRAFT_SEQ,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        GRADECODE,
        GRADENAME,
        STEELCODE,
        STEELNAME,
        SPEC_CODE,
        SPEC_NAME,
        LEN,
        DIMATER,
        PLN_LEN,
        PLN_LEN_MIN,
        PLN_LEN_MAX,
        HEIGHT,
        LEN_MIN,
        LEN_MAX,
        LEN_CUT_HEAD,
        LEN_CUT_END,
        ACT_SPEC_CODE,
        ACT_SPEC_NAME,
        ACT_DIMATER,
        ACT_HEIGHT,
        ACT_LEN,
        ACT_LEN_MIN,
        ACT_LEN_MAX,
        ACT_MATERIAL_NO,
        ACT_MATERIAL_NAME,
        PRO_NUM,
        PRO_WT,
        STATION_STATUS,
        RRO_TIME,
        RRO_TIME_NU,
        COL_OPERATOR,
        PRO_SHIFT,
        PRO_GROUP,
        CREATE_TIME,
        BAL_YEAR_MONTH,
        INSTOCK_DOC)
        VALUES(
        V_RESULT_NO,
        ?,
        V_VRP_STATION_CODE,
        '交库',
        MYROW.PLINE_CODE,
        MYROW.PLINE_NAME,
        MYROW.LOT_NO,
        MYROW.PRO_PLAN_ID,
        MYROW.GX_PLAN_NO,
        '',
        '',
        '',
        '',
        '',
        MYROW.JUDGE_STOVE_NO,
        MYROW.BATCH_NO,
        MYROW.BATCH_GROUD_NO,
        MYROW.GRADECODE,
        MYROW.GRADENAME,
        MYROW.STEELCODE,
        MYROW.STEELNAME,
        MYROW.SPEC_CODE,
        MYROW.SPEC_NAME,
        '',
        MYROW.ACT_DIMATER,
        MYROW.ACT_LEN,
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        MYROW.ACT_HEIGHT,
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        '',
        '',
        MYROW.SPEC_CODE,
        MYROW.SPEC_NAME,
        MYROW.ACT_DIMATER,
        MYROW.ACT_HEIGHT,
        MYROW.ACT_LEN,
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        '',
        '',
        MYROW.ACT_COUNT,
        MYROW.ACT_WEIGHT,
        '1',
        SYSDATE,
        '',
        MYROW.CREATE_NAME,
        MYROW.PRO_BC,
        MYROW.PRO_BZ,
        SYSDATE,
        MYROW.BAL_YEAR_MONTH,
        MYROW.INSTOCK_DOC);

        END LOOP;
        END;

    </query>
   <query id = "FrmVrpInStore.getStorageNo" desc = "获取科室下对应产出库">
       SELECT S.STORAGE_NO
       FROM YDM_BS_STORAGE S,COM_BASE_PLINE T
       WHERE S.STORAGE_NO = T.OUT_REPOSITORY
       AND T.PLINE_CODE = ?
   </query>
     <query id = "FrmVrpInStore.getPhyBatch" desc = "查询性能批号">
      SELECT T.PHY_BATCH_NO FROM PORT_VRP_BATCH_SAMPLE_RESULT T WHERE T.PLINE_CODE = ? AND T.HEAT_PLAN_NO = ?
   </query>
   <query id = "FrmVrpInStore.selectBelong" desc = "查询产线对应所属权">
   SELECT T.DEPARTMENT_CODE,T.DEPARTMENT_DESC FROM COM_BASE_PLINE T WHERE T.PLINE_CODE = '#PLINE_CODE#'
   </query>
   <query id = "FrmVrpInStore.selectLxCount" desc= "查询待处理支数">
   SELECT COUNT(1) ACOUNT
  FROM PORT_VRP_BATCH_SAMPLE_RESULT T
 WHERE T.MAT_STATUS IN ('00', '20')
   AND T.INSTORE_FLAG = '0'
   AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   </query>
   <query id = "FrmVrpInStore.selectNodeFlag" desc = "查询结炉标识">
   SELECT T.BESIDE_STATUS
  FROM PLN_ZY_DBK_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   </query>
   <query id = "FrmVrpInStore.UpdateNodeFlag" desc = "结炉">
   DECLARE
BEGIN
  
  FOR MYROW IN (SELECT SUM(S.ACT_COUNT) ACT_COUNT,
                       SUM(S.ACT_WEIGHT) ACT_WEIGHT,
                       S.HEAT_PLAN_NO,
                       S.HEAT_PLAN_SQE
                  FROM PORT_VRP_BATCH_SAMPLE_RESULT S
                 WHERE S.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
                   AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND S.MAT_STATUS = '00'
                 GROUP BY S.HEAT_PLAN_NO, S.HEAT_PLAN_SQE) LOOP
    UPDATE PLN_ZY_DBK_C S
       SET S.REAL_OUTDOUBLE_NUM = MYROW.ACT_COUNT,
           S.REAL_OUTDOUBLE_WT  = MYROW.ACT_WEIGHT
     WHERE S.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO
       AND S.HEAT_PLAN_SQE = MYROW.HEAT_PLAN_SQE;
  END LOOP;
  UPDATE PLN_ZY_DBK_M T
     SET T.BESIDE_STATUS = '60',
     T.PLANSTATUS = '30'
   WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
  UPDATE VRP_INSTORE_RESULT S
     SET S.NODE_FUR_FLAG = '1'
   WHERE S.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
  UPDATE VRP_COM_INFO T SET T.STATION_STATUS = '2'
   WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.STATION_DESC = '交库';
END;
   </query>
   <query id = "FrmVrpInStore.selectNode" desc = "查询是否结炉">
   SELECT COUNT(1) ACOUNT
  FROM PLN_ZY_DBK_M T
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BESIDE_STATUS = '60'
   </query>
      <query id = "FrmHttInStore.selectQcmApp" desc = "查询是否送判">
   SELECT COUNT(1) ACOUNT 
   FROM (SELECT COUNT(1) ACOUNT
  FROM mat_bc_m T
 WHERE  T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CDOE = 'F'
   AND T.JUGDE_APPLY_CODE IS NULL
   UNION
    SELECT COUNT(1) ACOUNT
  FROM mat_bc_backup T
 WHERE  T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CDOE = 'F'
   AND T.JUGDE_APPLY_CODE IS NULL)
   </query>
        <query id = "FrmVrpInStore.selectQcmApp" desc = "查询是否送判">
   SELECT COUNT(1) ACOUNT 
   FROM (SELECT COUNT(1) ACOUNT
  FROM mat_bc_m T
 WHERE  T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CDOE = 'E'
   AND T.JUGDE_APPLY_CODE IS NULL
   UNION
    SELECT COUNT(1) ACOUNT
  FROM mat_bc_backup T
 WHERE  T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.PROCESS_CDOE = 'E'
   AND T.JUGDE_APPLY_CODE IS NULL)
   </query>
   <query id = "FrmVrpInStore.SelectMatGpStorageE" desc = "查询在库物料">
       SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT,
       MAX(T.JUGDE_APPLY_CODE) JUGDE_APPLY_CODE,
       NVL(MAX(T.LOCK_LIKU), 0) LOCK_LIKU
       FROM (SELECT S.STORAGE_NO,
       T1.ACT_COUNT,
       T1.JUGDE_APPLY_CODE,
       T1.LOCK_LIKU,
       T.PLINE_CODE
       FROM YDM_BC_INLIST T, MAT_BC_M T1, YDM_BC_BUTTRESS S
       WHERE T.MAT_NO = T1.MAT_NO
       AND T.MAT_NO = S.MAT_NO
       AND T.INSTOCK_DOC = '#INSTOCK_DOC#'
       AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND T1.BATCH_NO = '#BATCH_NO#'
       --AND T.ACT_LEN = '#ACT_LEN#'
       AND T1.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
       --     AND S.STORAGE_NO = '#STORAGE_NO#'
       AND T1.PLINE_CODE = '#PLINE_CODE#'
       AND T1.QCM_STAUS = '00'
       AND T1.PROCESS_CDOE = 'E') T
       LEFT JOIN COM_BASE_PLINE C
       ON C.OUT_REPOSITORY = T.STORAGE_NO
       AND C.PLINE_CODE = T.PLINE_CODE
       WHERE DECODE(C.OUT_REPOSITORY,NULL,'已倒运','未倒运') = '#STATUS#'

</query>

 <query id = "FrmVrpInStore.SelectMatGpStorageF" desc = "查询在库物料">
     SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT,
     MAX(T.JUGDE_APPLY_CODE) JUGDE_APPLY_CODE,
     NVL(MAX(T.LOCK_LIKU), 0) LOCK_LIKU
     FROM (SELECT S.STORAGE_NO,
     T1.ACT_COUNT,
     T1.JUGDE_APPLY_CODE,
     T1.LOCK_LIKU,
     T.PLINE_CODE
     FROM YDM_BC_INLIST T, MAT_BC_M T1, YDM_BC_BUTTRESS S
     WHERE T.MAT_NO = T1.MAT_NO
     AND T.MAT_NO = S.MAT_NO
     AND T.INSTOCK_DOC = '#INSTOCK_DOC#'
     AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T1.BATCH_NO = '#BATCH_NO#'
     AND T.ACT_LEN = '#ACT_LEN#'
     AND T1.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
     --     AND S.STORAGE_NO = '#STORAGE_NO#'
     AND T1.PLINE_CODE = '#PLINE_CODE#'
     AND T1.QCM_STAUS = '00'
     AND T1.PROCESS_CDOE = 'F') T
     LEFT JOIN COM_BASE_PLINE C
     ON C.OUT_REPOSITORY = T.STORAGE_NO
     AND C.PLINE_CODE = T.PLINE_CODE
     WHERE DECODE(C.OUT_REPOSITORY,NULL,'已倒运','未倒运') = '#STATUS#'
</query>

<query id = "FrmVrpInStore.SelectMatGpStorageG" desc = "查询在库物料">
    SELECT NVL(SUM(T.ACT_COUNT), 0) ACOUNT,
    MAX(T.JUGDE_APPLY_CODE) JUGDE_APPLY_CODE,
    NVL(MAX(T.LOCK_LIKU), 0) LOCK_LIKU
    FROM (SELECT S.STORAGE_NO,
    T1.ACT_COUNT,
    T1.JUGDE_APPLY_CODE,
    T1.LOCK_LIKU,
    T.PLINE_CODE
    FROM YDM_BC_INLIST T, MAT_BC_M T1, YDM_BC_BUTTRESS S
    WHERE T.MAT_NO = T1.MAT_NO
    AND T.MAT_NO = S.MAT_NO
    AND T.INSTOCK_DOC = '#INSTOCK_DOC#'
    AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
    AND T1.BATCH_NO = '#BATCH_NO#'
    --AND T.ACT_LEN = '#ACT_LEN#'
    AND T.ACT_LEN_MIN = #ACT_LEN_MIN#
    AND T.ACT_LEN_MAX  = #ACT_LEN_MAX#
    AND T1.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
    --     AND S.STORAGE_NO = '#STORAGE_NO#'
    AND T1.PLINE_CODE = '#PLINE_CODE#'
    AND T1.QCM_STAUS = '00'
    AND T1.PROCESS_CDOE = 'G') T
    LEFT JOIN COM_BASE_PLINE C
    ON C.OUT_REPOSITORY = T.STORAGE_NO
    AND C.PLINE_CODE = T.PLINE_CODE
    WHERE DECODE(C.OUT_REPOSITORY,NULL,'已倒运','未倒运') = '#STATUS#'

</query>

  <query id = "FrmVrpInStore.SelectMatApplyCode" desc = "查询申请判定单号">
  SELECT T.JUGDE_APPLY_CODE
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
 AND T.BATCH_NO = '#BATCH_NO#'
 AND T.JUGDE_APPLY_CODE IS NOT NULL
</query>

<query id = "FrmVrpInStore.DeleteInList" desc = "撤销交库">
<![CDATA[
DECLARE
  V_COUNT  NUMBER := 0;
  V_ICOUNT NUMBER := 0;

  T_COUNT NUMBER := 0;
  T_WT    NUMBER := 0;
  T_WT_1  NUMBER := 0;
BEGIN
  FOR MYROW IN (SELECT T.PLINE_CODE,
                       T.MAT_NO,
                       BATCH_NO,
                       BATCH_GROUD_NO,
                       JUDGE_STOVE_NO,
                       INSTOCK_SQE,
                       T.ACT_WEIGHT,
                       T.ACT_THEORY_WEIGHT
                  FROM (SELECT T.*, S.STORAGE_NO CSTORAGE_NO
                          FROM YDM_BC_INLIST   T,
                               MAT_BC_M        T1,
                               YDM_BC_BUTTRESS S
                         WHERE T.MAT_NO = T1.MAT_NO
                           AND T.MAT_NO = S.MAT_NO
                           AND T.INSTOCK_DOC = '#INSTOCK_DOC#'
                           AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T1.BATCH_NO = '#BATCH_NO#'
                           AND T1.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                           AND T1.PLINE_CODE = '#PLINE_CODE#'
                           AND T1.QCM_STAUS = '00'
                           AND T1.PROCESS_CDOE = 'E') T
                  LEFT JOIN COM_BASE_PLINE C
                    ON C.OUT_REPOSITORY = T.CSTORAGE_NO
                   AND C.PLINE_CODE = T.PLINE_CODE
                 WHERE DECODE(C.OUT_REPOSITORY, NULL, '已倒运', '未倒运') = '未倒运') LOOP

    T_COUNT := T_COUNT + 1;
    T_WT    := T_WT + MYROW.ACT_WEIGHT;
    T_WT_1  := T_WT_1 + MYROW.ACT_THEORY_WEIGHT;

    UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
       SET T.INSTORE_FLAG = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO;

    DELETE FROM MAT_BC_M T
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.BATCH_NO = MYROW.BATCH_NO
       AND T.BATCH_GROUD_NO = MYROW.BATCH_GROUD_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;

    SELECT COUNT(1)
      INTO V_ICOUNT
      FROM YDM_BC_BUTTRESS_BACK
     WHERE MAT_NO = MYROW.MAT_NO
       AND PLINE_CODE = MYROW.PLINE_CODE;

    IF (V_ICOUNT = 0) THEN
      INSERT INTO YDM_BC_BUTTRESS_BACK
        (MAT_NO,
         JUDGE_STOVE_NO,
         BATCH_NO,
         BATCH_GROUD_NO,
         STORAGE_NO,
         LOCATION_NO,
         LARY_NO,
         LOC_NO,
         STORAGE_ATTR,
         STORAGE_ATTR_NAME,
         STORAGE_TYPE_NO,
         STORAGE_TYPE_NAME,
         MANAGEMENT_NO,
         MANAGEMENT_NAME,
         MEMO,
         CREATE_NAME,
         CREATE_TIME,
         UPDATE_NAME,
         UPDATE_TIME,
         DELETE_NAME,
         DELETE_TIME,
         DEPARTMENT_CODE,
         DEPARTMENT_DESC,
         PLINE_CODE)
        SELECT MAT_NO,
               JUDGE_STOVE_NO,
               BATCH_NO,
               BATCH_GROUD_NO,
               STORAGE_NO,
               LOCATION_NO,
               LARY_NO,
               LOC_NO,
               STORAGE_ATTR,
               STORAGE_ATTR_NAME,
               STORAGE_TYPE_NO,
               STORAGE_TYPE_NAME,
               MANAGEMENT_NO,
               MANAGEMENT_NAME,
               MEMO,
               CREATE_NAME,
               CREATE_TIME,
               UPDATE_NAME,
               UPDATE_TIME,
               DELETE_NAME,
               DELETE_TIME,
               DEPARTMENT_CODE,
               DEPARTMENT_DESC,
               MYROW.PLINE_CODE
          FROM YDM_BC_BUTTRESS
         WHERE MAT_NO = MYROW.MAT_NO
           AND PLINE_CODE = MYROW.PLINE_CODE;

    ELSE
      UPDATE YDM_BC_BUTTRESS_BACK T
         SET (MAT_NO,
              JUDGE_STOVE_NO,
              BATCH_NO,
              BATCH_GROUD_NO,
              STORAGE_NO,
              LOCATION_NO,
              LARY_NO,
              LOC_NO,
              STORAGE_ATTR,
              STORAGE_ATTR_NAME,
              STORAGE_TYPE_NO,
              STORAGE_TYPE_NAME,
              MANAGEMENT_NO,
              MANAGEMENT_NAME,
              MEMO,
              CREATE_NAME,
              CREATE_TIME,
              UPDATE_NAME,
              UPDATE_TIME,
              DELETE_NAME,
              DELETE_TIME,
              DEPARTMENT_CODE,
              DEPARTMENT_DESC,
              PLINE_CODE) =
             (SELECT MAT_NO,
                     JUDGE_STOVE_NO,
                     BATCH_NO,
                     BATCH_GROUD_NO,
                     STORAGE_NO,
                     LOCATION_NO,
                     LARY_NO,
                     LOC_NO,
                     STORAGE_ATTR,
                     STORAGE_ATTR_NAME,
                     STORAGE_TYPE_NO,
                     STORAGE_TYPE_NAME,
                     MANAGEMENT_NO,
                     MANAGEMENT_NAME,
                     MEMO,
                     CREATE_NAME,
                     CREATE_TIME,
                     UPDATE_NAME,
                     UPDATE_TIME,
                     DELETE_NAME,
                     DELETE_TIME,
                     DEPARTMENT_CODE,
                     DEPARTMENT_DESC,
                     MYROW.PLINE_CODE
                FROM YDM_BC_BUTTRESS
               WHERE MAT_NO = T.MAT_NO)
       WHERE MAT_NO = MYROW.MAT_NO
         AND PLINE_CODE = MYROW.PLINE_CODE;
    END IF;

    DELETE FROM YDM_BC_BUTTRESS T WHERE MAT_NO = MYROW.MAT_NO;

    DELETE FROM YDM_BC_INLIST F WHERE F.INSTOCK_SQE = MYROW.INSTOCK_SQE;
  END LOOP;
  UPDATE VRP_INSTORE_RESULT S
     SET S.PRO_NUM       = TO_NUMBER(S.PRO_NUM) - TO_NUMBER('#ACT_COUNT#'),
         S.PRO_WT        = TO_NUMBER(S.PRO_WT) - TO_NUMBER('#ACT_WEIGHT#'),
         S.NODE_FUR_FLAG = '0'
   WHERE S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND S.PRO_PLAN_ID = '#PRO_PLAN_ID#'
     AND S.GX_PLAN_NO = '#GX_PLAN_NO#';
  SELECT NVL(SUM(S.PRO_NUM), 0)
    INTO V_COUNT
    FROM VRP_INSTORE_RESULT S
   WHERE S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND S.PRO_PLAN_ID = '#PRO_PLAN_ID#'
     AND S.GX_PLAN_NO = '#GX_PLAN_NO#';
  IF (V_COUNT = 0) THEN
    DELETE FROM VRP_INSTORE_RESULT S
     WHERE S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND S.PRO_PLAN_ID = '#PRO_PLAN_ID#'
       AND S.GX_PLAN_NO = '#GX_PLAN_NO#';
  END IF;

  INSERT INTO VRP_COM_INFO
    (RESULT_NO,
     HEAT_PLAN_NO,
     STATION_CODE,
     STATION_DESC,
     PLINE_CODE,
     PLINE_NAME,
     ZY_BATCH_ID,
     PRO_PLAN_ID,
     GX_PLAN_NO,
     IF_MONITOR_DBK,
     PRDCR_NO,
     MONITORDEMAND,
     PRODUCER,
     PRODUCER_TIME,
     CRAFT_FILE_NO,
     CRAFT_FILE_MAN,
     CRAFT_SEQ,
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     GRADECODE,
     GRADENAME,
     STEELCODE,
     STEELNAME,
     SPEC_CODE,
     SPEC_NAME,
     LEN,
     DIMATER,
     PLN_LEN,
     PLN_LEN_MIN,
     PLN_LEN_MAX,
     HEIGHT,
     LEN_MIN,
     LEN_MAX,
     LEN_CUT_HEAD,
     LEN_CUT_END,
     ACT_SPEC_CODE,
     ACT_SPEC_NAME,
     ACT_DIMATER,
     ACT_HEIGHT,
     ACT_LEN,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     PLN_SPEC_CODE,
     PLN_SPEC_NAME,
     PLN_DIMATER,
     PLN_HEIGHT,
     ACT_MATERIAL_NO,
     ACT_MATERIAL_NAME,
     IN_WL_ID,
     IN_WL_DESC,
     PRO_NUM,
     PRO_WT,
     FAIL_NUM,
     FAIL_WT,
     OFFLINE_NUM,
     OFFLINE_WT,
     RE_NUM,
     RE_WT,
     STATION_STATUS,
     RRO_TIME,
     RRO_TIME_NU,
     PRO_USER,
     PRO_SHIFT,
     PRO_GROUP,
     VALIDFLAG,
     CREATE_TIME,
     COL_OPERATOR,
     PONDER_GROSS_WT,
     PRO_YEAR_MONTH_DAY,
     BAL_YEAR_MONTH,
     INSTOCK_DOC,
     BELONG_CODE,
     BELONG_NAME,
     FACE_RESULT_PATH)
    SELECT  (SELECT T.RESULT_NO || LPAD(NVL(MAX(TO_NUMBER(SUBSTR(RESULT_NO,
                                                                LENGTH(RESULT_NO) - 1))),
                                           0) + 1,
                                       2,
                                       '0') RESULT_NO
              FROM VRP_COM_INFO
             WHERE RESULT_NO LIKE T.RESULT_NO || '__'),
           HEAT_PLAN_NO,
           STATION_CODE,
           STATION_DESC,
           PLINE_CODE,
           PLINE_NAME,
           ZY_BATCH_ID,
           PRO_PLAN_ID,
           GX_PLAN_NO,
           IF_MONITOR_DBK,
           PRDCR_NO,
           MONITORDEMAND,
           PRODUCER,
           PRODUCER_TIME,
           CRAFT_FILE_NO,
           CRAFT_FILE_MAN,
           CRAFT_SEQ,
           JUDGE_STOVE_NO,
           BATCH_NO,
           BATCH_GROUD_NO,
           GRADECODE,
           GRADENAME,
           STEELCODE,
           STEELNAME,
           SPEC_CODE,
           SPEC_NAME,
           LEN,
           DIMATER,
           PLN_LEN,
           PLN_LEN_MIN,
           PLN_LEN_MAX,
           HEIGHT,
           LEN_MIN,
           LEN_MAX,
           LEN_CUT_HEAD,
           LEN_CUT_END,
           ACT_SPEC_CODE,
           ACT_SPEC_NAME,
           ACT_DIMATER,
           ACT_HEIGHT,
           ACT_LEN,
           ACT_LEN_MIN,
           ACT_LEN_MAX,
           PLN_SPEC_CODE,
           PLN_SPEC_NAME,
           PLN_DIMATER,
           PLN_HEIGHT,
           ACT_MATERIAL_NO,
           ACT_MATERIAL_NAME,
           IN_WL_ID,
           IN_WL_DESC,
           0 - T_COUNT,
           0 - T_WT,
           FAIL_NUM,
           FAIL_WT,
           OFFLINE_NUM,
           OFFLINE_WT,
           RE_NUM,
           RE_WT,
           STATION_STATUS,
           RRO_TIME,
           RRO_TIME_NU,
           PRO_USER,
           PRO_SHIFT,
           PRO_GROUP,
           VALIDFLAG,
           CREATE_TIME,
           COL_OPERATOR,
           PONDER_GROSS_WT,
           PRO_YEAR_MONTH_DAY,
           BAL_YEAR_MONTH,
           INSTOCK_DOC,
           BELONG_CODE,
           BELONG_NAME,
           FACE_RESULT_PATH
      FROM VRP_COM_INFO T
     WHERE T.INSTOCK_DOC = '#INSTOCK_DOC#'
       AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND T.BATCH_NO = '#BATCH_NO#'
       AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
       AND T.PRO_NUM >0
       AND ROWNUM = 1;
END;

]]>
</query>
<query id = "FrmVrpInStore.selectPlnZyRcl" desc = "查询">
SELECT  S.*
  FROM PLN_ZY_RCL_M S
 WHERE S.UPPER_HEATPLAN_ID ='#HEAT_PLAN_NO#'
 ORDER BY TO_NUMBER(S.GX_PRO_SEQ) ASC
</query>

<query id = "FrmVrpInStore.selectPlnZyJg" desc = "查询">
SELECT  S.*
  FROM PLN_ZY_JGX_M S
 WHERE S.UPPER_HEATPLAN_ID ='#HEAT_PLAN_NO#'
 ORDER BY TO_NUMBER(S.GX_PRO_SEQ) ASC
</query>

<query id = "FrmVrpInStore.selectPlnZyJgm" desc = "查询">
SELECT  S.*
  FROM PLN_ZY_JG_M S
 WHERE S.UPPER_HEATPLAN_ID ='#HEAT_PLAN_NO#'
 ORDER BY TO_NUMBER(S.GX_PRO_SEQ) ASC
</query>
<query id = "FrmVrpInStore.selectPlnZyJgmProp" desc = "查询">
SELECT MIN(T.CODE_JG_BL) CODE_JG_BL
  FROM PLN_GX_JG_PROP_S T
 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
</query>

<query id = "FrmVrpInStore.selectMatGpMNumZg" desc = "查询已挂单倍坯支数">
SELECT nvl(SUM(ACT_COUNT),0) ACT_COUNT
  FROM (SELECT T.ACT_COUNT
          FROM MAT_BC_M T
         WHERE T.PRO_PLAN_ID_NEXT = '#PRO_PLAN_ID#'
           AND T.GX_PLAN_NO_NEXT = '#GX_PLAN_NO#'
           AND T.HEAT_PLAN_NO = '#UPPER_HEATPLAN_ID#'
        UNION ALL
        SELECT T.ACT_COUNT
          FROM MAT_BC_BACKUP T
         WHERE T.PRO_PLAN_ID_NEXT = '#PRO_PLAN_ID#'
           AND T.GX_PLAN_NO_NEXT = '#GX_PLAN_NO#'
           AND T.HEAT_PLAN_NO = '#UPPER_HEATPLAN_ID#')
</query>
<query id = "FrmVrpInStore.QueryLoadingPiece" desc = "查询上料支数">
SELECT NVL(SUM(T.REAL_INDOUBLE_NUM),0) REAL_INDOUBLE_NUM,NVL(SUM(T.REAL_OUTDOUBLE_NUM),0) REAL_OUTDOUBLE_NUM
  FROM PLN_ZY_DBK_C T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>
<query id = "FrmVrpInStore.QueryOfflinePiece" desc = "查询离线支数">
select NVL(SUM(T.OFFLINE_NUM),0) OFFLINE_NUM, NVL(SUM(T.RE_NUM),0) RE_NUM,NVL(SUM(T.GROUP_NUM),0) GROUP_NUM
  from VRP_OFFLINE_RESULT T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
</query>
<query id = "FrmVrpInStore.QueryVrpPortFailPiece" desc = "查询各实绩废品和">
select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
  from PORT_VRP_BATCH_SAMPLE_RESULT t
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND ((T.MAT_STATUS = '00' and t.instore_flag='0')
   or t.mat_status = '20')
</query>
	<query id="FrmVrpInStore.queryPortStuts" desc="查询管号队列废品">
        <![CDATA[
	SELECT NVL(SUM(T.ACT_COUNT),0) ACT_COUNT FROM PORT_VRP_BATCH_SAMPLE_RESULT T 
WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#' AND T.PLINE_CODE = '#PLINE_CODE#'
 AND T.MAT_STATUS not in ('10','40','30') 
        ]]>
	</query>
		<query id="FrmVrpInStore.plnupdateStuts" desc="结炉修改计划表状态为关闭">
		<![CDATA[
 UPDATE PLN_ZY_DBK_M
    SET  PLANSTATUS = '40'
  WHERE HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
			]]>
	</query>
<query id = "FrmVrpInStore.QueryMatbcmPiece" desc = "查询交库后库存表支数">
SELECT NVL(SUM(REAL_OUTDOUBLE_NUM),0) REAL_OUTDOUBLE_NUM FROM (
SELECT NVL(SUM(T.ACT_COUNT), 0) REAL_OUTDOUBLE_NUM
  FROM MAT_BC_M T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE = 'E'
UNION
SELECT NVL(SUM(T.ACT_COUNT), 0) REAL_OUTDOUBLE_NUM
  FROM MAT_BC_BACKUP T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE = 'E')
</query>
<query id = "FrmVrpInStore.CancelupdateNodeFlag" desc = "结炉回退">
DECLARE
BEGIN
  UPDATE PLN_ZY_DBK_C S
       SET S.REAL_OUTDOUBLE_NUM = '',
           S.REAL_OUTDOUBLE_WT  = ''
     WHERE S.HEAT_PLAN_NO = '#HEAT_PLAN_NO#';
  UPDATE PLN_ZY_DBK_M T
     SET T.BESIDE_STATUS = '40',
     T.PLANSTATUS = '20'
   WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
  UPDATE VRP_INSTORE_RESULT S
     SET S.NODE_FUR_FLAG = '0'
   WHERE S.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
  UPDATE VRP_COM_INFO T SET T.STATION_STATUS = '1'
   WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.STATION_DESC = '交库';
END;
</query>
<query id = "FrmVrpInStore.updateMatBcM" desc = "挂下工序订单">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM MAT_BC_M T
                         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
                           AND T.PRO_ORDER_ID = '#PRO_ORDER_ID#'
                           AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
                           AND T.PLINE_CODE = '#PLINE_CODE#'
                           AND T.QCM_STAUS = '00'
                           AND T.PRO_PLAN_ID_NEXT IS NULL
                         ORDER BY T.MAT_NO ASC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE MAT_BC_M T
       SET T.PRO_PLAN_ID_NEXT = '#PRO_PLAN_ID_NEXT#',
           T.GX_PLAN_NO_NEXT  = '#GX_PLAN_NO_NEXT#',
           T.HEAT_PLAN_NO_NEXT ='#HEAT_PLAN_NO_NEXT#',
           T.CODE_JG_BL ='#CODE_JG_BL#'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.PLINE_CODE = MYROW.PLINE_CODE;
  END LOOP;
END;
]]>
</query>
<query id = "FrmVrpInStore.updateBatchNo" desc = "修改性能批号">
<![CDATA[
DECLARE
  V_COUNT NUMBER := 0;
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT *
                          FROM PORT_VRP_BATCH_SAMPLE_RESULT T
                         WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                           AND T.PHY_BATCH_NO = '#PHY_BATCH_NO#'
                         ORDER BY T.MAT_NO, T.MAT_STATUS ASC)
                 WHERE ROWNUM <= #ACT_COUNT#) LOOP
    UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
       SET T.PHY_BATCH_NO = '#NEW_PHY_BATCH_NO#',T.IS_SAMPLE_PIPE = '0'
     WHERE T.MAT_NO = MYROW.MAT_NO;
     IF(MYROW.MAT_STATUS = '00' AND V_COUNT<#SAMPLE_NUM#)THEN
     UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
       SET T.IS_SAMPLE_PIPE = '1'
     WHERE T.MAT_NO = MYROW.MAT_NO;
     END IF;
     V_COUNT := V_COUNT + 1;
  END LOOP;
END;
]]>
</query>

<query id = "FrmVrpInStore.updateCutLength" desc = "回报切头尾长度">
<![CDATA[
DECLARE
  V_HEAT_PLAN_NO    PLN_ZY_DBK_M.HEAT_PLAN_NO%type := ?;
  V_JUDGE_STOVE_NO  PLN_ZY_DBK_M.JUDGE_STOVE_NO%type := ?;
  V_CUT_NAME        PLN_ZY_DBK_M.CUT_NAME%type := ?;
  V_ACT_LEN_CUTHEAD PLN_ZY_DBK_M.ACT_LEN_CUTHEAD%type := ?;
  V_ACT_LEN_CUTEND  PLN_ZY_DBK_M.ACT_LEN_CUTEND%type := ?;
BEGIN
  UPDATE PLN_ZY_DBK_M T
     SET T.ACT_LEN_CUTHEAD = V_ACT_LEN_CUTHEAD,
         T.ACT_LEN_CUTEND  = V_ACT_LEN_CUTEND,
         T.CUT_NAME        = V_CUT_NAME,
         T.CUT_TIME        = SYSDATE
   WHERE T.HEAT_PLAN_NO = V_HEAT_PLAN_NO
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;

  UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
     SET T.CUT_ACT_LEN = T.ACT_LEN, T.CUT_ACT_WEIGHT = T.ACT_WEIGHT
   WHERE T.HEAT_PLAN_NO = V_HEAT_PLAN_NO
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
     AND T.CUT_ACT_LEN IS NULL
     AND T.CUT_ACT_WEIGHT IS NULL;

  UPDATE PORT_VRP_BATCH_SAMPLE_RESULT T
     SET T.ACT_LEN    = NVL(T.CUT_ACT_LEN, T.ACT_LEN) -
                        (V_ACT_LEN_CUTHEAD + V_ACT_LEN_CUTEND) / 1000,
         T.ACT_WEIGHT = NVL(T.CUT_ACT_WEIGHT, T.ACT_WEIGHT) *
                        (NVL(T.CUT_ACT_LEN, T.ACT_LEN) -
                         (V_ACT_LEN_CUTHEAD + V_ACT_LEN_CUTEND) / 1000) /
                        NVL(T.CUT_ACT_LEN, T.ACT_LEN)
   WHERE T.HEAT_PLAN_NO = V_HEAT_PLAN_NO
     AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO;
END;
]]>
</query>

<query id = "FrmVrpInStore.SelectVrpInStore" desc = "查询镦拔扩交库支数">
<![CDATA[
SELECT (SELECT COUNT(*)
          FROM MAT_BC_M T
         WHERE T.HEAT_PLAN_NO = ?
           AND T.JUDGE_STOVE_NO = ?) +
       (SELECT COUNT(*)
          FROM MAT_BC_BACKUP T
         WHERE T.HEAT_PLAN_NO = ?
           AND T.JUDGE_STOVE_NO = ?) ACOUNT
  FROM DUAL
]]>
</query>

<query id = "FrmVrpInStore.selectTmsDemandM" desc = "查询下线的支、吨">
<![CDATA[
SELECT NVL(SUM(ACT_COUNT), 0) ACT_COUNT, NVL(SUM(ACT_WEIGHT), 0) ACT_WEIGHT
  FROM (select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT,
               NVL(SUM(T.ACT_WEIGHT), 0) ACT_WEIGHT
          from MAT_BC_M t
         WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
           AND T.HEAT_PLAN_NO = ?
           AND T.QCM_STAUS = '00'
        
        UNION ALL
        
        select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT,
               NVL(SUM(T.ACT_WEIGHT), 0) ACT_WEIGHT
          from MAT_BC_BACKUP t
         WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
           AND T.HEAT_PLAN_NO = ?
           AND T.QCM_STAUS = '00')
       ]]>
</query>

<query id = "FrmVrpInStore.selectTmsScrap" desc = "查询废品支、吨">
<![CDATA[
SELECT NVL(SUM(ACT_COUNT), 0) ACT_COUNT, NVL(SUM(ACT_WEIGHT), 0) ACT_WEIGHT
  FROM (select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT,
               NVL(SUM(T.ACT_WEIGHT), 0) ACT_WEIGHT
          from MAT_BC_M t
         WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
           AND T.HEAT_PLAN_NO = ?
           AND T.QCM_STAUS = '22'
        
        UNION ALL
        
        select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT,
               NVL(SUM(T.ACT_WEIGHT), 0) ACT_WEIGHT
          from MAT_BC_BACKUP t
         WHERE T.JUDGE_STOVE_NO = REGEXP_REPLACE(?, '-.*', '')
           AND T.HEAT_PLAN_NO = ?
           AND T.QCM_STAUS = '22')
       ]]>
</query>

<query id = "FrmVrpInStore.UpdateTmsDemandM" desc = "更新运输需求">
<![CDATA[
DECLARE
  V_ACT_COUNT      TMS_DEMAND_M.OUTPUT_QTY_VAL%type := ?;
  V_ACT_WEIGHT     TMS_DEMAND_M.DEMAND_WT_VAL%type := ?;
  V_JUDGE_STOVE_NO TMS_DEMAND_M.HEAT_NO%type := REGEXP_REPLACE(?, '-.*', '');
  V_CURRENT_JOB_NO TMS_DEMAND_M.CURRENT_JOB_NO%type := ?;
  V_FLAG           TMS_DEMAND_M.CURRENT_JOB_NO%type := ?;
  V_SCRAP_QTY_VAL  TMS_DEMAND_M.SCRAP_QTY_VAL%type := ?;
  V_SCRAP_WT_VAL   TMS_DEMAND_M.SCRAP_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.SCRAP_QTY_VAL  = 0,
           T.SCRAP_WT_VAL   = 0,
           T.OUTPUT_QTY_VAL = 0,
           T.OUTPUT_WT_VAL  = 0
     WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
    --写实际数量
    IF (V_ACT_COUNT > 0) THEN
      IF (MYROW.DEMAND_QTY_VAL >= V_ACT_COUNT) THEN
        UPDATE TMS_DEMAND_M T
           SET T.OUTPUT_QTY_VAL = V_ACT_COUNT,
               T.OUTPUT_WT_VAL  = V_ACT_WEIGHT
         WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
        V_ACT_COUNT  := 0;
        V_ACT_WEIGHT := 0;
      ELSE
        UPDATE TMS_DEMAND_M T
           SET T.OUTPUT_QTY_VAL = T.DEMAND_QTY_VAL,
               T.OUTPUT_WT_VAL  = T.DEMAND_WT_VAL
         WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
        V_ACT_COUNT  := V_ACT_COUNT - MYROW.DEMAND_QTY_VAL;
        V_ACT_WEIGHT := V_ACT_WEIGHT - MYROW.DEMAND_WT_VAL;
      END IF;
    END IF;
  END LOOP;

  --结炉的数据处理
  FOR MYROW1 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
  
    IF (V_FLAG = 'JL') THEN
      IF (V_SCRAP_QTY_VAL > 0) THEN
        IF (MYROW1.DEMAND_QTY_VAL - MYROW1.OUTPUT_QTY_VAL >=
           V_SCRAP_QTY_VAL) THEN
          UPDATE TMS_DEMAND_M T
             SET T.SCRAP_QTY_VAL = V_SCRAP_QTY_VAL,
                 T.SCRAP_WT_VAL  = V_SCRAP_WT_VAL
           WHERE T.DEMAND_NO = MYROW1.DEMAND_NO;
          V_SCRAP_QTY_VAL := 0;
          V_SCRAP_WT_VAL  := 0;
        ELSE
          UPDATE TMS_DEMAND_M T
             SET T.SCRAP_QTY_VAL = T.DEMAND_QTY_VAL - T.OUTPUT_QTY_VAL,
                 T.SCRAP_WT_VAL =
                 (T.DEMAND_QTY_VAL - T.OUTPUT_QTY_VAL) / V_SCRAP_QTY_VAL *
                 V_SCRAP_WT_VAL
           WHERE T.DEMAND_NO = MYROW1.DEMAND_NO;
        
          V_SCRAP_QTY_VAL := V_SCRAP_QTY_VAL - MYROW1.DEMAND_QTY_VAL +
                             MYROW1.OUTPUT_QTY_VAL;
          V_SCRAP_WT_VAL  := (V_SCRAP_QTY_VAL - MYROW1.DEMAND_QTY_VAL +
                             MYROW1.OUTPUT_QTY_VAL) / V_SCRAP_QTY_VAL *
                             V_SCRAP_WT_VAL;
        END IF;
      END IF;
    END IF;
  END LOOP;
END;
       ]]>
</query>
<query id = "FrmVrpInStore.selectHeatPlanNo" desc = "查询炉计划">
   SELECT T.*
  FROM PLN_ZY_DBK_M T
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   </query>
   
   <query id = "FrmVrpInStore.selectLoadTime" desc= "查询上料时间">
	<![CDATA[
	SELECT MIN(loadTime) loadTime
  FROM (SELECT TO_CHAR(MIN(T.LOAD_TIME), 'YYYY-MM-DD HH24:MI:SS') loadTime
          FROM VRP_LOADING_RESULT T
         WHERE T.HEAT_PLAN_NO = ?
        UNION
        SELECT TO_CHAR(MIN(T.LOAD_TIME), 'YYYY-MM-DD HH24:MI:SS') loadTime
          FROM HTT_LOADING_RESULT T
         WHERE T.HEAT_PLAN_NO = ?
        UNION
        SELECT TO_CHAR(MIN(T.LOAD_TIME), 'YYYY-MM-DD HH24:MI:SS') loadTime
          FROM MCH_LOADING_RESULT T
         WHERE T.HEAT_PLAN_NO = ?)
   ]]>
	</query>
	
	<query id = "FrmVrpInStore.selectLoadCountE" desc= "查询镦拔扩上料支吨">
	<![CDATA[
	select NVL(SUM(T.PRO_NUM), 0) PRONUM, NVL(SUM(T.PRO_WT), 0) PROWT
  from VRP_LOADING_RESULT t
 WHERE T.HEAT_PLAN_NO = ?
   ]]>
	</query>
	<query id = "FrmVrpInStore.selectLoadCountF" desc= "查询热处理上料支吨">
	<![CDATA[
	select NVL(SUM(T.PRO_NUM), 0) PRONUM, NVL(SUM(T.PRO_WT), 0) PROWT
  from HTT_LOADING_RESULT t
 WHERE T.HEAT_PLAN_NO = ?
   ]]>
	</query>
	<query id = "FrmVrpInStore.selectLoadCountG" desc= "查询加工线上料支吨">
	<![CDATA[
	select NVL(SUM(T.PRO_NUM), 0) PRONUM, NVL(SUM(T.PRO_WT), 0) PROWT
  from MCH_LOADING_RESULT t
 WHERE T.HEAT_PLAN_NO = ?
   ]]>
	</query>
	
	<query id = "FrmVrpInStore.UpdateTmsDemandMLoadTime" desc = "更新运输需求上料时间">
<![CDATA[
DECLARE
  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.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 = CASE
                                WHEN V_DEMAND_QTY_VAL > MYROW.DEMAND_QTY_VAL THEN
                                 V_DEMAND_QTY_VAL
                                ELSE
                                 MYROW.DEMAND_QTY_VAL
                              END,
           T.DEMAND_WT_VAL = CASE
                               WHEN V_DEMAND_WT_VAL > MYROW.DEMAND_WT_VAL THEN
                                V_DEMAND_WT_VAL
                               ELSE
                                MYROW.DEMAND_WT_VAL
                             END
     WHERE T.DEMAND_NO = MYROW.DEMAND_NO;
  END LOOP;
END;
       ]]>
</query>
</queryMap>