<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="天淮半成品合同">
	<query id="FrmTHOrderManage.doQuery" desc="获取半成品合同">
	<![CDATA[
      SELECT DISTINCT DECODE(T.ISENDGX,
              '1',
              '天,' || (CASE
                WHEN D.TRANSIT_TYP = '110501' THEN
                 '汽运' || '  ' ||
                 (SELECT D1.DELVRY_ADDR
                    FROM SLM_ORDER_LINE_DELIVERY D1
                   WHERE D1.VALIDFLAG = '1'
                     AND INSTR(D1.DELVRY_ADDR, '客户库') > 0
                     AND D1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK)
                WHEN D.TRANSIT_TYP = '110502' THEN
                 '铁运' || '  ' ||
                 (SELECT  MIN(C.STATION_NM)
                    FROM SLM_ORDER_DELIVERY_TRANSIT Y, SLM_BASE_STATION C
                   WHERE Y.VALIDFLAG = '1'
                     AND Y.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                     AND Y.STATION_NO = C.STATION_NO
                     AND C.VALIDFLAG = '1'
                     AND Y.VALIDFLAG = '1')
                ELSE
                 (SELECT MAX(M.PLINE_NAME)
                    FROM PLN_GX_JG_M M, PLN_JG_AND_BL B
                   WHERE M.PRO_PLAN_ID = B.PRO_PLAN_ID
                     AND B.REQ_BL_ID = T.ORD_LN_DLY_PK)
              END) || ',条',
              (CASE
                WHEN T.WHOLE_BACKLOG_DESC LIKE '%镦拔扩%' THEN
                 (SELECT
                         MAX(S3.PLINE_NAME)
                    FROM PLN_ORDER_DBK_S S3
                   WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
                WHEN T.WHOLE_BACKLOG_DESC LIKE '%热处理%' THEN
                 (SELECT
                         MAX(S3.PLINE_NAME)
                    FROM PLN_ORDER_RCL_S S3
                   WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
                WHEN T.WHOLE_BACKLOG_DESC LIKE '%加工%' THEN
                 (SELECT
                         MAX(S3.PLINE_NAME)
                    FROM PLN_ORDER_JGX_S S3
                   WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
                ELSE
                 ''
              END)) AF_INFO,
       (CASE
         WHEN T.WHOLE_BACKLOG_DESC LIKE '%镦拔扩%' THEN
          (SELECT TO_CHAR(MIN(S3.PLAN_TIME_B), 'YYYY-MM-DD HH24:MI:SS') AF_PLAN_TIME_B
             FROM PLN_ORDER_DBK_S S3
            WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
         WHEN T.WHOLE_BACKLOG_DESC LIKE '%热处理%' THEN
          (SELECT TO_CHAR(MIN(S3.PLAN_TIME_B), 'YYYY-MM-DD HH24:MI:SS') AF_PLAN_TIME_B
             FROM PLN_ORDER_RCL_S S3
            WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
         WHEN T.WHOLE_BACKLOG_DESC LIKE '%加工%' THEN
          (SELECT TO_CHAR(MIN(S3.PLAN_TIME_B), 'YYYY-MM-DD HH24:MI:SS') AF_PLAN_TIME_B
             FROM PLN_ORDER_JGX_S S3
            WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
         ELSE
          ''
       END) AF_PLAN_TIME_B,
         DECODE((CASE
                WHEN T.WHOLE_BACKLOG_DESC LIKE '%镦拔扩%' THEN
                 (SELECT min(S3.EXE_STATUS)
                    FROM PLN_ORDER_DBK_S S3
                   WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
                WHEN T.WHOLE_BACKLOG_DESC LIKE '%热处理%' THEN
                 (SELECT min(S3.EXE_STATUS)
                    FROM PLN_ORDER_RCL_S S3
                   WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
                WHEN T.WHOLE_BACKLOG_DESC LIKE '%加工%' THEN
                 (SELECT min(S3.EXE_STATUS)
                    FROM PLN_ORDER_JGX_S S3
                   WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
                ELSE
                 ''
              END),
              '0',
              '计划',
              '1',
              '生产中',
              '2',
              '已生产',
              '3',
              '关闭A',
              '') EXE_STATUS_AFTER,
       D.TRANSIT_TYP,
       D.DELVRY_ADDR,
       D.VALIDFLAG,
       T.ORD_LN_DLY_PK,
       D.ORD_LN_DLY_PK,
       T.PRO_ORDER_NO,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.PLAN_GROUP_ID,
       T.ORDER_SOURCE,
       T.ORD_LN_DLY_PK,
       T.PLN_DIVIDE_ID,
       DECODE(T.ISENDGX,
              '1',
              NULLIF(T.ORDER_NO || '/' || T.ORDER_SEQ, '/'),
              T.PRO_PLAN_ID) PRO_PLAN_NO,
       NULLIF(T.ORDER_NO || '/' || T.ORDER_SEQ, '/') ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.LENGTHDISC,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.LEN_ROLL_MAX,
       T.LEN_ROLL_MIN,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.AIMLENGTH,
       T.DIAMETER_GP,
       T.LEN_GP_SINGLE,
       T.ROLL_LENGTH,
       T.LEN_CUTHEAD,
       T.LEN_CUTEND,
       T.OUTNUM_CUT,
       T.DIAMETER_MANDREL,
       T.PASS_CODE,
       T.PASS_NAME,
       T.IN_WEIGHT_S,
       T.IN_NUM_S,
       T.WEIGTH_S,
       T.NUM_S,
       T.ADD_WT_IN,
       T.ADD_NUM_IN,
       T.MATCH_WT_IN,
       T.MATCH_NUM_IN,
       DECODE(T.ISENDGX, '1', '是', '/') ISENDGX,
       DECODE(T.IF_MONITOR_ZG, '1', '是', '/') IF_MONITOR_ZG,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.STATION_ROAD,
       T.PRO_MONTH,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.WIC,
       T.GIC,
       T.GX_PRO_SEQ,
       TO_CHAR(ROUND(TO_NUMBER(NVL(T.PLAN_USETIME, '0')) / 60, 2)) PLAN_USETIME,
       TO_CHAR(T.PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
       TO_CHAR(T.PLAN_TIME_E, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E,
       T.BATCHED_WT,
       T.BATCHED_NUM,
       T.FINISHWEIGHT,
       T.FINISHNUM,
       DECODE(T.EXE_STATUS,
              '0',
              '计划',
              '1',
              '生产中',
              '2',
              '已生产',
              '3' , '关闭A' , '') EXE_STATUS,
       DECODE(T.IS_REPAIR_PLN, '1', '是', '/') IS_REPAIR_PLN,
       T.REPAIR_TYPE,
       DECODE(T.IS_PLAN_OK, '1', '是', '/') IS_PLAN_OK,
       DECODE(T.GPREQ_IF_OK, '1', '是', '/') GPREQ_IF_OK,
       T.GPREQ_ID,
       T.ZY_BATCH_ID,
       T.CIC_GROUP_GP,
       T.PIC_GROUP_GP,
       T.SIC_GROUP_GP,
       T.DIC_GROUP_GP,
       T.WIC_GROUP_GP,
       T.GIC_GROUP_GP,
       T.CIC_GP,
       T.PIC_GP,
       T.SIC_GP,
       T.DIC_GP,
       T.WIC_GP,
       T.GIC_GP,
       T.TH_ORDER_NO_SEQ,
       H.CUSTOMER_NM,H.SALE_ORG_DESC,H.SALE_AREA_DESC,
       T.IF_EXPORT,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       TO_CHAR(T.CONFIRM_DATE_ZZB, 'YYYY-MM-DD HH24:MI:SS') CONFIRM_DATE_ZZB,
       TO_CHAR(T.CONFIRM_DATE_PDFWK, 'YYYY-MM-DD HH24:MI:SS') CONFIRM_DATE_PDFWK,
       TO_CHAR(T.CONFIRM_DATE_TH, 'YYYY-MM-DD HH24:MI:SS') CONFIRM_DATE_TH,
       T.MEMO,
       TO_CHAR(T.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
       T.ISSUED_MAN,
       TO_CHAR(T.LAST_UNDOWN_TIME, 'YYYY-MM-DD HH24:MI:SS') LAST_UNDOWN_TIME,
       T.LAST_UNDOWN_MAN,
       T.VERSION_NO,
       T.PROCESSING_COST,
       T.TOTAL_COST,
       DECODE(T.IF_STOVE_ISSUED, '1', '是', '/') IF_STOVE_ISSUED,
       DECODE(T.IS_NOTICE_EP,'0','未通知','1','已通知')IS_NOTICE_EP,
       T.IS_NOTICE_USER,
       TO_CHAR(T.IS_NOTICE_TIME, 'YYYY-MM-DD HH24:MI:SS') IS_NOTICE_TIME,
       TO_CHAR(T.STOVE_ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') STOVE_ISSUED_TIME,
       T.STOVE_ISSUED_MAN,
       T.IS_ONLOAD_LINE,
       (T.OUTDIAMETER_ZG) AIMOUTDIAMETER,
       (T.WALLTHICK_ZG) AIMWALLTHICK,
       T.WHOLE_BACKLOG_DESC,
       T.MSC,
       T.INDEX_SEQ,
       T.BOM,
       (SELECT S1.CRAFT_PATH
          FROM CRAFT_FILE_LV2 S1
         WHERE INSTR(T1.CRAFT_FILE_LV2_D, S1.PK) > 0
           AND INSTR(S1.PLINE_CODE, T.PLINE_CODE) > 0
           AND S1.VALIDFLAG = '1'
           AND S1.PROCESS_CODE = 'D') CRAFT_FILE_LV2_G,
      (SELECT CD.CRAFT_PATH  FROM CRAFT_ORD_DESIGN CD WHERE CD.ORD_LN_PK=T1.ORD_LN_PK AND CD.CRAFT_SEQ=T.CRAFT_SEQ) CRAFT_PATH,
       T.CRAFT_SEQ,
       T.CRAFT_FILE_NO,
       T.CRAFT_FILE_MAN,
       T1.PRODUCCODE,
       T1.PRODUCNAME,
       T1.STD_CODE,
       CASE
	WHEN T.ORD_LN_DLY_PK LIKE 'ZZBY%' THEN
		(SELECT
			PRODUCNAME || ',' || STEELNAME || ',' || SPEC_NAME || ',' || MODEL_DESC
		FROM
			PLN_SALEORD
		WHERE
			ORD_LN_DLY_PK = T.ORD_LN_DLY_PK)
	ELSE
		(SELECT  SS1.PRODUCNAME ||
       DECODE(SS1.STD_STYLE_DESC, NULL, '', ',' ||SS1.STD_STYLE_DESC) || ',' ||
       SS1.STEELNAME || ',' || SS1.SPEC_NAME ||
       DECODE(SS1.MODEL_DESC, '/', '', ',' || SS1.MODEL_DESC) PSC_NAME_DESC FROM  SLM_ORDER_LINE  SS1  WHERE SS1.ORD_LN_PK=D.ORD_LN_PK)
	END PSC_NAME_DESC ,
      (SELECT  SS1.ORDER_QTY FROM  SLM_ORDER_LINE  SS1  WHERE SS1.ORD_LN_PK=D.ORD_LN_PK ) ORDER_QTY,
       (SELECT  SS1.ORD_ENSU_TOTL_LEN FROM  SLM_ORDER_LINE  SS1  WHERE SS1.ORD_LN_PK=D.ORD_LN_PK  ) ORD_ENSU_TOTL_LEN,
       T1.STD_NAME,
       T1.STD_STYLE_DESC,
       T1.SPEC_CODE,
       T1.SPEC_NAME,
       T1.MODEL_DESC,
       DECODE(T.IF_LEN_CONTROL, '1', '是', '0', '/') IF_LEN_CONTROL,
       DECODE(T.IF_MINUS_SIC_ROLL, '1', '是', '0', '/') IF_MINUS_SIC_ROLL,
       T.TUBE_END_RATIO,
       T.GPREQ_NUM,
       T.GPREQ_WEIGHT,
       T.VERIFY1,
       T.VERIFY2,
       T.VERIFY3,
       NVL(T.WEIGTH_S_MIN, 0) WEIGTH_S_MIN,
       (SELECT T9.BASENAME
          FROM COM_BASE_INFO T9
         WHERE T9.BASECODE = T.PRIORITY) PRIORITY,
       T.PRIORITY_MEMO,
       NVL(T.PLANS_NUM, 0) PLANS_NUM,
       T.ORIGINAL_NUMBER,
       T1.FINAL_USER_DESC,
       T.PROD_STANDARD,
       T.OUTPUT_STANDARD,
       T.PRODUCTION_TH_FLAG,
       B.BASENAME PRODUCTION_TH_NAME,
       T.THICKNESS_WALL,
       T.DECISION,
       TO_CHAR(T.DELVRY_EDATE,'YYYY-MM-DD') ORDER_DELVRY_EDATE,
       T.PROCESS_DESC_C,
       T.APPLY_NO,
       DECODE(T.APPLY_STATUS,
              '00',
              '作废',
              '10',
              '申请',
              '20',
              '审批通过',
              '30',
              '审批不通过') APPLY_STATUS,
       T.ISSUED_MEMO,
       DECODE(T.OUTS_BILLET_FL, '0', '自炼', '1', '外购') OUTS_BILLET_FL,
       T1.OUTS_STL_PIPE_FL,
       T1.LEN_NO,
       T1.LENGTHDISC_N,
       T1.LEN_NO_N,
       T.PROGY_MEMO,
       (SELECT P.GRADECODE_ALL
          FROM PLN_SALEORD_PROC P
         WHERE P.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
           AND P.PLN_DIVIDE_ID = T.PLN_DIVIDE_ID) GRADECODE_ALL,
       T1.PRD_CLS,
       CASE
        WHEN T.ORDER_NO LIKE 'TH%' THEN
          (SELECT SALE_ORG_DESC FROM SLM_ORDER_HEAD WHERE ORDER_NO = (
          SELECT CUSTM_ORDER_NO FROM SLM_ORDER_HEAD WHERE ORDER_NO = T.ORDER_NO
          ))
        ELSE
          T1.ORDERFROM
      END ORDERFROM,
       T1.PRODUCE_SORT,
       (SELECT SP.HR_CAPCTY
          FROM SLM_BASE_MATERIAL_D_PL SP
         WHERE SP.PLINE_CODE = T.PLINE_CODE
           AND SP.IN_MATERIAL_NO = T.INWL_ID
           AND SP.OUT_MATERIAL_NO = T.OUTWL_ID) HR_CAPCTY,
           DECODE(T.PASSIVE,'1','主动','0','被动') PASSIVE,
           DECODE(B.CODE_JG_BL,'',B.CODE_DJ_BL,B.CODE_JG_BL) REQ_BL_ID,
           T.GRADECODE_LK,T.GRADENAME_LK,T.CIC_GROUP_LK,
            (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_MAT_NUM(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) PEND_NUM,
       (SELECT GET_GP_MAT_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) PEND_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,
       (SELECT GET_ZG_REDUCED_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) REDUCED_WT,
       (SELECT GET_ZG_YJCC_NUM(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) EXPECT_NUM,
       (SELECT GET_ZG_YJCC_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) EXPECT_WT,
       (SELECT GET_GP_LJB_NUM(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJ_NUM_B,
       (SELECT GET_GP_LJB_WT(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) LJ_WEIGHT_B,
       (SELECT GET_ZG_TS(T.PRO_PLAN_ID, T.GX_PLAN_NO) FROM DUAL) PHY_NAME,
       (SELECT LISTAGG(C.GRADENAME, ',') WITHIN GROUP(ORDER BY C.GRADENAME ASC) PROD_GRADENAME
          FROM (SELECT DISTINCT(M.GRADENAME) GRADENAME, M.PRO_PLAN_ID, M.GX_PLAN_NO
                  FROM PLN_ZY_ZG_M M) C
         WHERE C.PRO_PLAN_ID = T.PRO_PLAN_ID
           AND C.GX_PLAN_NO = T.GX_PLAN_NO
           GROUP BY C.PRO_PLAN_ID ,C.GX_PLAN_NO) PROD_GRADENAME,
           T1.CUSTM_ORDER_NO,
  TO_CHAR(D.DELVRY_EDATE,'YYYY-MM-DD') DELVRY_EDATE,T1.ORDER_ADD_DESC,
  			(SELECT
				SUM(ACT_WEIGHT) ACT_WEIGHT
			FROM
				YDM_ZC_BILL_C
			WHERE
				ORDER_NO = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '/.*', '')
				AND ORDER_SEQ = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '.*/', '')
				AND RECEIVE_FLAG = '0') THDJS,
				(SELECT
				SUM(ACT_WEIGHT) ACT_WEIGHT
			FROM
				YDM_ZC_BILL_C
			WHERE
				ORDER_NO = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '/.*', '')
				AND ORDER_SEQ = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '.*/', '')

			AND RECEIVE_FLAG != '0') THYJS,
			(SELECT
				SUM(ACT_WEIGHT) ACT_WEIGHT
			FROM
				MAT_ZC_M
			WHERE
				ORDER_NO = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '/.*', '')
				AND ORDER_SEQ = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '.*/', '')
				AND MAT_STATUS = '80150301') THWBD,
				(SELECT
				DECODE(IF_STOVE_ISSUED, '0','否', '是')
			FROM
				PLN_ORDER_ZG_S
			WHERE
				ORDER_NO = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '/.*', '')
				AND ORDER_SEQ = REGEXP_REPLACE(T.TH_ORDER_NO_SEQ, '.*/', '') and rownum = 1) THSFXF,
						(SELECT ORDER_NO_SEQ FROM(
			SELECT
				jg.ORDER_NO || '/' || JG.ORDER_SEQ ORDER_NO_SEQ ,bl.REQ_BL_ID
			FROM
				PLN_ORDER_JG JG
				LEFT JOIN PLN_SALEORD t ON t.ORD_LN_DLY_PK = jg.ORD_LN_DLY_PK
				LEFT JOIN PLN_GX_JG_M D ON d.PRO_PLAN_ID = JG.PRO_PLAN_ID
				LEFT JOIN PLN_JG_AND_BL R ON r.PRO_PLAN_ID = d.PRO_PLAN_ID
				LEFT JOIN PLN_PORDER_BL_REQ BL ON bl.REQ_BL_ID = r.REQ_BL_ID
				 UNION ALL
				SELECT
				 ORDER_NO || '/' || ORDER_SEQ ORDER_NO_SEQ,REQ_BL_ID
			FROM
				PLN_PORDER_BL_REQ
				)WHERE REQ_BL_ID = T.ORDER_NO || '/' || T.ORDER_SEQ  AND
	 rownum = 1) BLXSHT
  FROM PLN_ORDER_ZG_S T,SLM_ORDER_HEAD H, COM_BASE_INFO B,
       (SELECT Q1.PRODUCCODE,
               Q1.PRODUCNAME,
               Q1.STD_CODE,
               Q1.STD_NAME,
               Q1.STD_STYLE_DESC,
               Q1.SPEC_CODE,
               Q1.SPEC_NAME,
               Q1.ORD_LN_DLY_PK,
               Q1.ORD_LN_PK,
               Q1.STEELCODE,
               Q1.STEELNAME,
               Q1.DELVRY_RANGE_TPE,
               Q1.DELVRY_RANGE_MAX,
               Q1.DELVRY_RANGE_MIN,
               Q1.DELVRY_QTY,
               Q1.MODEL_DESC,
               Q4.ABRVITION FINAL_USER_DESC,
               Q1.LENGTHMAX,
               Q1.LENGTHMIN,
               Q1.OUTS_BILLET_FL,
               Q1.OUTS_STL_PIPE_FL,
               Q1.LENGTHDISC_N,
               Q1.LEN_NO_N,
               Q1.LEN_NO,
               (SELECT F.CUSTM_ORDER_NO FROM SLM_ORDER_HEAD F WHERE F.ORD_PK = Q1.ORD_PK )CUSTM_ORDER_NO,
               Q2.CRAFT_FILE_LV2_D,
               (SELECT A.PRODUC_DESC
                  FROM COM_BASE_PRODUCT A
                 WHERE A.PRODUCCODE = Q1.PRODUCCODE
                   AND A.VALIDFLAG = '1') PRD_CLS,
               (SELECT A.BASENAME
                  FROM COM_BASE_INFO A
                 WHERE A.BASECODE = Q1.ORDERFROM) ORDERFROM,
               Q1.PRODUCE_SORT, Q2.CRAFT_SEQ,
               Q2.DESGIN_KEY,Q1.ORDER_ADD_DESC
          FROM PLN_SALEORD              Q1,
               CRAFT_ORD_DESIGN         Q2,
               CRAFT_ORD_DESIGN_APPOINT Q3,
               SLM_BASE_CUSTOMER        Q4
         WHERE Q1.ORD_LN_PK = Q3.ORD_LN_PK(+)
           AND Q1.FINAL_USER = Q4.CUSTOMER_NO(+)
           AND Q1.ORD_LN_PK = Q2.ORD_LN_PK(+)
           AND Q2.VALIDFLAG(+) = '1') T1,
       (SELECT MIN(S.NEXT_GX) NEXT_GX,
               S.PRO_PLAN_ID,
               MIN(S.PLAN_GROUP_ID) PLAN_GROUP_ID
          FROM PLN_ORDER_ZG S
         GROUP BY S.PRO_PLAN_ID) T2,
       SLM_ORDER_LINE_DELIVERY D,PLN_PORDER_BL_REQ B
 WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK(+)
   AND T.PRO_PLAN_ID = T2.PRO_PLAN_ID(+)
   AND T.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK(+)
   AND T.ORD_LN_DLY_PK=B.REQ_BL_ID(+)
   AND T.ORDER_NO = H.ORDER_NO(+)
   AND T.PRODUCTION_TH_FLAG = B.BASECODE(+)
   AND T.PLINE_CODE IN ('C065','C066') AND T.VALIDFLAG = '1'
		]]>
	</query>


	<query id="FrmTHOrderManage.doQueryThOrderReport" desc="报表">
		<![CDATA[
		SELECT * FROM (
		 SELECT
			'成品' HTTYPE,
			A.STLMT_UNIT_NM,
			A.ORDER_NO || '/' || B.ORDER_SEQ THCOHT,
			A.CUSTM_ORDER_NO || '/' || B.ORDER_SEQ TPCOHT,
			B.PRODUCNAME || ',' || B.STEELNAME || ',' || B.SPEC_NAME || ',' || B.MODEL_DESC ORDER_DESC,
			B.ORDER_QTY,
			(
			SELECT
				BALNCE_PRICE_ORG
			FROM
				SLM_ORDER_LINE LE
			WHERE
				LE.ORD_PK = ( SELECT ORD_PK FROM SLM_ORDER_HEAD WHERE ORDER_NO = A.CUSTM_ORDER_NO AND VALIDFLAG = '1' )
				AND LE.VALIDFLAG = '1'
				AND LE.ORDER_SEQ = B.ORDER_SEQ
			) BALNCE_PRICE,
			A.CREATE_TIME
		FROM
			SLM_ORDER_HEAD A
			LEFT JOIN SLM_ORDER_LINE B ON A.ORD_PK = B.ORD_PK
		WHERE
			A.ORDER_NO LIKE 'TH%'
			AND A.VALIDFLAG = '1'
			AND B.VALIDFLAG = '1' UNION ALL
		SELECT
			'半成品' HTTYPE,
			C.STLMT_UNIT_NM,
			T.TH_ORDER_NO_SEQ THCOHT,
			T.ORDER_NO || '/' || T.ORDER_SEQ TPCOHT,
			C.ORDER_DESC,
			C.ORDER_QTY,
			C.BALNCE_PRICE,
			C.CREATE_TIME
		FROM
			PLN_ORDER_ZG_S T
			LEFT JOIN (
			SELECT
				A.STLMT_UNIT_NM,
				A.ORDER_NO || '/' || B.ORDER_SEQ THCOHT,
				B.PRODUCNAME || ',' || B.STEELNAME || ',' || B.SPEC_NAME || ',' || B.MODEL_DESC ORDER_DESC,
				B.ORDER_QTY,
				B.BALNCE_PRICE,
				A.CREATE_TIME
			FROM
				SLM_ORDER_HEAD A
				LEFT JOIN SLM_ORDER_LINE B ON A.ORD_PK = B.ORD_PK
			WHERE
				A.VALIDFLAG = '1'
				AND B.VALIDFLAG = '1'
			) C ON T.TH_ORDER_NO_SEQ = C.THCOHT
		WHERE
			T.TH_ORDER_NO_SEQ IS NOT NULL
			) T where 1=1
		]]>
	</query>

	<query id="FrmTHOrderManage.getThBcOrder" desc="获取半成品合同">
		<![CDATA[
			SELECT TH_ORDER_NO_SEQ FROM PLN_ORDER_ZG_S WHERE TH_ORDER_NO_SEQ LIKE ? || '%'
		]]>
	</query>


	<query id="FrmTHOrderManage.getThBcOrderState" desc="获取半成品合同状态">
		<![CDATA[
			SELECT max(ORDER_STS) ORDER_STS FROM SLM_ORDER_HEAD WHERE {0} LIKE ORDER_NO || '%' and VALIDFLAG = '1'
		]]>
	</query>

	<query id="FrmTHOrderManage.doUpdate" desc="修改生产表半成品合同状态">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S
			 SET PRODUCTION_TH_FLAG = ?,
			 #something#
			WHERE
			PRO_PLAN_ID = ? AND GX_PLAN_NO = ?
		]]>
	</query>

	<query id="FrmTHOrderManage.doupdateWeight" desc="修改信息">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
       SET
        T.MEMO=?
       WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
		]]>
	</query>




	<query id="FrmTHOrderManage.doupdateField" desc="修改信息">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T
       SET
        T.DELVRY_EDATE=TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
       WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
		]]>
	</query>
	<query id="FrmTHOrderManage.doUpdateThOrder" desc="修改生产表">
		<![CDATA[
			UPDATE PLN_ORDER_ZG_S T SET TH_ORDER_NO_SEQ = ?
			WHERE
			PRO_PLAN_ID = ? AND GX_PLAN_NO = ?
		]]>
	</query>


	<query id="FrmTHOrderManage.doQueryZc" desc="查询成品合同">
		<![CDATA[
		SELECT H.MANAG_NO,
       H.ORDER_NO,
       H.CUSTM_ORDER_NO,
       H.ORDER_TYP,
       H.ORDER_TYP_DESC,
       H.PROTCL_NO,
       H.CUSTOMER_NO,
       H.CUSTOMER_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = H.SUPPLY_UNIT) SUPPLY_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = H.PRICE_FL) PRICE_FL_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = H.CURRENCY) CURRENCY_NM,
       H.STLMT_UNIT_NO,
       H.STLMT_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = H.FST_DRAWEE_UNIT) FST_DRAWEE_UNIT_NM,
       H.LEGAL_PSN,
       AGENT,
       H.ADDRESS,
       H.ZIP_CODE,
       H.BANK,
       ACCOUNT,
       H.TAX_ID,
       H.PHONE,
       H.FAX,
       H.ORDER_WGT,
       H.ORDER_MNY_TAX,
       H.ORDER_MNY_NTAX,
       H.MNY_ASK_DESC,
       H.SIGN_PERSON,
       TO_CHAR(H.SIGN_DATE, 'YYYY-MM-DD') SIGN_DATE,
       H.ORDER_BDATE,
       H.ORDER_EDATE,
       H.ORDER_SCAN_NO,
       H.CUSTOMER_MODEL_FL,
       H.ORDER_MODEL_NO,
       H.SALE_ORG,
       H.SALE_ORG_DESC,
       H.SALE_AREA_NO,
       H.SALE_AREA_DESC,
       H.MEMO,
       H.ORDER_STS,
       (SELECT BASENAME
          FROM COM_BASE_INFO
         WHERE BASECODE = H.ORDER_STS
           AND VALIDFLAG = '1') ORDER_STS_DESC,
       H.APPROVAL_MAN,
       H.APPROVAL_TIME,
		CASE
			WHEN ORDER_NO LIKE 'TH%' THEN
				(SELECT MAX(VALIDFLAG) FROM SLM_ORDER_HEAD WHERE ORDER_NO = H.CUSTM_ORDER_NO AND ROWNUM = 1)
			ELSE
				H.VALIDFLAG
		END VALIDFLAG,
       H.CREATE_NAME,
       TO_CHAR(H.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       H.UPDATE_NAME,
       TO_CHAR(H.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       H.ORDER_YEAR,
       H.EFFECT_TIME,
       H.EFFECT_MAN,
       H.CLOSE_TIME,
       H.CLOSE_MAN,
       (SELECT COUNT(BALNCE_PRICE_STS)||'个'||DECODE(BALNCE_PRICE_STS, '1', '确认', '未确认') FROM SLM_ORDER_LINE LE WHERE LE.ORD_PK=(select ORD_PK from slm_order_head where order_no = h.CUSTM_ORDER_NO and VALIDFLAG = '1') AND LE.VALIDFLAG = '1' GROUP BY BALNCE_PRICE_STS ) BALNCE_PRICE_STS,
       (SELECT COUNT(BALNCE_PRICE_ORG_STS)||'个'||DECODE(BALNCE_PRICE_ORG_STS, '1', '确认', '未确认') FROM SLM_ORDER_LINE LE WHERE LE.ORD_PK=(select ORD_PK from slm_order_head where order_no = h.CUSTM_ORDER_NO and VALIDFLAG = '1') AND LE.VALIDFLAG = '1' GROUP BY BALNCE_PRICE_ORG_STS ) BALNCE_PRICE_ORG_STS,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = H.MNY_ASK_TYP) MNY_ASK_TYP_NM,
       H.SIGN_ADDRESS,
       H.SUPPLY_UNIT,
       H.PRICE_FL,
       H.CURRENCY,
       H.FST_DRAWEE_UNIT,
       H.MNY_ASK_TYP,
       NVL(H.ORDER_MODEL_DESC, ' ') ORDER_MODEL_DESC,
       H.ORD_PK,
       H.CREATE_DEPT,
       H.MARKET_SYS,
       H.MARKET_SYS_DESC,
       H.ABRVITION,
       H.REVW_RPT_NO,
       H.PRINT_PRICE,
       H.PRICE_PLAN,
       H.CONTAIN_TAX,
       DECODE(H.CONTAIN_TAX, '1', '是', '否') CONTAIN_TAX_DESC,
       DECODE(H.ORDER_ARCHIVE, '1', '是', '否') ORDER_ARCHIVE,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = H.TRADE_TYPE) TRADE_TYPE,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = H.ORDER_CLASSIFY) ORDER_CLASSIFY,
       H.BUSINESS_TYPE,
       H.TRADE_TYPE TRADE_TYPE_CODE,
       H.ORDER_CLASSIFY ORDER_CLASSIFY_CODE,
       H.LOCAL_LAW,
       H.DOCUMENTARY_NAME,
       H.DOCUMENTARY_DEPT,
       DECODE(H.TH_ORDER_FALG_ZC, '1', '已下发', '未下发') TH_ORDER_FALG_ZC,
       (
		SELECT B.BASENAME FROM slm_order_head A LEFT JOIN COM_BASE_INFO B ON BASECODE = A.ORDER_STS WHERE A.order_no = h.CUSTM_ORDER_NO AND A.VALIDFLAG = '1'
		) CUSTM_ORDER_STS
  FROM SLM_ORDER_HEAD H
 WHERE ORDER_NO || '&' LIKE '%' || ? || '%'
   AND CREATE_TIME >=
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND CREATE_TIME <=
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND VALIDFLAG = '1'
   AND ORDER_NO LIKE 'TH%'
		]]>
	</query>

	<query id="FrmTHOrderManage.doQueryZcState" desc="查询成品合同下发状态">
		<![CDATA[
			SELECT TH_ORDER_FALG_ZC,ORDER_STS FROM SLM_ORDER_HEAD WHERE ORDER_NO LIKE 'TH%' AND ORD_PK = {0}
		]]>
	</query>

	<query id="FrmTHOrderManage.doUpdateZcState" desc="修改成品合同下发状态">
		<![CDATA[
			UPDATE SLM_ORDER_HEAD SET TH_ORDER_FALG_ZC = ? where order_no like 'TH%' AND ORD_PK = ?
		]]>
	</query>

</queryMap>