From eca2d2fd7342370f0158993a4ddc7f58ae49d1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Wed, 27 Sep 2023 18:37:44 +0800 Subject: [PATCH] =?UTF-8?q?:card=5Ffile=5Fbox:SysUser=E8=A1=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/System/SysLoginController.cs | 2 +- ZR.ServiceCore/Model/Dto/RegisterDto.cs | 1 + ZR.ServiceCore/Model/SysUser.cs | 7 +--- ZR.ServiceCore/Services/SysUserService.cs | 39 ++++++++++--------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 7e256cf..4122662 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -172,7 +172,7 @@ namespace ZR.Admin.WebApi.Controllers.System { return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误"); } - + dto.UserIP = HttpContext.GetClientUserIp(); SysUser user = sysUserService.Register(dto); if (user.UserId > 0) { diff --git a/ZR.ServiceCore/Model/Dto/RegisterDto.cs b/ZR.ServiceCore/Model/Dto/RegisterDto.cs index 53755ff..b2da1bd 100644 --- a/ZR.ServiceCore/Model/Dto/RegisterDto.cs +++ b/ZR.ServiceCore/Model/Dto/RegisterDto.cs @@ -30,5 +30,6 @@ namespace ZR.Model.System.Dto /// 头像 /// public string Photo { get; set; } + public string UserIP { get; set; } } } diff --git a/ZR.ServiceCore/Model/SysUser.cs b/ZR.ServiceCore/Model/SysUser.cs index ff55b72..01e9dbc 100644 --- a/ZR.ServiceCore/Model/SysUser.cs +++ b/ZR.ServiceCore/Model/SysUser.cs @@ -1,8 +1,4 @@ using MiniExcelLibs.Attributes; -using Newtonsoft.Json; -using SqlSugar; -using System; -using System.Collections.Generic; namespace ZR.Model.System { @@ -82,7 +78,8 @@ namespace ZR.Model.System /// [SugarColumn(DefaultValue = "0")] public long DeptId { get; set; } - + public string Province { get; set; } + public string City { get; set; } #region 表额外字段 public bool IsAdmin() { diff --git a/ZR.ServiceCore/Services/SysUserService.cs b/ZR.ServiceCore/Services/SysUserService.cs index 8cb03fb..7d7a4c3 100644 --- a/ZR.ServiceCore/Services/SysUserService.cs +++ b/ZR.ServiceCore/Services/SysUserService.cs @@ -1,11 +1,7 @@ using Infrastructure; using Infrastructure.Attribute; -using Infrastructure.Extensions; -using SqlSugar; -using System; +using IPTools.Core; using System.Collections; -using System.Collections.Generic; -using System.Linq; using ZR.Common; using ZR.Model; using ZR.Model.System; @@ -125,19 +121,22 @@ namespace ZR.Service var roleIds = RoleService.SelectUserRoles(user.UserId); var diffArr = roleIds.Where(c => !((IList)user.RoleIds).Contains(c)).ToArray(); var diffArr2 = user.RoleIds.Where(c => !((IList)roleIds).Contains(c)).ToArray(); - - if (diffArr.Length > 0 || diffArr2.Length > 0) + bool result = UseTran2(() => { - //删除用户与角色关联 - UserRoleService.DeleteUserRoleByUserId((int)user.UserId); - //新增用户与角色关联 - UserRoleService.InsertUserRole(user); - } - // 删除用户与岗位关联 - UserPostService.Delete(user.UserId); - // 新增用户与岗位管理 - UserPostService.InsertUserPost(user); - return ChangeUser(user); + if (diffArr.Length > 0 || diffArr2.Length > 0) + { + //删除用户与角色关联 + UserRoleService.DeleteUserRoleByUserId((int)user.UserId); + //新增用户与角色关联 + UserRoleService.InsertUserRole(user); + } + // 删除用户与岗位关联 + UserPostService.Delete(user.UserId); + // 新增用户与岗位管理 + UserPostService.InsertUserPost(user); + ChangeUser(user); + }); + return result ? 1 : 0; } public int ChangeUser(SysUser user) @@ -222,7 +221,7 @@ namespace ZR.Service } //密码md5 string password = NETCore.Encrypt.EncryptProvider.Md5(dto.Password); - + var ip_info = IpTool.Search(dto.UserIP); SysUser user = new() { Create_time = DateTime.Now, @@ -231,7 +230,9 @@ namespace ZR.Service Password = password, Status = 0, DeptId = 0, - Remark = "用户注册" + Remark = "用户注册", + Province = ip_info.Province, + City = ip_info.City }; if (UserConstants.NOT_UNIQUE.Equals(CheckUserNameUnique(dto.Username))) {