Эх сурвалжийг харах

修复 修改用户部门时,会清空部门主管的问题

zhontai 1 жил өмнө
parent
commit
e804a07c1f

+ 19 - 13
src/platform/ZhonTai.Admin/Services/Role/RoleService.cs

@@ -36,6 +36,25 @@ public class RoleService : BaseService, IRoleService, IDynamicApi
     {
     }
 
+    /// <summary>
+    /// 添加角色部门
+    /// </summary>
+    /// <param name="roleId"></param>
+    /// <param name="orgIds"></param>
+    /// <returns></returns>
+    private async Task AddRoleOrgAsync(long roleId, long[] orgIds)
+    {
+        if (orgIds != null && orgIds.Any())
+        {
+            var roleOrgs = orgIds.Select(orgId => new RoleOrgEntity
+            {
+                RoleId = roleId,
+                OrgId = orgId
+            }).ToList();
+            await _roleOrgRepository.InsertAsync(roleOrgs);
+        }
+    }
+
     /// <summary>
     /// 查询
     /// </summary>
@@ -159,19 +178,6 @@ public class RoleService : BaseService, IRoleService, IDynamicApi
         }
     }
 
-    private async Task AddRoleOrgAsync(long roleId, long[] orgIds)
-    {
-        if (orgIds != null && orgIds.Any())
-        {
-            var roleOrgs = orgIds.Select(orgId => new RoleOrgEntity 
-            { 
-                RoleId = roleId, 
-                OrgId = orgId 
-            }).ToList();
-            await _roleOrgRepository.InsertAsync(roleOrgs);
-        }
-    }
-
     /// <summary>
     /// 新增
     /// </summary>

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

@@ -453,10 +453,18 @@ public partial class UserService : BaseService, IUserService, IDynamicApi
         await _staffRepository.InsertOrUpdateAsync(staff);
 
         //所属部门
-        await _userOrgRepository.DeleteAsync(a => a.UserId == userId);
-        if (input.OrgIds != null && input.OrgIds.Any())
+        var orgIds = await _userOrgRepository.Select.Where(a => a.UserId == userId).ToListAsync(a => a.OrgId);
+        var insertOrgIds = input.OrgIds.Except(orgIds);
+
+        var deleteOrgIds = orgIds.Except(input.OrgIds);
+        if (deleteOrgIds != null && deleteOrgIds.Any())
         {
-            var orgs = input.OrgIds.Select(orgId => new UserOrgEntity
+            await _userOrgRepository.DeleteAsync(a => a.UserId == userId && deleteOrgIds.Contains(a.OrgId));
+        }
+            
+        if (insertOrgIds != null && insertOrgIds.Any())
+        {
+            var orgs = insertOrgIds.Select(orgId => new UserOrgEntity
             {
                 UserId = userId,
                 OrgId = orgId

+ 8 - 0
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -6714,6 +6714,14 @@
             角色服务
             </summary>
         </member>
+        <member name="M:ZhonTai.Admin.Services.Role.RoleService.AddRoleOrgAsync(System.Int64,System.Int64[])">
+            <summary>
+            添加角色部门
+            </summary>
+            <param name="roleId"></param>
+            <param name="orgIds"></param>
+            <returns></returns>
+        </member>
         <member name="M:ZhonTai.Admin.Services.Role.RoleService.GetAsync(System.Int64)">
             <summary>
             查询