From e7ea3832627bc4682d110c9d602950bc10df02c6 Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Tue, 18 Apr 2023 09:45:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E7=9A=84=E6=B8=AF=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/DataSync/DataSyncService.cs | 96 ++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs index e1466397..1da0ec96 100644 --- a/Myshipping.Application/Service/DataSync/DataSyncService.cs +++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs @@ -61,6 +61,7 @@ namespace Myshipping.Application private readonly SqlSugarRepository _mapcarrier; private readonly SqlSugarRepository _codeLaneRep; private readonly SqlSugarRepository _codePortRep; + private readonly SqlSugarRepository _relaPortLane; private readonly ICommonDBService _commonDBService; public DataSyncService(ILogger logger, ISysCacheService cache, SqlSugarRepository rep, SqlSugarRepository repCtn, @@ -69,7 +70,7 @@ namespace Myshipping.Application , SqlSugarRepository bookingEDIExt, SqlSugarRepository bookinglog, SqlSugarRepository bookinglogdetail, SqlSugarRepository goodsStatus, SqlSugarRepository goodsStatusConfig, SqlSugarRepository repline, SqlSugarRepository bookingremark, SqlSugarRepository mapcarrier, - SqlSugarRepository codePortRep, SqlSugarRepository codeLaneRep, ICommonDBService commonDBService) + SqlSugarRepository codePortRep, SqlSugarRepository codeLaneRep, ICommonDBService commonDBService, SqlSugarRepository relaPortLane) { this._logger = logger; this._rep = rep; @@ -91,7 +92,8 @@ namespace Myshipping.Application this._mapcarrier = mapcarrier; this._codePortRep = codePortRep; this._codeLaneRep = codeLaneRep; - this._commonDBService=commonDBService; + this._commonDBService = commonDBService; + this._relaPortLane = relaPortLane; } @@ -1636,6 +1638,96 @@ namespace Myshipping.Application } } + + + + /// + /// 目的港上传同步 + /// + /// + [HttpPost("/DataSync/SyncDisport"), ApiUser(ApiCode = "SyncDisport")] + [SqlSugarUnitOfWork] + public async Task SyncDisport(DisportSyncDto dto) + { + var idList = dto.DataList.Select(x => x.Code).ToList(); + var portList = _codePortRep.Where(x => idList.Contains(x.Code)).ToList(); + var relaList = _relaPortLane.Where(x => idList.Contains(x.PortCode) && (x.CarrierCode == null || x.CarrierCode == "") && (x.Module == null || x.Module == "")).ToList(); + var laneList = _codeLaneRep.ToList(); + if (dto.Type == "save") + { + foreach (var dtoPort in dto.DataList) + { + var port = portList.FirstOrDefault(x => x.Code == dtoPort.Code); + if (port != null) + { + dtoPort.Adapt(port); + port.ModifyTime = DateTime.Now; + port.ModifyUser = UserManager.Name; + await _codePortRep.UpdateAsync(port); + } + else + { + port = new CodePort(); + port.GID = Guid.NewGuid().ToString(); + dtoPort.Adapt(port); + port.CreateTime = DateTime.Now; + port.CreateUser = UserManager.Name; + await _codePortRep.InsertAsync(port); + } + + //处理港口、航线对应关系 + var lane = laneList.FirstOrDefault(x => x.CnName == port.ShippingRoute); + if (lane != null) + { + var rela = relaList.FirstOrDefault(x => x.PortCode == port.Code && x.LaneCode == lane.Code); + if (rela == null) //没有存在的映射关系,直接添加 + { + rela = new RelaPortCarrierLane(); + rela.GID = Guid.NewGuid().ToString(); + rela.PortCode = port.Code; + rela.LaneCode = lane.Code; + rela.CarrierCode = ""; + rela.Module = ""; + rela.CreateTime = DateTime.Now; + rela.CreateUser = UserManager.Name; + await _relaPortLane.InsertAsync(rela); + } + else if (rela.LaneCode != lane.Code) //存在映射关系,但不是上传数据中的航线 + { + rela.LaneCode = lane.Code; //修改航线映射 + rela.ModifyTime = DateTime.Now; + rela.ModifyUser = UserManager.Name; + await _relaPortLane.UpdateAsync(rela); + } + } + } + + await _commonDBService.GetAllPort(false); //刷新缓存 + await _commonDBService.GetAllRelaPortCarrierLane(false); //刷新缓存 + } + else if (dto.Type == "del") + { + //删除港口数据 + foreach (var port in portList) + { + await _codePortRep.DeleteAsync(port); + } + + //删除映射关系 + foreach (var rela in relaList) + { + await _relaPortLane.DeleteAsync(rela); + } + + await _commonDBService.GetAllPort(false); //刷新缓存 + await _commonDBService.GetAllRelaPortCarrierLane(false); //刷新缓存 + } + else + { + throw Oops.Bah($"同步类型无效:{dto.Type}"); + } + + } #endregion #region 下载数据