<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="销售合同接收下发">
	<query id="CoreOrdFinishSet.querySaleOrderSc" desc="查询销售合同">
		<![CDATA[
			SELECT T.ORD_PK,
			       T.ORD_LN_PK,
			       T.ORD_LN_DLY_PK,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       (T.ORDER_NO || '/' || T.ORDER_SEQ) ORDER_NO_SEQ,
			       (SELECT A.PRODUC_DESC
			          FROM COM_BASE_PRODUCT A
			         WHERE A.PRODUCCODE = T.PRODUCCODE
			           AND A.VALIDFLAG = '1') PRD_CLS,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.LEN_UNIT,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.LENGTHDISC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.ORDER_UNIT,
			       T.ORDER_QTY,
			       T.ORDERWEIGHT,
			       DECODE(T.ORDER_UNIT, '米', '吨', '英尺', '吨', T.ORDER_UNIT) ORDERWEIGHTUNIT,
			       DECODE(T.TOTLENGTH, 0, '', T.TOTLENGTH) TOTLENGTH,
			       T.TOTLENGTH_UNIT,
			       T.DELVRY_RANGE_TPE,
			       T.DELVRY_RANGE_MIN,
			       T.DELVRY_RANGE_MAX,
			       '(-' || TO_CHAR(ABS(T.DELVRY_RANGE_MIN)) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
			       TO_CHAR(T.DELVRY_RANGE_MAX) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
			       T.BUYER_ID,
			       (SELECT A.ABRVITION
			          FROM SLM_BASE_CUSTOMER A
			         WHERE A.CUSTOMER_NO = T.BUYER_ID) BUYER_NAME,
			       T.ORDER_SPECIAL_DESC,
			       T.ADD_ASK_NO,
			       T2.ORDER_ADD_DESC,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.ORDERFROM) ORDERFROM,
			       T.FINAL_USER,
			       NVL((SELECT A.ABRVITION
			             FROM SLM_BASE_CUSTOMER A
			            WHERE A.CUSTOMER_NO = DECODE(T.FINAL_USER,
			                                         NULL,
			                                         T.BUYER_ID,
			                                         '/',
			                                         T.BUYER_ID,
			                                         T.FINAL_USER)),
			           DECODE(T.FINAL_USER_DESC,
			                  NULL,
			                  T.BUYER_NAME,
			                  '/',
			                  T.BUYER_NAME,
			                  T.FINAL_USER_DESC)) FINAL_USER_DESC,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.MONITORDEMAND) MONITORDEMAND,
			       T.SPECSTANDARD,
			       DECODE(T.PORDERSTATUS,
			              '0',
			              '待接收',
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成') PORDERSTATUS,
			       T.PSC,
			       T.MSC,
			       T.CODE_JG,
			       T.CODE_DJ_BL,
			       T.PLANWEIGHT,
			       T.PAYDOWNWEIGHT,
			       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,
			       T.ENDGXNAME,
			       T.MERGETYPE,
			       DECODE(T.JZ_FILE_IF_ALL, '1', '是', '0', '否') JZ_FILE_IF_ALL,
			       T.PRDCR_NO,
			       T.ROLL_MONTH,
			       T.MATERIAL_NO,
			       T.MATERIAL_DESC,
			       T.BL_GROUP_NUM,
			       T.SHRT_LEN_RATO,
			       T.SHORTEST,
			       T.LONG_LEN_RATO,
			       T.LONGEST,
			       T.SHRT_STOVE,
			       T.AVG_LEN_MIN,
			       T.DIFRNC_LEN_MAX,
			       T.SIGL_LEN,
			       T.ENDLEN_SPECSTD,
			       T.STATION_NO,
			       T.STATION_NM,
			       T.PRODUCE_SORT,
			       T.USE_CODE,
			       T.USE_DESC,
			       DECODE(T.TOTLENGTH_M, 0, '', T.TOTLENGTH_M) TOTLENGTH_M,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = NVL(TRIM(T.OUTS_BILLET_FL), '121802')) OUTS_BILLET_FL,
			       T.PIPE_PROPERTY,
			       T.LEN_TOEND_MIN,
			       T.LEN_TOEND_MAX,
			       T.LENGTH_JG,
			       T.WEIGH_TYPE,
			       T.TRANSIT_TYP,
			       T.ACCEPT_NO,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
			       DECODE(T.JGORD_IS_OK, '0', '否', '1', '是', '2', '/') JGORD_IS_OK,
			       DECODE(T.JGL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') JGL_REQ_IS_OK,
			       DECODE(T.DJBL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') DJBL_REQ_IS_OK,
			       T.ASK_TYPE_STATUS,
			       T.STD_STYLE_DESC,
			       NVL(T.ROLL_WELL_MONTH, T.ROLL_MONTH) ROLL_WELL_MONTH,
			       T.WEIGHT_PER_M,
			       T.PAYDOWN_NUM,
			       T.PAYDOWN_WT_MIN,
			       T.PAYDOWN_WT_MAX,
			       T.CRAFT_FILE_NO_IN,
			       T.CRAFT_FILE_MAN_IN,
			       (SELECT SUM(B.REQWEIGHT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) REQ_QTYSUM,
			       (SELECT SUM(B.CONFIRM_WT)
			          FROM PLN_SALEORDER_R_NUM B
			         WHERE B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) CONFIRM_WT_SUM,
			       T.HEIGHT_ORD_MIN,
			       T.HEIGHT_ORD_MAX,
			       H.SALE_AREA_DESC,
			       M.UNIT_DESC_PROCESS UNIT_DESC,
			       F.DEPARTNAME,
			       T2.DESIGN_STS
			  FROM PLN_SALEORD T
			  LEFT JOIN SLM_ORDER_HEAD H
			    ON H.ORD_PK = T.ORD_PK
			   AND H.VALIDFLAG = '1'
			  LEFT JOIN (SELECT DECODE(K.DESIGN_STS,
			                           'W',
			                           '等待',
			                           'S',
			                           '通过',
			                           'F',
			                           '失败') DESIGN_STS,
			                    H.ORD_LN_PK,
			                    H.AW,
			                    H.ORDER_ADD_DESC
			               FROM SLM_ORDER_LINE H, CRAFT_ORD_DESIGN M
			               LEFT JOIN CRAFT_ORD_DESIGN_STS_TKLG K
			                 ON K.DESGIN_KEY = M.DESGIN_KEY
			                AND K.VALIDFLAG = '1'
			              WHERE M.CRAFT_SEQ =
			                    (SELECT MAX(CRAFT_SEQ)
			                       FROM CRAFT_ORD_DESIGN
			                      WHERE ORD_LN_PK = M.ORD_LN_PK)
			                AND H.VALIDFLAG <> '0'
			                AND M.ORD_LN_PK = H.ORD_LN_PK
			                AND M.VALIDFLAG <> '0') T2
			    ON T2.ORD_LN_PK = T.ORD_LN_PK
			  LEFT JOIN COM_MSC M
			  LEFT JOIN CORE_APP_DEPARTMENT E
			    ON E.DEPARTID = M.UNIT_CODE_PROCESS
			  LEFT JOIN CORE_APP_DEPARTMENT F
			    ON F.DEPARTID = E.PID ON T.MSC = M.MSC
			 WHERE NVL(T.ROLL_MONTH, '1') LIKE '%' || NVL(?, '1') || '%'
			   AND NVL(T.ACCEPT_NO, '1') LIKE '%' || NVL(NLS_UPPER(?), '1') || '%'
			   AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND DECODE(?, '1', T.JGORD_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T.DJBL_REQ_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T.MERGETYPE, 1) = DECODE(?, '1', '3', 1)
			   AND T.PORDERSTATUS < '6'
		]]>
	</query>
	
	
	<query id="CoreOrdFinishSet.queryFinishOrdSale" desc="查询">
		<![CDATA[
			SELECT M.DESGIN_KEY,
			       T.ORD_PK,
			       T.ORD_LN_PK,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       (T.ORDER_NO || '/' || T.ORDER_SEQ) ORDER_NO_SEQ,
			       (SELECT A.PRODUC_DESC
			          FROM COM_BASE_PRODUCT A
			         WHERE A.PRODUCCODE = T.PRODUCCODE
			           AND A.VALIDFLAG = '1') PRD_CLS,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.SPEC_CODE,
			       T.SPEC_NAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.LEN_UNIT,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.LENGTHDISC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.ORDERWEIGHT,
			       ROUND(DECODE(T.PORDERSTATUS_TIME,
              '',
              '100',
              NULL,
              '100',
              SYSDATE - T.PORDERSTATUS_TIME),2) PORDERSTATUS_TIME,
			       DECODE(T.ORDER_UNIT, '支', '支', '吨') ORDERWEIGHTUNIT,
			       DECODE(T.TOTLENGTH, 0, '', T.TOTLENGTH) TOTLENGTH,
			       T.TOTLENGTH_UNIT,
			       T.DELVRY_RANGE_TPE,
			       T.DELVRY_RANGE_MIN,
			       T.DELVRY_RANGE_MAX,
			       '(-' || TO_CHAR(ABS(T.DELVRY_RANGE_MIN)) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
			       TO_CHAR(T.DELVRY_RANGE_MAX) ||
			       DECODE(T.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE,
			       T.BUYER_ID,
			       (SELECT A.ABRVITION
			          FROM SLM_BASE_CUSTOMER A
			         WHERE A.CUSTOMER_NO = T.BUYER_ID) BUYER_NAME,
			       T.ORDER_SPECIAL_DESC,
			       T.ADD_ASK_NO,
			       T.ORDER_ADD_DESC,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.ORDERFROM) ORDERFROM,
			       T.FINAL_USER,
			       NVL((SELECT A.ABRVITION
			             FROM SLM_BASE_CUSTOMER A
			            WHERE A.CUSTOMER_NO = DECODE(T.FINAL_USER,
			                                         NULL,
			                                         T.BUYER_ID,
			                                         '/',
			                                         T.BUYER_ID,
			                                         T.FINAL_USER)),
			           DECODE(T.FINAL_USER_DESC,
			                  NULL,
			                  T.BUYER_NAME,
			                  '/',
			                  T.BUYER_NAME,
			                  T.FINAL_USER_DESC)) FINAL_USER_DESC,
			       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
			       T.ORDERCONTACT,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.MONITORDEMAND) MONITORDEMAND,
			       E.PRDCRPRO,
			       T.SPECSTANDARD,
			       T.PSC,
			       T.MSC,
			       T.CODE_JG,
			       T.CODE_DJ_BL,
			       T.PLANWEIGHT,
			       DECODE(E.ORDER_SOURCE, '补量需求', R.REQ_NAME, T.CREATE_NAME) CREATE_NAME,
			       TO_CHAR(DECODE(E.ORDER_SOURCE, '补量需求', R.REQ_TIME, T.CREATE_TIME),
			               'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       DECODE(E.ORDER_SOURCE, '补量需求', R.PLAN_DEAL_NAME, T.UPDATE_NAME) UPDATE_NAME,
			       TO_CHAR(DECODE(E.ORDER_SOURCE,
			                      '补量需求',
			                      R.PLAN_DEAL_TIME,
			                      T.UPDATE_TIME),
			               'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       T.ENDGXNAME,
			       T.MERGETYPE,
			       DECODE(T.JZ_FILE_IF_ALL, '1', '是', '0', '否') JZ_FILE_IF_ALL,
			       T.PRDCR_NO,
			       E.ROLL_MONTH,
			       T.MATERIAL_NO,
			       T.MATERIAL_DESC,
			       T.BL_GROUP_NUM,
			       T.SHRT_LEN_RATO,
			       T.SHORTEST,
			       T.LONG_LEN_RATO,
			       T.LONGEST,
			       T.SHRT_STOVE,
			       T.AVG_LEN_MIN,
			       T.DIFRNC_LEN_MAX,
			       T.SIGL_LEN,
			       T.ENDLEN_SPECSTD,
			       T.STATION_NO,
			       T.STATION_NM,
			       T.PRODUCE_SORT,
			       T.USE_CODE,
			       T.USE_DESC,
			       ROUND(DECODE(T.PORDERSTATUS_TIME,
              '',
              '100',
              NULL,
              '100',
              SYSDATE - T.PORDERSTATUS_TIME),2) PORDERSTATUS_TIME,
			       DECODE(T.TOTLENGTH_M, 0, '', T.TOTLENGTH_M) TOTLENGTH_M,
			       T.ORDERNUM,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_BILLET_FL) OUTS_BILLET_FL,
			       T.PIPE_PROPERTY,
			       T.LEN_TOEND_MIN,
			       T.LEN_TOEND_MAX,
			       T.LENGTH_JG,
			       T.WEIGH_TYPE,
			       T.TRANSIT_TYP,
			       DECODE(E.ORDER_SOURCE,
			              '补量需求',
			              R.ACCEPT_NO,
			              T.ACCEPT_NO) ACCEPT_NO,
			       (SELECT A.BASENAME
			          FROM COM_BASE_INFO A
			         WHERE A.BASECODE = T.OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
			       DECODE(T.JGORD_IS_OK, '0', '否', '1', '是', '2', '/') JGORD_IS_OK,
			       DECODE(T.JGL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') JGL_REQ_IS_OK,
			       DECODE(T.DJBL_REQ_IS_OK, '0', '否', '1', '是', '2', '/') DJBL_REQ_IS_OK,
			       DECODE(T.IF_SALE_FREEZE, '1', '是', '0', '否') IF_SALE_FREEZE,
			       T.ASK_TYPE_STATUS,
			       T.STD_STYLE_DESC,
			       NVL(T.ROLL_WELL_MONTH, T.ROLL_MONTH) ROLL_WELL_MONTH,
			       T.HEIGHT_ORD_MIN,
			       T.HEIGHT_ORD_MAX,
			       DECODE(E.ORDER_SOURCE, '补量需求', NULL, T.PAYDOWNWEIGHT) PAYDOWNWEIGHT,
			       DECODE(E.ORDER_SOURCE, '补量需求', NULL, T.PAYDOWN_NUM) PAYDOWN_NUM,
			       (SELECT A.BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = E.PRIORITY) PRIORITY,
			       E.PRIORITY_MEMO,
			       E.ORDER_SOURCE,
			       E.ORD_LN_DLY_PK,
			       E.PLN_DIVIDE_ID,
			       E.R_NUM_ID,
			       E.CRAFT_SEQ,
			       E.CRAFT_FILE_NO,
			       E.CRAFT_NO_V,
			       (SELECT T1.CRAFT_NAME
			          FROM CRAFT_ORD_DESIGN_APPOINT T1
			         WHERE T1.ORD_LN_PK = T.ORD_LN_PK) CRAFT_FILE_MAN,
			       (SELECT MAX(T1.CRAFT_NO)
			          FROM CRAFT_ORD_DESIGN T1
			         WHERE T1.ORD_LN_PK = T.ORD_LN_PK
			           AND T1.VALIDFLAG = '1') CRAFT_NO_NEW,
			       (SELECT MAX(T1.CRAFT_NO_V)
			          FROM CRAFT_ORD_DESIGN T1
			         WHERE T1.ORD_LN_PK = T.ORD_LN_PK
			           AND T1.VALIDFLAG = '1') CRAFT_NO_V_NEW,
			       DECODE(E.CRAFT_SEQ,
			              NVL((SELECT MAX(T1.CRAFT_SEQ)
			                    FROM CRAFT_ORD_DESIGN T1
			                   WHERE T1.ORD_LN_PK = T.ORD_LN_PK
			                     AND T1.VALIDFLAG = '1'),
			                  E.CRAFT_SEQ),
			              '无更新',
			              DECODE(E.PLANSTATUS, '4', '无更新', '5', '无更新', '待替换')) CRAFT_RENEW_ST,
			       E.INDEX_SEQ,
			       E.PROCESS_SEQ,
			       (SELECT P.WHOLE_BACKLOG_DESC
			          FROM CRAFT_ORD_DESIGN_MSC_PL P
			         WHERE P.DESGIN_KEY = M.DESGIN_KEY
			           AND P.MSC_PLINE = E.INDEX_SEQ) WHOLE_BACKLOG_DESC,
			       E.BOM,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = E.GROUP_JGX) GROUP_JGX,
			       (SELECT B.BASENAME
			          FROM COM_BASE_INFO B
			         WHERE B.BASECODE = E.GROUP_RCL) GROUP_RCL,
			       DECODE(E.PLANSTATUS,
			              '1',
			              '已接收',
			              '2',
			              '已下发',
			              '3',
			              '生产中',
			              '4',
			              '生产完成',
			              '5',
			              '缴库完成') PLANSTATUS,
			       E.GRADECODE_ALL,
			       (SELECT A.GRADENAME
			          FROM COM_BASE_GRADE A
			         WHERE A.GRADECODE = E.GRADECODE) GRADECODE,
			       E.GROUP_ROLL_ALL,
			       (SELECT A.PLINE_NAME
			          FROM COM_BASE_PLINE A
			         WHERE A.PLINE_CODE = E.GROUP_ROLL) GROUP_ROLL,
			       E.BJ_TYPE,
			       E.E_IN_MATERIAL_NO,
			       E.E_IN_MATERIAL_DESC,
			       E.DIMATER_YLG,
			       E.HEIGHT_YLG,
			       E.STUFF_PROPERTY,
			       E.WEIGHT_PER_M,
			       E.PLAN_TOT_LEN_D,
			       E.ORDER_QTY_D,
			       E.ORDER_UNIT,
			       E.PLAN_WT_D,
			       E.PLAN_NUM_D,
			       E.FINISH_WT,
			       E.PLAN_WT_BEGIN,
			       E.PLAN_NUM_BEGIN,
			       E.HEIGHT_NK_MIN,
			       E.HEIGHT_NK_MAX,
			       E.AIM_LEN_END,
			       E.AIM_LEN_ROLL,
			       E.TOT_LEN_ONE_P,
			       E.CUT_NUM_P,
			       E.AIM_WALLTHICK,
			       E.ROLL_LENGTH,
			       E.PLAN_P_MAIN,
			       E.ISSUED_MAN,
			       TO_CHAR(E.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
			       DECODE(E.F_IS_OK, '0', '否', '1', '是', '2', '/') F_IS_OK,
			       DECODE(E.IF_ALLOW_ISSUE, '0', '否', '1', '是') IF_ALLOW_ISSUE,
			       DECODE(E.G_IS_OK, '0', '否', '1', '是', '2', '/') G_IS_OK,
			       DECODE(E.GRADECODE_IS_OK, '0', '否', '1', '是') GRADECODE_IS_OK,
			       DECODE(E.D_IS_OK, '0', '否', '1', '是', '2', '/') D_IS_OK,
			       DECODE(E.PLAN_IS_OK, '0', '否', '1', '是') PLAN_IS_OK,
			       DECODE(E.E_IS_OK, '0', '否', '1', '是', '2', '/') E_IS_OK,
			       M.UNIT_DESC_PROCESS UNIT_DESC,
			       F.DEPARTNAME,
			       T2.AW,
			       T2.DESIGN_STS,
			       (select SALE_AREA_DESC from SLM_ORDER_HEAD where ORD_PK=T.ORD_PK) SALE_AREA_DESC,
			       E.DELETE_NAME,
			       E.DELETE_TIME,
			       (SELECT Pay_Len FROM PROCESS_ORDER_M WHERE ORD_LN_DLY_PK = E.ORD_LN_DLY_PK) paydown_Len,
			       ( SELECT sum(ACT_WEIGHT) FROM QCM_ZG_JUGDE_APPLY WHERE ORD_LN_DLY_PK = E.ORD_LN_DLY_PK and TARGET = 'A' ) pdzl ,
				   ( SELECT sum(ACT_LEN) FROM QCM_ZG_JUGDE_APPLY WHERE ORD_LN_DLY_PK = E.ORD_LN_DLY_PK and TARGET = 'A') pdcd
			  FROM PLN_SALEORD_PROC E
			  LEFT JOIN PLN_SALEORD T ON E.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			  LEFT JOIN SLM_ORDER_HEAD OH ON T.ORD_PK = OH.ORD_PK
			  LEFT JOIN (SELECT DECODE(K.DESIGN_STS,
			                           'W',
			                           '等待',
			                           'S',
			                           '通过',
			                           'F',
			                           '失败') DESIGN_STS,
			                    H.ORD_LN_PK,
			                    H.AW
			               FROM SLM_ORDER_LINE H, CRAFT_ORD_DESIGN M
			               LEFT JOIN CRAFT_ORD_DESIGN_STS_TKLG K
			                 ON K.DESGIN_KEY = M.DESGIN_KEY
			                AND K.VALIDFLAG = '1'
			              WHERE M.CRAFT_SEQ =
			                    (SELECT MAX(CRAFT_SEQ)
			                       FROM CRAFT_ORD_DESIGN
			                      WHERE ORD_LN_PK = M.ORD_LN_PK)
			                AND H.VALIDFLAG <> '0'
			                AND M.ORD_LN_PK = H.ORD_LN_PK
			                AND M.VALIDFLAG <> '0') T2
			    ON T2.ORD_LN_PK = T.ORD_LN_PK
			  LEFT JOIN COM_MSC M
			  LEFT JOIN CORE_APP_DEPARTMENT N
			    ON N.DEPARTID = M.UNIT_CODE_PROCESS
			  LEFT JOIN CORE_APP_DEPARTMENT F
			    ON F.DEPARTID = N.PID ON T.MSC = M.MSC
			  LEFT JOIN CRAFT_ORD_DESIGN M
			    ON M.ORD_LN_PK = T.ORD_LN_PK
			   AND M.CRAFT_SEQ = E.CRAFT_SEQ
			  LEFT JOIN PLN_SALEORDER_R_NUM R
			    ON R.R_NUM_ID = E.R_NUM_ID
			 WHERE T.ORD_LN_DLY_PK = E.ORD_LN_DLY_PK
			   AND NVL(E.ROLL_MONTH, '1') LIKE
			       '%' || NVL(?, NVL(E.ROLL_MONTH, '1')) || '%'
			   AND (DECODE(E.ORDER_SOURCE,
			               '补量需求',
			               R.ACCEPT_NO,
			               NVL(T.ACCEPT_NO, '1')) LIKE
			       '%' || NVL(NLS_UPPER(?),
			                   DECODE(E.ORDER_SOURCE,
			                          '补量需求',
			                          R.ACCEPT_NO,
			                          NVL(T.ACCEPT_NO, '1'))) || '%')
			   AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER(?) || '%'
			   AND DECODE(?, '1', T.JGORD_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T.DJBL_REQ_IS_OK, 1) != DECODE(?, '1', '2', 2)
			   AND DECODE(?, '1', T.MERGETYPE, 1) = DECODE(?, '1', '3', 1)
		]]>
	</query>
	
	
	<query id="CoreOrdFinishSet.setModifySale" desc="修改排产合同状态">
		<![CDATA[
			UPDATE PLN_SALEORD T
   SET T.PORDERSTATUS = ?, T.PORDERSTATUS_TIME = SYSDATE
 WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CoreOrdFinishSet.setModifySaleProc" desc="修改交货行分解表状态">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T SET T.PLANSTATUS = ?,T.DELETE_NAME = ?,T.DELETE_TIME = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>

	<query id="CoreOrdFinishSet.setModifySaleProcJk" desc="修改交货行分解表状态">
		<![CDATA[
			UPDATE PLN_SALEORD_PROC T SET T.PLANSTATUS = ? WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	<query id="CoreOrdFinishSet.setLineDeliveryStatus" desc="修改销售交货行表状态">
		<![CDATA[
			UPDATE SLM_ORDER_LINE_DELIVERY T SET T.DELIVERY_STATUS = ? WHERE T.ORD_LN_DLY_PK = ?
		]]>
	</query>
	
	<query id="CoreOrdFinishSet.getNumDeliveryByLine" desc="查询和同行的交货行数目">
		<![CDATA[
			SELECT COUNT(T.DELIVERY_STATUS) DELIVERY_NUM
			  FROM SLM_ORDER_LINE_DELIVERY T
			 WHERE T.ORD_LN_PK = ?
			   AND SUBSTR(T.DELIVERY_STATUS, 0, 6) != '120210'
			   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CoreOrdFinishSet.setOrdLineStatus" desc="修改销售合同行表状态">
		<![CDATA[
			UPDATE SLM_ORDER_LINE T SET T.ORDER_LN_STATUS = ? WHERE T.ORD_LN_PK = ?
		]]>
	</query>
	<query id="CoreOrdFinishSet.queryPlnExeStatus" desc="查询交货行对应排产计划">
		<![CDATA[
			SELECT T1.*
  FROM (SELECT '1' XH,
               '轧管' PROCESS_DESC,
               T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_NO,
               T.DELIVERY_NO,
               T.PRO_PLAN_ID,
               T.GX_PLAN_NO,
               DECODE(T.EXE_STATUS,
                      '0',
                      '计划',
                      '1',
                      '生产中',
                      '2',
                      '已生产',
                      '3',
                      '关闭A') EXE_STATUS,
               T.ORD_LN_DLY_PK,
               T.PLN_DIVIDE_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,
       (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
                 FROM PLN_ORDER_ZG_S T
         WHERE T.ORD_LN_DLY_PK = ?
           AND T.PLN_DIVIDE_ID = ?
        UNION ALL
        SELECT '2' XH,
               '镦拔扩' PROCESS_DESC,
               T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_NO,
               T.DELIVERY_NO,
               T.PRO_PLAN_ID,
               T.GX_PLAN_NO,
               DECODE(T.EXE_STATUS,
                      '0',
                      '计划',
                      '1',
                      '生产中',
                      '2',
                      '已生产',
                      '3',
                      '关闭A') EXE_STATUS,
               T.ORD_LN_DLY_PK,
               T.PLN_DIVIDE_ID,
               '0' FURNA_NUM,
               '0' FURNA_WEIGHT,
               '0' LJ_NUM,
               '0' LJ_WEIGHT,
               '0' CK_WEIGHT,
               '0' CK_NUM
          FROM PLN_ORDER_DBK_S T
         WHERE T.ORD_LN_DLY_PK = ?
           AND T.PLN_DIVIDE_ID = ?
        UNION ALL
        SELECT '3' XH,
               '热处理' PROCESS_DESC,
               T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_NO,
               T.DELIVERY_NO,
               T.PRO_PLAN_ID,
               T.GX_PLAN_NO,
               DECODE(T.EXE_STATUS,
                      '0',
                      '计划',
                      '1',
                      '生产中',
                      '2',
                      '已生产',
                      '3',
                      '关闭A') EXE_STATUS,
               T.ORD_LN_DLY_PK,
               T.PLN_DIVIDE_ID,
                   '0' FURNA_NUM,
               '0' FURNA_WEIGHT,
               '0' LJ_NUM,
               '0' LJ_WEIGHT,
               '0' CK_WEIGHT,
               '0' CK_NUM
          FROM PLN_ORDER_RCL_S T
         WHERE T.ORD_LN_DLY_PK = ?
           AND T.PLN_DIVIDE_ID = ?
        UNION ALL
        SELECT '4' XH,
               '加工' PROCESS_DESC,
               T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_NO,
               T.DELIVERY_NO,
               T.PRO_PLAN_ID,
               T.GX_PLAN_NO,
               DECODE(T.EXE_STATUS,
                      '0',
                      '计划',
                      '1',
                      '生产中',
                      '2',
                      '已生产',
                      '3',
                      '关闭A') EXE_STATUS,
               T.ORD_LN_DLY_PK,
               T.PLN_DIVIDE_ID,
                '0' FURNA_NUM,
               '0' FURNA_WEIGHT,
               '0' LJ_NUM,
               '0' LJ_WEIGHT,
               '0' CK_WEIGHT,
               '0' CK_NUM
          FROM PLN_ORDER_JGX_S T
         WHERE T.ORD_LN_DLY_PK = ?
           AND T.PLN_DIVIDE_ID = ?) T1
 ORDER BY T1.XH, T1.PRO_PLAN_ID, T1.GX_PLAN_NO

		]]>
	</query>
	<query id="CoreOrdFinishSet.selectPlnOrderZgStatus" desc="查询轧管排产状态">
		<![CDATA[
		SELECT T.EXE_STATUS,T.PRO_PLAN_ID,T.GX_PLAN_NO FROM PLN_ORDER_ZG_S T WHERE T.ORD_LN_DLY_PK = ? AND T.PLN_DIVIDE_ID=?
			]]>
	</query>
	<query id="CoreOrdFinishSet.selectPlnOrderDbkStatus" desc="查询镦拔扩排产状态">
		<![CDATA[
		SELECT T.EXE_STATUS  FROM PLN_ORDER_DBK_S T WHERE T.ORD_LN_DLY_PK = ? AND T.PLN_DIVIDE_ID=?
			]]>
	</query>
	<query id="CoreOrdFinishSet.selectPlnOrderRclStatus" desc="查询热处理排产状态">
		<![CDATA[
		SELECT T.EXE_STATUS  FROM PLN_ORDER_RCL_S T WHERE T.ORD_LN_DLY_PK = ? AND T.PLN_DIVIDE_ID=?
			]]>
	</query>
	<query id="CoreOrdFinishSet.selectPlnOrderJgxStatus" desc="查询加工线排产状态">
		<![CDATA[
		SELECT T.EXE_STATUS  FROM PLN_ORDER_JGX_S T WHERE T.ORD_LN_DLY_PK = ? AND T.PLN_DIVIDE_ID=?
			]]>
	</query>
	<query id="CoreOrdFinishSet.selectPlnOrderJgStatus" desc="查询接箍排产状态">
		<![CDATA[
		SELECT T.EXE_STATUS  FROM PLN_GX_JG_PROP_S T WHERE T.ORD_LN_DLY_PK = ? AND T.PLN_DIVIDE_ID=?
			]]>
	</query>
	<query id="CoreOrdFinishSet.selectPlnSaleordProcPl" desc="查询排产分解表交货行是否全部关闭">
		<![CDATA[
		SELECT MIN(T.PLANSTATUS) PLANSTATUS FROM PLN_SALEORD_PROC T WHERE T.ORD_LN_DLY_PK=?
			]]>
	</query>
</queryMap>