|
|
@@ -0,0 +1,101 @@
|
|
|
+package com.dgtis.data.api;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.domain.AjaxResult;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:客户信息列表api
|
|
|
+ * @author:qxm
|
|
|
+ * @date:2021/1/22 10:24
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping("/customer")
|
|
|
+public class CustomerApiController {
|
|
|
+
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(CustomerApiController.class);
|
|
|
+
|
|
|
+ @Value("${elasticsearch.host}")
|
|
|
+ private String host;
|
|
|
+ @Value("${elasticsearch.port}")
|
|
|
+ private String port;
|
|
|
+
|
|
|
+ @GetMapping("/getCustomerList")
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxResult getCustomerList(int pageNum,int pageSize) {
|
|
|
+ // 获取索引的别名,字段,创建时间
|
|
|
+ HttpConfig config = HttpConfig.custom().url("http://"+host+":"+port+"/shanglifeecif.individual/_search?from="+pageNum+"&size="+pageSize);
|
|
|
+ try {
|
|
|
+ String result = HttpClientUtil.get(config);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
+ JSONArray array = JSON.parseArray(hitsobject.get("hits").toString());
|
|
|
+ List listMap = new ArrayList<>();
|
|
|
+ Map map = new HashMap();
|
|
|
+ for (int i = 0; i <array.size() ; i++) {
|
|
|
+ JSONObject json = (JSONObject)array.get(i);
|
|
|
+ Map mp = new HashMap();
|
|
|
+ mp.put("id",json.getString("_id"));
|
|
|
+ JSONObject jsonOb = JSON.parseObject(json.getString("_source"));;
|
|
|
+ mp.putAll(JSON.parseObject(json.getString("_source"),Map.class));
|
|
|
+ mp.put("birthday", DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",jsonOb.getDate("birthday")));
|
|
|
+ listMap.add(mp);
|
|
|
+ }
|
|
|
+ long total = hitsobject.getLong("total");
|
|
|
+
|
|
|
+ map.put("list",listMap);
|
|
|
+ map.put("total",total);
|
|
|
+
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ } catch (HttpProcessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResult.error();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/getCustomerById")
|
|
|
+ @ResponseBody
|
|
|
+ public AjaxResult getCustomerById(String id) {
|
|
|
+ // 获取索引的别名,字段,创建时间http://10.32.2.231:9200/shanglifeecif.individual/default_type_/1
|
|
|
+ HttpConfig config = HttpConfig.custom().url("http://"+host+":"+port+"/shanglifeecif.individual/default_type_/"+id);
|
|
|
+ try {
|
|
|
+ Map map = new HashMap();
|
|
|
+ String result = HttpClientUtil.get(config);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ Map mpInfo = new HashMap();
|
|
|
+ mpInfo.put("id",jsonObject.getString("_id"));
|
|
|
+ mpInfo.putAll(JSON.parseObject(jsonObject.getString("_source"),Map.class));
|
|
|
+ mpInfo.put("birthday",DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",jsonObject.getDate("birthday")));
|
|
|
+ map.put("custInfo",mpInfo);
|
|
|
+ map.put("custInfo1",null);
|
|
|
+ map.put("custInfo2",null);
|
|
|
+ map.put("custInfo3",null);
|
|
|
+ map.put("custInfo4",null);
|
|
|
+ map.put("custInfo5",null);
|
|
|
+ map.put("custInfo6",null);
|
|
|
+ map.put("custInfo7",null);
|
|
|
+ map.put("custInfo8",null);
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ } catch (HttpProcessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResult.error();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|