#update
This commit is contained in:
@@ -5,14 +5,12 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.checkerframework.checker.units.qual.s;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@@ -26,7 +24,6 @@ import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.maibu.constant.FastBeeConstant;
|
||||
import com.maibu.core.business.AlarmOrderConfig;
|
||||
import com.maibu.core.business.Device;
|
||||
import com.maibu.core.business.DeviceModel;
|
||||
import com.maibu.core.business.DevicePlan;
|
||||
import com.maibu.core.business.DevicePlanTask;
|
||||
@@ -35,9 +32,12 @@ import com.maibu.core.business.ErrorIdentificationStandard;
|
||||
import com.maibu.core.business.IoTCommonDevice;
|
||||
import com.maibu.core.business.OrderModel;
|
||||
import com.maibu.core.business.Product;
|
||||
import com.maibu.core.business.WorkRecord;
|
||||
import com.maibu.core.domain.entity.SysParam;
|
||||
import com.maibu.core.domain.entity.SysSite;
|
||||
import com.maibu.core.domain.map.SiteMapInfo;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.core.enums.RouteType;
|
||||
import com.maibu.influxdb.util.InfluxDBUtil;
|
||||
import com.maibu.mapper.AlarmOrderConfigMapper;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
@@ -47,9 +47,11 @@ import com.maibu.mapper.DeviceRunParamMapper;
|
||||
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
||||
import com.maibu.mapper.IotDeviceCommonMapper;
|
||||
import com.maibu.mapper.OrderModelMapper;
|
||||
import com.maibu.mapper.SiteMapInfoMapper;
|
||||
import com.maibu.mapper.SysDeviceModelMapper;
|
||||
import com.maibu.mapper.SysParamMapper;
|
||||
import com.maibu.mapper.SysSiteMapper;
|
||||
import com.maibu.mapper.WorkRecordMapper;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
import com.maibu.mybatis.LambdaQueryWrapperX;
|
||||
@@ -57,7 +59,6 @@ import com.maibu.service.DevicePlanTaskMonitorService;
|
||||
import com.maibu.service.DeviceThreadService;
|
||||
import com.maibu.service.impl.IotDeviceCommonService;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -75,6 +76,9 @@ public class InitThread implements ApplicationRunner {
|
||||
@Resource(name = FastBeeConstant.TASK.MAP_MESSAGE_PUSH)
|
||||
private Executor mapMessagePushExecutor;
|
||||
|
||||
@Resource(name = FastBeeConstant.TASK.AUTO_RULE)
|
||||
private Executor autoRuleExecutor;
|
||||
|
||||
@Resource(name = FastBeeConstant.TASK.COMMON_DEVICE_MONITOR)
|
||||
private Executor commonDeviceMonitorExecutor;
|
||||
|
||||
@@ -96,6 +100,9 @@ public class InitThread implements ApplicationRunner {
|
||||
@Autowired
|
||||
private SysSiteMapper sysSiteMapper;
|
||||
|
||||
@Autowired
|
||||
private SiteMapInfoMapper siteMapInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private DeviceRunParamMapper deviceRunParamMapper;
|
||||
|
||||
@@ -111,7 +118,7 @@ public class InitThread implements ApplicationRunner {
|
||||
@Autowired
|
||||
private ErrorIdentificationStandardMapper errorIdentificationStandardMapper;
|
||||
@Autowired
|
||||
|
||||
|
||||
private OrderModelMapper orderModelMapper;
|
||||
@Autowired
|
||||
private AlarmOrderConfigMapper alarmOrderConfigMapper;
|
||||
@@ -125,6 +132,9 @@ public class InitThread implements ApplicationRunner {
|
||||
@Autowired
|
||||
private SysParamMapper sysParamMapper;
|
||||
|
||||
@Autowired
|
||||
private WorkRecordMapper workRecordMapper;
|
||||
|
||||
@Value("${influxdb.url}")
|
||||
private String influxDBUrl;
|
||||
|
||||
@@ -162,14 +172,21 @@ public class InitThread implements ApplicationRunner {
|
||||
}
|
||||
|
||||
private void init() throws Exception {
|
||||
//初始化系统参数
|
||||
// 初始化系统参数
|
||||
initSystemParam();
|
||||
|
||||
initDefaultWorkRecord();
|
||||
|
||||
// 初始化InfluxDBUtil
|
||||
GlobalMemory.influxDBUtil = new InfluxDBUtil(influxDBUrl, influxDBToken, influxDBOrg, influxDBBucket);
|
||||
|
||||
GlobalMemory.initMqttDeviceMonitor(mqttHostUrl, mqttClientId, mqttUsername, mqttPassword);
|
||||
|
||||
// 规则触发线程
|
||||
autoRuleExecutor.execute(() -> {
|
||||
deviceThreadService.autoRule();
|
||||
});
|
||||
|
||||
// 地图监控推送
|
||||
mapMessagePushExecutor.execute(() -> {
|
||||
deviceThreadService.mapMessagePush();
|
||||
@@ -225,6 +242,19 @@ public class InitThread implements ApplicationRunner {
|
||||
});
|
||||
}
|
||||
|
||||
// 场站的 地图配置信息
|
||||
List<SiteMapInfo> siteMapInfoList = siteMapInfoMapper.selectList();
|
||||
if (!CollectionUtils.isEmpty(siteMapInfoList)) {
|
||||
siteMapInfoList.forEach(x -> {
|
||||
Long orgId = x.getOrgId();
|
||||
Long siteId = x.getSiteId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory != null) {
|
||||
siteMemory.getSysSite().setSiteMapInfo(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 外部设备
|
||||
List<IoTCommonDevice> ioTCommonDeviceList = iotDeviceCommonMapper.selectList();
|
||||
if (!CollectionUtils.isEmpty(ioTCommonDeviceList)) {
|
||||
@@ -391,4 +421,40 @@ public class InitThread implements ApplicationRunner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void initDefaultWorkRecord() throws IOException {
|
||||
LambdaQueryWrapper<WorkRecord> queryWrapper = new LambdaQueryWrapper<>();
|
||||
List<WorkRecord> list = workRecordMapper.selectList(queryWrapper);
|
||||
try {
|
||||
// 读取resource目录下的dsystemParam.json文件
|
||||
org.springframework.core.io.Resource resource = resourceLoader
|
||||
.getResource("classpath:workRecordTemplete.json");
|
||||
// 使用fastjson2转换为DeviceConfig对象
|
||||
String jsonContent;
|
||||
jsonContent = IoUtil.readUtf8(resource.getInputStream());
|
||||
List<WorkRecord> records = JSON.parseArray(jsonContent, WorkRecord.class);
|
||||
List<WorkRecord> saveList = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
saveList.addAll(records);
|
||||
} else {
|
||||
Map<String, List<WorkRecord>> map = list.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(workRecord -> workRecord.getRouteType() != null)
|
||||
.collect(Collectors.groupingBy(
|
||||
workRecord -> workRecord.getRouteType().toString()));
|
||||
if (!CollectionUtils.isEmpty(records)) {
|
||||
records.forEach(x -> {
|
||||
if (!map.containsKey(x.getRouteType())) {
|
||||
x.setUserId(1L);
|
||||
saveList.add(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
workRecordMapper.saveOrUpdateBatch(saveList);
|
||||
} catch (Exception e) {
|
||||
log.error("初始化系统参数失败", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user