|
|
|
@ -7,6 +7,7 @@ using Furion.FriendlyException;
|
|
|
|
|
using Furion.JsonSerialization;
|
|
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using MathNet.Numerics;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
@ -16,6 +17,7 @@ using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using MySqlX.XDevAPI.Common;
|
|
|
|
|
using Org.BouncyCastle.Crypto;
|
|
|
|
|
using Org.BouncyCastle.Utilities;
|
|
|
|
|
using SqlSugar;
|
|
|
|
@ -55,6 +57,7 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _djyWebsiteAccountConfigRepository;
|
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRepository;
|
|
|
|
|
private readonly SqlSugarRepository<BookingLetteryard> _bookingLetteryardRepository;
|
|
|
|
|
private readonly SqlSugarRepository<TaskBCInfo> _taskBCInfoRepository;
|
|
|
|
|
|
|
|
|
|
const string CONST_MAPPING_BC_MODULE_ROUTE = "BC_DOWN_RT";
|
|
|
|
|
const string CONST_MAPPING_DRAFT_MODULE_ROUTE = "DRAFT_DOWN_RT";
|
|
|
|
@ -72,7 +75,8 @@ namespace Myshipping.Application
|
|
|
|
|
public BookingValueAddedService(ISysCacheService cache, ILogger<BookingTruckService> logger,
|
|
|
|
|
SqlSugarRepository<BookingOrder> bookingOrderRepository, SqlSugarRepository<BookingFile> bookingfile,
|
|
|
|
|
SqlSugarRepository<DjyWebsiteAccountConfig> djyWebsiteAccountConfigRepository, SqlSugarRepository<SysUser> sysUserRepository,
|
|
|
|
|
SqlSugarRepository<BookingLetteryard> bookingLetteryardRepository, IBookingOrderService bookingOrderService)
|
|
|
|
|
SqlSugarRepository<BookingLetteryard> bookingLetteryardRepository, IBookingOrderService bookingOrderService
|
|
|
|
|
, SqlSugarRepository<TaskBCInfo> taskBCInfoRepository)
|
|
|
|
|
{
|
|
|
|
|
_cache = cache;
|
|
|
|
|
_logger = logger;
|
|
|
|
@ -84,6 +88,7 @@ namespace Myshipping.Application
|
|
|
|
|
_sysUserRepository = sysUserRepository;
|
|
|
|
|
_bookingLetteryardRepository = bookingLetteryardRepository;
|
|
|
|
|
_bookingOrderService = bookingOrderService;
|
|
|
|
|
_taskBCInfoRepository = taskBCInfoRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1403,6 +1408,118 @@ namespace Myshipping.Application
|
|
|
|
|
if (bookingOrder == null)
|
|
|
|
|
throw Oops.Bah($"订舱信息获取失败,订舱信息不存在或已作废");
|
|
|
|
|
|
|
|
|
|
var updateRlt = InnerBCUpdateBookingOrder(model, bookingOrder, batchNo,1).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
if (!updateRlt.succ)
|
|
|
|
|
throw Oops.Bah($"订舱信息更新失败,{updateRlt.msg}");
|
|
|
|
|
|
|
|
|
|
if (model.IsLetterYard)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,用户选择转为入货通知,开始执行入货通知", batchNo
|
|
|
|
|
, bookingOrder.Id);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.FileTempPath))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 未提交文件路径,请求失败", batchNo
|
|
|
|
|
, bookingOrder.Id);
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah($"未提交文件路径,执行放舱失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var letterYardDto = new UpdateBookingLetteryardInput();
|
|
|
|
|
|
|
|
|
|
letterYardDto = model.LetteryardDto.Adapt<UpdateBookingLetteryardInput>();
|
|
|
|
|
|
|
|
|
|
if (model.LetterYardId.HasValue && model.LetterYardId.Value > 0)
|
|
|
|
|
{
|
|
|
|
|
letterYardDto.Id = model.LetterYardId.Value;
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,存在放舱记录 LetterYardId={LetterYardId}", batchNo
|
|
|
|
|
, bookingOrder.Id, letterYardDto.Id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var letterYardModel = _bookingLetteryardRepository.AsQueryable()
|
|
|
|
|
.First(x => x.BookingId == model.BookingOrderId);
|
|
|
|
|
|
|
|
|
|
if(letterYardModel != null)
|
|
|
|
|
letterYardDto.Id = letterYardModel.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//放舱保存
|
|
|
|
|
var letterYardId = await _bookingOrderService.LetteryardSave(letterYardDto);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 已完放舱记录保存 返回结果{rlt}", batchNo
|
|
|
|
|
, bookingOrder.Id, letterYardId);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} templateid={tempid} 开始发送放舱", batchNo
|
|
|
|
|
, bookingOrder.Id, model.TemplateId);
|
|
|
|
|
|
|
|
|
|
//发送放舱
|
|
|
|
|
await _bookingOrderService.SendLetterYard(model.BookingOrderId, model.TemplateId);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} templateid={tempid} 完成发送放舱", batchNo
|
|
|
|
|
, bookingOrder.Id, model.TemplateId);
|
|
|
|
|
|
|
|
|
|
string fileTypeCode = "bc";
|
|
|
|
|
string fileTypeName = "Booking Confirmation";
|
|
|
|
|
|
|
|
|
|
//重新将暂存文件写入正式路径
|
|
|
|
|
|
|
|
|
|
//读取文件配置
|
|
|
|
|
var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), model.FileTempPath,batchNo);
|
|
|
|
|
|
|
|
|
|
//将BC引入的文件写入订舱的附件
|
|
|
|
|
await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name,
|
|
|
|
|
fileTypeCode, fileTypeName);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 完成写入附件表 {filepath}", batchNo
|
|
|
|
|
, bookingOrder.Id, model.FileTempPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "执行成功";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 单票BC更新订舱信息
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 单票BC更新订舱信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model">BC详情</param>
|
|
|
|
|
/// <param name="bookingOrder">订舱详情</param>
|
|
|
|
|
/// <param name="batchNo">批次号</param>
|
|
|
|
|
/// <param name="sortNo">顺序号</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
private async Task<TaskManageOrderResultDto> InnerBCUpdateBookingOrder(SingleBCDto model, BookingOrder bookingOrder,
|
|
|
|
|
string batchNo,int sortNo)
|
|
|
|
|
{
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
|
|
|
|
result.bno = bookingOrder.MBLNO;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(result.bno))
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(bookingOrder.CUSTNO))
|
|
|
|
|
{
|
|
|
|
|
result.bno = $"订 {bookingOrder.CUSTNO}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.bno = $"NO.{sortNo}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//截单日期
|
|
|
|
|
if (model.ClosingDate.HasValue)
|
|
|
|
|
{
|
|
|
|
@ -1464,12 +1581,11 @@ namespace Myshipping.Application
|
|
|
|
|
bookingOrder.MBLNO = model.BLNo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bookingOrder.UpdatedTime = DateTime.Now;
|
|
|
|
|
bookingOrder.UpdatedUserId = UserManager.UserId;
|
|
|
|
|
bookingOrder.UpdatedUserName = UserManager.Name;
|
|
|
|
|
|
|
|
|
|
_bookingOrderRepository.AsUpdateable(bookingOrder).UpdateColumns(it => new
|
|
|
|
|
await _bookingOrderRepository.AsUpdateable(bookingOrder).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.UpdatedTime,
|
|
|
|
|
it.UpdatedUserId,
|
|
|
|
@ -1481,81 +1597,117 @@ namespace Myshipping.Application
|
|
|
|
|
it.VESSEL,
|
|
|
|
|
it.VOYNO,
|
|
|
|
|
it.MBLNO
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} BC引入更新订舱完成", batchNo, bookingOrder.Id);
|
|
|
|
|
|
|
|
|
|
if (model.IsLetterYard)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,用户选择转为入货通知,开始执行入货通知", batchNo
|
|
|
|
|
, bookingOrder.Id);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.FileTempPath))
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "执行成功";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 未提交文件路径,请求失败", batchNo
|
|
|
|
|
, bookingOrder.Id);
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah($"未提交文件路径,执行放舱失败");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var letterYardDto = new UpdateBookingLetteryardInput();
|
|
|
|
|
#region 批量BC更新订舱
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量BC更新订舱
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="batchBCList">批量BC更新列表</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
[HttpPost("/BookingValueAdded/BatchBCUpdate")]
|
|
|
|
|
public async Task<TaskManageOrderResultDto> BatchBCUpdate([FromBody]List<BatchBCDto> batchBCList)
|
|
|
|
|
{
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
List<Task<TaskManageOrderResultDto>> taskList = new List<Task<TaskManageOrderResultDto>>();
|
|
|
|
|
|
|
|
|
|
letterYardDto = model.LetteryardDto.Adapt<UpdateBookingLetteryardInput>();
|
|
|
|
|
string batchNo = IDGen.NextID().ToString();
|
|
|
|
|
|
|
|
|
|
if (model.LetterYardId.HasValue && model.LetterYardId.Value > 0)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
letterYardDto.Id = model.LetterYardId.Value;
|
|
|
|
|
var bcTaskList = batchBCList.Select(a=>a.bcPKId).Distinct().ToList();
|
|
|
|
|
var bkOrderList = batchBCList.Select(a => a.bkOrderId.Value).Distinct().ToList();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 单票BC更新订舱后,存在放舱记录 LetterYardId={LetterYardId}", batchNo
|
|
|
|
|
, bookingOrder.Id, letterYardDto.Id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var letterYardModel = _bookingLetteryardRepository.AsQueryable()
|
|
|
|
|
.First(x => x.BookingId == model.BookingOrderId);
|
|
|
|
|
var bklist = _bookingOrderRepository.AsQueryable()
|
|
|
|
|
.Where(a => bkOrderList.Contains(a.Id)).ToList();
|
|
|
|
|
|
|
|
|
|
if(letterYardModel != null)
|
|
|
|
|
letterYardDto.Id = letterYardModel.Id;
|
|
|
|
|
}
|
|
|
|
|
var bclist = _taskBCInfoRepository.AsQueryable()
|
|
|
|
|
.Where(a => bcTaskList.Contains(a.PK_ID)).ToList();
|
|
|
|
|
|
|
|
|
|
//放舱保存
|
|
|
|
|
var letterYardId = await _bookingOrderService.LetteryardSave(letterYardDto);
|
|
|
|
|
if (bklist.Count != bkOrderList.Count)
|
|
|
|
|
throw Oops.Oh($"订舱信息获取失败,订舱信息不存在或已作废");
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 已完放舱记录保存 返回结果{rlt}", batchNo
|
|
|
|
|
, bookingOrder.Id, letterYardId);
|
|
|
|
|
var noList = bklist.Select((a, idx) => new { no = idx + 1, id = a.Id }).ToList();
|
|
|
|
|
foreach (var bk in bklist)
|
|
|
|
|
{
|
|
|
|
|
var sortNo = noList.FirstOrDefault(a => a.id == bk.Id).no;
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} templateid={tempid} 开始发送放舱", batchNo
|
|
|
|
|
, bookingOrder.Id, model.TemplateId);
|
|
|
|
|
var currBC = batchBCList.Join(bclist, l => l.bcPKId, r => r.PK_ID, (l, r) => {
|
|
|
|
|
return r;
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
SingleBCDto singleBCDto = new SingleBCDto {
|
|
|
|
|
BLNo = currBC.MBL_NO,
|
|
|
|
|
Vessel = currBC.VESSEL,
|
|
|
|
|
Voyage = currBC.VOYNO,
|
|
|
|
|
ETD = currBC.ETD,
|
|
|
|
|
CYCutOffTime = currBC.CY_CUTOFF_TIME,
|
|
|
|
|
VGMCutOffTime = currBC.VGM_CUTOFF_TIME,
|
|
|
|
|
ClosingDate = currBC.CUT_SINGLE_TIME
|
|
|
|
|
};
|
|
|
|
|
taskList.Add(Task.Run(() => InnerBCUpdateBookingOrder(singleBCDto,bk, batchNo, sortNo)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//发送放舱
|
|
|
|
|
await _bookingOrderService.SendLetterYard(model.BookingOrderId, model.TemplateId);
|
|
|
|
|
Task.WaitAll(taskList.ToArray());
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} templateid={tempid} 完成发送放舱", batchNo
|
|
|
|
|
, bookingOrder.Id, model.TemplateId);
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "批量执行成功";
|
|
|
|
|
|
|
|
|
|
string fileTypeCode = "bc";
|
|
|
|
|
string fileTypeName = "Booking Confirmation";
|
|
|
|
|
var downResultList = taskList.Select(x => x.Result).ToList();
|
|
|
|
|
|
|
|
|
|
//重新将暂存文件写入正式路径
|
|
|
|
|
if (downResultList.Any(x => !x.succ))
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = "批量执行失败";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = downResultList.FirstOrDefault().msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//读取文件配置
|
|
|
|
|
var bookFilePath = await FileAttachHelper.MoveFile(bookingOrder.Id.ToString(), model.FileTempPath,batchNo);
|
|
|
|
|
result.ext = downResultList;
|
|
|
|
|
|
|
|
|
|
//将BC引入的文件写入订舱的附件
|
|
|
|
|
await SaveEDIFile(bookingOrder.Id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name,
|
|
|
|
|
fileTypeCode, fileTypeName);
|
|
|
|
|
var succ = downResultList.Count(x => x.succ);
|
|
|
|
|
var fail = downResultList.Count(x => !x.succ);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} id={id} 完成写入附件表 {filepath}", batchNo
|
|
|
|
|
, bookingOrder.Id, model.FileTempPath);
|
|
|
|
|
if (succ > 0)
|
|
|
|
|
{
|
|
|
|
|
result.batchTotal = succ.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.batchTotal = "- ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "执行成功";
|
|
|
|
|
if (fail > 0)
|
|
|
|
|
{
|
|
|
|
|
result.batchTotal += "/" + fail.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.batchTotal += " -";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = ex.Message;
|
|
|
|
|
result.msg = $"批量执行失败,原因:{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|