任务自动化处理

master
douhandong 5 months ago
parent fd9091f989
commit 9e780ca089

@ -3,6 +3,7 @@ using SqlSugar;
using System.ComponentModel;
using Myshipping.Core.Entity;
using NPOI.SS.UserModel;
using MimeKit.Cryptography;
namespace Myshipping.Application.Entity
{
@ -14,9 +15,44 @@ namespace Myshipping.Application.Entity
public class TaskFlowTenant : TaskManageDbEntity
{
/// <summary>
/// 任务APIID
/// 流程编码
/// </summary>
public string TaskApiId { get; set; }
public string FlowCode { get; set; }
/// <summary>
/// 方法名称
/// </summary>
public string MethodName { get; set; }
/// <summary>
/// 上级方法Id
/// </summary>
public string PId { get; set; }
/// <summary>
/// 是否主入口方法
/// </summary>
public bool IsMain { get; set; }
/// <summary>
/// 是否bool类型返回
/// </summary>
public bool IsBoolReturn { get; set; }
/// <summary>
/// 执行为true后续方法
/// </summary>
public string TrueMethod { get;set; }
/// <summary>
/// 执行为false后续方法
/// </summary>
public string FalseMethod { get;set; }
/// <summary>
/// apiId
/// </summary>
public string TaskApiId { get; set; }
/// <summary>
/// 平台代码

@ -1,4 +1,7 @@
using Furion.EventBus;
using Furion.DependencyInjection;
using Furion.EventBus;
using Furion.RemoteRequest.Extensions;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
@ -21,6 +24,7 @@ namespace Myshipping.Application.Event
{
private IServiceProvider _services { get; }
private readonly ILogger<BookingAutoSubscriber> _logger;
private readonly INamedServiceProvider<IBookingSlotService> _namedBookingSlotServiceProvider;
public BookingAutoSubscriber(IServiceProvider services, ILogger<BookingAutoSubscriber> logger)
{
@ -68,6 +72,7 @@ namespace Myshipping.Application.Event
};
await bookingfile.InsertAsync(newFile);
}
}

@ -0,0 +1,66 @@
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application.Event
{
/// <summary>
/// 对比实体
/// </summary>
public class BookingAutoContrast
{
/// <summary>
/// 约号
/// </summary>
public string CONTRACTNO { get; set; }
/// <summary>
/// 箱型箱量
/// </summary>
public string CNTRTOTAL { get; set; }
/// <summary>
/// 船名
/// </summary>
public string VESSEL { get; set; }
/// <summary>
/// 航次
/// </summary>
public string VOYNO { get; set; }
/// <summary>
/// 最低温度
/// </summary>
public string TEMPMIN { get; set; }
/// <summary>
/// 最高温度
/// </summary>
public string TEMPMAX { get; set; }
/// <summary>
/// 运输温度
/// </summary>
public string TEMPSET { get; set; }
/// <summary>
/// 湿度
/// </summary>
public string HUMIDITY { get; set; }
/// <summary>
/// 通风
/// </summary>
public string REEFERF { get; set; }
/// <summary>
/// 卸货港
/// </summary>
public string PORTDISCHARGECODE { get; set; }
/// <summary>
/// 目的港
/// </summary>
public string DESTINATION { get; set; }
/// <summary>
/// 货物标识
/// </summary>
public string CARGOID { get; set; }
}
}

@ -1,17 +1,22 @@
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.RemoteRequest.Extensions;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Application.Event;
using Myshipping.Core;
using Myshipping.Core.Entity;
using Newtonsoft.Json.Linq;
using NPOI.XSSF.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -29,18 +34,20 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<SysUser> _repoUser;
private readonly SqlSugarRepository<BookingOrder> _repoBookingOrder;
private readonly BookingOrderService _servBookingOrder;
private IServiceProvider _services { get; }
public BookingOrderAutoService(ILogger<BookingOrderAutoService> logger,
SqlSugarRepository<SysTenant> repoTenant,
SqlSugarRepository<SysUser> repoUser,
SqlSugarRepository<BookingOrder> repoBookingOrder,
BookingOrderService servBookingOrder)
BookingOrderService servBookingOrder, IServiceProvider services)
{
_logger = logger;
_repoTenant = repoTenant;
_repoUser = repoUser;
_repoBookingOrder = repoBookingOrder;
_servBookingOrder = servBookingOrder;
_services= services;
}
/// <summary>
@ -168,5 +175,50 @@ namespace Myshipping.Application
{
}
/// <summary>
/// cma bc 对比方法
/// </summary>
/// <returns></returns>
public async Task<bool> CMABCContrast(RecursiveMethodModel model)
{
//待对比字段
//BookingAutoContrast ac = new BookingAutoContrast();
//ac.CONTRACTNO = booking.CONTRACTNO;//约号
//ac.CNTRTOTAL = booking.CNTRTOTAL; //箱型箱量
//ac.VESSEL = booking.VESSEL;//船名
//ac.VOYNO = booking.VOYNO;//航次
//ac.TEMPMIN = booking.TEMPMIN;//最低温度
//ac.TEMPMAX = booking.TEMPMAX;//最高温度
//ac.TEMPSET = booking.TEMPSET;//运输温度
//ac.HUMIDITY = booking.HUMIDITY;//湿度
//ac.REEFERF = booking.REEFERF;//通风
//ac.PORTDISCHARGECODE = booking.PORTDISCHARGECODE;//卸货港
//ac.DESTINATION = booking.DESTINATION;//目的地
//ac.CARGOID = booking.CARGOID;//货物标识
//获取当前租户配置
var scope = _services.CreateScope();
var _taskFlowTenant = scope.ServiceProvider.GetRequiredService<SqlSugarRepository<TaskFlowTenant>>();
var apiinfo = _taskFlowTenant.AsQueryable().Filter(null, true)
.LeftJoin<TaskAPIInfo>((t, api) => t.TaskApiId == api.PK_ID)
.Where((t, api) => t.FlowCode == "CMABC")
.Select((t, api) => new { api.Key, api.SecretKey, api.URL })
.First();
//请求接口获取数据
var dto = await apiinfo.URL.SetHeaders(new Dictionary<string, object> {
{ "USER_KEY", apiinfo.Key},
{ "USER_SECRET", apiinfo.SecretKey}
}).SetBody(new { Code = "参数待完善" }).PostAsync();
return true;
}
}
}

@ -14,10 +14,40 @@ namespace Myshipping.Application
{
/// <summary>
/// 任务APIId
/// 流程编码
/// </summary>
public string TaskApiId { get; set; }
public string FlowCode { get; set; }
/// <summary>
/// 方法名称
/// </summary>
public string MethodName { get; set; }
/// <summary>
/// 上级方法Id
/// </summary>
public string PId { get; set; }
/// <summary>
/// 是否主入口方法
/// </summary>
public bool IsMain { get; set; }
/// <summary>
/// 是否bool类型返回
/// </summary>
public bool IsBoolReturn { get; set; }
/// <summary>
/// 执行为true后续方法
/// </summary>
public string TrueMethod { get; set; }
/// <summary>
/// 执行为false后续方法
/// </summary>
public string FalseMethod { get; set; }
/// <summary>
/// 平台代码
@ -69,4 +99,18 @@ namespace Myshipping.Application
/// </summary>
public string PK_ID { get; set; }
}
/// <summary>
/// 任务流程请求参数
/// </summary>
public class RecursiveMethodModel
{
/// <summary>
/// cma解析
/// </summary>
public List<Parse_attachmentItem> parse_attachment { get; set; }
}
}

@ -351,5 +351,287 @@ namespace Myshipping.Application
/// 计费时间
/// </summary>
public Nullable<DateTime> PriceCalculationDate { get; set; }
}
#region CMA BC的解析
public class ContainersItem
{
/// <summary>
///
/// </summary>
public string CartonQuantity { get; set; }
/// <summary>
///
/// </summary>
public string BoxPile { get; set; }
/// <summary>
///
/// </summary>
public string Pieces { get; set; }
/// <summary>
///
/// </summary>
public string Size { get; set; }
/// <summary>
///
/// </summary>
public string GrossWeight { get; set; }
/// <summary>
///
/// </summary>
public string TareWeight { get; set; }
/// <summary>
///
/// </summary>
public string IODGT { get; set; }
/// <summary>
///
/// </summary>
public string IODGTLevel { get; set; }
/// <summary>
///
/// </summary>
public string Temperature { get; set; }
/// <summary>
///
/// </summary>
public string Ventilate { get; set; }
/// <summary>
///
/// </summary>
public string SpecialLoadingRequirement { get; set; }
/// <summary>
///
/// </summary>
public string SuitcaseTterminal { get; set; }
/// <summary>
///
/// </summary>
public string SuitcaseTime { get; set; }
/// <summary>
///
/// </summary>
public string ReturnDepot { get; set; }
}
public class BCListItem
{
/// <summary>
///
/// </summary>
public string BookingParty { get; set; }
/// <summary>
///
/// </summary>
public string Shipper { get; set; }
/// <summary>
///
/// </summary>
public string Consigner { get; set; }
/// <summary>
///
/// </summary>
public string NotifyParty { get; set; }
/// <summary>
///
/// </summary>
public string BCUpdateTimes { get; set; }
/// <summary>
///
/// </summary>
public string BCUpdateTime { get; set; }
/// <summary>
///
/// </summary>
public string BLNo { get; set; }
/// <summary>
///
/// </summary>
public string ReferenceNo { get; set; }
/// <summary>
///
/// </summary>
public string Vessel { get; set; }
/// <summary>
///
/// </summary>
public string Voyage { get; set; }
/// <summary>
///
/// </summary>
public string ShippingCompany { get; set; }
/// <summary>
///
/// </summary>
public string PlaceOfReceipt { get; set; }
/// <summary>
///
/// </summary>
public string LoadingPort { get; set; }
/// <summary>
///
/// </summary>
public string ClosingDate { get; set; }
/// <summary>
///
/// </summary>
public string VGMCutOffTime { get; set; }
/// <summary>
///
/// </summary>
public string ETA { get; set; }
/// <summary>
///
/// </summary>
public string ETD { get; set; }
/// <summary>
///
/// </summary>
public string DischargingPort { get; set; }
/// <summary>
///
/// </summary>
public string DeliveryPlace { get; set; }
/// <summary>
///
/// </summary>
public string PortOfDestinationETA { get; set; }
/// <summary>
///
/// </summary>
public string ShippingWay { get; set; }
/// <summary>
///
/// </summary>
public string ShippingTerms { get; set; }
/// <summary>
///
/// </summary>
public string PreportTransportationMode { get; set; }
/// <summary>
///
/// </summary>
public string OfTheGoods { get; set; }
/// <summary>
///
/// </summary>
public string SignTheBillLocation { get; set; }
/// <summary>
///
/// </summary>
public string CollectionTerminal { get; set; }
/// <summary>
///
/// </summary>
public string AboutNo { get; set; }
/// <summary>
///
/// </summary>
public string PlaceInAdvance { get; set; }
/// <summary>
///
/// </summary>
public string ShipAgency { get; set; }
/// <summary>
///
/// </summary>
public string FreightForwarder { get; set; }
/// <summary>
///
/// </summary>
public string Station { get; set; }
/// <summary>
///
/// </summary>
public string StationContact { get; set; }
/// <summary>
///
/// </summary>
public string StationContactNumber { get; set; }
/// <summary>
///
/// </summary>
public string CutSingleTime { get; set; }
/// <summary>
///
/// </summary>
public string FirstCustomerServiceName { get; set; }
/// <summary>
///
/// </summary>
public string FirstCustomerServiceNumber { get; set; }
/// <summary>
///
/// </summary>
public string FirstCustomerServiceEmail { get; set; }
/// <summary>
///
/// </summary>
public string CYCutOffTime { get; set; }
/// <summary>
///
/// </summary>
public string Remark { get; set; }
/// <summary>
///
/// </summary>
public List<ContainersItem> Containers { get; set; }
}
public class Data
{
/// <summary>
///
/// </summary>
public string ModelID { get; set; }
/// <summary>
///
/// </summary>
public string ModelName { get; set; }
/// <summary>
///
/// </summary>
public List<BCListItem> BCList { get; set; }
}
public class Parse_info
{
/// <summary>
///
/// </summary>
public int status { get; set; }
/// <summary>
///
/// </summary>
public string message { get; set; }
/// <summary>
///
/// </summary>
public Data data { get; set; }
}
public class Parse_attachmentItem
{
/// <summary>
///
/// </summary>
public string filename { get; set; }
/// <summary>
///
/// </summary>
public string download_path { get; set; }
/// <summary>
///
/// </summary>
public string is_parse { get; set; }
/// <summary>
///
/// </summary>
public Parse_info parse_info { get; set; }
}
#endregion
}

@ -281,5 +281,10 @@ namespace Myshipping.Application
/// 截止时间变更(华南港口)
/// </summary>
public TaskManageOrderForInformCutOffDetailInfo ForInformCutOffDetailInfo { get; set; }
/// <summary>
/// CMA BC的解析
/// </summary>
public List<Parse_attachmentItem> parse_attachment { get; set; }
}
}

@ -41,7 +41,7 @@ namespace Myshipping.Application.Service.TaskManagePlat
.Select(u => new TaskFlowTenant
{
PK_ID = u.PK_ID,
TaskApiId = u.TaskApiId,
SYSTEM_CODE = u.SYSTEM_CODE,
SYSTEM_NAME = u.SYSTEM_NAME
});

@ -48,6 +48,7 @@ using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.Util;
using NPOI.XSSF.Model;
using NPOI.XSSF.UserModel;
using Org.BouncyCastle.Asn1.Tsp;
using Org.BouncyCastle.Asn1.X500;
using Org.BouncyCastle.Asn1.X9;
@ -63,6 +64,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;
using System.Security.Policy;
@ -133,6 +135,9 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<TaskPOLContainerNotPickUpInfo> _taskPOLContainerNotPickUpInfoRepository;
private readonly SqlSugarRepository<TaskFlowTenant> _taskFlowTenant;
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
private readonly ISysCacheService _cache;
@ -162,6 +167,7 @@ namespace Myshipping.Application
//LARA纸计算常量
const int LARA_PARER_DRAFT_VAR = 3;
private readonly BookingOrderAutoService _bookingOrderAuto;
public TaskManageService(SqlSugarRepository<TaskBaseInfo> taskBaseInfoRepository,
SqlSugarRepository<TaskSISubmitted> taskSISubmittedRepository,
@ -220,7 +226,8 @@ namespace Myshipping.Application
INamedServiceProvider<ITaskPOLContainerNotPickUpService> namedTaskPOLContainerNotPickUpServiceProvider,
INamedServiceProvider<ITaskManageCutDateChangeService> namedTaskManageCutDateChangeServiceProvider,
INamedServiceProvider<IRouteChangeAdvisoryService> namedRouteChangeAdvisoryServiceServiceProvider,
ILogger<BookingOrderService> logger)
ILogger<BookingOrderService> logger, BookingOrderAutoService bookingOrderAuto,
SqlSugarRepository<TaskFlowTenant> taskFlowTenant)
{
_taskBaseInfoRepository = taskBaseInfoRepository;
_taskSISubmittedRepository = taskSISubmittedRepository;
@ -289,6 +296,8 @@ namespace Myshipping.Application
_namedTaskPOLContainerNotPickUpServiceProvider = namedTaskPOLContainerNotPickUpServiceProvider;
_namedTaskManageCutDateChangeServiceProvider = namedTaskManageCutDateChangeServiceProvider;
_namedRouteChangeAdvisoryServiceServiceProvider = namedRouteChangeAdvisoryServiceServiceProvider;
_bookingOrderAuto = bookingOrderAuto;
_taskFlowTenant = taskFlowTenant;
}
#region 创建任务
@ -1049,6 +1058,30 @@ namespace Myshipping.Application
await name.SyncBookingSlotChange(bcInfo.TASK_ID, bcInfo.TenantId.Value);
}
#region 自动化处理
if (taskInfo.CARRIER_ID =="CMA")
{
var flow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.FlowCode == "CMABC" && t.IsMain == true).First();
if (flow!=null)
{
//方法请求参数
RecursiveMethodModel mt = new RecursiveMethodModel();
//TODO待完善请求参数
mt.parse_attachment = info.Main.parse_attachment;
RecursiveMethod(flow, 0, mt);
}
}
#endregion
}
#endregion
@ -1911,7 +1944,71 @@ namespace Myshipping.Application
return result;
}
#endregion
/// <summary>
/// 执行方法
/// </summary>
/// <param name="flow">当前流程配置</param>
/// <param name="depth">循环深度</param>
public void RecursiveMethod(TaskFlowTenant flow,int depth, RecursiveMethodModel model)
{
depth = depth++;
//防止配置错误引发死循环,此处设置最多深度20层
if (depth>=20)
{
return;
}
// 获取方法信息
MethodInfo methodInfo = typeof(BookingOrderAutoService).GetMethod(flow.MethodName);
// 确保方法存在
if (methodInfo != null)
{
// 调用方法
object result = methodInfo.Invoke(_bookingOrderAuto, new object[] { model });
//如果返回类型为bool
if (flow.IsBoolReturn)
{
if ((bool)result)
{
if (string.IsNullOrEmpty( flow.TrueMethod))
{
return;
}
var newflow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.MethodName == flow.TrueMethod).First();
RecursiveMethod(newflow, depth,model);
}
if ((bool)result)
{
if (flow.TrueMethod==null)
{
return;
}
var newflow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.MethodName == flow.FalseMethod).First();
RecursiveMethod(newflow, depth, model);
}
}
else
{
var newflow = _taskFlowTenant.AsQueryable().Filter(null, true).Where(t => t.PId == flow.PK_ID).First();
if (newflow==null)
{
return;
}
RecursiveMethod(newflow, depth,model);
}
}
else
{
($"方法{flow.MethodName}不存在").LogInformation();
return;
}
}
#region 查询订舱表查询用户和租户信息
/// <summary>

@ -2075,6 +2075,16 @@
客服
</summary>
</member>
<member name="P:Myshipping.Core.Entity.DjyCustomer.BUSINESSID">
<summary>
商务id
</summary>
</member>
<member name="P:Myshipping.Core.Entity.DjyCustomer.BUSINESS">
<summary>
商务
</summary>
</member>
<member name="P:Myshipping.Core.Entity.DjyCustomer.TIDANINFO">
<summary>
提单信息
@ -12481,6 +12491,16 @@
客服
</summary>
</member>
<member name="P:Myshipping.Core.Service.DjyCustomerInput.BUSINESSID">
<summary>
商务id
</summary>
</member>
<member name="P:Myshipping.Core.Service.DjyCustomerInput.BUSINESS">
<summary>
商务
</summary>
</member>
<member name="P:Myshipping.Core.Service.DjyCustomerInput.TIDANINFO">
<summary>
提单信息
@ -12706,6 +12726,16 @@
客服
</summary>
</member>
<member name="P:Myshipping.Core.Service.BatchUpdateInput.BUSINESSID">
<summary>
商务id
</summary>
</member>
<member name="P:Myshipping.Core.Service.BatchUpdateInput.BUSINESS">
<summary>
商务
</summary>
</member>
<member name="T:Myshipping.Core.Service.DjyCustomerOutput">
<summary>
客户输出参数

Loading…
Cancel
Save