1
huanghongfeng
10 天以前 0b4792ff8245f9eac16e6d02452eb9a091f6f72b
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NetTaste;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using System.Net;
using WIDESEAWCS_ISystemServices;
using System.Security.Claims;
using WIDESEAWCS_Common.TaskEnum;
 
namespace WIDESEAWCS_TaskInfoService
{
    public class RgvOperationService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvOperationService
    {
        private readonly IAgvStationService _gvStationService;
        private readonly ITaskRepository _taskRepository;
        public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, ITaskRepository taskRepository) : base(BaseDal)
        {
            _gvStationService = agvStationService;
            _taskRepository = taskRepository;
        }
 
 
        public WebResponseContent WriteInitialization(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
 
            string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
            //获取实例
            DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand");        //任务类型
            //第一步写入任务
            RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3);
 
            //复位报警
            DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //复位报警信息
            RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
 
            //写入自动
            DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        //任务id
            RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)1);
 
            //写入清除任务
            RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)4);
 
            //反馈确认任务
            DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete");        //任务id
            RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)1);
 
            return webResponse.OK();
        }
 
        public WebResponseContent WriteRGVmokuai(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            string DeviceName = saveModel.DelKeys[0].ToString();    //工作类型
            string DBType = saveModel.DelKeys[1].ToString();    //设备名称
            short WriteRGVvalue = short.Parse(saveModel.DelKeys[2].ToString());    //写入值
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            switch (DBType)
            {
                case "1":  // 工作模式(0手动、1自动)
                           //获取实例
                    DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        //任务类型
                                                                                                                                                //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, WriteRGVvalue);
                    break;
                case "2":   //复位操作(0不复位、1复位)
                    DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //任务类型
                                                                                                                                                    //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, WriteRGVvalue);
                    break;
                case "3":   //任务确认完成(0不确定,1确定)
                    DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete");        //任务类型
                                                                                                                                                   //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, WriteRGVvalue);
                    break;
                case "4":   //任务类型(4清除)
                    DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand");        //任务类型
                                                                                                                                                //第一步写入任务
                    RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, WriteRGVvalue);
                    break;
            }
            return webResponse.OK();
        }
 
        /// <summary>
        /// 手动移动RGV
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent ManualmovementRGV(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
 
            string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
            short Nextaddres = short.Parse(saveModel.DelKeys[1].ToString());
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
            //获取实例
            DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand");        //任务类型
            //第一步写入任务
            RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3);
 
            //目标位置
            DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVTasklocationt", "DeviceCommand");        //复位报警信息
            RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)Nextaddres);
 
            //写入自动
            DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Rgvtaskidt", "DeviceCommand");        //任务id
            //任务id
            RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)30001);
 
            //任务id
            DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Lanjiantaskidt", "DeviceCommand");        //任务id
            RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)30001);
 
 
            return webResponse.OK();
        }
 
        /// <summary>
        /// 一键启动入库子母车
        /// </summary>
        public WebResponseContent WriteInReset(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
 
            List<AGVStation> rgvdata = _gvStationService.GetInStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //复位报警信息
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
            }
            return webResponse.OK();
        }
 
        /// <summary>
        /// 写入复位(出库端)
        /// </summary>
        public WebResponseContent WriteOutReset(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //复位报警信息
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
            }
            return webResponse.OK();
        }
 
        /// <summary>
        /// 一键暂停
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent WriteOutbuttonpause(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
            }
            return webResponse.OK();
        }
 
        public WebResponseContent InWriteOutbuttonpause(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.InGetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
            }
            return webResponse.OK();
        }
 
        /// <summary>
        /// 一键启动
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent WriteOuttouchstart(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
            foreach (AGVStation rgvstation in rgvdata)
            {
                string DeviceName = rgvstation.ChildPosiDeviceCode;    //设备名称
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                if (device == null) continue;
                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
 
                //获取需要复位的设备
                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        
                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
            }
            return webResponse.OK();
        }
 
 
 
        /// <summary>
        /// 查询RGV设备
        /// </summary>
        /// <param name="Commonstacker"></param>
        /// <param name="SCAddress"></param>
        /// <param name="Interactivet"></param>
        /// <returns></returns>
        public static DeviceProDTO? GetRGVDeviceProDTO(SpeStackerCrane Commonstacker, string SCAddress, string DeviceProParamName, string DeviceProParamType)
        {
            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
        }
        /// <summary>
        /// 读取设备信息
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public static int GetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
        {
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
 
        /// <summary>
        /// 写入设备信息
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public static bool RgvSetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock, short rgvvalues)
        {
            return Commonstacker.Communicator.Write<short>(DeviceProDataBlock, rgvvalues);
        }
 
        /// <summary>
        /// 正常入库
        /// </summary>
        public WebResponseContent WriteInNormal(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
            dt_Task.TaskState = (int)TaskInStatusEnum.RGV_InPickupFinish;
            dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
            dt_Task.NextAddress = "1021";
            _taskRepository.UpdateData(dt_Task);
            return content;
        }
        /// <summary>
        /// 入库异常排出
        /// </summary>
        public WebResponseContent WriteInAbnormal(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
            dt_Task.TaskState = (int)TaskInStatusEnum.InexceptionalSelection;
            dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
            _taskRepository.UpdateData(dt_Task);
            return content;
        }
 
 
 
        public static List<string> OutStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
        public static List<string> InStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
        /// <summary>
        /// 查看报警
        /// </summary>
        public bool AQMReadAlarminform(int tasktype)
        {
            var deviceList = tasktype == 1 ? InStationareaList : OutStationareaList;
 
            foreach (string deviceName in deviceList)
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceName);
                if (device == null) return false;
 
                SpeStackerCrane stacker = (SpeStackerCrane)device;
                DeviceProDTO? faultInfo = GetRGVDeviceProDTO(stacker, deviceName, "RGV_Faultcode", "ReadDeviceCommand");
                int alarmCode = GetLine(stacker, faultInfo.DeviceProAddress);
 
                if (alarmCode != 0)
                {
                    return true;
                }
            }
 
            return true;
        }
 
 
        /// <summary>
        /// 查看报警
        /// </summary>
        public WebResponseContent ReadAlarminformation(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            string DeviceName = saveModel.DelKeys[0].ToString();    //设备名称
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
            if (device == null) return webResponse.Error();
            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
            DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand");
            int baoj = GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress);
            string alarmMessage = "";
            if (DeviceName == "RGV118")
            {
                 alarmMessage = GetAlarmMessage(baoj);
            }
            else if (DeviceName == "RGV111" || DeviceName == "RGV116")
            {
                 alarmMessage = GetAlarmMessage2(baoj);
            }
            else if (DeviceName == "RGV110" || DeviceName == "RGV112" || DeviceName == "RGV114" || DeviceName == "RGV115")
            {
                 alarmMessage = GetAlarmMessage3(baoj);
            }
 
 
            return webResponse.OK(data: alarmMessage);
        }
 
        // 报警代码映射方法
        private string GetAlarmMessage(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
            {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "正转雷达报警"},
        {3, "反转雷达报警"},
        {4, "前进限位报警"},
        {5, "后退限位报警"},
        {6, ""},
        {7, "PLC摸块故障"},
        {8, "PLC扩展模块故障"},
        {9, "称重模块故障"},
        {10, "扫码定位故障"},
        {11, "RGV长时间空转故障"},
        {12, "目的地不等于实际位置故障"},
        {13, "与总控通讯故障"},
        {14, "前雷达屏蔽警告"},
        {15, "后雷达屏蔽警告"},
        {16, "行走变频器故障"},
        {17, "伸缩叉变频器故障"},
        {18, "液压单元过载保护故障"},
        {19, "液压上升超时报警"},
        {20, "液压下降超时报警"},
        {21, "伸缩叉伸出超时报警"},
        {22, "伸缩叉缩回超时报警"},
        {23, "外形检测报警"},
        {24, "称重超重报警"},
        {25, "货叉伸出极限限位报警"},
        {26, "货叉缩回极限限位报警"},
        {27, "取货时自身有货物报警"},
        {28, "放货时自身无货物报警"},
        {29, "货叉未回到初始位报警"},
        {30, "触发仅移动命令时货叉不在初始位报警"},
                {31, "货叉到达初始位但中位传感器未检测到报警"}
            };
 
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
 
 
        private string GetAlarmMessage2(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "扫码定位故障"},
        {7, "RGV长时间空转故障"},
        {8, "目的地不等于实际位置故障"},
        {9, "与总控通讯故障"},
        {10, "行走变频器故障"},
        {11, "液压单元过载保护故障"},
        {12, "液压上升超时报警"},
        {13, "液压下降超时报警"},
        {14, "取货时自身有货物报警"},
        {15, "放货时自身无货物报警"},
        {16, "取货检测不到货物报警"}
    };
 
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
 
        private string GetAlarmMessage3(int alarmCode)
        {
            var alarmMessages = new Dictionary<int, string>
    {
        {0, "无报警"},
        {1, "RGV小车急停被按下"},
        {2, "前进限位报警"},
        {3, "后退限位报警"},
        {4, "PLC摸块故障"},
        {5, "PLC扩展模块故障"},
        {6, "RGV长时间空转故障"},
        {7, "目的地不等于实际位置故障"},
        {8, "与总控通讯故障"},
        {9, "行走变频器故障"},
        {10, "取货时自身有货物报警"},
        {11, "放货时自身无货物报警"},
        {12, "停止时位置过冲报警"}
    };
 
            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
        }
    }
}