潘志宝
9 天以前 44ba81f6aab41b5939c6a5e13c776971604467b8
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
@@ -1,6 +1,5 @@
package com.iailab.module.data.point.collection;
import com.alibaba.fastjson.JSONObject;
import com.iailab.module.data.common.enums.DataSourceType;
import com.iailab.module.data.common.utils.R;
import com.iailab.module.data.channel.kio.collector.KingIOCollector;
@@ -30,7 +29,6 @@
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -88,6 +86,7 @@
     */
    public void collect(Date collectTime, String minfreq) {
        try {
            log.info("collectTime=" + collectTime.getTime());
            Map<String, Object> dataMap = new HashMap<>();
            List<InfluxPointValuePOJO> pointValues = new ArrayList<>();
            // 记录点位状态
@@ -101,42 +100,16 @@
            List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(minfreq);
            pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap, listGood, listBad));
            List<String> listBadNew = new ArrayList<>();
            if (!CollectionUtils.isEmpty(listBad)) {
                log.info("BAD点值修复");
                List<InfluxPointValuePOJO> influxParams = new ArrayList<>();
                for (String bad : listBad) {
                    DaPointDTO daPointDTO = daPointService.getByNo(bad);
                    InfluxPointValuePOJO pojo = new InfluxPointValuePOJO();
                    pojo.setPoint(bad);
                    pojo.setType(daPointDTO.getDataType());
                    influxParams.add(pojo);
                }
                Map<String, Object> lastValue = influxDBService.queryPointsLastValue(influxParams);
                log.info("lastValue=" + JSONObject.toJSONString(lastValue));
                if (!CollectionUtils.isEmpty(lastValue)) {
                    for (String bad : listBad) {
                        if (lastValue.containsKey(bad)) {
                            listGood.add(bad);
                            dataMap.put(bad, lastValue.get(bad));
                        } else {
                            listBadNew.add(bad);
                        }
                    }
                } else {
                    listBadNew = listBad;
                }
            }
            log.info("读取计算点");
            List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq);
            pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap, listGood, listBadNew));
            pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap, listGood, listBad));
            log.info("读取累计点");
            List<DaPointDTO> pointCumulateList = daPointService.getCumulatePoint(minfreq);
            pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList, listGood, listBadNew));
            pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList, listGood, listBad));
            log.info("存入时序库");
            log.info("pointValueTimestamp=" + (pointValues.get(0) == null ? 0 : pointValues.get(0).getTimestamp().getNano()));
            influxDBService.asyncWritePointValues(pointValues);
            log.info("存入缓存");