2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using iWareCc.DecomposeTask.Entity;
using iWareCc.Properties;
using iWareCommon.Common.Entity;
using iWareCommon.Utils;
using iWareDataCore.ORM;
using iWareDataCore.TASK.Entity;
using iWareDataCore.TASK.EnumType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.DecomposeTask.Chain
{
   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 DbModelCore())
            {
                try
                {
                    var mTask = dbModel.TASKMainTasks.OrderBy(x => x.decompositiontimes).ThenBy(x => x.sendtime).ThenBy(x => x.priority).FirstOrDefault(x => x.status == (int)EMainTaskStatus.未分解);
                    if (mTask == null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "获取第一个分解任务:暂无待分解的任务");
                        return;
                    }
                    mTask.decompositiontimes += 1;
                    if (mTask.decompositiontimes >= 100)
                    {
                        mTask.decompositiontimes = 0;
                    }
                    dbModel.SaveChanges();
                    
                    MainTaskContainer.MainTask = new MainTaskEntity(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);
                }
            }
 
 
        }
    }
}