diff --git a/Ape.Volo.Api/Authentication/Jwt/PermissionHandler.cs b/Ape.Volo.Api/Authentication/Jwt/PermissionHandler.cs index 5720a99..cb857c7 100644 --- a/Ape.Volo.Api/Authentication/Jwt/PermissionHandler.cs +++ b/Ape.Volo.Api/Authentication/Jwt/PermissionHandler.cs @@ -172,8 +172,8 @@ await _apeContext.Cache.RemoveAsync(GlobalConstants.CachePrefix.OnlineKey + #region 系统管理免接口鉴权 - var setting = await _settingService.FindSettingByName("IsAdminNotAuthentication"); - if (setting != null && setting.Value.ToBool()) + var value = await _settingService.GetSettingValue("IsAdminNotAuthentication"); + if (value) { // loginUserInfo = await _apeContext.Cache.GetAsync( // GlobalConstants.CacheKey.OnlineKey + diff --git a/Ape.Volo.Api/Controllers/Permission/DeptController.cs b/Ape.Volo.Api/Controllers/Permission/DeptController.cs index 0c32802..313119b 100644 --- a/Ape.Volo.Api/Controllers/Permission/DeptController.cs +++ b/Ape.Volo.Api/Controllers/Permission/DeptController.cs @@ -143,20 +143,19 @@ public async Task> Download(DeptQueryCriteria deptQueryCrit /// /// 获取同级与父级部门 /// - /// + /// /// - [HttpPost] + [HttpGet] [Route("superior")] [Description("获取同级、父级部门")] - public async Task> GetSuperior([FromBody] IdCollection idCollection) + public async Task> GetSuperior(long id) { - if (!ModelState.IsValid) + if (id.IsNullOrEmpty()) { - var actionError = ModelState.GetErrors(); - return Error(actionError); + return Error("id cannot be empty"); } - var deptList = await _departmentService.QuerySuperiorDeptAsync(idCollection.IdArray); + var deptList = await _departmentService.QuerySuperiorDeptAsync(id); return JsonContent(new ActionResultVm { diff --git a/Ape.Volo.Api/Controllers/Permission/MenuController.cs b/Ape.Volo.Api/Controllers/Permission/MenuController.cs index 981a261..cac4116 100644 --- a/Ape.Volo.Api/Controllers/Permission/MenuController.cs +++ b/Ape.Volo.Api/Controllers/Permission/MenuController.cs @@ -171,20 +171,19 @@ public async Task> Download(MenuQueryCriteria menuQueryCrit /// /// 获取同级与上级菜单 /// - /// + /// /// - [HttpPost] + [HttpGet] [Description("获取同级、父级菜单")] [Route("superior")] - public async Task> GetSuperior([FromBody] IdCollection idCollection) + public async Task> GetSuperior(long id) { - if (!ModelState.IsValid) + if (id.IsNullOrEmpty()) { - var actionError = ModelState.GetErrors(); - return Error(actionError); + return Error("id cannot be empty"); } - var menuVos = await _menuService.FindSuperiorAsync(idCollection.IdArray.FirstOrDefault()); + var menuVos = await _menuService.FindSuperiorAsync(id); return menuVos.ToJsonByIgnore(); } diff --git a/Ape.Volo.Api/Controllers/System/DictDetailController.cs b/Ape.Volo.Api/Controllers/System/DictDetailController.cs index 97a3275..ba0cf6e 100644 --- a/Ape.Volo.Api/Controllers/System/DictDetailController.cs +++ b/Ape.Volo.Api/Controllers/System/DictDetailController.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System.Collections.Generic; +using System.ComponentModel; using System.Threading.Tasks; using Ape.Volo.Api.Controllers.Base; using Ape.Volo.Common.Extensions; @@ -20,14 +21,16 @@ public class DictDetailController : BaseApiController #region 字段 private readonly IDictDetailService _dictDetailService; + private readonly IDictService _dictService; #endregion #region 构造函数 - public DictDetailController(IDictDetailService dictDetailService) + public DictDetailController(IDictDetailService dictDetailService, IDictService dictService) { _dictDetailService = dictDetailService; + _dictService = dictService; } #endregion @@ -85,11 +88,11 @@ public async Task> Update( [HttpDelete] [Route("delete")] [Description("删除")] - public async Task> Delete(string id) + public async Task> Delete(long id) { if (id.IsNullOrEmpty()) { - return Error("id is null"); + return Error("id cannot be empty"); } await _dictDetailService.DeleteAsync(id); @@ -99,20 +102,18 @@ public async Task> Delete(string id) /// /// 查看字典详情列表 /// - /// - /// + /// /// [HttpGet] [Route("query")] [Description("查询")] - public async Task> Query(DictDetailQueryCriteria dictDetailQueryCriteria, - Pagination pagination) + public async Task> Query(string dictName) { - var list = await _dictDetailService.QueryAsync(dictDetailQueryCriteria, pagination); + var list = await _dictDetailService.QueryAsync(dictName); return JsonContent(new ActionResultVm { Content = list, - TotalElements = pagination.TotalElements + TotalElements = list.Count }); } diff --git a/Ape.Volo.Api/Filter/AuditingFilter.cs b/Ape.Volo.Api/Filter/AuditingFilter.cs index 48cabb0..9da6cf9 100644 --- a/Ape.Volo.Api/Filter/AuditingFilter.cs +++ b/Ape.Volo.Api/Filter/AuditingFilter.cs @@ -72,7 +72,8 @@ private async Task ExecuteAuditing(ActionExecutingContext context, ActionExecuti //执行结果 //var action = context.ActionDescriptor as ControllerActionDescriptor; //var isTrue = action.MethodInfo.IsDefined(typeof(DescriptionAttribute), false); - if ((await _settingService.FindSettingByName("IsAuditLogSaveDB")).Value.ToBool()) + var saveDb = await _settingService.GetSettingValue("IsAuditLogSaveDB"); + if (saveDb) { var result = resultContext.Result; if (context.HttpContext.IsNotNull() && result.IsNotNull()) diff --git a/Ape.Volo.Api/Filter/GlobalExceptionFilter.cs b/Ape.Volo.Api/Filter/GlobalExceptionFilter.cs index 42ae1b3..b48a983 100644 --- a/Ape.Volo.Api/Filter/GlobalExceptionFilter.cs +++ b/Ape.Volo.Api/Filter/GlobalExceptionFilter.cs @@ -106,8 +106,8 @@ public async Task OnExceptionAsync(ExceptionContext context) _browserDetector.Browser?.Version)); } - var settingDto = await _settingService.FindSettingByName("IsExceptionLogSaveDB"); - if (settingDto != null && settingDto.Value.ToBool() && exceptionType != typeof(DemoRequestException)) + var saveDb = await _settingService.GetSettingValue("IsExceptionLogSaveDB"); + if (saveDb && exceptionType != typeof(DemoRequestException)) { //记录日志到数据库 try diff --git a/Ape.Volo.Api/wwwroot/resources/db/sys_apis.tsv b/Ape.Volo.Api/wwwroot/resources/db/sys_apis.tsv index b2090a7..a0166aa 100644 --- a/Ape.Volo.Api/wwwroot/resources/db/sys_apis.tsv +++ b/Ape.Volo.Api/wwwroot/resources/db/sys_apis.tsv @@ -283,7 +283,7 @@ "group":"部门管理", "url":"/api/dept/superior", "description":"获取同级、父级部门", - "method":"POST", + "method":"GET", "isDeleted":false, "createBy":"apevolo", "CreateTime":"\/Date(1609430400000+0800)\/", @@ -363,7 +363,7 @@ "group":"菜单管理", "url":"/api/menu/superior", "description":"获取同级、父级菜单", - "method":"POST", + "method":"GET", "isDeleted":false, "createBy":"apevolo", "CreateTime":"\/Date(1609430400000+0800)\/", diff --git a/Ape.Volo.Api/wwwroot/resources/db/sys_dict.tsv b/Ape.Volo.Api/wwwroot/resources/db/sys_dict.tsv index df36f0a..2aa0a00 100644 --- a/Ape.Volo.Api/wwwroot/resources/db/sys_dict.tsv +++ b/Ape.Volo.Api/wwwroot/resources/db/sys_dict.tsv @@ -1,6 +1,18 @@ [ + { + "Id": "1306054134645919763", + "DictType": 1, + "Name": "dict_type", + "Description": "字典类型(系统or业务)", + "CreateBy": "apevolo", + "CreateTime": "/Date(1609430400000+0800)/", + "UpdateBy": null, + "UpdateTime": null, + "IsDeleted": false + }, { "Id": "1306054134645919764", + "DictType": 2, "Name": "job_status", "Description": "岗位状态", "CreateBy": "apevolo", @@ -11,6 +23,7 @@ }, { "Id": "1306054134645919765", + "DictType": 2, "Name": "dept_status", "Description": "部门状态", "CreateBy": "apevolo", @@ -21,6 +34,7 @@ }, { "Id": "1306054134645919766", + "DictType": 2, "Name": "user_status", "Description": "用户状态", "CreateBy": "apevolo", @@ -31,6 +45,7 @@ }, { "Id": "1380547002701451264", + "DictType": 2, "Name": "email_message_template_status", "Description": "邮件消息模板状态", "CreateBy": "apevolo", @@ -41,6 +56,7 @@ }, { "Id": "1425449857383927808", + "DictType": 2, "Name": "setting_status", "Description": "全局设置状态", "CreateBy": "apevolo", @@ -51,6 +67,7 @@ }, { "Id": "1787853620566298624", + "DictType": 1, "Name": "task_trigger_type", "Description": "作业触发器类型", "CreateBy": "apevolo", @@ -61,6 +78,7 @@ }, { "Id": "1799832537057464320", + "DictType": 1, "Name": "tenant_type", "Description": "租户类型", "CreateBy": "apevolo", @@ -71,6 +89,7 @@ }, { "Id": "1799832924720205824", + "DictType": 1, "Name": "db_type", "Description": "数据库类型", "CreateBy": "apevolo", diff --git a/Ape.Volo.Api/wwwroot/resources/db/sys_dict_detail.tsv b/Ape.Volo.Api/wwwroot/resources/db/sys_dict_detail.tsv index da841b3..25c6347 100644 --- a/Ape.Volo.Api/wwwroot/resources/db/sys_dict_detail.tsv +++ b/Ape.Volo.Api/wwwroot/resources/db/sys_dict_detail.tsv @@ -1,10 +1,34 @@ [ + { + "Id": "1306054134645919764", + "DictId": "1306054134645919763", + "Label": "系统类", + "Value": "1", + "DictSort": 2, + "CreateBy": "apevolo", + "CreateTime": "/Date(1609430400000+0800)/", + "UpdateBy": null, + "UpdateTime": null, + "IsDeleted": false + }, + { + "Id": "1306054134645919765", + "DictId": "1306054134645919763", + "Label": "业务类", + "Value": "2", + "DictSort": 1, + "CreateBy": "apevolo", + "CreateTime": "/Date(1609430400000+0800)/", + "UpdateBy": null, + "UpdateTime": null, + "IsDeleted": false + }, { "Id": "1306054134645919767", "DictId": "1306054134645919764", "Label": "停用", "Value": "false", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -16,7 +40,7 @@ "DictId": "1306054134645919764", "Label": "启用", "Value": "true", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -28,7 +52,7 @@ "DictId": "1306054134645919765", "Label": "停用", "Value": "false", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -40,7 +64,7 @@ "DictId": "1306054134645919765", "Label": "启用", "Value": "true", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -52,7 +76,7 @@ "DictId": "1306054134645919766", "Label": "禁用", "Value": "false", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -64,7 +88,7 @@ "DictId": "1306054134645919766", "Label": "激活", "Value": "true", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -76,7 +100,7 @@ "DictId": "1380547002701451264", "Label": "启用", "Value": "true", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": "", @@ -88,7 +112,7 @@ "DictId": "1380547002701451264", "Label": "禁用", "Value": "false", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -100,7 +124,7 @@ "DictId": "1425449857383927808", "Label": "启用", "Value": "true", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": "", @@ -112,7 +136,7 @@ "DictId": "1425449857383927808", "Label": "禁用", "Value": "false", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -124,7 +148,7 @@ "DictId": "1787853620566298624", "Label": "cron", "Value": "1", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": "", @@ -136,7 +160,7 @@ "DictId": "1787853620566298624", "Label": "simple", "Value": "0", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -148,7 +172,7 @@ "DictId": "1799832537057464320", "Label": "ID隔离", "Value": "1", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": "", @@ -160,7 +184,7 @@ "DictId": "1799832537057464320", "Label": "库隔离", "Value": "2", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -172,7 +196,7 @@ "DictId": "1799832924720205824", "Label": "MySql", "Value": "0", - "DictSort": "1", + "DictSort": 1, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": "", @@ -184,7 +208,7 @@ "DictId": "1799832924720205824", "Label": "SqlServer", "Value": "1", - "DictSort": "2", + "DictSort": 2, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, @@ -196,7 +220,7 @@ "DictId": "1799832924720205824", "Label": "Sqlite", "Value": "2", - "DictSort": "3", + "DictSort": 3, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": "", @@ -208,7 +232,7 @@ "DictId": "1799832924720205824", "Label": "Oracle", "Value": "3", - "DictSort": "4", + "DictSort": 4, "CreateBy": "apevolo", "CreateTime": "/Date(1609430400000+0800)/", "UpdateBy": null, diff --git a/Ape.Volo.Business/Message/Email/SmtpBuilder.cs b/Ape.Volo.Business/Message/Email/SmtpBuilder.cs index 858d186..1b6bc7c 100644 --- a/Ape.Volo.Business/Message/Email/SmtpBuilder.cs +++ b/Ape.Volo.Business/Message/Email/SmtpBuilder.cs @@ -49,8 +49,8 @@ public virtual async Task BuildAsync(EmailAccount emailAccount = nul if (emailAccount is null) { //var defaultEmailAccountId = AppSettings.GetValue("DefaultEmailAccountId");//系统默认发送邮箱ID - var settingDto = await _settingService.FindSettingByName("DefaultEmailAccountId"); - var defaultEmailAccountId = settingDto?.Value.ToLong(); + var value = await _settingService.GetSettingValue("DefaultEmailAccountId"); + var defaultEmailAccountId = value; emailAccount = await _emailAccountService.TableWhere(x => x.Id == defaultEmailAccountId).FirstAsync() ?? throw new Exception("Email account could not be loaded"); diff --git a/Ape.Volo.Business/Permission/DepartmentService.cs b/Ape.Volo.Business/Permission/DepartmentService.cs index 8069bf1..6fbbb57 100644 --- a/Ape.Volo.Business/Permission/DepartmentService.cs +++ b/Ape.Volo.Business/Permission/DepartmentService.cs @@ -205,16 +205,13 @@ public async Task> DownloadAsync(DeptQueryCriteria deptQueryCri #region 扩展方法 - public async Task> QuerySuperiorDeptAsync(HashSet ids) + public async Task> QuerySuperiorDeptAsync(long id) { var departmentList = new List(); - foreach (var id in ids) - { - var dept = await TableWhere(x => x.Id == id).FirstAsync(); - var deptDto = ApeContext.Mapper.Map(dept); - var departmentDtoList = await FindSuperiorAsync(deptDto, new List()); - departmentList.AddRange(departmentDtoList); - } + var dept = await TableWhere(x => x.Id == id).FirstAsync(); + var deptDto = ApeContext.Mapper.Map(dept); + var departmentDtoList = await FindSuperiorAsync(deptDto, new List()); + departmentList.AddRange(departmentDtoList); departmentList = TreeHelper.ListToTrees(departmentList, "Id", "ParentId", 0); diff --git a/Ape.Volo.Business/System/DictDetailService.cs b/Ape.Volo.Business/System/DictDetailService.cs index fd9ce83..3dc6bb3 100644 --- a/Ape.Volo.Business/System/DictDetailService.cs +++ b/Ape.Volo.Business/System/DictDetailService.cs @@ -1,14 +1,15 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Ape.Volo.Business.Base; using Ape.Volo.Common.Exception; +using Ape.Volo.Common.Extensions; using Ape.Volo.Common.Model; using Ape.Volo.Common.WebApp; using Ape.Volo.Entity.System; using Ape.Volo.IBusiness.Dto.System; using Ape.Volo.IBusiness.Interface.System; -using Ape.Volo.IBusiness.QueryModel; using SqlSugar; namespace Ape.Volo.Business.System; @@ -31,58 +32,79 @@ public DictDetailService(ApeContext apeContext) : base(apeContext) public async Task CreateAsync(CreateUpdateDictDetailDto createUpdateDictDetailDto) { if (await TableWhere(dd => - dd.DictId == createUpdateDictDetailDto.Dict.Id && - dd.Label == createUpdateDictDetailDto.Label && - dd.Value == createUpdateDictDetailDto.Value).AnyAsync()) + dd.DictId == createUpdateDictDetailDto.DictId && + (dd.Label == createUpdateDictDetailDto.Label || + dd.Value == createUpdateDictDetailDto.Value)).AnyAsync()) { - throw new BadRequestException($"字典详情标签=>{createUpdateDictDetailDto.Label}=>已存在!"); + throw new BadRequestException( + $"字典详情标签或值=>({createUpdateDictDetailDto.Label},{createUpdateDictDetailDto.Value})=>已存在!"); } var dictDetail = ApeContext.Mapper.Map(createUpdateDictDetailDto); - dictDetail.DictId = createUpdateDictDetailDto.Dict.Id; + //dictDetail.DictId = createUpdateDictDetailDto.Dict.Id; + dictDetail.DictId = createUpdateDictDetailDto.DictId; return await AddEntityAsync(dictDetail); } public async Task UpdateAsync(CreateUpdateDictDetailDto createUpdateDictDetailDto) { - if (!await TableWhere(dd => dd.Id == createUpdateDictDetailDto.Id).AnyAsync()) + var oldDictDetail = + await TableWhere(x => x.Id == createUpdateDictDetailDto.Id).FirstAsync(); + + if (oldDictDetail.IsNull()) { throw new BadRequestException("数据不存在!"); } + if (oldDictDetail.DictId != createUpdateDictDetailDto.DictId && + await TableWhere(dd => + dd.DictId == createUpdateDictDetailDto.DictId && + (dd.Label == createUpdateDictDetailDto.Label || + dd.Value == createUpdateDictDetailDto.Value)).AnyAsync()) + { + throw new BadRequestException( + $"字典详情标签或值=>({createUpdateDictDetailDto.Label},{createUpdateDictDetailDto.Value})=>已存在!"); + } + + var dictDetail = ApeContext.Mapper.Map(createUpdateDictDetailDto); - dictDetail.DictId = createUpdateDictDetailDto.Dict.Id; + dictDetail.DictId = createUpdateDictDetailDto.DictId; return await UpdateEntityAsync(dictDetail); } - public async Task DeleteAsync(string id) + public async Task DeleteAsync(long id) { - var newId = Convert.ToInt64(id); - var dictDetail = await TableWhere(x => x.Id == newId).FirstAsync(); + var dictDetail = await TableWhere(x => x.Id == id).FirstAsync(); if (dictDetail == null) { throw new BadRequestException("数据不存在!"); } - var logidId = Convert.ToInt64(id); - return await LogicDelete(x => x.Id == logidId) > 0; + return await LogicDelete(x => x.Id == id) > 0; } - public async Task> QueryAsync(DictDetailQueryCriteria dictDetailQueryCriteria, - Pagination pagination) + public async Task> QueryAsync(string dictName) { - pagination.SortFields = new List { "dict_sort asc" }; - var list = await SugarRepository.QueryMuchPageAsync(pagination, - (d, dd) => new object[] - { - JoinType.Left, d.Id == dd.DictId, - }, - (d, dd) => dd, - (d, dd) => d.Name == dictDetailQueryCriteria.DictName - ); - var dictDetailDtos = ApeContext.Mapper.Map>(list); - dictDetailDtos.ForEach(dd => dd.Dict = new DictDto2 { Id = dd.DictId }); - return dictDetailDtos; + //这样写生成的key太长太多 + // var list = await SugarClient.Queryable().RightJoin((d, dd) => d.Id == dd.DictId) + // .Where((d, dd) => d.Name == dictName).OrderBy((d, dd) => dd.DictSort).Select((d, dd) => dd).WithCache(86400) + // .ToListAsync(); + + + var dictList = await SugarClient.Queryable().WithCache(86400).ToListAsync(); + var dictDetailList = await Table.WithCache(86400).ToListAsync(); + var dictModel = dictList.FirstOrDefault(x => x.Name == dictName); + if (dictModel != null) + { + var dictDetailDtos = + ApeContext.Mapper.Map>(dictDetailList.Where(x => x.DictId == dictModel.Id) + .ToList()); + + //dictDetailDtos.ForEach(dd => dd.Dict = new DictDto2 { Id = dd.DictId }); + return dictDetailDtos.OrderBy(x => x.DictSort).ToList(); + } + + return new List(); } #endregion diff --git a/Ape.Volo.Business/System/DictService.cs b/Ape.Volo.Business/System/DictService.cs index 06f8d98..4f1eb27 100644 --- a/Ape.Volo.Business/System/DictService.cs +++ b/Ape.Volo.Business/System/DictService.cs @@ -51,7 +51,7 @@ public async Task UpdateAsync(CreateUpdateDictDto createUpdateDictDto) } if (oldDict.Name != createUpdateDictDto.Name && - await TableWhere(j => j.Id == createUpdateDictDto.Id).AnyAsync()) + await TableWhere(j => j.Name == createUpdateDictDto.Name).AnyAsync()) { throw new BadRequestException($"名称=>{createUpdateDictDto.Name}=>已存在!"); } @@ -70,13 +70,18 @@ public async Task DeleteAsync(HashSet ids) public async Task> QueryAsync(DictQueryCriteria dictQueryCriteria, Pagination pagination) { var whereExpression = GetWhereExpression(dictQueryCriteria); - var list = await SugarRepository.QueryMapperPageListAsync(it => it.DictDetails, - it => it.DictDetails.FirstOrDefault().DictId, whereExpression, pagination); - var dicts = ApeContext.Mapper.Map>(list); - foreach (var item in dicts) + var queryOptions = new QueryOptions { - item.DictDetails.ForEach(d => d.Dict = new DictDto2 { Id = d.DictId }); - } + Pagination = pagination, + WhereLambda = whereExpression, + //IsIncludes = true + }; + var list = await SugarRepository.QueryPageListAsync(queryOptions); + var dicts = ApeContext.Mapper.Map>(list); + // foreach (var item in dicts) + // { + // item.DictDetails.ForEach(d => d.Dict = new DictDto2 { Id = d.DictId }); + // } return dicts; } @@ -92,6 +97,7 @@ public async Task> DownloadAsync(DictQueryCriteria dictQueryCri { dictExports.AddRange(x.DictDetails.Select(d => new DictExport() { + DictType = x.DictType, Name = x.Name, Description = x.Description, Lable = d.Label, @@ -116,6 +122,12 @@ private static Expression> GetWhereExpression(DictQueryCriteria d.Name.Contains(dictQueryCriteria.KeyWords) || d.Description.Contains(dictQueryCriteria.KeyWords)); } + if (dictQueryCriteria.DictType.IsNotNull()) + { + whereExpression = whereExpression.AndAlso(d => + d.DictType == dictQueryCriteria.DictType); + } + return whereExpression; } diff --git a/Ape.Volo.Business/System/SettingService.cs b/Ape.Volo.Business/System/SettingService.cs index 3298fa0..be6b9d4 100644 --- a/Ape.Volo.Business/System/SettingService.cs +++ b/Ape.Volo.Business/System/SettingService.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using System.Threading.Tasks; using Ape.Volo.Business.Base; using Ape.Volo.Common.AttributeExt; @@ -15,6 +17,8 @@ using Ape.Volo.IBusiness.ExportModel.System; using Ape.Volo.IBusiness.Interface.System; using Ape.Volo.IBusiness.QueryModel; +using Microsoft.Extensions.Logging; +using static Ape.Volo.Common.Helper.ExceptionHelper; namespace Ape.Volo.Business.System; @@ -22,8 +26,11 @@ public class SettingService : BaseServices, ISettingService { #region 构造函数 - public SettingService(ApeContext apeContext) : base(apeContext) + private readonly ILogger _logger; + + public SettingService(ApeContext apeContext, ILogger logger) : base(apeContext) { + _logger = logger; } #endregion @@ -102,22 +109,41 @@ public async Task> DownloadAsync(SettingQueryCriteria settingQu return settingExports; } - [UseCache(Expiration = 30, KeyPrefix = GlobalConstants.CachePrefix.LoadSettingByName)] - public async Task FindSettingByName(string settingName) + //[UseCache(Expiration = 30, KeyPrefix = GlobalConstants.CachePrefix.LoadSettingByName)] + public async Task GetSettingValue(string settingName) + { + var settingList = await Table.WithCache(86400).ToListAsync(); + + var setting = settingList.FirstOrDefault(x => x.Name == settingName.Trim()); + if (setting == null) return default; + + try + { + return (T)ConvertValue(typeof(T), setting.Value); + } + catch (Exception e) + { + _logger.LogError(GetExceptionAllMsg(e)); + return default; + } + + return default; + } + + private static object ConvertValue(Type type, string value) { - if (settingName.IsNullOrEmpty()) + if (type == typeof(object)) { - throw new BadRequestException("设置键不能为空"); + return value; } - SettingDto settingDto = null; - var setting = await TableWhere(x => x.Name == settingName).FirstAsync(); - if (setting != null) + if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) { - settingDto = ApeContext.Mapper.Map(setting); + return string.IsNullOrEmpty(value) ? value : ConvertValue(Nullable.GetUnderlyingType(type), value); } - return settingDto; + var converter = TypeDescriptor.GetConverter(type); + return converter.CanConvertFrom(typeof(string)) ? converter.ConvertFromInvariantString(value) : null; } #endregion diff --git a/Ape.Volo.Common/Ape.Volo.Common.csproj b/Ape.Volo.Common/Ape.Volo.Common.csproj index bd46a45..af7763d 100644 --- a/Ape.Volo.Common/Ape.Volo.Common.csproj +++ b/Ape.Volo.Common/Ape.Volo.Common.csproj @@ -36,7 +36,7 @@ - + diff --git a/Ape.Volo.Common/Enums/DictType.cs b/Ape.Volo.Common/Enums/DictType.cs new file mode 100644 index 0000000..b80cdfa --- /dev/null +++ b/Ape.Volo.Common/Enums/DictType.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace Ape.Volo.Common.Enums; + +public enum DictType +{ + /// + /// 系统类 + /// + [Display(Name = "系统类")] + System = 1, + + /// + /// 业务类 + /// + [Display(Name = "业务类")] + Business = 2 +} diff --git a/Ape.Volo.Common/Enums/TenantType.cs b/Ape.Volo.Common/Enums/TenantType.cs index ac4569a..b7e8926 100644 --- a/Ape.Volo.Common/Enums/TenantType.cs +++ b/Ape.Volo.Common/Enums/TenantType.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.ComponentModel.DataAnnotations; namespace Ape.Volo.Common.Enums; @@ -10,12 +11,12 @@ public enum TenantType /// /// Id隔离 /// - [Description("Id隔离")] + [Display(Name = "Id隔离")] Id = 1, /// /// 库隔离 /// - [Description("库隔离")] + [Display(Name = "库隔离")] Db = 2 } diff --git a/Ape.Volo.Entity/System/Dict.cs b/Ape.Volo.Entity/System/Dict.cs index b274b50..831ec78 100644 --- a/Ape.Volo.Entity/System/Dict.cs +++ b/Ape.Volo.Entity/System/Dict.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Ape.Volo.Common.Enums; using Ape.Volo.Common.Model; using Ape.Volo.Entity.Base; using SqlSugar; @@ -11,17 +12,22 @@ namespace Ape.Volo.Entity.System [SugarTable("sys_dict")] public class Dict : BaseEntity, ISoftDeletedEntity { + /// + /// 字典类型 + /// + /// + public DictType DictType { get; set; } + /// /// 字典名称 /// /// - [SugarColumn(IsNullable = false)] public string Name { get; set; } /// /// 描述 /// - [SugarColumn(IsNullable = false)] + [SugarColumn(IsNullable = true)] public string Description { get; set; } diff --git a/Ape.Volo.Entity/System/DictDetail.cs b/Ape.Volo.Entity/System/DictDetail.cs index e006508..c1c5bba 100644 --- a/Ape.Volo.Entity/System/DictDetail.cs +++ b/Ape.Volo.Entity/System/DictDetail.cs @@ -31,8 +31,8 @@ public class DictDetail : BaseEntity, ISoftDeletedEntity /// /// 排序 /// - [SugarColumn(IsNullable = false)] - public string DictSort { get; set; } + [SugarColumn(IsNullable = true)] + public int DictSort { get; set; } /// /// 是否已删除 diff --git a/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDetailDto.cs b/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDetailDto.cs index 4f8e73d..c4995c7 100644 --- a/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDetailDto.cs +++ b/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDetailDto.cs @@ -14,7 +14,8 @@ public class CreateUpdateDictDetailDto : BaseEntityDto /// /// 字典ID /// - public string DictId { get; set; } + [Required] + public long DictId { get; set; } /// /// 标签 @@ -31,10 +32,5 @@ public class CreateUpdateDictDetailDto : BaseEntityDto /// /// 排序 /// - public string DictSort { get; set; } - - /// - /// 字典 - /// - public DictDto2 Dict { get; set; } + public int DictSort { get; set; } } diff --git a/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDto.cs b/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDto.cs index 7abc3d6..435f71f 100644 --- a/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDto.cs +++ b/Ape.Volo.IBusiness/Dto/System/CreateUpdateDictDto.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Ape.Volo.Common.AttributeExt; +using Ape.Volo.Common.Enums; using Ape.Volo.Entity.System; using Ape.Volo.IBusiness.Base; @@ -12,10 +13,16 @@ namespace Ape.Volo.IBusiness.Dto.System; [AutoMapping(typeof(Dict), typeof(CreateUpdateDictDto))] public class CreateUpdateDictDto : BaseEntityDto { + /// + /// 名称 + /// + public DictType DictType { get; set; } = DictType.System; + /// /// 名称 /// [Required] + public string Name { get; set; } /// diff --git a/Ape.Volo.IBusiness/Dto/System/DictDetailDto.cs b/Ape.Volo.IBusiness/Dto/System/DictDetailDto.cs index a0af9ba..14e223f 100644 --- a/Ape.Volo.IBusiness/Dto/System/DictDetailDto.cs +++ b/Ape.Volo.IBusiness/Dto/System/DictDetailDto.cs @@ -31,10 +31,5 @@ public class DictDetailDto : BaseEntityDto /// /// 排序 /// - public string DictSort { get; set; } - - /// - /// 字典 - /// - public DictDto2 Dict { get; set; } + public int DictSort { get; set; } } diff --git a/Ape.Volo.IBusiness/Dto/System/DictDto.cs b/Ape.Volo.IBusiness/Dto/System/DictDto.cs index 4907233..10341ef 100644 --- a/Ape.Volo.IBusiness/Dto/System/DictDto.cs +++ b/Ape.Volo.IBusiness/Dto/System/DictDto.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Ape.Volo.Common.AttributeExt; +using Ape.Volo.Common.Enums; using Ape.Volo.Entity.System; using Ape.Volo.IBusiness.Base; @@ -11,6 +12,12 @@ namespace Ape.Volo.IBusiness.Dto.System; [AutoMapping(typeof(Dict), typeof(DictDto))] public class DictDto : BaseEntityDto { + /// + /// 字典类型 + /// + /// + public DictType DictType { get; set; } + /// /// 名称 /// diff --git a/Ape.Volo.IBusiness/Dto/System/DictDto2.cs b/Ape.Volo.IBusiness/Dto/System/DictDto2.cs deleted file mode 100644 index a4b78e7..0000000 --- a/Ape.Volo.IBusiness/Dto/System/DictDto2.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Ape.Volo.IBusiness.Dto.System; - -/// -/// 字典Dto -/// -//[AutoInject(typeof(Dict), typeof(DictDTO2))] -public class DictDto2 -{ - /// - /// ID - /// - public long Id { get; set; } -} diff --git a/Ape.Volo.IBusiness/ExportModel/System/DictExport.cs b/Ape.Volo.IBusiness/ExportModel/System/DictExport.cs index db5d642..0e5b1e9 100644 --- a/Ape.Volo.IBusiness/ExportModel/System/DictExport.cs +++ b/Ape.Volo.IBusiness/ExportModel/System/DictExport.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Ape.Volo.Common.Enums; using Ape.Volo.Common.Model; namespace Ape.Volo.IBusiness.ExportModel.System; @@ -8,6 +9,12 @@ namespace Ape.Volo.IBusiness.ExportModel.System; /// public class DictExport : ExportBase { + /// + /// 字典类型 + /// + [Display(Name = "字典类型")] + public DictType DictType { get; set; } + /// /// 字典名称 /// diff --git a/Ape.Volo.IBusiness/Interface/Permission/IDepartmentService.cs b/Ape.Volo.IBusiness/Interface/Permission/IDepartmentService.cs index c94e2d9..64986fd 100644 --- a/Ape.Volo.IBusiness/Interface/Permission/IDepartmentService.cs +++ b/Ape.Volo.IBusiness/Interface/Permission/IDepartmentService.cs @@ -75,7 +75,7 @@ public interface IDepartmentService : IBaseServices /// /// /// - Task> QuerySuperiorDeptAsync(HashSet ids); + Task> QuerySuperiorDeptAsync(long id); /// /// 获取所选部门及全部下级部门ID diff --git a/Ape.Volo.IBusiness/Interface/System/IDictDetailService.cs b/Ape.Volo.IBusiness/Interface/System/IDictDetailService.cs index 40186d3..7009268 100644 --- a/Ape.Volo.IBusiness/Interface/System/IDictDetailService.cs +++ b/Ape.Volo.IBusiness/Interface/System/IDictDetailService.cs @@ -34,16 +34,14 @@ public interface IDictDetailService : IBaseServices /// /// /// - Task DeleteAsync(string id); + Task DeleteAsync(long id); /// /// 查询 /// - /// - /// + /// /// - Task> QueryAsync(DictDetailQueryCriteria dictDetailQueryCriteria, - Pagination pagination); + Task> QueryAsync(string dictName); #endregion } diff --git a/Ape.Volo.IBusiness/Interface/System/ISettingService.cs b/Ape.Volo.IBusiness/Interface/System/ISettingService.cs index b85076b..9a0a5ac 100644 --- a/Ape.Volo.IBusiness/Interface/System/ISettingService.cs +++ b/Ape.Volo.IBusiness/Interface/System/ISettingService.cs @@ -56,7 +56,7 @@ public interface ISettingService : IBaseServices /// /// /// - Task FindSettingByName(string settingName); + Task GetSettingValue(string settingName); #endregion } diff --git a/Ape.Volo.IBusiness/QueryModel/DictQueryCriteria.cs b/Ape.Volo.IBusiness/QueryModel/DictQueryCriteria.cs index e053530..4959d0b 100644 --- a/Ape.Volo.IBusiness/QueryModel/DictQueryCriteria.cs +++ b/Ape.Volo.IBusiness/QueryModel/DictQueryCriteria.cs @@ -1,3 +1,5 @@ +using Ape.Volo.Common.Enums; + namespace Ape.Volo.IBusiness.QueryModel; /// @@ -9,4 +11,9 @@ public class DictQueryCriteria /// 关键字 /// public string KeyWords { get; set; } + + /// + /// 类型 + /// + public DictType? DictType { get; set; } } diff --git a/Ape.Volo.Repository/SugarHandler/SugarRepository.cs b/Ape.Volo.Repository/SugarHandler/SugarRepository.cs index ce0d182..d74c80a 100644 --- a/Ape.Volo.Repository/SugarHandler/SugarRepository.cs +++ b/Ape.Volo.Repository/SugarHandler/SugarRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; @@ -39,8 +40,8 @@ public SugarRepository(IUnitOfWork unitOfWork) var httpUser = AutofacHelper.GetService(); if (httpUser.IsNotNull() && httpUser.TenantId > 0) { - var tenant = sqlSugarScope.Queryable().WithCache(86400) - .First(x => x.TenantId == httpUser.TenantId); + var tenants = sqlSugarScope.Queryable().WithCache(86400).ToList(); + var tenant = tenants.FirstOrDefault(x => x.TenantId == httpUser.TenantId); if (tenant != null) { var iTenant = sqlSugarScope.AsTenant();