From 0f338bf642827ce4e617facb06a7a74ab654edcf Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 21 六月 2022 09:23:26 +0800
Subject: [PATCH] 优化代码
---
service-community/src/main/java/com/java110/community/cmd/unit/UpdateUnitCmd.java | 89 +++++++++++++++++++++++++-------------------
1 files changed, 51 insertions(+), 38 deletions(-)
diff --git a/service-community/src/main/java/com/java110/community/cmd/unit/UpdateUnitCmd.java b/service-community/src/main/java/com/java110/community/cmd/unit/UpdateUnitCmd.java
index 7afe39b..4f6754b 100644
--- a/service-community/src/main/java/com/java110/community/cmd/unit/UpdateUnitCmd.java
+++ b/service-community/src/main/java/com/java110/community/cmd/unit/UpdateUnitCmd.java
@@ -1,27 +1,15 @@
-/*
- * 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.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,45 +17,70 @@
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.updateUnit
- * 璇锋眰璺姴锛�/app/unit.UpdateUnit
- * 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.updateUnit")
-public class UpdateUnitCmd extends AbstractServiceCmdListener {
+public class UpdateUnitCmd extends Cmd {
+ @Autowired
+ private IFloorInnerServiceSMO floorInnerServiceSMOImpl;
- private static Logger logger = LoggerFactory.getLogger(UpdateUnitCmd.class);
-
+ @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, "communityId", "communityId涓嶈兘涓虹┖");
+ Assert.jsonObjectHaveKey(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId鑺傜偣");
+ Assert.jsonObjectHaveKey(reqJson, "floorId", "璇锋眰鎶ユ枃涓湭鍖呭惈floorId鑺傜偣");
+ Assert.jsonObjectHaveKey(reqJson, "unitId", "璇锋眰鎶ユ枃涓湭鍖呭惈unitId鑺傜偣");
+ 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涓嶆槸璇ュ皬鍖虹殑妤�");
+ }
+
+ //鏍¢獙 灏忓尯妤糏D 鍜屽崟鍏僆D鏄惁鏈夊叧绯�
+ UnitDto unitDto = new UnitDto();
+ unitDto.setFloorId(reqJson.getString("floorId"));
+ unitDto.setUnitId(reqJson.getString("unitId"));
+ total = unitInnerServiceSMOImpl.queryUnitsCount(unitDto);
+ if (total < 1) {
+ throw new IllegalArgumentException("浼犲叆鍗曞厓涓嶆槸璇ュ皬鍖虹殑妤肩殑鍗曞厓");
+ }
}
@Override
@Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
-
- UnitPo unitPo = BeanConvertUtil.covertBean(reqJson, UnitPo.class);
+ JSONObject businessUnit = new JSONObject();
+ businessUnit.put("floorId", reqJson.getString("floorId"));
+ businessUnit.put("layerCount", reqJson.getString("layerCount"));
+ businessUnit.put("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.updateUnit(unitPo);
if (flag < 1) {
- throw new CmdException("鏇存柊鏁版嵁澶辫触");
+ throw new CmdException("淇敼鍗曞厓澶辫触");
}
cmdDataFlowContext.setResponseEntity(ResultVo.success());
--
Gitblit v1.8.0