schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
//using iWareCommon.Utils;
//using iWareModel.Entity.MES;
//using iWareSql.MyDbContext;
//using Newtonsoft.Json;
//using System;
//using System.Collections.Generic;
//using System.Threading;
//using System.Linq;
//using Admin.NET.Core.TaskModule.Enum;
//using System.Configuration;
//using iWareModel.Entity.WCS;
//using iWareCC.Common.Helper;
//using Newtonsoft.Json.Bson;
//using System.Data.Entity;
//using System.Web;
//using iWareModel.Entity.WMS;
//using iWareCommon;
//using System.Threading.Tasks;
//using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
//using System.Windows.Forms;
//using iWareSql.DataAccess;
 
//namespace iWareCC
//{
//    /// <summary>
//    /// 3巷道下发任务处理的线程
//    /// </summary>
//    public class IssueTask3Handler
//    {
//        public static void Handler()
//        {
//            var errMsg = "";
//            while (true)
//            {
//                try
//                {
//                    //SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "循环开始...";
//                    if (SystemValue.isAllowRuning_OutTaskIssueTaskHandler3 && SystemValue.isStartedModel)
//                    {
//                        errMsg = "";//重置
//                        try
//                        {
 
//                            #region 查询堆垛机是否空闲
//                            //var utl = string.Format(WcsIp + @"GetDevicesInfo?Timestamp={0}&Creator={1}", DateTime.Now.ToString(), "cc");
//                            //var result1 = HttpHelper.Post(utl, "");
 
//                            WCSDevicesOutput data1 = null;
//                            if (FormCC.IsSimulationPLC)
//                            {//如果是模拟
//                                data1 = MyExtendHelper.GetSimulationSrmDevicesOutput();
//                                Log4NetHelper.WriteInfoLog(LogType.IssueTask3, "出库处理的线程(OutPlanTaskHandler)查询堆垛机是否空闲,模拟环境");
//                                SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "堆垛机状态查询模拟";
//                            }
//                            else
//                            {
//                                var utl = string.Format(@"GetDevicesInfo?Timestamp={0}&Creator={1}", DateTime.Now.ToString(), "cc");
//                                IDictionary<string, string> parameter = new Dictionary<string, string>();
//                                var result1 = new HTTPService(FormCC.WcsIp).postContentForString(utl, parameter, "");
 
//                                Log4NetHelper.WriteInfoLog(LogType.IssueTask3, "出库处理的线程(OutPlanTaskHandler)查询堆垛机是否空闲,返回结果:" + result1);
//                                if (result1 == null)
//                                {
//                                    SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "堆垛机状态查询失败,WCS返回NULL";
//                                    continue;//继续下一次循环
//                                }
//                                data1 = JsonConvert.DeserializeObject<WCSDevicesOutput>(result1);
//                                if (data1 == null || !data1.Success || data1.Data == null)
//                                {
//                                    SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "堆垛机状态查询失败,WCS返回结果:" + result1;
//                                    continue;//继续下一次循环
//                                }
//                            }
 
 
//                            if (data1.Data != null && data1.Data.SRM3 != null && data1.Data.SRM3.isfree == "1")
//                            {
//                                using (MyDbContext mycontext3 = new MyDbContext())
//                                {
//                                    int Lane = int.Parse(data1.Data.SRM3.SrmNo);
//                                    //如果有 ,就不下发出库任务了 【Editby shaocx,2023-03-07】
//                                    var wareTask = TaskHandler.IsExistNoFinishedAndHasIssueWCSTaskByLane(mycontext3, 3);
//                                    if (wareTask != null)
//                                    {
//                                        SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = $"|| 3巷道下发出库任务失败,因为存在未结束,但是已下发WCS的任务!任务号:{wareTask.TaskNo},起点:{wareTask.FromLocationCode},目标点:{wareTask.ToLocationCode}";
//                                        continue;//继续下一次循环
//                                    }
 
//                                    var ware_Tasks = mycontext3.ware_task.Where(x => (x.IsDeleted == null || x.IsDeleted == false) && x.State == 0 && x.AreaType == (int)AreaTypeEnum.立体库 && x.TaskCategory == 2 && x.Lane == Lane)
//                                          .Where(TaskHandler.CommonFilterExpressionForNoFinishAndNoCancel())
//                                        .OrderByDescending(x => x.TaskPriority).ToList();//查询未WCS下发未完成的任务
//                                    if (ware_Tasks != null && ware_Tasks.Count > 0)
//                                    {
//                                        IssueTaskHelper.Out(mycontext3, FormCC.WcsIp, Lane, ware_Tasks, ref errMsg);
//                                        if (!string.IsNullOrEmpty(errMsg))
//                                        {
//                                            SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "|| 3巷道下发出库任务失败," + errMsg;
//                                        }
//                                    }
//                                }
//                            }
//                            else
//                            {
//                                SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "|| 3号巷道无任务或者3号堆垛机不是空闲状态!";
//                            }
//                            #endregion
//                            // SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "循环结束...";
//                        }
//                        catch (Exception ex)
//                        {
//                            Log4NetHelper.WriteErrorLog(LogType.IssueTask3, "处理出入库下发=>" + errMsg + ",异常:" + ex.Message, ex);
//                            SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "处理出入库下发=>" + errMsg + ",异常:" + ex.Message;
//                        }
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3 = "出现异常:" + ex.Message;
//                    Log4NetHelper.WriteErrorLog(LogType.IssueTask3, "OutPlanTaskHandler 出库任务 出现异常:" + ex.Message, ex);
//                }
//                Thread.Sleep(3 * 1000);//休眠3秒
//            }
//        }
//    }
//}