潘志宝
2025-06-03 5bffdf35c5ef601ae970faf3f5ac50bbe6b50974
计算点递归查询
已修改1个文件
22 ■■■■ 文件已修改
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java
@@ -16,6 +16,7 @@
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import javax.validation.constraints.Max;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
@@ -64,6 +65,8 @@
    private final static String POINT_PREFIX = "M";
    private final static String PENDING_FLAG = "pending";
    private final static int MAX_RECURSION = 10;
    public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap, List<String> listGood, List<String> listBad) {
        List<InfluxPointValuePOJO> result = new ArrayList<>();
@@ -124,7 +127,7 @@
        }
        log.info("处理包含计算点的");
        log.info("handPending count=" + count);
        if (count > 10) {
        if (count > MAX_RECURSION) {
            log.info("最多递归10次");
            return;
        }
@@ -214,7 +217,7 @@
            if (redisTemplate.hasKey(PointCollector.PV + item.getPointNo())) {
                value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo());
            } else {
                Object rawValue = singleCompute(item);
                Object rawValue = singleCompute(item, 1);
                BigDecimal coefficient = item.getUnittransfactor() == null ? BigDecimal.ONE : item.getUnittransfactor();
                value = new BigDecimal(rawValue.toString()).multiply(coefficient);
            }
@@ -223,7 +226,7 @@
        return data;
    }
    private Object singleCompute(DaPointDTO dto) {
    private Object singleCompute(DaPointDTO dto, int count) {
        String result = CommonConstant.BAD_VALUE.toString();
        Map<String, Object> dataMap = new HashMap<>();
        String expression = dto.getExpression();
@@ -239,6 +242,19 @@
            dataMap.putAll(constantHandle.getCurrent(pointNos));
            dataMap.putAll(cumulateHandle.getCurrent(pointNos));
            dataMap.putAll(extremalHandle.getCurrent(pointNos));
            if (s.contains(POINT_PREFIX)) {
                log.info("计算点递归查询");
                List<DaPointDTO> pointMathList = daPointService.getMathPoint(pointNos);
                if (CollectionUtils.isEmpty(pointMathList)) {
                    return result;
                }
                log.info("count = " + count);
                if (count > MAX_RECURSION) {
                    return result;
                }
                this.singleCompute(pointMathList.get(0), count);
                count = count + 1;
            }
            if (dataMap.get(s) == null) {
                log.info("计算点数据异常");
                log.info("pointNo=" + dto.getPointNo() + ";dataMap.key=" + s);