|
|
|
|
using DS.Module.Core;
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
long tid = long.Parse(User.TenantId);
|
|
|
|
|
return await Db.Queryable<FlowTemplateTenant>().OrderByDescending(x => x.CreateTime).Take(1)
|
|
|
|
|
.FirstAsync(x => x.TenantId == tid && x.Status == StatusEnum.Enable && x.AuditType == auditType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|