This commit is contained in:
2026-06-03 16:53:02 +08:00
parent f02329b2d0
commit 133a2bd223
31 changed files with 929 additions and 296 deletions

View File

@@ -2,9 +2,14 @@ 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;
@@ -46,7 +51,10 @@ public class InitThread implements ApplicationRunner {
private DevicePlanMapper devicePlanMapper;
@Autowired
private SysUserClientMapper sysUserClientMapper;
private DevicePlanTaskMapper devicePlanTaskMapper;
@Autowired
private SysSiteMapper sysSiteMapper;
@Override
public void run(ApplicationArguments args) {
@@ -82,17 +90,60 @@ public class InitThread implements ApplicationRunner {
/**
* 恢复内存
*/
public void recoverMemory(){
public void recoverMemory() {
//todo 启动时清除当前登录记录
// System.out.println("开始清除登录信息");
// sysUserClientMapper.clearDeviceName();
List<SysSite> siteList = sysSiteMapper.selectList();
if (!CollectionUtils.isEmpty(siteList)) {
siteList.forEach(x -> {
Long orgId = x.getOrgId();
Long siteId = x.getId();
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
if (siteMemory == null) {
siteMemory = new SiteMemory();
GlobalMemory.addSiteMemory(orgId, siteId, siteMemory);
}
});
}
// 未执行完的重复计划
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)){
devicePlanList.forEach(SiteMemory::addDevicePlan);
if (!CollectionUtils.isEmpty(devicePlanList)) {
devicePlanList.forEach(x -> {
Long orgId = x.getOrgId();
Long siteId = x.getSiteId();
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
siteMemory.addDevicePlan(x);
});
}
// 未执行完的重复计划
LambdaQueryWrapperX<DevicePlanTask> taskQuery = new LambdaQueryWrapperX<>();
taskQuery.eq(DevicePlanTask::getTaskStaus, DeviceTaskStaus.NEW.getCode());
List<DevicePlanTask> newStatusList = devicePlanTaskMapper.selectList(taskQuery);
if (!CollectionUtils.isEmpty(newStatusList)) {
newStatusList.forEach(x -> {
Long orgId = x.getOrgId();
Long siteId = x.getSiteId();
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
siteMemory.addDevicePlanPrepare(x);
});
}
LambdaQueryWrapperX<DevicePlanTask> executeTaskQuery = new LambdaQueryWrapperX<>();
executeTaskQuery.eq(DevicePlanTask::getTaskStaus, DeviceTaskStaus.EXECUTING.getCode());
List<DevicePlanTask> executeStatusList = devicePlanTaskMapper.selectList(executeTaskQuery);
if (!CollectionUtils.isEmpty(executeStatusList)) {
executeStatusList.forEach(x -> {
Long orgId = x.getOrgId();
Long siteId = x.getSiteId();
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
siteMemory.addDevicePlanExecute(x);
});
}
}
}