using IWareCC.CacheInfo.Container;
|
using IWareCC.ORM;
|
using IWareCC.Properties;
|
using IWareCommon.Enum.Common;
|
using IWareCommon.Help;
|
using IWareCommon.Util;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IWareCC.DecomposeTask.Handle.DecomposeTask
|
{
|
public class 按策略获取一个待分解任务 : IHandler
|
{
|
|
|
private IHandler nextHandler = null;
|
/// <summary>
|
/// 该节点的下一个节点
|
/// </summary>
|
public IHandler NextHandler
|
{
|
set { nextHandler = value; }
|
}
|
|
|
/// <summary>
|
/// 主任务容器
|
/// </summary>
|
private MainTaskContainer MainTaskContainer;
|
|
|
|
/// <summary>
|
/// 从数据库里提取一个待分解的主任务
|
/// </summary>
|
public 按策略获取一个待分解任务(MainTaskContainer mainTaskContainer)
|
{
|
this.MainTaskContainer = mainTaskContainer;
|
}
|
|
/// <summary>
|
/// 从数据库中提取一个未分解的主任务(按照分解次数,优先级,创建时间排序)
|
/// </summary>
|
public void Handle()
|
{
|
|
using (var dbModel = new DbModel())
|
{
|
try
|
{
|
//调整排序方式,按照(优先级,分解次数,创建时间排序) 【Editby shaocx,2024-02-28】
|
//var mTask = dbModel.MainTasks.OrderByDescending(x => x.id).ThenBy(x => x.decompositiontimes).ThenBy(x => x.sendtime).ThenByDescending(x => x.priority).FirstOrDefault(x => x.status == (int)EMainTaskStatus.未分解);
|
var mTask = dbModel.MainTasks.OrderByDescending(x => x.priority).ThenBy(x => x.decompositiontimes).ThenBy(x => x.sendtime).FirstOrDefault(x => x.status == (int)EMainTaskStatus.未分解);
|
if (mTask == null)
|
{
|
// LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "获取第一个分解任务:暂无待分解的任务");
|
return;
|
}
|
mTask.decompositiontimes += 1;
|
dbModel.SaveChanges();
|
MainTaskContainer.DecompositionMainTask = mTask;
|
LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "获取第一个分解任务:{0}", mTask.id);
|
|
if (nextHandler != null)
|
{
|
nextHandler.Handle();
|
}
|
|
}
|
catch (Exception ex)
|
{
|
LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
|
}
|
}
|
|
|
}
|
}
|
}
|