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.

275 lines
11 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.Code.Interface;
using DS.WMS.Core.Sys.Interface;
using Microsoft.Extensions.DependencyInjection;
using NPOI.SS.Formula.Functions;
using SqlSugar;
namespace DS.WMS.Core.Code.Method
{
/// <summary>
///
/// </summary>
public class CodeInfoSyncService : ICodeInfoSyncService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
private readonly ISysCacheService _sysCacheService;
private readonly SqlSugarScopeProvider tenantDb;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public CodeInfoSyncService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
_sysCacheService = _serviceProvider.GetRequiredService<ISysCacheService>();
tenantDb = saasService.GetBizDbScopeById(user.TenantId);
}
public async Task<DataResult<string>> SyncCarrierInfo()
{
var publicList = await db.Queryable<CodeCarrier>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var clientList = await tenantDb.Queryable<CodeCarrier>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var updateList = new List<CodeCarrier>();
var insertList = new List<CodeCarrier>();
foreach (var item in publicList)
{
var client = clientList.Where(x => x.Id == item.Id).FirstOrDefault();
if (client.IsNotNull())
{
client.Code = item.Code;
client.CnName = item.CnName;
client.CnShortName = item.CnShortName;
client.EnName = item.EnName;
client.OtherCode = item.OtherCode;
client.CountryId = item.CountryId;
client.CountryName = item.CountryName;
client.Logo = item.Logo;
client.Description = item.Description;
client.Remark = item.Remark;
updateList.Add(client);
}
else
{
insertList.Add(item);
}
}
if (updateList.Count > 0)
await tenantDb.Updateable(updateList).ExecuteCommandAsync();
if (insertList.Count > 0)
await tenantDb.Insertable(insertList).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess));
}
public async Task<DataResult<string>> SyncCountryInfo()
{
var publicList = await db.Queryable<CodeCountry>().Where(x=>x.Status == StatusEnum.Enable).ToListAsync();
var clientList = await tenantDb.Queryable<CodeCountry>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var updateList = new List<CodeCountry>();
var insertList = new List<CodeCountry>();
foreach (var item in publicList) {
var client = clientList.Where(x=> x.Id == item.Id).FirstOrDefault();
if (client.IsNotNull())
{
client.CountryCode = item.CountryCode;
client.CountryName = item.CountryName;
client.CountryEnName = item.CountryEnName;
client.Chau = item.Chau;
client.Capital = item.Capital;
client.Tariff = item.Tariff;
client.TonnageTax = item.TonnageTax;
client.CountryCode3 = item.CountryCode3;
client.Explain = item.Explain;
updateList.Add(client);
}
else {
insertList.Add(item);
}
}
if (updateList.Count > 0)
await tenantDb.Updateable(updateList).ExecuteCommandAsync();
if (insertList.Count > 0)
await tenantDb.Insertable(insertList).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess));
}
public async Task<DataResult<string>> SyncCtnInfo()
{
var publicList = await db.Queryable<CodeCtn>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var clientList = await tenantDb.Queryable<CodeCtn>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var updateList = new List<CodeCtn>();
var insertList = new List<CodeCtn>();
foreach (var item in publicList)
{
var client = clientList.Where(x => x.Id == item.Id).FirstOrDefault();
if (client.IsNotNull())
{
client.CtnSize = item.CtnSize;
client.CtnType = item.CtnType;
client.CtnName = item.CtnName;
client.EdiCode = item.EdiCode;
client.CtnWeight = item.CtnWeight;
client.CnExplain = item.CnExplain;
client.EnExplain = item.EnExplain;
client.AfrCode = item.AfrCode;
client.LimitWeight = item.LimitWeight;
client.TEU = item.TEU;
updateList.Add(client);
}
else
{
insertList.Add(item);
}
}
if (updateList.Count > 0)
await tenantDb.Updateable(updateList).ExecuteCommandAsync();
if (insertList.Count > 0)
await tenantDb.Insertable(insertList).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess));
}
public async Task<DataResult<string>> SyncGoodsInfo()
{
var publicList = await db.Queryable<CodeGoods>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var clientList = await tenantDb.Queryable<CodeGoods>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var updateList = new List<CodeGoods>();
var insertList = new List<CodeGoods>();
foreach (var item in publicList)
{
var client = clientList.Where(x => x.Id == item.Id).FirstOrDefault();
if (client.IsNotNull())
{
client.GoodsCode = item.GoodsCode;
client.GoodName = item.GoodName;
client.GoodNo = item.GoodNo;
client.EnName = item.EnName;
client.Description = item.Description;
client.HSCode = item.HSCode;
client.RuleUnit = item.RuleUnit;
client.RuleUnit1 = item.RuleUnit1;
client.RuleUnit2 = item.RuleUnit2;
updateList.Add(client);
}
else
{
insertList.Add(item);
}
}
if (updateList.Count > 0)
await tenantDb.Updateable(updateList).ExecuteCommandAsync();
if (insertList.Count > 0)
await tenantDb.Insertable(insertList).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess));
}
public async Task<DataResult<string>> SyncPackageInfo()
{
var publicList = await db.Queryable<CodePackage>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var clientList = await tenantDb.Queryable<CodePackage>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var updateList = new List<CodePackage>();
var insertList = new List<CodePackage>();
foreach (var item in publicList)
{
var client = clientList.Where(x => x.Id == item.Id).FirstOrDefault();
if (client.IsNotNull())
{
client.PackageName = item.PackageName;
client.CnExplain = item.CnExplain;
client.AfrCode = item.AfrCode;
client.EdiCode = item.EdiCode;
updateList.Add(client);
}
else
{
insertList.Add(item);
}
}
if (updateList.Count > 0)
await tenantDb.Updateable(updateList).ExecuteCommandAsync();
if (insertList.Count > 0)
await tenantDb.Insertable(insertList).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess));
}
public async Task<DataResult<string>> SyncPortInfo()
{
var publicList = await db.Queryable<CodePort>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var clientList = await tenantDb.Queryable<CodePort>().Where(x => x.Status == StatusEnum.Enable).ToListAsync();
var updateList = new List<CodePort>();
var insertList = new List<CodePort>();
foreach (var item in publicList)
{
var client = clientList.Where(x => x.Id == item.Id).FirstOrDefault();
if (client.IsNotNull())
{
client.PortName = item.PortName;
client.CnName = item.CnName;
client.CountryName = item.CountryName;
client.Chau = item.Chau;
client.Explain = item.Explain;
client.PortType = item.PortType;
//client.CountryId = item.CountryId;
//client.LaneId = item.LaneId;
//client.LaneCode = item.LaneCode;
//client.Lane = item.Lane;
client.EdiCode = item.EdiCode;
updateList.Add(client);
}
else
{
insertList.Add(item);
}
}
if (updateList.Count > 0)
await tenantDb.Updateable(updateList).ExecuteCommandAsync();
if (insertList.Count > 0)
await tenantDb.Insertable(insertList).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess));
}
}
}