package com.ruoyi.ucp.util;

import cn.hutool.setting.Setting;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.ucp.entity.PointData;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.List;

public class AdapterUtil {

    private static final RestTemplate restTemplate = new RestTemplate();
    private static String taosUrl, goldenUrl;
    private final Setting setting = new Setting("taos.setting");

    {
        setting.set("db.url.golden", "http://127.0.0.1:8011/ts");
        setting.set("db.url.taos", "http://127.0.0.1:8012/ts");
        setting.store("taos.setting");
        taosUrl = setting.getStr("db.url.taos", "http://127.0.0.1:8012/ts");
        goldenUrl = setting.getStr("db.url.golden", "http://127.0.0.1:8011/ts");
    }

    public List<PointData> getHistorySnap(String key, long startTs, long endTs, int interval) {

        String url = goldenUrl + "/history/snap?null=0&tagName="
                + key + "&startTs=" + startTs + "&endTs=" + endTs + "&interval=" + interval;
        ResponseEntity<JSONArray> resp = restTemplate.getForEntity(url, JSONArray.class);
        return resp.getBody().toJavaList(PointData.class);
    }
}
