|
|
|
@ -1,9 +1,13 @@
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DistributedIDGenerator;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Furion.EventBus;
|
|
|
|
|
using Furion.Extensions;
|
|
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
using Furion.JsonSerialization;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
@ -12,14 +16,17 @@ using Myshipping.Application.Service.BookingOrder.Dto;
|
|
|
|
|
using Myshipping.Application.Service.BookingSlot.Dto;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using Org.BouncyCastle.Asn1.Tsp;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
@ -34,6 +41,7 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotStock> _repStock;
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotAllocation> _repAllocation;
|
|
|
|
|
private readonly SqlSugarRepository<BookingSlotAllocationCtn> _repAllocationCtn;
|
|
|
|
|
private readonly SqlSugarRepository<BookingFile> _bookingFileRepository;
|
|
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingLog> _repBookingLog;
|
|
|
|
|
private readonly SqlSugarRepository<BookingLogDetail> _repBookingLogDetail;
|
|
|
|
@ -44,6 +52,12 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
private readonly IEventPublisher _publisher;
|
|
|
|
|
|
|
|
|
|
const string CONST_BC_FILE_CODE = "bc";
|
|
|
|
|
const string CONST_BC_FILE_NAME = "Booking Confirmation";
|
|
|
|
|
|
|
|
|
|
const string CONST_BC_NOTICE_FILE_CODE = "bc_notice";
|
|
|
|
|
const string CONST_BC_NOTICE_FILE_NAME = "Booking Confirmation Notice";
|
|
|
|
|
|
|
|
|
|
public BookingSlotService(SqlSugarRepository<BookingSlotBase> repBase,
|
|
|
|
|
SqlSugarRepository<BookingSlotCtn> repCtn,
|
|
|
|
|
SqlSugarRepository<BookingSlotStock> repStock,
|
|
|
|
@ -54,7 +68,8 @@ namespace Myshipping.Application
|
|
|
|
|
ISysCacheService cache,
|
|
|
|
|
IEventPublisher publisher,
|
|
|
|
|
SqlSugarRepository<BookingSlotAllocation> repAllocation,
|
|
|
|
|
SqlSugarRepository<BookingSlotAllocationCtn> repAllocationCtn)
|
|
|
|
|
SqlSugarRepository<BookingSlotAllocationCtn> repAllocationCtn,
|
|
|
|
|
SqlSugarRepository<BookingFile> bookingFileRepository)
|
|
|
|
|
{
|
|
|
|
|
_repBase = repBase;
|
|
|
|
|
_repCtn = repCtn;
|
|
|
|
@ -70,6 +85,7 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
_publisher = publisher;
|
|
|
|
|
_bookingfile = bookingfile;
|
|
|
|
|
_bookingFileRepository = bookingFileRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 舱位
|
|
|
|
@ -180,12 +196,99 @@ namespace Myshipping.Application
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingSlot/ApiReceive"), AllowAnonymous, ApiUser]
|
|
|
|
|
public async Task<long> ApiReceive(BookingSlotBaseApiDto dto)
|
|
|
|
|
public async Task<TaskManageOrderResultDto> ApiReceive(string jsonData, IFormFile file = null, IFormFile modifyFile = null)
|
|
|
|
|
{
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BookingSlotBaseApiDto dto = JSON.Deserialize<BookingSlotBaseApiDto>(jsonData);
|
|
|
|
|
|
|
|
|
|
DynameFileInfo bcFile = null;
|
|
|
|
|
DynameFileInfo bcNoticeFile = null;
|
|
|
|
|
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
bcFile = new DynameFileInfo
|
|
|
|
|
{
|
|
|
|
|
FileBytes = file.ToByteArray(),
|
|
|
|
|
FileName = file.FileName
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (modifyFile != null)
|
|
|
|
|
{
|
|
|
|
|
bcNoticeFile = new DynameFileInfo
|
|
|
|
|
{
|
|
|
|
|
FileBytes = file.ToByteArray(),
|
|
|
|
|
FileName = file.FileName
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var id = InnerApiReceive(dto, bcFile, bcNoticeFile).GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "成功";
|
|
|
|
|
result.ext = id;
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"失败,原因:{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 舱位接收保存、取消接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto"></param>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <param name="modifyFile"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BookingSlot/InnerApiReceive")]
|
|
|
|
|
public async Task<long> InnerApiReceive(BookingSlotBaseApiDto dto, DynameFileInfo file = null, DynameFileInfo modifyFile = null)
|
|
|
|
|
{
|
|
|
|
|
long id = 0;
|
|
|
|
|
|
|
|
|
|
//接口方法直接调用save、delete等方法会报错,可能因为非token授权登录导致,故重写一遍保存、删除代码
|
|
|
|
|
if (dto.OpType == "add" || dto.OpType == "update" || dto.OpType == "del")
|
|
|
|
|
{
|
|
|
|
|
//翻译船公司
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(dto.DataObj.CARRIERID) && string.IsNullOrWhiteSpace(dto.DataObj.CARRIER))
|
|
|
|
|
{
|
|
|
|
|
var carrierInfo = _cache.GetAllCodeCarrier().GetAwaiter().GetResult()
|
|
|
|
|
.Where(t => t.Code.Equals(dto.DataObj.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|| t.EnName.Equals(dto.DataObj.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|| t.CnName.Equals(dto.DataObj.CARRIERID, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if(carrierInfo != null)
|
|
|
|
|
{
|
|
|
|
|
dto.DataObj.CARRIER = carrierInfo.CnName?.Trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//翻译箱型代码
|
|
|
|
|
if (dto.DataObj.CtnList != null && dto.DataObj.CtnList.Count > 0 &&
|
|
|
|
|
dto.DataObj.CtnList.Any(t => string.IsNullOrWhiteSpace(t.CTNCODE)))
|
|
|
|
|
{
|
|
|
|
|
var ctnCodeList = _cache.GetAllCodeCtn().GetAwaiter().GetResult().ToList();
|
|
|
|
|
|
|
|
|
|
dto.DataObj.CtnList.ForEach(t =>
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(t.CTNALL) && string.IsNullOrWhiteSpace(t.CTNCODE))
|
|
|
|
|
{
|
|
|
|
|
var ctnCode = ctnCodeList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.Name) &&
|
|
|
|
|
a.Name.Equals(t.CTNALL, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (ctnCode != null)
|
|
|
|
|
t.CTNCODE = ctnCode?.Code;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BookingSlotBase model = null;
|
|
|
|
|
if (dto.OpType == "add")
|
|
|
|
|
{
|
|
|
|
@ -208,6 +311,33 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await InsLog("Add", model.Id, "新增舱位");
|
|
|
|
|
|
|
|
|
|
string batchNo = IDGen.NextID().ToString();
|
|
|
|
|
|
|
|
|
|
//处理附件
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
var fileFullPath = await FileAttachHelper.SaveFileDirect(model.Id.ToString(), file.FileBytes, batchNo, file.FileName, "bcfiles");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(fileFullPath))
|
|
|
|
|
{
|
|
|
|
|
//将格式单附件写入订舱的附件
|
|
|
|
|
SaveEDIFile(id, fileFullPath, file.FileName, UserManager.TENANT_ID,
|
|
|
|
|
CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (modifyFile != null)
|
|
|
|
|
{
|
|
|
|
|
var fileFullPath = await FileAttachHelper.SaveFileDirect(model.Id.ToString(), modifyFile.FileBytes, batchNo, modifyFile.FileName, "bcnoticefiles");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(fileFullPath))
|
|
|
|
|
{
|
|
|
|
|
//将格式单附件写入订舱的附件
|
|
|
|
|
SaveEDIFile(id, fileFullPath, file.FileName, UserManager.TENANT_ID,
|
|
|
|
|
CONST_BC_NOTICE_FILE_CODE, CONST_BC_NOTICE_FILE_NAME).GetAwaiter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (dto.OpType == "update")
|
|
|
|
|
{
|
|
|
|
@ -269,7 +399,6 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 插入日志(仅显示一条文本信息)
|
|
|
|
@ -704,5 +833,54 @@ namespace Myshipping.Application
|
|
|
|
|
return result.XnPagedResult();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 异步写入附件表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 异步写入附件表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="boookId">订舱ID</param>
|
|
|
|
|
/// <param name="FilePath">文件路径</param>
|
|
|
|
|
/// <param name="fileName">文件名</param>
|
|
|
|
|
/// <param name="tenantId">租户ID</param>
|
|
|
|
|
/// <param name="fileTypeCode">附件类型代码</param>
|
|
|
|
|
/// <param name="fileTypeName">附件类型名称</param>
|
|
|
|
|
/// <param name="moudle">附件模块代码</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task SaveEDIFile(long boookId, string FilePath, string fileName, long tenantId,
|
|
|
|
|
string fileTypeCode = "bc", string fileTypeName = "Booking Confirmation", string moudle = "BookingSlot")
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
直接将附件信息写入附件表
|
|
|
|
|
*/
|
|
|
|
|
//EDI文件
|
|
|
|
|
var bookFile = new BookingFile
|
|
|
|
|
{
|
|
|
|
|
Id = YitIdHelper.NextId(),
|
|
|
|
|
FileName = fileName,
|
|
|
|
|
FilePath = FilePath,
|
|
|
|
|
TypeCode = fileTypeCode,
|
|
|
|
|
TypeName = fileTypeName,
|
|
|
|
|
BookingId = boookId,
|
|
|
|
|
TenantId = tenantId,
|
|
|
|
|
Moudle = moudle
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await _bookingFileRepository.InsertAsync(bookFile);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DynameFileInfo
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 文件名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 文件二进制流
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] FileBytes { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|