|
|
@@ -1,17 +1,25 @@
|
|
|
package com.dgtis.data.api;
|
|
|
|
|
|
+import cn.hutool.json.JSON;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
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.utils.StringUtils;
|
|
|
import com.dgtis.common.core.web.controller.BaseController;
|
|
|
import com.dgtis.common.core.web.domain.AjaxResult;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
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;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @author koucx
|
|
|
@@ -26,24 +34,64 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
@RequestMapping("/index")
|
|
|
public class IndexApiController extends BaseController {
|
|
|
|
|
|
+ @Value("${elasticsearch.host}")
|
|
|
+ private String esHost;
|
|
|
+
|
|
|
+ @Value("${elasticsearch.port}")
|
|
|
+ private int esPort;
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/riskcode")
|
|
|
@ResponseBody
|
|
|
- public AjaxResult getById() {
|
|
|
+ public AjaxResult riskcode() {
|
|
|
// 获取索引的别名,字段,创建时间
|
|
|
- HttpConfig config = HttpConfig.custom().url("http://10.32.2.231:9200/shanglifeecif.individual/_search?");
|
|
|
+ HttpConfig config = HttpConfig.custom().url("http://"+esHost+":"+esPort+"/shanglifeecif.riskcode_statistics/_search?");
|
|
|
String jsonStr = null;
|
|
|
+ List xaxisData = new ArrayList();//存放险种
|
|
|
+ List seriesData = new ArrayList();//客户数量和保单数量
|
|
|
try {
|
|
|
|
|
|
jsonStr = HttpClientUtil.get(config);
|
|
|
if(StringUtils.isNotEmpty(jsonStr)){
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
|
|
|
+ jsonObject = jsonObject.getJSONObject("hits");
|
|
|
+ if(jsonObject!=null){
|
|
|
+ JSONArray hits = jsonObject.getJSONArray("hits");
|
|
|
+ if(hits!=null && hits.size()>0){
|
|
|
+ List khnum = new ArrayList();//客户数量
|
|
|
+ List bdtotalPrem = new ArrayList();//保单数量
|
|
|
+ for (Object o:hits) {
|
|
|
+ JSONObject object = JSONUtil.parseObj(o);
|
|
|
+ if(object!=null){
|
|
|
+ JSONObject source = object.getJSONObject("_source");
|
|
|
+ xaxisData.add(source.getStr("kindname"));
|
|
|
+ khnum.add(source.getStr("kindname"));
|
|
|
+ bdtotalPrem.add(source.getStr("tatolprem"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Map code1 = new HashMap();
|
|
|
+ code1.put("name","客户数量");
|
|
|
+ code1.put("data",khnum);
|
|
|
+ seriesData.add(code1);
|
|
|
+ Map code2 = new HashMap();
|
|
|
+ code2.put("name","保单总金额");
|
|
|
+ code2.put("data",bdtotalPrem);
|
|
|
+ seriesData.add(code2);
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- } catch (HttpProcessException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- return AjaxResult.error();
|
|
|
+ return AjaxResult.error("获取数据失败");
|
|
|
}
|
|
|
|
|
|
- return AjaxResult.success(jsonStr);
|
|
|
+ Map data = new HashMap();
|
|
|
+ data.put("xaxisData",xaxisData);
|
|
|
+ data.put("seriesData",seriesData);
|
|
|
+ return AjaxResult.success("险种数据返回成功!",data);
|
|
|
}
|
|
|
|
|
|
|