|
@@ -1,9 +1,13 @@
|
|
|
using Hotline.Repository.SqlSugar;
|
|
|
using Hotline.Settings;
|
|
|
+using Hotline.Share.Dtos.Home;
|
|
|
+using MapsterMapper;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using SqlSugar;
|
|
|
using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+
|
|
|
namespace Hotline.Api.Controllers;
|
|
|
|
|
|
/// <summary>
|
|
@@ -15,17 +19,23 @@ public class HomeController : BaseController
|
|
|
private readonly ISessionContext _sessionContext;
|
|
|
private readonly ISystemAuthorityRepository _systemAuthorityRepository;
|
|
|
private readonly ISystemMenuRepository _systemMenuRepository;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly IUserFastMenuRepository _userFastMenuRepository;
|
|
|
|
|
|
public HomeController(
|
|
|
ISugarUnitOfWork<HotlineDbContext> uow,
|
|
|
ISessionContext sessionContext,
|
|
|
ISystemAuthorityRepository systemAuthorityRepository,
|
|
|
- ISystemMenuRepository systemMenuRepository)
|
|
|
+ ISystemMenuRepository systemMenuRepository,
|
|
|
+ IMapper mapper,
|
|
|
+ IUserFastMenuRepository userFastMenuRepository)
|
|
|
{
|
|
|
_uow = uow;
|
|
|
_sessionContext = sessionContext;
|
|
|
_systemAuthorityRepository = systemAuthorityRepository;
|
|
|
_systemMenuRepository = systemMenuRepository;
|
|
|
+ _mapper = mapper;
|
|
|
+ _userFastMenuRepository = userFastMenuRepository;
|
|
|
}
|
|
|
|
|
|
#region 开放请求接口
|
|
@@ -36,14 +46,12 @@ public class HomeController : BaseController
|
|
|
{
|
|
|
var db = _uow.Db;
|
|
|
db.DbMaintenance.CreateDatabase();
|
|
|
- db.CodeFirst.InitTables<SystemMenu, SystemAuthority,SystemButton,SystemOrganize,OrgUser>();
|
|
|
- db.CodeFirst.InitTables<SystemDataAuthority>();
|
|
|
-
|
|
|
+ db.CodeFirst.InitTables<UserFastMenu>();
|
|
|
return Task.CompletedTask;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 获取可选快速入口
|
|
|
+ /// 获取可选快捷入口
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[AllowAnonymous]
|
|
@@ -51,9 +59,49 @@ public class HomeController : BaseController
|
|
|
public async Task<IReadOnlyList<SystemMenu>> GetFastMenuByToken()
|
|
|
{
|
|
|
var roles = _sessionContext.Roles;
|
|
|
- return await _systemMenuRepository.GetFastMenuByToken(roles);
|
|
|
+ return await _systemMenuRepository.GetFastMenu(roles,_sessionContext.UserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 设置快捷入口
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [AllowAnonymous]
|
|
|
+ [HttpPost("set-fastmenu")]
|
|
|
+ public async Task SetFastMenu([FromBody]SetFastMenuDto dto)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(_sessionContext.UserId))
|
|
|
+ {
|
|
|
+ string userId = _sessionContext.UserId;
|
|
|
+ var model = await _userFastMenuRepository.GetAsync(x => x.UserId == dto.UserId);
|
|
|
+ if (model is null)
|
|
|
+ {
|
|
|
+ var fastmenu = _mapper.Map<UserFastMenu>(dto);
|
|
|
+ await _userFastMenuRepository.AddAsync(fastmenu);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _mapper.Map(dto, model);
|
|
|
+ await _userFastMenuRepository.UpdateAsync(model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw UserFriendlyException.SameMessage("无效用户");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取我的快捷入口
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [AllowAnonymous]
|
|
|
+ [HttpGet("get-myfastmenu")]
|
|
|
+ public async Task<IReadOnlyList<SystemMenu>> GetMyFastMenu()
|
|
|
+ {
|
|
|
+ var roles = _sessionContext.Roles;
|
|
|
+ return await _systemMenuRepository.GetMyFastMenu(roles, _sessionContext.UserId);
|
|
|
+ }
|
|
|
|
|
|
#endregion
|
|
|
|