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.

210 lines
7.2 KiB
C#

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
{
/// <summary>
/// 费用服务基类
/// </summary>
public abstract class CMServiceBase
{
/// <summary>
/// 人民币代码
/// </summary>
public const string RMB_CODE = "CNY";
/// <summary>
/// 美元代码
/// </summary>
public const string USD_CODE = "USD";
/// <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 CMServiceBase(IServiceProvider serviceProvider)
{
User = serviceProvider.GetRequiredService<IUser>();
Db = serviceProvider.GetRequiredService<ISqlSugarClient>();
SaasService = serviceProvider.GetRequiredService<ISaasDbService>();
}
/// <summary>
/// 检查业务是否已费用锁定或已业务锁定
/// </summary>
/// <param name="bid">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <param name="type">锁定范围</param>
/// <returns></returns>
internal async Task<bool> IsLockedAsync(long bizid, BusinessType businessType)
{
bool? isFeeLocking = null;
isFeeLocking = await TenantDb.Queryable<BusinessFeeStatus>().Where(
x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).FirstAsync();
var IsBusinessLocking = await TenantDb.Queryable<BusinessFeeStatus>().Where(
x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsBusinessLocking).FirstAsync();
return (isFeeLocking.GetValueOrDefault()|| IsBusinessLocking.GetValueOrDefault());
}
/// <summary>
/// 是否业务锁定
/// </summary>
/// <param name="bizid"></param>
/// <param name="businessType"></param>
/// <returns></returns>
internal async Task<bool> IsBusinessLocking(long bizid, BusinessType businessType)
{
var IsBusinessLocking = await TenantDb.Queryable<BusinessFeeStatus>().Where(
x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsBusinessLocking).FirstAsync();
return IsBusinessLocking.GetValueOrDefault();
}
/// <summary>
/// 是否费用锁定
/// </summary>
/// <param name="bizid"></param>
/// <param name="businessType"></param>
/// <returns></returns>
internal async Task<bool> IsFeeLockedAsync(long bizid, BusinessType businessType)
{
bool? isFeeLocking = null;
isFeeLocking = await TenantDb.Queryable<BusinessFeeStatus>().Where(
x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).FirstAsync();
return isFeeLocking.GetValueOrDefault() ;
}
/// <summary>
/// 业务是否包含费用
/// </summary>
/// <param name="bizid"></param>
/// <param name="businessType"></param>
/// <returns></returns>
internal async Task<bool> IsHaveFee(long bizid, BusinessType businessType)
{
bool? isFeeLocking = null;
isFeeLocking = await TenantDb.Queryable<BusinessFeeStatus>().Where(
x => x.BusinessId == bizid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).FirstAsync();
return isFeeLocking.GetValueOrDefault();
}
/// <summary>
/// 返回箱当前状态与箱基础信息联合的查询对象
/// </summary>
/// <param name="expr1">关联条件1</param>
/// <returns>查询对象</returns>
public ISugarQueryable<CM_CurrentStateRes> CreateCurrentStateQuery()
{
var query1 = TenantDb.Queryable<CM_CurrentState>()
.LeftJoin<CM_BaseInfo>((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<ISugarQueryable<CM_CurrentStateRes>> { query1 });
}
/// <summary>
/// 初始化费用状态表
/// </summary>
public async void InitBusiness(long Id)
{
#region 初始化费用状态表
var feeStatus = BusinessFeeStatus.Init(Id);
TenantDb.Insertable(feeStatus).ExecuteCommand();
#endregion
}
}
}