/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 大恒泰山系统
 * 创建日期:2022/8/22
 */
package org.springblade.etl.controller;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.ContentType;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.etl.EtlTaskManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


/***
 * Date:2022/8/22
 * Title:测试接口
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@RequestMapping("galaxy-test/test")
@AllArgsConstructor
@Api(value = "测试接口", tags = "测试接口")
@Slf4j
public class TestController extends BladeController {

    @Resource
    private EtlTaskManager etlTaskManager;

    @GetMapping("/etl/rain")
    @ApiOperationSupport(order = 1)
    public R<String> etlRain(@RequestParam(name = "rtuCode") String rtuCode) {
//        etlTaskManager.submitRainDataEtlTask();
//        etlTaskManager.submitRiverDataEtlTask();
//        etlTaskManager.submitRsvrDataEtlTask();
//        etlTaskManager.submitGroundDataEtlTask();
        return R.data("ok");
    }

    private Map<String, String> getHeaders() {

        Map<String, String> headers = new HashMap<>();

        headers.put("Content-Type", "application/json-rpc; charset=utf-8");

        return headers;
    }

    @GetMapping("/zabbix")
    @ApiOperationSupport(order = 1)
    public R<String> zabbix() {
//        JSONObject p = new JSONObject();
//        p.put("jsonrpc", "2.0");
//        p.put("method", "apiinfo.version");
//        JSONArray params = new JSONArray();
//        p.put("params", params);
//        p.put("id", 1);

//        JSONObject p = new JSONObject();
//        p.put("jsonrpc", "2.0");
//        p.put("method", "user.login");
//        JSONObject  params = new JSONObject();
//        params.put("user","Admin");
//        params.put("password","zabbix");
//        p.put("params", params);
//        p.put("id", 1);
//
//        int nTimeOut = 20 * 1000;
//        Map<String, String> headers = getHeaders();
//        String url = "http://172.31.1.186:8080/api_jsonrpc.php";
//        HttpResponse response = HttpRequest.post(url)
//                .contentType("application/json-rpc; charset=utf-8")
//                .body(JSONObject.toJSONString(p))
//                .addHeaders(headers)
//                .timeout(nTimeOut)
//                .execute();
//        if (response.getStatus() == HttpStatus.HTTP_OK) {
//            String body = response.body();
//            return R.data(body);
//        }else{
//            return R.fail("error "+response.getStatus());
//        }

        return R.data("ok");
    }
}
