liurunyu
2024-12-05 267e622c876bea09b61af34fc93cd08b022aa423
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/Web2RtuMw.java
@@ -34,7 +34,7 @@
    protected static final String ContextRtuLogText = "/rtuMw/com/rtuLogText";
    protected static final String ContextUgTaskSend = "/rtuMw/com/upgradeRtu";
    protected static final String ContextUgForceStop = "/rtuMw/com/ugForceStop";
    protected static final String ContextUgForceOver = "/rtuMw/com/ugForceOver";
    /**
     * 得到向通信中间件发送数据的URL
     * @param env
@@ -57,20 +57,15 @@
     * 向通信中间件发送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方式调用接口
@@ -87,6 +82,39 @@
    }
    /**
     * 向通信中间件发送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