From 2d9f375aa63d2eb16fb4849f23536542e27caa2f Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 30 九月 2022 13:29:48 +0800
Subject: [PATCH] 优化代码

---
 service-community/src/main/java/com/java110/community/cmd/community/UpdateCommunityCmd.java |   83 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/service-community/src/main/java/com/java110/community/cmd/community/UpdateCommunityCmd.java b/service-community/src/main/java/com/java110/community/cmd/community/UpdateCommunityCmd.java
index 9c2bdf0..a9527df 100644
--- a/service-community/src/main/java/com/java110/community/cmd/community/UpdateCommunityCmd.java
+++ b/service-community/src/main/java/com/java110/community/cmd/community/UpdateCommunityCmd.java
@@ -15,23 +15,58 @@
  */
 package com.java110.community.cmd.community;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.java110.community.bmo.community.ICommunityBMO;
 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.doc.annotation.*;
 import com.java110.intf.community.ICommunityV1InnerServiceSMO;
-import com.java110.po.community.CommunityPo;
 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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import com.java110.core.log.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
 
+@Java110CmdDoc(title = "淇敼灏忓尯",
+        description = "涓昏鎻愪緵缁欏绯荤粺淇敼灏忓尯",
+        httpMethod = "post",
+        url = "http://{ip}:{port}/app/community.updateCommunity",
+        resource = "communityDoc",
+        author = "鍚村鏂�",
+        serviceCode = "community.updateCommunity"
+)
+
+@Java110ParamsDoc(params = {
+        @Java110ParamDoc(name = "communityId", length = 30, remark = "灏忓尯缂栫爜"),
+        @Java110ParamDoc(name = "address", length = 30, remark = "灏忓尯鍦板潃"),
+        @Java110ParamDoc(name = "cityCode", length = 12, remark = "鍦板尯缂栫爜"),
+        @Java110ParamDoc(name = "feePrice", type = "int",length = 11, remark = "灏忓尯鏀惰垂浠锋牸"),
+        @Java110ParamDoc(name = "mapX", length = 12, remark = "缁忓害"),
+        @Java110ParamDoc(name = "mapY", length = 12, remark = "绾害"),
+        @Java110ParamDoc(name = "name", length = 64, remark = "鍚嶇О"),
+        @Java110ParamDoc(name = "nearbyLandmarks", length = 64, remark = "鍦版爣锛屽xx 鍏洯鏃�"),
+        @Java110ParamDoc(name = "payFeeMonth", type = "int",length = 11, remark = "灏忓尯鏀惰垂鍛ㄦ湡"),
+        @Java110ParamDoc(name = "tel", length = 11, remark = "灏忓尯瀹㈡湇鐢佃瘽"),
+})
+
+@Java110ResponseDoc(
+        params = {
+                @Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "杩斿洖缂栧彿锛�0 鎴愬姛 鍏朵粬澶辫触"),
+                @Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "鎴愬姛", remark = "鎻忚堪"),
+        }
+)
+
+@Java110ExampleDoc(
+        reqBody="{\"communityId\":\"2022092293190329\",\"name\":\"api鎺ュ彛灏忓尯1\",\"address\":\"澶╂触鐪佸ぉ娲ュ競鍜屽钩鍖篴pi鎺ュ彛灏忓尯\",\"nearbyLandmarks\":\"23\",\"cityCode\":\"120101\",\"mapX\":\"101.33\",\"mapY\":\"101.33\",\"payFeeMonth\":12,\"feePrice\":0,\"tel\":\"18909711443\",\"attrs\":[{\"domain\":\"COMMON\",\"listShow\":\"Y\",\"page\":-1,\"records\":0,\"required\":\"Y\",\"row\":0,\"specCd\":\"9329000004\",\"specHoldplace\":\"蹇呭~锛岃濉啓绀惧尯缂栫爜\",\"specId\":\"9329000004\",\"specName\":\"绀惧尯缂栫爜\",\"specShow\":\"Y\",\"specType\":\"2233\",\"specValueType\":\"1001\",\"statusCd\":\"0\",\"tableName\":\"building_community_attr\",\"total\":0,\"value\":\"123123\",\"values\":[],\"attrId\":\"112022092280950341\"}]}",
+        resBody="{'code':0,'msg':'鎴愬姛'}"
+)
 /**
  * 绫昏〃杩帮細鏇存柊
  * 鏈嶅姟缂栫爜锛歝ommunity.updateCommunity
@@ -43,7 +78,7 @@
  * // modify by 寮犱笁 at 2021-09-12 绗�10琛屽湪鏌愮鍦烘櫙涓嬪瓨鍦ㄦ煇绉峛ug 闇�瑕佷慨澶嶏紝娉ㄩ噴10鑷�20琛� 鍔犲叆 20琛岃嚦30琛�
  */
 @Java110Cmd(serviceCode = "community.updateCommunity")
-public class UpdateCommunityCmd extends AbstractServiceCmdListener {
+public class UpdateCommunityCmd extends Cmd {
 
     private static Logger logger = LoggerFactory.getLogger(UpdateCommunityCmd.class);
 
@@ -51,9 +86,20 @@
     @Autowired
     private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl;
 
+
+    @Autowired
+    private ICommunityBMO communityBMOImpl;
+
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
-        Assert.hasKeyAndValue(reqJson, "communityId", "communityId涓嶈兘涓虹┖");
+
+        Assert.hasKeyAndValue(reqJson, "communityId", "灏忓尯ID涓嶈兘涓虹┖");
+        Assert.hasKeyAndValue(reqJson, "name", "蹇呭~锛岃濉啓灏忓尯鍚嶇О");
+        Assert.hasKeyAndValue(reqJson, "address", "蹇呭~锛岃濉啓灏忓尯鍦板潃");
+        Assert.hasKeyAndValue(reqJson, "nearbyLandmarks", "蹇呭~锛岃濉啓灏忓尯闄勮繎鍦版爣");
+
+        Assert.judgeAttrValue(reqJson);
 
     }
 
@@ -61,11 +107,28 @@
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
 
-        CommunityPo communityPo = BeanConvertUtil.covertBean(reqJson, CommunityPo.class);
-        int flag = communityV1InnerServiceSMOImpl.updateCommunity(communityPo);
 
-        if (flag < 1) {
-            throw new CmdException("鏇存柊鏁版嵁澶辫触");
+        communityBMOImpl.updateCommunityOne(reqJson, cmdDataFlowContext);
+
+        if (!reqJson.containsKey("attrs")) {
+            return;
+        }
+
+        JSONArray attrs = reqJson.getJSONArray("attrs");
+        if (attrs.size() < 1) {
+            return;
+        }
+
+
+        JSONObject attr = null;
+        for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
+            attr = attrs.getJSONObject(attrIndex);
+            attr.put("communityId", reqJson.getString("communityId"));
+            if (!attr.containsKey("attrId") || attr.getString("attrId").startsWith("-") || StringUtil.isEmpty(attr.getString("attrId"))) {
+                communityBMOImpl.addAttr(attr, cmdDataFlowContext);
+                continue;
+            }
+            communityBMOImpl.updateAttr(attr, cmdDataFlowContext);
         }
 
         cmdDataFlowContext.setResponseEntity(ResultVo.success());

--
Gitblit v1.8.0