|  |  |  | 
|---|
|  |  |  | * 向通信中间件发送rtu远程升级任务 | 
|---|
|  |  |  | * @param restTemplate SpringBoot的RestTemplate | 
|---|
|  |  |  | * @param toMwUrl 到通信中间件的web请求Url | 
|---|
|  |  |  | * @param param 请求参数 | 
|---|
|  |  |  | * @param body 请求数据 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | protected BaseResponse sendRequest2Mw(RestTemplate restTemplate, String toMwUrl, Object param) { | 
|---|
|  |  |  | protected BaseResponse sendPostRequest2Mw(RestTemplate restTemplate, String toMwUrl, Object body) { | 
|---|
|  |  |  | String url = UriComponentsBuilder.fromUriString(toMwUrl) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .toUriString(); | 
|---|
|  |  |  | HttpHeaders headers = new HttpHeaders(); | 
|---|
|  |  |  | HttpEntity<?> httpEntity ; | 
|---|
|  |  |  | if(param != null){ | 
|---|
|  |  |  | httpEntity = new HttpEntity<>(param, headers); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | httpEntity = new HttpEntity<>(headers); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | HttpEntity<?> httpEntity = new HttpEntity<>(body, headers); | 
|---|
|  |  |  | ResponseEntity<BaseResponse> response = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 通过Post方式调用接口 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 向通信中间件发送rtu远程升级任务 | 
|---|
|  |  |  | * @param restTemplate SpringBoot的RestTemplate | 
|---|
|  |  |  | * @param toMwUrl 到通信中间件的web请求Url | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | protected BaseResponse sendGetRequest2Mw(RestTemplate restTemplate, String toMwUrl) { | 
|---|
|  |  |  | String url = UriComponentsBuilder.fromUriString(toMwUrl) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .toUriString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) | 
|---|
|  |  |  | //        .queryParam("test", test); | 
|---|
|  |  |  | UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ResponseEntity<BaseResponse> response = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 通过Get方式调用接口 | 
|---|
|  |  |  | response = restTemplate.exchange(builder.toUriString(), | 
|---|
|  |  |  | HttpMethod.GET, | 
|---|
|  |  |  | new HttpEntity<>(new HttpHeaders()), | 
|---|
|  |  |  | BaseResponse.class); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return BaseResponseUtils.buildError("后端系统出错,中间件调用异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(response == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildError("后端系统出错,中间件调用异常"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return response.getBody(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 创建外部命令(发给控制器) | 
|---|
|  |  |  | * @param code 命令code | 
|---|
|  |  |  | * @return | 
|---|