From d2b1ed4fd18badeb60ac9b166908c263b2b90435 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=8D=E7=88=B1=E5=AD=A6=E4=B9=A0=E7=9A=84=E7=9F=B3?=
=?UTF-8?q?=E5=90=8C=E5=AD=A6?= <2936013465@qq.com>
Date: Sun, 17 Nov 2024 22:21:26 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A1=88=E4=BB=B6=E6=A0=B8=E6=9F=A5=E8=B6=8B?=
=?UTF-8?q?=E5=8A=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 9 +
.../datav/DataVCaseVerifController.java | 14 +
.../controller/datav/PoliceComment.java | 67 ++++-
.../datav/SupervisionNotifyController.java | 8 +-
.../mapper/DataCaseVerifMapper.java | 11 +
.../supervision/mapper/NegativeMapper.java | 122 ++------
.../service/DataPetition12337Service.java | 1 -
.../DataSupervisionNotifyServiceImpl.java | 19 +-
.../supervision/util/HttpClientUtil.java | 276 ++++++++++++++++++
.../com/biutag/supervision/util/SslUtil.java | 64 ++++
10 files changed, 485 insertions(+), 106 deletions(-)
create mode 100644 src/main/java/com/biutag/supervision/util/HttpClientUtil.java
create mode 100644 src/main/java/com/biutag/supervision/util/SslUtil.java
diff --git a/pom.xml b/pom.xml
index 2631f6a..8ef4ec0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,15 @@
17
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.13
+
+
+
org.springframework.boot
spring-boot-starter-web
diff --git a/src/main/java/com/biutag/supervision/controller/datav/DataVCaseVerifController.java b/src/main/java/com/biutag/supervision/controller/datav/DataVCaseVerifController.java
index 41283dd..b043879 100644
--- a/src/main/java/com/biutag/supervision/controller/datav/DataVCaseVerifController.java
+++ b/src/main/java/com/biutag/supervision/controller/datav/DataVCaseVerifController.java
@@ -10,6 +10,7 @@ import com.biutag.supervision.pojo.Result;
import com.biutag.supervision.pojo.dto.CaseVerifDepart;
import com.biutag.supervision.pojo.dto.common.PieItem;
import com.biutag.supervision.pojo.entity.DataCaseVerif;
+import com.biutag.supervision.pojo.vo.EchartsVo;
import com.biutag.supervision.service.DataCaseVerifService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
@@ -75,4 +76,17 @@ public class DataVCaseVerifController {
return Result.success(data);
}
+
+ @GetMapping("/trend")
+ public Result caseVerifTrend(
+ @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime,
+ @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
+ @RequestParam Integer month) {
+ List ajhcqsList = dataCaseVerifMapper.selectTrend(beginTime, endTime, 12);
+ JSONObject data = new JSONObject().fluentPut("ajhcqsList", ajhcqsList);
+ return Result.success(data);
+
+ }
+
+
}
diff --git a/src/main/java/com/biutag/supervision/controller/datav/PoliceComment.java b/src/main/java/com/biutag/supervision/controller/datav/PoliceComment.java
index 9773104..8ef3c4a 100644
--- a/src/main/java/com/biutag/supervision/controller/datav/PoliceComment.java
+++ b/src/main/java/com/biutag/supervision/controller/datav/PoliceComment.java
@@ -1,11 +1,21 @@
package com.biutag.supervision.controller.datav;
+import com.alibaba.fastjson.JSONObject;
+import com.biutag.supervision.pojo.Result;
+import com.biutag.supervision.util.HttpClientUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @Auther: sh
* @Date: 2024/11/17 11:04
@@ -16,8 +26,61 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequiredArgsConstructor
-@RequestMapping("DSJ/GetDCQK")
-@Tag(name = "现场督察相关")
+@RequestMapping("datav/DSJ")
public class PoliceComment {
+ private final String BASE_URL = "";
+
+
+ @GetMapping("/GetDCQK")
+ public Result getDCQK() {
+ Map params = new HashMap<>();
+ params.put("PeriodId", "6");
+ params.put("PeriodSonID", "-1");
+ params.put("OrgNo", "4304");
+ Map header = new HashMap<>();
+ header.put("Content-Type", "application/json");
+ String s = HttpClientUtil.doPost(BASE_URL, params, header);
+ JSONObject jsonObject = JSONObject.parseObject(s);
+ log.info("返回数据字符串=============" + s);
+ log.info("返回数据JSON对象=============" + jsonObject.toJSONString());
+ System.out.println(jsonObject.get("data").toString());
+ return Result.success(jsonObject);
+ }
+
+
+ @GetMapping("/GetBMYYBQS")
+ public Result getBMYYBQS(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime) {
+ Map params = new HashMap<>();
+ params.put("PeriodId", "6");
+ params.put("OrgNo", "4304");
+ String res = HttpClientUtil.doPost(BASE_URL, params, null);
+ log.info("返回GetBMYYBQS数据字符串=============" + res);
+ return Result.success();
+ }
+
+
+ @GetMapping("/GetZHMYLPM")
+ public Result getGetZHMYLPM(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime,
+ @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime) {
+ Map params = new HashMap<>();
+ params.put("PeriodId", "6");
+ String res = HttpClientUtil.doPost(BASE_URL, params, null);
+ log.info("返回GetZHMYLPM数据字符串=============" + res);
+ return Result.success();
+ }
+
+ @GetMapping("/GetRCSQQK")
+ public Result getRCSQQK(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime,
+ @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){
+ Map params = new HashMap<>();
+ params.put("PeriodId", "6");
+ params.put("PeriodSonID", "-1");
+ params.put("OrgNo", "4304");
+ String res = HttpClientUtil.doPost(BASE_URL, params, null);
+ log.info("返回GetRCSQQK数据字符串=============" + res);
+ return Result.success();
+ }
+
+
}
diff --git a/src/main/java/com/biutag/supervision/controller/datav/SupervisionNotifyController.java b/src/main/java/com/biutag/supervision/controller/datav/SupervisionNotifyController.java
index 3644c77..8902341 100644
--- a/src/main/java/com/biutag/supervision/controller/datav/SupervisionNotifyController.java
+++ b/src/main/java/com/biutag/supervision/controller/datav/SupervisionNotifyController.java
@@ -53,15 +53,16 @@ public class SupervisionNotifyController {
// 黄赌毒总览
-// List hddzlList = dataSupervisionNotifyService.getYellowBet(beginTime, endTime);
+ JSONObject hddOverview = dataSupervisionNotifyService.getYellowBetOverview(beginTime, endTime);
-// // 黄毒赌列表
+ // 黄毒赌列表
List hddList = dataSupervisionNotifyService.getYellowBet(beginTime, endTime);
JSONObject data = new JSONObject().fluentPut("wtlxList", wtlxList)
.fluentPut("overview", overview)
.fluentPut("superviseTempMapVoList", superviseTempMapVoList)
- .fluentPut("hddList", hddList);
+ .fluentPut("hddList", hddList)
+ .fluentPut("hddOverview", hddOverview);
return Result.success(data);
}
@@ -103,5 +104,6 @@ public class SupervisionNotifyController {
return Result.success(data);
}
+
}
diff --git a/src/main/java/com/biutag/supervision/mapper/DataCaseVerifMapper.java b/src/main/java/com/biutag/supervision/mapper/DataCaseVerifMapper.java
index 5c588bb..08a2338 100644
--- a/src/main/java/com/biutag/supervision/mapper/DataCaseVerifMapper.java
+++ b/src/main/java/com/biutag/supervision/mapper/DataCaseVerifMapper.java
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.biutag.supervision.pojo.dto.CaseVerifDepart;
import com.biutag.supervision.pojo.dto.common.PieItem;
import com.biutag.supervision.pojo.entity.DataCaseVerif;
+import com.biutag.supervision.pojo.vo.EchartsVo;
import org.apache.ibatis.annotations.Select;
import java.util.Date;
@@ -21,4 +22,14 @@ public interface DataCaseVerifMapper extends BaseMapper {
@Select("select problem_sources name, count(originId) value from data_case_verif where discovery_time between #{beginTime} and #{endTime} group by problem_sources")
List selectGroupByProblemSources(Date beginTime, Date endTime);
+ @Select("SELECT DATE_FORMAT(discoveryTime, '%m') AS name, COUNT(*) AS value FROM negative " +
+ "WHERE discoveryTime " +
+ "BETWEEN IF(DATE_SUB(#{endTime}, INTERVAL #{months} MONTH) < DATE_FORMAT(#{endTime}, '%Y-01-01'), " +
+ " DATE_FORMAT(#{endTime}, '%Y-01-01'), DATE_SUB(#{endTime}, " +
+ " INTERVAL #{months} MONTH)) " +
+ " AND #{endTime} " +
+ " AND checkStatus IN (1, 2) " +
+ "GROUP BY name " +
+ "ORDER BY value asc;")
+ List selectTrend(Date beginTime, Date endTime, Integer months);
}
\ No newline at end of file
diff --git a/src/main/java/com/biutag/supervision/mapper/NegativeMapper.java b/src/main/java/com/biutag/supervision/mapper/NegativeMapper.java
index efc6ad6..2e49a0e 100644
--- a/src/main/java/com/biutag/supervision/mapper/NegativeMapper.java
+++ b/src/main/java/com/biutag/supervision/mapper/NegativeMapper.java
@@ -104,51 +104,6 @@ public interface NegativeMapper extends BaseMapper {
// region 现场督察大屏
- /**
- * 获取现场督察和专项督察的通报问题数
- *
- * @param beginTime
- * @param endTime
- * @return
- */
- @Select("SELECT count(*) FROM negative WHERE checkStatus <> #{checkStatus} " +
- "AND problemSourcesCode IN (13, 15) " +
- "AND discoveryTime BETWEEN #{beginTime} AND #{endTime}")
- Long selectSupervisionNotifyCount(Date beginTime, Date endTime, String checkStatus);
-
-
- /**
- * 获取现场督察和专项督察属实的已经整改的问题数
- * @param beginTime
- * @param endTime
- * @return
- */
- @Select("SELECT count(*) FROM negative WHERE checkStatus <> #{checkStatus} " +
- "AND problemSourcesCode IN (13, 15) " +
- "AND isRectifyCode=#{isRectify}" +
- "AND discoveryTime BETWEEN #{beginTime} AND #{endTime}")
- Long selectChangSupervisionNotifyCount(Date beginTime, Date endTime, String checkStatus, String isRectify);
-
-
- /**
- * 获取现场督察和专项督察属实的涉及单位数
- *
- * @param beginTime
- * @param endTime
- * @return
- */
- @Select("SELECT count(*) FROM " +
- " ( SELECT DISTINCT involveDepartName FROM negative " +
- " WHERE checkStatus<>3 AND problemSourcesCode in (13, 15) AND discoveryTime " +
- " BETWEEN #{beginTime} AND #{endTime}" +
- " )" +
- "AS distinct_departments;")
- Long selectRelationOrgCount(Date beginTime, Date endTime, String checkStatus);
-
-
-
-
-
/**
* 获取现场督察按二级机构分组和整改状态划分的的问题数
*/
@@ -168,28 +123,11 @@ public interface NegativeMapper extends BaseMapper {
- @Select("SELECT count(*) FROM negative ng INNER JOIN " +
- "(SELECT sd.id, sd.pid, sd.`name`, sd1.short_name FROM sup_depart sd INNER JOIN sup_depart sd1 " +
- "ON sd.pid = sd1.id AND sd1.`level`=2 AND sd1.statistics_group_id=3) as temp " +
- "ON ng.involveDepartId=temp.id " +
- "AND pid=#{departId} " +
- "AND problemSourcesCode= 13 " +
- "AND checkStatus <> 3 " +
- "AND isRectifyCode =1 " +
- "AND discoveryTime BETWEEN #{beginTime} AND #{endTime}")
- Long getChangedCountByGroupType(Date beginTime, Date endTime, String departId);
-
-
-
- @Select("SELECT count(*) FROM negative ng INNER JOIN " +
- "(SELECT sd.id, sd.pid, sd.`name`, sd1.short_name FROM sup_depart sd INNER JOIN sup_depart sd1 " +
- "ON sd.pid = sd1.id AND sd1.`level`=2 AND sd1.statistics_group_id=3) as temp " +
- "ON ng.involveDepartId=temp.id " +
- "AND pid=#{departId} " +
- "AND problemSourcesCode= 13 " +
- "AND isRectifyCode =1 " +
- "AND discoveryTime BETWEEN #{beginTime} AND #{endTime}")
- Long getCountByGroupType(Date beginTime, Date endTime, String departId);
+
+
+
+
+
@Select("SELECT npr.oneLevelContent as name, count(*) value FROM negative ng, negative_problem_relation npr " +
"WHERE ng.id = npr.negativeId " +
@@ -201,41 +139,16 @@ public interface NegativeMapper extends BaseMapper {
List getProblemTypes(Date beginTime, Date endTime);
- @Select("SELECT DATE_FORMAT(discoveryTime, '%m') AS `name`, COUNT(*) AS `value` FROM negative " +
- "WHERE discoveryTime BETWEEN DATE_SUB(#{time}, INTERVAL 12 MONTH) AND #{time} " +
- "AND checkStatus <> 3 " +
- "AND problemSourcesCode in (13, 15) " +
- "GROUP BY DATE_FORMAT(discoveryTime, '%Y-%m') " +
- "ORDER BY DATE_FORMAT(discoveryTime, '%Y-%m');")
+ @Select("SELECT DATE_FORMAT(discoveryTime, '%m') AS `name`, COUNT(*) AS `value` FROM negative " +
+ "WHERE discoveryTime BETWEEN DATE_FORMAT(CONCAT(YEAR(#{time}), '-01-01'), '%Y-%m-%d') AND #{time} " +
+ " AND checkStatus <> 3 " +
+ " AND problemSourcesCode IN (13, 15) " +
+ "GROUP BY DATE_FORMAT(discoveryTime, '%Y-%m') " +
+ "ORDER BY DATE_FORMAT(discoveryTime, '%Y-%m'); ")
List getSupervisionTrend(String time);
- @Select("SELECT count(*) FROM negative ng INNER JOIN " +
- "(SELECT sd.id, sd.pid, sd.`name`, sd1.short_name FROM sup_depart sd INNER JOIN sup_depart sd1 " +
- "ON sd.pid = sd1.id AND sd1.`level`=2 AND sd1.statistics_group_id=3) as temp " +
- "ON ng.involveDepartId=temp.id " +
- "AND pid=#{departId} " +
- "AND problemSourcesCode in (13, 15) " +
- "AND checkStatus <> 3 " +
- "AND isRectifyCode =1 " +
- "AND discoveryTime BETWEEN #{beginTime} AND #{endTime}")
- Long getNotifyChanged(Date beginTime, Date endTime, String departId);
-
-
- @Select("SELECT count(*) FROM negative ng INNER JOIN " +
- "(SELECT sd.id, sd.pid, sd.`name`, sd1.short_name FROM sup_depart sd INNER JOIN sup_depart sd1 " +
- "ON sd.pid = sd1.id AND sd1.`level`=2 AND sd1.statistics_group_id=3) as temp " +
- "ON ng.involveDepartId=temp.id " +
- "AND pid=#{departId} " +
- "AND problemSourcesCode in (13, 15) " +
- "AND checkStatus <> 3 " +
- "AND isRectifyCode =0 " +
- "AND discoveryTime BETWEEN #{beginTime} AND #{endTime}")
- Long getNotifyChanging(Date beginTime, Date endTime, String departId);
-
- @Select("")
- Long getRelationOrgCountByDepartId(String departId);
@Select("SELECT a.departId, a.name, COUNT(DISTINCT c.id) AS totalPro, COUNT(DISTINCT IF(c.isRectifyCode = 0, c.id, 0)) - 1 AS changing, COUNT(DISTINCT IF(c.isRectifyCode = 1, c.id, 0)) - 1 AS changed, COUNT(DISTINCT c.involveDepartId) AS relationOrg, COUNT(DISTINCT d.blameIdCode) AS personNum, ROUND((COUNT(DISTINCT IF(c.isRectifyCode = 1, c.id, 0)) - 1) / COUNT(DISTINCT c.id) * 100, 1) AS changedRate\n" +
"FROM statistics_depart a INNER JOIN sup_depart b ON a.departId = b.pid " +
@@ -245,6 +158,13 @@ public interface NegativeMapper extends BaseMapper {
"GROUP BY a.name, a.departId")
List getMap(Date beginTime, Date endTime);
+
+ /**
+ * 黄赌毒总览
+ * @param beginTime
+ * @param endTime
+ * @return
+ */
@Select("SELECT a.name , " +
"COUNT(DISTINCT c.id) AS problem_number, " +
"COUNT(DISTINCT IF(c.isRectifyCode = 0, c.id, 0)) - 1 AS rectifing_number, " +
@@ -293,6 +213,12 @@ public interface NegativeMapper extends BaseMapper {
RankVoSupTwo getTemp(Date beginTime, Date endTime);
+ @Select("SELECT COUNT(DISTINCT c.id) AS problem_number, COUNT(DISTINCT IF(c.isRectifyCode = 0, c.id, 0)) - 1 AS rectifing_number, COUNT(DISTINCT IF(c.isRectifyCode = 1, c.id, 0)) - 1 AS rectifed_number, COUNT(DISTINCT c.involveDepartId) AS depart_number, COUNT(DISTINCT d.blameIdCode) AS person_number, ROUND((COUNT(DISTINCT IF(c.isRectifyCode = 1, c.id, 0)) - 1) / COUNT(DISTINCT c.id) * 100, 1) AS rectify_rate\n" +
+ "FROM sup_depart b INNER JOIN negative c ON b.id = c.involveDepartId " +
+ " LEFT JOIN negative_blame d ON c.id = d.negativeId " +
+ "WHERE discoveryTime BETWEEN #{beginTime} AND #{endTime} AND checkStatus IN ('1', '2') AND special_supervision = 1 ")
+ RankVoSup getYellowBetOverview(Date beginTime, Date endTime);
+
// endregion
}
diff --git a/src/main/java/com/biutag/supervision/service/DataPetition12337Service.java b/src/main/java/com/biutag/supervision/service/DataPetition12337Service.java
index 1529c1e..8d24795 100644
--- a/src/main/java/com/biutag/supervision/service/DataPetition12337Service.java
+++ b/src/main/java/com/biutag/supervision/service/DataPetition12337Service.java
@@ -69,7 +69,6 @@ public class DataPetition12337Service extends ServiceImpl getYellowBet(Date beginTime, Date endTime) {
List res = negativeMapper.getYellowBet(beginTime, endTime);
-
List resv = new ArrayList<>();
if (res == null) {
return resv;
@@ -180,6 +178,23 @@ public class DataSupervisionNotifyServiceImpl extends ServiceImpl param, Map header) {
+ long time = System.currentTimeMillis();
+ URIBuilder builder;
+ HttpGet httpGet;
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setCookieSpec(CookieSpecs.STANDARD)
+ .setConnectionRequestTimeout(120000)
+ .setSocketTimeout(120000)
+ .setConnectTimeout(120000).build();
+ try {
+ builder = new URIBuilder(url);
+ for (Map.Entry entry : param.entrySet()) {
+ builder.addParameter(entry.getKey(), entry.getValue());
+ }
+ URI uri = builder.build();
+ httpGet = new HttpGet(uri);
+ httpGet.setConfig(requestConfig);
+ for (Map.Entry entry : header.entrySet()) {
+ httpGet.setHeader(entry.getKey(), entry.getValue());
+ }
+
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ return null;
+ }
+ try {
+ SslUtil.ignoreSsl();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ // 创建Httpclient对象
+ try (CloseableHttpClient httpclient = createSSLClientDefault();
+ CloseableHttpResponse response = httpclient.execute(httpGet)) {
+ // 判断返回状态是否为200
+ if (response.getStatusLine().getStatusCode() == 200) {
+ log.info("{}ms", System.currentTimeMillis() - time);
+ return EntityUtils.toString(response.getEntity(), "UTF-8");
+ }
+ log.info("{}", response.getStatusLine().getStatusCode());
+ return null;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static CloseableHttpClient createSSLClientDefault() {
+ try {
+ //使用 loadTrustMaterial() 方法实现一个信任策略,信任所有证书
+ // 信任所有
+ SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true).build();
+ //NoopHostnameVerifier类: 作为主机名验证工具,实质上关闭了主机名验证,它接受任何
+ //有效的SSL会话并匹配到目标主机。
+ HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
+ SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
+ return HttpClients.custom().setSSLSocketFactory(sslsf).build();
+ } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
+ e.printStackTrace();
+ }
+ return HttpClients.createDefault();
+
+ }
+
+ public static Boolean doDelete(String url, Map header) {
+ URIBuilder builder;
+ HttpDelete httpGet;
+ try {
+ builder = new URIBuilder(url);
+ URI uri = builder.build();
+ httpGet = new HttpDelete(uri);
+ for (Map.Entry entry : header.entrySet()) {
+ httpGet.setHeader(entry.getKey(), entry.getValue());
+ }
+ } catch (URISyntaxException e) {
+ log.error("exception message", e);
+ return null;
+ }
+ // 创建Httpclient对象
+ try (CloseableHttpClient httpclient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpclient.execute(httpGet)) {
+ // 判断返回状态是否为200
+ return response.getStatusLine().getStatusCode() == 200;
+ } catch (Exception e) {
+ log.error("exception message", e);
+ return false;
+ }
+ }
+
+ public static String doGetResponseHead(String url,Map header,String headKey) {
+ URIBuilder builder;
+ HttpGet httpGet;
+ try {
+ builder = new URIBuilder(url);
+ URI uri = builder.build();
+ httpGet = new HttpGet(uri);
+ for (Map.Entry entry : header.entrySet()) {
+ httpGet.setHeader(entry.getKey(), entry.getValue());
+ }
+ } catch (URISyntaxException e) {
+ log.error("exception message", e);
+ return null;
+ }
+ // 创建Httpclient对象
+ try (CloseableHttpClient httpclient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpclient.execute(httpGet)) {
+ // 判断返回状态是否为200
+ if (response.getStatusLine().getStatusCode() == 200) {
+ return response.getFirstHeader(headKey).getValue();
+ }
+ return null;
+ } catch (Exception e) {
+ log.error("exception message", e);
+ return null;
+ }
+ }
+
+ public static String doGet(String url, Map header) {
+ return doGet(url, new HashMap<>(0), header);
+ }
+
+ public static String doPost(String url, Map param, Map headers) {
+ HttpPost httpPost = new HttpPost(url);
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setCookieSpec(CookieSpecs.STANDARD)
+ .setConnectionRequestTimeout(120000)
+ .setSocketTimeout(120000)
+ .setConnectTimeout(120000).build();
+ httpPost.setConfig(requestConfig);
+ // 创建参数列表
+ List paramList = new ArrayList<>();
+ for (Map.Entry entry : param.entrySet()) {
+ paramList.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+ }
+ if(!paramList.isEmpty()) {
+ try {
+ httpPost.setEntity(new UrlEncodedFormEntity(paramList));
+ } catch (UnsupportedEncodingException e) {
+ log.error("exception message", e);
+ return null;
+ }
+ }
+ for (Map.Entry entry : headers.entrySet()) {
+ httpPost.setHeader(entry.getKey(), entry.getValue());
+ }
+ // 创建Httpclient对象
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(httpPost)) {
+ return EntityUtils.toString(response.getEntity(), "utf-8");
+ } catch (Exception e) {
+ log.error("exception message", e);
+ return null;
+ }
+ }
+
+ public static String doPostJson(String url, String json, Map map) {
+ long time = System.currentTimeMillis();
+ HttpPost httpPost = new HttpPost(url);
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setCookieSpec(CookieSpecs.STANDARD)
+ .setConnectionRequestTimeout(120000)
+ .setSocketTimeout(120000)
+ .setConnectTimeout(120000).build();
+ httpPost.setConfig(requestConfig);
+ for (Map.Entry entry : map.entrySet()) {
+ httpPost.setHeader(entry.getKey(), entry.getValue());
+ }
+ log.info("请求body: {}",json);
+ httpPost.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
+ // 创建Httpclient对象
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(httpPost)) {
+ log.info("{}ms", System.currentTimeMillis() - time);
+ return EntityUtils.toString(response.getEntity(), "utf-8");
+ } catch (Exception e) {
+ log.error("exception message", e);
+ return null;
+ }
+ }
+
+ public static String doPostJsonCmcc(String url, String json, HttpHeaders headers) {
+ long time = System.currentTimeMillis();
+ HttpPost httpPost = new HttpPost(url);
+
+// httpPost.setHeader("Authorization", map.get("Authorization"));
+// httpPost.setHeader("X-Req-Time", map.get("X-Req-Time"));
+// httpPost.setHeader("X-Req-Version", map.get("X-Req-Version"));
+// httpPost.setHeader("X-Req-AppId", map.get("X-Req-AppId"));
+// httpPost.setHeader("X-Req-ClientIP", map.get("X-Req-ClientIP"));
+// httpPost.setHeader("X-Req-SignType", map.get("X-Req-SignType"));
+// httpPost.setHeader("X-Req-Seq", map.get("X-Req-Seq"));
+// httpPost.setHeader("Content-Type", "application/json");
+// httpPost.setHeader("X-Req-Hmac", map.get("X-Req-Hmac"));
+ for (Header header : httpPost.getAllHeaders()) {
+ System.out.println(header.getName() + ": " + header.getValue());
+ }
+ log.info(json);
+ httpPost.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
+ // 创建Httpclient对象
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(httpPost)) {
+
+ log.info("{}ms", System.currentTimeMillis() - time);
+ return EntityUtils.toString(response.getEntity(), "utf-8");
+ } catch (Exception e) {
+ log.error("exception message", e);
+ return null;
+ }
+ }
+
+ public static Boolean doPostJsonEmpty(String url, String json, Map map) {
+ HttpPost httpPost = new HttpPost(url);
+ for (Map.Entry entry : map.entrySet()) {
+ httpPost.setHeader(entry.getKey(), entry.getValue());
+ }
+ httpPost.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
+ // 创建Httpclient对象
+ try (CloseableHttpClient httpClient = HttpClients.createDefault();
+ CloseableHttpResponse response = httpClient.execute(httpPost)) {
+ if (response.getStatusLine().getStatusCode() == 200) {
+ return true;
+ }
+ } catch (Exception e) {
+ log.error("exception message", e);
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/com/biutag/supervision/util/SslUtil.java b/src/main/java/com/biutag/supervision/util/SslUtil.java
new file mode 100644
index 0000000..b0facae
--- /dev/null
+++ b/src/main/java/com/biutag/supervision/util/SslUtil.java
@@ -0,0 +1,64 @@
+package com.biutag.supervision.util;
+
+import lombok.experimental.UtilityClass;
+
+import javax.net.ssl.*;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+/**
+ * @author kami on 2024-02-07 11:17:09
+ * @version 0.0.1
+ * @since 1.8
+ */
+@UtilityClass
+public class SslUtil {
+
+ private static void trustAllHttpsCertificates() throws Exception {
+ TrustManager[] trustAllCerts = new TrustManager[1];
+ TrustManager tm = new miTM();
+ trustAllCerts[0] = tm;
+ SSLContext sc = SSLContext.getInstance("SSL");
+ sc.init(null, trustAllCerts, null);
+ HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
+ }
+
+ static class miTM implements TrustManager, X509TrustManager {
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+
+ public boolean isServerTrusted(X509Certificate[] certs) {
+ return true;
+ }
+
+ public boolean isClientTrusted(X509Certificate[] certs) {
+ return true;
+ }
+
+ public void checkServerTrusted(X509Certificate[] certs, String authType)
+ throws CertificateException {
+ return;
+ }
+
+ public void checkClientTrusted(X509Certificate[] certs, String authType)
+ throws CertificateException {
+ return;
+ }
+ }
+
+ /**
+ * 忽略HTTPS请求的SSL证书,必须在openConnection之前调用
+ * @throws Exception
+ */
+ public static void ignoreSsl() throws Exception{
+ HostnameVerifier hv = new HostnameVerifier() {
+ public boolean verify(String urlHostName, SSLSession session) {
+ System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
+ return true;
+ }
+ };
+ trustAllHttpsCertificates();
+ HttpsURLConnection.setDefaultHostnameVerifier(hv);
+ }
+}