|
|
using Myshipping.Core;
|
|
|
using Furion.DependencyInjection;
|
|
|
using Furion.DynamicApiController;
|
|
|
using Mapster;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using SqlSugar;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using Myshipping.Application.Entity;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Furion;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Furion.DataEncryption;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Security.Claims;
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
using Furion.FriendlyException;
|
|
|
using Furion.Logging;
|
|
|
using System;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using System.Reflection;
|
|
|
using System.ComponentModel;
|
|
|
using Myshipping.Application.ConfigOption;
|
|
|
using System.IO;
|
|
|
using Yitter.IdGenerator;
|
|
|
using Myshipping.Core.Entity;
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
using System.Net.Http;
|
|
|
using Myshipping.Core.Service;
|
|
|
using System.Reflection.Emit;
|
|
|
using Myshipping.Application.Service.DataSync.Dto;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using Myshipping.Application.Service.BookingOrder.Dto;
|
|
|
using Myshipping.Application.Enum;
|
|
|
using Myshipping.Core.Helper;
|
|
|
using Furion.TaskScheduler;
|
|
|
using System.Linq.Expressions;
|
|
|
using Myshipping.Core.Service.Dict.Dto;
|
|
|
using Furion.JsonSerialization;
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
using Furion.EventBus;
|
|
|
using Myshipping.Core.Const;
|
|
|
using NPOI.Util;
|
|
|
using Org.BouncyCastle.Utilities;
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 数据同步服务
|
|
|
/// </summary>
|
|
|
[ApiDescriptionSettings("Application", Name = "DataSync", Order = 1), AllowAnonymous]
|
|
|
public class DataSyncService : IDynamicApiController, ITransient
|
|
|
{
|
|
|
private readonly ILogger<DataSyncService> _logger;
|
|
|
private readonly ISysCacheService _cache;
|
|
|
private readonly SqlSugarRepository<BookingOrder> _rep;
|
|
|
private readonly SqlSugarRepository<BookingCtn> _repCtn;
|
|
|
private readonly SqlSugarRepository<BookingCtnDetail> _ctndetailrep;
|
|
|
private readonly SqlSugarRepository<SysUser> _repUser;
|
|
|
private readonly SqlSugarRepository<SysTenant> _repTenant;
|
|
|
private readonly SqlSugarRepository<DjyCustomer> _djycustomer;
|
|
|
private readonly SqlSugarRepository<DjyCustomerContact> _djycustomercontact;
|
|
|
private readonly SqlSugarRepository<DjyVesselInfo> _vesselinfo;
|
|
|
private readonly SqlSugarRepository<BookingEDIExt> _bookingEDIExt;
|
|
|
private readonly SqlSugarRepository<BookingLog> _bookinglog;
|
|
|
private readonly SqlSugarRepository<BookingLogDetail> _bookinglogdetail;
|
|
|
private readonly SqlSugarRepository<BookingRemark> _bookingremark;
|
|
|
private readonly SqlSugarRepository<BookingGoodsStatus> _goodsStatus;
|
|
|
private readonly SqlSugarRepository<BookingGoodsStatusConfig> _goodsStatusConfig;
|
|
|
private readonly SqlSugarRepository<DjyTenantLine> _repline;
|
|
|
private readonly SqlSugarRepository<MappingCarrier> _mapcarrier;
|
|
|
private readonly SqlSugarRepository<CodeLane> _codeLaneRep;
|
|
|
private readonly SqlSugarRepository<CodePort> _codePortRep;
|
|
|
private readonly SqlSugarRepository<RelaPortCarrierLane> _relaPortLane;
|
|
|
private readonly ICommonDBService _commonDBService;
|
|
|
private readonly SqlSugarRepository<CodeForwarder> _codeForwarder;
|
|
|
private readonly SqlSugarRepository<BookingFile> _bookingfile;
|
|
|
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _accountconfig;
|
|
|
private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog;
|
|
|
private readonly SqlSugarRepository<BookingStatusLogDetail> _statuslogdetail;
|
|
|
private readonly SqlSugarRepository<BookingStatus> _repBookingStatus;
|
|
|
private readonly IBookingOrderService _bookingorderservice;
|
|
|
private readonly SqlSugarRepository<BookingExtendState> _bookingextstate;
|
|
|
|
|
|
private readonly IBookingValueAddedService _bookingValueAddedService;
|
|
|
private readonly IHubContext<ChatHub, IChatClient> _chatHubContext;
|
|
|
private readonly IEventPublisher _publisher;
|
|
|
private readonly SqlSugarRepository<DjyTenantParamValue> _tenantParamValue;
|
|
|
|
|
|
public DataSyncService(ILogger<DataSyncService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
|
|
|
SqlSugarRepository<SysUser> repUser, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<DjyCustomer> djycustomer,
|
|
|
SqlSugarRepository<BookingStatusLog> statuslog, SqlSugarRepository<BookingStatusLogDetail> statuslogdetail, SqlSugarRepository<BookingStatus> repBookingStatus,
|
|
|
SqlSugarRepository<DjyCustomerContact> djycustomercontact, SqlSugarRepository<DjyVesselInfo> vesselinfo, SqlSugarRepository<BookingCtnDetail> ctndetailrep
|
|
|
, SqlSugarRepository<BookingEDIExt> bookingEDIExt, SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail,
|
|
|
SqlSugarRepository<BookingGoodsStatus> goodsStatus, SqlSugarRepository<BookingGoodsStatusConfig> goodsStatusConfig, SqlSugarRepository<DjyTenantLine> repline,
|
|
|
SqlSugarRepository<BookingRemark> bookingremark, SqlSugarRepository<MappingCarrier> mapcarrier, SqlSugarRepository<CodeForwarder> codeForwarder, SqlSugarRepository<BookingExtendState> bookingextstate,
|
|
|
SqlSugarRepository<CodePort> codePortRep, SqlSugarRepository<CodeLane> codeLaneRep, ICommonDBService commonDBService, SqlSugarRepository<RelaPortCarrierLane> relaPortLane,
|
|
|
SqlSugarRepository<DjyWebsiteAccountConfig> accountconfig, SqlSugarRepository<BookingFile> bookingfile, IBookingOrderService bookingorderservice,
|
|
|
IBookingValueAddedService bookingValueAddedService,
|
|
|
IHubContext<ChatHub, IChatClient> chatHubContext,
|
|
|
IEventPublisher publisher,
|
|
|
SqlSugarRepository<DjyTenantParamValue> tenantParamValue)
|
|
|
{
|
|
|
this._logger = logger;
|
|
|
this._rep = rep;
|
|
|
this._repCtn = repCtn;
|
|
|
this._cache = cache;
|
|
|
this._repUser = repUser;
|
|
|
this._repTenant = repTenant;
|
|
|
this._djycustomer = djycustomer;
|
|
|
this._djycustomercontact = djycustomercontact;
|
|
|
this._vesselinfo = vesselinfo;
|
|
|
this._ctndetailrep = ctndetailrep;
|
|
|
this._bookingEDIExt = bookingEDIExt;
|
|
|
this._bookinglog = bookinglog;
|
|
|
this._bookinglogdetail = bookinglogdetail;
|
|
|
this._bookingremark = bookingremark;
|
|
|
this._goodsStatus = goodsStatus;
|
|
|
this._goodsStatusConfig = goodsStatusConfig;
|
|
|
this._repline = repline;
|
|
|
this._mapcarrier = mapcarrier;
|
|
|
this._codePortRep = codePortRep;
|
|
|
this._codeLaneRep = codeLaneRep;
|
|
|
this._commonDBService = commonDBService;
|
|
|
this._relaPortLane = relaPortLane;
|
|
|
this._codeForwarder = codeForwarder;
|
|
|
this._accountconfig = accountconfig;
|
|
|
this._bookingfile = bookingfile;
|
|
|
this._bookingorderservice = bookingorderservice;
|
|
|
this._repStatuslog = statuslog;
|
|
|
this._statuslogdetail = statuslogdetail;
|
|
|
this._repBookingStatus = repBookingStatus;
|
|
|
this._bookingextstate = bookingextstate;
|
|
|
this._bookingValueAddedService = bookingValueAddedService;
|
|
|
this._chatHubContext = chatHubContext;
|
|
|
this._publisher = publisher;
|
|
|
this._tenantParamValue = tenantParamValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 上传数据
|
|
|
/// <summary>
|
|
|
/// 同步客户
|
|
|
/// </summary>
|
|
|
/// <param name="model">参数</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/SyncCustomer"), ApiUser(ApiCode = "SyncCustomer")]
|
|
|
public async Task<long> SyncCustomer(DjyCustomerSyncDto model)
|
|
|
{
|
|
|
var userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
if (string.IsNullOrWhiteSpace(model.ShortName))
|
|
|
{
|
|
|
throw Oops.Bah("简称未录入");
|
|
|
}
|
|
|
var m = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.ShortName == model.ShortName && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).FirstAsync();
|
|
|
var entity = model.Adapt<DjyCustomer>();
|
|
|
if (!string.IsNullOrEmpty(entity.SALE))
|
|
|
{
|
|
|
entity.SALEID = userlist.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.OP))
|
|
|
{
|
|
|
entity.OPID = userlist.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.DOC))
|
|
|
{
|
|
|
entity.DOCID = userlist.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
entity.CUSTSERVICEID = userlist.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (entity.Level == "R3" && !string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("等级为R3,客服为空");
|
|
|
|
|
|
}
|
|
|
if ((entity.Level == "R1" || entity.Level == "R2") && string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("等级为R1/R2,客服必填");
|
|
|
}
|
|
|
entity.PropString = entity.PropString.Replace("forwarder", "booking_agent");
|
|
|
if (m == null)
|
|
|
{
|
|
|
entity.TenantId = UserManager.TENANT_ID;
|
|
|
await _djycustomer.InsertAsync(entity);
|
|
|
foreach (var item in model.ContactList)
|
|
|
{
|
|
|
var contact = item.Adapt<DjyCustomerContact>();
|
|
|
contact.CustomerId = entity.Id;
|
|
|
contact.TenantId = UserManager.TENANT_ID;
|
|
|
await _djycustomercontact.InsertAsync(contact);
|
|
|
}
|
|
|
if (entity.PropString.Contains("shipagency"))
|
|
|
{
|
|
|
var ship = await _codeForwarder.AsQueryable().Where(x => x.Code == entity.CodeName).FirstAsync();
|
|
|
if (ship == null)
|
|
|
{
|
|
|
await _codeForwarder.InsertAsync(new CodeForwarder
|
|
|
{
|
|
|
GID = Guid.NewGuid().ToString(),
|
|
|
CreateTime = DateTime.Now,
|
|
|
CreateUser = UserManager.DjyUserId,
|
|
|
Code = entity.CodeName,
|
|
|
Name = entity.ShortName
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ship.Code = entity.CodeName;
|
|
|
ship.Name = entity.ShortName;
|
|
|
ship.ModifyTime = DateTime.Now;
|
|
|
ship.ModifyUser = UserManager.DjyUserId;
|
|
|
await _codeForwarder.UpdateAsync(ship);
|
|
|
}
|
|
|
await _commonDBService.GetAllForwarder(false);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
entity.Id = m.Id;
|
|
|
|
|
|
|
|
|
|
|
|
await _djycustomer.AsUpdateable(entity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.TenantId,
|
|
|
it.TIDANINFO
|
|
|
}).ExecuteCommandAsync();
|
|
|
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
|
|
|
if (entity.PropString.Contains("shipagency"))
|
|
|
{
|
|
|
|
|
|
var ship = await _codeForwarder.AsQueryable().Where(x => x.Code == entity.CodeName).FirstAsync();
|
|
|
if (ship == null)
|
|
|
{
|
|
|
|
|
|
await _codeForwarder.InsertAsync(new CodeForwarder
|
|
|
{
|
|
|
GID = Guid.NewGuid().ToString(),
|
|
|
CreateTime = DateTime.Now,
|
|
|
CreateUser = UserManager.DjyUserId,
|
|
|
Code = entity.CodeName,
|
|
|
Name = entity.ShortName
|
|
|
});
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
ship.Code = entity.CodeName;
|
|
|
ship.Name = entity.ShortName;
|
|
|
ship.ModifyTime = DateTime.Now;
|
|
|
ship.ModifyUser = UserManager.DjyUserId;
|
|
|
await _codeForwarder.UpdateAsync(ship);
|
|
|
|
|
|
}
|
|
|
|
|
|
await _commonDBService.GetAllForwarder(false);
|
|
|
|
|
|
}
|
|
|
foreach (var item in model.ContactList)
|
|
|
{
|
|
|
var contact = item.Adapt<DjyCustomerContact>();
|
|
|
contact.CustomerId = entity.Id;
|
|
|
contact.TenantId = UserManager.TENANT_ID;
|
|
|
await _djycustomercontact.InsertAsync(contact);
|
|
|
}
|
|
|
}
|
|
|
return entity.Id;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量同步客户无返回值
|
|
|
/// </summary>
|
|
|
/// <param name="model">参数</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/SyncCustomerList"), ApiUser(ApiCode = "SyncCustomerList")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task SyncCustomer(List<DjyCustomerSyncDto> model)
|
|
|
{
|
|
|
foreach (DjyCustomerSyncDto item in model)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(item.ShortName))
|
|
|
{
|
|
|
throw Oops.Bah("简称未录入");
|
|
|
}
|
|
|
DjyCustomer customer = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.ShortName == item.ShortName).FirstAsync();
|
|
|
var shiplist = await _codeForwarder.AsQueryable().ToListAsync();
|
|
|
|
|
|
if (customer == null)
|
|
|
{
|
|
|
var entity = item.Adapt<DjyCustomer>();
|
|
|
if (!string.IsNullOrEmpty(entity.SALE))
|
|
|
{
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == entity.SALE).FirstAsync();
|
|
|
entity.SALEID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.OP))
|
|
|
{
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == entity.OP).FirstAsync();
|
|
|
entity.OPID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.DOC))
|
|
|
{
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == entity.DOC).FirstAsync();
|
|
|
entity.DOCID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == entity.CUSTSERVICE).FirstAsync();
|
|
|
entity.CUSTSERVICEID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
if (entity.Level == "R3" && !string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
throw Oops.Bah("等级为R3,客服为空");
|
|
|
}
|
|
|
if ((entity.Level == "R1" || entity.Level == "R2") && string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
throw Oops.Bah("等级为R1/R2,客服必填");
|
|
|
}
|
|
|
entity.PropString = entity.PropString.Replace("forwarder", "booking_agent");
|
|
|
entity.TenantId = UserManager.TENANT_ID;
|
|
|
await _djycustomer.InsertAsync(entity);
|
|
|
foreach (var it in item.ContactList)
|
|
|
{
|
|
|
var contact = it.Adapt<DjyCustomerContact>();
|
|
|
contact.CustomerId = entity.Id;
|
|
|
contact.TenantId = UserManager.TENANT_ID;
|
|
|
await _djycustomercontact.InsertAsync(contact);
|
|
|
}
|
|
|
if (entity.PropString.Contains("shipagency"))
|
|
|
{
|
|
|
var ship = shiplist.Where(x => x.Code == entity.CodeName).FirstOrDefault();
|
|
|
if (ship == null)
|
|
|
{
|
|
|
//船代
|
|
|
await _codeForwarder.InsertAsync(new CodeForwarder
|
|
|
{
|
|
|
GID = Guid.NewGuid().ToString(),
|
|
|
CreateTime = DateTime.Now,
|
|
|
CreateUser = UserManager.DjyUserId,
|
|
|
Code = entity.CodeName,
|
|
|
Name = entity.ShortName
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ship.Code = entity.CodeName;
|
|
|
ship.Name = entity.ShortName;
|
|
|
ship.ModifyTime = DateTime.Now;
|
|
|
ship.ModifyUser = UserManager.DjyUserId;
|
|
|
await _codeForwarder.UpdateAsync(ship);
|
|
|
}
|
|
|
await _commonDBService.GetAllForwarder(false);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DjyCustomer updateModel = new();
|
|
|
updateModel.Id = customer.Id;
|
|
|
_djycustomer.Context.Tracking(updateModel);
|
|
|
|
|
|
// 字段分类1:取值和东胜相同的字段
|
|
|
updateModel.CodeName = item.CodeName;
|
|
|
updateModel.FullName = item.FullName;
|
|
|
updateModel.Chief = item.Chief;
|
|
|
updateModel.Tel = item.Tel;
|
|
|
updateModel.Email = item.Email;
|
|
|
updateModel.QQ = item.QQ;
|
|
|
updateModel.WebUrl = item.WebUrl;
|
|
|
updateModel.Province = item.Province;
|
|
|
updateModel.City = item.City;
|
|
|
updateModel.Addr = item.Addr;
|
|
|
//updateModel.FullNameEN = item.FullNameEN;
|
|
|
//updateModel.AddrEN = item.AddrEN;
|
|
|
updateModel.InvTitle = item.InvTitle;
|
|
|
updateModel.TaxNO = item.TaxNO;
|
|
|
updateModel.InvAddrTel = item.InvAddrTel;
|
|
|
updateModel.RMBBank = item.RMBBank;
|
|
|
updateModel.RmbAccount = item.RmbAccount;
|
|
|
updateModel.USDBank = item.USDBank;
|
|
|
updateModel.USDAccount = item.USDAccount;
|
|
|
|
|
|
// 字段分类2:特殊处理
|
|
|
if (!string.IsNullOrEmpty(item.PropString) && item.PropString != customer.PropString)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(customer.PropString))
|
|
|
{
|
|
|
updateModel.PropString = item.PropString;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// 原有的客户属性code列表
|
|
|
List<string> oldProps = customer.PropString.Split("][").Select(o => o.Replace("[", "").Replace("]", "")).ToList();
|
|
|
|
|
|
// 东胜客户属性在大简云中存在的code列表
|
|
|
List<DictDataDto> dictDataDtos = await _cache.GetAllDictData();
|
|
|
List<string> dsCustPropCodeList = dictDataDtos.Where(d => d.TypeCode == "djy_cust_prop_map_ds")?.Select(v => v.Code)?.ToList();
|
|
|
if (dsCustPropCodeList != null && dsCustPropCodeList.Count > 0)
|
|
|
{
|
|
|
// 新的客户属性code列表
|
|
|
List<string> newProps = new();
|
|
|
|
|
|
// 判断:如果原有的客户属性code列表中,存在东胜没有的,则保留
|
|
|
oldProps.ForEach(o =>
|
|
|
{
|
|
|
if (!dsCustPropCodeList.Contains(o))
|
|
|
{
|
|
|
newProps.Add(o);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 添加上东胜传过来的客户属性code列表
|
|
|
List<string> dsProps = item.PropString.Split("][").Select(o => o.Replace("[", "").Replace("]", "")).ToList();
|
|
|
newProps.AddRange(dsProps);
|
|
|
|
|
|
// 去重
|
|
|
newProps = newProps.Distinct().ToList();
|
|
|
|
|
|
// 赋值
|
|
|
string newPropsStr = "[" + string.Join("][", newProps) + "]";
|
|
|
updateModel.PropString = newPropsStr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah("未检索到【djy_cust_prop_map_ds】字典信息");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 字段分类3:东胜传过来的值不为空则更新,否则保持不变
|
|
|
if (!string.IsNullOrEmpty(item.SALE))
|
|
|
{
|
|
|
updateModel.SALE = item.SALE;
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == item.SALE).FirstAsync();
|
|
|
updateModel.SALEID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(item.OP))
|
|
|
{
|
|
|
updateModel.OP = item.OP;
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == item.OP).FirstAsync();
|
|
|
updateModel.OPID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(item.DOC))
|
|
|
{
|
|
|
updateModel.DOC = item.DOC;
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == item.DOC).FirstAsync();
|
|
|
updateModel.DOCID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(item.CUSTSERVICE))
|
|
|
{
|
|
|
updateModel.CUSTSERVICE = item.CUSTSERVICE;
|
|
|
var sysUser = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == item.CUSTSERVICE).FirstAsync();
|
|
|
updateModel.CUSTSERVICEID = sysUser?.Id.ToString() ?? "";
|
|
|
}
|
|
|
|
|
|
// 执行更新
|
|
|
await _djycustomer.Context.Updateable(updateModel).ExecuteCommandAsync();
|
|
|
|
|
|
if (item.PropString.Contains("shipagency"))
|
|
|
{
|
|
|
//船代
|
|
|
var ship = shiplist.Where(x => x.Code == item.CodeName).FirstOrDefault();
|
|
|
if (ship == null)
|
|
|
{
|
|
|
await _codeForwarder.InsertAsync(new CodeForwarder
|
|
|
{
|
|
|
GID = Guid.NewGuid().ToString(),
|
|
|
CreateTime = DateTime.Now,
|
|
|
CreateUser = UserManager.DjyUserId,
|
|
|
Code = item.CodeName,
|
|
|
Name = item.ShortName
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ship.Code = item.CodeName;
|
|
|
ship.Name = item.ShortName;
|
|
|
ship.ModifyTime = DateTime.Now;
|
|
|
ship.ModifyUser = UserManager.DjyUserId;
|
|
|
await _codeForwarder.UpdateAsync(ship);
|
|
|
}
|
|
|
await _commonDBService.GetAllForwarder(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量同步船期无返回值
|
|
|
/// </summary>
|
|
|
/// <param name="model"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/SyncVesselDateList"), ApiUser(ApiCode = "SyncVesselDateList")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task<dynamic> SyncVesselDateList(List<DjyVesselInfoDto> model)
|
|
|
{
|
|
|
Lazy<List<MappingCarrier>> mapcarrier = new(() => _mapcarrier.Where(x => x.Module == "HeChuan").ToList());
|
|
|
|
|
|
foreach (var item in model)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(item.BSNO))
|
|
|
{
|
|
|
_logger.LogError("SyncVesselDateList同步船期时发生异常:BSNO未录入");
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
var entity = item.Adapt<DjyVesselInfo>();
|
|
|
entity.Vessel = item.Vessel.ToUpper().Trim();
|
|
|
if (!string.IsNullOrEmpty(entity.CARRIER))
|
|
|
{
|
|
|
// 东胜6中没有CARRIERID,但是船公司属于东胜中的客户,所以从东胜推送的客户信息中查询船公司Id
|
|
|
entity.CARRIERID = _djycustomer.AsQueryable().Filter(null, true).Where(c => c.IsDeleted == false && c.TenantId == UserManager.TENANT_ID && c.ShortName == entity.CARRIER).First()?.CodeName;
|
|
|
if (string.IsNullOrEmpty(entity.CARRIERID))
|
|
|
{
|
|
|
entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == item.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(entity.CARRIERID))
|
|
|
{
|
|
|
entity.CARRIERID = mapcarrier.Value.Where(x => x.MapName == item.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(entity.CARRIERID))
|
|
|
{
|
|
|
_logger.LogError($"SyncVesselDateList同步船期时发生异常:未找到{item.CARRIER}对应code,请联系管理员!");
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.CreatedUserName))
|
|
|
{
|
|
|
var createdUserId = await _repUser.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID && x.Name == item.CreatedUserName)
|
|
|
.Select(x => x.Id)
|
|
|
.FirstAsync();
|
|
|
entity.CreatedUserId = createdUserId;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(item.Voyno))
|
|
|
{
|
|
|
entity.Voyno = entity.VoynoInside;
|
|
|
}
|
|
|
|
|
|
//没有港口的按青岛港处理
|
|
|
if (string.IsNullOrEmpty(entity.PortLoadingId))
|
|
|
{
|
|
|
entity.PortLoadingId = "CNTAO";
|
|
|
}
|
|
|
|
|
|
//根据东胜bsno获取当前数据查询不到则为新增
|
|
|
var oldByBsno = await _vesselinfo.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.BSNO == item.BSNO)
|
|
|
.FirstAsync();
|
|
|
if (oldByBsno == null)
|
|
|
{
|
|
|
//查询是否存在相同船名航次数据
|
|
|
var oldByInfo = await _vesselinfo.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false
|
|
|
&& x.CARRIERID == entity.CARRIERID && x.Vessel == entity.Vessel && x.Voyno == entity.Voyno && x.VoynoInside == entity.VoynoInside)
|
|
|
.FirstAsync();
|
|
|
|
|
|
//2023年7月27日,王书岚:航次为V.开头的不查询船期
|
|
|
if (!string.IsNullOrEmpty(entity.VoynoInside) && entity.VoynoInside.StartsWith("V."))
|
|
|
{
|
|
|
entity.Sign = true;
|
|
|
}
|
|
|
if (oldByInfo == null)
|
|
|
{
|
|
|
await _vesselinfo.InsertAsync(entity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
entity.Id = oldByInfo.Id;
|
|
|
if (oldByInfo.ETA != null)
|
|
|
{
|
|
|
entity.ETA = oldByInfo.ETA;
|
|
|
}
|
|
|
await _vesselinfo.AsUpdateable(entity).IgnoreColumns(x => x.TenantId).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//2023年7月27日,王书岚:航次为V.开头的不查询船期
|
|
|
if (!string.IsNullOrEmpty(entity.VoynoInside) && entity.VoynoInside.StartsWith("V."))
|
|
|
{
|
|
|
entity.Sign = true;
|
|
|
}
|
|
|
entity.Id = oldByBsno.Id;
|
|
|
if (oldByBsno.ETA != null)
|
|
|
{
|
|
|
entity.ETA = oldByBsno.ETA;
|
|
|
}
|
|
|
await _vesselinfo.AsUpdateable(entity).IgnoreColumns(x => x.TenantId).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
|
// 根据旧的船期数据,查找订舱数据,批量更新为新的海关航次
|
|
|
// 3.25 12:16 前端保存台账时,如果航次里面有1NC或者1MA,会去掉;所以这里进行查询时,也去掉,保持一致,这样才能查询到
|
|
|
string voyno = null;
|
|
|
if (!string.IsNullOrEmpty(oldByBsno.Voyno))
|
|
|
{
|
|
|
voyno = oldByBsno.Voyno.Replace("1NC", "").Replace("1MA", "");
|
|
|
}
|
|
|
var orderList = await _rep.AsQueryable()
|
|
|
.Filter(null, true)
|
|
|
.Where(x => x.TenantId == UserManager.TENANT_ID
|
|
|
&& x.IsDeleted == false
|
|
|
&& x.CARRIERID == oldByBsno.CARRIERID
|
|
|
&& x.VESSEL == oldByBsno.Vessel
|
|
|
&& x.VOYNO == voyno
|
|
|
&& x.VOYNOINNER == oldByBsno.VoynoInside)
|
|
|
.Distinct()
|
|
|
.ToListAsync();
|
|
|
|
|
|
foreach (var order in orderList)
|
|
|
{
|
|
|
var oldOrder = order.Adapt<BookingOrder>();
|
|
|
|
|
|
var oldVoyno = order.VOYNO?.Replace("1NC", "").Replace("1MA", "");
|
|
|
var newVoyno = entity.Voyno?.Replace("1NC", "").Replace("1MA", "");
|
|
|
if (oldVoyno != newVoyno)
|
|
|
{
|
|
|
order.VOYNO = newVoyno;
|
|
|
await _rep.Context.Updateable(order).UpdateColumns(o => new
|
|
|
{
|
|
|
o.VOYNO,
|
|
|
o.UpdatedTime,
|
|
|
o.UpdatedUserId,
|
|
|
o.UpdatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
await _bookingorderservice.SaveLog(order, oldOrder, "东胜同步船期");
|
|
|
|
|
|
await _bookingorderservice.SendBookingOrder(new long[] { order.Id });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据船公司船名航次更新船期信息
|
|
|
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.IsDeleted == false && x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel)
|
|
|
.WhereIF(!string.IsNullOrEmpty(item.Voyno), x => x.VOYNO == item.Voyno)
|
|
|
.WhereIF(!string.IsNullOrEmpty(item.VoynoInside), x => x.VOYNOINNER == item.VoynoInside)
|
|
|
.Distinct()
|
|
|
.ToListAsync();
|
|
|
|
|
|
var orderIds = order.Select(x => x.Id).ToList();
|
|
|
|
|
|
//已封账的订舱数据不更新
|
|
|
var lockedList = await _bookingextstate.AsQueryable().Where(x => orderIds.Contains(x.bookingId) && x.IsLockBooking).Select(x => x.bookingId).ToListAsync();
|
|
|
|
|
|
_logger.LogInformation($"同步船期_查询到{UserManager.TENANT_NAME}需要更新{order.Count()}条订舱数据");
|
|
|
foreach (var it in order)
|
|
|
{
|
|
|
if (lockedList.Contains(it.Id))
|
|
|
{
|
|
|
_logger.LogWarning($"提单号:{it.MBLNO}、ID: {it.Id} 的订舱数据已封账,不更新船期");
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
var old = it.Adapt<BookingOrder>();
|
|
|
//更新订舱船期
|
|
|
if (it.ETD != item.ETD && item.ETD != null)
|
|
|
{
|
|
|
it.ETD = item.ETD;
|
|
|
|
|
|
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,
|
|
|
it.LstShipOrderCompareId,
|
|
|
it.LstShipOrderCompareDate,
|
|
|
it.LstShipOrderCompareRlt,
|
|
|
it.LstShipOrderCompareRltName,
|
|
|
it.LstShipOrderCompareMode,
|
|
|
it.LstDraftCompareRlt,
|
|
|
it.LstDraftCompareDate
|
|
|
}).ExecuteCommandAsync();
|
|
|
await _bookingorderservice.SaveLog(it, old, "东胜同步船期");
|
|
|
await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//通知前端更新缓存
|
|
|
await _chatHubContext.Clients.All.NotifyVesselChange();
|
|
|
|
|
|
return "上传成功!";
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 删除船期
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/DeletaVesselDate"), ApiUser(ApiCode = "DeletaVesselDate")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task DeletaVesselDate(string bsnos)
|
|
|
{
|
|
|
var arr = bsnos.Split(",");
|
|
|
if (arr.Count() > 0)
|
|
|
{
|
|
|
|
|
|
foreach (var item in arr)
|
|
|
{
|
|
|
await _vesselinfo.UpdateAsync(x => x.BSNO == item, x => new DjyVesselInfo { IsDeleted = true });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//通知前端更新缓存
|
|
|
await _chatHubContext.Clients.All.NotifyVesselChange();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 同步订舱批量 没有返回值
|
|
|
/// </summary>
|
|
|
/// <param name="list"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/DataSync/SyncBookingList"), ApiUser(ApiCode = "SyncBookingList")]
|
|
|
public async Task SyncBookingList(List<SyncBookingOrderDto> list)
|
|
|
{
|
|
|
List<CodeCtn> ctncode = await _cache.GetAllCodeCtn();
|
|
|
var mapcarrier = await _mapcarrier.Where(x => x.Module == "HeChuan").ToListAsync();
|
|
|
var userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
var djycustomer = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
var goodsconfig = await _goodsStatusConfig.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
var linelist = await _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
|
|
|
foreach (var model in list)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO))
|
|
|
{
|
|
|
throw Oops.Bah("主单BSNO未录入");
|
|
|
}
|
|
|
if (string.IsNullOrWhiteSpace(model.CreatedUserName))
|
|
|
{
|
|
|
throw Oops.Bah("未录入创建人");
|
|
|
}
|
|
|
|
|
|
var user = userlist.Where(x => x.Name == model.CreatedUserName.Trim() && x.IsDeleted == false).FirstOrDefault();
|
|
|
if (user == null)
|
|
|
{
|
|
|
throw Oops.Bah($"未匹配到创建人{model.CreatedUserName.Trim()}请联系管理员添加相关用户");
|
|
|
}
|
|
|
var order = orderlist.Where(x => x.BSNO == model.BSNO).FirstOrDefault();
|
|
|
|
|
|
|
|
|
if (order == null)
|
|
|
{
|
|
|
|
|
|
#region 新增
|
|
|
if (string.IsNullOrWhiteSpace(model.MBLNO))
|
|
|
{
|
|
|
throw Oops.Bah("请填写提单号!");
|
|
|
}
|
|
|
|
|
|
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
var ms = JsonUtil.TrimFields(model);
|
|
|
if (!string.IsNullOrEmpty(ms))
|
|
|
{
|
|
|
throw Oops.Bah(ms);
|
|
|
}
|
|
|
if (model.ctnInputs != null)
|
|
|
{
|
|
|
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
model.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
}
|
|
|
var et = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == 0).FirstAsync();
|
|
|
if (et != null)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
|
|
|
}
|
|
|
var entity = model.Adapt<BookingOrder>();
|
|
|
if (!string.IsNullOrEmpty(entity.ROUTE))
|
|
|
{
|
|
|
entity.ROUTEID = userlist.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.SALE))
|
|
|
{
|
|
|
entity.SALEID = userlist.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.OP))
|
|
|
{
|
|
|
entity.OPID = userlist.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.DOC))
|
|
|
{
|
|
|
entity.DOCID = userlist.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
entity.CUSTSERVICEID = userlist.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTOMSER))
|
|
|
{
|
|
|
entity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.TRUCKER))
|
|
|
{
|
|
|
entity.TRUCKERID = djycustomer.Where(x => x.ShortName == entity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTOMERNAME))
|
|
|
{
|
|
|
entity.CUSTOMERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.FORWARDER))
|
|
|
{
|
|
|
entity.FORWARDERID = djycustomer.Where(x => x.ShortName == entity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.YARD))
|
|
|
{
|
|
|
entity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.YARD).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CARRIER))
|
|
|
{
|
|
|
entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
|
|
|
if (string.IsNullOrEmpty(entity.CARRIERID))
|
|
|
{
|
|
|
|
|
|
entity.CARRIERID = mapcarrier.Where(x => x.MapName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.LineName))
|
|
|
{
|
|
|
var line = linelist.Where(m => m.LineName.Contains(entity.LineName)).FirstOrDefault();
|
|
|
if (line == null)
|
|
|
{
|
|
|
await _repline.InsertAsync(new DjyTenantLine
|
|
|
{
|
|
|
LineName = entity.LineName,
|
|
|
LineCode = "",
|
|
|
TenantId = UserManager.TENANT_ID,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
|
|
|
entity.CreatedUserId = user.Id;
|
|
|
entity.CreatedUserName = user.Name.ToString();
|
|
|
entity.CreatedTime = DateTime.Now;
|
|
|
entity.TenantId = UserManager.TENANT_ID;
|
|
|
entity.TenantName = UserManager.TENANT_NAME;
|
|
|
entity.ParentId = 0;
|
|
|
await _rep.InsertAsync(entity);
|
|
|
if (model.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var item in model.ctnInputs)
|
|
|
{
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
ctnentity.BILLID = entity.Id;
|
|
|
ctnentity.CreatedUserId = user.Id;
|
|
|
ctnentity.CreatedUserName = user.Name;
|
|
|
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
|
|
|
ctnentity.CreatedUserId = user.Id;
|
|
|
ctnentity.CreatedUserName = user.Name.ToString();
|
|
|
ctnentity.CreatedTime = DateTime.Now;
|
|
|
ctnentity.TenantId = UserManager.TENANT_ID;
|
|
|
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
//这里保存有可能没有添加多品名,所有箱下没有货物信息
|
|
|
if (item.ctnDetailInputs != null)
|
|
|
{
|
|
|
foreach (var it in item.ctnDetailInputs)
|
|
|
{
|
|
|
var ctndetail = it.Adapt<BookingCtnDetail>();
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
ctndetail.CreatedUserId = user.Id;
|
|
|
ctndetail.CreatedUserName = user.Name;
|
|
|
ctndetail.CreatedUserId = user.Id;
|
|
|
ctndetail.CreatedUserName = user.Name.ToString();
|
|
|
ctndetail.CreatedTime = DateTime.Now;
|
|
|
ctndetail.TenantId = UserManager.TENANT_ID;
|
|
|
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (model.BookingEDIExt != null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
ediExtEntity.BookingId = entity.Id;
|
|
|
ediExtEntity.CreatedUserId = user.Id;
|
|
|
ediExtEntity.CreatedUserName = user.Name;
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
ediExtEntity.TenantId = UserManager.TENANT_ID;
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
}
|
|
|
////添加booking日志
|
|
|
await _bookinglog.InsertAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Add",
|
|
|
BookingId = entity.Id,
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = "系统"
|
|
|
});
|
|
|
|
|
|
|
|
|
//分单
|
|
|
if (model.childrens != null)
|
|
|
{
|
|
|
foreach (var item in model.childrens)
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(item.HBLNO))
|
|
|
{
|
|
|
throw Oops.Bah("请填写分提单号!");
|
|
|
}
|
|
|
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
|
|
|
var fms = JsonUtil.TrimFields(item);
|
|
|
if (!string.IsNullOrEmpty(fms))
|
|
|
{
|
|
|
throw Oops.Bah(fms);
|
|
|
}
|
|
|
if (item.ctnInputs != null)
|
|
|
{
|
|
|
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
item.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
}
|
|
|
var fdet = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == entity.Id).FirstAsync();
|
|
|
if (fdet != null)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah($"当前分单中提单号({item.MBLNO}_{item.HBLNO})已存在,请勿重复录入!");
|
|
|
|
|
|
}
|
|
|
var fdentity = item.Adapt<BookingOrder>();
|
|
|
if (!string.IsNullOrEmpty(fdentity.ROUTE))
|
|
|
{
|
|
|
fdentity.ROUTEID = userlist.Where(x => x.Name == fdentity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.SALE))
|
|
|
{
|
|
|
fdentity.SALEID = userlist.Where(x => x.Name == fdentity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.OP))
|
|
|
{
|
|
|
fdentity.OPID = userlist.Where(x => x.Name == fdentity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.OP).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.DOC))
|
|
|
{
|
|
|
fdentity.DOCID = userlist.Where(x => x.Name == fdentity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
|
|
|
{
|
|
|
fdentity.CUSTSERVICEID = userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CUSTOMSER))
|
|
|
{
|
|
|
fdentity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.TRUCKER))
|
|
|
{
|
|
|
fdentity.TRUCKERID = djycustomer.Where(x => x.ShortName == fdentity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CUSTOMERNAME))
|
|
|
{
|
|
|
fdentity.CUSTOMERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.FORWARDER))
|
|
|
{
|
|
|
fdentity.FORWARDERID = djycustomer.Where(x => x.ShortName == fdentity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CARRIERID))
|
|
|
{
|
|
|
fdentity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == fdentity.CARRIERID).Select(x => x.CnName).FirstOrDefault();
|
|
|
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.YARD))
|
|
|
{
|
|
|
fdentity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.YARD).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CARRIER))
|
|
|
{
|
|
|
fdentity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
|
|
|
if (string.IsNullOrEmpty(fdentity.CARRIERID))
|
|
|
{
|
|
|
|
|
|
fdentity.CARRIERID = mapcarrier.Where(x => x.MapName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(item.LineName))
|
|
|
{
|
|
|
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(item.LineName)).FirstAsync();
|
|
|
if (line == null)
|
|
|
{
|
|
|
await _repline.InsertAsync(new DjyTenantLine
|
|
|
{
|
|
|
LineName = item.LineName,
|
|
|
LineCode = "",
|
|
|
TenantId = UserManager.TENANT_ID,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fdentity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
|
|
|
fdentity.MBLNO = entity.MBLNO;
|
|
|
fdentity.CreatedUserId = user.Id;
|
|
|
fdentity.CreatedUserName = user.Name;
|
|
|
fdentity.CreatedTime = DateTime.Now;
|
|
|
fdentity.TenantId = UserManager.TENANT_ID;
|
|
|
fdentity.TenantName = UserManager.TENANT_NAME;
|
|
|
fdentity.ParentId = entity.Id;
|
|
|
await _rep.InsertAsync(fdentity);
|
|
|
|
|
|
if (item.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var it in item.ctnInputs)
|
|
|
{
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
ctnentity.BILLID = fdentity.Id;
|
|
|
ctnentity.CreatedUserId = user.Id;
|
|
|
ctnentity.CreatedUserName = user.Name;
|
|
|
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
//这里保存有可能没有添加多品名,所有箱下没有货物信息
|
|
|
if (it.ctnDetailInputs != null)
|
|
|
{
|
|
|
foreach (var dit in it.ctnDetailInputs)
|
|
|
{
|
|
|
var ctndetail = dit.Adapt<BookingCtnDetail>();
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
ctndetail.CreatedUserId = user.Id;
|
|
|
ctndetail.CreatedUserName = user.Name;
|
|
|
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.BookingEDIExt != null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
ediExtEntity.BookingId = fdentity.Id;
|
|
|
ediExtEntity.CreatedUserId = user.Id;
|
|
|
ediExtEntity.CreatedUserName = user.Name;
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
}
|
|
|
////添加booking日志
|
|
|
await _bookinglog.InsertAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Add",
|
|
|
BookingId = fdentity.Id,
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = "系统"
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (model.GoodsStatus != null)
|
|
|
{
|
|
|
|
|
|
foreach (var item in model.GoodsStatus)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(item.StatusName))
|
|
|
{
|
|
|
|
|
|
|
|
|
var gc = goodsconfig.Where(x => x.StatusName == item.StatusName && x.CreatedUserId == user.Id).FirstOrDefault();
|
|
|
if (gc != null)
|
|
|
{
|
|
|
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = gc.Id,
|
|
|
FinishTime = item.FinishTime,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = item.Remark,
|
|
|
ExtData = item.ExtData
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
var configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
|
|
|
{
|
|
|
|
|
|
StatusName = item.StatusName,
|
|
|
Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Max(x => x.Sort) + 1,
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name,
|
|
|
IsDeleted = false
|
|
|
});
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = configid,
|
|
|
FinishTime = item.FinishTime,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = item.Remark,
|
|
|
ExtData = item.ExtData
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(model.CtnDayNum))
|
|
|
{
|
|
|
var gc = goodsconfig.Where(x => x.StatusName == "申请箱使" && x.CreatedUserId == user.Id).FirstOrDefault();
|
|
|
if (gc != null)
|
|
|
{
|
|
|
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = gc.Id,
|
|
|
FinishTime = DateTime.Now,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = "",
|
|
|
ExtData = model.CtnDayNum
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
var configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
|
|
|
{
|
|
|
|
|
|
StatusName = "申请箱使",
|
|
|
Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Max(x => x.Sort) + 1,
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name,
|
|
|
IsDeleted = false
|
|
|
});
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = configid,
|
|
|
FinishTime = DateTime.Now,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = "",
|
|
|
ExtData = model.CtnDayNum
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
#region 编辑
|
|
|
if (string.IsNullOrWhiteSpace(model.MBLNO))
|
|
|
{
|
|
|
throw Oops.Bah("请填写提单号!");
|
|
|
}
|
|
|
|
|
|
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
|
|
|
var ms = JsonUtil.TrimFields(model);
|
|
|
if (!string.IsNullOrEmpty(ms))
|
|
|
{
|
|
|
throw Oops.Bah(ms);
|
|
|
}
|
|
|
if (model.ctnInputs != null)
|
|
|
{
|
|
|
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
model.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
}
|
|
|
|
|
|
var main = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO && x.IsDeleted == false).FirstAsync();
|
|
|
|
|
|
var et = await _rep.AsQueryable().Filter(null, true).Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.BSNO != model.BSNO).FirstAsync();
|
|
|
if (et != null)
|
|
|
{
|
|
|
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
|
|
|
}
|
|
|
var entity = model.Adapt<BookingOrder>();
|
|
|
entity.Id = main.Id;
|
|
|
entity.UpdatedUserName = user.Name;
|
|
|
entity.UpdatedUserId = user.Id;
|
|
|
entity.UpdatedTime = DateTime.Now;
|
|
|
if (!string.IsNullOrEmpty(entity.ROUTE))
|
|
|
{
|
|
|
entity.ROUTEID = userlist.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.SALE))
|
|
|
{
|
|
|
entity.SALEID = userlist.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.OP))
|
|
|
{
|
|
|
entity.OPID = userlist.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.DOC))
|
|
|
{
|
|
|
entity.DOCID = userlist.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
|
|
|
{
|
|
|
entity.CUSTSERVICEID = userlist.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTOMSER))
|
|
|
{
|
|
|
entity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.TRUCKER))
|
|
|
{
|
|
|
entity.TRUCKERID = djycustomer.Where(x => x.ShortName == entity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CUSTOMERNAME))
|
|
|
{
|
|
|
entity.CUSTOMERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.FORWARDER))
|
|
|
{
|
|
|
entity.FORWARDERID = djycustomer.Where(x => x.ShortName == entity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.YARD))
|
|
|
{
|
|
|
entity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.YARD).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(entity.CARRIER))
|
|
|
{
|
|
|
entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
|
|
|
if (string.IsNullOrEmpty(entity.CARRIERID))
|
|
|
{
|
|
|
|
|
|
entity.CARRIERID = mapcarrier.Where(x => x.MapName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(entity.LineName))
|
|
|
{
|
|
|
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(entity.LineName)).FirstAsync();
|
|
|
if (line == null)
|
|
|
{
|
|
|
await _repline.InsertAsync(new DjyTenantLine
|
|
|
{
|
|
|
LineName = entity.LineName,
|
|
|
LineCode = "",
|
|
|
TenantId = UserManager.TENANT_ID,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.BOOKINGNO,
|
|
|
it.ParentId,
|
|
|
it.TenantId,
|
|
|
it.TenantName,
|
|
|
it.YgtETD,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName,
|
|
|
it.LstShipOrderCompareId,
|
|
|
it.LstShipOrderCompareDate,
|
|
|
it.LstShipOrderCompareRltName,
|
|
|
it.LstShipOrderCompareMode
|
|
|
}).ExecuteCommandAsync();
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == main.Id).Select(x => x.Id).ToListAsync();
|
|
|
await _repCtn.DeleteAsync(x => x.BILLID == main.Id);
|
|
|
await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID));
|
|
|
await _goodsStatus.DeleteAsync(x => x.bookingId == main.Id);
|
|
|
if (model.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var item in model.ctnInputs)
|
|
|
{
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
ctnentity.BILLID = main.Id;
|
|
|
ctnentity.CreatedUserId = user.Id;
|
|
|
ctnentity.CreatedUserName = user.Name;
|
|
|
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
if (item.ctnDetailInputs != null)
|
|
|
{
|
|
|
foreach (var it in item.ctnDetailInputs)
|
|
|
{
|
|
|
var ctndetail = it.Adapt<BookingCtnDetail>();
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
ctndetail.CreatedUserId = user.Id;
|
|
|
ctndetail.CreatedUserName = user.Name;
|
|
|
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (model.BookingEDIExt != null)
|
|
|
{
|
|
|
//检索EDI扩展
|
|
|
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == main.Id).FirstAsync();
|
|
|
|
|
|
if (ediExtEntity == null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
ediExtEntity.BookingId = main.Id;
|
|
|
ediExtEntity.CreatedUserId = user.Id;
|
|
|
ediExtEntity.CreatedUserName = user.Name;
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新EDI扩展
|
|
|
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
currEdiExtEntity.Id = ediExtEntity.Id;
|
|
|
currEdiExtEntity.UpdatedUserId = user.Id;
|
|
|
currEdiExtEntity.UpdatedTime = DateTime.Now;
|
|
|
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.BookingId,
|
|
|
it.TenantId,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (model.GoodsStatus != null)
|
|
|
{
|
|
|
|
|
|
foreach (var item in model.GoodsStatus)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(item.StatusName))
|
|
|
{
|
|
|
var gc = goodsconfig.Where(x => x.StatusName == item.StatusName && x.CreatedUserId == user.Id).FirstOrDefault();
|
|
|
if (gc != null)
|
|
|
{
|
|
|
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = gc.Id,
|
|
|
FinishTime = item.FinishTime,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = item.Remark,
|
|
|
ExtData = item.ExtData
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
long configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
|
|
|
{
|
|
|
|
|
|
StatusName = item.StatusName,
|
|
|
Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Max(x => x.Sort) + 1,
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name,
|
|
|
IsDeleted = false
|
|
|
});
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = configid,
|
|
|
FinishTime = item.FinishTime,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = item.Remark,
|
|
|
ExtData = item.ExtData
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(model.CtnDayNum))
|
|
|
{
|
|
|
var gc = goodsconfig.Where(x => x.StatusName == "申请箱使" && x.CreatedUserId == user.Id).FirstOrDefault();
|
|
|
if (gc != null)
|
|
|
{
|
|
|
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = gc.Id,
|
|
|
FinishTime = DateTime.Now,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = "",
|
|
|
ExtData = model.CtnDayNum
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Count();
|
|
|
var configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
|
|
|
{
|
|
|
|
|
|
StatusName = "申请箱使",
|
|
|
Sort = Sort + 1,
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name,
|
|
|
IsDeleted = false
|
|
|
});
|
|
|
await _goodsStatus.InsertAsync(new BookingGoodsStatus
|
|
|
{
|
|
|
bookingId = entity.Id,
|
|
|
ConfigId = configid,
|
|
|
FinishTime = DateTime.Now,
|
|
|
FinishUser = user.Name,
|
|
|
FinishUserId = user.Id,
|
|
|
Remark = "",
|
|
|
ExtData = model.CtnDayNum
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
bool flag = true;
|
|
|
long bid = 0;
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(entity))
|
|
|
{
|
|
|
string name = descriptor.Name;
|
|
|
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
object value = descriptor.GetValue(entity);
|
|
|
var oldvalue = main.GetType().GetProperty(name).GetValue(main, null);
|
|
|
|
|
|
if (name == "KGS" || name == "CBM")
|
|
|
{
|
|
|
if (Convert.ToDecimal(value) == Convert.ToDecimal(oldvalue))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
string _oldvalue = oldvalue != null ? oldvalue.ToString() : "";
|
|
|
string _value = value != null ? value.ToString() : "";
|
|
|
if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
{
|
|
|
if (flag)
|
|
|
{
|
|
|
////添加booking日志
|
|
|
bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Edit",
|
|
|
BookingId = entity.Id,
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name
|
|
|
});
|
|
|
flag = false;
|
|
|
}
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = bid,
|
|
|
Field = descriptor.Description,
|
|
|
OldValue = _oldvalue,
|
|
|
NewValue = _value,
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//分单
|
|
|
if (model.childrens != null)
|
|
|
{
|
|
|
foreach (var item in model.childrens)
|
|
|
{
|
|
|
var fenlanename = item.LANECODE;
|
|
|
var fenlinename = item.LANENAME;
|
|
|
if (string.IsNullOrWhiteSpace(item.HBLNO))
|
|
|
{
|
|
|
throw Oops.Bah("请填写分提单号!");
|
|
|
}
|
|
|
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
|
|
|
var fms = JsonUtil.TrimFields(item);
|
|
|
if (!string.IsNullOrEmpty(fms))
|
|
|
{
|
|
|
throw Oops.Bah(fms);
|
|
|
}
|
|
|
if (item.ctnInputs != null)
|
|
|
{
|
|
|
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
item.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
}
|
|
|
|
|
|
var fdmain = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO && x.IsDeleted == false).FirstAsync();
|
|
|
var fdentity = item.Adapt<BookingOrder>();
|
|
|
if (fdmain != null)
|
|
|
{
|
|
|
var fdet = await _rep.Where(x => x.MBLNO == item.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == item.HBLNO && x.BSNO != fdmain.BSNO).FirstAsync();
|
|
|
if (fdet != null)
|
|
|
{
|
|
|
throw Oops.Bah($"当前提单号{fdet.MBLNO}_{fdet.HBLNO}已存在,请勿重复录入!");
|
|
|
}
|
|
|
fdentity.MBLNO = entity.MBLNO;
|
|
|
fdentity.Id = fdmain.Id;
|
|
|
fdentity.UpdatedUserName = user.Name;
|
|
|
fdentity.UpdatedUserId = user.Id;
|
|
|
fdentity.UpdatedTime = DateTime.Now;
|
|
|
if (!string.IsNullOrEmpty(fdentity.ROUTE))
|
|
|
{
|
|
|
fdentity.ROUTEID = userlist.Where(x => x.Name == fdentity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.SALE))
|
|
|
{
|
|
|
fdentity.SALEID = userlist.Where(x => x.Name == fdentity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.OP))
|
|
|
{
|
|
|
fdentity.OPID = userlist.Where(x => x.Name == fdentity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.OP).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.DOC))
|
|
|
{
|
|
|
fdentity.DOCID = userlist.Where(x => x.Name == fdentity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
|
|
|
{
|
|
|
fdentity.CUSTSERVICEID = userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CUSTOMSER))
|
|
|
{
|
|
|
fdentity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.TRUCKER))
|
|
|
{
|
|
|
fdentity.TRUCKERID = djycustomer.Where(x => x.ShortName == fdentity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CUSTOMERNAME))
|
|
|
{
|
|
|
fdentity.CUSTOMERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.FORWARDER))
|
|
|
{
|
|
|
fdentity.FORWARDERID = djycustomer.Where(x => x.ShortName == fdentity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.YARD))
|
|
|
{
|
|
|
fdentity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.YARD).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.CARRIER))
|
|
|
{
|
|
|
fdentity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
|
|
|
if (string.IsNullOrEmpty(fdentity.CARRIERID))
|
|
|
{
|
|
|
|
|
|
fdentity.CARRIERID = mapcarrier.Where(x => x.MapName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(fdentity.LineName))
|
|
|
{
|
|
|
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(fdentity.LineName)).FirstAsync();
|
|
|
if (line == null)
|
|
|
{
|
|
|
await _repline.InsertAsync(new DjyTenantLine
|
|
|
{
|
|
|
LineName = fdentity.LineName,
|
|
|
LineCode = "",
|
|
|
TenantId = UserManager.TENANT_ID,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.BOOKINGNO,
|
|
|
it.ParentId,
|
|
|
it.TenantId,
|
|
|
it.TenantName,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.YgtETD,
|
|
|
it.CreatedUserName,
|
|
|
it.LstShipOrderCompareId,
|
|
|
it.LstShipOrderCompareDate,
|
|
|
it.LstShipOrderCompareRltName,
|
|
|
it.LstShipOrderCompareMode
|
|
|
}).ExecuteCommandAsync();
|
|
|
var fdctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == fdmain.Id).Select(x => x.Id).ToListAsync();
|
|
|
await _repCtn.DeleteAsync(x => x.BILLID == fdmain.Id);
|
|
|
await _ctndetailrep.DeleteAsync(x => fdctnlist.Contains((long)x.CTNID));
|
|
|
if (item.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var it in model.ctnInputs)
|
|
|
{
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
ctnentity.BILLID = fdmain.Id;
|
|
|
ctnentity.CreatedUserId = user.Id;
|
|
|
ctnentity.CreatedUserName = user.Name;
|
|
|
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
if (it.ctnDetailInputs != null)
|
|
|
{
|
|
|
foreach (var it_ in it.ctnDetailInputs)
|
|
|
{
|
|
|
var ctndetail = it_.Adapt<BookingCtnDetail>();
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
ctndetail.CreatedUserId = user.Id;
|
|
|
ctndetail.CreatedUserName = user.Name;
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (item.BookingEDIExt != null)
|
|
|
{
|
|
|
//检索EDI扩展
|
|
|
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdmain.Id).FirstAsync();
|
|
|
|
|
|
if (ediExtEntity == null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
ediExtEntity = item.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
ediExtEntity.BookingId = fdmain.Id;
|
|
|
ediExtEntity.CreatedUserId = user.Id;
|
|
|
ediExtEntity.CreatedUserName = user.Name;
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新EDI扩展
|
|
|
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
currEdiExtEntity.Id = ediExtEntity.Id;
|
|
|
|
|
|
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.BookingId,
|
|
|
it.TenantId,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
}
|
|
|
}
|
|
|
bool fdflag = true;
|
|
|
long fdbid = 0;
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(fdentity))
|
|
|
{
|
|
|
string name = descriptor.Name;
|
|
|
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
object value = descriptor.GetValue(fdentity);
|
|
|
var oldvalue = fdmain.GetType().GetProperty(name).GetValue(fdmain, null);
|
|
|
|
|
|
if (name == "KGS" || name == "CBM")
|
|
|
{
|
|
|
if (Convert.ToDecimal(value) == Convert.ToDecimal(oldvalue))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
string _oldvalue = oldvalue != null ? oldvalue.ToString() : "";
|
|
|
string _value = value != null ? value.ToString() : "";
|
|
|
if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
{
|
|
|
if (fdflag)
|
|
|
{
|
|
|
////添加booking日志
|
|
|
fdbid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Edit",
|
|
|
BookingId = fdentity.Id,
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = user.Id,
|
|
|
CreatedUserName = user.Name,
|
|
|
});
|
|
|
fdflag = false;
|
|
|
}
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = fdbid,
|
|
|
Field = descriptor.Description,
|
|
|
OldValue = _oldvalue,
|
|
|
NewValue = _value,
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
|
|
|
fdentity.CreatedUserId = user.Id;
|
|
|
fdentity.CreatedUserName = user.Name;
|
|
|
fdentity.CreatedTime = DateTime.Now;
|
|
|
fdentity.ParentId = entity.Id;
|
|
|
await _rep.InsertAsync(fdentity);
|
|
|
|
|
|
if (item.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var it in item.ctnInputs)
|
|
|
{
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
ctnentity.BILLID = fdentity.Id;
|
|
|
ctnentity.CreatedUserId = user.Id;
|
|
|
ctnentity.CreatedUserName = user.Name;
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
//这里保存有可能没有添加多品名,所有箱下没有货物信息
|
|
|
if (it.ctnDetailInputs != null)
|
|
|
{
|
|
|
foreach (var dit in it.ctnDetailInputs)
|
|
|
{
|
|
|
var ctndetail = dit.Adapt<BookingCtnDetail>();
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
ctndetail.CreatedUserId = user.Id;
|
|
|
ctndetail.CreatedUserName = user.Name;
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (item.BookingEDIExt != null)
|
|
|
{
|
|
|
//检索EDI扩展
|
|
|
|
|
|
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdentity.Id).FirstAsync();
|
|
|
if (ediExtEntity == null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
ediExtEntity.BookingId = fdentity.Id;
|
|
|
ediExtEntity.CreatedUserId = user.Id;
|
|
|
ediExtEntity.CreatedUserName = user.Name;
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新EDI扩展
|
|
|
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
currEdiExtEntity.Id = ediExtEntity.Id;
|
|
|
currEdiExtEntity.UpdatedUserId = user.Id;
|
|
|
currEdiExtEntity.UpdatedTime = DateTime.Now;
|
|
|
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.BookingId,
|
|
|
it.TenantId,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 爬虫上传船期港前
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/SaveSyncVesselDate"), ApiUser(ApiCode = "SaveSyncVesselDate")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task SaveSyncVesselDate(List<DjyVesselDto> dto)
|
|
|
{
|
|
|
var feeIdList = new List<long>();
|
|
|
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
//var model = infolist.Where(x => x.Vessel == item.Vessel && x.Voyno == item.Voyno).FirstOrDefault();
|
|
|
//if (model != null)
|
|
|
//{
|
|
|
// model.ETA = item.ETA;
|
|
|
// model.YgtETD = item.ETD;
|
|
|
// model.ATD = item.ATD;
|
|
|
// model.UpdatedTime = DateTime.Now;
|
|
|
// await _vesselinfo.AsUpdateable(model).IgnoreColumns().ExecuteCommandAsync();
|
|
|
//}
|
|
|
|
|
|
//变更船期
|
|
|
//await _vesselinfo.UpdateAsync(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.Vessel == item.Vessel && x.Voyno == item.Voyno && x.PortLoadingId == item.PortLoadId,
|
|
|
// x => new DjyVesselInfo
|
|
|
// {
|
|
|
// ETA = item.ETA,
|
|
|
// YgtETD = item.ETD,
|
|
|
// ATD = item.ATD,
|
|
|
// UpdatedTime = DateTime.Now
|
|
|
// });
|
|
|
|
|
|
await _vesselinfo.AsUpdateable()
|
|
|
.SetColumnsIF(item.ETA != null, x => x.ETA == item.ETA)
|
|
|
.SetColumnsIF(item.ETD != null, x => x.YgtETD == item.ETD)
|
|
|
.SetColumnsIF(item.ATD != null, x => x.ATD == item.ATD)
|
|
|
.SetColumns(x => x.UpdatedTime == DateTime.Now)
|
|
|
.Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false && x.Vessel == item.Vessel && x.Voyno == item.Voyno && x.PortLoadingId == item.PortLoadId)
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
//没有港口的按青岛港处理
|
|
|
if (string.IsNullOrEmpty(item.PortLoadId))
|
|
|
{
|
|
|
item.PortLoadId = "CNTAO";
|
|
|
}
|
|
|
|
|
|
#region 扣费相关
|
|
|
//当前租户配置为实际开船后扣费
|
|
|
var paraVal = _tenantParamValue.AsQueryable().Filter(null, true).First(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "BOOKING_FEE_METHOD");
|
|
|
//有实际开船,扣费
|
|
|
if (paraVal != null && paraVal.ItemCode == "ATD" && item.ATD.HasValue)
|
|
|
{
|
|
|
var orderIdList = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID
|
|
|
&& x.IsDeleted == false
|
|
|
&& x.VESSEL == item.Vessel
|
|
|
&& x.VOYNO == item.Voyno
|
|
|
&& x.PORTLOADID == item.PortLoadId).Select(x => x.Id).ToListAsync();
|
|
|
|
|
|
feeIdList.AddRange(orderIdList.Where(x => !feeIdList.Contains(x)));
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
// 118订舱系统2024.7.19修改:同一船名航次,启运港不同,船期也会不同;更新订舱时需要判断启运港
|
|
|
// 钉钉审批单号:202407121821000478565
|
|
|
var query = _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID
|
|
|
&& x.IsDeleted == false
|
|
|
&& x.VESSEL == item.Vessel
|
|
|
&& x.VOYNO == item.Voyno
|
|
|
&& x.PORTLOADID == item.PortLoadId);
|
|
|
|
|
|
List<BookingOrder> orderList = await query.Select(x => new BookingOrder
|
|
|
{
|
|
|
Id = x.Id,
|
|
|
ParentId = x.ParentId,
|
|
|
StartETA = x.StartETA,
|
|
|
YgtETD = x.YgtETD,
|
|
|
ATD = x.ATD,
|
|
|
StartATA = x.StartATA,
|
|
|
PORTLOADID = x.PORTLOADID
|
|
|
}).ToListAsync();
|
|
|
|
|
|
bool issend = false;
|
|
|
//批量变更业务数据
|
|
|
if (orderList != null)
|
|
|
{
|
|
|
List<long> waitSendOrderId = new();
|
|
|
foreach (var order in orderList)
|
|
|
{
|
|
|
bool isupdate = false;
|
|
|
Lazy<IUpdateable<BookingOrder>> update = new(() => _rep.Context.Updateable<BookingOrder>());
|
|
|
Lazy<BookingOrder> newOrder = new(() => order.Adapt<BookingOrder>());
|
|
|
|
|
|
if (order.StartETA != item.ETA && item.ETA != null)
|
|
|
{
|
|
|
isupdate = true;
|
|
|
newOrder.Value.StartETA = item.ETA;
|
|
|
update.Value.SetColumns(b => b.StartETA == item.ETA);
|
|
|
}
|
|
|
if (order.YgtETD != item.ETD && item.ETD != null)
|
|
|
{
|
|
|
isupdate = true;
|
|
|
newOrder.Value.YgtETD = item.ETD;
|
|
|
update.Value.SetColumns(b => b.YgtETD == item.ETD);
|
|
|
}
|
|
|
if (order.ATD != item.ATD && item.ATD != null)
|
|
|
{
|
|
|
isupdate = true;
|
|
|
newOrder.Value.ATD = item.ATD;
|
|
|
update.Value.SetColumns(b => b.ATD == item.ATD);
|
|
|
}
|
|
|
if (order.StartATA != item.ATA && item.ATA != null)
|
|
|
{
|
|
|
isupdate = true;
|
|
|
newOrder.Value.StartATA = item.ATA;
|
|
|
update.Value.SetColumns(b => b.StartATA == item.ATA);
|
|
|
}
|
|
|
if (isupdate)
|
|
|
{
|
|
|
issend = true;
|
|
|
_logger.LogInformation($"船期更新接口/DataSync/SaveSyncVesselDate临时日志:需要更新的订舱Id:{order.Id})");
|
|
|
await update.Value.Where(b => b.Id == order.Id).ExecuteCommandAsync();
|
|
|
await _bookingorderservice.SaveLog(newOrder.Value, order, "回推船期", new List<string>()
|
|
|
{
|
|
|
nameof(BookingOrder.StartATA),
|
|
|
nameof(BookingOrder.StartETA),
|
|
|
nameof(BookingOrder.YgtETD),
|
|
|
nameof(BookingOrder.ATD),
|
|
|
});
|
|
|
|
|
|
if (order.ParentId == 0)
|
|
|
{
|
|
|
waitSendOrderId.Add(order.Id);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_logger.LogInformation($"船期更新接口/DataSync/SaveSyncVesselDate临时日志:不需要更新的订舱Id:{order.Id})");
|
|
|
}
|
|
|
}
|
|
|
if (issend)
|
|
|
{
|
|
|
_logger.LogInformation($"船期更新接口/DataSync/SaveSyncVesselDate临时日志:待发送的订舱Id列表(ids:{string.Join(',', waitSendOrderId)})");
|
|
|
if (waitSendOrderId.Count > 0)
|
|
|
{
|
|
|
//同步东胜
|
|
|
await _bookingorderservice.SendBookingOrder(waitSendOrderId.ToArray());
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_logger.LogInformation($"船期更新接口/DataSync/SaveSyncVesselDate临时日志:无待发送的订舱");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//通知前端更新缓存
|
|
|
//await _chatHubContext.Clients.All.NotifyVesselChange();
|
|
|
|
|
|
//扣费
|
|
|
if (feeIdList.Count > 0)
|
|
|
{
|
|
|
await _publisher.PublishAsync(new ChannelEventSource($"Booking:DoFeeRecord", new { bsType = 28, sendtype = 0, idList = feeIdList }));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 爬虫上传船期港后
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/SaveSyncGHVesselDate"), ApiUser(ApiCode = "SaveSyncGHVesselDate")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task SaveSyncGHVesselDate(List<DjyVesselGHDto> dto)
|
|
|
{
|
|
|
var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync();
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
|
|
|
//var model = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.Vessel == item.Vessel && x.Voyno == item.Voyno && x.TenantId == UserManager.TENANT_ID).FirstOrDefault();
|
|
|
//model.ETA = item.ETA;
|
|
|
//model.ETD = item.ETD;
|
|
|
//model.ATD = item.ATD;
|
|
|
//await _vesselinfo.AsUpdateable(model).IgnoreColumns().ExecuteCommandAsync();
|
|
|
var order = orderlist.Where(x => x.VESSEL == item.Vessel && x.VOYNO == item.Voyno).ToList();
|
|
|
|
|
|
bool issend = false;
|
|
|
if (order != null)
|
|
|
{
|
|
|
foreach (var it in order)
|
|
|
{
|
|
|
var old = it;
|
|
|
bool flag = false;
|
|
|
|
|
|
if (it.ETA != item.ETA)
|
|
|
{
|
|
|
flag = true;
|
|
|
|
|
|
it.ETA = item.ETA;
|
|
|
}
|
|
|
if (it.MiddleETA != item.MiddleETA)
|
|
|
{
|
|
|
flag = true;
|
|
|
|
|
|
it.MiddleETA = item.MiddleETA;
|
|
|
}
|
|
|
if (it.MiddleETD != item.MiddleETD)
|
|
|
{
|
|
|
flag = true;
|
|
|
|
|
|
it.MiddleETD = item.MiddleETD;
|
|
|
}
|
|
|
if (item.MiddleATA != it.MiddleATA)
|
|
|
{
|
|
|
flag = true;
|
|
|
|
|
|
it.MiddleATA = item.MiddleATA;
|
|
|
}
|
|
|
|
|
|
if (item.MiddleATD != it.MiddleATD)
|
|
|
{
|
|
|
flag = true;
|
|
|
|
|
|
it.MiddleATD = item.MiddleATD;
|
|
|
}
|
|
|
|
|
|
if (item.ATA != it.ATA)
|
|
|
{
|
|
|
flag = true;
|
|
|
|
|
|
it.ATA = item.ATA;
|
|
|
}
|
|
|
|
|
|
if (flag)
|
|
|
{
|
|
|
issend = true;
|
|
|
await _rep.AsUpdateable(it).IgnoreColumns().ExecuteCommandAsync();
|
|
|
await _bookingorderservice.SaveLog(it, old, "回推船期");
|
|
|
}
|
|
|
}
|
|
|
if (issend)
|
|
|
{
|
|
|
var ids = order.Where(x => x.ParentId == 0).Select(x => x.Id).ToArray();
|
|
|
if (ids.Count() > 0)
|
|
|
{ //同步东胜
|
|
|
await _bookingorderservice.SendBookingOrder(ids);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
await _commonDBService.GetAllLane(false); //刷新缓存
|
|
|
}
|
|
|
else if (dto.Type == "del")
|
|
|
{
|
|
|
foreach (var lane in laneList)
|
|
|
{
|
|
|
await _codeLaneRep.DeleteAsync(lane);
|
|
|
}
|
|
|
|
|
|
await _commonDBService.GetAllLane(false); //刷新缓存
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah($"同步类型无效:{dto.Type}");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 目的港上传同步
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[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}");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 船期获取异常提醒
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/SyncVesselDateExcept"), ApiUser(ApiCode = "SyncVesselDateExcept")]
|
|
|
public async Task SyncVesselDateExcept(List<DjyVesselExceptDto> dto)
|
|
|
{
|
|
|
if (dto != null)
|
|
|
{
|
|
|
string msg = string.Empty;
|
|
|
dto = dto.Distinct().ToList();
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
msg += $"船名:{item.Vessel} 航次:{item.Voyno} 异常信息: {item.Message}";
|
|
|
msg += "\r\n";
|
|
|
}
|
|
|
//推送钉钉消息
|
|
|
DingTalkGroupHelper.SendDingTalkGroupMessage("hechuanVesselExcepNotify", "船期获取异常提醒", msg);
|
|
|
|
|
|
//推送和川钉钉群,@具体操作
|
|
|
SyncVesselExcepAtOp(dto);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//[HttpPost("/DataSync/SyncVesselDateTest"), ApiUser(ApiCode = "SaveSyncVesselDate")]
|
|
|
//public async Task SyncVesselDateTest(List<DjyVesselExceptDto> dto)
|
|
|
private async Task SyncVesselExcepAtOp(List<DjyVesselExceptDto> dto)
|
|
|
{
|
|
|
var tenantId = UserManager.TENANT_ID;
|
|
|
SpareTime.DoOnce(60000, (tmr, l) =>
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
_logger.LogInformation($"SaveSyncVesselDate @通知执行");
|
|
|
int maxSendLimit = 20; //钉钉每分钟发送限制
|
|
|
|
|
|
var usrList = _repUser.AsQueryable().Filter(null, true).Where(u => u.TenantId == tenantId && !u.IsDeleted).ToList();
|
|
|
Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
|
|
|
|
|
|
//遍历船名航次,查询船期维护人
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
var veUserList = _vesselinfo.AsQueryable().Filter(null, true)
|
|
|
.Where(v => v.TenantId == tenantId && v.Vessel == item.Vessel && v.Voyno == item.Voyno && !v.IsDeleted)
|
|
|
.Select(x => x.CreatedUserId)
|
|
|
.ToList();
|
|
|
|
|
|
if (veUserList.Count > 0)
|
|
|
{
|
|
|
var phoneList = usrList.Where(u => veUserList.Contains(u.Id) && u.Phone != "" && u.Phone != null).Select(x => x.Phone).ToList();
|
|
|
|
|
|
foreach (var phone in phoneList)
|
|
|
{
|
|
|
var msg = $"船名:{item.Vessel},航次:{item.Voyno},{item.Message}";
|
|
|
if (dic.ContainsKey(phone))
|
|
|
{
|
|
|
dic[phone].Add(msg);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dic.Add(phone, new List<string>(new string[] { msg }));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_logger.LogInformation($"处理发送后,准备给{dic.Count}个用户发送通知");
|
|
|
|
|
|
if (dic.Count > maxSendLimit) //大于限制,分多次发送
|
|
|
{
|
|
|
int times = (int)Math.Ceiling(dic.Count * 1.0 / maxSendLimit);
|
|
|
_logger.LogInformation($"发送通知超限,准备分为{times}次发送");
|
|
|
for (var t = 0; t < times; t++)
|
|
|
{
|
|
|
var keyList = dic.Keys.Skip(t * maxSendLimit).Take(maxSendLimit);
|
|
|
var currTimes = t + 1;
|
|
|
SpareTime.DoOnce(t == 0 ? 1000 : 70 * 1000 * t, doWhat: (st, val) =>
|
|
|
{
|
|
|
_logger.LogInformation($"超限第{currTimes}次发送,共{keyList.Count()}个");
|
|
|
foreach (var k in keyList)
|
|
|
{
|
|
|
var content = string.Join("\r\n", dic[k]);
|
|
|
_logger.LogInformation($"准备发送船期通知给 {k},内容:\r\n{content}");
|
|
|
DingTalkGroupHelper.SendDingTalkGroupMessage("hechuanVesselAtOpNotify", "船期提醒", content, false, new string[] { k }, null);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
foreach (var item in dic)
|
|
|
{
|
|
|
var content = string.Join("\r\n", item.Value);
|
|
|
_logger.LogInformation($"准备发送船期通知给 {item.Key},内容:\r\n{content}");
|
|
|
DingTalkGroupHelper.SendDingTalkGroupMessage("hechuanVesselAtOpNotify", "船期提醒", content, false, new string[] { item.Key }, null);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
var excep = ex;
|
|
|
while (excep != null)
|
|
|
{
|
|
|
_logger.LogError(excep.Message);
|
|
|
_logger.LogError(excep.StackTrace);
|
|
|
|
|
|
excep = excep.InnerException;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 插入货运动态
|
|
|
/// </summary>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/DataSync/AddBookingStatusLog"), ApiUser(ApiCode = "AddBookingStatusLog")]
|
|
|
public async Task AddBookingStatusLog(List<BookingStatusLogDto> all)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var traceTime = true;
|
|
|
var ticks = DateTime.Now;
|
|
|
if (traceTime)
|
|
|
{
|
|
|
_logger.LogInformation($"{all[0].BusinessId} AddBookingStatusLog Stage 0 ");
|
|
|
}
|
|
|
|
|
|
// 当BusinessId不为空时,将BusinessId的值转为订舱主键;否则仍然使用BookingId作为订舱记录主键
|
|
|
if (!string.IsNullOrEmpty(all[0].BusinessId))
|
|
|
{
|
|
|
if (long.TryParse(all[0].BusinessId, out long businessId))
|
|
|
{
|
|
|
all[0].BookingId = businessId;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_logger.LogError($"在将BusinessId转为BookingId时发生异常,货运动态插入失败;BusinessId的值为:{all[0].BusinessId}");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (traceTime)
|
|
|
{
|
|
|
var et = DateTime.Now - ticks;
|
|
|
ticks = DateTime.Now;
|
|
|
_logger.LogInformation($"{all[0].BusinessId} AddBookingStatusLog Stage 1 {et.TotalMilliseconds}");
|
|
|
}
|
|
|
|
|
|
var old = await _repStatuslog.AsQueryable().Filter(null, true).Where(x => x.BookingId == all[0].BookingId && x.Category == "yunzong" && x.IsDeleted == false).ToListAsync();
|
|
|
await _repStatuslog.DeleteAsync(x => x.BookingId == all[0].BookingId && x.Category == "yunzong");
|
|
|
foreach (var ot in old)
|
|
|
{
|
|
|
await _statuslogdetail.DeleteAsync(x => x.PId == ot.Id);
|
|
|
}
|
|
|
var dicdatalist = _cache.GetAllDictData().Result;
|
|
|
var list = await _repBookingStatus.AsQueryable().Filter(null, true).InnerJoin<SysDictData>((d, t) => d.StaCode == t.Code && d.StaCate == "book_sta_cate_billtrace" && d.BookingId == all[0].BookingId).Select((d, t) => new
|
|
|
{
|
|
|
BookingId = d.BookingId,
|
|
|
StaCode = d.StaCode,
|
|
|
StaName = d.StaName,
|
|
|
StaTime = d.StaTime,
|
|
|
Code = t.Code,
|
|
|
Value = t.Value
|
|
|
}).ToListAsync();
|
|
|
|
|
|
if (traceTime)
|
|
|
{
|
|
|
var et = DateTime.Now - ticks;
|
|
|
ticks = DateTime.Now;
|
|
|
_logger.LogInformation($"{all[0].BusinessId} AddBookingStatusLog Stage 2 {et.TotalMilliseconds}");
|
|
|
}
|
|
|
|
|
|
var sendDsList = new List<long>();
|
|
|
foreach (var item in all)
|
|
|
{
|
|
|
// 当BusinessId不为空时,将BusinessId的值转为订舱主键;否则仍然使用BookingId作为订舱记录主键
|
|
|
if (!string.IsNullOrEmpty(item.BusinessId))
|
|
|
{
|
|
|
if (long.TryParse(item.BusinessId, out long itemBusinessId))
|
|
|
{
|
|
|
item.BookingId = itemBusinessId;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_logger.LogError($"在将item.BusinessId转为BookingId时发生异常,货运动态插入失败;item.BusinessId的值为:{item.BusinessId}");
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#region 日志
|
|
|
//新增数据
|
|
|
var bookingStatusLog = new BookingStatusLog();
|
|
|
bookingStatusLog.BookingId = item.BookingId;
|
|
|
bookingStatusLog.Category = "yunzong";
|
|
|
bookingStatusLog.CreatedTime = DateTime.Now;
|
|
|
bookingStatusLog.Status = item.Status;
|
|
|
bookingStatusLog.OpTime = item.OpTime;
|
|
|
bookingStatusLog.MBLNO = item.MBLNO;
|
|
|
await _repStatuslog.InsertAsync(bookingStatusLog);
|
|
|
|
|
|
|
|
|
if (item.detail != null && item.detail.Count > 0)
|
|
|
{
|
|
|
foreach (var dt in item.detail)
|
|
|
{
|
|
|
var BookingStatusLogDetail = new BookingStatusLogDetail();
|
|
|
BookingStatusLogDetail.PId = bookingStatusLog.Id;
|
|
|
BookingStatusLogDetail.Status = dt.Status;
|
|
|
BookingStatusLogDetail.CNTRNO = dt.CNTRNO;
|
|
|
BookingStatusLogDetail.OPTime = dt.OPTime;
|
|
|
await _statuslogdetail.InsertAsync(BookingStatusLogDetail);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.Status == "提箱")
|
|
|
{
|
|
|
await _bookingorderservice.AutoYardData(item.BookingId);
|
|
|
|
|
|
#region 推送已提箱状态
|
|
|
//2023-12-28 JHQ 增加提箱推送状态
|
|
|
DateTime opTime = DateTime.MinValue;
|
|
|
|
|
|
if (item.detail != null && item.detail.Count > 0 && item.detail.Any(x => x.OPTime.HasValue))
|
|
|
opTime = item.detail.Where(x => x.OPTime.HasValue).Max(x => x.OPTime.Value);
|
|
|
|
|
|
var pushModel = new ModifyServiceProjectStatusDto
|
|
|
{
|
|
|
BookingId = item.BookingId,
|
|
|
SourceType = TrackingSourceTypeEnum.AUTO,
|
|
|
StatusCodes = new List<ModifyServiceProjectStatusDetailDto> {
|
|
|
new ModifyServiceProjectStatusDetailDto { StatusCode = "YTX" } }
|
|
|
};
|
|
|
|
|
|
if (opTime != DateTime.MinValue)
|
|
|
{
|
|
|
pushModel.StatusCodes[0].SetActDate = opTime;
|
|
|
}
|
|
|
|
|
|
var saveStatusRlt = await _bookingValueAddedService.SaveServiceStatus(pushModel);
|
|
|
|
|
|
_logger.LogInformation("请求JSON={json} 异步推送服务状态完成,结果={rlt}", JSON.Serialize(pushModel), JSON.Serialize(saveStatusRlt));
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
if (item.Status == "提箱" || item.Status == "返场")
|
|
|
{
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
if (traceTime)
|
|
|
{
|
|
|
var et = DateTime.Now - ticks;
|
|
|
ticks = DateTime.Now;
|
|
|
_logger.LogInformation($"{all[0].BusinessId} AddBookingStatusLog Stage 3 {et.TotalMilliseconds}");
|
|
|
}
|
|
|
|
|
|
#region 订舱状态
|
|
|
if (item.Status == "舱单")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_cangdan").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_cangdan";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_cangdan").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
//2023-12-28 JHQ 增加舱单放行推送状态
|
|
|
await _bookingorderservice.SetGoodsStatus("CDFX", item.BookingId);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "海关放行")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_haifang").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_haifang";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_haifang").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
await _bookingorderservice.SetGoodsStatus("BG", item.BookingId);
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "装载")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_zhuangzai").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_zhuangzai";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_zhuangzai").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
await _bookingorderservice.SetGoodsStatus("ZZFX", item.BookingId);
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "码放")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_mafang").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_mafang";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_mafang").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
await _bookingorderservice.SetGoodsStatus("MTFX", item.BookingId);
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "装船")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_zhuangchuan").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_zhuangchuan";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_zhuangchuan").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.detail.Max(x => x.OPTime);
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "ATD")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_atd").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_atd";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_atd").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "MDGETA")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_mdgeta").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_mdgeta";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_mdgeta").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "MDGATA")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_mdgeta").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_mdgata";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_mdgata").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
#region 入港时间
|
|
|
if (item.Status == "入港")
|
|
|
{
|
|
|
|
|
|
if (list.Where(x => x.Code == "sta_rugang").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_rugang";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_rugang").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
await _bookingorderservice.SetGoodsStatus("YRG", item.BookingId);
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
if (traceTime)
|
|
|
{
|
|
|
var et = DateTime.Now - ticks;
|
|
|
ticks = DateTime.Now;
|
|
|
_logger.LogInformation($"{all[0].BusinessId} AddBookingStatusLog Stage 4 {et.TotalMilliseconds}");
|
|
|
}
|
|
|
|
|
|
#region 船舶动态:ATD ETD ATA ETA MDGETA MDGATA
|
|
|
if (item.Status == "ATD" || item.Status == "ETD" || item.Status == "ATA" || item.Status == "ETA" || item.Status == "MDGETA" || item.Status == "MDGATA")
|
|
|
{
|
|
|
var enableStatusToSailingDate = _cache.GetAllTenantParam().Result
|
|
|
.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID
|
|
|
&& x.ParaCode == TenantParamCode.ENABLE_STATUS_TO_SAILING_DATE)?.ItemCode;
|
|
|
if (enableStatusToSailingDate == "YES")
|
|
|
{
|
|
|
if (item.Status == "ATD")
|
|
|
{
|
|
|
//2023-8-31,排查单号为177GZHZHQ5711V的数据,原来录入的船已开船,运踪港前不再查询,而因订阅港后数据会继续回推数据,所以导致ATD被改
|
|
|
//因此,暂时取消运踪回推时写入ATD,还是以船期表查询为准
|
|
|
|
|
|
// 2024-4-8 因为港捷需要,重新开启,并通过租户参数判断
|
|
|
//变更ATD
|
|
|
var oldOrder = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == item.BookingId && x.MBLNO == item.MBLNO && x.IsDeleted == false).FirstAsync();
|
|
|
if (oldOrder != null && item.OpTime != null && oldOrder.ATD != item.OpTime)
|
|
|
{
|
|
|
var newOrder = oldOrder.Adapt<BookingOrder>();
|
|
|
newOrder.ATD = item.OpTime;
|
|
|
newOrder.UpdatedUserId = UserManager.UserId;
|
|
|
newOrder.UpdatedUserName = UserManager.Name;
|
|
|
await _rep.AsUpdateable(newOrder).UpdateColumns(x => new
|
|
|
{
|
|
|
x.ATD,
|
|
|
x.UpdatedTime,
|
|
|
x.UpdatedUserId,
|
|
|
x.UpdatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 2023年8月24日改,取消运踪回推ATD的批量更新功能
|
|
|
* 和川操作经常修改提单号和船名航次,但修改时间会差好几天,导致运踪根据提单号查询的数据,回写回来之后,再根据船名航次去批量更新数据时,错误的把其他数据修改了
|
|
|
* 因此,不能根据船名航次去批量修改数据,因为操作写的船名航次可能是错误的,导致把他人的数据修改错误
|
|
|
*/
|
|
|
////批量变更相同船期
|
|
|
//if (!string.IsNullOrEmpty(o.VESSEL) && !string.IsNullOrEmpty(o.VOYNO) && !string.IsNullOrEmpty(o.CARRIERID))
|
|
|
//{
|
|
|
// var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == o.VOYNO && x.VESSEL == o.VESSEL && x.CARRIERID == o.CARRIERID && x.TenantId == o.TenantId && x.IsDeleted == false && x.Id != item.BookingId).ToListAsync();
|
|
|
|
|
|
// foreach (var it in order)
|
|
|
// {
|
|
|
// var _oldorder = it;
|
|
|
// var _oldatd = it.ATD;
|
|
|
// if (_oldatd != item.OpTime)
|
|
|
// {
|
|
|
// it.ATD = item.OpTime;
|
|
|
// await _rep.UpdateAsync(it);
|
|
|
// await _bookingorderservice.SaveLog(it, _oldorder);
|
|
|
// await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
else if (item.Status == "ETD")
|
|
|
{
|
|
|
var oldOrder = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == item.BookingId && x.MBLNO == item.MBLNO && x.IsDeleted == false).FirstAsync();
|
|
|
if (oldOrder != null && item.OpTime != null && oldOrder.YgtETD != item.OpTime)
|
|
|
{
|
|
|
var newOrder = oldOrder.Adapt<BookingOrder>();
|
|
|
newOrder.YgtETD = item.OpTime;
|
|
|
newOrder.UpdatedUserId = UserManager.UserId;
|
|
|
newOrder.UpdatedUserName = UserManager.Name;
|
|
|
await _rep.AsUpdateable(newOrder).UpdateColumns(x => new
|
|
|
{
|
|
|
x.YgtETD,
|
|
|
x.UpdatedTime,
|
|
|
x.UpdatedUserId,
|
|
|
x.UpdatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
|
|
|
}
|
|
|
}
|
|
|
else if (item.Status == "ATA")
|
|
|
{
|
|
|
var oldOrder = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == item.BookingId && x.MBLNO == item.MBLNO && x.IsDeleted == false).FirstAsync();
|
|
|
if (oldOrder != null && item.OpTime != null && oldOrder.StartATA != item.OpTime)
|
|
|
{
|
|
|
var newOrder = oldOrder.Adapt<BookingOrder>();
|
|
|
newOrder.StartATA = item.OpTime;
|
|
|
newOrder.UpdatedUserId = UserManager.UserId;
|
|
|
newOrder.UpdatedUserName = UserManager.Name;
|
|
|
await _rep.AsUpdateable(newOrder).UpdateColumns(x => new
|
|
|
{
|
|
|
x.StartATA,
|
|
|
x.UpdatedTime,
|
|
|
x.UpdatedUserId,
|
|
|
x.UpdatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
|
|
|
}
|
|
|
}
|
|
|
else if (item.Status == "ETA")
|
|
|
{
|
|
|
var oldOrder = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == item.BookingId && x.MBLNO == item.MBLNO && x.IsDeleted == false).FirstAsync();
|
|
|
if (oldOrder != null && item.OpTime != null && oldOrder.StartETA != item.OpTime)
|
|
|
{
|
|
|
var newOrder = oldOrder.Adapt<BookingOrder>();
|
|
|
newOrder.StartETA = item.OpTime;
|
|
|
newOrder.UpdatedUserId = UserManager.UserId;
|
|
|
newOrder.UpdatedUserName = UserManager.Name;
|
|
|
await _rep.AsUpdateable(newOrder).UpdateColumns(x => new
|
|
|
{
|
|
|
x.StartETA,
|
|
|
x.UpdatedTime,
|
|
|
x.UpdatedUserId,
|
|
|
x.UpdatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
|
|
|
}
|
|
|
}
|
|
|
else if (item.Status == "MDGETA")
|
|
|
{
|
|
|
var oldOrder = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == item.BookingId && x.MBLNO == item.MBLNO && x.IsDeleted == false).FirstAsync();
|
|
|
if (oldOrder != null && item.OpTime != null && oldOrder.ETA != item.OpTime)
|
|
|
{
|
|
|
var newOrder = oldOrder.Adapt<BookingOrder>();
|
|
|
newOrder.ETA = item.OpTime;
|
|
|
newOrder.UpdatedUserId = UserManager.UserId;
|
|
|
newOrder.UpdatedUserName = UserManager.Name;
|
|
|
await _rep.AsUpdateable(newOrder).UpdateColumns(x => new
|
|
|
{
|
|
|
x.ETA,
|
|
|
x.UpdatedTime,
|
|
|
x.UpdatedUserId,
|
|
|
x.UpdatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
|
|
|
}
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(o.VESSEL) && !string.IsNullOrEmpty(o.VOYNO) && !string.IsNullOrEmpty(o.CARRIERID))
|
|
|
//{
|
|
|
// var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == o.VOYNO && x.VESSEL == o.VESSEL && x.CARRIERID == o.CARRIERID && x.TenantId == o.TenantId && x.IsDeleted == false && x.Id != item.BookingId).ToListAsync();
|
|
|
// foreach (var it in order)
|
|
|
// {
|
|
|
// var _oldorder = it;
|
|
|
// var _oldatd = it.ETA;
|
|
|
// if (_oldatd != item.OpTime)
|
|
|
// {
|
|
|
// it.ETA = item.OpTime;
|
|
|
// await _rep.UpdateAsync(it);
|
|
|
// await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
|
|
|
// await _bookingorderservice.SaveLog(it, _oldorder);
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
else if (item.Status == "MDGATA")
|
|
|
{
|
|
|
var oldOrder = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == item.BookingId && x.MBLNO == item.MBLNO && x.IsDeleted == false).FirstAsync();
|
|
|
if (oldOrder != null && item.OpTime != null && oldOrder.ATA != item.OpTime)
|
|
|
{
|
|
|
var newOrder = oldOrder.Adapt<BookingOrder>();
|
|
|
newOrder.ATA = item.OpTime;
|
|
|
newOrder.UpdatedUserId = UserManager.UserId;
|
|
|
newOrder.UpdatedUserName = UserManager.Name;
|
|
|
await _rep.AsUpdateable(newOrder).UpdateColumns(x => new
|
|
|
{
|
|
|
x.ATA,
|
|
|
x.UpdatedTime,
|
|
|
x.UpdatedUserId,
|
|
|
x.UpdatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
sendDsList.Add(item.BookingId);
|
|
|
await _bookingorderservice.SaveLog(newOrder, oldOrder, "运踪更新船期");
|
|
|
}
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(o.VESSEL) && !string.IsNullOrEmpty(o.VOYNO) && !string.IsNullOrEmpty(o.CARRIERID))
|
|
|
//{
|
|
|
// var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == o.VOYNO && x.VESSEL == o.VESSEL && x.CARRIERID == o.CARRIERID && x.TenantId == o.TenantId && x.IsDeleted == false && x.Id != item.BookingId).ToListAsync();
|
|
|
// foreach (var it in order)
|
|
|
// {
|
|
|
// var _oldorder = it;
|
|
|
// var _oldatd = it.ATA;
|
|
|
// if (_oldatd != item.OpTime)
|
|
|
// {
|
|
|
// it.ATA = item.OpTime;
|
|
|
// await _rep.UpdateAsync(it);
|
|
|
// await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
|
|
|
// await _bookingorderservice.SaveLog(it, _oldorder);
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
if (traceTime)
|
|
|
{
|
|
|
var et = DateTime.Now - ticks;
|
|
|
ticks = DateTime.Now;
|
|
|
_logger.LogInformation($"{all[0].BusinessId} AddBookingStatusLog Stage 5 {et.TotalMilliseconds}");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (sendDsList.Count > 0)
|
|
|
{
|
|
|
await _bookingorderservice.SendBookingOrder(sendDsList.ToArray());
|
|
|
|
|
|
|
|
|
if (traceTime)
|
|
|
{
|
|
|
var et = DateTime.Now - ticks;
|
|
|
ticks = DateTime.Now;
|
|
|
_logger.LogInformation($"{all[0].BusinessId} AddBookingStatusLog Stage 6 {et.TotalMilliseconds}");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex.Message);
|
|
|
_logger.LogError(ex.StackTrace);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 接收其他系统上传订舱数据
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/UploadOrderData"), AllowAnonymous, ApiUser(ApiCode = "UploadOrderData")]
|
|
|
public async Task UploadOrderData(BookingOrderDto dto)
|
|
|
{
|
|
|
var saveDto = dto.Adapt<SaveBookingOrderInput>();
|
|
|
var dbModel = await _rep.AsQueryable().Filter(null, true).FirstAsync(x => x.TenantId == UserManager.TENANT_ID && x.BSNO == dto.BSNO);
|
|
|
if (dbModel != null)
|
|
|
{
|
|
|
dto.Id = dbModel.Id;
|
|
|
saveDto.Id = dbModel.Id;
|
|
|
|
|
|
var compareModel = dbModel.Adapt<BookingOrderDto>();
|
|
|
var propsOrder = typeof(BookingOrderDto).GetProperties();
|
|
|
var changeFileds = new List<string>();
|
|
|
foreach (var prop in propsOrder)
|
|
|
{
|
|
|
if (prop.Name != "ctnInputs" && prop.Name != "BookingEDIExt" && prop.Name != "ExtendState")
|
|
|
{
|
|
|
var v1 = prop.GetValue(compareModel);
|
|
|
var v2 = prop.GetValue(dto);
|
|
|
if (v1 != v2)
|
|
|
{
|
|
|
changeFileds.Add(prop.Name);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
saveDto.ChangedFields = changeFileds;
|
|
|
}
|
|
|
|
|
|
#region 处理操作、单证、客户、订舱代理等ID
|
|
|
var sysUserList = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
var customerList = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
|
|
|
var carrList = await _cache.GetAllCodeCarrier();
|
|
|
|
|
|
//销售
|
|
|
if (!string.IsNullOrEmpty(saveDto.SALE))
|
|
|
{
|
|
|
var sale = sysUserList.FirstOrDefault(x => x.Name == saveDto.SALE);
|
|
|
if (sale != null)
|
|
|
{
|
|
|
saveDto.SALEID = sale.Id.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//操作
|
|
|
if (!string.IsNullOrEmpty(saveDto.OP))
|
|
|
{
|
|
|
var operatorUser = sysUserList.FirstOrDefault(x => x.Name == saveDto.OP);
|
|
|
if (operatorUser != null)
|
|
|
{
|
|
|
saveDto.OPID = operatorUser.Id.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//客服
|
|
|
if (!string.IsNullOrEmpty(saveDto.CUSTSERVICE))
|
|
|
{
|
|
|
var custServiceUser = sysUserList.FirstOrDefault(x => x.Name == saveDto.CUSTSERVICE);
|
|
|
if (custServiceUser != null)
|
|
|
{
|
|
|
saveDto.CUSTSERVICEID = custServiceUser.Id.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//单证
|
|
|
if (!string.IsNullOrEmpty(saveDto.DOC))
|
|
|
{
|
|
|
var docUser = sysUserList.FirstOrDefault(x => x.Name == saveDto.DOC);
|
|
|
if (docUser != null)
|
|
|
{
|
|
|
saveDto.DOCID = docUser.Id.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//航线操作
|
|
|
if (!string.IsNullOrEmpty(saveDto.ROUTE))
|
|
|
{
|
|
|
var routeUser = sysUserList.FirstOrDefault(x => x.Name == saveDto.ROUTE);
|
|
|
if (routeUser != null)
|
|
|
{
|
|
|
saveDto.ROUTEID = routeUser.Id.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//航线管理
|
|
|
if (!string.IsNullOrEmpty(saveDto.LineManage))
|
|
|
{
|
|
|
var lineManageUser = sysUserList.FirstOrDefault(x => x.Name == saveDto.LineManage);
|
|
|
if (lineManageUser != null)
|
|
|
{
|
|
|
saveDto.LineManageID = lineManageUser.Id.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//委托单位
|
|
|
if (!string.IsNullOrEmpty(saveDto.CUSTOMERNAME))
|
|
|
{
|
|
|
var customer = customerList.FirstOrDefault(x => x.ShortName == saveDto.CUSTOMERNAME);
|
|
|
if (customer != null)
|
|
|
{
|
|
|
saveDto.CUSTOMERID = customer.Id;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//订舱代理
|
|
|
if (!string.IsNullOrEmpty(saveDto.FORWARDER))
|
|
|
{
|
|
|
var forwarder = customerList.FirstOrDefault(x => x.ShortName == saveDto.FORWARDER);
|
|
|
if (forwarder != null)
|
|
|
{
|
|
|
saveDto.FORWARDERID = forwarder.CodeName;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//船司
|
|
|
if (!string.IsNullOrEmpty(saveDto.CARRIER))
|
|
|
{
|
|
|
var carrier = carrList.FirstOrDefault(x => x.EnName == saveDto.CARRIER || x.CnName == saveDto.CARRIER);
|
|
|
if (carrier != null)
|
|
|
{
|
|
|
saveDto.CARRIERID = carrier.Code;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
saveDto.DoNotSendDS = true;
|
|
|
await _bookingorderservice.Save(saveDto);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 下载数据
|
|
|
|
|
|
/// <summary>
|
|
|
/// 爬虫获取船名航次
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DataSync/GetSyncVesselDate"), ApiUser(ApiCode = "GetSyncVesselDate")]
|
|
|
public async Task<dynamic> GetSyncVesselDate()
|
|
|
{
|
|
|
var list = await _vesselinfo.AsQueryable().Filter(null, true)
|
|
|
.Where(x => x.Sign == false && x.ATD == null
|
|
|
&& x.IsDeleted == false
|
|
|
&& x.TenantId == UserManager.TENANT_ID
|
|
|
&& (x.Voyno != null && x.Voyno != "")
|
|
|
&& x.ETD >= DateTime.Today.AddDays(-15) //2024-9-4,陈冠宇要求ETD前后15天
|
|
|
&& x.ETD <= DateTime.Today.AddDays(15)) //2023年7月19日,根据吴悦蓉反馈,查询3周左右的即可,再远的无效,而且也会产生无效提醒;2023年7月25日,改为2周
|
|
|
.Select(x => new
|
|
|
{
|
|
|
Vessel = x.Vessel,
|
|
|
Voyno = x.Voyno,
|
|
|
CARRIER = x.CARRIER,
|
|
|
CARRIERID = x.CARRIERID,
|
|
|
PortLoadId = x.PortLoadingId
|
|
|
}).Distinct().ToListAsync();
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 其他
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 自动化接口
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取订舱数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DataSync/GetBookingOrder"), ApiUser(ApiCode = "GetBookingOrder")]
|
|
|
public async Task<dynamic> GetBookingOrder(QueryBookingOrder query)
|
|
|
{
|
|
|
if (query == null)
|
|
|
{
|
|
|
throw Oops.Bah("未录入正确查询条件");
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(query.MBLNO) && string.IsNullOrEmpty(query.TMBLNO) && string.IsNullOrEmpty(query.BOOKINGNO))
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
var list = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).
|
|
|
WhereIF(!string.IsNullOrEmpty(query.MBLNO), x => x.MBLNO == query.MBLNO).
|
|
|
WhereIF(!string.IsNullOrEmpty(query.TMBLNO), x => x.TMBLNO == query.TMBLNO).
|
|
|
WhereIF(!string.IsNullOrEmpty(query.BOOKINGNO), x => x.BOOKINGNO == query.BOOKINGNO).ToListAsync();
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新订舱
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/DataSync/SaveBookingOrder"), ApiUser(ApiCode = "SaveBookingOrder")]
|
|
|
public async Task SaveBookingOrder(UpdateBookingOrder input)
|
|
|
{
|
|
|
if (input == null)
|
|
|
{
|
|
|
throw Oops.Bah("未录入数据");
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(input.MBLNO) && string.IsNullOrEmpty(input.TMBLNO) && string.IsNullOrEmpty(input.BOOKINGNO) && input.Id == 0)
|
|
|
{
|
|
|
throw Oops.Bah("未录入正确数据");
|
|
|
}
|
|
|
|
|
|
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == input.Id).FirstAsync();
|
|
|
var old = order.Adapt<BookingOrder>();
|
|
|
order.MBLNO = input.MBLNO;
|
|
|
order.TMBLNO = input.TMBLNO;
|
|
|
order.BOOKINGNO = input.BOOKINGNO;
|
|
|
order.UpdatedUserId = order.CreatedUserId;
|
|
|
order.UpdatedUserName = order.CreatedUserName;
|
|
|
order.UpdatedTime = DateTime.Now;
|
|
|
await _rep.AsUpdateable(order).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.ParentId,
|
|
|
it.TenantId,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName,
|
|
|
it.TenantName,
|
|
|
it.IsDeleted,
|
|
|
}).ExecuteCommandAsync();
|
|
|
await _bookingorderservice.SaveLog(order, old, "自动化更新接口");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取接口Key 个人或公司
|
|
|
/// </summary>
|
|
|
/// <param name="TypeCode"></param>
|
|
|
/// <param name="UserId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DataSync/GetAccountConfig"), ApiUser(ApiCode = "GetAccountConfig")]
|
|
|
public async Task<DjyWebsiteAccountConfig> GetAccountConfig(string TypeCode, long UserId)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(TypeCode))
|
|
|
{
|
|
|
throw Oops.Bah("请传入正确参数!");
|
|
|
}
|
|
|
DjyWebsiteAccountConfig accountConfig = new DjyWebsiteAccountConfig();
|
|
|
if (UserId == 0)
|
|
|
{
|
|
|
|
|
|
accountConfig = await _accountconfig.AsQueryable().InnerJoin<SysUser>((d, t) => d.TenantId == t.TenantId).Where((d, t) => d.TypeCode == TypeCode && t.TenantId == UserManager.TENANT_ID && d.IsTenant == true).FirstAsync();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
accountConfig = await _accountconfig.FirstOrDefaultAsync(x => x.TypeCode == TypeCode && x.CreatedUserId == UserId);
|
|
|
}
|
|
|
return accountConfig;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取租户参数
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DataSync/GetParamValue"), ApiUser(ApiCode = "GetParamValue")]
|
|
|
public dynamic GetParamValue()
|
|
|
{
|
|
|
|
|
|
var list = _cache.GetAllTenantParam().Result.Where(x => x.TenantId == UserManager.TENANT_ID).OrderBy(x => x.Sort).ToList();
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 挂载订舱文件
|
|
|
/// </summary>
|
|
|
/// <param name="file"></param>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/AddFile"), ApiUser(ApiCode = "AddFile")]
|
|
|
public async Task AddFile(IFormFile file, [FromForm] BookingFileDto dto)
|
|
|
{
|
|
|
//未上传文件
|
|
|
if (file == null || file.Length == 0)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK200);
|
|
|
}
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
var originalFilename = file.FileName; // 文件原始名称
|
|
|
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
|
|
|
if (!opt.fileType.Contains(fileSuffix))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK114);
|
|
|
}
|
|
|
|
|
|
var dirAbs = string.Empty;
|
|
|
if (string.IsNullOrEmpty(opt.basePath))
|
|
|
{
|
|
|
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
|
|
|
}
|
|
|
|
|
|
if (!Directory.Exists(dirAbs))
|
|
|
Directory.CreateDirectory(dirAbs);
|
|
|
|
|
|
|
|
|
// 先存库获取Id
|
|
|
var id = YitIdHelper.NextId();
|
|
|
var fileSaveName = $"{id}{fileSuffix}".ToLower();
|
|
|
var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower();
|
|
|
var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
|
|
|
var newFile = new BookingFile
|
|
|
{
|
|
|
Id = id,
|
|
|
FileName = originalFilename,
|
|
|
FilePath = fileRelaPath,
|
|
|
TypeCode = dto.TypeCode,
|
|
|
TypeName = dto.TypeName,
|
|
|
BookingId = dto.BookingId,
|
|
|
|
|
|
};
|
|
|
await _bookingfile.InsertAsync(newFile);
|
|
|
using (var stream = File.Create(fileAbsPath))
|
|
|
{
|
|
|
await file.CopyToAsync(stream);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 东胜封账
|
|
|
/// </summary>
|
|
|
/// <param dto=""></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/DataSync/SaveBookingOrderLock"), ApiUser(ApiCode = "SaveBookingOrderLock")]
|
|
|
public async Task SaveBookingOrderLock(List<BookingOrderLock> dto)
|
|
|
{
|
|
|
if (dto == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK201);
|
|
|
|
|
|
}
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
var extends = _bookingextstate.FirstOrDefault(x => x.bookingId == item.BookingId);
|
|
|
var oldSta = "";
|
|
|
if (extends == null)
|
|
|
{
|
|
|
extends = new BookingExtendState();
|
|
|
extends.Id = YitIdHelper.NextId();
|
|
|
extends.bookingId = item.BookingId;
|
|
|
extends.IsLockBooking = item.LockStatus;
|
|
|
await _bookingextstate.InsertAsync(extends);
|
|
|
|
|
|
oldSta = "未封账";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
oldSta = extends.IsLockBooking ? "已封账" : "未封账";
|
|
|
extends.IsLockBooking = item.LockStatus;
|
|
|
await _bookingextstate.AsUpdateable(extends).IgnoreColumns().ExecuteCommandAsync();
|
|
|
}
|
|
|
|
|
|
////添加booking日志
|
|
|
var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Edit",
|
|
|
BookingId = item.BookingId,
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = 0,
|
|
|
CreatedUserName = string.IsNullOrEmpty(item.UserName) ? UserManager.Name : item.UserName,
|
|
|
FromFunc = "封账"
|
|
|
});
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = bid,
|
|
|
Field = "封账状态",
|
|
|
OldValue = oldSta,
|
|
|
NewValue = extends.IsLockBooking ? "已封账" : "未封账"
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 提箱小票回推接收
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DataSync/TxxpReceiveFeedback"), ApiUser(ApiCode = "TxxpReceiveFeedback")]
|
|
|
public async Task TxxpReceiveFeedback(TxxpReceiveFeedbackDto dto)
|
|
|
{
|
|
|
_logger.LogInformation($"收到提箱小票数据回推:{dto.ToJsonString()}");
|
|
|
|
|
|
long bookingId = 0;
|
|
|
if (!dto.BookingId.HasValue || dto.BookingId == 0)
|
|
|
{
|
|
|
bookingId = _rep.AsQueryable().Filter(null, true).Where(x => x.MBLNO == dto.MBLNO && x.ParentId == 0 && x.IsDeleted == false).Select(x => x.Id).First();
|
|
|
if (bookingId == 0)
|
|
|
{
|
|
|
throw Oops.Bah($"未找到订舱数据:{dto.BookingId} {dto.MBLNO}");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
bookingId = dto.BookingId.Value;
|
|
|
}
|
|
|
|
|
|
var extData = _bookingextstate.FirstOrDefault(x => x.bookingId == bookingId);
|
|
|
if (extData == null)
|
|
|
{
|
|
|
extData = new BookingExtendState();
|
|
|
extData.Id = YitIdHelper.NextId();
|
|
|
extData.bookingId = bookingId;
|
|
|
await _bookingextstate.InsertAsync(extData);
|
|
|
}
|
|
|
|
|
|
extData.TxxpBeginTime = dto.BeginTime;
|
|
|
extData.TxxpEndTime = dto.EndTime;
|
|
|
extData.TxxpPdfUrl = dto.PdfUrl;
|
|
|
await _bookingextstate.UpdateAsync(extData);
|
|
|
|
|
|
_logger.LogInformation($"处理提箱小票数据回推完成");
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|