新增BC批量引入方法

optimize
jianghaiqing 1 year ago
parent 80b9635b3c
commit 822e436edd

@ -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;
}
@ -1400,9 +1405,121 @@ namespace Myshipping.Application
*/
var bookingOrder = _bookingOrderRepository.AsQueryable().First(a => a.Id == model.BookingOrderId);
if(bookingOrder == null)
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)
{
@ -1419,7 +1536,7 @@ namespace Myshipping.Application
bookingOrder.CLOSEVGMDATE = model.VGMCutOffTime;
}
//截港日期
if (model.CYCutOffTime.HasValue)
{
@ -1436,16 +1553,16 @@ namespace Myshipping.Application
bookingOrder.ETD = model.ETD;
}
//船名
if(!string.IsNullOrWhiteSpace(model.Vessel))
if (!string.IsNullOrWhiteSpace(model.Vessel))
{
_logger.LogInformation("批次={no} id={id} 更新船名 原:{date1} 变更为 {date2}", batchNo, bookingOrder.Id,
bookingOrder.VESSEL, model.Vessel);
bookingOrder.VESSEL = model.Vessel;
}
//航次
if (!string.IsNullOrWhiteSpace(model.Voyage))
{
@ -1454,7 +1571,7 @@ namespace Myshipping.Application
bookingOrder.VOYNO = model.Voyage;
}
//提单号
if (!string.IsNullOrWhiteSpace(model.BLNo))
{
@ -1463,13 +1580,12 @@ 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))
{
_logger.LogInformation("批次={no} id={id} 未提交文件路径,请求失败", batchNo
, bookingOrder.Id);
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
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)
{
letterYardDto.Id = model.LetterYardId.Value;
try
{
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;

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// BC批量引入
/// </summary>
public class BatchBCDto
{
/// <summary>
/// BC的主键
/// </summary>
public string bcPKId { get; set; }
/// <summary>
/// 订舱主键
/// </summary>
public Nullable<long> bkOrderId { get; set; }
}
}

@ -51,5 +51,11 @@ namespace Myshipping.Application
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> SingleBCUpdateBookingOrder(SingleBCDto model);
/// <summary>
/// 批量BC更新订舱
/// </summary>
/// <param name="batchBCList">批量BC更新列表</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> BatchBCUpdate(List<BatchBCDto> batchBCList);
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
public class BookingOrderBCTaskDto: BookingOrderDto
{
/// <summary>
/// 序号
/// </summary>
public int Indx { get; set; }
/// <summary>
/// 对应BC序号
/// </summary>
public int BCIndx { get; set; }
}
}

@ -240,9 +240,15 @@ namespace Myshipping.Application
/// 集装箱列表
/// </summary>
public List<TaskBCCTNInfoDto> CtnList { get; set; }
/// <summary>
/// 顺序号
/// </summary>
public int Indx { get; set; }
/// <summary>
/// 对应订舱序号
/// </summary>
public int BKOrderIndx { get; set; }
}
}

@ -258,6 +258,10 @@ namespace Myshipping.Application
}).OrderByDescending(a => a.Sort).FirstOrDefault().OBJ.Adapt<BookingOrderBCTaskDto>();
bookingOrder.Indx = odNum;
bookingOrder.BCIndx = num;
bcInfo.BKOrderIndx = odNum;
odNum++;
tupList.Add(new Tuple<TaskBCInfoDto, BookingOrderBCTaskDto>(
@ -276,7 +280,8 @@ namespace Myshipping.Application
num++;
}
result.ext = tupList;
result.ext = tupList.Select(a=>a.Item1).ToList();
result.ext2 = tupList.Select(a => a.Item2).ToList();
}
result.succ = true;

Loading…
Cancel
Save