package com.fdkankan.download.config;

import com.alibaba.fastjson.JSON;
import com.fdkankan.fyun.oss.UploadToOssUtil;
import com.fdkankan.redis.util.RedisUtil;
import com.fdkankan.common.bean.DownLoadTaskBean;
import com.fdkankan.download.service.impl.SceneDownloadHandlerServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author dengsixing
 * @since 2022/2/24
 **/
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Value("${download.config.server-url}")
    private String serverUrl;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    UploadToOssUtil uploadToOssUtil;

    @Autowired
    SceneDownloadHandlerServiceImpl downloadHandlerService;
    @Autowired
    RedisUtil redisUtil;

    @GetMapping("/test")
    public String test() throws Exception{
//        Map<String, String> param = new HashMap<>();
//        param.put("num", "t-YhBCzQr");
//        String getInfoStr = restTemplate.postForObject(serverUrl + "api/scene/getInfo?num=t-YhBCzQr", param, String.class);
//
//        ResultData resultData = JSONUtil.toBean(getInfoStr, ResultData.class);
//        if(resultData == null || ServerCode.SUCCESS.code() != resultData.getCode()){
//            log.error("getInfo请求失败，url：" + serverUrl + "api/scene/getInfo?num=t-YhBCzQr");
//        }
//
//        JSONObject dataJson = JSONUtil.parseObj(resultData.getData());
//        dataJson.set("sceneScheme", 3);
//        dataJson.set("needKey", 0);
//        dataJson.set("sceneKey","");

//        List<String> strings = uploadToOssUtil.listKeysFromAli("data/datat-ieXdyGl6Md");
//        for (String string : strings) {
//            System.out.println(string);
//        }

        redisUtil.lLeftPush("downloads:task:v4", JSON
            .toJSONString(DownLoadTaskBean.builder().num("eur-3wdeOQaa0").type("local").build()));

//        List<String> strings = uploadToOssUtil.listKeysFromAws("data/datawJ6cAq3tc");

        return "123";
    }

}
