#update
This commit is contained in:
@@ -15,6 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.maibu.core.business.dto.DeviceMapPushDTO;
|
||||
import com.maibu.core.business.dto.DeviceTaskCommandDTO;
|
||||
import com.maibu.core.business.dto.WebMapMessageDTO;
|
||||
import com.maibu.core.business.dto.WebOlineStatusMessageDTO;
|
||||
import com.maibu.core.enums.*;
|
||||
@@ -40,8 +41,13 @@ import com.maibu.core.business.ErrorIdentificationStandard;
|
||||
import com.maibu.core.business.alarm_center.AlarmMessage;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.inter.WebsocketMesDispather;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.domain.rule.ActionConfig;
|
||||
import com.maibu.core.domain.rule.IotAutoRule;
|
||||
import com.maibu.core.domain.rule.TriggerConditions;
|
||||
import com.maibu.core.host.HeartBeatDTO;
|
||||
import com.maibu.core.host.LocationMessage;
|
||||
import com.maibu.core.host.VehicleMessage;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.dto.DeviceErrorPushDTO;
|
||||
import com.maibu.dto.DeviceTaskStatusMessageDTO;
|
||||
@@ -95,6 +101,9 @@ public class DeviceThreadService {
|
||||
@Autowired
|
||||
private DeviceRunStatisticsMapper deviceRunStatisticsMapper;
|
||||
|
||||
@Autowired
|
||||
private DeviceTaskService deviceTaskService;
|
||||
|
||||
public void deviceErrorMonitor() throws InterruptedException, IOException {
|
||||
initStandard();
|
||||
|
||||
@@ -456,4 +465,101 @@ public class DeviceThreadService {
|
||||
}, 0, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则触发自动判断
|
||||
*/
|
||||
public void autoRule() {
|
||||
executor.scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
List<SiteMemory> list = GlobalMemory.getAllSiteMemory();
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
list.forEach(x -> {
|
||||
List<IotAutoRule> rules = x.getAllIotAutoRule();
|
||||
if (!CollectionUtils.isEmpty(rules)) {
|
||||
rules.forEach(rule -> {
|
||||
// 根据不同的 类型区分处理方式
|
||||
handleAutoRule(rule, x);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("执行规则出发线程错误:{}", e.getMessage());
|
||||
}
|
||||
}, 0, 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void handleAutoRule(IotAutoRule rule, SiteMemory siteMemory) {
|
||||
|
||||
if (RuleType.LOW_BATTERY_RETURN.equals(rule.getRuleType())) {
|
||||
TriggerConditions conditions = rule.getConditions();
|
||||
String key = conditions.getKey();
|
||||
CompareEnum compareType = conditions.getOperator();
|
||||
String compareValue = conditions.getValue();
|
||||
List<VehicleMessage> vList = siteMemory.getAllVehicleMessage();
|
||||
if (!CollectionUtils.isEmpty(vList)) {
|
||||
vList.forEach(x -> {
|
||||
String deviceId = x.getDeviceId();
|
||||
String value = classFieldFinding(key, x);
|
||||
boolean result = CompareUtils.compare(compareType, value, compareValue);
|
||||
if (result) {
|
||||
ActionConfig aConfig = rule.getActionConfig();
|
||||
if (aConfig != null && aConfig.getActionType() != null) {
|
||||
ActionType actionType = aConfig.getActionType();
|
||||
if (ActionType.BACK_TO_REST.equals(actionType)) {
|
||||
if (siteMemory.hasTask(deviceId)) {
|
||||
return;
|
||||
}
|
||||
DeviceTaskCommandDTO dto = new DeviceTaskCommandDTO();
|
||||
dto.setDeviceId(deviceId);
|
||||
dto.setOrgId(siteMemory.getSysSite().getOrgId());
|
||||
dto.setSiteId(siteMemory.getSysSite().getId());
|
||||
|
||||
deviceTaskService.backToRestPoint(dto, "system");
|
||||
}
|
||||
if (ActionType.AUTO_TASK.equals(actionType)) {
|
||||
if (siteMemory.hasTask(deviceId)) {
|
||||
return;
|
||||
}
|
||||
Long routeId = aConfig.getRouteId();
|
||||
DeviceTaskCommandDTO dto = new DeviceTaskCommandDTO();
|
||||
dto.setDeviceId(deviceId);
|
||||
dto.setOrgId(siteMemory.getSysSite().getOrgId());
|
||||
dto.setSiteId(siteMemory.getSysSite().getId());
|
||||
dto.setRouteId(routeId);
|
||||
deviceTaskService.createDeviceTask(dto, "system");
|
||||
}
|
||||
if (ActionType.ALARM.equals(actionType)) {
|
||||
|
||||
}
|
||||
if (ActionType.SEND_COMMAND.equals(actionType)) {
|
||||
|
||||
}
|
||||
if (ActionType.WORK_ORDER.equals(actionType)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String classFieldFinding(String fieldName, VehicleMessage history) {
|
||||
try {
|
||||
// 1. 获取类的Class对象
|
||||
Class<?> vehicleClass = VehicleMessage.class;
|
||||
Field field = vehicleClass.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(history);
|
||||
return (String) value;
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
System.out.println("获取字段失败: " + e.getMessage());
|
||||
log.error("获取属性值失败:{}", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user