| | |
| | | package com.iailab.module.data.point.collection.handler; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.framework.common.util.string.StrUtils; |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import com.iailab.module.data.common.enums.DataTypeEnum; |
| | |
| | | |
| | | public final static String regex = "[+\\-\\*/()\\&\\|\\>\\<]"; |
| | | |
| | | private final static String POINT_PREFIX = "M"; |
| | | private final static String POINT_PREFIX = "C"; |
| | | |
| | | private final static String PENDING_FLAG = "pending"; |
| | | |
| | |
| | | // 去掉arr中的空格 |
| | | arr = Stream.of(arr).filter(StringUtils::isNotBlank).toArray(String[]::new); |
| | | // 判断arr都在dataMap中包含 |
| | | if (!Arrays.stream(arr).allMatch(dataMap::containsKey)) { |
| | | /*if (!Arrays.stream(arr).allMatch(dataMap::containsKey)) { |
| | | log.info("dataMap not contains key"); |
| | | listBad.add(dto.getPointNo()); |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | | }*/ |
| | | |
| | | for (int i = 0; i < arr.length; i++) { |
| | | String s = arr[i]; |
| | | if (StringUtils.isNotBlank(s) && dataMap.containsKey(s)) { |
| | | // 对每个数加(),否则负值报错 |
| | | expression = expression.replace(s, "(" + dataMap.get(s).toString() + ")"); |
| | | } else if(StringUtils.isNotBlank(s) && s.trim().startsWith(POINT_PREFIX)) { |
| | | log.info("包含计算点,先挂起"); |
| | | log.info("dataMap=" + JSONObject.toJSONString(dataMap)); |
| | | return PENDING_FLAG; |
| | | } else if(StringUtils.isNotBlank(s) && !dataMap.containsKey(s)) { |
| | | log.info("dataMap not contains key " + s); |
| | | listBad.add(dto.getPointNo()); |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | | } |
| | | expression = expression.replace("&", "&&"); |
| | |
| | | expression = expression.replace("False", "false"); |
| | | expression = expression.replace("True", "true"); |
| | | log.info("PointNo=" + dto.getPointNo() + ";expression=" + expression); |
| | | if(expression.contains(POINT_PREFIX)) { |
| | | // 包含计算点,先挂起 |
| | | return PENDING_FLAG; |
| | | } |
| | | |
| | | String result = javaScriptHandler.eval(expression); |
| | | log.info("result=" + result); |
| | |
| | | dataMap.putAll(constantHandle.getCurrent(pointNos)); |
| | | dataMap.putAll(cumulateHandle.getCurrent(pointNos)); |
| | | dataMap.putAll(extremalHandle.getCurrent(pointNos)); |
| | | if (s.contains(POINT_PREFIX)) { |
| | | if (s.trim().startsWith(POINT_PREFIX)) { |
| | | log.info("计算点递归查询"); |
| | | List<DaPointDTO> pointMathList = daPointService.getMathPoint(pointNos); |
| | | if (CollectionUtils.isEmpty(pointMathList)) { |
| | |
| | | if (count > MAX_RECURSION) { |
| | | return result; |
| | | } |
| | | this.singleCompute(pointMathList.get(0), count); |
| | | Object v = this.singleCompute(pointMathList.get(0), count); |
| | | dataMap.put(s, v); |
| | | count = count + 1; |
| | | } |
| | | if (dataMap.get(s) == null) { |