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 { /// /// 服务基类 /// public abstract class ServiceBase { /// /// 获取服务容器 /// protected IServiceProvider ServiceProvider { get; private set; } /// /// 获取用户相关信息 /// protected IUser User { get; private set; } /// /// 获取主库访问对象 /// protected ISqlSugarClient Db { get; private set; } /// /// 获取业务库访问对象 /// protected ISaasDbService SaasService { get; private set; } SqlSugarScopeProvider? _tenantDb; /// /// 获取业务库访问对象 /// protected SqlSugarScopeProvider TenantDb { get { if (_tenantDb == null) _tenantDb = SaasService.GetBizDbScopeById(User.TenantId); return _tenantDb; } } /// /// 初始化 /// /// 服务提供程序 protected ServiceBase(IServiceProvider serviceProvider) { ServiceProvider = serviceProvider; User = serviceProvider.GetRequiredService(); Db = serviceProvider.GetRequiredService(); SaasService = serviceProvider.GetRequiredService(); } /// /// 查找审批模板 /// /// 审批类型 /// protected internal async Task FindTemplateAsync(AuditType auditType) { return await Db.Queryable().OrderByDescending(x => x.CreateTime).Take(1) .FirstAsync(x => x.Status == StatusEnum.Enable && x.AuditType == auditType); } } }