Skip to content

Commit

Permalink
实现用户部门转移功能
Browse files Browse the repository at this point in the history
调整:用户修改取消部门设置
  • Loading branch information
zhontai committed Dec 15, 2024
1 parent abb5740 commit 39e9e82
Show file tree
Hide file tree
Showing 12 changed files with 561 additions and 77 deletions.
10 changes: 10 additions & 0 deletions src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserAddInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
/// </summary>
public class UserAddInput: UserFormInput
{
/// <summary>
/// 所属部门Ids
/// </summary>
public virtual long[] OrgIds { get; set; }

/// <summary>
/// 主属部门Id
/// </summary>
public long OrgId { get; set; }

/// <summary>
/// 密码
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace ZhonTai.Admin.Services.User.Dto;

/// <summary>
/// 批量设置部门
/// </summary>
public class UserBatchSetOrgInput
{
/// <summary>
/// 用户Id列表
/// </summary>
public long[] UserIds { get; set; }

/// <summary>
/// 所属部门Ids
/// </summary>
public virtual long[] OrgIds { get; set; }

/// <summary>
/// 主属部门Id
/// </summary>
public long OrgId { get; set; }
}
10 changes: 0 additions & 10 deletions src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserFormInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public class UserFormInput
/// </summary>
public virtual long[] RoleIds { get; set; }

/// <summary>
/// 所属部门Ids
/// </summary>
public virtual long[] OrgIds { get; set; }

/// <summary>
/// 主属部门Id
/// </summary>
public long OrgId { get; set; }

/// <summary>
/// 直属主管Id
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions src/modules/admin/ZhonTai.Admin/Services/User/Dto/UserGetOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ public class UserGetOutput : UserUpdateInput
/// </summary>
public ICollection<UserGetRoleDto> Roles { get; set; }

/// <summary>
/// 部门列表
/// </summary>
public ICollection<UserGetOrgDto> Orgs { get; set; }

/// <summary>
/// 所属部门Ids
/// </summary>
public override long[] OrgIds => Orgs?.Select(a => a.Id)?.ToArray();

/// <summary>
/// 角色Ids
/// </summary>
Expand Down
69 changes: 49 additions & 20 deletions src/modules/admin/ZhonTai.Admin/Services/User/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -833,6 +814,54 @@ public async Task SetEnableAsync(UserSetEnableInput input)
await _userRep.UpdateAsync(entity);
}

/// <summary>
/// 批量设置部门
/// </summary>
/// <returns></returns>
[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<UserOrgEntity>();
foreach (var userId in input.UserIds)
{
orgs.AddRange(insertOrgIds.Select(orgId => new UserOrgEntity
{
UserId = userId,
OrgId = orgId
}).ToList());
}

await _userOrgRep.InsertAsync(orgs);
}

//发送cap消息

}

/// <summary>
/// 彻底删除用户
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions ui/zhontai.ui.admin.vue3/src/api/admin/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ResultOutputUserGetPermissionOutput,
UserAddInput,
UserAddMemberInput,
UserBatchSetOrgInput,
UserChangePasswordInput,
UserResetPasswordInput,
UserSetEnableInput,
Expand Down Expand Up @@ -274,6 +275,24 @@ export class UserApi<SecurityDataType = unknown> extends HttpClient<SecurityData
type: ContentType.Json,
...params,
})
/**
* No description
*
* @tags user
* @name BatchSetOrg
* @summary 批量设置部门
* @request PUT:/api/admin/user/batch-set-org
* @secure
*/
batchSetOrg = (data: UserBatchSetOrgInput, params: RequestParams = {}) =>
this.request<AxiosResponse, any>({
path: `/api/admin/user/batch-set-org`,
method: 'PUT',
body: data,
secure: true,
type: ContentType.Json,
...params,
})
/**
* No description
*
Expand Down
49 changes: 20 additions & 29 deletions ui/zhontai.ui.admin.vue3/src/api/admin/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -5018,6 +5011,13 @@ export interface UserAddInput {
managerUserName?: string | null
/** 员工添加 */
staff: StaffAddInput
/** 所属部门Ids */
orgIds?: number[] | null
/**
* 主属部门Id
* @format int64
*/
orgId?: number
/** 密码 */
password?: string | null
/** 启用 */
Expand Down Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -5209,12 +5222,6 @@ export interface UserGetBasicOutput {
lastLoginCity?: string | null
}

export interface UserGetOrgDto {
/** @format int64 */
id?: number
name?: string | null
}

export interface UserGetOutput {
/**
* 账号
Expand All @@ -5230,11 +5237,6 @@ export interface UserGetOutput {
mobile?: string | null
/** 邮箱 */
email?: string | null
/**
* 主属部门Id
* @format int64
*/
orgId?: number
/**
* 直属主管Id
* @format int64
Expand All @@ -5251,10 +5253,6 @@ export interface UserGetOutput {
id: number
/** 角色列表 */
roles?: UserGetRoleDto[] | null
/** 部门列表 */
orgs?: UserGetOrgDto[] | null
/** 所属部门Ids */
orgIds?: number[] | null
/** 角色Ids */
roleIds?: number[] | null
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 39e9e82

Please sign in to comment.