|
|
|
@ -25,12 +25,16 @@ using DS.WMS.Core.TaskPlat.Interface;
|
|
|
|
|
using HtmlAgilityPack;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NLog;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
{
|
|
|
|
@ -50,6 +54,11 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
private readonly IWebHostEnvironment _environment;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
|
|
|
|
|
private readonly string bcCompareUrl;
|
|
|
|
|
private readonly string bcMSKReadUrl;
|
|
|
|
|
private readonly string bcMSKModifyFileUrl;
|
|
|
|
|
private readonly string bcCMAReadUrl;
|
|
|
|
|
|
|
|
|
|
// 按需构建
|
|
|
|
|
private Lazy<IBookingSlotService> bookingSlotService;
|
|
|
|
|
private Lazy<ISeaExportService> seaExportService;
|
|
|
|
@ -66,6 +75,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
const string CONST_AUTO_TRANS_EMAIL_OP_CCTO = "AUTO_TRANS_EMAIL_OP_CCTO";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TaskManageBCService(IUser user,
|
|
|
|
|
ILogger<TaskManageBCService> logger,
|
|
|
|
|
ISaasDbService saasDbService,
|
|
|
|
@ -97,6 +107,11 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
|
|
|
|
|
tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
tenantDb.QueryFilter.Clear<IOrgId>();
|
|
|
|
|
|
|
|
|
|
bcCompareUrl = AppSetting.app(new string[] { "BCCompare", "Url" });
|
|
|
|
|
bcMSKReadUrl = AppSetting.app(new string[] { "BCCompare", "MSKBCReadUrl" });
|
|
|
|
|
bcMSKModifyFileUrl = AppSetting.app(new string[] { "BCCompare", "MSKBCModifyFileUrl" });
|
|
|
|
|
bcCMAReadUrl = AppSetting.app(new string[] { "BCCompare", "CMABCReadUrl" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -1121,12 +1136,12 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对比BC与海运出口订单(任务台使用)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<DataResult<CompareResultInfo>> CompareBcWithSeaExportTask(TaskFlowDataContext dataContext)
|
|
|
|
|
public async Task<DataResult<(bool isExistsDiff, List<CompareResultDetailInfo>)>> CompareBcWithSeaExportTask(TaskFlowDataContext dataContext)
|
|
|
|
|
{
|
|
|
|
|
var taskBcInfo = dataContext.Get<TaskBCInfo?>(TaskFlowDataNameConst.TaskBCInfo) ?? throw new ArgumentException($"缺少参数:{nameof(TaskFlowDataNameConst.TaskBCInfo)}");
|
|
|
|
|
var taskBcCtnList = dataContext.Get<List<TaskBCCTNInfo>?>(TaskFlowDataNameConst.TaskBCCtnList) ?? throw new ArgumentException($"缺少参数:{nameof(TaskFlowDataNameConst.TaskBCCtnList)}");
|
|
|
|
|
|
|
|
|
|
var seaExport = await tenantDb.Queryable<SeaExport>().Where(x => x.ParentId == 0 && taskBcInfo.MBL_NO == x.MBLNO).Select(x => new SeaExport()
|
|
|
|
|
var seaExport = await tenantDb.Queryable<SeaExport>().Where(x => x.Id == taskBcInfo.BOOKING_ORDER_ID).Select(x => new SeaExport()
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
MBLNO = x.MBLNO,
|
|
|
|
@ -1159,19 +1174,18 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
SeaExport = seaExport,
|
|
|
|
|
OpCtnList = seaExportCtnList
|
|
|
|
|
};
|
|
|
|
|
var result = await CompareBcWithSeaExport(compareDto);
|
|
|
|
|
(bool isExistsDiff, List<CompareResultDetailInfo>) result = await CompareBcWithSeaExport(compareDto);
|
|
|
|
|
|
|
|
|
|
dataContext.Set(TaskFlowDataNameConst.BcCompareWithSeaExportResult, result);
|
|
|
|
|
dataContext.Set(TaskFlowDataNameConst.BcCompareBcWithSeaExportIsExistsDiff, result.isExistsDiff);
|
|
|
|
|
|
|
|
|
|
return DataResult<CompareResultInfo>.Success(result);
|
|
|
|
|
return DataResult<(bool isExistsDiff, List<CompareResultDetailInfo>)>.Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对比BC与海运出口订单
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<CompareResultInfo> CompareBcWithSeaExport(CompareBcWithSeaExportDto compareDto)
|
|
|
|
|
public async Task<(bool isExistsDiff, List<CompareResultDetailInfo>)> CompareBcWithSeaExport(CompareBcWithSeaExportDto compareDto)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var taskBcInfo = compareDto.TaskBCInfo;
|
|
|
|
|
var taskBcCtnList = compareDto.TaskBCCtnList;
|
|
|
|
|
var seaExport = compareDto.SeaExport;
|
|
|
|
@ -1243,7 +1257,7 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
|
|
|
|
|
logger.LogInformation($"批次={batchNo} taskBcInfo.id={taskBcInfo.Id} seaExport.id={seaExport.Id} 请求BC对比订单结果完成,耗时:{timeDiff}ms,是否成功:{(compareResult?.succ == true ? "成功" : "失败")} ");
|
|
|
|
|
|
|
|
|
|
if (compareResult != null && compareResult?.succ == true)
|
|
|
|
|
if (compareResult != null)
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation($"批次={batchNo} BC对比订单结果={JsonConvert.SerializeObject(compareResult)}");
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
@ -1289,22 +1303,13 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
it.UpdateUserName
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
return new CompareResultInfo()
|
|
|
|
|
{
|
|
|
|
|
IsExistsDiff = compareResult.extra.IsExistsDiff,
|
|
|
|
|
ShowDetailList = compareResult.extra.ShowDetailList,
|
|
|
|
|
DetailList = compareResult.extra.DetailList,
|
|
|
|
|
IsSuccess = true
|
|
|
|
|
};
|
|
|
|
|
//return (compareResult.extra.IsExistsDiff, compareResult.extra.ShowDetailList);
|
|
|
|
|
|
|
|
|
|
return (compareResult.extra.IsExistsDiff, compareResult.extra.ShowDetailList);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.LogError($"批次={batchNo} BC对比订单结果为空");
|
|
|
|
|
return new CompareResultInfo()
|
|
|
|
|
{
|
|
|
|
|
IsSuccess = false
|
|
|
|
|
};
|
|
|
|
|
throw new Exception($"批次={batchNo} BC对比订单结果为空");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#region 生成并推送邮件
|
|
|
|
@ -2251,5 +2256,163 @@ namespace DS.WMS.Core.TaskPlat.Method
|
|
|
|
|
|
|
|
|
|
return await SyncBookingSlotChange(taskBaseId.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 读取BC详情
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取BC详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="carrierCode">船公司代码</param>
|
|
|
|
|
/// <param name="file">BC文件</param>
|
|
|
|
|
/// <returns>返回解析详情</returns>
|
|
|
|
|
public async Task<DataResult<ParserBCInfoDto>> GetReadBC(string carrierCode, IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
string msg = string.Empty;
|
|
|
|
|
|
|
|
|
|
var messageInfo = new
|
|
|
|
|
{
|
|
|
|
|
Head = new
|
|
|
|
|
{
|
|
|
|
|
GID = SnowFlakeSingle.Instance.NextId().ToString(),
|
|
|
|
|
MessageType = "BOOKING_GAMENDMENT",
|
|
|
|
|
SenderId = AppSetting.app(new string[] { "ExcuteRuleService", "RulesEngineSender" }),
|
|
|
|
|
SenderName = AppSetting.app(new string[] { "ExcuteRuleService", "RulesEngineSenderName" }),
|
|
|
|
|
ReceiverId = "RulesEngine",
|
|
|
|
|
ReceiverName = "大简云规则引擎",
|
|
|
|
|
Version = "1.0",
|
|
|
|
|
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
RequestAction = "ReadFile",
|
|
|
|
|
},
|
|
|
|
|
Main = new
|
|
|
|
|
{
|
|
|
|
|
TenantId = user.TenantId.ToString()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var reduceAttach = new MultipartFormDataContent())
|
|
|
|
|
{
|
|
|
|
|
var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messageInfo)));
|
|
|
|
|
|
|
|
|
|
dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data")
|
|
|
|
|
{
|
|
|
|
|
Name = "jsonData"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reduceAttach.Add(dataContent);
|
|
|
|
|
|
|
|
|
|
#region 文件参数
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
var Content = new ByteArrayContent(file.ToByteArray());
|
|
|
|
|
|
|
|
|
|
Content.Headers.Add("Content-Type", "application/json");
|
|
|
|
|
|
|
|
|
|
reduceAttach.Add(Content, "file", HttpUtility.UrlEncode(file.FileName));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var url = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (carrierCode.Equals("MSK", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
url = bcMSKReadUrl;
|
|
|
|
|
|
|
|
|
|
if (carrierCode.Equals("CMA", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
url = bcCMAReadUrl;
|
|
|
|
|
//请求
|
|
|
|
|
var response = httpClient.PostAsync(url, reduceAttach).Result;
|
|
|
|
|
string result = response.Content.ReadAsStringAsync().Result;
|
|
|
|
|
|
|
|
|
|
var model = JsonConvert.DeserializeObject<BCReadResultDto>(result);
|
|
|
|
|
|
|
|
|
|
if(model != null && model.succ)
|
|
|
|
|
{
|
|
|
|
|
var bcInfo = JsonConvert.DeserializeObject<ParserBCInfoDto>(JsonConvert.SerializeObject(model.extra));
|
|
|
|
|
|
|
|
|
|
return DataResult<ParserBCInfoDto>.Success(bcInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
msg = model.msg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, "请求BC读取详情异常,原因:{error}", ex.Message);
|
|
|
|
|
|
|
|
|
|
msg = $"请求BC读取详情异常,原因:{ex.Message}";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataResult<ParserBCInfoDto>.Failed(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 读取BC擦写后文件流
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取BC擦写后文件流
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="carrierCode">船公司代码</param>
|
|
|
|
|
/// <param name="file">BC文件</param>
|
|
|
|
|
/// <returns>返回解析详情</returns>
|
|
|
|
|
public async Task<DataResult<byte[]>> GetModifyBCFile(string carrierCode, IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
byte[] bytes;
|
|
|
|
|
|
|
|
|
|
var result = string.Empty;
|
|
|
|
|
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var reduceAttach = new MultipartFormDataContent())
|
|
|
|
|
{
|
|
|
|
|
var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(""));
|
|
|
|
|
|
|
|
|
|
dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data")
|
|
|
|
|
{
|
|
|
|
|
Name = "jsonData"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reduceAttach.Add(dataContent);
|
|
|
|
|
|
|
|
|
|
#region 文件参数
|
|
|
|
|
if (file != null)
|
|
|
|
|
{
|
|
|
|
|
var Content = new ByteArrayContent(file.ToByteArray());
|
|
|
|
|
|
|
|
|
|
Content.Headers.Add("Content-Type", "application/json");
|
|
|
|
|
|
|
|
|
|
reduceAttach.Add(Content, "file", HttpUtility.UrlEncode(file.FileName));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//请求
|
|
|
|
|
var response = httpClient.PostAsync(bcMSKModifyFileUrl, reduceAttach).Result;
|
|
|
|
|
bytes = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
return DataResult<byte[]>.Success(bytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, "请求自动变更文件内容异常,原因:{error}", ex.Message);
|
|
|
|
|
|
|
|
|
|
result = $"请求自动变更文件内容异常,原因:{ex.Message}";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<byte[]>.Failed(result);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|