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.
89 lines
2.9 KiB
C#
89 lines
2.9 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 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; }
|
|
|
|
readonly Lazy<ICommonService> commonService;
|
|
|
|
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>();
|
|
commonService = new Lazy<ICommonService>(serviceProvider.GetRequiredService<ICommonService>());
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
}
|
|
}
|