This commit is contained in:
高云鹏 2024-11-04 10:28:17 +08:00
commit f24f10a5b3
13 changed files with 1595 additions and 1267 deletions

View File

@ -7,9 +7,29 @@ import lombok.Data;
*/ */
@Data @Data
public class DeviceInfoCache { public class DeviceInfoCache {
/**
* 设备ID
*/
private Long deviceId; private Long deviceId;
/**
* 设备Code
*/
private String deviceCode; private String deviceCode;
/**
* 设备名称
*/
private String deviceName; private String deviceName;
/**
* 设备类型
*/
private Integer objectType; private Integer objectType;
/**
* 父设备
*/
private Long parentDeviceId; private Long parentDeviceId;
/**
* 物模型ID
*/
private Long iotModelId;
} }

View File

@ -1,147 +1,13 @@
package com.das.modules.cache.service; package com.das.modules.cache.service;
import com.das.modules.cache.domain.DeviceInfoCache;
import com.das.modules.equipment.entity.SysEquipment;
import com.das.modules.equipment.mapper.SysEquipmentMapper;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* 计算缓存服务 * 应用缓存接口
* 用于缓存常用数据供计算服务使用 *
*/ */
@Service public interface CacheService {
public class CacheService {
@Autowired
SysEquipmentMapper sysEquipmentMapper;
/** /**
* 缓存初始化 * 获取设备缓存接口
*/
@PostConstruct
public void init() {
initDeviceInfoCaches();
}
/**
* 缓存释放
*/
@PreDestroy
public void destroy() {
freeDeviceInfoCaches();
}
///-设备缓存----------------------------------------------------------------
/**
* 设备缓存信息
*/
private final List<DeviceInfoCache> deviceInfoCaches = Collections.synchronizedList(new ArrayList<>());
/**
* 设备CODE索引用于通过设备CODE访问设备缓存信息
*/
private final ConcurrentHashMap<String, Integer> deviceCodeIndex = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Long, Integer> deviceIdIndex = new ConcurrentHashMap<>();
private DeviceInfoCache windFarmCache = null;
/**
* 初始化设备缓存信息
*/
private void initDeviceInfoCaches() {
List<SysEquipment> equipments = sysEquipmentMapper.selectList();
for (int i = 0; i < equipments.size(); i++) {
SysEquipment equipment = equipments.get(i);
DeviceInfoCache deviceInfoCache = new DeviceInfoCache();
deviceInfoCache.setDeviceId(equipment.getId());
deviceInfoCache.setDeviceCode(equipment.getCode());
deviceInfoCache.setDeviceName(equipment.getName());
deviceInfoCache.setObjectType(equipment.getObjectType());
deviceInfoCache.setParentDeviceId(equipment.getParentEquipmentId());
deviceInfoCaches.add(deviceInfoCache);
//创建Code索引
deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),i);
//创建Id索引
deviceIdIndex.put(equipment.getId(),i);
}
}
/**
* 释放设备缓存信息
*/
private void freeDeviceInfoCaches() {
deviceInfoCaches.clear();
deviceCodeIndex.clear();
}
/**
* 返回设备缓存信息列表
* @return * @return
*/ */
public List<DeviceInfoCache> getDevicesCache() { EquipmentCache getEquipmentCache();
return deviceInfoCaches;
}
/**
* 根据设备CODE返回设备缓存信息
* @param deviceCode
* @return
*/
public DeviceInfoCache getDeviceInfoCache(String deviceCode) {
Integer index = deviceCodeIndex.get(deviceCode);
if (index != null) {
return deviceInfoCaches.get(index);
}
return null;
}
/**
* 根据设备IRN返回设备缓存信息
* @param deviceId
* @return
*/
public DeviceInfoCache getDeviceInfoCache(Long deviceId) {
Integer index = deviceIdIndex.get(deviceId);
if (index != null) {
return deviceInfoCaches.get(index);
}
return null;
}
/**
* 刷新指定设备ID的设备缓存如果缓存不存在则添加
* @param deviceId
*/
public void refreshDeviceCache(Long deviceId) {
SysEquipment equipment = sysEquipmentMapper.selectById(deviceId);
if (equipment != null) {
DeviceInfoCache deviceInfoCache = new DeviceInfoCache();
deviceInfoCache.setDeviceId(equipment.getId());
deviceInfoCache.setDeviceCode(equipment.getCode());
deviceInfoCache.setDeviceName(equipment.getName());
deviceInfoCache.setObjectType(equipment.getObjectType());
deviceInfoCache.setParentDeviceId(equipment.getParentEquipmentId());
//如果是已经缓存过的设备直接缓存
Integer index = deviceIdIndex.get(deviceId);
if (index != null) {
deviceInfoCaches.set(index, deviceInfoCache);
}
else{
deviceInfoCaches.add(deviceInfoCache);
index = deviceInfoCaches.size();
deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),index);
deviceIdIndex.put(equipment.getId(),index);
}
}
}
///-设备缓存=END---------------------------------------------------------------
} }

View File

@ -0,0 +1,19 @@
package com.das.modules.cache.service;
import com.das.modules.cache.domain.DeviceInfoCache;
import java.util.List;
/**
* 设备缓存
*/
public interface EquipmentCache {
/**
* 获取设备缓存列表
* @return List<DeviceInfoCache>
*/
public List<DeviceInfoCache> getDevicesCache();
public void refreshDeviceCache(Long deviceId);
DeviceInfoCache getDeviceInfoCache(String deviceCode);
DeviceInfoCache getDeviceInfoCache(Long deviceId);
}

View File

@ -0,0 +1,18 @@
package com.das.modules.cache.service.impl;
import com.das.modules.cache.service.CacheService;
import com.das.modules.cache.service.EquipmentCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CacheServiceImpl implements CacheService {
@Autowired
EquipmentCache equipmentCache;;
@Override
public EquipmentCache getEquipmentCache() {
return equipmentCache;
}
}

View File

@ -0,0 +1,108 @@
package com.das.modules.cache.service.impl;
import com.das.modules.cache.domain.DeviceInfoCache;
import com.das.modules.cache.service.EquipmentCache;
import com.das.modules.equipment.entity.SysEquipment;
import com.das.modules.equipment.mapper.SysEquipmentMapper;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class EquipmentCacheImpl implements EquipmentCache {
@Autowired
SysEquipmentMapper sysEquipmentMapper;
private final List<DeviceInfoCache> deviceInfoCaches = Collections.synchronizedList(new ArrayList<>());
/**
* 设备CODE索引用于通过设备CODE访问设备缓存信息
*/
private final ConcurrentHashMap<String, Integer> deviceCodeIndex = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Long, Integer> deviceIdIndex = new ConcurrentHashMap<>();
/**
* 初始化设备缓存
*/
@PostConstruct
private void initDeviceInfoCaches() {
List<SysEquipment> equipments = sysEquipmentMapper.selectList();
for (int i = 0; i < equipments.size(); i++) {
SysEquipment equipment = equipments.get(i);
DeviceInfoCache deviceInfoCache = new DeviceInfoCache();
deviceInfoCache.setDeviceId(equipment.getId());
deviceInfoCache.setDeviceCode(equipment.getCode());
deviceInfoCache.setDeviceName(equipment.getName());
deviceInfoCache.setObjectType(equipment.getObjectType());
deviceInfoCache.setParentDeviceId(equipment.getParentEquipmentId());
deviceInfoCaches.add(deviceInfoCache);
//创建Code索引
deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),i);
//创建Id索引
deviceIdIndex.put(equipment.getId(),i);
}
}
/**
* 释放设备缓存信息
*/
private void freeDeviceInfoCaches() {
deviceInfoCaches.clear();
deviceCodeIndex.clear();
}
@Override
public List<DeviceInfoCache> getDevicesCache() {
return Collections.unmodifiableList(deviceInfoCaches);
}
@Override
public void refreshDeviceCache(Long deviceId) {
SysEquipment equipment = sysEquipmentMapper.selectById(deviceId);
if (equipment != null) {
DeviceInfoCache deviceInfoCache = new DeviceInfoCache();
deviceInfoCache.setDeviceId(equipment.getId());
deviceInfoCache.setDeviceCode(equipment.getCode());
deviceInfoCache.setDeviceName(equipment.getName());
deviceInfoCache.setObjectType(equipment.getObjectType());
deviceInfoCache.setParentDeviceId(equipment.getParentEquipmentId());
deviceInfoCache.setIotModelId(equipment.getIotModelId());
//如果是已经缓存过的设备直接缓存
Integer index = deviceIdIndex.get(deviceId);
if (index != null) {
deviceInfoCaches.set(index, deviceInfoCache);
}
else{
deviceInfoCaches.add(deviceInfoCache);
index = deviceInfoCaches.size();
deviceCodeIndex.put(deviceInfoCache.getDeviceCode(),index);
deviceIdIndex.put(equipment.getId(),index);
}
}
}
@Override
public DeviceInfoCache getDeviceInfoCache(String deviceCode) {
Integer index = deviceCodeIndex.get(deviceCode);
if (index != null) {
return deviceInfoCaches.get(index);
}
return null;
}
@Override
public DeviceInfoCache getDeviceInfoCache(Long deviceId) {
Integer index = deviceIdIndex.get(deviceId);
if (index != null) {
return deviceInfoCaches.get(index);
}
return null;
}
}

View File

@ -37,7 +37,7 @@ public class FunctionRealData extends AbstractFunction {
public AviatorObject call(Map<String, Object> env, AviatorObject deviceCode, AviatorObject attributes) { public AviatorObject call(Map<String, Object> env, AviatorObject deviceCode, AviatorObject attributes) {
//设备Code //设备Code
String code = (String)deviceCode.getValue(env); String code = (String)deviceCode.getValue(env);
DeviceInfoCache deviceInfoCache = cacheService.getDeviceInfoCache(code); DeviceInfoCache deviceInfoCache = cacheService.getEquipmentCache().getDeviceInfoCache(code);
//属性列表 //属性列表
List<String> list = (List<String>)attributes.getValue(env); List<String> list = (List<String>)attributes.getValue(env);
List<String> attrs = list.stream().map(String::toLowerCase).toList(); List<String> attrs = list.stream().map(String::toLowerCase).toList();

View File

@ -62,7 +62,7 @@ public class FunctionSaveCalcData extends AbstractVariadicFunction {
if ( (args.length - 1) % 3 != 0) { return AviatorRuntimeJavaType.valueOf(1);} if ( (args.length - 1) % 3 != 0) { return AviatorRuntimeJavaType.valueOf(1);}
//deviceCode //deviceCode
String code = (String)args[0].getValue(env); String code = (String)args[0].getValue(env);
DeviceInfoCache deviceInfoCache = cacheService.getDeviceInfoCache(code); DeviceInfoCache deviceInfoCache = cacheService.getEquipmentCache().getDeviceInfoCache(code);
List<CalculateRTData> dataList = new ArrayList<>(); List<CalculateRTData> dataList = new ArrayList<>();
for (int i = 1; i < args.length; i+=3) { for (int i = 1; i < args.length; i+=3) {
Date date = (Date)FunctionUtils.getJavaObject(args[i], env); Date date = (Date)FunctionUtils.getJavaObject(args[i], env);

View File

@ -1,5 +1,6 @@
package com.das.modules.calc.service; package com.das.modules.calc.service;
import com.das.modules.cache.service.CacheService; import com.das.modules.cache.service.CacheService;
import com.das.modules.calc.domain.entity.CalcModule; import com.das.modules.calc.domain.entity.CalcModule;
import com.googlecode.aviator.AviatorEvaluatorInstance; import com.googlecode.aviator.AviatorEvaluatorInstance;
@ -32,7 +33,7 @@ public class CalcJob implements Job {
if (expression == null) { if (expression == null) {
throw new JobExecutionException("expression is null"); throw new JobExecutionException("expression is null");
} }
Map<String,Object> envs = expression.newEnv("G_DEVICES", cacheService.getDevicesCache()); Map<String,Object> envs = expression.newEnv("G_DEVICES", cacheService.getEquipmentCache().getDevicesCache());
Object result = expression.execute(envs); Object result = expression.execute(envs);
sw.stop(); sw.stop();
log.debug("任务[{}]已执行,结果:{}, 耗时:{}秒", calcModule.getName(), result, sw.getTotalTimeMillis()/1000.0); log.debug("任务[{}]已执行,结果:{}, 耗时:{}秒", calcModule.getName(), result, sw.getTotalTimeMillis()/1000.0);

View File

@ -6,20 +6,15 @@ import com.das.modules.cache.domain.DeviceInfoCache;
import com.das.modules.cache.service.CacheService; import com.das.modules.cache.service.CacheService;
import com.das.modules.data.domain.DeviceEventInfo; import com.das.modules.data.domain.DeviceEventInfo;
import com.das.modules.data.service.impl.DataServiceImpl; import com.das.modules.data.service.impl.DataServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.das.common.constant.MeasType; import com.das.common.constant.MeasType;
import com.das.common.utils.AdminRedisTemplate; import com.das.common.utils.AdminRedisTemplate;
import com.das.modules.equipment.domain.vo.IotModelFieldVo;
import com.das.modules.equipment.entity.SysIotModelField;
import com.das.modules.equipment.mapper.SysIotModelMapper; import com.das.modules.equipment.mapper.SysIotModelMapper;
import com.das.modules.node.disruptor.MessageEventFactory; import com.das.modules.node.disruptor.MessageEventFactory;
import com.das.modules.node.disruptor.TerminalMessageEventHandler; import com.das.modules.node.disruptor.TerminalMessageEventHandler;
import com.das.modules.node.domain.bo.CalculateRTData;
import com.das.modules.node.domain.bo.RTData; import com.das.modules.node.domain.bo.RTData;
import com.das.modules.node.domain.bo.TerminalMessage; import com.das.modules.node.domain.bo.TerminalMessage;
import com.das.modules.node.domain.vo.*; import com.das.modules.node.domain.vo.*;
@ -28,8 +23,6 @@ import com.das.modules.node.mapper.SysCommunicationLinkMapper;
import com.das.modules.node.mapper.SysImpTabMappingMapper; import com.das.modules.node.mapper.SysImpTabMappingMapper;
import com.das.modules.node.service.NodeMessageService; import com.das.modules.node.service.NodeMessageService;
import com.das.modules.data.service.TDEngineService; import com.das.modules.data.service.TDEngineService;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.lmax.disruptor.RingBuffer; import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor; import com.lmax.disruptor.dsl.Disruptor;
@ -42,10 +35,8 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
@ -308,7 +299,7 @@ public class NodeMessageServiceImpl implements NodeMessageService {
}); });
log.info("消息data转化deviceVo,{}",list); log.info("消息data转化deviceVo,{}",list);
for (DeviceEventVo item : list){ for (DeviceEventVo item : list){
DeviceInfoCache deviceInfoCache = cacheService.getDeviceInfoCache(item.getDeviceId()); DeviceInfoCache deviceInfoCache = cacheService.getEquipmentCache().getDeviceInfoCache(Long.valueOf(item.getDeviceId()));
DeviceEventInfo deviceEventInfo = new DeviceEventInfo(); DeviceEventInfo deviceEventInfo = new DeviceEventInfo();
deviceEventInfo.setUpdateTime(item.getEventTime()); deviceEventInfo.setUpdateTime(item.getEventTime());
deviceEventInfo.setEventId(IdWorker.getId()); deviceEventInfo.setEventId(IdWorker.getId());
@ -316,7 +307,7 @@ public class NodeMessageServiceImpl implements NodeMessageService {
deviceEventInfo.setDeviceName(deviceInfoCache.getDeviceName()); deviceEventInfo.setDeviceName(deviceInfoCache.getDeviceName());
deviceEventInfo.setDeviceCode(deviceInfoCache.getDeviceCode()); deviceEventInfo.setDeviceCode(deviceInfoCache.getDeviceCode());
String eventType = getEventType(item.getEventType()); String eventType = getEventType(item.getEventType());
String model = dataService.iotModelMap.get(item.getDeviceId()); String model = dataService.deviceModelMap.get(item.getDeviceId());
if (StringUtils.isEmpty(model)){ if (StringUtils.isEmpty(model)){
log.debug("未查询到物模型code设备id{}",item.getDeviceId()); log.debug("未查询到物模型code设备id{}",item.getDeviceId());
} }

File diff suppressed because it is too large Load Diff

View File

@ -200,7 +200,7 @@ const getalarmsList = () => {
// }) // })
} }
const okSubmit = (val) => { const okSubmit = (val: any) => {
console.log(val) console.log(val)
getalarmsList() getalarmsList()
} }
@ -231,7 +231,7 @@ onMounted(() => {
objectType: 10002, objectType: 10002,
}).then((res) => { }).then((res) => {
if (res.code == 200) { if (res.code == 200) {
airBlowerList.value = res.data.map((item) => { airBlowerList.value = res.data.map((item: any) => {
return { return {
label: item.code, label: item.code,
value: item.id, value: item.id,

View File

@ -277,7 +277,7 @@ const linkMonitorTableData = ref<LinkMonitorTableType[]>([])
// //
const paginationOptions = reactive({ const paginationOptions = reactive({
current: 1, current: 1,
pageSize: 10, pageSize: 20,
total: 0, total: 0,
pageSizes: [20, 50, 100], pageSizes: [20, 50, 100],
}) })

View File

@ -232,7 +232,7 @@ const pageSetting = reactive({
current: 1, current: 1,
pageSize: 20, pageSize: 20,
total: 0, total: 0,
pageSizes: [10, 20, 30], pageSizes: [20, 50, 100],
}) })
const getcurrentPage = () => { const getcurrentPage = () => {