mes_cx_rcl_zzpnew_hand.sql 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. CREATE OR REPLACE procedure mes_cx_rcl_zzpnew_hand is
  2. a number(4);
  3. b varchar(200);
  4. cxdata orderdetail_v@th_cx_link%rowtype;
  5. prod_name_cx varchar(200);
  6. sg_grade_cx varchar(200);
  7. sg_sign_cx varchar(200);
  8. wall_thickness_cx varchar(200);
  9. material_code_cx varchar(200);
  10. MATERIAL_NAME_cx varchar(200);
  11. outer_diam_cx varchar(200);
  12. --热处理
  13. cursor oporder_cursor_rcl is
  14. SELECT *
  15. FROM (select t.judge_stove_no,
  16. (case
  17. when t.judge_stove_no like 'W%' then
  18. '是'
  19. else
  20. '否'
  21. end) resource_type,
  22. t.ZY_BATCH_ID 生产批号,
  23. T.STOVE_NO,
  24. '2026-02' acct_period,
  25. null high_tech_code, null high_tech_name, 0 high_prod_weight,
  26. 0 high_mate_weight, 0 estimated_unit_price, 0 estimated_cost,
  27. T.PRODUCNAME,
  28. t.gradename steel_no,
  29. T.DECISION,
  30. T.OUTDIAMETER || '*' || T.WALLTHICK spec,
  31. T.ORDER_NO || T.ORDER_SEQ orderid,
  32. (SELECT DECODE(MAX(S.ORDER_TYP),
  33. '120108',
  34. '双经销',
  35. '120109',
  36. '定销订购',
  37. '120107',
  38. '来料加工',
  39. '自用')
  40. FROM SLM_ORDER_HEAD S
  41. WHERE S.ORDER_NO = REGEXP_REPLACE(T.ORDER_NO, '/.*', '')) contract_type,
  42. MAX(T.STD_STYLE_DESC) 标准类别,
  43. MAX(T.GOWHERE_NAME) 物流去向,
  44. MAX(T.OUTPUT_STANDARD) 输出标准,
  45. MAX(T.STEELNAME) steel_level,
  46. MAX(T.MODEL_DESC) 扣型,
  47. T.PLINE_CODE,
  48. (SELECT C.PLINE_NAME
  49. FROM COM_BASE_PLINE C
  50. WHERE C.PLINE_CODE = T.PLINE_CODE) PLINE_NAME,
  51. sum(a.act_count) act_count,
  52. sum(a.act_weight) act_weight,
  53. null billet_code
  54. from PLN_ZY_RCL_M t,
  55. (select t.judge_stove_no,
  56. T.HEAT_PLAN_NO,
  57. sum(t.act_count) act_count,
  58. sum(decode(T.act_weight,
  59. '',
  60. t.act_theory_weight,
  61. t.act_weight)) act_weight
  62. from PORT_HTT_BATCH_SAMPLE_RESULT t
  63. where (t.group_flag = 0 OR T.GROUP_FLAG IS NULL)
  64. --AND T.INSTORE_FLAG = '0'
  65. AND T.PROCESS_SEQ = '1'
  66. AND T.MAT_STATUS IN ('00', '20')
  67. and t.bal_year_month <= '202602'
  68. and t.bal_year_month >= '202002'
  69. group by t.judge_stove_no, T.HEAT_PLAN_NO
  70. UNION ALL
  71. select t.judge_stove_no,
  72. T.HEAT_PLAN_NO,
  73. -SUM(T.ACT_COUNT) act_count,
  74. -sum(t.ACT_WEIGHT) act_weight
  75. from QCM_ZG_JUGDE_APPLY t
  76. where ((t.validflag = '20' and
  77. t.JUDGE_RESULT_CODE in ('40740701', '40740709')) OR
  78. T.INSTANCY_FLAG = '1')
  79. and t.is_flag = 0
  80. and t.PROCESS_CODE = 'F'
  81. and t.bal_year_month <= '202602'
  82. and t.bal_year_month >= '202002'
  83. group by t.judge_stove_no, T.HEAT_PLAN_NO
  84. ) a
  85. where a.judge_stove_no = t.judge_stove_no
  86. AND T.HEAT_PLAN_NO = A.HEAT_PLAN_NO
  87. group by t.judge_stove_no,
  88. t.ZY_BATCH_ID,
  89. T.STOVE_NO,
  90. T.PRODUCNAME,
  91. T.DECISION,
  92. t.gradename,
  93. T.OUTDIAMETER,
  94. T.WALLTHICK,
  95. T.PLINE_CODE,
  96. T.ORDER_NO,
  97. T.ORDER_SEQ
  98. order by t.pline_code, t.judge_stove_no)
  99. WHERE act_count > 0 and orderid not like '%ZZBY%';
  100. curoporder_rcl oporder_cursor_rcl%rowtype;
  101. begin
  102. open oporder_cursor_rcl;
  103. loop
  104. fetch oporder_cursor_rcl
  105. into curoporder_rcl;
  106. exit when oporder_cursor_rcl%notfound;
  107. select count(*)
  108. into a
  109. from orderdetail_v@th_cx_link t
  110. where t.contractno_num = curoporder_rcl.orderid
  111. and material_code is not null;
  112. if a > 0 then
  113. select prod_name,sg_grade,sg_sign,outer_diam,wall_thickness,material_code,MATERIAL_NAME
  114. into prod_name_cx,sg_grade_cx ,sg_sign_cx,outer_diam_cx ,wall_thickness_cx ,material_code_cx , MATERIAL_NAME_cx
  115. from orderdetail_v@th_cx_link t
  116. where t.contractno_num = curoporder_rcl.orderid
  117. and material_code is not null
  118. and rownum = 1;
  119. elsif substr(curoporder_rcl.orderid, 1, 2) in ('TH', 'XS') then
  120. select count(*)
  121. into a
  122. from orderdetail_v@th_cx_link t
  123. where substr(t.contractno_num, 3) =
  124. substr(curoporder_rcl.orderid, 3)
  125. and material_code is not null
  126. and rownum = 1;
  127. if a > 0 then
  128. select prod_name,sg_grade,sg_sign,outer_diam,wall_thickness,material_code,MATERIAL_NAME
  129. into prod_name_cx,sg_grade_cx ,sg_sign_cx,outer_diam_cx ,wall_thickness_cx ,material_code_cx , MATERIAL_NAME_cx
  130. from orderdetail_v@th_cx_link t
  131. where substr(t.contractno_num, 3) =
  132. substr(curoporder_rcl.orderid, 3)
  133. and material_code is not null
  134. and rownum = 1;
  135. end if;
  136. end if;
  137. if a > 0 then
  138. insert into HOT_HEAT_PRODUCTION_MES_GX
  139. (cx_no, contract_type, prod_variety, steel_level, steel_no, spec,
  140. prod_type, prod_weight, mate_weight, steel_waste, process,
  141. high_tech_code, high_tech_name, high_prod_weight, high_mate_weight,
  142. estimated_unit_price, estimated_cost, acct_period, mate_code,
  143. resource_type, billet_code, memo, flag, go_there, mate_name,
  144. orderid,judge_stove_no,PRE_PROCESS,DELIVERY_STATUS,INSERT_TIME)
  145. values
  146. (seq_mes_cx.nextval, curoporder_rcl.contract_type, prod_name_cx,
  147. sg_sign_cx, sg_grade_cx,
  148. outer_diam_cx || '*' || wall_thickness_cx, '在产品', null,
  149. curoporder_rcl.act_weight, null, '热处理',
  150. curoporder_rcl.high_tech_code, curoporder_rcl.high_tech_name,
  151. curoporder_rcl.high_prod_weight, curoporder_rcl.high_mate_weight,
  152. curoporder_rcl.estimated_unit_price, curoporder_rcl.estimated_cost,
  153. curoporder_rcl.acct_period, material_code_cx,
  154. curoporder_rcl.resource_type, material_code_cx || '1', '', '0',
  155. (case
  156. when material_code_cx like '%B' then
  157. '加工'
  158. when material_code_cx like '%C' then
  159. '热处理'
  160. else
  161. ''
  162. 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);
  163. else
  164. insert into HOT_HEAT_PRODUCTION_MES_GX
  165. (cx_no, contract_type, prod_variety, steel_level, steel_no, spec,
  166. prod_type, prod_weight, mate_weight, steel_waste, process,
  167. high_tech_code, high_tech_name, high_prod_weight, high_mate_weight,
  168. estimated_unit_price, estimated_cost, acct_period, mate_code,
  169. resource_type, billet_code, memo, flag, go_there, mate_name,
  170. orderid,judge_stove_no)
  171. values
  172. (seq_mes_cx.nextval, curoporder_rcl.contract_type,
  173. null, null,
  174. null, null, '在产品', null,
  175. curoporder_rcl.act_weight, null, '热处理', curoporder_rcl.high_tech_code,
  176. curoporder_rcl.high_tech_name, curoporder_rcl.high_prod_weight,
  177. curoporder_rcl.high_mate_weight, curoporder_rcl.estimated_unit_price,
  178. curoporder_rcl.estimated_cost, curoporder_rcl.acct_period, null,
  179. curoporder_rcl.resource_type, null, '', '0',
  180. (case when cxdata.material_code like '%B' then '加工' when
  181. cxdata.material_code like '%C' then '热处理' else '' end), null,
  182. curoporder_rcl.orderid,curoporder_rcl.judge_stove_no);
  183. end if;
  184. end loop;
  185. close oporder_cursor_rcl;
  186. commit;
  187. end mes_cx_rcl_zzpnew_hand;