From 620c3af4bb8c53d5ec4c4d0127c9d92dc8aa4f65 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期一, 03 六月 2024 09:53:49 +0800
Subject: [PATCH] 2024-06-03 朱宝民 平台开关阀及小程序开关阀
---
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java | 115 +++++++++++++++++++++++++++++----------------------------
1 files changed, 59 insertions(+), 56 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
similarity index 66%
rename from pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java
rename to pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
index 7a81f76..89ba085 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/common/ComSupport.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
@@ -1,19 +1,20 @@
-package com.dy.pipIrrRemote.common;
+package com.dy.pipIrrGlobal.command;
import com.alibaba.fastjson2.JSON;
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.downVos.ComCdXyVo;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.command.result.CommandResultCode;
import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper;
+import com.dy.pipIrrGlobal.daoPr.PrControllerMapper;
+import com.dy.pipIrrGlobal.pojoPr.PrController;
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.context.annotation.DependsOn;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -22,9 +23,12 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -32,29 +36,18 @@
/**
* @author ZhuBaoMin
- * @date 2024-05-21 15:30
- * @LastEditTime 2024-05-21 15:30
- * @Description
+ * @date 2024-05-30 15:45
+ * @LastEditTime 2024-05-30 15:45
+ * @Description 鍛戒护鏀拺绫�
*/
@Component
+@DependsOn({"baSettingsMapper", "prControllerMapper"})
public class ComSupport {
- //@NotNull
- //private final CommandSv commandSv;
-
- protected static String mwUrlTest = "http://127.0.0.1:8070/rtuMw/com/test" ;
protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send" ;
- //protected static String rtuAddr = "37142501020100215" ;
- protected static String rtuResultSendWebUrl = "http://127.0.0.1:8081/remote/comRes/receive" ;
-
- protected static String controllerType = "57" ;//鎺у埗鍣ㄧ被鍨�
- protected static Integer projectNo = 100 ;//椤圭洰缂栫爜
-
- //protected static String icCardAddr = "04BEA5BB" ;//IC鍗″湴鍧�
- //protected static String icCardNo = "37142501020500001" ;//IC鍗$紪鍙凤紙鐢ㄦ埛鍗″簭鍒楀彿锛�
- //protected String protocolName = ProtocolConstantV206V202404.protocolName;
-
+ protected static String controllerType = null;
+ protected static Integer projectNo = null;
protected String commandTypeOuter = CommandType.outerCommand;
// 瀛樺偍瀹炰緥鍖栫殑 CompletableFuture<Data> 瀵硅薄
@@ -66,6 +59,8 @@
@Autowired
private BaSettingsMapper baSettingsMapper;
+ @Autowired
+ private PrControllerMapper prControllerMapper;
public static ComSupport comSupport;
/**
@@ -75,23 +70,51 @@
public void init() {
comSupport = this;
comSupport.baSettingsMapper = this.baSettingsMapper;
+ comSupport.prControllerMapper = this.prControllerMapper;
}
/**
* 鑾峰彇绯荤粺閰嶇疆鍙傛暟
*/
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() ;
- comVo.controllerType = controllerType ;
- comVo.projectNo = projectNo ;
- return comVo ;
+ /**
+ * 鐢熸垚璁㈠崟鍙�
+ * @return
+ */
+ public String generateOrderNo() {
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyMMddHHmmss");
+ LocalDateTime dateTime = LocalDateTime.now();
+ Random random = new Random();
+ String CHARACTERS = "0123456789";
+ StringBuilder sb = new StringBuilder(4);
+ for (int i = 0; i < 4; i++) {
+ int index = random.nextInt(CHARACTERS.length());
+ sb.append(CHARACTERS.charAt(index));
+ }
+ return dtf.format(dateTime) + sb.toString();
+ }
+
+ /**
+ * 鏍规嵁鍙栨按鍙D鎴栭榾鎺у櫒鍦板潃鑾峰彇闃�鎺у櫒瀵硅薄
+ * @param intakeId
+ * @return
+ */
+ public JSONObject getRtu(Long intakeId, String rtuAddr) {
+ PrController prController = prControllerMapper.getRtu(intakeId, rtuAddr);
+ if(prController == null) {
+ return null;
+ }
+ JSONObject job_rtu = new JSONObject();
+ job_rtu.put("rtuAddr", prController.getRtuAddr());
+ job_rtu.put("protocol", prController.getProtocol());
+ job_rtu.put("intakeId", prController.getIntakeId());
+
+ return job_rtu;
}
/**
@@ -104,11 +127,12 @@
* @param operator 鎿嶄綔鍛�
* @return
*/
- protected RmCommandHistory getComHistory(Long comId, String commandCode, Long intakeId, String rtuAddr, String protocol, Object param, Long operator ) {
+ protected RmCommandHistory getComHistory(Long comId, String commandCode, String commandName, 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.setCommandName(CodeV202404.getCodeName(commandCode));
+ rmCommandHistory.setCommandName(commandName);
rmCommandHistory.setIntakeId(intakeId);
rmCommandHistory.setRtuAddr(rtuAddr);
rmCommandHistory.setProtocol(protocol);
@@ -126,7 +150,7 @@
* @param param 鍙傛暟鏁版嵁
* @return 鏋勯�犲ソ鐨勫懡浠ゅ璞�
*/
- protected Command command(Long comId, String commandCode, String rtuAddr, String protocol, Object param){
+ protected Command command(Long comId, String commandCode, String rtuAddr, String protocol, String rtuResultSendWebUrl, Object param){
Command com = new Command() ;
com.id = String.valueOf(comId);
com.code = commandCode ;
@@ -152,9 +176,9 @@
try {
CompletableFuture<Data> feature = (CompletableFuture<Data>) features.get(comId);
System.out.println("receive result ID:" + comId);
- Data resultData = feature.get(10, TimeUnit.SECONDS);
+ Data resultData = feature.get(30, TimeUnit.SECONDS);
features.remove(comId);
- String commandId = resultData.getCommandId();
+ Long commandId = Long.parseLong(resultData.getCommandId());
if(commandId.equals(comId)) {
return BaseResponseUtils.buildSuccess(resultData);
}else {
@@ -162,33 +186,13 @@
}
} catch (InterruptedException e) {
e.printStackTrace();
- return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_ERROR.getMessage());
+ return BaseResponseUtils.buildFail(CommandResultCode.GET_RESULT_ERROR.getMessage());
} catch (ExecutionException e) {
e.printStackTrace();
- return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_ERROR.getMessage());
+ return BaseResponseUtils.buildFail(CommandResultCode.GET_RESULT_ERROR.getMessage());
} catch (TimeoutException e) {
- return BaseResponseUtils.buildFail(RemoteResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
+ return BaseResponseUtils.buildFail(CommandResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
}
- }
-
- /**
- * 杩炴帴閫氫俊涓棿浠舵祴璇�
- * @return
- */
- protected BaseResponse sendTest(){
- String url = UriComponentsBuilder.fromUriString(mwUrlTest)
- .build()
- .toUriString();
- HttpHeaders headers = new HttpHeaders();
- HttpEntity<?> httpEntity = new HttpEntity<>(headers);
- ResponseEntity<BaseResponse> response = null;
- try {
- // 閫氳繃Get鏂瑰紡璋冪敤鎺ュ彛
- response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, BaseResponse.class);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return response.getBody();
}
/**
@@ -210,5 +214,4 @@
}
return response.getBody();
}
-
}
--
Gitblit v1.8.0