#区域连续作业相关
This commit is contained in:
@@ -20,6 +20,8 @@ import com.maibu.core.business.dto.WebMapMessageDTO;
|
||||
import com.maibu.core.business.dto.WebOlineStatusMessageDTO;
|
||||
import com.maibu.core.enums.*;
|
||||
import com.maibu.utils.json.JsonUtils;
|
||||
import com.maibu.utils.spring.SpringUtils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.checkerframework.checker.units.qual.s;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -31,6 +33,7 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.maibu.constant.Constant;
|
||||
import com.maibu.constant.NettyCacheKey;
|
||||
import com.maibu.core.business.Device;
|
||||
@@ -38,6 +41,7 @@ import com.maibu.core.business.DeviceRunStatistics;
|
||||
import com.maibu.core.business.DeviceRunningStatusHistory;
|
||||
import com.maibu.core.business.DeviceStatusRecordDTO;
|
||||
import com.maibu.core.business.ErrorIdentificationStandard;
|
||||
import com.maibu.core.business.RegionConsecutiveTaskRecord;
|
||||
import com.maibu.core.business.alarm_center.AlarmMessage;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.inter.WebsocketMesDispather;
|
||||
@@ -54,6 +58,7 @@ import com.maibu.dto.DeviceTaskStatusMessageDTO;
|
||||
import com.maibu.mapper.DeviceRunStatisticsMapper;
|
||||
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
||||
import com.maibu.mapper.HostLocationMapper;
|
||||
import com.maibu.mapper.RegionConsecutiveTaskRecordMapper;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
@@ -104,6 +109,9 @@ public class DeviceThreadService {
|
||||
@Autowired
|
||||
private DeviceTaskService deviceTaskService;
|
||||
|
||||
@JsonIgnore
|
||||
private RegionConsecutiveTaskRecordMapper regionConsecutiveTaskRecordMapper;
|
||||
|
||||
public void deviceErrorMonitor() throws InterruptedException, IOException {
|
||||
initStandard();
|
||||
|
||||
@@ -308,7 +316,8 @@ public class DeviceThreadService {
|
||||
}
|
||||
if (nowTime - lastActiveTime >= Constant.hostOfflineInterval) {
|
||||
// 超时了判断离线
|
||||
if (nettyDevice != null && nettyDevice.getOnlineStatus() == 1) {
|
||||
if (nettyDevice != null && nettyDevice.getOnlineStatus() != null
|
||||
&& nettyDevice.getOnlineStatus() == 1) {
|
||||
nettyDevice.status(DeviceStatus.offline.getType());
|
||||
// todo 推送设备离线
|
||||
String key = NettyCacheKey.latestPositonKey + deviceId;
|
||||
@@ -401,7 +410,7 @@ public class DeviceThreadService {
|
||||
} else {
|
||||
|
||||
Integer lastOnlineStatus = nettyDevice.getOnlineStatus();
|
||||
if (lastOnlineStatus == 0) {
|
||||
if (lastOnlineStatus == null || lastOnlineStatus == 0) {
|
||||
statusChangePush(deviceId, device.getSiteId(), 1);
|
||||
}
|
||||
// todo 推送设备上线
|
||||
@@ -567,4 +576,49 @@ public class DeviceThreadService {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则触发自动判断
|
||||
*/
|
||||
public void regionConsecutiveTaskHandler() {
|
||||
executor.scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
List<SiteMemory> list = GlobalMemory.getAllSiteMemory();
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
list.forEach(siteMemory -> {
|
||||
|
||||
ConcurrentHashMap<String, RegionConsecutiveTaskRecord> recordMap = siteMemory.regionConsecutiveTaskMap;
|
||||
if (!CollectionUtils.isEmpty(recordMap)) {
|
||||
recordMap.keySet().forEach(key -> {
|
||||
RegionConsecutiveTaskRecord record = recordMap.get(key);
|
||||
if (record == null || record.getDeviceId() == null
|
||||
|| CollectionUtils.isEmpty(record.getRouteIds()))
|
||||
return;
|
||||
if (siteMemory.hasTask(record.getDeviceId()))
|
||||
return;
|
||||
int currentIndex = record.getCurrentIndex();
|
||||
Long routeId = record.getRouteIds().get(currentIndex);
|
||||
DeviceTaskCommandDTO dto = new DeviceTaskCommandDTO();
|
||||
dto.setDeviceId(record.getDeviceId());
|
||||
dto.setOrgId(siteMemory.getSysSite().getOrgId());
|
||||
dto.setSiteId(siteMemory.getSysSite().getId());
|
||||
dto.setRouteId(routeId);
|
||||
Long taskId = deviceTaskService.createDeviceTask(dto, "system");
|
||||
if (taskId != null) {
|
||||
record.getTaskIds().add(taskId);
|
||||
record.setCurrentIndex(currentIndex + 1);
|
||||
|
||||
regionConsecutiveTaskRecordMapper.saveOrUpdate(record);
|
||||
siteMemory.regionConsecutiveTaskMap.put(key, record);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("区域连续任务处理线程错误:{}", e.getMessage());
|
||||
}
|
||||
}, 0, 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user