<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="管坯需求制定">
	<query id="CorePlnZgMStoGp.getQueryGradeChoose" desc="查询钢种">
		<![CDATA[	
		SELECT T.GRADECODE,
       T.GRADENAME,
       T.ASSORTMENT_CODE,
       T.ASSORTMENT_NAME,
       T.COEFFICIENT,
       DECODE(T.ALLOW_BUY, '0', '否', '1', '是') ALLOW_BUY
  FROM COM_BASE_GRADE T
 WHERE T.VALIDFLAG = '1'
 ORDER BY T.GRADENAME ASC
		]]>
	</query>
	<query id="CorePlnZgMStoGp.getMonitorPoint" desc="查询监制工序点">
		<![CDATA[	
SELECT LISTAGG(PR.STATION_DESC, ',') WITHIN GROUP(ORDER BY PR.STATION_CODE ASC) STATION_DESC
  FROM SLM_ORDER_LINE_PRDCR_LST PR, SLM_ORDER_LINE_PRDCR P
 WHERE PR.PRDCR_NO = P.PRDCR_NO
   AND PR.PRDCR_INDEX = P.PRDCR_INDEX
   AND P.CODE_JG IS NULL
   AND P.CODE_BL IS NULL
   AND P.PRDCR_NO = ?
   AND P.MSC_PLINE = ?
   AND PR.PRDCR_PRC_FL = '1'
   AND PR.PROCESS_CODE = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.getQueryGrade" desc="查询钢种及钢种索引码">
		<![CDATA[
SELECT T.AGREEMENT_CODE,
       T.AGREEMENT_DESC,
       T.STD_CODE_NK,
       T.STD_NAME_NK,
       T1.GRADECODE,
       T1.GRADENAME,
       T2.STD_IDX,
       T2.STD_IDX_TYPE,
       T1.VALIDFLAG
  FROM COM_BASE_PURCHASE_AGREEMENT T,
       COM_MSC_STD_CIC             T1,
       COM_BASE_PURCHASE_STD_IDX   T2
 WHERE T.AGREEMENT_CODE = T2.AGREEMENT_CODE
   AND T1.CIC = T2.STD_IDX
   AND T.VALIDFLAG = '1'
   AND T1.VALIDFLAG != '0'			  
		]]>
	</query>
	<query id="CorePlnZgMStoGp.getQueryGrade1" desc="查询钢种及钢种索引码">
		<![CDATA[
SELECT T.GRADECODE,
       T.GRADENAME,
       T.CIC STD_IDX,
       T1.STD_CODE STD_CODE_NK,
       T1.STD_NAME STD_NAME_NK,
       DECODE(T1.PURCHASE_STD, '0', '自炼', '外购') ALLOW_BUY,
       T.VALIDFLAG,T1.VALIDFLAG
  FROM COM_MSC_STD_CIC T, COM_BASE_STD T1
 WHERE T.STDSTYLE = 'N'
   AND T.STD_CODE_NK = T1.STD_CODE(+)
   AND T1.VALIDFLAG = '1'
   AND T.VALIDFLAG = '1'
   AND T.GRADECODE IS NOT NULL
   AND T1.PURCHASE_STD = ?
   ORDER BY T.GRADECODE ASC ,T.CIC ASC
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectSpecWt" desc="查询锭型规格">
		<![CDATA[
			SELECT T.SPEC_CODE, T.SPEC_NAME, T.MSC_STYLE,T.ACTUAL_WEIGHT,T.GROSS_RATE,T.GROSS_WETGHT
			  FROM COM_BASE_SPEC T
			 WHERE T.VALIDFLAG = '1'
			   AND T.MSC_STYLE = 'D'
			   AND T.WEIGHT = ?
			  
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectSpecDimater" desc="查询管坯规格">
		<![CDATA[
			SELECT T.SPEC_CODE, T.SPEC_NAME, T.MSC_STYLE,T.DIMATER
			  FROM COM_BASE_SPEC T
			 WHERE T.VALIDFLAG = '1'
			   AND T.MSC_STYLE = 'B'
			  
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getGpreqId" desc="查询管坯需求号">
		<![CDATA[
			SELECT T.GPREQ_ID FROM PLN_REQINF_GP T WHERE T.REQ_DONESTATUS < '2' ORDER BY T.GPREQ_ID ASC
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getProcessPline" desc="查询工序产线">
		<![CDATA[
			SELECT T.PLINE_CODE, T.PLINE_NAME
			  FROM COM_BASE_PLINE T
			 WHERE T.PROCESS_CODE = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getProPlanId" desc="查询工序订单号">
		<![CDATA[
			 SELECT T.PRO_PLAN_ID
			   FROM PLN_ORDER_ZG_S T
			  WHERE T.EXE_STATUS = '0'
			    AND (T.IS_REPAIR_PLN IS NULL OR T.IS_REPAIR_PLN = '0') AND T.VALIDFLAG='1'
			  GROUP BY T.PRO_PLAN_ID
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectProGpReqPln" desc="查询管坯">
		<![CDATA[
			SELECT T.GPREQ_ID,
       DECODE(T.GPTYPE, '1', '铸坯', '2', '锻坯','0','轧坯') GPTYPE,
       T.GRADECODE,
       T.GRADENAME,
       T.DIAMETER_GP,
       T.LEN_GP_SINGLE,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.WIC,
       T.GIC,
       DECODE(T.IF_MONITOR_LG, '1', '是', '否') IF_MONITOR_LG,
       T.PRDCR_NO,
       T.WEIGHT_GP_ONE,
       T.GP_WEIGHT,
       T.GP_NUM,
       T.CUT_NUM_GP,
       T.CUT_LOSE_LEN,
       T.LENGTH_GP,
       T.GP_WT_LONG,
       T.GP_NUM_LONG,
       DECODE(T.IFBUYPLAN, '1', '是', '否') IFBUYPLAN,
       DECODE(T.REQ_DONESTATUS,
              '0',
              '待处理',
              '1',
              '计划',
              '2',
              '生产',
              '3',
              '关闭') REQ_DONESTATUS,
       DECODE(T.CASTINGTYPE, '1', '连铸', '2', '模铸') CASTINGTYPE,
       CASE
         WHEN T.CASTINGTYPE = '2' THEN
          T.DIAMETER_ZZ || 't'
         ELSE
         T.DIAMETER_ZZ||''
       END DIAMETER_ZZ,
       T.LENGTH_ZZ,
       T.WT_ONE_ZZ,
       T.WLID_ZZ,
       T.WLDESC_ZZ,
       T.OUT_WT_ZZ,
       T.OUT_NUM_ZZ,
       DECODE(T.INWL_ISOK_DZ, '0', '否', '1', '是', '2', '非锻坯') INWL_ISOK_DZ,
       T.PLINE_CODE_DZ,
       T.PLINE_NAME_DZ,
       T.PLINE_CODE_ZZ,
       T.PLINE_NAME_ZZ,
       T.DZ_LOSE_ADD,
       T.DZ_CUT_HEAD_END,
       T.DZ_BURN_LOSE,
       T.MEMO,
       DECODE(T.REQ_STATUS,'0','编制','1','生效','2','提报','3','执行','4','交齐') REQ_STATUS,
       DECODE(T.REC_TYPE,'0','正常','1','预排') REC_TYPE,
       NVL(T.GP_SYWEIGHT,0) GP_SYWEIGHT,
       TO_CHAR(T.CREATE_TIME,'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.CREATE_NAME,
       TO_CHAR(T.ISSUED_TIME,'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
       T.ISSUED_MAN,
       T.PRO_MONTH,
       T.WHOLE_BACKLOG_DESC,
       T.STATION_ROAD_LG,
       T.SUPPLY_UNIT_CODE,
       T.SUPPLY_UNIT,
       DECODE(T.TYPE_FLAG,'0','否','1','双经销','2','定购订结','3','来料加工','4','库存商备坯')TYPE_FLAG
  FROM PLN_REQINF_GP T
 WHERE 1=1

		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectProZgMsPln" desc="查询工序订单排产计划">
		<![CDATA[
			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) ORDER_NO_SEQ,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.REQ_BL_ID,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       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,
			       NVL(T.MATCH_WT_IN,0) MATCH_WT_IN,
			       NVL(T.MATCH_NUM_IN,0) MATCH_NUM_IN,
			       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', '完成') EXE_STATUS,
			       DECODE(T.IS_PLAN_OK, '1', '是', '/') IS_PLAN_OK,
			       DECODE(T.GPREQ_IF_OK, '1', '是', '/') GPREQ_IF_OK,
			       DECODE(T.GPREQ_IF_DZ, '1', '是', '/') GPREQ_IF_DZ,       
			       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.TUBE_END_RATIO,
			       TO_NUMBER(NVL(T.GPREQ_NUM,0)) GPREQ_NUM,
			       TO_NUMBER(NVL(T.GPREQ_WEIGHT,0)) GPREQ_WEIGHT,
			       T.PLANS_NUM,
			       T.WEIGTH_S_MIN,
			       T.PRIORITY,
                   T.PRIORITY_MEMO,
			       DECODE(T.OUTS_BILLET_FL,'0','自炼','1','外购') OUTS_BILLET_FL,
                  T.WHOLE_BACKLOG_DESC,
                  T.PLINE_NAME_ZZ,
                  T.OUTDIAMETER_ZG,
                  T.WALLTHICK_ZG,
                  T.GRADENAME_LK,T.CIC_GROUP_LK,  NVL(T.GPREQ_WEIGHT_MIN,0) GPREQ_WEIGHT_MIN,
       T2.GRADECODE_ALL,
       (SELECT C.ABRVITION FROM SLM_BASE_CUSTOMER C WHERE C.CUSTOMER_NO=T1.FINAL_USER )FINAL_USER_DESC,
        (SELECT LISTAGG(S.STATION_DESC, ',') WITHIN GROUP(ORDER BY S.STATION_CODE)
          FROM CRAFT_ORD_DESIGN_MSC_PL_STI S,
               CRAFT_ORD_DESIGN            C,
               CRAFT_ORD_DESIGN_MSC_PL_PRC C1
         WHERE S.DESGIN_KEY = C1.DESGIN_KEY
           AND S.MSC_PLINE = C1.MSC_PLINE
           AND S.PROCESS_CODE = C1.PROCESS_CODE
           AND C.ORD_LN_PK = T1.ORD_LN_PK
           AND C.CRAFT_SEQ = T2.CRAFT_SEQ
           AND C1.DESGIN_KEY = C.DESGIN_KEY
           AND C1.MSC_PLINE = T2.INDEX_SEQ
           AND C1.PROCESS_CODE IN ('A','B','C')) STATION_ROAD_LG,
       DECODE((SELECT TO_CHAR(WM_CONCAT(PRL.STATION_CODE))
                FROM SLM_ORDER_LINE_PRDCR_LST PRL, SLM_ORDER_LINE_PRDCR PR
               WHERE PRL.PRDCR_NO = PR.PRDCR_NO
                 AND PRL.PRDCR_INDEX = PR.PRDCR_INDEX
                 AND PRL.PROCESS_CODE = 'A'
                 AND PR.PRDCR_NO = T.PRDCR_NO
                 AND PR.CODE_JG IS NULL
                 AND PR.CODE_BL IS NULL
                 AND PR.MSC_PLINE = T2.INDEX_SEQ),
              NULL,
              '否',
              '是') IF_MONITOR_LG,
              T1.PRODUCNAME,Q1.CRAFT_PATH,
              (SELECT GET_GP_MAT_NUM_ZL(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) FURNANUM,
       (SELECT GET_GP_MAT_WT_ZL(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) FURNAWEIGHT,
       (SELECT GET_GP_MAT_NUM(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) PEND_NUM,
       (SELECT GET_GP_MAT_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) PEND_WEIGHT,
       (SELECT GET_GP_PLNZGM_NUM(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJNUM,
       (SELECT GET_GP_PLNZGM_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJWEIGHT,
         (SELECT GET_GP_WT_CK(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) CK_WEIGHT,
       (SELECT GET_GP_NUM_CK(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) CK_NUM,
       (SELECT GET_ZG_REDUCED_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) REDUCED_WT,
       T1.SUPPLY_UNIT_CODE,
       T1.SUPPLY_UNIT,
       DECODE(T1.TYPE_FLAG,'1','双经销','0','非双经销') TYPE_FLAG
  FROM PLN_ORDER_ZG_S T, PLN_SALEORD T1, PLN_SALEORD_PROC T2,CRAFT_ORD_DESIGN Q1
 WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
   AND T.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
   AND T.PLN_DIVIDE_ID = T2.PLN_DIVIDE_ID
   AND T1.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
   AND Q1.ORD_LN_PK=T1.ORD_LN_PK
   AND Q1.CRAFT_SEQ=T.CRAFT_SEQ
   AND T.VALIDFLAG='1'
  
		]]>
	</query>

	<query id="CorePlnZgMStoGp.queryZgMSStatus" desc="查询轧管订单排产">
		<![CDATA[
	SELECT T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.INWL_ID,
       T.INWL_DESC,
       T.EXE_STATUS,
       T.GPREQ_ID,
       nvl(T.WEIGTH_S,0) WEIGTH_S,
       Nvl(T.WEIGTH_S_MIN,0) WEIGTH_S_MIN,
       T.NUM_S,
       NVL(T.ADD_WT_IN,0) ADD_WT_IN,
       T.CIC_GROUP_GP,
       T.CIC_GP,
       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.LEN_ROLL_MAX,
       T.LEN_ROLL_MIN,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.DIAMETER_GP,
       T.LEN_GP_SINGLE,
       T.LEN_CUTHEAD,
       T.LEN_CUTEND,
       T.PLINE_CODE,
       T.PLINE_NAME,
       B.LENGTH_COLDBED,
       T.ROLL_LENGTH,
       NVL(B.LENGTH_MAX_RING, 0) LENGTH_MAX_RING,
       B.BURNOUT_RATE,
       NVL(B.LENGTH_MAX_TUBE, 0) LENGTH_MAX_TUBE,
       NVL(B.LENGTH_MIN_TUBE, 0) LENGTH_MIN_TUBE,
       NVL(B.TOLERANCE_ZONE, 0) TOLERANCE_ZONE,
       T1.MODEL_DESC,
       T1.SIGL_LEN,
       T1.SHRT_STOVE,
       T1.SHRT_LEN_RATO,
       T1.SHORTEST,
       T1.LENGTHMAX,
       T1.LENGTHMIN,
       T1.OUTDIAMETER,
       T1.WALLTHICK,
       T1.TOTLENGTH,
       T1.ORDER_UNIT,
       T1.LEN_NO,
       NVL(T1.AVG_LEN_MIN, 0) AVG_LEN_MIN,
       M.PLAN_WT,
       M.PLAN_NUM,
       M.PLAN_WT_MAX,
       M.PLAN_WT_MIN,
       J.CHECK_J_VAL,
       L.INSPECTION_VALUE,
       DECODE(M.PLAN_NUM, NULL, 0, 0, 0, T.NUM_S / M.PLAN_NUM) RATE,
       NVL(T.DIAMETER_MANDREL, 0) DIAMETER_MANDREL,
       T.PASS_NAME,
       NVL(T.AIMWALLTHICK_OLD, 0) AIMWALLTHICK_OLD,
       NVL(T.WEIGTH_S_OLD, 0) WEIGTH_S_OLD,
       NVL(T.NUM_S_OLD, 0) NUM_S_OLD,
       (SELECT DESGIN_KEY
          FROM CRAFT_ORD_DESIGN O
         WHERE O.ORD_LN_PK = T1.ORD_LN_PK
           AND O.CRAFT_SEQ = T.CRAFT_SEQ) DESGIN_KEY,
       T.INDEX_SEQ,
       NVL(T1.ENDLEN_SPECSTD, 0) ENDLEN_SPECSTD,
       NVL(T.OUTNUM_CUT, 0) OUTNUM_CUT,
       NVL(T.AIMLENGTH, 0) AIMLENGTH,
       T.SIC_GP,
       T.SIC,
       T.PRO_MONTH,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.OUTS_BILLET_FL,
       L.OUTS_STL_PIPE_FL,
       L.LEN_DESC,
       L.LEN_MIN,
       L.LEN_MAX,
       L.CREATE_NAME FOUNDER_NAME,
       T1.LEN_NO_N,
       T.IS_PLAN_OK,
       T.IF_STOVE_ISSUED,
       T.CRAFT_FILE_NO,
       T.CRAFT_SEQ,
       T.ORDER_SOURCE,
       T1.ORD_LN_PK,
       T.ORD_LN_DLY_PK ,
       T1.LENGTHDISC_N,
       T.PASSIVE,
       T.VERIFY1,
       T.TUBE_END_RATIO,
       T.BOM,
       T.INDEX_SEQ,
       T.WHOLE_BACKLOG_DESC,
       (SELECT COUNT(*) FROM PLN_ZY_ZG_M T2 WHERE T2.PRO_PLAN_ID=T.PRO_PLAN_ID AND T2.GX_PLAN_NO=T.GX_PLAN_NO) COUNTZY
  FROM PLN_ORDER_ZG_S T
  LEFT JOIN PLN_GX_ZG_M M
    ON M.PRO_PLAN_ID = T.PRO_PLAN_ID
  LEFT JOIN COM_BASE_PLINE B
    ON B.PLINE_CODE = T.PLINE_CODE
  LEFT JOIN PLN_SALEORD T1
    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
  LEFT JOIN SLM_ORDER_LINE L
    ON L.ORD_LN_PK = T1.ORD_LN_PK
  LEFT JOIN COM_MSC_JG J
    ON J.CODE_JG = T1.CODE_JG
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
			   AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectZgMsDbk" desc="查询轧管是否经过镦拔扩">
		<![CDATA[
			SELECT T.INWL_ID,
			       T.OUTWL_ID,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       P.CROP_HEAD,
			       P.CROP_END,
			       P.UPSETTING_LENGTH,
			       (select nvl(BURNOUT_RATE,0) from COM_BASE_PLINE where PLINE_CODE=t.pline_code) BURNOUT_RATE_DBK
			  FROM PLN_ORDER_DBK_S T
			  LEFT JOIN SLM_BASE_MATERIAL_E_PL P
			    ON P.IN_MATERIAL_NO = T.INWL_ID
			   AND P.OUT_MATERIAL_NO = T.OUTWL_ID
			   AND P.PLINE_CODE = T.PLINE_CODE
			 WHERE T.PREV_GXPLAN_ID = ?
		]]>
	</query>


	<query id="CorePlnZgMStoGp.selectAfterDProcess" desc="查询轧管之后 的工序">
		<![CDATA[
			SELECT M1.WHOLE_BACKLOG,
			       M1.PROCESS_CODE,
			       M1.PROCESS_DESC,
			       M1.PROCESS_CODE_C,
			       M1.PROCESS_DESC_C
			  FROM PLN_ORDER_ZG_S T
			  LEFT JOIN PLN_SALEORD T1
			    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			  LEFT JOIN PLN_SALEORD_PROC T2
			    ON T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			   AND T2.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.ORD_LN_PK = T1.ORD_LN_PK
			   AND M.CRAFT_SEQ = T.CRAFT_SEQ
			  LEFT JOIN CRAFT_ORD_DESIGN_MSC_PL_PRC M1
			    ON M1.DESGIN_KEY = M.DESGIN_KEY
			   AND M1.MSC_PLINE = T2.INDEX_SEQ
			   AND M1.PROCESS_CODE > 'D'
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
			   AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updateZgMsInfoWall" desc="调整控制壁厚后更新轧制信息">
		<![CDATA[
UPDATE PLN_ORDER_ZG_S T
   SET T.AIMWALLTHICK     = '#AIMWALLTHICK#',
       T.WEIGTH_S         = T.WEIGTH_S + ?,
       T.NUM_S            = T.NUM_S + ?,
       --T.PLAN_USETIME     = '#PLAN_USETIME#',
       --T.PLAN_TIME_E      = TO_DATE('#PLAN_TIME_E#', 'YYYY-MM-DD HH24:MI:SS'),
       T.AIMWALLTHICK_OLD = ?,
       T.WEIGTH_S_OLD     = ?,
       T.NUM_S_OLD        = ?,
       T.WALL_UPDATE_USER = ?,
       T.WALL_UPDATE_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
      
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateZgMsInfo" desc="调整单倍坯长后更新轧制信息">
		<![CDATA[
		   --T.AIMWALLTHICK  = '#AIMWALLTHICK#',
		   --T.WEIGTH_S      = T.WEIGTH_S + ?,
		   --T.NUM_S         = T.NUM_S + ?,
		   --T.PLAN_USETIME  = '#PLAN_USETIME#',
		   -- T.PLAN_TIME_E   = TO_DATE('#PLAN_TIME_E#', 'YYYY-MM-DD HH24:MI:SS')
			UPDATE PLN_ORDER_ZG_S T
			   SET 
			       T.AIMLENGTH     = '#AIMLENGTH#',
			       T.LEN_GP_SINGLE = '#LEN_GP_SINGLE#',
			       T.ROLL_LENGTH   = '#ROLL_LENGTH#',
			       T.LEN_CUTHEAD   = '#LEN_CUTHEAD#',
			       T.LEN_CUTEND    = '#LEN_CUTEND#',
			       T.OUTNUM_CUT    = '#OUTNUM_CUT#'	,  
			       T.TUBE_END_RATIO='#TUBE_END_RATIO#',
			       T.VERIFY1 ='#VERIFY1#',	
			       T.VERIFY2 ='#VERIFY2#',	
			       T.VERIFY3 ='#VERIFY3#',	
			       T.GPREQ_NUM =?,	
			       T.GPREQ_WEIGHT=?,
			       T.PLAN_USETIME  = '#PLAN_USETIME#',
		           T.PLAN_TIME_E   = TO_DATE('#PLAN_TIME_E#', 'YYYY-MM-DD HH24:MI:SS'),
		           T.PLANS_NUM     ='#PLANS_NUM#',
		           T.GPREQ_WEIGHT_MIN='#GPREQ_WEIGHT_MIN#'   
			 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
			   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
			   AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.saveZgMsGpIc" desc="保存轧管订单管坯内控标准">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET 
			       T.CIC_GP       = '#CIC_GP#',
			       T.PIC_GP       = '#PIC_GP#',
			       T.SIC_GP       = '#SIC_GP#',
			       T.DIC_GP       = '#DIC_GP#',
			       T.WIC_GP       = '#WIC_GP#',
			       T.GIC_GP       = '#GIC_GP#'
			 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
			   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
			   AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectGpIcList" desc="查询管坯需求内控标准项集合">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       M1.PROCESS_CODE,
			       M1.PROCESS_DESC,
			       M2.CIC,
			       M1.PIC,
			       M1.SIC,
			       M1.DIC,
			       M1.WIC,
			       M1.GIC,
			       T.GRADECODE
			  FROM PLN_GX_ZG_M T
			  LEFT JOIN PLN_ORDER_ZG T2
			    ON T2.PRO_ORDER_NO = T.PRO_ORDER_NO
			  LEFT JOIN PLN_SALEORD T1
			    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			  LEFT JOIN SLM_ORD_DESIGN_BOM B
			    ON B.BOM = T2.BOM
			   AND B.MATERIAL_NO = T1.MATERIAL_NO
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.ORD_LN_PK = T1.ORD_LN_PK
			   AND M.CRAFT_SEQ = T2.CRAFT_SEQ
			  LEFT JOIN CRAFT_ORD_DESIGN_MSC_PL_PRC M1
			    ON M1.DESGIN_KEY = M.DESGIN_KEY
			   AND M1.MSC_PLINE = T2.INDEX_SEQ
			   AND M1.BACKLOG_SEQ = (T2.BACKLOG_SEQ - 1)
			  LEFT JOIN CRAFT_ORD_DESIGN_MSC_PL_PRC M2
			    ON M2.DESGIN_KEY = M.DESGIN_KEY
			   AND M2.MSC_PLINE = T2.INDEX_SEQ
			   AND M2.PROCESS_CODE = 'A'
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.screenCicByGrade" desc="根据钢种过滤成分">
		<![CDATA[
			SELECT T.CIC,
			       T.STDSTYLE      标准类型,
			       T.PRODUCNAME_NK 内控品名集合,
			       T.STD_NAME_NK   内控标准,
			       T.STEELNAME_NK  内控钢级集合,
			       T.GRADENAME     内控钢种集合,
			       T.MODEL_DESC_NK 内控扣型集合		       
			  FROM COM_MSC_STD_CIC T
			 WHERE 1=1
		]]>
	</query>

	<query id="CorePlnZgMStoGp.screenPic" desc="根据钢种过滤成分">
		<![CDATA[
			SELECT T.PIC,
			       T.STDSTYLE      标准类型,
			       T.PRODUCNAME_NK 内控品名集合,
			       T.STD_NAME_NK   内控标准,
			       T.STEELNAME_NK  内控钢级集合,
			       T.GRADENAME     内控钢种集合,
			       T.MODEL_DESC_NK 内控扣型集合
        	  FROM COM_MSC_STD_PIC T
		]]>
	</query>

	<query id="CorePlnZgMStoGp.screenSic" desc="根据钢种过滤成分">
		<![CDATA[
			SELECT T.SIC,
			       T.STDSTYLE      标准类型,
			       T.PRODUCNAME_NK 内控品名集合,
			       T.STEELNAME_NK  内控钢级集合,
			       T.MODEL_DESC_NK 内控扣型集合
        	  FROM COM_MSC_STD_SPEC T
		]]>
	</query>

	<query id="CorePlnZgMStoGp.screenDic" desc="根据钢种过滤成分">
		<![CDATA[
			SELECT T.DIC,
			       T.STDSTYLE      标准类型,
			       T.PRODUCNAME_NK 内控品名集合,
			       T.STD_NAME_NK   内控标准,
			       T.STEELNAME_NK  内控钢级集合,
			       T.MODEL_DESC_NK 内控扣型集合
			  FROM COM_MSC_STD_DETECTION T
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectZgMsPreviousGx" desc="查询轧管工序订单的前一炼钢工序">
		<![CDATA[
		SELECT P.WHOLE_BACKLOG,
       P.DESGIN_KEY,
       P.MSC_PLINE,
       T.BOM,
       T.MSC,
       B.B_IN_MATERIAL_NO,
       B.B_IN_MATERIAL_DESC,
       B.B_OUT_MATERIAL_NO,
       B.B_OUT_MATERIAL_DESC,    
       B.C_IN_MATERIAL_NO,
       B.C_IN_MATERIAL_DESC,
       B.C_OUT_MATERIAL_NO,
       B.C_OUT_MATERIAL_DESC
  FROM PLN_ORDER_ZG_S T
  LEFT JOIN PLN_SALEORD T1
    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
  LEFT JOIN CRAFT_ORD_DESIGN M
    ON M.ORD_LN_PK = T1.ORD_LN_PK
   AND M.CRAFT_SEQ = T.CRAFT_SEQ
  LEFT JOIN CRAFT_ORD_DESIGN_MSC_PL_PRC P
    ON P.DESGIN_KEY = M.DESGIN_KEY
   AND P.MSC_PLINE = T.INDEX_SEQ
   AND P.PROCESS_CODE = 'D'
  LEFT JOIN SLM_ORD_DESIGN_BOM B
       ON B.BOM = T.BOM
   AND B.MSC = T.MSC
   AND B.MSC_PLINE=T.INDEX_SEQ
   AND B.WHOLE_BACKLOG_DESC=T.WHOLE_BACKLOG_DESC
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectMscPlProc" desc="查询工序">
		<![CDATA[
			SELECT T.PROCESS_CODE,
			       T.PROCESS_DESC,
			       T.BACKLOG_SEQ,
			       T.WHOLE_BACKLOG,
			       T.PROCESS_CODE_C,
			       T.PROCESS_DESC_C
			  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T
			 WHERE T.DESGIN_KEY = ?
			   AND T.MSC_PLINE = ?
			   AND T.PROCESS_CODE = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectZgStoGp" desc="查询轧管订单组坯信息">
		<![CDATA[
		select WEIGTH_S,
       NUM_S,
       GPREQ_ID,
       EXE_STATUS,
       INWL_ID,
       INWL_DESC,
       GPREQ_NUM-LJ_NUM_B GPREQ_NUM,
       GPREQ_WEIGHT-LJ_WEIGHT_B  GPREQ_WEIGHT,
       PLANS_NUM,
       WEIGTH_S_MIN,
       GRADECODE,
       GRADENAME,
       DIAMETER_GP,
       LEN_GP_SINGLE,
       OUTNUM_CUT,
       PRO_PLAN_ID,
       GX_PLAN_NO,
      CASE
         WHEN IF_MONITOR_LG = '1' THEN
          PRDCR_NO
         ELSE
          ''
       END PRDCR_NO,
       SIC_GP,
       DIC_GP,
       PIC_GP,
       CIC_GP,
       WIC_GP,
       GIC_GP,
       IC_JOINT,
       IFBUYPLAN,
       IF_MONITOR_LG,
       PRO_MONTH,
       PLINE_CODE,
       PRIORITY,
       PRIORITY_MEMO,
       DESGIN_KEY,
       PROCESS,
       SUBSTR(STATION_ROAD_LG, INSTR(STATION_ROAD_LG, '真空处理', 1, 1),DECODE(INSTR(STATION_ROAD_LG, '真空处理', 1, 1),0,0,4)) STATION_ROAD_LG,
       GOWHERE_CODE,
       GOWHERE_NAME,OUTS_STL_PIPE_FL,
       SUPPLY_UNIT_CODE,
       SUPPLY_UNIT,
       TYPE_FLAG
  from (SELECT T.PLINE_CODE GOWHERE_CODE,
               T.PLINE_NAME GOWHERE_NAME,
               T.WEIGTH_S,
               T.NUM_S,
               T.GPREQ_ID,
               T.EXE_STATUS,
               T.INWL_ID,
               T.INWL_DESC,
               T.GPREQ_NUM,
               T.GPREQ_WEIGHT,
               T.PLANS_NUM,
               T.WEIGTH_S_MIN,
               T.GRADECODE,
               T.GRADENAME,
               T.DIAMETER_GP,
               T.LEN_GP_SINGLE,
               T.OUTNUM_CUT,
               T.PRO_PLAN_ID,
               T.GX_PLAN_NO,
               T.PRDCR_NO,
               T.SIC_GP,
               T.DIC_GP,
               T.PIC_GP,
               T.CIC_GP,
               T.WIC_GP,
               T.GIC_GP,
               (T.SIC_GP || ',' || T.DIC_GP || ',' || T.PIC_GP || ',' ||
               T.CIC_GP || ',' || T.WIC_GP || ',' || T.GIC_GP) IC_JOINT,
               T.OUTS_BILLET_FL IFBUYPLAN,
               DECODE((SELECT TO_CHAR(WM_CONCAT(PRL.STATION_CODE))
                        FROM SLM_ORDER_LINE_PRDCR_LST PRL
                       WHERE PRL.PRDCR_NO = PR.PRDCR_NO
                         AND PRL.PRDCR_INDEX = PR.PRDCR_INDEX
                         AND PRL.PROCESS_CODE = 'A'),
                      NULL,
                      '0',
                      '1') IF_MONITOR_LG,
               T.PRO_MONTH,
               T.PLINE_CODE,
               T.PRIORITY,
               T.PRIORITY_MEMO,
               D.DESGIN_KEY,
               (SELECT SUBSTR(WHOLE_BACKLOG_DESC,
                              0,
                              INSTR(WHOLE_BACKLOG_DESC, '轧制', '1', '1') - 2)
                  FROM CRAFT_ORD_DESIGN_MSC_PL T
                 WHERE T.DESGIN_KEY = D.DESGIN_KEY
                   AND T.MSC_PLINE = T2.INDEX_SEQ
                   AND T.VALIDFLAG = '1') PROCESS,
               (SELECT C.ABRVITION
                  FROM SLM_BASE_CUSTOMER C
                 WHERE C.CUSTOMER_NO = T1.FINAL_USER) FINAL_USER_DESC,
               (SELECT LISTAGG(S.STATION_DESC, ',') WITHIN GROUP(ORDER BY S.STATION_CODE)
                  FROM CRAFT_ORD_DESIGN_MSC_PL_STI S,
                       CRAFT_ORD_DESIGN            C,
                       CRAFT_ORD_DESIGN_MSC_PL_PRC C1
                 WHERE S.DESGIN_KEY = C1.DESGIN_KEY
                   AND S.MSC_PLINE = C1.MSC_PLINE
                   AND S.PROCESS_CODE = C1.PROCESS_CODE
                   AND C.ORD_LN_PK = T1.ORD_LN_PK
                   AND C.CRAFT_SEQ = T2.CRAFT_SEQ
                   AND C1.DESGIN_KEY = C.DESGIN_KEY
                   AND C1.MSC_PLINE = T2.INDEX_SEQ
                   AND C1.PROCESS_CODE IN ('A')) STATION_ROAD_LG,
                   T1.OUTS_STL_PIPE_FL,
                    (SELECT GET_GP_LJB_NUM(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJ_NUM_B,
                   (SELECT GET_GP_LJB_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJ_WEIGHT_B,
                   T1.SUPPLY_UNIT_CODE,
                   T1.SUPPLY_UNIT,
                   T1.TYPE_FLAG
          FROM PLN_ORDER_ZG_S T
          LEFT JOIN PLN_SALEORD T1
            ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
          LEFT JOIN PLN_SALEORD_PROC T2
            ON T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
           AND T2.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID
          LEFT JOIN SLM_ORDER_LINE_PRDCR PR
            ON PR.PRDCR_NO = T.PRDCR_NO
           AND PR.CODE_JG IS NULL
           AND PR.CODE_BL IS NULL
           AND PR.MSC_PLINE = T2.INDEX_SEQ
          LEFT JOIN CRAFT_ORD_DESIGN D
            ON D.ORD_LN_PK = T1.ORD_LN_PK
           AND D.CRAFT_SEQ = T2.CRAFT_SEQ
         WHERE T.PRO_PLAN_ID = ?
           AND T.GX_PLAN_NO = ?
           AND T.VALIDFLAG='1')
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getGpReqinfId" desc="生成管坯需求ID">
		<![CDATA[
			SELECT ? || TO_CHAR(SYSDATE, 'YYYYMM') ||
			       LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.GPREQ_ID, 11)) + 1), 1), 5, '0') GPREQ_ID
			  FROM PLN_REQINF_GP T
			 WHERE SUBSTR(T.GPREQ_ID, 5, 6) = TO_CHAR(SYSDATE, 'YYYYMM')
			 AND T.IFBUYPLAN=?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.addGpReqinf" desc="新增管坯需求记录">
		<![CDATA[
			INSERT INTO PLN_REQINF_GP
				  (GPREQ_ID,
				   GPTYPE,
				   GRADECODE,
				   GRADENAME,
				   DIAMETER_GP,
				   LEN_GP_SINGLE,
				   MATERIAL_NO,
				   MATERIAL_NAME,
				   CIC,
				   PIC,
				   SIC,
				   DIC,
				   WIC,
				   GIC,
				   IF_MONITOR_LG,
				   PRDCR_NO,
				   WEIGHT_GP_ONE,
				   GP_WEIGHT,
				   GP_NUM,
				   CUT_NUM_GP,
				   CUT_LOSE_LEN,
				   LENGTH_GP,
				   GP_WT_LONG,
				   GP_NUM_LONG,
				   IFBUYPLAN,
				   REQ_DONESTATUS,
				   MEMO,
				   CASTINGTYPE,
				   DIAMETER_ZZ,
				   LENGTH_ZZ,
				   WT_ONE_ZZ,
				   WLID_ZZ,
				   WLDESC_ZZ,
				   OUT_WT_ZZ,
				   OUT_NUM_ZZ,
				   INWL_ISOK_DZ,
				   PLINE_CODE_DZ,
				   PLINE_NAME_DZ,
				   PLINE_CODE_ZZ,
				   PLINE_NAME_ZZ,
				   DZ_LOSE_ADD,
				   DZ_CUT_HEAD_END,
				   DZ_BURN_LOSE,PRO_MONTH,REC_TYPE,WHOLE_BACKLOG_DESC,
				   CREATE_TIME,CREATE_NAME,STATION_ROAD_LG,
				   GP_WT_LONG_MIN,GP_WEIGHT_MIN,GOWHERE_NAME,GOWHERE_CODE,SUPPLY_UNIT_CODE,SUPPLY_UNIT,TYPE_FLAG)
				VALUES
				  ('#GPREQ_ID#',
				   '#GPTYPE#',
				   '#GRADECODE#',
				   '#GRADENAME#',
				   '#DIAMETER_GP#',
				   '#LEN_GP_SINGLE#',
				   '#MATERIAL_NO#',
				   '#MATERIAL_NAME#',
				   '#CIC#',
				   '#PIC#',
				   '#SIC#',
				   '#DIC#',
				   '#WIC#',
				   '#GIC#',
				   '#IF_MONITOR_LG#',
				   '#PRDCR_NO#',
				   '#WEIGHT_GP_ONE#',
				   '#GP_WEIGHT#',
				   '#GP_NUM#',
				   '#CUT_NUM_GP#',
				   '#CUT_LOSE_LEN#',
				   '#LENGTH_GP#',
				   '#GP_WT_LONG#',
				   '#GP_NUM_LONG#',
				   '#IFBUYPLAN#',
				   '#REQ_DONESTATUS#',
				   '#MEMO#',
				   '#CASTINGTYPE#',
				   '#DIAMETER_ZZ#',
				   '#LENGTH_ZZ#',
				   '#WT_ONE_ZZ#',
				   '#WLID_ZZ#',
				   '#WLDESC_ZZ#',
				   '#OUT_WT_ZZ#',
				   '#OUT_NUM_ZZ#',
				   '#INWL_ISOK_DZ#',
				   '#PLINE_CODE_DZ#',
				   '#PLINE_NAME_DZ#',
				   '#PLINE_CODE_ZZ#',
				   '#PLINE_NAME_ZZ#',
				   '#DZ_LOSE_ADD#',
				   '#DZ_CUT_HEAD_END#',
				   '#DZ_BURN_LOSE#','#PRO_MONTH#','0',?,
				   TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
				   '#CREATE_NAME#','#STATION_ROAD_LG#','#GP_WT_LONG_MIN#','#GP_WEIGHT_MIN#','#GOWHERE_NAME#','#GOWHERE_CODE#',
				   '#SUPPLY_UNIT_CODE#','#SUPPLY_UNIT#','#TYPE_FLAG#')
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updateZgMsGpReqId" desc="新增管坯铸造工序产线">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET T.GPREQ_ID = '#GPREQ_ID#',
			       T.ACTUAL_WEIGHT='#REALL_WT#'
			 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
			   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
			   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectProcessBPline" desc="查询管坯铸造工序产线">
		<![CDATA[
			SELECT T.PLINE_CODE,
       T.PLINE_NAME,
       T.PLINE_LEVEL,
       T.PRD_RATE,
       C.BURNOUT_RATE,
       C.LENGTH_MAX,
       C.LENGTH_MIN,
       T.OUT_MATERIAL_NO
  FROM SLM_BASE_MATERIAL_B_PL T, COM_BASE_PLINE C
 WHERE C.PLINE_CODE = T.PLINE_CODE
   AND C.VALIDFLAG = '1'
   AND T.IN_MATERIAL_NO = ?
   AND T.OUT_MATERIAL_NO = ?
   AND (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
   AND T.PLINE_CODE IN (SELECT B.PLINE_CODE
                          FROM CRAFT_ORD_DESIGN_MSC_PL_GX_PRL B,
                               (SELECT C.PLINE_CODE, C.SPEC_NAME
                                  FROM COM_MSC_PLINE_R_SPEC C
                                 WHERE C.VALIDFLAG = '1'
                                   AND C.WELL_CODE in ('J002','J017')
                                 GROUP BY C.PLINE_CODE, C.SPEC_NAME) B1
                         WHERE B1.PLINE_CODE=B.PLINE_CODE
                           AND B.PROCESS_CODE = 'B'
                           AND B1.SPEC_NAME=?
                           AND B.DESGIN_KEY = ?
                           AND B.MSC_PLINE = ?   
                           AND B.VALIDFLAG = '1'
		]]>
	</query>

<query id="CorePlnZgMStoGp.selectProcessBPlineNEW" desc="查询管坯铸造工序产线（新的）">
		<![CDATA[
			SELECT T.PLINE_CODE,
       T.PLINE_NAME,
       T.PLINE_LEVEL,
       T.PRD_RATE,
       C.BURNOUT_RATE,
       C.LENGTH_MAX,
       C.LENGTH_MIN,
       T.OUT_MATERIAL_NO
  FROM SLM_BASE_MATERIAL_B_PL T, COM_BASE_PLINE C
 WHERE C.PLINE_CODE = T.PLINE_CODE
   AND C.VALIDFLAG = '1'
   AND T.IN_MATERIAL_NO = ?
   AND T.OUT_MATERIAL_NO = ?
   AND (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
   AND T.PLINE_CODE IN (SELECT B.PLINE_CODE
                          FROM CRAFT_ORD_DESIGN_MSC_PL_GX_PRL B,
                               (SELECT C.PLINE_CODE, C.SPEC_NAME
                                  FROM COM_MSC_PLINE_R_SPEC C
                                 WHERE C.VALIDFLAG = '1'
                                   AND C.WELL_CODE in ('J002','J017')
                                 GROUP BY C.PLINE_CODE, C.SPEC_NAME) B1
                         WHERE B1.PLINE_CODE=B.PLINE_CODE
                           --AND B.PROCESS_CODE = 'B'
                          -- AND B1.SPEC_NAME=?
                          -- AND B.DESGIN_KEY = ?
                           --AND B.MSC_PLINE = ?   
                           AND B.VALIDFLAG = '1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectProcessBPline1" desc="新增管坯铸造工序产线">
		<![CDATA[ 
		SELECT T.PLINE_CODE,
       T.PLINE_NAME,
       T.HR_CAPCTY,
       T.PRD_RATE,
       P.LENGTH_MIN,
       P.LENGTH_MAX,
       T.IN_MATERIAL_NO,
       T1.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T1.OUT_MATERIAL_DESC,
       P.BURNOUT_RATE
  FROM SLM_BASE_MATERIAL_B_PL T
  LEFT JOIN SLM_BASE_MATERIAL_B T1
    ON T1.IN_MATERIAL_NO = T.IN_MATERIAL_NO
   AND T1.OUT_MATERIAL_NO = T.OUT_MATERIAL_NO
  LEFT JOIN COM_BASE_PLINE P
    ON P.PLINE_CODE = T.PLINE_CODE
 WHERE (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
   AND T.IN_MATERIAL_NO = ?
   AND T.OUT_MATERIAL_NO = ?
		 ]]>
	</query>
	<query id="CorePlnZgMStoGp.selectProcessBPline2" desc="新增管坯锻造工序产线">
		<![CDATA[
		SELECT T.PLINE_CODE,
       T.PLINE_NAME,
       T.HR_CAPCTY,
       T.PRD_RATE,
       P.LENGTH_MIN,
       P.LENGTH_MAX,
       T.IN_MATERIAL_NO,
       T1.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T1.OUT_MATERIAL_DESC,
       P.BURNOUT_RATE
  FROM SLM_BASE_MATERIAL_C_PL T
  LEFT JOIN SLM_BASE_MATERIAL_C T1
    ON T1.IN_MATERIAL_NO = T.IN_MATERIAL_NO
   AND T1.OUT_MATERIAL_NO = T.OUT_MATERIAL_NO
  LEFT JOIN COM_BASE_PLINE P
    ON P.PLINE_CODE = T.PLINE_CODE
 WHERE (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
   AND T.OUT_MATERIAL_NO = ?
		 ]]>
	</query>
	<query id="CorePlnZgMStoGp.selectProcessCPline" desc="查询管坯锻造工序产线">
		<![CDATA[
			SELECT T.PLINE_CODE,
              T.PLINE_NAME,
              T.PLINE_LEVEL,
              T.PRD_RATE,
              C.BURNOUT_RATE,
              C.LENGTH_MIN,
              C.LENGTH_MAX
         FROM SLM_BASE_MATERIAL_C_PL T, COM_BASE_PLINE C
        WHERE C.PLINE_CODE = T.PLINE_CODE
          AND C.VALIDFLAG = '1'
          AND T.IN_MATERIAL_NO = ?
          AND T.OUT_MATERIAL_NO = ?
          AND (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
          AND T.PLINE_CODE IN
              (SELECT B.PLINE_CODE
                 FROM CRAFT_ORD_DESIGN_MSC_PL_GX_PRL B
                WHERE B.PROCESS_CODE = 'C'
                  AND B.DESGIN_KEY = ?
                  AND B.MSC_PLINE = ?
                  AND B.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectProcessCPline1" desc="获取锻造产线">
		<![CDATA[ SELECT T.PLINE_CODE,
       T.PLINE_NAME,
       T.HR_CAPCTY,
       T.PRD_RATE,
       P.LENGTH_MIN,
       P.LENGTH_MAX,
       T.IN_MATERIAL_NO,
       T1.IN_MATERIAL_DESC,
       T.OUT_MATERIAL_NO,
       T1.OUT_MATERIAL_DESC,
       P.BURNOUT_RATE
  FROM SLM_BASE_MATERIAL_C_PL T
  LEFT JOIN SLM_BASE_MATERIAL_C T1
    ON T1.IN_MATERIAL_NO = T.IN_MATERIAL_NO
   AND T1.OUT_MATERIAL_NO = T.OUT_MATERIAL_NO
  LEFT JOIN COM_BASE_PLINE P
    ON P.PLINE_CODE = T.PLINE_CODE
 WHERE (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
   AND T.IN_MATERIAL_NO = ?
   AND T.OUT_MATERIAL_NO = ?
 ]]>
	</query>
	<query id="CorePlnZgMStoGp.deleteGpReq" desc="删除管坯需求">
		<![CDATA[
			DELETE FROM PLN_REQINF_GP T WHERE T.GPREQ_ID = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updateZgMsGpReqIdByGpId" desc="删除时修改轧管管坯需求号，状态">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET T.GPREQ_ID = ?,
			    T.GPREQ_IF_OK='0',
			    T.GPREQ_IF_DZ='0'
			 WHERE T.GPREQ_ID = ?
			 AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectGpReqStatus" desc="查询管坯需求状态">
		<![CDATA[
SELECT T.REQ_DONESTATUS,
       T.GP_NUM,
       T.REC_TYPE,
       T.CASTINGTYPE,
       T.GPTYPE,
       T.DIAMETER_ZZ,
       T.DIAMETER_GP,
       T.LEN_GP_SINGLE,
       T.CUT_LOSE_LEN,
       T.DZ_BURN_LOSE,
       T.DZ_LOSE_ADD,
       T.DZ_CUT_HEAD_END,
       T.LENGTH_GP,
       T.CUT_NUM_GP,
       T.REQ_STATUS,
       T.IFBUYPLAN
  FROM PLN_REQINF_GP T
 WHERE T.GPREQ_ID = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getZgMsStatus" desc="查询订单管坯状态">
		<![CDATA[
			SELECT T.WEIGTH_S,
			       T.NUM_S,
			       T.EXE_STATUS,
			       T.OUTNUM_CUT,
			       T.PRO_PLAN_ID,
			       T.GX_PLAN_NO,
			       T1.GPREQ_ID,
			       T1.REQ_DONESTATUS,
			       T.GRADECODE,
			       T.GRADENAME,
			       T.DIAMETER_GP,
			       T.LEN_GP_SINGLE,
			       T.GPREQ_NUM,
			       T.GPREQ_WEIGHT
			  FROM PLN_ORDER_ZG_S T
			  left JOIN PLN_REQINF_GP T1
			    ON T1.GPREQ_ID = T.GPREQ_ID
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
			   AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updateGpReqAmunt" desc="更新管坯需求量">
		<![CDATA[
			UPDATE PLN_REQINF_GP T
			   SET T.GP_WEIGHT   = T.GP_WEIGHT * (1 - '#RATE#'),
			       T.GP_NUM      = FLOOR(T.GP_NUM * (1 - '#RATE#')),
			       T.GP_WT_LONG  = T.GP_WT_LONG * (1 - '#RATE#'),
			       T.GP_NUM_LONG = FLOOR(T.GP_NUM_LONG * (1 - '#RATE#'))
			 WHERE T.GPREQ_ID = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateGpReqWetNum" desc="更新管坯需求量">
		<![CDATA[
		UPDATE PLN_REQINF_GP T
   SET T.GP_WEIGHT   = TO_NUMBER(T.GP_WEIGHT) - TO_NUMBER(?),
       T.GP_NUM      = TO_NUMBER(T.GP_NUM) - TO_NUMBER(?),
       T.GP_WT_LONG  = TO_NUMBER(T.GP_WT_LONG) - TO_NUMBER(?),
       T.GP_NUM_LONG = TO_NUMBER(T.GP_NUM_LONG) - TO_NUMBER(?)
 WHERE T.GPREQ_ID = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.getMscCastRForg" desc="获取锻造对应铸造规格">
		<![CDATA[
			SELECT T.SPEC_CODE_FORG,
			       T.SPEC_NAME_FORG,
			       T.SPEC_CODE_INGOT,
			       T.SPEC_NAME_INGOT,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       (S2.WEIGHT / 1000) WEIGHT,
			       S1.DIMATER,
			       S2.ACTUAL_WEIGHT,
                   S2.GROSS_RATE,
                   S2.GROSS_WETGHT
			  FROM COM_MSC_CAST_R_FORG T
			  LEFT JOIN COM_BASE_SPEC S2
			    ON S2.SPEC_CODE = T.SPEC_CODE_INGOT
			   AND S2.VALIDFLAG = '1'
			   AND S2.MSC_STYLE = 'D'
			  LEFT JOIN COM_BASE_SPEC S1
			    ON S1.SPEC_CODE = T.SPEC_CODE
			   AND S1.VALIDFLAG = '1'
			   AND S1.MSC_STYLE = 'B', COM_BASE_SPEC S
			 WHERE T.VALIDFLAG = '1'
			   AND T.SPEC_CODE_FORG = S.SPEC_CODE
			   AND S.MSC_STYLE = 'B'
			   AND S.VALIDFLAG = '1'
			   AND S.DIMATER = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getMscCastRForgGpid" desc="获取锻造对应铸造规格">
		<![CDATA[
			SELECT T.SPEC_CODE_FORG,
			       T.SPEC_NAME_FORG,
			       T.SPEC_CODE_INGOT,
			       T.SPEC_NAME_INGOT,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       (S2.WEIGHT / 1000) WEIGHT,
			       S1.DIMATER,
			       S2.ACTUAL_WEIGHT,
                   S2.GROSS_RATE,
                   S2.GROSS_WETGHT
			  FROM COM_MSC_CAST_R_FORG T
			  LEFT JOIN COM_BASE_SPEC S2
			    ON S2.SPEC_CODE = T.SPEC_CODE_INGOT
			   AND S2.VALIDFLAG = '1'
			   AND S2.MSC_STYLE = 'D'
			  LEFT JOIN COM_BASE_SPEC S1
			    ON S1.SPEC_CODE = T.SPEC_CODE
			   AND S1.VALIDFLAG = '1'
			   AND S1.MSC_STYLE = 'B', COM_BASE_SPEC S, PLN_REQINF_GP T1
			 WHERE T.VALIDFLAG = '1'
			   AND T.SPEC_CODE_FORG = S.SPEC_CODE
			   AND S.MSC_STYLE = 'B'
			   AND S.VALIDFLAG = '1'
			   AND S.DIMATER = T1.DIAMETER_GP
			   AND T1.GPREQ_ID = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getZgMsInMaterial" desc="查询轧管投料">
		<![CDATA[
			 select B.D_IN_MATERIAL_NO,
               B.D_IN_MATERIAL_DESC,
               B.GRADECODE,
               B.GRADENAME,
               NVL(B.SPEC_NAME_D, B.SPEC_NAME_Z) SPEC_GP,
               S.DIMATER,B.BOM,T.DIAMETER_GP
             FROM PLN_ORDER_ZG_S T, PLN_SALEORD P,CRAFT_ORD_DESIGN D,CRAFT_ORD_LINE_BOM C,SLM_ORD_DESIGN_BOM B
             LEFT JOIN COM_BASE_SPEC S
               ON S.SPEC_CODE = NVL(B.SPEC_CODE_D, B.SPEC_CODE_Z)
               AND S.VALIDFLAG = '1'
             where t.ORD_LN_DLY_PK = p.ORD_LN_DLY_PK and p.ord_ln_pk=d.ord_ln_pk 
               and t.CRAFT_SEQ=d.CRAFT_SEQ and d.desgin_key=c.desgin_key and c.bom=b.bom
			   AND T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
			   AND T.VALIDFLAG='1'
			   
		]]>
	</query>

	<query id="CorePlnZgMStoGp.selectDMaterial" desc="查询轧管投料编码名称">
		<![CDATA[
			SELECT T.IN_MATERIAL_NO, T.IN_MATERIAL_DESC
			  FROM SLM_BASE_MATERIAL_D T
			 GROUP BY T.IN_MATERIAL_NO, T.IN_MATERIAL_DESC
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updateZgMsInMaterial" desc="更新轧管订单投料">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET T.INWL_ID     = '#INWL_ID#',
			       T.INWL_DESC   = '#INWL_DESC#',
			       T.GRADECODE   = '#GRADECODE#',
			       T.GRADENAME   = '#GRADENAME#',
			       T.BOM          ='#BOM#',
			       T.CIC_GP       ='#CIC_GP#'
			 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
			   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
			   AND T.VALIDFLAG='1'
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updateGpReqinfDz" desc="更新管坯需求锻造到铸造">
		<![CDATA[
			UPDATE PLN_REQINF_GP T
			   SET T.CUT_NUM_GP      = '#CUT_NUM_GP#',
			       T.CUT_LOSE_LEN    = '#CUT_LOSE_LEN#',
			       T.LENGTH_GP       = '#LENGTH_GP#',
			       T.GP_WT_LONG      = '#GP_WT_LONG#',
			       T.GP_NUM_LONG     = '#GP_NUM_LONG#',
			       T.DIAMETER_ZZ     = '#DIAMETER_ZZ#',
			       T.LENGTH_ZZ       = '#LENGTH_ZZ#',
			       T.WT_ONE_ZZ       = '#WT_ONE_ZZ#',
			       T.WLID_ZZ         = '#WLID_ZZ#',
			       T.WLDESC_ZZ       = '#WLDESC_ZZ#',
			       T.OUT_WT_ZZ       = '#OUT_WT_ZZ#',
			       T.OUT_NUM_ZZ      = '#OUT_NUM_ZZ#',
			       T.INWL_ISOK_DZ    = '#INWL_ISOK_DZ#',
			       T.PLINE_CODE_DZ   = '#PLINE_CODE_DZ#',
			       T.PLINE_NAME_DZ   = '#PLINE_NAME_DZ#',
			       T.PLINE_CODE_ZZ   = '#PLINE_CODE_ZZ#',
			       T.PLINE_NAME_ZZ   = '#PLINE_NAME_ZZ#',
			       T.DZ_LOSE_ADD     = '#DZ_LOSE_ADD#',
			       T.DZ_CUT_HEAD_END = '#DZ_CUT_HEAD_END#',
			       T.DZ_BURN_LOSE    = '#DZ_BURN_LOSE#',
			       T.GP_WT_LONG_MIN  ='#GP_WT_LONG_MIN#'
			 WHERE T.GPREQ_ID = '#GPREQ_ID#'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateGpReqinfDzAdd" desc="新增时条件同一管坯需求号修改">
		<![CDATA[
	UPDATE PLN_REQINF_GP T
   SET T.GP_WEIGHT   = TO_NUMBER(T.GP_WEIGHT) + TO_NUMBER('#GP_WEIGHT#'),
       T.GP_NUM      = TO_NUMBER(T.GP_NUM) + TO_NUMBER('#GP_NUM#'),
       T.GP_WT_LONG  = TO_NUMBER(T.GP_WT_LONG) + TO_NUMBER('#GP_WT_LONG#'),
       T.GP_NUM_LONG = TO_NUMBER(T.GP_NUM_LONG) + TO_NUMBER('#GP_NUM_LONG#'),
       T.OUT_WT_ZZ   = TO_NUMBER(T.OUT_WT_ZZ) + TO_NUMBER('#OUT_WT_ZZ#'),
       T.OUT_NUM_ZZ  = TO_NUMBER(T.OUT_NUM_ZZ) + TO_NUMBER('#OUT_NUM_ZZ#'),
       T.GP_WT_LONG_MIN   = TO_NUMBER(T.GP_WT_LONG_MIN) + TO_NUMBER('#GP_WT_LONG_MIN#'),
       T.GP_WEIGHT_MIN      = TO_NUMBER(T.GP_WEIGHT_MIN) + TO_NUMBER('#GP_WEIGHT_MIN#')
 WHERE T.GPREQ_ID = '#GPREQ_ID#'

		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectReqinfGpStatus" desc="查询管坯需求">
		<![CDATA[
			SELECT T.GPREQ_ID,
			       T.ISENDGX,
			       T.GPTYPE,
			       T.GRADECODE,
			       T.GRADENAME,
			       T.DIAMETER_GP,
			       T.LEN_GP_SINGLE,
			       T.MATERIAL_NO,
			       T.MATERIAL_NAME,
			       T.CIC,
			       T.PIC,
			       T.SIC,
			       T.DIC,
			       T.WIC,
			       T.GIC,
			       T.IF_MONITOR_LG,
			       T.PRDCR_NO,
			       T.WEIGHT_GP_ONE,
			       T.GP_WEIGHT,
			       T.GP_NUM,
			       T.CUT_NUM_GP,
			       T.CUT_LOSE_LEN,
			       T.LENGTH_GP,
			       T.GP_WT_LONG,
			       T.GP_NUM_LONG,
			       T.IFBUYPLAN,
			       T.BUYPLANID,
			       T.BUYPLAN_WT_LONG,
			       T.BUYPLAN_NUM_ONE,
			       T.BUYPLAN_NUM_LONG,
			       T.PPC_LG_WT_LONG,
			       T.PPC_LG_NUM_ONE,
			       T.PPC_LG_NUM_LONG,
			       T.PRO_PLAN_ID_DZ,
			       T.PRO_PLAN_ID_ZZ,
			       T.REQ_DONESTATUS,
			       T.CASTINGTYPE,
			       T.DIAMETER_ZZ,
			       T.LENGTH_ZZ,
			       T.WT_ONE_ZZ,
			       T.WLID_ZZ,
			       T.WLDESC_ZZ,
			       T.OUT_WT_ZZ,
			       T.OUT_NUM_ZZ,
			       T.INWL_ISOK_DZ,
			       T.PLINE_CODE_DZ,
			       T.PLINE_NAME_DZ,
			       T.PLINE_CODE_ZZ,
			       T.PLINE_NAME_ZZ,
			       T.DZ_LOSE_ADD,
			       T.DZ_CUT_HEAD_END,
			       T.DZ_BURN_LOSE,
			       T.PRO_MONTH,
			       T.REC_TYPE,
			       T.REQ_STATUS,
			       nvl(T.GP_WT_LONG_MIN,0) GP_WT_LONG_MIN,
			       nvl(T.GP_WEIGHT_MIN,0) GP_WEIGHT_MIN,T.GOWHERE_NAME,T.GOWHERE_CODE
			  FROM PLN_REQINF_GP T
			 WHERE T.GPREQ_ID = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getPlnGxCastMPlanId" desc="生产铸造工序订单订单号">
		<![CDATA[
			SELECT 'ZZ_' || TO_CHAR(SYSDATE, 'YYYYMM') ||
				          LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.PRO_PLAN_ID, 10)) + 1), 1),
				               5,
				               '0') AS PLAN_ID
				     FROM PLN_GX_CAST_M T
				    WHERE SUBSTR(T.PRO_PLAN_ID, 4, 6) = TO_CHAR(SYSDATE, 'YYYYMM')
		]]>
	</query>

	<query id="CorePlnZgMStoGp.getPlnGxGpMPlanId" desc="生产锻造工序订单订单号">
		<![CDATA[
			SELECT ('DZ_' || TO_CHAR(SYSDATE, 'YYYYMM') ||
				          LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.PRO_PLAN_ID, 10)) + 1), 1),
				                5,
				                '0')) AS PLAN_ID
				     FROM PLN_GX_DP_M T
				    WHERE SUBSTR(T.PRO_PLAN_ID, 4, 6) = TO_CHAR(SYSDATE, 'YYYYMM')
		]]>
	</query>


	<query id="CorePlnZgMStoGp.addPlnGxCastM" desc="新增铸造订单">
		<![CDATA[
			INSERT INTO PLN_GX_CAST_M
				  (PRO_PLAN_ID,
				   GPTYPE,
				   CASTINGTYPE,
				   PLINE_CODE_MAY,
				   PLINE_NAME_MAY,
				   GRADECODE,
				   GRADENAME,
				   DIAMETER_LZ,
				   LEN_GP_SINGLE,
				   CUT_NUM_GP,
				   CUT_LOSE_LEN,
				   LENGTH_LZ,
				   MATERIAL_NO,
				   MATERIAL_NAME,
				   CIC,
				   PIC,
				   SIC,
				   DIC,
				   WIC,
				   GIC,
				   IF_MONITOR_LG,
				   PRDCR_NO,
				   MONITOR_POINT,
				   WT_CAST_ONE,
				   PLAN_WT,
				   PLAN_NUM,
				   REQ_STATUS,
				   CREATE_NAME,
				   CREATE_TIME,PLINE_CODE,PLINE_NAME)
				VALUES
				  ('#PRO_PLAN_ID#',
				   '#GPTYPE#',
				   '#CASTINGTYPE#',
				   '#PLINE_CODE_MAY#',
				   '#PLINE_NAME_MAY#',
				   '#GRADECODE#',
				   '#GRADENAME#',
				   '#DIAMETER_LZ#',
				   '#LEN_GP_SINGLE#',
				   '#CUT_NUM_GP#',
				   '#CUT_LOSE_LEN#',
				   '#LENGTH_LZ#',
				   '#MATERIAL_NO#',
				   '#MATERIAL_NAME#',
				   '#CIC#',
				   '#PIC#',
				   '#SIC#',
				   '#DIC#',
				   '#WIC#',
				   '#GIC#',
				   '#IF_MONITOR_LG#',
				   '#PRDCR_NO#',
				   '#MONITOR_POINT#',
				   '#WT_CAST_ONE#',
				   '#PLAN_WT#',
				   '#PLAN_NUM#',
				   '#REQ_STATUS#',
				   '#CREATE_NAME#',
				   TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
				   '#PLINE_CODE#','#PLINE_NAME#')
		]]>
	</query>

	<query id="CorePlnZgMStoGp.addPlnGxDpM" desc="新增锻造订单">
		<![CDATA[
			INSERT INTO PLN_GX_DP_M
				  (PRO_PLAN_ID,
				   PLINE_CODE_MAY,
				   PLINE_NAME_MAY,
				   PLINE_CODE,
				   PLINE_NAME,
				   CASTINGTYPE,
				   GRADECODE,
				   GRADENAME,
				   DIAMETER_OUT,
				   LEN_GP_SINGLE,
				   CUT_NUM_GP,
				   LENGTH_OUT,
				   OUTWL_ID,
				   OUTWL_DESC,
				   OUT_WT_ONE,
				   OUT_WT_TOT,
				   OUT_NUM_TOT,
				   DIAMETER_IN,
				   LENGTH_IN,
				   WT_ONE_IN,
				   WLID_IN,
				   WLDESC_IN,
				   IN_WT,
				   IN_NUM,
				   ZZ_PRO_PLAN_ID,
				   IF_MONITOR_DZ,
				   PRDCR_NO,
				   MONITOR_POINT,
				   CIC,
				   PIC,
				   SIC,
				   DIC,
				   WIC,
				   GIC,
				   PRO_MONTH,
				   PLANSTATUS,
				   CREATE_NAME,
				   CREATE_TIME)
				VALUES
				  ('#PRO_PLAN_ID#',
				   '#PLINE_CODE_MAY#',
				   '#PLINE_NAME_MAY#',
				   '#PLINE_CODE#',
				   '#PLINE_NAME#',
				   '#CASTINGTYPE#',
				   '#GRADECODE#',
				   '#GRADENAME#',
				   '#DIAMETER_OUT#',
				   '#LEN_GP_SINGLE#',
				   '#CUT_NUM_GP#',
				   '#LENGTH_OUT#',
				   '#OUTWL_ID#',
				   '#OUTWL_DESC#',
				   '#OUT_WT_ONE#',
				   '#OUT_WT_TOT#',
				   '#OUT_NUM_TOT#',
				   '#DIAMETER_IN#',
				   '#LENGTH_IN#',
				   '#WT_ONE_IN#',
				   '#WLID_IN#',
				   '#WLDESC_IN#',
				   '#IN_WT#',
				   '#IN_NUM#',
				   '#ZZ_PRO_PLAN_ID#',
				   '#IF_MONITOR_DZ#',
				   '#PRDCR_NO#',
				   '#MONITOR_POINT#',
				   '#CIC#',
				   '#PIC#',
				   '#SIC#',
				   '#DIC#',
				   '#WIC#',
				   '#GIC#',
				   '#PRO_MONTH#',
				   '#PLANSTATUS#',
				   '#CREATE_NAME#',
				   TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'))
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updateReqinfGpConfirm" desc="管坯需求确认">
		<![CDATA[
			UPDATE PLN_REQINF_GP T
			   SET T.PRO_PLAN_ID_DZ = '#PRO_PLAN_ID_DZ#',
			       T.PRO_PLAN_ID_ZZ = '#PRO_PLAN_ID_ZZ#',
			       T.REQ_DONESTATUS = '#REQ_DONESTATUS#',
			       T.REQ_STATUS=?,
			       T.ISSUED_TIME =TO_DATE('#ISSUED_TIME#','YYYY-MM-DD HH24:MI:SS'),
			       T.ISSUED_MAN     ='#ISSUED_MAN#',
			       T.INWL_ISOK_DZ   ='#INWL_ISOK_DZ#'
			 WHERE T.GPREQ_ID = '#GPREQ_ID#'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnOrderZgGpStart" desc="更新轧管订单需求确认标志">
		<![CDATA[
		  UPDATE PLN_ORDER_ZG_S T
         SET T.GPREQ_IF_OK =?
       WHERE T.GPREQ_ID = ?
       AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.deletePlanCastM" desc="删除铸造订单">
		<![CDATA[
			DELETE FROM PLN_GX_CAST_M T WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.deletePlanDpM" desc="删除锻造订单">
		<![CDATA[
			DELETE FROM PLN_GX_DP_M T WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CorePlnZgMStoGp.updatePlnOrderZgS" desc="重新计算更新轧管排产耗时表">
		<![CDATA[
UPDATE PLN_ORDER_ZG_S T
   SET T.LEN_ROLL_MAX     = '#LEN_ROLL_MAX#',
       T.LEN_ROLL_MIN     = '#LEN_ROLL_MIN#',
       T.AIMOUTDIAMETER   = '#AIMOUTDIAMETER#',
       T.AIMWALLTHICK     = '#AIMWALLTHICK#',
       T.AIMLENGTH        = '#AIMLENGTH#',
       T.DIAMETER_GP      = '#DIAMETER_GP#',
       T.LEN_GP_SINGLE    = '#LEN_GP_SINGLE#',
       T.ROLL_LENGTH      = '#ROLL_LENGTH#',
       T.LEN_CUTHEAD      = '#LEN_CUTHEAD#',
       T.LEN_CUTEND       = '#LEN_CUTEND#',
       T.OUTNUM_CUT       = '#OUTNUM_CUT#',
       T.DIAMETER_MANDREL = '#DIAMETER_MANDREL#',
       T.PASS_CODE        = '#PASS_CODE#',
       T.PASS_NAME        = '#PASS_NAME#',
       T.IN_WEIGHT_S      = '#IN_WEIGHT_S#',
       T.IN_NUM_S         = '#IN_NUM_S#',
       T.ADD_WT_IN        = '#ADD_WT_IN#',
       T.ADD_NUM_IN       = '#ADD_NUM_IN#',
       T.PLAN_USETIME     = '#PLAN_USETIME#',
       T.PLAN_TIME_B      = TO_DATE('#PLAN_TIME_B#','YYYY-MM-DD HH24:MI:SS'),
       T.PLAN_TIME_E      = TO_DATE('#PLAN_TIME_E#','YYYY-MM-DD HH24:MI:SS'),
       T.GPREQ_NUM        = '#GPREQ_NUM#',
       T.GPREQ_WEIGHT     = '#GPREQ_WEIGHT#',
       T.VERIFY1          = '#VERIFY1#',
       T.VERIFY2          = '#VERIFY2#',
       T.VERIFY3          = '#VERIFY3#',
       T.PLANS_NUM        = '#PLANS_NUM#',
       T.THICKNESS_WALL   = '#THICKNESS_WALL#',
       T.PROD_STANDARD    ='#PROD_STANDARD#',
       T.OUTPUT_STANDARD  ='#OUTPUT_STANDARD#',
       T.DECISION         ='#DECISION#',
       T.WEIGTH_S         ='#WEIGTH_S#',
       T.NUM_S            ='#NUM_S#',
       T.WEIGTH_S_MIN     ='#WEIGTH_S_MIN#',
       T.GPREQ_WEIGHT_MIN    ='#GPREQ_WEIGHT_MIN#',
       T.OUTDIAMETER_ZG ='#OUTDIAMETER_ZG#',
       T.WALLTHICK_ZG   ='#WALLTHICK_ZG#'
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnOrderZg" desc="重新计算更新轧管合同表">
		<![CDATA[
UPDATE PLN_ORDER_ZG T
   SET T.LENGTHMAX     = '#LEN_ROLL_MAX#',
       T.LENGTHMIN     = '#LEN_ROLL_MIN#',
       T.AIMWALLTHICK  = '#AIMWALLTHICK#',
       T.AIMLENGTH     = '#AIMLENGTH#',
       T.DIAMETER_GP   = '#DIAMETER_GP#',
       T.LENGTH_GP     = '#LEN_GP_SINGLE#',
       T.ROLL_LENGTH   = '#ROLL_LENGTH#',
       T.OUTNUM_SINGLE = '#OUTNUM_CUT#',
       T.PASS_CODE     = '#PASS_CODE#',
       T.PASS_NAME     = '#PASS_NAME#',
       T.IN_WT        =
       (SELECT SUM(NVL(T1.IN_WEIGHT_S, 0))
          FROM PLN_ORDER_ZG_S T1
         WHERE T1.PRO_ORDER_NO = '#PRO_ORDER_NO#'
           AND T1.PRO_ORDER_NO=T.PRO_ORDER_NO
           AND T1.VALIDFLAG='1'),
       T.IN_NUM       =
       (SELECT SUM(NVL(T1.IN_NUM_S, 0))
          FROM PLN_ORDER_ZG_S T1
         WHERE T1.PRO_ORDER_NO = '#PRO_ORDER_NO#'
           AND T1.PRO_ORDER_NO=T.PRO_ORDER_NO AND T1.VALIDFLAG='1'),
       T.ADD_WT_IN    =
       (SELECT SUM(NVL(T1.ADD_WT_IN, 0))
          FROM PLN_ORDER_ZG_S T1
         WHERE T1.PRO_ORDER_NO = '#PRO_ORDER_NO#'
           AND T1.PRO_ORDER_NO=T.PRO_ORDER_NO AND T1.VALIDFLAG='1'),
       T.ADD_NUM_IN   =
       (SELECT SUM(NVL(T1.ADD_NUM_IN, 0))
          FROM PLN_ORDER_ZG_S T1
         WHERE T1.PRO_ORDER_NO = '#PRO_ORDER_NO#'
           AND T1.PRO_ORDER_NO=T.PRO_ORDER_NO AND T1.VALIDFLAG='1'),
       T.GETRATE       = ?,
       T.WEIGHT_GP_ONE = ?,
       T.ORDERWEIGHT=  '#WEIGTH_S#',
       T.ORDERNUM ='#NUM_S#'
 WHERE T.PRO_ORDER_NO = '#PRO_ORDER_NO#'

		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateZgOrdGxMNo" desc="重新计算更新工序合同">
		<![CDATA[
	UPDATE PLN_GX_ZG_M T
   SET T.AIMWALLTHICK     = '#AIMWALLTHICK#',
       T.LENGTHMAX        = '#LEN_ROLL_MAX#',
       T.LENGTHMIN        = '#LEN_ROLL_MIN#',
       T.AIMLENGTH        = '#AIMLENGTH#',
       T.ROLL_LENGTH      = '#ROLL_LENGTH#',
       T.OUTNUM_SINGLE    = '#OUTNUM_CUT#',
       T.DIAMETER_MANDREL = '#DIAMETER_MANDREL#',
       T.DIAMETER_GP      = '#DIAMETER_GP#',
       T.LENGTH_GP        = '#LEN_GP_SINGLE#',
       T.IN_WT           =
       (SELECT SUM(NVL(T1.IN_WEIGHT_S, 0))
          FROM PLN_ORDER_ZG_S T1
         WHERE T1.PRO_PLAN_ID = '#PRO_PLAN_ID#'
           AND T1.PRO_PLAN_ID=T.PRO_PLAN_ID AND T1.VALIDFLAG='1'),
       T.IN_NUM          =
       (SELECT SUM(NVL(T1.IN_NUM_S, 0))
          FROM PLN_ORDER_ZG_S T1
         WHERE T1.PRO_PLAN_ID = '#PRO_PLAN_ID#'
           AND T1.PRO_PLAN_ID=T.PRO_PLAN_ID AND T1.VALIDFLAG='1'),
       T.GETRATE          = ?,
       T.WEIGHT_GP_ONE    = ?,
       T.PLAN_WT          ='#WEIGTH_S#',
       T.PLAN_NUM         ='#NUM_S#', 
       T.PLAN_WT_MIN      =?,
       T.PLAN_WT_MAX      =?
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.querySaleProcStatus" desc="查询">
		<![CDATA[
		SELECT T.SIC,
       T.GPREQ_ID,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.EXE_STATUS,
       T.ORD_LN_DLY_PK,
       (SELECT DESGIN_KEY
          FROM CRAFT_ORD_DESIGN O
         WHERE O.ORD_LN_PK = T1.ORD_LN_PK
           AND O.CRAFT_SEQ = T.CRAFT_SEQ) DESGIN_KEY,
       T.MSC,
       T.INDEX_SEQ,
       T2.CRAFT_FILE_NO,
       T2.PROCESS_SEQ,
       T.BOM,
       T2.GROUP_ROLL,
       T2.GROUP_ROLL_NAME,
       T2.PLAN_WT_D,
       T2.PLAN_P_MAIN,
       T2.PLAN_NUM_D,
       T2.ORDER_UNIT,
       T2.WEIGHT_PER_M,
       T2.AIM_LEN_ROLL,
       T2.AIM_LEN_END,
       T2.LEN_ROLL_MAX,
       T2.LEN_ROLL_MIN,
       T2.GROUP_JGX,
       T2.GROUP_RCL,
       T1.PRDCR_NO,
       T1.LENGTHMAX,
       T1.LENGTHMIN,
       T1.OUTDIAMETER,
       T1.WALLTHICK,
       T1.SHRT_STOVE,
       T1.SIGL_LEN,
       (SELECT C.SHORTEST
          FROM SLM_ORDER_LINE C
         WHERE C.VALIDFLAG = '1'
           AND C.ORD_LN_PK = T1.ORD_LN_PK) SHORTEST,
       T1.OUTS_STL_PIPE_FL,
       T2.OUT_MULT_D,
       (SELECT C.INSPECTION_VALUE
          FROM SLM_ORDER_LINE C
         WHERE C.VALIDFLAG = '1'
           AND C.ORD_LN_PK = T1.ORD_LN_PK) INSPECTION_VALUE,
       T1.MODEL_DESC,
       (SELECT C.CHECK_J_VAL FROM COM_MSC_JG C WHERE C.CODE_JG = T1.CODE_JG) CHECK_J_VAL,
       NVL(T1.AVG_LEN_MIN, 0) AVG_LEN_MIN,
       T2.ORD_LN_DLY_PK,
       T1.ORDER_UNIT,
       NVL(T1.TOTLENGTH, 0) TOTLENGTH,
       NVL(T1.TOTLENGTH_UNIT, T1.LEN_UNIT) TOTLENGTH_UNIT,
       T1.WEIGH_TYPE,
       T2.ORDER_UNIT,
       T2.PLAN_P_MAIN_MIN,
       T1.ENDLEN_SPECSTD,
       T1.PRD_CLS,
       T1.PRODUCE_SORT,
       T.PRO_MONTH ROLL_MONTH,
       T1.ORD_LN_PK,
       T1.STD_NAME,
       T1.USE_DESC,
       (SELECT C.OUTPUT_STD_NO
			          FROM SLM_ORDER_LINE C
			         WHERE C.VALIDFLAG = '1'
			           AND C.ORD_LN_PK = T1.ORD_LN_PK) OUTPUT_STD_NO,
       T2.ABC,
       T2.ORDER_SOURCE,
       ABS(DECODE(T1.DELVRY_RANGE_TPE,
                  '绝对值',
                  T1.DELVRY_RANGE_MAX * 100 / T1.ORDER_QTY,
                  T1.DELVRY_RANGE_MAX)) DELVRY_RANGE_MAX,
       ABS(DECODE(T1.DELVRY_RANGE_TPE,
                  '绝对值',
                  T1.DELVRY_RANGE_MIN * 100 / T1.ORDER_QTY,
                  T1.DELVRY_RANGE_MIN)) DELVRY_RANGE_MIN,
       T.IS_PLAN_OK,
       T2.LEN_CUTHEAD_DBK,
       T2.LEN_CUTEND_DBK,
       T2.LEN_LONGER_DBK,
       T2.RATIO_DBK,
       T2.LEN_SCOPE
  FROM PLN_ORDER_ZG_S T
  LEFT JOIN PLN_SALEORD T1
    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
  LEFT JOIN PLN_SALEORD_PROC T2
    ON T2.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
   AND T2.PLN_DIVIDE_ID=T.PLN_DIVIDE_ID
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.VALIDFLAG='1'
		
	]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnOrderZgSMonth" desc="修改轧管耗时表排产年月">
		<![CDATA[
		UPDATE PLN_ORDER_ZG_S T
   SET T.PRO_MONTH   = '#PRO_MONTH#',
       T.PLAN_TIME_B = TO_DATE('#PLAN_TIME_B#','YYYY-MM-DD HH24:MI:SS'),
       T.PLAN_TIME_E = TO_DATE('#PLAN_TIME_E#','YYYY-MM-DD HH24:MI:SS'),
       T.GX_PRO_SEQ  = '#GX_PRO_SEQ#'
 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
   AND T.GX_PLAN_NO  = '#GX_PLAN_NO#'
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnOrderJGXSMonth" desc="修改加工线耗时表排产年月">
		<![CDATA[
		UPDATE PLN_ORDER_JGX_S T
   SET T.PRO_MONTH = '#PRO_MONTH#'
 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
    AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnOrderRCLSMonth" desc="修改热处理耗时表排产年月">
		<![CDATA[
		UPDATE PLN_ORDER_RCL_S T
   SET T.PRO_MONTH = '#PRO_MONTH#'
 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
    AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnOrderDBKSMonth" desc="修改墩拔扩耗时表排产年月">
		<![CDATA[
		UPDATE PLN_ORDER_DBK_S T
   SET T.PRO_MONTH = '#PRO_MONTH#'
 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
    AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectZgPlnSMonthMin" desc="查询轧管耗时表排产最小年月">
		<![CDATA[
SELECT MIN(T.PRO_MONTH) PRO_MONTH,
       MIN(TO_CHAR(T.PLAN_TIME_B,'YYYY-MM-DD HH24:MI:SS')) PLAN_TIME_B,
       SUM(T.PLAN_USETIME) PLAN_USETIME
  FROM PLN_ORDER_ZG_S T
 WHERE T.PRO_PLAN_ID = ?
 AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatPlnGxZgMonth" desc="修改轧管订单主表排产年月">
		<![CDATA[
UPDATE PLN_GX_ZG_M T
   SET T.PRO_MONTH = ?,
       T.PLAN_TIME =TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       T.PLAN_USETIME=?
 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatPlnGxJGXMonth" desc="修改加工订单主表排产年月">
		<![CDATA[
UPDATE PLN_GX_JGX_M T
   SET T.PRO_MONTH = ?
 WHERE T.ORD_LN_DLY_PK = ?
   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatPlnGxDBKMonth" desc="修改墩拔扩订单主表排产年月">
		<![CDATA[
UPDATE PLN_GX_DBK_M T
   SET T.PRO_MONTH = ?
 WHERE T.ORD_LN_DLY_PK = ?
   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatPlnGxRCLMonth" desc="修改热处理订单主表排产年月">
		<![CDATA[
UPDATE PLN_GX_RCL_M T
   SET T.PRO_MONTH = ?
 WHERE T.ORD_LN_DLY_PK = ?
   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatplnSaleord" desc="修改合同提报表">
		<![CDATA[
UPDATE PLN_SALEORD T
   SET T.OUTS_BILLET_FL = ?
 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatplnOrderZgSApply" desc="修改轧管耗时表申请单号">
		<![CDATA[
UPDATE PLN_ORDER_ZG_S T
   SET T.APPLY_NO = ?, T.APPLY_STATUS = ?
 WHERE T.ORDER_NO = ?
   AND T.ORDER_SEQ = ?
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatplnGroupGp" desc="修改管坯索引码">
		<![CDATA[
UPDATE PLN_ORDER_ZG_S
   SET CIC_GROUP_GP = '#CIC_GROUP_GP#',
       PIC_GROUP_GP = '#PIC_GROUP_GP#',
       SIC_GROUP_GP = '#SIC_GROUP_GP#',
       DIC_GROUP_GP = '#DIC_GROUP_GP#',
       WIC_GROUP_GP = '#WIC_GROUP_GP#',
       GIC_GROUP_GP = '#GIC_GROUP_GP#',
       CIC_GP       = '#CIC_GP#',
       PIC_GP       = '#PIC_GP#',
       SIC_GP       = '#SIC_GP#',
       DIC_GP       = '#DIC_GP#',
       WIC_GP       = '#WIC_GP#',
       GIC_GP       = '#GIC_GP#',
       CIC = '#CIC#',
       PIC = '#PIC#',
       SIC = '#SIC#',
       DIC = '#DIC#',
       WIC = '#WIC#',
       GIC = '#GIC#'
 WHERE PRO_PLAN_ID='#PRO_PLAN_ID#'
 AND GX_PLAN_NO='#GX_PLAN_NO#'
 AND VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatPlnJGXCic" desc="修改加工排产索引码">
		<![CDATA[
UPDATE PLN_ORDER_JGX_S
   SET CIC = '#CIC#',
       PIC = '#PIC#',
       SIC = '#SIC#',
       DIC = '#DIC#',
       WIC = '#WIC#',
       GIC = '#GIC#'
 WHERE CRAFT_FILE_NO = ?
   AND CRAFT_SEQ = ?
    AND VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatPlnRCLCic" desc="修改热处理排产索引码">
		<![CDATA[
UPDATE PLN_ORDER_RCL_S
   SET CIC = '#CIC#',
       PIC = '#PIC#',
       SIC = '#SIC#',
       DIC = '#DIC#',
       WIC = '#WIC#',
       GIC = '#GIC#'
 WHERE CRAFT_FILE_NO = ?
   AND CRAFT_SEQ = ?
    AND VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatPlnDBKCic" desc="修改墩拔扩排产索引码">
		<![CDATA[
UPDATE PLN_ORDER_DBK_S
   SET CIC = '#CIC#',
       PIC = '#PIC#',
       SIC = '#SIC#',
       DIC = '#DIC#',
       WIC = '#WIC#',
       GIC = '#GIC#'
 WHERE CRAFT_FILE_NO = ?
   AND CRAFT_SEQ = ?
    AND VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectCicByGrade" desc="根据内控标准号">
		<![CDATA[
		SELECT T.STD_CODE_NK FROM COM_MSC_STD_CIC T WHERE 1=1
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectGroupGp" desc="查询是否有自炼钢种索引码">
		<![CDATA[
		SELECT  COUNT(*) COUNT
  FROM COM_BASE_STD T
 WHERE T.VALIDFLAG = '1'
   AND T.STDSTYLE = 'N'
   AND T.PURCHASE_STD = ?
			]]>
	</query>
	<query id="CorePlnZgMStoGp.AddPlnSizUpApply" desc="插入长度上下限申请表">
		<![CDATA[
		 INSERT INTO PLN_SIZE_UPAPPLY(
        APPLY_NO,
        ORD_LN_PK,
        ORDER_SOURCE,
        ORD_LN_DLY_PK,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        PLINE_CODE,
        PLINE_NAME,
        STEELCODE,
        STEELNAME,
        GRADECODE,
        GRADENAME,
        OUTDIAMETER,
        WALLTHICK,
        LENGTH_MIN,
        LENGTH_MAX,
        LENGTHDISC,
        LENGTHDISC_N,
        EXE_STATUS,
        CREATE_TIME,
        APPLY_MAN,
        APPLY_TIME,
        FOUNDER_NAME,
        LEN_NO,LEN_NO_N)
 VALUES( 
        '#APPLY_NO#',
        '#ORD_LN_PK#',
        '#ORDER_SOURCE#',
        '#ORD_LN_DLY_PK#',
        '#ORDER_NO#',
        '#ORDER_SEQ#',
        '#DELIVERY_NO#',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#STEELCODE#',
        '#STEELNAME#',
        '#GRADECODE#',
        '#GRADENAME#',
        '#OUTDIAMETER#',
        '#WALLTHICK#',
        '#LENGTH_MIN#',
        '#LENGTH_MAX#',
        '#LENGTHDISC#',
        '#LENGTHDISC_N#',
        '#EXE_STATUS#',
        SYSDATE,
        '#APPLY_MAN#',
        TO_DATE('#APPLY_TIME#','YYYY-MM-DD HH24:MI:SS'),
        '#FOUNDER_NAME#',
        '#LEN_NO#','#LEN_NO_N#')
			]]>
	</query>
	<query id="CorePlnZgMStoGp.maxPlnSizUpApplyNo" desc="获取申请单号最大值">
		<![CDATA[
		SELECT ? ||
       LPAD(SUBSTR(NVL(MAX(T.APPLY_NO), '000'), -3, 3) + 1, 3, '0') AS APPLY_NO
  FROM PLN_SIZE_UPAPPLY T
 WHERE TRUNC(T.CREATE_TIME) = TO_DATE(?, 'YYYY-MM-DD')	
		]]>
	</query>
	<query id="CorePlnZgMStoGp.PlnSizUpApplyNoOrderNo" desc="同一个合同行PK只能申请一次">
		<![CDATA[
 SELECT COUNT(*) COUNT FROM PLN_SIZE_UPAPPLY T WHERE T.ORD_LN_PK = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnSaorder" desc="修改合同接收表">
		<![CDATA[
UPDATE PLN_SALEORD T
   SET T.LENGTHDISC_N = ?, T.LEN_NO_N = ?
 WHERE T.ORD_LN_PK = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdateBatchId" desc="修改轧管排产轧批号">
		<![CDATA[
 UPDATE PLN_ORDER_ZG_S T
    SET T.ZY_BATCH_ID ='#ZY_BATCH_ID#'
  WHERE T.PRO_PLAN_ID ='#PRO_PLAN_ID#'
    AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
    AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.SelectatchId" desc="查询是否存在轧批号">
		<![CDATA[
 SELECT COUNT(*) COUNT FROM PLN_ORDER_ZG_S T  
  WHERE T.ZY_BATCH_ID =?
    AND T.PLINE_CODE= ?
    AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.PlnSizUpApplyNoStrat" desc="查询审批单状态">
		<![CDATA[
 SELECT T.EXE_STATUS, DECODE(T.EXE_STATUS,
              '00',
              '作废',
              '10',
              '申请',
              '20',
              '审批通过',
              '30',
              '审批不通过') EXE_STATUS_TEXT,t.LENGTHDISC,T.LEN_NO FROM PLN_SIZE_UPAPPLY T WHERE T.APPLY_NO = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.DeletePlnSizUpApply" desc="删除审批单">
		<![CDATA[
DELETE PLN_SIZE_UPAPPLY WHERE APPLY_NO = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectBasePlineCode" desc="查询产线长度范围">
		<![CDATA[
SELECT T.LENGTH_MIN, T.LENGTH_MAX, T.BURNOUT_RATE,NVL(T.IN_MATERIAL_LEN_MIN, 0) IN_MATERIAL_LEN_MIN,
       NVL(T.IN_MATERIAL_LEN_MAX, 0) IN_MATERIAL_LEN_MAX
  FROM COM_BASE_PLINE T
 WHERE T.VALIDFLAG = '1'
   AND T.PLINE_CODE = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.addWalktHrough" desc="新增预排管坯需求">
		<![CDATA[
INSERT INTO PLN_REQINF_GP
  (GPREQ_ID,
   GPTYPE,
   GRADECODE,
   GRADENAME,
   MATERIAL_NO,
   MATERIAL_NAME,
   CIC,
   IF_MONITOR_LG,
   DIAMETER_GP,
   LENGTH_GP,
   GP_WT_LONG,
   REQ_DONESTATUS,
   PRO_MONTH,
   REC_TYPE,
   PLINE_CODE_DZ,
   PLINE_NAME_DZ,
   PLINE_CODE_ZZ,
   PLINE_NAME_ZZ,
   INWL_ISOK_DZ,
   WLID_ZZ,
   WLDESC_ZZ,
   IFBUYPLAN,REQ_STATUS,LEN_GP_SINGLE,CUT_NUM_GP,
   GP_WEIGHT,CREATE_TIME,CREATE_NAME,
   ISSUED_TIME,ISSUED_MAN,PRO_PLAN_ID_ZZ,SUPPLY_UNIT_CODE,SUPPLY_UNIT,TYPE_FLAG)
VALUES
  ('#GPREQ_ID#',
   '#GPTYPE#',
   '#GRADECODE#',
   '#GRADENAME#',
   '#MATERIAL_NO#',
   '#MATERIAL_NAME#',
   '#CIC#',
   '#IF_MONITOR_LG#',
   '#DIAMETER_GP#',
   '#LENGTH_GP#',
   '#GP_WT_LONG#',
   '#REQ_DONESTATUS#',
   '#PRO_MONTH#',
   '1',
   '#PLINE_CODE_DZ#',
   '#PLINE_NAME_DZ#',
   '#PLINE_CODE_ZZ#',
   '#PLINE_NAME_ZZ#',
   '#INWL_ISOK_DZ#',
   '#WLID_ZZ#',
   '#WLDESC_ZZ#',
   '#IFBUYPLAN#','#REQ_STATUS#', '#LEN_GP_SINGLE#','#CUT_NUM_GP#',
   '#GP_WT_LONG#',TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
    '#CREATE_NAME#',TO_DATE('#ISSUED_TIME#','YYYY-MM-DD HH24:MI:SS'),'#ISSUED_MAN#','#PRO_PLAN_ID_ZZ#','#SUPPLY_UNIT_CODE#','#SUPPLY_UNIT#','#TYPE_FLAG#')
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdateDecision" desc="修改轧管判定字头">
		<![CDATA[
DECLARE
BEGIN
  UPDATE PLN_ORDER_ZG_S T
     SET T.DECISION = '#DECISION#',
         T.ISENDGX=?
   WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
     AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
     AND T.VALIDFLAG='1';
END;

		]]>
	</query>
	<query id="CorePlnZgMStoGp.SelectPlnOrderZgCaiF" desc="查询是否拆分订单">
		<![CDATA[
		SELECT COUNT(*) COUNT FROM PLN_ORDER_ZG_S T WHERE T.PRO_PLAN_ID = ? AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectDesginKey" desc="查询制程">
		<![CDATA[
SELECT T.DESGIN_KEY,
       T.MSC_PLINE,
       T.WHOLE_BACKLOG,
       T.WHOLE_BACKLOG_DESC,
       T.PROCESS_CODE,
       T.PROCESS_DESC,
       C.CRAFT_SEQ,
       C.CRAFT_NO,
       S.CRAFT_FILE_NO,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.WIC,
       T.GIC  
  FROM PLN_ORDER_ZG_S              S,
       PLN_SALEORD_PROC            T1,
       PLN_SALEORD                 T2,
       CRAFT_ORD_DESIGN_MSC_PL_PRC T,
       CRAFT_ORD_DESIGN            C
 WHERE T1.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
   AND T1.PLN_DIVIDE_ID = S.PLN_DIVIDE_ID
   AND T2.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
   AND C.ORD_LN_PK = T2.ORD_LN_PK
   AND C.CRAFT_SEQ = T1.CRAFT_SEQ
   AND T.DESGIN_KEY = C.DESGIN_KEY
   AND T.MSC_PLINE = T1.INDEX_SEQ
   AND S.PRO_PLAN_ID =?
   AND S.GX_PLAN_NO = ?
   AND C.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectGpIcList1" desc="查询管坯需求内控标准项集合">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
       M1.PROCESS_CODE,
       M1.PROCESS_DESC,
       M1.CIC,
       M1.PIC,
       M1.SIC,
       M1.DIC,
       M1.WIC,
       M1.GIC,
       T.GRADECODE
  FROM PLN_ORDER_ZG_S T
  LEFT JOIN PLN_ORDER_ZG T2
    ON T2.PRO_ORDER_NO = T.PRO_ORDER_NO
  LEFT JOIN PLN_SALEORD T1
    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
  LEFT JOIN SLM_ORD_DESIGN_BOM B
    ON B.BOM = T2.BOM
   AND B.MATERIAL_NO = T1.MATERIAL_NO
  LEFT JOIN CRAFT_ORD_DESIGN M
    ON M.ORD_LN_PK = T1.ORD_LN_PK
   AND M.CRAFT_SEQ = T2.CRAFT_SEQ
  LEFT JOIN CRAFT_ORD_DESIGN_MSC_PL_PRC M1
    ON M1.DESGIN_KEY = M.DESGIN_KEY
   --AND M1.MSC_PLINE = T2.INDEX_SEQ
   AND M1.PROCESS_CODE IN ('A','B','C')
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO =?
   AND T.VALIDFLAG='1'

		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateGradeCode" desc="修改轧管钢种">
		<![CDATA[
  UPDATE PLN_ORDER_ZG_S T
     SET T.GRADECODE = '#GRADECODE#', T.GRADENAME = '#GRADENAME#'
   WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
     AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
     AND T.VALIDFLAG='1'

		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectCraftNo" desc="查询工艺文件">
		<![CDATA[
		SELECT NVL(T.CRAFT_SOURCE, '/') CRAFT_SOURCE
  FROM CRAFT_ORD_DESIGN T
 WHERE T.VALIDFLAG IN ('1','0')
   AND T.CRAFT_NO = ?
   AND T.CRAFT_SEQ = ?	
   AND T.DESGIN_KEY=? 
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectPlnOrderFun" desc="通过管坯需求号查订单">
		<![CDATA[
SELECT T.PRO_PLAN_ID,T.GX_PLAN_NO,T.GPREQ_ID,
(SELECT GET_GP_MAT_NUM_ZL(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) FURNA_NUM,
       (SELECT GET_GP_MAT_WT_ZL(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) FURNA_WEIGHT,
       (SELECT GET_GP_PLNZGM_NUM(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJ_NUM,
       (SELECT GET_GP_PLNZGM_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJ_WEIGHT
 FROM PLN_ORDER_ZG_S T WHERE T.IS_PLAN_OK='1' AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectPlnReqinfP" desc="查询存在管坯需求">
		<![CDATA[
		SELECT T.*
  FROM PLN_REQINF_GP T
 WHERE T.REQ_DONESTATUS = '0'
   AND T.REC_TYPE = '0'
   AND T.CIC = ?
   AND T.LEN_GP_SINGLE = ?
   AND T.MATERIAL_NO = ?
   AND T.IF_MONITOR_LG = ?
   AND T.IFBUYPLAN = ?
   AND T.WHOLE_BACKLOG_DESC = ?
 
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdateDoProMemo" desc="修改工艺备注">
		<![CDATA[
  UPDATE PLN_ORDER_ZG_S T
     SET T.PROGY_MEMO = '#PROGY_MEMO#'
   WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
     AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
     AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdateDoJhMemo" desc="修改计划备注">
		<![CDATA[
  UPDATE PLN_ORDER_ZG_S T
     SET T.MEMO = '#MEMO#'
   WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
     AND T.GX_PLAN_NO = '#GX_PLAN_NO#'
     AND T.VALIDFLAG='1'AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectProZgPlnAnaly" desc="查询是否存在余量">
		<![CDATA[
 SELECT NVL(T.GP_SYWEIGHT, 0) GP_SYWEIGHT,GPREQ_ID,REQ_STATUS
  FROM PLN_REQINF_GP T
 WHERE T.GRADECODE = ?
   AND T.LEN_GP_SINGLE = ?
   AND T.MATERIAL_NO = ?
   AND T.IF_MONITOR_LG = ?
   AND T.IFBUYPLAN = ?
   AND T.WHOLE_BACKLOG_DESC = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectDoBlunt" desc="查询是否可冲余量">
		<![CDATA[
		SELECT T.GPREQ_WEIGHT, T.GPREQ_NUM
  FROM PLN_ORDER_ZG_S T
 WHERE T.GPREQ_ID IS NULL
   AND T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdateDoBlunt" desc="冲余量">
		<![CDATA[
		BEGIN
  UPDATE PLN_ORDER_ZG_S T
     SET T.GPREQ_ID = ?, T.GPREQ_IF_OK = '1'
   WHERE T.PRO_PLAN_ID = ?
     AND T.GX_PLAN_NO = ? AND T.VALIDFLAG='1';
  UPDATE PLN_REQINF_GP T
     SET T.GP_SYWEIGHT = TO_NUMBER(T.GP_SYWEIGHT) - TO_NUMBER(?)
   WHERE T.GPREQ_ID = ?;
END;
		]]>
	</query>
	<query id="CorePlnZgMStoGp.deleteGperIdZgS" desc="删除订单管坯需求号">
		<![CDATA[
  UPDATE PLN_ORDER_ZG_S T
   SET T.GPREQ_IF_OK       = '0',
       T.GPREQ_ID          = '',
       T.ACTUAL_WEIGHT     =''      
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdatePlnZgSPass" desc="修改主被动">
		<![CDATA[
	UPDATE PLN_ORDER_ZG_S T
   SET T.GPREQ_NUM = ?, T.GPREQ_WEIGHT = ?,T.GPREQ_WEIGHT_MIN = ?, T.PASSIVE = ?
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.selectCraftPath" desc="查询工艺文件路径">
		<![CDATA[
SELECT DISTINCT Q1.CRAFT_PATH
  FROM PLN_ORDER_ZG_S   T,
       PLN_SALEORD_PROC T1,
       PLN_SALEORD      T2,
       CRAFT_ORD_DESIGN Q1
 WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
 AND T.PLN_DIVIDE_ID=T1.PLN_DIVIDE_ID
 AND T1.ORD_LN_DLY_PK=T2.ORD_LN_DLY_PK
 AND T2.ORD_LN_PK=Q1.ORD_LN_PK
 AND T.CRAFT_SEQ=Q1.CRAFT_SEQ
 AND T.PRO_PLAN_ID=?
 AND T.GX_PLAN_NO=?
 AND T.VALIDFLAG='1'

		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateZzPline" desc="修改铸造产线">
		<![CDATA[
UPDATE PLN_ORDER_ZG_S T
   SET T.PLINE_CODE_ZZ = ?, T.PLINE_NAME_ZZ = ?
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateLinShiCom" desc="修改临时确认功能">
		<![CDATA[
UPDATE PLN_ORDER_ZG_S T
   SET T.GPREQ_IF_DZ = ?
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.seletePlnZgS" desc="查询轧管产线">
		<![CDATA[
		SELECT P.WHOLE_BACKLOG,
       P.DESGIN_KEY,
       P.MSC_PLINE,
       T.BOM,
       T.MSC,
       B.B_IN_MATERIAL_NO,
       B.B_IN_MATERIAL_DESC,
       B.B_OUT_MATERIAL_NO,
       B.B_OUT_MATERIAL_DESC,
       B.C_IN_MATERIAL_NO,
       B.C_IN_MATERIAL_DESC,
       B.C_OUT_MATERIAL_NO,
       B.C_OUT_MATERIAL_DESC,
       T.PLINE_CODE
  FROM PLN_ORDER_ZG_S T
  LEFT JOIN PLN_SALEORD T1
    ON T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
  LEFT JOIN PLN_ORDER_ZG T2
    ON T2.PRO_ORDER_NO = T.PRO_ORDER_NO
  LEFT JOIN CRAFT_ORD_DESIGN M
    ON M.ORD_LN_PK = T1.ORD_LN_PK
   AND M.CRAFT_SEQ = T.CRAFT_SEQ
  LEFT JOIN CRAFT_ORD_DESIGN_MSC_PL_PRC P
    ON P.DESGIN_KEY = M.DESGIN_KEY
   AND P.MSC_PLINE = T2.INDEX_SEQ
   AND P.PROCESS_CODE = 'D'
  LEFT JOIN SLM_ORD_DESIGN_BOM B
    ON B.BOM = T.BOM
   AND B.MSC = T.MSC
   AND B.MSC_PLINE = T.INDEX_SEQ
   AND B.WHOLE_BACKLOG_DESC = T.WHOLE_BACKLOG_DESC
 WHERE T.GPREQ_ID = ?
 AND T.VALIDFLAG='1'
		
			]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnGxCastM" desc="修改铸造订单">
		<![CDATA[
		DECLARE
BEGIN
  UPDATE PLN_GX_CAST_M T
     SET T.CUT_NUM_GP    = ?,     
         T.CUT_LOSE_LEN  = ?,
         T.LENGTH_LZ     = ?,
         T.PLAN_WT       = ?,
         T.PLAN_NUM      = ?
   WHERE T.PRO_PLAN_ID = ?;
  UPDATE PLN_ORDER_CAST_S T
     SET T.CUT_NUM_GP    = ?,
         T.CUT_LOSE_LEN  = ?,
         T.LENGTH_LZ     = ?,
         T.PLAN_WT_S       = ?,
         T.PLAN_NUM_S      = ?
   WHERE T.PRO_PLAN_ID = ?;
END;
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updatePlnGxDpM" desc="修改锻造订单">
		<![CDATA[
		DECLARE
BEGIN
  UPDATE PLN_GX_CAST_M T
     SET T.CUT_NUM_GP   = ?,
         T.CUT_LOSE_LEN = ?,
         T.LENGTH_LZ    = ?,
         T.PLAN_WT      = ?,
         T.PLAN_NUM     = ?
   WHERE T.PRO_PLAN_ID = ?;
  UPDATE PLN_ORDER_CAST_S T
     SET T.CUT_NUM_GP   = ?,
         T.CUT_LOSE_LEN = ?,
         T.LENGTH_LZ    = ?,
         T.PLAN_WT_S    = ?,
         T.PLAN_NUM_S   = ?
   WHERE T.PRO_PLAN_ID = ?;
  UPDATE PLN_GX_DP_M T
     SET T.CUT_NUM_GP  = ?,
         T.LENGTH_OUT  = ?,
         T.OUT_WT_TOT  = ?,
         T.OUT_NUM_TOT = ?,
         T.IN_WT=?,
         T.IN_NUM=?
   WHERE T.PRO_PLAN_ID = ?;
  UPDATE PLN_ORDER_DZ_S T
     SET T.LENGTH_OUT = ?, T.OUT_WT_TOT = ?, T.OUT_NUM_TOT = ?, T.WEIGTH_S=?,
         T.NUM_S=?
   WHERE T.PRO_PLAN_ID = ?;
END;
		
		]]>
	</query>
	<query id="CorePlnZgMStoGp.updateGradCodePri" desc="查询钢种优先级">
		<![CDATA[
		SELECT T.PRIORITY
  FROM CRAFT_ORD_DESIGN_MSC_PL_GZ T
 WHERE T.DESGIN_KEY =?
   AND T.MSC_PLINE = ?
   AND T.GRADECODE = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.queryPlnOrderJgS" desc="查询加工排产信息">
		<![CDATA[
		SELECT T.* FROM PLN_ORDER_JGX_S T  WHERE T.ORD_LN_DLY_PK=? AND T.PLN_DIVIDE_ID=? AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.queryPlnOrderRclS" desc="查询热处理排产信息">
		<![CDATA[
		SELECT T.* FROM PLN_ORDER_RCL_S T  WHERE T.ORD_LN_DLY_PK=? AND T.PLN_DIVIDE_ID=? AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.queryPlnOrderDbkS" desc="查询墩拔扩排产信息">
		<![CDATA[
		SELECT T.* FROM PLN_ORDER_DBK_S T  WHERE T.ORD_LN_DLY_PK=? AND T.PLN_DIVIDE_ID=? AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdatePlnOrderJgS" desc="修改加工排产信息有效标志">
		<![CDATA[
		UPDATE PLN_ORDER_JGX_S T SET T.VALIDFLAG='0' WHERE T.ORD_LN_DLY_PK=? AND T.PLN_DIVIDE_ID=?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdatePlnOrderRclS" desc="修改热处理排产信息有效标志">
		<![CDATA[
		UPDATE PLN_ORDER_RCL_S T SET T.VALIDFLAG='0' WHERE T.ORD_LN_DLY_PK=? AND T.PLN_DIVIDE_ID=?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdatePlnOrderDbkS" desc="修改墩拔扩排产信息有效标志">
		<![CDATA[
	UPDATE PLN_ORDER_DBK_S T SET T.VALIDFLAG='0' WHERE T.ORD_LN_DLY_PK=? AND T.PLN_DIVIDE_ID=?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdatePlnOrderZgz" desc="修改轧管排产信息有效标志">
		<![CDATA[
		UPDATE PLN_ORDER_ZG_S T SET T.VALIDFLAG='0' WHERE T.ORD_LN_DLY_PK=? AND T.PLN_DIVIDE_ID=?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.UpdatePlnOrderZg" desc="修改轧管排产信息量">
		<![CDATA[
		UPDATE PLN_ORDER_ZG_S T
   SET T.WEIGTH_S     = ?,
       T.NUM_S        = ?,
       T.ADD_WT_IN    = ?,
       T.ADD_NUM_IN   = ?,
       T.MATCH_WT_IN  = ?,
       T.MATCH_NUM_IN = ?,
       T.GPREQ_NUM    = ?,
       T.GPREQ_WEIGHT = ?,
       T.WEIGTH_S_MIN = ?,
       T.PLANS_NUM    = ?
 WHERE T.ORD_LN_DLY_PK = ?
   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	<query id="CorePlnZgMStoGp.QueryMscPline" desc="查询轧管制程索引号">
		<![CDATA[
		SELECT T.INDEX_SEQ
  FROM PLN_ORDER_ZG_S T
 WHERE T.GPREQ_ID = ?
   AND T.PRDCR_NO = ?
   AND ROWNUM = 1
			]]>
	</query>
	<query id = "CorePlnZgMStoGp.selectOrderGl" desc = "查询管坯需求是否已生成关联交易合同行">
		SELECT COUNT(1)ACOUNT  FROM SLM_GL_ORDER_LINE T WHERE T.PRO_ORDER_NO = ? AND T.VALIDFLAG = '10'
	</query>
	<query id = "CorePlnZgMStoGp.selectMangageLen" desc = "查询芯棒对应最长单倍坯长">
		SELECT S.LEN_MANDREL
		FROM PLN_ORDER_ZG_S T, COM_BASE_MANDREL S
		WHERE T.DIAMETER_MANDREL = S.DIAMETER_MANDREL
		AND T.PRO_PLAN_ID = ?
		AND T.GX_PLAN_NO = ?
	</query>
	<!-- tzh 新增坯料需求接口 -->
		<query id="CorePlnZgMStoGp.selectProcessBPCx" desc="查询给产销坯料需求数据">
		<![CDATA[ 
		select 'xxx' as cs,t.supply_unit  from PLN_REQINF_GP t where GPREQ_ID =  ?
		 ]]>
	</query>
		<!-- tzh 保存坯料测算结果 -->
	<query id="TPoDemandPlan.updateTPoDemandPlan" desc="保存坯料测算结果">
		<![CDATA[
  UPDATE T_PO_DEMAND_PLAN T
     SET T.DIAMETER_MANDREL = '#DIAMETER_MANDREL#', T.WG_D = '#WG_D#',
     T.WG_H = '#WG_H#',T.MGCD = '#MGCD#',T.XBZJ = '#XBZJ#',T.ZZCD = '#ZZCD#',T.GGFQS = '#GGFQS#',T.CPCD = '#CPCD#',
     T.QT = '#QT#',T.QW = '#QW#',
     T.BCS = '#BCS#',T.DBCPLCD = '#DBCPLCD#',
     T.GPZJ = '#GPZJ#',T.HTCGZL = '#HTCGZL#',T.quantity_Purchased = '#quantity_Purchased#'
   WHERE T.plan_No ='#plan_No#'

		]]>
	</query>
	<!-- tzh 保存坯料测算结果 -->
	<query id="TPoDemandPlan.updateTPoDemandPlan2" desc="保存坯料测算结果">
		<![CDATA[
  UPDATE T_PO_DEMAND_PLAN T
     SET T.DIAMETER_MANDREL = ?, T.WG_D = ?,
     T.WG_H = ?,T.MGCD = ?,T.ZZCD = ?,T.GGFQS = ?,T.CPCD = ?,
     T.QT = ?,T.QW = ?,
     T.BCS = ?,T.DBCPLCD = ?,
     T.GPZJ = ?,T.HTCGZL_MAX =?,T.quantity_Purchased = ?,
     T.DBCPLZL= ?,T.SSL= ?,T.MZ= ?,
     T.zzzl= ?,T.jhlc= ?,T.HTCGZL_MIN =?
   WHERE T.plan_No =?

		]]>
	</query>
	
		<!--24.9.18  tzh 修改坯料测算上传状态 -->
	<query id="TPoDemandPlan.updateTPoDemandPlan3" desc="修改坯料测算上传状态">
		<![CDATA[
  UPDATE T_PO_DEMAND_PLAN T
     SET CX_FLAG = 1
   WHERE T.plan_No =?

		]]>
	</query>
	
	<!-- tzh 保存和撤销热处理高新 -->
	<query id="TPoDemandPlan.updateCxMesGx" desc="保存和撤销高新热处理">
		<![CDATA[
  UPDATE HOT_HEAT_PRODUCTION_MES_GX T
      SET T.FLAG = ?,t.High_Mate_Weight=?,t.High_Prod_Weight=?,ESTIMATED_UNIT_PRICE=?,ESTIMATED_COST=?,HIGH_TECH_CODE=?,HIGH_TECH_NAME=?
   WHERE T.CX_NO =?

		]]>
	</query>
	
		<!-- tzh 保存和撤销加工高新 -->
	<query id="TPoDemandPlan.updateCxMesGxJG" desc="保存和撤销加工高新">
		<![CDATA[
  UPDATE HOT_PRODUCTION_MES_JG T
     SET T.FLAG = ?,t.High_Mate_Weight=?,t.High_Prod_Weight=?,ESTIMATED_UNIT_PRICE=?,ESTIMATED_COST=?,HIGH_TECH_CODE=?,HIGH_TECH_NAME=?
   WHERE T.CX_NO =?
   ]]>
	</query>
	
		<!-- tzh 保存和撤销热轧高新 -->
	<query id="TPoDemandPlan.updateCxMesGxRZBF" desc="保存和撤销热轧高新">
		<![CDATA[
  UPDATE HOT_PRODUCTION_MES_RZ T
      SET T.FLAG = ?,t.High_Mate_Weight=?,t.High_Prod_Weight=?,ESTIMATED_UNIT_PRICE=?,ESTIMATED_COST=?,HIGH_TECH_CODE=?,HIGH_TECH_NAME=?
   WHERE T.CX_NO =?
   ]]>
	</query>
	
	<!-- tzh 查询热处理高新数据-->
	<query id="TPoDemandPlan.queryrclgx" desc="查询热处理高新数据">
		<![CDATA[
		  select a.CONTRACT_TYPE,
       a.PROD_VARIETY,
       a.ORDER_ID,
       a.STEEL_LEVEL,
       a.STEEL_NO,
       a.act_dimater act_diameter,
       a.act_height,
       a.SPEC,
       a.PROD_TYPE,
       a.PROD_WEIGHT,
       a.MATE_WEIGHT,
       a.STEEL_WASTE,
       a.PROCESS,
       a.BAL_YEAR_MONTH,
       a.MATE_CODE,
       a.RESOURCE_TYPE,
       a.JUDGE_STOVE_NO,
       a.BILLET_CODE,
       nvl(max(g.high_tech_code), 0) high_tech_code,
       nvl(max(g.high_tech_name), 0) high_tech_name,
       nvl(sum(g.high_prod_weight), 0) high_prod_weight,
       nvl(sum(g.high_mate_weight), 0) high_mate_weight,
       nvl(sum(g.estimated_unit_price), 0) estimated_unit_price,
       nvl(sum(g.estimated_cost), 0) estimated_cost,
       max((case
             when g.high_tech_code is null then
              '否'
             else
              '是'
           end)) FLAG
  from (select (select decode(max(s.order_typ),
                      '120108',
                      '双经销',
                      '120109',
                      '定销订购',
                      '120107',
                      '来料加工',
                      '自用')
          from cxuser.slm_order_head s
         where s.order_no = regexp_replace(t.pro_order_no, '/.*', '')) contract_type,
       t.producname prod_variety,
       replace(t.pro_order_no, '/', '') order_id,
       t.steelname steel_level,
       t.gradename steel_no,
       t.act_dimater,
       t.act_height,
       t.spec_name spec,
       (case
         when t.target = 'A' then
          '产成品'
         else
          '半成品'
       end) prod_type,
       sum(decode(t.act_weight, null, t.act_theory_weight, t.act_weight)) prod_weight,
       sum(input_weight) mate_weight,
       (case
         when sum(input_weight) <> 0 then
          round(sum(decode(t.act_weight,
                           null,
                           t.act_theory_weight,
                           t.act_weight)) / sum(input_weight),
                4) * 100
         else
          0
       end) steel_waste,
       '热处理' process,
       substr(T.bal_year_month, 0, 4) || '-' ||
       substr(T.bal_year_month, 5, 2) bal_year_month,
       mat.material_code mate_code,
       getislljg(t.judge_stove_no, replace(t.pro_order_no, '/', '')) resource_type,
       t.judge_stove_no,
       null billet_code
  from cxuser.qcm_zg_jugde_apply t
  left join mvm_Order_matNo_info mat
    on mat.contractno_num = REPLACE(t.pro_order_no, '/', '')
 where t.is_flag = '0'
   and t.is_all_scrap in ('0', '2')
   and ((t.validflag = '20' and t.target <> 'A' and
       t.judge_result_code in ('40740701', '40740705', '40740709')) or
       (t.validflag = '20' and t.target = 'A' and
       t.judge_tolresult_code in ('40740701', '40740705', '40740709')) or
       t.instancy_flag = '1')
   and t.process_code = 'F'
   and t.pline_code = 'C091'
   AND t.bal_year_month = ?
 group by t.producname,
          t.steelname,
          t.gradename,
          t.spec_name,
          t.target,
          T.bal_year_month,
          pro_order_no,
          T.judge_stove_no,
          mat.material_code,
          t.act_dimater,
          t.act_height) A
  left join gx_data_RCL g
    on g.judge_stove_no = a.judge_stove_no
   and g.orderid = a.order_id
   and g.bal_year_month = a.bal_year_month
 group by a.CONTRACT_TYPE,
          a.PROD_VARIETY,
          a.ORDER_ID,
          a.STEEL_LEVEL,
          a.STEEL_NO,
          a.SPEC,
          a.PROD_TYPE,
          a.PROD_WEIGHT,
          a.MATE_WEIGHT,
          a.STEEL_WASTE,
          a.PROCESS,
          a.BAL_YEAR_MONTH,
          a.MATE_CODE,
          a.RESOURCE_TYPE,
          a.JUDGE_STOVE_NO,
          a.BILLET_CODE,
          a.act_dimater,
          a.act_height
 

		]]>
	</query>
	
	<query id="TPoDemandPlan.queryrclgxBF" desc="查询热处理高新数据">
		<![CDATA[
		  select CONTRACT_TYPE,
PROD_VARIETY,
STEEL_LEVEL,
STEEL_NO,
SPEC,
PROD_TYPE,
PROD_WEIGHT,
MATE_WEIGHT,
STEEL_WASTE,
PROCESS,
HIGH_TECH_CODE,
HIGH_TECH_NAME,
HIGH_PROD_WEIGHT,
HIGH_MATE_WEIGHT,
ESTIMATED_UNIT_PRICE,
ESTIMATED_COST,
ACCT_PERIOD,
MATE_CODE,
RESOURCE_TYPE,
BILLET_CODE,
MEMO,
(case FLAG when '0' then '否' when '1' then '是' else FLAG end) FLAG,
CX_NO

 from Hot_Heat_Production_Mes_Gx t where 1=1   and PROD_TYPE = '产成品' 

		]]>
	</query>
	
	<!-- tzh 查询热轧高新数据-->
	<query id="TPoDemandPlan.queryrzgx" desc="查询rz高新数据">
		<![CDATA[
		  select a.CONTRACT_TYPE,
       a.PROD_VARIETY,
       a.ORDER_ID,
       a.STEEL_LEVEL,
       a.STEEL_NO,
       a.act_dimater act_diameter,
       a.act_height,
       a.SPEC,
       a.PROD_TYPE,
       a.PROD_WEIGHT,
       a.MATE_WEIGHT,
       a.STEEL_WASTE,
       a.PROCESS,
       a.BAL_YEAR_MONTH,
       a.MATE_CODE,
       a.RESOURCE_TYPE,
       a.JUDGE_STOVE_NO,
       a.BILLET_CODE,
       nvl(max(g.high_tech_code), 0) high_tech_code,
       nvl(max(g.high_tech_name), 0) high_tech_name,
       nvl(sum(g.high_prod_weight), 0) high_prod_weight,
       nvl(sum(g.high_mate_weight), 0) high_mate_weight,
       nvl(sum(g.estimated_unit_price), 0) estimated_unit_price,
       nvl(sum(g.estimated_cost), 0) estimated_cost,
       max((case
             when g.high_tech_code is null then
              '否'
             else
              '是'
           end)) FLAG
  from (select (select decode(max(s.order_typ),
                              '120108',
                              '双经销',
                              '120109',
                              '定销订购',
                              '120107',
                              '来料加工',
                              '自用')
                  from cxuser.slm_order_head s
                 where s.order_no = regexp_replace(t.pro_order_no, '/.*', '')) contract_type,
               t.producname prod_variety,
               nvl(replace(pro_order_no, '/', ''),
                   replace(get_cp_order(t.judge_stove_no), '/', '')) order_id,
               t.steelname steel_level,
               t.gradename steel_no,
               t.act_dimater,
               t.act_height,
               t.spec_name spec,
               (case
                 when t.target = 'A' then
                  '产成品'
                 else
                  '半成品'
               end) prod_type,
               sum(decode(t.act_weight,
                          null,
                          t.act_theory_weight,
                          t.act_weight)) prod_weight,
               sum(output_weight) mate_weight,
               (case
                 when sum(input_weight) <> 0 then
                  round(sum(decode(t.act_weight,
                                   null,
                                   t.act_theory_weight,
                                   t.act_weight)) / sum(input_weight),
                        4) * 100
                 else
                  0
               end) steel_waste,
               '热轧' process,
               substr(t.bal_year_month, 0, 4) || '-' ||
               substr(t.bal_year_month, 5, 2) bal_year_month,
               --get_cp_code6(t.pro_order_no) mate_code,
               mat.material_code mate_code,
               getislljg(t.judge_stove_no, replace(t.pro_order_no, '/', '')) resource_type,
               t.judge_stove_no,
               get_pl_code(t.gradename,
                           (select xxx.dimater
                              from cxuser.ydm_gp_outlist xxx
                             where xxx.stove_no = t.stove_no
                               and rownum = 1)) billet_code
        
          from cxuser.qcm_zg_jugde_apply t
          left join mil_plan t1
            on t.judge_stove_no =
               regexp_replace(t1.judge_stove_no, '-.*', '')
           and t1.back_slab_flag <> '2'
           and substr(t1.judge_stove_no, -2) = '01'
          left join mvm_Order_matNo_info mat
            on mat.contractno_num = REPLACE(t.pro_order_no, '/', '')
          left join pln_zy_zg_m t2
            on t2.heat_plan_no = t.heat_plan_no
         where t.is_flag = '0'
           and t.is_all_scrap in ('0', '1', '2', '7', '8')
           and ((t.validflag = '20' and t.target <> 'A' and
               t.judge_result_code in ('40740701', '40740705', '40740709')) or
               (t.validflag = '20' and t.target = 'A' and
               t.judge_tolresult_code in
               ('40740701', '40740705', '40740709')) or
               (t.validflag = '20' and t.target = 'A' and
               t.is_all_scrap = '1') or t.instancy_flag = '1')
           and t.process_code = 'D'
           and (t.target = t1.target or t.judge_stove_no <> 'F24070002' or
               t.judge_stove_no <> 'F24070006')
           AND t.bal_year_month = ?
         group by t.producname,
                  t.steelname,
                  t.gradename,
                  t.stove_no,
                  t.spec_name,
                  t.target,
                  t.bal_year_month,
                  pro_order_no,
                  t.judge_stove_no,
                  mat.material_code,
                  t.act_dimater,
                  t.act_height) A
  left join gx_data_rz g
    on g.judge_stove_no = a.judge_stove_no
   and g.orderid = a.order_id
   and g.bal_year_month = a.bal_year_month
 group by a.CONTRACT_TYPE,
          a.PROD_VARIETY,
          a.ORDER_ID,
          a.STEEL_LEVEL,
          a.STEEL_NO,
          a.SPEC,
          a.PROD_TYPE,
          a.PROD_WEIGHT,
          a.MATE_WEIGHT,
          a.STEEL_WASTE,
          a.PROCESS,
          a.BAL_YEAR_MONTH,
          a.MATE_CODE,
          a.RESOURCE_TYPE,
          a.JUDGE_STOVE_NO,
          a.BILLET_CODE,
          a.act_dimater,
          a.act_height

		  
		]]>
	</query>
	<query id="TPoDemandPlan.queryrzgxBF" desc="查询rz高新数据">
		<![CDATA[
		  select CONTRACT_TYPE,
PROD_VARIETY,
STEEL_LEVEL,
STEEL_NO,
SPEC,
PROD_TYPE,
PROD_WEIGHT,
MATE_WEIGHT,
STEEL_WASTE,
PROCESS,
HIGH_TECH_CODE,
HIGH_TECH_NAME,
HIGH_PROD_WEIGHT,
HIGH_MATE_WEIGHT,
ESTIMATED_UNIT_PRICE,
ESTIMATED_COST,
ACCT_PERIOD,
MATE_CODE,
RESOURCE_TYPE,
BILLET_CODE,
MEMO,
(case FLAG when '0' then '否' when '1' then '是' else FLAG end) FLAG,
CX_NO
 from HOT_PRODUCTION_MES_RZ t where 1=1  and PROD_TYPE = '产成品' 

		]]>
	</query>
	
	

		<!-- tzh 查询加工高新数据-->
	<query id="TPoDemandPlan.queryjggx" desc="查询加工高新数据">
		<![CDATA[
		  select a.CONTRACT_TYPE,
       a.PROD_VARIETY,
       a.ORDER_ID,
       a.STEEL_LEVEL,
       a.STEEL_NO,
       a.act_dimater act_diameter,
       a.act_height,
       a.SPEC,
       a.PROD_TYPE,
       a.PROD_WEIGHT,
       a.MATE_WEIGHT,
       a.STEEL_WASTE,
       a.PROCESS,
       a.BAL_YEAR_MONTH,
       a.MATE_CODE,
       a.RESOURCE_TYPE,
       a.JUDGE_STOVE_NO,
       a.BILLET_CODE,
       a.MODEL_DESC,a.PREVIOUS_GX, a.PREVIOUS_GX_CODE,
       nvl(max(g.high_tech_code), 0) high_tech_code,
       nvl(max(g.high_tech_name), 0) high_tech_name,
       nvl(sum(g.high_prod_weight), 0) high_prod_weight,
       nvl(sum(g.high_mate_weight), 0) high_mate_weight,
       nvl(sum(g.estimated_unit_price), 0) estimated_unit_price,
       nvl(sum(g.estimated_cost), 0) estimated_cost,
       max((case
             when g.high_tech_code is null then
              '否'
             else
              '是'
           end)) FLAG
  from (select (select decode(max(s.order_typ),
                              '120108',
                              '双经销',
                              '120109',
                              '定销订购',
                              '120107',
                              '来料加工',
                              '自用')
                  from cxuser.slm_order_head s
                 where s.order_no = regexp_replace(t.pro_order_no, '/.*', '')) contract_type,
                 t.MODEL_DESC,
               --合同类型
               replace(t.PRO_ORDER_NO, '/', '') order_id,
               t.producname prod_variety,
               --品名、品种,
               t.steelname steel_level,
               --钢级,
               t.gradename steel_no,
               t.act_dimater,
                  t.act_height,
               --钢号,
               t.spec_name spec,
               --规格,
               (case
                 when t.target = 'A' then
                  '产成品'
                 else
                  '半成品'
               end) prod_type,
               --产量类型
               sum(decode(t.act_weight,
                          null,
                          t.act_theory_weight,
                          t.act_weight)) prod_weight,
               --成品重量
               sum(nvl(t.input_weight, 0)) + sum(nvl(t1.coupling_wt, 0)) +
               sum(nvl(t1.coupling_fail_wt, 0)) mate_weight,
               --来料重量
               (case
                 when sum(nvl(t.input_weight, 0)) +
                      sum(nvl(t1.coupling_wt, 0)) +
                      sum(nvl(t1.coupling_fail_wt, 0)) <> 0 then
                  round(sum(decode(t.act_weight,
                                   null,
                                   t.act_theory_weight,
                                   t.act_weight)) /
                        (sum(nvl(t.input_weight, 0)) +
                        sum(nvl(t1.coupling_wt, 0)) +
                        sum(nvl(t1.coupling_fail_wt, 0))),
                        4) * 100
                 else
                  0
               end) steel_waste,
               --消耗占比
               '加工' process,
               substr(T.bal_year_month, 0, 4) || '-' ||
               substr(T.bal_year_month, 5, 2) bal_year_month,
               mat.material_code mate_code,
               --物料编码
               getislljg(t.judge_stove_no, replace(t.PRO_ORDER_NO, '/', '')) resource_type,
               t.judge_stove_no,
               --是否来料加工
               null billet_code, --钢坯编码
               jgx.PREVIOUS_GX, jgx.PREVIOUS_GX_CODE
          from cxuser.qcm_zg_jugde_apply t,
               (select t1.heat_plan_no,
                       t1.judge_stove_no,
                       t1.batch_no,
                       sum(nvl(t1.coupling_wt, 0)) coupling_wt,
                       sum(nvl(t1.coupling_fail_wt, 0)) coupling_fail_wt
                  from cxuser.mch_twistingly_result_d t1
                 group by t1.heat_plan_no, t1.judge_stove_no, t1.batch_no) t1,
               (select a.basename, b.pline_code, b.pline_name
                  from cxuser.com_base_info a, cxuser.com_base_pline b
                 where a.basecode = b.factory_code) c,
               mvm_Order_matNo_info mat,pln_order_jgx jgx
         where t.PRO_ORDER_ID = jgx.pro_plan_id 
         and t.is_flag = '0'
           and t.is_all_scrap in ('0', '2')
           and ((t.validflag = '20' and t.target <> 'A' and
               t.judge_result_code in ('40740701', '40740705', '40740709')) or
               (t.validflag = '20' and t.target = 'A' and
               t.judge_tolresult_code in
               ('40740701', '40740705', '40740709')) or
               t.instancy_flag = '1')
           and t.process_code = 'G'
           and t.pline_name = c.pline_name(+)
           and t.heat_plan_no = t1.heat_plan_no(+)
           and t.judge_stove_no = t1.judge_stove_no(+)
           and mat.contractno_num = REPLACE(t.pro_order_no, '/', '')
           and t.batch_no = t1.batch_no(+)
           and t.pline_name in ('天淮加工1#线',
                                '天淮加工2#线',
                                '天淮外委加工线',
                                '天淮探伤简易线','套管线01#（635套管线）')
           AND t.bal_year_month = ?
         group by t.producname,
                  t.steelname,
                  t.gradename,
                  t.spec_name,
                  t.target,
                  T.bal_year_month,
                  T.pro_order_no,
                  T.judge_stove_no,
                  mat.material_code,
                  t.act_dimater,
                  t.act_height,t.MODEL_DESC,jgx.PREVIOUS_GX, jgx.PREVIOUS_GX_CODE) A
  left join gx_data_JG g
    on g.judge_stove_no = a.judge_stove_no
   and g.orderid = a.order_id
   and g.bal_year_month = a.bal_year_month
 group by a.CONTRACT_TYPE,
          a.PROD_VARIETY,
          a.ORDER_ID,
          a.STEEL_LEVEL,
          a.STEEL_NO,
          a.SPEC,
          a.PROD_TYPE,
          a.PROD_WEIGHT,
          a.MATE_WEIGHT,
          a.STEEL_WASTE,
          a.PROCESS,
          a.BAL_YEAR_MONTH,
          a.MATE_CODE,
          a.RESOURCE_TYPE,
          a.JUDGE_STOVE_NO,
          a.BILLET_CODE,
          a.act_dimater,
          a.act_height,a.MODEL_DESC,a.PREVIOUS_GX, a.PREVIOUS_GX_CODE

 


		]]>
	</query>
	<query id="TPoDemandPlan.queryjggxBF" desc="查询加工高新数据">
		<![CDATA[
		  select 
CONTRACT_TYPE,
PROD_VARIETY,
STEEL_LEVEL,
STEEL_NO,
SPEC,
PROD_TYPE,
PROD_WEIGHT,
MATE_WEIGHT,
STEEL_WASTE,
PROCESS,
HIGH_TECH_CODE,
HIGH_TECH_NAME,
HIGH_PROD_WEIGHT,
HIGH_MATE_WEIGHT,
ESTIMATED_UNIT_PRICE,
ESTIMATED_COST,
ACCT_PERIOD,
MATE_CODE,
RESOURCE_TYPE,
BILLET_CODE,
MEMO,
(case FLAG when '0' then '否' when '1' then '是' else FLAG end) FLAG,
CX_NO
 from HOT_PRODUCTION_MES_JG t where 1=1   and PROD_TYPE = '产成品' 

		]]>
	</query>
	
		<!-- tzh 24.9.13 add-->
	<query id="CorePlnZgMStoGp.updateZgMSWt" desc="修改坯料需求的重量">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
			   SET 
			       T.GPREQ_WEIGHT  = ?
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
			
		]]>
	</query>
	
			<!-- tzh 24.9.13 add-->
	<query id="CorePlnZgMStoGp.insertZgMSWt" desc="修改坯料需求的重量日志">
		<![CDATA[
			INSERT INTO PLN_ORDER_ZG_WT_LOG (
        PRO_PLAN_ID,
        GX_PLAN_NO,
        GPREQ_WEIGHT_OLD,
        GPREQ_WEIGHT_NEW,
        CREATE_MAN
       )
 VALUES( ?,
 		 ?,
 		  ?,
         ?,
         ?
        )
        
		]]>
	</query>
	
	 <!-- TZH 24.10.28 add -->
		<query id = "CorePlnZgMStoGp.GXS" desc = "查询高新基础信息">
		<![CDATA[
	SELECT GX_CODE,
       GX_NAME,
       GX_TIME,
       GX_CREATE,
       TO_CHAR(GX_DATE, 'YYYY-MM-DD HH24:MI:SS') GX_DATE,
       VALIDFLAG,
       DECODE(VALIDFLAG, '1', '有效', '无效') VALIDFLAGNAME,
       MEMO,
       GX_YFFY,
       GX_FZR,
       GX_UP_CREATE,
       GX_UP_TIME
  FROM HOT_PRODUCTION_MES_GX 
 WHERE VALIDFLAG IN ('1', ?)
   AND LOWER(GX_NAME) || '&' LIKE '%' || LOWER(?) || '%'
 ORDER BY GX_CODE
 	]]>
	</query>
	<!-- TZH 24.10.28 add -->
	<query id="CorePlnZgMStoGp.GXADD" desc="高新新增">
		<![CDATA[
			 INSERT INTO HOT_PRODUCTION_MES_GX
							(GX_CODE,
					        GX_NAME,
					        GX_TIME,
							GX_CREATE,
					        MEMO,
					        GX_YFFY,
					        GX_FZR
					        )
							VALUES(?,?,?,?,?,?,?)
								  
		]]>
	</query>
	<!-- TZH 24.10.28 add -->
	<query id="CorePlnZgMStoGp.GXMODIFY" desc="高新修改">
		<![CDATA[
			 UPDATE HOT_PRODUCTION_MES_GX set
							GX_NAME=?, 
							GX_TIME=?, 
							GX_UP_CREATE=?, 
							GX_UP_TIME=SYSDATE,
							MEMO=?,
							GX_YFFY=?,
							GX_FZR = ?
							WHERE GX_CODE=?
		]]>
	</query>
	<!-- TZH 24.10.28 add -->
	<query id="CorePlnZgMStoGp.GXDELETE" desc="高新作废">
		<![CDATA[
			 UPDATE HOT_PRODUCTION_MES_GX T
			   SET T.VALIDFLAG = '0'
			 WHERE T.GX_CODE = ?
		]]>
	</query>
	<!-- TZH 24.10.28 add -->
	<query id="CorePlnZgMStoGp.GXRESUME" desc="高新恢复">
		<![CDATA[
			 UPDATE HOT_PRODUCTION_MES_GX T
			   SET T.VALIDFLAG = '1'
			 WHERE T.GX_CODE = ?
		]]>
	</query>
	<!-- TZH 24.10.28 add -->
	<query id="CorePlnZgMStoGp.GXGetCode" desc="判断描述是否存在">
		<![CDATA[
			select GX_CODE from HOT_PRODUCTION_MES_GX where GX_CODE=?
		]]>
	</query>
	<query id="TPoDemandPlan.queryGXCNT" desc="查询rz高新数据">
		<![CDATA[
		   SELECT * FROM gx_data_rz WHERE judge_stove_no = ? AND orderid = ? AND bal_year_month = ?

		]]>
	</query>
	<query id="TPoDemandPlan.queryGXCNTRCL" desc="查询RCL高新数据">
		<![CDATA[
		   SELECT * FROM gx_data_rCL WHERE judge_stove_no = ? AND orderid = ? AND bal_year_month = ?

		]]>
	</query>
	<query id="TPoDemandPlan.queryGXCNTJG" desc="查询JG高新数据">
		<![CDATA[
		   SELECT * FROM gx_data_JG WHERE judge_stove_no = ? AND orderid = ? AND bal_year_month = ?

		]]>
	</query>
	<query id="TPoDemandPlan.insertCxMesGxRZ" desc="保存和撤销热轧高新">
		<![CDATA[
            
insert into gx_data_rz(judge_stove_no,
                       orderid,
                       bal_year_month,
                       high_tech_code,
                       high_tech_name,
                       high_prod_weight,
                       high_mate_weight,
                       estimated_unit_price,
                       estimated_cost)
                       values(?,?,?,?,?,?,?,?,?)
   ]]>
	</query>
	<!-- tzh 保存和撤销热轧高新 -->
	<query id="TPoDemandPlan.updateCxMesGxRZ" desc="保存和撤销热轧高新">
		<![CDATA[
  UPDATE gx_data_rz T
      SET T.high_tech_code = ?,t.high_tech_name=?,t.high_prod_weight=?,high_mate_weight=?,estimated_unit_price=?,estimated_cost=?
   WHERE T.judge_stove_no =? and T.orderid =? and T.bal_year_month =?
   ]]>
	</query>
	<query id="TPoDemandPlan.deleteCxMesGxRZ" desc="保存和撤销热轧高新">
		<![CDATA[
  delete from gx_data_rz
   WHERE judge_stove_no =? and orderid =? and bal_year_month =?
   ]]>
	</query>
	
	<query id="TPoDemandPlan.insertCxMesGxRCL" desc="保存和撤销热轧高新">
		<![CDATA[
            
insert into gx_data_rCL(judge_stove_no,
                       orderid,
                       bal_year_month,
                       high_tech_code,
                       high_tech_name,
                       high_prod_weight,
                       high_mate_weight,
                       estimated_unit_price,
                       estimated_cost)
                       values(?,?,?,?,?,?,?,?,?)
   ]]>
	</query>
	<!-- tzh 保存和撤销热轧高新 -->
	<query id="TPoDemandPlan.updateCxMesGxRCL" desc="保存和撤销热轧高新">
		<![CDATA[
  UPDATE gx_data_rCL T
      SET T.high_tech_code = ?,t.high_tech_name=?,t.high_prod_weight=?,high_mate_weight=?,estimated_unit_price=?,estimated_cost=?
   WHERE T.judge_stove_no =? and T.orderid =? and T.bal_year_month =?
   ]]>
	</query>
	<query id="TPoDemandPlan.deleteCxMesGxRCL" desc="保存和撤销热轧高新">
		<![CDATA[
  delete from gx_data_rCL
   WHERE judge_stove_no =? and orderid =? and bal_year_month =?
   ]]>
	</query>
	
	<query id="TPoDemandPlan.insertCxMesGxJG" desc="保存和撤销热轧高新">
		<![CDATA[
            
insert into gx_data_JG(judge_stove_no,
                       orderid,
                       bal_year_month,
                       high_tech_code,
                       high_tech_name,
                       high_prod_weight,
                       high_mate_weight,
                       estimated_unit_price,
                       estimated_cost)
                       values(?,?,?,?,?,?,?,?,?)
   ]]>
	</query>
	<!-- tzh 保存和撤销热轧高新 -->
	<query id="TPoDemandPlan.updateCxMesGxJG" desc="保存和撤销热轧高新">
		<![CDATA[
  UPDATE gx_data_JG T
      SET T.high_tech_code = ?,t.high_tech_name=?,t.high_prod_weight=?,high_mate_weight=?,estimated_unit_price=?,estimated_cost=?
   WHERE T.judge_stove_no =? and T.orderid =? and T.bal_year_month =?
   ]]>
	</query>
	<query id="TPoDemandPlan.deleteCxMesGxJG" desc="保存和撤销热轧高新">
		<![CDATA[
  delete from gx_data_JG
   WHERE judge_stove_no =? and orderid =? and bal_year_month =?
   ]]>
	</query>
</queryMap>