feat: 增加点表缓存,定时更新和启动104服务端

iec104
huangfeng 15 hours ago
parent f1aed43e7c
commit e5f35cffd8

@ -2,21 +2,29 @@ package com.xydl.cac.iec104;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.service.Iec104PointService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
@Service
@Slf4j
public class Iec104ServerService {
@Resource
Iec104PointService iec104PointService;
@PostConstruct
private void init() {
try {
// this.startServer(2404);
iec104PointService.findAll();
if (!CollectionUtils.isEmpty(StaticVariable.point104_Cache)) {
this.startServer(2404);
}
} catch (Exception ignore) {
}
}

@ -32,6 +32,7 @@ public class StaticVariable {
public static List<Zsb> zsb_Cache = null;
public static ConcurrentHashMap<Integer, WarnRule> rule_Cache = new ConcurrentHashMap<>();
public static HashMap<String, Integer> ruleRelationMap = new HashMap<>();
public static List<Iec104Point> point104_Cache = null;
// 更新服务端

@ -2,6 +2,7 @@ package com.xydl.cac.service.impl;
import com.xydl.cac.entity.Iec104Point;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.repository.Iec104PointRepository;
import com.xydl.cac.service.Iec104PointService;
import lombok.extern.slf4j.Slf4j;
@ -23,7 +24,8 @@ public class Iec104PointServiceImpl implements Iec104PointService {
@Override
public List<Iec104Point> findAll() {
return iec104PointRepository.findAll();
StaticVariable.point104_Cache = iec104PointRepository.findAll();
return StaticVariable.point104_Cache;
}
@Override

@ -1,7 +1,9 @@
package com.xydl.cac.task;
import com.xydl.cac.entity.Iec104Point;
import com.xydl.cac.entity.WarnRule;
import com.xydl.cac.model.StaticVariable;
import com.xydl.cac.service.Iec104PointService;
import com.xydl.cac.service.WarnRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
@ -16,9 +18,11 @@ public class CacheTask {
@Resource
WarnRuleService ruleService;
@Resource
Iec104PointService iec104PointService;
@Scheduled(cron = "0 0 1 * * ?")
private void clearCache1() {
public void clearCache1() {
StaticVariable.unit_Cache.clear();
StaticVariable.modevType_Cache = null;
StaticVariable.jg_Cache = null;
@ -29,12 +33,12 @@ public class CacheTask {
}
@Scheduled(cron = "0 30 9 * * ?")
private void clearCache9() {
public void clearCache9() {
StaticVariable.doneWarnMap.clear();
}
@Scheduled(initialDelay = 30 * 1000, fixedDelay = 60 * 1000)
private void refreshRule() {
public void refreshRule() {
try {
List<WarnRule> list = ruleService.listAll(null);
for (WarnRule item : list) {
@ -52,4 +56,9 @@ public class CacheTask {
log.error("CacheTask.refreshRule error.", e);
}
}
@Scheduled(initialDelay = 5 * 60 * 1000, fixedDelay = 5 * 60 * 1000)
public void refresh104() {
iec104PointService.findAll();
}
}

Loading…
Cancel
Save