Pārlūkot izejas kodu

检查错误的原始脚本

zhangguo 2 nedēļas atpakaļ
vecāks
revīzija
133b96fd07

+ 1 - 1
MES_FIN_MONTH/InitScript/Origin/MES_CX_YDM_BC_INITIAL_hand.sql

@@ -99,7 +99,7 @@ select --t1.bal_year_month 记账日期,
            
    and
       --t1.bal_year_month = to_char(sysdate,'yyyymm')
-       t1.bal_year_month in ('{0}}')
+       t1.bal_year_month in ('{0}')
    and t1.belong_code = '002023005'
    and nvl((t1.order_no || t1.order_seq),
            replace(get_cp_order(t1.judge_stove_no), '/', ''))

+ 0 - 8
MES_FIN_MONTH/InitScript/Origin/mes_cx_JG_zzpnew_hand.sql

@@ -624,8 +624,6 @@ prod_name_cx varchar(200);
                                             AND EXISTS (SELECT 1 FROM PORT_MCH_BATCH_SAMPLE_RESULT WHERE HEAT_PLAN_NO = M.HEAT_PLAN_NO)
                   and t.PLINE_CODE in  ('C109', 'C108', 'C092','C102','C107','C104','C100')
 
-
-
                       UNION ALL  -- 部分精整返线转短节  上料支数减去
                           SELECT
                  T.PRODUCCODE,
@@ -757,12 +755,6 @@ prod_name_cx varchar(200);
 
 begin
 
-  --先删除
-/*  delete from hot_production_mes_jg
-   where acct_period in ('2025-01', '2025-01')
-     and prod_type = '在产品'
-     and FLAG = '0';*/
-
   open oporder_cursor_jg;
   loop
     fetch oporder_cursor_jg

+ 145 - 150
MES_FIN_MONTH/InitScript/Origin/mes_cx_jg_CSJG_HAND.sql

@@ -1,8 +1,8 @@
-CREATE OR REPLACE procedure mes_cx_rcl_zzpnew_hand is
-  a      number(4);
-  b      varchar(200);
-  cxdata orderdetail_v@th_cx_link%rowtype;
-  prod_name_cx varchar(200);
+CREATE OR REPLACE procedure mes_cx_jg_CSJG_HAND is
+      a number(4);
+      b varchar(200);
+cxdata orderdetail_v@th_cx_link%rowtype;
+      prod_name_cx varchar(200);
       sg_grade_cx varchar(200);
       sg_sign_cx varchar(200);
       wall_thickness_cx varchar(200);
@@ -10,195 +10,190 @@ CREATE OR REPLACE procedure mes_cx_rcl_zzpnew_hand is
       MATERIAL_NAME_cx varchar(200);
       outer_diam_cx varchar(200);
 
-  --热处理
-  cursor oporder_cursor_rcl is
-
- SELECT *
-  FROM (select t.judge_stove_no,
-  (case
-         when t.judge_stove_no like 'W%' then
-          '是'
-         else
-          '否'
-       end) resource_type,
-               t.ZY_BATCH_ID 生产批号,
-               T.STOVE_NO,
-               '2026-02' acct_period,
-               null high_tech_code, null high_tech_name, 0 high_prod_weight,
+--加工
+ CURSOR OPOrder_Cursor_jg IS
+
+select (select decode(max(s.order_typ),
+                        '120108',
+                        '双经销',
+                        '120109',
+                        '定销订购',
+                        '120107',
+                        '来料加工',
+                        '自用')
+           from cxuser.slm_order_head s
+          where s.order_no = regexp_replace(t.pro_order_no, '/.*', '')) contract_type,
+        --合同类型
+       replace(t.PRO_ORDER_NO, '/', '') orderid, t.producname prod_variety,
+        --品名、品种,
+       t.steelname steel_level,
+        --钢级,
+       t.gradename steel_no,
+        --钢号,
+       t.spec_name spec,
+        --规格,
+       '半成品' prod_type,
+        --产量类型
+        sum(decode(t.act_weight, null, t.act_theory_weight, t.act_weight)) prod_weight,
+        --成品重量
+       sum(nvl(t.input_weight, 0)) + sum(nvl(t1.coupling_wt, 0)) +
+        sum(nvl(t1.coupling_fail_wt, 0)) mate_weight,
+       NVL(
+        round(
+          sum(decode(t.act_weight, null, t.act_theory_weight, t.act_weight)) * 100
+          /
+          NULLIF( sum(nvl(t.input_weight, 0)) + sum(nvl(t1.coupling_wt, 0)) + sum(nvl(t1.coupling_fail_wt, 0)) , 0)
+        , 4)
+      , 0) as steel_waste,
+        --消耗占比
+       '加工' as process,
+        --工序
+       null high_tech_code, null high_tech_name, 0 high_prod_weight,
        0 high_mate_weight, 0 estimated_unit_price, 0 estimated_cost,
-               T.PRODUCNAME,
-               t.gradename steel_no,
-               T.DECISION,
-               T.OUTDIAMETER || '*' || T.WALLTHICK spec,
-               T.ORDER_NO || T.ORDER_SEQ orderid,
-               (SELECT DECODE(MAX(S.ORDER_TYP),
-                              '120108',
-                              '双经销',
-                              '120109',
-                              '定销订购',
-                              '120107',
-                              '来料加工',
-                              '自用')
-                  FROM SLM_ORDER_HEAD S
-                 WHERE S.ORDER_NO = REGEXP_REPLACE(T.ORDER_NO, '/.*', '')) contract_type,
-               MAX(T.STD_STYLE_DESC) 标准类别,
-               MAX(T.GOWHERE_NAME) 物流去向,
-               MAX(T.OUTPUT_STANDARD) 输出标准,
-               MAX(T.STEELNAME) steel_level,
-               MAX(T.MODEL_DESC) 扣型,
-               T.PLINE_CODE,
-               (SELECT C.PLINE_NAME
-                  FROM COM_BASE_PLINE C
-                 WHERE C.PLINE_CODE = T.PLINE_CODE) PLINE_NAME,
-               sum(a.act_count) act_count,
-               sum(a.act_weight) act_weight,
-               null billet_code
-
-          from PLN_ZY_RCL_M t,
-               (select t.judge_stove_no,
-                       T.HEAT_PLAN_NO,
-                       sum(t.act_count) act_count,
-                       sum(decode(T.act_weight,
-                                  '',
-                                  t.act_theory_weight,
-                                  t.act_weight)) act_weight
-                  from PORT_HTT_BATCH_SAMPLE_RESULT t
-                 where (t.group_flag = 0 OR T.GROUP_FLAG IS NULL)
-                      --AND T.INSTORE_FLAG = '0'
-                   AND T.PROCESS_SEQ = '1'
-                   AND T.MAT_STATUS IN ('00', '20')
-                   and t.bal_year_month <= '202602'
-                   and t.bal_year_month >= '202002'
-
-                 group by t.judge_stove_no, T.HEAT_PLAN_NO
-
-                UNION ALL
-
-                select t.judge_stove_no,
-                       T.HEAT_PLAN_NO,
-                       -SUM(T.ACT_COUNT) act_count,
-                       -sum(t.ACT_WEIGHT) act_weight
-                  from QCM_ZG_JUGDE_APPLY t
-                 where ((t.validflag = '20' and
-                       t.JUDGE_RESULT_CODE in ('40740701', '40740709')) OR
-                       T.INSTANCY_FLAG = '1')
-                   and t.is_flag = 0
-                   and t.PROCESS_CODE = 'F'
-                   and t.bal_year_month <= '202602'
-                   and t.bal_year_month >= '202002'
-
-                 group by t.judge_stove_no, T.HEAT_PLAN_NO
-
-                ) a
-         where a.judge_stove_no = t.judge_stove_no
-           AND T.HEAT_PLAN_NO = A.HEAT_PLAN_NO
-
-         group by t.judge_stove_no,
-                  t.ZY_BATCH_ID,
-                  T.STOVE_NO,
-                  T.PRODUCNAME,
-                  T.DECISION,
-                  t.gradename,
-                  T.OUTDIAMETER,
-                  T.WALLTHICK,
-                  T.PLINE_CODE,
-                  T.ORDER_NO,
-                  T.ORDER_SEQ
-         order by t.pline_code, t.judge_stove_no)
- WHERE act_count > 0 and orderid not like '%ZZBY%';
-
-  curoporder_rcl oporder_cursor_rcl%rowtype;
+       substr(bal_year_month, 0, 4) || '-' || substr(bal_year_month, 5, 2) acct_period,
+       --换成取产销提供的视图 tzh 24.12.4
+       get_cp_code6(t.pro_order_no) mate_code,
+        --物料编码
+       getislljg(t.judge_stove_no,replace(t.PRO_ORDER_NO, '/', '')) resource_type,t.judge_stove_no,
+        --是否来料加工
+       null billet_code --钢坯编码
+
+  from cxuser.qcm_zg_jugde_apply t,
+       (select t1.heat_plan_no, t1.judge_stove_no, t1.batch_no,
+                sum(nvl(t1.coupling_wt, 0)) coupling_wt,
+                sum(nvl(t1.coupling_fail_wt, 0)) coupling_fail_wt
+           from cxuser.mch_twistingly_result_d t1
+          group by t1.heat_plan_no, t1.judge_stove_no, t1.batch_no) t1,
+       (select a.basename, b.pline_code, b.pline_name
+           from cxuser.com_base_info a, cxuser.com_base_pline b
+          where a.basecode = b.factory_code) c
+ where t.is_flag = '0'
+   and t.is_all_scrap in ('0', '2')
+   and ((t.validflag = '20' and t.target <> 'A' and
+       t.judge_result_code in ('40740701', '40740705', '40740709')) or
+       (t.validflag = '20' and t.target = 'A' and
+       t.judge_tolresult_code in ('40740701', '40740705', '40740709')) or
+       t.instancy_flag = '1')
+   and t.process_code = 'G'
+   and t.pline_name = c.pline_name(+)
+   and t.heat_plan_no = t1.heat_plan_no(+)
+   and t.judge_stove_no = t1.judge_stove_no(+)
+   and t.batch_no = t1.batch_no(+)
+   and t.bal_year_month in ('{0}')
+   and t.PRO_ORDER_NO not like 'ZZBY%'
+   AND t.judge_stove_no NOT LIKE 'F%'
+   and t.pline_code = 'C108'
+   and t.target = 'A'
+ group by t.producname, t.steelname,
+           --钢级
+          t.gradename,
+           --钢号
+          t.spec_name,
+           --规格
+          t.target, bal_year_month, pro_order_no, t.judge_stove_no;
+
+curoporder_jg oporder_cursor_jg%rowtype;
+cnt number;
 
 begin
-
-  open oporder_cursor_rcl;
+ cnt := 0;
+  open oporder_cursor_jg;
   loop
-    fetch oporder_cursor_rcl
-      into curoporder_rcl;
-    exit when oporder_cursor_rcl%notfound;
+    fetch oporder_cursor_jg
+      into curoporder_jg;
+    exit when oporder_cursor_jg%notfound;
 
     select count(*)
       into a
       from orderdetail_v@th_cx_link t
-     where t.contractno_num = curoporder_rcl.orderid
+     where t.contractno_num = curoporder_jg.orderid
        and material_code is not null;
 
     if a > 0 then
       select prod_name,sg_grade,sg_sign,outer_diam,wall_thickness,material_code,MATERIAL_NAME
         into prod_name_cx,sg_grade_cx ,sg_sign_cx,outer_diam_cx ,wall_thickness_cx ,material_code_cx , MATERIAL_NAME_cx
         from orderdetail_v@th_cx_link t
-       where t.contractno_num = curoporder_rcl.orderid
+       where t.contractno_num = curoporder_jg.orderid
          and material_code is not null
          and rownum = 1;
 
-    elsif substr(curoporder_rcl.orderid, 1, 2) in ('TH', 'XS') then
+    elsif substr(curoporder_jg.orderid, 1, 2) in ('TH', 'XS') then
       select count(*)
         into a
         from orderdetail_v@th_cx_link t
-       where substr(t.contractno_num, 3) =
-             substr(curoporder_rcl.orderid, 3)
+       where substr(t.contractno_num, 3) = substr(curoporder_jg.orderid, 3)
          and material_code is not null
          and rownum = 1;
       if a > 0 then
         select prod_name,sg_grade,sg_sign,outer_diam,wall_thickness,material_code,MATERIAL_NAME
-        into prod_name_cx,sg_grade_cx ,sg_sign_cx,outer_diam_cx ,wall_thickness_cx ,material_code_cx , MATERIAL_NAME_cx
+        into prod_name_cx,sg_grade_cx ,sg_sign_cx ,outer_diam_cx,wall_thickness_cx ,material_code_cx , MATERIAL_NAME_cx
           from orderdetail_v@th_cx_link t
          where substr(t.contractno_num, 3) =
-               substr(curoporder_rcl.orderid, 3)
+               substr(curoporder_jg.orderid, 3)
            and material_code is not null
            and rownum = 1;
       end if;
     end if;
-
     if a > 0 then
-      insert into HOT_HEAT_PRODUCTION_MES_GX
+      insert into hot_production_mes_jg
         (cx_no, contract_type, prod_variety, steel_level, steel_no, spec,
          prod_type, prod_weight, mate_weight, steel_waste, process,
          high_tech_code, high_tech_name, high_prod_weight, high_mate_weight,
          estimated_unit_price, estimated_cost, acct_period, mate_code,
-         resource_type, billet_code, memo, flag, go_there, mate_name,
-         orderid,judge_stove_no,PRE_PROCESS,DELIVERY_STATUS,INSERT_TIME)
+         resource_type, billet_code, memo, flag,mate_name,orderid,judge_stove_no,PRE_PROCESS,DELIVERY_STATUS,INSERT_TIME)
       values
-        (seq_mes_cx.nextval, curoporder_rcl.contract_type, prod_name_cx,
-         sg_sign_cx, sg_grade_cx,
-         outer_diam_cx || '*' || wall_thickness_cx, '在产品', null,
-         curoporder_rcl.act_weight, null, '热处理',
-         curoporder_rcl.high_tech_code, curoporder_rcl.high_tech_name,
-         curoporder_rcl.high_prod_weight, curoporder_rcl.high_mate_weight,
-         curoporder_rcl.estimated_unit_price, curoporder_rcl.estimated_cost,
-         curoporder_rcl.acct_period, material_code_cx,
-         curoporder_rcl.resource_type, material_code_cx || '1', '', '0',
+        (seq_mes_cx.nextval, curoporder_jg.contract_type,
+         prod_name_cx, sg_sign_cx,
+         sg_grade_cx, outer_diam_cx || '*' || wall_thickness_cx, curoporder_jg.prod_type,
+         curoporder_jg.prod_weight, curoporder_jg.mate_weight,
+         curoporder_jg.steel_waste, curoporder_jg.process,
+         curoporder_jg.high_tech_code, curoporder_jg.high_tech_name,
+         curoporder_jg.high_prod_weight, curoporder_jg.high_mate_weight,
+         curoporder_jg.estimated_unit_price, curoporder_jg.estimated_cost,
+         curoporder_jg.acct_period, material_code_cx,
+         curoporder_jg.resource_type,
+         --(case when curOPOrder_jg.BILLET_CODE like ),
          (case
-            when material_code_cx like '%B' then
-             '加工'
-            when material_code_cx like '%C' then
+            when curoporder_jg.mate_code like '%B' then
+             curoporder_jg.mate_code || '1'
+            when curoporder_jg.mate_code like '%C' then
+             curoporder_jg.mate_code || '2'
+             when curoporder_jg.mate_code like '%G' OR curoporder_jg.mate_code like '%H' then
+             curoporder_jg.mate_code || '3'
+          end), '', '0',MATERIAL_NAME_cx,curoporder_jg.orderid,curoporder_jg.judge_stove_no,(case
+            when curoporder_jg.mate_code like '%B' then
+             '热轧'
+            when curoporder_jg.mate_code like '%C' then
              '热处理'
-            else
-             ''
-          end), MATERIAL_NAME_cx, curoporder_rcl.orderid,curoporder_rcl.judge_stove_no,'热轧',SUBSTR(MATERIAL_NAME_cx,INSTR(MATERIAL_NAME_cx, ',', 1, 1) + 1, INSTR(MATERIAL_NAME_cx, ',', 1,2) - INSTR(MATERIAL_NAME_cx, ',', 1, 1) - 1),sysdate);
+            when curoporder_jg.mate_code like '%H' OR curoporder_jg.mate_code like '%G' then
+             '加工'
+          end),SUBSTR(MATERIAL_NAME_cx,INSTR(MATERIAL_NAME_cx, ',', 1, 1) + 1, INSTR(MATERIAL_NAME_cx, ',', 1,2) - INSTR(MATERIAL_NAME_cx, ',', 1, 1) - 1),sysdate);
     else
-      insert into HOT_HEAT_PRODUCTION_MES_GX
+      insert into hot_production_mes_jg
         (cx_no, contract_type, prod_variety, steel_level, steel_no, spec,
          prod_type, prod_weight, mate_weight, steel_waste, process,
          high_tech_code, high_tech_name, high_prod_weight, high_mate_weight,
          estimated_unit_price, estimated_cost, acct_period, mate_code,
-         resource_type, billet_code, memo, flag, go_there, mate_name,
-         orderid,judge_stove_no)
+         resource_type, billet_code, memo, flag,mate_name,orderid,judge_stove_no)
       values
-        (seq_mes_cx.nextval, curoporder_rcl.contract_type,
-         null, null,
-         null, null, '在产品', null,
-         curoporder_rcl.act_weight, null, '热处理', curoporder_rcl.high_tech_code,
-         curoporder_rcl.high_tech_name, curoporder_rcl.high_prod_weight,
-         curoporder_rcl.high_mate_weight, curoporder_rcl.estimated_unit_price,
-         curoporder_rcl.estimated_cost, curoporder_rcl.acct_period, null,
-         curoporder_rcl.resource_type, null, '', '0',
-         (case when cxdata.material_code like '%B' then '加工' when
-           cxdata.material_code like '%C' then '热处理' else '' end), null,
-         curoporder_rcl.orderid,curoporder_rcl.judge_stove_no);
+        (seq_mes_cx.nextval, curoporder_jg.contract_type,
+         curoporder_jg.prod_variety, curoporder_jg.steel_level,
+         curoporder_jg.steel_no, curoporder_jg.spec, curoporder_jg.prod_type,
+         curoporder_jg.prod_weight, curoporder_jg.mate_weight,
+         curoporder_jg.steel_waste, curoporder_jg.process,
+         curoporder_jg.high_tech_code, curoporder_jg.high_tech_name,
+         curoporder_jg.high_prod_weight, curoporder_jg.high_mate_weight,
+         curoporder_jg.estimated_unit_price, curoporder_jg.estimated_cost,
+         curoporder_jg.acct_period, curoporder_jg.mate_code,
+         curoporder_jg.resource_type,
+         --(case when curOPOrder_jg.BILLET_CODE like ),
+         (case when curoporder_jg.mate_code like '%B' then
+           curoporder_jg.mate_code || '1' when
+           curoporder_jg.mate_code like '%C' then
+           curoporder_jg.mate_code || '2' end), '', '0',null,curoporder_jg.orderid,curoporder_jg.judge_stove_no);
     end if;
+
   end loop;
-  close oporder_cursor_rcl;
+  close oporder_cursor_jg;
   commit;
-
-end mes_cx_rcl_zzpnew_hand;
+end mes_cx_jg_CSJG_HAND;

+ 3 - 3
MES_FIN_MONTH/InitScript/Origin/mes_cx_rcl_zzpnew_hand.sql

@@ -23,7 +23,7 @@ CREATE OR REPLACE procedure mes_cx_rcl_zzpnew_hand is
        end) resource_type,
                t.ZY_BATCH_ID 生产批号,
                T.STOVE_NO,
-               '2026-02' acct_period,
+               '{3}' acct_period,
                null high_tech_code, null high_tech_name, 0 high_prod_weight,
        0 high_mate_weight, 0 estimated_unit_price, 0 estimated_cost,
                T.PRODUCNAME,
@@ -67,7 +67,7 @@ CREATE OR REPLACE procedure mes_cx_rcl_zzpnew_hand is
                       --AND T.INSTORE_FLAG = '0'
                    AND T.PROCESS_SEQ = '1'
                    AND T.MAT_STATUS IN ('00', '20')
-                   and t.bal_year_month <= '202602'
+                   and t.bal_year_month <= '{0}'
                    and t.bal_year_month >= '202002'
 
                  group by t.judge_stove_no, T.HEAT_PLAN_NO
@@ -84,7 +84,7 @@ CREATE OR REPLACE procedure mes_cx_rcl_zzpnew_hand is
                        T.INSTANCY_FLAG = '1')
                    and t.is_flag = 0
                    and t.PROCESS_CODE = 'F'
-                   and t.bal_year_month <= '202602'
+                   and t.bal_year_month <= '{0}'
                    and t.bal_year_month >= '202002'
 
                  group by t.judge_stove_no, T.HEAT_PLAN_NO

+ 1 - 1
MES_FIN_MONTH/InitScript/Origin/mes_cx_ydm_bc_inlist_csjg_hand.sql

@@ -74,7 +74,7 @@ CREATE OR REPLACE procedure mes_cx_ydm_bc_inlist_CSJG_hand is
            get_cp_pass(get_cp_order(t1.judge_stove_no)) pass --孔型
       from ydm_zc_inlist t1
      where instock_type_code in ('800701', '800702', '800706')--产出盘盈改判
-        and BAL_YEAR_MONTH = '{0}}'
+        and BAL_YEAR_MONTH = '{0}'
        and belong_code in ('100101', '100102', '100105')
        and supply_unit_code = '120504'
        and nvl(replace(pro_order_no, '/', ''),