using HH.WCS.ZhongCeJinTan.api; using HH.WCS.ZhongCeJinTan.dispatch; using HH.WCS.ZhongCeJinTan.process; using HH.WCS.ZhongCeJinTan.util; using HH.WCS.ZhongCeJinTan.wms; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Web.Services.Description; using static HH.WCS.ZhongCeJinTan.api.ApiModel; namespace HH.WCS.ZhongCeJinTan.core { /// /// 定时轮询任务 /// internal class Monitor { /// /// 根据作业创建对应任务 /// public static void CreateTask() { var db = new SqlHelper().GetInstance(); // 获取所有等待中的作业 var operations = db.Queryable().Where(p => p.N_B_STATE == 0).ToList(); foreach (var operation in operations) { TaskHelper.CreateTask(operation); } } /// /// 根据任务状态更新作业状态 /// public static void UpdateWorkState() { var db = new SqlHelper().GetInstance(); var operations = db.Queryable().Where(p => p.N_B_STATE == 1).ToList(); foreach (var operation in operations) { // 判断该任务是否全部完成 var tasks = db.Queryable().Where(p => p.S_OP_CODE == operation.S_CODE).ToList(); if (tasks.Count == tasks.Count(p => p.N_B_STATE == 3)) { operation.N_B_STATE = 2; operation.S_B_STATE = "完成"; operation.T_MODIFY = DateTime.Now; operation.T_END_TIME = DateTime.Now; db.Updateable(operation).UpdateColumns(it => new { it.N_B_STATE, it.S_B_STATE,it.T_MODIFY,it.T_END_TIME }).ExecuteCommand(); } else if (tasks.Count(p => p.N_B_STATE == 5) > 0) { operation.N_B_STATE = 7; operation.S_B_STATE = "取消"; operation.T_MODIFY = DateTime.Now; operation.T_END_TIME = DateTime.Now; db.Updateable(operation).UpdateColumns(it => new { it.N_B_STATE, it.S_B_STATE, it.T_MODIFY, it.T_END_TIME }).ExecuteCommand(); } } } } }