|
@@ -1,532 +0,0 @@
|
|
|
-package com.gyee.neic_service.cache;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
-import com.gyee.neic_service.config.FileManager;
|
|
|
-import com.gyee.neic_service.dao.alarm.IWarningDao;
|
|
|
-import com.gyee.neic_service.dao.entity.EquipmentModel;
|
|
|
-import com.gyee.neic_service.dao.entity.Line;
|
|
|
-import com.gyee.neic_service.dao.entity.Windturbine;
|
|
|
-import com.gyee.neic_service.dao.repsoitory.ILineDao;
|
|
|
-import com.gyee.neic_service.dao.repsoitory.IWindturbineDao;
|
|
|
-import com.gyee.neic_service.model.*;
|
|
|
-import com.gyee.neic_service.model.agc.AGCInfo;
|
|
|
-import com.gyee.neic_service.model.alarm.Warning;
|
|
|
-import com.gyee.neic_service.model.boost_station.BoostStation;
|
|
|
-import com.gyee.neic_service.model.boost_station.WindStation;
|
|
|
-import com.gyee.neic_service.model.enums.UniformCode;
|
|
|
-import com.gyee.neic_service.model.station.TagInfo;
|
|
|
-import com.gyee.neic_service.model.windturbine.JpaModelDao;
|
|
|
-import com.gyee.neic_service.model.windturbine.ModelInfo;
|
|
|
-import com.gyee.neic_service.tspoint.TsPoint;
|
|
|
-import com.gyee.neic_service.util.ConfigurationManager;
|
|
|
-import org.apache.logging.log4j.Level;
|
|
|
-import org.apache.logging.log4j.LogManager;
|
|
|
-import org.apache.logging.log4j.Logger;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.core.env.Environment;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.lang.reflect.Field;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * 基础信息缓存
|
|
|
- *
|
|
|
- * @author nnns
|
|
|
- */
|
|
|
-@Component
|
|
|
-public class InfoCache {
|
|
|
- private static final Logger logger = LogManager.getLogger();
|
|
|
- /**
|
|
|
- * 是否加载控制信息
|
|
|
- */
|
|
|
- @Value("${doControl:false}")
|
|
|
- private String isNeedControl;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private Environment environment;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private FileManager fileManager;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private IWindturbineDao windturbineDao;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private IWarningDao warningDao;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private ILineDao lineDao;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private JpaModelDao jpaModelDao;
|
|
|
-
|
|
|
- /**
|
|
|
- * 升压站信息,<期次名称,升压站信息>
|
|
|
- */
|
|
|
- private Map<String, BoostStation> boostStationMap;
|
|
|
- /**
|
|
|
- * 所有场站的信息
|
|
|
- */
|
|
|
- private Map<String, WindStation> windStationMap;
|
|
|
- /**
|
|
|
- * 所有风机信息
|
|
|
- */
|
|
|
- private Map<String, WindturbineInfo> windturbineInfoMap;
|
|
|
-
|
|
|
- /**
|
|
|
- * 所有测点集合
|
|
|
- */
|
|
|
- private final Map<String, TsPoint> tsPoints = new HashMap<>();
|
|
|
-
|
|
|
- /**
|
|
|
- * 场站状态
|
|
|
- */
|
|
|
- private Map<String, StationStatus> stationStatusMap = new LinkedHashMap<>();
|
|
|
- /**
|
|
|
- * 关注信息
|
|
|
- */
|
|
|
- private Map<String, AttentionInfo> attentionInfoMap;
|
|
|
-
|
|
|
- /**
|
|
|
- * UniformCode
|
|
|
- */
|
|
|
- private Map<String, Map<String, ModelInfo[]>> modelInfos;
|
|
|
-
|
|
|
- /**
|
|
|
- * AGC 信息
|
|
|
- */
|
|
|
- private AGCInfo[] agcInfos;
|
|
|
-
|
|
|
- /**
|
|
|
- * 升压站信息
|
|
|
- */
|
|
|
- private Map<String, BoostStationData> boostStationDatas;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * lock锁
|
|
|
- */
|
|
|
- private Object lockObject = new Object();
|
|
|
-
|
|
|
-
|
|
|
- public Map<String, BoostStation> getBoostStationMap() {
|
|
|
- if (boostStationMap == null) {
|
|
|
- boostStationMap = new HashMap<>(20);
|
|
|
- }
|
|
|
- return boostStationMap;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, WindStation> getWindStationMap() {
|
|
|
- if (windStationMap == null) {
|
|
|
- windStationMap = new HashMap<>(20);
|
|
|
- }
|
|
|
- return windStationMap;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, WindturbineInfo> getWindturbineInfoMap() {
|
|
|
- if (windturbineInfoMap == null) {
|
|
|
- windturbineInfoMap = new HashMap<>(500);
|
|
|
- }
|
|
|
- return windturbineInfoMap;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, AttentionInfo> getAttentionInfoMap() {
|
|
|
- if (attentionInfoMap == null) {
|
|
|
- attentionInfoMap = new HashMap<>(20);
|
|
|
- }
|
|
|
- return attentionInfoMap;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //key;风机型号,value:不可复位的报警id集合
|
|
|
- private Map<String, List<Integer>> unAbleResetWarningMap = new HashMap<>();
|
|
|
-
|
|
|
- public Map<String, List<Integer>> getUnAbleResetWarningMap() {
|
|
|
- return unAbleResetWarningMap;
|
|
|
- }
|
|
|
-
|
|
|
- public void setUnAbleResetWarningMap(Map<String, List<Integer>> unAbleResetWarningMap) {
|
|
|
- this.unAbleResetWarningMap = unAbleResetWarningMap;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, StationStatus> getStationStatusMap() {
|
|
|
- return stationStatusMap;
|
|
|
- }
|
|
|
-
|
|
|
- public AGCInfo[] getAgcInfos() {
|
|
|
- if (agcInfos == null) {
|
|
|
- agcInfos = new AGCInfo[0];
|
|
|
- }
|
|
|
- return agcInfos;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Map<String, ModelInfo[]>> getModelInfos() {
|
|
|
- if (modelInfos == null) {
|
|
|
- modelInfos = new HashMap<>();
|
|
|
- }
|
|
|
- return modelInfos;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, BoostStationData> getBoostStationDatas() {
|
|
|
- if (boostStationDatas == null) {
|
|
|
- boostStationDatas = new HashMap<>();
|
|
|
- }
|
|
|
- return boostStationDatas;
|
|
|
- }
|
|
|
-
|
|
|
- public Object getLockObject() {
|
|
|
- return lockObject;
|
|
|
- }
|
|
|
-
|
|
|
- public void init() {
|
|
|
- logger.log(Level.INFO, "开始初始化基本信息...");
|
|
|
- // 初始化升压站信息
|
|
|
- initBoostStationInfo();
|
|
|
- // 初始化线路信息
|
|
|
- initLineInfo();
|
|
|
- // 初始化场站信息
|
|
|
- initWindStations();
|
|
|
- // 初始化场站标签点信息
|
|
|
- initStationInfos();
|
|
|
- // 初始化风机标签点信息
|
|
|
- initWindtrubineInfos();
|
|
|
- // 创建不可复位报警集合
|
|
|
- initUnAbleResetMap();
|
|
|
- // 初始化场站状态
|
|
|
- initStationStatus();
|
|
|
-
|
|
|
- // 初始化AGC信息
|
|
|
- this.agcInfos = fileManager.getFromFile("agc_info.json", AGCInfo[].class);
|
|
|
-
|
|
|
- // 初始化UniformCode
|
|
|
- modelInfos = fileManager.getFromFile("windturbine_info.json", new TypeReference<Map<String, Map<String, ModelInfo[]>>>() {
|
|
|
- });
|
|
|
-
|
|
|
- // 初始化升压站视图信息
|
|
|
- initBoostStationView();
|
|
|
-
|
|
|
- logger.log(Level.INFO, "基本信息初始化结束");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化线路信息
|
|
|
- */
|
|
|
- private void initLineInfo() {
|
|
|
- try {
|
|
|
- List<Line> ls = lineDao.findAll();
|
|
|
- for (BoostStation bs : getBoostStationMap().values()) {
|
|
|
- bs.initLineInfo(ls);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("初始化风机线路信息出错!");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化场站状态
|
|
|
- */
|
|
|
- private void initStationStatus() {
|
|
|
- StationStatus[] ls = fileManager.getFromFile("staion_status.json", StationStatus[].class);
|
|
|
- for (StationStatus ss : ls) {
|
|
|
- if (!stationStatusMap.containsKey(ss.getStationId())) {
|
|
|
- stationStatusMap.put(ss.getStationId(), ss);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化场站和升压站信息
|
|
|
- */
|
|
|
- private void initBoostStationInfo() {
|
|
|
- // 场站信息
|
|
|
- windStationMap = new HashMap<>(20);
|
|
|
- BoostStation[] infos = fileManager.getFromFile("boost_station.json", BoostStation[].class);
|
|
|
- boostStationMap = Arrays.stream(infos).collect(Collectors.toMap(BoostStation::getId, b -> b));
|
|
|
- for (BoostStation bs : infos) {
|
|
|
- if (!windStationMap.containsKey(bs.getStationId())) {
|
|
|
- WindStation ws = new WindStation(bs);
|
|
|
- windStationMap.put(ws.getId(), ws);
|
|
|
- ws.addBoostStation(bs);
|
|
|
- } else {
|
|
|
- windStationMap.get(bs.getStationId()).addBoostStation(bs);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化场站信息和风机信息
|
|
|
- */
|
|
|
- private void initWindStations() {
|
|
|
- // 风机信息
|
|
|
- Map<String, WindturbineInfo> wbm = getWindturbineInfoMap();
|
|
|
-
|
|
|
- List<EquipmentModel> models = jpaModelDao.findAll();
|
|
|
- Map<String, EquipmentModel> modelMap = models.stream().collect(Collectors.toMap(EquipmentModel::getId, e -> e));
|
|
|
-
|
|
|
- try {
|
|
|
- List<Windturbine> ws = windturbineDao.find();
|
|
|
- for (Windturbine wb : ws) {
|
|
|
- if (!wb.getWindPowerStationId().contains("FDC") || !windStationMap.containsKey(wb.getWindPowerStationId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- WindturbineInfo wi = new WindturbineInfo();
|
|
|
- wi.setId(wb.getId());
|
|
|
- wi.setCode(wb.getCode());
|
|
|
- wi.setModelId(wb.getModelId());
|
|
|
- wi.setProjectId(wb.getProjectId());
|
|
|
- wi.setLineId(wb.getLineId());
|
|
|
- wi.setStationId(wb.getWindPowerStationId());
|
|
|
- if (modelMap.containsKey(wi.getModelId())) {
|
|
|
- wi.setPowerProduction(modelMap.get(wi.getModelId()).getPowerProduction());
|
|
|
- }
|
|
|
-
|
|
|
- if (!wbm.containsKey(wi.getId())) {
|
|
|
- wbm.put(wi.getId(), wi);
|
|
|
- }
|
|
|
- if (windStationMap.containsKey(wi.getStationId())) {
|
|
|
- final WindStation windStation = windStationMap.get(wi.getStationId());
|
|
|
- wi.setStationName(windStation.getName());
|
|
|
- windStation.addWindturbine(wi);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化场站标签点信息
|
|
|
- */
|
|
|
- private void initStationInfos() {
|
|
|
- /*String[] ucs = getUniformCodes(WindStation.class);
|
|
|
- // 获取所有的标签点
|
|
|
- List<TsPoint> pls = thingsPointDao.findTsPointByThingTypeAndUniformCodes("station", ucs);
|
|
|
- // 获取场站中的属性
|
|
|
- Map<String, Field> fieldsMap = getFields(WindStation.class);
|
|
|
- for (TsPoint tp : pls) {
|
|
|
- if (!windStationMap.containsKey(tp.getThingId())
|
|
|
- || !fieldsMap.containsKey(tp.getUniformCode())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- WindStation ws = windStationMap.get(tp.getThingId());
|
|
|
- Field field = fieldsMap.get(tp.getUniformCode());
|
|
|
- setTagInfo(ws, field, tp.getId());
|
|
|
- }*/
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化风机信息
|
|
|
- */
|
|
|
- private void initWindtrubineInfos() {
|
|
|
- /*// 获取需要刷新的UniformCode
|
|
|
- String[] ucs = getUniformCodes(WindturbineInfo.class);
|
|
|
- // 获取所有的标签点
|
|
|
- List<TsPoint> pls = thingsPointDao.findTsPointByThingTypeAndUniformCodes("windturbine", ucs);
|
|
|
- // 获取风机中的属性
|
|
|
- Map<String, Field> fieldsMap = getFields(WindturbineInfo.class);
|
|
|
- // 风机信息
|
|
|
- Map<String, WindturbineInfo> wbm = getWindturbineInfoMap();
|
|
|
- for (TsPoint tp : pls) {
|
|
|
- if (!wbm.containsKey(tp.getThingId()) || !fieldsMap.containsKey(tp.getUniformCode())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- WindturbineInfo wi = wbm.get(tp.getThingId());
|
|
|
- Field field = fieldsMap.get(tp.getUniformCode());
|
|
|
- // 初始化TagInfo并添加
|
|
|
- setTagInfo(wi, field, tp.getId());
|
|
|
- }*/
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化TagInfo并添加
|
|
|
- *
|
|
|
- * @param o 要添加的实体
|
|
|
- * @param field 要添加的属性
|
|
|
- * @param tag 标签点
|
|
|
- */
|
|
|
- private void setTagInfo(Object o, Field field, String tag) {
|
|
|
- TagInfo ti = new TagInfo();
|
|
|
- ti.setTag(tag);
|
|
|
- try {
|
|
|
- field.set(o, ti);
|
|
|
- } catch (IllegalAccessException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化PointInfo并添加
|
|
|
- *
|
|
|
- * @param o 要添加的实体
|
|
|
- * @param field 要添加的属性
|
|
|
- * @param tag 标签点
|
|
|
- * @param v 倍率
|
|
|
- */
|
|
|
- private void setPointInfo(Object o, Field field, String tag, double v) {
|
|
|
- PointInfo pi = new PointInfo();
|
|
|
- pi.setTag(tag);
|
|
|
- pi.setMultiplier(v);
|
|
|
- try {
|
|
|
- field.set(o, pi);
|
|
|
- } catch (IllegalAccessException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取风机信息中的UniformCode
|
|
|
- */
|
|
|
- private String[] getUniformCodes(Class c) {
|
|
|
- List<String> ls = new ArrayList<>();
|
|
|
- Field[] fs = c.getDeclaredFields();
|
|
|
- for (Field f : fs) {
|
|
|
- try {
|
|
|
- String ucv = ConfigurationManager.getAnnotationValue(UniformCode.class, f, environment);
|
|
|
-
|
|
|
- if (ucv == null || "".equals(ucv)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- ls.add(ucv);
|
|
|
- } catch (NoSuchFieldException | IllegalAccessException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- String[] ucs = new String[ls.size()];
|
|
|
- ls.toArray(ucs);
|
|
|
- return ucs;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取风机信息中的属性
|
|
|
- */
|
|
|
- private Map<String, Field> getFields(Class c) {
|
|
|
- Map<String, Field> fields = new HashMap<>(50);
|
|
|
- Field[] fs = c.getDeclaredFields();
|
|
|
- for (Field f : fs) {
|
|
|
- try {
|
|
|
- String ucv = ConfigurationManager.getAnnotationValue(UniformCode.class, f, environment);
|
|
|
- if (ucv == null || "".equals(ucv)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!fields.containsKey(ucv)) {
|
|
|
- f.setAccessible(true);
|
|
|
- fields.put(ucv, f);
|
|
|
- }
|
|
|
- } catch (NoSuchFieldException | IllegalAccessException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return fields;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据tingId和uniformCode获取TsPoint
|
|
|
- */
|
|
|
- public TsPoint getTsPointByIdAndUniformCode(String tingtype, String id, String uniformCode) {
|
|
|
- /*String key = id + uniformCode;
|
|
|
- if (tsPoints.containsKey((key))) {
|
|
|
- return tsPoints.get(key);
|
|
|
- }
|
|
|
- // "windturbine"
|
|
|
- List<TsPoint> tss = thingsPointDao.findTsPointByUnformCodes(tingtype, id, uniformCode);
|
|
|
- if (tss != null && tss.size() > 0) {
|
|
|
- tsPoints.put(key, tss.get(0));
|
|
|
- return tss.get(0);
|
|
|
- }*/
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 创建不可复位报警集合
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- private boolean initUnAbleResetMap() {
|
|
|
- boolean result = false;
|
|
|
- try {
|
|
|
- List<Warning> warningList = warningDao.findByIsReset(1);
|
|
|
- warningList.forEach(s ->
|
|
|
- {
|
|
|
- if (unAbleResetWarningMap.containsKey(s.getModelId())) {
|
|
|
- List<Integer> lst = unAbleResetWarningMap.get(s.getModelId());
|
|
|
- if (!lst.contains(s.getEdnaValue())) {
|
|
|
- lst.add(s.getEdnaValue());
|
|
|
- }
|
|
|
- } else {
|
|
|
- List<Integer> lst = new ArrayList<>();
|
|
|
- unAbleResetWarningMap.put(s.getModelId(), lst);
|
|
|
- }
|
|
|
- });
|
|
|
- result = true;
|
|
|
- logger.info("不可复位信息初始化完成");
|
|
|
- } catch (Exception ex) {
|
|
|
- logger.info("不可复位信息初始化失败:" + ex.getMessage());
|
|
|
- } finally {
|
|
|
- return result;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新场站状态
|
|
|
- */
|
|
|
- public String updateStationStatus(String stationId, boolean type, String name) {
|
|
|
- if (stationId.equals("")) {
|
|
|
- return "场站ID不能为空";
|
|
|
- }
|
|
|
- if (stationStatusMap.containsKey(stationId)) {
|
|
|
- stationStatusMap.get(stationId).setType(type);
|
|
|
- } else {
|
|
|
- StationStatus ss = new StationStatus();
|
|
|
- ss.setType(type);
|
|
|
- ss.setStationId(stationId);
|
|
|
- ss.setName(name);
|
|
|
- stationStatusMap.put(stationId, ss);
|
|
|
- }
|
|
|
- // 保存操作记录
|
|
|
- fileManager.saveObjectToFile("staion_status.json", stationStatusMap.values());
|
|
|
- return "success";
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化升压站视图信息
|
|
|
- */
|
|
|
- private void initBoostStationView() {
|
|
|
- System.out.println("初始化升压站视图信息...");
|
|
|
- boostStationDatas = new HashMap<>();
|
|
|
- BoostStationData[] ls = fileManager.getFromFile("boost_station_info.json", BoostStationData[].class);
|
|
|
- for (BoostStationData bsd : ls) {
|
|
|
- if (!boostStationDatas.containsKey(bsd.getId())) {
|
|
|
- boostStationDatas.put(bsd.getId(), bsd);
|
|
|
- }
|
|
|
- }
|
|
|
- System.out.println("升压站视图信息初始化结束");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新升压站信息
|
|
|
- *
|
|
|
- * @param data
|
|
|
- */
|
|
|
- public boolean updateBoostStationInfo(BoostStationData data) {
|
|
|
- Map<String, BoostStationData> datas = this.getBoostStationDatas();
|
|
|
- if (datas.containsKey(data.getId())) {
|
|
|
- // 保存旧升压站信息
|
|
|
- boolean b = fileManager.saveObjectToFile("boost_station_info.json" + System.currentTimeMillis(), boostStationDatas.values());
|
|
|
- if (!b) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- datas.remove(data.getId());
|
|
|
- }
|
|
|
- datas.put(data.getId(), data);
|
|
|
- return fileManager.saveObjectToFile("boost_station_info.json", boostStationDatas.values());
|
|
|
- }
|
|
|
-
|
|
|
-}
|