12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package com.slibra.web.controller.business;
- import cn.hutool.http.HttpRequest;
- import com.alibaba.fastjson2.JSON;
- import com.alibaba.fastjson2.JSONArray;
- import java.math.BigDecimal;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import static com.slibra.common.constant.MyConstants.INDUSTRY_INTERFACE_ADDR;
- /***
- *
- * 手动处处理一些数据
- *
- */
- public class DataHandleByHand {
- public static void main(String[] args) {
- testExistsGYKField();
- }
- /**
- * 查看工业库的某个值是否存在
- * 或者某个时间段是否存在
- */
- public static void testExistsGYKField() {
- String[] queryTags = {"信义污水厂_除磷P04预测值_"};
- // 给定时间段的起始时间和结束时间
- LocalDateTime startTime = LocalDateTime.parse("2024-04-25T00:09:25");
- LocalDateTime endTime = LocalDateTime.parse("2024-04-25T09:30:00");
- // 每个小时的时间格式
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- // 循环按小时分割
- LocalDateTime currentHour = startTime;
- while (currentHour.isBefore(endTime)) {
- String begin = currentHour.format(formatter);
- String end = currentHour.plusMinutes(10).format(formatter);
- // 输出当前小时的起始时间和结束时间
- System.out.println("起始时间:" + begin);
- System.out.println("结束时间:" + end);
- // 当前小时加一小时,作为下一个小时的起始时间
- currentHour = currentHour.plusMinutes(10);
- //每个小时查询一次数据
- HashMap<String, Object> req = new HashMap<>();
- req.put("tagNames", queryTags);
- req.put("startTime", begin);
- req.put("endTime", end);
- req.put("recordNumbers", 100000);
- String body = HttpRequest.post(INDUSTRY_INTERFACE_ADDR).header("Authorization", "c2E6c2E=").header("clientName", "hongshan").body(JSON.toJSONString(req)).execute().body();
- System.out.println("body = " + body);
- //行转列数据处理
- for (String queryTag : queryTags) {
- JSONArray array = JSON.parseObject(body).getJSONArray(queryTag);
- System.out.println(JSON.toJSONString(array));
- }
- }
- }
- }
|