From 74e32c36b9f4a95e20c483bb81cae0a567635b8a Mon Sep 17 00:00:00 2001
From: wet <1034391973@qq.com>
Date: Mon, 3 Apr 2023 11:27:25 +0800
Subject: [PATCH] 1
---
.../Service/DataSync/DataSyncService.cs | 161 +++++++++++++++++-
1 file changed, 160 insertions(+), 1 deletion(-)
diff --git a/Myshipping.Application/Service/DataSync/DataSyncService.cs b/Myshipping.Application/Service/DataSync/DataSyncService.cs
index 4f12fedc..b1a19900 100644
--- a/Myshipping.Application/Service/DataSync/DataSyncService.cs
+++ b/Myshipping.Application/Service/DataSync/DataSyncService.cs
@@ -128,6 +128,52 @@ namespace Myshipping.Application
}
+
+ ///
+ /// 批量同步客户无返回值
+ ///
+ /// 参数
+ ///
+ [HttpPost("/DataSync/SyncCustomerList"), ApiUser(ApiCode = "SyncCustomerList")]
+ public async Task SyncCustomer(List model)
+ {
+ foreach (var item in model)
+ {
+
+
+ if (string.IsNullOrWhiteSpace(item.ShortName))
+ {
+ throw Oops.Bah("简称未录入");
+ }
+ var m = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.ShortName == item.ShortName && x.IsDeleted == false).FirstAsync();
+ var entity = model.Adapt();
+ if (m == null)
+ {
+ await _djycustomer.InsertAsync(entity);
+ foreach (var it in item.ContactList)
+ {
+ var contact = it.Adapt();
+ contact.CustomerId = entity.Id;
+ await _djycustomercontact.InsertAsync(contact);
+ }
+ }
+ else
+ {
+ entity.Id = m.Id;
+ await _djycustomer.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
+ await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
+ foreach (var it in item.ContactList)
+ {
+ var contact = it.Adapt();
+ contact.CustomerId = entity.Id;
+ await _djycustomercontact.InsertAsync(contact);
+ }
+ }
+ }
+
+ }
+
+
///
/// 同步船期
///
@@ -148,7 +194,6 @@ namespace Myshipping.Application
entity.Vessel = model.Vessel.ToUpper().Trim();
if (!string.IsNullOrEmpty(model.CARRIERID))
{
-
entity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == entity.CARRIERID).Select(x => x.CnName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(model.CreatedUserName))
@@ -240,6 +285,120 @@ namespace Myshipping.Application
return entity.Id;
}
+
+ ///
+ /// 批量同步船期无返回值
+ ///
+ ///
+ ///
+ [HttpPost("/DataSync/SyncVesselDateList"), ApiUser(ApiCode = "SyncVesselDateList")]
+ [SqlSugarUnitOfWork]
+ public async Task SyncVesselDateList(List model)
+ {
+ foreach (var item in model)
+ {
+
+ if (string.IsNullOrWhiteSpace(item.BSNO))
+ {
+ throw Oops.Bah("BSNO未录入");
+ }
+ var userlist = _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false).ToListAsync();
+ var m = await _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO).FirstAsync();
+ var entity = model.Adapt();
+ entity.Vessel = item.Vessel.ToUpper().Trim();
+ if (!string.IsNullOrEmpty(item.CARRIERID))
+ {
+ entity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == entity.CARRIERID).Select(x => x.CnName).FirstOrDefault();
+ }
+ if (!string.IsNullOrEmpty(item.CreatedUserName))
+ {
+
+ entity.CreatedUserId = userlist.Result.Where(x => x.Name == item.CreatedUserName).Select(x => x.Id).FirstOrDefault();
+ }
+ if (m == null)
+ {
+ await _vesselinfo.InsertAsync(entity);
+ }
+ else
+ {
+ entity.Id = m.Id;
+ await _vesselinfo.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
+ }
+ ////根据船公司船名航次更新船期信息
+ if (!string.IsNullOrEmpty(item.CARRIER) && !string.IsNullOrEmpty(item.Vessel) && (!string.IsNullOrEmpty(item.Voyno) || !string.IsNullOrWhiteSpace(item.VoynoInside)))
+ {
+
+ var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel && x.IsDeleted == false)
+ .WhereIF(!string.IsNullOrEmpty(item.Voyno), x => x.VOYNO == item.Voyno)
+ .WhereIF(!string.IsNullOrEmpty(item.VoynoInside), x => x.VOYNOINNER == item.VoynoInside).ToListAsync();
+
+ _logger.LogInformation($"同步船期_查询到{UserManager.TENANT_NAME}需要更新{order.Count()}条订舱数据");
+ foreach (var it in order)
+ {
+ //更新订舱船期
+ if (it.ETD != item.ETD)
+ {
+ it.ETD = item.ETD;
+ }
+ if (it.ATD != item.ATD)
+ {
+ it.ATD = item.ATD;
+ }
+ await _rep.AsUpdateable(it).IgnoreColumns(it => new
+ {
+ it.ParentId,
+ it.TenantId,
+ it.CreatedTime,
+ it.CreatedUserId,
+ it.CreatedUserName,
+ it.UpdatedTime,
+ it.UpdatedUserId,
+ it.UpdatedUserName,
+ it.TenantName,
+ it.IsDeleted,
+ it.BOOKINGNO
+ }).ExecuteCommandAsync();
+ //记录日志
+
+
+
+ ////添加booking日志
+ var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
+ {
+ Type = "Edit",
+ BookingId = it.Id,
+ TenantId = Convert.ToInt64(UserManager.TENANT_ID),
+ CreatedTime = DateTime.Now,
+ CreatedUserId = UserManager.UserId,
+ CreatedUserName = UserManager.Name
+ });
+ if (it.ETD != item.ETD)
+ {
+ await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
+ {
+ PId = bid,
+ Field = "ETD",
+ OldValue = it.ETD != null ? it.ETD.ToSqlValue() : null,
+ NewValue = item.ETD != null ? item.ETD.ToSqlValue() : null,
+ });
+ }
+ if (it.ATD != item.ATD)
+ {
+ await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
+ {
+ PId = bid,
+ Field = "ATD",
+ OldValue = it.ATD != null ? it.ATD.ToSqlValue() : null,
+ NewValue = item.ATD != null ? item.ATD.ToSqlValue() : null,
+ });
+ }
+
+ }
+
+ }
+ }
+ }
+
#region
/////
///// 同步订舱