using System.Linq.Expressions; using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.WMS.Core.Fee.Dtos; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Flow.Entity; using DS.WMS.Core.Op.Entity; using Microsoft.Extensions.DependencyInjection; using SqlSugar; namespace DS.WMS.ContainerManagement.Info.Method { /// /// 费用服务基类 /// public abstract class CMServiceBase { /// /// 人民币代码 /// public const string RMB_CODE = "CNY"; /// /// 美元代码 /// public const string USD_CODE = "USD"; /// /// 获取用户相关信息 /// 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 CMServiceBase(IServiceProvider serviceProvider) { User = serviceProvider.GetRequiredService(); Db = serviceProvider.GetRequiredService(); SaasService = serviceProvider.GetRequiredService(); } /// /// 检查业务是否已费用锁定或已业务锁定 /// /// 业务ID /// 业务类型 /// 锁定范围 /// internal async Task IsLockedAsync(long bizid, BusinessType businessType) { bool? isFeeLocking = null; isFeeLocking = await TenantDb.Queryable().Where( x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).FirstAsync(); var IsBusinessLocking = await TenantDb.Queryable().Where( x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsBusinessLocking).FirstAsync(); return (isFeeLocking.GetValueOrDefault()|| IsBusinessLocking.GetValueOrDefault()); } /// /// 是否业务锁定 /// /// /// /// internal async Task IsBusinessLocking(long bizid, BusinessType businessType) { var IsBusinessLocking = await TenantDb.Queryable().Where( x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsBusinessLocking).FirstAsync(); return IsBusinessLocking.GetValueOrDefault(); } /// /// 是否费用锁定 /// /// /// /// internal async Task IsFeeLockedAsync(long bizid, BusinessType businessType) { bool? isFeeLocking = null; isFeeLocking = await TenantDb.Queryable().Where( x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).FirstAsync(); return isFeeLocking.GetValueOrDefault() ; } /// /// 业务是否包含费用 /// /// /// /// internal async Task IsHaveFee(long bizid, BusinessType businessType) { bool? isFeeLocking = null; isFeeLocking = await TenantDb.Queryable().Where( x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).FirstAsync(); return isFeeLocking.GetValueOrDefault(); } } }