using Abp.Application.Services.Dto; using Abp.Auditing; using Abp.Authorization; using Abp.Domain.Repositories; using Abp.Linq.Extensions; using Abp.Runtime.Caching; using Microsoft.EntityFrameworkCore; using VberZero.AppService.Base; using VberZero.AppService.Base.Dto; using VberZero.AppService.Helps.Dto; using VberZero.Auditing; using VberZero.BaseSystem; using VberZero.Session; using VberZero.Tools.StringModel; namespace VberZero.AppService.Helps; [AbpAuthorize, AuditLog("帮助管理", "帮助")] public class SysHelpAppServiceBase : VzCrudAppServiceBase, ISysHelpsAppServiceBase { public SysHelpAppServiceBase(IRepository repository, IRepository funRepository, ICacheManager cacheManager) : base(repository, "") { CacheManager = cacheManager; FunRepository = funRepository; } protected IRepository FunRepository { get; } [DisableAuditing] public override async Task> GetAll(VzPagedRequestDto input) { CheckGetAllPermission(); var userType = (VzDefinition.HelpType)(int)AbpSession.GetUserType(); var query = CreateFilteredQuery(input, a => a.Function); query = ApplyFilter(query, input, a => a.HelpType >= userType); var totalCount = await AsyncQueryableExecuter.CountAsync(query); query = ApplySorting(query, input); query = ApplyPaging(query, input); var entities = await query.Select(a => new SysHelpDto() { Id = a.Id, HelpType = a.HelpType, Title = a.Title, KeyWords = a.KeyWords, FunctionNo = (int)a.FunctionNo, FunctionDisplayName = a.Function != null ? a.Function.DisplayName : "", PermissionName = a.PermissionName, Sequence = a.Sequence }).ToListAsync(); var dtos = new PagedResultDto( totalCount, entities ); return dtos; } public override async Task Create(SysHelpCreateDto input) { //input.PermissionName = input.PermissionName.Replace("_", "."); //input.FunctionNo = await GetFunctionId(input.PermissionName); await CreateEntity(input); } public override async Task Update(SysHelpUpdateDto input) { var dto = await UpdateEntity(input); await CacheManager.GetCache(VzConsts.CacheSysHelp).SetAsync(dto.Id, dto); } public override async Task Delete(VzEntityDto input) { await base.Delete(input); await CacheManager.GetCache(VzConsts.CacheSysHelp).RemoveAsync(input.Id); } private async Task GetFunctionId(string permName) { return await CacheManager.GetCache(VzConsts.CachePermissionFunction).GetAsync(permName, async () => { var fun = await FunRepository.FirstOrDefaultAsync(a => a.PermissionName == permName); if (fun == null) { CheckErrors("未查询到功能菜单!"); return 0; } if (fun.Id != null) return (int)fun.Id; return 0; }); } protected override SysHelpDto MapToEntityDto(SysHelp entity) { var dto = base.MapToEntityDto(entity); dto.FunctionDisplayName = entity.Function?.DisplayName ?? ""; return dto; } protected override IQueryable SelfSorting(IQueryable query, VzPagedRequestDto input) { if (query is IQueryable queryable) return (IQueryable)queryable.OrderBy(r => r.Sequence); return query; } protected override IQueryable KeyWordFilter(IQueryable query, string keyword) { if (query is IQueryable queryable) return (IQueryable)queryable.WhereIf(keyword.NotEmpty(), a => a.Title.Contains(keyword) || a.KeyWords.Contains(keyword)); return query; } }