From 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 19 七月 2022 21:49:55 +0800
Subject: [PATCH] 优化添加设备 功能
---
service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineCmd.java | 75 +++++++++++++++++++++++++++++++++----
1 files changed, 66 insertions(+), 9 deletions(-)
diff --git a/service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineCmd.java b/service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineCmd.java
index b98002e..89b14bd 100644
--- a/service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineCmd.java
+++ b/service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineCmd.java
@@ -15,22 +15,31 @@
*/
package com.java110.common.cmd.machine;
+import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.event.cmd.AbstractServiceCmdListener;
+import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.dto.community.CommunityLocationDto;
+import com.java110.intf.common.IMachineAttrInnerServiceSMO;
import com.java110.intf.common.IMachineV1InnerServiceSMO;
+import com.java110.intf.community.ICommunityLocationV1InnerServiceSMO;
+import com.java110.po.machine.MachineAttrPo;
import com.java110.po.machine.MachinePo;
+import com.java110.utils.constant.BusinessTypeConstant;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
-import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
/**
@@ -44,32 +53,80 @@
* // modify by 寮犱笁 at 2021-09-12 绗�10琛屽湪鏌愮鍦烘櫙涓嬪瓨鍦ㄦ煇绉峛ug 闇�瑕佷慨澶嶏紝娉ㄩ噴10鑷�20琛� 鍔犲叆 20琛岃嚦30琛�
*/
@Java110Cmd(serviceCode = "machine.updateMachine")
-public class UpdateMachineCmd extends AbstractServiceCmdListener {
+public class UpdateMachineCmd extends Cmd {
- private static Logger logger = LoggerFactory.getLogger(UpdateMachineCmd.class);
+ private static Logger logger = LoggerFactory.getLogger(UpdateMachineCmd.class);
@Autowired
private IMachineV1InnerServiceSMO machineV1InnerServiceSMOImpl;
+ @Autowired
+ private IMachineAttrInnerServiceSMO machineAttrInnerServiceSMOImpl;
+
+ @Autowired
+ private ICommunityLocationV1InnerServiceSMO communityLocationV1InnerServiceSMOImpl;
+
@Override
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
- Assert.hasKeyAndValue(reqJson, "machineId", "machineId涓嶈兘涓虹┖");
-Assert.hasKeyAndValue(reqJson, "communityId", "communityId涓嶈兘涓虹┖");
+ Assert.hasKeyAndValue(reqJson, "machineId", "璁惧ID涓嶈兘涓虹┖");
+ Assert.hasKeyAndValue(reqJson, "machineCode", "蹇呭~锛岃濉啓璁惧缂栫爜");
+ Assert.hasKeyAndValue(reqJson, "machineVersion", "蹇呭~锛岃濉啓璁惧鐗堟湰鍙�");
+ Assert.hasKeyAndValue(reqJson, "machineName", "蹇呭~锛岃濉啓璁惧鍚嶇О");
+ Assert.hasKeyAndValue(reqJson, "machineTypeCd", "蹇呭~锛岃閫夋嫨璁惧绫诲瀷");
+ Assert.hasKeyAndValue(reqJson, "direction", "蹇呭~锛岃閫夋嫨璁惧鏂瑰悜");
+ Assert.hasKeyAndValue(reqJson, "authCode", "蹇呭~锛岃濉啓閴存潈缂栫爜");
+ Assert.hasKeyAndValue(reqJson, "locationTypeCd", "蹇呭~锛岃閫夋嫨浣嶇疆绫诲瀷");
+ Assert.hasKeyAndValue(reqJson, "locationObjId", "蹇呭~锛岃濉啓浣嶇疆瀵硅薄ID");
+
+ Assert.judgeAttrValue(reqJson);
}
@Override
@Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
+ CommunityLocationDto communityLocationDto = new CommunityLocationDto();
+ communityLocationDto.setCommunityId(reqJson.getString("communityId"));
+ communityLocationDto.setLocationId(reqJson.getString("locationTypeCd"));
+ List<CommunityLocationDto> locationDtos = communityLocationV1InnerServiceSMOImpl.queryCommunityLocations(communityLocationDto);
- MachinePo machinePo = BeanConvertUtil.covertBean(reqJson, MachinePo.class);
+ Assert.listOnlyOne(locationDtos, "浣嶇疆涓嶅瓨鍦�");
+ MachinePo machinePo = BeanConvertUtil.covertBean(reqJson, MachinePo.class);
+ machinePo.setLocationObjId(locationDtos.get(0).getLocationObjId());
+
int flag = machineV1InnerServiceSMOImpl.updateMachine(machinePo);
-
if (flag < 1) {
throw new CmdException("鏇存柊鏁版嵁澶辫触");
}
+ JSONArray attrs = reqJson.getJSONArray("attrs");
+ if (attrs.size() < 1) {
+ return;
+ }
+
+ MachineAttrPo attr = null;
+ JSONObject aObj = null;
+ for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
+ aObj = attrs.getJSONObject(attrIndex);
+ attr = BeanConvertUtil.covertBean(aObj, MachineAttrPo.class);
+ attr.setCommunityId(reqJson.getString("communityId"));
+ attr.setMachineId(reqJson.getString("machineId"));
+ if (!aObj.containsKey("attrId") || aObj.getString("attrId").startsWith("-") || StringUtil.isEmpty(aObj.getString("attrId"))) {
+ attr.setAttrId(GenerateCodeFactory.getGeneratorId("11"));
+ flag = machineAttrInnerServiceSMOImpl.saveMachineAttrs(attr);
+ if (flag < 1) {
+ throw new CmdException("娣诲姞鏁版嵁澶辫触");
+ }
+ continue;
+ }
+ attr.setAttrId(aObj.getString("attrId"));
+ flag = machineAttrInnerServiceSMOImpl.updateMachineAttrs(attr);
+ if (flag < 1) {
+ throw new CmdException("鏇存柊鏁版嵁澶辫触");
+ }
+ }
+
cmdDataFlowContext.setResponseEntity(ResultVo.success());
}
}
--
Gitblit v1.8.0