Explorar o código

储存过程全上线

Signed-off-by: zhangguo <zhangguo@qq.com>
zhangguo hai 3 días
pai
achega
13f3a89548

+ 33 - 4
MES_FIN_MONTH/FinMES202602.md

@@ -8,7 +8,7 @@
   
   ```sql
     select sum(t.prod_weight),sum(t.lc_weight) from hot_production_mes_jg t where t.acct_period = '2026-02' and t.prod_type  in ('在产品');
-    delete hot_production_mes_jg t where t.acct_period = '2026-02';
+    delete hot_production_mes_jg t wheWre t.acct_period = '2026-02';
   ```
   
   - 热处理生产月报
@@ -78,17 +78,28 @@
   > [mes_cx_rz_zxnew_hand](./FinMES202602/mes_cx_rz_zxnew_hand.md)
   > 
   > [MES_CX_YDM_BC_INITIAL_hand](./FinMES202602/MES_CX_YDM_BC_INITIAL_hand.md)
+  > 
   > [mes_cx_ydm_bc_inlist_csjg_hand](./FinMES202602/mes_cx_ydm_bc_inlist_csjg_hand.md)
+  > 
   > [mes_cx_ydm_bc_inlist_new_hand](./FinMES202602/mes_cx_ydm_bc_inlist_new_hand.md)
+  > 
   > [mes_cx_ydm_bc_outlist_csjg](./FinMES202602/mes_cx_ydm_bc_outlist_csjg.md)
+  > 
   > [mes_cx_ydm_bc_outlist_new_hand](./FinMES202602/mes_cx_ydm_bc_outlist_new_hand.md)
+  > 
   > [mes_cx_ydm_zc_initialnew_hand](./FinMES202602/mes_cx_ydm_zc_initialnew_hand.md)
+  > 
   > [mes_cx_ydm_zc_inlist_new_hand](./FinMES202602/mes_cx_ydm_zc_inlist_new_hand.md)
+  > 
   > [mes_cx_ydm_zc_outlist_new_hand](./FinMES202602/mes_cx_ydm_zc_outlist_new_hand.md)
+  > 
   > [mes_cx_JG_zzpnew_hand](./FinMES202602/mes_cx_JG_zzpnew_hand.md)
-  > mes_cx_rcl_zzpnew_hand 
-  > mes_cx_rz_zzpnew_hand 
-  > mes_cx_jg_CSJG_HAND
+  > 
+  > [mes_cx_rcl_zzpnew_hand](./FinMES202602/mes_cx_rcl_zzpnew_hand.md)
+  > 
+  > [mes_cx_rz_zzpnew_hand](./FinMES202602/mes_cx_rz_zzpnew_hand.md)
+  > 
+  > [mes_cx_jg_CSJG_HAND](./FinMES202602/mes_cx_jg_CSJG_HAND.md)
 
 - 使用脚本
   
@@ -121,22 +132,40 @@
 > 成品台账不连续: TQ6400106600305A重量: 本月期初=1318.366t ≠ 计算值=1316.671t (上月期初=1448.088 + 入库=1849.375 - 出库=1980.792)    2026-02    TQ6400106600305A    2026-02-24 13:50:52    台账期初差异
 > 
 > 成品台账不连续: TQ8818312001410A重量: 本月期初=9.414t ≠ 计算值=7.754t (上月期初=38.16 + 入库=-30.406 - 出库=0)    2026-02    TQ8818312001410A    2026-02-24 13:50:52    台账期初差异
+> 
 > 成品台账不连续: TBAA18212000411C重量: 本月期初=6.616t ≠ 计算值=6.947t (上月期初=8.938 + 入库=-1.991 - 出库=0)    2026-02    TBAA18212000411C    2026-02-24 13:50:53    台账期初差异
+> 
 > 成品台账不连续: TD4610704874412C重量: 本月期初=6131.27t ≠ 计算值=6132.876t (上月期初=0 + 入库=6132.876 - 出库=0)    2026-02    TD4610704874412C    2026-02-24 13:50:56    台账期初差异
+> 
 > 成品台账不连续: TQ0218210501411B重量: 本月期初=34.002t ≠ 计算值=39.951t (上月期初=59.82 + 入库=-18.064 - 出库=1.805)    2026-02    TQ0218210501411B    2026-02-24 13:50:57    台账期初差异
 > 成品台账不连续: TB0618312201412C 支数: 本月期初=8支 ≠ 计算值=0支 (上月期初=4 + 入库=0 - 出库=4); 重量: 本月期初=.502t ≠ 计算值=0t (上月期初=14.27 + 入库=0 - 出库=14.27)    2026-02    TB0618312201412C    2026-02-24 13:51:01    台账期初差异
+> 
 > 成品台账不连续: TQ9618312007410B 支数: 本月期初=227支 ≠ 计算值=215支 (上月期初=0 + 入库=215 - 出库=0); 重量: 本月期初=360.956t ≠ 计算值=355.3t (上月期初=0 + 入库=355.3 - 出库=0)    2026-02    TQ9618312007410B    2026-02-24 13:51:01    台账期初差异
+> 
 > 成品台账不连续: TQAD18212001410B 支数: 本月期初=3支 ≠ 计算值=5支 (上月期初=19 + 入库=96 - 出库=110); 重量: 本月期初=4.73t ≠ 计算值=7.648t (上月期初=31.688 + 入库=152.857 - 出库=176.897)    2026-02    TQAD18212001410B    2026-02-24 13:51:02    台账期初差异
+> 
 > 成品台账不连续: TQAD18312001411B重量: 本月期初=203.707t ≠ 计算值=204.447t (上月期初=12.688 + 入库=1339.846 - 出库=1148.087)    2026-02    TQAD18312001411B    2026-02-24 13:51:05    台账期初差异
+> 
 > 成品台账不连续: TQ0218312001410A重量: 本月期初=6.899t ≠ 计算值=125.741t (上月期初=224.988 + 入库=-99.247 - 出库=0)    2026-02    TQ0218312001410A    2026-02-24 13:51:10    台账期初差异
+> 
 > 半成品台账不连续: TQAD18212001411B重量: 本月期初=3.618t ≠ 计算值=3.986t (上月期初=102.088 + 入库=102.996 - 出库=201.098)    2026-02    TQAD18212001411B    2026-02-24 13:51:11    台账期初差异
+> 
 > 半成品台账不连续: TQ0218312001410B 支数: 本月期初=11支 ≠ 计算值=15支 (上月期初=14 + 入库=42 - 出库=41); 重量: 本月期初=16.117t ≠ 计算值=22.281t (上月期初=20.721 + 入库=65.11 - 出库=63.55)    2026-02    TQ0218312001410B    2026-02-24 13:51:11    台账期初差异
+> 
 > 半成品台账不连续: TQAA18212001411B重量: 本月期初=13.089t ≠ 计算值=12.721t (上月期初=3.66 + 入库=21.802 - 出库=12.741)    2026-02    TQAA18212001411B    2026-02-24 13:51:11    台账期初差异
+> 
 > 成品台账物料缺失: TQ0318312007410B 上月有业务但本月无期初    2026-02    TQ0318312007410B    2026-02-24 13:51:13    台账期初差异
+> 
 > 成品台账物料缺失: TQAF18312007410B 上月有业务但本月无期初    2026-02    TQAF18312007410B    2026-02-24 13:51:13    台账期初差异
+> 
 > 物料编码(MATE_CODE)为空    2026-02        2026-02-24 13:51:13    非空字段校验
+> 
 > 物料编码(MATE_CODE)为空    2026-02        2026-02-24 13:51:13    非空字段校验
+> 
 > 物料编码(MATE_CODE)为空    2026-02        2026-02-24 13:51:13    非空字段校验
+> 
 > 物料编码(MATE_CODE)为空    2026-02        2026-02-24 13:51:13    非空字段校验
+> 
 > 热轧生产月报物料不存在于收发存:     2026-02        2026-02-24 13:51:14    物料编码存在性
+> 
 > 总问题数: 23    2026-02        2026-02-24 13:51:14    汇总结果

+ 233 - 0
MES_FIN_MONTH/FinMES202602/mes_cx_jg_CSJG_HAND.md

@@ -0,0 +1,233 @@
+# mes_cx_rcl_zzpnew_hand 存储过程(什么什么热轧)
+
+## 模板下载
+
+[模板](./mes_cx_rcl_zzpnew_hand.sql)
+
+用{0}表达 当前月份 替换成202602
+
+用{1}表达 下个月份 替换成202603
+
+用{2}表达 下个月份 替换成202601
+
+用{3}表达 当前月份 替换成2026-02
+
+## 原始脚本内容
+
+```sql
+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);
+      sg_grade_cx varchar(200);
+      sg_sign_cx varchar(200);
+      wall_thickness_cx varchar(200);
+      material_code_cx varchar(200);
+      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,
+       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;
+
+begin
+
+  --先删除
+/*  delete from HOT_HEAT_PRODUCTION_MES_GX
+   where acct_period in ('2025-01')
+     and prod_type = '在产品'
+     and flag = '0';*/
+
+  open oporder_cursor_rcl;
+  loop
+    fetch oporder_cursor_rcl
+      into curoporder_rcl;
+    exit when oporder_cursor_rcl%notfound;
+
+    select count(*)
+      into a
+      from orderdetail_v@th_cx_link t
+     where t.contractno_num = curoporder_rcl.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
+         and material_code is not null
+         and rownum = 1;
+
+    elsif substr(curoporder_rcl.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)
+         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
+          from orderdetail_v@th_cx_link t
+         where substr(t.contractno_num, 3) =
+               substr(curoporder_rcl.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
+        (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)
+      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',
+         (case
+            when material_code_cx like '%B' then
+             '加工'
+            when material_code_cx 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);
+    else
+      insert into HOT_HEAT_PRODUCTION_MES_GX
+        (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)
+      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);
+    end if;
+  end loop;
+  close oporder_cursor_rcl;
+  commit;
+
+  /*
+
+  exception
+    when others then
+      null;*/
+end mes_cx_rcl_zzpnew_hand;
+```

+ 204 - 0
MES_FIN_MONTH/FinMES202602/mes_cx_jg_CSJG_HAND.sql

@@ -0,0 +1,204 @@
+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);
+      sg_grade_cx varchar(200);
+      sg_sign_cx varchar(200);
+      wall_thickness_cx varchar(200);
+      material_code_cx varchar(200);
+      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,
+       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;
+
+begin
+
+  open oporder_cursor_rcl;
+  loop
+    fetch oporder_cursor_rcl
+      into curoporder_rcl;
+    exit when oporder_cursor_rcl%notfound;
+
+    select count(*)
+      into a
+      from orderdetail_v@th_cx_link t
+     where t.contractno_num = curoporder_rcl.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
+         and material_code is not null
+         and rownum = 1;
+
+    elsif substr(curoporder_rcl.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)
+         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
+          from orderdetail_v@th_cx_link t
+         where substr(t.contractno_num, 3) =
+               substr(curoporder_rcl.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
+        (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)
+      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',
+         (case
+            when material_code_cx like '%B' then
+             '加工'
+            when material_code_cx 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);
+    else
+      insert into HOT_HEAT_PRODUCTION_MES_GX
+        (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)
+      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);
+    end if;
+  end loop;
+  close oporder_cursor_rcl;
+  commit;
+
+end mes_cx_rcl_zzpnew_hand;

+ 233 - 0
MES_FIN_MONTH/FinMES202602/mes_cx_rcl_zzpnew_hand.md

@@ -0,0 +1,233 @@
+# mes_cx_rcl_zzpnew_hand 存储过程(什么什么热轧)
+
+## 模板下载
+
+[模板](./mes_cx_rcl_zzpnew_hand.sql)
+
+用{0}表达 当前月份 替换成202602
+
+用{1}表达 下个月份 替换成202603
+
+用{2}表达 下个月份 替换成202601
+
+用{3}表达 当前月份 替换成2026-02
+
+## 原始脚本内容
+
+```sql
+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);
+      sg_grade_cx varchar(200);
+      sg_sign_cx varchar(200);
+      wall_thickness_cx varchar(200);
+      material_code_cx varchar(200);
+      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,
+       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;
+
+begin
+
+  --先删除
+/*  delete from HOT_HEAT_PRODUCTION_MES_GX
+   where acct_period in ('2025-01')
+     and prod_type = '在产品'
+     and flag = '0';*/
+
+  open oporder_cursor_rcl;
+  loop
+    fetch oporder_cursor_rcl
+      into curoporder_rcl;
+    exit when oporder_cursor_rcl%notfound;
+
+    select count(*)
+      into a
+      from orderdetail_v@th_cx_link t
+     where t.contractno_num = curoporder_rcl.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
+         and material_code is not null
+         and rownum = 1;
+
+    elsif substr(curoporder_rcl.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)
+         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
+          from orderdetail_v@th_cx_link t
+         where substr(t.contractno_num, 3) =
+               substr(curoporder_rcl.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
+        (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)
+      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',
+         (case
+            when material_code_cx like '%B' then
+             '加工'
+            when material_code_cx 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);
+    else
+      insert into HOT_HEAT_PRODUCTION_MES_GX
+        (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)
+      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);
+    end if;
+  end loop;
+  close oporder_cursor_rcl;
+  commit;
+
+  /*
+
+  exception
+    when others then
+      null;*/
+end mes_cx_rcl_zzpnew_hand;
+```

+ 204 - 0
MES_FIN_MONTH/FinMES202602/mes_cx_rcl_zzpnew_hand.sql

@@ -0,0 +1,204 @@
+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);
+      sg_grade_cx varchar(200);
+      sg_sign_cx varchar(200);
+      wall_thickness_cx varchar(200);
+      material_code_cx varchar(200);
+      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,
+       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;
+
+begin
+
+  open oporder_cursor_rcl;
+  loop
+    fetch oporder_cursor_rcl
+      into curoporder_rcl;
+    exit when oporder_cursor_rcl%notfound;
+
+    select count(*)
+      into a
+      from orderdetail_v@th_cx_link t
+     where t.contractno_num = curoporder_rcl.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
+         and material_code is not null
+         and rownum = 1;
+
+    elsif substr(curoporder_rcl.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)
+         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
+          from orderdetail_v@th_cx_link t
+         where substr(t.contractno_num, 3) =
+               substr(curoporder_rcl.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
+        (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)
+      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',
+         (case
+            when material_code_cx like '%B' then
+             '加工'
+            when material_code_cx 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);
+    else
+      insert into HOT_HEAT_PRODUCTION_MES_GX
+        (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)
+      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);
+    end if;
+  end loop;
+  close oporder_cursor_rcl;
+  commit;
+
+end mes_cx_rcl_zzpnew_hand;

+ 399 - 290
MES_FIN_MONTH/FinMES202602/mes_cx_rz_zzpnew_hand.sql

@@ -1,310 +1,419 @@
-CREATE OR REPLACE procedure mes_cx_ydm_zc_outlist_new_hand is
+CREATE OR REPLACE procedure mes_cx_rz_zzpnew_hand is
   a      number(4);
-  b      varchar(200);
-  gxstr  varchar(200);
-    prod_name_cx varchar(200);
-  prod_code_cx varchar(200);
-      sg_grade_cx varchar(200);
-      sg_gradename_cx varchar(200);
-      sg_sign_cx varchar(200);
-      sg_signname_cx varchar(200);
-      wall_thickness_cx varchar(200);
-      material_code_cx varchar(200);
-      MATERIAL_NAME_cx varchar(200);
-      outer_diam_cx varchar(200);
+  b      varchar(4000);
+  -- 为cxdata定义显式变量而不是使用%rowtype
+  cxdata_contractno_num    varchar2(100);
+  cxdata_prod_name         varchar2(200);
+  cxdata_sg_sign           varchar2(100);
+  cxdata_sg_grade          varchar2(100);
+  cxdata_outer_diam        varchar2(50);
+  cxdata_wall_thickness    varchar2(50);
+  cxdata_material_code     varchar2(100);
+  cxdata_material_name     varchar2(500); -- 特别关注这个字段
+  cxdata orderdetail_v@th_cx_link%rowtype;
 
-  cursor oporder_cursor is
-  
-    select substr(t1.bal_year_month, 0, 4) || '-' ||
-            substr(t1.bal_year_month, 5, 2) bal_year_month,
-           --记账日期
-           '天淮成品库' ckmc, t1.judge_stove_no,
-           --库存地名称,
-           spec_code,
-           --产品规格代码,
-           spec_name,
-           -- 产品规格描述,
-           max(std_code) std_code,
-           --执行标准代码,
-           max(std_name) std_name,
-           --执行标准名称,
-           produccode,
-           --品名代码,
-           producname,
-           --品名描述,
-           gradecode,
-           --钢种代码,
-           gradename,
-           --钢种名称,
-           steelcode,
-           --钢级代码,
-           steelname,
-           --钢级名称,
-           0 act_count,
-           --期初库存支数,
-           0 act_weight,
-           --期初库存重量,
-           0 act_in_count,
-           --本期入库支数,
-           0 act_in_weight,
-           --本期入库重量,
-           sum(act_count) act_out_count,
-           --本期出库支数,
-           sum(nvl(PONDER_GROSS_WT,act_weight)) act_out_weight,
-           (select nvl(sum(act_weight), 0)
-                from ydm_zc_stocktakinglist t
-               where t.judge_stove_no = t1.judge_stove_no
-                 and t.stocktaking_type_code = '800603'
-                 and t.bal_year_month = '{0}') lc,
-           --本期出库重量,
-           getislljg(t1.judge_stove_no,
-                      nvl(replace(pro_order_no, '/', ''),
-                          replace(get_cp_order(t1.judge_stove_no), '/', ''))) is_lljg,
-           --是否来料加工,
-           case max(PLINE_CODE) when 'C108' then '车丝' else
-           (case process_desc
-              when '轧制' then
-               '热轧'
-              when '加工线' then
-               '加工'
-              else
-               process_desc
-            end) end as process_name,
-           --工序,
-           
-          -- '否' is_ckc,
-           --是否出口材
-          (case
-           when nvl(mvm.if_export,'内贸') ='内贸' then
-            '否'
-           when nvl(mvm.if_export,'内贸') ='外贸' then
-            '是'
-           else
-            '否'
-           end) is_ckc,
-           
-           act_dimater dimater,
-           --外径
-           act_height height,
-           --壁厚
-           nvl(replace(pro_order_no, '/', ''),
-                replace(get_cp_order(t1.judge_stove_no), '/', '')) orderid,
-           --合同号
-           model_desc,
-           -- 扣型描述
-           outstock_type_name,
-           --入库类型名称
-           get_cp_buyer(get_cp_order(t1.judge_stove_no)) buyer,
-           --客户名称
-           get_cp_pass(get_cp_order(t1.judge_stove_no)) pass --孔型
-           
-      from ydm_zc_outlist t1,mvm_order_matno_info mvm--增加MVN
-     where nvl(replace(pro_order_no, '/', ''),
-                replace(get_cp_order(t1.judge_stove_no), '/', '')) =
-           mvm.CONTRACTNO_NUM
-           
-       and outstock_type_code in
-          -- ('800805', '800804', '800802', '800808', '800806','800812')
-           ('800805', '800804', '800802', '800808', '800806')
-       and belong_code in ('100101', '100102', '100105')
-       and supply_unit_code = '120504'
-       and t1.bal_year_month in ('{0}')
-       and t1.order_no || '/' || t1.order_seq not in
-           ('XSXGQ-25A0432/001',
-            'XSXGQ-25A0975/001',
-            'XSXGQ-25A0975/002',
-            'XSXKQ-25A0174/007',
-            'XSXKQ-25A0174/008',
-            'XSXKQ-25A0795/001')
-       and nvl(replace(pro_order_no, '/', ''),
-               replace(get_cp_order(t1.judge_stove_no), '/', '')) not like
-           'ZZBY%'
-       --and t1.judge_stove_no  like 'F%'
-     group by bal_year_month, spec_code,
-              --产品规格代码,
-              produccode,
-              --品名代码,
-              producname, gradecode,
-              --钢种代码,
-              gradename, steelcode,
-              --钢级代码,
-              steelname, judge_stove_no, process_desc, act_dimater,
-              --外径
-              act_height,
-              --壁厚
-              model_desc, t1.pro_order_no,-- t1.order_no, t1.order_seq,
-              spec_code, spec_name, batch_no,mvm.if_export,outstock_type_name;
+  --加工
+  cursor oporder_cursor_jg is
 
-  curoporder oporder_cursor%rowtype;
+ SELECT J.*,REPLACE(GET_CP_ORDER(J.Judge_Stove_No), '/', '') ORDERID,(select decode(max(s.order_typ),
+                            '120108',
+                            '双经销',
+                            '120109',
+                            '定销订购',
+                            '120107',
+                            '来料加工',
+                            '自用')
+               from cxuser.slm_order_head s
+              where s.order_no = regexp_replace(REPLACE(GET_CP_ORDER(J.Judge_Stove_No), '/', ''), '/.*', '')) contract_type,(case
+             when j.judge_stove_no like 'W%' then
+              '是'
+             else
+              '否'
+           end) resource_type,null high_tech_code, null high_tech_name,
+           0 high_prod_weight, 0 high_mate_weight, 0 estimated_unit_price,
+           0 estimated_cost, '{3}' acct_period,
+           get_pl_code((select max(GRADENAME) from PLN_ZY_ZG_m p where p.FEED_HEAT_NO = j.judge_stove_no),
+                    (select max(DIAMETER) from PLN_ZY_ZG_m p where p.FEED_HEAT_NO = j.judge_stove_no) --规格
+                    ) billet_code
+  FROM (select aa.JUDGE_STOVE_NO,
+               aa.PLINE_NAME,
+               sum(aa.act_COUNT) act_COUNT,
+               sum(aa.WEIGHT) WEIGHT
+          from ( --期初
+                SELECT T.JUDGE_STOVE_NO,
+                        T.PLINE_NAME,
+                        SUM(NVL(T.ACT_COUNT, 0)) act_COUNT,
+                        SUM(NVL(T.ACT_WEIGHT, 0)) WEIGHT
+                  FROM YDM_ZC_INITIAL_ZG T
+                 WHERE 1 = 1
+                   AND t.bal_year_month = '{0}'
+                 group by t.JUDGE_STOVE_NO, t.PLINE_NAME
+                UNION ALL
+                --入库
+                select t.JUDGE_STOVE_NO,
+                        t.PLINE_NAME,
+                        nvl((case
+                              when t.BAL_YEAR_MONTH = '{0}' then
+                               nvl(t.count, 0)
+                            end),
+                            0) act_COUNT,
+                        nvl((case
+                              when t.BAL_YEAR_MONTH = '{0}' then
+                               nvl(t.weight, 0)
+                            end),
+                            0) WEIGHT
+                  from (SELECT REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
+                                (CEIL(T.ACT_COUNT / S.SAW_NUM)) AS count,
+                                t.weight,
+                                t.BAL_YEAR_MONTH,
+                                t.PLINE_NAME
+                           FROM (SELECT T1.JUDGE_STOVE_NO,
+                                        T1.BAL_YEAR_MONTH,
+                                        (SELECT C.PLINE_NAME
+                                           FROM COM_BASE_PLINE C
+                                          WHERE C.PLINE_CODE = T1.PLINE_CODE) PLINE_NAME,
+                                        SUM(T1.ACT_COUNT) ACT_COUNT,
+                                        SUM(T1.INPUT_WEIGHT) weight
+                                   FROM PORT_MIL_BATCH_SAMPLE_RESULT T1
+                                  WHERE T1.JUDGE_STOVE_NO =
+                                        REGEXP_REPLACE(T1.JUDGE_STOVE_NO,
+                                                       '-.*',
+                                                       '') || '-01'
+                                    AND T1.BAL_YEAR_MONTH = '{0}'
+
+                                  GROUP BY T1.JUDGE_STOVE_NO,
+                                           T1.BAL_YEAR_MONTH,
+                                           T1.PLINE_CODE) T,
+                                MIL_PLAN S
+                          WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
+                            AND S.BACK_PLAN_FLAG = '0'
+                            AND S.BACK_SLAB_FLAG = '0') t
+
+                union all
+
+                --出库
+                select t.JUDGE_STOVE_NO,
+                        t.PLINE_NAME,
+                        -nvl((case
+                               when t.BAL_YEAR_MONTH = '{0}' then
+                                nvl(t.count, 0)
+                             end),
+                             0) act_COUNT,
+                        -nvl((case
+                               when t.BAL_YEAR_MONTH = '{0}' then
+                                nvl(t.weight, 0)
+                             end),
+                             0) WEIGHT
+
+                  from (SELECT JUDGE_STOVE_NO,
+                                BAL_YEAR_MONTH,
+                                PLINE_NAME,
+                                SUM(COUNT) COUNT,
+                                SUM(WEIGHT) WEIGHT
+                           FROM (SELECT T1.JUDGE_STOVE_NO,
+                                        T1.BAL_YEAR_MONTH,
+                                        (SELECT C.PLINE_NAME
+                                           FROM COM_BASE_PLINE C
+                                          WHERE C.PLINE_CODE = T1.PLINE_CODE) PLINE_NAME,
+                                        SUM(T1.OUTPUT_COUNT) AS COUNT,
+                                        SUM(T1.OUTPUT_WEIGHT) AS WEIGHT
+                                   FROM QCM_ZG_JUGDE_APPLY T1, MIL_PLAN S5
+                                  WHERE T1.JUDGE_STOVE_NO || '-01' =
+                                        S5.JUDGE_STOVE_NO
+                                    AND S5.BACK_PLAN_FLAG = '0'
+                                    AND S5.BACK_SLAB_FLAG = '0'
+                                    AND T1.PROCESS_CODE = 'D'
+                                    AND T1.BAL_YEAR_MONTH = '{0}'
+                                    AND ((T1.VALIDFLAG = '20' AND
+                                        T1.TARGET <> 'A' AND
+                                        T1.JUDGE_RESULT_CODE IN
+                                        ('40740701', '40740705', '40740709')) OR
+                                        (T1.VALIDFLAG = '20' AND T1.TARGET = 'A' AND
+                                        T1.JUDGE_TOLRESULT_CODE IN
+                                        ('40740701', '40740705', '40740709')) OR
+                                        (T1.VALIDFLAG = '20' AND T1.TARGET = 'A' AND
+                                        T1.IS_ALL_SCRAP = '1') OR
+                                        T1.INSTANCY_FLAG = '1')
+                                    AND T1.PLINE_CODE NOT IN ('C065', 'C066')
+
+                                  GROUP BY T1.JUDGE_STOVE_NO,
+                                           T1.BAL_YEAR_MONTH,
+                                           T1.PLINE_CODE
+                                 UNION ALL
+                                 SELECT REGEXP_REPLACE(F.JUDGE_STOVE_NO,
+                                                       '-.*',
+                                                       '') JUDGE_STOVE_NO,
+                                        F.BAL_YEAR_MONTH,
+                                        S1.PLINE_NAME,
+                                        COUNT(1) COUNT,
+                                        SUM(S1.INPUT_WEIGHT) WEIGHT
+                                   FROM (SELECT COUNT(1) ACOUNT,
+                                                T3.JUDGE_STOVE_NO,
+                                                T3.NEW_HEAT_NO,
+                                                T3.BAL_YEAR_MONTH
+                                           FROM (SELECT G2.*, T1.BAL_YEAR_MONTH
+                                                   FROM MIL_SLAB_SCRAP     G2,
+                                                        QCM_ZG_JUGDE_APPLY T1
+                                                  WHERE REGEXP_REPLACE(G2.NEW_HEAT_NO,
+                                                                       '-.*',
+                                                                       '') =
+                                                        T1.JUDGE_STOVE_NO
+                                                    AND (G2.REMARK <> '无' OR
+                                                         G2.REMARK IS NULL)
+                                                    AND ((t1.validflag = '20' and
+                                                         t1.JUDGE_RESULT_CODE in
+                                                         ('40740701',
+                                                           '40740705',
+                                                           '40740709')) OR
+                                                         T1.INSTANCY_FLAG = '1')
+                                                    AND T1.IS_FLAG = '0'
+                                                    AND T1.PROCESS_CODE = 'D'
+                                                    AND T1.BAL_YEAR_MONTH =
+                                                        '{0}'
+                                                ) T3
+                                          WHERE T3.PROCESS_NO <= 6
+                                            AND T3.NEW_HEAT_NO IS NOT NULL
+                                          GROUP BY T3.JUDGE_STOVE_NO,
+                                                   T3.NEW_HEAT_NO,
+                                                   T3.BAL_YEAR_MONTH) F,
+                                        (SELECT SUM(S.INPUT_WEIGHT) INPUT_WEIGHT,
+                                                S.JUDGE_STOVE_NO,
+                                                S.M_MAT_NO,
+                                                (SELECT C.PLINE_NAME
+                                                   FROM COM_BASE_PLINE C
+                                                  WHERE C.PLINE_CODE = S.PLINE_CODE) PLINE_NAME,
+                                                ROW_NUMBER() OVER(PARTITION BY JUDGE_STOVE_NO ORDER BY JUDGE_STOVE_NO) RNUM
+                                           FROM PORT_MIL_BATCH_SAMPLE_RESULT S
+                                          WHERE
+
+                                          S.TR_FLAG = '0'
+                                          GROUP BY S.M_MAT_NO,
+                                                   S.JUDGE_STOVE_NO,
+                                                   S.PLINE_CODE) S1
+                                  WHERE F.JUDGE_STOVE_NO = S1.JUDGE_STOVE_NO
+                                    AND RNUM <= F.ACOUNT
+                                  GROUP BY F.JUDGE_STOVE_NO,
+                                           F.BAL_YEAR_MONTH,
+                                           S1.PLINE_NAME
+                                 UNION ALL
+                                 SELECT REGEXP_REPLACE(S.JUDGE_STOVE_NO,
+                                                       '-.*',
+                                                       '') JUDGE_STOVE_NO,
+                                        T.BAL_YEAR_MONTH,
+                                        S.PLINE_NAME,
+                                        COUNT(1) COUNT,
+                                        SUM(S.INPUT_WEIGHT) WEIGHT
+                                   FROM (SELECT G1.*, T1.BAL_YEAR_MONTH
+                                           FROM MIL_FURNACES_RESLUT_DETIA G1,
+                                                QCM_ZG_JUGDE_APPLY        T1
+                                          WHERE REGEXP_REPLACE(G1.ZP_JUDGE_STOVE_NO,
+                                                               '-.*',
+                                                               '') =
+                                                T1.JUDGE_STOVE_NO
+                                            AND (G1.REMARK <> '无' OR
+                                                 G1.REMARK IS NULL)
+                                            AND ((t1.validflag = '20' and
+                                                 t1.JUDGE_RESULT_CODE in
+                                                 ('40740701',
+                                                   '40740705',
+                                                   '40740709')) OR
+                                                 T1.INSTANCY_FLAG = '1')
+                                            AND T1.IS_FLAG = '0'
+                                            AND T1.PROCESS_CODE = 'D'
+                                            AND T1.BAL_YEAR_MONTH = '{0}'
+                                         ) T,
+                                        (SELECT SUM(S1.INPUT_WEIGHT) INPUT_WEIGHT,
+                                                S1.M_MAT_NO,
+                                                S1.JUDGE_STOVE_NO,
+                                                (SELECT C.PLINE_NAME
+                                                   FROM COM_BASE_PLINE C
+                                                  WHERE C.PLINE_CODE =
+                                                        S1.PLINE_CODE) PLINE_NAME,
+                                                ROW_NUMBER() OVER(PARTITION BY JUDGE_STOVE_NO ORDER BY JUDGE_STOVE_NO) RNUM
+                                           FROM PORT_MIL_BATCH_SAMPLE_RESULT S1
+                                          WHERE
+                                          S1.TR_FLAG = '0'
+                                          GROUP BY S1.JUDGE_STOVE_NO,
+                                                   S1.M_MAT_NO,
+                                                   S1.PLINE_CODE) S
+                                  WHERE T.JUDGE_STOVE_NO = S.JUDGE_STOVE_NO
+                                    AND RNUM <= T.GROUP_NUM
+                                  GROUP BY S.JUDGE_STOVE_NO,
+                                           S.PLINE_NAME,
+                                           T.BAL_YEAR_MONTH
+                                 UNION ALL
+                                 SELECT REGEXP_REPLACE(T8.JUDGE_STOVE_NO,
+                                                       '-.*',
+                                                       '') JUDGE_STOVE_NO,
+                                        T7.BAL_YEAR_MONTH,
+                                        T8.PLINE_NAME,
+                                        COUNT(1) COUNT,
+                                        SUM(INPUT_WEIGHT) WEIGHT
+                                   FROM (SELECT T.OLD_ZP_JUDGE_STOVE_NO,
+                                                CEIL(SUM(T.ZP_COUNT) / S.SAW_NUM) AS RN,
+                                                T1.BAL_YEAR_MONTH
+                                           FROM MIL_OFFLINE_GROUP  T,
+                                                MIL_PLAN           S,
+                                                QCM_ZG_JUGDE_APPLY T1
+                                          WHERE T.Old_Zp_Judge_Stove_No =
+                                                S.JUDGE_STOVE_NO
+                                            AND (T.REMARK <> '无' OR
+                                                T.REMARK IS NULL)
+                                            AND S.BACK_SLAB_FLAG <> '2'
+                                            AND REGEXP_REPLACE(T.ZP_JUDGE_STOVE_NO,
+                                                               '-.*',
+                                                               '') =
+                                                T1.Judge_Stove_No
+                                            AND ((t1.validflag = '20' and
+                                                t1.JUDGE_RESULT_CODE in
+                                                ('40740701',
+                                                   '40740705',
+                                                   '40740709')) OR
+                                                T1.INSTANCY_FLAG = '1')
+                                            AND T1.IS_FLAG = '0'
+                                            AND T1.PROCESS_CODE = 'D'
+                                            AND T1.BAL_YEAR_MONTH = '{0}'
+
+                                          GROUP BY T.OLD_ZP_JUDGE_STOVE_NO,
+                                                   S.SAW_NUM,
+                                                   T1.BAL_YEAR_MONTH) T7,
+                                        (SELECT SUM(S2.INPUT_WEIGHT) INPUT_WEIGHT,
+                                                S2.JUDGE_STOVE_NO,
+                                                S2.M_MAT_NO,
+                                                (SELECT C.PLINE_NAME
+                                                   FROM COM_BASE_PLINE C
+                                                  WHERE C.PLINE_CODE =
+                                                        S2.PLINE_CODE) PLINE_NAME,
+                                                ROW_NUMBER() OVER(PARTITION BY JUDGE_STOVE_NO ORDER BY JUDGE_STOVE_NO) RNUM
+                                           FROM PORT_MIL_BATCH_SAMPLE_RESULT S2
+                                          WHERE
+                                          S2.TR_FLAG = '0'
+                                          GROUP BY S2.M_MAT_NO,
+                                                   S2.JUDGE_STOVE_NO,
+                                                   S2.PLINE_CODE) T8
+                                  WHERE REGEXP_REPLACE(T7.OLD_ZP_JUDGE_STOVE_NO,
+                                                       '-.*',
+                                                       '') || '-01' =
+                                        T8.JUDGE_STOVE_NO
+                                    AND RNUM <= RN
+                                  GROUP BY T8.JUDGE_STOVE_NO,
+                                           T7.BAL_YEAR_MONTH,
+                                           T8.PLINE_NAME)
+                          GROUP BY JUDGE_STOVE_NO, BAL_YEAR_MONTH, PLINE_NAME) t) aa
+         group by aa.JUDGE_STOVE_NO, aa.PLINE_NAME) J
+ WHERE act_COUNT > 0;
+
+  curoporder_jg oporder_cursor_jg%rowtype;
 
 begin
 
-  open oporder_cursor;
+  open oporder_cursor_jg;
   loop
-    fetch oporder_cursor
-      into curoporder;
-    exit when oporder_cursor%notfound;
-    --获取期初或入库的工序
-    select count(*)
-      into a
-      from cxuser.ydm_zc_initial t
-     where t.judge_stove_no = curoporder.judge_stove_no
-       and bal_year_month = replace(curoporder.bal_year_month, '-', '');
-    if a > 0 then
-      select (case PLINE_CODE when 'C108' then '车丝' else
-           (case process_desc
-              when '轧制' then
-               '热轧'
-              when '加工线' then
-               '加工'
-              else
-               process_desc
-            end) end)
-        into gxstr
-        from cxuser.ydm_zc_initial t
-       where t.judge_stove_no = curoporder.judge_stove_no
-         and bal_year_month = replace(curoporder.bal_year_month, '-', '')
-         and rownum = 1;
-    else
+    fetch oporder_cursor_jg into curoporder_jg;
+    exit when oporder_cursor_jg%notfound;
+
+    begin  -- 添加内部begin块用于异常处理
       select count(*)
         into a
-        from cxuser.ydm_zc_inlist t
-       where t.judge_stove_no = curoporder.judge_stove_no
-         and bal_year_month = replace(curoporder.bal_year_month, '-', '');
+        from orderdetail_v@th_cx_link t
+       where t.contractno_num = curoporder_jg.orderid
+         and material_code is not null;
+
       if a > 0 then
-        select (case PLINE_CODE when 'C108' then '车丝' else
-           (case process_desc
-              when '轧制' then
-               '热轧'
-              when '加工线' then
-               '加工'
-              else
-               process_desc
-            end) end)
-          into gxstr
-          from cxuser.ydm_zc_inlist t
-         where t.judge_stove_no = curoporder.judge_stove_no
-           and bal_year_month = replace(curoporder.bal_year_month, '-', '')
+        -- 使用显式字段选择而不是select *
+        select contractno_num, prod_name, sg_sign, sg_grade, 
+               outer_diam, wall_thickness, material_code, material_name
+          into cxdata_contractno_num, cxdata_prod_name, cxdata_sg_sign, 
+               cxdata_sg_grade, cxdata_outer_diam, cxdata_wall_thickness,
+               cxdata_material_code, cxdata_material_name
+          from orderdetail_v@th_cx_link t
+         where t.contractno_num = curoporder_jg.orderid
+           and material_code is not null
            and rownum = 1;
-      else
-        gxstr := curoporder.process_name;
-      end if;
-    end if;
-  
-    select count(*)
-      into a
-      from mvm_order_matno_info t
-     where t.contractno_num = curoporder.orderid
-       and material_code is not null;
-  
-    if a > 0 then
-      select outer_diam,prod_code,prod_name,SG_GRADE_CODE,sg_grade,SG_SIGN_CODE,sg_sign,wall_thickness,material_code,MATERIAL_NAME
-        into outer_diam_cx,prod_code_cx,prod_name_cx,sg_grade_cx,sg_gradename_cx ,sg_sign_cx,sg_signname_cx ,wall_thickness_cx ,material_code_cx , MATERIAL_NAME_cx 
-        from mvm_order_matno_info t
-       where t.contractno_num = curoporder.orderid
-         and material_code is not null
-         and rownum = 1;
-    
-    elsif substr(curoporder.orderid, 1, 2) in ('TH', 'XS','EX') then
-      select count(*)
-        into a
-        from mvm_order_matno_info t
-       where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
-         and material_code is not null
-         and rownum = 1;
-      if a > 0 then
-        select outer_diam,prod_code,prod_name,SG_GRADE_CODE,sg_grade,SG_SIGN_CODE,sg_sign,wall_thickness,material_code,MATERIAL_NAME
-        into outer_diam_cx,prod_code_cx,prod_name_cx,sg_grade_cx,sg_gradename_cx ,sg_sign_cx,sg_signname_cx ,wall_thickness_cx ,material_code_cx , MATERIAL_NAME_cx 
-        from mvm_order_matno_info t
-         where substr(t.contractno_num, 3) = substr(curoporder.orderid, 3)
+
+      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_jg.orderid, 3)
            and material_code is not null
            and rownum = 1;
+        if a > 0 then
+          select contractno_num, prod_name, sg_sign, sg_grade, 
+                 outer_diam, wall_thickness, material_code, material_name
+            into cxdata_contractno_num, cxdata_prod_name, cxdata_sg_sign, 
+                 cxdata_sg_grade, cxdata_outer_diam, cxdata_wall_thickness,
+                 cxdata_material_code, cxdata_material_name
+            from orderdetail_v@th_cx_link t
+           where substr(t.contractno_num, 3) = substr(curoporder_jg.orderid, 3)
+             and material_code is not null
+             and rownum = 1;
+        end if;
       end if;
-    end if;
-  
-    if a > 0 then
-      -- 检查是否已存在相同judge_stove_no且differential不为空的记录
-    declare
-        v_count number;
-    begin
-        select count(*)
-        into v_count
-        from cx_ydm_zc_outlist t
-        where judge_stove_no = curoporder.judge_stove_no
-          and differential <> 0
-          and bal_year_month = curoporder.bal_year_month;
-        if v_count > 0 then
-            insert into cx_ydm_zc_outlist
-                (bal_year_month, ckmc, material_no, material_name, spec_code,
-                 spec_name, std_code, std_name, produccode, producname, gradecode,
-                 gradename, steelcode, steelname, act_count, act_weight,
-                 act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
-                 process_name, is_ckc, dimater, height, pass, model_desc, buyer,
-                 orderid, bc_type, judge_stove_no,INSERT_TIME,DIFFERENTIAL,bak1)
-              values
-                (curoporder.bal_year_month, curoporder.ckmc, material_code_cx,
-                 MATERIAL_NAME_cx, curoporder.spec_code,
-                 outer_diam_cx || '*' || wall_thickness_cx,
-                 curoporder.std_code, curoporder.std_name, prod_code_cx,
-                 prod_name_cx, sg_grade_cx, sg_gradename_cx,
-                 sg_sign_cx, sg_signname_cx, curoporder.act_count,
-                 curoporder.act_weight, curoporder.act_in_count,
-                 curoporder.act_in_weight, curoporder.act_out_count,
-                 curoporder.act_out_weight, curoporder.is_lljg, gxstr,
-                 curoporder.is_ckc, curoporder.dimater, curoporder.height,
-                 curoporder.pass, curoporder.model_desc, curoporder.buyer,
-                 curoporder.orderid, '成品出库', curoporder.judge_stove_no,sysdate,curoporder.lc,curoporder.outstock_type_name);
+      
+      if INSTR(curoporder_jg.orderid, 'ZZBY') <= 0 then
+        if a > 0 then
+          insert into hot_production_mes_rz
+            (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)
+          values
+            (seq_mes_cx.nextval, curoporder_jg.contract_type, cxdata_prod_name,
+             cxdata_sg_sign, cxdata_sg_grade, 
+             cxdata_outer_diam || '*' || cxdata_wall_thickness, '在产品', null,
+             curoporder_jg.WEIGHT, null, '热轧',
+             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, cxdata_material_code,
+             curoporder_jg.resource_type, curoporder_jg.billet_code, '', '0',
+             (case
+                when cxdata_material_code like '%B' then '加工'
+                when cxdata_material_code like '%C' then '热处理'
+                else ''
+              end), cxdata_material_name, curoporder_jg.orderid, 
+             curoporder_jg.judge_stove_no, null,
+             SUBSTR(cxdata_material_name, 
+                    INSTR(cxdata_material_name, ',', 1, 1) + 1, 
+                    INSTR(cxdata_material_name, ',', 1, 2) - INSTR(cxdata_material_name, ',', 1, 1) - 1),
+             sysdate);
         else
-            insert into cx_ydm_zc_outlist
-                (bal_year_month, ckmc, material_no, material_name, spec_code,
-                 spec_name, std_code, std_name, produccode, producname, gradecode,
-                 gradename, steelcode, steelname, act_count, act_weight,
-                 act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
-                 process_name, is_ckc, dimater, height, pass, model_desc, buyer,
-                 orderid, bc_type, judge_stove_no,INSERT_TIME,DIFFERENTIAL,bak1)
-              values
-                (curoporder.bal_year_month, curoporder.ckmc, material_code_cx,
-                 MATERIAL_NAME_cx, curoporder.spec_code,
-                 outer_diam_cx || '*' || wall_thickness_cx,
-                 curoporder.std_code, curoporder.std_name, prod_code_cx,
-                 prod_name_cx, sg_grade_cx, sg_gradename_cx,
-                 sg_sign_cx, sg_signname_cx, curoporder.act_count,
-                 curoporder.act_weight, curoporder.act_in_count,
-                 curoporder.act_in_weight, curoporder.act_out_count,
-                 curoporder.act_out_weight, curoporder.is_lljg, gxstr,
-                 curoporder.is_ckc, curoporder.dimater, curoporder.height,
-                 curoporder.pass, curoporder.model_desc, curoporder.buyer,
-                 curoporder.orderid, '成品出库', curoporder.judge_stove_no,sysdate,curoporder.lc,curoporder.outstock_type_name);
+          -- 处理没有找到数据的情况
+          insert into HOT_PRODUCTION_MES_RZ
+            (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)
+          values
+            (seq_mes_cx.nextval, curoporder_jg.contract_type,
+             null, null, null, null, '在产品', null,
+             curoporder_jg.WEIGHT, null, '热轧', 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, null,
+             curoporder_jg.resource_type, curoporder_jg.billet_code, '', '0',
+             null, null, curoporder_jg.orderid, curoporder_jg.judge_stove_no);
         end if;
+      end if;
+      
+    exception
+      when value_error then  -- 处理值错误
+        -- 记录错误信息,但继续处理下一条记录
+        dbms_output.put_line('数据截断错误 for orderid: ' || curoporder_jg.orderid);
+        continue;
+      when others then
+        -- 处理其他异常
+        dbms_output.put_line('其他错误 for orderid: ' || curoporder_jg.orderid || ' - ' || sqlerrm);
+        continue;
     end;
-    else
-      insert into cx_ydm_zc_outlist
-        (bal_year_month, ckmc, material_no, material_name, spec_code,
-         spec_name, std_code, std_name, produccode, producname, gradecode,
-         gradename, steelcode, steelname, act_count, act_weight,
-         act_in_count, act_in_weight, act_out_count, act_out_weight, is_lljg,
-         process_name, is_ckc, dimater, height, pass, model_desc, buyer,
-         orderid, bc_type, judge_stove_no,DIFFERENTIAL,bak1)
-      values
-        (curoporder.bal_year_month, curoporder.ckmc, null, null,
-         curoporder.spec_code, null, curoporder.std_code,
-         curoporder.std_name, null, null, null, null, null, null,
-         curoporder.act_count, curoporder.act_weight,
-         curoporder.act_in_count, curoporder.act_in_weight,
-         curoporder.act_out_count, curoporder.act_out_weight,
-         curoporder.is_lljg, gxstr, curoporder.is_ckc, curoporder.dimater,
-         curoporder.height, curoporder.pass, curoporder.model_desc,
-         curoporder.buyer, curoporder.orderid, '成品出库',
-         curoporder.judge_stove_no,curoporder.lc,curoporder.outstock_type_name);
-    end if;
-  
+    
   end loop;
-  close oporder_cursor;
+  close oporder_cursor_jg;
   commit;
 
-  /*
-  
-  exception
-    when others then
-      null;*/
-end mes_cx_ydm_zc_outlist_new_hand;
+end mes_cx_rz_zzpnew_hand;

+ 3 - 3
README.md

@@ -4,7 +4,7 @@
 
 | 版本号  | 变更日期       | 变更内容                   | 变更人 |
 | ---- | ---------- | ---------------------- | --- |
-| v1.6 | 2026-03-11 | 增加第三课的视频解读             | 薛渗  |
+| v1.6 | 2026-03-12 | 增加第三课的视频解读             | 薛渗  |
 | v1.5 | 2026-03-11 | 增加第二课的视频解读             | 张果  |
 | v1.4 | 2026-03-11 | 增加财务月结栏目,添加FinMES.md链接 | 张果  |
 | v1.3 | 2026-03-10 | 在相关软件栏目添加软件表格          | 张果  |
@@ -56,9 +56,9 @@ MES生产部月结
     
       [环境部分视频解读](./video/Lession3/cailiao.md)
     
-      [分料视频解读](./video/Lession3/cailiao.md)
+      [分料视频解读](./video/Lession3/fenliao.md)
   
-  - 教学记录
+  - **教学记录**
     
       [教学历史](./video/培训记录.xlsx)
 

+ 0 - 2
video/Lession3/cailiao.md

@@ -87,5 +87,3 @@
   - 在"General"选项卡中设置Git.exe路径
   - 在"Credential"选项卡中设置凭证存储方式
   - 在"Git"选项卡中设置用户名和邮箱
-
-# 

+ 2 - 4
video/Lession3/fenliao.md

@@ -15,9 +15,9 @@
 有的数据的 库存挂料剩余支 字段 大于 装炉支-上料支 的值,需要将其调整到 库存挂料剩余支小于装炉支-上料支的数据,如图里的106、108和109行需要调整到107行
 
 - **处理方法**
-  
+
 > 将106、108和109行的 炉计划ID和判定单号 改成107行的(如下图的炉计划ID是一样的,所以只改判定单号,如果是炉计划ID不一样的需要炉计划ID和判定单号都该)
-  
+
   ![](./images/Snipaste_2026-03-12_19-07-40.png) 
 
 ```sql
@@ -35,8 +35,6 @@ and jugde_apply_code  ='C0728014012026011900015123'
 > 
 > judge_stove_no-判定炉号
 
-
-
 **查询出要改的数据**
 
 ```sql