<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "外购管手工入库">
<query id = "FrmSemiFinish.doQueryPlnOrderZg" desc = "查询外购订单信息">
 
SELECT T.WHOLE_BACKLOG_DESC,
       T.PRO_ORDER_NO,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.DECISION,
       T.PLAN_GROUP_ID,
       T.ORDER_SOURCE,
       T.ORD_LN_DLY_PK,
       T.PLN_DIVIDE_ID,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.REQ_BL_ID,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.LENGTHDISC,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.LEN_ROLL_MAX,
       T.LEN_ROLL_MIN,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.AIMLENGTH,
       T.DIAMETER_GP,
       T.LEN_GP_SINGLE,
       T.ROLL_LENGTH,
       T.LEN_CUTHEAD,
       T.LEN_CUTEND,
       T.OUTNUM_CUT,
       T.DIAMETER_MANDREL,
       T.PASS_CODE,
       T.PASS_NAME,
       T.IN_WEIGHT_S,
       T.IN_NUM_S,
       T.WEIGTH_S,
       T.NUM_S,
       T.ADD_WT_IN,
       T.ADD_NUM_IN,
       T.MATCH_WT_IN,
       T.MATCH_NUM_IN,
       T.ISENDGX,
       T.IF_MONITOR_ZG,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.CRAFT_FILE_NO,
       T.CRAFT_FILE_MAN,
       T.CRAFT_SEQ,
       T.STATION_ROAD,
       T.PRO_MONTH,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.WIC,
       T.GIC,
       T.GX_PRO_SEQ,
       T.PLAN_USETIME,
       TO_CHAR(T.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
       TO_CHAR(T.PLAN_TIME_E, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E,
       T.BATCHED_WT,
       T.BATCHED_NUM,
       T.FINISHWEIGHT,
       T.FINISHNUM,
       DECODE(T.EXE_STATUS,'0','计划','1','生产中','2','生产完成','3','关闭')EXE_STATUS,
       T.IS_REPAIR_PLN,
       T.REPAIR_TYPE,
       T.IS_PLAN_OK,
       T.GPREQ_IF_OK,
       T.GPREQ_ID,
       T.ZY_BATCH_ID,
       T.CIC_GROUP_GP,
       T.PIC_GROUP_GP,
       T.SIC_GROUP_GP,
       T.DIC_GROUP_GP,
       T.WIC_GROUP_GP,
       T.GIC_GROUP_GP,
       T.CIC_GP,
       T.PIC_GP,
       T.SIC_GP,
       T.DIC_GP,
       T.WIC_GP,
       T.GIC_GP,
       T.IF_EXPORT,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.MEMO,
       TO_CHAR(T.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
       T.ISSUED_MAN,
       TO_CHAR(T.LAST_UNDOWN_TIME, 'YYYY-MM-DD HH24:MI:SS') LAST_UNDOWN_TIME,
       T.LAST_UNDOWN_MAN,
       T.VERSION_NO,
       T.PROCESSING_COST,
       T.TOTAL_COST,
       T.IF_STOVE_ISSUED,
       TO_CHAR(T.STOVE_ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') STOVE_ISSUED_TIME,
       T.STOVE_ISSUED_MAN,
       T.IS_ONLOAD_LINE,
       S.STD_CODE,
       S.STD_NAME,
       S.MATERIAL_NO,
       S.MATERIAL_DESC,
       S.PRODUCCODE,
       S.PRODUCNAME,
       S.STEELCODE,
       S.STEELNAME,
       S.SPEC_CODE,
       S.SPEC_NAME,
       S.MODEL_CODE,
       S.MODEL_DESC,
       S.STD_STYLE_DESC
 FROM PLN_ORDER_ZG_S T,PLN_SALEORD S WHERE T.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
 AND T.EXE_STATUS IN ('0','1')
 AND T.PLINE_CODE IN ('C065','C066','C098','C099')
</query>
<!-- SELECT T1.*,T2.* FROM (
SELECT 
       T.PRO_ORDER_NO,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.PLAN_GROUP_ID,
       T.ORDER_SOURCE,
       T.ORD_LN_DLY_PK,
       T.PLN_DIVIDE_ID,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.REQ_BL_ID,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.GRADECODE,
       T.GRADENAME,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.LENGTHDISC,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.LEN_ROLL_MAX,
       T.LEN_ROLL_MIN,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.AIMLENGTH,
       T.DIAMETER_GP,
       T.LEN_GP_SINGLE,
       T.ROLL_LENGTH,
       T.LEN_CUTHEAD,
       T.LEN_CUTEND,
       T.OUTNUM_CUT,
       T.DIAMETER_MANDREL,
       T.PASS_CODE,
       T.PASS_NAME,
       T.IN_WEIGHT_S,
       T.IN_NUM_S,
       T.WEIGTH_S,
       T.NUM_S,
       T.ADD_WT_IN,
       T.ADD_NUM_IN,
       T.MATCH_WT_IN,
       T.MATCH_NUM_IN,
       T.ISENDGX,
       T.IF_MONITOR_ZG,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.CRAFT_FILE_NO,
       T.CRAFT_FILE_MAN,
       T.CRAFT_SEQ,
       T.STATION_ROAD,
       T.PRO_MONTH,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.WIC,
       T.GIC,
       T.GX_PRO_SEQ,
       T.PLAN_USETIME,
       TO_CHAR(T.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
       TO_CHAR(T.PLAN_TIME_E, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E,
       T.BATCHED_WT,
       T.BATCHED_NUM,
       T.FINISHWEIGHT,
       T.FINISHNUM,
       DECODE(T.EXE_STATUS,'0','计划','1','生产中','2','生产完成','3','关闭')EXE_STATUS,
       T.IS_REPAIR_PLN,
       T.REPAIR_TYPE,
       T.IS_PLAN_OK,
       T.GPREQ_IF_OK,
       T.GPREQ_ID,
       T.ZY_BATCH_ID,
       T.CIC_GROUP_GP,
       T.PIC_GROUP_GP,
       T.SIC_GROUP_GP,
       T.DIC_GROUP_GP,
       T.WIC_GROUP_GP,
       T.GIC_GROUP_GP,
       T.CIC_GP,
       T.PIC_GP,
       T.SIC_GP,
       T.DIC_GP,
       T.WIC_GP,
       T.GIC_GP,
       T.IF_EXPORT,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.MEMO,
       TO_CHAR(T.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
       T.ISSUED_MAN,
       TO_CHAR(T.LAST_UNDOWN_TIME, 'YYYY-MM-DD HH24:MI:SS') LAST_UNDOWN_TIME,
       T.LAST_UNDOWN_MAN,
       T.VERSION_NO,
       T.PROCESSING_COST,
       T.TOTAL_COST,
       T.IF_STOVE_ISSUED,
       TO_CHAR(T.STOVE_ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') STOVE_ISSUED_TIME,
       T.STOVE_ISSUED_MAN,
       T.IS_ONLOAD_LINE,
       S.ORD_PK,
       S.ORD_LN_PK
 FROM PLN_ORDER_ZG_S T LEFT JOIN SLM_ORDER_LINE_DELIVERY S ON T.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
 WHERE T.EXE_STATUS IN ('0','1')
 AND T.PLINE_CODE IN ('C065','C066'))T1
 LEFT JOIN SLM_ORDER_LINE T2 ON T1.ORD_LN_PK = T2.ORD_LN_PK -->
<query id = "FrmSemiFinish.doQueryInListWg" desc= "查询外购管手工入库信息">
SELECT T.INSTOCK_DOC,
       T.JUDGE_STOVE_NO,
       T.BATCH_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,
       TO_CHAR(T.ACT_LEN_MIN, 'FM999990.00') || '-' ||
       TO_CHAR(T.ACT_LEN_MAX, 'FM999990.00') AS LEN,
       SUM(T.ACT_COUNT) AS ACT_COUNT,
       TO_CHAR(SUM(T.ACT_WEIGHT), 'FM999999990.000') AS ACT_WEIGHT,
       SUM(NVL(T.ACT_LEN, 0)) AS ACT_LEN,
       T.BELONG_CODE,
       T.BELONG_NAME,
       S.STORAGE_NAME AS 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,
       DECODE(T.PRODUCT_FLAG,
              '801401',
              '在制品',
              '801402',
              '成品',
              '801403',
              '商品') PRODUCT_FLAG,
       T.PIPMEMO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NAME,
       T.LOT_NO,
       T.PRO_ORDER_NO,
       T.MAT_STATUS,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.FLAG_STOVE_NO_ZG
  FROM YDM_BC_INLIST T
  LEFT JOIN YDM_BS_STORAGE S
    ON T.STORAGE_NO = S.STORAGE_NO
 WHERE T.INSTOCK_TYPE_CODE = '800701'
   AND T.HAND_FLAG = '1'
</query>
<query id = "FrmSemiFinish.SelectMaxInDoc" desc = "查询最大入库单号">
SELECT 'IA'||'WG'||TO_CHAR(SYSDATE,'YYMMDD')||LPAD(NVL(MAX(SUBSTR(T.INSTOCK_DOC, LENGTH(T.INSTOCK_DOC) - 4)), 0)+1,5,0) INSTOCK_DOC FROM YDM_BC_INLIST T
    WHERE 
    TRUNC(T.CREATE_TIME) = TRUNC(SYSDATE)
    AND T.INSTOCK_TYPE_CODE  = '800701'
    --AND T.BELONG_CODE = '002001001'
</query>
<query id = "FrmSemiFinish.SelectMaxresultNo" desc = "查询最大实绩编号">
SELECT 'WG' || TO_CHAR(SYSDATE, 'YYMMDD') ||
       LPAD(NVL(MAX(SUBSTR(T.RESULT_NO, LENGTH(T.RESULT_NO) - 2)), 0) + 1,
            4,
            0) RESULT_NO
  FROM MIL_INSTORE_RESULT T
 WHERE TRUNC(T.START_TIME) = TRUNC(SYSDATE)
   AND T.PLINE_CODE IN('C065','C066','C098','C099')
</query>
<query id = "FrmSemiFinish.addMatZcM" desc = "插入材料表">
INSERT INTO MAT_BC_M
  (STD_CODE,
   STD_NAME,
   STD_STYLE,
   STD_STYLE_DESC,
   PRO_ORDER_NO,
   PRO_ORDER_ID,
   ORDER_NO,
   ORDER_SEQ,
   ORDER_SEQ_NO,
   CRAF_NO,
   CRAFT_SEQ,
   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,
   MAT_NO,
   PRODUCT_FLAG,
   MAT_STATUS,
   LOT_NO,
   STOVE_NO,
   JUDGE_STOVE_NO,
   BATCH_NO,
   BATCH_GROUD_NO,
   SAMPLE_FLAG,
   MATERIAL_NO,
   MATERIAL_NAME,
   INPUT_MATERIAL_NAME,
   INPUT_MATERIAL_NO,
   PRODUCCODE,
   PRODUCNAME,
   STEELCODE,
   STEELNAME,
   GRADECODE,
   GRADENAME,
   SPEC_CODE,
   SPEC_NAME,
   MODEL_CODE,
   MODEL_DESC,
   ORD_PK,
   ORD_LN_PK,
   ORD_LN_DLY_PK,
   BAR_CODE,
   MEMO,
   PIPMEMO,
   CREATE_NAME,
   CREATE_TIME,
   BAL_YEAR_MONTH,
   SOURE_CODE,
   SOURE_NAME,
   QCM_STAUS,
   TARGET,
   GX_PLAN_NO,
   FLAG_STOVE_NO_ZG,
   CIC,
   JUDGE_STD_NAME,
   JUDGE_STD_DES
   )
VALUES
  ('#STD_CODE#',
   '#STD_NAME#',
   '#STD_STYLE#',
   '#STD_STYLE_DESC#',
   '#PRO_ORDER_NO#',
   '#PRO_ORDER_ID#',
   '#ORDER_NO#',
   '#ORDER_SEQ#',
   '#DELIVERY_NO#',
   '#CRAFT_FILE_NO#',
   '#CRAFT_SEQ#',
   'D',
   '轧制',
   '#NEXT_PROCESS_CDOE#',
   '#NEXT_PROCESS_NAME#',
   '#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#',
   '#STORAGE_NO#',
   '#STORAGE_NAME#',
   TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
   '#MAT_NO#',
   '#PRODUCT_FLAG#',
   '#MAT_STATUS#',
   '#LOT_NO#',
   '#STOVE_NO#',
   '#JUDGE_STOVE_NO#',
   '#BATCH_NO#',
   '#BATCH_GROUD_NO#',
   '',
   '#MATERIAL_NO#',
   '#MATERIAL_NAME#',
   '',
   '',
   '#PRODUCCODE#',
   '#PRODUCNAME#',
   '#STEELCODE#',
   '#STEELNAME#',
   '#GRADECODE#',
   '#GRADENAME#',
   '#SPEC_CODE#',
   '#SPEC_NAME#',
   '#MODEL_CODE#',
   '#MODEL_DESC#',
   '#ORD_PK#',
   '#ORD_LN_PK#',
   '#ORD_LN_DLY_PK#',
   '',
   '#MEMO#',
   '#MEMO#',
   '#CREATE_NAME#',
   TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
   '#BAL_YEAR_MONTH#',
   '#SOURE_CODE#',
   '#SOURE_NAME#',
   '00',
   '#TARGET#',
   '#GX_PLAN_NO#',
   '#FLAG_STOVE_NO_ZG#',
   '#CIC#',
   '#JUDGE_STD_NAME#',
   '#JUDGE_STD_DES#')
</query>
<query id = "FrmSemiFinish.addYdmZcButtress" desc = "插入位置表">
<![CDATA[
	      INSERT INTO YDM_BC_BUTTRESS
  (
   MAT_NO,
   JUDGE_STOVE_NO,
   BATCH_NO,
   BATCH_GROUD_NO,
   STORAGE_NO,
   LOCATION_NO,
   STORAGE_ATTR,
   STORAGE_ATTR_NAME,
   STORAGE_TYPE_NO,
   STORAGE_TYPE_NAME,
   MEMO,
   CREATE_NAME,
   CREATE_TIME)
VALUES
  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  SYSDATE)
  ]]>
</query>
<query id = "FrmSemiFinish.addYdmZcInlist" desc = "插入入库表">
<![CDATA[
	   INSERT INTO YDM_BC_INLIST
  (ORD_PK,
   ORD_LN_PK,
   ORD_LN_DLY_PK,
   DEPARTMENT_CODE,
   DEPARTMENT_DESC,
   INSTOCK_SQE,
   INSTOCK_DOC,
   INSTOCK_TYPE_CODE,
   INSTOCK_TYPE_NAME,
   INSTOCK_BAR_CODE,
   ICCAR_NO,
   VEHICLE_NO,
   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,
   LOC_NO,
   STORAGE_ATTR,
   STORAGE_ATTR_NAME,
   STORAGE_TYPE_NO,
   STORAGE_TYPE_NAME,
   MANAGEMENT_NO,
   MANAGEMENT_NAME,
   RPO_TIME,
   PRO_BC,
   PRO_BZ,
   INSTOCK_TIME,
   IN_BC,
   IN_BZ,
   BAR_CODE,
   HAND_FLAG,
   MEMO,
   VALIDFLAG,
   CREATE_NAME,
   CREATE_TIME,
   UPDATE_NAME,
   UPDATE_TIME,
   DELETE_NAME,
   DELETE_TIME,
   BAL_YEAR_MONTH,
   SOURE_CODE,
   SOURE_NAME,
   QCM_STAUS,
   IN_TIME_F,
   PRODUCT_FLAG,
   MAT_STATUS,
   ORDER_NO,
   ORDER_SEQ,
   DELIVERY_NO,
   PRO_PLAN_ID,
   GX_PLAN_NO,
   FLAG_STOVE_NO_ZG,
   PROCESS_CDOE,
   PROCESS_DESC,
   PIPMEMO)
VALUES
  ('#ORD_PK#',
   '#ORD_LN_PK#',
   '#ORD_LN_DLY_PK#',
   '',
   '',
   '#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#',
   '',
   '',
   '#STORAGE_ATTR#',
   '#STORAGE_ATTR_NAME#',
   '#STORAGE_TYPE_NO#',
   '#STORAGE_TYPE_NAME#',
   '#MANAGEMENT_NO#',
   '#MANAGEMENT_NAME#',
   NULL,
   '',
   '',
   SYSDATE,
   '',
   '',
   '',
   '1',
   '#MEMO#',
   '1',
   '#CREATE_NAME#',
   SYSDATE,
   '',
   NULL,
   '',
   NULL,
   '#BAL_YEAR_MONTH#',
   '#SOURE_CODE#',
   '#SOURE_NAME#',
   '00',
   SYSDATE,
   '#PRODUCT_FLAG#',
   '#MAT_STATUS#',
   '#ORDER_NO#',
   '#ORDER_SEQ#',
   '#DELIVERY_NO#',
   '#PRO_PLAN_ID#',
   '#GX_PLAN_NO#',
   '#FLAG_STOVE_NO_ZG#',
   'D',
   '轧制',
   '#MEMO#')
		]]>
</query>

<query id = "FrmSemiFinish.addMilInStore" desc = "插入下线实绩表">
INSERT INTO MIL_INSTORE_RESULT
      (RESULT_NO,
       JUDGE_STOVE_NO,
       LOT_NO,
       PLINE_CODE,
       TYPE,
       QUALIFIED_NUM,
       QUALIFIED_TONS,
       START_TIME,
       END_TIME,
       PRO_PLAN_ID,
       GX_PLAN_NO,
       NODE_FUR_FLAG)
    VALUES
      ('#RESULT_NO#',
       '#JUDGE_STOVE_NO#',
       '#LOT_NO#',
       '#PLINE_CODE#',
       '#GRADENAME#',
       '#ACT_COUNT#',
       '#ACT_WEIGHT#',
       SYSDATE,
       SYSDATE,
       '#PRO_PLAN_ID#',
       '#GX_PLAN_NO#',
       '1')
</query>
<query id = "FrmSemiFinish.updatePlanOrderZgS" desc = "回写排产支吨">
UPDATE PLN_ORDER_ZG_S T
   SET T.FINISHNUM = TO_NUMBER(NVL(T.FINISHNUM,0))+TO_NUMBER('#FINISHNUM#'), T.FINISHWEIGHT = TO_NUMBER(NVL(T.FINISHWEIGHT,0))+TO_NUMBER('#FINISHWEIGHT#')
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
</query>
<query id = "FrmSemiFinish.doCancelInList" desc = "撤销入库">
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM MAT_BC_M T, YDM_BC_BUTTRESS S
                 WHERE T.MAT_NO = S.MAT_NO
                   AND T.BELONG_CODE = '#BELONG_CODE#'
                   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                   AND T.BATCH_NO = '#BATCH_NO#'
                   AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
                 ORDER BY T.MAT_NO DESC) LOOP
    DELETE FROM YDM_BC_BUTTRESS S WHERE S.MAT_NO = MYROW.MAT_NO;
    DELETE FROM MAT_BC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  DELETE FROM YDM_BC_INLIST S
   WHERE S.INSTOCK_DOC = '#INSTOCK_DOC#'
     AND S.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
     AND S.BATCH_NO = '#BATCH_NO#'
     AND S.BATCH_GROUD_NO = '#BATCH_GROUD_NO#';
  DELETE FROM MIL_INSTORE_RESULT T WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#';
  UPDATE PLN_ORDER_ZG_S T
   SET T.FINISHNUM    = TO_NUMBER(NVL(T.FINISHNUM,0)) - TO_NUMBER('#ACT_COUNT#'),
       T.FINISHWEIGHT = TO_NUMBER(NVL(T.FINISHWEIGHT,0)) -
                        TO_NUMBER('#ACT_WEIGHT#')
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#';
END;
</query>
<query id = "FrmSemiFinish.SelectMatZcCount" desc = "查询库存支数">
SELECT COUNT(1)ACT_COUNT
    FROM MAT_BC_M T, YDM_BC_BUTTRESS S
   WHERE T.MAT_NO = S.MAT_NO
     AND T.JUDGE_STOVE_NO = ?
     AND T.BATCH_NO = ?
     AND T.BATCH_GROUD_NO = ?
</query>
<query id = "FrmSemiFinish.SelectApplyMatZcCount" desc = "查询库存支数">
SELECT COUNT(1)APPLY_ACT_COUNT
    FROM MAT_BC_M T
   WHERE T.BELONG_CODE = '002001001'
     AND T.JUDGE_STOVE_NO = ?
     AND T.BATCH_NO = ?
     AND T.BATCH_GROUD_NO = ?
     AND T.JUGDE_APPLY_CODE IS NOT NULL
</query>
<query id = "FrmSemiFinish.queryGroupNo" desc = "查询同炉同批组号">
       SELECT LPAD(NVL(MAX(T.Batch_Groud_No), 0) + 1, 3, 0) BATCH_GROUD_NO
          FROM (SELECT T.BATCH_GROUD_NO
            FROM MAT_BC_M T
           WHERE T.JUDGE_STOVE_NO = ?
             AND T.BATCH_NO = ?
          UNION ALL
          SELECT T.BATCH_GROUD_NO
            FROM MAT_BC_BACKUP T
           WHERE T.JUDGE_STOVE_NO = ?
             AND T.BATCH_NO = ?)T
       </query>
       <query id = "FrmSemiFinish.SelectDbkS" desc = "查询镦拔扩订单">
       SELECT S.PRO_PLAN_ID,
       S.GX_PLAN_NO,
       S.WEIGTH_S,
       NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT
  FROM PLN_ORDER_DBK_S S
  LEFT JOIN PLN_ZY_DBK_M T ON S.PRO_PLAN_ID = T.PRO_PLAN_ID
                          AND S.GX_PLAN_NO = T.GX_PLAN_NO
 WHERE S.PREV_GXPLAN_ID = '#PRO_PLAN_ID#'
   AND S.EXE_STATUS = '0'
 GROUP BY S.PRO_PLAN_ID, S.GX_PLAN_NO, S.WEIGTH_S
 ORDER BY S.GX_PLAN_NO ASC
       </query>
       <query id = "FrmSemiFinish.SelectRclS" desc = "查询热处理订单">
       SELECT S.PRO_PLAN_ID,
       S.GX_PLAN_NO,
       S.WEIGTH_S,
       NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT
  FROM PLN_ORDER_RCL_S S
  LEFT JOIN PLN_ZY_RCL_M T ON S.PRO_PLAN_ID = T.PRO_PLAN_ID
                          AND S.GX_PLAN_NO = T.GX_PLAN_NO
 WHERE S.PREV_GXPLAN_ID = '#PRO_PLAN_ID#'
   AND S.EXE_STATUS = '0'
 GROUP BY S.PRO_PLAN_ID, S.GX_PLAN_NO, S.WEIGTH_S
 ORDER BY S.GX_PLAN_NO ASC
       </query>
       <query id = "FrmSemiFinish.SelectGxS" desc = "查询管加工订单">
       SELECT S.PRO_PLAN_ID,
       S.GX_PLAN_NO,
       S.WEIGTH_S,
       NVL(SUM(T.PLN_INSINGLE_WT),0) PLN_INSINGLE_WT
  FROM PLN_ORDER_JGX_S S
  LEFT JOIN PLN_ZY_JGX_M T ON S.PRO_PLAN_ID = T.PRO_PLAN_ID
                          AND S.GX_PLAN_NO = T.GX_PLAN_NO
 WHERE S.PREV_GXPLAN_ID = '#PRO_PLAN_ID#'
   AND S.EXE_STATUS = '0'
 GROUP BY S.PRO_PLAN_ID, S.GX_PLAN_NO, S.WEIGTH_S
 ORDER BY S.GX_PLAN_NO ASC
       </query>
       <query id = "FrmSemiFinish.SelectMatBc" desc = "查询入库记录">
       SELECT *
  FROM MAT_BC_M T
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.QCM_STAUS = '00'
   AND T.PRO_PLAN_ID_NEXT IS NULL
       </query>
       <query id = "FrmSemiFinish.UpdateMatBcPro" desc = "修改下工序单号">
       UPDATE MAT_BC_M T
   SET T.PRO_PLAN_ID_NEXT = '#PRO_PLAN_ID_NEXT#',
       T.GX_PLAN_NO_NEXT  = '#GX_PLAN_NO_NEXT#'
 WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND T.BATCH_NO = '#BATCH_NO#'
   AND T.MAT_NO = '#MAT_NO#'
       </query>
       
       <query id = "FrmSemiFinish.doQueryJugdeCount" desc = "查询是否存在同炉">
		SELECT SUM(ACT_COUNT) ACT_COUNT
  FROM (SELECT COUNT(1) ACT_COUNT
          FROM YDM_BC_INLIST T
         WHERE T.JUDGE_STOVE_NO = ?
        
        UNION ALL
        
        SELECT COUNT(1) ACT_COUNT
          FROM PLN_ZY_DBK_M T
         WHERE T.JUDGE_STOVE_NO = ?
        
        UNION ALL
        
        SELECT COUNT(1) ACT_COUNT
          FROM PLN_ZY_RCL_M T
         WHERE T.JUDGE_STOVE_NO = ?
        
        UNION ALL
        
        SELECT COUNT(1) ACT_COUNT
          FROM PLN_ZY_JGX_M T
         WHERE T.JUDGE_STOVE_NO = ?
        
        UNION ALL
        
        SELECT COUNT(1) ACT_COUNT
          FROM PLN_ZY_ZG_M T
         WHERE T.FLAG_HEAT_NO = ?)
	</query>
	
	<query id = "FrmSemiFinish.getMaxMatNo" desc = "查询最大的材料号">
			SELECT TO_NUMBER(SUBSTR(NVL(MAX(T.MAT_NO), '000000000000'),
		                        LENGTH(NVL(MAX(T.MAT_NO), '000000000000')) - 3)) MAX_SEQ
		  FROM (select max(mat_no)MAT_NO from MAT_BC_M where JUDGE_STOVE_NO = ?  and  batch_no = ?
		       union select max(mat_no)MAT_NO from MAT_BC_BACKUP where JUDGE_STOVE_NO = ?  and  batch_no = ?)T
	</query>
</queryMap>