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

ProductTopicsService.cs 4.1 KiB

11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using BPA.SAAS.Manage.Application.Device.Dtos.Device;
  2. using BPA.SAAS.Manage.Application.Device.Dtos.ProductTopics;
  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 StackExchange.Profiling.Internal;
  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 ProductTopicsService : IProductTopicsService, ITransient
  17. {
  18. private readonly ISqlSugarClient _db;
  19. public ProductTopicsService(ISqlSugarClient db)
  20. {
  21. _db= db;
  22. }
  23. /// <summary>
  24. /// 分页查询
  25. /// </summary>
  26. /// <param name="inputDto"></param>
  27. /// <returns></returns>
  28. public async Task<PageUtil> GetProductTopicsPage(ProductTopicsQueryInputDto inputDto)
  29. {
  30. var total = new RefAsync<int>();
  31. var data = await _db.Queryable<BPA_ProductTopics>().Where(x=>x.ProductId== inputDto.ProductId && x.ProductVesionId== inputDto.ProductVesionId && x.IsDefault== inputDto.IsDefault)
  32. .WhereIF(inputDto.TopicsType!=null, x => x.TopicsType== (TopicsTypeEnum)(Enum.Parse(typeof(TopicsTypeEnum), inputDto.TopicsType.ToString())))
  33. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Topics), x => x.Topics == inputDto.Topics)
  34. .OrderBy(x => x.CreateAt, OrderByType.Desc).OrderBy(x => x.Name, OrderByType.Desc)
  35. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  36. return new PageUtil()
  37. {
  38. Data = data,
  39. Total = total
  40. };
  41. }
  42. public async Task<List<BPA_ProductTopics>> GetProductTopicList(ProductTopicsQueryDto inputDto)
  43. {
  44. var total = new RefAsync<int>();
  45. var data = await _db.Queryable<BPA_ProductTopics>().Where(x => x.ProductId == inputDto.ProductId && x.ProductVesionId == inputDto.ProductVesionId && x.IsDefault == inputDto.IsDefault)
  46. .OrderBy(x => x.CreateAt, OrderByType.Desc)
  47. .ToListAsync();
  48. return data;
  49. }
  50. /// <summary>
  51. /// 添加
  52. /// </summary>
  53. /// <param name="inputDto"></param>
  54. /// <returns></returns>
  55. public async Task<bool> AddProductTopics(ProductTopicsBaseDto inputDto)
  56. {
  57. BPA_ProductTopics BPA_ProductTopics = inputDto.Adapt<BPA_ProductTopics>();
  58. var res = await _db.Insertable(BPA_ProductTopics).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
  59. return res != null;
  60. }
  61. /// <summary>
  62. /// 更新
  63. /// </summary>
  64. /// <param name="inputDto"></param>
  65. /// <returns></returns>
  66. public async Task<bool> UpdateProductTopics(ProductTopicsBaseDto inputDto)
  67. {
  68. var data = await _db.Queryable<BPA_ProductTopics>().Where(x => x.Id == inputDto.Id).FirstAsync();
  69. if (data != null)
  70. {
  71. var product = _db.Queryable<BPA_ProductTopics>().Where(x => x.Id == inputDto.ProductId).First();
  72. var inputData = inputDto.Adapt<BPA_ProductTopics>();
  73. var res = await _db.Updateable(inputData)
  74. .UpdateColumns(x => new
  75. {
  76. x.Topics,
  77. x.TopicsType,
  78. x.Description,
  79. })
  80. .Where(x => x.Id == inputDto.Id).ExecuteCommandAsync();
  81. return res > 0;
  82. }
  83. return false;
  84. }
  85. /// <summary>
  86. /// 删除
  87. /// </summary>
  88. /// <param name="inputList"></param>
  89. /// <returns></returns>
  90. public async Task<bool> DelProductTopics(List<string> inputList)
  91. {
  92. var data = await _db.Queryable<BPA_ProductTopics>().Where(x => inputList.Contains(x.Id)).ToListAsync();
  93. var res = await _db.Deleteable(data).ExecuteCommandAsync();
  94. return res > 0;
  95. }
  96. }
  97. }