222
schangxiang@126.com
2024-12-03 60a4de55deb1aeeb5621028a8f8c732c38027f81
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
using iWareCC.Common.Helper;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareModel.EnumType.XiGangPublicCommon;
using iWareSql;
using iWareSql.DataAccess;
using iWareSql.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using XiGang.Core.Model;
 
namespace iWareCC
{
    /// <summary>
    /// 空托盘转运任务
    /// </summary>
    public static class EmptySalverTransferTask
    {
        /// <summary>
        /// 空托盘转运任务
        /// </summary>
        public static void Handler()
        {
            while (true)
            {
                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound = string.Empty;
                bool isHasFinishedCurrentHanlder = false;//是否已经处理完了空托盘转运任务
                try
                {
                    if (SystemValue.isAllowRuning_DataProcess_RobotBuffer_IssueOutboundTask && SystemValue.isStartedModel)
                    {
                        //此处判断 1009 1010 1011的状态
                        bool isEmptyPlace_1011 = false, isEmptyPlace_1010 = false, isEmptyPlace_1009 = false;
                        V_AllStore store = null;
                        using (DbModel context = new DbModel())
                        {
                            //1、先看1011站点,光电是否有货,并且系统有库存,如果 光电有货+系统有库存,
                            EDevice rgvLocation = EDevice.空托缓存1011;
                            var stationCode = Convert.ToInt32(rgvLocation).ToString();
                            bool isGD_HasCatogryForRgvStattion = MyExtendHelper.IsGD_HasCatogryForRgvStattion(stationCode);
                            bool isSys_HasCatogryForRgvStattion = MyExtendHelper.IsSys_HasCatogryForRgvStattion(context, stationCode, ref store);
                            bool isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(stationCode);
                            if (isSys_HasCatogryForRgvStattion || isGD_HasCatogryForRgvStattion)
                            {
                                isEmptyPlace_1011 = false;
                            }
                            else
                            {
                                isEmptyPlace_1011 = true;
                            }
                            if (isSys_HasCatogryForRgvStattion && isGD_HasCatogryForRgvStattion && !isExistOtherTaskDoing)
                            {
                                var isAllowDoHandlerFor1011 = false;
 
 
                                #region 判断是否允许发任务给1011
                                var isGD_HasCatogryForRgvStattion_1014 = MyExtendHelper.IsGD_HasCatogryForRgvStattion(((int)EDevice.拆盘机入口1014).ToString());
                                if (!isGD_HasCatogryForRgvStattion_1014)
                                {//1014无货
                                    isAllowDoHandlerFor1011 = true;
                                }
                                else
                                {//1014有货
                                    //判断1009是否有货
                                    var isGD_HasCatogryForRgvStattion_1009 = MyExtendHelper.IsGD_HasCatogryForRgvStattionFor2(((int)EDevice.空托缓存1009).ToString());
                                    if (isGD_HasCatogryForRgvStattion_1009)
                                    {//1009有货,就要下发1011的任务了,不能堵着人家1009的任务啊
                                        isAllowDoHandlerFor1011 = true;
                                    }
                                    else
                                    {
                                        if (FormCC.RGV_1011_HasCategory_COUNT < SysGloble.MAX_RGV_1011_HasCategory_COUNT)
                                        {
                                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:1011处不允许创建任务,1011有货时间:" + FormCC.RGV_1011_HasCategory_COUNT
                                                + ",还未大于设定的最大超时时间:" + SysGloble.MAX_RGV_1011_HasCategory_COUNT + SysGloble.SPLIT_STR;
                                        }
                                        else
                                        {
                                            isAllowDoHandlerFor1011 = true;
                                        }
                                    }
                                }
                                #endregion
 
                                if (isAllowDoHandlerFor1011 == true)
                                {
                                    var fr = MyExtendHelper.DoHandler(context, store, rgvLocation);
                                    if (fr.result == false)
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:1011处新建任务失败:" + fr.resMsg + SysGloble.SPLIT_STR;
                                    }
                                    else
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "成功创建1011任务" + SysGloble.SPLIT_STR;
                                        continue;
                                    }
                                    isHasFinishedCurrentHanlder = true;
                                }
                                else
                                {//不允许下发1011的任务
 
                                }
                            }
 
                            //2、先看1010站点,光电是否有货,并且系统有库存,如果 光电有货+系统有库存,
                            //还要判断1011是否有货
                            rgvLocation = EDevice.空托缓存1010;
                            stationCode = Convert.ToInt32(rgvLocation).ToString();
                            isGD_HasCatogryForRgvStattion = MyExtendHelper.IsGD_HasCatogryForRgvStattion(stationCode);
                            isSys_HasCatogryForRgvStattion = false;//1010的不关心库存,因为他不是目的点
                            // isSys_HasCatogryForRgvStattion = IsSys_HasCatogryForRgvStattion(context, stationCode, ref store);
                            if (isSys_HasCatogryForRgvStattion || isGD_HasCatogryForRgvStattion)
                            {
                                isEmptyPlace_1010 = false;
                            }
                            else
                            {
                                isEmptyPlace_1010 = true;
                            }
                            //isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(context, stationCode);
                            //if (isSys_HasCatogryForRgvStattion && isGD_HasCatogryForRgvStattion && !isExistOtherTaskDoing
                            //    && isEmptyPlace_1011 == true)
                            //{
                            //    var fr = DoHandler(context, store, rgvLocation);
                            //    if (fr.result == false)
                            //    {
                            //        SystemWarningMsg._lbl_Alert_EmptySalverTransfer = "错误:1010处新建任务失败:" + fr.resMsg;
                            //    }
                            //}
 
                            //3、先看1009站点,光电是否有货,并且系统有库存,如果 光电有货+系统有库存,
                            //还要判断1010是否有货
                            rgvLocation = EDevice.空托缓存1009;
                            stationCode = Convert.ToInt32(rgvLocation).ToString();
                            isGD_HasCatogryForRgvStattion = MyExtendHelper.IsGD_HasCatogryForRgvStattionFor2(stationCode);
                            isSys_HasCatogryForRgvStattion = MyExtendHelper.IsSys_HasCatogryForRgvStattion(context, stationCode, ref store);
                            if (isSys_HasCatogryForRgvStattion || isGD_HasCatogryForRgvStattion)
                            {
                                isEmptyPlace_1009 = false;
                            }
                            else
                            {
                                isEmptyPlace_1009 = true;
                            }
                            isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(stationCode);
                            if (!isSys_HasCatogryForRgvStattion && isGD_HasCatogryForRgvStattion && !isExistOtherTaskDoing
                                //注意:1009要判断没有库存才可以。
                                //1010必须是空闲无货
                                && isEmptyPlace_1010 == true
                                //1011必须是空闲无货
                                && isEmptyPlace_1011 == true
                                //是否已经处理完了空托盘转运任务为false
                                && isHasFinishedCurrentHanlder == false
                                )
                            {
                                #region 增加光电信号点的检测
                                //增加光电信号点的检测 【Editby shaocx,2022-05-01】
                                var salverStackCount = MyExtendHelper.GetSalverStackCountForBackToStore();
                                if (salverStackCount == 0)
                                {
                                    //报错
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += ("[检测]根据1009站点的光电获取返回立体库的托盘数为0") + SysGloble.SPLIT_STR;
                                    continue;
                                }
                                //休眠5秒
                                Thread.Sleep(5000);
                                var salverStackCount2 = MyExtendHelper.GetSalverStackCountForBackToStore();
                                if (salverStackCount2 == 0)
                                {
                                    //报错
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += ("[检测]根据1009站点的光电获取返回立体库的托盘数为0") + SysGloble.SPLIT_STR;
                                    continue;
                                }
                                if (salverStackCount != salverStackCount2)
                                {
                                    //报错
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += ("根据1009站点的光电,相差5秒获取返回立体库的托盘数不一致,第一次是" + salverStackCount + ",第二次是" + salverStackCount2) + SysGloble.SPLIT_STR;
                                    continue;
                                }
 
                                #endregion
 
 
                                var fr = MyExtendHelper.DoHandler(context, null, rgvLocation);
                                if (fr.result == false)
                                {
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:1009处新建任务失败:" + fr.resMsg + SysGloble.SPLIT_STR;
                                }
                                else
                                {
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "成功创建1009任务" + SysGloble.SPLIT_STR;
                                    continue;
                                }
                                isHasFinishedCurrentHanlder = true;
                            }
 
 
                            //3、判断1014是否需要去放空托,从立体库送过来的 【EditBy shaocx,2022-04-14】
                            rgvLocation = EDevice.拆盘机入口1014;
                            stationCode = Convert.ToInt32(rgvLocation).ToString();
 
                            //增加验证,1009上两个光电有货,或 1010上其中一个光电有货,或 1011上一个光电有货,就先暂停不要下发去1014的任务,目的是为了优先让托盘回收的去1014位置,提高节拍 [EditBy shaocx,2022-05-01]
                            var errMsg = "";
                            if (!MyExtendHelper.IsAllowSendTaskTo1014ByTPHS(ref errMsg))
                            {
                                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += errMsg + SysGloble.SPLIT_STR;
                                continue;
                            }
 
                            var isAllowSendTaskToPlace1014 = MyExtendHelper.IsAllowSendTaskToPlace1014(context, stationCode, ref store);
 
                            if (isAllowSendTaskToPlace1014 && isHasFinishedCurrentHanlder == false)
                            {
                                //再校验一次
                                isExistOtherTaskDoing = PartTaskHandler.IsExistOtherTaskDoing(stationCode);
                                if (!isExistOtherTaskDoing)
                                {
                                    if (!MyExtendHelper.IsAllowSendTaskTo1014ByTPHS(ref errMsg))
                                    {//再次校验 【EditBy shaocx,2022-05-18】
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += errMsg + SysGloble.SPLIT_STR;
                                        continue;
                                    }
                                    //判断1011位置是否有库存,并且是未锁定状态,如果是,就不要创建从立体库到1014的任务了【EditBy shaocx,2022-05-18】
                                    var query1011 = ((int)EDevice.空托缓存1011).ToString();
                                    var store1011 = context.V_AllStore.Where(x => x.RgvStationCode == query1011).FirstOrDefault();
                                    if (store1011 != null && store1011.StationId > 0)
                                    //if (store1011 != null && store1011.StationIsLock == false && store1011.StationIsHasTaskDoing == false)
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "1011位置有系统库存存在,因此不需要创建从立体库到1014的任务。。" + SysGloble.SPLIT_STR;
                                        continue;
                                    }
 
                                    var fr = MyExtendHelper.DoHandler(context, null, rgvLocation);
                                    if (fr.result == false)
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "错误:拆盘机入口1014处新建从立体库叫托盘任务失败:" + fr.resMsg + SysGloble.SPLIT_STR;
                                    }
                                    else
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "成功创建拆盘机入口1014处新建从立体库叫托盘任务" + SysGloble.SPLIT_STR;
                                        continue;
                                    }
                                }
                            }
 
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += "分解线程出现异常:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(LogType.DataProcess_RobotBuffer_IssueOutboundTask, "HandlerIssuingTask出现异常:" + ex.Message, ex);
                }
 
            }
        }
    }
}