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
86
87
88
89
90
91
92
93
94
95
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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.HandleTask.Chain
{
  public  class 保存处理信息 : IHandler
    {
        private IHandler nextHandler = null;
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        /// <summary>
        /// 处理任务容器
        /// </summary>
        private PartTaskContainer HandleTaskContainer;
 
        /// <summary>
        /// 下一任务容器
        /// </summary>
        private PartTaskContainer NextTaskContainer;
 
        /// <summary>
        /// 保存处理任务
        /// </summary>
        public 保存处理信息(PartTaskContainer handleTaskContainer, PartTaskContainer nextTaskContainer)
        {
            this.HandleTaskContainer = handleTaskContainer;
            this.NextTaskContainer = nextTaskContainer;
        }
 
        /// <summary>
        /// 数据库里更新处理任务,保存下一任务
        /// </summary>
        public void Handle()
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var hTask = dbModel.TASKPartTasks.FirstOrDefault(x => x.id == HandleTaskContainer.PartTask.Id);
                    hTask.ishandled = (int)EYesOrNo.是;
                    hTask.updatetime = DateTime.Now;
 
                    var nTask = NextTaskContainer.PartTask;
                    if (nTask != null)
                    {
                        dbModel.TASKPartTasks.Add(nTask.ToOrm());
                        var toPlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == nTask.ToPlaceId);
                        if (toPlace != null)
                        {
                            toPlace.isexecute = (int)EYesOrNo.是;
                            toPlace.islock = (int)EYesOrNo.是;
                            toPlace.status = (int)EPlaceStatus.执行中;
                        }
 
                        var fromPlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == nTask.SourcePlaceId);
 
                        if (fromPlace != null)
                        {
                            fromPlace.isexecute = (int)EYesOrNo.是;
                            fromPlace.islock = (int)EYesOrNo.是;
                            fromPlace.status = (int)EPlaceStatus.执行中;
                        }
                    }
                    dbModel.SaveChanges();
                    LogTextHelper.WriteLine(Resources.LogDir + @"/处理任务流程", "保存处理信息");
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine(Resources.LogDir + @"/处理任务流程", "保存处理信息:{0}", ex.Message);
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}