StateAppServiceBase.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Abp.Authorization;
  2. using Abp.Domain.Repositories;
  3. using Abp.Linq.Extensions;
  4. using Abp.Runtime.Caching;
  5. using VberZero.AppService.Base;
  6. using VberZero.AppService.Base.Dto;
  7. using VberZero.AppService.States.Dto;
  8. using VberZero.Auditing;
  9. using VberZero.BaseSystem;
  10. using VberZero.BaseSystem.Users;
  11. using VberZero.Session;
  12. using VberZero.Tools.StringModel;
  13. namespace VberZero.AppService.States;
  14. [AbpAuthorize, AuditLog("字典管理", "字典")]
  15. public class StateAppServiceBase : VzCrudAppServiceBase<SysState, StateDto, int, VzPagedRequestDto, StateCreateDto, StateUpdateDto>, IStateAppServiceBase
  16. {
  17. public StateAppServiceBase(ICacheManager cacheManager, IRepository<SysState, int> repository) : base(repository, "StateNo")
  18. {
  19. CacheManager = cacheManager;
  20. }
  21. protected override string KeyExistMessage => string.Format(L("KeyExistMessageFormatter"), L("state"));
  22. protected override string KeyNotExistMessage => string.Format(L("KeyNotExistMessageFormatter"), L("state"));
  23. public override Task Create(StateCreateDto input)
  24. {
  25. return Task.CompletedTask;
  26. }
  27. public override async Task Update(StateUpdateDto input)
  28. {
  29. //if (AbpSession.GetUserName() != User.AdminUserName && AbpSession.GetUserName() != User.SystemUserName)
  30. //{
  31. // ThrowError("NoPermissionOperation");
  32. //}
  33. if (AbpSession.GetUserType() > VzDefinition.UserType.System)
  34. {
  35. ThrowError("NoPermissionOperation");
  36. }
  37. CheckUpdatePermission();
  38. var entity = await GetEntity(input);
  39. await UpdateEntity(input, entity);
  40. await CacheManager.GetCache(VzConsts.CacheSysState)
  41. .RemoveAsync(entity.CodeKey + "." + entity.CodeValue);
  42. }
  43. public override async Task Delete(VzEntityDto<int> input)
  44. {
  45. #if DEBUG
  46. if (AbpSession.GetUserName() != User.AdminUserName && AbpSession.GetUserName() != User.SystemUserName)
  47. {
  48. ThrowError("NoPermissionOperation");
  49. }
  50. await base.Delete(input);
  51. #else
  52. ThrowError("CanNotDelete");
  53. #endif
  54. }
  55. protected override IQueryable<T> SelfSorting<T>(IQueryable<T> query, VzPagedRequestDto input)
  56. {
  57. if (query is IQueryable<SysState> queryable)
  58. return (IQueryable<T>)queryable.OrderByDescending(r => r.Id);
  59. return query;
  60. }
  61. protected override IQueryable<T> KeyWordFilter<T>(IQueryable<T> query, string keyword)
  62. {
  63. if (query is IQueryable<SysState> queryable)
  64. return (IQueryable<T>)queryable.WhereIf(keyword.NotEmpty(), a =>
  65. a.CodeKey.Contains(keyword) ||
  66. a.CodeValue.Contains(keyword));
  67. return query;
  68. }
  69. }