ruoyi对接

登录接口、用户信息接口、用户管理接口等
This commit is contained in:
陈淳
2022-09-07 18:22:15 +08:00
parent bf17312a5f
commit 781fa7ea1b
8 changed files with 52 additions and 7 deletions

View File

@@ -44,13 +44,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[HttpPost] [HttpPost]
public async Task<Result> Login(LoginDto loginDto) public async Task<Result> Login(LoginDto loginDto)
{ {
//跳过
//先效验验证码和UUID
UserEntity user = new(); UserEntity user = new();
if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o)) if (await _iUserService.Login(loginDto.UserName, loginDto.Password, o => user = o))
{ {
var userRoleMenu= await _iUserService.GetUserAllInfo(user.Id); var userRoleMenu= await _iUserService.GetUserAllInfo(user.Id);
return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User,userRoleMenu.Menus) }); return Result.Success("登录成功!").SetData(new { token = _jwtInvoker.GetAccessToken(userRoleMenu.User,userRoleMenu.Menus) });
} }
return Result.SuccessError("登录失败!用户名或者密码错误!"); return Result.Error("登录失败!用户名或者密码错误!");
} }
/// <summary> /// <summary>
@@ -90,11 +94,13 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{ {
//通过鉴权jwt获取到用户的id //通过鉴权jwt获取到用户的id
var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id; var userId = HttpContext.GetCurrentUserEntityInfo(out _).Id;
var data = await _iUserService.GetUserAllInfo(userId);
return Result.Success().SetData(await _iUserService.GetUserAllInfo(userId)); data.Menus.Clear();
return Result.Success().SetData(data);
} }
/// <summary> /// <summary>
/// 更新登录的用户密码 /// 更新登录的用户密码
/// </summary> /// </summary>

View File

@@ -35,7 +35,6 @@ namespace Yi.Framework.ApiMicroservice.Controllers
} }
/// <summary> /// <summary>
/// 得到树形菜单 /// 得到树形菜单
/// </summary> /// </summary>

View File

@@ -30,9 +30,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
} }
[HttpGet] [HttpGet]
public async Task<Result> PageList() public async Task<Result> PageList([FromQuery]UserEntity user, [FromQuery] PageParModel page)
{ {
return Result.Success().SetData(await _iUserService._repository.GetListAsync()); return Result.Success().SetData(new PageModel(await _iUserService._repository.GetListAsync(),100) );
} }
/// <summary> /// <summary>

View File

@@ -9,11 +9,21 @@ namespace Yi.Framework.Common.Models
public class PageModel<T> public class PageModel<T>
{ {
public PageModel() { }
public PageModel(T data,int total)
{
Data = data;
Total = total;
}
public int Total { get; set; } public int Total { get; set; }
public T Data { get; set; } public T Data { get; set; }
} }
public class PageModel : PageModel<object> public class PageModel : PageModel<object>
{ {
public PageModel() { }
public PageModel(object data, int total) : base(data, total)
{
}
} }
} }

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Common.Models
{
public class PageParModel
{
public int PageNum { get; set; }
public int PageSize { get; set; }
}
}

View File

@@ -10,5 +10,9 @@ namespace Yi.Framework.DTOModel
{ {
public string UserName { get; set; } public string UserName { get; set; }
public string Password { get; set; } public string Password { get; set; }
public string Uuid { get; set; }
public string Code { get; set; }
} }
} }

View File

@@ -13,5 +13,7 @@ namespace Yi.Framework.DTOModel
public HashSet<RoleEntity> Roles { get; set; } = new(); public HashSet<RoleEntity> Roles { get; set; } = new();
public HashSet<MenuEntity> Menus { get; set; }=new(); public HashSet<MenuEntity> Menus { get; set; }=new();
public List<string> RoleCodes { get; set; } =new();
public List<string> PermissionCodes { get; set; } = new();
} }
} }

View File

@@ -121,9 +121,15 @@ namespace Yi.Framework.Service
//得到菜单集合 //得到菜单集合
foreach (var role in roleList) foreach (var role in roleList)
{ {
userRoleMenu.RoleCodes.Add(role.RoleCode);
foreach (var menu in role.Menus) foreach (var menu in role.Menus)
{ {
userRoleMenu.Menus.Add(menu); if (!string.IsNullOrEmpty(menu.PermissionCode))
{
userRoleMenu.PermissionCodes.Add(menu.PermissionCode);
userRoleMenu.Menus.Add(menu);
}
} }
//刚好可以去除一下多余的导航属性 //刚好可以去除一下多余的导航属性
role.Menus = null; role.Menus = null;
@@ -133,6 +139,9 @@ namespace Yi.Framework.Service
user.Roles = null; user.Roles = null;
userRoleMenu.User = user; userRoleMenu.User = user;
return userRoleMenu; return userRoleMenu;
} }