航线同步接口

optimize
wanghaomei 2 years ago
parent 2604ba3866
commit 8423f31ae7

@ -31,6 +31,7 @@ using System.Net.Http;
using Myshipping.Core.Service; using Myshipping.Core.Service;
using System.Reflection.Emit; using System.Reflection.Emit;
using Myshipping.Application.Service.DataSync.Dto; using Myshipping.Application.Service.DataSync.Dto;
using Newtonsoft.Json.Linq;
namespace Myshipping.Application namespace Myshipping.Application
{ {
@ -58,13 +59,16 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<BookingGoodsStatusConfig> _goodsStatusConfig; private readonly SqlSugarRepository<BookingGoodsStatusConfig> _goodsStatusConfig;
private readonly SqlSugarRepository<DjyTenantLine> _repline; private readonly SqlSugarRepository<DjyTenantLine> _repline;
private readonly SqlSugarRepository<MappingCarrier> _mapcarrier; private readonly SqlSugarRepository<MappingCarrier> _mapcarrier;
private readonly SqlSugarRepository<CodeLane> _codeLaneRep;
private readonly SqlSugarRepository<CodePort> _codePortRep;
public DataSyncService(ILogger<DataSyncService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, public DataSyncService(ILogger<DataSyncService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
SqlSugarRepository<SysUser> repUser, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<DjyCustomer> djycustomer, SqlSugarRepository<SysUser> repUser, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<DjyCustomer> djycustomer,
SqlSugarRepository<DjyCustomerContact> djycustomercontact, SqlSugarRepository<DjyVesselInfo> vesselinfo, SqlSugarRepository<BookingCtnDetail> ctndetailrep SqlSugarRepository<DjyCustomerContact> djycustomercontact, SqlSugarRepository<DjyVesselInfo> vesselinfo, SqlSugarRepository<BookingCtnDetail> ctndetailrep
, SqlSugarRepository<BookingEDIExt> bookingEDIExt, SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, , SqlSugarRepository<BookingEDIExt> bookingEDIExt, SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail,
SqlSugarRepository<BookingGoodsStatus> goodsStatus, SqlSugarRepository<BookingGoodsStatusConfig> goodsStatusConfig, SqlSugarRepository<DjyTenantLine> repline, SqlSugarRepository<BookingGoodsStatus> goodsStatus, SqlSugarRepository<BookingGoodsStatusConfig> goodsStatusConfig, SqlSugarRepository<DjyTenantLine> repline,
SqlSugarRepository<BookingRemark> bookingremark, SqlSugarRepository<MappingCarrier> mapcarrier) SqlSugarRepository<BookingRemark> bookingremark, SqlSugarRepository<MappingCarrier> mapcarrier,
SqlSugarRepository<CodePort> codePortRep, SqlSugarRepository<CodeLane> codeLaneRep)
{ {
this._logger = logger; this._logger = logger;
this._rep = rep; this._rep = rep;
@ -84,6 +88,8 @@ namespace Myshipping.Application
this._goodsStatusConfig = goodsStatusConfig; this._goodsStatusConfig = goodsStatusConfig;
this._repline = repline; this._repline = repline;
this._mapcarrier = mapcarrier; this._mapcarrier = mapcarrier;
this._codePortRep = codePortRep;
this._codeLaneRep = codeLaneRep;
} }
@ -431,7 +437,7 @@ namespace Myshipping.Application
} }
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO && x.IsDeleted == false).FirstAsync(); var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO && x.IsDeleted == false).FirstAsync();
if (order == null) if (order == null)
{ {
@ -497,7 +503,7 @@ namespace Myshipping.Application
} }
if (!string.IsNullOrEmpty(entity.YARD)) if (!string.IsNullOrEmpty(entity.YARD))
{ {
entity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.YARD).Select(x => x.Code).FirstOrDefault(); entity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.YARD).Select(x => x.Code).FirstOrDefault();
} }
if (!string.IsNullOrEmpty(entity.CARRIER)) if (!string.IsNullOrEmpty(entity.CARRIER))
{ {
@ -509,7 +515,7 @@ namespace Myshipping.Application
entity.CARRIERID = mapcarrier.Where(x => x.MapName == entity.CARRIER).Select(x => x.Code).FirstOrDefault(); entity.CARRIERID = mapcarrier.Where(x => x.MapName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
} }
} }
if (!string.IsNullOrEmpty(entity.LineName)) if (!string.IsNullOrEmpty(entity.LineName))
{ {
@ -526,9 +532,9 @@ namespace Myshipping.Application
}); });
} }
} }
entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString(); entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
entity.CreatedUserId = user.Id; entity.CreatedUserId = user.Id;
entity.CreatedUserName = user.Name.ToString(); entity.CreatedUserName = user.Name.ToString();
@ -593,7 +599,7 @@ namespace Myshipping.Application
foreach (var item in model.childrens) foreach (var item in model.childrens)
{ {
if (string.IsNullOrWhiteSpace(item.HBLNO)) if (string.IsNullOrWhiteSpace(item.HBLNO))
{ {
@ -674,7 +680,7 @@ namespace Myshipping.Application
fdentity.CARRIERID = mapcarrier.Where(x => x.MapName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault(); fdentity.CARRIERID = mapcarrier.Where(x => x.MapName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
} }
} }
if (!string.IsNullOrEmpty(item.LineName)) if (!string.IsNullOrEmpty(item.LineName))
{ {
@ -691,7 +697,7 @@ namespace Myshipping.Application
}); });
} }
} }
fdentity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString(); fdentity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
fdentity.MBLNO = entity.MBLNO; fdentity.MBLNO = entity.MBLNO;
fdentity.CreatedUserId = user.Id; fdentity.CreatedUserId = user.Id;
@ -956,7 +962,7 @@ namespace Myshipping.Application
}); });
} }
} }
await _rep.AsUpdateable(entity).IgnoreColumns(it => new await _rep.AsUpdateable(entity).IgnoreColumns(it => new
{ {
it.BOOKINGNO, it.BOOKINGNO,
@ -1275,7 +1281,7 @@ namespace Myshipping.Application
}); });
} }
} }
await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new
{ {
it.BOOKINGNO, it.BOOKINGNO,
@ -1314,7 +1320,7 @@ namespace Myshipping.Application
if (item.BookingEDIExt != null) if (item.BookingEDIExt != null)
{ {
//检索EDI扩展 //检索EDI扩展
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdmain.Id).FirstAsync(); var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdmain.Id).FirstAsync();
if (ediExtEntity == null) if (ediExtEntity == null)
{ {
@ -1429,7 +1435,7 @@ namespace Myshipping.Application
if (item.BookingEDIExt != null) if (item.BookingEDIExt != null)
{ {
//检索EDI扩展 //检索EDI扩展
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdentity.Id).FirstAsync(); var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdentity.Id).FirstAsync();
if (ediExtEntity == null) if (ediExtEntity == null)
{ {
@ -1572,6 +1578,59 @@ namespace Myshipping.Application
} }
/// <summary>
/// 航线上传同步
/// </summary>
/// <returns></returns>
[HttpPost("/DataSync/SyncLine"), ApiUser(ApiCode = "SyncLine")]
[SqlSugarUnitOfWork]
public async Task SyncLine(LineSyncDto dto)
{
var idList = dto.DataList.Select(x => x.Code).ToList();
var laneList = _codeLaneRep.Where(x => idList.Contains(x.Code)).ToList();
if (dto.Type == "save")
{
foreach (var dtoLine in dto.DataList)
{
var lane = laneList.FirstOrDefault(x => x.Code == dtoLine.Code);
if (lane != null)
{
lane.EnName = dtoLine.Name;
lane.CnName = dtoLine.Name;
lane.ModifyTime = DateTime.Now;
lane.ModifyUser = UserManager.Name;
await _codeLaneRep.UpdateAsync(lane);
}
else
{
lane = new CodeLane();
lane.GID = Guid.NewGuid().ToString();
lane.Code = dtoLine.Code;
lane.EnName = dtoLine.Name;
lane.CnName = dtoLine.Name;
lane.LaneType = "SEA";
lane.CreateTime = DateTime.Now;
lane.CreateUser = UserManager.Name;
await _codeLaneRep.InsertAsync(lane);
}
}
}
else if (dto.Type == "del")
{
foreach (var lane in laneList)
{
await _codeLaneRep.DeleteAsync(lane);
}
}
else
{
throw Oops.Bah($"同步类型无效:{dto.Type}");
}
}
#endregion #endregion
#region 下载数据 #region 下载数据

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application.Service.DataSync.Dto
{
public class LineSyncDto
{
/// <summary>
/// 类型保存save、删除del
/// </summary>
public string Type { get; set; }
/// <summary>
/// 数据列表
/// </summary>
public List<LineSyncModel> DataList { get; set; }
}
public class LineSyncModel
{
/// <summary>
/// 代码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
}
}
Loading…
Cancel
Save