联调前端用户管理及角色管理
This commit is contained in:
@@ -155,6 +155,13 @@
|
||||
用户管理
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.Add(Yi.Framework.Model.Models.UserEntity)">
|
||||
<summary>
|
||||
添加用户,去重,密码加密
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GiveUserSetRole(Yi.Framework.DTOModel.GiveUserSetRoleDto)">
|
||||
<summary>
|
||||
给多用户设置多角色
|
||||
@@ -162,5 +169,11 @@
|
||||
<param name="giveUserSetRoleDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.GetRoleListByUserId(System.Int64)">
|
||||
<summary>
|
||||
通过用户id得到角色列表
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:one")]
|
||||
[HttpGet]
|
||||
public async Task<Result> GetById(long id)
|
||||
public virtual async Task<Result> GetById(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetByIdAsync(id));
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:list")]
|
||||
[HttpPost]
|
||||
public async Task<Result> GetList(QueryCondition queryCondition)
|
||||
public virtual async Task<Result> GetList(QueryCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetListAsync(queryCondition));
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get:page")]
|
||||
[HttpPost]
|
||||
public async Task<Result> PageList(QueryPageCondition queryCondition)
|
||||
public virtual async Task<Result> PageList(QueryPageCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.CommonPageAsync(queryCondition));
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:add")]
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(T entity)
|
||||
public virtual async Task<Result> Add(T entity)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.InsertReturnSnowflakeIdAsync(entity));
|
||||
}
|
||||
@@ -81,7 +81,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:update")]
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(T entity)
|
||||
public virtual async Task<Result> Update(T entity)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.UpdateIgnoreNullAsync(entity));
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:delete:list")]
|
||||
[HttpDelete]
|
||||
public async Task<Result> DeleteList(List<long> ids)
|
||||
public virtual async Task<Result> DeleteList(List<long> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.DeleteByLogicAsync(ids));
|
||||
}
|
||||
|
||||
@@ -39,5 +39,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,23 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
_iUserService = iUserService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户,去重,密码加密
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(UserEntity)}:add")]
|
||||
[HttpPost]
|
||||
public override 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>
|
||||
@@ -37,7 +54,18 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[HttpPut]
|
||||
public async Task<Result> GiveUserSetRole(GiveUserSetRoleDto giveUserSetRoleDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.GiveUserSetRole(giveUserSetRoleDto.UserIds,giveUserSetRoleDto.RoleIds));
|
||||
return Result.Success().SetStatus(await _iUserService.GiveUserSetRole(giveUserSetRoleDto.UserIds, giveUserSetRoleDto.RoleIds));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户id得到角色列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetRoleListByUserId(long userId)
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetRoleListByUserId(userId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -44,5 +44,20 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> GiveUserSetRole(List<long> userIds, List<long> roleIds);
|
||||
|
||||
/// <summary>
|
||||
/// 判断用户名是否存在,如果存在可返回该用户
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="userAction"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> Exist(string userName, Action<UserEntity> userAction = null);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户id得到角色列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<RoleEntity>> GetRoleListByUserId(long userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ namespace Yi.Framework.Model.Models
|
||||
public partial class MenuEntity
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsIgnore = true)]
|
||||
public List<MenuEntity> Childs { get; set; }
|
||||
public List<MenuEntity> Children { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
@@ -15,10 +16,8 @@ namespace Yi.Framework.Model.Models
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
@@ -15,10 +16,8 @@ namespace Yi.Framework.Model.Models
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
@@ -15,10 +16,8 @@ namespace Yi.Framework.Model.Models
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
@@ -15,10 +16,8 @@ namespace Yi.Framework.Model.Models
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
@@ -15,10 +16,10 @@ namespace Yi.Framework.Model.Models
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
@@ -75,5 +76,35 @@ namespace Yi.Framework.Model.Models
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Salt" )]
|
||||
public string Salt { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Icon" )]
|
||||
public long? Icon { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Nick" )]
|
||||
public string Nick { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Email" )]
|
||||
public string Email { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Ip" )]
|
||||
public string Ip { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Address" )]
|
||||
public string Address { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Phone" )]
|
||||
public string Phone { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
@@ -15,10 +16,8 @@ namespace Yi.Framework.Model.Models
|
||||
this.IsDeleted = false;
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
/// <summary>
|
||||
/// 1
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
14
Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs
Normal file
14
Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
|
||||
public partial class RoleEntity
|
||||
{
|
||||
//[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.RoleId), nameof(UserRoleEntity.UserId))]
|
||||
//public List<UserEntity> Users { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,21 @@ namespace Yi.Framework.Model.Models
|
||||
/// 看好啦!ORM精髓,导航属性
|
||||
///</summary>
|
||||
[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))]
|
||||
public List<RoleEntity> Roles { get; set; }
|
||||
public List<RoleEntity> Roles { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构建密码,MD5盐值加密
|
||||
/// </summary>
|
||||
public void BuildPassword(string password = null)
|
||||
{
|
||||
//如果不传值,那就把自己的password当作传进来的password
|
||||
if (password == null)
|
||||
{
|
||||
password = this.Password;
|
||||
}
|
||||
this.Salt = Common.Helper.MD5Helper.GenerateSalt();
|
||||
this.Password = Common.Helper.MD5Helper.SHA2Encode(password, this.Salt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Yi.Framework.Service
|
||||
{
|
||||
//ParentId 0,代表为根目录,只能存在一个
|
||||
//复杂查询直接使用db代理
|
||||
return await _repository._Db.Queryable<MenuEntity>().ToTreeAsync(it=>it.Childs,it=>it.ParentId,0);
|
||||
return await _repository._Db.Queryable<MenuEntity>().ToTreeAsync(it=>it.Children,it=>it.ParentId,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,5 +41,6 @@ namespace Yi.Framework.Service
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Yi.Framework.Service
|
||||
{
|
||||
return await _repository._Db.Queryable<UserEntity>().ToListAsync();
|
||||
}
|
||||
public async Task<bool> Exist(Guid id, Action<UserEntity> userAction = null)
|
||||
public async Task<bool> Exist(long id, Action<UserEntity> userAction = null)
|
||||
{
|
||||
var user = await _repository.GetByIdAsync(id);
|
||||
userAction.Invoke(user);
|
||||
@@ -58,8 +58,7 @@ namespace Yi.Framework.Service
|
||||
if (!await Exist(userEntity.UserName))
|
||||
{
|
||||
user.UserName = userEntity.UserName;
|
||||
user.Salt = Common.Helper.MD5Helper.GenerateSalt();
|
||||
user.Password = Common.Helper.MD5Helper.SHA2Encode(userEntity.Password, user.Salt);
|
||||
user.BuildPassword();
|
||||
userAction.Invoke(await _repository.InsertReturnEntityAsync(user));
|
||||
return true;
|
||||
}
|
||||
@@ -79,23 +78,29 @@ namespace Yi.Framework.Service
|
||||
return await _repositoryUserRole.UseTranAsync(async () =>
|
||||
{
|
||||
|
||||
//遍历用户
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryUserRole.DeleteAsync(u => u.UserId == userId);
|
||||
//遍历用户
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryUserRole.DeleteAsync(u => u.UserId == userId);
|
||||
|
||||
//添加新的关系
|
||||
List<UserRoleEntity> userRoleEntities = new();
|
||||
//添加新的关系
|
||||
List<UserRoleEntity> userRoleEntities = new();
|
||||
foreach (var roleId in roleIds)
|
||||
{
|
||||
userRoleEntities.Add(new UserRoleEntity() { UserId = userId, RoleId = roleId });
|
||||
}
|
||||
|
||||
//一次性批量添加
|
||||
await _repositoryUserRole.InsertRangeAsync(userRoleEntities);
|
||||
//一次性批量添加
|
||||
await _repositoryUserRole.InsertRangeAsync(userRoleEntities);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<RoleEntity>> GetRoleListByUserId(long userId)
|
||||
{
|
||||
return (await _repository._Db.Queryable<UserEntity>().Includes(u => u.Roles).InSingleAsync(userId)).Roles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,6 +17,8 @@ namespace Yi.Framework.WebCore.BuilderExtend
|
||||
{
|
||||
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
|
||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm";
|
||||
|
||||
//options.SerializerSettings.Converters.Add(new ValueToStringConverter());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user