From 39e9e8220d390a6f61c5bde68e1da22613adaf94 Mon Sep 17 00:00:00 2001 From: zhontai <361243234@qq.com> Date: Sun, 15 Dec 2024 19:42:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=94=A8=E6=88=B7=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E8=BD=AC=E7=A7=BB=E5=8A=9F=E8=83=BD=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=EF=BC=9A=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E9=83=A8=E9=97=A8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/User/Dto/UserAddInput.cs | 10 + .../Services/User/Dto/UserBatchSetOrgInput.cs | 22 ++ .../Services/User/Dto/UserFormInput.cs | 10 - .../Services/User/Dto/UserGetOutput.cs | 10 - .../Services/User/UserService.cs | 69 ++++-- .../src/api/admin/User.ts | 19 ++ .../src/api/admin/data-contracts.ts | 49 ++-- .../src/layout/navBars/topBar/user.vue | 2 +- .../views/admin/user/components/user-form.vue | 2 - .../admin/user/components/user-set-org.vue | 181 +++++++++++++++ .../user/components/user-update-form.vue | 211 ++++++++++++++++++ .../src/views/admin/user/index.vue | 53 ++++- 12 files changed, 561 insertions(+), 77 deletions(-) create mode 100644 src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserBatchSetOrgInput.cs create mode 100644 ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-set-org.vue create mode 100644 ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-update-form.vue diff --git a/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserAddInput.cs b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserAddInput.cs index f0d3ce68..338ae5fc 100644 --- a/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserAddInput.cs +++ b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserAddInput.cs @@ -5,6 +5,16 @@ /// public class UserAddInput: UserFormInput { + /// + /// 所属部门Ids + /// + public virtual long[] OrgIds { get; set; } + + /// + /// 主属部门Id + /// + public long OrgId { get; set; } + /// /// 密码 /// diff --git a/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserBatchSetOrgInput.cs b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserBatchSetOrgInput.cs new file mode 100644 index 00000000..7a27fa96 --- /dev/null +++ b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserBatchSetOrgInput.cs @@ -0,0 +1,22 @@ +namespace ZhonTai.Admin.Services.User.Dto; + +/// +/// 批量设置部门 +/// +public class UserBatchSetOrgInput +{ + /// + /// 用户Id列表 + /// + public long[] UserIds { get; set; } + + /// + /// 所属部门Ids + /// + public virtual long[] OrgIds { get; set; } + + /// + /// 主属部门Id + /// + public long OrgId { get; set; } +} \ No newline at end of file diff --git a/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserFormInput.cs b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserFormInput.cs index fb4b73a1..ad1c4816 100644 --- a/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserFormInput.cs +++ b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserFormInput.cs @@ -40,16 +40,6 @@ public class UserFormInput /// public virtual long[] RoleIds { get; set; } - /// - /// 所属部门Ids - /// - public virtual long[] OrgIds { get; set; } - - /// - /// 主属部门Id - /// - public long OrgId { get; set; } - /// /// 直属主管Id /// diff --git a/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserGetOutput.cs b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserGetOutput.cs index 11709e38..8b413a59 100644 --- a/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserGetOutput.cs +++ b/src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserGetOutput.cs @@ -10,16 +10,6 @@ public class UserGetOutput : UserUpdateInput /// public ICollection Roles { get; set; } - /// - /// 部门列表 - /// - public ICollection Orgs { get; set; } - - /// - /// 所属部门Ids - /// - public override long[] OrgIds => Orgs?.Select(a => a.Id)?.ToArray(); - /// /// 角色Ids /// diff --git a/src/modules/admin/ZhonTai.Admin/Services/User/UserService.cs b/src/modules/admin/ZhonTai.Admin/Services/User/UserService.cs index 462ee845..aee94bc2 100644 --- a/src/modules/admin/ZhonTai.Admin/Services/User/UserService.cs +++ b/src/modules/admin/ZhonTai.Admin/Services/User/UserService.cs @@ -40,6 +40,7 @@ using ZhonTai.Admin.Resources; using ZhonTai.Admin.Domain.Permission; using Microsoft.Extensions.Options; +using ZhonTai.Admin.Core.Db; namespace ZhonTai.Admin.Services.User; @@ -594,26 +595,6 @@ public virtual async Task UpdateAsync(UserUpdateInput input) await _userStaffRep.InsertAsync(staff); } - //所属部门 - var orgIds = await _userOrgRep.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()) - { - await _userOrgRep.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 - }).ToList(); - await _userOrgRep.InsertAsync(orgs); - } - await Cache.DelByPatternAsync(CacheKeys.GetDataPermissionPattern(userId)); } @@ -833,6 +814,54 @@ public async Task SetEnableAsync(UserSetEnableInput input) await _userRep.UpdateAsync(entity); } + /// + /// 批量设置部门 + /// + /// + [AdminTransaction] + public virtual async Task BatchSetOrgAsync(UserBatchSetOrgInput input) + { + //主属部门 + await _userRep.UpdateDiy.Set(a => new UserEntity + { + OrgId = input.OrgId, + ModifiedUserId = User.Id, + ModifiedUserName = User.UserName, + ModifiedUserRealName = User.Name, + ModifiedTime = DbHelper.ServerTime, + }) + .Where(a => a.Id.In(input.UserIds)) + .ExecuteAffrowsAsync(); + + //所属部门 + var orgIds = await _userOrgRep.Select.Where(a => a.UserId.In(input.UserIds)).ToListAsync(a => a.OrgId); + var insertOrgIds = input.OrgIds.Except(orgIds); + + var deleteOrgIds = orgIds.Except(input.OrgIds).ToArray(); + if (deleteOrgIds != null && deleteOrgIds.Any()) + { + await _userOrgRep.DeleteAsync(a => a.UserId.In(input.UserIds) && a.OrgId.In(deleteOrgIds)); + } + + if (insertOrgIds != null && insertOrgIds.Any()) + { + var orgs = new List(); + foreach (var userId in input.UserIds) + { + orgs.AddRange(insertOrgIds.Select(orgId => new UserOrgEntity + { + UserId = userId, + OrgId = orgId + }).ToList()); + } + + await _userOrgRep.InsertAsync(orgs); + } + + //发送cap消息 + + } + /// /// 彻底删除用户 /// diff --git a/ui/zhontai.ui.admin.vue3/src/api/admin/User.ts b/ui/zhontai.ui.admin.vue3/src/api/admin/User.ts index 051f259f..eda00d2a 100644 --- a/ui/zhontai.ui.admin.vue3/src/api/admin/User.ts +++ b/ui/zhontai.ui.admin.vue3/src/api/admin/User.ts @@ -21,6 +21,7 @@ import { ResultOutputUserGetPermissionOutput, UserAddInput, UserAddMemberInput, + UserBatchSetOrgInput, UserChangePasswordInput, UserResetPasswordInput, UserSetEnableInput, @@ -274,6 +275,24 @@ export class UserApi extends HttpClient + this.request({ + path: `/api/admin/user/batch-set-org`, + method: 'PUT', + body: data, + secure: true, + type: ContentType.Json, + ...params, + }) /** * No description * diff --git a/ui/zhontai.ui.admin.vue3/src/api/admin/data-contracts.ts b/ui/zhontai.ui.admin.vue3/src/api/admin/data-contracts.ts index c035837c..d7ee9af3 100644 --- a/ui/zhontai.ui.admin.vue3/src/api/admin/data-contracts.ts +++ b/ui/zhontai.ui.admin.vue3/src/api/admin/data-contracts.ts @@ -5002,13 +5002,6 @@ export interface UserAddInput { email?: string | null /** 角色Ids */ roleIds?: number[] | null - /** 所属部门Ids */ - orgIds?: number[] | null - /** - * 主属部门Id - * @format int64 - */ - orgId?: number /** * 直属主管Id * @format int64 @@ -5018,6 +5011,13 @@ export interface UserAddInput { managerUserName?: string | null /** 员工添加 */ staff: StaffAddInput + /** 所属部门Ids */ + orgIds?: number[] | null + /** + * 主属部门Id + * @format int64 + */ + orgId?: number /** 密码 */ password?: string | null /** 启用 */ @@ -5051,6 +5051,19 @@ export interface UserAddMemberInput { status?: UserStatus } +/** 批量设置部门 */ +export interface UserBatchSetOrgInput { + /** 用户Id列表 */ + userIds?: number[] | null + /** 所属部门Ids */ + orgIds?: number[] | null + /** + * 主属部门Id + * @format int64 + */ + orgId?: number +} + /** 修改密码 */ export interface UserChangePasswordInput { /** @@ -5209,12 +5222,6 @@ export interface UserGetBasicOutput { lastLoginCity?: string | null } -export interface UserGetOrgDto { - /** @format int64 */ - id?: number - name?: string | null -} - export interface UserGetOutput { /** * 账号 @@ -5230,11 +5237,6 @@ export interface UserGetOutput { mobile?: string | null /** 邮箱 */ email?: string | null - /** - * 主属部门Id - * @format int64 - */ - orgId?: number /** * 直属主管Id * @format int64 @@ -5251,10 +5253,6 @@ export interface UserGetOutput { id: number /** 角色列表 */ roles?: UserGetRoleDto[] | null - /** 部门列表 */ - orgs?: UserGetOrgDto[] | null - /** 所属部门Ids */ - orgIds?: number[] | null /** 角色Ids */ roleIds?: number[] | null } @@ -5464,13 +5462,6 @@ export interface UserUpdateInput { email?: string | null /** 角色Ids */ roleIds?: number[] | null - /** 所属部门Ids */ - orgIds?: number[] | null - /** - * 主属部门Id - * @format int64 - */ - orgId?: number /** * 直属主管Id * @format int64 diff --git a/ui/zhontai.ui.admin.vue3/src/layout/navBars/topBar/user.vue b/ui/zhontai.ui.admin.vue3/src/layout/navBars/topBar/user.vue index cb15bb6e..dda07b0a 100644 --- a/ui/zhontai.ui.admin.vue3/src/layout/navBars/topBar/user.vue +++ b/ui/zhontai.ui.admin.vue3/src/layout/navBars/topBar/user.vue @@ -208,7 +208,7 @@ const checkUnreadMsg = async () => { state.unread = res.data } } -const initWebSocket = async () => { +const initWebSocket = () => { wsClient.value = new WebSocketClient({ onMessage: (event: MessageEvent) => { if (event.data) { diff --git a/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-form.vue b/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-form.vue index 5013ef80..5273ecf6 100644 --- a/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-form.vue +++ b/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-form.vue @@ -262,8 +262,6 @@ const open = async (row: UserUpdateInput & UserUpdateInput) => { } } else { state.form = { - orgIds: row.orgIds, - orgId: row.orgId, roleIds: [] as number[], staff: {}, } as UserAddInput & UserUpdateInput diff --git a/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-set-org.vue b/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-set-org.vue new file mode 100644 index 00000000..aae8a468 --- /dev/null +++ b/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-set-org.vue @@ -0,0 +1,181 @@ + + + diff --git a/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-update-form.vue b/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-update-form.vue new file mode 100644 index 00000000..6767042a --- /dev/null +++ b/ui/zhontai.ui.admin.vue3/src/views/admin/user/components/user-update-form.vue @@ -0,0 +1,211 @@ + + + diff --git a/ui/zhontai.ui.admin.vue3/src/views/admin/user/index.vue b/ui/zhontai.ui.admin.vue3/src/views/admin/user/index.vue index d256494a..bf190318 100644 --- a/ui/zhontai.ui.admin.vue3/src/views/admin/user/index.vue +++ b/ui/zhontai.ui.admin.vue3/src/views/admin/user/index.vue @@ -7,7 +7,7 @@
- + @@ -15,13 +15,25 @@ 查询 高级查询 - 新增 - +
+
+ 新增 + 部门转移 +
+
+ + + +
+
+ + +