修改舱位接口

修改BC任务
optimize
jianghaiqing 10 months ago
parent d083ee3cc2
commit 145b0358d6

@ -306,5 +306,83 @@ namespace Myshipping.Application
return bookFilePath;
}
#endregion
#region 保存文件并返回文件完整路径
/// <summary>
/// 保存文件并返回文件完整路径
/// </summary>
/// <param name="fileDictKey">文件目录KEY</param>
/// <param name="fileBytes">文件二进制流</param>
/// <param name="batchNo">批次号</param>
/// <param name="fileName">文件名称</param>
/// <param name="attachFileType">附件类型 bcfiles-BC文件 sofile-订舱附件</param>
/// <returns>返回文件完整路径</returns>
public static async Task<string> SaveFileDirect(string fileDictKey, byte[] fileBytes, string batchNo,
string fileName,string attachFileType = "sofiles")
{
var logger = Log.CreateLogger(nameof(FileAttachHelper));
var fileCfg = App.GetOptions<BookingAttachOptions>();
string fileRoot = string.Empty;
if (fileCfg != null)
{
if (!string.IsNullOrWhiteSpace(fileCfg.basePath))
{
fileRoot = fileCfg.basePath;
}
}
if (string.IsNullOrWhiteSpace(fileRoot))
fileRoot = App.WebHostEnvironment.WebRootPath;
string relativePath = fileCfg.relativePath;
if (!string.IsNullOrWhiteSpace(attachFileType))
relativePath += $"\\{attachFileType}";
if (!string.IsNullOrWhiteSpace(fileDictKey))
relativePath += $"\\{fileDictKey}";
relativePath += $"\\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}";
string filePath = $"{fileRoot}\\{relativePath}";
string fileFullName = $"{filePath}\\{fileName}";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
relativePath = relativePath.Replace("\\", "/");
filePath = filePath.Replace("\\", "/");
fileFullName = fileFullName.Replace("\\", "/");
}
logger.LogInformation("批次={no} 生成文件保存路径完成 路由={filePath} 服务器系统={system}", batchNo, filePath,
RuntimeInformation.OSDescription);
//预先创建目录
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
await File.WriteAllBytesAsync(fileFullName, fileBytes);
string bookFilePath = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
bookFilePath = System.Text.RegularExpressions.Regex.Match(fileFullName, relativePath.Replace("/", "\\/") + ".*").Value;
}
else
{
bookFilePath = System.Text.RegularExpressions.Regex.Match(fileFullName, relativePath.Replace("\\", "\\\\") + ".*").Value;
}
return bookFilePath;
}
#endregion
}
}

@ -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; }
}
}

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Myshipping.Application.Entity;
using Myshipping.Application.Event;
using Myshipping.Application.Service.BookingSlot.Dto;
@ -9,7 +10,15 @@ namespace Myshipping.Application
{
public interface IBookingSlotService
{
Task<long> ApiReceive(BookingSlotBaseApiDto dto);
/// <summary>
/// 舱位接收保存、取消接口
/// </summary>
/// <param name="jsonData">请求详情</param>
/// <param name="file">BC附件</param>
/// <param name="modifyFile">BC变更附件</param>
/// <returns></returns>
Task<TaskManageOrderResultDto> ApiReceive(string jsonData, IFormFile file = null, IFormFile modifyFile = null);
Task<BookingSlotBaseSaveOutput> Detail(long id);
Task<List<BookingSlotBaseWithCtnDto>> GetAvailableSlots(BookingSlotBaseDto input);
@ -55,5 +64,15 @@ namespace Myshipping.Application
/// <param name="input"></param>
/// <returns></returns>
Task<dynamic> Page(BookingSlotBasePageInput input);
/// <summary>
/// 舱位接收保存、取消接口
/// </summary>
/// <param name="dto"></param>
/// <param name="file"></param>
/// <param name="modifyFile"></param>
/// <returns></returns>
Task<long> InnerApiReceive(BookingSlotBaseApiDto dto, DynameFileInfo file = null, DynameFileInfo modifyFile = null);
}
}

@ -361,5 +361,6 @@ namespace Myshipping.Application
/// 订舱确认时间
/// </summary>
public Nullable<DateTime> BookingConfirmDate { get; set; }
}
}

@ -957,52 +957,42 @@ namespace Myshipping.Application
});
}
id = await _bookingSlotService.ApiReceive(slotModel);
var opt = App.GetOptions<BookingAttachOptions>();
var dirAbs = opt.basePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
string batchNo = IDGen.NextID().ToString();
DynameFileInfo dynameFile = null;
DynameFileInfo dynameNoticeFile = null;
//成功后写入附件
if (id > 0)
if (taskFileList.Any(t => t.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString()))
{
var opt = App.GetOptions<BookingAttachOptions>();
var dirAbs = opt.basePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
var fileInfo = taskFileList.FirstOrDefault(t => t.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString());
var fileFullPath = Path.Combine(dirAbs, fileInfo.FILE_PATH);
taskFileList.ForEach(file =>
dynameFile = new DynameFileInfo
{
if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString())
{
var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH);
FileBytes = File.ReadAllBytes(fileFullPath),
FileName = Path.GetFileName(fileFullPath)
};
}
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo, false, "bcfiles", true).GetAwaiter().GetResult();
if (taskFileList.Any(t => t.FILE_CATEGORY == TaskFileCategoryEnum.BC_NOTICE.ToString()))
{
var fileInfo = taskFileList.FirstOrDefault(t => t.FILE_CATEGORY == TaskFileCategoryEnum.BC.ToString());
var fileFullPath = Path.Combine(dirAbs, fileInfo.FILE_PATH);
//将格式单附件写入订舱的附件
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value,
CONST_BC_FILE_CODE, CONST_BC_FILE_NAME).GetAwaiter();
}
}
else if (file.FILE_CATEGORY == TaskFileCategoryEnum.BC_NOTICE.ToString())
{
var fileFullPath = Path.Combine(dirAbs, file.FILE_PATH);
dynameNoticeFile = new DynameFileInfo
{
FileBytes = File.ReadAllBytes(fileFullPath),
FileName = Path.GetFileName(fileFullPath)
};
}
if (File.Exists(fileFullPath))
{
//如果确认文件读取成功
var bookFilePath = FileAttachHelper.MoveFile(id.ToString(), fileFullPath, batchNo,false,"bcnoticefile",true).GetAwaiter().GetResult();
id = await _bookingSlotService.InnerApiReceive(slotModel, dynameFile, dynameNoticeFile);
//将格式单附件写入订舱的附件
SaveEDIFile(id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name, taskBCInfo.TenantId.Value,
CONST_BC_NOTICE_FILE_CODE, CONST_BC_NOTICE_FILE_NAME).GetAwaiter();
}
}
});
}
}
catch (Exception ex)
{
@ -1368,7 +1358,7 @@ namespace Myshipping.Application
string filePath = string.Empty;
//读取邮件模板并填充数据
string emailHtml = GenerateSendEmailHtml(taskBCInfo).GetAwaiter().GetResult();
string emailHtml = GenerateSendEmailHtml(taskBCInfo, UserManager.TENANT_NAME).GetAwaiter().GetResult();
_logger.LogInformation($"生成邮件BODY结果{emailHtml}");
@ -1406,6 +1396,7 @@ namespace Myshipping.Application
_logger.LogInformation($"生成请求邮件参数,结果:{JSON.Serialize(emailApiUserDefinedDto)}");
//推送邮件
var emailRlt = await PushEmail(emailApiUserDefinedDto, filePath);
@ -1431,8 +1422,9 @@ namespace Myshipping.Application
/// 通过邮件模板生成HTML
/// </summary>
/// <param name="taskBCInfo">BC任务详情</param>
/// <param name="tenantName">当前租户全称</param>
/// <returns>返回生成的HTML</returns>
public async Task<string> GenerateSendEmailHtml(TaskBCInfo taskBCInfo)
public async Task<string> GenerateSendEmailHtml(TaskBCInfo taskBCInfo,string tenantName)
{
string result = string.Empty;
@ -1465,43 +1457,59 @@ namespace Myshipping.Application
{
var tdList = baseTr.SelectNodes(".//td");
foreach (var baseTd in tdList)
if (baseTr.Attributes["class"].Value == "email-noreply")
{
if (baseTd.Attributes["class"].Value == "billno-val")
{
baseTd.InnerHtml = taskBCInfo.MBL_NO;
}
else if (baseTd.Attributes["class"].Value == "takebillno-val")
foreach (var baseTd in tdList)
{
baseTd.InnerHtml = taskBCInfo.MBL_NO;
}
else if (baseTd.Attributes["class"].Value == "pol-val")
{
baseTd.InnerHtml = taskBCInfo.PLACERECEIPT;
}
else if (baseTd.Attributes["class"].Value == "pod-val")
{
baseTd.InnerHtml = taskBCInfo.PLACEDELIVERY;
}
else if (baseTd.Attributes["class"].Value == "ctn-val")
{
baseTd.InnerHtml = taskBCInfo.CTN_STAT;
}
else if (baseTd.Attributes["class"].Value == "etd-val")
{
if (taskBCInfo.ETD.HasValue)
if (baseTd.Attributes["class"].Value == "notice-comp-val")
{
baseTd.InnerHtml = taskBCInfo.ETD.Value.ToString("yyyy-MM-dd");
baseTd.InnerHtml = tenantName;
}
}
else if (baseTd.Attributes["class"].Value == "eta-val")
}
else
{
foreach (var baseTd in tdList)
{
if (taskBCInfo.ETA.HasValue)
if (baseTd.Attributes["class"].Value == "billno-val")
{
baseTd.InnerHtml = taskBCInfo.MBL_NO;
}
else if (baseTd.Attributes["class"].Value == "takebillno-val")
{
baseTd.InnerHtml = taskBCInfo.MBL_NO;
}
else if (baseTd.Attributes["class"].Value == "pol-val")
{
baseTd.InnerHtml = taskBCInfo.PLACERECEIPT;
}
else if (baseTd.Attributes["class"].Value == "pod-val")
{
baseTd.InnerHtml = taskBCInfo.PLACEDELIVERY;
}
else if (baseTd.Attributes["class"].Value == "ctn-val")
{
baseTd.InnerHtml = taskBCInfo.ETA.Value.ToString("yyyy-MM-dd");
baseTd.InnerHtml = taskBCInfo.CTN_STAT;
}
else if (baseTd.Attributes["class"].Value == "etd-val")
{
if (taskBCInfo.ETD.HasValue)
{
baseTd.InnerHtml = taskBCInfo.ETD.Value.ToString("yyyy-MM-dd");
}
}
else if (baseTd.Attributes["class"].Value == "eta-val")
{
if (taskBCInfo.ETA.HasValue)
{
baseTd.InnerHtml = taskBCInfo.ETA.Value.ToString("yyyy-MM-dd");
}
}
}
}
}
result = html.DocumentNode.OuterHtml;

@ -1184,7 +1184,7 @@ namespace Myshipping.Application
_logger.LogInformation("任务台账权限范围 {list}", userlist);
var entities = await _taskBaseInfoRepository.AsQueryable()
.Where(t=> userlist.Contains(t.CreatedUserId))
.Where(t=> userlist.Contains(t.CreatedUserId) || t.IS_PUBLIC == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), t => mblList.Contains(t.MBL_NO))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), t => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim()))
.WhereIF(etdBegin != DateTime.MinValue, t => t.ETD.HasValue && t.ETD.Value >= etdBegin)

Loading…
Cancel
Save