schangxiang@126.com
2025-09-23 1ec17ce75f4e4324e9756a91c74f3f52928c9351
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
using iWareCc.DecomposeTask.Entity;
using iWareCcTest.Properties;
using iWareCc.Srm.Entity;
using iWareCommon.Common.Entity;
using iWareCommon.Common.EnumType;
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.FinishStackerTask.Chain
{
   public class 获取当前的堆垛机任务 : IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private StackerEntity Stacker;
 
        /// <summary>
        /// 任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
 
        public 获取当前的堆垛机任务(StackerEntity stacker, PartTaskContainer decompositionTaskContainer)
        {
            this.Stacker = stacker;
            this.DecompositionTaskContainer = decompositionTaskContainer;
        }
 
 
        public void Handle()
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var task = dbModel.TASKPartTasks.OrderBy(x => x.finishtimes).FirstOrDefault(x => x.iscurrent == (int)EYesOrNo.是 && x.isreleased == (int)EYesOrNo.是 && x.isfinished == (int)EYesOrNo.否 && x.type == (int)EPartTaskType.堆垛机任务 && x.equipid == Stacker.Equipment.Id);
 
                    if (task == null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "获取当前的堆垛机任务:{0}", "没有找到待完成的任务");
                        return;
                    }
 
 
                    task.finishtimes += 1;
 
                    dbModel.SaveChanges();
 
                    DecompositionTaskContainer.PartTask = new PartTaskEntity(task);
                    LogTextHelper.WriteLine(Resources.LogDir + @"/完成堆垛机任务/" + Stacker.Equipment.EquipName, "获取当前的堆垛机任务:{0}", DecompositionTaskContainer.PartTask.Id);
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
 
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}