schangxiang@126.com
2025-06-04 3e837690e8a1d3b6e86f3db72d2d84eab1bc7114
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
96
97
98
99
100
101
102
103
104
105
106
using iWareCc.Cache.Entity;
using iWareCc.DecomposeTask.Entity;
using iWareCc.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.DoStackerTaskAuto.Chain
{
   public class 选择一个未执行的堆垛机的任务 : IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        private StackerEntity Stacker;
 
        /// <summary>
        /// WIP任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
 
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="resultContainer">结果容器</param>
        /// <param name="decompositionTaskContainer">WIP任务容器</param>
        public 选择一个未执行的堆垛机的任务(StackerEntity stacker, PartTaskContainer decompositionTaskContainer)
        {
            this.Stacker = stacker;
            this.DecompositionTaskContainer = decompositionTaskContainer;
        }
 
 
        public void Handle()
        {
 
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    string msg;
                    if (!Stacker.CanParseTask(out msg))
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "选择一个未执行的堆垛机的任务:堆垛机{0}不能执行任务--{1}", Stacker.Equipment.EquipName, msg);
                        return;
                    }
 
                    var task = dbModel.TASKPartTasks.OrderByDescending(x=>x.maintasktype == (int)EMainTaskType.出库任务).OrderByDescending(x => x.priority).ThenBy(x => x.createtime).FirstOrDefault(x => x.type == (int)EPartTaskType.堆垛机任务 && x.isreleased == (int)EYesOrNo.否 && x.isfinished == (int)EYesOrNo.否 && x.equipid == Stacker.Equipment.Id);
 
                    if (task == null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "选择一个未执行的堆垛机的任务:{0}", "未找到相应的堆垛机任务");
                        return;
                    }
 
                    if (task.maintasktype == (int)EMainTaskType.出库任务)//出库任务验证gate21端口是否为空,否则不能执行出库任务
                    {
                        var gate = CacheEntity.Conveyors.Find(x => x.Equipment.EquipName == "conveyor2").Gates.FirstOrDefault(x => x.Place.PlaceTypeName == "gate21");
                        var gate22 = CacheEntity.Conveyors.Find(x => x.Equipment.EquipName == "conveyor2").Gates.FirstOrDefault(x => x.Place.PlaceTypeName == "gate22");
                        if (!gate.RIsEmpty|| !gate22.RIsEmpty)
                        {
                            LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "选择一个未执行的堆垛机的任务:{0}", "出库口有料不能发送出库任务");
                            return;
                        }
                        //判断有没有gate21去gate22的未完成任务
                        var covtask = dbModel.TASKPartTasks.FirstOrDefault(x => x.isfinished == 0 && x.sourceplace == "100201" && x.toplace == "100202");
                        if (covtask!=null)
                        {
                            LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "选择一个未执行的堆垛机的任务:{0}", "当前有未完成的出库输送线任务");
                            return;
                        }
                    }
                    // 这段代码我希望在出库口有料和当前有未完成的出库输送线任务时task时task不取出库任务怎么修改代码
                    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);
                }
            }
        }
    }
}