|
@@ -0,0 +1,149 @@
|
|
|
+package com.bizmatics.mhfire.service.api;
|
|
|
+
|
|
|
+import com.bizmatics.common.core.exception.BusinessException;
|
|
|
+import com.bizmatics.common.core.util.HttpUtils;
|
|
|
+import com.bizmatics.common.spring.util.JsonUtils;
|
|
|
+import com.bizmatics.mhfire.model.Alert;
|
|
|
+import com.bizmatics.mhfire.model.FireSite;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yq
|
|
|
+ * @date 2021/8/12 9:38
|
|
|
+ */
|
|
|
+@Log4j2
|
|
|
+public class AlertAndSiteApi {
|
|
|
+ /**
|
|
|
+ * 账号
|
|
|
+ */
|
|
|
+ public static final String USER_NAME = "zhgl";
|
|
|
+ /**
|
|
|
+ * 密码
|
|
|
+ */
|
|
|
+ public static final String USER_PASSWORD = "4VshDAQwHJEQSikJKE3oIiwxDcjfUEbi5nTWsNX6Y8ZFX2rk6c6ez7uDZdRjsQfzwSEGVVqdIfPeq1JPLYqw==";
|
|
|
+ /**
|
|
|
+ * 登录url
|
|
|
+ */
|
|
|
+ private static final String LOGIN_URL = "http://172.200.50.4:7100/bsUser/user/login";
|
|
|
+ /**
|
|
|
+ * 警情url
|
|
|
+ */
|
|
|
+ private static final String ALERT_URL = "http://172.200.50.4:7100/xf/case/queryCase";
|
|
|
+ /**
|
|
|
+ * 消防站点url
|
|
|
+ */
|
|
|
+ private static final String FIRE_SITE_URL = "http://172.200.50.4:7100/xf/fire/queryNature";
|
|
|
+
|
|
|
+ private static final ObjectMapper MAPPER = new ObjectMapper();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String login(String userName,String userPassword){
|
|
|
+ Map<String,String> params = new HashMap<>();
|
|
|
+ params.put("userName",userName);
|
|
|
+ params.put("userPassword",userPassword);
|
|
|
+ String token = "";
|
|
|
+ try {
|
|
|
+ String result = HttpUtils.postJson(LOGIN_URL, JsonUtils.toJson(params), null);
|
|
|
+ JsonNode arrNode = new ObjectMapper().readTree(result);
|
|
|
+ log.info("获取登录接口信息"+arrNode);
|
|
|
+ if ("200".equals(arrNode.get("code").asText())){
|
|
|
+ token = arrNode.get("data").asText();
|
|
|
+ }else {
|
|
|
+ log.error("调用登录api失败"+arrNode.get("msg"));
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("调用登录api异常"+ e.getMessage());
|
|
|
+ }
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param ajlx 案件类型
|
|
|
+ * @param searchValue 地址或补充信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<Alert> alertPage(String ajlx,String searchValue,Integer page,Integer size,String token){
|
|
|
+ List<Alert> alerts = new ArrayList<>();
|
|
|
+ //添加参数信息
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("ajlx",ajlx);
|
|
|
+ params.put("searchValue",searchValue);
|
|
|
+ params.put("page",page);
|
|
|
+ params.put("size",size);
|
|
|
+ //添加token信息
|
|
|
+ Map<String,String> header = new HashMap<>();
|
|
|
+ header.put("Authorization",token);
|
|
|
+ try {
|
|
|
+ String result = HttpUtils.postJson(ALERT_URL, JsonUtils.toJson(params), header);
|
|
|
+ JsonNode arrNode = MAPPER.readTree(result);
|
|
|
+ log.info("获取警情接口信息"+arrNode);
|
|
|
+ if ("200".equals(arrNode.get("code").asText())){
|
|
|
+ JsonNode data = arrNode.get("data");
|
|
|
+ JsonNode iterms = data.get("items");
|
|
|
+ if (iterms.isArray() && iterms.size() > 0){
|
|
|
+ alerts = MAPPER.readValue(iterms.traverse(), new TypeReference<List<Alert>>() {});
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.error("调用警情api失败:"+arrNode.get("msg"));
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("调用警情api异常"+ e.getMessage());
|
|
|
+ throw new BusinessException("调用警情api异常:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return alerts;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 站点集合
|
|
|
+ * @param dwxz 单位
|
|
|
+ * @param xfzlx 消防站类型
|
|
|
+ * @param rang 半径范围
|
|
|
+ * @param addr 地址
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<FireSite> fireSiteList(String dwxz, String xfzlx, String rang, String addr,String token){
|
|
|
+ List<FireSite> list = new ArrayList<>();
|
|
|
+ //添加参数信息
|
|
|
+ Map<String,String> params = new HashMap<>();
|
|
|
+ params.put("dwxz",dwxz);
|
|
|
+ params.put("xfzlx",xfzlx);
|
|
|
+ params.put("rang",rang);
|
|
|
+ params.put("addr",addr);
|
|
|
+ //添加token信息
|
|
|
+ Map<String,String> header = new HashMap<>();
|
|
|
+ header.put("Authorization",token);
|
|
|
+ try {
|
|
|
+ String result = HttpUtils.postJson(FIRE_SITE_URL, JsonUtils.toJson(params), header);
|
|
|
+ JsonNode arrNode = MAPPER.readTree(result);
|
|
|
+ log.info("获取警情接口信息"+arrNode);
|
|
|
+ if ("200".equals(arrNode.get("code").asText())){
|
|
|
+ JsonNode data = arrNode.get("data");
|
|
|
+ JsonNode iterms = data.get("items");
|
|
|
+ if (iterms.isArray() && iterms.size() > 0){
|
|
|
+ list = MAPPER.readValue(iterms.traverse(), new TypeReference<List<FireSite>>() {});
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.error("调用站点api异常:"+arrNode.get("msg"));
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("调用站点api异常:"+ e.getMessage());
|
|
|
+ throw new BusinessException("调用站点api异常:"+e.getMessage());
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|