From ae42d2da37fe9d161e7058b51367b95f24c3d97a Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 13 六月 2023 15:11:36 +0800
Subject: [PATCH] optimize
---
service-common/src/main/java/com/java110/common/cmd/chargeMachine/SaveChargeMachineCmd.java | 84 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/service-common/src/main/java/com/java110/common/cmd/chargeMachine/SaveChargeMachineCmd.java b/service-common/src/main/java/com/java110/common/cmd/chargeMachine/SaveChargeMachineCmd.java
index 6cdbdfc..1e3c76b 100644
--- a/service-common/src/main/java/com/java110/common/cmd/chargeMachine/SaveChargeMachineCmd.java
+++ b/service-common/src/main/java/com/java110/common/cmd/chargeMachine/SaveChargeMachineCmd.java
@@ -15,6 +15,7 @@
*/
package com.java110.common.cmd.chargeMachine;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
@@ -22,8 +23,14 @@
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.chargeMachine.ChargeMachineDto;
+import com.java110.dto.chargeMachine.ChargeMachinePortDto;
+import com.java110.intf.common.IChargeMachinePortV1InnerServiceSMO;
+import com.java110.intf.common.IChargeMachineSpecV1InnerServiceSMO;
import com.java110.intf.common.IChargeMachineV1InnerServiceSMO;
import com.java110.po.chargeMachine.ChargeMachinePo;
+import com.java110.po.chargeMachinePort.ChargeMachinePortPo;
+import com.java110.po.chargeMachineSpec.ChargeMachineSpecPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
@@ -53,14 +60,43 @@
@Autowired
private IChargeMachineV1InnerServiceSMO chargeMachineV1InnerServiceSMOImpl;
+ @Autowired
+ private IChargeMachinePortV1InnerServiceSMO chargeMachinePortV1InnerServiceSMOImpl;
+
+ @Autowired
+ private IChargeMachineSpecV1InnerServiceSMO chargeMachineSpecV1InnerServiceSMOImpl;
+
@Override
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
Assert.hasKeyAndValue(reqJson, "machineName", "璇锋眰鎶ユ枃涓湭鍖呭惈machineName");
Assert.hasKeyAndValue(reqJson, "machineCode", "璇锋眰鎶ユ枃涓湭鍖呭惈machineCode");
Assert.hasKeyAndValue(reqJson, "implBean", "璇锋眰鎶ユ枃涓湭鍖呭惈implBean");
- Assert.hasKeyAndValue(reqJson, "durationPrice", "璇锋眰鎶ユ枃涓湭鍖呭惈durationPrice");
- Assert.hasKeyAndValue(reqJson, "energyPrice", "璇锋眰鎶ユ枃涓湭鍖呭惈energyPrice");
+ Assert.hasKeyAndValue(reqJson, "ruleId", "璇锋眰鎶ユ枃涓湭鍖呭惈ruleId");
Assert.hasKeyAndValue(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId");
+ Assert.hasKeyAndValue(reqJson, "portCount", "璇锋眰鎶ユ枃涓湭鍖呭惈portCount");
+
+ ChargeMachineDto chargeMachineDto = new ChargeMachineDto();
+ chargeMachineDto.setMachineCode(reqJson.getString("machineCode"));
+ int count = chargeMachineV1InnerServiceSMOImpl.queryChargeMachinesCount(chargeMachineDto);
+
+ if (count > 0) {
+ throw new CmdException("鍏呯數妗╃紪鍙峰凡瀛樺湪");
+ }
+
+
+ JSONArray specs = reqJson.getJSONArray("specs");
+ if (specs == null || specs.size() < 1) {
+ cmdDataFlowContext.setResponseEntity(ResultVo.success());
+
+ return;
+ }
+
+ JSONObject specObj = null;
+ for (int specIndex = 0; specIndex < specs.size(); specIndex++) {
+ specObj = specs.getJSONObject(specIndex);
+
+ Assert.hasKeyAndValue(specObj, "specValue", "鏈寘鍚�" + specObj.getString("specName"));
+ }
}
@@ -77,6 +113,50 @@
throw new CmdException("淇濆瓨鏁版嵁澶辫触");
}
+ int portCount = reqJson.getIntValue("portCount");
+ ChargeMachinePortPo chargeMachinePortPo = null;
+ for (int portIndex = 0; portIndex < portCount; portIndex++) {
+ chargeMachinePortPo = new ChargeMachinePortPo();
+ chargeMachinePortPo.setMachineId(chargeMachinePo.getMachineId());
+ chargeMachinePortPo.setPortId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+ chargeMachinePortPo.setPortCode((portIndex + 1) + "");
+ chargeMachinePortPo.setPortName((portIndex + 1) + "鍙锋彃搴�");
+ chargeMachinePortPo.setCommunityId(chargeMachinePo.getCommunityId());
+ chargeMachinePortPo.setState(ChargeMachinePortDto.STATE_FREE);
+ chargeMachinePortV1InnerServiceSMOImpl.saveChargeMachinePort(chargeMachinePortPo);
+ }
+
+ if (!reqJson.containsKey("specs")) {
+ cmdDataFlowContext.setResponseEntity(ResultVo.success());
+
+ return;
+ }
+
+ JSONArray specs = reqJson.getJSONArray("specs");
+ if (specs == null || specs.size() < 1) {
+ cmdDataFlowContext.setResponseEntity(ResultVo.success());
+
+ return;
+ }
+
+ JSONObject specObj = null;
+ ChargeMachineSpecPo chargeMachineSpecPo = null;
+ for (int specIndex = 0; specIndex < specs.size(); specIndex++) {
+ specObj = specs.getJSONObject(specIndex);
+ chargeMachineSpecPo = new ChargeMachineSpecPo();
+ chargeMachineSpecPo.setMachineId(chargeMachinePo.getMachineId());
+ chargeMachineSpecPo.setSpecId(specObj.getString("specId"));
+ chargeMachineSpecPo.setSpecName(specObj.getString("specName"));
+ chargeMachineSpecPo.setSpecValue(specObj.getString("specValue"));
+ chargeMachineSpecPo.setCmsId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+ chargeMachineSpecPo.setCommunityId(chargeMachinePo.getCommunityId());
+ flag = chargeMachineSpecV1InnerServiceSMOImpl.saveChargeMachineSpec(chargeMachineSpecPo);
+
+ if (flag < 1) {
+ throw new CmdException("淇濆瓨鏁版嵁澶辫触");
+ }
+ }
+
cmdDataFlowContext.setResponseEntity(ResultVo.success());
}
}
--
Gitblit v1.8.0