用户信息添加修改
This commit is contained in:
@@ -360,5 +360,17 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.UpdateInfo(Yi.Framework.DTOModel.UserInfoDto)">
|
||||
<summary>
|
||||
更新用户信息
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.AddInfo(Yi.Framework.DTOModel.UserInfoDto)">
|
||||
<summary>
|
||||
添加用户
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
var userEntiy = await _iUserService._repository.GetByIdAsync(userId);
|
||||
|
||||
//判断输入的老密码是否和原密码相同
|
||||
if (_iUserService.JudgePassword(userEntiy, updatePasswordDto.OldPassword))
|
||||
if (userEntiy.JudgePassword(updatePasswordDto.OldPassword))
|
||||
{
|
||||
userEntiy.Password = updatePasswordDto.NewPassword;
|
||||
userEntiy.BuildPassword();
|
||||
|
||||
@@ -94,5 +94,26 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetInfoById(id));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateInfo(UserInfoDto userDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.UpdateInfo(userDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> AddInfo(UserInfoDto userDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.AddInfo(userDto));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs
Normal file
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class UserInfoDto
|
||||
{
|
||||
public UserEntity User { get; set; }
|
||||
public List<long> RoleIds { get; set; }
|
||||
public List<long> PostId { get; set; }
|
||||
public long? DeptId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -68,13 +68,7 @@ namespace Yi.Framework.Interface
|
||||
/// <returns></returns>
|
||||
Task<UserRoleMenuDto> GetUserAllInfo(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 判断用户密码是否和原密码相同
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
bool JudgePassword(UserEntity user, string password);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
@@ -90,5 +84,19 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="menus"></param>
|
||||
/// <returns></returns>
|
||||
List<VueRouterModel> RouterBuild(List<MenuEntity> menus);
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户信息
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateInfo(UserInfoDto userDto);
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户信息
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddInfo(UserInfoDto userDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Common.Helper;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public partial class UserEntity
|
||||
@@ -26,5 +28,19 @@ namespace Yi.Framework.Model.Models
|
||||
this.Salt = Common.Helper.MD5Helper.GenerateSalt();
|
||||
this.Password = Common.Helper.MD5Helper.SHA2Encode(password, this.Salt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断密码和加密后的密码是否相同
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public bool JudgePassword(string password)
|
||||
{
|
||||
if (this.Password == MD5Helper.SHA2Encode(password, this.Salt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +81,12 @@ namespace Yi.Framework.Service
|
||||
//多次操作,需要事务确保原子性
|
||||
return await _repositoryUserRole.UseTranAsync(async () =>
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryUserRole.DeleteAsync(u => userIds.Contains((long)u.UserId));
|
||||
|
||||
//遍历用户
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryUserRole.DeleteAsync(u => u.UserId == userId);
|
||||
|
||||
//添加新的关系
|
||||
List<UserRoleEntity> userRoleEntities = new();
|
||||
foreach (var roleId in roleIds)
|
||||
@@ -154,14 +153,7 @@ namespace Yi.Framework.Service
|
||||
return userRoleMenu;
|
||||
}
|
||||
|
||||
public bool JudgePassword(UserEntity user, string password)
|
||||
{
|
||||
if (user.Password == MD5Helper.SHA2Encode(password, user.Salt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<PageModel<List<UserEntity>>> SelctPageList(UserEntity user, PageParModel page)
|
||||
@@ -222,5 +214,26 @@ namespace Yi.Framework.Service
|
||||
}
|
||||
return routers;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateInfo(UserInfoDto userDto)
|
||||
{
|
||||
//未填写密码,可不更新
|
||||
userDto.User.Salt = null;
|
||||
if (userDto.User.Password.IsNotNull())
|
||||
{
|
||||
userDto.User.BuildPassword();
|
||||
}
|
||||
var res1 = await _repository.UpdateIgnoreNullAsync(userDto.User);
|
||||
var res2 = await GiveUserSetRole(new List<long> { userDto.User.Id }, userDto.RoleIds);
|
||||
return res1 && res2;
|
||||
}
|
||||
|
||||
public async Task<bool> AddInfo(UserInfoDto userDto)
|
||||
{
|
||||
userDto.User.BuildPassword();
|
||||
var res1 = await _repository.InsertReturnSnowflakeIdAsync(userDto.User);
|
||||
var res2 = await GiveUserSetRole(new List<long> { res1 }, userDto.RoleIds);
|
||||
return !0.Equals(res1) && res2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user