|
|
|
@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Myshipping.Application.ConfigOption;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Application.Event;
|
|
|
|
|
using Myshipping.Application.Service.BookingOrder.Dto;
|
|
|
|
@ -19,6 +20,7 @@ using Myshipping.Application.Service.BookingSlot.Dto;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using MySqlX.XDevAPI.Common;
|
|
|
|
|
using NPOI.XWPF.UserModel;
|
|
|
|
|
using Org.BouncyCastle.Asn1.Tsp;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
@ -52,6 +54,7 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotAllocationCtn> _repAllocationCtn;
|
|
|
|
|
private readonly SqlSugarRepository<BookingFile> _bookingFileRepository;
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotCompare> _bookingSlotCompareRepository;
|
|
|
|
|
private readonly SqlSugarRepository<BookingOrderContact> _bookingOrderContactRepository;
|
|
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingLog> _repBookingLog;
|
|
|
|
|
private readonly SqlSugarRepository<BookingLogDetail> _repBookingLogDetail;
|
|
|
|
@ -61,6 +64,9 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
|
|
|
|
|
private readonly IEventPublisher _publisher;
|
|
|
|
|
private readonly IBookingOrderService _bookingOrderService;
|
|
|
|
|
private readonly IDjyCustomerService _djyCustomerService;
|
|
|
|
|
private readonly IBookingValueAddedService _bookingValueAddedService;
|
|
|
|
|
|
|
|
|
|
const string CONST_BC_FILE_CODE = "bc";
|
|
|
|
|
const string CONST_BC_FILE_NAME = "Booking Confirmation";
|
|
|
|
@ -83,10 +89,14 @@ namespace Myshipping.Application
|
|
|
|
|
ILogger<BookingSlotService> logger,
|
|
|
|
|
ISysCacheService cache,
|
|
|
|
|
IEventPublisher publisher,
|
|
|
|
|
IDjyCustomerService djyCustomerService,
|
|
|
|
|
SqlSugarRepository<BookingSlotAllocation> repAllocation,
|
|
|
|
|
SqlSugarRepository<BookingSlotAllocationCtn> repAllocationCtn,
|
|
|
|
|
SqlSugarRepository<BookingFile> bookingFileRepository,
|
|
|
|
|
SqlSugarRepository<BookingSlotCompare> bookingSlotCompareRepository)
|
|
|
|
|
SqlSugarRepository<BookingSlotCompare> bookingSlotCompareRepository,
|
|
|
|
|
SqlSugarRepository<BookingOrderContact> bookingOrderContactRepository,
|
|
|
|
|
IBookingOrderService bookingOrderService,
|
|
|
|
|
IBookingValueAddedService bookingValueAddedService)
|
|
|
|
|
{
|
|
|
|
|
_repBase = repBase;
|
|
|
|
|
_repCtn = repCtn;
|
|
|
|
@ -95,7 +105,7 @@ namespace Myshipping.Application
|
|
|
|
|
_repBookingLogDetail = repBookingLogDetail;
|
|
|
|
|
_repAllocation = repAllocation;
|
|
|
|
|
_repAllocationCtn = repAllocationCtn;
|
|
|
|
|
|
|
|
|
|
_djyCustomerService = djyCustomerService;
|
|
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_cache = cache;
|
|
|
|
@ -104,6 +114,9 @@ namespace Myshipping.Application
|
|
|
|
|
_bookingfile = bookingfile;
|
|
|
|
|
_bookingFileRepository = bookingFileRepository;
|
|
|
|
|
_bookingSlotCompareRepository = bookingSlotCompareRepository;
|
|
|
|
|
_bookingOrderService = bookingOrderService;
|
|
|
|
|
_bookingOrderContactRepository = bookingOrderContactRepository;
|
|
|
|
|
_bookingValueAddedService = bookingValueAddedService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 舱位
|
|
|
|
@ -1148,8 +1161,275 @@ namespace Myshipping.Application
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 生成订舱订单
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成订舱订单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model">生成订舱订单请求</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<TaskManageOrderResultDto> CreateBookingOrder(BookingGenerateDto model)
|
|
|
|
|
{
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
|
|
|
|
if (!model.SlotId.HasValue || model.SlotId.Value < 1)
|
|
|
|
|
throw Oops.Oh($"舱位ID不能为空");
|
|
|
|
|
|
|
|
|
|
var slotInfo = await _repBase.AsQueryable()
|
|
|
|
|
.FirstAsync(a => a.Id == model.SlotId.Value);
|
|
|
|
|
|
|
|
|
|
if (slotInfo == null)
|
|
|
|
|
throw Oops.Oh($"舱位信息不存在或已作废");
|
|
|
|
|
|
|
|
|
|
// 判断是否已存在引用关系
|
|
|
|
|
if (_repAllocation.IsExists(a => a.BOOKING_SLOT_ID == slotInfo.Id
|
|
|
|
|
&& a.BOOKING_ID > 0 && a.IsDeleted == false))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"舱位已有对应的订舱订单,不能重复执行");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ctnList = _repCtn.AsQueryable().Where(a => a.SLOT_ID == slotInfo.Id && a.IsDeleted == false)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var fileList = await _bookingfile.AsQueryable().Filter(null, true)
|
|
|
|
|
.Where(u => u.BookingId == slotInfo.Id && u.Moudle == "BookingSlot").ToListAsync();
|
|
|
|
|
|
|
|
|
|
var bookingOrderId = await GenerateBookingOrder(slotInfo, ctnList, fileList, model);
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "成功";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 生成订舱
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成订舱
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingSlotBase">舱位详情</param>
|
|
|
|
|
/// <param name="bookingSlotCtnList">舱位集装箱列表</param>
|
|
|
|
|
/// <param name="bookingSlotFileList">舱位附件列表</param>
|
|
|
|
|
/// <param name="generateModel">订舱请求详情</param>
|
|
|
|
|
/// <returns>返回订舱ID</returns>
|
|
|
|
|
private async Task<long> GenerateBookingOrder(BookingSlotBase bookingSlotBase, List<BookingSlotCtn> bookingSlotCtnList,
|
|
|
|
|
List<BookingFile> bookingSlotFileList,
|
|
|
|
|
BookingGenerateDto generateModel)
|
|
|
|
|
{
|
|
|
|
|
long id = 0;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
1、新增订舱
|
|
|
|
|
2、推送服务项目
|
|
|
|
|
3、推送附件
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var carrierInfo = _cache.GetAllCodeCarrier().GetAwaiter().GetResult()
|
|
|
|
|
.Where(t => t.Code.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|| t.EnName.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|| t.CnName.Equals(bookingSlotBase.CARRIERID, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
SaveBookingOrderInput bkModel = new SaveBookingOrderInput
|
|
|
|
|
{
|
|
|
|
|
CUSTOMERID = generateModel.CustomerId,
|
|
|
|
|
CUSTOMERNAME = generateModel.CustomerName,
|
|
|
|
|
CARRIERID = carrierInfo.Code?.Trim(),
|
|
|
|
|
CARRIER = carrierInfo.CnName?.Trim(),
|
|
|
|
|
MBLNO = bookingSlotBase.SLOT_BOOKING_NO.Trim(),
|
|
|
|
|
CONTRACTNO = !string.IsNullOrWhiteSpace(bookingSlotBase.CONTRACT_NO) ? bookingSlotBase.CONTRACT_NO : "",
|
|
|
|
|
VESSEL = bookingSlotBase.VESSEL.ToUpper().Trim(),
|
|
|
|
|
VOYNO = bookingSlotBase.VOYNO.ToUpper().Trim(),
|
|
|
|
|
VOYNOINNER = bookingSlotBase.VOYNO.ToUpper().Trim(),
|
|
|
|
|
ETD = bookingSlotBase.ETD,
|
|
|
|
|
ETA = bookingSlotBase.ETA,
|
|
|
|
|
SALEID = generateModel.SaleId.ToString(),
|
|
|
|
|
SALE = generateModel.SaleName,
|
|
|
|
|
OPID = generateModel.OpId.ToString(),
|
|
|
|
|
OP = generateModel.OpName,
|
|
|
|
|
DOCID = generateModel.DocId.ToString(),
|
|
|
|
|
DOC = generateModel.DocName,
|
|
|
|
|
ROUTEID = generateModel.RouteID.ToString(),
|
|
|
|
|
ROUTE = generateModel.Route,
|
|
|
|
|
CZRemark = generateModel.CZRemark,
|
|
|
|
|
ShenQingXiangShi = generateModel.ShenQingXiangShi,
|
|
|
|
|
LineManageID = generateModel.LineManageID.ToString(),
|
|
|
|
|
LineName = generateModel.LineManage,
|
|
|
|
|
CLOSEVGMDATE = bookingSlotBase.VGM_SUBMISSION_CUT_DATE,
|
|
|
|
|
CLOSINGDATE = bookingSlotBase.CY_CUT_DATE,
|
|
|
|
|
CLOSEDOCDATE = bookingSlotBase.SI_CUT_DATE,
|
|
|
|
|
ctnInputs = new List<BookingCtnDto>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList();
|
|
|
|
|
|
|
|
|
|
if (bookingSlotCtnList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
bookingSlotCtnList.ForEach(t =>
|
|
|
|
|
{
|
|
|
|
|
var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) &&
|
|
|
|
|
a.Name.Equals(t.CTNALL, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
BookingCtnDto ctn = new BookingCtnDto
|
|
|
|
|
{
|
|
|
|
|
CTNCODE = ctnCode?.Code,
|
|
|
|
|
CTNALL = t.CTNALL,
|
|
|
|
|
CTNNUM = t.CTNNUM
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bkModel.ctnInputs.Add(ctn);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bkRlt = await _bookingOrderService.Save(bkModel);
|
|
|
|
|
|
|
|
|
|
id = bkRlt.Id;
|
|
|
|
|
|
|
|
|
|
string batchNo = IDGen.NextID().ToString();
|
|
|
|
|
|
|
|
|
|
if (id > 0)
|
|
|
|
|
{
|
|
|
|
|
//这里如果指定了委托单位的邮件联系人,则推送订舱联系人
|
|
|
|
|
if (generateModel.CustomerContactList != null && generateModel.CustomerContactList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var bookingContactList = _bookingOrderContactRepository.AsQueryable()
|
|
|
|
|
.Where(a => a.BookingId == id && !a.IsDeleted).ToList();
|
|
|
|
|
|
|
|
|
|
var djyCustomerInfo = _djyCustomerService.Detail(new GetDjyCustomerInput { Id = generateModel.CustomerId.Value })
|
|
|
|
|
.GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
generateModel.CustomerContactList.ForEach(contact =>
|
|
|
|
|
{
|
|
|
|
|
DjyCustomerContactOutput djyCustomerContactMan = null;
|
|
|
|
|
|
|
|
|
|
if (djyCustomerInfo.Contacts != null && djyCustomerInfo.Contacts.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
djyCustomerContactMan = djyCustomerInfo.Contacts.FirstOrDefault(a =>
|
|
|
|
|
a.Id == contact.CustomerContactId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (djyCustomerContactMan != null)
|
|
|
|
|
{
|
|
|
|
|
var bookingContact = bookingContactList
|
|
|
|
|
.FirstOrDefault(x => x.Email.Equals(djyCustomerContactMan.Email, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (bookingContact == null)
|
|
|
|
|
{
|
|
|
|
|
bookingContact = new BookingOrderContact
|
|
|
|
|
{
|
|
|
|
|
Name = djyCustomerContactMan.Name,
|
|
|
|
|
BookingId = id,
|
|
|
|
|
Email = djyCustomerContactMan.Email,
|
|
|
|
|
Remark = djyCustomerContactMan.Remark,
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
CreatedUserId = UserManager.UserId,
|
|
|
|
|
CreatedUserName = UserManager.Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_bookingOrderContactRepository.Insert(bookingContact);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bookingContact.Name = djyCustomerContactMan.Name;
|
|
|
|
|
bookingContact.Email = djyCustomerContactMan.Email;
|
|
|
|
|
bookingContact.Remark = djyCustomerContactMan.Remark;
|
|
|
|
|
bookingContact.UpdatedTime = DateTime.Now;
|
|
|
|
|
bookingContact.UpdatedUserId = UserManager.UserId;
|
|
|
|
|
bookingContact.UpdatedUserName = UserManager.Name;
|
|
|
|
|
|
|
|
|
|
_bookingOrderContactRepository.AsUpdateable(bookingContact).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.Name,
|
|
|
|
|
it.Email,
|
|
|
|
|
it.Remark,
|
|
|
|
|
it.UpdatedTime,
|
|
|
|
|
it.UpdatedUserId,
|
|
|
|
|
it.UpdatedUserName
|
|
|
|
|
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (generateModel.ProjectList != null && generateModel.ProjectList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
ModifyServiceProjectDto projectDto = new ModifyServiceProjectDto
|
|
|
|
|
{
|
|
|
|
|
BookingId = id,
|
|
|
|
|
ProjectCodes = generateModel.ProjectList.Distinct().ToArray(),
|
|
|
|
|
};
|
|
|
|
|
//写入服务项目
|
|
|
|
|
var prjRlt = await _bookingValueAddedService.SaveServiceProject(projectDto);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"推送订舱的服务项目完成 id={id} rlt={JSON.Serialize(prjRlt)}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
var dirAbs = opt.basePath;
|
|
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
|
|
{
|
|
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bookingSlotFileList.Any(a => a.TypeCode.Equals("bc", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var file = bookingSlotFileList.OrderByDescending(a => a.CreatedTime)
|
|
|
|
|
.FirstOrDefault(a => a.TypeCode.Equals("bc", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
var fileFullPath = Path.Combine(dirAbs, file.FilePath);
|
|
|
|
|
|
|
|
|
|
if (File.Exists(fileFullPath))
|
|
|
|
|
{
|
|
|
|
|
//如果确认文件读取成功
|
|
|
|
|
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo
|
|
|
|
|
, false, null, true).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
//将格式单附件写入订舱的附件
|
|
|
|
|
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, file.TenantId.Value,
|
|
|
|
|
CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bookingSlotFileList.Any(a => a.TypeCode.Equals("bc_notice", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var file = bookingSlotFileList.OrderByDescending(a => a.CreatedTime)
|
|
|
|
|
.FirstOrDefault(a => a.TypeCode.Equals("bc_notice", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
var fileFullPath = Path.Combine(dirAbs, file.FilePath);
|
|
|
|
|
|
|
|
|
|
if (File.Exists(fileFullPath))
|
|
|
|
|
{
|
|
|
|
|
//如果确认文件读取成功
|
|
|
|
|
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo
|
|
|
|
|
, false, "bcnoticefile", true).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
//将格式单附件写入订舱的附件
|
|
|
|
|
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, file.TenantId.Value,
|
|
|
|
|
CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"MBLNO:{bookingSlotBase.SLOT_BOOKING_NO} 生成订舱订单成功 id={id}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"MBLNO:{bookingSlotBase.SLOT_BOOKING_NO} 生成订舱订单异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class DynameFileInfo
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|