修改马士基订舱,增加定时订舱

master
jianghaiqing 3 months ago
parent ac32af277b
commit fdad75c187

@ -1352,6 +1352,13 @@ namespace Myshipping.Application.EDI
r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO) + "'"); r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO) + "'");
icount = icount + 1; icount = icount + 1;
if (InttrEdi.SENDNAME.Length > 35)
r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'");
else
r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'");
icount = icount + 1;
} }
else else
{ {

@ -576,5 +576,16 @@ namespace Myshipping.Application.Entity
/// 交货地定位ID /// 交货地定位ID
/// </summary> /// </summary>
public string PLACEDELIVERY_GEO_ID { get; set; } public string PLACEDELIVERY_GEO_ID { get; set; }
/// <summary>
/// 定时方案ID
/// </summary>
public string TIMER_PLAN_ID { get; set; }
/// <summary>
/// 定时方案名称
/// </summary>
public string TIMER_PLAN_NAME { get; set; }
} }
} }

@ -1098,5 +1098,15 @@ namespace Myshipping.Application.Entity
/// 所属公司名称 /// 所属公司名称
/// </summary> /// </summary>
public string SubTenantName { get; set; } public string SubTenantName { get; set; }
/// <summary>
/// 订舱方式 CONTRACT_ORDER-合约订舱SPOT_ORDER-SPOT订舱
/// </summary>
public string BookingSlotType { get; set; }
/// <summary>
/// 订舱方式名称 CONTRACT_ORDER-合约订舱SPOT_ORDER-SPOT订舱
/// </summary>
public string BookingSlotTypeName { get; set; }
} }
} }

@ -29,6 +29,14 @@ using StackExchange.Profiling.Internal;
using SqlSugar; using SqlSugar;
using static Aliyun.OSS.Model.InventoryConfigurationModel; using static Aliyun.OSS.Model.InventoryConfigurationModel;
using System.Threading; using System.Threading;
using System.Collections;
using MathNet.Numerics;
using Myshipping.Core.Entity;
using HtmlAgilityPack;
using System.Security.Cryptography;
using Myshipping.Application.ConfigOption;
using System.IO;
using System.Net.Http;
namespace Myshipping.Application.Service.BookingOrder namespace Myshipping.Application.Service.BookingOrder
{ {
@ -41,6 +49,9 @@ namespace Myshipping.Application.Service.BookingOrder
private readonly SqlSugarRepository<BookingDeliveryRecord> _bookingDeliveryRecordRep; private readonly SqlSugarRepository<BookingDeliveryRecord> _bookingDeliveryRecordRep;
private readonly SqlSugarRepository<BookingDeliveryRecordCtn> _bookingDeliveryRecordCtnRep; private readonly SqlSugarRepository<BookingDeliveryRecordCtn> _bookingDeliveryRecordCtnRep;
private readonly SqlSugarRepository<BookingDeliveryRecordShipSchedule> _bookingDeliveryRecordShipScheduleRep; private readonly SqlSugarRepository<BookingDeliveryRecordShipSchedule> _bookingDeliveryRecordShipScheduleRep;
private readonly SqlSugarRepository<BookingDeliveryRecordJobRun> _bookingDeliveryRecordJobRunScheduleRep;
private readonly SqlSugarRepository<DjyUserMailAccount> _djyUserMailAccount;
private readonly SqlSugarRepository<SysUser> _sysUserRepository;
private readonly ISysCacheService _cache; private readonly ISysCacheService _cache;
private readonly IDjyWebsiteAccountConfigService _webAccountConfig; private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
@ -55,7 +66,8 @@ namespace Myshipping.Application.Service.BookingOrder
public BookingMSKAPIService(ILogger<BookingMSKAPIService> logger, ISysCacheService cache, public BookingMSKAPIService(ILogger<BookingMSKAPIService> logger, ISysCacheService cache,
IDjyWebsiteAccountConfigService webAccountConfig, SqlSugarRepository<BookingDeliveryRecord> bookingDeliveryRecordRep, IDjyWebsiteAccountConfigService webAccountConfig, SqlSugarRepository<BookingDeliveryRecord> bookingDeliveryRecordRep,
ISysDataUserMenu sysDataUserMenuService, ISysDataUserMenu sysDataUserMenuService,
SqlSugarRepository<BookingDeliveryRecordCtn> bookingDeliveryRecordCtnRep, SqlSugarRepository<BookingDeliveryRecordShipSchedule> bookingDeliveryRecordShipScheduleRep) SqlSugarRepository<BookingDeliveryRecordCtn> bookingDeliveryRecordCtnRep, SqlSugarRepository<BookingDeliveryRecordShipSchedule> bookingDeliveryRecordShipScheduleRep,
SqlSugarRepository<DjyUserMailAccount> djyUserMailAccount, SqlSugarRepository<BookingDeliveryRecordJobRun> bookingDeliveryRecordJobRunScheduleRep)
{ {
_logger = logger; _logger = logger;
_cache = cache; _cache = cache;
@ -64,6 +76,8 @@ namespace Myshipping.Application.Service.BookingOrder
_bookingDeliveryRecordCtnRep = bookingDeliveryRecordCtnRep; _bookingDeliveryRecordCtnRep = bookingDeliveryRecordCtnRep;
_sysDataUserMenuService = sysDataUserMenuService; _sysDataUserMenuService = sysDataUserMenuService;
_bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep; _bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep;
_djyUserMailAccount = djyUserMailAccount;
_bookingDeliveryRecordJobRunScheduleRep = bookingDeliveryRecordJobRunScheduleRep;
} }
#region 检索海运船期详情 #region 检索海运船期详情
@ -2293,5 +2307,212 @@ namespace Myshipping.Application.Service.BookingOrder
return list; return list;
} }
#region 发送马士基订舱请求
/// <summary>
/// 发送马士基订舱请求
/// </summary>
/// <param name="id">请求订舱ID</param>
/// <returns>返回检索结果</returns>
[HttpGet("/BookingMSKAPI/SendMSKBookingById")]
public async Task<MSKBookingResultDto> SendMSKBookingById(long id)
{
var model = await GetInfo(id);
if (model != null)
{
return await InnerSendMSKBooking(model, id, false);
}
return new MSKBookingResultDto
{
succ = false,
msg = "预订舱信息不存在"
};
}
#endregion
#region 生成订舱订舱报告邮件并自动转发
/// <summary>
/// 生成订舱订舱报告邮件并自动转发
/// </summary>
/// <returns></returns>
[HttpGet("/BookingMSKAPI/GenerateTimerReportEmail")]
public async Task<string> GenerateTimerReportEmail()
{
DateTime nowDate = DateTime.Now;
DateTime startDate = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day);
var runList = _bookingDeliveryRecordJobRunScheduleRep.AsQueryable().Filter(null, true)
.Where(a => a.CreatedTime >= startDate && a.IsDeleted == false && a.IS_SEND_REPORT == false).ToList();
if (runList.Count > 0)
{
var idList = runList.Select(a => a.RECORD_ID).ToList();
var orderList = _bookingDeliveryRecordRep.AsQueryable().Filter(null, true)
.Where(a => a.IsDeleted == false && idList.Contains(a.Id)).ToList();
orderList.GroupBy(a => a.CreatedUserId.Value).ToList().ForEach(b =>
{
var nextJobTime = DateTime.MinValue;
var nextOrder = _bookingDeliveryRecordRep.AsQueryable().Filter(null, true)
.Where(a => a.IsDeleted == false && a.JOB_TIME != null && a.JOB_TIME.Value >= nowDate && a.CreatedUserId == b.Key).OrderBy(a=>a.JOB_TIME.Value).First();
if (nextOrder != null)
nextJobTime = nextOrder.JOB_TIME.Value;
var opUser = _sysUserRepository.AsQueryable().Filter(null, true).First(a => a.Id == b.Key);
DjyUserMailAccount publicMailAccount = _djyUserMailAccount.AsQueryable().Filter(null, true).First(x => x.TenantId == opUser.TenantId && x.ShowName == "PublicSend"
&& x.SmtpPort > 0 && x.SmtpServer != null && x.SmtpServer != "");
if (publicMailAccount == null)
{
throw Oops.Oh($"提取公共邮箱配置失败请在用户邮箱账号管理增加配置显示名为PublicSend或者配置个人邮箱");
}
string emailHtml = string.Empty;
var currList = b.OrderBy(t=>t.SEND_TIME.Value).ToList();
string templatePath = App.Configuration["EmailTemplateFilePath"];
var opt = App.GetOptions<BookingAttachOptions>();
var dirAbs = opt.basePath;
if (string.IsNullOrEmpty(dirAbs))
{
dirAbs = App.WebHostEnvironment.WebRootPath;
}
templatePath = $"{dirAbs}{templatePath}\\MSKAPITimerReportTemplate.html";
string baseHtml = File.ReadAllText(templatePath);
HtmlDocument html = new HtmlDocument();
html.LoadHtml(baseHtml);
baseHtml = baseHtml.Replace("#ReportTime#", nowDate.ToString("yyyy-MM-dd HH:mm:ss"));
baseHtml = baseHtml.Replace("#total#", currList.Count.ToString());
baseHtml = baseHtml.Replace("#succ#", currList.Count(x=>x.STATUS == "SUCC").ToString());
baseHtml = baseHtml.Replace("#failure#", currList.Count(x => x.STATUS == "FAILURE").ToString());
if (nextJobTime != DateTime.MinValue)
{
baseHtml = baseHtml.Replace("#NextTime#", nextJobTime.ToString("yyyy-MM-dd HH:mm"));
}
else
{
baseHtml = baseHtml.Replace("#NextTime#", "");
}
var tableNode = html.DocumentNode.SelectSingleNode(".//table[@id='show-table']");
if (tableNode != null)
{
StringBuilder tableBuilder = new StringBuilder();
for (int i = 0; i < currList.Count; i++)
{
tableBuilder.Append($"<tr><td>{(currList[i].SEND_TIME.HasValue ? currList[i].SEND_TIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "")}</td>");
tableBuilder.Append($"<td>{currList[i].STATUS_NAME}</td><td>{currList[i].BOOKING_REFERENCE}</td><td>{currList[i].PLACERECEIPT}</td><td>{currList[i].PLACEDELIVERY}</td>");
tableBuilder.Append($"<td>{currList[i].CTN_STAT}</td><td>{(currList[i].ETD.HasValue ? currList[i].ETD.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td>");
tableBuilder.Append($"<td>{(currList[i].TOTAL_CARGO_WEIGHT.HasValue? currList[i].TOTAL_CARGO_WEIGHT.Value.ToString():"")}</td><td>{currList[i].PRICE_OWNER_REFERENCE}</td>");
tableBuilder.Append($"<td>{(currList[i].IS_RECV_BC ? "1" : "")}</td><td>{(currList[i].IS_RECV_BK_CANCEL ? "1" : "")}</td><td>{(currList[i].JOB_TIME.HasValue ? currList[i].JOB_TIME.Value.ToString("yyyy-MM-dd HH:mm") : "")}</td></tr>");
}
//生成From Vessel的table列表
tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString()));
}
EmailApiUserDefinedDto emailApiUserDefinedDto = new EmailApiUserDefinedDto
{
SendTo = opUser.Email,
//CCTo = opEmail,
Title = $"马士基API定时订舱统计报告 {nowDate.ToString("yyyy-MM-dd HH:mm:ss")}",
Body = emailHtml,
Account = publicMailAccount.MailAccount?.Trim(),
Password = publicMailAccount.Password?.Trim(),
Server = publicMailAccount.SmtpServer?.Trim(),
Port = publicMailAccount.SmtpPort.HasValue ? publicMailAccount.SmtpPort.Value : 465,
UseSSL = publicMailAccount.SmtpSSL.HasValue ? publicMailAccount.SmtpSSL.Value : true,
Attaches = new List<AttachesInfo>()
};
List<EmailApiUserDefinedDto> emailList = new List<EmailApiUserDefinedDto>();
var emailUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "email_api_url")?.Value;
if (emailUrl == null)
_logger.LogInformation("字典未配置 url_set->email_api_url 请联系管理员");
emailList.Add(emailApiUserDefinedDto);
//string strJoin = System.IO.File.ReadAllText(filePath);
DateTime bDate = DateTime.Now;
HttpResponseMessage res = null;
try
{
res = emailUrl.SetBody(emailList, "application/json").PostAsync().GetAwaiter().GetResult();
}
catch (Exception ex)
{
_logger.LogInformation($"发送邮件异常:{ex.Message}");
}
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation($"发送邮件返回:{JSON.Serialize(res)}");
if (res != null && res.StatusCode == System.Net.HttpStatusCode.OK)
{
var userResult = res.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var respObj = JsonConvert.DeserializeAnonymousType(userResult, new
{
Success = false,
Message = string.Empty,
Code = -9999,
});
if(respObj.Success)
{
var updateList = currList.Join(runList, l => l.Id, r => r.RECORD_ID, (l, r) =>
{
return r;
}).ToList();
foreach (var update in updateList) {
update.IS_SEND_REPORT = true;
update.REPORT_TIME = DateTime.Now;
_bookingDeliveryRecordJobRunScheduleRep.AsUpdateable(update).UpdateColumns(x => new
{
x.IS_SEND_REPORT,
x.REPORT_TIME
}).ExecuteCommand();
};
}
}
});
}
return "";
}
#endregion
} }
} }

@ -10389,6 +10389,8 @@ namespace Myshipping.Application
dto.SyncType = syncTypeEnum.ToString(); dto.SyncType = syncTypeEnum.ToString();
} }
dto.OPERATOREMAIL = item.BookingSlotType;
List<ServiceProjectStatusDto> statusList = new List<ServiceProjectStatusDto>(); List<ServiceProjectStatusDto> statusList = new List<ServiceProjectStatusDto>();
if (App.Configuration["ServiceStatusOpenAuto"] == "1") if (App.Configuration["ServiceStatusOpenAuto"] == "1")

@ -481,6 +481,16 @@ namespace Myshipping.Application
/// 集装箱 /// 集装箱
/// </summary> /// </summary>
public List<BookingDeliveryRecordCtnDto> ctns { get; set; } public List<BookingDeliveryRecordCtnDto> ctns { get; set; }
/// <summary>
/// 定时方案ID
/// </summary>
public string TimerPlanId { get; set; }
/// <summary>
/// 定时方案名称
/// </summary>
public string TimerPlanName { get; set; }
} }
public class BookingDeliveryRecordCtnDto public class BookingDeliveryRecordCtnDto

@ -319,7 +319,9 @@ namespace Myshipping.Application
.Map(dest => dest.isRecvBC, src => src.IS_RECV_BC) .Map(dest => dest.isRecvBC, src => src.IS_RECV_BC)
.Map(dest => dest.LstRecvBCDate, src => src.LST_RECV_BC_DATE) .Map(dest => dest.LstRecvBCDate, src => src.LST_RECV_BC_DATE)
.Map(dest => dest.isRecvBKCancel, src => src.IS_RECV_BK_CANCEL) .Map(dest => dest.isRecvBKCancel, src => src.IS_RECV_BK_CANCEL)
.Map(dest => dest.LstRecvBKCancelDate, src => src.LST_RECV_BK_CANCEL_DATE); .Map(dest => dest.LstRecvBKCancelDate, src => src.LST_RECV_BK_CANCEL_DATE)
.Map(dest => dest.TimerPlanId, src => src.TIMER_PLAN_ID)
.Map(dest => dest.TimerPlanName, src => src.TIMER_PLAN_NAME);

@ -892,6 +892,16 @@ namespace Myshipping.Application
/// 所属公司名称 /// 所属公司名称
/// </summary> /// </summary>
public string SubTenantName { get; set; } public string SubTenantName { get; set; }
/// <summary>
/// 订舱方式 CONTRACT_ORDER-合约订舱SPOT_ORDER-SPOT订舱
/// </summary>
public string BookingSlotType { get; set; }
/// <summary>
/// 订舱方式名称 CONTRACT_ORDER-合约订舱SPOT_ORDER-SPOT订舱
/// </summary>
public string BookingSlotTypeName { get; set; }
} }
/// <summary> /// <summary>

@ -122,5 +122,19 @@ namespace Myshipping.Application
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
Task<List<MSKAPITimerSchemeDto>> GetTimerSchemeList(); Task<List<MSKAPITimerSchemeDto>> GetTimerSchemeList();
/// <summary>
/// 发送马士基订舱请求
/// </summary>
/// <param name="id">请求订舱ID</param>
/// <returns>返回检索结果</returns>
Task<MSKBookingResultDto> SendMSKBookingById(long id);
/// <summary>
/// 生成订舱订舱报告邮件并自动转发
/// </summary>
/// <returns></returns>
Task<string> GenerateTimerReportEmail();
} }
} }

@ -3219,6 +3219,8 @@ namespace Myshipping.Application
PLACEDELIVERYID = bookingSlotBase.PLACEDELIVERYID, PLACEDELIVERYID = bookingSlotBase.PLACEDELIVERYID,
PLACERECEIPT = bookingSlotBase.PLACERECEIPT, PLACERECEIPT = bookingSlotBase.PLACERECEIPT,
PLACERECEIPTID = bookingSlotBase.PLACERECEIPTID, PLACERECEIPTID = bookingSlotBase.PLACERECEIPTID,
BookingSlotType = bookingSlotBase.BOOKING_SLOT_TYPE,
BookingSlotTypeName = bookingSlotBase.BOOKING_SLOT_TYPE_NAME,
ctnInputs = new List<BookingCtnDto>() ctnInputs = new List<BookingCtnDto>()
}; };

@ -855,6 +855,11 @@ namespace Myshipping.Application.Service.DataSync.Dto
/// 分单操作 /// 分单操作
/// </summary> /// </summary>
public string SubOp { get; set; } public string SubOp { get; set; }
/// <summary>
/// 场站备注
/// </summary>
public string OPERATOREMAIL { get; set; }
} }

@ -1558,6 +1558,9 @@ namespace Myshipping.Application
}); });
} }
bkModel.BookingSlotType = taskBCInfo.BOOKING_SLOT_TYPE;
bkModel.BookingSlotTypeName = taskBCInfo.BOOKING_SLOT_TYPE_NAME;
var bkRlt = await _bookingOrderService.Save(bkModel); var bkRlt = await _bookingOrderService.Save(bkModel);
id = bkRlt.Id; id = bkRlt.Id;
@ -1965,7 +1968,7 @@ namespace Myshipping.Application
_logger.LogInformation($"提取当前公共邮箱的配置完成id={publicMailAccount.Id}"); _logger.LogInformation($"提取当前公共邮箱的配置完成id={publicMailAccount.Id}");
string emailTitle = $"Booking Confirmation : {taskBCInfo.MBL_NO}"; string emailTitle = $"Booking Confirmation : {bookingOrderEntity.MBLNO}";
string filePath = string.Empty; string filePath = string.Empty;
@ -1976,7 +1979,7 @@ namespace Myshipping.Application
if (taskBCInfo.BUSI_TYPE == "BookingAmendment") if (taskBCInfo.BUSI_TYPE == "BookingAmendment")
{ {
emailTitle = $"【变更】Booking Amendment : {taskBCInfo.MBL_NO}"; emailTitle = $"【变更】Booking Amendment : {bookingOrderEntity.MBLNO}";
} }
//读取邮件模板并填充数据 //读取邮件模板并填充数据

@ -1,55 +0,0 @@
using Furion;
using Furion.DataEncryption;
using Furion.Logging;
using Furion.TaskScheduler;
using Myshipping.Core.Const;
using Myshipping.Core.Entity;
using Myshipping.Core.Service;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Core.Job
{
/// <summary>
/// 马士基API定时自动订舱
/// </summary>
public class MSKAPIBookingWorker : ISpareTimeWorker
{
/// <summary>
/// 发送马士基API自动订舱
/// </summary>
/// <param name="timer"></param>
/// <param name="count"></param>
[SpareTime(60000, "MSKAPISendBooking", Description = "发送马士基API自动订舱", DoOnce = false, StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
public void MSKAPISendBooking(SpareTimer timer, long count)
{
Log.Information($"UserSyncWorker {DateTime.Now}");
/*
1
2
3
*/
}
/// <summary>
/// 生成当天的发送结果统计给操作
/// </summary>
/// <param name="timer"></param>
/// <param name="count"></param>
[SpareTime(60000, "MSKAPIResultReportToOp", Description = "生成当天的发送结果统计给操作", DoOnce = false, StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
public void MSKAPIResultReportToOp(SpareTimer timer, long count)
{
Log.Information($"UserSyncWorker {DateTime.Now}");
/*
1MSK API
2
*/
}
}
}

@ -6971,25 +6971,6 @@
日志清理 日志清理
</summary> </summary>
</member> </member>
<member name="T:Myshipping.Core.Job.MSKAPIBookingWorker">
<summary>
马士基API定时自动订舱
</summary>
</member>
<member name="M:Myshipping.Core.Job.MSKAPIBookingWorker.MSKAPISendBooking(Furion.TaskScheduler.SpareTimer,System.Int64)">
<summary>
发送马士基API自动订舱
</summary>
<param name="timer"></param>
<param name="count"></param>
</member>
<member name="M:Myshipping.Core.Job.MSKAPIBookingWorker.MSKAPIResultReportToOp(Furion.TaskScheduler.SpareTimer,System.Int64)">
<summary>
生成当天的发送结果统计给操作
</summary>
<param name="timer"></param>
<param name="count"></param>
</member>
<member name="T:Myshipping.Core.Job.UserSyncWorker"> <member name="T:Myshipping.Core.Job.UserSyncWorker">
<summary> <summary>
和川用户同步 和川用户同步

@ -56,7 +56,7 @@
}, },
"Cache": { "Cache": {
"CacheType": "RedisCache", // RedisCache "CacheType": "RedisCache", // RedisCache
"RedisConnectionString": "127.0.0.1:6379,password=,defaultDatabase=11" "RedisConnectionString": "60.209.125.238:36379,password=,defaultDatabase=11"
}, },
"SnowId": { "SnowId": {
"WorkerId": "1" // 0~63,1 "WorkerId": "1" // 0~63,1

@ -26,6 +26,10 @@
<Content Remove="wwwroot\Template\Service.cs.vm" /> <Content Remove="wwwroot\Template\Service.cs.vm" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="wwwroot\EmailTemplate\MSKAPITimerReportTemplate.html" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<_WebToolingArtifacts Remove="Properties\PublishProfiles\linux.pubxml" /> <_WebToolingArtifacts Remove="Properties\PublishProfiles\linux.pubxml" />
<_WebToolingArtifacts Remove="Properties\PublishProfiles\windows.pubxml" /> <_WebToolingArtifacts Remove="Properties\PublishProfiles\windows.pubxml" />

Loading…
Cancel
Save