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
using iWareCc.Cache.Entity;
using iWareCc.DecomposeTask.Entity;
using iWareCcTest.Properties;
using iWareCc.Srm.Entity;
using iWareCommon.Common.Entity;
using iWareCommon.Utils;
using iWareDataCore.TASK.EnumType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCc.DecomposeTask.Strategy.出库任务.Chain
{
    public class 判断堆垛机是否空闲: IHandler
    {
        private MainTaskContainer LogisticalTaskContainer;
 
        private ResultContainer ResultContainer;
 
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
        public 判断堆垛机是否空闲(ResultContainer resultContainer, MainTaskContainer logisticalTaskContainer)
        {
            this.ResultContainer = resultContainer;
            this.LogisticalTaskContainer = logisticalTaskContainer;
        }
 
        public void Handle()
        {
            try
            {
                StackerEntity stacker = null;
                string stackerName = Enum.GetName(typeof(iWareDataCore.DEV.EnumType.EEquipmentCnName), iWareDataCore.DEV.EnumType.EEquipmentCnName.stacker1);
                if (CacheEntity.DeviceRunningMode == null || CacheEntity.DeviceRunningMode.Mode == (int)EDeviceMode.双堆垛机模式)
                {
                    stacker = CacheEntity.Stackers.FirstOrDefault(x => x.Equipment.EquipName == stackerName);
                }
                else
                {
                    stacker = CacheEntity.Stackers.FirstOrDefault(x => x.Equipment.EquipName == CacheEntity.DeviceRunningMode.EquipmentName);
                }    
 
                string msg;
 
                if (!stacker.CanDecomposeTask(out msg))
                {
                    ResultContainer.Msg = msg;
                    LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "判断与任务匹配的堆垛机是否空闲:{0}", msg);
                    return;
                }
 
                var conveyor = CacheEntity.Conveyors.FirstOrDefault(x => x.Equipment.EquipName == "conveyor2");
                var gate = conveyor.Gates.FirstOrDefault(x => x.Place.PlaceTypeName == "gate21");
 
                if (!gate.RIsEmpty)
                {
                    ResultContainer.Msg = "出库口不允许放货";
                    LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "判断与任务匹配的堆垛机是否空闲:{0}", ResultContainer.Msg);
                    return;
                }
 
                LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "判断与任务匹配的堆垛机是否空闲:{0}", "ok");
                
                if (nextHandler != null)
                {
                    nextHandler.Handle();
                }
            }
            catch (Exception ex)
            {
                ResultContainer.Msg = ex.Message;
                LogTextHelper.WriteLine(Resources.LogDir + @"/分解任务流程", "判断与任务匹配的堆垛机是否空闲:{0}", ex.Message);
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
            }
        }
    }
}