qinchulong
2025-03-29 039a4a5433e7f80adc88b491b549e5d9486e4f9a
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using WIDESEA_Common;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_Services.Services;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS.Jobs
{
    public partial class EquipmentExecutor : SchedulerExecuteBase 
    {
        private static int _readFFQDOWNSignalso = 0;
        public static void F_FQSB_DownTask()
        {
            if (Interlocked.Exchange(ref _readFFQDOWNSignalso, 1) == 0)
            {
                try
                {
                    VOLContext Context = new VOLContext();
                    Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(Context);
                    dt_task_numberService tasknumber = new dt_task_numberService(tasknumberRep);
                    Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
                    Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
                    Ibill_pda_groupdiskRepository pdaRepository = new bill_pda_groupdiskRepository(Context);
                    Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
                    Ibill_group_stockRepository groupRepository = new bill_group_stockRepository(Context);
                    IequipmentRepository equipmentRepository = new equipmentRepository(Context);
                    List<string> FQSBS = new List<string> { "负机1号分切机", "负机2号分切机" };
                    //List<string> FQSBS = new List<string> {  "负机2号分切机" };
                    PLCClient zagvplc = WCSService.Clients.Find(v => v.PLCName == "负极1号AGV");
                    foreach (var FQSB in FQSBS)
                    {
                        WriteLog.Info($"{FQSB}下料").Write($"{FQSB}开始,时间:" + DateTime.Now + "   ----------", $"{FQSB}下料");
                        PLCClient plc = WCSService.Clients.Find(v => v.PLCName == FQSB);
                        if (plc == null)
                        {
                            continue;
                        }
                        var task = agvRepository.FindFirst(f => f.agv_toaddress == ""&&f.agv_fromaddress.Substring(0,2)=="FJ");
                        if (task == null)
                        {
                            //读取下料请求信号
                            string isWork = plc.ReadValue(ConveyorLineInfoDBName.R_FQSB_DOWNrequest.ToString(), plc.PLCDescroption).ToString();
                            //获取工单号
                            string batchNo = plc.ReadValue(ConveyorLineInfoDBName.R_FQSB_DOWNbatchNo.ToString(), plc.PLCDescroption).ToString();
                            GetEquipmentInfo(plc.PLCDownLoc, isWork, batchNo, "", "");
                            WriteLog.Info($"{FQSB}下料").Write($"isWork:{isWork},batchNo:{batchNo},时间:" + DateTime.Now + "   ----------", $"{FQSB}下料");
                            if (bool.Parse(isWork))
                            {
                                //调用MES接口获取设备下料信息
                                MESback material = MESAPIInvoke.EquipUnloading(plc.PLCDownLoc, batchNo);
                                WriteLog.Info($"{FQSB}下料").Write($"MES返回数据:{JsonConvert.SerializeObject(material)},时间:" + DateTime.Now + "", $"{FQSB}下料");
                                if (material.Code == 0)
                                {
                                    //查询路由信息
                                    var routes = routingRepository.Find(v => v.route_began == plc.PLCDownLoc).ToList();
                                    foreach (var route in routes)
                                    {
                                        string ismaterial = zagvplc.ReadValue(ConveyorLineInfoDBName.R_Location_iswork.ToString(), route.route_end).ToString();
                                        GetEquipmentInfo(plc.PLCDownLoc, isWork, batchNo, "", route.route_end + "的货位状态是" + ismaterial);
                                        if (ismaterial == "1")
                                            continue;
                                        var location = locRepository.FindFirst(v => v.upper_code == route.route_end);
                                        if (location.location_state != LocationStateEnum.LocationState_Wait.ToString())
                                            continue;
                                        float width = float.Parse(plc.ReadValue(ConveyorLineInfoDBName.width.ToString(), plc.PLCDescroption).ToString());
                                        int Anumber = int.Parse(plc.ReadValue(ConveyorLineInfoDBName.Anumber.ToString(), plc.PLCDescroption).ToString());
                                        int Bnumber = int.Parse(plc.ReadValue(ConveyorLineInfoDBName.Bnumber.ToString(), plc.PLCDescroption).ToString());
                                        GetEquipmentInfo(plc.PLCDownLoc, isWork, batchNo, "宽度:" + width + ",A轴卷数:" + Anumber + ",B轴卷数:" + Bnumber, route.route_end + "的货位状态是" + ismaterial);
                                        int Asum = Convert.ToInt32(width) * Anumber;
                                        int Bsum = Convert.ToInt32(width) * Bnumber;
                                        string taskId = "KH-" + tasknumber.GetTaskNumber(tasknumberRep);
                                        if (Asum + Bsum > 750 && Bsum!=0)//Asum + Bsum > 780 && Asum < 780 && Bsum < 780 && Bsum != 0
                                        {
                                            //条件全部通过,生成AGV任务
                                            dt_agvtask agvtask = new dt_agvtask
                                            {
                                                agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
                                                agv_barcode = "B",
                                                agv_code = "负极1号AGV",
                                                agv_createtime = DateTime.Now,
                                                agv_fromaddress = route.route_began,
                                                agv_grade = 1,
                                                agv_materielid = material.MaterialType,
                                                agv_qty = 1,
                                                agv_tasknum = taskId + ":1",
                                                agv_taskstate = "Create",
                                                agv_tasktype = "TaskType_Outbound",
                                                agv_toaddress = "",
                                                agv_userid = "WCS",
                                                agv_worktype = 1
                                            };
                                            agvRepository.Add(agvtask, true);
                                            dt_agvtask agvtask2 = new dt_agvtask
                                            {
                                                agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
                                                agv_barcode = "",
                                                agv_code = "负极1号AGV",
                                                agv_createtime = DateTime.Now,
                                                agv_fromaddress = route.route_end,
                                                agv_grade = 1,
                                                agv_materielid = material.MaterialType,
                                                agv_qty = 1,
                                                agv_tasknum = taskId + ":2,END",
                                                agv_taskstate = "Create",
                                                agv_tasktype = "TaskType_Outbound",
                                                agv_toaddress = "",
                                                agv_userid = "WCS",
                                                agv_worktype = 3
                                            };
                                            agvRepository.Add(agvtask2, true);
                                            location.location_state = LocationStateEnum.LocationState_Lock.ToString();
                                            locRepository.Update(location, true);
                                        }
                                        else if (Bsum == 0 && Asum != 0)//Asum + Bsum < 780 && Asum < 780 && Bsum < 780 && Asum != 0//Asum + Bsum < 780 && Asum != 0//
                                        {
                                            //条件全部通过,生成AGV任务
                                            dt_agvtask agvtask = new dt_agvtask
                                            {
                                                agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
                                                agv_barcode = "A",
                                                agv_code = "负极1号AGV",
                                                agv_createtime = DateTime.Now,
                                                agv_fromaddress = route.route_began,
                                                agv_grade = 1,
                                                agv_materielid = material.MaterialType,
                                                agv_qty = 1,
                                                agv_tasknum = taskId + ":1",
                                                agv_taskstate = "Create",
                                                agv_tasktype = "TaskType_Outbound",
                                                agv_toaddress = "",
                                                agv_userid = "WCS",
                                                agv_worktype = 1
                                            };
                                            agvRepository.Add(agvtask, true);
                                            dt_agvtask agvtask2 = new dt_agvtask
                                            {
                                                agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
                                                agv_barcode = "",
                                                agv_code = "负极1号AGV",
                                                agv_createtime = DateTime.Now,
                                                agv_fromaddress = route.route_end,
                                                agv_grade = 1,
                                                agv_materielid = material.MaterialType,
                                                agv_qty = 1,
                                                agv_tasknum = taskId + ":2,END",
                                                agv_taskstate = "Create",
                                                agv_tasktype = "TaskType_Outbound",
                                                agv_toaddress = "",
                                                agv_userid = "WCS",
                                                agv_worktype = 3
                                            };
                                            agvRepository.Add(agvtask2, true);
                                            location.location_state = LocationStateEnum.LocationState_Lock.ToString();
                                            locRepository.Update(location, true);
                                        }
                                        else if (Asum + Bsum <=750)//(width * Anumber + width * Bnumber < 780) && Asum != 0 && Bsum != 0
                                        {
                                            dt_agvtask agvtask = new dt_agvtask
                                            {
                                                agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
                                                agv_barcode = "A",
                                                agv_code = "负极1号AGV",
                                                agv_createtime = DateTime.Now,
                                                agv_fromaddress = route.route_began,
                                                agv_grade = 1,
                                                agv_materielid = material.MaterialType,
                                                agv_qty = 1,
                                                agv_tasknum = taskId + ":1",
                                                agv_taskstate = "Create",
                                                agv_tasktype = "TaskType_Outbound",
                                                agv_toaddress = "",
                                                agv_userid = "WCS",
                                                agv_worktype = 1
                                            };
                                            agvRepository.Add(agvtask, true);
                                            dt_agvtask agvtask2 = new dt_agvtask
                                            {
                                                agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
                                                agv_barcode = "B",
                                                agv_code = "负极1号AGV",
                                                agv_createtime = DateTime.Now,
                                                agv_fromaddress = route.route_began,
                                                agv_grade = 1,
                                                agv_materielid = material.MaterialType,
                                                agv_qty = 1,
                                                agv_tasknum = taskId + ":2",
                                                agv_taskstate = "Create",
                                                agv_tasktype = "TaskType_Outbound",
                                                agv_toaddress = "",
                                                agv_userid = "WCS",
                                                agv_worktype = 1
                                            };
                                            agvRepository.Add(agvtask2, true);
                                            dt_agvtask agvtask3 = new dt_agvtask
                                            {
                                                agv_materbarcode = "daiding",//下料任务预先没有条码,PDA在缓存架绑定时接收新的条码
                                                agv_barcode = "",
                                                agv_code = "负极1号AGV",
                                                agv_createtime = DateTime.Now,
                                                agv_fromaddress = route.route_end,
                                                agv_grade = 1,
                                                agv_materielid = material.MaterialType,
                                                agv_qty = 1,
                                                agv_tasknum = taskId + ":3,END",
                                                agv_taskstate = "Create",
                                                agv_tasktype = "TaskType_Outbound",
                                                agv_toaddress = "",
                                                agv_userid = "WCS",
                                                agv_worktype = 3
                                            };
                                            agvRepository.Add(agvtask3, true);
                                            location.location_state = LocationStateEnum.LocationState_Lock.ToString();
                                            locRepository.Update(location, true);
                                        }
                                        break;
                                    }
                                }
                                else
                                {
                                    WriteLog.Info("F_FQSB_DownTask").Write("调用MES接口EquipUnloading失败"+FQSB + material.Message, "F_FQSB_DownTask");
                                }
                            }
                        }
                        WriteLog.Info($"{FQSB}下料").Write($"{FQSB}结束,时间:" + DateTime.Now + $"   ----------{Environment.NewLine}", $"{FQSB}下料");
                    }
                }
                catch (Exception ex)
                {
                    WriteLog.Info("F_FQSB_DownTask").Write("F_FQSB_DownTask" + ex.Message, "F_FQSB_DownTask");
                    StackTrace stackTrace = new StackTrace();
                    StackFrame[] stackFrames = stackTrace.GetFrames();
                    string str = "";
                    foreach (var item in stackFrames)
                    {
                        str += "方法名:" + item.GetMethod().Name + ",行号:" + item.GetFileLineNumber() + ",文件名:" + item.GetFileName() + Environment.NewLine;
                    }
                    WIDESEA_Common.Tools.WriteLog.GetLog("负极分切设备下料").Write($"错误信息:{ex.Message},{str}", "负极分切设备下料");
                }
                finally
                {
                    Interlocked.Exchange(ref _readFFQDOWNSignalso, 0);
                }
            }
        }
    }
}