package com.dgtis.data.api;

import com.arronlong.httpclientutil.HttpClientUtil;
import com.arronlong.httpclientutil.common.HttpConfig;
import com.arronlong.httpclientutil.exception.HttpProcessException;
import com.dgtis.common.core.utils.DateUtils;
import com.dgtis.common.core.web.controller.BaseController;
import com.dgtis.common.core.web.domain.AjaxResult;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author koucx
 * @version 1.0
 * @descption: TODO
 * @company 神州数码通用软件（洛阳）有限公司
 * @copyright (c) 2019 LuoYang DGT Co'Ltd Inc. All rights reserved.
 * @date 2021-01-21
 * @since JDK1.8
 */
@Controller
@RequestMapping("/api")
public class DocumentApiController extends BaseController {

   /* @Autowired
    private TransportClient transportClient;*/

    @Autowired
    private ObjectMapper objectMapper;

    /*@GetMapping("/getIndex")
    @ResponseBody
    public AjaxResult getIndex() {

        GetResponse response = transportClient.prepareGet("shanglifeecif.individual","default_type_", "1").get();
        String result = response.getSourceAsString();
        return AjaxResult.success(result);
    }*/

    @GetMapping("/getIndex")
    @ResponseBody
    public AjaxResult getById() {
        // 获取索引的别名，字段，创建时间
        System.out.println(DateUtils.getTime());
        HttpConfig config = HttpConfig.custom().url("http://10.32.2.231:9200/shanglifeecif.individual/_search?from=1&size=10");
        System.out.println(DateUtils.getTime());
        String jsonStr = null;
        try {

            jsonStr = HttpClientUtil.get(config);
            System.out.println(DateUtils.getTime());
        } catch (HttpProcessException e) {
            e.printStackTrace();
            return null;
        }

        return AjaxResult.success(jsonStr);
    }



}
