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.

69 lines
2.5 KiB
C#

9 months ago
using FluentScheduler;
using JwKdsV.Core.SocketMessage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace JwKdsV.Core.Job
{
public class ChupinJob : IJob
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private bool isRunning = false;
public void Execute()
{
var sw = new Stopwatch();
List<string> serviceIdList = new List<string>();
try
{
if (isRunning)
{
logger.Debug("定时任务:出品同步至服务中心执行中,请稍候...");
return;
}
isRunning = true;
sw.Start();
lock (Global.Instance.SyncLock)
{
using(var db = Global.Instance.OpenDataBase)
{
using (var transaction = db.GetTransaction())
{
var sql = "select distinct p.[serviceId] from [pos_order_item] p where p.[huacai2ServiceStatus] = 0 and p.[huacaiTime] != '' and p.[huacaiTime] < '{0}' order by p.[huacaiTime], p.[huacai2ServiceNum];";
serviceIdList = db.Fetch<string>(string.Format(sql, DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss")));
foreach(var id in serviceIdList)
{
var updateSql = "update [pos_order_item] set huacai2ServiceNum = huacai2ServiceNum + 1 where serviceId = '{0}' and huacai2ServiceStatus = 0;";
db.Execute(string.Format(updateSql, id));
}
transaction.Complete();
}
}
}
//发送通知
foreach (var id in serviceIdList)
{
ChupinNotify.SendOrderChupinNotify(id);
}
}
catch(Exception ex)
{
logger.Error(ex, "定时任务:出品同步至服务中心数据异常");
}
finally
{
sw.Stop();
logger.Info("定时任务:出品同步至服务中心 数量<{0}> 耗时<{1}>", serviceIdList.Count, sw.ElapsedMilliseconds);
isRunning = false;
}
}
}
}