基础服务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.
 
 

144 lines
5.4 KiB

  1. using BPA.SAAS.Manage.Application.Device.Dtos.Device;
  2. using BPA.SAAS.Manage.Application.Device.Dtos.DeviceVesion;
  3. using BPA.SAAS.Manage.Application.Device.Interface;
  4. using BPA.SAAS.Manage.Comm.Const;
  5. using BPA.SAAS.Manage.Comm.Enum;
  6. using BPA.SAAS.Manage.Core.Base;
  7. using BPA.SAAS.Manage.Core.Product;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace BPA.SAAS.Manage.Application.Device.Services
  14. {
  15. public class ProductService : IProductService, ITransient
  16. {
  17. ISqlSugarClient _db;
  18. public ProductService(ISqlSugarClient db)
  19. {
  20. _db=db;
  21. }
  22. /// <summary>
  23. /// 分页查询
  24. /// </summary>
  25. /// <param name="inputDto"></param>
  26. /// <returns></returns>
  27. public async Task<PageUtil> GetProductPage(ProductQueryInputDto inputDto)
  28. {
  29. var total = new RefAsync<int>();
  30. var data = await _db.Queryable<BPA_Product>().Where((x) => x.IsDeleted == 0)
  31. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Name), x => x.Name.Contains(inputDto.Name))
  32. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Key), x => x.Key.Contains(inputDto.Key))
  33. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Code), x => x.Code.Contains(inputDto.Code))
  34. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Remark), x => x.Remark.Contains(inputDto.Remark))
  35. .OrderBy(x => x.CreateAt, OrderByType.Desc)
  36. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  37. return new PageUtil()
  38. {
  39. Data = data,
  40. Total = total
  41. };
  42. }
  43. /// <summary>
  44. /// 查询列表
  45. /// </summary>
  46. /// <returns></returns>
  47. public async Task<List<BPA_Product>> GetProductList()
  48. {
  49. var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value;
  50. var data = await _db.Queryable<BPA_Product>().Where(x=>x.Status==0) .ToListAsync();
  51. return data;
  52. }
  53. public async Task<BPA_Product> GetProduct(string productId)
  54. {
  55. var data = await _db.Queryable<BPA_Product>().Where(x => x.Id == productId).FirstAsync();
  56. return data;
  57. }
  58. /// <summary>
  59. /// 新增
  60. /// </summary>
  61. /// <returns></returns>
  62. public async Task<bool> AddProduct(ProductBaseDto inputDto)
  63. {
  64. var count=_db.Queryable<BPA_Product>().Count();
  65. var check=_db.Queryable<BPA_Product>().Where(x => x.Name == inputDto.Name || x.Code == inputDto.Code).Any();
  66. if (check) throw Oops.Oh("产品名称和标识不能重复");
  67. var res = await _db.Insertable(new BPA_Product
  68. {
  69. Name = inputDto.Name,
  70. Key = GetNumber2(count),
  71. Remark=inputDto.Remark,
  72. Code= inputDto.Code,
  73. Status = CommonStatus.ENABLE
  74. }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
  75. return res > 0;
  76. }
  77. /// <summary>
  78. /// 删除
  79. /// </summary>
  80. /// <param name="inputList"></param>
  81. /// <returns></returns>
  82. public async Task<bool> DeProduct(List<string> inputList)
  83. {
  84. var datas = await _db.Queryable<BPA_Product>()
  85. .Where(x => inputList.Contains(x.Id))
  86. .ToListAsync();
  87. _db.Deleteable(datas).ExecuteCommand();
  88. return true;
  89. }
  90. /// <summary>
  91. /// 修改
  92. /// </summary>
  93. /// <returns></returns>
  94. public async Task<bool> UpdateProduct(ProductBaseDto inputDto)
  95. {
  96. var data = await _db.Queryable<BPA_Product>().Where(x => x.Id == inputDto.Id).FirstAsync();
  97. var check = _db.Queryable<BPA_Product>().Where(x => (x.Name == inputDto.Name || x.Code == inputDto.Code) && x.Id != inputDto.Id).Any();
  98. if (check) throw Oops.Oh("产品名称和标识不能重复");
  99. if (data != null)
  100. {
  101. var res = _db.Updateable<BPA_Product>()
  102. .SetColumns(t => t.Name == inputDto.Name)
  103. .SetColumns(t => t.Code == inputDto.Code)
  104. .SetColumns(t => t.Remark == inputDto.Remark).Where(t => t.Id == inputDto.Id)
  105. .ExecuteCommandHasChange();
  106. return res;
  107. }
  108. return false;
  109. }
  110. /// <summary>
  111. /// 更新状态
  112. /// </summary>
  113. /// <param name="inputDto"></param>
  114. /// <returns></returns>
  115. public async Task<bool> UpdateDeviceVesionSatatus(ProductSatatusDto inputDto)
  116. {
  117. var data = await _db.Queryable<BPA_Product>().Where(x => x.Id == inputDto.Id).FirstAsync();
  118. if (data != null)
  119. {
  120. var res = _db.Updateable<BPA_Product>()
  121. .SetColumns(t => t.Status == (CommonStatus)inputDto.Status).Where(t => t.Id == inputDto.Id)
  122. .ExecuteCommandHasChange();
  123. return res;
  124. }
  125. return false;
  126. }
  127. private string GetNumber2(int count)
  128. {
  129. var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value;
  130. var res=MD5Encryption.Encrypt(groupId + DateTime.Now.ToString("yyyyMMddhhmmsss"), false,true)+ count;
  131. return res;
  132. }
  133. }
  134. }