using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.HangfireJob.Interface;
using DS.WMS.Core.Info.Entity;
using Microsoft.Extensions.DependencyInjection;
using NLog;
using SqlSugar;
using Logger = NLog.Logger;
namespace DS.WMS.Core.HangfireJob.Method
{
public class JobCommonService: IJobCommonService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
///
///
///
///
public JobCommonService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
saasService = _serviceProvider.GetRequiredService();
}
///
/// 获取船公司代码
///
///
///
///
public string GetCarrierCode(long Id, SqlSugarScopeProvider tenantDb)
{
if (Id == 0)
return "";
var client = tenantDb.Queryable().First(v => v.Id == Id);
if (client.IsNull())
{
throw new Exception("请检查船公司信息");
}
return client.EdiCode.IsNull() ? client.Code : client.EdiCode;
}
///
/// 获取港口代码
///
///
///
///
public string GetPortCode(long Id, SqlSugarScopeProvider tenantDb)
{
if (Id == 0)
return "";
var port = tenantDb.Queryable().First(v => v.Id == Id && v.Status == StatusEnum.Enable);
if (port.IsNull())
{
throw new Exception("请检查港口信息");
}
return port.EdiCode.IsNull() ? port.PortName : port.EdiCode;
}
///
/// 获取往来单位代码 有EDICode返 无返回CodeName
///
///
///
///
///
public string GetClientCode(long Id, SqlSugarScopeProvider tenantDb, bool isEDI = true)
{
if (Id == 0)
return "";
var client = tenantDb.Queryable().First(v => v.Id == Id && v.Status == StatusEnum.Enable.ToEnumInt());
if (client.IsNull())
{
throw new Exception("请检查往来单位信息");
}
if (isEDI)
{
return client.EDICode.IsNotEmptyOrNull() ? client.EDICode : client.CodeName;
}
else
{
return client.CodeName;
}
}
///
/// 获取第三方账户
///
///
///
///
///
///
public CodeThirdParty GetCodeThirdParty(string type, string userId, SqlSugarScopeProvider tenantDb, long customerId = 0)
{
//var account = new CodeThirdParty();
if (userId.IsNull())
{
return tenantDb.Queryable().First(x => x.AccountType == type);
}
var uId = long.Parse(userId);
if (customerId == 0)
{
if (tenantDb.Queryable().Where(x => x.AccountType == type && x.CreateBy == uId).Any())
{
return tenantDb.Queryable().Where(x => x.AccountType == type && x.CreateBy == uId).First();
}
else
{
return tenantDb.Queryable().First(x => x.AccountType == type);
}
}
else
{
if (tenantDb.Queryable().Where(x => x.AccountType == type && x.CreateBy == uId && x.CustomerId == customerId).Any())
{
return tenantDb.Queryable().Where(x => x.AccountType == type && x.CreateBy == uId && x.CustomerId == customerId).First();
}
else if (tenantDb.Queryable().Where(x => x.AccountType == type && x.CreateBy == uId).Any())
{
return tenantDb.Queryable().First(x => x.AccountType == type && x.CreateBy == uId);
}
else
{
return tenantDb.Queryable().First(x => x.AccountType == type);
}
}
//return account;
}
}
}