操控平台后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.4 KiB

// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
using Admin.NET.Bodk.Core.Entities;
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion.DynamicApiController;
using SqlSugar;
namespace Admin.NET.Bodk.Core;
public abstract class ServiceBase(UserManager userManager, SysOrgService sysOrgService, SysUserService sysUserService)
: IDynamicApiController
{
protected readonly UserManager UserManager = userManager;
protected readonly SysOrgService SysOrgService = sysOrgService;
protected async Task<ISugarQueryable<T>> GetDataOutOfOrg<T>(ISugarQueryable<T> queryable, long orgId = 0)
where T : OrgEntityBase
{
var userOrgIdList = await SysOrgService.GetUserOrgIdList();
List<long>? orgList;
if (orgId > 0) // 指定机构查询时
{
orgList = await SysOrgService.GetChildIdListWithSelfById(orgId);
orgList = UserManager.SuperAdmin ? orgList : orgList.Where(u => userOrgIdList.Contains(u)).ToList();
}
else // 各管理员只能看到自己机构下的用户列表
{
orgList = UserManager.SuperAdmin ? null : userOrgIdList;
}
return queryable.WhereIF(orgList != null, u => orgList != null && orgList.Contains(u.OrgId));
}
//新增前置步骤
protected async Task<T> AddBefore<T>(T entity) where T : EntityBase
{
var user = await sysUserService.GetBaseInfo();
entity.CreateUser = user;
entity.CreateTime = DateTime.Now;
entity.CreateUserName = user.NickName;
entity.CreateUserId = user.Id;
return entity;
}
protected async Task<T> AddOrgBefore<T>(T entity) where T : OrgEntityBase
{
var user = await sysUserService.GetBaseInfo();
entity.CreateUser = user;
entity.CreateTime = DateTime.Now;
entity.CreateUserName = user.NickName;
entity.CreateUserId = user.Id;
entity.OrgId = UserManager.OrgId;
return entity;
}
protected async Task<T> UpdateBefore<T>(T entity) where T : EntityBase
{
var user = await sysUserService.GetBaseInfo();
entity.UpdateUser = user;
entity.UpdateTime = DateTime.Now;
entity.UpdateUserName = user.NickName;
entity.UpdateUserId = user.Id;
return entity;
}
}