SyncMySQLDataAppService.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using Business.Core.MongoDBHelper;
  2. using Business.Core.Utilities;
  3. using Business.Model.MES.IC;
  4. using Business.Model.SRM;
  5. using Business.Model.Tech;
  6. using Business.MongoModel.MES.IC;
  7. using Business.MongoModel.SRM;
  8. using Business.MongoModel.Tech;
  9. using System;
  10. using System.Collections.Generic;
  11. using Volo.Abp.Application.Services;
  12. using Volo.Abp.Domain.Repositories;
  13. namespace Business.SyncDataManagement
  14. {
  15. /// <summary>
  16. /// 同步mysql数据到mongodb
  17. /// </summary>
  18. public class SyncMySQLDataAppService : ApplicationService
  19. {
  20. #region 服务
  21. /// <summary>
  22. /// 物料bom
  23. /// </summary>
  24. private readonly IMongoDB<mo_ic_bom> _ic_bom;
  25. private IRepository<ic_bom, long> _mysql_ic_bom;
  26. /// <summary>
  27. /// 物料bom子表
  28. /// </summary>
  29. private readonly IMongoDB<mo_ic_bom_child> _ic_bom_child;
  30. private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
  31. /// <summary>
  32. /// 物料
  33. /// </summary>
  34. private readonly IMongoDB<mo_ic_item> _ic_item;
  35. private IRepository<ic_item, long> _mysql_ic_item;
  36. /// <summary>
  37. /// 替代群组
  38. /// </summary>
  39. private readonly IMongoDB<mo_ic_substitute> _ic_substitute;
  40. private IRepository<ic_substitute, long> _mysql_ic_substitute;
  41. /// <summary>
  42. /// 物料替代多群组
  43. /// </summary>
  44. private readonly IMongoDB<mo_ic_substitute_group> _ic_substitute_group;
  45. private IRepository<ic_substitute_group, long> _mysql_ic_substitute_group;
  46. /// <summary>
  47. /// 物料替代多群组明细
  48. /// </summary>
  49. private readonly IMongoDB<mo_ic_substitute_group_detail> _ic_substitute_group_detail;
  50. private IRepository<ic_substitute_group_detail, long> _mysql_ic_substitute_group_detail;
  51. /// <summary>
  52. /// 供应商
  53. /// </summary>
  54. private readonly IMongoDB<mo_srm_supplier> _srm_supplier;
  55. private IRepository<srm_supplier, long> _mysql_srm_supplier;
  56. /// <summary>
  57. /// 工艺路径
  58. /// </summary>
  59. private readonly IMongoDB<mo_mes_technique> _mes_technique;
  60. private IRepository<mes_technique, long> _mysql_mes_technique;
  61. /// <summary>
  62. /// 工序
  63. /// </summary>
  64. private readonly IMongoDB<mo_mes_process> _mes_process;
  65. private IRepository<mes_process, long> _mysql_mes_process;
  66. /// <summary>
  67. /// 工艺路径关联工序
  68. /// </summary>
  69. private readonly IMongoDB<mo_mes_tech_process> _mes_tech_process;
  70. private IRepository<mes_tech_process, long> _mysql_mes_tech_process;
  71. /// <summary>
  72. /// 物料采购报价单
  73. /// </summary>
  74. private readonly IMongoDB<mo_srm_purchase> _srm_purchase;
  75. private IRepository<srm_purchase, long> _mysql_srm_purchase;
  76. /// <summary>
  77. /// 雪花算法
  78. /// </summary>
  79. SnowFlake help = new SnowFlake();
  80. #endregion
  81. /// <summary>
  82. /// 构造函数
  83. /// </summary>
  84. public SyncMySQLDataAppService(
  85. IMongoDB<mo_ic_bom> ic_bom,
  86. IMongoDB<mo_ic_bom_child> ic_bom_child,
  87. IMongoDB<mo_ic_item> ic_item,
  88. IMongoDB<mo_ic_substitute> ic_substitute,
  89. IMongoDB<mo_ic_substitute_group> ic_substitute_group,
  90. IMongoDB<mo_ic_substitute_group_detail> ic_substitute_group_detail,
  91. IMongoDB<mo_srm_supplier> srm_supplier,
  92. IMongoDB<mo_mes_technique> mes_technique,
  93. IMongoDB<mo_mes_process> mes_process,
  94. IMongoDB<mo_mes_tech_process> mes_tech_process,
  95. IMongoDB<mo_srm_purchase> srm_purchase,
  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<ic_substitute, long> mysql_ic_substitute,
  100. IRepository<ic_substitute_group, long> mysql_ic_substitute_group,
  101. IRepository<ic_substitute_group_detail, long> mysql_ic_substitute_group_detail,
  102. IRepository<srm_supplier, long> mysql_srm_supplier,
  103. IRepository<mes_technique, long> mysql_mes_technique,
  104. IRepository<mes_process, long> mysql_mes_process,
  105. IRepository<mes_tech_process, long> mysql_mes_tech_process,
  106. IRepository<srm_purchase, long> mysql_srm_purchase
  107. )
  108. {
  109. _ic_bom= ic_bom;
  110. _ic_bom_child= ic_bom_child;
  111. _ic_item= ic_item;
  112. _ic_substitute= ic_substitute;
  113. _ic_substitute_group= ic_substitute_group;
  114. _ic_substitute_group_detail = ic_substitute_group_detail;
  115. _srm_supplier= srm_supplier;
  116. _mes_technique = mes_technique;
  117. _mes_process= mes_process;
  118. _mes_tech_process = mes_tech_process;
  119. _srm_purchase = srm_purchase;
  120. _mysql_ic_bom = mysql_ic_bom;
  121. _mysql_ic_bom_child= mysql_ic_bom_child;
  122. _mysql_ic_item= mysql_ic_item;
  123. _mysql_ic_substitute= mysql_ic_substitute;
  124. _mysql_ic_substitute_group= mysql_ic_substitute_group;
  125. _mysql_ic_substitute_group_detail= mysql_ic_substitute_group_detail;
  126. _mysql_srm_supplier= mysql_srm_supplier;
  127. _mysql_mes_technique= mysql_mes_technique;
  128. _mysql_mes_process= mysql_mes_process;
  129. _mysql_mes_tech_process= mysql_mes_tech_process;
  130. _mysql_srm_purchase = mysql_srm_purchase;
  131. }
  132. /// <summary>
  133. /// 同步基础数据到mongodb
  134. /// </summary>
  135. /// <returns></returns>
  136. /// <exception cref="NotImplementedException"></exception>
  137. public async void SyncBaseDataToMongoDB()
  138. {
  139. //物料采购报价单
  140. var srm_purchase = _mysql_srm_purchase.GetListAsync().Result;
  141. if (srm_purchase.Count > 0)
  142. {
  143. //先清空表数据
  144. await _srm_purchase.Delete(p => p.mysql_id != -1);
  145. var mosrm_purchase = ObjectMapper.Map<List<srm_purchase>, List<mo_srm_purchase>>(srm_purchase);
  146. mosrm_purchase.ForEach(s => s.id = help.NextId());
  147. await _srm_purchase.InsertMany(mosrm_purchase);
  148. }
  149. /*//同步物料BOM明细数据
  150. var icbom_childs = _mysql_ic_bom_child.GetListAsync().Result;
  151. if (icbom_childs.Count > 0)
  152. {
  153. //先清空表数据
  154. await _ic_bom_child.Delete(p => p.mysql_id != -1);
  155. var moIcbom_childs = ObjectMapper.Map<List<ic_bom_child>, List<mo_ic_bom_child>>(icbom_childs);
  156. moIcbom_childs.ForEach(s => s.id = help.NextId());
  157. //插入数据
  158. await _ic_bom_child.InsertMany(moIcbom_childs);
  159. }*/
  160. /*//同步物料Bom数据
  161. var icBoms = _mysql_ic_bom.GetListAsync().Result;
  162. if (icBoms.Count > 0)
  163. {
  164. //先清空表数据
  165. await _ic_bom.Delete(p => p.mysql_id != -1);
  166. var moIcBoms = ObjectMapper.Map<List<ic_bom>, List<mo_ic_bom>>(icBoms);
  167. moIcBoms.ForEach(s => s.id = help.NextId());
  168. //插入数据
  169. await _ic_bom.InsertMany(moIcBoms);
  170. }
  171. //同步物料BOM明细数据
  172. var icbom_childs = _mysql_ic_bom_child.GetListAsync().Result;
  173. if (icbom_childs.Count > 0)
  174. {
  175. //先清空表数据
  176. await _ic_bom_child.Delete(p => p.mysql_id != -1);
  177. var moIcbom_childs = ObjectMapper.Map<List<ic_bom_child>, List<mo_ic_bom_child>>(icbom_childs);
  178. moIcbom_childs.ForEach(s => s.id = help.NextId());
  179. //插入数据
  180. await _ic_bom_child.InsertMany(moIcbom_childs);
  181. }
  182. ////工厂物料明细表
  183. //var ic_factory_details = _mysql_ic_factory_details.GetListAsync().Result;
  184. //if (ic_factory_details.Count > 0)
  185. //{
  186. // //先清空表数据
  187. // await _ic_factory_details.Delete(p => p.mysql_id != -1);
  188. // var moIc_factory_details = ObjectMapper.Map<List<ic_factory_details>, List<mo_ic_factory_details>>(ic_factory_details);
  189. // moIc_factory_details.ForEach(s => s.id = help.NextId());
  190. // await _ic_factory_details.InsertMany(moIc_factory_details);
  191. //}
  192. //同步物料数据
  193. var icItems = _mysql_ic_item.GetListAsync().Result;
  194. if (icItems.Count > 0)
  195. {
  196. //先清空表数据
  197. await _ic_item.Delete(p => p.mysql_id != -1);
  198. var moIcItems = ObjectMapper.Map<List<ic_item>, List<mo_ic_item>>(icItems);
  199. moIcItems.ForEach(s => s.id = help.NextId());
  200. //插入数据
  201. await _ic_item.InsertMany(moIcItems);
  202. }
  203. //同步替代群组数据
  204. var subtitutes = _mysql_ic_substitute.GetListAsync().Result;
  205. if (subtitutes.Count > 0)
  206. {
  207. //先清空表数据
  208. await _ic_substitute.Delete(p => p.mysql_id != -1);
  209. var moSubtitutes = ObjectMapper.Map<List<ic_substitute>, List<mo_ic_substitute>>(subtitutes);
  210. moSubtitutes.ForEach(s => s.id = help.NextId());
  211. //插入数据
  212. await _ic_substitute.InsertMany(moSubtitutes);
  213. }
  214. //同步物料替代多群组数据
  215. var subAlls = _mysql_ic_substitute_group.GetListAsync().Result;
  216. if (subAlls.Count > 0)
  217. {
  218. //先清空表数据
  219. await _ic_substitute_group.Delete(p => p.mysql_id != -1);
  220. var moSubAlls = ObjectMapper.Map<List<ic_substitute_group>, List<mo_ic_substitute_group>>(subAlls);
  221. moSubAlls.ForEach(s => s.id = help.NextId());
  222. //插入数据
  223. await _ic_substitute_group.InsertMany(moSubAlls);
  224. }
  225. //同步物料替代多群组明细数据
  226. var subAllDtls = _mysql_ic_substitute_group_detail.GetListAsync().Result;
  227. if (subAllDtls.Count > 0)
  228. {
  229. //先清空表数据
  230. await _ic_substitute_group_detail.Delete(p => p.mysql_id != -1);
  231. var moSubAllDtls = ObjectMapper.Map<List<ic_substitute_group_detail>, List<mo_ic_substitute_group_detail>>(subAllDtls);
  232. moSubAllDtls.ForEach(s => s.id = help.NextId());
  233. //插入数据
  234. await _ic_substitute_group_detail.InsertMany(moSubAllDtls);
  235. }
  236. //同步供应商数据
  237. var suppliers = _mysql_srm_supplier.GetListAsync().Result;
  238. if (suppliers.Count > 0)
  239. {
  240. //先清空表数据
  241. await _srm_supplier.Delete(p => p.mysql_id != -1);
  242. var moSuppliers = ObjectMapper.Map<List<srm_supplier>, List<mo_srm_supplier>>(suppliers);
  243. moSuppliers.ForEach(s => s.id = help.NextId());
  244. //插入数据
  245. await _srm_supplier.InsertMany(moSuppliers);
  246. }
  247. //同步工艺路径数据
  248. var techs = _mysql_mes_technique.GetListAsync().Result;
  249. if (techs.Count > 0)
  250. {
  251. //先清空表数据
  252. await _mes_technique.Delete(p => p.mysql_id != -1);
  253. var moTechs = ObjectMapper.Map<List<mes_technique>, List<mo_mes_technique>>(techs);
  254. moTechs.ForEach(s => s.id = help.NextId());
  255. //插入数据
  256. await _mes_technique.InsertMany(moTechs);
  257. }
  258. //同步工序数据
  259. var processes = _mysql_mes_process.GetListAsync().Result;
  260. if (suppliers.Count > 0)
  261. {
  262. //先清空表数据
  263. await _mes_process.Delete(p => p.mysql_id != -1);
  264. var moProcesses = ObjectMapper.Map<List<mes_process>, List<mo_mes_process>>(processes);
  265. moProcesses.ForEach(s => s.id = help.NextId());
  266. //插入数据
  267. await _mes_process.InsertMany(moProcesses);
  268. }
  269. //同步工艺关联工序数据
  270. var tech_procs = _mysql_mes_tech_process.GetListAsync().Result;
  271. if (tech_procs.Count > 0)
  272. {
  273. //先清空表数据
  274. await _mes_tech_process.Delete(p => p.mysql_id != -1);
  275. var moTech_procs = ObjectMapper.Map<List<mes_tech_process>, List<mo_mes_tech_process>>(tech_procs);
  276. moTech_procs.ForEach(s => s.id = help.NextId());
  277. //插入数据
  278. await _mes_tech_process.InsertMany(moTech_procs);
  279. }
  280. ////物料采购计划表
  281. //var ic_plan = _mysql_ic_plan.GetListAsync().Result;
  282. //if (ic_plan.Count > 0)
  283. //{
  284. // //先清空表数据
  285. // await _ic_plan.Delete(p => p.mysql_id != -1);
  286. // var moIc_plan = ObjectMapper.Map<List<ic_plan>, List<mo_ic_plan>>(ic_plan);
  287. // moIc_plan.ForEach(s => s.id = help.NextId());
  288. // await _ic_plan.InsertMany(moIc_plan);
  289. //}
  290. //物料采购报价单
  291. var srm_purchase = _mysql_srm_purchase.GetListAsync().Result;
  292. if (srm_purchase.Count > 0)
  293. {
  294. //先清空表数据
  295. await _srm_purchase.Delete(p => p.mysql_id != -1);
  296. var mosrm_purchase = ObjectMapper.Map<List<srm_purchase>, List<mo_srm_purchase>>(srm_purchase);
  297. mosrm_purchase.ForEach(s => s.id = help.NextId());
  298. await _srm_purchase.InsertMany(mosrm_purchase);
  299. }*/
  300. }
  301. }
  302. }