瀏覽代碼

新增用户和会员支持传入自定义分布式id

zhontai 2 年之前
父節點
當前提交
31c0e19020

+ 1 - 1
src/hosts/ZhonTai.Host/Configs/appconfig.json

@@ -94,7 +94,7 @@
     //结果格式化
     "formatResult": true
   },
-  //实现标准标识密码哈希,相同密码加密后各不相同
+  //实现标准标识密码哈希,启用后相同密码加密后各不相同
   "passwordHasher": false,
   //最大请求大小
   "maxRequestBodySize": 104857600,

+ 1 - 0
src/platform/ZhonTai.Admin/Services/User/Dto/UserAddMemberInput.cs

@@ -13,6 +13,7 @@ public class UserAddMemberInput: UserMemberFormInput
     /// </summary>
     [Required(ErrorMessage = "请输入密码")]
     public string Password { get; set; }
+
     /// <summary>
     /// 状态
     /// </summary>

+ 5 - 0
src/platform/ZhonTai.Admin/Services/User/Dto/UserFormInput.cs

@@ -8,6 +8,11 @@ namespace ZhonTai.Admin.Services.User.Dto;
 /// </summary>
 public class UserFormInput
 {
+    /// <summary>
+    /// 用户Id
+    /// </summary>
+    public virtual long Id { get; set; }
+
     /// <summary>
     /// 账号
     /// </summary>

+ 5 - 0
src/platform/ZhonTai.Admin/Services/User/Dto/UserMemberFormInput.cs

@@ -7,6 +7,11 @@ namespace ZhonTai.Admin.Services.User.Dto;
 /// </summary>
 public class UserMemberFormInput
 {
+    /// <summary>
+    /// 会员Id
+    /// </summary>
+    public virtual long Id { get; set; }
+
     /// <summary>
     /// 账号
     /// </summary>

+ 1 - 1
src/platform/ZhonTai.Admin/Services/User/Dto/UserUpdateInput.cs

@@ -14,5 +14,5 @@ public partial class UserUpdateInput: UserFormInput
     /// </summary>
     [Required]
     [ValidateRequired("请选择用户")]
-    public long Id { get; set; }
+    public override long Id { get; set; }
 }

+ 2 - 2
src/platform/ZhonTai.Admin/Services/User/Dto/UserUpdateMemberInput.cs

@@ -12,6 +12,6 @@ public class UserUpdateMemberInput: UserMemberFormInput
     /// 主键Id
     /// </summary>
     [Required]
-    [ValidateRequired("请选择用户")]
-    public long Id { get; set; }
+    [ValidateRequired("请选择会员")]
+    public override long Id { get; set; }
 }

+ 83 - 83
src/platform/ZhonTai.Admin/Services/User/UserService.cs

@@ -378,6 +378,89 @@ public partial class UserService : BaseService, IUserService, IDynamicApi
         return userId;
     }
 
+    /// <summary>
+    /// 修改用户
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    [AdminTransaction]
+    public virtual async Task UpdateAsync(UserUpdateInput input)
+    {
+        if (input.Id == input.ManagerUserId)
+        {
+            throw ResultOutput.Exception("直属主管不能是自己");
+        }
+
+        Expression<Func<UserEntity, bool>> where = (a => a.UserName == input.UserName);
+        where = where.Or(input.Mobile.NotNull(), a => a.Mobile == input.Mobile)
+            .Or(input.Email.NotNull(), a => a.Email == input.Email);
+
+        var existsUser = await _userRepository.Select.Where(a => a.Id != input.Id).Where(where)
+            .FirstAsync(a => new { a.UserName, a.Mobile, a.Email });
+
+        if (existsUser != null)
+        {
+            if (existsUser.UserName == input.UserName)
+            {
+                throw ResultOutput.Exception($"账号已存在");
+            }
+
+            if (input.Mobile.NotNull() && existsUser.Mobile == input.Mobile)
+            {
+                throw ResultOutput.Exception($"手机号已存在");
+            }
+
+            if (input.Email.NotNull() && existsUser.Email == input.Email)
+            {
+                throw ResultOutput.Exception($"邮箱已存在");
+            }
+        }
+
+        var user = await _userRepository.GetAsync(input.Id);
+        if (!(user?.Id > 0))
+        {
+            throw ResultOutput.Exception("用户不存在");
+        }
+
+        Mapper.Map(input, user);
+        await _userRepository.UpdateAsync(user);
+
+        var userId = user.Id;
+
+        // 用户角色
+        await _userRoleRepository.DeleteAsync(a => a.UserId == userId);
+        if (input.RoleIds != null && input.RoleIds.Any())
+        {
+            var roles = input.RoleIds.Select(roleId => new UserRoleEntity
+            {
+                UserId = userId,
+                RoleId = roleId
+            }).ToList();
+            await _userRoleRepository.InsertAsync(roles);
+        }
+
+        // 员工信息
+        var staff = await _staffRepository.GetAsync(userId);
+        staff ??= new UserStaffEntity();
+        Mapper.Map(input.Staff, staff);
+        staff.Id = userId;
+        await _staffRepository.InsertOrUpdateAsync(staff);
+
+        //所属部门
+        await _userOrgRepository.DeleteAsync(a => a.UserId == userId);
+        if (input.OrgIds != null && input.OrgIds.Any())
+        {
+            var orgs = input.OrgIds.Select(orgId => new UserOrgEntity
+            {
+                UserId = userId,
+                OrgId = orgId
+            }).ToList();
+            await _userOrgRepository.InsertAsync(orgs);
+        }
+
+        await Cache.DelAsync(CacheKeys.DataPermission + user.Id);
+    }
+
     /// <summary>
     /// 新增会员
     /// </summary>
@@ -479,89 +562,6 @@ public partial class UserService : BaseService, IUserService, IDynamicApi
         await _userRepository.UpdateAsync(user);
     }
 
-    /// <summary>
-    /// 修改用户
-    /// </summary>
-    /// <param name="input"></param>
-    /// <returns></returns>
-    [AdminTransaction]
-    public virtual async Task UpdateAsync(UserUpdateInput input)
-    {
-        if (input.Id == input.ManagerUserId)
-        {
-            throw ResultOutput.Exception("直属主管不能是自己");
-        }
-
-        Expression<Func<UserEntity, bool>> where = (a => a.UserName == input.UserName);
-        where = where.Or(input.Mobile.NotNull(), a => a.Mobile == input.Mobile)
-            .Or(input.Email.NotNull(), a => a.Email == input.Email);
-
-        var existsUser = await _userRepository.Select.Where(a => a.Id != input.Id).Where(where)
-            .FirstAsync(a => new { a.UserName, a.Mobile, a.Email });
-
-        if (existsUser != null)
-        {
-            if (existsUser.UserName == input.UserName)
-            {
-                throw ResultOutput.Exception($"账号已存在");
-            }
-
-            if (input.Mobile.NotNull() && existsUser.Mobile == input.Mobile)
-            {
-                throw ResultOutput.Exception($"手机号已存在");
-            }
-
-            if (input.Email.NotNull() && existsUser.Email == input.Email)
-            {
-                throw ResultOutput.Exception($"邮箱已存在");
-            }
-        }
-
-        var user = await _userRepository.GetAsync(input.Id);
-        if (!(user?.Id > 0))
-        {
-            throw ResultOutput.Exception("用户不存在");
-        }
-
-        Mapper.Map(input, user);
-        await _userRepository.UpdateAsync(user);
-
-        var userId = user.Id;
-
-        // 用户角色
-        await _userRoleRepository.DeleteAsync(a => a.UserId == userId);
-        if (input.RoleIds != null && input.RoleIds.Any())
-        {
-            var roles = input.RoleIds.Select(roleId => new UserRoleEntity 
-            { 
-                UserId = userId, 
-                RoleId = roleId 
-            }).ToList();
-            await _userRoleRepository.InsertAsync(roles);
-        }
-
-        // 员工信息
-        var staff = await _staffRepository.GetAsync(userId);
-        staff ??= new UserStaffEntity();
-        Mapper.Map(input.Staff, staff);
-        staff.Id = userId;
-        await _staffRepository.InsertOrUpdateAsync(staff);
-
-        //所属部门
-        await _userOrgRepository.DeleteAsync(a => a.UserId == userId);
-        if (input.OrgIds != null && input.OrgIds.Any())
-        {
-            var orgs = input.OrgIds.Select(orgId => new UserOrgEntity
-            {
-                UserId = userId,
-                OrgId = orgId
-            }).ToList();
-            await _userOrgRepository.InsertAsync(orgs);
-        }
-
-        await Cache.DelAsync(CacheKeys.DataPermission + user.Id);
-    }
-
     /// <summary>
     /// 更新用户基本信息
     /// </summary>

+ 16 - 6
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -6484,6 +6484,11 @@
             用户表单
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.User.Dto.UserFormInput.Id">
+            <summary>
+            用户Id
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Services.User.Dto.UserFormInput.UserName">
             <summary>
             账号
@@ -6644,6 +6649,11 @@
             会员表单
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.User.Dto.UserMemberFormInput.Id">
+            <summary>
+            会员Id
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Services.User.Dto.UserMemberFormInput.UserName">
             <summary>
             账号
@@ -6800,23 +6810,23 @@
             <param name="input"></param>
             <returns></returns>
         </member>
-        <member name="M:ZhonTai.Admin.Services.User.UserService.AddMemberAsync(ZhonTai.Admin.Services.User.Dto.UserAddMemberInput)">
+        <member name="M:ZhonTai.Admin.Services.User.UserService.UpdateAsync(ZhonTai.Admin.Services.User.Dto.UserUpdateInput)">
             <summary>
-            新增会员
+            修改用户
             </summary>
             <param name="input"></param>
             <returns></returns>
         </member>
-        <member name="M:ZhonTai.Admin.Services.User.UserService.UpdateMemberAsync(ZhonTai.Admin.Services.User.Dto.UserUpdateMemberInput)">
+        <member name="M:ZhonTai.Admin.Services.User.UserService.AddMemberAsync(ZhonTai.Admin.Services.User.Dto.UserAddMemberInput)">
             <summary>
-            修改会员
+            新增会员
             </summary>
             <param name="input"></param>
             <returns></returns>
         </member>
-        <member name="M:ZhonTai.Admin.Services.User.UserService.UpdateAsync(ZhonTai.Admin.Services.User.Dto.UserUpdateInput)">
+        <member name="M:ZhonTai.Admin.Services.User.UserService.UpdateMemberAsync(ZhonTai.Admin.Services.User.Dto.UserUpdateMemberInput)">
             <summary>
-            修改用户
+            修改会员
             </summary>
             <param name="input"></param>
             <returns></returns>