<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍二级工艺">
	<query id="FrmJgSecondProcess.queryJgOrder" desc="查询接箍合同">
		<![CDATA[
SELECT T2.*
  FROM (SELECT T.JG_ORDERNO,
               T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_NO,
               T.ORDER_SEQ,
               T.DELIVERY_NO,
               T.BUYER_ID,
               T.BUYER_NAME,
               TO_CHAR(T.DELVRY_BDATE, 'YYYY-MM-DD HH24:MI:SS') DELVRY_BDATE,
               TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD HH24:MI:SS') DELVRY_EDATE,
               T.ORDERCONTACT,
               T.MONITORDEMAND,
               DECODE(T.IF_MONITOR_JG, '1', '是', '/') IF_MONITOR_JG,
               T.PRDCR_NO,
               T.PSC,
               T.MSC,
               T.INDEX_SEQ,
               T.CODE_JG,
               T.STEELCODE,
               T.STEELNAME,
               T.OUTDIAMETER,
               T.WALLTHICK,
               T.AIMWALLTHICK,
               T.MODEL_CODE,
               T.AIMLENGTH,
               T.SINGLEWEIGHT,
               NVL(T.ORDERWEIGHT, 0) ORDERWEIGHT,
               NVL(T.ORDERNUM, 0) ORDERNUM,
               TO_CHAR(T.LATEST_PROD_DATE, 'YYYY-MM-DD HH24:MI:SS') LATEST_PROD_DATE,
               NVL(T.MATCHWEIGHT, 0) MATCHWEIGHT,
               NVL(T.MATCHNUM, 0) MATCHNUM,
               T.IFBUYPLAN,
               T.BUYPLANID,
               NVL(T.BUYPLANWEIGHT, 0) BUYPLANWEIGHT,
               NVL(T.BUYPLANNUM, 0) BUYPLANNUM,
               DECODE(T.JGORDERSTATUS,
                      '0',
                      '待处理',
                      '1',
                      '已组订单',
                      '2',
                      '已完成') JGORDERSTATUS,
               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.GROUP_JGX,
               T.JGWT_BLREQ,
               TO_CHAR(T.ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
               T.SPEC_JG,
               T.SPEC_JG_DESC,
               T.MODEL_DESC,
               T.STYLE_JG,
               T.DIAMETER,
               T.CHECK_J_VAL,
               T.ORD_LN_DLY_PK,
               (SELECT B.BASENAME
                  FROM COM_BASE_INFO B
                 WHERE B.BASECODE = T.DEMAND_DETECTION
                   AND B.VALIDFLAG = '1') DEMAND_DETECTION,
               (SELECT B.BASENAME
                  FROM COM_BASE_INFO B
                 WHERE B.BASECODE = T.DEMAND_BONDERIZING
                   AND B.VALIDFLAG = '1') DEMAND_BONDERIZING,
               (SELECT B.BASENAME
                  FROM COM_BASE_INFO B
                 WHERE B.BASECODE = T.DEMAND_COPPER
                   AND B.VALIDFLAG = '1') DEMAND_COPPER,
               (SELECT B.BASENAME
                  FROM COM_BASE_INFO B
                 WHERE B.BASECODE = T.DEMAND_BLAST
                   AND B.VALIDFLAG = '1') DEMAND_BLAST,
               T.PRO_PLAN_ID,
               T.KEY_JG,
               T.JG_GROUP_ID,
               T.FINAL_USER,
               T.FINAL_USER_DESC,
               DECODE(T.IF_JG_SALEORD, '1', '是', '/') IF_JG_SALEORD,
               T.PRO_PLAN_ID_S,
               (SELECT NVL(SUM(C.OFFLINE_NUM), 0)
                  FROM COUPLING_COM_INFO C
                 WHERE C.JG_ORDERNO = T.JG_ORDERNO
                   AND C.STATION_CODE = '700313'
                   AND C.STATION_STATUS = '2') COUNT_FINISH,
               (SELECT GET_PROCESS_TIME(T1.ORD_LN_DLY_PK,
                                        T1.PROCESS_SEQ)
                  FROM DUAL) TIME_CP,
               DECODE((SELECT GET_PROCESS_STATUS(T1.ORD_LN_DLY_PK,
                                                T1.PROCESS_SEQ)
                        FROM DUAL),
                      '0',
                      '计划',
                      '1',
                      '生产中',
                      '2',
                      '生产完成',
                      '3',
                      '关闭A') EXE_STATUS,
               DECODE(T.STATUS, '0', '计划', '1', '下发', '2', '完成') STATUS,
               (SELECT DECODE(B.PRODUC_TYPE,
                              'A',
                              '钢管（管坯）',
                              'B',
                              '钢管+接箍',
                              'C',
                              '短节+附件',
                              'D',
                              '接箍',
                              'E',
                              '双公短节')
                  FROM COM_BASE_PRODUCT B
                 WHERE B.PRODUCCODE = S.PRODUCCODE) PRODUC_TYPE,
                 T.KEY,
               S.PRODUCNAME,
               C1.CRAFT_PATH,
               C1.CRAFT_NO_JG2,
               C1.CRAFT_SEQ2,
               (SELECT DECODE(MIN(JGS.IS_PLAN_OK),'1','是','/') FROM PLN_GX_JG_PROP_S JGS WHERE JGS.PRO_PLAN_ID=T.PRO_PLAN_ID_S) IS_PLAN_OK
          FROM PLN_ORDER_JG     T,
               PLN_SALEORD_PROC T1,
               PLN_SALEORD      S,
               (SELECT C.KEY, C.CRAFT_PATH, C.CRAFT_NO_JG2, C.CRAFT_SEQ2
          FROM CRAFT_FILE_JG2 C
         WHERE C.VALIDFLAG = '1') C1
         WHERE T.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
           AND S.ORD_LN_DLY_PK = T1.ORD_LN_DLY_PK
           AND T.KEY = C1.KEY(+)
           AND T1.ORDER_SOURCE = '销售合同') T2
 WHERE 1 = 1
		]]>
	</query>
		<query id="FrmJgSecondProcess.doQueryCraftSeconed" desc="查询接箍订单(7+4)与二级工艺关系">
		<![CDATA[
		SELECT T.PK,
       T.CRAFT_NO_JG2,
       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.DELETE_NAME,
       TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       DECODE(T.VALIDFLAG,'0','无效','有效') VALIDFLAG,
       T.CRAFT_PATH,
       T.MEMO,
       T.CRAFT_SEQ2,
       T.KEY, T.MEMO1,T.CONTENT,T.NUMBERS,T.MEMO2
  FROM CRAFT_FILE_JG2 T WHERE 1=1 AND T.KEY=?
		]]>
	</query>
	<query id="FrmJgSecondProcess.doMaxCraftSeq" desc="查询接箍订单(7+4)与二级工艺关系最大序号">
		<![CDATA[
		SELECT T.CRAFT_SEQ2 FROM CRAFT_FILE_JG2 T WHERE 1=1 AND T.KEY=? ORDER BY T.CRAFT_SEQ2 DESC
		]]>
	</query>
	<query id="FrmJgSecondProcess.doAddCraft" desc="新增接箍订单(7+4)与二级工艺关系">
		<![CDATA[
		INSERT INTO CRAFT_FILE_JG2
  (KEY,
   CRAFT_NO_JG2,
   CRAFT_SEQ2,
   CRAFT_PATH,
   MEMO,
   CREATE_NAME,
   CREATE_TIME,
   VALIDFLAG,MEMO1,CONTENT,MEMO2,NUMBERS)
VALUES
  (?, ?, ?, ?, ?, ?, TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), '1',?,?,?,?)

		]]>
	</query>
	<query id="FrmJgSecondProcess.queryPlanStoveReadyH" desc="查询接箍实际炉计划">
            <![CDATA[ 
SELECT T.HEAT_PLAN_NO,
       T.PRO_PLAN_ID,
       T.JG_GROUP_ID,
       T.GX_PLAN_NO,
       T.JUDGE_STOVE_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.CODE_JG_BL,
       T.BL_WL_ID,
       T.BL_WL_DESC,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.MIN_D,
       T.MIN_H,
       T.AIMLENGTH_BL,
       T.AIM_CUT_LEN,
       T.LENGTH_MIN,
       T.LENGTH_MAX,
       T.TAPER,
       T.CODE_JG,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.SPEC_JG,
       T.SPEC_JG_DESC,
      (SELECT T1.BASENAME FROM COM_BASE_INFO T1 WHERE T1.BASECODE=T.STYLE_JG  AND T1.VALIDFLAG='1')  STYLE_JG,
       T.DIAMETER,
       T.CHECK_J_VAL,
       T.AIMLENGTH,
       T.SINGLEWEIGHT,
       T.COAT_TYPE,
       NVL(T.PLAN_JG_NUM,0) PLAN_JG_NUM,
       NVL(T.PLAN_BL_NUM,0) PLAN_BL_NUM,
       NVL(T.PLAN_BL_WT,0) PLAN_BL_WT,
       T.MONITORDEMAND,
       DECODE(T.IF_MONITOR_JG, '1', '是', '/') IF_MONITOR_JG,
       T.PRDCR_NO,
       T.CUT_MACH_GRP_NO,
       T.CUT_MACH_GRP_NM,
        (SELECT T1.BASENAME FROM COM_BASE_INFO T1 WHERE T1.BASECODE=T.DEMAND_COPPER  AND T1.VALIDFLAG='1') DEMAND_COPPER,
       T.LATHE_GRP_NO,
       T.LATHE_GRP_NM,
       DECODE(T.PLANSTATUS,
              '00',
              '计划',
              '10',
              '下发',
              '20',
              '生产中',
              '30',
              '生产完成',
              '40',
              '关闭') PLANSTATUS,
       T.MEMO,
       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.CUST_ALPHA_NO,
       T.ORDER_SPECIAL_DESC,
       T.ALPHA_CODE,
       T.CRAFT_FILE_NO,
       T.CRAFT_SEQ,
       T.ORD_LN_DLY_PK,
       T.SINGLE_CUT_NUN,
       DECODE(T.IF_MATCH_ODD, '0', '正常计划','2','精整利库', '利库计划') IF_MATCH_ODD,
       DECODE(T.IF_DO_HEAT_PLAN, '1', '是', '/') IF_DO_HEAT_PLAN,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.STOVE_NO,
       T.FLAG_STOVE_NO,
       T.GX_PRO_SEQ,
       T.PRO_DAY,
       T.BAL_YEAR_MONTH,
       T.PROD_STANDARD,
       T.OUTPUT_STANDARD,
       T.UPPER_HEATPLAN_ID,
       (SELECT MAX(DECODE(Z.PLANSTATUS,
                          '00',
                          '计划',
                          '10',
                          '下发',
                          '20',
                          '生产中',
                          '30',
                          '生产完成',
                          '40',
                          '关闭'))
          FROM PLN_ZY_RCL_M Z
         WHERE Z.JUDGE_STOVE_NO = T.JUDGE_STOVE_NO) PLANSTATUS_GX,
       T.UPPER_PROCESS_CODE,
       T1.HEAT_PLAN_SQE,
       T1.JUGDE_APPLY_CODE,
       T1.OUT_JG_NUM,
       T1.USE_BL_NUM,
       T1.USE_BL_WT,T.STD_CODE,
       T.STD_NAME,T.STD_STYLE,T.STD_STYLE_DESC,
       T.PRODUCCODE_JG,T.PRODUCCODE_JG_DESC,T1.BATCH_NO,
       T1.BATCH_GROUD_NO
  FROM PLN_ZY_JG_M T, PLN_ZY_JG_C T1
 WHERE T.HEAT_PLAN_NO = T1.HEAT_PLAN_NO(+)
              ]]>
	</query>
	<query id="FrmJgSecondProcess.doQueryOrderJgMemo" desc="查询合同接箍一级备注">
		<![CDATA[
		SELECT C.MEMO || B.MEMO || CHR(10) || B.JG_MEMO MEMO
  FROM CRAFT_ORD_DESIGN_MSC_JG B, COM_MSC_JG C
 WHERE B.CODE_JG = C.CODE_JG
   AND B.DESGIN_KEY =
       (SELECT T2.DESGIN_KEY
          FROM SLM_ORDER_LINE T, SLM_ORDER_HEAD T1, CRAFT_ORD_DESIGN_MSC T2
         WHERE T1.ORD_PK = T.ORD_PK
           AND T.ORD_PK = T2.ORD_PK
           AND T.ORD_LN_PK = T2.ORD_LN_PK
           AND T2.VALIDFLAG = '1'
           AND T1.ORDER_NO || '/' || T.ORDER_SEQ = ?
           AND T2.CREATE_TIME =
               (SELECT MAX(CREATE_TIME)
                  FROM CRAFT_ORD_DESIGN_MSC
                 WHERE ORD_PK = T1.ORD_PK
                   AND ORD_LN_PK = T.ORD_LN_PK))
		]]>
	</query>
	<query id="FrmJgSecondProcess.doQueryNumBeiMax" desc="查询最大编号">
		<![CDATA[
   SELECT ?||
          LPAD(SUBSTR(NVL(MAX(T.NUMBERS), '0000'), -4, 4) + 1, 4, '0') AS NUMBERS
     FROM CRAFT_FILE_JG2 T
    WHERE T.NUMBERS LIKE '%'||?||'%'

		]]>
	</query>
</queryMap>