微调
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -170,6 +170,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<finalName>jb_syncdata</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.njcn.jbsyncdata.component;
|
||||||
|
|
||||||
|
|
||||||
|
import com.njcn.jbsyncdata.pojo.result.TokenResult;
|
||||||
|
import com.njcn.jbsyncdata.util.RestTemplateUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class TokenComponent {
|
||||||
|
|
||||||
|
@Value("${jibei.client_id}")
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
@Value("${jibei.client_secret}")
|
||||||
|
private String clientSecret;
|
||||||
|
|
||||||
|
@Value("${jibei.grant_type}")
|
||||||
|
private String grantType;
|
||||||
|
|
||||||
|
@Value("${jibei.url}")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
|
||||||
|
public TokenResult getTokenWithRestTemplate() {
|
||||||
|
RestTemplateUtil restTemplateUtil = new RestTemplateUtil();
|
||||||
|
ResponseEntity<TokenResult> userEntity = restTemplateUtil.post(url.concat("/psr-auth/oauth/accessToken?client_id=" + clientId + "&client_secret=" + clientSecret + "&grant_type=" + grantType), TokenResult.class);
|
||||||
|
//返回状态不正常返回空
|
||||||
|
log.info("getTokenWithRestTemplate获取token结束,结果为:{}", userEntity);
|
||||||
|
if (userEntity.getStatusCodeValue() == 200 && userEntity.getBody().getStatus().equalsIgnoreCase("000000")) {
|
||||||
|
return userEntity.getBody();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.njcn.jbsyncdata.controller;
|
package com.njcn.jbsyncdata.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.njcn.jbsyncdata.pojo.DisPhotovoltaic10Excel;
|
import com.njcn.jbsyncdata.pojo.DisPhotovoltaic10Excel;
|
||||||
import com.njcn.jbsyncdata.pojo.DisPhotovoltaic380Excel;
|
import com.njcn.jbsyncdata.pojo.DisPhotovoltaic380Excel;
|
||||||
|
import com.njcn.jbsyncdata.pojo.ExcelData;
|
||||||
|
import com.njcn.jbsyncdata.service.IBusinessService;
|
||||||
|
import com.njcn.jbsyncdata.util.StreamUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -13,6 +17,11 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wr
|
* @author wr
|
||||||
@@ -26,14 +35,21 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DisPhotovoltaicController {
|
public class DisPhotovoltaicController {
|
||||||
|
|
||||||
|
private final IBusinessService businessService;
|
||||||
|
|
||||||
@ApiOperation(value = "获取10kv分布式光伏接入情况")
|
@ApiOperation(value = "获取10kv分布式光伏接入情况")
|
||||||
@PostMapping("/import10")
|
@PostMapping("/import10")
|
||||||
public void importTakeOrder(MultipartFile file) throws Exception {
|
public void importTakeOrder(MultipartFile file) throws Exception {
|
||||||
List<DisPhotovoltaic10Excel> list = EasyExcel.read(file.getInputStream())
|
List<ExcelData> list = EasyExcel.read(file.getInputStream())
|
||||||
.head(DisPhotovoltaic10Excel.class)
|
.head(ExcelData.class)
|
||||||
.headRowNumber(2)
|
.headRowNumber(2)
|
||||||
.sheet(2).doReadSync();
|
.sheet(2).doReadSync();
|
||||||
|
//排重
|
||||||
|
list = list.stream()
|
||||||
|
.filter(t -> StrUtil.isNotBlank(t.getGenerationUserID()))
|
||||||
|
.filter(StreamUtil.distinctByKey(ExcelData::getGenerationUserID))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
businessService.testInterfaceByUserId(list);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,12 +57,21 @@ public class DisPhotovoltaicController {
|
|||||||
@ApiOperation(value = "获取380kv分布式光伏接入情况")
|
@ApiOperation(value = "获取380kv分布式光伏接入情况")
|
||||||
@PostMapping("/import380")
|
@PostMapping("/import380")
|
||||||
public void import380(MultipartFile file) throws Exception {
|
public void import380(MultipartFile file) throws Exception {
|
||||||
List<DisPhotovoltaic380Excel> list = EasyExcel.read(file.getInputStream())
|
List<ExcelData> list = EasyExcel.read(file.getInputStream())
|
||||||
.head(DisPhotovoltaic380Excel.class)
|
.head(ExcelData.class)
|
||||||
.headRowNumber(2)
|
.headRowNumber(2)
|
||||||
.sheet(3).doReadSync();
|
.sheet(3).doReadSync();
|
||||||
|
//排重
|
||||||
|
list = list.stream()
|
||||||
|
.filter(t -> StrUtil.isNotBlank(t.getGenerationUserID()))
|
||||||
|
.filter(StreamUtil.distinctByKey(ExcelData::getGenerationUserID))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
businessService.testInterfaceByUserId(list);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.njcn.jbsyncdata.controller;
|
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@Api(tags = "首页模块")
|
|
||||||
@RestController
|
|
||||||
public class IndexController {
|
|
||||||
|
|
||||||
@ApiImplicitParam(name = "name",value = "姓名",required = true)
|
|
||||||
@ApiOperation(value = "向客人问好")
|
|
||||||
@GetMapping("/sayHi")
|
|
||||||
public ResponseEntity<String> sayHi(@RequestParam(value = "name")String name){
|
|
||||||
return ResponseEntity.ok("Hi:"+name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.njcn.jbsyncdata.controller;
|
||||||
|
|
||||||
|
import com.njcn.jbsyncdata.component.TokenComponent;
|
||||||
|
import com.njcn.jbsyncdata.pojo.result.TokenResult;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "冀北获取token")
|
||||||
|
@RequestMapping("/oauth")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class TokenController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TokenComponent tokenComponent;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "测试获取token")
|
||||||
|
@PostMapping("/testToken")
|
||||||
|
public TokenResult testToken() {
|
||||||
|
return tokenComponent.getTokenWithRestTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
23
src/main/java/com/njcn/jbsyncdata/pojo/ExcelData.java
Normal file
23
src/main/java/com/njcn/jbsyncdata/pojo/ExcelData.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package com.njcn.jbsyncdata.pojo;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ExcelData implements Serializable {
|
||||||
|
|
||||||
|
@ExcelProperty(value = "发电客户编号")
|
||||||
|
private String generationUserID;
|
||||||
|
|
||||||
|
@ExcelProperty(value = "发电客户名称")
|
||||||
|
private String generationUserName;
|
||||||
|
|
||||||
|
@ExcelProperty(value = "台区编号")
|
||||||
|
private String stageID;
|
||||||
|
|
||||||
|
@ExcelProperty(value = "台区名称")
|
||||||
|
private String stageName;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.njcn.jbsyncdata.pojo.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DataResult implements Serializable {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.njcn.jbsyncdata.pojo.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token数据响应体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TokenResult implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
|
private String errors;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private Integer expires_in;
|
||||||
|
|
||||||
|
private String access_token;
|
||||||
|
|
||||||
|
private String refresh_token;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.njcn.jbsyncdata.service;
|
||||||
|
|
||||||
|
import com.njcn.jbsyncdata.pojo.ExcelData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IBusinessService {
|
||||||
|
void testInterface(List<ExcelData> list);
|
||||||
|
|
||||||
|
void testInterfaceByUserId(List<ExcelData> list);
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package com.njcn.jbsyncdata.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.njcn.jbsyncdata.component.TokenComponent;
|
||||||
|
import com.njcn.jbsyncdata.pojo.ExcelData;
|
||||||
|
import com.njcn.jbsyncdata.pojo.result.TokenResult;
|
||||||
|
import com.njcn.jbsyncdata.service.IBusinessService;
|
||||||
|
import com.njcn.jbsyncdata.util.RestTemplateUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class BusinessServiceImpl implements IBusinessService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TokenComponent tokenComponent;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void testInterface(List<ExcelData> list) {
|
||||||
|
RestTemplateUtil restTemplateUtil = new RestTemplateUtil();
|
||||||
|
TokenResult tokenWithRestTemplate = tokenComponent.getTokenWithRestTemplate();
|
||||||
|
if (null == tokenWithRestTemplate) {
|
||||||
|
log.error("token信息没有获取到");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JSONObject jsonObject;
|
||||||
|
JSONObject jsonObjectSub;
|
||||||
|
for (ExcelData excelData : list) {
|
||||||
|
jsonObject = JSONUtil.createObj();
|
||||||
|
jsonObjectSub = JSONUtil.createObj();
|
||||||
|
jsonObject.set("page", 1);
|
||||||
|
jsonObject.set("perPage", 50);
|
||||||
|
List<String> psrIds = Stream.of(excelData.getStageID()).collect(Collectors.toList());
|
||||||
|
jsonObjectSub.set("psrIds", psrIds);
|
||||||
|
jsonObjectSub.set("psrType", "0401004");
|
||||||
|
jsonObjectSub.set("astIds", new ArrayList<>());
|
||||||
|
jsonObjectSub.set("astType", "");
|
||||||
|
jsonObjectSub.set("termIds", new ArrayList<>());
|
||||||
|
jsonObjectSub.set("termType", "");
|
||||||
|
jsonObjectSub.set("measPointIds", new ArrayList<>());
|
||||||
|
jsonObject.set("filter", jsonObjectSub);
|
||||||
|
if (excelData.getStageID().equalsIgnoreCase("1502760751")) {
|
||||||
|
log.error("组装后的json为:{}", jsonObject);
|
||||||
|
}
|
||||||
|
//组装好json开始发送请求
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
headers.put("x-token", tokenWithRestTemplate.getAccess_token());
|
||||||
|
ResponseEntity<String> response = restTemplateUtil.post(tokenComponent.getUrl().concat("/realMeasCenter/measPoint/commonQuery"), headers, jsonObject, String.class);
|
||||||
|
log.error("请求接口,台区号为:{},结果为:{}", excelData.getStageID(), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void testInterfaceByUserId(List<ExcelData> list) {
|
||||||
|
RestTemplateUtil restTemplateUtil = new RestTemplateUtil();
|
||||||
|
TokenResult tokenWithRestTemplate = tokenComponent.getTokenWithRestTemplate();
|
||||||
|
if (null == tokenWithRestTemplate) {
|
||||||
|
log.error("token信息没有获取到");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JSONObject jsonObject;
|
||||||
|
JSONObject jsonObjectSub;
|
||||||
|
for (ExcelData excelData : list) {
|
||||||
|
jsonObject = JSONUtil.createObj();
|
||||||
|
jsonObjectSub = JSONUtil.createObj();
|
||||||
|
jsonObject.set("page", 1);
|
||||||
|
jsonObject.set("perPage", 50);
|
||||||
|
jsonObject.set("startTime", "2023-10-07 00:00:00");
|
||||||
|
jsonObject.set("endTime", "2023-10-07 23:59:59");
|
||||||
|
List<String> userId = Stream.of("160".concat(excelData.getGenerationUserID())).collect(Collectors.toList());
|
||||||
|
jsonObjectSub.set("consNos", userId);
|
||||||
|
jsonObjectSub.set("consType", 3);
|
||||||
|
|
||||||
|
jsonObjectSub.set("astIds", new ArrayList<>());
|
||||||
|
jsonObjectSub.set("astType", "");
|
||||||
|
jsonObjectSub.set("psrIds", new ArrayList<>());
|
||||||
|
jsonObjectSub.set("psrType", "");
|
||||||
|
jsonObjectSub.set("measPointIds", new ArrayList<>());
|
||||||
|
List<String> typeList = Stream.of("PhV_phsA","PhV_phsB","PhV_phsC").collect(Collectors.toList());
|
||||||
|
jsonObjectSub.set("telemetryTypes", typeList);
|
||||||
|
jsonObject.set("filter", jsonObjectSub);
|
||||||
|
if (excelData.getStageID().equalsIgnoreCase("2226675026")) {
|
||||||
|
log.error("组装后的json为:{}", jsonObject);
|
||||||
|
}
|
||||||
|
//组装好json开始发送请求
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
headers.put("x-token", tokenWithRestTemplate.getAccess_token());
|
||||||
|
ResponseEntity<String> response = restTemplateUtil.post(tokenComponent.getUrl().concat("/realMeasCenter/measPoint/commonQuery"), headers, jsonObject, String.class);
|
||||||
|
log.error("请求接口,台区号为:{},结果为:{}", excelData.getStageID(), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
636
src/main/java/com/njcn/jbsyncdata/util/RestTemplateUtil.java
Normal file
636
src/main/java/com/njcn/jbsyncdata/util/RestTemplateUtil.java
Normal file
@@ -0,0 +1,636 @@
|
|||||||
|
package com.njcn.jbsyncdata.util;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hongawen
|
||||||
|
* package javax.utils;
|
||||||
|
* @createDate 2019-02-08
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RestTemplateUtil {
|
||||||
|
|
||||||
|
private static final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
// ----------------------------------GET-------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> get(String url, Class<T> responseType) {
|
||||||
|
return restTemplate.getForEntity(url, responseType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> get(String url, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return restTemplate.getForEntity(url, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> get(String url, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
return restTemplate.getForEntity(url, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的GET请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> get(String url, Map<String, String> headers, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return get(url, httpHeaders, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的GET请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> get(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
|
||||||
|
return exchange(url, HttpMethod.GET, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的GET请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> get(String url, Map<String, String> headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return get(url, httpHeaders, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的GET请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> get(String url, HttpHeaders headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
|
||||||
|
return exchange(url, HttpMethod.GET, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------POST-------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, Class<T> responseType) {
|
||||||
|
return restTemplate.postForEntity(url, HttpEntity.EMPTY, responseType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param uri 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(URI uri, Class<T> responseType) {
|
||||||
|
return restTemplate.exchange(uri,HttpMethod.POST, HttpEntity.EMPTY, responseType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType) {
|
||||||
|
return restTemplate.postForEntity(url, requestBody, responseType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return post(url, httpHeaders, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
|
||||||
|
return post(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return post(url, httpHeaders, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
|
||||||
|
return post(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义请求头和请求体的POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return restTemplate.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义请求头和请求体的POST请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
return restTemplate.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------PUT-------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return put(url, HttpEntity.EMPTY, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
|
||||||
|
return put(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
|
||||||
|
return put(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return put(url, httpHeaders, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
|
||||||
|
return put(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return put(url, httpHeaders, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
|
||||||
|
return put(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义请求头和请求体的PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return restTemplate.exchange(url, HttpMethod.PUT, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义请求头和请求体的PUT请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
return restTemplate.exchange(url, HttpMethod.PUT, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------DELETE-------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
|
||||||
|
return delete(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
|
||||||
|
return delete(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return delete(url, httpHeaders, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
|
||||||
|
return delete(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return delete(url, httpHeaders, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
|
||||||
|
return delete(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return delete(url, httpHeaders, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
|
||||||
|
return delete(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setAll(headers);
|
||||||
|
return delete(url, httpHeaders, requestBody, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带请求头的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param headers 请求头参数
|
||||||
|
* @param requestBody 请求参数体
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
|
||||||
|
return delete(url, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义请求头和请求体的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义请求头和请求体的DELETE请求调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
return restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------通用方法-------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param method 请求方法类型
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,按顺序依次对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
||||||
|
return restTemplate.exchange(url, method, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用调用方式
|
||||||
|
*
|
||||||
|
* @param url 请求URL
|
||||||
|
* @param method 请求方法类型
|
||||||
|
* @param requestEntity 请求头和请求体封装对象
|
||||||
|
* @param responseType 返回对象类型
|
||||||
|
* @param uriVariables URL中的变量,与Map中的key对应
|
||||||
|
* @return ResponseEntity 响应对象封装类
|
||||||
|
*/
|
||||||
|
public static <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
||||||
|
return restTemplate.exchange(url, method, requestEntity, responseType, uriVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取RestTemplate实例对象,可自由调用其方法
|
||||||
|
*
|
||||||
|
* @return RestTemplate实例对象
|
||||||
|
*/
|
||||||
|
public static RestTemplate getRestTemplate() {
|
||||||
|
return restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
19
src/main/java/com/njcn/jbsyncdata/util/StreamUtil.java
Normal file
19
src/main/java/com/njcn/jbsyncdata/util/StreamUtil.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.njcn.jbsyncdata.util;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class StreamUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对对象过滤属性重复
|
||||||
|
*/
|
||||||
|
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||||
|
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||||
|
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,27 +1,24 @@
|
|||||||
server:
|
server:
|
||||||
port: 10288
|
port: 10288
|
||||||
|
tomcat:
|
||||||
|
max-swallow-size: 100MB #重要的一行,修改tomcat的吞吐量
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: jbsyncdata
|
name: hbsyncdata
|
||||||
#???????
|
#数据库内容配置
|
||||||
datasource:
|
datasource:
|
||||||
druid:
|
druid:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# url: jdbc:mysql://101.132.25.239:13306/pqsinfo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=CTT&rewriteBatchedStatements=true
|
url: jdbc:mysql://101.132.25.239:13306/pqsinfo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=CTT&rewriteBatchedStatements=true
|
||||||
url: jdbc:mysql://192.168.1.18:13306/pqsinfo_pmscs?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
|
||||||
username: root
|
username: root
|
||||||
password: njcnpqs
|
password: njcnpqs
|
||||||
# url: jdbc:mysql://localhost:3306/info?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT
|
#初始化建立物理连接的个数、最小、最大连接数
|
||||||
# username: root
|
|
||||||
# password: root
|
|
||||||
|
|
||||||
#?????????????????????
|
|
||||||
initial-size: 5
|
initial-size: 5
|
||||||
min-idle: 5
|
min-idle: 5
|
||||||
max-active: 50
|
max-active: 50
|
||||||
#???????????????
|
#获取连接最大等待时间,单位毫秒
|
||||||
max-wait: 60000
|
max-wait: 60000
|
||||||
#?????????????????????
|
#链接保持空间而不被驱逐的最长时间,单位毫秒
|
||||||
min-evictable-idle-time-millis: 300000
|
min-evictable-idle-time-millis: 300000
|
||||||
validation-query: select 1
|
validation-query: select 1
|
||||||
test-while-idle: true
|
test-while-idle: true
|
||||||
@@ -34,31 +31,35 @@ spring:
|
|||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
locale: zh_CN
|
locale: zh_CN
|
||||||
serialization:
|
serialization:
|
||||||
# ?????
|
# 格式化输出
|
||||||
indent_output: false
|
indent_output: false
|
||||||
servlet:
|
servlet:
|
||||||
multipart:
|
multipart:
|
||||||
max-file-size: 100MB
|
max-request-size: 100MB
|
||||||
max-request-size: 500MB
|
max-file-size: 500MB
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
|
||||||
#mybatis????
|
|
||||||
|
#mybatis配置信息
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
mapper-locations: classpath*:com/njcn/**/mapping/*.xml
|
mapper-locations: classpath*:com/njcn/**/mapping/*.xml
|
||||||
configuration:
|
configuration:
|
||||||
#????
|
#驼峰命名
|
||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
#??sql????
|
#配置sql日志输出
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
#??????
|
#关闭日志输出
|
||||||
#log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
#log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||||
global-config:
|
global-config:
|
||||||
db-config:
|
db-config:
|
||||||
#????????
|
#指定主键生成策略
|
||||||
id-type: assign_uuid
|
id-type: assign_uuid
|
||||||
log:
|
log:
|
||||||
commonLevel: info
|
commonLevel: info
|
||||||
|
|
||||||
|
jibei:
|
||||||
|
client_id: bad079495dc111ee987b0a580a080620
|
||||||
|
client_secret: OxXlgFs9HH105L3cOg8ogYoFRFs8sKITJhVocyOprxoWSadcX0we2wffjyTUYGsK
|
||||||
|
grant_type: credentials
|
||||||
|
url: http://25.42.182.119.32001
|
||||||
Reference in New Issue
Block a user