<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="合同制程更改">
	<query id="CoreChangeIndex.queryPlnOrderProc" desc="查询合同拆分明细">
		<![CDATA[
			SELECT T.ORD_LN_DLY_PK,
			       T.PLN_DIVIDE_ID,
			       T.ORDER_SOURCE,
			       T.ROLL_MONTH,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.R_NUM_ID,
			       T.PSC,
			       T.CRAFT_SEQ,
			       T.CRAFT_FILE_NO,
			       T.CRAFT_FILE_MAN,
			       T.MSC,
			       T.INDEX_SEQ,
			       T.PROCESS_SEQ,
			       T.BOM,
			       T.GRADECODE_ALL,
			       (SELECT A.GRADENAME
			          FROM COM_BASE_GRADE A
			         WHERE A.GRADECODE = T.GRADECODE) GRADECODE,
			       DECODE(T.G_IS_OK, '0', '否', '1', '是', '2', '/') G_IS_OK,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.GROUP_JGX) GROUP_JGX,
			       DECODE(T.F_IS_OK, '0', '否', '1', '是', '2', '/') F_IS_OK,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.GROUP_RCL) GROUP_RCL,
			       T.GROUP_ROLL_ALL,
			       (SELECT A.PLINE_NAME
			          FROM COM_BASE_PLINE A
			         WHERE A.PLINE_CODE = T.GROUP_ROLL) GROUP_ROLL,
			       T.BJ_TYPE,
			       T.E_IN_MATERIAL_NO,
			       T.E_IN_MATERIAL_DESC,
			       T.DIMATER_YLG,
			       T.HEIGHT_YLG,
			       T.MATERIAL_NO,
			       T.MATERIAL_DESC,
			       T.STUFF_PROPERTY,
			       DECODE(T.GRADECODE_IS_OK, '0', '否', '1', '是') GRADECODE_IS_OK,
			       DECODE(T.D_IS_OK, '0', '否', '1', '是', '2', '/') D_IS_OK,
			       DECODE(T.PLAN_IS_OK, '0', '否', '1', '是') PLAN_IS_OK,
			       DECODE(T.E_IS_OK, '0', '否', '1', '是', '2', '/') E_IS_OK,
			       T.WEIGHT_PER_M,
			       T.PLAN_WT_D,
			       T.PLAN_NUM_D,
			       T.FINISH_WT,
			       DECODE(T.IF_CHANGE, '1', '是', '0', '否') IF_CHANGE,
			       T.PLAN_WT_BEGIN,
			       T.PLAN_NUM_BEGIN,
			       T.HEIGHT_NK_MIN,
			       T.HEIGHT_NK_MAX,
			       T.ORDER_QTY_D,
			       T.ORDER_UNIT,
			       T.AIM_LEN_ROLL,
			       T.AIM_LEN_END,
			       T.TOT_LEN_ONE_P,
			       T.CUT_NUM_P,
			       T.AIM_WALLTHICK,
			       T.ROLL_LENGTH,
			       T.PLAN_P_MAIN,
			       DECODE(T.PLANSTATUS,
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '关闭',
			              '6',
			              '取消') PLANSTATUS,
			       DECODE(T.IF_ALLOW_ISSUE, '0', '否', '1', '是') IF_ALLOW_ISSUE,
			       TO_CHAR(T.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
			       T.ISSUED_MAN,
			       T.IF_EXPORT, T.AIM_OUTDIAMETER,
           T.FEED_RATE,T.COEFFICIENT,T.COEFFICIENT_MIN,T.PLAN_P_MAIN_MIN,T.AIM_WT_END,T.WEIGHT_KZ_M,
           NVL((SELECT T1.CHECK_J_VAL
             FROM COM_MSC_JG T1
            WHERE T1.CODE_JG = E.CODE_JG
              AND T1.VALIDFLAG = '1'),
           0)/1000 CHECK_J_VAL,
       NVL((SELECT T1.WEIGHT_JG
             FROM COM_MSC_JG T1
            WHERE T1.CODE_JG = E.CODE_JG
              AND T1.VALIDFLAG = '1'),
           0)/1000 WEIGHT_JG
			  FROM PLN_SALEORD_PROC T, PLN_SALEORD E 
			 WHERE T.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK AND T.ORD_LN_DLY_PK = ?
			AND T.PLN_DIVIDE_ID=?
		]]>
	</query>
	
	<query id="CoreChangeIndex.queryPlnSaleOrderProc" desc="查询交货行子记录">
		<![CDATA[
			SELECT T1.ORDER_NO,
			       T1.ORDER_SEQ,
			       T1.DELIVERY_NO,
			       T1.PORDERSTATUS,
			       T1.FINAL_USER,
			       T1.PRODUCCODE,
			       T1.MSC,
			       T1.MATERIAL_NO,
			       T1.MERGETYPE,
			       T.ROLL_MONTH,
			       T1.CODE_JG,
			       T1.OUTDIAMETER,
			       T1.OUTS_BILLET_FL,
			       T1.OUTS_STL_PIPE_FL,
			       T1.OUTDIAMETER,
			       T1.WALLTHICK,
			       T1.LENGTHMAX,
			       T1.LENGTHMIN,
			       T1.DELVRY_RANGE_TPE,
			       T1.DELVRY_RANGE_MIN,
			       T1.DELVRY_RANGE_MAX,
			       T.WEIGHT_PER_M,
			       T.INDEX_SEQ,
			       T.CRAFT_FILE_NO,
			       T.CRAFT_SEQ,
			       T1.PRDCR_NO
			  FROM PLN_SALEORD_PROC T, PLN_SALEORD T1
			 WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
			   AND T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CoreChangeIndex.queryPlnOrdProcById" desc="查询交货行子记录状态">
		<![CDATA[
			SELECT (SELECT DESGIN_KEY
			          FROM CRAFT_ORD_DESIGN M
			         WHERE M.ORD_LN_PK = T1.ORD_LN_PK
			           AND M.CRAFT_SEQ = T.CRAFT_SEQ) DESGIN_KEY,
			       T.ORDER_QTY_D,
			       T.ORDER_UNIT,
			       T.PLAN_WT_D,
			       T.PLAN_NUM_D,
			       T.FINISH_WT,
			       T.INDEX_SEQ,
			       T.BOM,
			       T.GROUP_ROLL,
			       T.AIM_LEN_END,
			       T.WEIGHT_PER_M,
			       T.PLANSTATUS,
			       T.PROCESS_SEQ,
			       T1.OUTS_STL_PIPE_FL,
			       T.COEFFICIENT_MIN,
			       T.GRADECODE_ALL,
			       T.IF_EXPORT
			  FROM PLN_SALEORD_PROC T, PLN_SALEORD T1
			 WHERE T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			   AND T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	
	<query id="CoreChangeIndex.newPlnOrdProc" desc="新增交货行子记录">
		<![CDATA[
			INSERT INTO PLN_SALEORD_PROC
		          (ORD_LN_DLY_PK,
		           PLN_DIVIDE_ID,
		           ORDER_SOURCE,
		           ORDER_NO,
		           ORDER_SEQ,
		           DELIVERY_NO,
		           PSC,
		           CRAFT_SEQ,
		           CRAFT_NO_V,
		           CRAFT_FILE_NO,
		           CRAFT_FILE_MAN,
		           MSC,
		           INDEX_SEQ,
		           PROCESS_SEQ,
		           BOM,
		           GRADECODE_ALL,
		           GRADECODE,
		           G_IS_OK,
		           GROUP_JGX,
		           F_IS_OK,
		           GROUP_RCL,
		           GROUP_ROLL_ALL,
		           GROUP_ROLL,
				   GROUP_ROLL_NAME,
		           BJ_TYPE,
		           ABC,
		           E_IN_MATERIAL_NO,
		           E_IN_MATERIAL_DESC,
		           DIMATER_YLG,
		           HEIGHT_YLG,
		           MATERIAL_NO,
		           MATERIAL_DESC,
		           STUFF_PROPERTY,
		           GRADECODE_IS_OK,
		           D_IS_OK,
		           E_IS_OK,
		           WEIGHT_PER_M,
		           PLAN_WT_D,
		           PLAN_NUM_D,
		           FINISH_WT,
		           PLANSTATUS,
		           IF_ALLOW_ISSUE,
		           HEIGHT_NK_MIN,
		           HEIGHT_NK_MAX,
		           ORDER_QTY_D,
		           ORDER_UNIT,
		           AIM_LEN_ROLL,
		           AIM_LEN_END,
		           PLAN_P_MAIN,
		           PLAN_TOT_LEN_D,
		           TOT_LEN_ONE_P,
		           CUT_NUM_P,
		           AIM_WALLTHICK,
		           ROLL_LENGTH,
				   LEN_ROLL_MAX,
				   LEN_ROLL_MIN,
		           PRDCRPRO,AIM_OUTDIAMETER,
           FEED_RATE,COEFFICIENT,COEFFICIENT_MIN,PLAN_P_MAIN_MIN,AIM_WT_END,WEIGHT_KZ_M,IF_EXPORT)
		          SELECT B.ORD_LN_DLY_PK,
		                 (SELECT LPAD(NVL(MAX(TO_NUMBER(C.PLN_DIVIDE_ID) + 1), 1), 2, '0')
						            FROM PLN_SALEORD_PROC C
						           WHERE C.ORD_LN_DLY_PK = B.ORD_LN_DLY_PK),
		                 '#ORDER_SOURCE#',
		                 B.ORDER_NO,
		                 B.ORDER_SEQ,
		                 B.DELIVERY_NO,
		                 B.PSC,
		                 '#CRAFT_SEQ#',
				         (SELECT M.CRAFT_NO_V
				            FROM CRAFT_ORD_DESIGN M
				           WHERE M.ORD_LN_PK = B.ORD_LN_PK
				             AND M.CRAFT_SEQ = '#CRAFT_SEQ#'),
				         (SELECT M.CRAFT_NO
				            FROM CRAFT_ORD_DESIGN M
				           WHERE M.ORD_LN_PK = B.ORD_LN_PK
				             AND M.CRAFT_SEQ = '#CRAFT_SEQ#'),
				         (SELECT M.CRAFT_NAME
				            FROM CRAFT_ORD_DESIGN_APPOINT M
				           WHERE M.ORD_LN_PK = B.ORD_LN_PK),
		                 B.MSC,
		                 '#INDEX_SEQ#',
		                 '#PROCESS_SEQ#',
		                 '#BOM#',
		                 '#GRADECODE_ALL#',
		                 '#GRADECODE#',
		                 '#G_IS_OK#',
		                 '#GROUP_JGX#',
		                 '#F_IS_OK#',
		                 '#GROUP_RCL#',
		                 '#GROUP_ROLL_ALL#',
		                 '#GROUP_ROLL#',
				         (SELECT B.PLINE_NAME
				          FROM COM_BASE_PLINE B
				         WHERE B.PLINE_CODE = '#GROUP_ROLL#'),
		                 '#BJ_TYPE#',
		                 '#ABC#',
		                 '#E_IN_MATERIAL_NO#',
		                 '#E_IN_MATERIAL_DESC#',
		                 '#DIMATER_YLG#',
		                 '#HEIGHT_YLG#',
		                 B.MATERIAL_NO,
		                 B.MATERIAL_DESC,
		                 '#STUFF_PROPERTY#',
		                 '0',
		                 '#D_IS_OK#',
		                 '#E_IS_OK#',
		                 '#WEIGHT_PER_M#',
		                 '#PLAN_WT_D#',
		                 '#PLAN_NUM_D#',
		                 '0',
		                 '1',
		                 '0',
		                 '#HEIGHT_NK_MIN#',
		                 '#HEIGHT_NK_MAX#',
		                 '#ORDER_QTY_D#',
		                 B.ORDER_UNIT,
		                 '#AIM_LEN_ROLL#',
		                 '#AIM_LEN_END#',
		                 '#PLAN_P_MAIN#',
		                 '#PLAN_TOT_LEN_D#',
		                 '#TOT_LEN_ONE_P#',
		                 '#CUT_NUM_P#',
		                 '#AIM_WALLTHICK#',
		                 '#ROLL_LENGTH#',
				         '#LEN_ROLL_MAX#',
				         '#LEN_ROLL_MIN#',
		                 '#PRDCRPRO#','#AIM_OUTDIAMETER#',
           '#FEED_RATE#','#COEFFICIENT#','#COEFFICIENT_MIN#',
           '#PLAN_P_MAIN_MIN#','#AIM_WT_END#','#WEIGHT_KZ_M#','#IF_EXPORT#'
		            FROM PLN_SALEORD B
		           WHERE B.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		]]>
	</query>
	
	<query id="CoreChangeIndex.updateProcOrdQtyD" desc="更新原交货拆分记录分配量">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.PLAN_WT_D      = T.PLAN_WT_D * (? / T.ORDER_QTY_D),
			       T.PLAN_NUM_D     = T.PLAN_NUM_D * (? / T.ORDER_QTY_D),
			       T.ORDER_QTY_D    = ?,
			       T.PLAN_P_MAIN    = T.PLAN_P_MAIN * (? / T.ORDER_QTY_D),
			       T.PLAN_TOT_LEN_D = T.PLAN_TOT_LEN_D * (? / T.ORDER_QTY_D),
			       T.PLAN_P_MAIN_MIN = T.PLAN_P_MAIN_MIN*(?/T.ORDER_QTY_D)
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	
	<query id="CoreChangeIndex.updatePlnOrdProcOutPi" desc="更新外购管交货行子记录拆分量">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.PLAN_WT_D      = '#PLAN_WT_D#',
			       T.PLAN_NUM_D     = '#PLAN_NUM_D#',
			       T.ORDER_QTY_D    = '#ORDER_QTY_D#',
			       T.AIM_LEN_END    = '#AIM_LEN_END#',
			       T.PLAN_P_MAIN    = '#PLAN_P_MAIN#',
			       T.PLAN_TOT_LEN_D = '#PLAN_TOT_LEN_D#',
			       T.PLAN_P_MAIN_MIN = '#PLAN_P_MAIN_MIN#'
			 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
			   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
		]]>
	</query>
	
	<query id="CoreChangeIndex.updatePlnOrdProc" desc="更新交货行子记录拆分量">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.PLAN_WT_D      = '#PLAN_WT_D#',
			       T.PLAN_NUM_D     = '#PLAN_NUM_D#',
			       T.ORDER_QTY_D    = '#ORDER_QTY_D#',
			       T.WEIGHT_PER_M   = '#WEIGHT_PER_M#',
			       T.AIM_LEN_END    = '#AIM_LEN_END#',
			       T.AIM_LEN_ROLL   = '#AIM_LEN_ROLL#',
			       T.PLAN_P_MAIN    = '#PLAN_P_MAIN#',
			       T.PLAN_TOT_LEN_D = '#PLAN_TOT_LEN_D#',
			       T.TOT_LEN_ONE_P  = '#TOT_LEN_ONE_P#',
			       T.CUT_NUM_P      = '#CUT_NUM_P#',
			       T.AIM_WALLTHICK  = '#AIM_WALLTHICK#',
			       T.ROLL_LENGTH    = '#ROLL_LENGTH#',
			       T.AIM_OUTDIAMETER = '#AIM_OUTDIAMETER#',
                   T.FEED_RATE       = '#FEED_RATE#',
                   T.COEFFICIENT     = '#COEFFICIENT#',
			       T.PLAN_P_MAIN_MIN = '#PLAN_P_MAIN_MIN#',
			       T.AIM_WT_END      = '#AIM_WT_END#',
			       T.WEIGHT_KZ_M     = '#WEIGHT_KZ_M#'
			 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
			   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
		]]>
	</query>
	
	<query id="CoreChangeIndex.queryNewCaft" desc="查询排产行更新的工艺文件信息">
		<![CDATA[
			SELECT M.ORD_LN_PK, M.CRAFT_SEQ
			  FROM PLN_SALEORD_PROC T
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.CRAFT_NO = T.CRAFT_NO_NEW
			   AND M.CRAFT_NO_V = T.CRAFT_NO_V_NEW
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	
	<query id="CoreChangeIndex.updateNewCaft" desc="更新">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.CRAFT_NO_NEW = '', T.CRAFT_NO_V_NEW = '', T.CRAFT_RENEW_ST = '2'
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	
	<query id="CoreChangeIndex.updatePlnOrdProcAmout" desc="更新交货行子记录制程工艺j,重算量">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.WEIGHT_PER_M       = '#WEIGHT_PER_M#',
			       T.PLAN_WT_D          = '#PLAN_WT_D#',
			       T.PLAN_NUM_D         = '#PLAN_NUM_D#',
			       T.AIM_LEN_ROLL       = '#AIM_LEN_ROLL#',
			       T.AIM_LEN_END        = '#AIM_LEN_END#',
			       T.PLAN_P_MAIN        = '#PLAN_P_MAIN#',
			       T.PLAN_TOT_LEN_D     = '#PLAN_TOT_LEN_D#',
			       T.TOT_LEN_ONE_P      = '#TOT_LEN_ONE_P#',
			       T.CUT_NUM_P          = '#CUT_NUM_P#',
			       T.AIM_WALLTHICK      = '#AIM_WALLTHICK#',
			       T.ROLL_LENGTH        = '#ROLL_LENGTH#'
			 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
			   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
		]]>
	</query>
	
	<query id="CoreChangeIndex.updatePlnOrdProcDPline" desc="更新产线">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.GROUP_ROLL = '#GROUP_ROLL#', T.D_IS_OK = '#D_IS_OK#'
			 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
			   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
		]]>
	</query>
	
	<query id="CoreChangeIndex.updatePlnOrdProcMscPline" desc="更新交货行子记录制程工艺">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.INDEX_SEQ          = '#INDEX_SEQ#',
			       T.PROCESS_SEQ        = '#PROCESS_SEQ#',
			       T.BOM                = '#BOM#',
			       T.GRADECODE_ALL      = '#GRADECODE_ALL#',
			       T.GRADECODE          = '#GRADECODE#',
			       T.GROUP_ROLL_ALL     = '#GROUP_ROLL_ALL#',
			       T.GROUP_ROLL         = '#GROUP_ROLL#',
			       T.GROUP_ROLL_NAME =
			       (SELECT B.PLINE_NAME
			          FROM COM_BASE_PLINE B
			         WHERE B.PLINE_CODE = '#GROUP_ROLL#'),
			       T.BJ_TYPE            = '#BJ_TYPE#',
			       T.ABC                = '#ABC#',
			       T.E_IN_MATERIAL_NO   = '#E_IN_MATERIAL_NO#',
			       T.E_IN_MATERIAL_DESC = '#E_IN_MATERIAL_DESC#',
			       T.DIMATER_YLG        = '#DIMATER_YLG#',
			       T.HEIGHT_YLG         = '#HEIGHT_YLG#',
			       T.GROUP_JGX          = '#GROUP_JGX#',
			       T.GROUP_RCL          = '#GROUP_RCL#',
			       T.STUFF_PROPERTY     = '#STUFF_PROPERTY#',
			       T.GRADECODE_IS_OK    = '0',
			       T.E_IS_OK            = '#E_IS_OK#',
			       T.D_IS_OK            = '#D_IS_OK#',
			       T.PROC_DESC_C_RCL    ='#PROC_DESC_C_RCL#'
			 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
			   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
		]]>
	</query>
	
	<query id="CoreChangeIndex.updatePlnOrdProcCraft" desc="更新交货行子记录工艺">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T
			   SET T.CRAFT_FILE_NO =
			       (SELECT M.CRAFT_NO
			          FROM CRAFT_ORD_DESIGN M, PLN_SALEORD T1
			         WHERE M.ORD_LN_PK = T1.ORD_LN_PK
			           AND T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			           AND M.CRAFT_SEQ = '#CRAFT_SEQ#'),
			       T.CRAFT_FILE_MAN =
			       (SELECT M.CRAFT_NAME
			          FROM CRAFT_ORD_DESIGN_APPOINT M, PLN_SALEORD T1
			         WHERE M.ORD_LN_PK = T1.ORD_LN_PK
			           AND T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK),
			       T.CRAFT_SEQ      = '#CRAFT_SEQ#',
			       T.CRAFT_NO_V    =
			       (SELECT M.CRAFT_NO_V
			          FROM CRAFT_ORD_DESIGN M, PLN_SALEORD T1
			         WHERE M.ORD_LN_PK = T1.ORD_LN_PK
			           AND T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			           AND M.CRAFT_SEQ = '#CRAFT_SEQ#')
			 WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
			   AND T.PLN_DIVIDE_ID = '#PLN_DIVIDE_ID#'
		]]>
	</query>
	
	<query id="CoreChangeIndex.deletePlnOrdProc" desc="删除交货行子记录">
		<![CDATA[
			DELETE FROM PLN_SALEORD_PROC T
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	
</queryMap>
