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
86
87
88
89
90
91
92
93
94
using iWareCc.DecomposeTask.Entity;
using iWareCcTest.Properties;
using iWareCommon.Common.Entity;
using iWareCommon.Common.EnumType;
using iWareCommon.Utils;
using iWareDataCore.BASE.EnumType;
using iWareDataCore.ORM;
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
    {
        /// <summary>
        /// 主任务容器
        /// </summary>
        private MainTaskContainer MainTaskContainer;
 
        /// <summary>
        /// 分解任务容器
        /// </summary>
        private PartTaskContainer PartTaskContainer;
 
        /// <summary>
        /// 呼叫任务容器
        /// </summary>
        private PlaceContainer PlaceContainer;
 
 
        private IHandler nextHandler = null;
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        /// <summary>
        /// 保存分解任务并将主任务标记为已分解
        /// </summary>
        public 保存分解任务(MainTaskContainer mainTaskContainer, PartTaskContainer partTaskContainer, PlaceContainer placeContainer)
        {
            this.MainTaskContainer = mainTaskContainer;
            this.PartTaskContainer = partTaskContainer;
            this.PlaceContainer = placeContainer;
        }
 
        /// <summary>
        /// 将主任务标记为已分解,并将分解任务保存在数据库
        /// </summary>
        public void Handle()
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var lTask = dbModel.TASKMainTasks.FirstOrDefault(x => x.id == MainTaskContainer.MainTask.Id);
 
                    lTask.status = (int)EMainTaskStatus.已分解;
                    lTask.decompositiontime = DateTime.Now;
                    dbModel.TASKPartTasks.Add(PartTaskContainer.PartTask.ToOrm());
 
                    if (PlaceContainer.Place != null)
                    {
                        var place = dbModel.BASEPlaces.FirstOrDefault(x => x.id == PlaceContainer.Place.Id);
                        if (place != null && place.id> 0)
                        {
                            place.isexecute = (int)EYesOrNo.是;
                            place.islock = (int)EYesOrNo.是;
                            place.status = (int)EPlaceStatus.执行中;
                        }
                    }
                    var count = dbModel.SaveChanges();
                    LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "保存相应的分解任务:{0}", count);
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
                }
                catch (Exception ex)
                {
 
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            } 
        }
    }
}