<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="制程变更">

	<query id="CoreMscPlineChange.querySaleOrdProc" desc="查询合同排产">
             <![CDATA[
               SELECT T1.ORDER_NO || '/' || T1.ORDER_SEQ ORDER_NO_SEQ,
				       T1.ORD_LN_DLY_PK,
				       T1.PLN_DIVIDE_ID,
				       T1.ORDER_SOURCE,
				       T1.ORDER_NO,
				       T1.ORDER_SEQ,
				       T1.DELIVERY_NO,
				       T1.R_NUM_ID,
				       T1.PSC,
				       T1.CRAFT_FILE_NO,
				       T1.CRAFT_FILE_MAN,
				       T1.MSC,
				       T1.INDEX_SEQ,
				       T1.PROCESS_SEQ,
				       T1.BOM,
				       T1.GRADECODE_ALL,
				       (SELECT B.GRADENAME
				          FROM COM_BASE_GRADE B
				         WHERE B.GRADECODE = T1.GRADECODE) GRADECODE,
				       DECODE(T1.G_IS_OK, '否', '1', '是', '无') G_IS_OK,
				       (SELECT B.BASENAME
				          FROM COM_BASE_INFO B
				         WHERE B.BASECODE = T1.GROUP_JGX) GROUP_JGX,
				       DECODE(T1.F_IS_OK, '否', '1', '是', '无') F_IS_OK,
				       (SELECT B.BASENAME
				          FROM COM_BASE_INFO B
				         WHERE B.BASECODE = T1.GROUP_RCL) GROUP_RCL,
				       T1.GROUP_ROLL_ALL,
				       (SELECT B.PLINE_NAME
				          FROM COM_BASE_PLINE B
				         WHERE B.PLINE_CODE = T1.GROUP_ROLL) GROUP_ROLL,
				       T1.BJ_TYPE,
				       T1.E_IN_MATERIAL_NO,
				       T1.E_IN_MATERIAL_DESC,
				       T1.DIMATER_YLG,
				       T1.HEIGHT_YLG,
				       T1.MATERIAL_NO,
				       T1.MATERIAL_DESC,
				       T1.STUFF_PROPERTY,
				       DECODE(T1.GRADECODE_IS_OK, '否', '1', '是', '无') GRADECODE_IS_OK,
				       DECODE(T1.D_IS_OK, '0', '否', '1', '是', '无') D_IS_OK,
				       DECODE(T1.E_IS_OK, '0', '否', '1', '是', '无') E_IS_OK,
				       T1.WEIGHT_PER_M,
				       T1.PLAN_WT_D,
				       T1.PLAN_NUM_D,
				       T1.FINISH_WT,
				       DECODE(T1.IF_CHANGE, '0', '否', '1', '是', '无') IF_CHANGE,
				       T1.PLAN_WT_BEGIN,
				       T1.PLAN_NUM_BEGIN,
				       DECODE(T1.PLANSTATUS,
				              '0',
				              '维护中',
				              '1',
				              '计划',
				              '2',
				              '已下发',
				              '3',
				              '生产中',
				              '4',
				              '生产完成',
				              '5',
				              '关闭',
				              '6',
				              '取消',
				              '无') PLANSTATUS,
				       DECODE(T1.IF_ALLOW_ISSUE, '0', '否', '1', '是', '无') IF_ALLOW_ISSUE,
				       TO_CHAR(T1.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
				       T1.ISSUED_MAN,
				       T1.HEIGHT_NK_MIN,
				       T1.HEIGHT_NK_MAX,
				       T1.ORDER_QTY_D,
				       T1.ORDER_UNIT,
				       T1.AIM_LEN_ROLL,
				       T1.AIM_LEN_END,
				       T1.PLAN_P_MAIN,
				       (SELECT 100 *
				               DECODE(SUM(A.ORDERWEIGHT),
				                      0,
				                      0,
				                      SUM(NVL(A.FINISHWEIGHT, 0)) / SUM(A.ORDERWEIGHT))
				          FROM PLN_ORDER_ZG A
				         WHERE A.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
				           AND A.PLN_DIVIDE_ID = T1.PLN_DIVIDE_ID) FINISH_PRECENT3,
				       (SELECT 100 *
				               DECODE(SUM(A.ORDERWEIGHT),
				                      0,
				                      0,
				                      SUM(NVL(A.FINISHWEIGHT, 0)) / SUM(A.ORDERWEIGHT))
				          FROM PLN_ORDER_DBK A
				         WHERE A.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
				           AND A.PLN_DIVIDE_ID = T1.PLN_DIVIDE_ID) FINISH_PRECENT4,
				       (SELECT 100 *
				               DECODE(SUM(A.ORDERWEIGHT),
				                      0,
				                      0,
				                      SUM(NVL(A.FINISHWEIGHT, 0)) / SUM(A.ORDERWEIGHT))
				          FROM PLN_ORDER_RCL A
				         WHERE A.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
				           AND A.PLN_DIVIDE_ID = T1.PLN_DIVIDE_ID) FINISH_PRECENT5,
				       (SELECT 100 *
				               DECODE(SUM(A.ORDERWEIGHT),
				                      0,
				                      0,
				                      SUM(NVL(A.FINISHWEIGHT, 0)) / SUM(A.ORDERWEIGHT))
				          FROM PLN_ORDER_JGX A
				         WHERE A.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
				           AND A.PLN_DIVIDE_ID = T1.PLN_DIVIDE_ID) FINISH_PRECENT6
					  FROM PLN_SALEORD_PROC T1
					 WHERE T1.ORD_LN_DLY_PK = ?
					 AND (T1.PLANSTATUS IN ('2', '3') OR (T1.PLANSTATUS IN ('4', '5') 
					 AND TO_DATE(T1.ROLL_MONTH, 'YYYY-MM') = TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM')))
					  ORDER BY T1.ORDER_NO,T1.ORDER_SEQ,T1.DELIVERY_NO
                 ]]>
	</query>

	<query id="CoreMscPlineChange.queryPline" desc="查询制程">
             <![CDATA[
             SELECT T1.CRAFT_NO,
       T2.DESGIN_KEY,
       T1.CRAFT_SEQ,
       T2.MSC_PLINE,
       T2.WHOLE_BACKLOG,
       T2.WHOLE_BACKLOG_DESC,
       DECODE(T2.SET_FL,'1','是','否') SET_FL,
       T2.WARN_DESC,
       T2.ORD_LN_PK,
       DECODE(T2.VALIDFLAG,'1','有效','无效') VALIDFLAG
  FROM CRAFT_ORD_DESIGN        T1,
       CRAFT_ORD_DESIGN_MSC_PL T2,
       PLN_SALEORD T3
 WHERE T1.DESGIN_KEY = T2.DESGIN_KEY
   AND T1.ORD_LN_PK = T3.ORD_LN_PK
   AND T3.ORD_LN_DLY_PK = ?
                 ]]>
	</query>

	<query id="CoreMscPlineChange.queryGrade" desc="查询钢种">
             <![CDATA[
             SELECT DESGIN_KEY,
       MSC_PLINE,
       WHOLE_BACKLOG,
       WHOLE_BACKLOG_DESC,
       GRADECODE,
       GRADENAME,
       ASSORTMENT_CODE,
       ASSORTMENT_NAME
  FROM CRAFT_ORD_DESIGN_MSC_PL_GZ T
 WHERE T.DESGIN_KEY = ?
   AND T.MSC_PLINE = ?
                 ]]>
	</query>

	<query id="CoreMscPlineChange.queryOperation" desc="查询工序">
             <![CDATA[
             SELECT DESGIN_KEY,
       MSC_PLINE,
       WHOLE_BACKLOG,
       WHOLE_BACKLOG_DESC,
       BACKLOG_SEQ,
       PROCESS_CODE,
       PROCESS_DESC,
       PROCESS_SEQ,
       PROCESS_CODE_C,
       PROCESS_DESC_C,
       MINUTE_PRODUCT,
       MINUTE_PRODUCT_OUT,
       MINUTE_WAITE,
       MINUTE_WAITE_OUT,
       BATCH_WAITE,
       BATCH_WAITE_OUT,
       CIC,
       PIC,
       SIC,
       DIC,
       WIC,
       GIC
  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T
 WHERE T.DESGIN_KEY = ?
   AND T.MSC_PLINE = ?
   ORDER BY T.PROCESS_CODE
                 ]]>
	</query>

	<query id="CoreMscPlineChange.queryOperationPoint" desc="查询工序点">
             <![CDATA[
             SELECT REPLACE(WMSYS.WM_CONCAT(T.STATION_DESC || '->'), ',', '') POINTS
  FROM CRAFT_ORD_DESIGN_MSC_PL_STI T
 WHERE T.DESGIN_KEY = ?
   AND T.MSC_PLINE = ?
 ORDER BY T.STATION_ID
                 ]]>
	</query>

	<query id="CoreMscPlineChange.queryBom" desc="查询BOM">
             <![CDATA[
            SELECT T.MATERIAL_NO,
       T.MATERIAL_DESC,
       T.BOM,
       DECODE(T.BOM_TYP,'A','产品','B','产品配接','C','产品备料','D','接箍备料') BOM_TYP,
       T.MSC_PLINE,
       T.WHOLE_BACKLOG,
       T.WHOLE_BACKLOG_DESC,
       T.MSC,
       T.MSC_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE_C,
       T.SPEC_NAME_C,
       T.SPEC_CODE_R,
       T.SPEC_NAME_R,
       T.SPEC_CODE_D,
       T.SPEC_NAME_D,
       T.SPEC_CODE_Z,
       T.SPEC_NAME_Z,
       T.A_IN_MATERIAL_NO,
       T.A_IN_MATERIAL_DESC,
       T.A_OUT_MATERIAL_NO,
       T.A_OUT_MATERIAL_DESC,
       T.B_IN_MATERIAL_NO,
       T.B_IN_MATERIAL_DESC,
       T.B_OUT_MATERIAL_NO,
       T.B_OUT_MATERIAL_DESC,
       T.C_IN_MATERIAL_NO,
       T.C_IN_MATERIAL_DESC,
       T.C_OUT_MATERIAL_NO,
       T.C_OUT_MATERIAL_DESC,
       T.D_IN_MATERIAL_NO,
       T.D_IN_MATERIAL_DESC,
       T.D_OUT_MATERIAL_NO,
       T.D_OUT_MATERIAL_DESC,
       T.E_IN_MATERIAL_NO,
       T.E_IN_MATERIAL_DESC,
       T.E_OUT_MATERIAL_NO,
       T.E_OUT_MATERIAL_DESC,
       T.F_IN_MATERIAL_NO,
       T.F_IN_MATERIAL_DESC,
       T.F_OUT_MATERIAL_NO,
       T.F_OUT_MATERIAL_DESC,
       T.J_IN_MATERIAL_NO,
       T.J_IN_MATERIAL_DESC,
       T.J_OUT_MATERIAL_NO,
       T.J_OUT_MATERIAL_DESC,
       T.I_IN_MATERIAL_NO,
       T.I_IN_MATERIAL_DESC,
       T.I_OUT_MATERIAL_NO,
       T.I_OUT_MATERIAL_DESC,
       T.PROCESS_CODE_CS
  FROM SLM_ORD_DESIGN_BOM T
 WHERE  T.MATERIAL_NO = ?
   AND T.MSC = ?
   AND T.MSC_PLINE = ?
   AND T.WHOLE_BACKLOG = ?
                 ]]>
	</query>


	<query id="CoreMscPlineChange.queryLine" desc="查询轧管产线">
             <![CDATA[
             SELECT DISTINCT T1.PLINE_CODE, T1.PLINE_NAME
  FROM CRAFT_ORD_DESIGN_MSC_PL_GX_PRL T1, CRAFT_ORD_DESIGN_MSC_GZ_GG_PL T2
 WHERE T1.DESGIN_KEY = T2.DESGIN_KEY
   AND T1.PLINE_CODE = T2.PLINE_CODE
   AND T1.DESGIN_KEY = ?
   AND T1.MSC_PLINE = ?
   AND T1.PLINE_CODE IN (SELECT T3.PLINE_CODE
                           FROM SLM_BASE_MATERIAL_D_PL T3
                          WHERE T3.IN_MATERIAL_NO = ?
                            AND T3.OUT_MATERIAL_NO = ?)
                 ]]>
	</query>
	
	<query id="CoreMscPlineChange.queryProcCraftIndex" desc="查询排产行工艺制程物料产线">
		<![CDATA[
			SELECT T.CRAFT_SEQ, T.INDEX_SEQ, T.BOM, T.GROUP_ROLL, M.DESGIN_KEY
			  FROM PLN_SALEORD_PROC T
			  LEFT JOIN PLN_SALEORD T2
			    ON T2.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.ORD_LN_PK = t2.ord_ln_pk
			   AND T.CRAFT_SEQ = M.CRAFT_SEQ
			 WHERE T.ORD_LN_DLY_PK = ?
			   AND T.PLN_DIVIDE_ID = ?
		]]>
	</query>
	
	<query id="CoreMscPlineChange.queryBomMaterialNo" desc="查询Bom工序产出物料">
		<![CDATA[
			SELECT T.B_OUT_MATERIAL_NO,
			       T.C_OUT_MATERIAL_NO,
			       T.D_OUT_MATERIAL_NO,
			       T.E_OUT_MATERIAL_NO,
			       T.F_OUT_MATERIAL_NO
			  FROM SLM_ORD_DESIGN_BOM T
			 WHERE T.BOM = ?
		]]>
	</query>

</queryMap>