package com.jiayue.ipfcst.client.Schedule;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.jiayue.ipfcst.client.ClientApplication;
import com.jiayue.ipfcst.client.domain.entity.ClientConfig;
import com.jiayue.ipfcst.client.utils.ClientFileUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ClientApplication.class})// 指定启动类
@Slf4j
public class SaticScheduleTaskV2Test {

    @Test
    public void t() throws Throwable {
        ClientConfig clientConfig = ClientFileUtils.loadLocalConfigFile();
        System.out.println(JSONUtil.toJsonStr(clientConfig));
    }

    @Test
    public void w(){
        Map m = new HashMap();
        m.put("stationCode","T00001");
        m.put("cloudAddr","https://117.78.19.70:9010/client/");
        ClientFileUtils.createJsonFile(JSONUtil.toJsonStr(m),"./default.properties");
    }


    public static void main(String[] args) {

        //String url = "https://49.4.68.219:9100/cemp-forecast-test/T00003/NWP_202209281734440.RB";
        String url = "https://49.4.68.219:9100/cemp-forecast-test/J00001/NWP_202209282134240.RB?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=S5T90KFISSUAHUO03GYT%2F20220928%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220928T134505Z&X-Amz-Expires=604800&X-Amz-Security-Token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NLZXkiOiJTNVQ5MEtGSVNTVUFIVU8wM0dZVCIsImV4cCI6MTY2NDM3NTYwNCwicGFyZW50IjoibWluaW9hZG1pbiJ9.NMkLI7lapbs-evmCE5PWcq-1BhPfgPglglMmC1gTgMyNVBGQtXuM0uEulyebYXrQNoNFxhoSuSUCHqb7JkcgWg&X-Amz-SignedHeaders=host&versionId=null&X-Amz-Signature=54dda497c488038f1c048a00426d9236110865d33296e8395a3ae41e648c5445";
        String tempFilePath = "D:\\temp\\download\\";
        Long size = HttpUtil.downloadFile(url, new File(tempFilePath + File.separatorChar
                + "NWP_202209281734440.RB"),10000);
        System.out.println(size);
    }
}