上代码:
public void zeroPowerData() throws IOException, ExecutionException, InterruptedException { // 读取所有的电力数据 List<DataTypeDTO> dataTypeList = stoneDataTypeDao.getDataTypeList(); if (CollectionUtils.isEmpty(dataTypeList)) { return; } dataTypeList.removeIf(data -> !Objects.equals(DataCategoryEnums.POWER.getCode(), data.getFacilityCategory())); for (DataTypeDTO dataTypeDTO : dataTypeList) { log.info("执行dataTypeDTO={}", JSON.toJSONString(dataTypeDTO)); String startTime = "2023-07-12 00:00:00"; LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime now = LocalDateTime.now(); while (start.isBefore(now)) { // 查询所有的metric Long begin = start.toEpochSecond(ZoneOffset.of("+8")); Long end = start.plusDays(1).toEpochSecond(ZoneOffset.of("+8")); Query query = Query.begin(begin) .end(end) .sub(SubQuery.metric(dataTypeDTO.getProcessNo() + "_" + dataTypeDTO.getTitleNo()) .aggregator(SubQuery.Aggregator.NONE) .tag("customer_id", dataTypeDTO.getCustomerId().toString()) .rollupUsage(SubQuery.RollupUsage.ROLLUP_NOFALLBACK.getUsage()) .build()) .build(); List<QueryResult> QueryResultList = originalClient.query(query); if (!CollectionUtils.isEmpty(QueryResultList)) { QueryResult queryResult = QueryResultList.get(0); LinkedHashMap<Long, Number> dps = queryResult.getDps(); // 将其置为0 dps.forEach((timeStamp, value) -> { Point point = Point.metric(dataTypeDTO.getProcessNo() + "_" + dataTypeDTO.getTitleNo()) .tag("customer_id", String.valueOf(dataTypeDTO.getCustomerId())) .value(timeStamp, 0) .build(); try { log.info("将要覆盖的Point===>{}", JSON.toJSONString(point)); originalClient.putSync(point); } catch (Exception e) { log.error("原料数据入库异常", e); } }); } start = start.plusDays(1); } } }
标签:dataTypeList,段时间,dataTypeDTO,start,query,LocalDateTime,opentsdb,now,数据 From: https://www.cnblogs.com/juncaoit/p/17705339.html