<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="利库">

	<query id="FrmMaterialChoose.queryMaterialE" desc="查询库存镦拔扩物料">
            <![CDATA[
       SELECT T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T1.STORAGE_NO,
       (SELECT T2.STORAGE_NAME
          FROM YDM_BS_STORAGE T2
         WHERE T2.STORAGE_NO = T1.STORAGE_NO) STORAGE_NAME,
       T.VRP_PRO_ORDER_ID PRO_PLAN_ID,
       T.VRP_GX_PLAN_NO GX_PLAN_NO,
       T.VRP_HEAT_PLAN_NO HEAT_PLAN_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.GRADECODE,
       T.GRADENAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       SUM(T.ACT_COUNT) ACT_COUNT,
       SUM(T.ACT_WEIGHT) ACT_WEIGHT,
       (SELECT I.BASENAME FROM COM_BASE_INFO I WHERE I.BASECODE=T.PRODUCT_FLAG) PRODUCT_FLAG,
       (SELECT I.BASENAME FROM COM_BASE_INFO I WHERE I.BASECODE=T.MAT_STATUS) MAT_STATUS
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO
   AND T.MATERIAL_NO = ?
   and t.PRODUCT_FLAG = '801401'
   and t.MAT_STATUS in ('80150102', '80150103')
 GROUP BY T.MATERIAL_NO,
          T.MATERIAL_NAME,
          T1.STORAGE_NO,
          T.JUDGE_STOVE_NO,
          T.BATCH_NO,
          T.BATCH_GROUD_NO,
          T.GRADECODE,
          T.GRADENAME,
          T.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.ACT_LEN,
          T.ACT_LEN_MIN,
          T.ACT_LEN_MAX,
          T.MAT_STATUS,
          T.PRODUCT_FLAG,
          T.VRP_HEAT_PLAN_NO,
          T.VRP_PRO_ORDER_ID,
          T.VRP_GX_PLAN_NO
 ORDER BY T.JUDGE_STOVE_NO, T.BATCH_NO, T.BATCH_GROUD_NO
              ]]>
	</query>

	<query id="FrmMaterialChoose.getMatNoByJudgeLikuE" desc="通过炉批组号查询材料号">
            <![CDATA[
SELECT T.MAT_NO,T.ACT_WEIGHT
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO
   AND T.MATERIAL_NO = ?
   AND T.PRODUCT_FLAG = '801401' ---在制品（及半成品）
   AND T.MAT_STATUS = '80150102' --材料产出(已判定)
   AND T.VRP_PRO_ORDER_ID IS NULL
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
 ORDER BY T.MAT_NO
              ]]>
	</query>

	<query id="FrmMaterialChoose.getMatNoByJudgeMonomerE" desc="通过炉批组号查询材料号(脱单)">
            <![CDATA[
SELECT T.MAT_NO,T.ACT_WEIGHT
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO
   AND T.MATERIAL_NO = ?
   AND T.PRODUCT_FLAG = '801401' ---在制品（及半成品）
   AND T.MAT_STATUS = '80150103' --材料产出(已判定)
   AND T.VRP_PRO_ORDER_ID IS NOT NULL
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
   AND T.BATCH_GROUD_NO = ?
 ORDER BY T.MAT_NO
              ]]>
	</query>

	<query id="FrmMaterialChoose.updateMatE" desc="修改镦拔扩库存数据">
            <![CDATA[
           UPDATE MAT_ZC_M T
   SET T.MAT_STATUS        = ?,
       T.VRP_PRO_ORDER_ID  = ?,
       T.VRP_GX_PLAN_NO    = ?,
       T.VRP_HEAT_PLAN_NO  = ?,
       T.VRP_PRO_ORDER_ID1 = T.VRP_PRO_ORDER_ID,
       T.VRP_GX_PLAN_NO1   = T.VRP_GX_PLAN_NO
 WHERE T.MAT_NO = ?
              ]]>
	</query>


	<query id="FrmMaterialChoose.getMaxHeatPlanNoD" desc="查询轧管最大炉号ID后四位">
            <![CDATA[
           SELECT TO_NUMBER(SUBSTR(NVL(MAX(T.HEAT_PLAN_NO), 'D000000000000'), 10, 4)) + 1 AS HEAT_PLAN_NO
  FROM PLN_ZY_ZG_M T
 WHERE SUBSTR(T.HEAT_PLAN_NO, 2, 8) = ?
              ]]>
	</query>


	<query id="FrmMaterialChoose.getMaxHeatPlanNoE" desc="查询镦拔扩最大炉号ID后四位">
            <![CDATA[
            SELECT TO_NUMBER(SUBSTR(NVL(MAX(T.HEAT_PLAN_NO), 'D000000000000'), 10, 4)) + 1 AS HEAT_PLAN_NO
  FROM PLN_ZY_DBK_M T
   WHERE SUBSTR(T.HEAT_PLAN_NO, 2, 8) = ?
              ]]>
	</query>



	<query id="FrmMaterialChoose.getProdIndexE" desc="查询最大镦拔扩批次生产序号">
            <![CDATA[
            SELECT TO_NUMBER(NVL(MAX(T.PROD_INDEX), '0')) + 1 PROD_INDEX
  FROM PLN_ZY_DBK_M T
 WHERE T.ZY_BATCH_ID = ?
              ]]>
	</query>



	<query id="FrmMaterialChoose.addZyDbkReadyE" desc="新增镦拔扩虚拟炉计划">
            <![CDATA[
       INSERT INTO PLN_ZY_DBK_READY
  (PRO_PLAN_ID,
   GX_PLAN_NO,
   READY_PLAN_NO,
   ZY_BATCH_ID,
   PLINE_CODE,
   PLINE_NAME,
   ZG_HEAT_PLAN_NO,
   JUDGE_STOVE_NO,
   ORDER_SOURCE,
   ORD_LN_DLY_PK,
   ORDER_NO,
   ORDER_SEQ,
   DELIVERY_NO,
   REQ_BL_ID,
   OUTWL_ID,
   OUTWL_DESC,
   ALLOT_NUM,
   ALLOT_WT,
   IF_MATCH_ODD,
   IF_DO_HEAT_PLAN,
   CREATE_TIME,
   REAL_ALLOT_NUM,
   REAL_ALLOT_WT,
   REAL_STOVE_NO,
   CRAFT_FILE_NO,
   CRAFT_SEQ,
   SEC_CRAFT_FILE_NO,
   OUT_JUDGE_STD)
VALUES
  ('#PRO_PLAN_ID#',
   '#GX_PLAN_NO#',
   '#READY_PLAN_NO#',
   '#ZY_BATCH_ID#',
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#ZG_HEAT_PLAN_NO#',
   '#JUDGE_STOVE_NO#',
   '#ORDER_SOURCE#',
   '#ORD_LN_DLY_PK#',
   '#ORDER_NO#',
   '#ORDER_SEQ#',
   '#DELIVERY_NO#',
   '#REQ_BL_ID#',
   '#OUTWL_ID#',
   '#OUTWL_DESC#',
   '#ALLOT_NUM#',
   '#ALLOT_WT#',
   '#IF_MATCH_ODD#',
   '#IF_DO_HEAT_PLAN#',
   SYSDATE,
   '#REAL_ALLOT_NUM#',
   '#REAL_ALLOT_WT#',
   '#REAL_STOVE_NO#',
   '#CRAFT_FILE_NO#',
   '#CRAFT_SEQ#',
   '#SEC_CRAFT_FILE_NO#',
   '#OUT_JUDGE_STD#')
              ]]>
	</query>

	<query id="FrmMaterialChoose.addZyDbkME" desc="新增镦拔扩实际计划">
            <![CDATA[
   INSERT INTO PLN_ZY_DBK_M(
        HEAT_PLAN_NO,
        ZY_BATCH_ID,
        PROD_INDEX,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        READY_PLAN_NO,
        PLINE_CODE,
        PLINE_NAME,
        ZG_HEAT_PLAN_NO,
        HEATNO_LAST,
        ZG_BATCH_NO,
        BATCH_GROUD_NO,
        ISENDGX,
        ORDER_SOURCE,
        ORD_LN_DLY_PK,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        REQ_BL_ID,
        GRADECODE,
        GRADENAME,
        AIMOUTDIAMETER,
        AIMWALLTHICK,
        AIMLENGTH,
        OUTDIAMETER_IN,
        WALLTHICK_IN,
        LENGTH_IN,
        LENGTHMAX_IN,
        LENGTHMIN_IN,
        LEN_CUTHEAD,
        LEN_CUTEND,
        INWL_ID,
        INWL_DESC,
        IN_WT,
        IN_NUM,
        IF_WL_MATCHED,
        OUTWL_ID,
        OUTWL_DESC,
        IF_MONITOR_DBK,
        PRDCR_NO,
        MONITOR_POINT,
        CRAFT_FILE_NO,
        CRAFT_FILE_MAN,
        CRAFT_SEQ,
        SEC_CRAFT_FILE_NO,
        STATION_ROAD,
        PLANSTATUS,
        IN_WT_REAL,
        IN_NUM_REAL,
        OUT_WT_REAL,
        OUT_NUM_REAL,
        CREATE_NAME,
        CREATE_TIME,
        UPDATE_NAME,
        UPDATE_TIME,
        IN_JUDGE_STD)
 VALUES( 
        '#HEAT_PLAN_NO#',
        '#ZY_BATCH_ID#',
        '#PROD_INDEX#',
        '#PRO_PLAN_ID#',
        '#GX_PLAN_NO#',
        '#READY_PLAN_NO#',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#ZG_HEAT_PLAN_NO#',
        '#HEATNO_LAST#',
        '#ZG_BATCH_NO#',
        '#BATCH_GROUD_NO#',
        '#ISENDGX#',
        '#ORDER_SOURCE#',
        '#ORD_LN_DLY_PK#',
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#REQ_BL_ID#',
        '#GRADECODE#',
        '#GRADENAME#',
        '#AIMOUTDIAMETER#',
        '#AIMWALLTHICK#',
        '#AIMLENGTH#',
        '#OUTDIAMETER_IN#',
        '#WALLTHICK_IN#',
        '#LENGTH_IN#',
        '#LENGTHMAX_IN#',
        '#LENGTHMIN_IN#',
        '#LEN_CUTHEAD#',
        '#LEN_CUTEND#',
        '#INWL_ID#',
        '#INWL_DESC#',
        '#IN_WT#',
        '#IN_NUM#',
        '#IF_WL_MATCHED#',
        '#OUTWL_ID#',
        '#OUTWL_DESC#',
        '#IF_MONITOR_DBK#',
        '#PRDCR_NO#',
        '#MONITOR_POINT#',
        '#CRAFT_FILE_NO#',
        '#CRAFT_FILE_MAN#',
        '#CRAFT_SEQ#',
        '#SEC_CRAFT_FILE_NO#',
        '#STATION_ROAD#',
        '#PLANSTATUS#',
        '#IN_WT_REAL#',
        '#IN_NUM_REAL#',
        '#OUT_WT_REAL#',
        '#OUT_NUM_REAL#',
        '#CREATE_NAME#',
        SYSDATE,
        '#UPDATE_NAME#',
        NULL,
        '#IN_JUDGE_STD#')
              ]]>
	</query>

	<query id="FrmMaterialChoose.updatePlanDataE" desc="修改镦拔扩排产加投与实际挂量数据">
            <![CDATA[
UPDATE PLN_ORDER_DBK_S T
   SET T.MATCH_NUM_IN   = TO_NUMBER(NVL(T.MATCH_NUM_IN, '0')) + TO_NUMBER(?),
       T.MATCH_WT_IN    = TO_NUMBER(NVL(T.MATCH_WT_IN, '0')) + TO_NUMBER(?),
       T.REAL_BATCH_NUM = TO_NUMBER(NVL(T.REAL_BATCH_NUM, '0')) +
                          TO_NUMBER(?),
       T.REAL_BATCH_WT  = TO_NUMBER(NVL(T.REAL_BATCH_WT, '0')) +
                          TO_NUMBER(?),
       T.BATCHED_NUM    = TO_NUMBER(NVL(T.BATCHED_NUM, '0')) + TO_NUMBER(?),
       T.BATCHED_WT     = TO_NUMBER(NVL(T.BATCHED_WT, '0')) + TO_NUMBER(?)
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
              ]]>
	</query>


	<query id="FrmMaterialChoose.deleteDbkMByHeatPlanNo" desc="通过炉计划ID删除实际炉计划">
            <![CDATA[
            DELETE FROM PLN_ZY_DBK_M T WHERE T.HEAT_PLAN_NO=?
              ]]>
	</query>

	<query id="FrmMaterialChoose.deleteReadyById" desc="删除虚拟炉计划">
            <![CDATA[
           DELETE FROM PLN_ZY_DBK_READY T
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.READY_PLAN_NO = ?
              ]]>
	</query>

	<query id="FrmMaterialChoose.queryDbkMByHeatPlanNo" desc="查询实际炉计划数据">
            <![CDATA[
           SELECT T1.PRO_PLAN_ID, T1.GX_PLAN_NO, T1.READY_PLAN_NO, T1.HEAT_PLAN_NO
  FROM PLN_ZY_DBK_M T1, PLN_ZY_DBK_M T2
 WHERE T1.PRO_PLAN_ID = T2.PRO_PLAN_ID
   AND T1.GX_PLAN_NO = T2.GX_PLAN_NO
   AND T1.READY_PLAN_NO = T2.READY_PLAN_NO
   AND T1.HEAT_PLAN_NO = ?
              ]]>
	</query>

	<query id="FrmMaterialChoose.getMaxReadyPlanNo" desc="查询最大预排序号">
            <![CDATA[
               SELECT NVL(MAX(TO_NUMBER(T.READY_PLAN_NO)),0) READY_PLAN_NO FROM PLN_ZY_DBK_READY T WHERE T.PRO_PLAN_ID=? 
              ]]>
	</query>

	<query id="FrmMaterialChoose.updateReadyNum" desc="修改虚拟炉计划量">
            <![CDATA[
           UPDATE PLN_ZY_DBK_READY T
   SET T.REAL_ALLOT_NUM = T.REAL_ALLOT_NUM - TO_NUMBER(?),
       T.REAL_ALLOT_WT  = T.REAL_ALLOT_WT - TO_NUMBER(?)
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.READY_PLAN_NO = ?
              ]]>
	</query>


</queryMap>