SystemJobAppService.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. using Business.Core.Utilities;
  2. using Business.Domain;
  3. using Business.EntityFrameworkCore;
  4. using Business.EntityFrameworkCore.SqlRepositories;
  5. using Business.ResourceExamineManagement;
  6. using Business.SystemJob;
  7. using EFCore.BulkExtensions;
  8. using MongoDB.Driver.Linq;
  9. using NLog;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14. using Volo.Abp.Application.Services;
  15. using Volo.Abp.Domain.Repositories;
  16. using Volo.Abp.MultiTenancy;
  17. using WkHtmlToPdfDotNet;
  18. namespace Business.SystemJobManagement
  19. {
  20. public class SystemJobAppService : ApplicationService, ISystemJobAppService
  21. {
  22. /// <summary>
  23. /// 物料bom
  24. /// </summary>
  25. private IRepository<ic_bom, long> _mysql_ic_bom;
  26. /// <summary>
  27. /// 物料bom子表
  28. /// </summary>
  29. private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
  30. /// <summary>
  31. /// 物料
  32. /// </summary>
  33. private IRepository<ic_item, long> _mysql_ic_item;
  34. /// <summary>
  35. /// 供应商
  36. /// </summary>
  37. private IRepository<srm_supplier, long> _mysql_srm_supplier;
  38. /// <summary>
  39. /// 物料采购报价单
  40. /// </summary>
  41. private IRepository<srm_purchase, long> _mysql_srm_purchase;
  42. /// <summary>
  43. /// 物料采购报价单
  44. /// </summary>
  45. private IRepository<crm_customer, long> _mysql_crm_customer;
  46. /// <summary>
  47. /// 销售订单
  48. /// </summary>
  49. private IRepository<crm_seorder, long> _mysql_crm_seorder;
  50. /// <summary>
  51. /// 销售订单明细
  52. /// </summary>
  53. private IRepository<crm_seorderentry, long> _mysql_crm_seorderentry;
  54. /// <summary>
  55. /// 雪花算法
  56. /// </summary>
  57. SnowFlake help = new SnowFlake();
  58. private readonly BusinessDbContext _businessDbContext;
  59. private readonly ISqlRepository<CustMaster> _custMaster;
  60. private readonly ISqlRepository<SuppMaster> _suppMaster;
  61. private readonly ISqlRepository<ConsigneeAddressMaster> _consigneeAddressMaster;
  62. private readonly ISqlRepository<ItemMaster> _itemMaster;
  63. private readonly ISqlRepository<ProductStructureMaster> _productStructureMaster;
  64. /// <summary>
  65. /// 替代群组
  66. /// </summary>
  67. private IRepository<ic_substitute, long> _mysql_ic_substitute;
  68. /// <summary>
  69. /// 物料替代多群组
  70. /// </summary>
  71. private IRepository<ic_substitute_group, long> _mysql_ic_substitute_group;
  72. /// <summary>
  73. /// 物料替代多群组明细
  74. /// </summary>
  75. private IRepository<ic_substitute_group_detail, long> _mysql_ic_substitute_group_detail;
  76. /// <summary>
  77. /// 工艺路径
  78. /// </summary>
  79. private readonly IRepository<mo_mes_technique, long> _mes_technique;
  80. private IRepository<mes_technique, long> _mysql_mes_technique;
  81. /// <summary>
  82. /// 工序
  83. /// </summary>
  84. private readonly IRepository<mo_mes_process, long> _mes_process;
  85. private IRepository<mes_process, long> _mysql_mes_process;
  86. /// <summary>
  87. /// 工艺路径关联工序
  88. /// </summary>
  89. private readonly IRepository<mo_mes_tech_process, long> _mes_tech_process;
  90. private IRepository<mes_tech_process, long> _mysql_mes_tech_process;
  91. /// <summary>
  92. /// 生产排产
  93. /// </summary>
  94. private readonly ProductionScheduleAppService _productionScheduleAppService;
  95. public SystemJobAppService(
  96. IRepository<ic_bom, long> mysql_ic_bom,
  97. IRepository<ic_bom_child, long> mysql_ic_bom_child,
  98. IRepository<ic_item, long> mysql_ic_item,
  99. IRepository<srm_supplier, long> mysql_srm_supplier,
  100. IRepository<srm_purchase, long> mysql_srm_purchase,
  101. IRepository<crm_customer, long> mysql_crm_customer,
  102. IRepository<crm_seorder, long> mysql_crm_seorder,
  103. IRepository<crm_seorderentry, long> mysql_crm_seorderentry,
  104. IRepository<ic_substitute, long> mysql_ic_substitute,
  105. IRepository<ic_substitute_group, long> mysql_ic_substitute_group,
  106. IRepository<ic_substitute_group_detail, long> mysql_ic_substitute_group_detail,
  107. IRepository<mes_technique, long> mysql_mes_technique,
  108. IRepository<mes_process, long> mysql_mes_process,
  109. IRepository<mes_tech_process, long> mysql_mes_tech_process,
  110. ISqlRepository<CustMaster> custMaster,
  111. ISqlRepository<SuppMaster> suppMaster,
  112. ISqlRepository<ConsigneeAddressMaster> consigneeAddressMaster,
  113. ISqlRepository<ItemMaster> itemMaster,
  114. ISqlRepository<ProductStructureMaster> productStructureMaster,
  115. IRepository<mo_mes_technique, long> mes_technique,
  116. IRepository<mo_mes_process, long> mes_process,
  117. IRepository<mo_mes_tech_process, long> mes_tech_process,
  118. ProductionScheduleAppService productionScheduleAppService,
  119. BusinessDbContext businessDbContext
  120. )
  121. {
  122. _mysql_ic_bom = mysql_ic_bom;
  123. _mysql_ic_bom_child = mysql_ic_bom_child;
  124. _mysql_ic_item = mysql_ic_item;
  125. _mysql_srm_supplier = mysql_srm_supplier;
  126. _mysql_srm_purchase = mysql_srm_purchase;
  127. _mysql_crm_customer = mysql_crm_customer;
  128. _mysql_crm_seorder = mysql_crm_seorder;
  129. _mysql_crm_seorderentry = mysql_crm_seorderentry;
  130. _mysql_ic_substitute = mysql_ic_substitute;
  131. _mysql_ic_substitute_group = mysql_ic_substitute_group;
  132. _mysql_ic_substitute_group_detail = mysql_ic_substitute_group_detail;
  133. _mysql_mes_technique = mysql_mes_technique;
  134. _mysql_mes_process = mysql_mes_process;
  135. _mysql_mes_tech_process = mysql_mes_tech_process;
  136. _custMaster = custMaster;
  137. _suppMaster = suppMaster;
  138. _consigneeAddressMaster = consigneeAddressMaster;
  139. _itemMaster = itemMaster;
  140. _productStructureMaster = productStructureMaster;
  141. _mes_technique = mes_technique;
  142. _mes_process = mes_process;
  143. _mes_tech_process = mes_tech_process;
  144. _businessDbContext = businessDbContext;
  145. _itemMaster = itemMaster;
  146. _productionScheduleAppService = productionScheduleAppService;
  147. }
  148. public string SyncWMSDataToMySQLJob()
  149. {
  150. try
  151. {
  152. SyncCustMaster();
  153. SyncSuppMaster();
  154. //SyncSalesOrdMaster();
  155. //SyncSalesOrdMasterEntry();
  156. SyncItemMaster();
  157. SyncBom();
  158. }
  159. catch (Exception ex)
  160. {
  161. return ex.Message;
  162. }
  163. return "同步完成";
  164. }
  165. public string LogInstallJob()
  166. {
  167. try
  168. {
  169. LogManager.Configuration.Install(new NLog.Config.InstallationContext());//每天0点执行一次
  170. }
  171. catch (Exception ex)
  172. {
  173. return ex.Message;
  174. }
  175. return "任务执行成功";
  176. }
  177. public async Task<string> SyncBaseDataToMongoDBJob()
  178. {
  179. try
  180. {
  181. //物料采购报价单
  182. List<srm_purchase> srm_purchases = _mysql_srm_purchase.GetListAsync().Result;
  183. if (srm_purchases.Count > 0)
  184. {
  185. //先清空表数据
  186. await MongoHelper<mo_srm_purchase>.DeleteManyAsync(p => p.mysql_id != -1);
  187. var mosrm_purchase = ObjectMapper.Map<List<srm_purchase>, List<mo_srm_purchase>>(srm_purchases);
  188. mosrm_purchase.ForEach(s => s.GenerateNewId(help.NextId()));
  189. await MongoHelper<mo_srm_purchase>.InsertManyAsync(mosrm_purchase);
  190. }
  191. //同步物料BOM明细数据
  192. var icbom_childs = _mysql_ic_bom_child.GetListAsync().Result;
  193. if (icbom_childs.Count > 0)
  194. {
  195. //先清空表数据
  196. await MongoHelper<mo_ic_bom_child>.DeleteManyAsync(p => p.mysql_id != -1);
  197. var moIcbom_childs = ObjectMapper.Map<List<ic_bom_child>, List<mo_ic_bom_child>>(icbom_childs);
  198. moIcbom_childs.ForEach(s => s.GenerateNewId(help.NextId()));
  199. await MongoHelper<mo_ic_bom_child>.InsertManyAsync(moIcbom_childs);
  200. }
  201. //同步物料Bom数据
  202. var icBoms = _mysql_ic_bom.GetListAsync().Result;
  203. if (icBoms.Count > 0)
  204. {
  205. //先清空表数据
  206. await MongoHelper<mo_ic_bom>.DeleteManyAsync(p => p.mysql_id != -1);
  207. var moIcBoms = ObjectMapper.Map<List<ic_bom>, List<mo_ic_bom>>(icBoms);
  208. moIcBoms.ForEach(s => s.GenerateNewId(help.NextId()));
  209. await MongoHelper<mo_ic_bom>.InsertManyAsync(moIcBoms);
  210. }
  211. //同步物料数据
  212. var icItems = _mysql_ic_item.GetListAsync().Result;
  213. if (icItems.Count > 0)
  214. {
  215. //先清空表数据
  216. await MongoHelper<mo_ic_item>.DeleteManyAsync(p => p.mysql_id != -1);
  217. var moIcItems = ObjectMapper.Map<List<ic_item>, List<mo_ic_item>>(icItems);
  218. moIcItems.ForEach(s => s.GenerateNewId(help.NextId()));
  219. await MongoHelper<mo_ic_item>.InsertManyAsync(moIcItems);
  220. }
  221. //同步替代群组数据
  222. var subtitutes = _mysql_ic_substitute.GetListAsync().Result;
  223. if (subtitutes.Count > 0)
  224. {
  225. //先清空表数据
  226. await MongoHelper<mo_ic_substitute>.DeleteManyAsync(p => p.mysql_id != -1);
  227. var moSubtitutes = ObjectMapper.Map<List<ic_substitute>, List<mo_ic_substitute>>(subtitutes);
  228. moSubtitutes.ForEach(s => s.GenerateNewId(help.NextId()));
  229. await MongoHelper<mo_ic_substitute>.InsertManyAsync(moSubtitutes);
  230. }
  231. //同步物料替代多群组数据
  232. var subAlls = _mysql_ic_substitute_group.GetListAsync().Result;
  233. if (subAlls.Count > 0)
  234. {
  235. //先清空表数据
  236. await MongoHelper<mo_ic_substitute_group>.DeleteManyAsync(p => p.mysql_id != -1);
  237. var moSubAlls = ObjectMapper.Map<List<ic_substitute_group>, List<mo_ic_substitute_group>>(subAlls);
  238. moSubAlls.ForEach(s => s.GenerateNewId(help.NextId()));
  239. await MongoHelper<mo_ic_substitute_group>.InsertManyAsync(moSubAlls);
  240. }
  241. //同步物料替代多群组明细数据
  242. var subAllDtls = _mysql_ic_substitute_group_detail.GetListAsync().Result;
  243. if (subAllDtls.Count > 0)
  244. {
  245. //先清空表数据
  246. await MongoHelper<mo_ic_substitute_group_detail>.DeleteManyAsync(p => p.mysql_id != -1);
  247. var moSubAllDtls = ObjectMapper.Map<List<ic_substitute_group_detail>, List<mo_ic_substitute_group_detail>>(subAllDtls);
  248. moSubAllDtls.ForEach(s => s.GenerateNewId(help.NextId()));
  249. await MongoHelper<mo_ic_substitute_group_detail>.InsertManyAsync(moSubAllDtls);
  250. }
  251. //同步供应商数据
  252. var suppliers = _mysql_srm_supplier.GetListAsync().Result;
  253. if (suppliers.Count > 0)
  254. {
  255. //先清空表数据
  256. await MongoHelper<mo_srm_supplier>.DeleteManyAsync(p => p.mysql_id != -1);
  257. var moSuppliers = ObjectMapper.Map<List<srm_supplier>, List<mo_srm_supplier>>(suppliers);
  258. moSuppliers.ForEach(s => s.GenerateNewId(help.NextId()));
  259. await MongoHelper<mo_srm_supplier>.InsertManyAsync(moSuppliers);
  260. }
  261. }
  262. catch (Exception ex)
  263. {
  264. return ex.Message;
  265. }
  266. return "任务执行成功";
  267. }
  268. //同步客户
  269. public void SyncCustMaster()
  270. {
  271. var customerList = _mysql_crm_customer.GetListAsync().Result;
  272. List<CustMaster> custList = _custMaster.Select(a => a.IsActive);
  273. var addressList = _consigneeAddressMaster.Select(a => a.Typed == "Cust" && a.IsActive);
  274. List<crm_customer> ItemsAdd = new List<crm_customer>();
  275. if (custList != null && custList.Count > 0)
  276. {
  277. for (int i = 0; i < custList.Count; i++)
  278. {
  279. long domain = Convert.ToInt64(custList[i].Domain);
  280. long factory_id = domain;
  281. long tenant_id = 1000;
  282. var cust = customerList.Find(x => x.customer_no == custList[i].Cust);
  283. if (cust is null)
  284. {
  285. ConsigneeAddressMaster address = addressList.Find(a => a.Address == custList[i].Cust);
  286. var customer = new crm_customer
  287. {
  288. customer_no = custList[i].Cust,
  289. customer_name = address is not null ? address.Name : "",
  290. telephone = address is not null ? address.Telephone : "",
  291. email = address is not null ? address.AttentionEmail : "",
  292. contact = address is not null ? address.Attention1 : "",
  293. post_code = address is not null ? address.Post : "",
  294. country = address is not null ? address.Country : "",
  295. province = address is not null ? address.State : "",
  296. city = address is not null ? address.City : "",
  297. region = address is not null ? address.State : "",
  298. address = address is not null ? address.Address1 : "",
  299. short_name = custList[i].SortName,
  300. carrying_aos = custList[i].CustShippingLT.GetValueOrDefault(),
  301. currency = custList[i].Curr,
  302. employee_name = custList[i].Salesperson1,
  303. factory_id = factory_id,
  304. tenant_id=tenant_id,
  305. company_id = tenant_id
  306. };
  307. customer.GenerateNewId(help.NextId());
  308. ItemsAdd.Add(customer);
  309. }
  310. }
  311. _businessDbContext.BulkInsert(ItemsAdd);
  312. }
  313. }
  314. //同步供应商
  315. public void SyncSuppMaster()
  316. {
  317. var suppList = _mysql_srm_supplier.GetListAsync().Result;
  318. List<SuppMaster> custList = _suppMaster.Select(a => a.IsActive);
  319. var addressList = _consigneeAddressMaster.Select(a => a.Typed == "Supp" && a.IsActive);
  320. List<srm_supplier> ItemsAdd = new List<srm_supplier>();
  321. if (custList != null && custList.Count > 0)
  322. {
  323. for (int i = 0; i < custList.Count; i++)
  324. {
  325. long domain = Convert.ToInt64(custList[i].Domain.ToString());
  326. long factory_id = domain;
  327. long tenant_id = 1000;
  328. var supp = suppList.Find(x => x.supplier_no == custList[i].Supp.ToString() && x.company_id == tenant_id && x.factory_id == factory_id);
  329. if (supp is null)
  330. {
  331. ConsigneeAddressMaster address = addressList.Find(a => a.Address == custList[i].Supp);
  332. var supplier = new srm_supplier
  333. {
  334. supplier_no = custList[i].Supp,
  335. supplier_name = address is not null ? address.Name : "",
  336. supplier_short_name = custList[i].SortName,
  337. country = address is not null ? address.Country : "",
  338. state = address is not null ? address.State : "",
  339. region = address is not null ? address.City : "",
  340. contact = address is not null ? address.Attention1 : "",
  341. telephone = address is not null ? address.Telephone : "",
  342. post_code = address is not null ? address.Post : "",
  343. email = address is not null ? address.AttentionEmail : "",
  344. currency = custList[i].Curr,
  345. supply_type = custList[i].Type,
  346. settlement = custList[i].CrTerms,
  347. factory_id = factory_id,
  348. tenant_id = tenant_id,
  349. company_id = tenant_id
  350. };
  351. supplier.GenerateNewId(help.NextId());
  352. ItemsAdd.Add(supplier);
  353. }
  354. }
  355. _businessDbContext.BulkInsert(ItemsAdd);
  356. }
  357. }
  358. //////同步销售订单
  359. ////public void SyncSalesOrdMaster()
  360. ////{
  361. //// var customerList = _mysql_crm_customer.GetListAsync().Result;
  362. //// var saleOrderList = _mysql_crm_seorder.GetListAsync().Result;
  363. //// var ItemMasterDS = _repository.SelectDataBaseBySql("SELECT A.SalesOrd,C.SortName AS CustomName,A.SoldTo AS Cust,A.OrdDate,A.RequiredDate,A.Sequence,A.Curr,A.ExchRate,A.Salesperson1,A.Project,B.Descr AS ProjectName,A.[Domain] from SalesOrdMaster A INNER JOIN CustMaster C ON A.SoldTo=C.Cust and A.[Domain]=C.[Domain]\r\nLEFT JOIN ProjectMaster B On A.Project=B.Project AND A.[Domain]=B.[Domain] ", "SalesOrdMaster");
  364. //// List<crm_seorder> ItemsAdd = new List<crm_seorder>();
  365. //// List<crm_seorder> ItemsUpdate = new List<crm_seorder>();
  366. //// if (ItemMasterDS != null && ItemMasterDS.Tables.Count > 0 && ItemMasterDS.Tables[0].Rows.Count > 0)
  367. //// {
  368. //// for (int i = 0; i < ItemMasterDS.Tables[0].Rows.Count; i++)
  369. //// {
  370. //// long domain = Convert.ToInt64(ItemMasterDS.Tables[0].Rows[i]["Domain"].ToString());
  371. //// long factory_id = domain % 1000;
  372. //// long tenant_id = domain - factory_id;
  373. //// var custno = ItemMasterDS.Tables[0].Rows[i]["Cust"].ToString();
  374. //// var cust = customerList.Find(a => a.customer_no == custno && a.factory_id == factory_id && a.tenant_id == tenant_id);
  375. //// long? custom_id = cust is null ? cust.Id : null;
  376. //// var saleorder = saleOrderList.Find(x => x.bill_no == ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString() && x.tenant_id == factory_id && x.factory_id == tenant_id);
  377. //// if (saleorder is null)
  378. //// {
  379. //// var order = new crm_seorder
  380. //// {
  381. //// bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString(),
  382. //// custom_id = custom_id,
  383. //// custom_name = ItemMasterDS.Tables[0].Rows[i]["CustomName"].ToString(),
  384. //// custom_no = ItemMasterDS.Tables[0].Rows[i]["Cust"].ToString(),
  385. //// //custom_level = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? "外购" : "自制",
  386. //// date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
  387. //// rdate = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"],
  388. //// //urgent = "",
  389. //// currency = ItemMasterDS.Tables[0].Rows[i]["Curr"].ToString() == "RMB" ? 1 : 0,
  390. //// exchange_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  391. //// //biller = ItemMasterDS.Tables[0].Rows[i]["NetWeightUM"].ToString(),
  392. //// //emp_no = (decimal)ItemMasterDS.Tables[0].Rows[i]["Length"],
  393. //// emp_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  394. //// //auditor = (decimal)ItemMasterDS.Tables[0].Rows[i]["Height"],
  395. //// //audit_date = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? 1 : 0,
  396. //// //status = 1,
  397. //// //closed = "",
  398. //// //op_time = 1,
  399. //// bill_from = "",
  400. //// //project_name = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["LotSerialControl"]) == true ? 1 : 0,
  401. //// //project_code = "",
  402. //// out_stock_type = 1,//TODO
  403. //// //sale_dept_id = "",
  404. //// //sale_dept_name = 1,
  405. //// //sale_dept_code = 1,
  406. //// //create_dept = 1
  407. //// factory_id = factory_id,
  408. //// tenant_id = tenant_id
  409. //// };
  410. //// order.GenerateNewId();
  411. //// ItemsAdd.Add(order);
  412. //// }
  413. //// else
  414. //// {
  415. //// saleorder.bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString();
  416. //// saleorder.custom_id = custom_id;
  417. //// saleorder.custom_name = ItemMasterDS.Tables[0].Rows[i]["CustomName"].ToString();
  418. //// saleorder.custom_no = ItemMasterDS.Tables[0].Rows[i]["Cust"].ToString();
  419. //// //custom_level = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? "外购" : "自制",
  420. //// saleorder.date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"];
  421. //// saleorder.rdate = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"];
  422. //// saleorder.urgent = (int?)ItemMasterDS.Tables[0].Rows[i]["Sequence"];
  423. //// saleorder.currency = ItemMasterDS.Tables[0].Rows[i]["Curr"].ToString() == "RMB" ? 1 : 0;
  424. //// saleorder.exchange_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"];
  425. //// //biller = ItemMasterDS.Tables[0].Rows[i]["NetWeightUM"].ToString(),
  426. //// //emp_no = (decimal)ItemMasterDS.Tables[0].Rows[i]["Length"],
  427. //// saleorder.emp_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString();
  428. //// //auditor = (decimal)ItemMasterDS.Tables[0].Rows[i]["Height"],
  429. //// //audit_date = ItemMasterDS.Tables[0].Rows[i]["PurMfg"].ToString() == "P" ? 1 : 0,
  430. //// //status = 1,
  431. //// //closed = "",
  432. //// //op_time = 1,
  433. //// saleorder.bill_from = "";
  434. //// saleorder.project_name = ItemMasterDS.Tables[0].Rows[i]["ProjectName"].ToString();
  435. //// saleorder.project_code = ItemMasterDS.Tables[0].Rows[i]["Project"].ToString();
  436. //// saleorder.out_stock_type = 1;//TODO
  437. //// //sale_dept_id = "",
  438. //// //sale_dept_name = 1,
  439. //// //sale_dept_code = 1,
  440. //// //create_dept = 1
  441. //// ItemsUpdate.Add(saleorder);
  442. //// }
  443. //// }
  444. //// //_businessDbContext.crm_seorder.Delete();
  445. //// _businessDbContext.crm_seorder.BulkInsert(ItemsAdd);
  446. //// _businessDbContext.crm_seorder.BulkUpdate(ItemsUpdate);
  447. //// }
  448. ////}
  449. //////同步销售订单明细
  450. ////public void SyncSalesOrdMasterEntry()
  451. ////{
  452. //// var saleOrderEntryList = _mysql_crm_seorderentry.GetListAsync().Result;
  453. //// var saleOrderList = _mysql_crm_seorder.GetListAsync().Result;
  454. //// var ItemMasterDS = _repository.SelectDataBaseBySql("SELECT A.SalesOrd,A.Line,C.Descr,C.Descr1,A.ItemNum,A.UM,A.QtyOrded,A.Price,A.Disc,A.RequiredDate,A.Remark,B.CustPO,A.CustItem,A.Status,A.QtyShipped,A.QtyReturned,B.Contract,A.Domain from SalesOrdDetail A INNER JOIN SalesOrdMaster B On A.SalesOrd=B.SalesOrd and A.[Domain]=B.[Domain] INNER JOIN ItemMaster C on A.ItemNum=C.ItemNum and A.[Domain]=C.[Domain]", "SalesOrdDetail");
  455. //// List<crm_seorderentry> ItemsAdd = new List<crm_seorderentry>();
  456. //// List<crm_seorderentry> ItemsUpdate = new List<crm_seorderentry>();
  457. //// if (ItemMasterDS != null && ItemMasterDS.Tables.Count > 0 && ItemMasterDS.Tables[0].Rows.Count > 0)
  458. //// {
  459. //// for (int i = 0; i < ItemMasterDS.Tables[0].Rows.Count; i++)
  460. //// {
  461. //// long domain = Convert.ToInt64(ItemMasterDS.Tables[0].Rows[i]["Domain"].ToString());
  462. //// long factory_id = domain % 1000;
  463. //// long tenant_id = domain - factory_id;
  464. //// var bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString();
  465. //// var seorder = saleOrderList.Find(a => a.bill_no == bill_no && a.factory_id == factory_id && a.tenant_id == tenant_id);
  466. //// long? seorder_id = seorder is null ? seorder.Id : null;
  467. //// var saleorderentry = saleOrderEntryList.Find(x => x.bill_no == bill_no && x.tenant_id == factory_id && x.factory_id == tenant_id);
  468. //// if (saleorderentry is null)
  469. //// {
  470. //// var entry = new crm_seorderentry
  471. //// {
  472. //// seorder_id = seorder_id,
  473. //// bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString(),
  474. //// entry_seq = (int?)ItemMasterDS.Tables[0].Rows[i]["Line"],
  475. //// item_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString(),
  476. //// item_name = ItemMasterDS.Tables[0].Rows[i]["Descr"].ToString(),
  477. //// specification = ItemMasterDS.Tables[0].Rows[i]["Descr1"].ToString(),
  478. //// //urgent = (int?)ItemMasterDS.Tables[0].Rows[i]["PLPriority"],
  479. //// bom_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString(),
  480. //// unit = ItemMasterDS.Tables[0].Rows[i]["UM"].ToString(),
  481. //// qty = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyOrded"],
  482. //// //price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"],
  483. //// //tax_price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  484. //// //tax_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  485. //// amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"],
  486. //// //discount_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  487. //// discount_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Disc"],
  488. //// //total_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  489. //// plan_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"],
  490. //// //date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
  491. //// //planner_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  492. //// //planner_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  493. //// remark = ItemMasterDS.Tables[0].Rows[i]["Remark"].ToString(),
  494. //// //soure_bill_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  495. //// custom_order_bill_no = ItemMasterDS.Tables[0].Rows[i]["CustPO"].ToString(),
  496. //// //custom_order_entryid = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  497. //// //sys_capacity_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
  498. //// //adjust_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
  499. //// //mrp_closed = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
  500. //// custom_order_itemno = ItemMasterDS.Tables[0].Rows[i]["CustItem"].ToString(),
  501. //// state = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["Status"]),//TODO
  502. //// deliver_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyShipped"],
  503. //// returned_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyReturned"],
  504. //// //se_reject_reason = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  505. //// //out_stock_type = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  506. //// //is_checked = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
  507. //// //sys_material_date = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
  508. //// contract_no = ItemMasterDS.Tables[0].Rows[i]["Contract"].ToString(),
  509. //// //create_dept = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"])
  510. //// factory_id = factory_id,
  511. //// tenant_id = tenant_id
  512. //// };
  513. //// entry.GenerateNewId();
  514. //// ItemsAdd.Add(entry);
  515. //// }
  516. //// else
  517. //// {
  518. //// saleorderentry.seorder_id = seorder_id;
  519. //// saleorderentry.bill_no = ItemMasterDS.Tables[0].Rows[i]["SalesOrd"].ToString();
  520. //// saleorderentry.entry_seq = (int?)ItemMasterDS.Tables[0].Rows[i]["Line"];
  521. //// saleorderentry.item_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString();
  522. //// saleorderentry.item_name = ItemMasterDS.Tables[0].Rows[i]["Descr"].ToString();
  523. //// saleorderentry.specification = ItemMasterDS.Tables[0].Rows[i]["Descr1"].ToString();
  524. //// //urgent = (int?)ItemMasterDS.Tables[0].Rows[i]["PLPriority"],
  525. //// saleorderentry.bom_number = ItemMasterDS.Tables[0].Rows[i]["ItemNum"].ToString();
  526. //// saleorderentry.unit = ItemMasterDS.Tables[0].Rows[i]["UM"].ToString();
  527. //// saleorderentry.qty = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyOrded"];
  528. //// //price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"],
  529. //// //tax_price = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  530. //// //tax_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  531. //// saleorderentry.amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Price"];
  532. //// //discount_rate = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  533. //// saleorderentry.discount_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["Disc"];
  534. //// //total_amount = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  535. //// saleorderentry.plan_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["RequiredDate"];
  536. //// //date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
  537. //// //planner_name = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  538. //// //planner_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  539. //// saleorderentry.remark = ItemMasterDS.Tables[0].Rows[i]["Remark"].ToString();
  540. //// //soure_bill_no = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  541. //// saleorderentry.custom_order_bill_no = ItemMasterDS.Tables[0].Rows[i]["CustPO"].ToString();
  542. //// //custom_order_entryid = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  543. //// //sys_capacity_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
  544. //// //adjust_date = (DateTime?)ItemMasterDS.Tables[0].Rows[i]["OrdDate"],
  545. //// //mrp_closed = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
  546. //// saleorderentry.custom_order_itemno = ItemMasterDS.Tables[0].Rows[i]["CustItem"].ToString();
  547. //// saleorderentry.state = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["Status"]);//TODO
  548. //// //rnumber = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
  549. //// //deliver_notice_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["ExchRate"],
  550. //// saleorderentry.deliver_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyShipped"];
  551. //// saleorderentry.returned_count = (decimal?)ItemMasterDS.Tables[0].Rows[i]["QtyReturned"];
  552. //// //se_reject_reason = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  553. //// //out_stock_type = ItemMasterDS.Tables[0].Rows[i]["Salesperson1"].ToString(),
  554. //// //is_checked = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
  555. //// //sys_material_date = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"]),
  556. //// saleorderentry.contract_no = ItemMasterDS.Tables[0].Rows[i]["Contract"].ToString();
  557. //// //create_dept = Convert.ToBoolean(ItemMasterDS.Tables[0].Rows[i]["OrdDate"])
  558. //// ItemsUpdate.Add(saleorderentry);
  559. //// }
  560. //// }
  561. //// //_businessDbContext.crm_seorder.Delete();
  562. //// _businessDbContext.crm_seorderentry.BulkInsert(ItemsAdd);
  563. //// _businessDbContext.crm_seorderentry.BulkUpdate(ItemsUpdate);
  564. //// }
  565. ////}
  566. //同步物料
  567. public void SyncItemMaster()
  568. {
  569. //bool isAll = true;//是否同步所有物料
  570. var ic_itemList = _mysql_ic_item.GetListAsync().Result;
  571. List<ItemMaster> custList = new List<ItemMaster>();
  572. custList = _itemMaster.Select(a => a.IsActive);
  573. List<ic_item> ItemsAdd = new List<ic_item>();
  574. List<ic_item_stock> stockAdd = new List<ic_item_stock>();
  575. List<ic_item> ItemsUpd = new List<ic_item>();
  576. List<srm_purchase> srm_purchaseAdd = new List<srm_purchase>();
  577. if (custList != null && custList.Count > 0)
  578. {
  579. for (int i = 0; i < custList.Count; i++)
  580. {
  581. var ic_item = ic_itemList.Find(x => x.number == custList[i].ItemNum);
  582. int erpcls = 0;
  583. string erpclsText = "配置类";
  584. long itemId = help.NextId();
  585. if (custList[i].PurMfg == "L")
  586. {
  587. if (custList[i].EMTType == "50")
  588. {
  589. erpcls = 4;
  590. erpclsText = "虚拟";
  591. }
  592. else
  593. {
  594. erpcls = 1;
  595. erpclsText = "自制";
  596. }
  597. }
  598. else
  599. {
  600. if (custList[i].EMTType == "30")
  601. {
  602. erpcls = 2;
  603. erpclsText = "委外";
  604. }
  605. else
  606. {
  607. erpcls = 3;
  608. erpclsText = "外购";
  609. }
  610. }
  611. if (ic_item == null)
  612. {
  613. ItemsAdd.Add(new ic_item(itemId)
  614. {
  615. number = custList[i].ItemNum, //物料编码
  616. name = custList[i].Descr, //物料名称
  617. model = custList[i].Descr1,//规格型号
  618. fversion = custList[i].Rev,//版本号
  619. erp_cls = erpcls,//物料属性
  620. erp_cls_name = erpclsText,//物料属性名称
  621. unit = custList[i].UM,//单位
  622. item_level = 0,//物料等级
  623. source = "",//来源
  624. iskeyitem = custList[i].IsMainMas ? 1 : 0,//是否关键件
  625. net_weight = (decimal)custList[i].NetWeight,//净重
  626. maund = custList[i].NetWeightUM,//重量单位
  627. length = (decimal)custList[i].Length,//长度
  628. width = (decimal)custList[i].Width,//宽度
  629. height = (decimal)custList[i].Height,//高度
  630. allowpur = custList[i].PurMfg == "P" ? 1 : 0,//允许采购
  631. allowsale = 1,//允许销售
  632. allowmanu = custList[i].PurMfg == "L" ? 1 : 0,//允许生产
  633. allowout = 1,//允许委外
  634. allowbatch = custList[i].LotSerialControl ? 1 : 0,//批号管理
  635. allowserial = custList[i].LotSerialControl ? 1 : 0,//序列号管理
  636. photo = "",//图片
  637. enable_warning = 1,//启用预警
  638. factory_id = long.Parse(custList[i].Domain),
  639. company_id = 1000,
  640. tenant_id = 1000,
  641. IsDeleted = false,
  642. clean_leadtime = custList[i].MFGMTTR,
  643. is_clean = custList[i].IssuePolicy ? 1 : 0,
  644. batch_manager = custList[i].LotSerialControl ? 1 : 0,
  645. minorderqty = custList[i].MinOrd,
  646. minpackqty = 1,
  647. ordissu_days = 1,
  648. transportation_leadtime = 3,
  649. stock_leadtime = 1,
  650. production_leadtime = 4,
  651. order_leadtime = 4,
  652. fix_leadtime = 1,
  653. order_inter_val = 1,
  654. lead_time = 1,
  655. bat_change_economy = 1,
  656. total_tqq = 1,
  657. order_point = 1,
  658. secinv = 1,
  659. secinv_ratio = 1,
  660. self_inspection_date = custList[i].InsLT,
  661. Warehousing_date = 1,
  662. Shipping_date = 3,
  663. PurLT = custList[i].PurLT
  664. });;
  665. ic_item_stock addStock = new ic_item_stock();
  666. addStock.GenerateNewId(help.NextId());
  667. addStock.icitem_id = itemId;
  668. addStock.icitem_number = custList[i].ItemNum; //物料编码
  669. addStock.icitem_name = custList[i].Descr; //物料名称
  670. addStock.sqty = 0;
  671. addStock.quantity_in_transit = 0;
  672. addStock.fversion = "";
  673. addStock.factory_id = long.Parse(custList[i].Domain);
  674. addStock.company_id = 1000;
  675. addStock.tenant_id = 1000;
  676. addStock.create_time = DateTime.Now;
  677. addStock.update_time = DateTime.Now;
  678. addStock.create_by_name = "admin";
  679. addStock.update_by_name = "admin";
  680. stockAdd.Add(addStock);
  681. /*srm_purchaseAdd.Add(new srm_purchase(help.NextId())
  682. {
  683. icitem_id = itemId,
  684. icitem_name = custList[i].Descr,
  685. sourcelist_number = "HYQD12064",
  686. supplier_id = 10101000051,
  687. supplier_number = "",
  688. supplier_name = "广州市伟正金属构件有限公司",
  689. purchgroup = "",
  690. purcher = "",
  691. purchase_unit = "",
  692. netpurchase_price = 1,
  693. taxrate = 0.13m,
  694. currency_type = 1,
  695. order_rector_name = "",
  696. order_rector_num = "",
  697. factory_code = "",
  698. order_dept = "",
  699. order_price = 13,
  700. sale_price = 130,
  701. qty_min = 10,
  702. batch_append_qty = 10,
  703. factory_id = 1001,
  704. tenant_id = 1000,
  705. IsDeleted = false
  706. });*/
  707. }
  708. else
  709. {
  710. ic_item.name = custList[i].Descr;
  711. ic_item.model = custList[i].Descr1;//规格型号
  712. ic_item.fversion = custList[i].Rev;//版本号
  713. ic_item.erp_cls = erpcls;//物料属性
  714. ic_item.erp_cls_name = erpclsText;//物料属性名称
  715. ic_item.unit = custList[i].UM;//单位
  716. ic_item.clean_leadtime = custList[i].MFGMTTR;
  717. ic_item.PurLT = custList[i].PurLT;
  718. ItemsUpd.Add(ic_item);
  719. }
  720. }
  721. }
  722. _businessDbContext.BulkInsert(ItemsAdd);
  723. _businessDbContext.BulkInsert(stockAdd);
  724. _businessDbContext.ic_item.UpdateRange(ItemsUpd);
  725. }
  726. public void SyncBom()
  727. {
  728. var ic_bomList = _mysql_ic_bom.GetListAsync().Result;
  729. var ic_itemList = _mysql_ic_item.GetListAsync().Result;
  730. var ic_bomchildList = _mysql_ic_bom_child.GetListAsync().Result;
  731. List<ProductStructureMaster> wmsBomList = _productStructureMaster.Select(a => a.IsActive);
  732. List<ic_bom> ItemsAdd = new List<ic_bom>();
  733. List<ic_bom_child> childItemsAdd = new List<ic_bom_child>();
  734. List<ic_bom_child> childItemsUpd = new List<ic_bom_child>();
  735. if (wmsBomList != null && wmsBomList.Count > 0)
  736. {
  737. var ItemMasterDS = wmsBomList.Select(a => a.ParentItem).Distinct().ToList();
  738. foreach (var c in ItemMasterDS)
  739. {
  740. var icbom = ic_bomList.Find(x => x.item_number == c);
  741. var ItemList = wmsBomList.Where(a => a.ParentItem == c);
  742. var item = ic_itemList.Find(a => a.number == c);
  743. if (item == null)
  744. {
  745. continue;
  746. }
  747. if (icbom == null)
  748. {
  749. long domain = Convert.ToInt64(ItemList.First().Domain);
  750. long factory_id = domain % 8010;
  751. //long tenant_id = domain - factory_id;
  752. var bom = new ic_bom(help.NextId())
  753. {
  754. bom_number = c,
  755. icitem_id = item.Id,
  756. item_name = item.name,
  757. item_number = c,
  758. version = ItemList.First().Refs,
  759. factory_id = item.factory_id,
  760. company_id = item.company_id,
  761. tenant_id = item.company_id,
  762. IsDeleted = false,
  763. use_status = 1
  764. };
  765. ItemsAdd.Add(bom);
  766. foreach (var child in ItemList)
  767. {
  768. var itemchild = ic_itemList.Find(a => a.number == child.ComponentItem);
  769. if (itemchild == null) { continue; }
  770. var bomchild = new ic_bom_child(help.NextId())
  771. {
  772. bom_id = bom.Id,
  773. bom_number = bom.bom_number,
  774. icitem_id = itemchild == null ? long.MinValue : itemchild.Id,
  775. item_number = child.ComponentItem,
  776. item_name = itemchild == null ? "" : itemchild.name,
  777. unit = child.UM,
  778. qty = child.Qty,
  779. entryid = child.SequenceNum,
  780. erp_cls = itemchild == null ? 2 : itemchild.erp_cls,
  781. begin_day = child.StartEff,
  782. end_day = child.EndEff,
  783. child_num = child.SequenceNum,
  784. version = child.Refs,
  785. factory_id = item.factory_id,
  786. company_id = item.company_id,
  787. tenant_id = item.company_id,
  788. IsDeleted = false,
  789. Op = child.Op,
  790. use_status = 1,
  791. scrap = child.Scrap,
  792. wastage = child.QtyConsumed
  793. };
  794. childItemsAdd.Add(bomchild);
  795. }
  796. }
  797. else
  798. {
  799. foreach (var child in ItemList)
  800. {
  801. var itemchild = ic_itemList.Find(a => a.number == child.ComponentItem);
  802. if (itemchild == null) { continue; }
  803. var icbomchild = ic_bomchildList.Find(s => s.bom_number == c && s.item_number == child.ComponentItem);
  804. if (icbomchild == null)
  805. {
  806. var bomchild = new ic_bom_child(help.NextId())
  807. {
  808. bom_id = icbom.Id,
  809. bom_number = icbom.bom_number,
  810. icitem_id = itemchild == null ? long.MinValue : itemchild.Id,
  811. item_number = child.ComponentItem,
  812. item_name = itemchild == null ? "" : itemchild.name,
  813. unit = child.UM,
  814. qty = child.Qty,
  815. entryid = child.SequenceNum,
  816. erp_cls = itemchild == null ? 2 : itemchild.erp_cls,
  817. begin_day = child.StartEff,
  818. end_day = child.EndEff,
  819. child_num = child.SequenceNum,
  820. version = child.Refs,
  821. factory_id = item.factory_id,
  822. company_id = item.company_id,
  823. tenant_id = item.company_id,
  824. IsDeleted = false,
  825. Op = child.Op,
  826. use_status = 1,
  827. scrap = child.Scrap,
  828. wastage = child.QtyConsumed
  829. };
  830. childItemsAdd.Add(bomchild);
  831. }
  832. else
  833. {
  834. icbomchild.qty = child.Qty;
  835. icbomchild.erp_cls = itemchild == null ? 2 : itemchild.erp_cls;
  836. icbomchild.begin_day = child.StartEff;
  837. icbomchild.end_day = child.EndEff;
  838. icbomchild.version = child.Refs;
  839. icbomchild.factory_id = item.factory_id;
  840. icbomchild.company_id = item.company_id;
  841. icbomchild.tenant_id = item.company_id;
  842. icbomchild.Op = child.Op;
  843. icbomchild.scrap = child.Scrap;
  844. icbomchild.wastage = child.QtyConsumed;
  845. childItemsUpd.Add(icbomchild);
  846. }
  847. }
  848. }
  849. }
  850. _businessDbContext.BulkInsert(ItemsAdd);
  851. _businessDbContext.BulkInsert(childItemsAdd);
  852. _businessDbContext.ic_bom_child.UpdateRange(childItemsUpd);
  853. }
  854. }
  855. public string DoProductScheduleJob()
  856. {
  857. try
  858. {
  859. _productionScheduleAppService.DoExt();
  860. }
  861. catch (Exception ex)
  862. {
  863. return ex.Message;
  864. }
  865. return "任务执行成功";
  866. }
  867. }
  868. }