<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="排产补量">
	<query id="FrmLgAmount.query" desc="查询">
		<![CDATA[
	 SELECT H.* FROM ( SELECT T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       TO_NUMBER(NVL(T.PLAN_WT_S, '0')) - TO_NUMBER(NVL(T.PLANED_WT, '0'))-TO_NUMBER(NVL(T.PLAN_WT_SOLD, '0')) AS CAN_WGT,
       TO_NUMBER(NVL(T.PLAN_NUM_S, '0')) -
       TO_NUMBER(NVL(T.PLANED_NUM, '0'))-TO_NUMBER(NVL(T.PLAN_NUM_SOLD, '0')) AS CAN_NUM,
       DECODE(T.GPTYPE, '1', '铸坯', '2', '锻坯', '') GPTYPE,
       DECODE(T.CASTINGTYPE, '1', '连铸', '2', '模铸', '') CASTINGTYPE,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PLINE_CODE_A,
       T.PLINE_NAME_A,
       T.GRADECODE,
       T.GRADENAME,
       CASE
         WHEN T.CASTINGTYPE = '2' THEN
          T.DIAMETER_LZ || 't'
         ELSE
          T.DIAMETER_LZ
       END DIAMETER_LZ,
       T.LEN_GP_SINGLE,
       T.CUT_NUM_GP,
       T.CUT_LOSE_LEN,
       T.LENGTH_LZ,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.WLID_IN,
       T.WLDESC_IN,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.WIC,
       T.GIC,
       DECODE(T.IF_MONITOR_LG, '1', '是', '/') IF_MONITOR_LG,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.WT_CAST_ONE,
       T.PLAN_WT_S,
       T.PLAN_NUM_S,
       T.CAST_NUM_CALC,
       T.FURNACE_NUM_CALC,
       T.FURNACE_WT,
       T.GX_PRO_SEQ,
       T.PRO_MONTH,
       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,
       NVL(T.PLANED_WT, 0) PLANED_WT,
       NVL(T.PLANED_NUM, 0) PLANED_NUM,
       T.FINISHWEIGHT,
       T.FINISH_NUM,
       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,
       T.CAST_NUM,
       T.FURNACE_NUM,
       T.ADD_WT_BEGIN,
       T.ADD_WT_END,
       DECODE(T.IF_CONNECT_AHEAD, '1', '是', '/') IF_CONNECT_AHEAD,
       T.ADD_WT_AHEAD,
       DECODE(T.IF_CONNECT_NEXT, '1', '是', '/') IF_CONNECT_NEXT,
       T.ADD_WT_NEXT,
       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,
       T1.FINAL_USER_DESC,
       T1.ORDER_SEQ_NO,
       T2.PDEPT_NAME,
       T1.PRODUCNAME,
       DECODE(T.CASTINGTYPE, '2', 'ELVI', T3.STATION_DESC) STATION_DESC,
       T.CAST_NO_ALL,
       T1.EXE_STATUS_ZG,
       T.PROGY_MEMO,
       T.CRAFT_NO,
       DECODE(T.IF_CONFIRM, '1', '是', '/') IF_CONFIRM,
       T.CRAFT_PATH,
       (SELECT TO_CHAR(MIN(SZ.PLAN_TIME_B), 'YYYY-MM-DD HH24:MI:SS')
          FROM PLN_ORDER_ZG_S SZ
         WHERE SZ.GPREQ_ID = T.PRO_PLAN_ID
           AND SZ.EXE_STATUS IN ('0', '1')) PLAN_TIME_B_ZG,
        CASE
         WHEN T.GPTYPE = '1' THEN
          (SELECT LISTAGG(PLINE_NAME, ',') WITHIN GROUP(ORDER BY PLINE_NAME ASC) GOWHERE_NAME
             FROM (SELECT ZG.PLINE_NAME, CS.PRO_PLAN_ID
                     FROM PLN_ORDER_ZG_S ZG, PLN_ORDER_CAST_S CS
                    WHERE ZG.GPREQ_ID = CS.PRO_PLAN_ID
                    GROUP BY ZG.PLINE_NAME, CS.PRO_PLAN_ID) T4
            WHERE T4.PRO_PLAN_ID = T.PRO_PLAN_ID)
         ELSE
          '快锻'
       END GOWHERE_NAME,
       NVL(T.PLAN_NUM_SOLD,0) PLAN_NUM_SOLD,
       NVL(T.PLAN_WT_SOLD,0) PLAN_WT_SOLD,
       DECODE(T.IF_AMOUNT,'1','是','/') IF_AMOUNT,
       NVL(T.PLAN_WT_MIN,0) PLAN_WT_MIN
  FROM PLN_ORDER_CAST_S T,
       (SELECT MAX(J.PDEPT_NAME) PDEPT_NAME,
               MAX(J.PRDCR_MAN) PRDCR_MAN,
               C.PRDCR_NO
          FROM SLM_ORDER_LINE_PRDCR_LST J, PLN_ORDER_CAST_S C
         WHERE J.PRDCR_NO = C.PRDCR_NO
           AND J.PROCESS_CODE = 'A'
           AND J.PROCESS_CODE_C = 'B001'
         GROUP BY C.PRDCR_NO) T2,
       (SELECT MAX(Y.ABRVITION) FINAL_USER_DESC,
               MAX(S.ORDER_NO || '/' || S.ORDER_SEQ) ORDER_SEQ_NO,
               Z.GPREQ_ID,
               MAX(S.PRODUCNAME) PRODUCNAME,
               MAX(S.PRODUCCODE) PRODUCCODE,
               DECODE(MIN(Z.EXE_STATUS),
                      '0',
                      '计划',
                      '1',
                      '生产中',
                      '2',
                      '生产完成',
                      '3',
                      '关闭A') EXE_STATUS_ZG,
               MAX(TO_CHAR(CASE
                             WHEN CIC.UPDATE_TIME IS NULL THEN
                              CIC.CREATE_TIME
                             ELSE
                              CIC.UPDATE_TIME
                           END,
                           'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME_CIC            
          FROM PLN_ORDER_ZG_S           Z,
               PLN_SALEORD              S,
               PLN_ORDER_CAST_S         C,
               SLM_BASE_CUSTOMER        Y,
               CRAFT_ORD_DESIGN         DE,
               CRAFT_ORD_DESIGN_STD_CIC CIC
         WHERE Z.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
           AND Z.GPREQ_ID = C.PRO_PLAN_ID
           AND S.FINAL_USER = Y.CUSTOMER_NO
           AND DE.ORD_LN_PK = S.ORD_LN_PK
           AND DE.CRAFT_SEQ = Z.CRAFT_SEQ
           AND CIC.DESGIN_KEY = DE.DESGIN_KEY
           AND CIC.MSC_PLINE = Z.INDEX_SEQ
           AND CIC.SPECL_FL = '2'
           AND CIC.VALIDFLAG = '1'
         GROUP BY Z.GPREQ_ID) T1,
       (SELECT LISTAGG(STATION_DESC, '') WITHIN GROUP(ORDER BY STATION_CODE) STATION_DESC,
               GPREQ_ID
          FROM (SELECT DISTINCT CASE
                                  WHEN S.STATION_DESC = '电炉' THEN
                                   'E'
                                  WHEN S.STATION_DESC = '炉外精炼' THEN
                                   'L'
                                  WHEN T.PLINE_CODE_A = 'C006' AND
                                       S.STATION_DESC = '真空处理' THEN
                                   'R'
                                  WHEN T.PLINE_CODE_A = 'C001' AND
                                       S.STATION_DESC = '真空处理' THEN
                                   'V'
                                  WHEN T.PLINE_CODE_A = 'C003' AND
                                       S.STATION_DESC = '真空处理' THEN
                                   'V'
                                  WHEN S.STATION_DESC = '熔炼成分' THEN
                                   'C'
                                  ELSE
                                   ''
                                END STATION_DESC,
                                S.STATION_CODE,
                                T4.GPREQ_ID
                  FROM CRAFT_ORD_DESIGN_MSC_PL_STI S,
                       CRAFT_ORD_DESIGN            C,
                       CRAFT_ORD_DESIGN_MSC_PL_PRC C1,
                       PLN_SALEORD                 T1,
                       PLN_ORDER_ZG_S              T4,
                       PLN_ORDER_CAST_S            T
                 WHERE T1.ORD_LN_DLY_PK = T4.ORD_LN_DLY_PK
                   AND S.DESGIN_KEY = C1.DESGIN_KEY
                   AND S.MSC_PLINE = C1.MSC_PLINE
                   AND S.PROCESS_CODE = C1.PROCESS_CODE
                   AND C.ORD_LN_PK = T1.ORD_LN_PK
                   AND C.CRAFT_SEQ = T4.CRAFT_SEQ
                   AND C1.DESGIN_KEY = C.DESGIN_KEY
                   AND C1.MSC_PLINE = T4.INDEX_SEQ
                   AND T.PRO_PLAN_ID = T4.GPREQ_ID
                   AND C1.PROCESS_CODE IN ('A')
                 GROUP BY T4.GPREQ_ID,
                          S.STATION_DESC,
                          S.STATION_CODE,
                          T.PLINE_CODE_A)
         GROUP BY GPREQ_ID) T3,
       CRAFT_LG2_M M
 WHERE 1 = 1
   AND T.PRO_PLAN_ID = T1.GPREQ_ID(+)
   AND T.PRDCR_NO = T2.PRDCR_NO(+)
   AND T.PRO_PLAN_ID = T3.GPREQ_ID(+)
   AND T.CRAFT_NO = M.CRAFT_NO(+)
   AND T.IS_REPAIR_PLN='0'
		]]>
	</query>
	<query id="FrmLgAmount.queryAddPlnOrderZgSStrat" desc="查询铸造订单状态">
		<![CDATA[
		SELECT T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.GPTYPE,
       T.CASTINGTYPE,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PLINE_CODE_A,
       T.PLINE_NAME_A,
       T.GRADECODE,
       T.GRADENAME,
       T.DIAMETER_LZ,
       T.LEN_GP_SINGLE,
       T.CUT_NUM_GP,
       T.CUT_LOSE_LEN,
       T.LENGTH_LZ,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.WLID_IN,
       T.WLDESC_IN,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.WIC,
       T.GIC,
       T.IF_MONITOR_LG,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.WT_CAST_ONE,
       NVL(T.PLAN_WT_S,0) PLAN_WT_S,
       NVL(T.PLAN_NUM_S,0) PLAN_NUM_S,
       T.CAST_NUM_CALC,
       T.FURNACE_NUM_CALC,
       T.FURNACE_WT,
       T.GX_PRO_SEQ,
       T.PRO_MONTH,
       T.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,
       NVL(T.PLANED_WT,0) PLANED_WT,
       NVL(T.PLANED_NUM,0) PLANED_NUM,
       T.FINISHWEIGHT,
       T.FINISH_NUM,
       T.EXE_STATUS,
       T.IS_REPAIR_PLN,
       T.REPAIR_TYPE,
       T.IS_PLAN_OK,
       T.CAST_NUM,
       T.FURNACE_NUM,
       T.ADD_WT_BEGIN,
       T.ADD_WT_END,
       T.IF_CONNECT_AHEAD,
       T.ADD_WT_AHEAD,
       T.IF_CONNECT_NEXT,
       T.ADD_WT_NEXT,
       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,
       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.PROCESSING_COST_A,
       T.TOTAL_COST_A,
       T.PROCESSING_COST_B,
       T.TOTAL_COST_B,
       T.IF_CRAFT_LOCKED,
       T.CAST_NO_ALL,
       T.PROGY_MEMO,
       T.CRAFT_NO,
       T.CRAFT_PATH,
       T.IF_CONFIRM,
       NVL(T.PLAN_WT_MIN,0) PLAN_WT_MIN,
       T.GOWHERE_NAME,
       T.GOWHERE_CODE,
       T.STEEL_JUDGEMENT,
       T.PLAN_WT_SOLD,
       T.PLAN_NUM_SOLD,
       T.IF_AMOUNT
  FROM PLN_ORDER_CAST_S T
 WHERE T.PRO_PLAN_ID = ?
   AND T.GX_PLAN_NO = ?
		]]>
	</query>
	<query id="FrmLgAmount.queryAddAmount" desc="新增">
		<![CDATA[
		INSERT INTO PLN_ORDER_CAST_S
  (PRO_PLAN_ID,
   GX_PLAN_NO,
   GPTYPE,
   CASTINGTYPE,
   PLINE_CODE,
   PLINE_NAME,
   PLINE_CODE_A,
   PLINE_NAME_A,
   GRADECODE,
   GRADENAME,
   DIAMETER_LZ,
   LEN_GP_SINGLE,
   CUT_NUM_GP,
   CUT_LOSE_LEN,
   LENGTH_LZ,
   MATERIAL_NO,
   MATERIAL_NAME,
   WLID_IN,
   WLDESC_IN,
   CIC,
   PIC,
   SIC,
   DIC,
   WIC,
   GIC,
   IF_MONITOR_LG,
   PRDCR_NO,
   MONITOR_POINT,
   WT_CAST_ONE,
   PLAN_WT_S,
   PLAN_NUM_S,
   CAST_NUM_CALC,
   FURNACE_NUM_CALC,
   FURNACE_WT,
   GX_PRO_SEQ,
   PRO_MONTH,
   PLAN_USETIME,
   PLAN_TIME_B,
   PLAN_TIME_E,
   FINISHWEIGHT,
   FINISH_NUM,
   EXE_STATUS,
   IS_PLAN_OK,
   CAST_NUM,
   FURNACE_NUM,
   ADD_WT_BEGIN,
   ADD_WT_END,
   IF_CONNECT_AHEAD,
   ADD_WT_AHEAD,
   IF_CONNECT_NEXT,
   ADD_WT_NEXT,
   MEMO,
   CREATE_NAME,
   CREATE_TIME,
   PROCESSING_COST_A,
   TOTAL_COST_A,
   PROCESSING_COST_B,
   TOTAL_COST_B,
   IF_CRAFT_LOCKED,
   CAST_NO_ALL,
   PROGY_MEMO,
   CRAFT_NO,
   CRAFT_PATH,
   IF_CONFIRM,
   PLAN_WT_MIN,
   GOWHERE_NAME,
   GOWHERE_CODE,
   STEEL_JUDGEMENT,
   IF_AMOUNT)
VALUES
  ('#PRO_PLAN_ID#',
   '#GX_PLAN_NO#',
   '#GPTYPE#',
   '#CASTINGTYPE#',
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#PLINE_CODE_A#',
   '#PLINE_NAME_A#',
   '#GRADECODE#',
   '#GRADENAME#',
   '#DIAMETER_LZ#',
   '#LEN_GP_SINGLE#',
   '#CUT_NUM_GP#',
   '#CUT_LOSE_LEN#',
   '#LENGTH_LZ#',
   '#MATERIAL_NO#',
   '#MATERIAL_NAME#',
   '#WLID_IN#',
   '#WLDESC_IN#',
   '#CIC#',
   '#PIC#',
   '#SIC#',
   '#DIC#',
   '#WIC#',
   '#GIC#',
   '#IF_MONITOR_LG#',
   '#PRDCR_NO#',
   '#MONITOR_POINT#',
   '#WT_CAST_ONE#',
   '#PLAN_WT_S#',
   '#PLAN_NUM_S#',
   '#CAST_NUM_CALC#',
   '#FURNACE_NUM_CALC#',
   '#FURNACE_WT#',
   '#GX_PRO_SEQ#',
   '#PRO_MONTH#',
   '#PLAN_USETIME#',
   TO_DATE('#PLAN_TIME_B#', 'YYYY-MM-DD HH24:MI:SS'),
   TO_DATE('#PLAN_TIME_E#', 'YYYY-MM-DD HH24:MI:SS'),
   '#FINISHWEIGHT#',
   '#FINISH_NUM#',
   '#EXE_STATUS#',
   '#IS_PLAN_OK#',
   '#CAST_NUM#',
   '#FURNACE_NUM#',
   '#ADD_WT_BEGIN#',
   '#ADD_WT_END#',
   '#IF_CONNECT_AHEAD#',
   '#ADD_WT_AHEAD#',
   '#IF_CONNECT_NEXT#',
   '#ADD_WT_NEXT#',
   '#MEMO#',
   '#CREATE_NAME#',
   TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   '#PROCESSING_COST_A#',
   '#TOTAL_COST_A#',
   '#PROCESSING_COST_B#',
   '#TOTAL_COST_B#',
   '#IF_CRAFT_LOCKED#',
   '#CAST_NO_ALL#',
   '#PROGY_MEMO#',
   '#CRAFT_NO#',
   '#CRAFT_PATH#',
   '#IF_CONFIRM#',
   '#PLAN_WT_MIN#',
   '#GOWHERE_NAME#',
   '#GOWHERE_CODE#',
   '#STEEL_JUDGEMENT#',
   '#IF_AMOUNT#')
		]]>
	</query>
	<query id="FrmLgAmount.UpdatePlnOrderZgS" desc="修改状态(关闭，已生产)">
		<![CDATA[
		
		]]>
	</query>
	<query id="FrmLgAmount.DeleteAmount" desc="删除排产补量">
		<![CDATA[
		DELETE PLN_ORDER_CAST_S
 WHERE PRO_PLAN_ID = ?
   AND GX_PLAN_NO = ?
	]]>
	</query>
</queryMap>