using System.Linq.Expressions; using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.WMS.ContainerManagement.Info.Dtos; using DS.WMS.ContainerManagement.Info.Entity; using DS.WMS.Core.Application.Dtos; using DS.WMS.Core.Application.Entity; using DS.WMS.Core.Code.Entity; 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 NPOI.SS.Formula.Functions; 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(); } /// /// 返回箱当前状态与箱基础信息联合的查询对象 /// /// 关联条件1 /// 查询对象 public ISugarQueryable CreateCurrentStateQuery() { var query1 = TenantDb.Queryable() .LeftJoin((c, b) => c.CtnBaseinfoId == b.Id) //.WhereIF(expr1 != null, expr1) .Select((c,b) => new CM_CurrentStateRes { Id = c.Id, OrgId=c.OrgId, CtnBaseinfoId = c.CtnBaseinfoId, Cntrno= b.Cntrno, CtnCode = b.CtnCode, Ctnall = b.Ctnall, UsedState = c.UsedState, CtnOwnerId = c.CtnOwnerId, CtnOwner = c.CtnOwner, CtnSourceId = c.CtnSourceId, //CtnSource = c.CtnSource CtnBizStateId = c.CtnBizStateId, Billno = c.Billno, CtnReleaseNo = c.CtnReleaseNo, CtnStateId = c.CtnStateId, CtnBreakStateId = c.CtnBreakStateId, IsOnlineId = c.IsOnlineId, IsHeavy=c.IsHeavy, Portid = c.Portid, Port = c.Port, Depot = c.Depot, VesselVoyno = c.VesselVoyno, Mblno = c.Mblno, CustomerId = c.CustomerId, CustomerName = c.CustomerName, ETD = c.ETD, ETA = c.ETA, StateTime = c.StateTime, CtnWeight = b.CtnWeight, CtnValue_Base = b.CtnValue_Base, CreateTime= c.CreateTime, }); return query1; //return TenantDb.UnionAll(new List> { query1 }); } /// /// 初始化费用状态表 /// public async void InitBusiness(long Id) { #region 初始化费用状态表 var feeStatus = BusinessFeeStatus.Init(Id); TenantDb.Insertable(feeStatus).ExecuteCommand(); #endregion } } }