|
|
|
@ -30,9 +30,11 @@ using SqlSugar;
|
|
|
|
|
using StackExchange.Profiling.Internal;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Security.Principal;
|
|
|
|
@ -1664,7 +1666,7 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
if (fileInfo == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"提取订舱的Booking Confirmation Notice文件失败,不能发送邮件");
|
|
|
|
|
throw Oops.Oh($"提取变更文件失败,不能发送邮件");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"获取订舱附件地址,结果:{fileInfo.FILE_PATH}");
|
|
|
|
@ -2611,6 +2613,320 @@ namespace Myshipping.Application
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重新比对
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="taskPKId">BC任务主键</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/TaskManageBC/ReCompareResult")]
|
|
|
|
|
public async Task ReCompareResult(string taskPKId)
|
|
|
|
|
{
|
|
|
|
|
List<CompareResultDetailInfo> list = new List<CompareResultDetailInfo>();
|
|
|
|
|
/*
|
|
|
|
|
1、判断舱位是否存在,如果舱位不存在终止重新比对。
|
|
|
|
|
2、获取BookingConfirmation任务,如果不存在终止。
|
|
|
|
|
3、调取BookingConfirmation文件识别结果,与当前任务的文件识别重新比对。
|
|
|
|
|
4、更新到对应的舱位
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var baseTask = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskPKId);
|
|
|
|
|
|
|
|
|
|
if (baseTask == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"未提取有效的任务信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (baseTask.TASK_TYPE != TaskBaseTypeEnum.BC_MODIFY.ToString())
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"任务类型不是Amendment不能重新比对");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bcTaskInfo = _taskBCInfoRepository.AsQueryable().First(a => a.TASK_ID == taskPKId);
|
|
|
|
|
|
|
|
|
|
if (bcTaskInfo == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"未提取有效的BC任务信息");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long slotId = 0;
|
|
|
|
|
string reqBatchNo = bcTaskInfo.BATCH_NO;
|
|
|
|
|
|
|
|
|
|
var server = _namedBookingSlotServiceProvider.GetService<ITransient>(nameof(BookingSlotService));
|
|
|
|
|
|
|
|
|
|
//没有舱位先要匹配舱位,才能比对
|
|
|
|
|
if (!bcTaskInfo.BOOKING_SLOT_ID.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var searchInfo = await server.SearchBookingSlotWithOrderByNo(bcTaskInfo.MBL_NO);
|
|
|
|
|
|
|
|
|
|
if (searchInfo != null)
|
|
|
|
|
{
|
|
|
|
|
if (searchInfo.HasBookingOrder)
|
|
|
|
|
{
|
|
|
|
|
bcTaskInfo.BOOKING_SLOT_ID = searchInfo.BookingSlotId;
|
|
|
|
|
bcTaskInfo.BOOKING_ORDER_ID = searchInfo.BookingOrderList.FirstOrDefault();
|
|
|
|
|
bcTaskInfo.UpdatedTime = DateTime.Now;
|
|
|
|
|
bcTaskInfo.UpdatedUserId = UserManager.UserId;
|
|
|
|
|
bcTaskInfo.UpdatedUserName = UserManager.Name;
|
|
|
|
|
|
|
|
|
|
await _taskBCInfoRepository.AsUpdateable(bcTaskInfo).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.BOOKING_SLOT_ID,
|
|
|
|
|
it.BOOKING_ORDER_ID,
|
|
|
|
|
it.UpdatedTime,
|
|
|
|
|
it.UpdatedUserId,
|
|
|
|
|
it.UpdatedUserName
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bcTaskInfo.BOOKING_SLOT_ID = searchInfo.BookingSlotId;
|
|
|
|
|
bcTaskInfo.UpdatedTime = DateTime.Now;
|
|
|
|
|
bcTaskInfo.UpdatedUserId = UserManager.UserId;
|
|
|
|
|
bcTaskInfo.UpdatedUserName = UserManager.Name;
|
|
|
|
|
|
|
|
|
|
await _taskBCInfoRepository.AsUpdateable(bcTaskInfo).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.BOOKING_SLOT_ID,
|
|
|
|
|
it.UpdatedTime,
|
|
|
|
|
it.UpdatedUserId,
|
|
|
|
|
it.UpdatedUserName
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bcInfo = _taskBaseRepository.AsQueryable().Filter(null, true).Where(a => a.MBL_NO == bcTaskInfo.MBL_NO && a.CARRIER_ID == bcTaskInfo.CARRIERID
|
|
|
|
|
&& a.TASK_TYPE == TaskBaseTypeEnum.BC.ToString() && a.IsDeleted == false && a.TenantId == UserManager.TENANT_ID).First();
|
|
|
|
|
|
|
|
|
|
if (bcInfo == null)
|
|
|
|
|
throw Oops.Oh($"未检索到对应的BC任务");
|
|
|
|
|
|
|
|
|
|
var modifyFile = _taskFileRepository.AsQueryable().First(a => a.TASK_PKID == taskPKId && a.FILE_CATEGORY == "BC_MODIFY");
|
|
|
|
|
|
|
|
|
|
if(modifyFile == null)
|
|
|
|
|
throw Oops.Oh($"未获取到当前任务的文件信息");
|
|
|
|
|
|
|
|
|
|
var bcFile = _taskFileRepository.AsQueryable().First(a => a.TASK_PKID == bcInfo.PK_ID && a.FILE_CATEGORY == "BC");
|
|
|
|
|
|
|
|
|
|
if (bcFile == null)
|
|
|
|
|
throw Oops.Oh($"未获取到当前任务对应BC的文件信息");
|
|
|
|
|
|
|
|
|
|
var modifyFileName = Path.GetFileName(modifyFile.FILE_PATH);
|
|
|
|
|
var bcFileName = Path.GetFileName(bcFile.FILE_PATH);
|
|
|
|
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
var dirAbs = opt.basePath;
|
|
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
|
|
{
|
|
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var modifyFileFullPath = Path.Combine(dirAbs, modifyFile.FILE_PATH);
|
|
|
|
|
if (!File.Exists(modifyFileFullPath))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh("Amendment 文件提取失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bcFileFullPath = Path.Combine(dirAbs, bcFile.FILE_PATH);
|
|
|
|
|
if (!File.Exists(bcFileFullPath))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh("BC 文件提取失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskBCInfoReadDto modifyBCReadInfo = await GetBCReaderInfo(modifyFileFullPath, modifyFileName, UserManager.TENANT_ID, taskPKId, App.Configuration["BookingAmendReadWebApiUrl"]);
|
|
|
|
|
|
|
|
|
|
if (modifyBCReadInfo == null)
|
|
|
|
|
throw Oops.Oh($"重新读取BC变更文件详情失败");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TaskBCInfoReadDto BCReadInfo = await GetBCReaderInfo(bcFileFullPath, bcFileName, UserManager.TENANT_ID, taskPKId, App.Configuration["BCReadWebApiUrl"]);
|
|
|
|
|
|
|
|
|
|
if (BCReadInfo == null)
|
|
|
|
|
throw Oops.Oh($"重新读取BC文件详情失败");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TaskBCInfoDto bcSrcDto = BCReadInfo.Adapt<TaskBCInfoDto>();
|
|
|
|
|
TaskBCInfoDto bcTargetDto = modifyBCReadInfo.Adapt<TaskBCInfoDto>();
|
|
|
|
|
|
|
|
|
|
if (BCReadInfo.CtnList != null && BCReadInfo.CtnList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
bcSrcDto.CtnList = BCReadInfo.CtnList.GroupBy(x => x.CtnALL)
|
|
|
|
|
.Select(x =>
|
|
|
|
|
{
|
|
|
|
|
return new TaskBCCTNInfoDto
|
|
|
|
|
{
|
|
|
|
|
CtnALL = x.Key,
|
|
|
|
|
CTNNUM = x.ToList()
|
|
|
|
|
.Sum(a => a.CTNNUM)
|
|
|
|
|
};
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (modifyBCReadInfo.CtnList != null && modifyBCReadInfo.CtnList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
bcTargetDto.CtnList = modifyBCReadInfo.CtnList.GroupBy(x => x.CtnALL)
|
|
|
|
|
.Select(x =>
|
|
|
|
|
{
|
|
|
|
|
return new TaskBCCTNInfoDto
|
|
|
|
|
{
|
|
|
|
|
CtnALL = x.Key,
|
|
|
|
|
CTNNUM = x.ToList()
|
|
|
|
|
.Sum(a => a.CTNNUM)
|
|
|
|
|
};
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"触发比对差异开始,reqBatchNo={reqBatchNo}");
|
|
|
|
|
|
|
|
|
|
//比对差异
|
|
|
|
|
await server.PushCompareBCInfo(bcSrcDto, bcTargetDto, slotId, reqBatchNo);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"触发比对差异结束,reqBatchNo={reqBatchNo}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 读BC详情详情
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读BC详情详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="attachFullName">文件完整路径</param>
|
|
|
|
|
/// <param name="fileName">文件名称</param>
|
|
|
|
|
/// <param name="tenantId">所属租户</param>
|
|
|
|
|
/// <param name="taskPKId">任务ID</param>
|
|
|
|
|
/// <param name="url">请求URL</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private async Task<TaskBCInfoReadDto> GetBCReaderInfo(string attachFullName, string fileName, long tenantId,string taskPKId,string url)
|
|
|
|
|
{
|
|
|
|
|
TaskBCInfoReadDto taskBCInfoReadDto = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
EmailBCReadMessageInfo messageInfo = new EmailBCReadMessageInfo
|
|
|
|
|
{
|
|
|
|
|
Head = new TaskMessageHead
|
|
|
|
|
{
|
|
|
|
|
GID = IDGen.NextID().ToString(),
|
|
|
|
|
MessageType = "BOOKING_AMENDMENT",
|
|
|
|
|
SenderId = "DJY",
|
|
|
|
|
SenderName = "新大简云",
|
|
|
|
|
ReceiverId = "RulesEngine",
|
|
|
|
|
ReceiverName = "大简云规则引擎",
|
|
|
|
|
Version = "1.0",
|
|
|
|
|
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
RequestAction = "ReadFile",
|
|
|
|
|
},
|
|
|
|
|
Main = new EmailBCReadMessageMainInfo
|
|
|
|
|
{
|
|
|
|
|
TenantId = tenantId > 0 ? tenantId.ToString() : ""
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NameValueCollection par = new NameValueCollection();
|
|
|
|
|
par.Add("jsonData", JSON.Serialize(messageInfo));
|
|
|
|
|
|
|
|
|
|
//解析BookingAmendment
|
|
|
|
|
var compareRlt = await ExcuteReadFile(par, url,new
|
|
|
|
|
{
|
|
|
|
|
file = "file",
|
|
|
|
|
fileName = fileName,
|
|
|
|
|
fileBytes = File.ReadAllBytes(attachFullName)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"读取BC附件详情 taskPKId={taskPKId},compareRlt={JSON.Serialize(compareRlt)}");
|
|
|
|
|
|
|
|
|
|
if (compareRlt.succ)
|
|
|
|
|
{
|
|
|
|
|
taskBCInfoReadDto = JSON.Deserialize<TaskBCInfoReadDto>(JSON.Serialize(compareRlt.extra));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"读取BC附件详情异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return taskBCInfoReadDto;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 请求BookingAmendment解析
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 请求BookingAmendment解析
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="nameValueCollection">请求参数</param>
|
|
|
|
|
/// <param name="url">请求url</param>
|
|
|
|
|
/// <param name="fileInfo">文件</param>
|
|
|
|
|
/// <param name="contentType">请求类型</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task<ParserReaderExcuteResultDto> ExcuteReadFile(NameValueCollection nameValueCollection, string url,dynamic fileInfo,
|
|
|
|
|
string contentType = "application/json")
|
|
|
|
|
{
|
|
|
|
|
ParserReaderExcuteResultDto model = null;
|
|
|
|
|
var result = string.Empty;
|
|
|
|
|
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var reduceAttach = new MultipartFormDataContent())
|
|
|
|
|
{
|
|
|
|
|
string[] allKeys = nameValueCollection.AllKeys;
|
|
|
|
|
foreach (string key in allKeys)
|
|
|
|
|
{
|
|
|
|
|
var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(nameValueCollection[key]));
|
|
|
|
|
|
|
|
|
|
dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data")
|
|
|
|
|
{
|
|
|
|
|
Name = key
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reduceAttach.Add(dataContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 文件参数
|
|
|
|
|
if (fileInfo != null)
|
|
|
|
|
{
|
|
|
|
|
var Content = new ByteArrayContent(fileInfo.fileBytes);
|
|
|
|
|
|
|
|
|
|
//Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
|
|
|
|
//{
|
|
|
|
|
// Name = fileInfo.file.ToString(),
|
|
|
|
|
// FileName = fileInfo.fileName.ToString(),
|
|
|
|
|
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
Content.Headers.Add("Content-Type", contentType);
|
|
|
|
|
|
|
|
|
|
reduceAttach.Add(Content, fileInfo.file.ToString(), HttpUtility.UrlEncode(fileInfo.fileName.ToString()));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//httpClient.DefaultRequestHeaders.Add("USER_KEY", App.Configuration["ApiUserKey"]);
|
|
|
|
|
//httpClient.DefaultRequestHeaders.Add("USER_SECRET", App.Configuration["ApiUserSecret"]);
|
|
|
|
|
//请求
|
|
|
|
|
var response = httpClient.PostAsync(url, reduceAttach).Result;
|
|
|
|
|
result = response.Content.ReadAsStringAsync().Result;
|
|
|
|
|
|
|
|
|
|
model = JSON.Deserialize<ParserReaderExcuteResultDto>(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("请求读取BC附件详情读取详情异常,原因:{error}", ex.Message);
|
|
|
|
|
|
|
|
|
|
throw Oops.Oh($"请求读取BC附件详情读取详情异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|