using MiaoYu.Repository.LiveForum.Admin.Entities.Apps; namespace MiaoYu.Api.Admin.ApplicationServices.Apps.LiveForum; /// /// 用户等级配置表,定义用户等级体系和升级规则 服务 T_UserLevelsService /// public class T_UserLevelsService : ApplicationService> { public T_UserLevelsService(IRepository defaultRepository) : base(defaultRepository) { } /// /// 获取列表数据 /// /// /// public async Task FindListAsync(PagingSearchInput pagingSearchInput) { var query = this._defaultRepository.Select //等级名称 .WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search?.LevelName), w => w.LevelName.Contains(pagingSearchInput.Search.LevelName ?? "")) .OrderByDescending(w => w.Id) .Select(w => new { w.Id, w.LevelName,w.MinExperience,w.MaxExperience,w.LevelIcon,w.LevelColor,w.Privileges,w.CreatedAt,w.UpdatedAt,w.IsActive, // w.LastModificationTime, // w.CreationTime }) ; 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")) // ; // 设置列 //result.GetColumn(query, w => w.OperatorName).SetColumn("操作人"); //result.GetColumn(query, w => w.OperatorName!).SetColumn(w => w.Name!); return result; } /// /// 根据id数组删除 /// /// ids /// public async Task DeleteListAsync(List ids) { await this._defaultRepository.DeleteByIdsAsync(ids); } /// /// 查询表单数据 /// /// id /// public async Task> FindFormAsync(int id) { var res = new Dictionary(); var form = await this._defaultRepository.FindByIdAsync(id); form = form.NullSafe(); //if (form.CreateTime == null || form.CreateTime == DateTime.MinValue) //{ // form.CreateTime = DateTime.Now; //} //if (form.UpdateTime == null || form.UpdateTime == DateTime.MinValue) //{ // form.UpdateTime = DateTime.Now; //} res[nameof(id)] = id; res[nameof(form)] = form; return res; } /// /// 保存数据 /// /// form /// public Task SaveFormAsync(T_UserLevels form) { return this._defaultRepository.InsertOrUpdateAsync(form); } /// /// 导出Excel /// /// /// public async Task ExportExcelAsync(PagingSearchInput pagingSearchInput) { pagingSearchInput.Page = -1; var tableViewModel = await this.FindListAsync(pagingSearchInput); return ExcelUtil.ExportExcelByPagingView(tableViewModel, null, "Id"); } }