mes_cx_jg_zxnew_hand.sql 11 KB

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