//
using SafeCampus.Core.Extension;
namespace SafeCampus.System;
///
///
///
public class SysUserService : DbRepository, ISysUserService
{
private readonly ILogger _logger;
private readonly ISimpleCacheService _simpleCacheService;
private readonly IRelationService _relationService;
private readonly IResourceService _resourceService;
private readonly ISysOrgService _sysOrgService;
private readonly ISysRoleService _sysRoleService;
private readonly IImportExportService _importExportService;
private readonly ISysPositionService _sysPositionService;
private readonly IDictService _dictService;
private readonly IConfigService _configService;
private readonly IBatchEditService _batchEditService;
public SysUserService(ILogger logger, ISimpleCacheService simpleCacheService, IRelationService relationService,
IResourceService resourceService, ISysOrgService orgService, ISysRoleService sysRoleService,
IImportExportService importExportService, ISysPositionService sysPositionService, IDictService dictService,
IConfigService configService, IBatchEditService updateBatchService)
{
_logger = logger;
_simpleCacheService = simpleCacheService;
_relationService = relationService;
_resourceService = resourceService;
_sysOrgService = orgService;
_sysRoleService = sysRoleService;
_importExportService = importExportService;
_sysPositionService = sysPositionService;
_dictService = dictService;
_configService = configService;
_batchEditService = updateBatchService;
}
#region 查询
///
public async Task GetUserAvatar(long userId)
{
//先从缓存拿
var avatar = _simpleCacheService.HashGetOne(SystemConst.CACHE_SYS_USER_AVATAR, userId.ToString());
if (string.IsNullOrEmpty(avatar))
{
//单查获取用户头像
avatar = await GetFirstAsync(it => it.Id == userId, it => it.Avatar);
if (!string.IsNullOrEmpty(avatar))
{
//插入缓存
_simpleCacheService.HashAdd(SystemConst.CACHE_SYS_USER_AVATAR, userId.ToString(), avatar);
}
}
return avatar;
}
///
public async Task GetUserByAccount(string account, long? tenantId = null)
{
var userId = await GetIdByAccount(account, tenantId);//获取用户ID
if (userId != SafeCampusConst.ZERO)
{
var sysUser = await GetUserById(userId);//获取用户信息
if (sysUser.Account == account)//这里做了比较用来限制大小写
return sysUser;
return null;
}
return null;
}
///
public async Task GetUserByPhone(string phone, long? tenantId = null)
{
var userId = await GetIdByPhone(phone, tenantId);//获取用户ID
if (userId > 0)
{
return await GetUserById(userId);//获取用户信息
}
return null;
}
///
public async Task GetIdByPhone(string phone, long? tenantId = null)
{
var orgIds = new List();
var key = SystemConst.CACHE_SYS_USER_PHONE;
if (tenantId != null)
{
key += $":{tenantId}";
orgIds = await _sysOrgService.GetOrgChildIds(tenantId.Value);//获取下级机构
}
//先从缓存拿
var userId = _simpleCacheService.HashGetOne(key, phone);
if (userId == 0)
{
var sm4Phone = CryptogramUtil.Sm4Encrypt(phone);//SM4加密一下
//单查获取用户手机号对应的账号
userId = await Context.Queryable()
.Where(it => it.Phone == sm4Phone)
.WhereIF(orgIds.Count > 0, it => orgIds.Contains(it.OrgId))
.Select(it => it.Id)
.FirstAsync();
if (userId > 0)
{
//插入缓存
_simpleCacheService.HashAdd(key, phone, userId);
}
}
return userId;
}
///
public async Task GetUserById(long userId)
{
//先从缓存拿
var sysUser = _simpleCacheService.HashGetOne(SystemConst.CACHE_SYS_USER, userId.ToString());
if (sysUser == null)
{
sysUser = await GetUserFromDb(userId);//从数据库拿用户信息
}
return sysUser;
}
///
public async Task GetUserById(long userId)
{
var user = await GetUserById(userId);
return user.Adapt();
}
///
public async Task GetIdByAccount(string account, long? tenantId = null)
{
var orgIds = new List();
var key = SystemConst.CACHE_SYS_USER_ACCOUNT;
if (tenantId != null)
{
key += $":{tenantId}";
orgIds = await _sysOrgService.GetOrgChildIds(tenantId.Value);//获取下级机构
}
//先从缓存拿
var userId = _simpleCacheService.HashGetOne(key, account);
if (userId == 0)
{
//单查获取用户账号对应ID
userId = await Context.Queryable()
.Where(it => it.Account == account)
.WhereIF(orgIds.Count > 0, it => orgIds.Contains(it.OrgId))
.Select(it => it.Id)
.FirstAsync();
if (userId != 0)
{
//插入缓存
_simpleCacheService.HashAdd(key, account, userId);
}
}
return userId;
}
///
public async Task> GetButtonCodeList(long userId)
{
var buttonCodeList = new List();//按钮ID集合
//获取用户资源集合
var resourceList = await _relationService.GetRelationListByObjectIdAndCategory(userId, CateGoryConst.RELATION_SYS_USER_HAS_RESOURCE);
var buttonIdList = new List();//按钮ID集合
if (resourceList.Count == 0)//如果有表示用户单独授权了不走用户角色
{
//获取用户角色关系集合
var roleList = await _relationService.GetRelationListByObjectIdAndCategory(userId, CateGoryConst.RELATION_SYS_USER_HAS_ROLE);
var roleIdList = roleList.Select(x => x.TargetId.ToLong()).ToList();//角色ID列表
if (roleIdList.Count > 0)//如果该用户有角色
{
resourceList = await _relationService.GetRelationListByObjectIdListAndCategory(roleIdList,
CateGoryConst.RELATION_SYS_ROLE_HAS_RESOURCE);//获取资源集合
}
}
resourceList.ForEach(it =>
{
if (!string.IsNullOrEmpty(it.ExtJson))
buttonIdList.AddRange(it.ExtJson.ToJsonEntity().ButtonInfo);//如果有按钮权限,将按钮ID放到buttonIdList
});
if (buttonIdList.Count > 0)
{
buttonCodeList = await _resourceService.GetCodeByIds(buttonIdList, CateGoryConst.RESOURCE_BUTTON);
}
return buttonCodeList;
}
///
public async Task> GetPermissionListByUserId(long userId, long orgId)
{
var permissions = new List();//权限集合
var sysRelations =
await _relationService.GetRelationListByObjectIdAndCategory(userId, CateGoryConst.RELATION_SYS_USER_HAS_PERMISSION);//根据用户ID获取用户权限
if (sysRelations.Count == 0)//如果有表示用户单独授权了不走用户角色
{
var roleIdList =
await _relationService.GetRelationListByObjectIdAndCategory(userId, CateGoryConst.RELATION_SYS_USER_HAS_ROLE);//根据用户ID获取角色ID
if (roleIdList.Count > 0)//如果角色ID不为空
{
//获取角色权限信息
sysRelations = await _relationService.GetRelationListByObjectIdListAndCategory(roleIdList.Select(it => it.TargetId.ToLong()).ToList(),
CateGoryConst.RELATION_SYS_ROLE_HAS_PERMISSION);
}
}
var relationGroup = sysRelations.GroupBy(it => it.TargetId).ToList();//根据目标ID,也就是接口名分组,因为存在一个用户多个角色
//遍历分组
foreach (var it in relationGroup)
{
var scopeSet = new HashSet();//定义不可重复列表
var relationList = it.ToList();//关系列表
var scopeCategory = CateGoryConst.SCOPE_SELF;//数据权限分类,默认为仅自己
//获取角色权限信息列表
var rolePermissions = relationList.Select(it => it.ExtJson.ToJsonEntity()).ToList();
if (rolePermissions.Any(role => role.ScopeCategory == CateGoryConst.SCOPE_ALL))//如果有全部
scopeCategory = CateGoryConst.SCOPE_ALL;//标记为全部
else if (rolePermissions.Any(role => role.ScopeCategory == CateGoryConst.SCOPE_ORG_CHILD))//如果有机构及以下机构
scopeCategory = CateGoryConst.SCOPE_ORG_CHILD;//标记为机构及以下机构
else if (rolePermissions.Any(role => role.ScopeCategory == CateGoryConst.SCOPE_ORG))//如果有仅自己机构
scopeCategory = CateGoryConst.SCOPE_ORG;//标记为仅自己机构
else if (rolePermissions.Any(role => role.ScopeCategory == CateGoryConst.SCOPE_ORG_DEFINE))//如果有自定义机构
{
scopeCategory = CateGoryConst.SCOPE_ORG_DEFINE;//标记为仅自己
rolePermissions.ForEach(s =>
{
scopeSet.AddRange(s.ScopeDefineOrgIdList);//添加自定义范围的机构ID
});
}
var dataScopes = scopeSet.ToList();//获取范围列表转列表
permissions.Add(new DataScope
{
ApiUrl = it.Key,
ScopeCategory = scopeCategory,
DataScopes = dataScopes
});//将改URL的权限集合加入权限集合列表
}
return permissions;
}
///
public async Task> Selector(UserSelectorInput input)
{
var orgIds = await _sysOrgService.GetOrgChildIds(input.OrgId);//获取下级机构
var result = await Context.Queryable()
.WhereIF(input.OrgId > 0, u => orgIds.Contains(u.OrgId))//指定机构
.WhereIF(input.OrgIds != null, u => input.OrgIds.Contains(u.OrgId))//在指定机构列表查询
.WhereIF(input.PositionId > 0, u => u.PositionId == input.PositionId)//指定职位
.WhereIF(input.RoleId > 0,
u => SqlFunc.Subqueryable()
.Where(r => r.TargetId == input.RoleId.ToString() && r.ObjectId == u.Id && r.Category == CateGoryConst.RELATION_SYS_USER_HAS_ROLE)
.Any())//指定角色
.WhereIF(!string.IsNullOrEmpty(input.Account), u => u.Account.Contains(input.Account))//根据关键字查询
.Select().ToPagedListAsync(input.PageNum, input.PageSize);
return result;
}
///
public async Task> Page(UserPageInput input)
{
var query = await GetQuery(input);//获取查询条件
var pageInfo = await query.ToPagedListAsync(input.PageNum, input.PageSize);//分页
return pageInfo;
}
///
public async Task> List(UserPageInput input)
{
var query = await GetQuery(input);//获取查询条件
var list = await query.ToListAsync();
return list;
}
///
public async Task> OwnRole(BaseIdInput input)
{
var relations = await _relationService.GetRelationListByObjectIdAndCategory(input.Id, CateGoryConst.RELATION_SYS_USER_HAS_ROLE);
var roleIds = relations.Select(it => it.TargetId.ToLong()).ToList();
var roleList = await Context.Queryable().Where(it => roleIds.Contains(it.Id)).Select().ToListAsync();
return roleList;
}
///
public async Task OwnResource(BaseIdInput input)
{
return await _sysRoleService.OwnResource(input, CateGoryConst.RELATION_SYS_USER_HAS_RESOURCE);
}
///
public async Task OwnPermission(BaseIdInput input)
{
var roleOwnPermission = new RoleOwnPermissionOutput
{
Id = input.Id
};//定义结果集
var grantInfoList = new List();//已授权信息集合
//获取关系列表
var relations = await _relationService.GetRelationListByObjectIdAndCategory(input.Id, CateGoryConst.RELATION_SYS_USER_HAS_PERMISSION);
//遍历关系表
relations.ForEach(it =>
{
//将扩展信息转为实体
var relationPermission = it.ExtJson.ToJsonEntity();
grantInfoList.Add(relationPermission);//添加到已授权信息
});
roleOwnPermission.GrantInfoList = grantInfoList;//赋值已授权信息
return roleOwnPermission;
}
///
public async Task> UserPermissionTreeSelector(BaseIdInput input)
{
var permissionTreeSelectors = new List();//授权树结果集
//获取用户资源关系
var relationsRes = await _relationService.GetRelationByCategory(CateGoryConst.RELATION_SYS_USER_HAS_RESOURCE);
var menuIds = relationsRes.Where(it => it.ObjectId == input.Id).Select(it => it.TargetId.ToLong()).ToList();
if (menuIds.Any())
{
//获取菜单信息
var menus = await _resourceService.GetResourcesByIds(menuIds, CateGoryConst.RESOURCE_MENU);
//获取权限授权树
var permissions = _resourceService.PermissionTreeSelector(menus.Select(it => it.Path).ToList());
if (permissions.Count > 0)
{
permissionTreeSelectors = permissions.Select(it => it.PermissionName).ToList();//返回授权树权限名称列表
}
}
return permissionTreeSelectors;
}
///
public async Task> GetUserListByIdList(IdListInput input)
{
var userList = await Context.Queryable().Where(it => input.IdList.Contains(it.Id)).Select().ToListAsync();
return userList;
}
///
public async Task Detail(BaseIdInput input)
{
var user = await GetUserById(input.Id);
if (user != null)
{
user.Password = null;//清空密码
}
return user;
}
#endregion 查询
#region 数据范围相关
///
public async Task?> GetLoginUserApiDataScope()
{
var userInfo = await GetUserById(UserManager.UserId);//获取用户信息
// 路由名称
var routeName = App.HttpContext.Request.Path.Value;
//获取当前url的数据范围
var dataScope = userInfo.DataScopeList.Where(it => it.ApiUrl == routeName).FirstOrDefault();
if (dataScope != null)
{
//根据数据范围分类获取数据范围
//null:代表拥有全部数据权限
//[xx,xx]:代表拥有部分机构的权限
//[]:代表仅自己权限
switch (dataScope.ScopeCategory)
{
case CateGoryConst.SCOPE_ALL:
return null;
case CateGoryConst.SCOPE_ORG_CHILD:
return userInfo.ScopeOrgChildList;
case CateGoryConst.SCOPE_ORG:
return new List { userInfo.OrgId };
case CateGoryConst.SCOPE_ORG_DEFINE:
return dataScope.DataScopes;
case CateGoryConst.SCOPE_SELF:
return new List();
}
}
return new List();
}
///
public async Task CheckApiDataScope(long? orgId, long? createUerId, string errMsg = "")
{
var hasPermission = true;
//判断数据范围
var dataScope = await GetLoginUserApiDataScope();
if (dataScope is { Count: > 0 })//如果有机构
{
if (orgId == null || !dataScope.Contains(orgId.Value))//判断机构id是否在数据范围
hasPermission = false;
}
else if (dataScope is { Count: 0 })// 表示仅自己
{
if (createUerId != UserManager.UserId)
hasPermission = false;//机构的创建人不是自己则报错
}
//如果传了错误信息,直接抛出异常
if (!hasPermission && !string.IsNullOrEmpty(errMsg))
throw Oops.Bah(errMsg);
return hasPermission;
}
public async Task CheckApiDataScope(List orgIds, List createUerIds, string errMsg = "")
{
var hasPermission = true;
//判断数据范围
var dataScope = await GetLoginUserApiDataScope();
if (dataScope is { Count: > 0 })//如果有机构
{
if (orgIds == null || !dataScope.ContainsAll(orgIds))//判断机构id列表是否全在数据范围
hasPermission = false;
}
else if (dataScope is { Count: 0 })// 表示仅自己
{
if (createUerIds.Any(it => it != UserManager.UserId))//如果创建者id里有任何不是自己创建的机构
hasPermission = false;
}
//如果传了错误信息,直接抛出异常
if (!hasPermission && !string.IsNullOrEmpty(errMsg))
throw Oops.Bah(errMsg);
return hasPermission;
}
#endregion
#region 新增
///
public async Task Add(UserAddInput input)
{
await CheckInput(input);//检查参数
var sysUser = input.Adapt();//实体转换
//默认头像
sysUser.Avatar = AvatarUtil.GetNameImageBase64(sysUser.Name);
//获取默认密码
sysUser.Password = await GetDefaultPassWord(true);//设置密码
sysUser.Status = CommonStatusConst.ENABLE;//默认状态
await InsertAsync(sysUser);//添加数据
}
#endregion 新增
#region 编辑
///
public async Task Edit(UserEditInput input)
{
await CheckInput(input);//检查参数
var exist = await GetUserById(input.Id);//获取用户信息
if (exist != null)
{
var isSuperAdmin = exist.Account == SysRoleConst.SUPER_ADMIN;//判断是否有超管
if (isSuperAdmin && !UserManager.SuperAdmin)
throw Oops.Bah("不可修改系统内置超管用户账号");
var name = exist.Name;//姓名
var sysUser = input.Adapt();//实体转换
if (name != input.Name)
sysUser.Avatar = AvatarUtil.GetNameImageBase64(input.Name);//如果姓名改变了,重新生成头像
if (await Context.Updateable(sysUser).IgnoreColumns(it => new
{
//忽略更新字段
it.Password,
it.LastLoginAddress,
it.LastLoginDevice,
it.LastLoginIp,
it.LastLoginTime,
it.LatestLoginAddress,
it.LatestLoginDevice,
it.LatestLoginIp,
it.LatestLoginTime
}).IgnoreColumnsIF(name == input.Name, it => it.Avatar).ExecuteCommandAsync() > 0
)//修改数据
{
DeleteUserFromRedis(sysUser.Id);//删除用户缓存
//删除用户token缓存
_simpleCacheService.HashDel>(CacheConst.CACHE_USER_TOKEN, sysUser.Id.ToString());
}
}
}
///
public async Task Edits(BatchEditInput input)
{
//获取参数字典
var data = await _batchEditService.GetUpdateBatchConfigDict(input.Code, input.Columns);
if (data.Count > 0)
{
await Context.Updateable(data).Where(it => input.Ids.Contains(it.Id)).ExecuteCommandAsync();
}
}
///
public async Task DisableUser(BaseIdInput input)
{
var sysUser = await GetUserById(input.Id);//获取用户信息
if (sysUser != null)
{
var isSuperAdmin = sysUser.Account == SysRoleConst.SUPER_ADMIN;//判断是否有超管
if (isSuperAdmin)
throw Oops.Bah("不可禁用系统内置超管用户账号");
CheckSelf(input.Id, SystemConst.DISABLE);//判断是不是自己
//设置状态为禁用
if (await UpdateSetColumnsTrueAsync(it => new SysUser
{
Status = CommonStatusConst.DISABLED
}, it => it.Id == input.Id))
DeleteUserFromRedis(input.Id);//从缓存删除用户信息
}
}
///
public async Task EnableUser(BaseIdInput input)
{
CheckSelf(input.Id, SystemConst.ENABLE);//判断是不是自己
//设置状态为启用
if (await UpdateSetColumnsTrueAsync(it => new SysUser
{
Status = CommonStatusConst.ENABLE
}, it => it.Id == input.Id))
DeleteUserFromRedis(input.Id);//从缓存删除用户信息
}
///
public async Task ResetPassword(BaseIdInput input)
{
var password = await GetDefaultPassWord(true);//获取默认密码,这里不走Aop所以需要加密一下
//重置密码
if (await UpdateSetColumnsTrueAsync(it => new SysUser
{
Password = password
}, it => it.Id == input.Id))
DeleteUserFromRedis(input.Id);//从缓存删除用户信息
}
///
public async Task GrantRole(UserGrantRoleInput input)
{
var sysUser = await GetUserById(input.Id);//获取用户信息
if (sysUser != null)
{
var isSuperAdmin = sysUser.Account == SysRoleConst.SUPER_ADMIN;//判断是否有超管
if (isSuperAdmin)
throw Oops.Bah("不能给超管分配角色");
CheckSelf(input.Id, SystemConst.GRANT_ROLE);//判断是不是自己
//给用户赋角色
await _relationService.SaveRelationBatch(CateGoryConst.RELATION_SYS_USER_HAS_ROLE, input.Id,
input.RoleIdList.Select(it => it.ToString()).ToList(), null, true);
DeleteUserFromRedis(input.Id);//从缓存删除用户信息
}
}
///
public async Task GrantResource(UserGrantResourceInput input)
{
var menuIds = input.GrantInfoList.Select(it => it.MenuId).ToList();//菜单ID
var extJsons = input.GrantInfoList.Select(it => it.ToJson()).ToList();//拓展信息
var relationRoles = new List();//要添加的用户资源和授权关系表
var sysUser = await GetUserById(input.Id);//获取用户
if (sysUser != null)
{
#region 用户资源处理
//遍历角色列表
for (var i = 0; i < menuIds.Count; i++)
{
//将用户资源添加到列表
relationRoles.Add(new SysRelation
{
ObjectId = sysUser.Id,
TargetId = menuIds[i].ToString(),
Category = CateGoryConst.RELATION_SYS_USER_HAS_RESOURCE,
ExtJson = extJsons == null ? null : extJsons[i]
});
}
#endregion 用户资源处理
#region 用户权限处理.
var relationRolePer = new List();//要添加的用户有哪些权限列表
var defaultDataScope = input.DefaultDataScope;//获取默认数据范围
//获取菜单信息
var menus = await _resourceService.GetResourcesByIds(menuIds, CateGoryConst.RESOURCE_MENU);
if (menus.Count > 0)
{
#region 用户模块关系
//获取我的模块信息Id列表
var moduleIds = menus.Select(it => it.Module.Value).Distinct().ToList();
moduleIds.ForEach(it =>
{
//将角色资源添加到列表
relationRoles.Add(new SysRelation
{
ObjectId = sysUser.Id,
TargetId = it.ToString(),
Category = CateGoryConst.RELATION_SYS_USER_HAS_MODULE
});
});
#endregion
//获取权限授权树
var permissions = _resourceService.PermissionTreeSelector(menus.Select(it => it.Path).ToList());
permissions.ForEach(it =>
{
//新建角色权限关系
relationRolePer.Add(new SysRelation
{
ObjectId = sysUser.Id,
TargetId = it.ApiRoute,
Category = CateGoryConst.RELATION_SYS_USER_HAS_PERMISSION,
ExtJson = new RelationRolePermission
{
ApiUrl = it.ApiRoute,
ScopeCategory = defaultDataScope.ScopeCategory,
ScopeDefineOrgIdList = defaultDataScope.ScopeDefineOrgIdList
}.ToJson()
});
});
}
relationRoles.AddRange(relationRolePer);//合并列表
#endregion 用户权限处理.
#region 保存数据库
//事务
var result = await Tenant.UseTranAsync(async () =>
{
var relationRep = ChangeRepository>();//切换仓储
await relationRep.DeleteAsync(it => it.ObjectId == sysUser.Id && (it.Category == CateGoryConst.RELATION_SYS_USER_HAS_PERMISSION
|| it.Category == CateGoryConst.RELATION_SYS_USER_HAS_RESOURCE) || it.Category == CateGoryConst.RELATION_SYS_USER_HAS_MODULE);
await relationRep.InsertRangeAsync(relationRoles);//添加新的
});
if (result.IsSuccess)//如果成功了
{
await _relationService.RefreshCache(CateGoryConst.RELATION_SYS_USER_HAS_PERMISSION);//刷新关系缓存
await _relationService.RefreshCache(CateGoryConst.RELATION_SYS_USER_HAS_RESOURCE);//刷新关系缓存
await _relationService.RefreshCache(CateGoryConst.RELATION_SYS_USER_HAS_MODULE);//刷新关系缓存
DeleteUserFromRedis(input.Id);//删除该用户缓存
}
else
{
//写日志
_logger.LogError(result.ErrorMessage, result.ErrorException);
throw Oops.Oh(ErrorCodeEnum.A0003);
}
#endregion 保存数据库
}
}
///
public async Task GrantPermission(GrantPermissionInput input)
{
var sysUser = await GetUserById(input.Id);//获取用户
if (sysUser != null)
{
var apiUrls = input.GrantInfoList.Select(it => it.ApiUrl).ToList();//apiurl列表
var extJsons = input.GrantInfoList.Select(it => it.ToJson()).ToList();//拓展信息
await _relationService.SaveRelationBatch(CateGoryConst.RELATION_SYS_USER_HAS_PERMISSION, input.Id, apiUrls, extJsons,
true);//添加到数据库
DeleteUserFromRedis(input.Id);
}
}
#endregion 编辑
#region 删除
///
public async Task Delete(BaseIdListInput input)
{
//获取所有ID
var ids = input.Ids;
if (ids.Count > 0)
{
var containsSuperAdmin = await IsAnyAsync(it => it.Account == SysRoleConst.SUPER_ADMIN && ids.Contains(it.Id));//判断是否有超管
if (containsSuperAdmin)
throw Oops.Bah("不可删除系统内置超管用户");
if (ids.Contains(UserManager.UserId))
throw Oops.Bah("不可删除自己");
//定义删除的关系
var delRelations = new List
{
CateGoryConst.RELATION_SYS_USER_HAS_RESOURCE,
CateGoryConst.RELATION_SYS_USER_HAS_PERMISSION,
CateGoryConst.RELATION_SYS_USER_HAS_ROLE,
CateGoryConst.RELATION_SYS_USER_HAS_MODULE,
CateGoryConst.RELATION_SYS_USER_SCHEDULE_DATA,
CateGoryConst.RELATION_SYS_USER_WORKBENCH_DATA
};
//事务
var result = await Tenant.UseTranAsync(async () =>
{
//清除该用户作为主管信息
await UpdateAsync(it => new SysUser
{
DirectorId = null
}, it => ids.Contains(it.DirectorId.Value));
//删除用户
await DeleteByIdsAsync(ids.Cast