ExtJobService.cs 14 KB

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