You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Job/MSKAPIBookingWorker.cs

110 lines
4.2 KiB
C#

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>>();
}
}
}