mes_cx_rz_zxnew_hand.sql 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. CREATE OR REPLACE procedure MES_CX_RZ_ZXNEW_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_rz IS
  14. select (select decode(max(s.order_typ),
  15. '120108',
  16. '双经销',
  17. '120109',
  18. '定销订购',
  19. '120107',
  20. '来料加工',
  21. '自用')
  22. from cxuser.slm_order_head s
  23. where s.order_no = regexp_replace(t.pro_order_no, '/.*', '')) contract_type,
  24. --合同类型
  25. t.producname prod_variety,
  26. nvl(replace(PRO_ORDER_NO, '/', ''),
  27. replace(get_cp_order(t.judge_stove_no), '/', '')) orderid,
  28. --品名、品种
  29. t.steelname steel_level,
  30. --钢级
  31. t.gradename steel_no,
  32. --钢号
  33. t.spec_name spec,
  34. --规格
  35. (case
  36. when t.target = 'A' then
  37. '产成品'
  38. else
  39. '半成品'
  40. end) prod_type,
  41. --产量类型
  42. (case
  43. when t.target = 'A' then
  44. (sum(decode(t.act_weight,
  45. null,
  46. t.act_theory_weight,
  47. t.act_weight)) +
  48. nvl((select SUM(nvl(T2.act_weight, 0))
  49. from ydm_zc_stocktakinglist t2
  50. where t2.judge_stove_no = t.judge_stove_no
  51. and t2.STOCKTAKING_TYPE_CODE = '800603'
  52. and t2.BAL_YEAR_MONTH = '{0}'),
  53. 0))
  54. else
  55. sum(decode(t.act_weight,
  56. null,
  57. t.act_theory_weight,
  58. t.act_weight))
  59. end) prod_weight,
  60. --成品重量
  61. nvl((select SUM(nvl(T2.act_weight, 0))
  62. from ydm_zc_stocktakinglist t2
  63. where t2.judge_stove_no = t.judge_stove_no
  64. and t2.STOCKTAKING_TYPE_CODE = '800603'
  65. and t2.BAL_YEAR_MONTH = '{0}'),
  66. 0) lc_weight, --量差
  67. sum(output_weight) mate_weight,
  68. --来料重量
  69. (case
  70. when sum(input_weight) <> 0 then
  71. round(sum(decode(t.act_weight,
  72. null,
  73. t.act_theory_weight,
  74. t.act_weight)) / sum(input_weight),
  75. 4) * 100
  76. else
  77. 0
  78. end) steel_waste,
  79. --消耗占比
  80. '热轧' process,
  81. --工序
  82. null high_tech_code,
  83. null high_tech_name,
  84. 0 high_prod_weight,
  85. 0 high_mate_weight,
  86. 0 estimated_unit_price,
  87. 0 estimated_cost,
  88. substr(t.bal_year_month, 0, 4) || '-' ||
  89. substr(t.bal_year_month, 5, 2) acct_period,
  90. --换成取产销提供的视图 tzh 24.12.4
  91. get_cp_code6(t.pro_order_no) mate_code,
  92. --物料编码
  93. getislljg(t.judge_stove_no, replace(t.PRO_ORDER_NO, '/', '')) resource_type,
  94. t.judge_stove_no,
  95. --是否来料加工
  96. get_pl_code(t.gradename,
  97. (select xxx.dimater
  98. from cxuser.ydm_gp_outlist xxx
  99. where xxx.stove_no = CASE
  100. WHEN t.stove_no IS NOT NULL THEN
  101. t.stove_no
  102. ELSE
  103. get_max_stove_no(t.judge_stove_no)
  104. END
  105. and rownum = 1) --规格
  106. ) billet_code --,stove_no,t.pro_order_no--钢坯编码,
  107. from cxuser.qcm_zg_jugde_apply t
  108. left join mil_plan t1
  109. on t.judge_stove_no = regexp_replace(t1.judge_stove_no, '-.*', '')
  110. and t1.back_slab_flag <> '2'
  111. and substr(t1.judge_stove_no, -2) = '01'
  112. left join pln_zy_zg_m t2
  113. on t2.heat_plan_no = t.heat_plan_no
  114. where t.is_flag = '0'
  115. and t.is_all_scrap in ('0', '1', '2', '7', '8')
  116. and ((t.validflag = '20' and t.target <> 'A' and
  117. t.judge_result_code in ('40740701', '40740709')) or
  118. (t.validflag = '20' and t.target = 'A' and
  119. t.judge_tolresult_code in ('40740701', '40740709')) or
  120. (t.validflag = '20' and t.target = 'A' and t.is_all_scrap = '1') or
  121. t.instancy_flag = '1')
  122. and t.process_code = 'D'
  123. -- AND T.PLINE_CODE = 'C072'
  124. and t.target = t1.target
  125. and t.bal_year_month in ('{0}')
  126. and nvl(replace(PRO_ORDER_NO, '/', ''),
  127. replace(get_cp_order(t.judge_stove_no), '/', '')) not like
  128. 'ZZBY%'
  129. group by t.producname,
  130. t.steelname,
  131. --钢级
  132. t.gradename,
  133. --钢号
  134. t.stove_no,
  135. t.spec_name,
  136. --规格
  137. t.target,
  138. t.bal_year_month,
  139. pro_order_no,
  140. t.judge_stove_no;
  141. curoporder_jg oporder_cursor_rz%rowtype;
  142. cnt number;
  143. begin
  144. cnt := 0;
  145. open oporder_cursor_rz;
  146. loop
  147. fetch oporder_cursor_rz
  148. into curoporder_jg;
  149. exit when oporder_cursor_rz%notfound;
  150. select count(*)
  151. into a
  152. from orderdetail_v@th_cx_link t
  153. where t.contractno_num = curoporder_jg.orderid
  154. and material_code is not null;
  155. if a > 0 then
  156. select outer_diam,
  157. prod_name,
  158. sg_grade,
  159. sg_sign,
  160. wall_thickness,
  161. material_code,
  162. MATERIAL_NAME
  163. into outer_diam_cx,
  164. prod_name_cx,
  165. sg_grade_cx,
  166. sg_sign_cx,
  167. wall_thickness_cx,
  168. material_code_cx,
  169. MATERIAL_NAME_cx
  170. from orderdetail_v@th_cx_link t
  171. where t.contractno_num = curoporder_jg.orderid
  172. and material_code is not null
  173. and rownum = 1;
  174. elsif substr(curoporder_jg.orderid, 1, 2) in ('TH', 'XS') then
  175. select count(*)
  176. into a
  177. from orderdetail_v@th_cx_link t
  178. where substr(t.contractno_num, 3) = substr(curoporder_jg.orderid, 3)
  179. and material_code is not null
  180. and rownum = 1;
  181. if a > 0 then
  182. select outer_diam,
  183. prod_name,
  184. sg_grade,
  185. sg_sign,
  186. wall_thickness,
  187. material_code,
  188. MATERIAL_NAME
  189. into outer_diam_cx,
  190. prod_name_cx,
  191. sg_grade_cx,
  192. sg_sign_cx,
  193. wall_thickness_cx,
  194. material_code_cx,
  195. MATERIAL_NAME_cx
  196. from orderdetail_v@th_cx_link t
  197. where substr(t.contractno_num, 3) =
  198. substr(curoporder_jg.orderid, 3)
  199. and material_code is not null
  200. and rownum = 1;
  201. end if;
  202. end if;
  203. if a > 0 then
  204. insert into hot_production_mes_rz
  205. (cx_no,
  206. contract_type,
  207. prod_variety,
  208. steel_level,
  209. steel_no,
  210. spec,
  211. prod_type,
  212. prod_weight,
  213. mate_weight,
  214. steel_waste,
  215. process,
  216. high_tech_code,
  217. high_tech_name,
  218. high_prod_weight,
  219. high_mate_weight,
  220. estimated_unit_price,
  221. estimated_cost,
  222. acct_period,
  223. mate_code,
  224. resource_type,
  225. billet_code,
  226. memo,
  227. flag,
  228. go_there,
  229. mate_name,
  230. orderid,
  231. judge_stove_no,
  232. PRE_PROCESS,
  233. DELIVERY_STATUS,
  234. INSERT_TIME,
  235. lc_weight)
  236. values
  237. (seq_mes_cx.nextval,
  238. curoporder_jg.contract_type,
  239. prod_name_cx,
  240. sg_sign_cx,
  241. sg_grade_cx,
  242. outer_diam_cx || '*' || wall_thickness_cx,
  243. curoporder_jg.prod_type,
  244. curoporder_jg.prod_weight,
  245. curoporder_jg.mate_weight,
  246. curoporder_jg.steel_waste,
  247. curoporder_jg.process,
  248. curoporder_jg.high_tech_code,
  249. curoporder_jg.high_tech_name,
  250. curoporder_jg.high_prod_weight,
  251. curoporder_jg.high_mate_weight,
  252. curoporder_jg.estimated_unit_price,
  253. curoporder_jg.estimated_cost,
  254. curoporder_jg.acct_period,
  255. material_code_cx,
  256. curoporder_jg.resource_type,
  257. curoporder_jg.billet_code,
  258. '',
  259. '0',
  260. (case
  261. when curoporder_jg.mate_code like '%B' then
  262. '加工'
  263. when curoporder_jg.mate_code like '%C' then
  264. '热处理'
  265. else
  266. ''
  267. end),
  268. MATERIAL_NAME_cx,
  269. curoporder_jg.orderid,
  270. curoporder_jg.judge_stove_no,
  271. null,
  272. SUBSTR(MATERIAL_NAME_cx,
  273. INSTR(MATERIAL_NAME_cx, ',', 1, 1) + 1,
  274. INSTR(MATERIAL_NAME_cx, ',', 1, 2) -
  275. INSTR(MATERIAL_NAME_cx, ',', 1, 1) - 1),
  276. sysdate,
  277. curoporder_jg.lc_weight);
  278. else
  279. insert into hot_production_mes_rz
  280. (cx_no,
  281. contract_type,
  282. prod_variety,
  283. steel_level,
  284. steel_no,
  285. spec,
  286. prod_type,
  287. prod_weight,
  288. mate_weight,
  289. steel_waste,
  290. process,
  291. high_tech_code,
  292. high_tech_name,
  293. high_prod_weight,
  294. high_mate_weight,
  295. estimated_unit_price,
  296. estimated_cost,
  297. acct_period,
  298. mate_code,
  299. resource_type,
  300. billet_code,
  301. memo,
  302. flag,
  303. go_there,
  304. mate_name,
  305. orderid,
  306. judge_stove_no,
  307. lc_weight)
  308. values
  309. (seq_mes_cx.nextval,
  310. curoporder_jg.contract_type,
  311. curoporder_jg.prod_variety,
  312. curoporder_jg.steel_level,
  313. curoporder_jg.steel_no,
  314. curoporder_jg.spec,
  315. curoporder_jg.prod_type,
  316. curoporder_jg.prod_weight,
  317. curoporder_jg.mate_weight,
  318. curoporder_jg.steel_waste,
  319. curoporder_jg.process,
  320. curoporder_jg.high_tech_code,
  321. curoporder_jg.high_tech_name,
  322. curoporder_jg.high_prod_weight,
  323. curoporder_jg.high_mate_weight,
  324. curoporder_jg.estimated_unit_price,
  325. curoporder_jg.estimated_cost,
  326. curoporder_jg.acct_period,
  327. curoporder_jg.mate_code,
  328. curoporder_jg.resource_type,
  329. curoporder_jg.billet_code,
  330. '',
  331. '0',
  332. (case when curoporder_jg.mate_code like '%B' then '加工' when
  333. curoporder_jg.mate_code like '%C' then '热处理' else '' end),
  334. null,
  335. curoporder_jg.orderid,
  336. curoporder_jg.judge_stove_no,
  337. curoporder_jg.lc_weight);
  338. end if;
  339. cnt := cnt + 1;
  340. if cnt = 6 then
  341. cnt := 100;
  342. end if;
  343. end loop;
  344. close oporder_cursor_rz;
  345. commit;
  346. exception
  347. when others then
  348. DBMS_OUTPUT.PUT_LINE('错误: ' || cnt || '条' || SQLERRM);
  349. end mes_cx_rz_zxnew_HAND;