package com.dy.aceMw.web.comResult; 
 | 
  
 | 
import com.dy.common.mw.protocol.Data; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.http.HttpEntity; 
 | 
import org.springframework.http.HttpHeaders; 
 | 
import org.springframework.http.HttpMethod; 
 | 
import org.springframework.http.ResponseEntity; 
 | 
import org.springframework.stereotype.Component; 
 | 
import org.springframework.web.client.RestTemplate; 
 | 
import org.springframework.web.util.UriComponentsBuilder; 
 | 
  
 | 
/** 
 | 
 * @Author liurunyu 
 | 
 * @Date 2023/12/21 20:28 
 | 
 * @LastEditTime 2023/12/21 20:28 
 | 
 * @Description 
 | 
 */ 
 | 
@Slf4j 
 | 
@Component() 
 | 
public class CommandResultDeal { 
 | 
  
 | 
    private RestTemplate restTemplate; 
 | 
  
 | 
    @Autowired 
 | 
    public void setRestTemplate(RestTemplate restTemplate){ 
 | 
        this.restTemplate = restTemplate ; 
 | 
    } 
 | 
  
 | 
  
 | 
    public void deal(Data data) { 
 | 
        if (data.rtuResultSendWebUrl != null && data.rtuResultSendWebUrl.trim().equals("")) { 
 | 
            String url = UriComponentsBuilder.fromUriString(data.rtuResultSendWebUrl) 
 | 
                    .build() 
 | 
                    .toUriString(); 
 | 
            HttpHeaders headers = new HttpHeaders(); 
 | 
            HttpEntity<?> httpEntity = new HttpEntity<>(data, headers); 
 | 
            ResponseEntity<WebResponseVo> response = null; 
 | 
            try { 
 | 
                // 通过Post方式调用接口 
 | 
                response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, WebResponseVo.class); 
 | 
            } catch (Exception e) { 
 | 
                e.printStackTrace(); 
 | 
            } 
 | 
            assert response != null; 
 | 
        } else { 
 | 
            log.error("严重错误,在com.dy.aceMw.web.comResult.CommandResultDeal里,处理的是RTU命令结果Node,但数据中rtuResultSendWebUrl为空"); 
 | 
        } 
 | 
    } 
 | 
} 
 |