From 89d7bf273815013c3e4bd518b77dfd35a749d592 Mon Sep 17 00:00:00 2001
From: wuzeyu <1223318623@qq.com>
Date: 星期五, 31 五月 2024 16:55:10 +0800
Subject: [PATCH] 田间灌溉项目管理 优化代码 修改轮罐组绑定的灌溉单元接口
---
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java | 103 +++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 87 insertions(+), 16 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java
index ccba930..7a81f76 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java
@@ -4,20 +4,31 @@
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.mw.protocol.Command;
import com.dy.common.mw.protocol.CommandType;
+import com.dy.common.mw.protocol.Data;
import com.dy.common.mw.protocol.p206V202404.CodeV202404;
-import com.dy.common.mw.protocol.p206V202404.ProtocolConstantV206V202404;
import com.dy.common.mw.protocol.p206V202404.downVos.ComCdXyVo;
import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper;
import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
+import com.dy.pipIrrRemote.result.RemoteResultCode;
+import jakarta.annotation.PostConstruct;
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;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
/**
* @author ZhuBaoMin
@@ -25,7 +36,8 @@
* @LastEditTime 2024-05-21 15:30
* @Description
*/
-//@RequiredArgsConstructor
+
+@Component
public class ComSupport {
//@NotNull
//private final CommandSv commandSv;
@@ -37,17 +49,43 @@
protected static String rtuResultSendWebUrl = "http://127.0.0.1:8081/remote/comRes/receive" ;
protected static String controllerType = "57" ;//鎺у埗鍣ㄧ被鍨�
- protected static Integer projectNo = 10 ;//椤圭洰缂栫爜
+ protected static Integer projectNo = 100 ;//椤圭洰缂栫爜
- protected static String icCardAddr = "04BEA5BB" ;//IC鍗″湴鍧�
- protected static String icCardNo = "37142501020500001" ;//IC鍗$紪鍙凤紙鐢ㄦ埛鍗″簭鍒楀彿锛�
+ //protected static String icCardAddr = "04BEA5BB" ;//IC鍗″湴鍧�
+ //protected static String icCardNo = "37142501020500001" ;//IC鍗$紪鍙凤紙鐢ㄦ埛鍗″簭鍒楀彿锛�
+ //protected String protocolName = ProtocolConstantV206V202404.protocolName;
- protected String protocolName = ProtocolConstantV206V202404.protocolName;
- protected String commandTypeInner = CommandType.innerCommand;
protected String commandTypeOuter = CommandType.outerCommand;
+
+ // 瀛樺偍瀹炰緥鍖栫殑 CompletableFuture<Data> 瀵硅薄
+ protected static Map<Long, Object> features = new HashMap<>();
+ protected static Boolean setuped = false;
@Autowired
private RestTemplate restTemplate;
+
+ @Autowired
+ private BaSettingsMapper baSettingsMapper;
+ public static ComSupport comSupport;
+
+ /**
+ * 寮曞叆BaSettingsMapper
+ */
+ @PostConstruct
+ public void init() {
+ comSupport = this;
+ comSupport.baSettingsMapper = this.baSettingsMapper;
+ }
+
+ /**
+ * 鑾峰彇绯荤粺閰嶇疆鍙傛暟
+ */
+ public void setUp() {
+ //protocolName = comSupport.baSettingsMapper.getItemValue("protocolName");
+ controllerType = comSupport.baSettingsMapper.getItemValue("controllerType");
+ projectNo = Integer.parseInt(comSupport.baSettingsMapper.getItemValue("projectNo"));
+ setuped = true;
+ }
protected ComCdXyVo comCdXyVo(){
ComCdXyVo comVo = new ComCdXyVo() ;
@@ -58,20 +96,22 @@
/**
* 鍒涘缓鍛戒护鏃ュ織瀵硅薄
+ * @param comId 涓婚敭
* @param commandCode 鍔熻兘鐮�
* @param rtuAddr 闃�鎺у櫒鍦板潃
+ * @param protocol 閫氳鍗忚鍚嶇О
* @param param 鍙傛暟鏁版嵁
* @param operator 鎿嶄綔鍛�
- * @return 闆堕浂鏃ュ織瀵硅薄
+ * @return
*/
- protected RmCommandHistory getComHistory(String commandCode, String rtuAddr, Object param, Long operator ) {
+ protected RmCommandHistory getComHistory(Long comId, String commandCode, Long intakeId, String rtuAddr, String protocol, Object param, Long operator ) {
RmCommandHistory rmCommandHistory = new RmCommandHistory();
+ rmCommandHistory.setId(comId);
rmCommandHistory.setCommandCode(commandCode);
rmCommandHistory.setCommandName(CodeV202404.getCodeName(commandCode));
- rmCommandHistory.setRtuaddr(rtuAddr);
- rmCommandHistory.setProtocol(protocolName);
- rmCommandHistory.setCommandType(commandTypeOuter);
- rmCommandHistory.setCallback(rtuResultSendWebUrl);
+ rmCommandHistory.setIntakeId(intakeId);
+ rmCommandHistory.setRtuAddr(rtuAddr);
+ rmCommandHistory.setProtocol(protocol);
rmCommandHistory.setParam((JSONObject) JSON.toJSON(param));
rmCommandHistory.setSendTime(new Date());
rmCommandHistory.setOperator(operator);
@@ -86,19 +126,49 @@
* @param param 鍙傛暟鏁版嵁
* @return 鏋勯�犲ソ鐨勫懡浠ゅ璞�
*/
- protected Command command(String comId, String commandCode, String rtuAddr, Object param){
+ protected Command command(Long comId, String commandCode, String rtuAddr, String protocol, Object param){
Command com = new Command() ;
- com.id = comId==null?Command.defaultId:(comId.trim().equals("")?Command.defaultId:comId);
+ com.id = String.valueOf(comId);
com.code = commandCode ;
com.rtuAddr = rtuAddr ;
- com.protocol = protocolName;
+ com.protocol = protocol;
com.type = commandTypeOuter;
com.rtuResultSendWebUrl = rtuResultSendWebUrl ;
com.param = param ;
return com ;
+ }
+
+ /**
+ * 澶勭悊鍥炶皟鍐呭
+ * @param comId
+ * @return
+ */
+ protected BaseResponse<Data> dealWithCallBack(Long comId) {
+ CompletableFuture<Data> featureObject = new CompletableFuture<>();
+ features.put(comId, featureObject);
+ try {
+ CompletableFuture<Data> feature = (CompletableFuture<Data>) features.get(comId);
+ System.out.println("receive result ID:" + comId);
+ Data resultData = feature.get(10, TimeUnit.SECONDS);
+ features.remove(comId);
+ String commandId = resultData.getCommandId();
+ if(commandId.equals(comId)) {
+ return BaseResponseUtils.buildSuccess(resultData);
+ }else {
+ return BaseResponseUtils.buildSuccess();
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_ERROR.getMessage());
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_ERROR.getMessage());
+ } catch (TimeoutException e) {
+ return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
+ }
}
/**
@@ -140,4 +210,5 @@
}
return response.getBody();
}
+
}
--
Gitblit v1.8.0