123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- package com.dgtis.data.api;
- 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.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
- * @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("/index")
- public class IndexApiController extends BaseController {
- @Value("${elasticsearch.host}")
- private String esHost;
- @Value("${elasticsearch.port}")
- private int esPort;
- @GetMapping("/riskcode")
- @ResponseBody
- public AjaxResult riskcode() {
- // 获取索引的别名,字段,创建时间
- 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("khnum"));
- 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 (Exception e) {
- e.printStackTrace();
- return AjaxResult.error("获取数据失败");
- }
- Map data = new HashMap();
- data.put("xaxisData",xaxisData);
- data.put("seriesData",seriesData);
- return AjaxResult.success("险种数据返回成功!",data);
- }
- @GetMapping("/bdNumDis")
- @ResponseBody
- public AjaxResult bdNumDis() {
- // 获取索引的别名,字段,创建时间
- HttpConfig config = HttpConfig.custom().url("http://"+esHost+":"+esPort+"/shanglifeecif.bdnum_distribution/_search?");
- String jsonStr = null;
- Map[] seriesData = new HashMap[8];
- //List seriesData = new ArrayList();//客户数量和保单数量
- /* seriesData.add(0,"无保单");
- seriesData.add(1,"1件保单");
- seriesData.add(2,"2件保单");
- seriesData.add(3,"3-5件保单");
- seriesData.add(4,"6-10件保单");
- seriesData.add(5,"11-20件保单");
- seriesData.add(6,"21-50件保单");
- seriesData.add(7,"50件以上保单");*/
- 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){
- for (Object o:hits) {
- JSONObject object = JSONUtil.parseObj(o);
- if(object!=null){
- JSONObject source = object.getJSONObject("_source");
- Map map = new HashMap();
- String labelname = source.getStr("labelname").trim();
- /* map.put("value",source.getStr("bdnum"));
- map.put("name",source.getStr("labelname").trim());
- seriesData.add(map);*/
- Map m = new HashMap();
- m.put("name",labelname);
- m.put("value",source.getStr("bdnum"));
- if("无保单".equals(labelname)){
- seriesData[0] = m;
- }else if("1件".equals(labelname)){
- seriesData[1] = m;
- }else if("2件".equals(labelname)){
- seriesData[2] = m;
- }else if("3-5件".equals(labelname)){
- seriesData[3] = m;
- }else if("6-10件".equals(labelname)){
- seriesData[4] = m;
- }else if("11-20件".equals(labelname)){
- seriesData[5] = m;
- }else if("21-50件".equals(labelname)){
- seriesData[6] = m;
- }else{
- seriesData[7] = m;
- }
- }
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error("获取数据失败");
- }
- Map data = new HashMap();
- data.put("seriesData",seriesData);
- return AjaxResult.success("保单件数分布数据返回成功!",data);
- }
- @GetMapping("/ageSexDis")
- @ResponseBody
- public AjaxResult ageSexDis() {
- // 获取索引的别名,字段,创建时间
- HttpConfig config = HttpConfig.custom().url("http://"+esHost+":"+esPort+"/shanglifeecif.age_sex_distribution/_search?");
- String jsonStr = null;
- List legendData = new ArrayList();//性别集合
- legendData.add("男");
- legendData.add("女");
- List xaxisData = new ArrayList();//年龄段
- xaxisData.add("儿童");
- xaxisData.add("少年");
- xaxisData.add("青年");
- xaxisData.add("中年");
- xaxisData.add("老年");
- 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){
- String[] manNum = new String[5];
- String[] womanNum = new String[5];
- for (Object o:hits) {
- JSONObject object = JSONUtil.parseObj(o);
- if(object!=null){
- JSONObject source = object.getJSONObject("_source");
- String gender = source.getStr("gender");
- String labelname = source.getStr("labelname").trim();
- String cusnum = source.getStr("cusnum");
- if("0".equals(gender)){
- if("儿童".equals(labelname)){
- manNum[0] = cusnum;
- }else if("少年".equals(labelname)){
- manNum[1] = cusnum;
- }else if("青年".equals(labelname)){
- manNum[2] = cusnum;
- }else if("中年".equals(labelname)){
- manNum[3] = cusnum;
- }else {
- manNum[4] = cusnum;
- }
- }else {
- if("儿童".equals(labelname)){
- womanNum[0] = cusnum;
- }else if("少年".equals(labelname)){
- womanNum[1] = cusnum;
- }else if("青年".equals(labelname)){
- womanNum[2] = cusnum;
- }else if("中年".equals(labelname)){
- womanNum[3] = cusnum;
- }else {
- womanNum[4] = cusnum;
- }
- }
- }
- }
- seriesData.add(manNum);
- seriesData.add(womanNum);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- return AjaxResult.error("获取数据失败");
- }
- Map data = new HashMap();
- data.put("legendData",legendData);
- data.put("xaxisData",xaxisData);
- data.put("seriesData",seriesData);
- return AjaxResult.success("客户年龄段性别分布数据返回成功!",data);
- }
- }
|