From 95d5934a9686ab97d8bbb9abe958cfc849100bd6 Mon Sep 17 00:00:00 2001 From: zhanghan11 Date: Thu, 11 Apr 2024 10:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasyn/modbus/IPCPlcDataSyncThread.java | 2 +- .../service/IIpcAlarmRulesConfigService.java | 12 +++++-- .../impl/IpcAlarmRulesConfigServiceImpl.java | 3 +- .../ipc/utils/IpcRedisCacheConfiguration.java | 35 +++++++++++++++++++ .../java/com/inspur/ipc/utils/RuleUtils.java | 4 +-- 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java diff --git a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java index 7e9077e..381a4af 100644 --- a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java +++ b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCPlcDataSyncThread.java @@ -120,7 +120,7 @@ public class IPCPlcDataSyncThread implements Runnable { String format = simpleDateFormat.format(new Date()); fields.put("insertTime", format); // 根据运行状态获取规则 - List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigList(tags.get("part")); + List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigListByCache(tags.get("part")); if (IpcConstant.RUNNING_STATUS_RUNNING.equals(status)) { rulesConfigList = rulesConfigList.stream().filter(ipcAlarmRulesConfig -> ipcAlarmRulesConfig.getType().equals(IpcConstant.RULE_TYPE_IN_RUNNING)).collect(Collectors.toList()); } else { diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcAlarmRulesConfigService.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcAlarmRulesConfigService.java index 20385e4..9268cbf 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcAlarmRulesConfigService.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/IIpcAlarmRulesConfigService.java @@ -1,6 +1,7 @@ package com.inspur.ipc.service; import java.util.List; + import com.inspur.ipc.domain.IpcAlarmRulesConfig; /** @@ -9,8 +10,7 @@ import com.inspur.ipc.domain.IpcAlarmRulesConfig; * @author inspur * @date 2024-03-30 */ -public interface IIpcAlarmRulesConfigService -{ +public interface IIpcAlarmRulesConfigService { /** * 查询告警规则配置 * @@ -58,11 +58,17 @@ public interface IIpcAlarmRulesConfigService * @return 结果 */ public int deleteIpcAlarmRulesConfigById(Long id); + + /** + * 更新 redis 缓存 + */ + void updateRedisCache(); + /** * 获取告警规则缓存 * * @param part 监测部位 * @return 告警规则配置集合 */ - public List selectIpcAlarmRulesConfigList(String part); + public List selectIpcAlarmRulesConfigListByCache(String part); } diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcAlarmRulesConfigServiceImpl.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcAlarmRulesConfigServiceImpl.java index 29541c5..c60bddf 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcAlarmRulesConfigServiceImpl.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/service/impl/IpcAlarmRulesConfigServiceImpl.java @@ -100,6 +100,7 @@ public class IpcAlarmRulesConfigServiceImpl implements IIpcAlarmRulesConfigServi /** * 更新 redis 缓存 */ + @Override public void updateRedisCache() { // 获取监测部位 List partList = iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.MONITOR_PART_KEY); @@ -117,7 +118,7 @@ public class IpcAlarmRulesConfigServiceImpl implements IIpcAlarmRulesConfigServi * @return 告警规则配置集合 */ @Override - public List selectIpcAlarmRulesConfigList(String part) { + public List selectIpcAlarmRulesConfigListByCache(String part) { List list = redisCache.getCacheObject(CacheConstants.IPC_PREFIX+CacheConstants.RULE_CONFIG + part); if (list == null || list.isEmpty()) { this.updateRedisCache(); diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java new file mode 100644 index 0000000..39c0dea --- /dev/null +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/IpcRedisCacheConfiguration.java @@ -0,0 +1,35 @@ +package com.inspur.ipc.utils; + +import com.inspur.common.constant.CacheConstants; +import com.inspur.common.utils.spring.SpringUtils; +import com.inspur.ipc.service.IIpcAlarmRecordService; +import com.inspur.ipc.service.IIpcAlarmRulesConfigService; +import com.inspur.ipc.service.IIpcMonitorFieldService; +import com.inspur.ipc.service.IIpcRunningStatusRecordService; +import com.inspur.system.service.influx.InfluxDBService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; + +@Configuration +public class IpcRedisCacheConfiguration { + @Autowired + IIpcMonitorFieldService iIpcMonitorFieldService; + @Autowired + IIpcAlarmRulesConfigService iIpcAlarmRulesConfigService; + @Autowired + IIpcRunningStatusRecordService iIpcRunningStatusRecordService; + + /** + * 预加载缓存 + */ + @PostConstruct + public void preloadedRedisCache(){ + iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.MONITOR_PART_KEY); + iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.SENSOR_MONITOR_PARAMS_KEY); + iIpcMonitorFieldService.selectFieldDataByType(CacheConstants.PLC_MONITOR_PARAMS_KEY); + iIpcAlarmRulesConfigService.updateRedisCache(); + iIpcRunningStatusRecordService.selectLatestStatus(); + } +} diff --git a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/RuleUtils.java b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/RuleUtils.java index c9bab20..f2234f7 100644 --- a/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/RuleUtils.java +++ b/tzipc-server/tzipc-system/src/main/java/com/inspur/ipc/utils/RuleUtils.java @@ -51,7 +51,7 @@ public class RuleUtils { public List plcDataDeal(Map map, String tag, String type, List paramList) { List returnList = new ArrayList<>(); // 获取判断规则 - List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigList(tag); + List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigListByCache(tag); try { // 创建ScriptEngineManager和ScriptEngine实例 ScriptEngineManager manager = new ScriptEngineManager(); @@ -95,7 +95,7 @@ public class RuleUtils { public List sensorDataDeal(Map map, String tag, String type, List paramList) { List returnList = new ArrayList<>(); // 获取判断规则 - List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigList(tag); + List rulesConfigList = iIpcAlarmRulesConfigService.selectIpcAlarmRulesConfigListByCache(tag); try { // 创建ScriptEngineManager和ScriptEngine实例 ScriptEngineManager manager = new ScriptEngineManager();