update
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.maibu.dto;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.maibu.core.domain.BaseEntity;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
|
||||
@@ -11,8 +14,10 @@ import lombok.EqualsAndHashCode;
|
||||
public class DeviceTaskQueryDTO extends BaseEntity {
|
||||
|
||||
private Long userId;
|
||||
// private LocalDateTime startTime;
|
||||
// private LocalDateTime endTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime startTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime endTime;
|
||||
private DeviceTaskStaus taskStaus;
|
||||
private String planName;
|
||||
private Long planId;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.maibu.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.maibu.core.business.device.DeviceStatusDetail;
|
||||
import com.maibu.core.enums.MesType;
|
||||
|
||||
@Data
|
||||
public class WebStatusMessageDTO {
|
||||
private List<DeviceStatusDetail> data;
|
||||
private MesType type;
|
||||
}
|
||||
@@ -1,20 +1,13 @@
|
||||
package com.maibu.init;
|
||||
|
||||
import com.maibu.constant.FastBeeConstant;
|
||||
import com.maibu.core.business.DevicePlan;
|
||||
import com.maibu.core.business.DevicePlanTask;
|
||||
import com.maibu.core.domain.entity.SysSite;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
import com.maibu.mapper.DevicePlanTaskMapper;
|
||||
import com.maibu.mapper.SysSiteMapper;
|
||||
import com.maibu.mapper.SysUserClientMapper;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
import com.maibu.mybatis.LambdaQueryWrapperX;
|
||||
import com.maibu.service.DevicePlanTaskMonitorService;
|
||||
import com.maibu.service.DeviceThreadService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
@@ -22,19 +15,29 @@ import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import com.maibu.constant.FastBeeConstant;
|
||||
import com.maibu.core.business.DevicePlan;
|
||||
import com.maibu.core.business.DevicePlanTask;
|
||||
import com.maibu.core.domain.entity.SysSite;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.influxdb.util.InfluxDBUtil;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
import com.maibu.mapper.DevicePlanTaskMapper;
|
||||
import com.maibu.mapper.SysSiteMapper;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
import com.maibu.mqtt.MqttClientUtil;
|
||||
import com.maibu.mybatis.LambdaQueryWrapperX;
|
||||
import com.maibu.service.DevicePlanTaskMonitorService;
|
||||
import com.maibu.service.DeviceThreadService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(20)
|
||||
public class InitThread implements ApplicationRunner {
|
||||
|
||||
|
||||
@Resource(name = FastBeeConstant.TASK.DEVICE_ERROR_MONITOR)
|
||||
private Executor deviceErrorMonitorExecutor;
|
||||
|
||||
@@ -56,15 +59,48 @@ public class InitThread implements ApplicationRunner {
|
||||
@Autowired
|
||||
private SysSiteMapper sysSiteMapper;
|
||||
|
||||
@Value("${influxdb.url}")
|
||||
private String influxDBUrl;
|
||||
|
||||
@Value("${influxdb.username}")
|
||||
private String influxDBUsername;
|
||||
|
||||
@Value("${influxdb.password}")
|
||||
private String influxDBPassword;
|
||||
|
||||
@Value("${influxdb.bucket}")
|
||||
private String influxDBBucket;
|
||||
|
||||
@Value("${influxdb.org}")
|
||||
private String influxDBOrg;
|
||||
|
||||
@Value("${influxdb.token}")
|
||||
private String influxDBToken;
|
||||
|
||||
@Value("${mqtt.username}")
|
||||
private String mqttUsername;
|
||||
|
||||
@Value("${mqtt.password}")
|
||||
private String mqttPassword;
|
||||
|
||||
@Value("${mqtt.host-url}")
|
||||
private String mqttHostUrl;
|
||||
|
||||
@Value("${mqtt.client-id}")
|
||||
private String mqttClientId;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
public void run(ApplicationArguments args) throws MqttException {
|
||||
recoverMemory();
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
//设备错误监听线程
|
||||
private void init() throws MqttException {
|
||||
// 初始化InfluxDBUtil
|
||||
GlobalMemory.influxDBUtil = new InfluxDBUtil(influxDBUrl, influxDBToken, influxDBOrg, influxDBBucket);
|
||||
// 初始化MqttClientUtil
|
||||
GlobalMemory.mqttClientUtil = new MqttClientUtil(mqttHostUrl, mqttClientId, mqttUsername, mqttPassword);
|
||||
// 设备错误监听线程
|
||||
deviceErrorMonitorExecutor.execute(() -> {
|
||||
try {
|
||||
deviceThreadService.deviceErrorMonitor();
|
||||
@@ -72,14 +108,14 @@ public class InitThread implements ApplicationRunner {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
//设备任务处理线程
|
||||
// 设备任务处理线程
|
||||
deviceTaskHandlerExecutor.execute(() -> {
|
||||
//任务下发
|
||||
// 任务下发
|
||||
try {
|
||||
devicePlanTaskMonitorService.generatePlanTask();
|
||||
//执行准备队列
|
||||
// 执行准备队列
|
||||
devicePlanTaskMonitorService.doLoop();
|
||||
//执行任务
|
||||
// 执行任务
|
||||
devicePlanTaskMonitorService.doExecute();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -91,9 +127,9 @@ public class InitThread implements ApplicationRunner {
|
||||
* 恢复内存
|
||||
*/
|
||||
public void recoverMemory() {
|
||||
//todo 启动时清除当前登录记录
|
||||
// System.out.println("开始清除登录信息");
|
||||
// sysUserClientMapper.clearDeviceName();
|
||||
// todo 启动时清除当前登录记录
|
||||
// System.out.println("开始清除登录信息");
|
||||
// sysUserClientMapper.clearDeviceName();
|
||||
List<SysSite> siteList = sysSiteMapper.selectList();
|
||||
if (!CollectionUtils.isEmpty(siteList)) {
|
||||
siteList.forEach(x -> {
|
||||
@@ -108,7 +144,8 @@ public class InitThread implements ApplicationRunner {
|
||||
}
|
||||
// 未执行完的重复计划
|
||||
LambdaQueryWrapperX<DevicePlan> query = new LambdaQueryWrapperX<>();
|
||||
List<String> list = Arrays.asList(DeviceTaskStaus.NEW.getCode(), DeviceTaskStaus.EXECUTING.getCode(), DeviceTaskStaus.PAUSE.getCode());
|
||||
List<String> list = Arrays.asList(DeviceTaskStaus.NEW.getCode(), DeviceTaskStaus.EXECUTING.getCode(),
|
||||
DeviceTaskStaus.PAUSE.getCode());
|
||||
query.in(DevicePlan::getTaskStaus, list);
|
||||
List<DevicePlan> devicePlanList = devicePlanMapper.selectList(query);
|
||||
if (!CollectionUtils.isEmpty(devicePlanList)) {
|
||||
@@ -116,7 +153,7 @@ public class InitThread implements ApplicationRunner {
|
||||
Long orgId = x.getOrgId();
|
||||
Long siteId = x.getSiteId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if(siteMemory!=null){
|
||||
if (siteMemory != null) {
|
||||
siteMemory.addDevicePlan(x);
|
||||
}
|
||||
});
|
||||
@@ -131,7 +168,7 @@ public class InitThread implements ApplicationRunner {
|
||||
Long orgId = x.getOrgId();
|
||||
Long siteId = x.getSiteId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if(siteMemory!=null){
|
||||
if (siteMemory != null) {
|
||||
siteMemory.addDevicePlanPrepare(x);
|
||||
}
|
||||
});
|
||||
@@ -145,7 +182,7 @@ public class InitThread implements ApplicationRunner {
|
||||
Long orgId = x.getOrgId();
|
||||
Long siteId = x.getSiteId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if(siteMemory!=null){
|
||||
if (siteMemory != null) {
|
||||
siteMemory.addDevicePlanExecute(x);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,102 +1,333 @@
|
||||
package com.maibu.netty.handler;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.maibu.common.CommandConstant;
|
||||
import com.maibu.common.NettyCacheKey;
|
||||
import com.maibu.core.business.DeviceRunStatistics;
|
||||
import com.maibu.core.business.DeviceRunningStatusHistory;
|
||||
import com.maibu.core.business.DeviceStatusRecordDTO;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.core.business.device.DeviceStatusDetail;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.inter.WebsocketMesDispather;
|
||||
import com.maibu.core.enums.MesType;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.dto.WebStatusMessageDTO;
|
||||
import com.maibu.influxdb.MowerRealTimeData;
|
||||
import com.maibu.influxdb.util.InfluxSqlBuilder;
|
||||
import com.maibu.manager.DeviceSessionManager;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.mqtt.MqttTopic;
|
||||
import com.maibu.utils.json.JsonUtils;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@ChannelHandler.Sharable
|
||||
public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataToDataBaseHandler.class);
|
||||
|
||||
@Autowired
|
||||
private DeviceSessionManager deviceSessionManager;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
private static final Long interval = 5000L;
|
||||
@Autowired
|
||||
private WebsocketMesDispather websocketMesDispather;
|
||||
|
||||
private static final Long interval = 5000L;
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
String deviceID = deviceSessionManager.getDeviceIdByChannel(channel);
|
||||
if (StringUtils.isEmpty(deviceID)) return;
|
||||
try {
|
||||
Channel channel = ctx.channel();
|
||||
String deviceID = deviceSessionManager.getDeviceIdByChannel(channel);
|
||||
if (StringUtils.isEmpty(deviceID))
|
||||
return;
|
||||
|
||||
byte[] bytes = Hex.decodeHex(msg.toCharArray());
|
||||
if (bytes[2] == CommandConstant.status) {
|
||||
String key = NettyCacheKey.deviceRunningStatusKey + deviceID;
|
||||
DeviceStatusRecordDTO recordDTO = redisCache.getCacheObject(key);
|
||||
boolean record = false;
|
||||
List<DeviceRunningStatusHistory> histories;
|
||||
if (recordDTO == null) {
|
||||
recordDTO = new DeviceStatusRecordDTO();
|
||||
histories = new ArrayList<>();
|
||||
record = true;
|
||||
} else {
|
||||
long lastRecordTime = recordDTO.getLastRecordTime();
|
||||
histories = recordDTO.getHistories();
|
||||
if (System.currentTimeMillis() - lastRecordTime >= interval) {
|
||||
record = true;
|
||||
}
|
||||
}
|
||||
if (record) {
|
||||
String deviceStatus = new String(bytes, 2, bytes.length - 4, StandardCharsets.UTF_8).trim();
|
||||
String[] split = deviceStatus.split(",");
|
||||
|
||||
DeviceRunningStatusHistory deviceRunningStatus = getDeviceRunningStatusHistory(deviceID, split);
|
||||
if (histories == null) {
|
||||
byte[] bytes = Hex.decodeHex(msg.toCharArray());
|
||||
if (bytes[2] == CommandConstant.status) {
|
||||
String key = NettyCacheKey.deviceRunningStatusKey + deviceID;
|
||||
DeviceStatusRecordDTO recordDTO = redisCache.getCacheObject(key);
|
||||
boolean record = false;
|
||||
List<DeviceRunningStatusHistory> histories;
|
||||
if (recordDTO == null) {
|
||||
recordDTO = new DeviceStatusRecordDTO();
|
||||
histories = new ArrayList<>();
|
||||
record = true;
|
||||
} else {
|
||||
long lastRecordTime = recordDTO.getLastRecordTime();
|
||||
histories = recordDTO.getHistories();
|
||||
if (System.currentTimeMillis() - lastRecordTime >= interval) {
|
||||
record = true;
|
||||
}
|
||||
}
|
||||
histories.add(deviceRunningStatus);
|
||||
recordDTO.setHistories(histories);
|
||||
recordDTO.setLastRecordTime(System.currentTimeMillis());
|
||||
if (record) {
|
||||
// 推送websocket实时消息给前端 todo mqtt推送
|
||||
|
||||
redisCache.setCacheObject(key, recordDTO);
|
||||
// 判断整点 记录到数据库
|
||||
// deviceStatusHistoryMapper.insert(deviceRunningStatus);
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceID);
|
||||
String workArea = deviceRunningStatus.getWorkingArea();
|
||||
DeviceRunStatistics latestStatus;
|
||||
if(nettyDevice.getLatestStatus() == null){
|
||||
latestStatus = new DeviceRunStatistics();
|
||||
latestStatus.setStartTime(LocalDateTime.now());
|
||||
latestStatus.setDeviceId(deviceID);
|
||||
}else {
|
||||
latestStatus = nettyDevice.getLatestStatus();
|
||||
// 使用Duration.between计算两个时间点之间的持续时间
|
||||
Duration duration = Duration.between(latestStatus.getStartTime(), LocalDateTime.now());
|
||||
long minutes = duration.toMinutes();
|
||||
latestStatus.setTime(minutes);
|
||||
String deviceStatus = new String(bytes, 2, bytes.length - 4, StandardCharsets.UTF_8).trim();
|
||||
String[] split = deviceStatus.split(",");
|
||||
WebStatusMessageDTO dto = createWebDeviceStatusMessage(split);
|
||||
try {
|
||||
GlobalMemory.mqttClientUtil.publish(
|
||||
String.format(MqttTopic.DEVICE_STATUS_TOPIC, deviceID),
|
||||
JsonUtils.toJsonString(dto));
|
||||
} catch (MqttException e) {
|
||||
logger.error("发送实时状态数据错误: {}", e.getMessage());
|
||||
}
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceID);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
controlMasters.forEach(x -> {
|
||||
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(dto));
|
||||
});
|
||||
}
|
||||
DeviceRunningStatusHistory deviceRunningStatus = getDeviceRunningStatusHistory(deviceID, split);
|
||||
if (histories == null) {
|
||||
histories = new ArrayList<>();
|
||||
}
|
||||
histories.add(deviceRunningStatus);
|
||||
recordDTO.setHistories(histories);
|
||||
recordDTO.setLastRecordTime(System.currentTimeMillis());
|
||||
redisCache.setCacheObject(key, recordDTO);
|
||||
|
||||
// todo 记录到InfluxDB 是否删除redis中的记录 目前先保留最近一次的记录在redis中
|
||||
MowerRealTimeData data = processInfluxData(deviceID, split);
|
||||
String line = InfluxSqlBuilder.buildLine(data);
|
||||
GlobalMemory.influxDBUtil.write(line);
|
||||
|
||||
// 判断整点 记录到数据库
|
||||
// deviceStatusHistoryMapper.insert(deviceRunningStatus);
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceID);
|
||||
String workArea = deviceRunningStatus.getWorkingArea();
|
||||
DeviceRunStatistics latestStatus;
|
||||
if (nettyDevice.getLatestStatus() == null) {
|
||||
latestStatus = new DeviceRunStatistics();
|
||||
latestStatus.setStartTime(LocalDateTime.now());
|
||||
latestStatus.setDeviceId(deviceID);
|
||||
} else {
|
||||
latestStatus = nettyDevice.getLatestStatus();
|
||||
// 使用Duration.between计算两个时间点之间的持续时间
|
||||
Duration duration = Duration.between(latestStatus.getStartTime(), LocalDateTime.now());
|
||||
long minutes = duration.toMinutes();
|
||||
latestStatus.setTime(minutes);
|
||||
}
|
||||
latestStatus.setWorkArea(Double.valueOf(workArea));
|
||||
nettyDevice.setLatestStatus(latestStatus);
|
||||
}
|
||||
latestStatus.setWorkArea(Double.valueOf(workArea));
|
||||
nettyDevice.setLatestStatus(latestStatus);
|
||||
}
|
||||
// else{
|
||||
// System.out.println(false);
|
||||
// }
|
||||
ctx.fireChannelRead(msg);
|
||||
} catch (Exception e) {
|
||||
logger.error("处理数据异常: {}", e.getMessage());
|
||||
}
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
|
||||
public WebStatusMessageDTO createWebDeviceStatusMessage(String[] split) {
|
||||
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
||||
List<DeviceStatusDetail> transferData = transferStatusData(split);
|
||||
webStatusMessageDTO.setData(transferData);
|
||||
webStatusMessageDTO.setType(MesType.deviceInfo);
|
||||
return webStatusMessageDTO;
|
||||
}
|
||||
|
||||
private List<DeviceStatusDetail> transferStatusData(String[] split) {
|
||||
List<DeviceStatusDetail> transferData = new ArrayList<>();
|
||||
|
||||
DeviceStatusDetail detail0 = new DeviceStatusDetail();
|
||||
detail0.setName("voltage");
|
||||
detail0.setValue(split[0]);
|
||||
detail0.setUnit("");
|
||||
transferData.add(detail0);
|
||||
|
||||
DeviceStatusDetail detail1 = new DeviceStatusDetail();
|
||||
detail1.setName("leftTargetSpeed");
|
||||
detail1.setValue(split[1]);
|
||||
detail1.setUnit("");
|
||||
transferData.add(detail1);
|
||||
|
||||
DeviceStatusDetail detail2 = new DeviceStatusDetail();
|
||||
detail2.setName("rightTargetSpeed");
|
||||
detail2.setValue(split[2]);
|
||||
detail2.setUnit("");
|
||||
transferData.add(detail2);
|
||||
|
||||
DeviceStatusDetail detail3 = new DeviceStatusDetail();
|
||||
detail3.setName("leftMeasureSpeed");
|
||||
detail3.setValue(split[3]);
|
||||
detail3.setUnit("");
|
||||
transferData.add(detail3);
|
||||
|
||||
DeviceStatusDetail detail4 = new DeviceStatusDetail();
|
||||
detail4.setName("rightMeasureSpeed");
|
||||
detail4.setValue(split[4]);
|
||||
detail4.setUnit("");
|
||||
transferData.add(detail4);
|
||||
|
||||
DeviceStatusDetail detail5 = new DeviceStatusDetail();
|
||||
detail5.setName("leftCurrent");
|
||||
detail5.setValue(split[5]);
|
||||
detail5.setUnit("");
|
||||
transferData.add(detail5);
|
||||
|
||||
DeviceStatusDetail detail6 = new DeviceStatusDetail();
|
||||
detail6.setName("rightCurrent");
|
||||
detail6.setValue(split[6]);
|
||||
detail6.setUnit("");
|
||||
transferData.add(detail6);
|
||||
|
||||
DeviceStatusDetail detail7 = new DeviceStatusDetail();
|
||||
detail7.setName("leftMotorTemp");
|
||||
detail7.setValue(split[7]);
|
||||
detail7.setUnit("");
|
||||
transferData.add(detail7);
|
||||
|
||||
DeviceStatusDetail detail8 = new DeviceStatusDetail();
|
||||
detail8.setName("rightMotorTemp");
|
||||
detail8.setValue(split[8]);
|
||||
detail8.setUnit("");
|
||||
transferData.add(detail8);
|
||||
|
||||
DeviceStatusDetail detail9 = new DeviceStatusDetail();
|
||||
detail9.setName("chipTemp");
|
||||
detail9.setValue(split[9]);
|
||||
detail9.setUnit("");
|
||||
transferData.add(detail9);
|
||||
|
||||
DeviceStatusDetail detail10 = new DeviceStatusDetail();
|
||||
detail10.setName("yaw");
|
||||
detail10.setValue(split[10]);
|
||||
detail10.setUnit("");
|
||||
transferData.add(detail10);
|
||||
|
||||
DeviceStatusDetail detail11 = new DeviceStatusDetail();
|
||||
detail11.setName("pitch");
|
||||
detail11.setValue(split[11]);
|
||||
detail11.setUnit("");
|
||||
transferData.add(detail11);
|
||||
|
||||
DeviceStatusDetail detail12 = new DeviceStatusDetail();
|
||||
detail12.setName("roll");
|
||||
detail12.setValue(split[12]);
|
||||
detail12.setUnit("");
|
||||
transferData.add(detail12);
|
||||
|
||||
DeviceStatusDetail detail13 = new DeviceStatusDetail();
|
||||
detail13.setName("satelliteCnt");
|
||||
detail13.setValue(split[13]);
|
||||
detail13.setUnit("");
|
||||
transferData.add(detail13);
|
||||
|
||||
DeviceStatusDetail detail14 = new DeviceStatusDetail();
|
||||
detail14.setName("qual");
|
||||
detail14.setValue(split[14]);
|
||||
detail14.setUnit("");
|
||||
transferData.add(detail14);
|
||||
|
||||
DeviceStatusDetail detail15 = new DeviceStatusDetail();
|
||||
detail15.setName("headingStatus");
|
||||
detail15.setValue(split[15]);
|
||||
detail15.setUnit("");
|
||||
transferData.add(detail15);
|
||||
|
||||
DeviceStatusDetail detail16 = new DeviceStatusDetail();
|
||||
detail16.setName("latitude");
|
||||
detail16.setValue(split[16]);
|
||||
detail16.setUnit("");
|
||||
transferData.add(detail16);
|
||||
|
||||
DeviceStatusDetail detail17 = new DeviceStatusDetail();
|
||||
detail17.setName("longitude");
|
||||
detail17.setValue(split[17]);
|
||||
detail17.setUnit("");
|
||||
transferData.add(detail17);
|
||||
|
||||
// 18 时间暂未给值
|
||||
|
||||
DeviceStatusDetail detail19 = new DeviceStatusDetail();
|
||||
detail19.setName("cuttingSpeed");
|
||||
detail19.setValue(split[19]);
|
||||
detail19.setUnit("");
|
||||
transferData.add(detail19);
|
||||
|
||||
DeviceStatusDetail detail20 = new DeviceStatusDetail();
|
||||
detail20.setName("controlMode");
|
||||
detail20.setValue(split[20]);
|
||||
detail20.setUnit("");
|
||||
transferData.add(detail20);
|
||||
|
||||
DeviceStatusDetail detail21 = new DeviceStatusDetail();
|
||||
detail21.setName("battery");
|
||||
detail21.setValue(split[21]);
|
||||
detail21.setUnit("");
|
||||
transferData.add(detail21);
|
||||
|
||||
DeviceStatusDetail detail22 = new DeviceStatusDetail();
|
||||
detail22.setName("workingArea");
|
||||
detail22.setValue(split[22]);
|
||||
detail22.setUnit("");
|
||||
transferData.add(detail22);
|
||||
|
||||
DeviceStatusDetail detail23 = new DeviceStatusDetail();
|
||||
detail23.setName("obstacleSign");
|
||||
detail23.setValue(split[23]);
|
||||
detail23.setUnit("");
|
||||
transferData.add(detail23);
|
||||
|
||||
return transferData;
|
||||
}
|
||||
|
||||
private MowerRealTimeData processInfluxData(String deviceID, String[] split) {
|
||||
MowerRealTimeData data = new MowerRealTimeData();
|
||||
data.setDeviceId(deviceID);
|
||||
data.setVoltage(split[0]);
|
||||
data.setLeftTargetSpeed(split[1]);
|
||||
data.setRightTargetSpeed(split[2]);
|
||||
data.setLeftMeasureSpeed(split[3]);
|
||||
data.setRightMeasureSpeed(split[4]);
|
||||
data.setLeftCurrent(split[5]);
|
||||
data.setRightCurrent(split[6]);
|
||||
data.setLeftMotorTemp(split[7]);
|
||||
data.setRightMotorTemp(split[8]);
|
||||
data.setChipTemp(split[9]);
|
||||
data.setYaw(split[10]);
|
||||
data.setPitch(split[11]);
|
||||
data.setRoll(split[12]);
|
||||
data.setSatelliteCnt(split[13]);
|
||||
data.setQual(split[14]);
|
||||
data.setHeadingStatus(split[15]);
|
||||
data.setLatitude(split[16]);
|
||||
data.setLongitude(split[17]);
|
||||
|
||||
// 18 时间暂未给值
|
||||
|
||||
data.setCuttingSpeed(split[19]);
|
||||
data.setControlMode(split[20]);
|
||||
data.setBattery(split[21]);
|
||||
data.setWorkingArea(split[22]);
|
||||
data.setObstacleSign(split[23]);
|
||||
|
||||
data.setTime(Instant.now());
|
||||
return data;
|
||||
}
|
||||
|
||||
private DeviceRunningStatusHistory getDeviceRunningStatusHistory(String deviceID, String[] split) {
|
||||
@@ -121,7 +352,7 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
|
||||
deviceRunningStatus.setLatitude(split[16]);
|
||||
deviceRunningStatus.setLongitude(split[17]);
|
||||
|
||||
//18 时间暂未给值
|
||||
// 18 时间暂未给值
|
||||
|
||||
deviceRunningStatus.setCuttingSpeed(split[19]);
|
||||
deviceRunningStatus.setControlMode(split[20]);
|
||||
|
||||
@@ -4,17 +4,16 @@ import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -22,9 +21,7 @@ import com.maibu.common.CommandConstant;
|
||||
import com.maibu.common.Constant;
|
||||
import com.maibu.core.business.Device;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.inter.DeviceWebSocketInterace;
|
||||
import com.maibu.core.business.inter.WebsocketMesDispather;
|
||||
import com.maibu.core.business.path.LatAndLngEntity;
|
||||
import com.maibu.core.domain.entity.SysUser;
|
||||
import com.maibu.core.domain.entity.UserClient;
|
||||
import com.maibu.core.enums.CommandRequestType;
|
||||
@@ -39,10 +36,11 @@ import com.maibu.dto.DeviceLoginResponseDTO;
|
||||
import com.maibu.dto.DeviceRequestDTO;
|
||||
import com.maibu.dto.DeviceRespondDTO;
|
||||
import com.maibu.dto.DeviceStatusChangeDTO;
|
||||
import com.maibu.dto.DeviceTaskReportDTO;
|
||||
import com.maibu.dto.DeviceTaskStatusMessageDTO;
|
||||
import com.maibu.manager.DeviceSessionManager;
|
||||
import com.maibu.mapper.DeviceRunStatisticsMapper;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.mqtt.MqttTopic;
|
||||
import com.maibu.service.IDeviceService;
|
||||
import com.maibu.service.ISysUserClientService;
|
||||
import com.maibu.service.ISysUserService;
|
||||
@@ -363,9 +361,13 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
|
||||
changeDTO.setStatus(DeviceTaskStaus.FINISH.toString());
|
||||
changeDTO.setType(MesType.device_task_change);
|
||||
changeDTO.setTaskId(taskId);
|
||||
// ByteBuf buf = ctx.alloc().buffer();
|
||||
// ByteBuf buf = Unpooled.buffer();
|
||||
// CommandUtils.buildCommand(buf, changeDTO, CommandConstant.interaction);
|
||||
|
||||
try {
|
||||
GlobalMemory.mqttClientUtil.publish(String.format(MqttTopic.DEVICE_TASK_STATUS_TOPIC, taskId),
|
||||
JsonUtils.toJsonString(changeDTO));
|
||||
} catch (MqttException e) {
|
||||
logger.error("任务完成状态推送失败 task:{},device:{}error:{}", taskId, deviceId, e.getMessage());
|
||||
}
|
||||
List<NettyDevice> controlMasters = sessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
@@ -373,14 +375,8 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
|
||||
websocketMesDispather.dispather(x.getConnectorId(),
|
||||
JsonUtils.toJsonString(changeDTO));
|
||||
// String content = buf.toString(CharsetUtil.UTF_8);
|
||||
logger.info("任务完成状态推送 task:{},device:{},content:{}", taskId, deviceId,
|
||||
logger.info("任务完成状态推送 task:{},device:{},content:{}", taskId, deviceId,
|
||||
JsonUtils.toJsonString(changeDTO));
|
||||
// if (x.getChannel() != null && x.getChannel().isActive()) {
|
||||
// x.getChannel().writeAndFlush(buf);
|
||||
// String content = buf.toString(CharsetUtil.UTF_8);
|
||||
// logger.info("任务完成状态推送 task:{},device:{},content:{}", taskId, deviceId,
|
||||
// content);
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -393,9 +389,14 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
|
||||
reportDTO.setTaskId(taskId);
|
||||
reportDTO.setEntity(device.getCurrentPoint());
|
||||
reportDTO.setType(MesType.device_task_arrive_point);
|
||||
// ByteBuf buf = ctx.alloc().buffer();
|
||||
// ByteBuf buf = Unpooled.buffer();
|
||||
// CommandUtils.buildCommand(buf, reportDTO, CommandConstant.interaction);
|
||||
try {
|
||||
|
||||
GlobalMemory.mqttClientUtil.publish(String.format(MqttTopic.DEVICE_TASK_ARRIVE_TOPIC, taskId),
|
||||
JsonUtils.toJsonString(reportDTO));
|
||||
} catch (MqttException e) {
|
||||
logger.error("任务点位到达推送失败 task:{},device:{}error:{}", taskId, deviceId, e.getMessage());
|
||||
}
|
||||
|
||||
List<NettyDevice> controlMasters = sessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
@@ -404,12 +405,6 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
|
||||
JsonUtils.toJsonString(reportDTO));
|
||||
logger.info("任务点位到达推送 task:{},device:{},content:{}", taskId, deviceId,
|
||||
JsonUtils.toJsonString(reportDTO));
|
||||
// if (x.getChannel() != null && x.getChannel().isActive()) {
|
||||
// x.getChannel().writeAndFlush(buf);
|
||||
// String content = buf.toString(CharsetUtil.UTF_8);
|
||||
// logger.info("任务点位到达推送 task:{},device:{},content:{}", taskId, deviceId,
|
||||
// content);
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class ScheduledTask {
|
||||
// recordDTO.getHistories().forEach(x -> {
|
||||
// deviceStatusHistoryMapper.insert(x);
|
||||
// });
|
||||
|
||||
deviceStatusHistoryMapper.insertBatch(recordDTO.getHistories());
|
||||
}
|
||||
redisCache.deleteObject(k);
|
||||
|
||||
@@ -375,6 +375,18 @@ public class DeviceTaskService {
|
||||
if (!StringUtils.isEmpty(dto.getDeviceId())) {
|
||||
list = list.stream().filter(x -> x.getDeviceId().equals(dto.getDeviceId())).collect(Collectors.toList());
|
||||
}
|
||||
if (dto.getStartTime() != null) {
|
||||
list = list.stream()
|
||||
.filter(x -> x.getCreateTime() != null
|
||||
&& !x.getCreateTime().isBefore(dto.getStartTime()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if (dto.getEndTime() != null) {
|
||||
list = list.stream()
|
||||
.filter(x -> x.getCreateTime() != null
|
||||
&& !x.getCreateTime().isAfter(dto.getEndTime()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return transferDeviceTaskData(list);
|
||||
}
|
||||
|
||||
@@ -395,6 +407,12 @@ public class DeviceTaskService {
|
||||
if (!StringUtils.isEmpty(dto.getDeviceId())) {
|
||||
queryWrapper.eq(DevicePlanTask::getDeviceId, dto.getDeviceId());
|
||||
}
|
||||
if (dto.getStartTime() != null) {
|
||||
queryWrapper.ge(DevicePlanTask::getCreateTime, dto.getStartTime());
|
||||
}
|
||||
if (dto.getEndTime() != null) {
|
||||
queryWrapper.le(DevicePlanTask::getCreateTime, dto.getEndTime());
|
||||
}
|
||||
return transferDeviceTaskData(devicePlanTaskMapper.selectList(queryWrapper));
|
||||
}
|
||||
|
||||
@@ -446,24 +464,32 @@ public class DeviceTaskService {
|
||||
}
|
||||
|
||||
public boolean cancelTask(DeviceTaskCommandDTO dto, String username) {
|
||||
if (!StringUtils.isEmpty(dto.getDeviceId())) {
|
||||
NettyDevice device = deviceSessionManager.getDevice(dto.getDeviceId());
|
||||
if (device != null) {
|
||||
return device.cancelTask();
|
||||
}
|
||||
} else {
|
||||
String deviceId = dto.getDeviceId();
|
||||
DevicePlanTask devicePlanTask = null;
|
||||
if (StringUtils.isEmpty(dto.getDeviceId())) {
|
||||
Long taskId = dto.getTaskId();
|
||||
// Long siteId = dto.getSiteId();
|
||||
// Long orgId = dto.getOrgId();
|
||||
DevicePlanTask devicePlanTask = devicePlanTaskMapper.selectById(taskId);
|
||||
devicePlanTask = devicePlanTaskMapper.selectById(taskId);
|
||||
if (devicePlanTask != null) {
|
||||
NettyDevice device = deviceSessionManager.getDevice(devicePlanTask.getDeviceId());
|
||||
if (device != null) {
|
||||
return device.cancelTask();
|
||||
}
|
||||
deviceId = devicePlanTask.getDeviceId();
|
||||
}
|
||||
}
|
||||
NettyDevice device = deviceSessionManager.getDevice(deviceId);
|
||||
if (device != null && device.getTask() != null) {
|
||||
return device.cancelTask();
|
||||
} else {
|
||||
if (devicePlanTask != null) {
|
||||
devicePlanTask.setTaskStaus(DeviceTaskStaus.CANCELED);
|
||||
devicePlanTask.setUpdateTime(LocalDateTime.now());
|
||||
devicePlanTaskMapper.saveOrUpdate(devicePlanTask);
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(devicePlanTask.getOrgId(),
|
||||
devicePlanTask.getSiteId());
|
||||
siteMemory.removeDevicePlanPrepare(devicePlanTask);
|
||||
siteMemory.removeDevicePlanExecute(devicePlanTask.getDeviceId());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// todo 完善
|
||||
|
||||
@@ -136,13 +136,13 @@ public class TransferDeviceService {
|
||||
if (device == null) {
|
||||
return AjaxResult.error("设备不存在");
|
||||
} else {
|
||||
Long tenantId = device.getTenantId();
|
||||
if (tenantId == -1) {
|
||||
return AjaxResult.error("设备未绑定");
|
||||
}
|
||||
if (!tenantId.equals(user.getUserId())) {
|
||||
return AjaxResult.error("无操作权限");
|
||||
}
|
||||
// Long tenantId = device.getTenantId();
|
||||
// if (tenantId == -1) {
|
||||
// return AjaxResult.error("设备未绑定");
|
||||
// }
|
||||
// if (!tenantId.equals(user.getUserId())) {
|
||||
// return AjaxResult.error("无操作权限");
|
||||
// }
|
||||
device.setDeviceAlias(bindDTO.getDeviceAlias());
|
||||
device.setUpdateTime(LocalDateTime.now());
|
||||
device.setCreateBy(user.getUsername());
|
||||
|
||||
Reference in New Issue
Block a user