|
|
|
@ -0,0 +1,200 @@
|
|
|
|
|
using Furion;
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DistributedIDGenerator;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
using Furion.JsonSerialization;
|
|
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Entity;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 请求下货纸比对
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings("Application", Name = "TaskShippingOrderCompare", Order = 9)]
|
|
|
|
|
public class TaskShippingOrderCompareService : ITaskShippingOrderCompareService, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
private readonly ILogger<TaskShippingOrderCompareService> _logger;
|
|
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
|
|
|
|
|
private readonly SqlSugarRepository<BookingCtn> _bookingOrderContaRepository;
|
|
|
|
|
|
|
|
|
|
public TaskShippingOrderCompareService(ISysCacheService cache, ILogger<TaskShippingOrderCompareService> logger)
|
|
|
|
|
{
|
|
|
|
|
_cache = cache;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 执行下货纸比对
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId">订舱主键</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<TaskManageExcuteResultDto> ExcuteShippingOrderCompareAsync(string bookingId)
|
|
|
|
|
{
|
|
|
|
|
string batchNo = IDGen.NextID().ToString();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no}获取订舱数据请求规则 {id}", batchNo, bookingId);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
处理逻辑
|
|
|
|
|
1、台账触发单票下货纸比对
|
|
|
|
|
2、调取订舱的详情。
|
|
|
|
|
3、对应请求报文。
|
|
|
|
|
4、请求比对接口。
|
|
|
|
|
5、返回回执。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
TaskManageExcuteResultDto result = new TaskManageExcuteResultDto();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
var model = _bookingOrderRepository.AsQueryable().InSingle(long.Parse(bookingId));
|
|
|
|
|
|
|
|
|
|
if (model == null)
|
|
|
|
|
throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息");
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no}获取订舱数据完成", batchNo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//附主信息
|
|
|
|
|
var mainInfo = model.Adapt<TaskMessageMain>();
|
|
|
|
|
|
|
|
|
|
mainInfo.BusiPKId = model.Id.ToString();
|
|
|
|
|
|
|
|
|
|
var contaList = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == model.Id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 提取箱完成 数量={total}", batchNo, contaList.Count);
|
|
|
|
|
|
|
|
|
|
if (contaList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
mainInfo.ContaList = contaList.Adapt<List<TaskMessageCtnInfo>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var msgModel = GetMessageInfo(batchNo, mainInfo);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 对应请求报文完成 msg={msg}", batchNo, JSON.Serialize(msgModel));
|
|
|
|
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
var ruleResult = await ExcuteRulesEngine(msgModel);
|
|
|
|
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, ruleResult.succ ? "成功" : "失败");
|
|
|
|
|
|
|
|
|
|
if (ruleResult == null)
|
|
|
|
|
throw Oops.Oh($"订舱主键{bookingId}请求规则失败,返回为空");
|
|
|
|
|
|
|
|
|
|
result.succ = ruleResult.succ;
|
|
|
|
|
result.msg = ruleResult.msg;
|
|
|
|
|
result.extra = ruleResult.extra;
|
|
|
|
|
result.extra2 = ruleResult.extra2;
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 返回结果{msg}", batchNo, JSON.Serialize(result));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"请求下货纸比对异常,{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成请求规则报文
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="batchNo">批次号</param>
|
|
|
|
|
/// <param name="mainInfo">订舱主业务信息</param>
|
|
|
|
|
/// <returns>返回请求报文类</returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private TaskMessageInfoDto GetMessageInfo(string batchNo, TaskMessageMain mainInfo)
|
|
|
|
|
{
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
TaskMessageInfoDto msgModel = new TaskMessageInfoDto();
|
|
|
|
|
|
|
|
|
|
msgModel.Head = new TaskMessageHead
|
|
|
|
|
{
|
|
|
|
|
GID = batchNo,
|
|
|
|
|
MessageType = "SHIP_ORDER_COMPARE",
|
|
|
|
|
SenderId = App.Configuration["RulesEngineSender"],
|
|
|
|
|
SenderName = App.Configuration["RulesEngineSenderName"],
|
|
|
|
|
ReceiverId = "RulesEngine",
|
|
|
|
|
ReceiverName = "大简云规则引擎",
|
|
|
|
|
Version = "1.0",
|
|
|
|
|
RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
RequestAction = "Compare",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
msgModel.Main = mainInfo;
|
|
|
|
|
|
|
|
|
|
return msgModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 请求下货纸比对
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 请求下货纸比对
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="BusinessMsg"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task<TaskManageExcuteResultDto> ExcuteRulesEngine(TaskMessageInfoDto info)
|
|
|
|
|
{
|
|
|
|
|
TaskManageExcuteResultDto model = null;
|
|
|
|
|
/*
|
|
|
|
|
1、读取配置文件中的规则引擎URL
|
|
|
|
|
2、填充请求的类,并生成JSON报文
|
|
|
|
|
3、POST请求接口,并记录回执。
|
|
|
|
|
4、返回信息。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var url = App.Configuration["ShippingOrderCompareUrl"];
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var res = await url.SetHttpMethod(HttpMethod.Post)
|
|
|
|
|
.SetBody(JSON.Serialize(info), "application/json")
|
|
|
|
|
.SetContentEncoding(Encoding.UTF8)
|
|
|
|
|
.PostAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 对应请求报文完成 res={res}", info.Head.GID, JSON.Serialize(res));
|
|
|
|
|
|
|
|
|
|
if (res.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
{
|
|
|
|
|
var userResult = await res.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
model = JSON.Deserialize<TaskManageExcuteResultDto>(userResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//写日志
|
|
|
|
|
if (ex is HttpRequestException)
|
|
|
|
|
throw Oops.Oh(10000002);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|