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 { /// /// /// 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; /// /// /// /// public CodeInfoSyncService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); saasService = _serviceProvider.GetRequiredService(); _sysCacheService = _serviceProvider.GetRequiredService(); tenantDb = saasService.GetBizDbScopeById(user.TenantId); } public async Task> SyncCarrierInfo() { var publicList = await db.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var clientList = await tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var updateList = new List(); var insertList = new List(); 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.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess)); } public async Task> SyncCountryInfo() { var publicList = await db.Queryable().Where(x=>x.Status == StatusEnum.Enable).ToListAsync(); var clientList = await tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var updateList = new List(); var insertList = new List(); 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.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess)); } public async Task> SyncCtnInfo() { var publicList = await db.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var clientList = await tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var updateList = new List(); var insertList = new List(); 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.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess)); } public async Task> SyncGoodsInfo() { var publicList = await db.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var clientList = await tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var updateList = new List(); var insertList = new List(); 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.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess)); } public async Task> SyncPackageInfo() { var publicList = await db.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var clientList = await tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var updateList = new List(); var insertList = new List(); 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.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess)); } public async Task> SyncPortInfo() { var publicList = await db.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var clientList = await tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToListAsync(); var updateList = new List(); var insertList = new List(); 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.Failed("同步成功!", MultiLanguageConst.DataUpdateSuccess)); } } }