namespace CloudGaming.Api.Admin.ApplicationServices.Systems; /// /// 服务 SysDataAuthorityService /// public class SysDataAuthorityService( IServiceProvider serviceProvider, IRepository sysDataAuthorityCustomRepository) : ApplicationService(serviceProvider) { /// /// 获取列表数据 /// /// page /// public override async Task FindListAsync(PagingSearchInput pagingSearchInput) { var query = Repository.Select .OrderByDescending(w => w.CreationTime) .Select(w => new { w.PermissionType, w.RoleId, w.LastModificationTime, w.CreationTime, w.Id, }) ; var result = await Repository.AsPagingViewAsync(query, pagingSearchInput); //覆盖值 result .FormatValue(query, w => w.CreationTime, (oldValue) => oldValue.ToString("yyyy-MM-dd")) .FormatValue(query, w => w.LastModificationTime, (oldValue) => oldValue?.ToString("yyyy-MM-dd")) ; return result; } /// /// 保存数据 /// /// form /// public override async Task SaveFormAsync(SysDataAuthorityFormDto form) { var sysDataAuthority = await Repository.InsertOrUpdateAsync(form.SysDataAuthority); //删除集合 操作自定义数据权限 await sysDataAuthorityCustomRepository.DeleteAsync(w => w.SysDataAuthorityId == sysDataAuthority.Id); foreach (var item in form.SysDataAuthorityCustomList) { item.SysDataAuthorityId = sysDataAuthority.Id; } await sysDataAuthorityCustomRepository.InsertRangeAsync(form.SysDataAuthorityCustomList); } /// /// 根据角色 id 获取数据权限 /// /// /// public async Task> GetDataAuthorityByRoleIdAsync(Guid roleId) { var result = new Dictionary(); var sysDataAuthority = await Repository.FindAsync(w => w.RoleId == roleId); sysDataAuthority = sysDataAuthority.NullSafe(); var sysDataAuthorityCustomList = await sysDataAuthorityCustomRepository.Select .Where(w => w.SysDataAuthorityId == sysDataAuthority.Id) .ToListAsync(); result.Add("sysDataAuthority", sysDataAuthority); result.Add("sysDataAuthorityCustomList", sysDataAuthorityCustomList); return result; } }