<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc=" 综合信息">
<query id = "FrmProductionSchedulingAndCoupling.getQrue" desc = "加工排产一级与接箍订单查询">
<![CDATA[
SELECT 
       T.IF_EXPORT,
       T.PROCESS_DESC_C_ZG,
       T.GROUP_ROLL_NAME,
       TO_CHAR(T.BEGIN_TIME_ZG, 'YYYY-MM-DD HH24:MI:SS') BEGIN_TIME_ZG,
       T.PRDCR_ADVC_DAY,
       T.WHOLE_BACKLOG_DESC,
       T.MSC,
       T.INDEX_SEQ,
       T.BOM,
       (SELECT T9.BASENAME
          FROM COM_BASE_INFO T9
         WHERE T9.BASECODE = T.PRIORITY) PRIORITY,
       T.PRIORITY_MEMO,
       TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
       T.STATION_NM,
       T.OUTLINE_SITE_250,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.MEMO,
       T.PRO_ORDER_NO,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       NULLIF(T.ORDER_NO || '/' || T.ORDER_SEQ, '/') PRO_PLAN_NO,
       T.PLAN_GROUP_ID,
       T.ORDER_SOURCE,
       T.ORD_LN_DLY_PK,
       T.PLN_DIVIDE_ID,
       NULLIF(T.ORDER_NO || '/' || T.ORDER_SEQ, '/') ORDER_NO1,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.REQ_BL_ID,
       T.PLINE_CODE,
       T.PLINE_NAME,
       (SELECT B.BASENAME
          FROM COM_BASE_PLINE A, COM_BASE_INFO B
         WHERE A.GROUP_PLAN = B.BASECODE
           AND B.SORTCODE = '2004'
           AND A.PLINE_CODE = T.PLINE_CODE) JGFZ,
       T.STEELCODE,
       T.STEELNAME,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.LENGTHMAX,
       T.LENGTHMIN,
       T.LENGTHDISC,
       T.AIMWALLTHICK,
       T.AIMLENGTH,
       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.MODEL_CODE,
       T.MODEL_DESC,
       T.LENGTHMAX_IN,
       T.LENGTHMIN_IN,
       T.LENGTH_IN,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.IN_WEIGHT_S,
       T.IN_NUM_S,
       T.WEIGTH_S,
       T.NUM_S,
       T.MATCH_WT_IN,
       T.MATCH_NUM_IN,
       DECODE(T.IF_MONITOR_JGX, '1', 'Y', '') IF_MONITOR_JGX,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.STATION_ROAD,
       T.GX_PRO_SEQ,
       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', 'Y', '') IS_REPAIR_PLN,
       T.REPAIR_TYPE,
       DECODE(T.IS_PLAN_OK, '1', 'Y', '') IS_PLAN_OK,
       T.ZY_BATCH_ID,
       T.PRO_MONTH,
       T.PREVIOUS_GX,
       T.PREV_GXPLAN_ID,
       T1.GROUP_JGX,
       T.FINAL_USER_DESC,
       T2.SALE_ORG_DESC,
       T2.PRODUCCODE,
       T2.PRODUCNAME,
       T2.STD_CODE,
       T2.STD_NAME,
       T2.STD_STYLE,
       T2.STD_STYLE_DESC,
       T2.ORDER_SPEC_CODE,
       T2.ORDER_SPEC_DESC,
       T2.SPEC_CODE,
       T2.SPEC_NAME,
       T2.CRAFT_PATH,
       T2.CRAFT_SEQ,
       T2.CRAFT_NO AS CRAFT_FILE_NO,
       T2.CRAFT_NAME AS CRAFT_FILE_MAN,
       (SELECT LV.CRAFT_PATH
          FROM CRAFT_FILE_LV2 LV
         WHERE INSTR(T2.CRAFT_FILE_LV2_G, LV.PK) > 0
           AND INSTR(LV.PLINE_CODE, T.PLINE_CODE) > 0
           AND LV.VALIDFLAG = '1'
           AND LV.PROCESS_CODE = 'G') CRAFT_FILE_LV2_G,
       T3.ADD_ASK1,
       T3.ADD_ASK2,
       T3.ADD_ASK3,
       T3.ADD_ASK4,
       T3.ADD_ASK5,
       T3.ADD_ASK6,
       T3.ADD_ASK7,
       T3.ADD_ASK8,
       T3.ADD_ASK9,
       T3.ADD_ASK10,
       T3.ADD_ASK11,
       T3.ADD_ASK12,
       T3.ADD_ASK13,
       DECODE(T4.JGORDERSTATUS,
              '0',
              '待处理',
              '1',
              '已组订单',
              '2',
              '已完成') JGORDERSTATUS,
       T4.JG_ORDERNO,
       T4.ORDERWEIGHT,
       T4.ORDERNUM,
       T4.CODE_JG,
       DECODE(T4.IF_MONITOR_JG, '0', '否', '1', '是') IF_MONITOR_JG,
       DECODE(T4.DEMAND_DETECTION,
              '0',
              '否',
              '1',
              '是',
              (SELECT B.BASENAME
                 FROM COM_BASE_INFO B
                WHERE B.BASECODE = T4.DEMAND_DETECTION)) DEMAND_DETECTION,
       DECODE(T4.DEMAND_BONDERIZING,
              '0',
              '否',
              '1',
              '是',
              (SELECT B.BASENAME
                 FROM COM_BASE_INFO B
                WHERE B.BASECODE = T4.DEMAND_BONDERIZING)) DEMAND_BONDERIZING,
       DECODE(T4.DEMAND_COPPER,
              '0',
              '否',
              '1',
              '是',
              (SELECT B.BASENAME
                 FROM COM_BASE_INFO B
                WHERE B.BASECODE = T4.DEMAND_COPPER)) DEMAND_COPPER,
       DECODE(T4.DEMAND_BLAST,
              '0',
              '否',
              '1',
              '是',
              (SELECT B.BASENAME
                 FROM COM_BASE_INFO B
                WHERE B.BASECODE = T4.DEMAND_BLAST)) DEMAND_BLAST,
       T4.SPEC_JG_DESC,
       T4.STEELNAME STEELNAME_JG,
       T4.MODEL_DESC MODEL_DESC_JG,
       T4.STYLE_JG,
       T4.PRODUCCODE_JG_DESC,
       T4.STD_NAME STD_NAME_JG,
       T4.STD_STYLE_DESC STD_STYLE_DESC_JG,
       (SELECT SUM(CASE
                     WHEN TO_NUMBER(NVL(Z.FINISHNUM, 0)) *
                          TO_NUMBER(NVL(Z.OUTNUM_CUT, 0)) >
                          TO_NUMBER(NVL(Z.PLANS_NUM, 0)) THEN
                      TO_NUMBER(NVL(Z.FINISHNUM, 0)) *
                      TO_NUMBER(NVL(Z.OUTNUM_CUT, 0))
                     ELSE
                      TO_NUMBER(NVL(Z.PLANS_NUM, 0))
                   END)
          FROM (SELECT SUM(NVL(ZG.FINISHNUM, 0)) FINISHNUM,
                       SUM(NVL(ZG.PLANS_NUM, 0)) PLANS_NUM,
                       NVL(ZG.OUTNUM_CUT, 0) OUTNUM_CUT,
                       ZG.ORD_LN_DLY_PK
                  FROM PLN_ORDER_ZG_S ZG

                 GROUP BY ZG.OUTNUM_CUT, ZG.ORD_LN_DLY_PK) Z
         WHERE Z.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK) OUTPUT_NUM,
       (SELECT SUM(Q.ACT_COUNT)
          FROM QCM_ZG_JUGDE_APPLY Q
         WHERE Q.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
           AND Q.VALIDFLAG = '20') ACTUAL_NUM
  FROM PLN_ORDER_JGX_S T,
       PLN_GX_JGX_M T1,
       (SELECT Q1.PRODUCCODE,
               Q1.PRODUCNAME,
               Q1.STD_CODE,
               Q1.STD_NAME,
               Q1.STD_STYLE,
               Q1.STD_STYLE_DESC,
               Q1.ORDER_SPEC_CODE,
               Q1.ORDER_SPEC_DESC,
               Q1.SPEC_CODE,
               Q1.SPEC_NAME,
               Q2.ORD_LN_DLY_PK,
               Q2.ORD_LN_PK,
               Q1.STEELCODE,
               Q1.STEELNAME,
               Q2.DELVRY_QTY,
               Q3.CRAFT_SEQ,
               Q3.CRAFT_NO,
               Q4.CRAFT_NAME,
               Q5.SALE_ORG_DESC,
               Q1.FINAL_USER_DESC,
               NVL(Q3.CRAFT_PATH,
                   (SELECT C1.CRAFT_PATH
                      FROM CRAFT_ORD_DESIGN C2, CRAFT_ORD_DESIGN_FILE C1
                     WHERE C1.CRAFT_NO = C2.CRAFT_NO
                       AND C1.CRAFT_NO_V = C2.CRAFT_NO_V
                       AND C1.VALIDFLAG = '1'
                       AND C2.VALIDFLAG = '1'
                       AND C2.ORD_LN_PK = Q1.ORD_LN_PK)) AS CRAFT_PATH,
               Q3.CRAFT_FILE_LV2_G
          FROM SLM_ORDER_LINE           Q1,
               SLM_ORDER_LINE_DELIVERY  Q2,
               CRAFT_ORD_DESIGN         Q3,
               CRAFT_ORD_DESIGN_APPOINT Q4,
               SLM_ORDER_HEAD           Q5
         WHERE Q1.ORD_LN_PK = Q2.ORD_LN_PK
           AND Q1.ORD_LN_PK = Q3.ORD_LN_PK(+)
           AND Q1.ORD_LN_PK = Q4.ORD_LN_PK(+)
           AND Q1.ORD_PK = Q5.ORD_PK
           AND Q3.VALIDFLAG(+) = '1') T2,
       (SELECT *
          FROM (SELECT Q.ASK_ITME_DESC,
                       Q.ASK_SUB_ITME_VAL_DESC,
                       Q.ORD_LN_DLY_PK
                  FROM (SELECT Q3.ASK_ITME_DESC,
                               Q1.ORD_LN_DLY_PK,
                               LISTAGG(Q3.ASK_SUB_ITME_VAL_DESC, ' ** ') WITHIN GROUP(ORDER BY Q3.ASK_ITME) ASK_SUB_ITME_VAL_DESC
                          FROM SLM_ORDER_LINE_DELIVERY Q1,
                               SLM_ORDER_LINE          Q2,
                               SLM_ORDER_ADD_ASK       Q3
                         WHERE Q1.ORD_LN_PK = Q2.ORD_LN_PK
                           AND Q2.ADD_ASK_NO = Q3.ADD_ASK_NO
                           AND Q1.VALIDFLAG = '1'
                           AND Q2.VALIDFLAG = '1'
                           AND Q2.CREATE_NAME IS NOT NULL
                           AND Q3.VALIDFLAG = '1'
                         GROUP BY Q3.ASK_ITME_DESC, Q1.ORD_LN_DLY_PK) Q) PIVOT(MAX(ASK_SUB_ITME_VAL_DESC) FOR ASK_ITME_DESC IN('喷标' AS
                                                                                                                               ADD_ASK1,
                                                                                                                               '涂漆' AS
                                                                                                                               ADD_ASK2,
                                                                                                                               '保护帽' AS
                                                                                                                               ADD_ASK3,
                                                                                                                               '丝扣油' AS
                                                                                                                               ADD_ASK4,
                                                                                                                               '计重方式' AS
                                                                                                                               ADD_ASK5,
                                                                                                                               '打捆' AS
                                                                                                                               ADD_ASK6,
                                                                                                                               '质量' AS
                                                                                                                               ADD_ASK7,
                                                                                                                               '交货材料' AS
                                                                                                                               ADD_ASK8,
                                                                                                                               '发货结算约定' AS
                                                                                                                               ADD_ASK9,
                                                                                                                               '特殊通径' AS
                                                                                                                               ADD_ASK10,
                                                                                                                               '特殊端部加工' AS
                                                                                                                               ADD_ASK11,
                                                                                                                               '取样备注' AS
                                                                                                                               ADD_ASK12,
                                                                                                                               '表面质量' AS
                                                                                                                               ADD_ASK13))) T3,
       (SELECT C1.ORD_LN_DLY_PK,
               C1.JGORDERSTATUS,
               C1.JG_ORDERNO,
               C1.ORDERWEIGHT,
               C1.ORDERNUM,
               C1.CODE_JG,
               C1.IF_MONITOR_JG,
               C1.DEMAND_DETECTION,
               C1.DEMAND_BONDERIZING,
               C1.DEMAND_COPPER,
               C1.DEMAND_BLAST,
               C1.SPEC_JG_DESC,
               C1.STEELNAME,
               C1.MODEL_DESC,
               C1.STYLE_JG,
               C2.PRODUCCODE_JG_DESC,
               C2.STD_NAME,
               C2.STD_STYLE_DESC
          FROM PLN_ORDER_JG C1, COM_MSC_JG C2
         WHERE C1.CODE_JG = C2.CODE_JG(+)) T4

 WHERE T.PRO_PLAN_ID = T1.PRO_PLAN_ID(+)
   AND T.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK(+)
   AND T.ORD_LN_DLY_PK = T3.ORD_LN_DLY_PK(+)
   AND T.ORD_LN_DLY_PK = T4.ORD_LN_DLY_PK(+)
   AND T.EXE_STATUS = '0'
   AND T.MODEL_DESC <> 'BE'
   AND T.MODEL_DESC <> 'PE'
   AND T.MODEL_DESC <> '/'
   AND T.MODEL_DESC IS NOT NULL
   #something#
]]>
</query>

</queryMap>