SystemJobAppService.cs 52 KB

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