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.
72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Data;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.UserModule;
|
|
using DS.WMS.Core.Flow.Entity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core
|
|
{
|
|
/// <summary>
|
|
/// 服务基类
|
|
/// </summary>
|
|
public abstract class ServiceBase
|
|
{
|
|
/// <summary>
|
|
/// 获取服务容器
|
|
/// </summary>
|
|
protected IServiceProvider ServiceProvider { get; private set; }
|
|
/// <summary>
|
|
/// 获取用户相关信息
|
|
/// </summary>
|
|
protected IUser User { get; private set; }
|
|
/// <summary>
|
|
/// 获取主库访问对象
|
|
/// </summary>
|
|
protected ISqlSugarClient Db { get; private set; }
|
|
/// <summary>
|
|
/// 获取业务库访问对象
|
|
/// </summary>
|
|
protected ISaasDbService SaasService { get; private set; }
|
|
|
|
SqlSugarScopeProvider? _tenantDb;
|
|
/// <summary>
|
|
/// 获取业务库访问对象
|
|
/// </summary>
|
|
protected SqlSugarScopeProvider TenantDb
|
|
{
|
|
get
|
|
{
|
|
if (_tenantDb == null)
|
|
_tenantDb = SaasService.GetBizDbScopeById(User.TenantId);
|
|
|
|
return _tenantDb;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="serviceProvider">服务提供程序</param>
|
|
protected ServiceBase(IServiceProvider serviceProvider)
|
|
{
|
|
ServiceProvider = serviceProvider;
|
|
User = serviceProvider.GetRequiredService<IUser>();
|
|
Db = serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
SaasService = serviceProvider.GetRequiredService<ISaasDbService>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找审批模板
|
|
/// </summary>
|
|
/// <param name="auditType">审批类型</param>
|
|
/// <returns></returns>
|
|
protected internal async Task<FlowTemplateTenant> FindTemplateAsync(TaskBaseTypeEnum auditType)
|
|
{
|
|
return await Db.Queryable<FlowTemplateTenant>().OrderByDescending(x => x.CreateTime).Take(1)
|
|
.FirstAsync(x => x.Status == StatusEnum.Enable && x.AuditType == auditType);
|
|
}
|
|
}
|
|
}
|