ExtJobService.cs 12 KB

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