#update
This commit is contained in:
@@ -11,6 +11,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import com.maibu.core.business.alarm_center.Alarm;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -26,7 +28,6 @@ import com.maibu.core.business.alarm_center.AlarmMessage;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.dto.DeviceErrorPushDTO;
|
||||
import com.maibu.manager.DeviceSessionManager;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
import com.maibu.service.impl.AlarmServiceImpl;
|
||||
@@ -93,25 +94,37 @@ public class AlertPushService {
|
||||
Boolean exists = redisCache.hasKey(pushKey);
|
||||
if (exists != null && !exists) {
|
||||
newList.add(detail);
|
||||
redisCache.setCacheObject(pushKey, JsonUtils.toJsonString(detail), 10,
|
||||
TimeUnit.MINUTES);
|
||||
redisCache.setCacheObject(pushKey, JsonUtils.toJsonString(detail));
|
||||
AlarmOrderConfig config = siteMemory.getAlarmOrderConfig(detail.getNo());
|
||||
log.debug("compare config:{}", JsonUtils.toJsonString(config));
|
||||
if (config != null && config.isAutoGenerateOrder()) {
|
||||
IOTWorkOrder workOrder = wService.generateWorkOrders(siteId, deviceId, orgId, config.getModelId(), detail.getNo());
|
||||
workOrders.add(workOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
AlarmOrderConfig config = siteMemory.getAlarmOrderConfig(detail.getNo());
|
||||
if (config != null && config.isAutoGenerateOrder()) {
|
||||
IOTWorkOrder workOrder = wService.generateWorkOrders(siteId, deviceId, orgId, orgId);
|
||||
workOrders.add(workOrder);
|
||||
}
|
||||
});
|
||||
//todo 后续添加配置推送的告警等级
|
||||
if (alertPush == 1) {
|
||||
alarmService.pushAlertMes(dto.getDetails());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(workOrders)) {
|
||||
wService.saveAll(workOrders);
|
||||
List<Alarm> alarms = alarmService.pushAlertMes(newList);
|
||||
log.debug("alarms : {}", JsonUtils.toJsonString(alarms));
|
||||
log.debug("workOrders : {}", JsonUtils.toJsonString(workOrders));
|
||||
if (!CollectionUtils.isEmpty(workOrders)) {
|
||||
if (!CollectionUtils.isEmpty(alarms)) {
|
||||
workOrders.forEach(x -> {
|
||||
alarms.forEach(y -> {
|
||||
if (x.getAlarmNo().equals(y.getAlarmNo())) {
|
||||
x.setAlarmId(y.getId());
|
||||
x.setTaskDescription(y.getAlarmContent());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
wService.saveAll(workOrders);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ package com.maibu.service;
|
||||
import com.maibu.core.business.DevicePlan;
|
||||
import com.maibu.core.business.DevicePlanTask;
|
||||
import com.maibu.core.business.DeviceTaskPlanRule;
|
||||
import com.maibu.core.business.WorkRecord;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.enums.DeviceTaskPlanRepeatType;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.manager.DeviceSessionManager;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
import com.maibu.mapper.DevicePlanTaskMapper;
|
||||
import com.maibu.mapper.WorkRecordMapper;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -29,7 +30,6 @@ import com.maibu.dto.DevicePlanStatisticsDTO;
|
||||
import com.maibu.dto.DevicePlanTaskStatisticsDTO;
|
||||
import com.maibu.dto.DeviceTaskQueryDTO;
|
||||
import com.maibu.dto.DeviceWorkStatisticsDTO;
|
||||
import com.maibu.manager.DeviceSessionManager;
|
||||
import com.maibu.mapper.DeviceMapper;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
import com.maibu.mapper.DevicePlanTaskMapper;
|
||||
@@ -454,7 +454,7 @@ public class DeviceTaskService {
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean createDeviceTask(DeviceTaskCommandDTO dto, String username) {
|
||||
public Long createDeviceTask(DeviceTaskCommandDTO dto, String username) {
|
||||
DevicePlanTask task = new DevicePlanTask();
|
||||
task.setOrgId(dto.getOrgId());
|
||||
task.setSiteId(dto.getSiteId());
|
||||
@@ -464,7 +464,7 @@ public class DeviceTaskService {
|
||||
task.setCreateTime(LocalDateTime.now());
|
||||
task.setRouteId(dto.getRouteId());
|
||||
task.setStartTime(dto.getStartTime());
|
||||
boolean result = devicePlanTaskMapper.saveOrUpdate(task);
|
||||
devicePlanTaskMapper.saveOrUpdate(task);
|
||||
if (dto.getOrgId() == null) {
|
||||
SysSite site = sysSiteMapper.selectById(dto.getSiteId());
|
||||
if (site != null) {
|
||||
@@ -473,7 +473,7 @@ public class DeviceTaskService {
|
||||
}
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(), task.getSiteId());
|
||||
siteMemory.addDevicePlanPrepare(task);
|
||||
return result;
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
public boolean cancelTask(DeviceTaskCommandDTO dto, String username) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -36,7 +37,6 @@ import com.maibu.core.enums.ErrorSource;
|
||||
import com.maibu.core.enums.RespondCode;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.dto.DeviceErrorPushDTO;
|
||||
import com.maibu.manager.DeviceSessionManager;
|
||||
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
@@ -92,19 +92,22 @@ public class DeviceThreadService {
|
||||
String[] parts = k.split(":");
|
||||
String deviceId = parts[1];
|
||||
NettyDevice slaveDevice = sessionManager.getDevice(deviceId);
|
||||
Long siteId = slaveDevice != null ? slaveDevice.getDevice().getSiteId() : null;
|
||||
Long orgId = slaveDevice != null ? slaveDevice.getDevice().getOrgId() : null;
|
||||
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
List<AlarmMessage> compared = compareErrorStandard(siteId, orgId, history,
|
||||
siteMemory.standards.get(ErrorSource.MOWER));
|
||||
|
||||
DeviceErrorPushDTO pushDTO = new DeviceErrorPushDTO();
|
||||
pushDTO.setDeviceId(deviceId);
|
||||
pushDTO.setTime(System.currentTimeMillis());
|
||||
pushDTO.setDetails(compared);
|
||||
pushDTO.setEvent(RespondCode.device_error_push);
|
||||
pushList.add(pushDTO);
|
||||
if (slaveDevice != null && slaveDevice.isOnline()) {
|
||||
Long siteId = slaveDevice.getDevice().getSiteId();
|
||||
Long orgId = slaveDevice.getDevice().getOrgId();
|
||||
log.debug("compare siteId:{},orgId:{}", siteId, orgId);
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory != null) {
|
||||
List<AlarmMessage> compared = compareErrorStandard(siteId, orgId, history,
|
||||
siteMemory.standards.get(ErrorSource.MOWER));
|
||||
DeviceErrorPushDTO pushDTO = new DeviceErrorPushDTO();
|
||||
pushDTO.setDeviceId(deviceId);
|
||||
pushDTO.setTime(System.currentTimeMillis());
|
||||
pushDTO.setDetails(compared);
|
||||
pushDTO.setEvent(RespondCode.device_error_push);
|
||||
pushList.add(pushDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// 按实际deviceId分组,推送错误信息
|
||||
@@ -195,7 +198,7 @@ public class DeviceThreadService {
|
||||
}
|
||||
|
||||
public List<AlarmMessage> compareErrorStandard(Long siteId, Long orgId, DeviceRunningStatusHistory history,
|
||||
List<ErrorIdentificationStandard> standards) {
|
||||
List<ErrorIdentificationStandard> standards) {
|
||||
if (history == null || CollectionUtils.isEmpty(standards))
|
||||
return null;
|
||||
List<AlarmMessage> list = new ArrayList<>();
|
||||
@@ -204,9 +207,11 @@ public class DeviceThreadService {
|
||||
String compareValues = standard.getCompareValues();
|
||||
CompareEnum compareType = standard.getCompareType();
|
||||
String targetValue = knownClassFieldFinding(fieldName, history);
|
||||
log.debug("compare2 compareType:{} compareValues:{},targetValue:{}", compareType, compareValues, targetValue);
|
||||
if (!StringUtils.isEmpty(compareValues) && !StringUtils.isEmpty(targetValue)) {
|
||||
boolean result = CompareUtils.compare(compareType, compareValues, targetValue);
|
||||
if (!result) {
|
||||
boolean result = CompareUtils.compare(compareType, targetValue, compareValues);
|
||||
log.debug("compare3 result:{}", result);
|
||||
if (result) {
|
||||
AlarmMessage alarm = new AlarmMessage();
|
||||
alarm.setContent(standard.getErrorDescription());
|
||||
alarm.setDeviceSn(history.getDeviceId());
|
||||
@@ -217,6 +222,7 @@ public class DeviceThreadService {
|
||||
alarm.setNo(standard.getErrorCode());
|
||||
alarm.setSuggestion(standard.getSuggestion());
|
||||
alarm.setStatus("未处理");
|
||||
alarm.setTimeValues(targetValue);
|
||||
alarm.setTime(LocalDateTime.now());
|
||||
alarm.setOrgId(orgId);
|
||||
alarm.setSiteId(siteId);
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.maibu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.maibu.constant.Constant;
|
||||
import com.maibu.core.business.DeviceRunningStatusHistory;
|
||||
import com.maibu.core.business.ErrorIdentificationStandard;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.dto.SendCommandDTO;
|
||||
import com.maibu.mapper.DeviceStatusHistoryMapper;
|
||||
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,6 +24,9 @@ public class NettyDeviceService {
|
||||
@Autowired
|
||||
private DeviceStatusHistoryMapper deviceStatusHistoryMapper;
|
||||
|
||||
@Autowired
|
||||
private DeviceSessionManager deviceSessionManager;
|
||||
|
||||
@Autowired
|
||||
private ErrorIdentificationStandardMapper errorIdentificationStandardMapper;
|
||||
|
||||
@@ -40,5 +48,25 @@ public class NettyDeviceService {
|
||||
return errorIdentificationStandardMapper.updateById(standard);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.domain.entity.UserClient;
|
||||
import com.maibu.core.domain.model.LoginUser;
|
||||
import com.maibu.core.enums.ConnectorStatus;
|
||||
import com.maibu.manager.DeviceSessionManager;
|
||||
import com.maibu.mapper.DeviceMapper;
|
||||
import com.maibu.mapper.SysUserClientMapper;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
Reference in New Issue
Block a user