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.
 
 

107 lines
3.7 KiB

  1. using BPA.KitChen.GroupMeal.Application.Service.Shop.Dtos;
  2. using BPA.KitChen.GroupMeal.Core.Common.Const;
  3. using BPA.KitChen.GroupMeal.Core.Entity;
  4. using BPA.KitChen.GroupMeal.SqlSugar;
  5. using Furion;
  6. using Furion.DependencyInjection;
  7. using Furion.DynamicApiController;
  8. using Furion.FriendlyException;
  9. using Mapster;
  10. using Microsoft.AspNetCore.Components.Forms;
  11. using Microsoft.AspNetCore.Mvc;
  12. using SqlSugar;
  13. namespace BPA.KitChen.GroupMeal.Application.Service.Shop
  14. {
  15. [ApiDescriptionSettings("店铺管理", Tag = "店铺管理", SplitCamelCase = false)]
  16. public class ShopService : IDynamicApiController, ITransient, IShopService
  17. {
  18. /// <summary>
  19. /// 分页查询
  20. /// </summary>
  21. /// <param name="inputDto"></param>
  22. /// <returns></returns>
  23. [HttpPost]
  24. public async Task<PageOutDto> GetPage(ShopPageDto inputDto)
  25. {
  26. var total = new RefAsync<int>();
  27. var data =await SqlSugarDb.Db.Queryable<ShopEntity>()
  28. .WhereIF(!string.IsNullOrEmpty(inputDto.Name),x=>x.Name.Contains(inputDto.Name))
  29. .WhereIF(!string.IsNullOrEmpty(inputDto.Phone), x => x.Phone.Contains(inputDto.Phone))
  30. .WhereIF(!string.IsNullOrEmpty(inputDto.OrgId), x => x.OrgId==inputDto.OrgId)
  31. .OrderBy(a => a.CreateAt, OrderByType.Desc)
  32. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  33. return new PageOutDto()
  34. {
  35. Data = data,
  36. Total = total
  37. };
  38. }
  39. public async Task<List<ShopEntity>> GetAllList()
  40. {
  41. var data = await SqlSugarDb.Db.Queryable<ShopEntity>().Where(x=>x.IsDeleted==0).ToListAsync();
  42. return data;
  43. }
  44. /// <summary>
  45. /// 新增
  46. /// </summary>
  47. /// <param name="inputDto"></param>
  48. /// <returns></returns>
  49. public async Task<bool> Add(ShopCreateOrUpdateDto inputDto)
  50. {
  51. inputDto.Id=Guid.NewGuid().ToString();
  52. var data=await SqlSugarDb.Db.Queryable< ShopEntity >().FirstAsync(x=>x.Name==inputDto.Name);
  53. if (data != null)
  54. {
  55. throw Oops.Oh($"名称重复");
  56. }
  57. var res =await SqlSugarDb.Db.Insertable(inputDto.Adapt<ShopEntity>()).ExecuteCommandAsync();
  58. return res > 0;
  59. }
  60. /// <summary>
  61. /// 修改
  62. /// </summary>
  63. /// <param name="inputDto"></param>
  64. /// <returns></returns>
  65. public async Task<bool> Update(ShopCreateOrUpdateDto inputDto)
  66. {
  67. var data = await SqlSugarDb.Db.Queryable<ShopEntity>().FirstAsync(x => x.Id == inputDto.Id);
  68. if (data == null)
  69. {
  70. throw Oops.Oh($"数据不存在");
  71. }
  72. var data2= await SqlSugarDb.Db.Queryable<ShopEntity>().FirstAsync(x => x.Id != inputDto.Id&&x.Name==inputDto.Name);
  73. if (data2 != null)
  74. {
  75. throw Oops.Oh($"名称存在");
  76. }
  77. data.Name = inputDto.Name;
  78. data.OrgId = inputDto.OrgId;
  79. data.Phone = inputDto.Phone;
  80. var res=await SqlSugarDb.Db.Updateable(data).ExecuteCommandAsync();
  81. return res > 0;
  82. }
  83. public async Task<bool> Del(string id)
  84. {
  85. var data = await SqlSugarDb.Db.Queryable<ShopEntity>().FirstAsync(x => x.Id == id);
  86. var res =await SqlSugarDb.Db.Updateable<ShopEntity>()
  87. .SetColumns(it => new ShopEntity {IsDeleted=1 })//类只能在表达示里面不能提取
  88. .Where(it => it.Id==id)
  89. .ExecuteCommandAsync();
  90. return res > 0;
  91. }
  92. }
  93. }