1. 修改发送功能
This commit is contained in:
parent
90b6c51460
commit
b99e08f20a
|
@ -59,9 +59,8 @@ public class AuthUser {
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
new ArrayList<>(Arrays.asList(0, 1, 2, 3)));
|
new ArrayList<>(Arrays.asList(0, 1, 2, 3)));
|
||||||
Long id = baidouAdapterService.getAllAdapter().get(0).getId();
|
|
||||||
baidouAdapterService.sendCommond(id, sensorPro);
|
|
||||||
|
|
||||||
|
baidouAdapterService.sendCommandToAllAdapter(sensorPro);
|
||||||
return "{\"result\": 0}";
|
return "{\"result\": 0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,14 @@ import java.util.List;
|
||||||
public interface BaidouAdapterService {
|
public interface BaidouAdapterService {
|
||||||
void startBeidouAdapter();
|
void startBeidouAdapter();
|
||||||
|
|
||||||
|
List<Long> getActiveAdapter();
|
||||||
|
|
||||||
void sendCommond(Long adapterId, Object command);
|
void sendCommond(Long adapterId, Object command);
|
||||||
|
|
||||||
void sendCommond(Channel ch, Object command);
|
void sendCommond(Channel ch, Object command);
|
||||||
|
|
||||||
|
void sendCommandToAllAdapter(Object command);
|
||||||
|
|
||||||
List<BeidouAdapterDevice> getAllAdapter();
|
List<BeidouAdapterDevice> getAllAdapter();
|
||||||
|
|
||||||
void addNewBeidouAdapter(BeidouAdapterDevice adapter);
|
void addNewBeidouAdapter(BeidouAdapterDevice adapter);
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.zjyr.beidouservice.pojo.dto.task.AlarmTaskReqDTO;
|
||||||
import com.zjyr.beidouservice.pojo.vo.PageInfoVO;
|
import com.zjyr.beidouservice.pojo.vo.PageInfoVO;
|
||||||
import com.zjyr.beidouservice.service.AdapterProtocolService;
|
import com.zjyr.beidouservice.service.AdapterProtocolService;
|
||||||
import com.zjyr.beidouservice.service.AlarmTaskService;
|
import com.zjyr.beidouservice.service.AlarmTaskService;
|
||||||
|
import com.zjyr.beidouservice.service.BaidouAdapterService;
|
||||||
import com.zjyr.beidouservice.service.DeviceService;
|
import com.zjyr.beidouservice.service.DeviceService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -55,6 +56,9 @@ import java.util.stream.Collectors;
|
||||||
public class AlarmTaskServiceImpl implements AlarmTaskService {
|
public class AlarmTaskServiceImpl implements AlarmTaskService {
|
||||||
@Resource
|
@Resource
|
||||||
AdapterProtocolService adapterProtocolService;
|
AdapterProtocolService adapterProtocolService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
BaidouAdapterService baidouAdapterService;
|
||||||
@Resource
|
@Resource
|
||||||
DeviceService deviceService;
|
DeviceService deviceService;
|
||||||
|
|
||||||
|
@ -110,7 +114,7 @@ public class AlarmTaskServiceImpl implements AlarmTaskService {
|
||||||
// 刷新设备告警状态
|
// 刷新设备告警状态
|
||||||
deviceService.refreshDeviceAlarmStatus(alarmDeviceTaskDOS);
|
deviceService.refreshDeviceAlarmStatus(alarmDeviceTaskDOS);
|
||||||
//执行控制任,默认只有一种通道方式
|
//执行控制任,默认只有一种通道方式
|
||||||
adapterProtocolService.createSensorControlProtocol(
|
baidouAdapterService.sendCommandToAllAdapter(adapterProtocolService.createSensorControlProtocol(
|
||||||
generatedId.intValue(),
|
generatedId.intValue(),
|
||||||
CommonEnumHandler.codeOf(AlarmModeName.class, alarmTaskReqDTO.getAlarmMode()),
|
CommonEnumHandler.codeOf(AlarmModeName.class, alarmTaskReqDTO.getAlarmMode()),
|
||||||
CommonEnumHandler.codeOf(AlarmControlTypeName.class, alarmTaskReqDTO.getAlarmType()),
|
CommonEnumHandler.codeOf(AlarmControlTypeName.class, alarmTaskReqDTO.getAlarmType()),
|
||||||
|
@ -120,7 +124,7 @@ public class AlarmTaskServiceImpl implements AlarmTaskService {
|
||||||
deviceInfo.getCityCodes(),
|
deviceInfo.getCityCodes(),
|
||||||
deviceInfo.getCountyCodes(),
|
deviceInfo.getCountyCodes(),
|
||||||
deviceInfo.getBeidouIds()
|
deviceInfo.getBeidouIds()
|
||||||
);
|
));
|
||||||
|
|
||||||
return MyResp.success("执行任务成功");
|
return MyResp.success("执行任务成功");
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@ import static com.zjyr.beidouservice.common.impl.SocketEventName.SOCKET_EVT_CONN
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implements BaidouAdapterService, ApplicationListener<T> {
|
public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implements BaidouAdapterService,
|
||||||
|
ApplicationListener<T> {
|
||||||
|
|
||||||
private final ConcurrentHashMap<Long, ControlAdapterSocketCtx> ctxMap = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<Long, ControlAdapterSocketCtx> ctxMap = new ConcurrentHashMap<>();
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -56,6 +57,13 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
||||||
tcpServer.start();
|
tcpServer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Long> getActiveAdapter() {
|
||||||
|
List<Long> adapterList = new ArrayList<>();
|
||||||
|
ctxMap.forEach((key, value) -> adapterList.add(key));
|
||||||
|
return adapterList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCommond(Long adapterId, Object command) {
|
public void sendCommond(Long adapterId, Object command) {
|
||||||
ControlAdapterSocketCtx ctx = ctxMap.get(adapterId);
|
ControlAdapterSocketCtx ctx = ctxMap.get(adapterId);
|
||||||
|
@ -72,24 +80,29 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendCommandToAllAdapter(Object command) {
|
||||||
|
getActiveAdapter().forEach(k -> sendCommond(k, command));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(@Nonnull T evtContent) {
|
public void onApplicationEvent(@Nonnull T evtContent) {
|
||||||
if (evtContent instanceof SocketNotifyEvent event) {
|
if (evtContent instanceof SocketNotifyEvent event) {
|
||||||
InetSocketAddress sa = (InetSocketAddress) event.getCtxChannel().remoteAddress();
|
InetSocketAddress sa = (InetSocketAddress) event.getCtxChannel().remoteAddress();
|
||||||
Long devId = Optional.ofNullable(getAdapterByAddr(sa.getAddress().getHostAddress()))
|
Long devId = Optional.ofNullable(getAdapterByAddr(sa.getAddress().getHostAddress()))
|
||||||
.orElse(BeidouAdapterDevice.builder()
|
.orElse(BeidouAdapterDevice.builder()
|
||||||
.id(-1)
|
.id(-1)
|
||||||
.build())
|
.build())
|
||||||
.getId();
|
.getId();
|
||||||
switch (event.getSocketEvent()) {
|
switch (event.getSocketEvent()) {
|
||||||
case SOCKET_EVT_CONNECT, SOCKET_EVT_IDLE_TIMEOUT -> {
|
case SOCKET_EVT_CONNECT, SOCKET_EVT_IDLE_TIMEOUT -> {
|
||||||
sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol());
|
sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol());
|
||||||
|
|
||||||
if (event.getSocketEvent() == SOCKET_EVT_CONNECT) {
|
if (event.getSocketEvent() == SOCKET_EVT_CONNECT) {
|
||||||
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
|
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
|
||||||
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
|
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
|
||||||
.adapterAddr(sa.getAddress().getHostAddress())
|
.adapterAddr(sa.getAddress().getHostAddress())
|
||||||
.build();
|
.build();
|
||||||
addNewBeidouAdapter(a);
|
addNewBeidouAdapter(a);
|
||||||
|
|
||||||
ControlAdapterSocketCtx sockCtx = new ControlAdapterSocketCtx(a.getId(), event.getCtxChannel());
|
ControlAdapterSocketCtx sockCtx = new ControlAdapterSocketCtx(a.getId(), event.getCtxChannel());
|
||||||
|
@ -108,19 +121,19 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
||||||
case SOCKET_EVT_RECV -> {
|
case SOCKET_EVT_RECV -> {
|
||||||
if (event.getEvtMessage() instanceof ControllerStatus status) {
|
if (event.getEvtMessage() instanceof ControllerStatus status) {
|
||||||
log.info("+++{}, {}, {}",
|
log.info("+++{}, {}, {}",
|
||||||
status.getWirelessStatus(),
|
status.getWirelessStatus(),
|
||||||
status.getTelphoneStatus(),
|
status.getTelphoneStatus(),
|
||||||
HelperUtils.bytesToHexString(status.getBeidouSignalStrength()));
|
HelperUtils.bytesToHexString(status.getBeidouSignalStrength()));
|
||||||
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
|
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
|
||||||
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
|
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
|
||||||
.adapterAddr(sa.getAddress().getHostAddress())
|
.adapterAddr(sa.getAddress().getHostAddress())
|
||||||
.sendEnabled(status.getSendStatus().getValue())
|
.sendEnabled(status.getSendStatus().getValue())
|
||||||
.beidouStatus(status.getBeidouStatus().getValue())
|
.beidouStatus(status.getBeidouStatus().getValue())
|
||||||
.beidouChannelStatus(HelperUtils.bytesToHexString(status.getBeidouFreq()))
|
.beidouChannelStatus(HelperUtils.bytesToHexString(status.getBeidouFreq()))
|
||||||
.beidouSignalStrength(HelperUtils.bytesToHexString(status.getBeidouSignalStrength()))
|
.beidouSignalStrength(HelperUtils.bytesToHexString(status.getBeidouSignalStrength()))
|
||||||
.wirelessStatus(status.getWirelessStatus().getValue())
|
.wirelessStatus(status.getWirelessStatus().getValue())
|
||||||
.telphoneStatus(status.getTelphoneStatus().getValue())
|
.telphoneStatus(status.getTelphoneStatus().getValue())
|
||||||
.build();
|
.build();
|
||||||
addNewBeidouAdapter(a);
|
addNewBeidouAdapter(a);
|
||||||
} else if (event.getEvtMessage() instanceof SensorTaskAck ack) {
|
} else if (event.getEvtMessage() instanceof SensorTaskAck ack) {
|
||||||
log.info("+++{}, {}, {}", ack.getTaskId(), ack.getAckTimestamp(), ack.getSensorStatus().size());
|
log.info("+++{}, {}, {}", ack.getTaskId(), ack.getAckTimestamp(), ack.getSensorStatus().size());
|
||||||
|
@ -143,16 +156,16 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
||||||
|
|
||||||
for (ControlDevice c : controlDevices) {
|
for (ControlDevice c : controlDevices) {
|
||||||
adapterDevices.add(BeidouAdapterDevice.builder()
|
adapterDevices.add(BeidouAdapterDevice.builder()
|
||||||
.id(c.getId())
|
.id(c.getId())
|
||||||
.adapterType(c.getDeviceType())
|
.adapterType(c.getDeviceType())
|
||||||
.adapterAddr(c.getDeviceAddr())
|
.adapterAddr(c.getDeviceAddr())
|
||||||
.sendEnabled(Optional.ofNullable(c.getSendEnabled()).orElse(0))
|
.sendEnabled(Optional.ofNullable(c.getSendEnabled()).orElse(0))
|
||||||
.beidouStatus(Optional.ofNullable(c.getBeidouStatus()).orElse(0))
|
.beidouStatus(Optional.ofNullable(c.getBeidouStatus()).orElse(0))
|
||||||
.beidouChannelStatus(Optional.ofNullable(c.getBeidouChannelStatus()).orElse(""))
|
.beidouChannelStatus(Optional.ofNullable(c.getBeidouChannelStatus()).orElse(""))
|
||||||
.beidouSignalStrength(Optional.ofNullable(c.getBeidouSignalStrength()).orElse(""))
|
.beidouSignalStrength(Optional.ofNullable(c.getBeidouSignalStrength()).orElse(""))
|
||||||
.wirelessStatus(Optional.ofNullable(c.getWirelessStatus()).orElse(0))
|
.wirelessStatus(Optional.ofNullable(c.getWirelessStatus()).orElse(0))
|
||||||
.telphoneStatus(Optional.ofNullable(c.getTelphoneStatus()).orElse(0))
|
.telphoneStatus(Optional.ofNullable(c.getTelphoneStatus()).orElse(0))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
return adapterDevices;
|
return adapterDevices;
|
||||||
|
@ -164,16 +177,16 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
||||||
@Override
|
@Override
|
||||||
public void addNewBeidouAdapter(BeidouAdapterDevice adapter) {
|
public void addNewBeidouAdapter(BeidouAdapterDevice adapter) {
|
||||||
ControlDevice device = ControlDevice.builder()
|
ControlDevice device = ControlDevice.builder()
|
||||||
.id(adapter.getId())
|
.id(adapter.getId())
|
||||||
.deviceType(adapter.getAdapterType())
|
.deviceType(adapter.getAdapterType())
|
||||||
.deviceAddr(adapter.getAdapterAddr())
|
.deviceAddr(adapter.getAdapterAddr())
|
||||||
.beidouStatus(adapter.getBeidouStatus())
|
.beidouStatus(adapter.getBeidouStatus())
|
||||||
.sendEnabled(adapter.getSendEnabled())
|
.sendEnabled(adapter.getSendEnabled())
|
||||||
.beidouChannelStatus(adapter.getBeidouChannelStatus())
|
.beidouChannelStatus(adapter.getBeidouChannelStatus())
|
||||||
.beidouSignalStrength(adapter.getBeidouSignalStrength())
|
.beidouSignalStrength(adapter.getBeidouSignalStrength())
|
||||||
.wirelessStatus(adapter.getWirelessStatus())
|
.wirelessStatus(adapter.getWirelessStatus())
|
||||||
.telphoneStatus(adapter.getTelphoneStatus())
|
.telphoneStatus(adapter.getTelphoneStatus())
|
||||||
.build();
|
.build();
|
||||||
BeidouAdapterDevice dev = getAdapterByAddr(adapter.getAdapterAddr());
|
BeidouAdapterDevice dev = getAdapterByAddr(adapter.getAdapterAddr());
|
||||||
if (dev == null) {
|
if (dev == null) {
|
||||||
controlDeviceMapper.addControlDevice(device);
|
controlDeviceMapper.addControlDevice(device);
|
||||||
|
|
Loading…
Reference in New Issue