| | |
| | | package com.iailab.module.data.point.collection.handler; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.iailab.framework.common.util.string.StrUtils; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import com.iailab.module.data.common.enums.DataTypeEnum; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * 计算点处理 |
| | |
| | | if (CollectionUtils.isEmpty(dtos)) { |
| | | return result; |
| | | } |
| | | log.info(JSON.toJSONString(listBad)); |
| | | dtos.forEach(dto -> { |
| | | try { |
| | | Object value = singleCompute(dto, dataMap, listGood, listBad); |
| | |
| | | |
| | | private Object singleCompute(DaPointDTO dto, Map<String, Object> dataMap,List<String> listGood,List<String> listBad) { |
| | | String expression = dto.getExpression(); |
| | | log.info("PointNo=" + dto.getPointNo() + ";SourceExpression=" + expression); |
| | | String[] arr = expression.split(regex); |
| | | // 去掉arr中的空格 |
| | | arr = Stream.of(arr).filter(StringUtils::isNotBlank).toArray(String[]::new); |
| | | // 判断arr都在dataMap中包含 |
| | | if (!Arrays.stream(arr).allMatch(dataMap::containsKey)) { |
| | | log.info("dataMap not contains key"); |
| | | listBad.add(dto.getPointNo()); |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | |
| | | pointNos.add(s); |
| | | dataMap.putAll(measureHandle.getCurrent(pointNos)); |
| | | dataMap.putAll(constantHandle.getCurrent(pointNos)); |
| | | if (dataMap.get(s) == null) { |
| | | log.info("计算点数据异常"); |
| | | log.info("pointNo=" + dto.getPointNo() +";dataMap.key=" + s); |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | | String valueStr = dataMap.get(s).toString(); |
| | | if (StrUtils.isNumeric(valueStr) && new BigDecimal(valueStr).compareTo(CommonConstant.BAD_VALUE) == 0) { |
| | | log.info("BAD_VALUE:" + s); |