SyncDOPAppService.cs 5.3 KB

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