You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.Flow.Entity;
|
|
using DS.WMS.Core.Sys.Interface;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core
|
|
{
|
|
/// <summary>
|
|
/// 服务基类
|
|
/// </summary>
|
|
public abstract class ServiceBase
|
|
{
|
|
/// <summary>
|
|
/// 获取服务容器
|
|
/// </summary>
|
|
protected IServiceProvider ServiceProvider { get; private set; }
|
|
/// <summary>
|
|
/// 获取主库访问对象
|
|
/// </summary>
|
|
protected ISqlSugarClient Db { get; private set; }
|
|
/// <summary>
|
|
/// 获取业务库访问对象
|
|
/// </summary>
|
|
protected ISaasDbService SaasService { get; private set; }
|
|
|
|
readonly Lazy<ICommonService> commonService;
|
|
|
|
SqlSugarScopeProvider? _tenantDb;
|
|
/// <summary>
|
|
/// 获取业务库访问对象
|
|
/// </summary>
|
|
protected SqlSugarScopeProvider TenantDb
|
|
{
|
|
get
|
|
{
|
|
_tenantDb ??= SaasService.GetBizDbScopeById(User.TenantId);
|
|
return _tenantDb;
|
|
}
|
|
}
|
|
|
|
IUser _user;
|
|
/// <summary>
|
|
/// 获取用户相关信息
|
|
/// </summary>
|
|
public virtual IUser User => _user;
|
|
|
|
/// <summary>
|
|
/// 日志记录对象
|
|
/// </summary>
|
|
public Lazy<ILogger<ServiceBase>> Logger { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="serviceProvider">服务提供程序</param>
|
|
protected ServiceBase(IServiceProvider serviceProvider)
|
|
{
|
|
ServiceProvider = serviceProvider;
|
|
_user = serviceProvider.GetRequiredService<IUser>();
|
|
Db = serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
SaasService = serviceProvider.GetRequiredService<ISaasDbService>();
|
|
commonService = new Lazy<ICommonService>(serviceProvider.GetRequiredService<ICommonService>());
|
|
Logger = new Lazy<ILogger<ServiceBase>>(serviceProvider.GetRequiredService<ILogger<ServiceBase>>());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取查询对象
|
|
/// </summary>
|
|
/// <typeparam name="T">对象类型</typeparam>
|
|
/// <returns></returns>
|
|
protected internal ISugarQueryable<T> AsQueryable<T>() where T : class
|
|
{
|
|
(ISugarQueryable<T> query, _) = commonService.Value.GetVisibleDataRuleFilter<T>(TenantDb)
|
|
.GetAwaiter().GetResult();
|
|
|
|
return query;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找审批模板
|
|
/// </summary>
|
|
/// <param name="auditType">审批类型</param>
|
|
/// <returns></returns>
|
|
protected internal async Task<FlowTemplate> FindTemplateAsync(TaskBaseTypeEnum auditType)
|
|
{
|
|
long tid = long.Parse(User.TenantId);
|
|
return await TenantDb.Queryable<FlowTemplate>().OrderByDescending(x => x.CreateTime).Take(1)
|
|
.FirstAsync(x => x.Status == StatusEnum.Enable && x.AuditType == auditType);
|
|
}
|
|
}
|
|
}
|