基础服务api
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

184 lines
7.5 KiB

  1. using BPA.SAAS.Manage.Application.Device.Dtos.Device;
  2. using BPA.SAAS.Manage.Application.Device.Dtos.WarehouseTemplate;
  3. using BPA.SAAS.Manage.Application.Device.Interface;
  4. using BPA.SAAS.Manage.Comm.Enum;
  5. using BPA.SAAS.Manage.Core.Base;
  6. using BPA.SAAS.Manage.Core.Device;
  7. using BPA.SAAS.Manage.Core.Product;
  8. using NPOI.XSSF.UserModel;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace BPA.SAAS.Manage.Application.Device.Services
  15. {
  16. public class WarehouseTemplateService : IWarehouseTemplateService, ITransient
  17. {
  18. ISqlSugarClient _db;
  19. public WarehouseTemplateService(ISqlSugarClient db)
  20. {
  21. _db = db;
  22. }
  23. public async Task<PageUtil> GetWarehouseTemplatePage(WarehouseTemplateQueryInputDto inputDto)
  24. {
  25. var total = new RefAsync<int>();
  26. var data = await _db.Queryable<BPA_WarehouseTemplate,BPA_DeviceInfo,BPA_ProductVesion>((a,b,c) => new JoinQueryInfos(JoinType.Left,a.DeviceId==b.Id, JoinType.Left, b.ProductVersionId == c.Id))
  27. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.TemplateName), (a, b, c) => a.TemplateName.Contains(inputDto.TemplateName))
  28. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.DeviceName), (a, b, c) => a.DeviceId.Contains(inputDto.DeviceName))
  29. .Select((a,b,c)=>new WarehouseTemplateView
  30. {
  31. Id=a.Id,
  32. DeviceId=a.DeviceId,
  33. DeviceName=b.DeviceName,
  34. TemplateName =a.TemplateName,
  35. CreateAt =a.CreateAt,
  36. ProductNumber=c.ProductNumber,
  37. ProductUrl=c.ProductUrl
  38. })
  39. .Mapper(x =>
  40. {
  41. x.WarehousePostion= _db.Queryable <BPA_WarehousePostion>().Where(t=>t.TemplateId==x.Id).ToList();
  42. })
  43. .OrderBy(a => a.CreateAt, OrderByType.Desc)
  44. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  45. return new PageUtil()
  46. {
  47. Data = data,
  48. Total = total
  49. };
  50. }
  51. public async Task<List<WarehouseTemplateView>> GetWarehouseTemplateList(string deviceId)
  52. {
  53. var total = new RefAsync<int>();
  54. var data = await _db.Queryable<BPA_WarehouseTemplate, BPA_DeviceInfo, BPA_ProductVesion>((a, b, c) => new JoinQueryInfos(JoinType.Left, a.DeviceId == b.Id, JoinType.Left, b.ProductVersionId == c.Id))
  55. .WhereIF(!string.IsNullOrWhiteSpace(deviceId), (a, b, c) => a.DeviceId.Contains(deviceId))
  56. .Select((a, b, c) => new WarehouseTemplateView
  57. {
  58. Id = a.Id,
  59. DeviceId = a.DeviceId,
  60. DeviceName = b.DeviceName,
  61. TemplateName = a.TemplateName,
  62. CreateAt = a.CreateAt,
  63. ProductNumber = c.ProductNumber,
  64. ProductUrl = c.ProductUrl
  65. })
  66. .Mapper(x =>
  67. {
  68. x.WarehousePostion = _db.Queryable<BPA_WarehousePostion>().Where(t => t.TemplateId == x.Id).ToList();
  69. })
  70. .OrderBy(a => a.CreateAt, OrderByType.Desc)
  71. .ToListAsync();
  72. return data;
  73. }
  74. /// <summary>
  75. /// 新增
  76. /// </summary>
  77. /// <returns></returns>
  78. public async Task<bool> AddWarehouseTemplate(WarehouseTemplatDto inputDto)
  79. {
  80. try
  81. {
  82. _db.Ado.BeginTran();
  83. var check = _db.Queryable<BPA_WarehouseTemplate>().Where(x => x.TemplateName == inputDto.TemplateName).Any();
  84. if (check) throw Oops.Oh("模板名称不能重复");
  85. var res = await _db.Insertable(new BPA_WarehouseTemplate
  86. {
  87. DeviceId = inputDto.DeviceId,
  88. TemplateName = inputDto.TemplateName,
  89. }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
  90. List<BPA_WarehousePostion> list = new();
  91. for (int i = 0; i < inputDto.WarehousePostionData.Count; i++)
  92. {
  93. var tem = new BPA_WarehousePostion
  94. {
  95. TemplateId = res.Id,
  96. Code = inputDto.WarehousePostionData[i].Code,
  97. BatchingId = inputDto.WarehousePostionData[i].BatchingId,
  98. };
  99. list.Add(tem);
  100. }
  101. var res1 = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
  102. _db.Ado.CommitTran();
  103. return true;
  104. }
  105. catch (Exception e)
  106. {
  107. _db.Ado.RollbackTran();
  108. throw Oops.Oh("添加失败,"+e.Message);
  109. }
  110. }
  111. /// <summary>
  112. /// 删除
  113. /// </summary>
  114. /// <param name="inputList"></param>
  115. /// <returns></returns>
  116. public async Task<bool> DeWarehouseTemplate(List<string> inputList)
  117. {
  118. try
  119. {
  120. _db.Ado.BeginTran();
  121. var datas = await _db.Queryable<BPA_WarehouseTemplate>()
  122. .Where(x => inputList.Contains(x.Id))
  123. .ToListAsync();
  124. var datas1 = await _db.Queryable<BPA_WarehousePostion>()
  125. .Where(x => inputList.Contains(x.TemplateId))
  126. .ToListAsync();
  127. _db.Deleteable(datas).ExecuteCommand();
  128. _db.Deleteable(datas1).ExecuteCommand();
  129. _db.Ado.CommitTran();
  130. return true;
  131. }
  132. catch (Exception)
  133. {
  134. _db.Ado.RollbackTran();
  135. throw Oops.Oh("删除失败");
  136. }
  137. }
  138. /// <summary>
  139. /// 修改
  140. /// </summary>
  141. /// <returns></returns>
  142. public async Task<bool> UpdateWarehouseTemplate(WarehouseTemplatDto inputDto)
  143. {
  144. try
  145. {
  146. _db.Ado.BeginTran();
  147. var model = _db.Queryable<BPA_WarehouseTemplate>().Where(x => x.Id == inputDto.Id).First();
  148. model.DeviceId= inputDto.DeviceId;
  149. model.TemplateName= inputDto.TemplateName;
  150. var res = await _db.Updateable(model).ExecuteCommandAsync();
  151. var warehousePostion = _db.Queryable<BPA_WarehousePostion>().Where(x => x.TemplateId == inputDto.Id).ToList();
  152. await _db.Deleteable(warehousePostion).ExecuteCommandAsync();
  153. List<BPA_WarehousePostion> list = new();
  154. for (int i = 0; i < inputDto.WarehousePostionData.Count; i++)
  155. {
  156. var tem = new BPA_WarehousePostion
  157. {
  158. TemplateId = inputDto.Id,
  159. Code = inputDto.WarehousePostionData[i].Code,
  160. BatchingId = inputDto.WarehousePostionData[i].BatchingId,
  161. };
  162. list.Add(tem);
  163. }
  164. var res1 = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
  165. _db.Ado.CommitTran();
  166. return true;
  167. }
  168. catch (Exception)
  169. {
  170. _db.Ado.RollbackTran();
  171. return false;
  172. }
  173. }
  174. }
  175. }