Browse Source

案件核查趋势

main
parent
commit
d2b1ed4fd1
  1. 9
      pom.xml
  2. 14
      src/main/java/com/biutag/supervision/controller/datav/DataVCaseVerifController.java
  3. 67
      src/main/java/com/biutag/supervision/controller/datav/PoliceComment.java
  4. 8
      src/main/java/com/biutag/supervision/controller/datav/SupervisionNotifyController.java
  5. 11
      src/main/java/com/biutag/supervision/mapper/DataCaseVerifMapper.java
  6. 122
      src/main/java/com/biutag/supervision/mapper/NegativeMapper.java
  7. 1
      src/main/java/com/biutag/supervision/service/DataPetition12337Service.java
  8. 19
      src/main/java/com/biutag/supervision/service/DataSupervisionNotifyServiceImpl.java
  9. 276
      src/main/java/com/biutag/supervision/util/HttpClientUtil.java
  10. 64
      src/main/java/com/biutag/supervision/util/SslUtil.java

9
pom.xml

@ -30,6 +30,15 @@
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

14
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<JSONObject> caseVerifTrend(
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
@RequestParam Integer month) {
List<EchartsVo> ajhcqsList = dataCaseVerifMapper.selectTrend(beginTime, endTime, 12);
JSONObject data = new JSONObject().fluentPut("ajhcqsList", ajhcqsList);
return Result.success(data);
}
}

67
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<JSONObject> getDCQK() {
Map<String, String> params = new HashMap<>();
params.put("PeriodId", "6");
params.put("PeriodSonID", "-1");
params.put("OrgNo", "4304");
Map<String, String> 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<JSONObject> getBMYYBQS(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime) {
Map<String, String> 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<JSONObject> getGetZHMYLPM(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime) {
Map<String, String> 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<JSONObject> getRCSQQK(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime){
Map<String, String> 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();
}
}

8
src/main/java/com/biutag/supervision/controller/datav/SupervisionNotifyController.java

@ -53,15 +53,16 @@ public class SupervisionNotifyController {
// 黄赌毒总览
// List<RankVo> hddzlList = dataSupervisionNotifyService.getYellowBet(beginTime, endTime);
JSONObject hddOverview = dataSupervisionNotifyService.getYellowBetOverview(beginTime, endTime);
// // 黄毒赌列表
// 黄毒赌列表
List<RankVo> 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);
}
}

11
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<DataCaseVerif> {
@Select("select problem_sources name, count(originId) value from data_case_verif where discovery_time between #{beginTime} and #{endTime} group by problem_sources")
List<PieItem> 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<EchartsVo> selectTrend(Date beginTime, Date endTime, Integer months);
}

122
src/main/java/com/biutag/supervision/mapper/NegativeMapper.java

@ -104,51 +104,6 @@ public interface NegativeMapper extends BaseMapper<Negative> {
// 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<Negative> {
@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<Negative> {
List<EchartsVo> 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<EchartsVo> 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<Negative> {
"GROUP BY a.name, a.departId")
List<SuperviseMapIconVo> 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<Negative> {
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
}

1
src/main/java/com/biutag/supervision/service/DataPetition12337Service.java

@ -69,7 +69,6 @@ public class DataPetition12337Service extends ServiceImpl<DataPetition12337Mappe
negativeDto.setDiscoveryTime(item.getDiscoverTime());
negativeDto.setProblemSourcesCode("24");
negativeDto.setProblemSources("12337信访");
// negativeDto.setBusinessTypeCode(BusinessTypeEnum.ABWW);
// negativeDto.setBusinessTypeName();
negativeDto.setResponderName(item.getName());

19
src/main/java/com/biutag/supervision/service/DataSupervisionNotifyServiceImpl.java

@ -57,7 +57,6 @@ public class DataSupervisionNotifyServiceImpl extends ServiceImpl<DataSupervisio
if (res == null) {
return null;
}
// 通报问题数
String supervisionNotifyTotal = res.getProblemNumber();
log.info("通报问题数:{}", res.getProblemNumber());
@ -157,7 +156,6 @@ public class DataSupervisionNotifyServiceImpl extends ServiceImpl<DataSupervisio
public List<RankVo> getYellowBet(Date beginTime, Date endTime) {
List<RankVoSupTwo> res = negativeMapper.getYellowBet(beginTime, endTime);
List<RankVo> resv = new ArrayList<>();
if (res == null) {
return resv;
@ -180,6 +178,23 @@ public class DataSupervisionNotifyServiceImpl extends ServiceImpl<DataSupervisio
}
return res;
}
public JSONObject getYellowBetOverview(Date beginTime, Date endTime) {
RankVoSup res = negativeMapper.getYellowBetOverview(beginTime, endTime);
if (res != null) {
return new JSONObject()
.fluentPut("proTotal", res.getProblemNumber())
.fluentPut("changing", res.getRectifingNumber())
.fluentPut("changed", res.getRectifedNumber())
.fluentPut("correctionRate", res.getRectifyRate());
}else {
return new JSONObject()
.fluentPut("problemNumber", "0")
.fluentPut("changing", "0")
.fluentPut("changed", "0")
.fluentPut("correctionRate", "0");
}
}
}

276
src/main/java/com/biutag/supervision/util/HttpClientUtil.java

@ -0,0 +1,276 @@
package com.biutag.supervision.util;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author kami
* @since 21:48 2020/10/19
*/
@Slf4j
@UtilityClass
public class HttpClientUtil {
public static String doGet(String url, Map<String, String> param, Map<String, String> 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<String, String> entry : param.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue());
}
URI uri = builder.build();
httpGet = new HttpGet(uri);
httpGet.setConfig(requestConfig);
for (Map.Entry<String, String> 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<String, String> header) {
URIBuilder builder;
HttpDelete httpGet;
try {
builder = new URIBuilder(url);
URI uri = builder.build();
httpGet = new HttpDelete(uri);
for (Map.Entry<String, String> 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<String, String> header,String headKey) {
URIBuilder builder;
HttpGet httpGet;
try {
builder = new URIBuilder(url);
URI uri = builder.build();
httpGet = new HttpGet(uri);
for (Map.Entry<String, String> 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<String, String> header) {
return doGet(url, new HashMap<>(0), header);
}
public static String doPost(String url, Map<String, String> param, Map<String, String> headers) {
HttpPost httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD)
.setConnectionRequestTimeout(120000)
.setSocketTimeout(120000)
.setConnectTimeout(120000).build();
httpPost.setConfig(requestConfig);
// 创建参数列表
List<NameValuePair> paramList = new ArrayList<>();
for (Map.Entry<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> map) {
HttpPost httpPost = new HttpPost(url);
for (Map.Entry<String, String> 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;
}
}

64
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);
}
}
Loading…
Cancel
Save