ExtJobService.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. using Business.Core.Utilities;
  2. using Business.EntityFrameworkCore;
  3. using Business.Model.Ext;
  4. using Business.Model.MES.IC;
  5. using Business.Model.SRM;
  6. using EFCore.BulkExtensions;
  7. using NLog;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using Volo.Abp.Application.Services;
  12. using Volo.Abp.Domain.Repositories;
  13. namespace Business.Quartz
  14. {
  15. //处理Ext数据库表
  16. public class ExtJobService: ApplicationService
  17. {
  18. SnowFlake help = new SnowFlake();
  19. private IRepository<in_kd_material, long> _kd_material;
  20. private IRepository<ic_item, long> _ic_item;
  21. private IRepository<srm_purchase, long> _srm_purchase;
  22. private IRepository<ic_item_stock, long> _ic_item_stock;
  23. private IRepository<in_kd_bom, long> _kd_bom;
  24. private IRepository<ic_bom, long> _ic_bom;
  25. private IRepository<ic_bom_child, long> _ic_bom_child;
  26. private IRepository<ic_substitute, long> _ic_substitute;
  27. private IRepository<ic_substitute_group, long> _ic_substitute_group;
  28. private IRepository<ic_substitute_group_detail, long> _ic_substitute_group_detail;
  29. private IRepository<ext_xref, long> _ext_xref;
  30. private readonly BusinessDbContext _businessDbContext;
  31. private readonly BusinessExtDbContext _businessExtDbContext;
  32. public ExtJobService(
  33. IRepository<in_kd_material, long> kd_material,
  34. IRepository<ic_item, long> ic_item,
  35. IRepository<srm_purchase, long> srm_purchase,
  36. IRepository<ic_item_stock, long> ic_item_stock,
  37. IRepository<in_kd_bom, long> kd_bom,
  38. IRepository<ic_bom, long> ic_bom,
  39. IRepository<ic_bom_child, long> ic_bom_child,
  40. IRepository<ic_substitute, long> ic_substitute,
  41. IRepository<ic_substitute_group, long> ic_substitute_group,
  42. IRepository<ic_substitute_group_detail, long> ic_substitute_group_detail,
  43. IRepository<ext_xref, long> ext_xref,
  44. BusinessDbContext businessDbContext,
  45. BusinessExtDbContext businessExtDbContext
  46. )
  47. {
  48. _kd_material= kd_material;
  49. _ic_item= ic_item;
  50. _srm_purchase = srm_purchase;
  51. _ic_item_stock = ic_item_stock;
  52. _kd_bom = kd_bom;
  53. _ic_bom= ic_bom;
  54. _ic_bom_child= ic_bom_child;
  55. _ic_substitute= ic_substitute;
  56. _ic_substitute_group= ic_substitute_group;
  57. _ic_substitute_group_detail= ic_substitute_group_detail;
  58. _ext_xref= ext_xref;
  59. _businessDbContext = businessDbContext;
  60. _businessExtDbContext = businessExtDbContext;
  61. }
  62. /// <summary>
  63. /// 处理物料
  64. /// </summary>
  65. public async void DoExt()
  66. {
  67. await DoMaterial();
  68. //DoBom();
  69. }
  70. /// <summary>
  71. /// 处理物料
  72. /// </summary>
  73. public async Task DoMaterial()
  74. {
  75. var extMaterials=_kd_material.GetListAsync();
  76. var ic_items = _ic_item.GetListAsync(p => p.factory_id == 10101 && p.org_id == 101 && p.tenant_id == 101);
  77. var srm_purchases = _srm_purchase.GetListAsync(p => p.factory_id == 10101 && p.org_id == 101 && p.tenant_id == 101);
  78. List<ic_item> ic_itemListAdd = new List<ic_item>();
  79. List<ic_item> ic_itemListUpdate = new List<ic_item>();
  80. List<srm_purchase> srm_purchaseListAdd = new List<srm_purchase>();
  81. List<srm_purchase> srm_purchaseListUpdate = new List<srm_purchase>();
  82. List<ext_xref> ext_xrefList = new List<ext_xref>();
  83. if (extMaterials != null)
  84. {
  85. extMaterials.Result.ForEach(ext =>
  86. {
  87. if (ic_items != null && ic_items.Result.Exists(a => a.number == ext.FNumber))
  88. {
  89. var ic_item = ic_items.Result.FirstOrDefault(a => a.number == ext.FNumber);
  90. if (ic_item != null)
  91. {
  92. ic_item.number = ext.FNumber;
  93. ic_item.name = ext.FName_2052;
  94. ic_item.model = ext.FSpecification_2052;
  95. ic_item.full_name = ext.FDescription_2052;
  96. ic_item.fms_number = ext.FOldNumber;
  97. //0.配置类 1. 2.委外加工 3.外购 4.虚拟件
  98. ic_item.erp_cls = ext.FErpClsID == "配置类" ? 0 : ext.FErpClsID == "自制" ? 1 : ext.FErpClsID == "委外" ? 2 : ext.FErpClsID == "外购" ? 3 : ext.FErpClsID == "虚拟" ? 4 : ext.FErpClsID == "费用" ? 5 : ext.FErpClsID == "服务" ? 6 : -1;
  99. ic_item.source = ext.FDataSource;
  100. ic_item.iskeyitem = ext.FIsKitting == "是" ? 1 : 0;
  101. ic_item.gross_weight = ext.FGROSSWEIGHT;
  102. ic_item.net_weight = ext.FNETWEIGHT;
  103. ic_item.maund = ext.FWEIGHTUNITID_Name;
  104. ic_item.cubic_measure = ext.FVOLUMEUNITID_Name;
  105. ic_item.length = ext.FLENGTH;
  106. ic_item.width = ext.FWIDTH;
  107. ic_item.height = ext.FHEIGHT;
  108. ic_item.size = ext.FVOLUME;
  109. ic_item.allowpur = ext.FIsPurchase == "是" ? 1 : 0;
  110. ic_item.allowsale = ext.FIsSale == "是" ? 1 : 0;
  111. ic_item.allowmanu = ext.FIsProduce == "是" ? 1 : 0;
  112. ic_item.allowout = ext.FIsSubContract == "是" ? 1 : 0;
  113. ic_item.allowbatch = ext.F_SFJLPCH == "是" ? 1 : 0;
  114. ic_item.product_line = ext.F_CPX_Name;
  115. ic_item.minpackqty = ext.FIncreaseQty;
  116. ic_item.fix_leadtime = ext.FFixLeadTime;
  117. ic_item.plan_trategy = ext.FPlanningStrategy == "MRP" ? 1 : 0;
  118. ic_item.order_trategy = ext.FOrderPolicy == "LFL(批对批)" ? 1 : 0;
  119. ic_item.order_inter_val = ext.FOrderIntervalTime;
  120. ic_item.lead_time = ext.FVarLeadTime;
  121. ic_item.bat_change_economy = ext.FVarLeadTimeLotSize;
  122. ic_item.order_point = ext.FReOrderGood;
  123. ic_item.secinv = ext.FPlanSafeStockQty;
  124. ic_itemListUpdate.Add(ic_item);
  125. ext_xrefList.Add(new ext_xref
  126. {
  127. dop_table_name = "ic_item",
  128. dop_id = ic_item.Id,
  129. dop_col1_name = "number",
  130. dop_col1_value = ic_item.number,
  131. other_sys_name = "kd",
  132. other_table_name = "in_kd_material",
  133. other_id = ext.Id,
  134. other_col1_name = "FNumber",
  135. other_col1_value = ext.FNumber
  136. });
  137. var srm_purchase = srm_purchases.Result.FirstOrDefault(a => a.icitem_id == ic_item.Id);
  138. if (srm_purchase != null)
  139. {
  140. srm_purchase.icitem_name = ic_item.name;
  141. srm_purchase.purchgroup = ext.FPurchaseGroupId_Name;
  142. srm_purchase.purcher = ext.FPurchaserId_Name;
  143. srm_purchase.purchase_unit = ext.FPurchaseUnitId_Name;
  144. srm_purchaseListUpdate.Add(srm_purchase);
  145. }
  146. }
  147. }
  148. else
  149. {
  150. ic_item item = new ic_item(help.NextId());
  151. item.number = ext.FNumber;
  152. item.name = ext.FName_2052;
  153. item.model = ext.FSpecification_2052;
  154. item.full_name = ext.FDescription_2052;
  155. item.fms_number = ext.FOldNumber;
  156. //0.配置类 1. 2.委外加工 3.外购 4.虚拟件
  157. item.erp_cls = ext.FErpClsID == "配置类" ? 0 : ext.FErpClsID == "自制" ? 1 : ext.FErpClsID == "委外" ? 2 : ext.FErpClsID == "外购" ? 3 : ext.FErpClsID == "虚拟" ? 4 : ext.FErpClsID == "费用" ? 5 : ext.FErpClsID == "服务" ? 6 : -1;
  158. item.source = ext.FDataSource;
  159. item.iskeyitem = ext.FIsKitting == "是" ? 1 : 0;
  160. item.gross_weight = ext.FGROSSWEIGHT;
  161. item.net_weight = ext.FNETWEIGHT;
  162. item.maund = ext.FWEIGHTUNITID_Name;
  163. item.cubic_measure = ext.FVOLUMEUNITID_Name;
  164. item.length = ext.FLENGTH;
  165. item.width = ext.FWIDTH;
  166. item.height = ext.FHEIGHT;
  167. item.size = ext.FVOLUME;
  168. item.allowpur = ext.FIsPurchase == "是" ? 1 : 0;
  169. item.allowsale = ext.FIsSale == "是" ? 1 : 0;
  170. item.allowmanu = ext.FIsProduce == "是" ? 1 : 0;
  171. item.allowout = ext.FIsSubContract == "是" ? 1 : 0;
  172. item.allowbatch = ext.F_SFJLPCH == "是" ? 1 : 0;
  173. item.tenant_id = 101;//TODO
  174. item.factory_id = 10101;//TODO
  175. item.org_id = 101;//TODO
  176. item.IsDeleted = false;//TODO
  177. item.is_equipment = 0;
  178. item.item_level = 0;
  179. item.picktype = 0;
  180. item.enable_warning = 0;
  181. item.batch_manager = 0;
  182. item.product_line = ext.F_CPX_Name;
  183. item.production_leadtime = 0;
  184. item.stock_leadtime = 0;
  185. item.transportation_leadtime = 0;
  186. item.order_leadtime = 0;
  187. item.minpackqty = ext.FIncreaseQty;
  188. item.minorderqty = 0;
  189. item.fix_leadtime = ext.FFixLeadTime;
  190. item.plan_trategy = ext.FPlanningStrategy == "MRP" ? 1 : 0;
  191. item.order_trategy = ext.FOrderPolicy == "LFL(批对批)" ? 1 : 0;
  192. item.order_inter_val = ext.FOrderIntervalTime;
  193. item.lead_time = ext.FVarLeadTime;
  194. item.bat_change_economy = ext.FVarLeadTimeLotSize;
  195. item.order_point = ext.FReOrderGood;
  196. item.secinv = ext.FPlanSafeStockQty;
  197. ic_itemListAdd.Add(item);
  198. ext_xrefList.Add(new ext_xref
  199. {
  200. dop_table_name = "ic_item",
  201. dop_id = item.Id,
  202. dop_col1_name = "number",
  203. dop_col1_value = item.number,
  204. other_sys_name = "kd",
  205. other_table_name = "in_kd_material",
  206. other_id = ext.Id,
  207. other_col1_name = "FNumber",
  208. other_col1_value = ext.FNumber
  209. });
  210. srm_purchaseListAdd.Add(new srm_purchase(help.NextId())
  211. {
  212. icitem_id = item.Id,
  213. icitem_name = item.name,
  214. currency_type = ext.FCurrencyId_Name == "人民币" ? 1 : 0,//TODO
  215. tenant_id = 101,//TODO
  216. factory_id = 10101,////TODO
  217. org_id = 101,//TODO
  218. IsDeleted = false,//TODO
  219. supplier_id = 0,
  220. purchgroup = ext.FPurchaseGroupId_Name,
  221. purcher = ext.FPurchaserId_Name,
  222. purchase_unit = ext.FPurchaseUnitId_Name
  223. });
  224. }
  225. });
  226. if (ic_itemListAdd.Count > 0)
  227. {
  228. //await _ic_item.InsertManyAsync(ic_itemListAdd);
  229. _businessDbContext.BulkInsert(ic_itemListAdd);
  230. }
  231. if (ic_itemListUpdate.Count > 0)
  232. {
  233. //await _ic_item.UpdateManyAsync(ic_itemListUpdate);
  234. _businessDbContext.BulkUpdate(ic_itemListUpdate);
  235. }
  236. if (srm_purchaseListAdd.Count > 0)
  237. {
  238. //await _ic_item_pur.InsertManyAsync(ic_item_purListAdd);
  239. _businessDbContext.BulkInsert(srm_purchaseListAdd);
  240. }
  241. if (srm_purchaseListUpdate.Count > 0)
  242. {
  243. //await _ic_item_pur.UpdateManyAsync(ic_item_purListUpdate);
  244. _businessDbContext.BulkUpdate(srm_purchaseListUpdate);
  245. }
  246. if (ext_xrefList.Count > 0)
  247. {
  248. //await _ext_xref.UpdateManyAsync(ext_xrefList);
  249. _businessExtDbContext.BulkInsert(ext_xrefList);
  250. }
  251. }
  252. }
  253. /// <summary>
  254. /// 处理物料清单
  255. /// </summary>
  256. public void DoBom()
  257. {
  258. LogManager.Configuration.Install(new NLog.Config.InstallationContext());
  259. }
  260. }
  261. }