1
HuBingJie
9 天以前 28110912ca4803e5793f181517d7bf2d7a5ea2ad
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
using AutoMapper;
using Quartz;
using WIDESEA_Common.Log;
using WIDESEAWCS_Core;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineJob : IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IAgvStationService _agvStationService;
        private readonly IMapper _mapper;
        private readonly IRgvOperationService _gvOperationService;
        private readonly IEquipmentStatusService _equipmentStatusService;
        //private readonly TaskService _task;
 
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IAgvStationService agvStation, IMapper mapper, IRgvOperationService gvOperationService, IEquipmentStatusService equipmentStatusService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _agvStationService = agvStation;
            _mapper = mapper;
            _gvOperationService = gvOperationService;
            _equipmentStatusService=equipmentStatusService;
            //_task = task;
        }
 
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    
 
                    //根据设备查找出对应的站台信息
                    List<AGVStation> aGVStations = _agvStationService.GetYljSide(conveyorLine.DeviceCode);
                    foreach (var Stations in aGVStations)
                    {
                        if (Stations.Station_material == (int)RGVEquipment.AQMexit)
                        {
 
                            bool Security = SecurityDoorEquipment(conveyorLine, Stations);  //安全门
                            if (Security) continue;
 
                        }
                        else
                        {
                            bool HCJPlat=PlatformEquipmentInformation(conveyorLine, Stations);  //异常站台,出库站台
                            if (HCJPlat) continue;
                        }
                        
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("安全门", "运行状况", "故障", new { 信息 = ex.Message });
            }
            return;
        }
 
       
        //处理安全门的逻辑
        private void HandleDoorRequest(AQMReturnnormal aQMConveyor, AGVStation aGVStation,int tasktype)  //1:入库  2:出库
        {
            /*bool RGValarm = _gvOperationService.AQMReadAlarminform(tasktype);
            bool SCstatus = _equipmentStatusService.GetSCstatus();
           if (RGValarm || SCstatus)
            {
                //写入报警
                GetDeviceAddress.WriteSecurityDoorpolice(aGVStation.ChildPosiDeviceCode, "AlarmSummary", 1);
 
                bool RGVRGV_DWorkingmode = tasktype == 1 ? _gvOperationService.InWriteOutbuttonpause(null).Status : _gvOperationService.WriteOutbuttonpause(null).Status;
            }*/
 
            if (aQMConveyor.DoorRequest == 1 && aQMConveyor.IndicatorStatus == (int)SafetyDoorStatus.YellowBlink2Hz)
            {
                if (aQMConveyor.EmergencyStopStatus == 1)  //请求开门等待任务完成
                {
                    bool AQMzckm = tasktype == 1 ? GetDeviceAddress.InRGVRGVStepprocess() : GetDeviceAddress.OutRGVRGVStepprocess();    //判断是否有进程任务
                    if (AQMzckm)
                    {
                        //写入停止的信息
                        bool RGVRGV_DWorkingmode = tasktype == 1 ? _gvOperationService.InWriteOutbuttonpause(null).Status : _gvOperationService.WriteOutbuttonpause(null).Status;
 
                        bool RGVstate = tasktype == 1 ? GetDeviceAddress.InRGVStatice() : GetDeviceAddress.OutRGVStatice();     //判断是否全为手动
                        WebResponseContent webResponse = _taskService.StkRunStatus();
                        if (RGVstate && webResponse.Status == true)
                        {
                            //写入开门信号
                            GetDeviceAddress.WriteSecurityDoorpolice(aGVStation.ChildPosiDeviceCode, "OpenDoor", 1);
                        }
                    }
 
                }
                else //急停立马暂停设备
                {
                    bool AQMkm = tasktype == 1 ? GetDeviceAddress.InRGVStatice() : GetDeviceAddress.OutRGVStatice();
                    WebResponseContent webResponse = _taskService.StkRunStatus();
 
                    if (AQMkm && webResponse.Status == true)
                    {
                        GetDeviceAddress.WriteSecurityDoorpolice(aGVStation.ChildPosiDeviceCode, "OpenDoor", 1);
                    }
                    
                }
            }
        }
 
        //安全门设备信息管理
        private bool SecurityDoorEquipment(CommonConveyorLine conveyorLine, AGVStation Stations)
        {
            try
            {
                // 获取安全门信息
                AQMReturnnormal aQMConveyor = AQMStoticCommand(conveyorLine, Stations.ChildPosiDeviceCode);
                if(aQMConveyor != null)
                {
                    if (aQMConveyor.SafetyLockStatus == 1)
                    {
                        //写入报警
                        GetDeviceAddress.WriteSecurityDoorpolice(Stations.ChildPosiDeviceCode, "AlarmSummary", 0);
                        //写入开门信号
                        GetDeviceAddress.WriteSecurityDoorpolice(Stations.ChildPosiDeviceCode, "OpenDoor", 0);
                    }
 
                    // 根据任务类型选择处理策略
                    if (Stations.Station_tasktype == (int)RGVTasktype.Outbound)
                    {
                        if (aQMConveyor.EmergencyStopStatus == 0 || aQMConveyor.SafetyLockStatus==0) _gvOperationService.WriteOutbuttonpause(null);
                        HandleDoorRequest(aQMConveyor, Stations, 2);
                    }
                    else
                    {
                        if (aQMConveyor.EmergencyStopStatus == 0 || aQMConveyor.SafetyLockStatus == 0) _gvOperationService.InWriteOutbuttonpause(null);
                        HandleDoorRequest(aQMConveyor, Stations, 1);
                    }
                }
                
                return false;
            }
            catch (Exception ex)
            {
                return true;
                throw;
            }
        }
 
        private bool PlatformEquipmentInformation(CommonConveyorLine conveyorLine, AGVStation Stations)
        {
            try
            {
                if (StoticCommand(conveyorLine, Stations.HCJStorageaddress.ToString()))    //可进行放货
                {
                    WebResponseContent webResponseContent = new WebResponseContent();
                    //根据类型查找任务
                    if (Stations.Station_material == (int)RGVEquipment.AbnormalOutbound)
                    {
                        //查找是否有异常搬运任务
                        webResponseContent = _taskService.UpdateDeliveryAddress(Stations.HCJStorageaddress.ToString(), 1);   //还需要传入地址
                    }
                    else
                    {
                        //出库站台的任务
                        webResponseContent = _taskService.UpdateDeliveryAddress(Stations.HCJStorageaddress.ToString(), 2);
                    }
                }
 
                return false;
            }
            catch (Exception ex)
            {
                return true;
                throw;
            }
        }
 
        /// <summary>
        /// 安全门信号
        /// </summary>
        public AQMReturnnormal AQMStoticCommand(CommonConveyorLine conveyorLine, string kladder)
        {
            try
            {
                AQMReturnnormal conveyorRgvCommand = new AQMReturnnormal();
                List<DeviceProDTO> deviceProDTO6 = conveyorLine.DeviceProDTOs
                    .Where(x => x.DeviceChildCode == kladder
                                //&& DBLine.ConveyorAQMReturnnormal.Contains(x.DeviceProParamName)
                                && x.DeviceProParamType == "ReadDeviceCommand")
                    .ToList();
                foreach (var item in deviceProDTO6)
                {
                    var paramName = item.DeviceProParamName;
                    var propertyInfo = typeof(AQMReturnnormal).GetProperty(paramName);
 
                    if (propertyInfo != null)
                    {
                        if (item.DeviceDataType == "short")
                        {
                            var value = conveyorLine.Communicator.Read<short>(item.DeviceProAddress);
                            propertyInfo.SetValue(conveyorRgvCommand, value);
                        }
                    }
                }
                return conveyorRgvCommand;
            }
            catch (Exception ex)
            {
                return null;
                throw;
            }
        }
 
        public DeviceProDTO? GetDeviceProDTO(CommonConveyorLine conveyorLine, string PLCmanipula, string DeviceProParamName, string DeviceProParamType)
        {
            return conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == PLCmanipula && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
        }
 
        //站台信号
     /*   public bool StoticCommand(CommonConveyorLine conveyorLine, string kladder)
        {
            DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == kladder
                            && x.DeviceProParamName == "HCJ_GoodsStatus"
                            && x.DeviceProParamType == "ReadDeviceCommand");
            if(deviceProDTO6 == null) { return false; }
 
            if (deviceProDTO6.DeviceChildCode == "2016"||deviceProDTO6.DeviceChildCode == "2017"|| deviceProDTO6.DeviceChildCode == "2018"|| deviceProDTO6.DeviceChildCode == "2019"
                || deviceProDTO6.DeviceChildCode == "1001"|| deviceProDTO6.DeviceChildCode == "1002")
            {
                var value1 = conveyorLine.Communicator.Read<short>(deviceProDTO6.DeviceProAddress);
                //延时5秒
                System.Threading.Thread.Sleep(5000);
                var value2 = conveyorLine.Communicator.Read<short>(deviceProDTO6.DeviceProAddress);
                if (value1 != value2 && (value1 !=0 && value2 !=0)) { return false; };
                return true;
            }
            var value = conveyorLine.Communicator.Read<short>(deviceProDTO6.DeviceProAddress);
 
            if (value == 0) {  return true; }
            return false;
        }*/
 
 
 
        //站台信号
        public bool StoticCommand(CommonConveyorLine conveyorLine, string kladder)
        {
            DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == kladder
                            && x.DeviceProParamName == "HCJ_GoodsStatus"
                            && x.DeviceProParamType == "ReadDeviceCommand");
            // 这些站台需要“延时5秒并比较第一次与最后一次结果”
            bool isPlatformCode =
                kladder == "2016" || kladder == "2017" || kladder == "2018" || kladder == "2019" ||
                kladder == "1001" || kladder == "1002";
 
            if (isPlatformCode)
            {
                // 第一次读取
                short first = conveyorLine.Communicator.Read<short>(deviceProDTO.DeviceProAddress);
 
                // 延时5秒
                System.Threading.Thread.Sleep(5000);
 
                // 最后一次读取
                short last = conveyorLine.Communicator.Read<short>(deviceProDTO.DeviceProAddress);
 
                // 协议:0=无信号=无货=空位
                return first == 0 && last == 0;
            }
            else
            {
                short value = conveyorLine.Communicator.Read<short>(deviceProDTO.DeviceProAddress);
                return value == 0; // 0=空位可放;1=有货不可放
            }
        }
    }
}