From a213f1486475bb455a9d6fcff8d94744083aaf6a Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期二, 25 六月 2024 10:10:12 +0800
Subject: [PATCH] 2024-06-25 朱宝民 构造命令、发送命令、结果处理代码放到父类,小程序部分完成
---
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/enums/LastOperateENUM.java | 27 +++
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java | 57 ++++-
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/dto/Param.java | 14 +
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java | 392 ++++++++++--------------------------------
4 files changed, 181 insertions(+), 309 deletions(-)
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
index 644f9b7..858ccf8 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
@@ -5,16 +5,18 @@
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.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrGlobal.command.dto.Param;
+import com.dy.pipIrrGlobal.command.enums.LastOperateENUM;
import com.dy.pipIrrGlobal.command.result.CommandResultCode;
import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper;
import com.dy.pipIrrGlobal.daoPr.PrControllerMapper;
import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper;
+import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper;
import com.dy.pipIrrGlobal.pojoPr.PrController;
import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
+import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
@@ -64,11 +66,11 @@
@Autowired
private PrControllerMapper prControllerMapper;
- //@Autowired
- //private CommandSv commandSv;
-
@Autowired
private RmCommandHistoryMapper rmCommandHistoryMapper;
+
+ @Autowired
+ private SeVirtualCardMapper seVirtualCardMapper;
public static ComSupport comSupport;
@@ -225,16 +227,19 @@
}
/**
- * 鍙戦�佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
+ * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
* @param po
* @return
*/
- protected BaseResponse dealWithCommandResult(Param po) {
+ protected BaseResponse<Boolean> dealWithCommandResult(Param po) {
Long comId = po.getComId();
+ Byte comType = po.getComType();
String commandCode = po.getCommandCode();
+ String commandName = po.getCommandName();
Long intakeId = po.getIntakeId();
String rtuAddr = po.getRtuAddr();
String protocol = po.getProtocol();
+ Long vcId = po.getVcId();
Object param = po.getParam();
String rtuResultSendWebUrl = po.getRtuResultSendWebUrl();
Long operator = po.getOperator();
@@ -245,28 +250,38 @@
// 鍙戦�佸懡浠�
JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
- //if(1 > 0) {
// 璇锋眰鎴愬姛
// 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
- String commandName = CodeV202404.getCodeName(commandCode);
RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
- //commandSv.insert(rmCommandHistory);
rmCommandHistoryMapper.insert(rmCommandHistory);
// 澶勭悊鍥炶皟
BaseResponse response_CallBack = dealWithCallBack(comId);
- // 鍥炶皟澶辫触
+ // 鍥炶皟寮傚父
if(!response_CallBack.getCode().equals("0001")) {
// 鍛戒护鏃ュ織鎵ц缁撴灉鏀逛负澶辫触
rmCommandHistory = new RmCommandHistory();
rmCommandHistory.setId(comId);
rmCommandHistory.setResult((byte)0);
- //commandSv.updateCommandResult(rmCommandHistory);
rmCommandHistoryMapper.updateByPrimaryKeySelective(rmCommandHistory);
- return BaseResponseUtils.buildFail(response_CallBack.getMsg());
- //return BaseResponseUtils.buildFail(response_CallBack.getContent().toString());
+ return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
+ }
+
+ // 鍥炶皟瓒呮椂
+ if (response_CallBack.getContent().toString().equals(CommandResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage())) {
+ /**
+ * 鍥炶皟瓒呮椂锛屾殏鏃惰涓烘墽琛屽け璐�
+ * 鍛戒护缃负澶辫触
+ * 铏氭嫙鍗′緷鏃т繚鎸佷娇鐢ㄤ腑鐨勭姸鎬�
+ */
+
+ rmCommandHistory = new RmCommandHistory();
+ rmCommandHistory.setId(comId);
+ rmCommandHistory.setResult((byte) 0);
+ rmCommandHistoryMapper.updateByPrimaryKeySelective(rmCommandHistory);
+ return BaseResponseUtils.buildErrorMsg(CommandResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
}
// 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
@@ -281,7 +296,23 @@
/**
* 鎵ц鎴愬姛锛岃繑鍥炲洖璋冨唴瀹�
+ * 濡傛灉鏄紑鍏抽榾锛氭洿鏀硅櫄鎷熷崱鐘舵�侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
*/
+ if(comType != null) {
+ SeVirtualCard virtualCard = new SeVirtualCard();
+ virtualCard.setId(vcId);
+ if(comType == 1) {
+ virtualCard.setInUse((byte) 1);
+ }else {
+ virtualCard.setInUse((byte) 0);
+ }
+ virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
+ virtualCard.setLastOperateTime(new Date());
+ seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
+ }
+
+
+ // 鍥炶皟杩斿洖鐨勫唴瀹�
Data myData = (Data)response_CallBack.getContent();
return BaseResponseUtils.buildSuccess(myData) ;
} else {
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/dto/Param.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/dto/Param.java
index e1541f7..9d5bcc7 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/dto/Param.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/dto/Param.java
@@ -6,7 +6,7 @@
* @author ZhuBaoMin
* @date 2024-06-04 11:25
* @LastEditTime 2024-06-04 11:25
- * @Description
+ * @Description 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋滄墍闇�鍙傛暟瀵硅薄
*/
@Data
@@ -15,7 +15,14 @@
private Long comId;
+ /**
+ * 鍛戒护绫诲瀷锛�1-寮�鍙戯紝2-鍏抽榾
+ */
+ private Byte comType;
+
private String commandCode;
+
+ private String commandName;
private Long intakeId;
@@ -23,6 +30,11 @@
private String protocol;
+ private Long vcId;
+
+ /**
+ * 瑙嗗浘瀵硅薄
+ */
private Object param;
private String rtuResultSendWebUrl;
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/enums/LastOperateENUM.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/enums/LastOperateENUM.java
new file mode 100644
index 0000000..4fcdf28
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/enums/LastOperateENUM.java
@@ -0,0 +1,27 @@
+package com.dy.pipIrrGlobal.command.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-06-24 22:08
+ * @LastEditTime 2024-06-24 22:08
+ * @Description 铏氭嫙鍗℃搷浣滄灇涓�
+ */
+
+@Getter
+@AllArgsConstructor
+public enum LastOperateENUM {
+ OPEN_ACCOUNT((byte)1, "寮�鎴�"),
+ RECHARGE((byte)2, "鍏呭��"),
+ CONSUME((byte)3, "娑堣垂"),
+ APPLY_REFUND((byte)4, "鐢宠閫�娆�"),
+ AUDIT_REFUND((byte)5, "閫�娆惧鏍�"),
+ REFUND((byte)6, "閫�娆�"),
+ OPEN_VALVE((byte)7, "寮�闃�"),
+ CLOSE_VALVE((byte)8, "鍏抽榾");
+
+ private final Byte code;
+ private final String message;
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
index d3fc309..05e8f1d 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/ValveCtrl.java
@@ -1,10 +1,6 @@
package com.dy.pipIrrWechat.command;
-import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
-import com.dy.common.aop.SsoAop;
-import com.dy.common.mw.protocol.Command;
-import com.dy.common.mw.protocol.Data;
import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1;
import com.dy.common.mw.protocol.p206V1_0_0.downVos.Com97Vo;
import com.dy.common.mw.protocol.p206V1_0_0.downVos.Com98Vo;
@@ -15,14 +11,12 @@
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrGlobal.command.ComSupport;
+import com.dy.pipIrrGlobal.command.dto.Param;
import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper;
-import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
-import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard;
import com.dy.pipIrrGlobal.voRm.VoUnclosedValve;
import com.dy.pipIrrGlobal.voSe.VoVirtualCard;
import com.dy.pipIrrWechat.command.dto.ValveClose;
import com.dy.pipIrrWechat.command.dto.ValveOpen;
-import com.dy.pipIrrWechat.command.enums.LastOperateENUM;
import com.dy.pipIrrWechat.result.WechatResultCode;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -33,10 +27,9 @@
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
-import java.time.format.DateTimeFormatter;
-import java.util.Date;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
/**
* @author ZhuBaoMin
@@ -48,13 +41,13 @@
@Slf4j
@Tag(name = "灏忕▼搴忛榾鎺у櫒鎺у埗", description = "灏忕▼搴忛榾鎺у櫒鎺у埗")
@RestController
-@RequestMapping(path="valve")
+@RequestMapping(path = "valve")
@RequiredArgsConstructor
public class ValveCtrl extends ComSupport {
private final CommandSv commandSv;
private final SeVirtualCardMapper seVirtualCardMapper;
private final IDLongGenerator idLongGenerator;
- private String rtuResultSendWebUrl = "http://127.0.0.1:8087/wx/comRes/receive" ;
+ private String rtuResultSendWebUrl = "http://127.0.0.1:8087/wx/comRes/receive";
/**
* 灏忕▼搴忚繙绋嬪紑闃�
@@ -64,10 +57,8 @@
*/
@PostMapping(path = "open_wx", consumes = MediaType.APPLICATION_JSON_VALUE)
@Transactional(rollbackFor = Exception.class)
- @SsoAop()
public BaseResponse<Boolean> open(@RequestBody @Valid ValveOpen valve, BindingResult bindingResult) {
- DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyMMddHHmmss");
- if(bindingResult != null && bindingResult.hasErrors()){
+ if (bindingResult != null && bindingResult.hasErrors()) {
return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
}
@@ -81,24 +72,24 @@
* 濡傛灉鍐滄埛鏈�夋嫨铏氭嫙鍗★紝鍒欐牴鎹彇姘村彛ID鑾峰彇涓庝箣缁戝畾鐨勮櫄鎷熷崱
* 濡傛灉鍙栨按鍙f病鏈変笌涔嬬粦瀹氱殑铏氭嫙鍗★紝鍒欐彁绀哄啘鎴烽�夋嫨涓�寮犺櫄鎷熷崱
*/
- if(vcId == null) {
+ if (vcId == null) {
vcId = commandSv.getVcIdByIntakeId(intakeId);
- if(vcId == null) {
+ if (vcId == null) {
return BaseResponseUtils.buildErrorMsg(WechatResultCode.PLEASE_SELECT_A_VC.getMessage());
}
}
// 鑾峰彇绯荤粺鍙傛暟
- if(!setuped) {
+ if (!setuped) {
setUp();
}
// 铏氭嫙鍗D鎹㈣櫄鎷熷崱瀵硅薄
VoVirtualCard vc = commandSv.getVcById(vcId);
- if(vc == null) {
+ if (vc == null) {
return BaseResponseUtils.buildErrorMsg(WechatResultCode.PLEASE_SELECT_A_VC.getMessage());
}
- if(vc.getInUse() == 1) {
+ if (vc.getInUse() == 1) {
return BaseResponseUtils.buildErrorMsg(WechatResultCode.IN_USE_VC_CANNOT_OPEN_VALVE.getMessage());
}
@@ -107,7 +98,7 @@
// 鍙栨按鍙D鎹㈤榾鎺у櫒鍦板潃鍙婇�氳鍗忚
JSONObject job_rtu = getRtu(intakeId, null);
- if(job_rtu == null) {
+ if (job_rtu == null) {
return BaseResponseUtils.buildErrorMsg(WechatResultCode.RTU_NOT_EXIST.getMessage());
}
String rtuAddr = job_rtu.getString("rtuAddr");
@@ -117,7 +108,7 @@
String orderNo = generateOrderNo();
String commandCode = null;
- if(protocol.equals("p206V202404")) {
+ if (protocol.equals("p206V202404")) {
// 鑾峰彇鍔熻兘鐮�
commandCode = CodeV202404.cd_A2;
@@ -132,147 +123,54 @@
param.elePrice = 0.0;
param.orderNo = orderNo;
- // 鏋勯�犲懡浠�
- Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
+ /**
+ * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
+ * 1 鍑嗗鍙傛暟
+ * 2 璋冪敤鍏叡鏂规硶
+ */
+ Param myParam = new Param();
+ myParam.setComId(comId);
+ myParam.setComType((byte)1);
+ myParam.setCommandCode(commandCode);
+ myParam.setCommandName(CodeV202404.getCodeName(commandCode));
+ myParam.setIntakeId(intakeId);
+ myParam.setRtuAddr(rtuAddr);
+ myParam.setProtocol(protocol);
+ myParam.setVcId(vcId);
+ myParam.setParam(param);
+ myParam.setRtuResultSendWebUrl(rtuResultSendWebUrl);
+ myParam.setOperator(operator);
+ return dealWithCommandResult(myParam);
- // 鍙戦�佸懡浠�
- JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
- if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
- //if(1 > 0) {
- // 璇锋眰鎴愬姛
-
- // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
- String commandName = CodeV202404.getCodeName(commandCode);
- RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
- commandSv.insert(rmCommandHistory);
-
- // 澶勭悊鍥炶皟
- BaseResponse response_CallBack = dealWithCallBack(comId);
-
- // 鍥炶皟澶辫触
- if(!response_CallBack.getCode().equals("0001")) {
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getMsg());
- //return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
- }
-
- // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
- JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
- System.out.println(job_content);
- JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
- System.out.println(job_subData);
- Boolean dealResult = job_subData.getBoolean("success");
- if(!dealResult) {
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
- }
-
- /**
- * 鎵ц鎴愬姛
- * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
- */
- //SeVirtualCard virtualCard = new SeVirtualCard();
- //virtualCard.setId(vcId);
- //virtualCard.setInUse((byte) 1);
- //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
- //virtualCard.setLastOperateTime(new Date());
- //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
-
- // 鍥炶皟杩斿洖鐨勫唴瀹�
- Data myData = (Data)response_CallBack.getContent();
- return BaseResponseUtils.buildSuccess(myData) ;
- } else {
- // 璇锋眰澶辫触
- JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
- return BaseResponseUtils.buildErrorMsg(job_param.getString("message"));
- }
- } else if(protocol.equals("p206V1_0_1")) {
+ } else if (protocol.equals("p206V1_0_1")) {
// 鑾峰彇鍔熻兘鐮�
commandCode = CodeV1_0_1.cd_97;
// 鍒涘缓瑙嗗浘
- Com97Vo param = new Com97Vo() ;
+ Com97Vo param = new Com97Vo();
param.icCardNo = vc.getVcNum();
param.moneyRemain = vc.getMoney();
param.waterPrice = waterPrice;
param.orderNo = orderNo;
- // 鏋勯�犲懡浠�
- Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
-
- // 鍙戦�佸懡浠�
- JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
- if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
- //if(1 > 0) {
- // 璇锋眰鎴愬姛
-
- // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
- String commandName = CodeV1_0_1.getCodeName(commandCode);
- RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
- commandSv.insert(rmCommandHistory);
-
- // 澶勭悊鍥炶皟
- BaseResponse response_CallBack = dealWithCallBack(comId);
-
- //鍥炶皟寮傚父
- if(!response_CallBack.getCode().equals("0001")) {
- // 鍛戒护鏃ュ織鎵ц缁撴灉鏀逛负澶辫触
- rmCommandHistory = new RmCommandHistory();
- rmCommandHistory.setId(comId);
- rmCommandHistory.setResult((byte)0);
- commandSv.update(rmCommandHistory);
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
- }
-
- // 鍥炶皟瓒呮椂
- if(response_CallBack.getContent().toString().equals(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage())) {
- /**
- * 鍥炶皟瓒呮椂锛屾殏鏃惰涓烘墽琛屽け璐�
- * 鍛戒护缃负澶辫触
- * 铏氭嫙鍗′緷鏃т繚鎸佷娇鐢ㄤ腑鐨勭姸鎬�
- */
-
- rmCommandHistory = new RmCommandHistory();
- rmCommandHistory.setId(comId);
- rmCommandHistory.setResult((byte)0);
- commandSv.update(rmCommandHistory);
-
- //SeVirtualCard virtualCard = new SeVirtualCard();
- //virtualCard.setId(vcId);
- //virtualCard.setInUse((byte) 1);
- //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
- //virtualCard.setLastOperateTime(new Date());
- //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
- return BaseResponseUtils.buildErrorMsg(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
- }
-
- // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
- JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
- System.out.println(job_content);
- JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
- System.out.println(job_subData);
- Boolean dealResult = job_subData.getBoolean("success");
- if(!dealResult) {
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
- }
-
- /**
- * 鎵ц鎴愬姛
- * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
- */
- SeVirtualCard virtualCard = new SeVirtualCard();
- virtualCard.setId(vcId);
- virtualCard.setInUse((byte) 1);
- virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
- virtualCard.setLastOperateTime(new Date());
- seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
-
- // 鍥炶皟杩斿洖鐨勫唴瀹�
- Data myData = (Data)response_CallBack.getContent();
- return BaseResponseUtils.buildSuccess(myData) ;
- } else {
- // 璇锋眰澶辫触
- JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
- return BaseResponseUtils.buildErrorMsg(job_param.getString("message"));
- }
+ /**
+ * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
+ * 1 鍑嗗鍙傛暟
+ * 2 璋冪敤鍏叡鏂规硶
+ */
+ Param myParam = new Param();
+ myParam.setComId(comId);
+ myParam.setComType((byte)1);
+ myParam.setCommandCode(commandCode);
+ myParam.setCommandName(CodeV1_0_1.getCodeName(commandCode));
+ myParam.setIntakeId(intakeId);
+ myParam.setRtuAddr(rtuAddr);
+ myParam.setProtocol(protocol);
+ myParam.setVcId(vcId);
+ myParam.setParam(param);
+ myParam.setRtuResultSendWebUrl(rtuResultSendWebUrl);
+ myParam.setOperator(operator);
+ return dealWithCommandResult(myParam);
} else {
return BaseResponseUtils.buildErrorMsg("绯荤粺鏆備笉鏀寔璇ュ崗璁�");
}
@@ -280,40 +178,40 @@
/**
* 灏忕▼搴忚繙绋嬪叧闃�
+ *
* @param valve
* @param bindingResult
* @return
*/
@PostMapping(path = "close_wx", consumes = MediaType.APPLICATION_JSON_VALUE)
@Transactional(rollbackFor = Exception.class)
- @SsoAop()
public BaseResponse<Boolean> close(@RequestBody @Valid ValveClose valve, BindingResult bindingResult) {
- DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyMMddHHmmss");
- if(bindingResult != null && bindingResult.hasErrors()){
+ if (bindingResult != null && bindingResult.hasErrors()) {
return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
}
String rtuAddr = valve.getRtuAddr();
String vcNum = valve.getVcNum();
+ Long vcId = Optional.ofNullable(seVirtualCardMapper.getVcIdByNum(vcNum)).orElse(0L);
String orderNo = valve.getOrderNo();
Long operator = valve.getOperator();
Long comId = idLongGenerator.generate();
// 鑾峰彇绯荤粺鍙傛暟
- if(!setuped) {
+ if (!setuped) {
setUp();
}
// 闃�鎺у櫒鍦板潃鎹㈠彇姘村彛ID鍜岄�氳鍗忚
JSONObject job_rtu = getRtu(null, rtuAddr);
- if(job_rtu == null) {
+ if (job_rtu == null) {
return BaseResponseUtils.buildErrorMsg(WechatResultCode.RTU_NOT_EXIST.getMessage());
}
Long intakeId = job_rtu.getLong("intakeId");
String protocol = job_rtu.getString("protocol");
String commandCode = null;
- if(protocol.equals("p206V202404")) {
+ if (protocol.equals("p206V202404")) {
// 鑾峰彇鍔熻兘鐮�
commandCode = CodeV202404.cd_A3;
@@ -324,147 +222,51 @@
param.icCardNo = vcNum;
param.orderNo = orderNo;
- // 鏋勯�犲懡浠�
- Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
-
- // 鍙戦�佸懡浠�
- JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
- if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
- // 璇锋眰鎴愬姛
-
- // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
- String commandName = CodeV202404.getCodeName(commandCode);
- RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
- commandSv.insert(rmCommandHistory);
-
- // 澶勭悊鍥炶皟
- BaseResponse response_CallBack = dealWithCallBack(comId);
-
- // 鍥炶皟澶辫触
- if(!response_CallBack.getCode().equals("0001")) {
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getMsg());
- //return BaseResponseUtils.buildErrorMsg(WechatResultCode.GET_RESULT_ERROR.getMessage());
- }
-
- // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
- JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
- System.out.println(job_content);
- JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
- System.out.println(job_subData);
- Boolean dealResult = job_subData.getBoolean("success");
- if(!dealResult) {
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
- }
-
- /**
- * 鎵ц鎴愬姛
- * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
- */
- //Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
- //SeVirtualCard virtualCard = new SeVirtualCard();
- //virtualCard.setId(vcId);
- //virtualCard.setInUse((byte) 0);
- //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
- //virtualCard.setLastOperateTime(new Date());
- //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
-
- // 鍥炶皟杩斿洖鐨勫唴瀹�
- Data myData = (Data)response_CallBack.getContent();
- return BaseResponseUtils.buildSuccess(myData) ;
- } else {
- // 璇锋眰澶辫触
- JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
- return BaseResponseUtils.buildErrorMsg(job_param.getString("message"));
- }
- } else if(protocol.equals("p206V1_0_1")) {
+ /**
+ * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
+ * 1 鍑嗗鍙傛暟
+ * 2 璋冪敤鍏叡鏂规硶
+ */
+ Param myParam = new Param();
+ myParam.setComId(comId);
+ myParam.setComType((byte)2);
+ myParam.setCommandCode(commandCode);
+ myParam.setCommandName(CodeV202404.getCodeName(commandCode));
+ myParam.setIntakeId(intakeId);
+ myParam.setRtuAddr(rtuAddr);
+ myParam.setProtocol(protocol);
+ myParam.setVcId(vcId);
+ myParam.setParam(param);
+ myParam.setRtuResultSendWebUrl(rtuResultSendWebUrl);
+ myParam.setOperator(operator);
+ return dealWithCommandResult(myParam);
+ } else if (protocol.equals("p206V1_0_1")) {
// 鑾峰彇鍔熻兘鐮�
commandCode = CodeV1_0_1.cd_98;
// 鍒涘缓瑙嗗浘
- Com98Vo param = new Com98Vo() ;
+ Com98Vo param = new Com98Vo();
param.icCardNo = vcNum;
param.orderNo = orderNo;
- // 鏋勯�犲懡浠�
- Command com = command(comId, commandCode, rtuAddr, protocol, rtuResultSendWebUrl, param);
-
- // 鍙戦�佸懡浠�
- JSONObject response_SendCom= (JSONObject) JSON.toJSON(sendCom2Mw(com));
- if(response_SendCom != null && response_SendCom.getString("code").equals("0001")) {
- //if(1 > 0) {
- // 璇锋眰鎴愬姛
-
- // 鍒涘缓鍛戒护鏃ュ織瀵硅薄骞舵坊鍔犲埌鏁版嵁搴撲腑
- String commandName = CodeV1_0_1.getCodeName(commandCode);
- RmCommandHistory rmCommandHistory = getComHistory(comId, commandCode, commandName, intakeId, rtuAddr, protocol, param, operator);
- commandSv.insert(rmCommandHistory);
-
- // 澶勭悊鍥炶皟
- BaseResponse response_CallBack = dealWithCallBack(comId);
-
- // 鍥炶皟寮傚父
- if(!response_CallBack.getCode().equals("0001")) {
- // 鍛戒护鏃ュ織鎵ц缁撴灉鏀逛负澶辫触
- rmCommandHistory = new RmCommandHistory();
- rmCommandHistory.setId(comId);
- rmCommandHistory.setResult((byte)0);
- commandSv.update(rmCommandHistory);
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
- }
-
- // 鍥炶皟瓒呮椂
- if(response_CallBack.getContent().toString().equals(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage())) {
- /**
- * 鍥炶皟瓒呮椂锛屾殏鏃惰涓烘墽琛屽け璐�
- * 鍛戒护缃负澶辫触
- * 铏氭嫙鍗′緷鏃т繚鎸佷娇鐢ㄤ腑鐨勭姸鎬�
- */
-
- rmCommandHistory = new RmCommandHistory();
- rmCommandHistory.setId(comId);
- rmCommandHistory.setResult((byte)0);
- commandSv.update(rmCommandHistory);
-
- //Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
- //SeVirtualCard virtualCard = new SeVirtualCard();
- //virtualCard.setId(vcId);
- //virtualCard.setInUse((byte) 0);
- //virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
- //virtualCard.setLastOperateTime(new Date());
- //seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
- return BaseResponseUtils.buildErrorMsg(WechatResultCode.GET_RESULT_IN_ONE_MINUTE.getMessage());
- }
-
- // 鍥炶皟鎴愬姛锛屽啀鍒ゆ柇鎵ц鏄惁鎴愬姛
- JSONObject job_content = (JSONObject)JSON.toJSON(response_CallBack.getContent());
- System.out.println(job_content);
- JSONObject job_subData = (JSONObject) job_content.getJSONObject("subData").getJSONObject("subData");
- System.out.println(job_subData);
- Boolean dealResult = job_subData.getBoolean("success");
- if(!dealResult) {
- return BaseResponseUtils.buildErrorMsg(response_CallBack.getContent().toString());
- }
-
- /**
- * 鎵ц鎴愬姛
- * 鏇存敼铏氭嫙鍗$姸鎬侊細鏄惁浣跨敤涓�佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂�
- */
- Long vcId = seVirtualCardMapper.getVcIdByNum(vcNum);
- SeVirtualCard virtualCard = new SeVirtualCard();
- virtualCard.setId(vcId);
- virtualCard.setInUse((byte) 0);
- virtualCard.setLastOperate(LastOperateENUM.OPEN_VALVE.getCode());
- virtualCard.setLastOperateTime(new Date());
- seVirtualCardMapper.updateByPrimaryKeySelective(virtualCard);
-
- // 鍥炶皟杩斿洖鐨勫唴瀹�
- Data myData = (Data)response_CallBack.getContent();
- return BaseResponseUtils.buildSuccess(myData) ;
- } else {
- // 璇锋眰澶辫触
- JSONObject job_param = response_SendCom.getJSONObject("content").getJSONObject("param");
- return BaseResponseUtils.buildErrorMsg(job_param.getString("message"));
- }
+ /**
+ * 鏋勯�犲懡浠ゃ�佸彂閫佸懡浠ゅ苟澶勭悊璇锋眰缁撴灉鍙婃墽琛岀粨鏋�
+ * 1 鍑嗗鍙傛暟
+ * 2 璋冪敤鍏叡鏂规硶
+ */
+ Param myParam = new Param();
+ myParam.setComId(comId);
+ myParam.setComType((byte)2);
+ myParam.setCommandCode(commandCode);
+ myParam.setCommandName(CodeV1_0_1.getCodeName(commandCode));
+ myParam.setIntakeId(intakeId);
+ myParam.setRtuAddr(rtuAddr);
+ myParam.setProtocol(protocol);
+ myParam.setVcId(vcId);
+ myParam.setParam(param);
+ myParam.setRtuResultSendWebUrl(rtuResultSendWebUrl);
+ myParam.setOperator(operator);
+ return dealWithCommandResult(myParam);
} else {
return BaseResponseUtils.buildErrorMsg("绯荤粺鏆備笉鏀寔璇ュ崗璁�");
}
@@ -472,18 +274,18 @@
/**
* 鏍规嵁鎿嶄綔鍛業D鑾峰彇鏈叧闃�璁板綍
+ *
* @param operator
* @return
*/
@GetMapping(path = "/get")
- //@SsoAop()
- public BaseResponse<List<VoUnclosedValve>> getUnclosedValves(@RequestParam Long operator){
+ public BaseResponse<List<VoUnclosedValve>> getUnclosedValves(@RequestParam Long operator) {
try {
List<VoUnclosedValve> res = commandSv.getUnclosedValves(operator);
return BaseResponseUtils.buildSuccess(res);
} catch (Exception e) {
log.error("鑾峰彇鏈叧闃�璁板綍寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage()) ;
+ return BaseResponseUtils.buildException(e.getMessage());
}
}
}
--
Gitblit v1.8.0