|
|
|
|
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}");
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
1、提取当天的MSK API订舱记录生成列表。
|
|
|
|
|
2、生成邮件正文发送给制单人邮箱
|
|
|
|
|
*/
|
|
|
|
|
var _repBookingDelivery = App.GetService<SqlSugarRepository<BookingDeliveryRecord>>();
|
|
|
|
|
var _repRunJob = App.GetService<SqlSugarRepository<BookingDeliveryRecordJobRun>>();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|