Skip to content

Commit

Permalink
[feat] 字典、设置增加二级缓存处理
Browse files Browse the repository at this point in the history
  • Loading branch information
xianhc committed Jun 27, 2024
1 parent 0fa1123 commit f68988a
Show file tree
Hide file tree
Showing 30 changed files with 276 additions and 145 deletions.
4 changes: 2 additions & 2 deletions Ape.Volo.Api/Authentication/Jwt/PermissionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("IsAdminNotAuthentication");
if (value)
{
// loginUserInfo = await _apeContext.Cache.GetAsync<LoginUserInfo>(
// GlobalConstants.CacheKey.OnlineKey +
Expand Down
13 changes: 6 additions & 7 deletions Ape.Volo.Api/Controllers/Permission/DeptController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,19 @@ public async Task<ActionResult<object>> Download(DeptQueryCriteria deptQueryCrit
/// <summary>
/// 获取同级与父级部门
/// </summary>
/// <param name="idCollection"></param>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
[HttpGet]
[Route("superior")]
[Description("获取同级、父级部门")]
public async Task<ActionResult<object>> GetSuperior([FromBody] IdCollection idCollection)
public async Task<ActionResult<object>> 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<DepartmentDto>
{
Expand Down
13 changes: 6 additions & 7 deletions Ape.Volo.Api/Controllers/Permission/MenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,19 @@ public async Task<ActionResult<object>> Download(MenuQueryCriteria menuQueryCrit
/// <summary>
/// 获取同级与上级菜单
/// </summary>
/// <param name="idCollection"></param>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
[HttpGet]
[Description("获取同级、父级菜单")]
[Route("superior")]
public async Task<ActionResult<object>> GetSuperior([FromBody] IdCollection idCollection)
public async Task<ActionResult<object>> 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();
}

Expand Down
21 changes: 11 additions & 10 deletions Ape.Volo.Api/Controllers/System/DictDetailController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -85,11 +88,11 @@ public async Task<ActionResult<object>> Update(
[HttpDelete]
[Route("delete")]
[Description("删除")]
public async Task<ActionResult<object>> Delete(string id)
public async Task<ActionResult<object>> Delete(long id)
{
if (id.IsNullOrEmpty())
{
return Error("id is null");
return Error("id cannot be empty");
}

await _dictDetailService.DeleteAsync(id);
Expand All @@ -99,20 +102,18 @@ public async Task<ActionResult<object>> Delete(string id)
/// <summary>
/// 查看字典详情列表
/// </summary>
/// <param name="dictDetailQueryCriteria"></param>
/// <param name="pagination"></param>
/// <param name="dictName"></param>
/// <returns></returns>
[HttpGet]
[Route("query")]
[Description("查询")]
public async Task<ActionResult<object>> Query(DictDetailQueryCriteria dictDetailQueryCriteria,
Pagination pagination)
public async Task<ActionResult<object>> Query(string dictName)
{
var list = await _dictDetailService.QueryAsync(dictDetailQueryCriteria, pagination);
var list = await _dictDetailService.QueryAsync(dictName);
return JsonContent(new ActionResultVm<DictDetailDto>
{
Content = list,
TotalElements = pagination.TotalElements
TotalElements = list.Count
});
}

Expand Down
3 changes: 2 additions & 1 deletion Ape.Volo.Api/Filter/AuditingFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("IsAuditLogSaveDB");
if (saveDb)
{
var result = resultContext.Result;
if (context.HttpContext.IsNotNull() && result.IsNotNull())
Expand Down
4 changes: 2 additions & 2 deletions Ape.Volo.Api/Filter/GlobalExceptionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("IsExceptionLogSaveDB");
if (saveDb && exceptionType != typeof(DemoRequestException))
{
//记录日志到数据库
try
Expand Down
4 changes: 2 additions & 2 deletions Ape.Volo.Api/wwwroot/resources/db/sys_apis.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"group":"部门管理",
"url":"/api/dept/superior",
"description":"获取同级、父级部门",
"method":"POST",
"method":"GET",
"isDeleted":false,
"createBy":"apevolo",
"CreateTime":"\/Date(1609430400000+0800)\/",
Expand Down Expand Up @@ -363,7 +363,7 @@
"group":"菜单管理",
"url":"/api/menu/superior",
"description":"获取同级、父级菜单",
"method":"POST",
"method":"GET",
"isDeleted":false,
"createBy":"apevolo",
"CreateTime":"\/Date(1609430400000+0800)\/",
Expand Down
19 changes: 19 additions & 0 deletions Ape.Volo.Api/wwwroot/resources/db/sys_dict.tsv
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -11,6 +23,7 @@
},
{
"Id": "1306054134645919765",
"DictType": 2,
"Name": "dept_status",
"Description": "部门状态",
"CreateBy": "apevolo",
Expand All @@ -21,6 +34,7 @@
},
{
"Id": "1306054134645919766",
"DictType": 2,
"Name": "user_status",
"Description": "用户状态",
"CreateBy": "apevolo",
Expand All @@ -31,6 +45,7 @@
},
{
"Id": "1380547002701451264",
"DictType": 2,
"Name": "email_message_template_status",
"Description": "邮件消息模板状态",
"CreateBy": "apevolo",
Expand All @@ -41,6 +56,7 @@
},
{
"Id": "1425449857383927808",
"DictType": 2,
"Name": "setting_status",
"Description": "全局设置状态",
"CreateBy": "apevolo",
Expand All @@ -51,6 +67,7 @@
},
{
"Id": "1787853620566298624",
"DictType": 1,
"Name": "task_trigger_type",
"Description": "作业触发器类型",
"CreateBy": "apevolo",
Expand All @@ -61,6 +78,7 @@
},
{
"Id": "1799832537057464320",
"DictType": 1,
"Name": "tenant_type",
"Description": "租户类型",
"CreateBy": "apevolo",
Expand All @@ -71,6 +89,7 @@
},
{
"Id": "1799832924720205824",
"DictType": 1,
"Name": "db_type",
"Description": "数据库类型",
"CreateBy": "apevolo",
Expand Down
Loading

0 comments on commit f68988a

Please sign in to comment.