From 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 19 七月 2022 21:49:55 +0800
Subject: [PATCH] 优化添加设备 功能

---
 service-community/src/main/java/com/java110/community/cmd/unit/DeleteUnitCmd.java |   89 ++++++++++++++++++++++++++------------------
 1 files changed, 52 insertions(+), 37 deletions(-)

diff --git a/service-community/src/main/java/com/java110/community/cmd/unit/DeleteUnitCmd.java b/service-community/src/main/java/com/java110/community/cmd/unit/DeleteUnitCmd.java
index 5f49b4a..613950d 100644
--- a/service-community/src/main/java/com/java110/community/cmd/unit/DeleteUnitCmd.java
+++ b/service-community/src/main/java/com/java110/community/cmd/unit/DeleteUnitCmd.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.dto.FloorDto;
+import com.java110.dto.RoomDto;
+import com.java110.dto.UnitDto;
+import com.java110.intf.community.IFloorInnerServiceSMO;
+import com.java110.intf.community.IRoomV1InnerServiceSMO;
+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,41 +19,66 @@
 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.deleteUnit
- * 璇锋眰璺姴锛�/app/unit.DeleteUnit
- * 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.DeleteUnit")
-public class DeleteUnitCmd extends AbstractServiceCmdListener {
-  private static Logger logger = LoggerFactory.getLogger(DeleteUnitCmd.class);
+
+@Java110Cmd(serviceCode = "unit.deleteUnit")
+public class DeleteUnitCmd extends Cmd {
+    @Autowired
+    private IFloorInnerServiceSMO floorInnerServiceSMOImpl;
+
+    @Autowired
+    private IUnitInnerServiceSMO unitInnerServiceSMOImpl;
 
     @Autowired
     private IUnitV1InnerServiceSMO unitV1InnerServiceSMOImpl;
 
+    @Autowired
+    private IRoomV1InnerServiceSMO roomV1InnerServiceSMOImpl;
+
     @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鑺傜偣");
 
+        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("浼犲叆鍗曞厓涓嶆槸璇ュ皬鍖虹殑妤肩殑鍗曞厓");
+        }
+
+        RoomDto roomDto = new RoomDto();
+        roomDto.setUnitId(reqJson.getString("unitId"));
+        roomDto.setCommunityId(reqJson.getString("communityId"));
+        int count = roomV1InnerServiceSMOImpl.queryRoomsCount(roomDto);
+        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);
+        JSONObject businessUnit = new JSONObject();
+        businessUnit.put("unitId", reqJson.getString("unitId"));
+        UnitPo unitPo = BeanConvertUtil.covertBean(businessUnit, UnitPo.class);
         int flag = unitV1InnerServiceSMOImpl.deleteUnit(unitPo);
 
         if (flag < 1) {
-            throw new CmdException("鍒犻櫎鏁版嵁澶辫触");
+            throw new CmdException("鍒犻櫎鍗曞厓澶辫触");
         }
 
         cmdDataFlowContext.setResponseEntity(ResultVo.success());

--
Gitblit v1.8.0