schangxiang@126.com
2025-04-01 de7dbe7cf85aa01abb64040aae1c04dfba74c135
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
//using Admin.NET.Application;
//using iWareCC.StationService;
//using iWareCommon.Common.Globle;
//using iWareCommon.Utils;
//using iWareModel;
//using iWareSql.DataAccess;
//using iWareSql.WmsDBModel;
//using System;
//using System.Linq;
//using System.Threading;
//using System.Threading.Tasks;
 
//namespace iWareCC.ThreadService
//{
//    /// <summary>
//    /// 机器人缓存岛出库任务完成处理
//    /// </summary>
//    public static class DataProcess_RobotBuffer_FinishTaskForOutbound
//    {
//        public static async void Handler()
//        {
//            var alertMsg = "";
//            LogType logType = LogType.DataProcess_RobotBuffer_FinishTaskForOutbound;
//            while (true)
//            {
//                Thread.Sleep(500);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
//                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = string.Empty;
//                try
//                {//SystemValue.isAllowRuning_DataProcess_RobotBuffer_FinishTaskForOutbound &&
//                    if (SystemValue.isStartedModel)
//                    {
//                        var rgvLocation = StationLocationEnum.BZ39.ToString();
//                        if (FormCC.stationView == null)
//                        {
//                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-获取PLC对象为null";
//                            continue;
//                        }
//                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
//                        if (obj.R_OutboundFinish)
//                        {
//                            //var result = obj.R_OutboundNumber;
//                            //if (string.IsNullOrEmpty(result))
//                            //{
//                            //    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}- 出库库位号是空的,此次循环结束";
//                            //    continue;
//                            //}
 
//                            var result2 = obj.R_Outbound_TaskID;
//                            if (result2 == 0)
//                            {
//                                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}- 出库任务号是空的,此次循环结束";
//                                continue;
//                            }
 
 
 
//                            using (WmsDBModel wmsDB = new WmsDBModel())
//                            {
//                                var task = wmsDB.wms_rbline_task.Where(x =>
//                                 x.TaskNo == obj.R_Outbound_TaskID.ToString()
//                                && (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
//                                ).OrderByDescending(x => x.Id).FirstOrDefault();
//                                if (task == null)
//                                {
//                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据 R_OutboundNumber:{obj.R_OutboundNumber}没有找到已下发的任务 ";
//                                    continue;
//                                }
//                                else
//                                {
//                                    if (task.TaskStatus == (int)TaskStatusEnum.已完成)
//                                    {
//                                        using (StationServiceClient client = new StationServiceClient())
//                                        {
//                                            var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation, false);
//                                        }
//                                        continue;
//                                    }
 
//                                }
 
//                                var isSuccess = await HandlerData(wmsDB, task, rgvLocation, logType, false);
//                                if (isSuccess == false)
//                                {
//                                    continue;
//                                }
 
//                                //var upiCode = task.Upi;
//                                //var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
//                                //if (upiObj == null)
//                                //{
//                                //    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
//                                //    continue;
//                                //}
//                                ////更新板件的状态和区域
//                                //if (task.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务)
//                                //{
//                                //    upiObj.UpiStatus = (int)UpiStatusEnum.已齐包;
//                                //    upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
//                                //}
//                                //else if (task.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
//                                //{
//                                //    upiObj.UpiStatus = (int)UpiStatusEnum.已下线;
//                                //    upiObj.AreaCode = (int)AreaCodeEnum.下线区域;
//                                //}
 
//                                ////库存减少
//                                //wms_stock_quan qun = wmsDB.wms_stock_quan.Where(x => x.PlaceCode == task.PlaceCode).FirstOrDefault();
//                                //wmsDB.wms_stock_quan.Remove(qun);
 
//                                //task.TaskStatus = (int)TaskStatusEnum.已完成;
//                                //task.FinishedTime = DateTime.Now;
 
//                                //var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
//                                //place.PlaceStatus = (int)PlaceStatusEnum.正常;
 
//                                ////给PLC推送任务完成确认信号
//                                //using (StationServiceClient client = new StationServiceClient())
//                                //{
//                                //    var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation, true);
//                                //    if (!res.result)
//                                //    {
//                                //        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发出库任务 失败,OutboundFinishConfirmAsync 返回:{res.resMsg}";
//                                //        continue;
//                                //    }
//                                //    else
//                                //    {
//                                //        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 成功,OutboundFinishConfirmAsync,参数: 站点{rgvLocation}");
//                                //    }
//                                //}
 
//                                //WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, $"出缓存库:{task.PlaceCode}," + task.TaskMsg);
 
//                                //wmsDB.SaveChanges();
//                            }
//                        }
//                        else
//                        {
//                            using (StationServiceClient client = new StationServiceClient())
//                            {
//                                var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, false, rgvLocation, false);
//                            }
 
//                            using (WmsDBModel wmsDB = new WmsDBModel())
//                            {
//                                var task = wmsDB.wms_rbline_task.Where(x =>
//                                 x.IsFlagFinish == true
//                               && (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
//                                && x.TaskStatus == (int)TaskStatusEnum.已下发
//                                ).OrderByDescending(x => x.Id).FirstOrDefault();
//                                if (task == null)
//                                {
//                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},没有找到已下发,并且标记强制完成的任务 ";
//                                    continue;
//                                }
 
//                                var isSuccess = await HandlerData(wmsDB, task, rgvLocation, logType, true);
//                                if (isSuccess == false)
//                                {
//                                    continue;
//                                }
//                            }
//                        }
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
//                    Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
//                }
//            }
//        }
 
 
//        public static async Task<bool> HandlerData(WmsDBModel wmsDB, wms_rbline_task task, string rgvLocation, iWareCommon.Utils.LogType logType, bool isFlagFinish)
//        {
//            var upiCode = task.Upi;
//            var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
//            if (upiObj == null)
//            {
//                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
//                return false;
//            }
//            //更新板件的状态和区域
//            if (task.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务)
//            {
//                upiObj.UpiStatus = (int)UpiStatusEnum.已齐包;
//                upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
//            }
//            else if (task.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
//            {
//                upiObj.UpiStatus = (int)UpiStatusEnum.已下线;
//                upiObj.AreaCode = (int)AreaCodeEnum.下线区域;
//            }
 
//            //库存减少
//            wms_stock_quan qun = wmsDB.wms_stock_quan.Where(x => x.PlaceCode == task.PlaceCode).FirstOrDefault();
//            wmsDB.wms_stock_quan.Remove(qun);
 
//            task.TaskStatus = (int)TaskStatusEnum.已完成;
//            task.FinishedTime = DateTime.Now;
 
//            var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
//            place.PlaceStatus = (int)PlaceStatusEnum.正常;
 
//            //if (isFlagFinish == false)
//            //{
//            //    //给PLC推送任务完成确认信号
//            //    using (StationServiceClient client = new StationServiceClient())
//            //    {
//            //        var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation, true);
//            //        if (!res.result)
//            //        {
//            //            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发出库任务 失败,OutboundFinishConfirmAsync 返回:{res.resMsg}";
//            //            return false;
//            //        }
//            //        else
//            //        {
//            //            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 成功,OutboundFinishConfirmAsync,参数: 站点{rgvLocation}");
//            //        }
//            //    }
//            //}
 
//            var flag = isFlagFinish ? "人工强制完成" : "(自动完成)";
//            WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, $"出缓存库:{task.PlaceCode}(" + flag + ")," + task.TaskMsg);
 
//            int changeNum = wmsDB.SaveChanges();
//            if (changeNum > 0)
//            {
//                //必须要给PLC下发成功,解决可能会给PLC重复下发任务的情况
//                var isRight = true;
 
//                if (isFlagFinish == false)
//                {
//                    while (isRight)
//                    {
//                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
//                        isRight = obj.R_OutboundFinish;
//                        //给PLC推送任务完成确认信号
//                        using (StationServiceClient client = new StationServiceClient())
//                        {
//                            var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation, true);
//                            if (!res.result)
//                            {
//                                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发入库任务 失败,InboundFinishConfirmAsync 返回:{res.resMsg}";
//                                Log4NetHelper.WriteErrorLog(logType, $"{rgvLocation.ToString()}-完成出库任务【true】 失败,OutboundFinishConfirmAsync,返回:{res.resMsg},参数:TaskNo:{task.TaskNo}, PlaceCode:{task.PlaceCode},条码:{task.Upi}");
//                            }
//                            else
//                            {
//                                Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-完成出库任务【true】 成功,OutboundFinishConfirmAsync,,参数:TaskNo:{task.TaskNo}, PlaceCode:{task.PlaceCode},条码:{task.Upi}");
//                                //isRight = false;
//                            }
//                        }
//                        Thread.Sleep(1000);
//                    }
//                }
//            }
 
//            return true;
//        }
 
//    }
//}