From 803afe68037faac34b7b120505ffeed434580318 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 14 七月 2023 14:06:40 +0800
Subject: [PATCH] 优化代码
---
service-user/src/main/java/com/java110/user/cmd/org/SaveOrgCmd.java | 37 +++++++++++++++++++++++++++++--------
1 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/service-user/src/main/java/com/java110/user/cmd/org/SaveOrgCmd.java b/service-user/src/main/java/com/java110/user/cmd/org/SaveOrgCmd.java
index fab1e8f..a087420 100644
--- a/service-user/src/main/java/com/java110/user/cmd/org/SaveOrgCmd.java
+++ b/service-user/src/main/java/com/java110/user/cmd/org/SaveOrgCmd.java
@@ -19,9 +19,10 @@
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.dto.org.OrgDto;
import com.java110.intf.user.IOrgV1InnerServiceSMO;
import com.java110.po.org.OrgPo;
import com.java110.utils.exception.CmdException;
@@ -31,6 +32,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import java.util.List;
/**
* 绫昏〃杩帮細淇濆瓨
@@ -43,7 +46,7 @@
* // modify by 寮犱笁 at 2021-09-12 绗�10琛屽湪鏌愮鍦烘櫙涓嬪瓨鍦ㄦ煇绉峛ug 闇�瑕佷慨澶嶏紝娉ㄩ噴10鑷�20琛� 鍔犲叆 20琛岃嚦30琛�
*/
@Java110Cmd(serviceCode = "org.saveOrg")
-public class SaveOrgCmd extends AbstractServiceCmdListener {
+public class SaveOrgCmd extends Cmd {
private static Logger logger = LoggerFactory.getLogger(SaveOrgCmd.class);
@@ -54,11 +57,20 @@
@Override
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
- Assert.hasKeyAndValue(reqJson, "orgId", "璇锋眰鎶ユ枃涓湭鍖呭惈orgId");
-Assert.hasKeyAndValue(reqJson, "storeId", "璇锋眰鎶ユ枃涓湭鍖呭惈storeId");
-Assert.hasKeyAndValue(reqJson, "orgName", "璇锋眰鎶ユ枃涓湭鍖呭惈orgName");
-Assert.hasKeyAndValue(reqJson, "orgLevel", "璇锋眰鎶ユ枃涓湭鍖呭惈orgLevel");
-Assert.hasKeyAndValue(reqJson, "parentOrgId", "璇锋眰鎶ユ枃涓湭鍖呭惈parentOrgId");
+ Assert.hasKeyAndValue(reqJson, "orgName", "蹇呭~锛岃濉啓缁勭粐鍚嶇О");
+ Assert.hasKeyAndValue(reqJson, "parentOrgId", "蹇呭~锛岃閫夋嫨涓婄骇ID");
+ //Assert.hasKeyAndValue(reqJson, "belongCommunityId", "蹇呭~锛岃閫夋嫨闅跺睘灏忓尯");
+ //Assert.hasKeyAndValue(reqJson, "description", "蹇呭~锛岃濉啓鎻忚堪");
+
+ OrgDto orgDto = new OrgDto();
+ orgDto.setOrgId(reqJson.getString("parentOrgId"));
+ List<OrgDto> orgDtos = orgV1InnerServiceSMOImpl.queryOrgs(orgDto);
+
+ Assert.listOnlyOne(orgDtos,"涓婄骇缁勭粐涓嶅瓨鍦�");
+
+ int orgLevel = Integer.parseInt(orgDtos.get(0).getOrgLevel());
+ orgLevel +=1;
+ reqJson.put("orgLevel",orgLevel);
}
@@ -66,8 +78,17 @@
@Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
- OrgPo orgPo = BeanConvertUtil.covertBean(reqJson, OrgPo.class);
+ String storeId = cmdDataFlowContext.getReqHeaders().get("store-id");
+
+ JSONObject businessOrg = new JSONObject();
+ businessOrg.putAll(reqJson);
+ businessOrg.put("allowOperation", "T");
+ businessOrg.put("belongCommunityId", "");
+
+ OrgPo orgPo = BeanConvertUtil.covertBean(businessOrg, OrgPo.class);
orgPo.setOrgId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+ orgPo.setStoreId(storeId);
+
int flag = orgV1InnerServiceSMOImpl.saveOrg(orgPo);
if (flag < 1) {
--
Gitblit v1.8.0