222
schangxiang@126.com
2025-08-23 06b5e669d423ba48fd3f92bbb318b6395e38af1b
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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.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.DoStackerTaskAuto.Chain
{
   public class 发送堆垛机任务 : IHandler
    {
        /// <summary>
        /// 该节点的下一个节点
        /// </summary>
        private IHandler nextHandler = null;
        public IHandler NextHandler
        {
            set { nextHandler = value; }
        }
 
 
        /// <summary>
        /// 任务容器
        /// </summary>
        private PartTaskContainer DecompositionTaskContainer;
 
        /// <summary>
        /// 需要执行任务的堆垛机
        /// </summary>
        private StackerEntity Stacker;
 
        /// <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
                {
                    var task = DecompositionTaskContainer.PartTask;
 
                    var dTask = dbModel.TASKPartTasks.FirstOrDefault(x => x.id == task.Id);
                    if (dTask.maintasktype != 4)//不是仅移动任务的任务需要判断物料库位,其余不用
                    {
                        var placeMaterial = dbModel.BASEPlaceMaterialViews.FirstOrDefault(x => x.materialcode == dTask.materialcode && x.placeid == dTask.sourceplaceid);
 
                        if (placeMaterial == null)
                        {
                            LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机任务:{0},{1}", task.Id, "未找到指定的物料的库位信息");
                            return;
                        }
                        placeMaterial.updatetime = DateTime.Now;
                    }
                    var toPlace = dbModel.BASEPlaces.FirstOrDefault(x => x.id == dTask.toplaceid);
 
                    if (toPlace == null)
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机任务:{0},{1}", task.Id, "未找到指定的目标库位");
                        return;
                    }
 
                    int SourcePosx = task.SourcePosx;
                    int SourcePosy = task.SourcePosy;
                    int SourcePosz = task.SourcePosz;
 
                    if (task.SourcePlace == "100105")//入库口
                    {
                        SourcePosx = 801;
                        SourcePosy = 0;
                        SourcePosz = 0;
                    }
                    else
                    {
                        if (SourcePosz % 2 == 0)
                        {
                            SourcePosz = 1;
                        }
                        else
                        {
                            SourcePosz = 2;
                        }
                    }
 
                    int ToPosx = task.ToPosx;
                    int ToPosy = task.ToPosy;
                    int ToPosz = task.ToPosz;
                    if (task.ToPlace == "100201")
                    {
                        ToPosx = 901;
                        ToPosy = 0;
                        ToPosz = 0;
                    }
                    else
                    {
                        if (ToPosz % 2 == 0)
                        {
                            ToPosz = 1;
                        }
                        else
                        {
                            ToPosz = 2;
                        }
                    }
                    int lots = task.IsLots;
                    if (CacheEntity.IsLots && task.MainTaskType == (int)EMainTaskType.入库任务)//如果设置批次入库按钮也是可以执行的
                    {
                        lots = 1;
                    }
 
                    string stackerCnName = Enum.GetName(typeof(iWareDataCore.DEV.EnumType.EEquipmentCnName), iWareDataCore.DEV.EnumType.EEquipmentCnName.stacker1);
                    var flag = Stacker.SendTask(task.Id, Stacker.Equipment.EquipName == stackerCnName ? 1 : 2, SourcePosx, SourcePosy, SourcePosz, ToPosx, ToPosy, ToPosz, task.MainTaskType, lots);//x列,y层,z排
 
                    if (flag)
                    {
                        dTask.isreleased = (int)EYesOrNo.是;
                        dTask.status = (int)EPartTaskStatus.执行中;
                        dTask.iscurrent = (int)EYesOrNo.是;
                        dTask.updatetime = DateTime.Now;
                        if (task.MainTaskType != 4)
                        {
                            toPlace.isexecute = (int)EYesOrNo.是;
                            toPlace.islock = (int)EYesOrNo.是;
                            toPlace.status = (int)EPlaceStatus.执行中;
                        }
 
                        dbModel.SaveChanges();
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机机任务:{0},{1},{2}", task.Id, flag, lots);
                    }
                    else
                    {
                        LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机机任务:{0},{1},{2}", task.Id, flag, lots);
                        return;
                    }
 
 
                    if (nextHandler != null)
                    {
                        nextHandler.Handle();
                    }
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine(Resources.LogDir + @"/自动执行堆垛机任务流程/" + Stacker.Equipment.EquipName, "发送堆垛机机任务:{0}", ex.Message);
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "Handle", ex.Message);
                }
            }
        }
    }
}