<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="下试轧料">

	<query id="FrmTryRollingMaterial.getRollingMaterial" desc="按条件试轧料查询">
	  <![CDATA[ 
	select T.JUDGE_STOVE_NO,
       T.GRADENAME,
       T.DIMATER,
       T.FIX_LEN,
       T.ACT_LEN,
       T.FIX_NUM,
       MAX(T.ACT_WEIGHT) ACT_WEIGHT
  from MAT_GP_M t
 WHERE t.hanging_flag = '0'
   and t.PRODUCT_FLAG = '801401'
   and t.pro_plan_id_zg is null
   and t.gx_plan_no_zg is null
   and (t.judge_result_code = '40740701' or
       t.judge_result_code = '40740702' or
       t.judge_result_code = '40740706') 
       #SomeThing#
 GROUP BY T.JUDGE_STOVE_NO,
          T.GRADENAME,
          T.DIMATER,
          T.FIX_LEN,
          T.ACT_LEN,
          T.FIX_NUM
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.getBackSlabForJudgeStoveNo" desc="查询已组炉试轧料计划2">
	  <![CDATA[ 
	select T1.GRADENAME,T1.FEED_HEAT_NO, t.*
  from MIL_FEED_PLAN t, MIL_PLAN T1
 where T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO(+)
   AND T.PLINE_CODE = T1.PLINE_CODE(+)
   AND t.judge_stove_no = ?
   and t.pline_code = ?
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.SelectStatus" desc="查询生产状态">
	  <![CDATA[ 
		select T.STATUS
	  from MIL_PLAN t
	 where t.judge_stove_no = ?
	   and t.pline_code = ?
	   AND T.TYPE = '1'
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.getBackSlabPlan" desc="查询已组炉试轧料计划">
	  <![CDATA[ 
	SELECT T.JUDGE_STOVE_NO,
       T.STATUS,
       CASE T.STATUS
         WHEN '00' THEN
          '上料'
         WHEN '05' THEN
          '开始锯切'
         WHEN '10' THEN
          '锯切完成'
         WHEN '15' THEN
          '入炉'
         WHEN '20' THEN
          '出炉'
         WHEN '25' THEN
          '开始穿孔'
         WHEN '30' THEN
          '穿孔完成'
         WHEN '35' THEN
          '开始连轧'
         WHEN '40' THEN
          '连轧完成'
         WHEN '45' THEN
          '入再加热炉'
         WHEN '50' THEN
          '出再加热炉'
         WHEN '55' THEN
          '开始定径'
         WHEN '60' THEN
          '定径完成'
         WHEN '65' THEN
          '开始分切'
         WHEN '70' THEN
          '分切完成'
         WHEN '75' THEN
          '开始矫直'
         WHEN '80' THEN
          '矫直完成 '
         WHEN '85' THEN
          '开始探伤'
         WHEN '90' THEN
          '探伤完成'
         WHEN '99' THEN
          '入库'
       END AS STATUS1,
       T.START_TIME
  FROM MIL_PLAN T
 WHERE t.varieties = '试轧料'
   AND T.PLINE_CODE = ?
   #SomeThing#
    ORDER BY T.START_TIME DESC
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.getRollingMaterialDetail" desc="按条件试轧料查询">
	  <![CDATA[ 
	SELECT T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.GRADECODE,
       T.GRADENAME,
       T.STD_CODE,
       T.STD_NAME,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.DIMATER,
       T.ACT_LEN,
       T.FIX_NUM,
       T.FIX_LEN,
       T.JUGDE_APPLY_CODE,
       SUM(T.ACT_COUNT) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT,
       MAX(T.ACT_WEIGHT) DB_WEIGHT,
       (SELECT B.BASENAME
          FROM COM_BASE_INFO B
         WHERE B.BASECODE = T.JUDGE_RESULT_CODE) JUDGE_RESULT_NAME,
       T.JUDGE_RESULT_CODE,
       DECODE(MAX(T.GPTYPE), '1', '铸坯', '2', '锻坯') GPTYPE,
       T1.STORAGE_NO,
       (SELECT S.STORAGE_NAME
          FROM YDM_BS_STORAGE S
         WHERE S.STORAGE_NO = T1.STORAGE_NO) STORAGE_NAME
  FROM MAT_GP_M T, YDM_GP_BUTTRESS T1
 WHERE t.hanging_flag = '0'
   and t.PRODUCT_FLAG = '801401'
   AND T.MAT_NO = T1.MAT_NO
   and t.pro_plan_id_zg is null
   and t.gx_plan_no_zg is null
   and (t.judge_result_code = '40740701' or
       t.judge_result_code = '40740702' or
       t.judge_result_code = '40740706')
   AND T.GRADENAME = ?
   AND T.DIMATER = ?
   AND T.ACT_LEN = ?
   AND T.JUDGE_STOVE_NO = ?
 GROUP BY T.STOVE_NO,
          T.JUDGE_STOVE_NO,
          T.GRADECODE,
          T.GRADENAME,
          T.STD_CODE,
          T.STD_NAME,
          T.PLINE_CODE,
          T.PLINE_NAME,
          T.JUGDE_APPLY_CODE,
          T.DIMATER,
          T.ACT_LEN,
          T.FIX_NUM,
          T.FIX_LEN,
          T.GRADENAME,
          T.DIMATER,
          T.ACT_LEN,
          T.FIX_NUM,
          T.FIX_LEN,
          T.JUDGE_RESULT_CODE,
          T1.STORAGE_NO
      ]]>
   </query>

<query id="FrmTryRollingMaterial.node" desc="管坯出库">
	  <![CDATA[ 
DECLARE
  V_JUDGE_STOVE_NO   YDM_GP_OUTLIST.JUDGE_STOVE_NO%TYPE := ?;
  V_JUDGE_STOVE_NO2  MIL_PLAN.JUDGE_STOVE_NO%TYPE := ?;
  V_JUGDE_APPLY_CODE MAT_GP_M.JUGDE_APPLY_CODE%TYPE := ?;
  V_ACT_COUNT        MAT_GP_M.ACT_LEN%TYPE := ?;
  V_FIX_NUM          MAT_GP_M.FIX_NUM%TYPE := ?;
  V_FEED_LENGTH      MIL_FEED_PLAN.FEED_LENGTH%TYPE := ?;
  V_OUTSTOCK_DOC_OA  YDM_GP_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  V_OUTSTOCK_DOC_CQ  YDM_GP_OUTLIST.OUTSTOCK_DOC%TYPE := NULL;
  V_BATHYEAR         MAT_GP_M.BAL_YEAR_MONTH%TYPE := ?;
  V_STORAGE_NO       YDM_GP_BUTTRESS.STORAGE_NO%TYPE := ?;
  V_ICOUNT           NUMBER := 1;

BEGIN

  --生成 投料出库单编号
  SELECT 'OA' || TO_CHAR(SYSDATE, 'YYMMDD') ||
         LPAD(NVL(MAX(SUBSTR(T.OUTSTOCK_DOC, 9)), 0) + 1, 5, 0) DI
    INTO V_OUTSTOCK_DOC_OA
    FROM YDM_GP_OUTLIST T
   WHERE TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =
         TO_CHAR(SYSDATE, 'YYYY-MM-DD')
     and t.outstock_type_code = '800801';

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

  FOR MYROW IN (SELECT T.*,
                       --T2.BATCH_NO,
                       T2.STORAGE_NO,
                       T2.LOCATION_NO,
                       T2.LARY_NO,
                       T2.LOC_NO,
                       T2.STORAGE_ATTR,
                       T2.STORAGE_ATTR_NAME,
                       T2.STORAGE_TYPE_NO,
                       T2.STORAGE_TYPE_NAME,
                       T2.DEPARTMENT_CODE,
                       T2.DEPARTMENT_DESC,
                       T2.MANAGEMENT_NO,
                       T2.MANAGEMENT_NAME
                  FROM MAT_GP_M T, YDM_GP_BUTTRESS T2
                 WHERE T.MAT_NO = T2.MAT_NO
                   AND T2.STORAGE_NO = V_STORAGE_NO
                   AND T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                   AND NVL(T.JUGDE_APPLY_CODE, '/') =
                       NVL(V_JUGDE_APPLY_CODE, '/')
                   AND T.ACT_LEN = V_FEED_LENGTH
                   AND T.FIX_NUM = V_FIX_NUM
                   AND T.HANGING_FLAG = '0'
                    #something#
                   and t.PRODUCT_FLAG = '801401'
                   and t.pro_plan_id_zg is null
                   and t.gx_plan_no_zg is null
                   and (t.judge_result_code = '40740701' or
                       t.judge_result_code = '40740702' or
                       t.judge_result_code = '40740706')
                   AND ROWNUM <= V_ACT_COUNT
                 ORDER BY T.MAT_NO DESC) LOOP
  
    --新增投料出库实绩表记录
    INSERT INTO YDM_GP_OUTLIST
      (OUTSTOCK_SQE,
       -- OUTSTOCK_PLAN_NO,
       OUTSTOCK_DOC,
       OUTSTOCK_TYPE_CODE,
       OUTSTOCK_TYPE_NAME,
       /*ICCAR_NO,
       VEHICLE_NO,*/
       MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       STOVE_NO,
       FLAG_STOVE_NO,
       JUDGE_STOVE_NO,
       CAST_NO,
       CCMID,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADECODE,
       GRADENAME,
       STD_CODE,
       STD_NAME,
       DIMATER,
       HEIGHT,
       ACT_LEN,
       FIX_NUM,
       FIX_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       PONDER_NO,
       PONDER_GROSS_WT,
       PLINE_CODE,
       PLINE_NAME,
       PRO_ORDER_NO,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       BELONG_CODE,
       BELONG_NAME,
       BAR_CODE,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       LOC_NO,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       /* TAR_STORAGE_NO,
       TAR_LOCATION_NO,
       TAR_LARY_NO,
       TAR_LOC_NO,
       TAR_DEPARTMENT_CODE,
       TAR_DEPARTMENT_DESC,
       TAR_MANAGEMENT_NO,
       TAR_MANAGEMENT_NAME,*/
       --TAR_REC_FLAG,
       
       RPO_TIME,
       PRO_BC,
       PRO_BZ,
       BAL_YEAR_MONTH,
       
       OUTSTOCK_TIME,
       
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       --HAND_FLAG,
       --VALIDFLAG,
       MEMO,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       /*DELETE_NAME,
       DELETE_TIME,*/
       GROUD_NO,
       /* SEND_NUM,
       RECEIV_NO,
       RECEIV_NM,*/
       --M_BILL_NO,
       PRINT_STOVE_NO,
       PRO_PLAN_ID_ZG,
       GX_PLAN_NO_ZG,
       LOT_NO,
       IS_DEALER,
       BACK_FLAG,
       SUPPLY_UNIT,
       SUPPLY_UNIT_CODE)
    VALUES
      (V_OUTSTOCK_DOC_OA || LPAD(V_ICOUNT, 4, 0),
       -- MYROW.OUTSTOCK_PLAN_NO,
       V_OUTSTOCK_DOC_OA,
       '800801',
       '投料出库',
       /* MYROW.ICCAR_NO,
       MYROW.VEHICLE_NO,*/
       MYROW.MAT_NO,
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.STOVE_NO,
       MYROW.FLAG_STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.CAST_NO,
       MYROW.CCMID,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.DIMATER,
       MYROW.HEIGHT,
       MYROW.ACT_LEN,
       MYROW.FIX_NUM,
       MYROW.FIX_LEN,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.PONDER_NO,
       MYROW.PONDER_GROSS_WT,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.PRO_ORDER_NO,
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       MYROW.BAR_CODE,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.LOC_NO,
       MYROW.DEPARTMENT_CODE,
       MYROW.DEPARTMENT_DESC,
       MYROW.MANAGEMENT_NO,
       MYROW.MANAGEMENT_NAME,
       /* MYROW.TAR_STORAGE_NO,
       MYROW.TAR_LOCATION_NO,
       MYROW.TAR_LARY_NO,
       MYROW.TAR_LOC_NO,
       MYROW.TAR_DEPARTMENT_CODE,
       MYROW.TAR_DEPARTMENT_DESC,
       MYROW.TAR_MANAGEMENT_NO,
       MYROW.TAR_MANAGEMENT_NAME,*/
       --MYROW.TAR_REC_FLAG,
       
       SYSDATE,
       MYROW.PRO_BC,
       MYROW.PRO_BZ,
       V_BATHYEAR,
       
       SYSDATE,
       
       MYROW.STORAGE_ATTR,
       MYROW.STORAGE_ATTR_NAME,
       MYROW.STORAGE_TYPE_NO,
       MYROW.STORAGE_TYPE_NAME,
       
       MYROW.MEMO,
       MYROW.CREATE_NAME,
       SYSDATE,
       MYROW.UPDATE_NAME,
       SYSDATE,
       
       MYROW.GROUD_NO,
       /*MYROW.SEND_NUM,
       MYROW.RECEIV_NO,
       MYROW.RECEIV_NM,*/
       --MYROW.M_BILL_NO,
       V_JUDGE_STOVE_NO2,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO,
       '试轧料',
       MYROW.IS_DEALER,
       MYROW.BACK_FLAG,
       MYROW.SUPPLY_UNIT,
       MYROW.SUPPLY_UNIT_CODE);
  
    --新增产权出库实绩表记录
    INSERT INTO YDM_GP_OUTLIST
      (OUTSTOCK_SQE,
       -- OUTSTOCK_PLAN_NO,
       OUTSTOCK_DOC,
       OUTSTOCK_TYPE_CODE,
       OUTSTOCK_TYPE_NAME,
       /*ICCAR_NO,
       VEHICLE_NO,*/
       MAT_NO,
       PRODUCT_FLAG,
       MAT_STATUS,
       STOVE_NO,
       FLAG_STOVE_NO,
       JUDGE_STOVE_NO,
       CAST_NO,
       CCMID,
       MATERIAL_NO,
       MATERIAL_NAME,
       GRADECODE,
       GRADENAME,
       STD_CODE,
       STD_NAME,
       DIMATER,
       HEIGHT,
       ACT_LEN,
       FIX_NUM,
       FIX_LEN,
       ACT_COUNT,
       ACT_WEIGHT,
       ACT_THEORY_WEIGHT,
       PONDER_NO,
       PONDER_GROSS_WT,
       PLINE_CODE,
       PLINE_NAME,
       PRO_ORDER_NO,
       ORDER_NO,
       ORDER_SEQ,
       ORDER_SEQ_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       BELONG_CODE,
       BELONG_NAME,
       BAR_CODE,
       STORAGE_NO,
       LOCATION_NO,
       LARY_NO,
       LOC_NO,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       /* TAR_STORAGE_NO,
       TAR_LOCATION_NO,
       TAR_LARY_NO,
       TAR_LOC_NO,
       TAR_DEPARTMENT_CODE,
       TAR_DEPARTMENT_DESC,
       TAR_MANAGEMENT_NO,
       TAR_MANAGEMENT_NAME,*/
       --TAR_REC_FLAG,
       
       RPO_TIME,
       PRO_BC,
       PRO_BZ,
       BAL_YEAR_MONTH,
       
       OUTSTOCK_TIME,
       
       STORAGE_ATTR,
       STORAGE_ATTR_NAME,
       STORAGE_TYPE_NO,
       STORAGE_TYPE_NAME,
       --HAND_FLAG,
       --VALIDFLAG,
       MEMO,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       /*DELETE_NAME,
       DELETE_TIME,*/
       GROUD_NO,
       /* SEND_NUM,
       RECEIV_NO,
       RECEIV_NM,*/
       --M_BILL_NO,
       PRINT_STOVE_NO,
       PRO_PLAN_ID_ZG,
       GX_PLAN_NO_ZG,
       LOT_NO,
       IS_DEALER,
       BACK_FLAG,
       SUPPLY_UNIT,
       SUPPLY_UNIT_CODE)
    VALUES
      (V_OUTSTOCK_DOC_CQ || LPAD(V_ICOUNT, 4, 0),
       -- MYROW.OUTSTOCK_PLAN_NO,
       V_OUTSTOCK_DOC_CQ,
       '800809',
       '产权出库',
       /* MYROW.ICCAR_NO,
       MYROW.VEHICLE_NO,*/
       MYROW.MAT_NO,
       MYROW.PRODUCT_FLAG,
       MYROW.MAT_STATUS,
       MYROW.STOVE_NO,
       MYROW.FLAG_STOVE_NO,
       MYROW.JUDGE_STOVE_NO,
       MYROW.CAST_NO,
       MYROW.CCMID,
       MYROW.MATERIAL_NO,
       MYROW.MATERIAL_NAME,
       MYROW.GRADECODE,
       MYROW.GRADENAME,
       MYROW.STD_CODE,
       MYROW.STD_NAME,
       MYROW.DIMATER,
       MYROW.HEIGHT,
       MYROW.ACT_LEN,
       MYROW.FIX_NUM,
       MYROW.FIX_LEN,
       MYROW.ACT_COUNT,
       MYROW.ACT_WEIGHT,
       MYROW.ACT_THEORY_WEIGHT,
       MYROW.PONDER_NO,
       MYROW.PONDER_GROSS_WT,
       MYROW.PLINE_CODE,
       MYROW.PLINE_NAME,
       MYROW.PRO_ORDER_NO,
       MYROW.ORDER_NO,
       MYROW.ORDER_SEQ,
       MYROW.ORDER_SEQ_NO,
       MYROW.ORD_PK,
       MYROW.ORD_LN_PK,
       MYROW.ORD_LN_DLY_PK,
       MYROW.BELONG_CODE,
       MYROW.BELONG_NAME,
       MYROW.BAR_CODE,
       MYROW.STORAGE_NO,
       MYROW.LOCATION_NO,
       MYROW.LARY_NO,
       MYROW.LOC_NO,
       MYROW.DEPARTMENT_CODE,
       MYROW.DEPARTMENT_DESC,
       MYROW.MANAGEMENT_NO,
       MYROW.MANAGEMENT_NAME,
       /* MYROW.TAR_STORAGE_NO,
       MYROW.TAR_LOCATION_NO,
       MYROW.TAR_LARY_NO,
       MYROW.TAR_LOC_NO,
       MYROW.TAR_DEPARTMENT_CODE,
       MYROW.TAR_DEPARTMENT_DESC,
       MYROW.TAR_MANAGEMENT_NO,
       MYROW.TAR_MANAGEMENT_NAME,*/
       --MYROW.TAR_REC_FLAG,
       
       SYSDATE,
       MYROW.PRO_BC,
       MYROW.PRO_BZ,
       V_BATHYEAR,
       
       SYSDATE,
       
       MYROW.STORAGE_ATTR,
       MYROW.STORAGE_ATTR_NAME,
       MYROW.STORAGE_TYPE_NO,
       MYROW.STORAGE_TYPE_NAME,
       
       MYROW.MEMO,
       MYROW.CREATE_NAME,
       SYSDATE,
       MYROW.UPDATE_NAME,
       SYSDATE,
       
       MYROW.GROUD_NO,
       /*MYROW.SEND_NUM,
       MYROW.RECEIV_NO,
       MYROW.RECEIV_NM,*/
       --MYROW.M_BILL_NO,
       V_JUDGE_STOVE_NO2,
       MYROW.PRO_PLAN_ID,
       MYROW.GX_PLAN_NO,
       '试轧料',
       MYROW.IS_DEALER,
       MYROW.BACK_FLAG,
       MYROW.SUPPLY_UNIT,
       MYROW.SUPPLY_UNIT_CODE);
  
    --复制数据到历史表
    insert into MAT_GP_M_HISTORY
      select * from MAT_GP_M t where t.mat_no = MYROW.MAT_NO;
  
    UPDATE MAT_GP_M_HISTORY T
       SET T.PRINT_STOVE_NO = V_JUDGE_STOVE_NO2
     where t.mat_no = MYROW.MAT_NO;
  
    --删除物料主表记录
    DELETE FROM MAT_GP_M T WHERE T.MAT_NO = MYROW.MAT_NO;
  
    --删除位置表记录
    DELETE FROM YDM_GP_BUTTRESS T2 WHERE T2.MAT_NO = MYROW.MAT_NO;
    V_ICOUNT := V_ICOUNT + 1;
  END LOOP;
END;
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.insertMianPlan" desc="插入主计划">
	  <![CDATA[ 
	INSERT INTO MIL_PLAN
  (ID,
   SEQ,
   LOT_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   DB_LENGTH,
   DB_HEIGHT,
   SAW_NUM,
   PIPE_SECTION,
   GRADENAME,
   DB_NUM,
   START_TIME,
   TOM,
   TOC,
   --TUBE_TYPE,
   --TUBE_SUORCE,
   TYPE,
   BRANCH,
   PIPE_SIZE,
   FEED_HEAT_NO,
   COL_TIME,
   VARIETIES,
   BAL_YEAR_MONTH,
   TARGET,
   PRT_FLAG,
   LENGTH_RANGE)
VALUES
  (?,
   ?,
   '试轧料',
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   SYSDATE,
   SYSDATE,
   SYSDATE,
   ?,
   ?,
   NVL(?, '241.00*9.00'),
   ?,
   SYSDATE,
   '试轧料',
   ?,
   'A',
   '1',
   '0-0')
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.insertFeedPlan" desc="插入子计划">
	  <![CDATA[ 
	INSERT INTO MIL_FEED_PLAN
  (FEED_ROW_NO,
   LOT_NO,
   JUDGE_STOVE_NO,
   PLINE_CODE,
   DB_NUM,
   MAT_HEIGHT,
   MAT_TOTAL_HEIGHT,
   FEED_NUM,
   FEED_LENGTH,
   USE_LENGTH,
   CUT_TARGET,
   CUT_LENGTH,
   CUT_WEIGHT,
   DB_LENGTH,
   PIPE_SECTION,
   DB_HEIGHT,
   CREATE_NAME,
   CREATE_TIME,
   STOVE_NO,
   FEED_NUM_PLAN)
VALUES
  (?, '试轧料', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, ?, ?)

      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.nodeBack" desc="撤销出库">
	  <![CDATA[ 
	DECLARE
  V_JUDGE_STOVE_NO MAT_GP_M.JUDGE_STOVE_NO%TYPE := ?;
  V_PRINT_STOVE_NO MAT_GP_M.PRINT_STOVE_NO%TYPE := ?;
  V_ACT_COUNT      PLN_ZY_ZG_C.REAL_INDOUBLE_NUM%TYPE := ?;
  V_FIX_NUM        MAT_GP_M.FIX_NUM%TYPE := ?;
  V_FEED_LENGTH    MIL_FEED_PLAN.FEED_LENGTH%TYPE := ?;

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

  FOR MYROW2 IN (SELECT *
                   FROM MAT_GP_M_HISTORY T
                  WHERE T.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
                    AND T.PRINT_STOVE_NO = V_PRINT_STOVE_NO
                    AND T.ACT_LEN = V_FEED_LENGTH
                    AND ROWNUM <= V_ACT_COUNT
                  ORDER BY T.MAT_NO) LOOP
  
    --复制数据到物料主表
    UPDATE MAT_GP_M_HISTORY T
       SET T.PRINT_STOVE_NO = ''
     WHERE T.MAT_NO = MYROW2.MAT_NO;
  
    insert into MAT_GP_M
      select * from MAT_GP_M_HISTORY t where t.mat_no = MYROW2.MAT_NO;
  
    --删除历史表记录
    DELETE FROM MAT_GP_M_HISTORY T WHERE T.MAT_NO = MYROW2.MAT_NO;
  
  END LOOP;
END;
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.deleteFeedPlan" desc="删除轧管计划从表">
	  <![CDATA[ 
	 DELETE FROM MIL_FEED_PLAN T WHERE T.STOVE_NO = ? AND T.JUDGE_STOVE_NO = ? AND T.PLINE_CODE =?
      ]]>
   </query>
   
   <query id="FrmTryRollingMaterial.deletePlan" desc="删除轧管计划主表">
	  <![CDATA[ 
	 DELETE FROM MIL_PLAN T WHERE T.JUDGE_STOVE_NO = ? AND T.PLINE_CODE = ? AND T.TYPE = '1'
      ]]>
   </query>
   
     <query id="FrmTryRollingMaterial.deletePortMil" desc="删除进程表管号队列">
	  <![CDATA[ 
	DELETE FROM PORT_MIL_BATCH_SAMPLE_RESULT T
 WHERE T.PLAN_ID = ?
   AND T.JUDGE_STOVE_NO = ?
   AND T.PLINE_CODE = ?
   AND T.LOT_NO = '试轧料'
   AND T.PRO_PLAN_ID IS NULL
   AND T.GX_PLAN_NO IS NULL
      ]]>
   </query>
   
   <query id = "FrmTryRollingMaterial.SelectKCZS" desc = "查询库存支数">
<![CDATA[
	select COUNT(1) ACT_COUNT
  from MAT_GP_M t, YDM_GP_BUTTRESS T1
 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
   AND T.MAT_NO = T1.MAT_NO
   AND T.HANGING_FLAG = '0'
   and t.PRODUCT_FLAG = '801401'
   AND T.PRO_PLAN_ID_ZG IS NULL
   AND T.GX_PLAN_NO_ZG IS NULL
   and (t.judge_result_code = '40740701' or
       t.judge_result_code = '40740702' or
       t.judge_result_code = '40740706')
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.JUGDE_APPLY_CODE,'/') = NVL(?,'/')
   AND T.ACT_LEN = ?
   AND T.FIX_NUM = ?
   AND T.GRADENAME = ?
   AND T.DIMATER = ?
]]>
</query>

<query id = "FrmTryRollingMaterial.SelectBackFlag" desc = "查询库存坯料类型">
<![CDATA[
	select T.BACK_FLAG
  from MAT_GP_M t, YDM_GP_BUTTRESS T1
 WHERE T.JUDGE_STOVE_NO = T1.JUDGE_STOVE_NO
   AND T.MAT_NO = T1.MAT_NO
   AND T.HANGING_FLAG = '0'
   and t.PRODUCT_FLAG = '801401'
   AND T.PRO_PLAN_ID_ZG IS NULL
   AND T.GX_PLAN_NO_ZG IS NULL
   and (t.judge_result_code = '40740701' or
       t.judge_result_code = '40740702' or
       t.judge_result_code = '40740706')
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.JUGDE_APPLY_CODE,'/') = NVL(?,'/')
   AND T.ACT_LEN = ?
   AND T.FIX_NUM = ?
   AND T.GRADENAME = ?
   AND T.DIMATER = ?
]]>
</query>
	
</queryMap>
