Platfrom_CylinderHandler.cs
3 KB
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
using HaHRCS.Rcs.Executor.PLC;
using MassTransit;
using Microsoft.Extensions.Logging;
using Rcs.Application.Common;
using Rcs.Application.MessageBus.Commands.PlatformInteraction;
using Rcs.Domain.Repositories;
using Rcs.Executor.PLC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rcs.Infrastructure.MessageBus.Handlers.Commands.PLCInteraction
{
public class Platfrom_CylinderHandler : IConsumer<GetCylinderStatu>
{
private readonly EquipmentExecutor _equipmentExecutor;
private readonly ILogger<Platfrom_CylinderHandler> _logger;
private readonly PlatformPickRepository _platformRepository;
public Platfrom_CylinderHandler(
ILogger<Platfrom_CylinderHandler> logger,
PlatformPickRepository platformRepository,
EquipmentExecutor equipmentExecutor)
{
_logger = logger;
_platformRepository = platformRepository;
_equipmentExecutor = equipmentExecutor;
}
public async Task Consume(ConsumeContext<GetCylinderStatu> context)
{
var command = context.Message;
try
{
ValidateCommand(command, context);
//Thread.Sleep(5000);
//await context.RespondAsync(ApiResponse.Successful($"开门成功"));
var equipment = _equipmentExecutor.equipment.First(t => t.Code == command.LocationCode);
if (equipment == null || string.IsNullOrEmpty(equipment.Code))
await context.RespondAsync(ApiResponse.ErrorToPlc("无效站台设备,请检查设备名称"));
var isExtended1 = equipment[$"{CylinderProps.Retracted}"].Value;
var istrue = equipment[$"{CylinderProps.Extended}"].Value;
if (isExtended1 == "" && istrue == "")
{
await context.RespondAsync(ApiResponse.ErrorToPlc("请检查设备是否离线,设备不在线"));
}
if (isExtended1 == "True")
{
await context.RespondAsync(ApiResponse.SuccessfulToPlc("设备伸出状态"));
}
if (istrue == "True")
{
await context.RespondAsync(ApiResponse.SuccessfulToPlc("设备缩回状态"));
}
//await HandlePickupCommand(command, equipment, context);
}
catch (Exception ex)
{
_logger.LogError(ex, $"处理查询指令异常,设备编码:{command?.LocationCode}");
throw new InvalidOperationException(ex.Message);
}
}
private void ValidateCommand(GetCylinderStatu command, ConsumeContext<GetCylinderStatu> context)
{
if (string.IsNullOrEmpty(command.LocationCode))
{
context.RespondAsync(ApiResponse.ErrorToPlc("请确认设备"));
return;
}
}
}
}