<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="管加工工序合同">

	<query id="CorePlnProcOrdJgx.queryPlnJgxOrd" desc="查询产线基础信息">
		<![CDATA[
			SELECT T.PRO_ORDER_NO,
			       T3.GX_PLAN_NO,
			       T.PLAN_GROUP_ID,
			       T.ORDER_SOURCE,
			       T1.ORD_LN_PK,
			       T2.CRAFT_SEQ,
			       T.ORD_LN_DLY_PK,
			       T.PLN_DIVIDE_ID,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       (T1.ORDER_NO || '/' || T1.ORDER_SEQ) ORDER_NO_SEQ,
			       T.DELIVERY_NO,
			       T.REQ_BL_ID,
			       T.INDEX_SEQ,
			       T.BOM,
			       T.BACKLOG_SEQ,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.AIMWALLTHICK,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.LENGTHDISC,
			       T.AIMLENGTH,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       (T.GETRATE * 100) GETRATE,
			       T.LENGTHMAX_IN,
			       T.LENGTHMIN_IN,
			       T.INWL_ID,
			       B.IN_MATERIAL_DESC INWL_DESC,
			       T.OUTWL_ID,
			       A.OUT_MATERIAL_DESC OUTWL_DESC,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.GROUP_JGX) GROUP_JGX,
			       T.PLINE_CODE_MAY,
			       T.PLINE_NAME_MAY,
			       T3.WEIGTH_S,
			       T3.NUM_S,
			       T.MATCH_WT,
			       T.MATCH_NUM,
			       DECODE(T.IFBUYPLAN, '0', '无', '1', '有') IFBUYPLAN,
			       T.BUYPLANID,
			       T.BUYPLAN_WT,
			       T.REQ_PROD_WT,
			       T.REQ_PROD_NUM,
			       TO_CHAR(T.PROD_END_DATE, 'YYYY-MM-DD HH24:MI:SS') PROD_END_DATE,
			       DECODE(T3.EXE_STATUS,
			              '0',
			              '计划',
			              '1',
			              '生产中',
			              '2',
			              '生产完成',
			              '异常') EXE_STATUS,
			       DECODE(T.IS_PLANED, '0', '否', '1', '是') IS_PLANED,
			       T.PRO_PLAN_ID,
			       T.FINISHWEIGHT,
			       DECODE(T.ISENDGX, '0', '否', '1', '是') ISENDGX,
			       T.NEXT_GX,
			       DECODE(T.IF_MONITOR_JGX, '0', '否', '1', '是') IF_MONITOR_JGX,
			       T.PRDCR_NO,
			       T.CRAFT_FILE_NO,
			       T.CRAFT_FILE_MAN,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       T3.PLINE_CODE,
			       T3.PLINE_NAME,
			       (SELECT REPLACE(TO_CHAR(WM_CONCAT(B.ASK_SUB_ITME_DESC || ':' ||
			                                         B.ASK_SUB_ITME_VAL_DESC)),
			                       ',',
			                       CHR(10))
			          FROM SLM_ORDER_ADD_ASK B
			         WHERE (B.ASK_ITME = '121001' OR B.ASK_ITME = '121003' OR
			               B.ASK_ITME = '121004')
			           AND B.ADD_ASK_NO = T1.ADD_ASK_NO) ADD_ASK_DESC
			  FROM PLN_ORDER_JGX 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
			  JOIN SLM_BASE_MATERIAL_I A
			    ON A.OUT_MATERIAL_NO = T.OUTWL_ID
			  JOIN SLM_BASE_MATERIAL_I_IN B
			    ON B.IN_MATERIAL_NO = T.INWL_ID, PLN_ORDER_JGX_S T3
			 WHERE B.IN_MATERIAL_SET = A.IN_MATERIAL_SET
			   AND T3.PRO_ORDER_NO = T.PRO_ORDER_NO
			   AND NVL(T1.ROLL_MONTH, '1') = NVL(?, NVL(T1.ROLL_MONTH, '1'))
			   AND (T1.ORDER_NO || '/' || T1.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND (T3.IS_REPAIR_PLN IS NULL OR T3.IS_REPAIR_PLN != '1')
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.queryBaseProcess" desc="查询工序基础表">
		<![CDATA[
			SELECT T.PROCESS_CODE, T.PROCESS_DESC
			  FROM COM_BASE_PROCESS T
			 WHERE T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.queryPineBase" 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="CorePlnProcOrdJgx.queryPineBaseId" desc="查询产线基础信息">
		<![CDATA[
			SELECT T.PLINE_CODE,
			       T.PLINE_NAME,
			       T.GROUP_PLAN
			  FROM COM_BASE_PLINE T
			 WHERE T.PLINE_CODE = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.queryJgOrdInf" desc="查询接箍合同">
		<![CDATA[
			SELECT T.JG_ORDERNO,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.BUYER_ID,
			       T.BUYER_NAME,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       T.MONITORDEMAND,
			       T.PSC,
			       T.INDEX_SEQ,
			       T.ORDERWEIGHT,
			       T.ORDERNUM,
			       T.CREATE_NAME,
			       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       T.UPDATE_NAME,
			       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       DECODE(T.JGORDERSTATUS,
			              '0',
			              '待处理',
			              '1',
			              '完成配料',
			              '2',
			              '已下发') JGORDERSTATUS,
			       T.MATCHWEIGHT,
			       T.MATCHNUM,
			       DECODE(T.IFBUYPLAN, '1', '有', '0', '无') IFBUYPLAN,
			       T.BUYPLANID,
			       T.BUYPLANWEIGHT,
			       T.BUYPLANNUM,
			       T.GROUP_JGX,
			       T.JGWT_BLREQ,
			       AA.*,
			       B.SPEC_NAME SPEC_JG_DESC,
			       C.BASENAME PRODUCCODE_JG_DESC,
			       D.STEELNAME STEELCODE_JG_DESC,
			       F.MODEL_DESC,
			       G.PRODUCNAME,
			       H.BASENAME STYLE_JG_DESC
			  FROM PLN_ORDER_JG T
			  LEFT JOIN (SELECT NVL((SELECT F.BASENAME
			                          FROM COM_BASE_INFO F
			                         WHERE F.BASECODE = B.DEMAND_DETECTION),
			                        B.DEMAND_DETECTION) DEMAND_DETECTION,
			                    NVL((SELECT F.BASENAME
			                          FROM COM_BASE_INFO F
			                         WHERE F.BASECODE = B.DEMAND_BONDERIZING),
			                        B.DEMAND_BONDERIZING) DEMAND_BONDERIZING,
			                    NVL((SELECT F.BASENAME
			                          FROM COM_BASE_INFO F
			                         WHERE F.BASECODE = B.DEMAND_COPPER),
			                        B.DEMAND_COPPER) DEMAND_COPPER,
			                    NVL((SELECT F.BASENAME
			                          FROM COM_BASE_INFO F
			                         WHERE F.BASECODE = B.DEMAND_BLAST),
			                        B.DEMAND_BLAST) DEMAND_BLAST,
			                    B.MSC,
			                    B.KEY_JG,
			                    B.CUST_ALPHA_NO,
			                    B.ORDER_SPECIAL_DESC,
			                    A.STD_NAME,
			                    A.STD_STYLE_DESC,
			                    A.CHECK_J_VAL,
			                    (SELECT REPLACE(WM_CONCAT(A.STEELCODE_JG_DESC), ',', ';')
			                       FROM COM_MSC_JG_R_STEEL N
			                      WHERE N.STEELCODE = A.STEELCODE_JG) REP_STEELNAME,
			                    A.TAPER,
			                    A.MIN_D_JG,
			                    A.MAX_D_JG,
			                    A.CODE_JG,
			                    A.SPEC_JG,
			                    A.PRODUCCODE_JG,
			                    A.STEELCODE_JG,
			                    (SELECT BASENAME
			                       FROM COM_BASE_INFO
			                      WHERE BASECODE = A.STYLE_JG) STYLE_JG,
			                    A.PRODUCCODE,
			                    A.MODEL_CODE,
			                    A.DIAMETER_JG,
			                    A.LENGTH_JG,
			                    A.HEIGHT_JG,
			                    A.WEIGHT_JG,
			                    A.MIN_D,
			                    A.MIN_H,
			                    A.DIAMETER_PL,
			                    A.HEIGHT_PL,
			                    A.LENGTH_MIN,
			                    A.LENGTH_MAX,
			                    A.MIN_H_CP,
			                    A.MAX_H_CP,
			                    A.MIN_D_CP,
			                    A.MAX_D_CP,
			                    A.DIAMETER,
			                    A.ALPHA
			               FROM COM_MSC_R_JG B, COM_MSC_JG A
			              WHERE B.STOCK_STYLE = 'A'
			                AND B.VALIDFLAG = '1'
			                AND B.CODE_JG = A.CODE_JG) AA
			    ON T.MSC = AA.MSC
			   AND T.CODE_JG = AA.CODE_JG
			  LEFT JOIN COM_BASE_SPEC B
			    ON B.SPEC_CODE = AA.SPEC_JG
			  LEFT JOIN COM_BASE_INFO C
			    ON C.BASECODE = AA.PRODUCCODE_JG
			  LEFT JOIN COM_BASE_STEEL D
			    ON D.STEELCODE = AA.STEELCODE_JG
			  LEFT JOIN COM_BASE_MODEL F
			    ON F.MODEL_CODE = AA.MODEL_CODE
			  LEFT JOIN COM_BASE_PRODUCT G
			    ON G.PRODUCCODE = AA.PRODUCCODE
			  LEFT JOIN COM_BASE_INFO H
			    ON H.BASECODE = AA.STYLE_JG
			 WHERE T.ORDER_NO = ?
			   AND T.ORDER_SEQ = ?
			   AND T.DELIVERY_NO = ?
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.queryJgxProcPine" desc="查询管加工工序可用产线">
		<![CDATA[
			SELECT T.PLINE_CODE, T.PLINE_NAME
		     FROM COM_BASE_PLINE T, PLN_ORDER_JGX T1
		     LEFT JOIN PLN_SALEORD T2
		       ON T2.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK, SLM_BASE_MATERIAL_k_PL B,
		    (SELECT M.ORD_LN_PK,
		                  M.CRAFT_SEQ,
		                  M1.MSC_PLINE,
		                  M1.PROCESS_CODE,
		                  M1.PLINE_CODE
		             FROM CRAFT_ORD_DESIGN M, CRAFT_ORD_DESIGN_MSC_PL_GX_PRL M1
		            WHERE M1.DESGIN_KEY = M.DESGIN_KEY
		              AND M1.PROCESS_CODE = 'G') E
		    WHERE T1.GROUP_JGX = T.GROUP_PLAN
		      AND B.OUT_MATERIAL_NO = T1.OUTWL_ID
		      AND B.IN_MATERIAL_NO = T1.INWL_ID
		      AND T.PLINE_CODE = B.PLINE_CODE
		      AND E.PLINE_CODE = B.PLINE_CODE
		      AND E.ORD_LN_PK = T2.ORD_LN_PK
		      AND E.CRAFT_SEQ = T1.CRAFT_SEQ
		      AND E.MSC_PLINE = T1.INDEX_SEQ
		      AND T1.PRO_ORDER_NO = ?
		    ORDER BY B.WASTE_RATE ASC
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.queryJgxProcMaterialPine" desc="查询管加工工序物料产线">
		<![CDATA[
			SELECT B.PLINE_CODE, B.PLINE_NAME
			  FROM PLN_ORDER_JGX T, SLM_BASE_MATERIAL_K_PL B
			 WHERE B.OUT_MATERIAL_NO = T.OUTWL_ID
			   AND B.IN_MATERIAL_NO = T.INWL_ID
			   AND T.PRO_ORDER_NO = ?
			 ORDER BY B.WASTE_RATE ASC
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.queryProcOrderNo" desc="查询工序产线">
		<![CDATA[
			SELECT T1.EXE_STATUS,
			       T.GROUP_JGX,
			       T1.PLINE_CODE,
			       T1.PLINE_NAME,
			       T1.GX_PLAN_NO,
			       (SELECT B.GROUP_PLAN
			          FROM COM_BASE_PLINE B
			         WHERE B.PLINE_CODE = T1.PLINE_CODE) PLINE_GROUP
			  FROM PLN_ORDER_JGX T, PLN_ORDER_JGX_S T1
			 WHERE T1.PRO_ORDER_NO = T.PRO_ORDER_NO
			   AND T1.PRO_ORDER_NO = ?
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.queryProcOrdStatus" desc="查询产线基础信息">
		<![CDATA[
			SELECT T1.EXE_STATUS,
			       T.GROUP_JGX,
			       T1.PLINE_CODE,
			       T1.PLINE_NAME,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = T.GROUP_JGX) GROUP_PLAN
			  FROM PLN_ORDER_JGX T, PLN_ORDER_JGX_S T1
			 WHERE T1.PRO_ORDER_NO = T.PRO_ORDER_NO
			   AND T1.PRO_ORDER_NO = ?
			   AND T1.GX_PLAN_NO = ?
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.updateJgxOrdPline" desc="修改管加工产线">
		<![CDATA[
			UPDATE PLN_ORDER_JGX T
			   SET T.PLINE_CODE = ?,
			       T.PLINE_NAME =
			       (SELECT B.PLINE_NAME FROM COM_BASE_PLINE B WHERE B.PLINE_CODE = ?)
			 WHERE T.PRO_ORDER_NO = ?
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.updateGroupJgxOrd" desc="修改管加工分组">
		<![CDATA[
			UPDATE PLN_ORDER_JGX T
	         SET T.GROUP_JGX =
	             (SELECT B.GROUP_PLAN FROM COM_BASE_PLINE B WHERE B.PLINE_CODE = ?)
	       WHERE T.PRO_ORDER_NO = ?
		]]>
	</query>

	<query id="CorePlnProcOrdJgx.updateGroupPlnOrdProc" desc="修改排产加工分组">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.GROUP_JGX =
			       (SELECT B.GROUP_PLAN FROM COM_BASE_PLINE B WHERE B.PLINE_CODE = ?)
			 WHERE T.ORD_LN_DLY_PK =
			       (SELECT M.ORD_LN_DLY_PK FROM PLN_ORDER_JGX M WHERE M.PRO_ORDER_NO = ?)
			   AND T.PLN_DIVIDE_ID =
			       (SELECT M.PLN_DIVIDE_ID FROM PLN_ORDER_JGX M WHERE M.PRO_ORDER_NO = ?)
		]]>
	</query>


	<query id="CorePlnProcOrdJgx.plineChange" desc="产线调整">
    	<![CDATA[
    		UPDATE PLN_ORDER_JGX_S T
			   SET T.PLAN_TIME_B  = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
			       T.PLAN_TIME_E  = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
			       T.PLAN_USETIME = ?,
			       T.PLINE_CODE   = ?,
			       T.PLINE_NAME   = (SELECT B.PLINE_NAME FROM COM_BASE_PLINE B WHERE B.PLINE_CODE = ?),
			       T.GX_PRO_SEQ  =?			       
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.GX_PLAN_NO = ?
    	]]>
	</query>
</queryMap>