From 5589528feb385d7881f8dbf9314b3abf5d4f4e9e Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: 星期五, 27 一月 2023 19:21:11 +0800
Subject: [PATCH] 优化 房屋页面查询功能

---
 service-community/src/main/java/com/java110/community/cmd/room/SaveRoomCmd.java |  180 +++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 124 insertions(+), 56 deletions(-)

diff --git a/service-community/src/main/java/com/java110/community/cmd/room/SaveRoomCmd.java b/service-community/src/main/java/com/java110/community/cmd/room/SaveRoomCmd.java
index 5d8a379..b675459 100644
--- a/service-community/src/main/java/com/java110/community/cmd/room/SaveRoomCmd.java
+++ b/service-community/src/main/java/com/java110/community/cmd/room/SaveRoomCmd.java
@@ -1,87 +1,155 @@
-/*
- * Copyright 2017-2020 鍚村鏂� and java110 team.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package com.java110.community.cmd.room;
 
 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.doc.annotation.*;
+import com.java110.dto.RoomDto;
+import com.java110.dto.UnitDto;
 import com.java110.intf.community.IRoomV1InnerServiceSMO;
+import com.java110.intf.community.IUnitInnerServiceSMO;
 import com.java110.po.room.RoomPo;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
-import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-/**
- * 绫昏〃杩帮細淇濆瓨
- * 鏈嶅姟缂栫爜锛歳oom.saveRoom
- * 璇锋眰璺姴锛�/app/room.SaveRoom
- * add by 鍚村鏂� at 2021-09-14 14:28:56 mail: 928255095@qq.com
- * open source address: https://gitee.com/wuxw7/MicroCommunity
- * 瀹樼綉锛歨ttp://www.homecommunity.cn
- * 娓╅Θ鎻愮ず锛氬鏋滄偍瀵规鏂囦欢杩涜淇敼 璇蜂笉瑕佸垹闄ゅ師鏈変綔鑰呭強娉ㄩ噴淇℃伅锛岃琛ュ厖鎮ㄧ殑 淇敼鐨勫師鍥犱互鍙婅仈绯婚偖绠卞涓�
- * // modify by 寮犱笁 at 2021-09-12 绗�10琛屽湪鏌愮鍦烘櫙涓嬪瓨鍦ㄦ煇绉峛ug 闇�瑕佷慨澶嶏紝娉ㄩ噴10鑷�20琛� 鍔犲叆 20琛岃嚦30琛�
- */
+import java.util.List;
+
+
+@Java110CmdDoc(title = "娣诲姞鎴垮眿",
+        description = "瀵瑰簲鍚庡彴 娣诲姞鎴垮眿鍔熻兘",
+        httpMethod = "post",
+        url = "http://{ip}:{port}/app/room.saveRoom",
+        resource = "communityDoc",
+        author = "鍚村鏂�",
+        serviceCode = "room.saveRoom"
+)
+
+@Java110ParamsDoc(params = {
+        @Java110ParamDoc(name = "communityId", length = 30, remark = "灏忓尯ID"),
+        @Java110ParamDoc(name = "roomNum", length = 64, remark = "鎴垮彿"),
+        @Java110ParamDoc(name = "layer", length = 12, remark = "灞傛暟"),
+        @Java110ParamDoc(name = "unitId", length = 30, remark = "鍗曞厓ID"),
+        @Java110ParamDoc(name = "section", length = 12, remark = "鎴垮眿涓暟"),
+        @Java110ParamDoc(name = "apartment", length = 12, remark = "鍥哄畾 10102"),
+        @Java110ParamDoc(name = "builtUpArea", length = 12, remark = "寤虹瓚闈㈢Н"),
+        @Java110ParamDoc(name = "feeCoefficient", length = 12, remark = "绠楄垂绯绘暟 鍥哄畾1"),
+        @Java110ParamDoc(name = "state", length = 12, remark = "鐘舵�� 2002\t鏈攢鍞�"),
+        @Java110ParamDoc(name = "roomSubType", length = 12, remark = "鎴垮眿绫诲瀷 110\t浣忓畢\n" +
+                "120\t鍔炲叕瀹n" +
+                "119\t瀹胯垗"),
+        @Java110ParamDoc(name = "roomArea", length = 12, remark = "瀹ゅ唴闈㈢Н"),
+        @Java110ParamDoc(name = "roomRent", length = 12, remark = "鍔炲叕瀹� 鎴栬�呭鑸� 鏃剁閲�"),
+        @Java110ParamDoc(name = "remark", length = 512, 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="{\n" +
+                "\t\"roomNum\": \"88488\",\n" +
+                "\t\"layer\": \"1\",\n" +
+                "\t\"unitId\":\"123123123\",\n" +
+                "\t\"section\": \"0\",\n" +
+                "\t\"apartment\": \"10102\",\n" +
+                "\t\"builtUpArea\": \"110\",\n" +
+                "\t\"feeCoefficient\": \"1.00\",\n" +
+                "\t\"state\": \"2002\",\n" +
+                "\t\"remark\": \"sdf\",\n" +
+                "\t\"roomSubType\": \"110\",\n" +
+                "\t\"roomArea\": \"110\",\n" +
+                "\t\"roomRent\": \"0\",\n" +
+                "\t\"communityId\": \"2022121921870161\",\n" +
+                "}",
+        resBody="{\"code\":0,\"msg\":\"鎴愬姛\"}"
+)
+
 @Java110Cmd(serviceCode = "room.saveRoom")
-public class SaveRoomCmd extends AbstractServiceCmdListener {
+public class SaveRoomCmd extends Cmd {
 
-    private static Logger logger = LoggerFactory.getLogger(SaveRoomCmd.class);
-
-    public static final String CODE_PREFIX_ID = "10";
+    @Autowired
+    private IUnitInnerServiceSMO unitInnerServiceSMOImpl;
 
     @Autowired
     private IRoomV1InnerServiceSMO roomV1InnerServiceSMOImpl;
 
     @Override
-    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
-        Assert.hasKeyAndValue(reqJson, "roomNum", "璇锋眰鎶ユ枃涓湭鍖呭惈roomNum");
-        Assert.hasKeyAndValue(reqJson, "unitId", "璇锋眰鎶ユ枃涓湭鍖呭惈unitId");
-        Assert.hasKeyAndValue(reqJson, "layer", "璇锋眰鎶ユ枃涓湭鍖呭惈layer");
-        Assert.hasKeyAndValue(reqJson, "apartment", "璇锋眰鎶ユ枃涓湭鍖呭惈apartment");
-        Assert.hasKeyAndValue(reqJson, "builtUpArea", "璇锋眰鎶ユ枃涓湭鍖呭惈builtUpArea");
-        Assert.hasKeyAndValue(reqJson, "feeCoefficient", "璇锋眰鎶ユ枃涓湭鍖呭惈feeCoefficient");
-        Assert.hasKeyAndValue(reqJson, "userId", "璇锋眰鎶ユ枃涓湭鍖呭惈userId");
-        Assert.hasKeyAndValue(reqJson, "statusCd", "璇锋眰鎶ユ枃涓湭鍖呭惈statusCd");
-        Assert.hasKeyAndValue(reqJson, "state", "璇锋眰鎶ユ枃涓湭鍖呭惈state");
-        Assert.hasKeyAndValue(reqJson, "roomType", "璇锋眰鎶ユ枃涓湭鍖呭惈roomType");
-        Assert.hasKeyAndValue(reqJson, "roomSubType", "璇锋眰鎶ユ枃涓湭鍖呭惈roomSubType");
-        Assert.hasKeyAndValue(reqJson, "roomArea", "璇锋眰鎶ユ枃涓湭鍖呭惈roomArea");
-        Assert.hasKeyAndValue(reqJson, "roomRent", "璇锋眰鎶ユ枃涓湭鍖呭惈roomRent");
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        Assert.jsonObjectHaveKey(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "unitId", "璇锋眰鎶ユ枃涓湭鍖呭惈unitId鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "roomNum", "璇锋眰鎶ユ枃涓湭鍖呭惈roomNum鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "layer", "璇锋眰鎶ユ枃涓湭鍖呭惈layer鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "section", "璇锋眰鎶ユ枃涓湭鍖呭惈section鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "apartment", "璇锋眰鎶ユ枃涓湭鍖呭惈apartment鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "state", "璇锋眰鎶ユ枃涓湭鍖呭惈state鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "builtUpArea", "璇锋眰鎶ユ枃涓湭鍖呭惈builtUpArea鑺傜偣");
+        Assert.jsonObjectHaveKey(reqJson, "feeCoefficient", "璇锋眰鎶ユ枃涓湭鍖呭惈feeCoefficient鑺傜偣");
 
+        Assert.isInteger(reqJson.getString("section"), "鎴块棿鏁颁笉鏄湁鏁堟暟瀛�");
+        Assert.isMoney(reqJson.getString("builtUpArea"), "寤虹瓚闈㈢Н鏁版嵁鏍煎紡閿欒");
+        Assert.isMoney(reqJson.getString("feeCoefficient"), "鎴垮眿鍗曚环鏁版嵁鏍煎紡閿欒");
+
+        if (!reqJson.containsKey("roomSubType")) {
+            reqJson.put("roomSubType", RoomDto.ROOM_SUB_TYPE_PERSON);
+        }
+
+        if (!reqJson.containsKey("roomRent")) {
+            reqJson.put("roomRent", "0");
+        }
+
+        if (!reqJson.containsKey("roomArea")) {
+            reqJson.put("roomRent", reqJson.getString("builtUpArea"));
+        }
+
+        /*if (!"1010".equals(reqJson.getString("apartment")) && !"2020".equals(reqJson.getString("apartment"))) {
+            throw new IllegalArgumentException("涓嶆槸鏈夋晥鎴垮眿鎴峰瀷 浼犲叆鏁版嵁閿欒");
+        }*/
+
+        if (!"2001".equals(reqJson.getString("state"))
+                && !"2002".equals(reqJson.getString("state"))
+                && !"2003".equals(reqJson.getString("state"))
+                && !"2004".equals(reqJson.getString("state"))) {
+            throw new IllegalArgumentException("涓嶆槸鏈夋晥鎴垮眿鐘舵�� 浼犲叆鏁版嵁閿欒");
+        }
+
+        UnitDto unitDto = new UnitDto();
+        unitDto.setCommunityId(reqJson.getString("communityId"));
+        unitDto.setUnitId(reqJson.getString("unitId"));
+        //鏍¢獙灏忓尯妤糏D鍜屽皬鍖烘槸鍚︽湁瀵瑰簲鍏崇郴
+        List<UnitDto> units = unitInnerServiceSMOImpl.queryUnitsByCommunityId(unitDto);
+
+        if (units == null || units.size() < 1) {
+            throw new IllegalArgumentException("浼犲叆鍗曞厓ID涓嶆槸璇ュ皬鍖虹殑鍗曞厓");
+        }
+
+        reqJson.put("unitNum", units.get(0).getUnitNum());
     }
 
     @Override
     @Java110Transactional
-    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
-
-        RoomPo roomPo = BeanConvertUtil.covertBean(reqJson, RoomPo.class);
-        roomPo.setRoomId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
-        int flag = roomV1InnerServiceSMOImpl.saveRoom(roomPo);
-
-        if (flag < 1) {
-            throw new CmdException("淇濆瓨鏁版嵁澶辫触");
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        if ("0".equals(reqJson.getString("unitNum"))) { // 澶勭悊涓哄晢閾�
+            reqJson.put("roomType", RoomDto.ROOM_TYPE_SHOPS);
+        } else {
+            reqJson.put("roomType", RoomDto.ROOM_TYPE_ROOM);
         }
 
-        cmdDataFlowContext.setResponseEntity(ResultVo.success());
+
+        reqJson.put("roomId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_roomId));
+        reqJson.put("userId", context.getReqHeaders().get(CommonConstant.HTTP_USER_ID));
+        RoomPo roomPo = BeanConvertUtil.covertBean(reqJson, RoomPo.class);
+        roomV1InnerServiceSMOImpl.saveRoom(roomPo);
     }
 }

--
Gitblit v1.8.0