<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍订单组料">
	<query id="CoreJgMBlOrd.queryJgGxMNo" desc="查询工序订单订单号">
		<![CDATA[
			SELECT T.PRO_PLAN_ID FROM PLN_GX_JG_M T WHERE T.PLANSTATUS < '2'
		]]>
	</query>

	<query id="CoreJgMBlOrd.queryJglRelNo" desc="查询接箍备料需求">
		<![CDATA[
			SELECT T.REQ_BL_ID FROM PLN_PORDER_BL_REQ T WHERE T.BLTYPE = '接箍料' AND T.PLANSTATUS = '0'
		]]>
	</query>

	<query id="CoreJgMBlOrd.getJgBlRelation" desc="查询接箍备料 关系表">
		<![CDATA[
			SELECT T.CODE_JG,
			       T.CODE_JG_BL,
			       T.NUM_JG,
			       T.WEIGHT_JG,
			       T.SINGLE_ADDLEN,
			       A.LENGTH_JG,
			       B.MIN_L,
			       B.MAX_L,
			       B.MIN_D,
			       B.MIN_H
			  FROM PLN_JG_AND_BL T
			  LEFT JOIN COM_MSC_JG A
			    ON A.CODE_JG = T.CODE_JG
			  LEFT JOIN COM_MSC_BL B
			    ON B.PSC_BL = T.CODE_JG_BL
			 WHERE T.PRO_PLAN_ID = ?
			   AND T.REQ_BL_ID = ?
		]]>
	</query>

	<query id="CoreJgMBlOrd.queryGxJgM" desc="查询接箍订单">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.PLINE_CODE,
			       T.PLINE_NAME,
			       T.PLAN_SEQ_NO,
			       T.MONITORDEMAND,
			       DECODE(T.IF_MONITOR_JG, '1', '是', '否') IF_MONITOR_JG,
			       T.PRDCR_NO,
			       T.CODE_JG,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.AIMLENGTH,
			       T.SINGLEWEIGHT,
			       T.SPEC_JG,
			       T.SPEC_JG_DESC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = T.STYLE_JG) STYLE_JG,
			       H.BASENAME STYLE_JG_DESC,
			       T.DIAMETER,
			       T.CHECK_J_VAL,
			       T.ALL_CODE_BL,
			       T.CODE_JG_BL,
			       T.BL_WL_ID,
			       T.BL_WL_DESC,
			       T.MIN_D,
			       T.MIN_H,
			       T.BL_MIN_D_OUT,
			       T.BL_MAX_D_IN,
			       T.AIMLENGTH_BL,
			       T.DIAMETER_PL,
			       T.HEIGHT_PL,
			       T.LENGTH_MIN,
			       T.LENGTH_MAX,
			       T.TAPER,
			       T.ALPHA_NAME,
			       A.STD_NAME,
			       A.STD_STYLE_DESC,
			       (SELECT REPLACE(WM_CONCAT(A.STEELCODE_JG_DESC), ',', ';')
			          FROM COM_MSC_JG_R_STEEL N
			         WHERE N.STEELCODE = A.STEELCODE_JG) REP_STEELNAME,
			       A.MIN_D_JG,
			       A.MAX_D_JG,
			       A.PRODUCCODE_JG,
			       C.BASENAME PRODUCCODE_JG_DESC,
			       A.STEELCODE_JG,
			       D.STEELNAME STEELCODE_JG_DESC,
			       A.PRODUCCODE,
			       G.PRODUCNAME,
			       A.DIAMETER_JG,
			       A.LENGTH_JG,
			       A.HEIGHT_JG,
			       A.WEIGHT_JG,
			       A.MIN_H_CP,
			       A.MAX_H_CP,
			       A.MIN_D_CP,
			       A.MAX_D_CP,
			       A.ALPHA,
			       T.PLAN_NUM,
			       T.BL_NUM,
			       T.BL_WEIGHT,
			       T.ZYPLAN_NUM,
			       T.PRODUCED_NUM,
			       T.CUST_ALPHA_NO,
			       T.ORDER_SPECIAL_DESC,
			       T.ALPHA_CODE,
			       DECODE(T.PLANSTATUS,
			              '0',
			              '计划',
			              '1',
			              '下发',
			              '2',
			              '生产中',
			              '3',
			              '生产完成',
			              '4',
			              '取消') PLANSTATUS,
			       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,
			       NVL(T.MATCHNUM, 0) MATCHNUM,
			       DECODE(T.IFBUYPLAN, '1', '是', '否') IFBUYPLAN,
			       T.BUYPLANID,
			       NVL(T.BUYPLANNUM, 0) BUYPLANNUM,
			       NVL(T.JGWT_BLREQ, 0) JGWT_BLREQ
			  FROM PLN_GX_JG_M T
			  LEFT JOIN COM_MSC_JG A
			    ON T.CODE_JG = A.CODE_JG
			  LEFT JOIN COM_BASE_INFO C
			    ON C.BASECODE = A.PRODUCCODE_JG
			  LEFT JOIN COM_BASE_STEEL D
			    ON D.STEELCODE = A.STEELCODE_JG
			  LEFT JOIN COM_BASE_PRODUCT G
			    ON G.PRODUCCODE = A.PRODUCCODE
			  LEFT JOIN COM_BASE_INFO H
			    ON H.BASECODE = A.STYLE_JG
			 WHERE T.IFBUYPLAN != '1'
			   AND SIGN(NVL(T.PLAN_NUM, 0) - NVL(T.MATCHNUM, 0)) = 1
			   AND T.PRO_PLAN_ID LIKE '%' || NLS_UPPER(?) || '%'
			   AND T.PLANSTATUS < '3'
		]]>
	</query>

	<query id="CoreJgMBlOrd.queryJgDealedit" desc="查询接箍料编辑信息">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
             DECODE(T.IFBUYPLAN,
                    '1',
                    '完成配料',
                    DECODE(SIGN(NVL(T.PLAN_NUM, 0) - NVL(T.MATCHNUM, 0) -
                                NVL(T.JGWT_BLREQ, 0)),
                           1,
                           '未完成配料',
                           '完成配料')) IS_FINISH,
             T.CODE_JG,
             C.CODE_JG_BL,
             T.SINGLEWEIGHT,
             T.OUTDIAMETER,
             T.AIMLENGTH,
             T.WALLTHICK,
             T.JGWT_BLREQ,
             D.PRODUCCODE,
             D.PRODUCNAME,
             D.STD_CODE,
             D.STD_NAME,
             D.STEELCODE,
             D.STEELNAME,
             D.STD_STYLE,
             D.STD_STYLE_DESC,
             D.MODEL_CODE,
             D.MODEL_DESC,
             D.MIN_D,
             D.MIN_H,
             D.USE_CODE,
             D.USE_DESC,
             D.MIN_L,
             D.MAX_L,
             15 AS SINGLE_ADDLEN,
              CASE
         WHEN NVL(T.PLAN_NUM, 0) - NVL(T.MATCHNUM, 0) - NVL(T.JGWT_BLREQ, 0) < 0 THEN
          0
         ELSE
          NVL(T.PLAN_NUM, 0) - NVL(T.MATCHNUM, 0) - NVL(T.JGWT_BLREQ, 0)
       END NUM_JG,
             T.PRDCR_NO, 
             T.PLINE_CODE,
             T.PLINE_NAME,
       		 T.BL_WL_ID,
      		 T.BL_WL_DESC,
       (SELECT H.OUT_MATERIAL_DESC
          FROM SLM_BASE_MATERIAL_H_PL H
         WHERE H.IN_MATERIAL_NO = T.BL_WL_ID
           AND H.OUT_MATERIAL_NO = T.CODE_JG
           AND H.PLINE_CODE = T.PLINE_CODE) OUT_MATERIAL_DESC
        FROM PLN_GX_JG_M T, PLN_GX_JG_C C
        LEFT JOIN COM_MSC_BL D
          ON D.PSC_BL = C.CODE_JG_BL
         AND D.VALIDFLAG = '1'
       WHERE T.IFBUYPLAN != '1'
         AND SIGN(NVL(T.PLAN_NUM, 0) - NVL(T.MATCHNUM, 0)) = 1
         AND T.PRO_PLAN_ID = C.PRO_PLAN_ID
		 AND T.PRO_PLAN_ID LIKE '%' || NLS_UPPER(?) || '%'
		]]>
	</query>

	<query id="CoreJgMBlOrd.queryJgBlNeed" desc="查询接箍备料需求">
		<![CDATA[
			SELECT T.REQ_BL_ID,
			       DECODE(T.PLANSTATUS, '0', '待处理', '1', '已确认', '2', '已下发') PLANSTATUS,
			       T.BLTYPE,
			       T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.JG_ORDERNO,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.OUTDIAMETER,
			       T.WALLTHICK,
			       T.AIMWALLTHICK,
			       T.LENGTHMAX,
			       T.LENGTHMIN,
			       T.AIMLENGTH,
			       T.CODE_DJ_BL,
			       T.CODE_JG_BL,
			       T.SINGLEWEIGHT,
			       T.JGBL_REQ_WEIGHT,
			       T.JGBL_REQ_NUM,
			       T.MATCHWEIGHT,
			       T.MATCHNUM,
			       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.STD_CODE,
			       T.STD_NAME,
			       T.MSC
			  FROM PLN_PORDER_BL_REQ T
			 WHERE T.BLTYPE = '接箍料' and PLANSTATUS<'2'
			   AND T.REQ_BL_ID LIKE '%' || NLS_UPPER(?) || '%'
		]]>
	</query>

	<query id="CoreJgMBlOrd.queryRelation" desc="查询接箍及备料关系">
		<![CDATA[
			SELECT T.PRO_PLAN_ID,
			       T.REQ_BL_ID,
			       T.CODE_JG,
			       T.OUTDIAMETER,
			       T.AIMLENGTH,
			       T.WALLTHICK,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.SINGLEWEIGHT,
			       T.CODE_JG_BL,
			       T.AIMLENGTH_BL,
			       T.SINGLEWEIGHT2,
			       T.JGBL_REQ_WEIGHT,
			       T.JGBL_REQ_NUM,
			       T.GETRATE,
			       T.WEIGHT_JG,
			       T.NUM_JG,
			       T.JGPLAN_NUM,
			       DECODE(T.PLANSTATUS,
			              '0',
			              '待处理',
			              '1',
			              '已确认',
			              '2',
			              '已下发') PLANSTATUS,
			       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.SINGLE_ADDLEN
			  FROM PLN_JG_AND_BL T
			 WHERE T.REQ_BL_ID = ?
		]]>
	</query>

	<query id="CoreJgMBlOrd.addJgAndBlRelation" desc="保存接箍与备料关系">
		<![CDATA[
			INSERT INTO PLN_JG_AND_BL
				  (PRO_PLAN_ID,
				   REQ_BL_ID,
				   CODE_JG,
				   OUTDIAMETER,
				   WALLTHICK,
				   AIMLENGTH,
				   STEELCODE,
				   STEELNAME,
				   SINGLEWEIGHT,
				   CODE_JG_BL,
				   AIMLENGTH_BL,
				   SINGLEWEIGHT2,
				   JGBL_REQ_WEIGHT,
				   JGBL_REQ_NUM,
				   GETRATE,
				   WEIGHT_JG,
				   NUM_JG,
				   PLANSTATUS,
				   CREATE_NAME,
				   CREATE_TIME,
				   SINGLE_ADDLEN)
				  SELECT '#PRO_PLAN_ID#',
				         '#REQ_BL_ID#',
				         A.CODE_JG,
				         A.MIN_D,
				         A.MIN_H,
				         A.LENGTH_JG,
				         B.STEELCODE,
				         B.STEELNAME,
				         A.WEIGHT_JG,
				         B.PSC_BL,
				         '#AIMLENGTH_BL#',
				         '#SINGLEWEIGHT2#',
				         '#JGBL_REQ_WEIGHT#',
				         '#JGBL_REQ_NUM#',
				         '#GETRATE#',
				         '#WEIGHT_JG#',
				         '#NUM_JG#',
				         '0',
				         '#CREATE_NAME#',
				         SYSDATE,
				         '#SINGLE_ADDLEN#'
				    FROM COM_MSC_JG A, COM_MSC_BL B
				   WHERE A.CODE_JG = '#CODE_JG#'
				     AND B.PSC_BL = '#CODE_JG_BL#'
				     AND A.VALIDFLAG = '1'
				     AND B.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CoreJgMBlOrd.updateRelation" desc="更新接箍与备料对应关系">
		<![CDATA[
			UPDATE PLN_JG_AND_BL T
			   SET T.JGBL_REQ_WEIGHT = T.JGBL_REQ_WEIGHT + '#JGBL_REQ_WEIGHT#',
			       T.JGBL_REQ_NUM    = T.JGBL_REQ_NUM + '#JGBL_REQ_NUM#',
			       T.WEIGHT_JG       = T.WEIGHT_JG + '#WEIGHT_JG#',
			       T.NUM_JG          = T.NUM_JG + '#NUM_JG#',
			       T.UPDATE_NAME     = '#UPDATE_NAME#',
			       T.UPDATE_TIME     = SYSDATE
			 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
			   AND T.REQ_BL_ID = '#REQ_BL_ID#'
		]]>
	</query>

	<query id="CoreJgMBlOrd.addPlnOrdJglReq" desc="保存接箍料需求信息">
		<![CDATA[
			INSERT INTO PLN_PORDER_BL_REQ
				  (REQ_BL_ID,
				   BLTYPE,
				   STEELCODE,
				   STEELNAME,
				   OUTDIAMETER,
				   WALLTHICK,
				   AIMWALLTHICK,
				   LENGTHMAX,
				   LENGTHMIN,
				   AIMLENGTH,
				   CODE_JG_BL,
				   STD_CODE,
				   STD_NAME,
				   MSC,
				   PSC,
				   SINGLEWEIGHT,
				   JGBL_REQ_WEIGHT,
				   JGBL_REQ_NUM,
				   MATCHWEIGHT,
				   MATCHNUM,
				   PLANSTATUS,
				   CREATE_NAME,
				   CREATE_TIME)
				  SELECT '#REQ_BL_ID#',
				         '接箍料',
				         T1.STEELCODE,
				         T1.STEELNAME,
				         T1.MIN_D,
				         T1.MIN_H,
				         T1.MIN_H,
				         T1.MAX_L,
				         T1.MIN_L,
				         '#AIMLENGTH#',
				         '#CODE_JG_BL#',
				         T1.STD_CODE,
				         T1.STD_NAME,
				         '#MSC#',
				         '#PSC#',
				         '#SINGLEWEIGHT#',
				         '#JGBL_REQ_WEIGHT#',
				         '#JGBL_REQ_NUM#',
				         '0',
				         '0',
				         '0',
				         '#CREATE_NAME#',
				         SYSDATE
				    FROM COM_MSC_BL T1
				   WHERE T1.PSC_BL = '#CODE_JG_BL#'
		]]>
	</query>

	<query id="CoreJgMBlOrd.updateJglneed" desc="更新备料需求">
		<![CDATA[
			UPDATE PLN_PORDER_BL_REQ T
			   SET T.JGBL_REQ_WEIGHT = T.JGBL_REQ_WEIGHT + '#JGBL_REQ_WEIGHT#',
			       T.JGBL_REQ_NUM    = T.JGBL_REQ_NUM + '#JGBL_REQ_NUM#',
			       T.UPDATE_NAME     = '#UPDATE_NAME#',
			       T.UPDATE_TIME     = SYSDATE
			 WHERE T.REQ_BL_ID = '#REQ_BL_ID#'
		]]>
	</query>

	<query id="CoreJgMBlOrd.updateBlreq" desc="更新已做备料需求的接箍量">
		<![CDATA[
			UPDATE PLN_GX_JG_M T
			   SET T.JGWT_BLREQ = ? + NVL(T.JGWT_BLREQ, 0)
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreJgMBlOrd.updateJgMBlPl" desc="更新接箍订单备料产线">
		<![CDATA[
			UPDATE PLN_GX_JG_M T
			   SET T.CODE_JG_BL = ?,
			       T.BL_WL_ID   = ?,
			       T.BL_WL_DESC = ?,
			       T.PLINE_CODE = ?,
			       T.PLINE_NAME = ?
			 WHERE T.PRO_PLAN_ID = ?
		]]>
	</query>


	<query id="CoreJgMBlOrd.queryJgReqblid" desc="查询接箍备料需求编号">
		<![CDATA[
			SELECT ('ZZBY-J' || TO_CHAR(SYSDATE, 'YYMMDD') || '/' ||
			       LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.REQ_BL_ID, 14)) + 1), '1'), 3, '0')) REQ_BL_ID
			  FROM PLN_PORDER_BL_REQ T
			 WHERE SUBSTR(T.REQ_BL_ID, 0, 12) = 'ZZBY-J' || TO_CHAR(SYSDATE, 'YYMMDD')
		]]>
	</query>

	<query id="CoreJgMBlOrd.queryBlList" desc="查询备料清单表">
		<![CDATA[
			SELECT T.PSC_BL,
			       T.PRODUCCODE,
			       T.PRODUCNAME,
			       T.STD_CODE,
			       T.STD_NAME,
			       T.STEELCODE,
			       T.STEELNAME,
			       T.STD_STYLE,
			       T.STD_STYLE_DESC,
			       T.MODEL_CODE,
			       T.MODEL_DESC,
			       T.MIN_D,
			       T.MIN_H,
			       T.USE_CODE,
			       T.USE_DESC,
			       T.MIN_L,
			       T.MAX_L,
			       P.PSC,
			       M.MSC
			  FROM COM_MSC_BL T
			  LEFT JOIN COM_PSC P
			    ON P.PRODUCCODE = T.PRODUCCODE
			   AND P.STD_CODE = T.STD_CODE
			   AND P.STEELCODE = T.STEELCODE
			   AND P.STD_STYLE = T.STD_STYLE
			   AND P.VALIDFLAG = '1'
			  LEFT JOIN COM_PSC_R_MSC M
			    ON M.PSC = P.PSC
			   AND M.VALIDFLAG = '1'
			 WHERE T.PSC_BL = ?
			   AND T.VALIDFLAG = '1'
		]]>
	</query>

	<query id="CoreJgMBlOrd.deleteRelation" desc="删除接箍与备料需求关系">
		<![CDATA[
			DELETE FROM PLN_JG_AND_BL T WHERE T.PRO_PLAN_ID = ? AND T.REQ_BL_ID = ?
		]]>
	</query>

	<query id="CoreJgMBlOrd.deleteBlneed" desc="删除备料需求信息">
		<![CDATA[
			DELETE FROM PLN_PORDER_BL_REQ T WHERE T.REQ_BL_ID=?
		]]>
	</query>

	<query id="CoreJgMBlOrd.selectBlReqStatus" desc="查询备料需求">
		<![CDATA[
			SELECT T.ORDER_NO,
			       T.ORDER_SEQ,
			       T.DELIVERY_NO,
			       T.ORD_LN_DLY_PK,
			       T.PLANSTATUS
			  FROM PLN_PORDER_BL_REQ T
			 WHERE T.REQ_BL_ID = ?
		]]>
	</query>



	<query id="CoreJgMBlOrd.selectJgMaterialPl" desc="查询接箍投入产出产线能力">
		<![CDATA[
			SELECT T.PLINE_CODE,
			       T.PLINE_NAME,
			       T.IN_MATERIAL_NO,
			       J.IN_MATERIAL_DESC,
			       T.OUT_MATERIAL_NO,
			       J.OUT_MATERIAL_DESC
			  FROM SLM_BASE_MATERIAL_H_PL T
			  LEFT JOIN SLM_BASE_MATERIAL_H J
			    ON J.IN_MATERIAL_NO = T.IN_MATERIAL_NO
			   AND J.OUT_MATERIAL_NO = T.OUT_MATERIAL_NO
			 WHERE (T.DISABLE_FL != '1' OR T.DISABLE_FL IS NULL)
			   AND T.IN_MATERIAL_NO = (select t2.material_no 
               from craft_ord_design td,craft_ord_line_bom t1,slm_ord_design_bom t2
               where td.desgin_key=t1.desgin_key and t1.bom=t2.bom 
               and td.ord_ln_pk= ?  and td.VALIDFLAG<>'0' group by t2.material_no)
			   AND T.OUT_MATERIAL_NO = ?
		]]>
	</query>

	<query id="CoreJgMBlOrd.selectJgMProP" desc="查询接箍订单明细">
		<![CDATA[
			SELECT T.CODE_JG_BL, T.GROUP_NUM, T.PRO_PLAN_ID, T.JG_GROUP_ID, T1.CODE_JG
			  FROM PLN_GX_JG_PROP T, PLN_GX_JG_M T1
			 WHERE T1.PRO_PLAN_ID = T.PRO_PLAN_ID
			   AND T.PRO_PLAN_ID = ?
		]]>
	</query>

	<query id="CoreJgMBlOrd.updateJgMProPBl" desc="更新接箍订单明细">
		<![CDATA[
			UPDATE PLN_GX_JG_PROP T
			   SET T.CODE_JG_BL     = '#CODE_JG_BL#',
			       T.AIMLENGTH_BL   = '#AIMLENGTH_BL#',
			       T.SINGLE_CUT_NUN = '#SINGLE_CUT_NUN#',
			       T.GROUP_BL_NUM   = '#GROUP_BL_NUM#',
			       T.GROUP_BL_WT    = '#GROUP_BL_WT#'
			 WHERE T.PRO_PLAN_ID = '#PRO_PLAN_ID#'
			   AND T.JG_GROUP_ID = '#JG_GROUP_ID#'
		]]>
	</query>

	<query id="CoreJgMBlOrd.querySaleOrder" 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.ORDERNUM,
			       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,
			       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,
			       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.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.PRDCR_NO,
			       T.ROLL_MONTH,
			       T.MATERIAL_NO,
			       T.MATERIAL_DESC,
			       NVL(T.BL_GROUP_NUM,
			           (SELECT MIN(A.GROUP_NUM)
			              FROM CRAFT_ORD_DESIGN_MSC_BL A
			             WHERE A.DESGIN_KEY = T1.DESGIN_KEY)) 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.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.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,
			       DECODE(T.IF_SALE_FREEZE, '1', '是', '0', '否') IF_SALE_FREEZE,
			       T.STD_STYLE_DESC,
			       NVL(T.ROLL_WELL_MONTH, T.ROLL_MONTH) ROLL_WELL_MONTH,
			       T.WEIGHT_PER_M,
			       T.PAYDOWN_NUM,
			       T.HEIGHT_ORD_MIN,
			       T.HEIGHT_ORD_MAX,
			       T1.DESGIN_KEY,
			       T2.DESIGN_STS,
			       T1.CRAFT_NO CRAFT_FILE_NO_NEW
			  FROM PLN_SALEORD T
			  LEFT JOIN CRAFT_ORD_DESIGN T1
			    ON T1.ORD_LN_PK = T.ORD_LN_PK
			   AND T1.VALIDFLAG = '1'
			  LEFT JOIN (SELECT DECODE(K.DESIGN_STS,
			                           'W',
			                           '等待',
			                           'S',
			                           '通过',
			                           'F',
			                           '失败') DESIGN_STS,
			                    H.ORD_LN_PK
			               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, PLN_GX_JG_M A, PLN_ORDER_JG B
			 WHERE A.PRO_PLAN_ID = B.PRO_PLAN_ID
			   AND B.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
			   AND NVL(T1.CRAFT_SEQ, 1) = NVL((SELECT MAX(M.CRAFT_SEQ)
			                                    FROM CRAFT_ORD_DESIGN M
			                                   WHERE M.ORD_LN_PK = T.ORD_LN_PK
			                                     AND M.VALIDFLAG = '1'),
			                                  1)
			   AND T.ORDER_TYPE = '1'
			   AND A.PRO_PLAN_ID = ?
		]]>
	</query>
</queryMap>