路由构建充血模型
This commit is contained in:
Binary file not shown.
@@ -113,7 +113,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
var data = await _iUserService.GetUserAllInfo(userId);
|
var data = await _iUserService.GetUserAllInfo(userId);
|
||||||
|
|
||||||
//将后端菜单转换成前端路由,组件级别需要过滤
|
//将后端菜单转换成前端路由,组件级别需要过滤
|
||||||
List<VueRouterModel> routers = _iUserService.RouterBuild(data.Menus.ToList());
|
List<VueRouterModel> routers = MenuEntity.RouterBuild(data.Menus.ToList());
|
||||||
return Result.Success().SetData(routers);
|
return Result.Success().SetData(routers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,24 +54,6 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// 添加用户,去重,密码加密
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="entity"></param>
|
|
||||||
///// <returns></returns>
|
|
||||||
//[Permission($"{nameof(UserEntity)}:add")]
|
|
||||||
//[HttpPost]
|
|
||||||
//public async Task<Result> Add(UserEntity entity)
|
|
||||||
//{
|
|
||||||
// if (!await _iUserService.Exist(entity.UserName))
|
|
||||||
// {
|
|
||||||
// entity.BuildPassword();
|
|
||||||
// return Result.Success().SetData(await _iUserService._repository.InsertReturnSnowflakeIdAsync(entity));
|
|
||||||
// }
|
|
||||||
// return Result.SuccessError("用户已存在");
|
|
||||||
//}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 给多用户设置多角色
|
/// 给多用户设置多角色
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Binary file not shown.
@@ -78,12 +78,6 @@ namespace Yi.Framework.Interface
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PageModel<List<UserEntity>>> SelctPageList(UserEntity user, PageParModel page);
|
Task<PageModel<List<UserEntity>>> SelctPageList(UserEntity user, PageParModel page);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 菜单构建前端路由
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menus"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
List<VueRouterModel> RouterBuild(List<MenuEntity> menus);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新用户信息
|
/// 更新用户信息
|
||||||
@@ -106,5 +100,6 @@ namespace Yi.Framework.Interface
|
|||||||
/// <param name="password"></param>
|
/// <param name="password"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<bool> RestPassword(long userId,string password );
|
Task<bool> RestPassword(long userId,string password );
|
||||||
|
Task<bool> GiveUserSetPost(List<long> userIds, List<long> postIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Yi.Framework.Common.Enum;
|
||||||
|
using Yi.Framework.Common.Models;
|
||||||
|
|
||||||
namespace Yi.Framework.Model.Models
|
namespace Yi.Framework.Model.Models
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -11,5 +14,56 @@ namespace Yi.Framework.Model.Models
|
|||||||
{
|
{
|
||||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||||
public List<MenuEntity> Children { get; set; }
|
public List<MenuEntity> Children { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public static List<VueRouterModel> RouterBuild(List<MenuEntity> menus)
|
||||||
|
{
|
||||||
|
menus = menus.Where(m => m.MenuType != null && m.MenuType != MenuTypeEnum.Component.GetHashCode()).ToList();
|
||||||
|
List<VueRouterModel> routers = new();
|
||||||
|
foreach (var m in menus)
|
||||||
|
{
|
||||||
|
|
||||||
|
var r = new VueRouterModel();
|
||||||
|
var routerName = m.Router.Split("/").LastOrDefault();
|
||||||
|
r.Id = m.Id;
|
||||||
|
r.ParentId = (long)m.ParentId;
|
||||||
|
|
||||||
|
//开头大写
|
||||||
|
r.Name = routerName.First().ToString().ToUpper() + routerName.Substring(1);
|
||||||
|
r.Path = m.Router;
|
||||||
|
r.Hidden = (bool)!m.IsShow;
|
||||||
|
|
||||||
|
|
||||||
|
if (m.MenuType == MenuTypeEnum.Catalogue.GetHashCode())
|
||||||
|
{
|
||||||
|
r.Redirect = "noRedirect";
|
||||||
|
r.AlwaysShow = true;
|
||||||
|
r.Component = "Layout";
|
||||||
|
}
|
||||||
|
if (m.MenuType == MenuTypeEnum.Menu.GetHashCode())
|
||||||
|
{
|
||||||
|
|
||||||
|
r.Redirect = "noRedirect";
|
||||||
|
r.AlwaysShow = true;
|
||||||
|
r.Component = m.Component;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
r.Meta = new Meta
|
||||||
|
{
|
||||||
|
Title = m.MenuName,
|
||||||
|
Icon = m.MenuIcon,
|
||||||
|
NoCache = (bool)!m.IsCache
|
||||||
|
};
|
||||||
|
if ((bool)m.IsLink)
|
||||||
|
{
|
||||||
|
r.Meta.link = m.Router;
|
||||||
|
}
|
||||||
|
|
||||||
|
routers.Add(r);
|
||||||
|
}
|
||||||
|
return Common.Helper.TreeHelper.SetTree(routers);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ namespace Yi.Framework.Model.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 部门id
|
/// 部门id
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName="Dept" )]
|
[SugarColumn(ColumnName="DeptId" )]
|
||||||
public long? Dept { get; set; }
|
public long? DeptId { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建者
|
/// 创建者
|
||||||
///</summary>
|
///</summary>
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ namespace Yi.Framework.Model.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 岗位id
|
/// 岗位id
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName="Post" )]
|
[SugarColumn(ColumnName= "PostId")]
|
||||||
public long? Post { get; set; }
|
public long? PostId { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建者
|
/// 创建者
|
||||||
///</summary>
|
///</summary>
|
||||||
|
|||||||
@@ -101,6 +101,34 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<bool> GiveUserSetPost(List<long> userIds, List<long> postIds)
|
||||||
|
{
|
||||||
|
var _repositoryUserPost = _repository.ChangeRepository<Repository<UserPostEntity>>();
|
||||||
|
|
||||||
|
//多次操作,需要事务确保原子性
|
||||||
|
return await _repositoryUserPost.UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||||
|
await _repositoryUserPost.DeleteAsync(u => userIds.Contains((long)u.UserId));
|
||||||
|
|
||||||
|
//遍历用户
|
||||||
|
foreach (var userId in userIds)
|
||||||
|
{
|
||||||
|
//添加新的关系
|
||||||
|
List<UserPostEntity> userPostEntities = new();
|
||||||
|
foreach (var post in postIds)
|
||||||
|
{
|
||||||
|
userPostEntities.Add(new UserPostEntity() { UserId = userId,PostId = post });
|
||||||
|
}
|
||||||
|
|
||||||
|
//一次性批量添加
|
||||||
|
await _repositoryUserPost.InsertReturnSnowflakeIdAsync(userPostEntities);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<UserEntity> GetInfoById(long userId)
|
public async Task<UserEntity> GetInfoById(long userId)
|
||||||
{
|
{
|
||||||
return await _repository._DbQueryable.Includes(u => u.Roles).InSingleAsync(userId);
|
return await _repository._DbQueryable.Includes(u => u.Roles).InSingleAsync(userId);
|
||||||
@@ -173,55 +201,8 @@ namespace Yi.Framework.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<VueRouterModel> RouterBuild(List<MenuEntity> menus)
|
|
||||||
{
|
|
||||||
menus = menus.Where(m => m.MenuType != null && m.MenuType != MenuTypeEnum.Component.GetHashCode()).ToList();
|
|
||||||
List<VueRouterModel> routers = new();
|
|
||||||
foreach (var m in menus)
|
|
||||||
{
|
|
||||||
|
|
||||||
var r = new VueRouterModel();
|
|
||||||
var routerName = m.Router.Split("/").LastOrDefault();
|
|
||||||
r.Id = m.Id;
|
|
||||||
r.ParentId = (long)m.ParentId;
|
|
||||||
|
|
||||||
//开头大写
|
|
||||||
r.Name = routerName.First().ToString().ToUpper() + routerName.Substring(1);
|
|
||||||
r.Path = m.Router;
|
|
||||||
r.Hidden = (bool)!m.IsShow;
|
|
||||||
|
|
||||||
|
|
||||||
if (m.MenuType == MenuTypeEnum.Catalogue.GetHashCode())
|
|
||||||
{
|
|
||||||
r.Redirect = "noRedirect";
|
|
||||||
r.AlwaysShow = true;
|
|
||||||
r.Component = "Layout";
|
|
||||||
}
|
|
||||||
if (m.MenuType == MenuTypeEnum.Menu.GetHashCode())
|
|
||||||
{
|
|
||||||
|
|
||||||
r.Redirect = "noRedirect";
|
|
||||||
r.AlwaysShow = true;
|
|
||||||
r.Component = m.Component;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
r.Meta = new Meta
|
|
||||||
{
|
|
||||||
Title = m.MenuName,
|
|
||||||
Icon = m.MenuIcon,
|
|
||||||
NoCache = (bool)!m.IsCache
|
|
||||||
};
|
|
||||||
if ((bool)m.IsLink)
|
|
||||||
{
|
|
||||||
r.Meta.link = m.Router;
|
|
||||||
}
|
|
||||||
|
|
||||||
routers.Add(r);
|
|
||||||
}
|
|
||||||
return Common.Helper.TreeHelper.SetTree(routers) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> UpdateInfo(UserInfoDto userDto)
|
public async Task<bool> UpdateInfo(UserInfoDto userDto)
|
||||||
{
|
{
|
||||||
//未填写密码,可不更新
|
//未填写密码,可不更新
|
||||||
@@ -230,9 +211,11 @@ namespace Yi.Framework.Service
|
|||||||
{
|
{
|
||||||
userDto.User.BuildPassword();
|
userDto.User.BuildPassword();
|
||||||
}
|
}
|
||||||
|
userDto.User.DeptId = userDto.DeptId;
|
||||||
var res1 = await _repository.UpdateIgnoreNullAsync(userDto.User);
|
var res1 = await _repository.UpdateIgnoreNullAsync(userDto.User);
|
||||||
var res2 = await GiveUserSetRole(new List<long> { userDto.User.Id }, userDto.RoleIds);
|
var res2 = await GiveUserSetRole(new List<long> { userDto.User.Id }, userDto.RoleIds);
|
||||||
return res1 && res2;
|
var res3 = await GiveUserSetPost(new List<long> { userDto.User.Id }, userDto.PostIds);
|
||||||
|
return res1 && res2&& res3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> AddInfo(UserInfoDto userDto)
|
public async Task<bool> AddInfo(UserInfoDto userDto)
|
||||||
@@ -240,7 +223,8 @@ namespace Yi.Framework.Service
|
|||||||
userDto.User.BuildPassword();
|
userDto.User.BuildPassword();
|
||||||
var res1 = await _repository.InsertReturnSnowflakeIdAsync(userDto.User);
|
var res1 = await _repository.InsertReturnSnowflakeIdAsync(userDto.User);
|
||||||
var res2 = await GiveUserSetRole(new List<long> { res1 }, userDto.RoleIds);
|
var res2 = await GiveUserSetRole(new List<long> { res1 }, userDto.RoleIds);
|
||||||
return !0.Equals(res1) && res2;
|
var res3 = await GiveUserSetPost(new List<long> { res1 }, userDto.PostIds);
|
||||||
|
return !0.Equals(res1) && res2&& res3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> RestPassword(long userId, string password)
|
public async Task<bool> RestPassword(long userId, string password)
|
||||||
|
|||||||
Reference in New Issue
Block a user