mes_cx_rcl_zxnew_hand.sql 10 KB

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