namespace MiaoYu.Api.Admin.ApplicationServices.Systems; /// /// 服务 SysDataAuthorityService /// public class SysDataAuthorityService : ApplicationService> { private readonly IRepository _sysDataAuthorityCustomRepository; public SysDataAuthorityService(IRepository defaultRepository, IRepository sysDataAuthorityCustomRepository) : base(defaultRepository) { _sysDataAuthorityCustomRepository = sysDataAuthorityCustomRepository; } /// /// 获取列表数据 /// /// page /// public async Task FindListAsync(PagingSearchInput pagingSearchInput) { var query = _defaultRepository.Select .OrderByDescending(w => w.CreationTime) .Select(w => new { w.PermissionType, w.RoleId, w.LastModificationTime, w.CreationTime, w.Id, }) ; var result = await _defaultRepository.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; } /// /// 根据id数组删除 /// /// ids /// public async Task DeleteListAsync(List ids) { await _defaultRepository.DeleteByIdsAsync(ids); } /// /// 查询表单数据 /// /// id /// public async Task> FindFormAsync(Guid id) { var res = new Dictionary(); var form = await _defaultRepository.FindByIdAsync(id); form = form.NullSafe(); res[nameof(id)] = id == Guid.Empty ? "" : id; res[nameof(form)] = form; return res; } /// /// 保存数据 /// /// form /// public async Task SaveFormAsync(SysDataAuthorityFormDto form) { var sysDataAuthority = await _defaultRepository.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); } /// /// 导出Excel /// /// /// public async Task ExportExcelAsync(PagingSearchInput pagingSearchInput) { pagingSearchInput.Page = -1; var tableViewModel = await FindListAsync(pagingSearchInput); return ExcelUtil.ExportExcelByPagingView(tableViewModel, null, "Id"); } /// /// 根据角色 id 获取数据权限 /// /// /// public async Task> GetDataAuthorityByRoleIdAsync(Guid roleId) { var result = new Dictionary(); var sysDataAuthority = await _defaultRepository.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; } }