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.

72 lines
2.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DSWeb.Common.DB;
using DSWeb.Common.Helper;
using DSWeb.Common.Model;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSWeb.Job.Common
{
public class TaskPostSiStatusJob : IJob
{
private CommonDataContext commonData = new CommonDataContext();
private BookingDB bookingData = new BookingDB();
private OpTaskDataContext taskData = new OpTaskDataContext();
private ILog logger = LogManager.GetLogger("TaskPostSiStatusJob");
public void Execute(IJobExecutionContext context)
{
var urlCfg = commonData.ParamSets.AsNoTracking().FirstOrDefault(p => p.PARAMNAME == "bookingPostSiStatusUrl");
var postUrl = urlCfg.PARAMVALUE;
var todoList = commonData.BackgroundTaskCommon
.Where(t => t.Status == BackgroundTaskCommon.StatusCreate && t.Type == BackgroundTaskCommon.TypeBookingPostSiStatus)
.ToList();
if (todoList.Count > 0)
{
logger.Debug($"发现{todoList.Count}条待反馈SI状态的任务");
todoList.ForEach(t =>
{
t.Status = BackgroundTaskCommon.StatusDoing;
t.ExecuteCount++;
t.ExecuteTime = DateTime.Now;
});
commonData.SaveChanges();
foreach (var item in todoList)
{
try
{
logger.Debug($"准备反馈SI状态:{item.GID} {item.ParamData}");
var rtn = WebRequestHelper.DoPost(postUrl, item.ParamData);
logger.Debug($"反馈SI状态返回:{rtn}");
item.Status = BackgroundTaskCommon.StatusSuccess;
commonData.SaveChanges();
}
catch (Exception ex)
{
item.Status = BackgroundTaskCommon.StatusFail;
commonData.SaveChanges();
logger.Error($"反馈SI状态出错{item.GID} {item.ParamData}");
logger.Error(ex.Message);
logger.Error(ex.StackTrace);
}
}
logger.Debug($"{todoList.Count}条反馈SI状态的任务执行完成");
}
}
}
}