<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "管加工交库管理">
<query id = "FrmMchInStore.querySinglePlan" desc = "查询管加工炉计划">
<![CDATA[
SELECT DISTINCT T.HEAT_PLAN_NO,
       T.GX_PRO_SEQ,
       T.ZY_BATCH_ID,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T2.BATCH_NO,
       T.DOWNTIME,
       T.PLANSTATUS,
       T.PER_STATUS,
       DECODE(T2.BESIDE_STATUS,
              '00',
              '上料结炉',
              '10',
              '探伤结束',
              '20',
              '切管结炉',
              '30',
              '车丝结炉',
              '40',
              '螺纹检验结炉',
              '50',
              '拧结结炉',
              '60',
              '通径结炉',
              '70',
              '水压结炉',
              '80',
              '倒棱结炉',
              '90',
              '测量结炉',
              '11',
              '交库结炉') BESIDE_STATUS,
       T.UPPER_HEATPLAN_ID,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       NVL(T2.PLINE_CODE_W,T.PLINE_CODE) PLINE_CODE,
       NVL(T2.PLINE_NAME_W,T.PLINE_NAME) 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.OUTDIAMETER,
       T.WALLTHICK,
       T.LENGTHMIN,
       T.LENGTHMAX,
       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,
       T.IF_PRODUCT,
       T.DECISION,
       T.SPEC_NAME,
       T.SPEC_CODE,
       T.FEED_HEAT_NO,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.STD_NAME,
       T.STD_CODE,
       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,
       T2.PLINE_CODE_W,
       T2.PLINE_NAME_W,
       T.IF_PRODUCT
  FROM PLN_ZY_JGX_M T,  (SELECT HEAT_PLAN_NO,
                    BATCH_NO,MAX(PER_STATUS) PER_STATUS,MAX(BESIDE_STATUS) BESIDE_STATUS,
                    MAX(PLINE_CODE_W) PLINE_CODE_W,
                    MAX(PLINE_NAME_W) PLINE_NAME_W
               FROM PLN_ZY_JGX_C
              GROUP BY HEAT_PLAN_NO, BATCH_NO) T2
 WHERE T.HEAT_PLAN_NO = T2.HEAT_PLAN_NO
 ]]>
</query>
<query id = "FrmMchInStore.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,
       TO_CHAR(SUM(T.ACT_LEN), 'FM999990.000')  ACT_LEN,
       T.BELONG_CODE,
       T.BELONG_NAME,
       B.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
    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
    UNION ALL
    SELECT M.MAT_NO,B.STORAGE_NO
    FROM MAT_ZC_M M, YDM_ZC_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
 WHERE T.INSTOCK_TYPE_CODE = '800701'
   AND T.HAND_FLAG = '0'
   AND T.QCM_STAUS = '00'
</query>
<query id = "FrmMchInStore.doQueryVrpRack" desc = "查询管号队列信息">
        <![CDATA[
SELECT T1.HEAT_PLAN_NO,
       T1.JUDGE_STOVE_NO,
       SUM(T1.ACT_COUNT) ACT_COUNT,
       SUM(T1.ACT_WEIGHT) ACT_WEIGHT,
       SUM(T1.ACT_LEN) ACT_LEN,
       DECODE(T1.IS_SAMPLE_PIPE, '0', '非样管', '1', '样管') IS_SAMPLE_PIPE,
       T1.PHY_BATCH_NO,
       T1.OUTNUM_CUT,
       DECODE(T1.TR_FLAG, '1', '是', '否') TR_FLAG,
       DECODE(T1.INSTORE_FLAG, '1', '已入库', '未入库') INSTORE_FLAG,
       T1.FLAG_STOVE_NO,
       T1.GROUP_NO,
       T1.ACT_LEN_MAX,
       T1.ACT_LEN_MIN
  FROM (SELECT T.HEAT_PLAN_NO,
               T.JUDGE_STOVE_NO,
               T.ACT_COUNT,
               T.ACT_WEIGHT,
               T.ACT_LEN,
               T.IS_SAMPLE_PIPE,
               T.PHY_BATCH_NO,
               T.OUTNUM_CUT,
               T.TR_FLAG,
               T.INSTORE_FLAG,
               T.FLAG_STOVE_NO,
               G.GROUP_NO,
                 case when PR.PRODUC_TYPE IN ('B','A') THEN  ----
                 
               --- 大于合同范围  1m 1个范围
CASE  WHEN T.ACT_LEN > NVL(P.MAX_LEN, O.LENGTHMAX) AND NVL(O.SIGL_LEN, 0) <=0 THEN  CEIL(T.ACT_LEN - NVL(P.MAX_LEN, O.LENGTHMAX)) +   NVL(P.MAX_LEN, O.LENGTHMAX)
        ---小于合同范围  1m 1个范围
            WHEN  T.ACT_LEN <NVL(P.MIN_LEN,NVL(O.SHORTEST,0)) AND NVL(O.SIGL_LEN, 0) <=0 THEN NVL(P.MIN_LEN,NVL(O.SHORTEST,0))  - CEIL(NVL(P.MIN_LEN,NVL(O.SHORTEST,0))  - T.ACT_LEN) + 1
            ELSE
                   --- 有单倍尺
                   CASE WHEN NVL(O.SIGL_LEN, 0) > 0 THEN
                                                         --- 长度大于合同最小值
                                           CASE  WHEN T.ACT_LEN >= O.LENGTHMIN THEN
                                                                      --长度不在 单倍尺的公差范围
                                                                     CASE  WHEN T.ACT_LEN -  (O.LENGTHMIN + O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                              -- 最大值超出合同最大值   取合同最大值
                                                                                               CASE   WHEN O.LENGTHMIN + O.SIGL_LEN *  (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN) + 1) >  O.LENGTHMAX THEN
                                                                                                                          O.LENGTHMIN +   O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN) + 1)
                                                                                                             ELSE
                                                                                                                        O.LENGTHMAX
                                                                                                 END
                                                                                   --长度在单倍尺的公差范围
                                                                                 ELSE   (O.LENGTHMIN + O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))) +   O.ENDLEN_SPECSTD
                                                                       END
                                                        ELSE     --- 长度大于合同最小值
                                                                           --长度不在 单倍尺的公差范围
                                                                     CASE WHEN T.ACT_LEN -  (O.LENGTHMIN - O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                          (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN)-1))
                                                                                     --长度在单倍尺的公差范围
                                                                                ELSE  (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) +     O.ENDLEN_SPECSTD
                                                                     END
                                            END
                                 ----没单倍尺  取已经存储规则的最大值
                             ELSE
                                       GROUP_MAX
                     END
       END
          ELSE 
          T.ACT_LEN
          END 
        ACT_LEN_MAX,

  case when PR.PRODUC_TYPE IN ('B','A') THEN  ----
        --- 大于合同范围  1m 1个范围
CASE  WHEN T.ACT_LEN > NVL(P.MAX_LEN, O.LENGTHMAX) AND NVL(O.SIGL_LEN, 0) <=0 THEN   CEIL(T.ACT_LEN - NVL(P.MAX_LEN, O.LENGTHMAX)) +  NVL(P.MAX_LEN, O.LENGTHMAX) - 1
        ---小于合同范围  1m 1个范围
            WHEN  T.ACT_LEN <NVL(P.MIN_LEN,NVL(O.SHORTEST,0)) AND NVL(O.SIGL_LEN, 0) <=0 THEN        NVL(P.MIN_LEN, NVL(O.SHORTEST, 0)) -  CEIL(NVL(P.MIN_LEN, NVL(O.SHORTEST, 0)) - T.ACT_LEN)
            ELSE
                   --- 有单倍尺
                   CASE WHEN NVL(O.SIGL_LEN, 0) > 0 THEN
                                                         --- 长度大于合同最小值
                                           CASE  WHEN T.ACT_LEN >= O.LENGTHMIN THEN
                                                                      --长度不在 单倍尺的公差范围
                                                                     CASE  WHEN T.ACT_LEN -  (O.LENGTHMIN + O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                                    O.LENGTHMIN +  O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN)) +ENDLEN_SPECSTD
                                                                                   --长度在单倍尺的公差范围
                                                                                 ELSE      O.LENGTHMIN +     O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))
                                                                       END
                                                        ELSE     --- 长度大于合同最小值
                                                                           --长度不在 单倍尺的公差范围
                                                                     CASE WHEN T.ACT_LEN -  (O.LENGTHMIN - O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                                       (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) +   O.ENDLEN_SPECSTD
                                                                                     --长度在单倍尺的公差范围
                                                                                ELSE                 (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN)))
                                                                     END
                                            END
                                 ----没单倍尺  取已经存储规则的最大值
                             ELSE
                                       GROUP_MIN
                     END
       END
          ELSE 
          T.ACT_LEN
          END 
        ACT_LEN_MIN
          FROM PORT_MCH_BATCH_SAMPLE_RESULT T
          LEFT JOIN PLN_ZY_JGX_M M
            ON M.HEAT_PLAN_NO = T.HEAT_PLAN_NO
             LEFT JOIN com_base_product PR
            ON M.PRODUCCODE = PR.PRODUCCODE
             LEFT JOIN PLN_ORDER_JGX_S O
    ON M.PRO_PLAN_ID = O.PRO_PLAN_ID
   AND M.GX_PLAN_NO = O.GX_PLAN_NO
          LEFT JOIN MCH_GROUPNO G
            ON G.ORDER_NO = M.ORDER_NO || '/' || M.ORDER_SEQ
           AND T.ACT_LEN <
               NVL(DECODE(GROUP_MAX_SIGN, '<=', GROUP_MAX + 0.001, GROUP_MAX),
                   T.ACT_LEN + 0.001)
           AND T.ACT_LEN >
               NVL(DECODE(GROUP_MIN_SIGN, '>=', GROUP_MIN - 0.001, GROUP_MIN),
                   T.ACT_LEN - 0.001)
           AND ROWNUM = 1
          LEFT JOIN (SELECT ORDER_NO,
                           MAX(GROUP_MAX) MAX_LEN,
                           MIN(GROUP_MIN) MIN_LEN
                      FROM MCH_GROUPNO
                     WHERE FLAG = '1'
                     GROUP BY ORDER_NO) P
            ON P.ORDER_NO = M.ORDER_NO || '/' || M.ORDER_SEQ
         WHERE T.HEAT_PLAN_NO =?
           AND T.PHY_BATCH_NO = ?
           AND T.MAT_STATUS = '00'
           AND T.INSTORE_FLAG = NVL(?,T.INSTORE_FLAG)
           AND T.VALIDFLAG = '1') T1
 GROUP BY T1.HEAT_PLAN_NO,
          T1.JUDGE_STOVE_NO,
          T1.IS_SAMPLE_PIPE,
          T1.PHY_BATCH_NO,
          T1.GROUP_NO,
          T1.OUTNUM_CUT,
          T1.TR_FLAG,
          T1.FLAG_STOVE_NO,
          T1.ACT_LEN_MAX,
          T1.ACT_LEN_MIN,
          T1.INSTORE_FLAG
       ORDER BY HEAT_PLAN_NO,
          JUDGE_STOVE_NO,
          PHY_BATCH_NO,
          INSTORE_FLAG,
          OUTNUM_CUT,
          TR_FLAG,
          GROUP_NO,
          ACT_LEN_MAX
]]>
    </query>

<query id = "FrmMchInStore.doQueryVrpRackNoGroup" desc = "无组号数据">
        <![CDATA[
SELECT T1.HEAT_PLAN_NO,
       T1.JUDGE_STOVE_NO,
       SUM(T1.ACT_COUNT) ACT_COUNT,
       SUM(T1.ACT_WEIGHT) ACT_WEIGHT,
       SUM(T1.ACT_LEN) ACT_LEN,
       DECODE(T1.IS_SAMPLE_PIPE, '0', '非样管', '1', '样管') IS_SAMPLE_PIPE,
       T1.PHY_BATCH_NO,
       T1.OUTNUM_CUT,
       DECODE(T1.TR_FLAG, '1', '是', '否') TR_FLAG,
       DECODE(T1.INSTORE_FLAG, '1', '已入库', '未入库') INSTORE_FLAG,
       T1.FLAG_STOVE_NO,
       T1.GROUP_NO,
       T1.ACT_LEN_MAX,
       T1.ACT_LEN_MIN
  FROM (SELECT T.HEAT_PLAN_NO,
               T.JUDGE_STOVE_NO,
               T.ACT_COUNT,
               T.ACT_WEIGHT,
               T.ACT_LEN,
               T.IS_SAMPLE_PIPE,
               T.PHY_BATCH_NO,
               T.OUTNUM_CUT,
               T.TR_FLAG,
               T.INSTORE_FLAG,
               T.FLAG_STOVE_NO,
               G.GROUP_NO,
                 case when PR.PRODUC_TYPE IN ('B','A') THEN  ----
               --- 大于合同范围  1m 1个范围
CASE  WHEN T.ACT_LEN > NVL(P.MAX_LEN, O.LENGTHMAX)  AND NVL(O.SIGL_LEN, 0) <=0 THEN  CEIL(T.ACT_LEN - NVL(P.MAX_LEN, O.LENGTHMAX)) +   NVL(P.MAX_LEN, O.LENGTHMAX)
        ---小于合同范围  1m 1个范围
            WHEN  T.ACT_LEN <NVL(P.MIN_LEN,NVL(O.SHORTEST,0))  AND NVL(O.SIGL_LEN, 0) <=0 THEN NVL(P.MIN_LEN,NVL(O.SHORTEST,0))  - CEIL(NVL(P.MIN_LEN,NVL(O.SHORTEST,0))  - T.ACT_LEN) + 1
            ELSE
                   --- 有单倍尺
                   CASE WHEN NVL(O.SIGL_LEN, 0) > 0 THEN
                                                         --- 长度大于合同最小值
                                           CASE  WHEN T.ACT_LEN >= O.LENGTHMIN THEN
                                                                      --长度不在 单倍尺的公差范围
                                                                     CASE  WHEN T.ACT_LEN -  (O.LENGTHMIN + O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                              -- 最大值超出合同最大值   取合同最大值
                                                                                               CASE   WHEN O.LENGTHMIN + O.SIGL_LEN *  (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN) + 1) >  O.LENGTHMAX THEN
                                                                                                                    O.LENGTHMIN +   O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN) + 1)
                                                                                                             ELSE
                                                                                                                          O.LENGTHMAX
                                                                                                 END
                                                                                   --长度在单倍尺的公差范围
                                                                                 ELSE   (O.LENGTHMIN + O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))) +   O.ENDLEN_SPECSTD
                                                                       END
                                                        ELSE     --- 长度大于合同最小值
                                                                           --长度不在 单倍尺的公差范围
                                                                     CASE WHEN T.ACT_LEN -  (O.LENGTHMIN - O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                          (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN)-1))
                                                                                     --长度在单倍尺的公差范围
                                                                                ELSE  (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) +     O.ENDLEN_SPECSTD
                                                                     END
                                            END
                                 ----没单倍尺  取已经存储规则的最大值
                             ELSE
                                       GROUP_MAX
                     END
       END
          ELSE 
          T.ACT_LEN
          END  ACT_LEN_MAX,

  case when PR.PRODUC_TYPE IN ('B','A') THEN  ----
        --- 大于合同范围  1m 1个范围
CASE  WHEN T.ACT_LEN > NVL(P.MAX_LEN, O.LENGTHMAX) THEN   CEIL(T.ACT_LEN - NVL(P.MAX_LEN, O.LENGTHMAX)) +  NVL(P.MAX_LEN, O.LENGTHMAX) - 1
        ---小于合同范围  1m 1个范围
            WHEN  T.ACT_LEN <NVL(P.MIN_LEN,NVL(O.SHORTEST,0)) THEN        NVL(P.MIN_LEN, NVL(O.SHORTEST, 0)) -  CEIL(NVL(P.MIN_LEN, NVL(O.SHORTEST, 0)) - T.ACT_LEN)
            ELSE
                   --- 有单倍尺
                   CASE WHEN NVL(O.SIGL_LEN, 0) > 0 THEN
                                                         --- 长度大于合同最小值
                                           CASE  WHEN T.ACT_LEN >= O.LENGTHMIN THEN
                                                                      --长度不在 单倍尺的公差范围
                                                                     CASE  WHEN T.ACT_LEN -  (O.LENGTHMIN + O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                                    O.LENGTHMIN +  O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN)) +ENDLEN_SPECSTD
                                                                                   --长度在单倍尺的公差范围
                                                                                 ELSE      O.LENGTHMIN +     O.SIGL_LEN * (FLOOR((T.ACT_LEN - O.LENGTHMIN) / O.SIGL_LEN))
                                                                       END
                                                        ELSE     --- 长度大于合同最小值
                                                                           --长度不在 单倍尺的公差范围
                                                                     CASE WHEN T.ACT_LEN -  (O.LENGTHMIN - O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) > O.ENDLEN_SPECSTD THEN
                                                                                                       (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN))) +   O.ENDLEN_SPECSTD
                                                                                     --长度在单倍尺的公差范围
                                                                                ELSE                 (O.LENGTHMIN -  O.SIGL_LEN * (CEIL((O.LENGTHMIN - T.ACT_LEN) / O.SIGL_LEN)))
                                                                     END
                                            END
                                 ----没单倍尺  取已经存储规则的最大值
                             ELSE
                                       GROUP_MIN
                     END
       END 
          ELSE 
          T.ACT_LEN
          END  ACT_LEN_MIN
          FROM PORT_MCH_BATCH_SAMPLE_RESULT T
          LEFT JOIN PLN_ZY_JGX_M M
            ON M.HEAT_PLAN_NO = T.HEAT_PLAN_NO
             LEFT JOIN com_base_product PR
            ON M.PRODUCCODE = PR.PRODUCCODE
             LEFT JOIN PLN_ORDER_JGX_S O
    ON M.PRO_PLAN_ID = O.PRO_PLAN_ID
   AND M.GX_PLAN_NO = O.GX_PLAN_NO
          LEFT JOIN MCH_GROUPNO G
            ON G.ORDER_NO = M.ORDER_NO || '/' || M.ORDER_SEQ
           AND T.ACT_LEN <
               NVL(DECODE(GROUP_MAX_SIGN, '<=', GROUP_MAX + 0.001, GROUP_MAX),
                   T.ACT_LEN + 0.001)
           AND T.ACT_LEN >
               NVL(DECODE(GROUP_MIN_SIGN, '>=', GROUP_MIN - 0.001, GROUP_MIN),
                   T.ACT_LEN - 0.001)
           AND ROWNUM = 1
          LEFT JOIN (SELECT ORDER_NO,
                           MAX(GROUP_MAX) MAX_LEN,
                           MIN(GROUP_MIN) MIN_LEN
                      FROM MCH_GROUPNO
                     WHERE FLAG = '1'
                     GROUP BY ORDER_NO) P
            ON P.ORDER_NO = M.ORDER_NO || '/' || M.ORDER_SEQ
         WHERE T.HEAT_PLAN_NO =?
           AND T.PHY_BATCH_NO = ?
           AND T.MAT_STATUS = '00'
           AND T.VALIDFLAG = '1'
           AND G.GROUP_NO IS NULL) T1
 GROUP BY T1.HEAT_PLAN_NO,
          T1.JUDGE_STOVE_NO,
          T1.IS_SAMPLE_PIPE,
          T1.PHY_BATCH_NO,
          T1.GROUP_NO,
          T1.OUTNUM_CUT,
          T1.TR_FLAG,
          T1.FLAG_STOVE_NO,
          T1.ACT_LEN_MAX,
          T1.ACT_LEN_MIN,
          T1.INSTORE_FLAG
       ORDER BY HEAT_PLAN_NO,
          JUDGE_STOVE_NO,
          PHY_BATCH_NO,
          INSTORE_FLAG,
          OUTNUM_CUT,
          TR_FLAG,
          GROUP_NO,
          ACT_LEN_MAX
]]>
    </query>

<query id = "FrmMchInStore.doQueryStausRack" desc = "查询指定炉批支数">
SELECT NVL(SUM(S.ACT_COUNT),'0')ACOUNT
  FROM PORT_MCH_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 S.PHY_BATCH_NO = ?
   AND S.IS_SAMPLE_PIPE = ?
</query>
<query id = "FrmMchInStore.doQueryStausRackWgt" desc = "查询指定炉批下支数重量">
<![CDATA[
SELECT NVL(SUM(ACT_WEIGHT),'0') ACT_WEIGHT
  FROM (SELECT S.ACT_WEIGHT
          FROM PORT_MCH_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 S.PHY_BATCH_NO = ?
           AND S.IS_SAMPLE_PIPE = ?
         ORDER BY S.MAT_NO ASC)
 WHERE ROWNUM <= ?
 ]]>
</query>

    <query id = "FrmMchInStore.doQueryCount" desc = "">
        <![CDATA[
SELECT COUNT(1)  COUNT
    FROM (SELECT *
    FROM PORT_MCH_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'
    AND T.VALIDFLAG = '1'
    AND DECODE(T.TR_FLAG,1,'是','否') = '#TR_FLAG#'
    AND  EXISTS(
    SELECT 1
    FROM MCH_GROUPNO T
    WHERE ORDER_NO = '#PRO_ORDER_NO#'
    AND GROUP_NO = '#BATCH_GROUD_NO#'
    AND T.ACT_LEN <
        NVL(DECODE(T.GROUP_MAX_SIGN,
    '<=',
    T.GROUP_MAX + 0.001,
    T.GROUP_MAX),
    T.ACT_LEN + 0.001)
    AND T.ACT_LEN >
    NVL(DECODE(GROUP_MIN_SIGN,
    '>=',
    T.GROUP_MIN - 0.001,
    T.GROUP_MIN),
    T.ACT_LEN - 0.001))
    ORDER BY  T.MEASURING_SEQ,T.MAT_NO ASC)
    WHERE ROWNUM <= #ACT_COUNT#
 ]]>
    </query>



<query id = "FrmMchInStore.insertMatBcM" desc = "交库">
   <![CDATA[
  DECLARE
  V_INSTOCK_SQE YDM_BC_INLIST.INSTOCK_SQE%TYPE := NULL;
  V_ICOUNT      NUMBER := 1;
  V_ICOUNT1     NUMBER := 1;
  V_ICOUNT2     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_MCH_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'
                           AND T.VALIDFLAG = '1'
                           AND DECODE(T.TR_FLAG, 1, '是', '否') = '#TR_FLAG#'
                           AND EXISTS
                         (SELECT 1
                                  FROM MCH_GROUPNO T
                                 WHERE ORDER_NO = '#PRO_ORDER_NO#'
                                   AND GROUP_NO = '#BATCH_GROUD_NO#'
                                   AND T.ACT_LEN <
                                       NVL(DECODE(T.GROUP_MAX_SIGN,
                                                  '<=',
                                                  T.GROUP_MAX + 0.001,
                                                  T.GROUP_MAX),
                                           T.ACT_LEN + 0.001)
                                   AND T.ACT_LEN >
                                       NVL(DECODE(GROUP_MIN_SIGN,
                                                  '>=',
                                                  T.GROUP_MIN - 0.001,
                                                  T.GROUP_MIN),
                                           T.ACT_LEN - 0.001))
                         ORDER BY T.MEASURING_SEQ, 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 = '#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'),
         '#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 = '#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,
       PONDER_GROSS_WT,
       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,
       FLAG_STOVE_NO_ZG,
       TARGET,
       CIC,
       HEAT_PLAN_NO_OLD,
       MEASURING_SEQ,
       ORD_PK,
       ORD_LN_PK,
       IS_DEALER,
       PIPMEMO,
       MEMO,
       length_type)
    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,
       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#',
       '#FLAG_STOVE_NO_ZG#',
       '#TARGET#',
       '#CIC#',
       '#HEAT_PLAN_NO_OLD#',
       MYROW.MEASURING_SEQ,
       '#ORD_PK#',
       '#ORD_LN_PK#',
       (SELECT DECODE(H.ORDER_TYP,
                      '120108',
                      '1',
                      '120107',
                      '2',
                      '120109',
                      '3',
                      '0')
          FROM SLM_ORDER_HEAD H
         WHERE H.ORD_PK = '#ORD_PK#'),
       '#MEMO#',
       MYROW.REMARK,
       (select decode(sign(MYROW.ACT_LEN -
                           (select max(LENGTHMAX)
                              from Pln_Zy_Jgx_M
                             where HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO)),
                      1,
                      1,
                      -1,
                      decode(sign(MYROW.ACT_LEN -
                                  (select LENGTHMIN
                                     from Pln_Zy_Jgx_M
                                    where HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO)),
                             -1,
                             2,
                             0),
                      0)
          from dual));
  
    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,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO)
      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#',
             '#ORDER_NO#',
             '#ORDER_SEQ#',
             '#ORDER_SEQ_NO#'
        FROM YDM_BC_BUTTRESS
       WHERE MAT_NO = MYROW.MAT_NO;
  
    UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T
       SET T.INSTORE_FLAG = '1'
     WHERE T.MAT_NO = MYROW.MAT_NO
       AND T.VALIDFLAG = '1';
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;
   ]]>
   </query>

    <query id = "FrmMchInStore.updateMatBcM" desc = "离线转交库">
        <![CDATA[
DECLARE
BEGIN
  UPDATE YDM_BC_BUTTRESS
     SET JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#', BATCH_NO = '#BATCH_NO#'
   WHERE MAT_NO = '#MAT_NO#';

  UPDATE MAT_BC_M
     SET PRODUCT_FLAG         = '#PRODUCT_FLAG#',
         MAT_STATUS           = '#MAT_STATUS#',
         LOT_NO               = '#LOT_NO#',
         STOVE_NO             = '#STOVE_NO#',
         JUDGE_STOVE_NO       = '#JUDGE_STOVE_NO#',
         BATCH_NO             = '#BATCH_NO#',
         SAMPLE_FLAG          = '#SAMPLE_FLAG#',
         MATERIAL_NO          = '#MATERIAL_NO#',
         MATERIAL_NAME        = '#MATERIAL_NAME#',
         PRODUCCODE           = '#PRODUCCODE#',
         PRODUCNAME           = '#PRODUCNAME#',
         STEELCODE            = '#STEELCODE#',
         STEELNAME            = '#STEELNAME#',
         GRADECODE            = '#GRADECODE#',
         GRADENAME            = '#GRADENAME#',
         SPEC_CODE            = '#SPEC_CODE#',
         SPEC_NAME            = '#SPEC_NAME#',
         MODEL_CODE           = '#MODEL_CODE#',
         MODEL_DESC           = '#MODEL_DESC#',
         STD_CODE             = '#STD_CODE#',
         STD_NAME             = '#STD_NAME#',
         STD_STYLE            = '#STD_STYLE#',
         STD_STYLE_DESC       = '#STD_STYLE_DESC#',
         PRO_ORDER_NO         = '#PRO_ORDER_NO#',
         PRO_ORDER_ID         = '#PRO_ORDER_ID#',
         PROCESS_CDOE         = '#PROCESS_CDOE#',
         PROCESS_DESC         = '#PROCESS_DESC#',
         NEXT_PROCESS_CDOE    = '#NEXT_PROCESS_CDOE#',
         NEXT_PROCESS_DESC    = '#NEXT_PROCESS_DESC#',
         PLINE_CODE           = '#PLINE_CODE#',
         PLINE_NAME           = '#PLINE_NAME#',
         MAT_ORIGIN_CODE      = '#MAT_ORIGIN_CODE#',
         MAT_ORIGIN_NAME      = '#MAT_ORIGIN_NAME#',
         ACT_DIMATER          = '#ACT_DIMATER#',
         ACT_HEIGHT           = '#ACT_HEIGHT#',
         PONDER_GROSS_WT      = '#PONDER_GROSS_WT#',
         BELONG_CODE          = '#BELONG_CODE#',
         BELONG_NAME          = '#BELONG_NAME#',
         MAT_GOWHERE_CODE     = '#MAT_GOWHERE_CODE#',
         MAT_GOWHERE_NAME     = '#MAT_GOWHERE_NAME#',
         INSTOCK_FLAG         = '0',
         INSTOCK_TIME         = sysdate,
         CREATE_NAME          = '#CREATE_NAME#',
         CREATE_TIME          = sysdate,
         BAL_YEAR_MONTH       = '#BAL_YEAR_MONTH#',
         JUDGE_STD_DES        = '#JUDGE_STD_DES#',
         QCM_STAUS            = '#QCM_STAUS#',
         HEAT_PLAN_NO         = '#HEAT_PLAN_NO#',
         GX_PLAN_NO           = '#GX_PLAN_NO#',
         CRAF_NO              = '#CRAF_NO#',
         CRAFT_SEQ            = '#CRAFT_SEQ#',
         ORD_LN_DLY_PK        = '#ORD_LN_DLY_PK#',
         ORDER_NO             = '#ORDER_NO#',
         ORDER_SEQ            = '#ORDER_SEQ#',
         ORDER_SEQ_NO         = '#ORDER_SEQ_NO#',
         FLAG_STOVE_NO_ZG     = '#FLAG_STOVE_NO_ZG#',
         TARGET               = '#TARGET#',
         CIC                  = '#CIC#',
         HEAT_PLAN_NO_OLD     = '#HEAT_PLAN_NO_OLD#',
         ORD_PK               = '#ORD_PK#',
         ORD_LN_PK            = '#ORD_LN_PK#',
         IS_DEALER           =
         (SELECT DECODE(H.ORDER_TYP, '120108', '1','120107','2', '0')
            FROM SLM_ORDER_HEAD H
           WHERE H.ORD_PK = '#ORD_PK#'),
         ACT_WEIGHT           = '#ACT_WEIGHT#',
         ACT_THEORY_WEIGHT    = '#ACT_THEORY_WEIGHT#',
         HEAT_PLAN_NO_NEXT    = '#HEAT_PLAN_NO_NEXT#',
         OFFLINE_DOC          = '',
         SCRAP_TYPE           = '',
         BELONG_CODE_RESPONSE = '',
         BELONG_NAME_RESPONSE = '',
         CUT_NUM              = '',
         ZG_STOVE_SQE         = '',
         MEMO =''
   WHERE MAT_NO = '#MAT_NO#';

  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,
     ORDER_NO,
     ORDER_SEQ,
     DELIVERY_NO)
    SELECT (SELECT '#INSTOCK_DOC#' || LPAD(NVL(MAX(TO_NUMBER(SUBSTR(INSTOCK_SQE,
                                                                    LENGTH(INSTOCK_SQE) - 3))),
                                               0) + 1,
                                           4,
                                           '0') INSTOCK_SQE
              FROM YDM_BC_INLIST
             WHERE INSTOCK_SQE LIKE '#INSTOCK_DOC#' || '____'),
           '#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_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#',
           '#ORDER_NO#',
           '#ORDER_SEQ#',
           '#ORDER_SEQ_NO#'
      FROM YDM_BC_BUTTRESS
     WHERE MAT_NO = '#MAT_NO#';

END;
   ]]>
    </query>

    <query id = "FrmMchInStore.insertVrpComInfo" desc = "插入公共信息表">
        DECLARE
        V_VRP_STATION_CODE MCH_COM_INFO.PLINE_CODE%TYPE := NULL;
        V_RESULT_NO        MCH_COM_INFO.RESULT_NO%TYPE := NULL;
        BEGIN
        V_VRP_STATION_CODE := '701311';
        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 MCH_COM_INFO T
        WHERE TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE);

        INSERT INTO MCH_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,
        INWL_ID,
        INWL_DESC,
        PRO_NUM,
        PRO_WT,
        STATION_STATUS,
        RRO_TIME,
        RRO_TIME_NU,
        COL_OPERATOR,
        PRO_SHIFT,
        PRO_GROUP,
        CREATE_TIME,
        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#',
        '#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#',
        '#INWL_ID#',
        '#INWL_DESC#',
        '#PRO_NUM#',
        '#PRO_WT#',
        '#STATION_STATUS#',
        TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#RRO_TIME_NU#',
        '#COL_OPERATOR#',
        '#PRO_SHIFT#',
        '#PRO_GROUP#',
        TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#PRO_YEAR_MONTH_DAY#',
        '#BAL_YEAR_MONTH#',
        '#INSTOCK_DOC#');
        END;





    </query>

    <query id = "FrmMchInStore.insertVrpComInfo2" desc = "插入公共信息表">
        DECLARE
        V_VRP_STATION_CODE MCH_COM_INFO.Station_Code%TYPE := NULL;
        V_RESULT_NO        MCH_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,
        SUM(ACT_LEN) 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_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 := '701311';

        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 MCH_COM_INFO T
        WHERE RESULT_NO LIKE  MYROW.PLINE_CODE  || V_VRP_STATION_CODE || TO_CHAR(SYSDATE, 'YYMMDD') || '______';

        INSERT INTO MCH_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,
        INWL_ID,
        INWL_DESC,
        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_HEIGHT,
        MYROW.ACT_LEN_MIN,
        MYROW.ACT_LEN_MAX,
        '',
        '',
        '',
        '',
        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 = "FrmMchInStore.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 = 'G') 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_MCH_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;

    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;
  INSERT INTO MCH_COM_INFO
    (RESULT_NO,
     HEAT_PLAN_NO,
     ZY_BATCH_ID,
     PROD_INDEX,
     PRO_PLAN_ID,
     GX_PLAN_NO,
     ORDER_SOURCE,
     ORDER_NO,
     ORDER_SEQ,
     REQ_BL_ID,
     PLINE_CODE,
     PLINE_NAME,
     STATION_CODE,
     STATION_DESC,
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     PRODUCCODE,
     PRODUCNAME,
     GRADECODE,
     GRADENAME,
     STEELCODE,
     STEELNAME,
     MODEL_CODE,
     MODEL_DESC,
     STD_CODE,
     STD_NAME,
     STD_STYLE,
     STD_STYLE_DESC,
     SPEC_CODE,
     SPEC_NAME,
     DIMATER,
     HEIGHT,
     LEN,
     LEN_MIN,
     LEN_MAX,
     PLN_LEN,
     PLN_LEN_MIN,
     PLN_LEN_MAX,
     OUTNUM_CUT,
     ACT_SPEC_CODE,
     ACT_SPEC_NAME,
     ACT_DIMATER,
     ACT_HEIGHT,
     ACT_LEN,
     ACT_LEN_MIN,
     ACT_LEN_MAX,
     LEN_CUT_HEAD,
     LEN_CUT_END,
     ACT_MATERIAL_NO,
     ACT_MATERIAL_NAME,
     INWL_ID,
     INWL_DESC,
     BELONG_CODE,
     BELONG_NAME,
     MONITOR_POINT,
     IF_MONITOR_MCH,
     MONITORDEMAND,
     PRDCR_NO,
     PRODUCER,
     PRODUCER_TIME,
     STATION_ROAD,
     CRAFT_FILE_NO,
     CRAFT_FILE_MAN,
     CRAFT_SEQ,
     CRAFT_NO_LV2,
     CRAFT_LV2_MAN,
     INP_NUM,
     INP_WT,
     PRO_NUM,
     PRO_WT,
     FAIL_NUM,
     FAIL_WT,
     OFFLINE_NUM,
     OFFLINE_WT,
     RE_NUM,
     RE_WT,
     PONDER_GROSS_WT,
     INSTOCK_DOC,
     STATION_STATUS,
     RRO_TIME,
     RRO_TIME_NU,
     PRO_SHIFT,
     PRO_GROUP,
     PRO_YEAR_MONTH_DAY,
     BAL_YEAR_MONTH,
     VALIDFLAG,
     CREATET_USER,
     CREATE_TIME,
     UPDATE_TIME,
     UPDATE_NAME,
     COL_OPERATOR,
     BESIDE_TIME)
    SELECT (SELECT T.RESULT_NO || LPAD(NVL(MAX(TO_NUMBER(SUBSTR(RESULT_NO,
                                                                LENGTH(RESULT_NO) - 1))),
                                           0) + 1,
                                       2,
                                       '0') RESULT_NO
              FROM MCH_COM_INFO
             WHERE RESULT_NO LIKE T.RESULT_NO || '__'),
           HEAT_PLAN_NO,
           ZY_BATCH_ID,
           PROD_INDEX,
           PRO_PLAN_ID,
           GX_PLAN_NO,
           ORDER_SOURCE,
           ORDER_NO,
           ORDER_SEQ,
           REQ_BL_ID,
           PLINE_CODE,
           PLINE_NAME,
           STATION_CODE,
           STATION_DESC,
           JUDGE_STOVE_NO,
           BATCH_NO,
           BATCH_GROUD_NO,
           PRODUCCODE,
           PRODUCNAME,
           GRADECODE,
           GRADENAME,
           STEELCODE,
           STEELNAME,
           MODEL_CODE,
           MODEL_DESC,
           STD_CODE,
           STD_NAME,
           STD_STYLE,
           STD_STYLE_DESC,
           SPEC_CODE,
           SPEC_NAME,
           DIMATER,
           HEIGHT,
           LEN,
           LEN_MIN,
           LEN_MAX,
           PLN_LEN,
           PLN_LEN_MIN,
           PLN_LEN_MAX,
           OUTNUM_CUT,
           ACT_SPEC_CODE,
           ACT_SPEC_NAME,
           ACT_DIMATER,
           ACT_HEIGHT,
           ACT_LEN,
           ACT_LEN_MIN,
           ACT_LEN_MAX,
           LEN_CUT_HEAD,
           LEN_CUT_END,
           ACT_MATERIAL_NO,
           ACT_MATERIAL_NAME,
           INWL_ID,
           INWL_DESC,
           BELONG_CODE,
           BELONG_NAME,
           MONITOR_POINT,
           IF_MONITOR_MCH,
           MONITORDEMAND,
           PRDCR_NO,
           PRODUCER,
           PRODUCER_TIME,
           STATION_ROAD,
           CRAFT_FILE_NO,
           CRAFT_FILE_MAN,
           CRAFT_SEQ,
           CRAFT_NO_LV2,
           CRAFT_LV2_MAN,
           INP_NUM,
           INP_WT,
           0- T_COUNT,
           0 - T_WT,
           FAIL_NUM,
           FAIL_WT,
           OFFLINE_NUM,
           OFFLINE_WT,
           RE_NUM,
           RE_WT,
           PONDER_GROSS_WT,
           INSTOCK_DOC,
           STATION_STATUS,
           RRO_TIME,
           RRO_TIME_NU,
           PRO_SHIFT,
           PRO_GROUP,
           PRO_YEAR_MONTH_DAY,
           BAL_YEAR_MONTH,
           VALIDFLAG,
           CREATET_USER,
           CREATE_TIME,
           UPDATE_TIME,
           UPDATE_NAME,
           COL_OPERATOR,
           BESIDE_TIME
      FROM MCH_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 = "FrmMchInStore.selectLxCount" desc= "查询待处理支数">
   SELECT COUNT(1) ACOUNT
  FROM PORT_MCH_BATCH_SAMPLE_RESULT T
 WHERE T.MAT_STATUS IN ('00', '20')
   AND T.INSTORE_FLAG = '0'
   AND T.VALIDFLAG = '1'
   AND T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   </query>
   <query id = "FrmMchInStore.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.BATCH_NO = '#BATCH_NO#'
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE = 'G'
   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.BATCH_NO = '#BATCH_NO#'
   AND T.QCM_STAUS = '00'
   AND T.PROCESS_CDOE = 'G')
</query>
<query id = "FrmMchInStore.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_JGX_C T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
</query>
<query id = "FrmMchInStore.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 MCH_OFFLINE_RESULT T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
</query>
<query id = "FrmMchInStore.QueryVrpPortFailPiece" desc = "查询各实绩废品和">
select NVL(SUM(T.ACT_COUNT), 0) ACT_COUNT
  from PORT_MCH_BATCH_SAMPLE_RESULT t
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.MAT_STATUS = '10'
</query>
   <query id = "FrmMchInStore.selectNodeFlag" desc = "查询结炉标识">
   SELECT T.BESIDE_STATUS
  FROM PLN_ZY_JGX_C T
 WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
       AND T.BATCH_NO = '#BATCH_NO#'
   </query>
      <query id = "FrmMchInStore.selectNode" desc = "查询是否结炉">

          SELECT STATION_STATUS FROM MCH_COM_INFO WHERE  JUDGE_STOVE_NO='#JUDGE_STOVE_NO#' AND BATCH_NO='#BATCH_NO#'  AND STATION_CODE ='701311' AND INSTOCK_DOC='#INSTOCK_DOC#'
   </query>
   <query id = "FrmMchInStore.selectHeatPlanNo" desc = "查询炉计划">
SELECT T.*
  FROM PLN_ZY_JGX_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 = "FrmMchInStore.UpdateNodeFlag" desc = "结炉">
   <![CDATA[
   DECLARE
  V_COUNT PLN_ZY_JGX_C.REAL_INDOUBLE_NUM%type := null;
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,
                       S.PHY_BATCH_NO BATCH_NO
                  FROM PORT_MCH_BATCH_SAMPLE_RESULT S
                 WHERE S.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
                   AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND S.PHY_BATCH_NO = '#BATCH_NO#'
                   AND S.MAT_STATUS = '00'
                   AND S.VALIDFLAG = '1'
                 GROUP BY S.HEAT_PLAN_NO, S.HEAT_PLAN_SQE, S.PHY_BATCH_NO) LOOP
    UPDATE pln_zy_jgx_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
       AND S.BATCH_NO = MYROW.BATCH_NO;


  UPDATE pln_zy_jgx_c S
       SET  S.BESIDE_STATUS      = '11'
     WHERE S.HEAT_PLAN_NO = MYROW.HEAT_PLAN_NO
       AND S.BATCH_NO = MYROW.BATCH_NO;

           UPDATE MCH_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.BATCH_NO = '#BATCH_NO#'
       AND T.STATION_CODE !='701305'
       AND T.STATION_CODE != '701313' ;
  END LOOP;



  SELECT COUNT(1)
    INTO V_COUNT
    FROM PLN_ZY_JGX_C T
   WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND (T.BESIDE_STATUS <> '11' OR T.BESIDE_STATUS IS  NULL);
  IF (V_COUNT = 0) THEN
    UPDATE PLN_ZY_JGX_M T
       SET T.PLANSTATUS = '30'
     WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
       AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';
  END IF;
END;
]]>
   </query>
   <query id = "FrmMchInStore.CancelupdateNodeFlag" desc = "结炉回退">
DECLARE
BEGIN
  UPDATE PLN_ZY_JGX_C T
     SET T.REAL_OUTDOUBLE_NUM = '',
         T.REAL_OUTDOUBLE_WT  = '',
         T.BESIDE_STATUS      = '00'
   WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND T.BATCH_NO = '#BATCH_NO#';
  UPDATE PLN_ZY_JGX_M T
     SET T.PLANSTATUS = '20'
   WHERE T.HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
     AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#';

  UPDATE MCH_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.BATCH_NO = '#BATCH_NO#'
       AND T.STATION_CODE !='701305'
       AND T.STATION_CODE != '701313'
       AND T.STATION_CODE != '701301';
END;
</query>

<query id = "FrmMchInStore.selectQcmApp" desc = "查询是否送判">
    SELECT COUNT(1) ACOUNT
    FROM MAT_BC_M T
    WHERE HEAT_PLAN_NO = '#HEAT_PLAN_NO#'
    AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
    AND T.BATCH_NO = '#BATCH_NO#'
    AND JUGDE_APPLY_CODE IS NULL

   </query>

    <query id = "FrmMchInStore.selectQcmApp2" desc = "查询是否送判">
        SELECT COUNT(1) ACOUNT
        FROM QCM_ZG_JUGDE_APPLY T
        WHERE T.PRO_ORDER_ID = '#PRO_PLAN_ID#'
        AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
        AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
        AND T.PLINE_CODE = '#PLINE_CODE#'
        AND T.BATCH_NO = '#BATCH_NO#'
        AND T.IS_FLAG = '0'
        AND T.IS_ALL_SCRAP !=2

    </query>
   
   <query id = "FrmVrpInStore.updateMchGroupNo" desc = "更新组号生成规则">
   UPDATE MCH_GROUPNO T
       SET (OFFLINE_NUM, OFFLINE_MAX, OFFLINE_MIN) =
       (SELECT SUM(OFFLINE_NUM),
       MAX(OFFLINE_MAX) OFFLINE_MAX,
       MIN(OFFLINE_MIN) OFFLINE_MIN
       FROM (SELECT PRO_ORDER_NO,
       BATCH_GROUD_NO,
       NVL(COUNT(1), 0) OFFLINE_NUM,
       MAX(ACT_LEN) OFFLINE_MAX,
       MIN(ACT_LEN) OFFLINE_MIN
       FROM MAT_BC_M
       WHERE QCM_STAUS = '00'
       AND PROCESS_CDOE = 'G'
       GROUP BY PRO_ORDER_NO, BATCH_GROUD_NO
       UNION ALL
       SELECT PRO_ORDER_NO,
       BATCH_GROUD_NO,
       NVL(COUNT(1), 0) OFFLINE_NUM,
       MAX(ACT_LEN) OFFLINE_MAX,
       MIN(ACT_LEN) OFFLINE_MIN
       FROM mat_bc_backup
       WHERE QCM_STAUS = '00'
       AND PROCESS_CDOE = 'G'
       GROUP BY PRO_ORDER_NO, BATCH_GROUD_NO)
       WHERE PRO_ORDER_NO = T.ORDER_NO
       AND BATCH_GROUD_NO = T.GROUP_NO)
       WHERE T.ORDER_NO = '#ORDER_NO#' || '/' || '#ORDER_SEQ#'
   </query>



    <query id = "FrmMchInStore.GetGroupByMaxMin" desc = "根据上下线找组号">
        SELECT GROUP_NO
        FROM MCH_GROUPNO
        WHERE ORDER_NO = ?
        AND GROUP_MIN = ?
        AND GROUP_MAX = ?
    </query>

    <query id = "FrmMchInStore.GetMaxGroup" desc = "找最大组号">
        SELECT LPAD((TO_NUMBER(NVL(MAX(GROUP_NO), '0')) + 1), 3, 0) GROUP_NO
        FROM MCH_GROUPNO
        WHERE ORDER_NO =?
    </query>

    <query id = "FrmMchInStore.getOrderInfo" desc = "找合同信息">
        SELECT T.*  FROM PLN_SALEORD T WHERE T.ord_ln_dly_pk=?
    </query>

    <query id = "FrmMchInStore.AddGroupRule" desc = "增加组号规则">
        INSERT INTO MCH_GROUPNO T
        (ORDER_NO, GROUP_MAX, GROUP_MIN, GROUP_NO, FLAG, GROUP_MAX_SIGN,GROUP_MIN_SIGN)
        VALUES
        (?, ?, ?, ?, '0',?,?)
    </query>



</queryMap>