修改马士基定时订舱报告邮件功能

master
jianghaiqing 3 months ago
parent 9e7b39b715
commit dffaae6ffa

@ -0,0 +1,54 @@
using Myshipping.Core.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application.Entity
{
/// <summary>
/// 订舱递送记录表定时订舱运行表
/// </summary>
[SugarTable("booking_delivery_record_job_run")]
[Description("订舱递送记录表定时订舱运行表")]
public class BookingDeliveryRecordJobRun : DBEntityTenant
{
/// <summary>
/// 主记录ID
/// </summary>
public long RECORD_ID { get; set; }
/// <summary>
/// 是否定时任务 1-是 0-否
/// </summary>
public Nullable<DateTime> JOB_TIME { get; set; }
/// <summary>
/// 发送时间
/// </summary>
public Nullable<DateTime> SEND_TIME { get; set; }
/// <summary>
/// 定时方案ID
/// </summary>
public string TIMER_PLAN_ID { get; set; }
/// <summary>
/// 定时方案名称
/// </summary>
public string TIMER_PLAN_NAME { get; set; }
/// <summary>
/// 是否已推送报告 1-已推送 0-未推送
/// </summary>
public bool IS_SEND_REPORT { get; set; }
/// <summary>
/// 推送报告时间
/// </summary>
public Nullable<DateTime> REPORT_TIME { get; set; }
}
}

@ -0,0 +1,109 @@
using Furion;
using Furion.DataEncryption;
using Furion.Logging;
using Furion.TaskScheduler;
using Microsoft.Extensions.Logging;
using Myshipping.Application;
using Myshipping.Application.Entity;
using Myshipping.Application.Job;
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;
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)
{
DateTime nowDate = DateTime.Now;
Log.Information($"UserSyncWorker {nowDate}");
/*
1
2
3
*/
//提取符合条件的订舱记录
var _repBookingDelivery = App.GetService<SqlSugarRepository<BookingDeliveryRecord>>();
var _repRunJob = App.GetService<SqlSugarRepository<BookingDeliveryRecordJobRun>>();
var _log = App.GetService<ILogger<MSKAPIBookingWorker>>();
var bookingMSKAPIService = App.GetService<IBookingMSKAPIService>();
//获取定时订舱的任务
var doList = _repBookingDelivery.AsQueryable().Filter(null, true).Where(a => a.IsDeleted == false && a.STATUS == "TEMP"
&& (a.REQUEST_ACKNOWLEDGEMENT_ID == null || a.REQUEST_ACKNOWLEDGEMENT_ID == "") && (a.BOOKING_REFERENCE == null || a.BOOKING_REFERENCE == "")
&& a.IS_JOB == true && a.JOB_TIME.HasValue && a.JOB_TIME.Value <= nowDate).ToList();
if (doList.Count > 0)
{
foreach (var item in doList)
{
try
{
//先写入运行表,再执行订舱
var runInfo = new BookingDeliveryRecordJobRun
{
RECORD_ID = item.Id,
JOB_TIME = item.JOB_TIME,
TIMER_PLAN_ID = item.TIMER_PLAN_ID,
TIMER_PLAN_NAME = item.TIMER_PLAN_NAME,
CreatedTime = DateTime.Now,
CreatedUserId = item.CreatedUserId,
CreatedUserName = item.CreatedUserName,
};
_repRunJob.Insert(runInfo);
var sendRlt = bookingMSKAPIService.SendMSKBookingById(item.Id).GetAwaiter().GetResult();
Thread.Sleep(200);
}
catch (Exception ex)
{
}
}
}
}
/// <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
*/
var _repBookingDelivery = App.GetService<SqlSugarRepository<BookingDeliveryRecord>>();
var _repRunJob = App.GetService<SqlSugarRepository<BookingDeliveryRecordJobRun>>();
}
}
}

@ -67,7 +67,7 @@ namespace Myshipping.Application.Service.BookingOrder
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) SqlSugarRepository<DjyUserMailAccount> djyUserMailAccount, SqlSugarRepository<BookingDeliveryRecordJobRun> bookingDeliveryRecordJobRunScheduleRep, SqlSugarRepository<SysUser> sysUserRepository)
{ {
_logger = logger; _logger = logger;
_cache = cache; _cache = cache;
@ -78,6 +78,7 @@ namespace Myshipping.Application.Service.BookingOrder
_bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep; _bookingDeliveryRecordShipScheduleRep = bookingDeliveryRecordShipScheduleRep;
_djyUserMailAccount = djyUserMailAccount; _djyUserMailAccount = djyUserMailAccount;
_bookingDeliveryRecordJobRunScheduleRep = bookingDeliveryRecordJobRunScheduleRep; _bookingDeliveryRecordJobRunScheduleRep = bookingDeliveryRecordJobRunScheduleRep;
_sysUserRepository = sysUserRepository;
} }
#region 检索海运船期详情 #region 检索海运船期详情
@ -2344,8 +2345,7 @@ namespace Myshipping.Application.Service.BookingOrder
DateTime startDate = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day); DateTime startDate = new DateTime(nowDate.Year, nowDate.Month, nowDate.Day);
var runList = _bookingDeliveryRecordJobRunScheduleRep.AsQueryable().Filter(null, true) var runList = _bookingDeliveryRecordJobRunScheduleRep.AsQueryable().Filter(null, true)
.Where(a => a.CreatedTime >= startDate && a.IsDeleted == false && a.IS_SEND_REPORT == false).ToList(); .Where(a => a.SEND_TIME >= startDate && a.IsDeleted == false && a.IS_SEND_REPORT == false).ToList();
if (runList.Count > 0) if (runList.Count > 0)
{ {
@ -2358,11 +2358,11 @@ namespace Myshipping.Application.Service.BookingOrder
{ {
var nextJobTime = DateTime.MinValue; var nextJobTime = DateTime.MinValue;
var nextOrder = _bookingDeliveryRecordRep.AsQueryable().Filter(null, true) var waitList = _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(); .Where(a => a.IsDeleted == false && a.JOB_TIME != null && a.JOB_TIME.Value >= nowDate && a.CreatedUserId == b.Key && a.STATUS == "TEMP").OrderBy(a=>a.JOB_TIME.Value).ToList();
if (nextOrder != null) if (waitList.Count > 0)
nextJobTime = nextOrder.JOB_TIME.Value; nextJobTime = waitList.FirstOrDefault().JOB_TIME.Value;
var opUser = _sysUserRepository.AsQueryable().Filter(null, true).First(a => a.Id == b.Key); var opUser = _sysUserRepository.AsQueryable().Filter(null, true).First(a => a.Id == b.Key);
@ -2390,15 +2390,21 @@ namespace Myshipping.Application.Service.BookingOrder
string baseHtml = File.ReadAllText(templatePath); 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("#ReportTime#", nowDate.ToString("yyyy-MM-dd HH:mm:ss"));
baseHtml = baseHtml.Replace("#total#", currList.Count.ToString()); baseHtml = baseHtml.Replace("#total#", currList.Count.ToString());
baseHtml = baseHtml.Replace("#succ#", currList.Count(x=>x.STATUS == "SUCC").ToString()); baseHtml = baseHtml.Replace("#succ#", currList.Count(x=>x.STATUS == "SUCC").ToString());
baseHtml = baseHtml.Replace("#failure#", currList.Count(x => x.STATUS == "FAILURE").ToString()); baseHtml = baseHtml.Replace("#failure#", currList.Count(x => x.STATUS == "FAILURE").ToString());
if(waitList.Count > 0)
{
baseHtml = baseHtml.Replace("#wait#", currList.Count().ToString());
}
else
{
baseHtml = baseHtml.Replace("#wait#", "0");
}
if (nextJobTime != DateTime.MinValue) if (nextJobTime != DateTime.MinValue)
{ {
baseHtml = baseHtml.Replace("#NextTime#", nextJobTime.ToString("yyyy-MM-dd HH:mm")); baseHtml = baseHtml.Replace("#NextTime#", nextJobTime.ToString("yyyy-MM-dd HH:mm"));
@ -2408,6 +2414,8 @@ namespace Myshipping.Application.Service.BookingOrder
baseHtml = baseHtml.Replace("#NextTime#", ""); baseHtml = baseHtml.Replace("#NextTime#", "");
} }
HtmlDocument html = new HtmlDocument();
html.LoadHtml(baseHtml);
var tableNode = html.DocumentNode.SelectSingleNode(".//table[@id='show-table']"); var tableNode = html.DocumentNode.SelectSingleNode(".//table[@id='show-table']");
@ -2417,10 +2425,10 @@ namespace Myshipping.Application.Service.BookingOrder
for (int i = 0; i < currList.Count; i++) 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($"<tr><td>{i+1}</td><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].STATUS_NAME}</td><td>{currList[i].BOOKING_REFERENCE}</td><td>{currList[i].PLACERECEIPT_CITY}</td><td>{currList[i].PLACEDELIVERY_CITY}</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].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].TOTAL_CARGO_WEIGHT.HasValue? currList[i].TOTAL_CARGO_WEIGHT.Value.ToString():"")}</td><td>{currList[i].PRICE_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>"); 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>");
} }
@ -2428,11 +2436,12 @@ namespace Myshipping.Application.Service.BookingOrder
tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString())); tableNode.ChildNodes.Add(HtmlNode.CreateNode(tableBuilder.ToString()));
} }
emailHtml = html.DocumentNode.OuterHtml;
EmailApiUserDefinedDto emailApiUserDefinedDto = new EmailApiUserDefinedDto EmailApiUserDefinedDto emailApiUserDefinedDto = new EmailApiUserDefinedDto
{ {
SendTo = opUser.Email, SendTo = opUser.Email,
//CCTo = opEmail, CCTo = string.Join(";", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList().ToArray()),
Title = $"马士基API定时订舱统计报告 {nowDate.ToString("yyyy-MM-dd HH:mm:ss")}", Title = $"马士基API定时订舱统计报告 {nowDate.ToString("yyyy-MM-dd HH:mm:ss")}",
Body = emailHtml, Body = emailHtml,
Account = publicMailAccount.MailAccount?.Trim(), Account = publicMailAccount.MailAccount?.Trim(),

@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title class="head-title">邮件模板</title>
</head>
<body style="margin: 0; padding: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#EDF9F5" style="font-size: 12px;font-family: Arial;">
<tr>
<td height="30"></td>
</tr>
<tr>
<td>
<table class="out-table" border="0" cellpadding="8" cellspacing="0" width="100%" bgcolor="#FFFFFF" align="center" style="font-size: 12px;font-family: Arial;">
<tr>
<td>
<p>以下是马士基API定时订舱报告 时间:#ReportTime#</p>
</td>
</tr>
<tr>
<td>
<p>定时任务共计:#total# 条;成功 #succ# 条;失败 #failure# 条;还有待订舱数量 #wait# 条;下一个订舱日期:#NextTime#</p>
</td>
</tr>
<tr>
<td>
<table id="show-table" border="1" cellpadding="8" cellspacing="0" width="100%" align="left" style="border-collapse: collapse;border-color: #ebeef5;font-size: 12px;font-family: Arial;">
<tr>
<th style="text-align: left;">序号</th>
<th style="text-align: left;">订舱日期</th>
<th style="text-align: left;">状态</th>
<th style="text-align: left;">订舱号</th>
<th style="text-align: left;">起运港</th>
<th style="text-align: left;">目的港</th>
<th style="text-align: left;">箱型箱量</th>
<th style="text-align: left;">ETD</th>
<th style="text-align: left;">总重KGS</th>
<th style="text-align: left;">合约号</th>
<th style="text-align: left;">BC</th>
<th style="text-align: left;">Cancellation</th>
<th style="text-align: left;">定时时间</th>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Loading…
Cancel
Save