pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/Web2RtuMw.java
File was renamed from pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/rtuMw/ToRtuMwCom.java
@@ -19,33 +19,71 @@
 * @Date: 2024/10/23 11:45
 * @Description
 */
public abstract class ToRtuMwCom {
public abstract class Web2RtuMw {
    /**
     * pro_mw:属性
     * tag从控制器中获取
     * key_mw:url的key
     */
    private static final String pro_mw = "mw";
    private static final String key_mw = "comSendUrl";
    private static final String keyUg_mw = "ugTaskSendUrl";
    private static final String pro_url = "url";
    protected static final String ContextComSend = "/rtuMw/com/send";
    protected static final String ContextRtuLogFile = "/rtuMw/com/rtuLogFile";
    protected static final String ContextRtuLogText = "/rtuMw/com/rtuLogText";
    protected static final String ContextUgTaskSend = "/rtuMw/com/upgradeRtu";
    protected static final String ContextUgForceStop = "/rtuMw/com/ugForceStop";
    /**
     * 得到向通信中间件发送数据的URL
     * @param env
     * @return
     */
    protected String getToMwUrl(Environment env) {
        return env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + key_mw);
    protected String get2MwUrl(Environment env) {
        return env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + pro_url);
    }
    /**
     * 得到向通信中间件发送强制停止升级的命令URL
     * @param env
     * @return
     */
    protected String get2MwRequestUrl(Environment env, String context) {
        return get2MwUrl(env) + context;
    }
    /**
     * 得到向通信中间件发送数据的URL
     * @param env
     * 向通信中间件发送rtu远程升级任务
     * @param restTemplate SpringBoot的RestTemplate
     * @param toMwUrl 到通信中间件的web请求Url
     * @param param 请求参数
     * @return
     */
    protected String getToMwUgUrl(Environment env) {
        return env.getProperty(pro_mw + "." + DataSourceContext.get() + "." + keyUg_mw);
    protected BaseResponse sendRequest2Mw(RestTemplate restTemplate, String toMwUrl, Object param) {
        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);
        }
        ResponseEntity<BaseResponse> response = null;
        try {
            // 通过Post方式调用接口
            response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponseUtils.buildError("后端系统出错,中间件调用异常");
        }
        if(response == null){
            return BaseResponseUtils.buildError("后端系统出错,中间件调用异常");
        }else{
            return response.getBody();
        }
    }
    /**
@@ -74,58 +112,4 @@
        return com ;
    }
    /**
     * 发送命令
     *
     * @return
     */
    protected BaseResponse sendCom2Mw(RestTemplate restTemplate, String comSendUrl, Command com) {
        String url = UriComponentsBuilder.fromUriString(comSendUrl)
                .build()
                .toUriString();
        HttpHeaders headers = new HttpHeaders();
        HttpEntity<Command> httpEntity = new HttpEntity<>(com, headers);
        ResponseEntity<BaseResponse> response = null;
        try {
            // 通过Post方式调用接口
            response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponseUtils.buildError("后端系统出错,中间件调用异常");
        }
        if(response == null){
            return BaseResponseUtils.buildError("后端系统出错,中间件调用异常");
        }else{
            return response.getBody();
        }
    }
    /**
     * 向通信中间件发送rtu远程升级任务
     * @param restTemplate
     * @param comSendUrl
     * @param vo
     * @return
     */
    protected BaseResponse sendUpgradeTask2Mw(RestTemplate restTemplate, String comSendUrl, UpgradeTaskVo vo) {
        String url = UriComponentsBuilder.fromUriString(comSendUrl)
                .build()
                .toUriString();
        HttpHeaders headers = new HttpHeaders();
        HttpEntity<UpgradeTaskVo> httpEntity = new HttpEntity<>(vo, headers);
        ResponseEntity<BaseResponse> response = null;
        try {
            // 通过Post方式调用接口
            response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseResponseUtils.buildError("后端系统出错,中间件调用异常");
        }
        if(response == null){
            return BaseResponseUtils.buildError("后端系统出错,中间件调用异常");
        }else{
            return response.getBody();
        }
    }
}