| | |
| | | try { |
| | | Map<String, Object> dataMap = new HashMap<>(); |
| | | List<InfluxPointValuePOJO> pointValues = new ArrayList<>(); |
| | | |
| | | // 记录点位状态 |
| | | List<String> listGood = new ArrayList<>(); |
| | | List<String> listBad = new ArrayList<>(); |
| | | log.info("读取常量点"); |
| | | List<DaPointDTO> pointConstantList = daPointService.getConstantPoint(minfreq); |
| | | pointValues.addAll(constantHandle.handle(collectTime, pointConstantList, dataMap)); |
| | | pointValues.addAll(constantHandle.handle(collectTime, pointConstantList, dataMap,listGood,listBad)); |
| | | |
| | | log.info("读取测量点"); |
| | | List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(minfreq); |
| | | pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap)); |
| | | pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap,listGood,listBad)); |
| | | |
| | | log.info("读取计算点"); |
| | | List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq); |
| | | pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap)); |
| | | pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap,listGood,listBad)); |
| | | |
| | | log.info("读取累计点"); |
| | | List<DaPointDTO> pointCumulateList = daPointService.getCumulatePoint(minfreq); |
| | | pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList)); |
| | | pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList,listGood,listBad)); |
| | | |
| | | log.info("存入时序库"); |
| | | influxDBService.asyncWritePointValues(pointValues); |
| | |
| | | } |
| | | } |
| | | log.info("更新采集状态"); |
| | | daPointCollectStatusService.recordStatusList(pointValues, collectTime); |
| | | daPointCollectStatusService.recordStatusList(listGood,listBad, collectTime); |
| | | log.info("采集完成"); |
| | | } catch (Exception ex) { |
| | | log.info("采集异常!"); |
| | |
| | | |
| | | public static final String regex = "[+\\-\\*/()\\&\\|\\>\\<]"; |
| | | |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap) { |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap,List<String> listGood,List<String> listBad) { |
| | | List<InfluxPointValuePOJO> result = new ArrayList<>(); |
| | | try { |
| | | log.info("计算点处理开始"); |
| | |
| | | } |
| | | dtos.forEach(dto -> { |
| | | try { |
| | | Object value = singleCompute(dto, dataMap); |
| | | Object value = singleCompute(dto, dataMap, listGood, listBad); |
| | | InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value); |
| | | pojo.setTimestamp(collectTime.toInstant()); |
| | | result.add(pojo); |
| | |
| | | return result; |
| | | } |
| | | |
| | | private Object singleCompute(DaPointDTO dto, Map<String, Object> dataMap) { |
| | | private Object singleCompute(DaPointDTO dto, Map<String, Object> dataMap,List<String> listGood,List<String> listBad) { |
| | | String expression = dto.getExpression(); |
| | | String[] arr = expression.split(regex); |
| | | // 判断arr都在dataMap中包含 |
| | | if (!Arrays.stream(arr).allMatch(dataMap::containsKey)) { |
| | | 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()); |
| | | // 对每个数加(),否则负值报错 |
| | | expression = expression.replace(s, "(" + dataMap.get(s).toString() + ")"); |
| | | } |
| | | } |
| | | expression = expression.replace("&", "&&"); |
| | |
| | | log.info("PointNo=" + dto.getPointNo() + ";expression=" + expression); |
| | | String result = javaScriptHandler.eval(expression); |
| | | log.info("result=" + result); |
| | | if (result == null) { |
| | | if (result == null || result.contains(JsErrorCode.Infinity.name()) || result.contains(JsErrorCode.NaN.name())) { |
| | | listBad.add(dto.getPointNo()); |
| | | return CommonConstant.BAD_VALUE; |
| | | } else if (result.contains(JsErrorCode.Infinity.name()) || |
| | | result.contains(JsErrorCode.NaN.name())) { |
| | | log.info("计算异常,使用默认值"); |
| | | return dto.getDefaultValue() == null ? BigDecimal.ZERO : dto.getDefaultValue(); |
| | | } else { |
| | | if (DataTypeEnum.INT.getCode().equals(dto.getDataType())) { |
| | | listGood.add(dto.getPointNo()); |
| | | return new BigDecimal(result).intValue(); |
| | | } else if (DataTypeEnum.FLOAT.getCode().equals(dto.getDataType())) { |
| | | listGood.add(dto.getPointNo()); |
| | | return new BigDecimal(result).setScale(4, BigDecimal.ROUND_UP).doubleValue(); |
| | | } else if (DataTypeEnum.BOOLEAN.getCode().equals(dto.getDataType())) { |
| | | listGood.add(dto.getPointNo()); |
| | | return Boolean.parseBoolean(result); |
| | | } else { |
| | | listBad.add(dto.getPointNo()); |
| | | throw new RuntimeException("计算异常,未知数据类型"); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public Map<String, Object> getCurrent(List<String> pointNos) { |
| | |
| | | @Resource |
| | | private DaPointService daPointService; |
| | | |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap) { |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap,List<String> listGood,List<String> listBad) { |
| | | log.info("常量点处理开始"); |
| | | List<InfluxPointValuePOJO> result = new ArrayList<>(); |
| | | if (CollectionUtils.isEmpty(dtos)) { |
| | |
| | | pojo.setTimestamp(collectTime.toInstant()); |
| | | dataMap.put(dto.getPointNo(), dto.getDefaultValue()); |
| | | result.add(pojo); |
| | | listGood.add(dto.getPointNo()); |
| | | }); |
| | | log.info("常量点处理结束"); |
| | | return result; |
| | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos) { |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos,List<String> listGood,List<String> listBad) { |
| | | List<InfluxPointValuePOJO> result = new ArrayList<>(); |
| | | try { |
| | | log.info("累计点处理开始"); |
| | |
| | | } |
| | | dtos.forEach(dto -> { |
| | | try { |
| | | Object value = singleCompute(dto, collectTime); |
| | | Object value = singleCompute(dto, collectTime,listGood,listBad); |
| | | InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value); |
| | | pojo.setTimestamp(collectTime.toInstant()); |
| | | result.add(pojo); |
| | |
| | | return data; |
| | | } |
| | | |
| | | |
| | | private Object singleCompute(DaPointDTO dto, Date collectTime) { |
| | | return singleCompute(dto,collectTime,null,null); |
| | | } |
| | | |
| | | private Object singleCompute(DaPointDTO dto, Date collectTime,List<String> listGood,List<String> listBad) { |
| | | ApiPointDTO pointDTO = dataPointApi.getInfoByNo(dto.getMomentPoint()); |
| | | if (pointDTO == null) { |
| | | if (listBad != null) { |
| | | listBad.add(dto.getPointNo()); |
| | | } |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | |
| | | List<ApiPointValueDTO> dataList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | if (CollectionUtils.isEmpty(dataList)) { |
| | | if (listGood != null) { |
| | | listGood.add(dto.getPointNo()); |
| | | } |
| | | return BigDecimal.ZERO; |
| | | } else if (dataList.size() < dto.getLength()) { |
| | | // 补全数据 |
| | | dataList = completionData(dto.getLength(), dataList, startTime, endTime, pointDTO); |
| | | } |
| | | double total = dataList.stream().mapToDouble(ApiPointValueDTO::getV).sum(); |
| | | if (listGood != null) { |
| | | listGood.add(dto.getPointNo()); |
| | | } |
| | | return new BigDecimal(total).divide(new BigDecimal(dto.getDivisor()), 2, BigDecimal.ROUND_HALF_UP); |
| | | } |
| | | |
| | |
| | | return item.getValue(); |
| | | } |
| | | } |
| | | return null; |
| | | return 0.0; |
| | | } |
| | | } |
| | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap) { |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap,List<String> listGood,List<String> listBad) { |
| | | log.info("测量点处理开始"); |
| | | List<InfluxPointValuePOJO> result = new ArrayList<>(); |
| | | if (CollectionUtils.isEmpty(dtos)) { |
| | |
| | | if (!CollectionUtils.isEmpty(httpTagIhd)) { |
| | | tagValues.putAll(httpCollectorForIhd.getTagValues(httpTagIhd, collectTime)); |
| | | } |
| | | this.toCommonResult(collectTime, dtos, tagValues, dataMap, result); |
| | | this.toCommonResult(collectTime, dtos, tagValues, dataMap, result,listGood,listBad); |
| | | log.info("测量点处理结束"); |
| | | return result; |
| | | } |
| | | |
| | | private void toCommonResult(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> tagValues, |
| | | Map<String, Object> dataMap, List<InfluxPointValuePOJO> result) { |
| | | Map<String, Object> dataMap, List<InfluxPointValuePOJO> result,List<String> listGood,List<String> listBad) { |
| | | if (!CollectionUtils.isEmpty(tagValues)) { |
| | | tagValues.forEach((k, v) -> { |
| | | dataMap.put(k, v); |
| | | }); |
| | | dtos.forEach(dto -> { |
| | | String tagId = TagUtils.genTagId(dto.getSourceType(), dto.getSourceName(), dto.getTagNo()); |
| | | if (tagValues.get(tagId) != null) { |
| | | if (tagValues.containsKey(tagId)) { |
| | | Object value = handleData(dto, tagValues.get(tagId)); |
| | | InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value); |
| | | pojo.setTimestamp(collectTime.toInstant()); |
| | | dataMap.put(dto.getPointNo(), value); |
| | | result.add(pojo); |
| | | listGood.add(dto.getPointNo()); |
| | | } else { |
| | | InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, CommonConstant.BAD_VALUE); |
| | | pojo.setTimestamp(collectTime.toInstant()); |
| | | result.add(pojo); |
| | | listBad.add(dto.getPointNo()); |
| | | System.out.println("值异常!TagId=" + tagId); |
| | | } |
| | | }); |
| | |
| | | if (DataTypeEnum.FLOAT.getCode().equals(dto.getDataType()) || DataTypeEnum.INT.getCode().equals(dto.getDataType())) { |
| | | BigDecimal rawValue = new BigDecimal(value.toString()); |
| | | if(CommonConstant.BAD_VALUE.compareTo(rawValue) == 0) { |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | | // 异常值处理 |
| | | if (rawValue.compareTo(maxValue) > 0 || rawValue.compareTo(minValue) < 0) { |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | | BigDecimal coefficient = dto.getUnittransfactor() == null ? BigDecimal.ONE : dto.getUnittransfactor(); |
| | |
| | | void recordStatus(String pointNo, String collectValue, Date collectTime); |
| | | |
| | | @Async |
| | | void recordStatusList(List<InfluxPointValuePOJO> pointValues, Date collectTime); |
| | | void recordStatusList(List<String> listGood,List<String> listBad, Date collectTime); |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void recordStatusList(List<InfluxPointValuePOJO> pointValues, Date collectTime) { |
| | | List<String> listGood = new ArrayList<>(); |
| | | List<String> listBad = new ArrayList<>(); |
| | | Object collectValue = null; |
| | | for (InfluxPointValuePOJO pointValue : pointValues) { |
| | | if (pointValue instanceof InfluxPointValueSimPOJO) { |
| | | InfluxPointValueSimPOJO pvo = (InfluxPointValueSimPOJO) pointValue; |
| | | collectValue = pvo.getValue(); |
| | | } else if (pointValue instanceof InfluxPointValueDigPOJO) { |
| | | InfluxPointValueDigPOJO pvo = (InfluxPointValueDigPOJO) pointValue; |
| | | collectValue = pvo.getValue(); |
| | | } else { |
| | | continue; |
| | | } |
| | | switch (DataQualityEnum.getEumByValue(collectValue)) { |
| | | case GOOD: |
| | | listGood.add(pointValue.getPoint()); |
| | | break; |
| | | case BAD: |
| | | listBad.add(pointValue.getPoint()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | public void recordStatusList(List<String> listGood,List<String> listBad, Date collectTime) { |
| | | if (!CollectionUtils.isEmpty(listGood)) { |
| | | QueryWrapper<DaPointCollectStatusEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.in("point_no", listGood); |
| | |
| | | // public static final String JsonSavePath = "D:/DLUT/json";//海康威视抓取图片上传路径 |
| | | |
| | | // public static final String HIK_WIN_PATH = "hikvision/win64/HCNetSDK.dll"; |
| | | public static final String HIK_WIN_PATH = "D:\\DLUT\\lib\\HCNetSDK.dll"; |
| | | public static final String HIK_WIN_PATH = "D:\\DLUT\\lib\\hikvision\\win64\\HCNetSDK.dll"; |
| | | |
| | | public static final String ModelCode = "Image_feature";//模型代码 |
| | | |