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.

144 lines
5.3 KiB
C#

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();
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public JobCommonService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
/// <summary>
/// 获取船公司代码
/// </summary>
/// <param name="Id"></param>
/// <param name="tenantDb"></param>
/// <returns></returns>
public string GetCarrierCode(long Id, SqlSugarScopeProvider tenantDb)
{
if (Id == 0)
return "";
var client = tenantDb.Queryable<CodeCarrier>().First(v => v.Id == Id);
if (client.IsNull())
{
throw new Exception("请检查船公司信息");
}
return client.EdiCode.IsNull() ? client.Code : client.EdiCode;
}
/// <summary>
/// 获取港口代码
/// </summary>
/// <param name="Id"></param>
/// <param name="tenantDb"></param>
/// <returns></returns>
public string GetPortCode(long Id, SqlSugarScopeProvider tenantDb)
{
if (Id == 0)
return "";
var port = tenantDb.Queryable<CodePort>().First(v => v.Id == Id && v.Status == StatusEnum.Enable);
if (port.IsNull())
{
throw new Exception("请检查港口信息");
}
return port.EdiCode.IsNull() ? port.PortName : port.EdiCode;
}
/// <summary>
/// 获取往来单位代码 有EDICode返 无返回CodeName
/// </summary>
/// <param name="Id"></param>
/// <param name="tenantDb"></param>
/// <param name="isEDI"></param>
/// <returns></returns>
public string GetClientCode(long Id, SqlSugarScopeProvider tenantDb, bool isEDI = true)
{
if (Id == 0)
return "";
var client = tenantDb.Queryable<InfoClient>().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;
}
}
/// <summary>
/// 获取第三方账户
/// </summary>
/// <param name="type"></param>
/// <param name="userId"></param>
/// <param name="tenantDb"></param>
/// <param name="customerId"></param>
/// <returns></returns>
public CodeThirdParty GetCodeThirdParty(string type, string userId, SqlSugarScopeProvider tenantDb, long customerId = 0)
{
//var account = new CodeThirdParty();
if (userId.IsNull())
{
return tenantDb.Queryable<CodeThirdParty>().First(x => x.AccountType == type);
}
var uId = long.Parse(userId);
if (customerId == 0)
{
if (tenantDb.Queryable<CodeThirdParty>().Where(x => x.AccountType == type && x.UserId == uId).Any())
{
return tenantDb.Queryable<CodeThirdParty>().Where(x => x.AccountType == type && x.UserId == uId).First();
}
else
{
return tenantDb.Queryable<CodeThirdParty>().First(x => x.AccountType == type && x.IsCompany == true);
}
}
else
{
if (tenantDb.Queryable<CodeThirdParty>().Where(x => x.AccountType == type && x.UserId == uId && x.CustomerId == customerId).Any())
{
return tenantDb.Queryable<CodeThirdParty>().Where(x => x.AccountType == type && x.UserId == uId && x.CustomerId == customerId).First();
}
else if (tenantDb.Queryable<CodeThirdParty>().Where(x => x.AccountType == type && x.UserId == uId).Any())
{
return tenantDb.Queryable<CodeThirdParty>().First(x => x.AccountType == type && x.UserId == uId);
}
else
{
return tenantDb.Queryable<CodeThirdParty>().First(x => x.AccountType == type && x.IsCompany == true);
}
}
//return account;
}
}
}