2026-04-17 17:12:41 +08:00
|
|
|
package com.maibu.service;
|
2026-04-17 10:42:16 +08:00
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2026-07-29 13:08:49 +08:00
|
|
|
import com.maibu.constant.Constant;
|
2026-04-30 15:25:58 +08:00
|
|
|
import com.maibu.core.business.DeviceRunningStatusHistory;
|
|
|
|
|
import com.maibu.core.business.ErrorIdentificationStandard;
|
2026-07-29 13:08:49 +08:00
|
|
|
import com.maibu.core.business.device.NettyDevice;
|
|
|
|
|
import com.maibu.dto.SendCommandDTO;
|
2026-04-17 17:12:41 +08:00
|
|
|
import com.maibu.mapper.DeviceStatusHistoryMapper;
|
|
|
|
|
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
2026-07-29 13:08:49 +08:00
|
|
|
import com.maibu.memory.DeviceSessionManager;
|
2026-04-17 10:42:16 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
2026-07-29 13:08:49 +08:00
|
|
|
import org.springframework.util.CollectionUtils;
|
2026-04-17 10:42:16 +08:00
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class NettyDeviceService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceStatusHistoryMapper deviceStatusHistoryMapper;
|
|
|
|
|
|
2026-07-29 13:08:49 +08:00
|
|
|
@Autowired
|
|
|
|
|
private DeviceSessionManager deviceSessionManager;
|
|
|
|
|
|
2026-04-17 10:42:16 +08:00
|
|
|
@Autowired
|
|
|
|
|
private ErrorIdentificationStandardMapper errorIdentificationStandardMapper;
|
|
|
|
|
|
|
|
|
|
public List<DeviceRunningStatusHistory> statusHistory(DeviceRunningStatusHistory history) {
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<DeviceRunningStatusHistory> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
if (!StringUtils.isEmpty(history.getDeviceId())) {
|
|
|
|
|
queryWrapper.eq(DeviceRunningStatusHistory::getDeviceId, history.getDeviceId());
|
|
|
|
|
}
|
|
|
|
|
return deviceStatusHistoryMapper.selectList(queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<ErrorIdentificationStandard> allErrorIdentificationStandard() {
|
|
|
|
|
return errorIdentificationStandardMapper.selectList(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int updateErrorIdentification(ErrorIdentificationStandard standard) {
|
|
|
|
|
return errorIdentificationStandardMapper.updateById(standard);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-29 13:08:49 +08:00
|
|
|
public void sendCommand(SendCommandDTO command) {
|
|
|
|
|
if (command == null || command.getCommandType() == null || CollectionUtils.isEmpty(command.getDeviceIds()))
|
|
|
|
|
return;
|
|
|
|
|
command.getDeviceIds().forEach(deviceId -> {
|
|
|
|
|
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
|
|
|
|
if (nettyDevice != null && !nettyDevice.isExecutingTask()) {
|
|
|
|
|
if (nettyDevice.getChannel() != null && nettyDevice.getChannel().isActive()) {
|
|
|
|
|
if (Constant.WheelGainCoefficients.equals(command.getCommandType())) {
|
|
|
|
|
double leftForwardGain = (double) command.getParams().get("leftForwardGain");
|
|
|
|
|
double leftBackwardGain = (double) command.getParams().get("leftBackwardGain");
|
|
|
|
|
double rightForwardGain = (double) command.getParams().get("rightForwardGain");
|
|
|
|
|
double rightBackwardGain = (double) command.getParams().get("rightBackwardGain");
|
|
|
|
|
nettyDevice.sendWheelGainCoefficientsCommand(leftForwardGain, leftBackwardGain, rightForwardGain, rightBackwardGain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-17 10:42:16 +08:00
|
|
|
|
|
|
|
|
}
|