zhubaomin
2025-03-26 37d2aec0dbe914c8924d6514da7eca053eee4cf3
Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
3个文件已修改
1个文件已添加
235 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/parse/Cd_92_A2_Down.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu3rd/src/main/java/com/dy/rtuMw3rd/http4Xjnk/HttpRq.java 228 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pom.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V202404test/CommandP206V202404Ctrl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V202404/parse/Cd_92_A2_Down.java
@@ -121,7 +121,7 @@
            if(cvo.moneyRemain == null){
                cvo.moneyRemain = 0.0 ;
            }
            strTemp = "" + (Double.valueOf(cvo.moneyRemain * 100)).intValue() ;
            strTemp = "" + (Double.valueOf(cvo.moneyRemain * 10000)).intValue() ;
            bTemp = ByteUtil.string2BCD_LE(strTemp) ;
            bTempLen = bTemp.length ;
            count = 0 ;
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu3rd/src/main/java/com/dy/rtuMw3rd/http4Xjnk/HttpRq.java
New file
@@ -0,0 +1,228 @@
package com.dy.rtuMw3rd.http4Xjnk;
import com.dy.common.util.HttpCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
 * @Author: liurunyu
 * @Date: 2025/3/15 9:56
 * @Description
 */
@Component()
public class HttpRq {
    private RestTemplate restTemplate ;
    @Autowired
    public void setRestTemplate(RestTemplate restTemplate){
        this.restTemplate = restTemplate;
    }
    /**
     * get请求,返回json内容
     * 同步
     * @param httpBaseUrl
     * @param params
     * @param cb
     * @throws Exception
     */
    public void get4JsonBySync(String httpBaseUrl, Map<String, String> params, HttpCallback cb) throws Exception {
        String url = UriComponentsBuilder.fromUriString(httpBaseUrl)
                .build()
                .toUriString();
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) ;
        if(params != null && params.size() > 0){
            Iterator<String> it = params.keySet().iterator() ;
            String key ;
            while (it.hasNext()){
                key = it.next() ;
                builder.queryParam(key, params.get(key)) ;
            }
        }
        httpGetRequestSync(builder, cb);
    }
    /**
     * get请求,返回json内容
     * 异步
     * @param httpBaseUrl
     * @param params
     * @param cb
     * @throws Exception
     */
    public void get4JsonByAsync(String httpBaseUrl, Map<String, String> params, HttpCallback cb) throws Exception {
        String url = UriComponentsBuilder.fromUriString(httpBaseUrl)
                .build()
                .toUriString();
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) ;
        if(params != null && params.size() > 0){
            Iterator<String> it = params.keySet().iterator() ;
            String key ;
            while (it.hasNext()){
                key = it.next() ;
                builder.queryParam(key, params.get(key)) ;
            }
        }
        httpGetRequestAsync(builder, cb);
    }
    /**
     * get请求,返回json内容
     * 同步
     * @param httpBaseUrl
     * @param params
     * @param cb
     * @throws Exception
     */
    public void post4JsonBySync(String httpBaseUrl, Map<String, String> params, HttpCallback cb) throws Exception {
        String url = UriComponentsBuilder.fromUriString(httpBaseUrl)
                .build()
                .toUriString();
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) ;
        httpPostRequestSync(builder, params, cb);
    }
    /**
     * get请求,返回json内容
     * 异步
     * @param httpBaseUrl
     * @param params
     * @param cb
     * @throws Exception
     */
    public void post4JsonByAsync(String httpBaseUrl, Map<String, String> params, HttpCallback cb) throws Exception {
        String url = UriComponentsBuilder.fromUriString(httpBaseUrl)
                .build()
                .toUriString();
        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) ;
        httpPostRequestAsync(builder, params, cb);
    }
    /**
     * 发起请求
     * @param builder
     * @param cb
     * @return
     */
    private void httpGetRequestSync(UriComponentsBuilder builder, HttpCallback cb) {
        HttpHeaders headers = new HttpHeaders() ;
        headers.setContentType(MediaType.APPLICATION_JSON) ;
        restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        // 通过Get方式调用接口
        ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
                HttpMethod.GET,
                new HttpEntity<>(headers),
                String.class);
        String contentType = response.getHeaders().getContentType().toString() ;
        cb.call(response.getStatusCode().value() + "", contentType, response.getBody());
    }
    /**
     * 发起请求
     * @param builder
     * @param cb
     * @return
     */
    private void httpGetRequestAsync(UriComponentsBuilder builder, HttpCallback cb) throws Exception {
        HttpHeaders headers = new HttpHeaders() ;
        headers.setContentType(MediaType.APPLICATION_JSON) ;
        restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        // 发起异步 GET 请求
        CompletableFuture<ResponseEntity<String>> future = CompletableFuture.supplyAsync(() ->
                // 通过Get方式调用接口
                restTemplate.exchange(builder.toUriString(),
                        HttpMethod.GET,
                        new HttpEntity<>(headers),
                        String.class)
        );
        future.thenAccept(response -> {
            String contentType = response.getHeaders().getContentType().toString() ;
            cb.call(response.getStatusCode().value() + "", contentType, response.getBody());
        }) ;
        /*
        AtomicReference<Throwable> exeEx = new AtomicReference() ;
        future.thenAccept(response -> {
            String contentType = response.getHeaders().getContentType().toString() ;
            cb.call(response.getStatusCode().value() + "", contentType, response.getBody());
        }).exceptionally(ex -> {
            exeEx.set(ex.getCause());
            return null;
        });
        */
    }
    /**
     * 发起请求
     * @param builder
     * @param body
     * @param cb
     * @return
     */
    private void httpPostRequestSync(UriComponentsBuilder builder, Map<String, String> body, HttpCallback cb) {
        HttpHeaders headers = new HttpHeaders() ;
        headers.setContentType(MediaType.APPLICATION_JSON) ;
        restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(body, headers);
        // 通过Get方式调用接口
        ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
                HttpMethod.POST,
                requestEntity,
                String.class);
        String contentType = response.getHeaders().getContentType().toString() ;
        cb.call(response.getStatusCode().value() + "", contentType, response.getBody());
    }
    /**
     * 发起请求
     * @param builder
     * @param body
     * @param cb
     * @return
     */
    private void httpPostRequestAsync(UriComponentsBuilder builder, Map<String, String> body, HttpCallback cb) throws Exception {
        HttpHeaders headers = new HttpHeaders() ;
        headers.setContentType(MediaType.APPLICATION_JSON) ;
        restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(body, headers);
        // 发起异步 GET 请求
        CompletableFuture<ResponseEntity<String>> future = CompletableFuture.supplyAsync(() ->
                // 通过Get方式调用接口
                restTemplate.exchange(builder.toUriString(),
                        HttpMethod.POST,
                        requestEntity,
                        String.class)
        );
        future.thenAccept(response -> {
            String contentType = response.getHeaders().getContentType().toString() ;
            cb.call(response.getStatusCode().value() + "", contentType, response.getBody());
        }) ;
        /*
        AtomicReference<Throwable> exeEx = new AtomicReference() ;
        future.thenAccept(response -> {
            String contentType = response.getHeaders().getContentType().toString() ;
            cb.call(response.getStatusCode().value() + "", contentType, response.getBody());
        }).exceptionally(ex -> {
            exeEx.set(ex.getCause());
            return null;
        });
        */
    }
}
pipIrr-platform/pipIrr-mw/pom.xml
@@ -21,7 +21,6 @@
        <module>pipIrr-mw-simulate-rtu202404</module>
        <module>pipIrr-mwTest-server</module>
        <module>pipIrr-mwTest-client</module>
        <module>pipIrr-mw-rtu3rdTest</module>
    </modules>
    <dependencies>
pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V202404test/CommandP206V202404Ctrl.java
@@ -218,8 +218,8 @@
        comVo.projectNo = CommandP206V202404Ctrl.projectNo  ;
        //comVo.icCardAddr = Test.icCardAddr ;//IC卡地址(8位数字或字母)
        comVo.icCardNo = CommandP206V202404Ctrl.icCardNo ;//用户卡序列号(17位数字)(6字节BCD,2字节HEX)
        comVo.waterRemain = 123.45 ;//单位:元  2位小数点(最大值 99999999.99)
        comVo.moneyRemain = 234.56 ;//单位:m3  2位小数点(最大值 99999999.99)
        comVo.waterRemain = 123.45 ;//单位:m3  2位小数点(最大值 99999999.99)
        comVo.moneyRemain = 12345.67 ;//单位:元  2位小数点(最大值 99999999.99)
        comVo.waterPrice = 0.8 ;//水量单价 单位:元, 2个小数点
        comVo.elePrice = 1.2 ;//电量单价 单位:元, 2个小数点
        comVo.orderNo = "1234567890123456" ;//订单号(16位数字)