From 0b04f664887c73e90bf684a4e69c0fdbfe26349d Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期三, 29 三月 2023 13:35:20 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity
---
service-community/src/main/java/com/java110/community/cmd/unit/SaveUnitCmd.java | 130 ++++++++++++++++++++++++++++--------------
1 files changed, 86 insertions(+), 44 deletions(-)
diff --git a/service-community/src/main/java/com/java110/community/cmd/unit/SaveUnitCmd.java b/service-community/src/main/java/com/java110/community/cmd/unit/SaveUnitCmd.java
index 872fac0..ddb5154 100644
--- a/service-community/src/main/java/com/java110/community/cmd/unit/SaveUnitCmd.java
+++ b/service-community/src/main/java/com/java110/community/cmd/unit/SaveUnitCmd.java
@@ -1,27 +1,17 @@
-/*
- * 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.unit;
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.FloorDto;
+import com.java110.dto.UnitDto;
+import com.java110.intf.community.IFloorInnerServiceSMO;
+import com.java110.intf.community.IUnitInnerServiceSMO;
import com.java110.intf.community.IUnitV1InnerServiceSMO;
import com.java110.po.unit.UnitPo;
import com.java110.utils.exception.CmdException;
@@ -29,52 +19,104 @@
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;
-/**
- * 绫昏〃杩帮細淇濆瓨
- * 鏈嶅姟缂栫爜锛歶nit.saveUnit
- * 璇锋眰璺姴锛�/app/unit.SaveUnit
- * add by 鍚村鏂� at 2021-09-14 18:42:46 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琛�
- */
-@Java110Cmd(serviceCode = "unit.SaveUnit")
-public class SaveUnitCmd extends AbstractServiceCmdListener {
- private static Logger logger = LoggerFactory.getLogger(SaveUnitCmd.class);
+@Java110CmdDoc(title = "娣诲姞鍗曞厓",
+ description = "鐢ㄤ簬澶栫郴缁熸坊鍔犲崟鍏冧俊鎭姛鑳�",
+ httpMethod = "post",
+ url = "http://{ip}:{port}/app/unit.saveUnit",
+ resource = "communityDoc",
+ author = "鍚村鏂�",
+ serviceCode = "unit.saveUnit",
+ seq = 9
+)
- public static final String CODE_PREFIX_ID = "10";
+@Java110ParamsDoc(params = {
+ @Java110ParamDoc(name = "communityId", length = 30, remark = "灏忓尯ID"),
+ @Java110ParamDoc(name = "floorId", length = 30, remark = "妤兼爧ID"),
+ @Java110ParamDoc(name = "unitNum", length = 30, remark = "鍗曞厓"),
+ @Java110ParamDoc(name = "layerCount", length = 30, remark = "妤煎眰"),
+ @Java110ParamDoc(name = "lift", length = 30, remark = "1010 鏈夌數姊� 2020 鏃犵數姊�"),
+ @Java110ParamDoc(name = "unitArea", length = 30, 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="{\"floorId\":\"732022081690440002\",\"unitNum\":\"2\",\"layerCount\":\"2\",\"lift\":\"1010\",\"remark\":\"2\",\"communityId\":\"2022081539020475\",\"unitArea\":\"2\"}",
+ resBody="{'code':0,'msg':'鎴愬姛'}"
+)
+
+@Java110Cmd(serviceCode = "unit.saveUnit")
+public class SaveUnitCmd extends Cmd {
+ @Autowired
+ private IFloorInnerServiceSMO floorInnerServiceSMOImpl;
+
+ @Autowired
+ private IUnitInnerServiceSMO unitInnerServiceSMOImpl;
@Autowired
private IUnitV1InnerServiceSMO unitV1InnerServiceSMOImpl;
@Override
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
- Assert.hasKeyAndValue(reqJson, "unitId", "璇锋眰鎶ユ枃涓湭鍖呭惈unitId");
- Assert.hasKeyAndValue(reqJson, "unitNum", "璇锋眰鎶ユ枃涓湭鍖呭惈unitNum");
- Assert.hasKeyAndValue(reqJson, "floorId", "璇锋眰鎶ユ枃涓湭鍖呭惈floorId");
- Assert.hasKeyAndValue(reqJson, "layerCount", "璇锋眰鎶ユ枃涓湭鍖呭惈layerCount");
- Assert.hasKeyAndValue(reqJson, "lift", "璇锋眰鎶ユ枃涓湭鍖呭惈lift");
- Assert.hasKeyAndValue(reqJson, "userId", "璇锋眰鎶ユ枃涓湭鍖呭惈userId");
- Assert.hasKeyAndValue(reqJson, "statusCd", "璇锋眰鎶ユ枃涓湭鍖呭惈statusCd");
- Assert.hasKeyAndValue(reqJson, "unitArea", "璇锋眰鎶ユ枃涓湭鍖呭惈unitArea");
+ Assert.jsonObjectHaveKey(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId鑺傜偣");
+ Assert.jsonObjectHaveKey(reqJson, "floorId", "璇锋眰鎶ユ枃涓湭鍖呭惈floorId鑺傜偣");
+ Assert.jsonObjectHaveKey(reqJson, "unitNum", "璇锋眰鎶ユ枃涓湭鍖呭惈unitNum鑺傜偣");
+ Assert.jsonObjectHaveKey(reqJson, "layerCount", "璇锋眰鎶ユ枃涓湭鍖呭惈layerCount鑺傜偣");
+ Assert.jsonObjectHaveKey(reqJson, "lift", "璇锋眰鎶ユ枃涓湭鍖呭惈lift鑺傜偣");
+ Assert.isInteger(reqJson.getString("layerCount"), "鍗曞厓鎬诲眰鏁版嵁涓嶆槸鏈夋晥鏁板瓧");
+
+ if (!"1010".equals(reqJson.getString("lift")) && !"2020".equals(reqJson.getString("lift"))) {
+ throw new IllegalArgumentException("鏄惁鏈夌數姊� 浼犲叆鏁版嵁閿欒");
+ }
+
+ FloorDto floorDto = new FloorDto();
+ floorDto.setCommunityId(reqJson.getString("communityId"));
+ floorDto.setFloorId(reqJson.getString("floorId"));
+ //鏍¢獙灏忓尯妤糏D鍜屽皬鍖烘槸鍚︽湁瀵瑰簲鍏崇郴
+ int total = floorInnerServiceSMOImpl.queryFloorsCount(floorDto);
+
+ if (total < 1) {
+ throw new IllegalArgumentException("浼犲叆灏忓尯妤糏D涓嶆槸璇ュ皬鍖虹殑妤�");
+ }
+
+ //鏍¢獙鍗曞厓缂栧彿鏄惁宸茬粡瀛樺湪
+ UnitDto unitDto = new UnitDto();
+ unitDto.setCommunityId(reqJson.getString("communityId"));
+ unitDto.setFloorId(reqJson.getString("floorId"));
+ unitDto.setUnitNum(reqJson.getString("unitNum"));
+ int count = unitInnerServiceSMOImpl.queryUnitsCount(unitDto);
+
+ if(count > 0){
+ throw new IllegalArgumentException("鍗曞厓缂栧彿宸茬粡瀛樺湪锛岃鍕块噸澶嶆坊鍔�");
+ }
}
@Override
@Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
-
- UnitPo unitPo = BeanConvertUtil.covertBean(reqJson, UnitPo.class);
- unitPo.setUnitId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+ JSONObject businessUnit = new JSONObject();
+ businessUnit.put("floorId", reqJson.getString("floorId"));
+ businessUnit.put("layerCount", reqJson.getString("layerCount"));
+ businessUnit.put("unitId", !reqJson.containsKey("unitId") ? GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_unitId)
+ : reqJson.getString("unitId"));
+ businessUnit.put("unitNum", reqJson.getString("unitNum"));
+ businessUnit.put("lift", reqJson.getString("lift"));
+ businessUnit.put("remark", reqJson.getString("remark"));
+ businessUnit.put("unitArea", reqJson.getString("unitArea"));
+ businessUnit.put("userId", reqJson.getString("userId"));
+ UnitPo unitPo = BeanConvertUtil.covertBean(businessUnit, UnitPo.class);
int flag = unitV1InnerServiceSMOImpl.saveUnit(unitPo);
if (flag < 1) {
- throw new CmdException("淇濆瓨鏁版嵁澶辫触");
+ throw new CmdException("淇濆瓨鍗曞厓澶辫触");
}
cmdDataFlowContext.setResponseEntity(ResultVo.success());
--
Gitblit v1.8.0