SyncDOPAppService.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using Abp.Application.Services;
  2. using Abp.Dependency;
  3. using Business.Core.Utilities;
  4. using Business.Dto;
  5. using Business.Model.WMS;
  6. using Newtonsoft.Json;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Threading.Tasks;
  10. using Volo.Abp.MultiTenancy;
  11. using Volo.Abp.Uow;
  12. using IUnitOfWorkManager = Volo.Abp.Uow.IUnitOfWorkManager;
  13. namespace Business.DOP
  14. {
  15. //DOP
  16. public class SyncDOPAppService : ApplicationService, ISyncDOPAppService, ITransientDependency
  17. {
  18. #region 服务
  19. /// <summary>
  20. /// 工单
  21. /// </summary>
  22. //private readonly ISqlRepository<PlatformSpecificationComparison> _PlatformSpecificationComparison;
  23. /// <summary>
  24. /// 平台规格型号对照表
  25. /// </summary>
  26. private readonly Volo.Abp.Domain.Repositories.IRepository<PlatformSpecificationComparison, long> _PlatformSpecificationComparison;
  27. /// <summary>
  28. /// 平台库存表
  29. /// </summary>
  30. private readonly Volo.Abp.Domain.Repositories.IRepository<PlatformInventory, long> _PlatformInventory;
  31. /// <summary>
  32. /// 雪花算法
  33. /// </summary>
  34. SnowFlake snowFlake = new SnowFlake();
  35. /// <summary>
  36. /// 事务
  37. /// </summary>
  38. private readonly IUnitOfWorkManager _unitOfWorkManager;
  39. #endregion
  40. #region 构造函数
  41. /// <summary>
  42. /// 构造函数
  43. /// </summary>
  44. public SyncDOPAppService(
  45. Volo.Abp.Domain.Repositories.IRepository<PlatformSpecificationComparison, long> PlatformSpecificationComparison,
  46. Volo.Abp.Domain.Repositories.IRepository<PlatformInventory, long> PlatformInventory,
  47. IUnitOfWorkManager unitOfWorkManager,
  48. ICurrentTenant currentTenant
  49. )
  50. {
  51. _PlatformSpecificationComparison = PlatformSpecificationComparison;
  52. _PlatformInventory = PlatformInventory;
  53. _unitOfWorkManager = unitOfWorkManager;
  54. }
  55. #endregion
  56. /// <summary>
  57. /// 海王平台成品监控
  58. /// </summary>
  59. /// <returns></returns>
  60. /// <exception cref="NotImplementedException"></exception>
  61. public async Task<string> SyncPlatformFinishedProductMonitoringHW(List<PlatformInventoryDto> platformInventoryDtoList)
  62. {
  63. var ret = SavePlatformFinishedProductMonitoringAsync(platformInventoryDtoList, 1);
  64. return await ret;
  65. }
  66. /// <summary>
  67. /// 国科平台成品监控
  68. /// </summary>
  69. /// <returns></returns>
  70. /// <exception cref="NotImplementedException"></exception>
  71. public async Task<string> SyncPlatformFinishedProductMonitoringGK(List<PlatformInventoryDto> platformInventoryDtoList)
  72. {
  73. var ret = SavePlatformFinishedProductMonitoringAsync(platformInventoryDtoList, 2);
  74. return await ret;
  75. }
  76. /// <summary>
  77. /// 保存库存信息
  78. /// </summary>
  79. /// <param name="platformInventoryDtoList"></param>
  80. /// <param name="type">1海王,2国科</param>
  81. public async Task<string> SavePlatformFinishedProductMonitoringAsync(List<PlatformInventoryDto> platformInventoryDtoList, int type)
  82. {
  83. if (platformInventoryDtoList.Count == 0)
  84. {
  85. return JsonConvert.SerializeObject("成品库存为空!");
  86. }
  87. List<PlatformInventory> platformInventoryInsert = new List<PlatformInventory>();
  88. List<PlatformInventory> platformInventoryDel;
  89. if (type == 1)
  90. {
  91. platformInventoryDel = _PlatformInventory.GetListAsync(x => x.Code == "HW0001").Result;
  92. }
  93. else
  94. {
  95. platformInventoryDel = _PlatformInventory.GetListAsync(x => x.Code == "HW0002").Result;
  96. }
  97. foreach (var item in platformInventoryDtoList)
  98. {
  99. PlatformInventory platformInventory = new PlatformInventory();
  100. platformInventory.GenerateNewId(snowFlake.NextId());
  101. platformInventory.Location = item.Location;
  102. platformInventory.SpecificationModel = item.SpecificationModel;
  103. platformInventory.BatchNumber = item.BatchNumber;
  104. platformInventory.InventoryQuantity = item.InventoryQuantity;
  105. platformInventory.PeriodOfValidity = item.PeriodOfValidity;
  106. if (type == 1)
  107. {
  108. platformInventory.Code = "HW0001";
  109. }
  110. else
  111. {
  112. platformInventory.Code = "HW0002";
  113. }
  114. platformInventoryInsert.Add(platformInventory);
  115. }
  116. using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
  117. {
  118. try
  119. {
  120. await _PlatformInventory.DeleteManyAsync(platformInventoryDel);
  121. await _PlatformInventory.InsertManyAsync(platformInventoryInsert);
  122. await unitOfWork.CompleteAsync();
  123. }
  124. catch (Exception e)
  125. {
  126. new NLogHelper("SyncDOPAppService").WriteLog("PrMerge", "接口获取失败:" + e.Message);
  127. unitOfWork.Dispose();
  128. return JsonConvert.SerializeObject(e.Message);
  129. }
  130. }
  131. return JsonConvert.SerializeObject("ok");
  132. }
  133. }
  134. }