新增加下货纸比对功能

optimize
jianghaiqing 2 years ago
parent d393d84dbf
commit 1ba73bab0d

@ -0,0 +1,158 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
///
/// </summary>
public class TaskManageExcuteResultDto
{
/// <summary>
/// 是否成功 true=成功 false=失败
/// </summary>
public bool succ { get; set; } = false;
/// <summary>
/// 状态 0-成功
/// </summary>
public int status { get; set; } = 0;
/// <summary>
/// 返回消息
/// </summary>
public string msg { get; set; }
/// <summary>
/// 总记录数
/// </summary>
public int total { get; set; }
/// <summary>
/// 比对详情
/// </summary>
public CompareResultDetailInfo extra { get; set; }
/// <summary>
/// 比对展示详情
/// </summary>
public List<CompareResultDetailInfo> extra2 { get; set; }
}
public class CompareResultInfo
{
/// <summary>
/// 原数据主键(请求方业务主键)
/// </summary>
public string OrigPKId { get; set; }
/// <summary>
/// 原数据主单号
/// </summary>
public string MBlNo { get; set; }
/// <summary>
/// 是否存在差异 true-存在差异 false-一致
/// </summary>
public bool IsExistsDiff { get; set; } = false;
/// <summary>
/// 比较时间
/// </summary>
public DateTime CompareTime { get; set; }
/// <summary>
/// 明细
/// </summary>
public List<CompareResultDetailInfo> DetailList { get; set; }
/// <summary>
/// 展示明细
/// </summary>
public List<CompareResultDetailInfo> ShowDetailList { get; set; }
}
/// <summary>
///
/// </summary>
public class CompareResultDetailInfo
{
/// <summary>
/// 字段代码
/// </summary>
public string FieldCode { get; set; }
/// <summary>
/// 字段名称
/// </summary>
public string FieldName { get; set; }
/// <summary>
/// 请求值
/// </summary>
public string ReqVal { get; set; }
/// <summary>
/// 目标值
/// </summary>
public string TargetVal { get; set; }
/// <summary>
/// 是否比对一致 false-一致 true-比对不一致
/// </summary>
public bool IsDiff { get; set; }
/// <summary>
/// 排序值
/// </summary>
public int Sort { get; set; }
/// <summary>
/// 合并KEY
/// </summary>
public string MergeGroupKey { get; set; }
/// <summary>
/// 合并排序值
/// </summary>
public int MergeSort { get; set; }
/// <summary>
/// 是否显示
/// </summary>
public bool IsDisplay { get; set; }
/// <summary>
/// 主键KEY(只有明细比较才有值)
/// </summary>
public string PrimaryKey { get; set; }
/// <summary>
/// 合并HTML(这里可以直接适用此数据网页展示)
/// </summary>
public string MergeHtml { get; set; }
/// <summary>
/// 合并分割符
/// </summary>
public string MergeBeforeSplit { get; set; }
/// <summary>
/// 提示内容
/// </summary>
public string Msg { get; set; }
/// <summary>
/// 父节点代码
/// </summary>
public string PCode { get; set; }
/// <summary>
/// 是否主键
/// </summary>
public bool IsPrimaryKey { get; set; }
}
}

@ -0,0 +1,329 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
public class TaskMessageInfoDto
{
/// <summary>
/// 表头
/// </summary>
public TaskMessageHead Head { get; set; }
/// <summary>
/// 表体
/// </summary>
public TaskMessageMain Main { get; set; }
}
/// <summary>
/// 报文表体
/// </summary>
public class TaskMessageMain
{
/// <summary>
/// 业务惟一主键
/// </summary>
public string BusiPKId { get; set; }
/// <summary>
/// 用户ID
/// </summary>
public string UserId { get; set; }
/// <summary>
/// 用户名称
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 用户邮件
/// </summary>
public string UserEmail { get; set; }
/// <summary>
/// 租户ID
/// </summary>
public string TenantId { get; set; }
/// <summary>
/// 租户名称
/// </summary>
public string TenantName { get; set; }
/// <summary>
/// 场站代码
/// </summary>
public string YardCode { get; set; }
/// <summary>
/// 场站中文名称
/// </summary>
public string YardCName { get; set; }
/// <summary>
/// 船名英文名
/// </summary>
public string VesselName { get; set; }
/// <summary>
/// 船名中文名
/// </summary>
public string VesselCName { get; set; }
/// <summary>
/// 航次号
/// </summary>
public string VoyNo { get; set; }
/// <summary>
/// 主提单号
/// </summary>
public string MasterBlNo { get; set; }
/// <summary>
/// 分提单号
/// </summary>
public string HouseBlNo { get; set; }
/// <summary>
/// 订舱编号
/// </summary>
public string BookingNo { get; set; }
/// <summary>
/// 起运港代码
/// </summary>
public string PortLoadId { get; set; }
/// <summary>
/// 起运港
/// </summary>
public string PortLoad { get; set; }
/// <summary>
/// 卸货港代码
/// </summary>
public string PortDischargeId { get; set; }
/// <summary>
/// 卸货港
/// </summary>
public string PortDischarge { get; set; }
/// <summary>
/// 中转港代码
/// </summary>
public string TransportId { get; set; }
/// <summary>
/// 中转港
/// </summary>
public string Transport { get; set; }
/// <summary>
/// 交货地代码
/// </summary>
public string PlaceDeliveryId { get; set; }
/// <summary>
/// 交货地
/// </summary>
public string PlaceDelivery { get; set; }
/// <summary>
/// 件数
/// </summary>
public Int32 PKGs { get; set; }
/// <summary>
/// 毛重
/// </summary>
public Nullable<decimal> KGs { get; set; }
/// <summary>
/// 尺码
/// </summary>
public Nullable<decimal> CBM { get; set; }
/// <summary>
/// 主等级(危险品)
/// </summary>
public string DClass { get; set; }
/// <summary>
/// 国际危险品编号(危险品)
/// </summary>
public string DUNNo { get; set; }
/// <summary>
/// 副等级(危险品)
/// </summary>
public string FuDClass { get; set; }
/// <summary>
/// 副国际危险品编号(危险品)
/// </summary>
public string FuDUNNo { get; set; }
/// <summary>
/// 海污(危险品)
/// </summary>
public string HaiWu { get; set; }
/// <summary>
/// 温度(冻柜)
/// </summary>
public string TempSet { get; set; }
/// <summary>
/// 通风(冻柜)
/// </summary>
public string Reeferf { get; set; }
/// <summary>
/// 湿度(冻柜)
/// </summary>
public string Humidity { get; set; }
/// <summary>
/// 箱信息列表
/// </summary>
public List<TaskMessageCtnInfo> ContaList { get; set; }
}
/// <summary>
/// 箱信息
/// </summary>
public class TaskMessageCtnInfo
{
/// <summary>
/// 集装箱箱型代码
/// </summary>
public string ContaType { get; set; }
/// <summary>
/// 集装箱箱型名称
/// </summary>
public string ContaTypeName { get; set; }
/// <summary>
/// 集装箱箱号
/// </summary>
public string ContaNo { get; set; }
/// <summary>
/// 铅封号
/// </summary>
public string SealNo { get; set; }
/// <summary>
/// 包装
/// </summary>
public string KindPKGs { get; set; }
/// <summary>
/// 皮重
/// </summary>
public string TareWeight { get; set; }
/// <summary>
/// 件数
/// </summary>
public Int32 PKGs { get; set; }
/// <summary>
/// 毛重
/// </summary>
public Nullable<decimal> KGs { get; set; }
/// <summary>
/// 尺码
/// </summary>
public Nullable<decimal> CBM { get; set; }
}
/// <summary>
/// 报文表头
/// </summary>
public class TaskMessageHead : WebAPIHeadBase
{
}
public class WebAPIHeadBase
{
/// <summary>
/// 报文惟一主键
/// </summary>
/// <example>08dab66c-96a1-4f90-8606-2626e06202ad</example>
[Required(ErrorMessage = "必填")]
public string GID { get; set; }
/// <summary>
/// 报文类型 BUSI_RULE-业务规则校验
/// </summary>
/// <example>BUSI_RULE</example>
[Required(ErrorMessage = "必填")]
public string MessageType { get; set; }
/// <summary>
/// 发送方代码
/// </summary>
/// <example>CUSTOMER1</example>
[Required(ErrorMessage = "必填")]
public string SenderId { get; set; }
/// <summary>
/// 发送方名称
/// </summary>
/// <example>企业A</example>
[Required(ErrorMessage = "必填")]
public string SenderName { get; set; }
/// <summary>
/// 接收方代码
/// </summary>
/// <example>RulesEngine</example>
[Required(ErrorMessage = "必填")]
public string ReceiverId { get; set; }
/// <summary>
/// 接收方名称
/// </summary>
/// <example>大简云规则引擎</example>
[Required(ErrorMessage = "必填")]
public string ReceiverName { get; set; }
/// <summary>
/// 请求方登录TOKEN可以是真实的登录人TOKEN或者是服务模拟登录人TOKEN
/// </summary>
/// <example>eyJhbGciOiJSUzI1NiIsImtpZCI6IkQ1RTkxMDI5OUU0RURFNUZEM0EwNTJBMEFDRDUzMUQzIiwidHlwIjoiYXQrand0In0</example>
public string Token { get; set; }
/// <summary>
/// 版本号 默认1.0
/// </summary>
/// <example>1.0</example>
[Required(ErrorMessage = "必填")]
public string Version { get; set; } = "1.0";
/// <summary>
/// 请求时间
/// </summary>
/// <example>2022-10-10 10:00:00</example>
public string RequestDate { get; set; }
/// <summary>
/// 请求操作类型
/// </summary>
/// <example>Add</example>
[Required(ErrorMessage = "必填")]
public string RequestAction { get; set; } = "Add";
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
///
/// </summary>
public interface ITaskShippingOrderCompareService
{
/// <summary>
/// 执行下货纸比对
/// </summary>
/// <param name="bookingId">订舱主键</param>
/// <returns>返回回执</returns>
Task<TaskManageExcuteResultDto> ExcuteShippingOrderCompareAsync(string bookingId);
}
}

@ -0,0 +1,50 @@
using Mapster;
using Myshipping.Application.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
public class TaskManageCompareMapper : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.ForType<BookingOrder, TaskMessageMain>()
.Map(dest => dest.BookingNo, src => src.BOOKINGNO)
.Map(dest => dest.TenantId, src => src.TenantId)
.Map(dest => dest.TenantName, src => src.TenantName)
.Map(dest => dest.YardCode, src => src.YARDID)
.Map(dest => dest.YardCName, src => src.YARD)
.Map(dest => dest.VesselName, src => src.VESSEL)
.Map(dest => dest.VoyNo, src => src.VOYNO)
.Map(dest => dest.MasterBlNo, src => src.MBLNO)
.Map(dest => dest.HouseBlNo, src => src.HBLNO)
.Map(dest => dest.PortLoadId, src => src.PORTLOADID)
.Map(dest => dest.PortLoad, src => src.PORTLOAD)
.Map(dest => dest.PortDischargeId, src => src.PORTDISCHARGEID)
.Map(dest => dest.PortDischarge, src => src.PORTDISCHARGE)
.Map(dest => dest.TransportId, src => src.TRANSPORTID)
.Map(dest => dest.Transport, src => src.TRANSPORT)
.Map(dest => dest.PlaceDeliveryId, src => src.PLACEDELIVERYID)
.Map(dest => dest.PlaceDelivery, src => src.PLACEDELIVERY)
.Map(dest => dest.PKGs, src => src.PKGS)
.Map(dest => dest.KGs, src => src.KGS)
.Map(dest => dest.CBM, src => src.CBM);
config.ForType<BookingCtn, TaskMessageCtnInfo>()
.Map(dest => dest.ContaType, src => src.CTNCODE)
.Map(dest => dest.ContaTypeName, src => src.CTNALL)
.Map(dest => dest.ContaNo, src => src.CNTRNO)
.Map(dest => dest.SealNo, src => src.SEALNO)
.Map(dest => dest.KindPKGs, src => src.KINDPKGS)
.Map(dest => dest.TareWeight, src => src.TAREWEIGHT)
.Map(dest => dest.PKGs, src => src.PKGS)
.Map(dest => dest.KGs, src => src.KGS)
.Map(dest => dest.CBM, src => src.CBM);
}
}
}

@ -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;
/*
1URL
2JSON
3POST
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
}
}

@ -118,5 +118,6 @@
"TempFile": {
"Path": "TempFiles",
"RemainHours": 2
}
},
"ShippingOrderCompareUrl": "http://60.209.125.238:35210/api/TaskShippingOrderCompare/ExcuteShippingOrderCompare"
}
Loading…
Cancel
Save