From 2a4e8387ebce7c0b20a69e9d0b1bda86c57a76fe Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 16 八月 2022 13:48:02 +0800
Subject: [PATCH] 优化代码

---
 service-user/src/main/java/com/java110/user/cmd/owner/QueryOwnersCmd.java |   37 +++++++++++++------------------------
 1 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/service-user/src/main/java/com/java110/user/cmd/owner/QueryOwnersCmd.java b/service-user/src/main/java/com/java110/user/cmd/owner/QueryOwnersCmd.java
index 4402907..b0079fe 100644
--- a/service-user/src/main/java/com/java110/user/cmd/owner/QueryOwnersCmd.java
+++ b/service-user/src/main/java/com/java110/user/cmd/owner/QueryOwnersCmd.java
@@ -3,7 +3,7 @@
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 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.dto.RoomDto;
 import com.java110.dto.basePrivilege.BasePrivilegeDto;
@@ -26,7 +26,7 @@
 import java.util.Map;
 
 @Java110Cmd(serviceCode = "owner.queryOwners")
-public class QueryOwnersCmd extends AbstractServiceCmdListener {
+public class QueryOwnersCmd extends Cmd {
 
     @Autowired
     private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
@@ -49,18 +49,14 @@
 
     @Override
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
-//鏍规嵁鎴垮眿鏌ヨ鏃� 鍏堢敤 鎴垮眿淇℃伅鏌ヨ 涓氫富ID
+        //鏍规嵁鎴垮眿鏌ヨ鏃� 鍏堢敤 鎴垮眿淇℃伅鏌ヨ 涓氫富ID
         freshRoomId(reqJson);
-
-        if (reqJson.containsKey("name")) {
+        if (reqJson.containsKey("name") && !StringUtil.isEmpty(reqJson.getString("name"))) {
             queryByCondition(reqJson, cmdDataFlowContext);
             return;
         }
-
         int row = reqJson.getInteger("row");
-
         ApiOwnerVo apiOwnerVo = new ApiOwnerVo();
-
         //鏌ヨ鎬昏褰曟暟
         int total = ownerInnerServiceSMOImpl.queryOwnersCount(BeanConvertUtil.covertBean(reqJson, OwnerDto.class));
         apiOwnerVo.setTotal(total);
@@ -85,45 +81,34 @@
             }
             apiOwnerVo.setOwners(BeanConvertUtil.covertBeanList(ownerDtos, ApiOwnerDataVo.class));
         }
-
         apiOwnerVo.setRecords((int) Math.ceil((double) total / (double) row));
-
-
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(apiOwnerVo), HttpStatus.OK);
         cmdDataFlowContext.setResponseEntity(responseEntity);
     }
 
     private void freshRoomId(JSONObject reqJson) {
-
         if (!reqJson.containsKey("roomName")) {
             return;
         }
-
         String roomName = reqJson.getString("roomName");
         if (StringUtil.isEmpty(roomName)) {
             return;
         }
-
         if (!roomName.contains("-")) {
             throw new IllegalArgumentException("鎴垮眿鏍煎紡閿欒,璇峰啓鍏ュ 妤兼爧-鍗曞厓-鎴垮眿 鏍煎紡");
         }
-
-        String[] params = roomName.split("-");
+        String[] params = roomName.split("-",3);
         if (params.length != 3) {
             throw new IllegalArgumentException("鎴垮眿鏍煎紡閿欒,璇峰啓鍏ュ 妤兼爧-鍗曞厓-鎴垮眿 鏍煎紡");
         }
-
         RoomDto roomDto = new RoomDto();
         roomDto.setFloorNum(params[0]);
         roomDto.setUnitNum(params[1]);
         roomDto.setRoomNum(params[2]);
         roomDto.setCommunityId(reqJson.getString("communityId"));
         List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
-
         Assert.listOnlyOne(roomDtos, "鏈煡璇㈠埌鎴垮眿涓嬩笟涓讳俊鎭�");
-
         reqJson.put("roomId", roomDtos.get(0).getRoomId());
-
     }
 
     /**
@@ -134,14 +119,20 @@
      */
     private void queryByCondition(JSONObject reqJson, ICmdDataFlowContext cmdDataFlowContext) {
         //鑾峰彇褰撳墠鐢ㄦ埛id
+        String ownerTypeCd = reqJson.getString("ownerTypeCd");
+        OwnerDto tmpOwnerDto = BeanConvertUtil.covertBean(reqJson, OwnerDto.class);
+        if(!StringUtil.isEmpty(ownerTypeCd) && ownerTypeCd.contains(",")){
+            tmpOwnerDto.setOwnerTypeCd("");
+            tmpOwnerDto.setOwnerTypeCds(ownerTypeCd.split(","));
+        }
         String userId = reqJson.getString("userId");
         int row = reqJson.getInteger("row");
         ApiOwnerVo apiOwnerVo = new ApiOwnerVo();
-        int total = ownerInnerServiceSMOImpl.queryOwnerCountByCondition(BeanConvertUtil.covertBean(reqJson, OwnerDto.class));
+        int total = ownerInnerServiceSMOImpl.queryOwnerCountByCondition(tmpOwnerDto);
         apiOwnerVo.setTotal(total);
         List<OwnerDto> ownerDtos = new ArrayList<>();
         if (total > 0) {
-            List<OwnerDto> ownerDtoList = ownerInnerServiceSMOImpl.queryOwnersByCondition(BeanConvertUtil.covertBean(reqJson, OwnerDto.class));
+            List<OwnerDto> ownerDtoList = ownerInnerServiceSMOImpl.queryOwnersByCondition(tmpOwnerDto);
             List<Map> mark = getPrivilegeOwnerList("/roomCreateFee", userId);
             for (OwnerDto ownerDto : ownerDtoList) {
                 //瀵逛笟涓昏韩浠借瘉鍙烽殣钘忓鐞�
@@ -160,9 +151,7 @@
             }
             apiOwnerVo.setOwners(BeanConvertUtil.covertBeanList(ownerDtos, ApiOwnerDataVo.class));
         }
-
         apiOwnerVo.setRecords((int) Math.ceil((double) total / (double) row));
-
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(apiOwnerVo), HttpStatus.OK);
         cmdDataFlowContext.setResponseEntity(responseEntity);
     }

--
Gitblit v1.8.0