From c4d56f4a2c7687739f3bf0f43bcc1f35c9bbeb8b Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 14 五月 2025 15:18:44 +0800
Subject: [PATCH] 1、表阀一体协议解析同步新版本;2、默认设备是表阀一体(0x02)
---
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java | 137 ++++++++++++++++-----------------------------
1 files changed, 50 insertions(+), 87 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java
index 96d3d20..1ee1493 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/monitor/ComTransCtrl.java
@@ -3,30 +3,24 @@
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.aop.SsoAop;
import com.dy.common.mw.protocol.Command;
-import com.dy.common.util.IDLongGenerator;
+import com.dy.common.util.Callback;
import com.dy.common.util.NumUtil;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
-import com.dy.pipIrrGlobal.command.ComResultWait;
-import com.dy.pipIrrGlobal.pojoPr.PrController;
+import com.dy.pipIrrRemote.common.dto.DtoBase;
+import com.dy.pipIrrRemote.monitor.common.ComCtrl;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.env.Environment;
+import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestTemplate;
-
-import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
/**
* @Author: liurunyu
@@ -38,24 +32,13 @@
@RestController
@RequestMapping(path = "comTrans")
@RequiredArgsConstructor
-public class ComTransCtrl {
+@Scope("prototype") //鍥犱负鏈夊璞$被灞炴�э紝鎵�浠ラ噰鐢ㄥ師鍨嬫ā寮忥紝姣忔璇锋眰鏂板缓涓�涓疄渚嬪璞�
+public class ComTransCtrl extends ComCtrl {
private static final String RtuSuccessMsg = "鎺у埗鍣ㄦ帴鏀跺苟鎵ц鍛戒护鎴愬姛";
@Autowired
- private Environment env ;
-
- @Autowired
- private RestTemplate restTemplate ;
-
- @Value("${mw.waitMwRtnResultTimeout}")
- private int waitMwRtnResultTimeout ;
-
- @Value("${mw.rtuCallbackUrl_rm}")
- private String rtuResultSendWebUrl;
-
- @Autowired
- private ComTransSv comSv;
+ private ComTransSv sv ;
/**
* 鍚戣澶囷紙鎺у埗鍣級鍙戦�侀�忎紶鍛戒护
@@ -66,66 +49,43 @@
@PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE)
@SsoAop()
public BaseResponse<Object> send(@RequestBody @Valid ComTransDto dto, BindingResult bindingResult) {
- if (bindingResult != null && bindingResult.hasErrors()) {
- return BaseResponseUtils.buildError(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
- String msg = this.checkDto(dto) ;
- if(msg != null){
- return BaseResponseUtils.buildError(msg) ;
- }
- //寰楀埌鎺у埗鍣ㄥ璞�
- PrController ctrlPo = comSv.getRtu(dto.getIntakeId());
- if (ctrlPo == null) {
- return BaseResponseUtils.buildError("浠庢暟鎹簱涓湭寰楀埌鎺у埗鍣ㄦ暟鎹�") ;
- }
- //妫�鏌ュ崗璁�
- msg = comSv.checkProtocol(ctrlPo) ;
- if(msg != null) {
- return BaseResponseUtils.buildError(msg) ;
- }
- //寰楀埌鍔熻兘鐮佸搴旂殑鍛戒护鍚嶇О
- String comName = comSv.getCommandName(dto.comCode, ctrlPo) ;
- if(comName == null) {
- return BaseResponseUtils.buildError("鏈緱鍒板姛鑳界爜瀵瑰簲鍛戒护鍚嶇О") ;
- }
- Long comId = new IDLongGenerator().generate();
- String comData = dto.comData.toUpperCase() ;
- //鐢熸垚骞朵繚瀛樺懡浠ゆ棩蹇�
- comSv.saveComHistoryPo(comId, ctrlPo.getProtocol(), dto.comCode, "閫忎紶锛�" + comName + "锛�",
- dto.getIntakeId(), ctrlPo.getRtuAddr(), new ComTransParam(dto.comCode, comData), dto.getOperator());
- try{
- CompletableFuture<JSONObject> feature = new CompletableFuture<>();
- ComResultWait.put(comId, feature);
- //鍒涘缓澶栭儴閫忎紶鍛戒护锛堝彂缁欐帶鍒跺櫒锛�
- Command com = comSv.createOuterTransparentCommand("" + comId, dto.comCode);
- com.rtuAddr = ctrlPo.getRtuAddr() ;
- com.attachment = comData ;
- com.rtuResultSendWebUrl = rtuResultSendWebUrl;
- //寰楀埌閫氫俊涓棿浠跺彂閫佸懡浠ょ殑web URL
- String rqUrl = comSv.get2MwRequestUrl(this.env, comSv.ContextComSend) ;
- //鍚戦�氫俊涓棿浠跺彂閫亀eb璇锋眰
- BaseResponse res = comSv.sendPostRequest2Mw(restTemplate, rqUrl, com) ;
- //澶勭悊閫氫俊涓棿浠跺web璇锋眰鐨勫搷搴�
- msg = comSv.dealMwDealResponse(res) ;
- if(msg != null) {
- return BaseResponseUtils.buildError(msg) ;
- }else{
- try{
- //绛夊緟閫氫俊涓棿浠堕�氱煡鎺у埗鍣ㄦ墽琛屽懡浠や笂琛屾暟鎹紙鍛戒护缁撴灉锛�
- JSONObject resultData = feature.get(waitMwRtnResultTimeout, TimeUnit.SECONDS);
- return BaseResponseUtils.buildSuccess(this.createRtnMsg(dto.comCode, resultData));
- }catch (Exception e){
- return BaseResponseUtils.buildFail("绛夊緟閫氫俊涓棿浠堕�氱煡鍛戒护缁撴灉瓒呮椂");
+ BaseResponse<Object> res ;
+ //鍙戦�佸懡浠ゅ墠-1锛氶獙璇�
+ res = super.pre1(sv, dto.comCode, dto, bindingResult);
+ if(res == null) {
+ //鍙戦�佸懡浠ゅ墠-2锛氳幏寰楁暟鎹�
+ res = super.pre2(sv, dto.comCode, dto, bindingResult);
+ if(res == null) {
+ //鍙戦�佸懡浠ゅ墠-3锛氫繚瀛樺懡浠ゆ棩蹇�
+ this.comName = "閫忎紶锛�" + comName + "锛�" ;
+ String comData = dto.comData.toUpperCase() ;
+ ComTransParam comParam = ComTransParam.builder().commandCode(dto.comCode).data(comData).build();
+ res = super.pre3(sv, dto.getIntakeId(), dto.getOperator(), dto.comCode, comParam);
+ if(res == null) {
+ //鍙戦�佸懡浠ゅ墠-4锛氬噯澶嘑eature
+ super.pre4();
+ try{
+ //鍒涘缓澶栭儴閫忎紶鍛戒护锛堝彂缁欐帶鍒跺櫒锛�
+ Command com = sv.createOuterTransparentCommand("" + comId, dto.comCode);
+ com.rtuAddr = ctrlPo.getRtuAddr() ;
+ com.attachment = comData ;
+ com.rtuResultSendWebUrl = rtuResultSendWebUrl;
+ //鍙戦�佸懡浠�
+ res = super.doSend(sv, com) ;
+ if(res == null) {
+ //鍙戦�佸懡浠ゅ悗
+ res = super.after(dto.comCode, null);
+ }
+ }catch (Exception e){
+ res = BaseResponseUtils.buildFail("鏈嶅姟绔瀯閫犲苟鍚戦�氫俊涓棿浠跺彂閫佽姹傛椂寮傚父" + (e.getMessage() == null?"":e.getMessage())) ;
+ }finally {
+ //鏈�缁�
+ super.end() ;
+ }
}
}
- }catch (Exception e){
- return BaseResponseUtils.buildFail("鏈嶅姟绔瀯閫犲苟鍚戦�氫俊涓棿浠跺彂閫佽姹傛椂寮傚父" + (e.getMessage() == null?"":e.getMessage())) ;
- }finally {
- try {
- //鏈�鍚庢竻闄ompletableFuture缂撳瓨
- ComResultWait.remove(comId);
- }catch (Exception ee){}
}
+ return res ;
}
/**
@@ -133,23 +93,26 @@
* @param dto
* @return
*/
- private String checkDto(ComTransDto dto){
- if(!NumUtil.isHex(dto.comCode)){
+ @Override
+ protected String checkDto(DtoBase dto){
+ ComTransDto myDto = (ComTransDto)dto;
+ if(!NumUtil.isHex(myDto.comCode)){
return "鍛戒护鍔熻兘鐮佷笉鏄崄鍏繘鍒舵暟";
}
- if(!NumUtil.isHex(dto.comData)){
+ if(!NumUtil.isHex(myDto.comData)){
return "鍛戒护鏁版嵁涓嶆槸鍗佸叚杩涘埗鏁�";
}
- if(dto.comData.length() % 2 != 0){
+ if(myDto.comData.length() % 2 != 0){
return "鍛戒护鏁版嵁涓嶅畬澶囷紙闀垮害涓嶆槸鍋舵暟锛�";
}
- if(!dto.comData.contains(dto.comCode)){
+ if(!myDto.comData.contains(myDto.comCode)){
return "鍛戒护鏁版嵁涓笉鍖呭惈鍔熻兘鐮�";
}
return null ;
}
- private String createRtnMsg(String code, JSONObject resultData){
+ @Override
+ protected String dealComResult(String code, JSONObject resultData, Callback callback){
String msg;
if(resultData != null){
JSONObject codeData = resultData.getJSONObject("data") ;
--
Gitblit v1.8.0