RegionsApplicationService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Linq.Dynamic.Core;
  4. using System.Threading.Tasks;
  5. using Abp.Application.Services.Dto;
  6. using Abp.Authorization;
  7. using Abp.Domain.Repositories;
  8. using Abp.Extensions;
  9. using IwbZero.AppServiceBase;
  10. using IwbZero.IdentityFramework;
  11. using ShwasherSys.Authorization.Permissions;
  12. using ShwasherSys.BaseSysInfo;
  13. using ShwasherSys.BaseSysInfo.Functions.Dto;
  14. using ShwasherSys.BasicInfo.Region.Dto;
  15. using ShwasherSys.Lambda;
  16. namespace ShwasherSys.BasicInfo.Region
  17. {
  18. [AbpAuthorize]
  19. public class RegionsAppService : ShwasherAsyncCrudAppService<Regions, RegionDto, string, PagedRequestDto, RegionCreateDto, RegionUpdateDto >, IRegionsAppService
  20. {
  21. public RegionsAppService(IRepository<Regions, string> repository) : base(repository)
  22. {
  23. }
  24. protected override string GetPermissionName { get; set; } = PermissionNames.PagesBasicInfoRegions;
  25. protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesBasicInfoRegions;
  26. protected override string CreatePermissionName { get; set; } = PermissionNames.PagesBasicInfoRegionsCreate;
  27. protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesBasicInfoRegionsUpdate;
  28. protected override string DeletePermissionName { get; set; } = PermissionNames.PagesBasicInfoRegionsDelete;
  29. public override async Task<RegionDto> Create(RegionCreateDto input)
  30. {
  31. CheckCreatePermission();
  32. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  33. if (entity!=null)
  34. {
  35. CheckErrors(IwbIdentityResult.Failed("此编号已经被使用!请更换其它编号!"));
  36. }
  37. var loFather =await Repository.GetAsync(input.FatherRegionID);
  38. loFather.IsLeaf = "N";
  39. input.FatherRegionID = loFather.Id;
  40. input.Depth = loFather.Depth + 1;
  41. input.IsLeaf = "Y";
  42. input.Path = loFather.Path + input.Id+",";
  43. input.Sort = input.Sort;
  44. await Repository.UpdateAsync(loFather);
  45. return await CreateEntity(input);
  46. }
  47. public override async Task Delete(EntityDto<string> input)
  48. {
  49. CheckDeletePermission();
  50. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  51. if ((await Repository.GetAllListAsync(a => a.FatherRegionID == entity.Id&&a.IsLock=="N")).Any())
  52. {
  53. CheckErrors(IwbIdentityResult.Failed("此菜单下还有子区域,不能删除"));
  54. }
  55. entity.IsLock = "Y";
  56. await Repository.UpdateAsync(entity);
  57. await CurrentUnitOfWork.SaveChangesAsync();
  58. }
  59. public async Task<string> GetRegionSelectStrs()
  60. {
  61. var options = "";
  62. var list = await Repository.GetAllListAsync(a => a.IsLock == "N");
  63. foreach (var l in list)
  64. {
  65. string parent = l.FatherRegionID == "0" ? "" : $" parent=\"{l.FatherRegionID}\"";
  66. options += $"<option value=\"{l.Id}\"{parent}>{l.RegionName}</option>\r\n";
  67. }
  68. return options;
  69. }
  70. /*public override async Task<PagedResultDto<RegionDto>> GetAll(PagedRequestDto input)
  71. {
  72. CheckGetAllPermission();
  73. var query = CreateFilteredQuery(input).Where(a => a.IsLock == "N");
  74. if (input.SearchList != null && input.SearchList.Count > 0)
  75. {
  76. List<LambdaObject> objList = new List<LambdaObject>();
  77. foreach (var o in input.SearchList)
  78. {
  79. if (o.KeyWords.IsNullOrEmpty())
  80. continue;
  81. object keyWords = o.KeyWords;
  82. objList.Add(new LambdaObject
  83. {
  84. FieldType = (LambdaFieldType)o.FieldType,
  85. FieldName = o.KeyField,
  86. FieldValue = keyWords,
  87. ExpType = (LambdaExpType)o.ExpType
  88. });
  89. }
  90. var exp = objList.GetExp<Regions>();
  91. query = query.Where(exp);
  92. }
  93. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  94. query = ApplySorting(query, input);
  95. query = ApplyPaging(query, input);
  96. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  97. var dtos = new PagedResultDto<RegionDto>(
  98. totalCount, ObjectMapper.Map<List<RegionDto>>(entities)
  99. );
  100. return dtos;
  101. }*/
  102. }
  103. }