From 9cf55daaafbdf49b6e7eee8298f81a3c2e602112 Mon Sep 17 00:00:00 2001
From: 1098226878 <1098226878@qq.com>
Date: 星期二, 31 八月 2021 18:44:15 +0800
Subject: [PATCH] 优化代码

---
 service-job/src/main/java/com/java110/job/adapt/hcIot/machine/AddMachineToIotAdapt.java |  100 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 76 insertions(+), 24 deletions(-)

diff --git a/service-job/src/main/java/com/java110/job/adapt/hcIot/machine/AddMachineToIotAdapt.java b/service-job/src/main/java/com/java110/job/adapt/hcIot/machine/AddMachineToIotAdapt.java
old mode 100644
new mode 100755
index 896913d..37e3a52
--- a/service-job/src/main/java/com/java110/job/adapt/hcIot/machine/AddMachineToIotAdapt.java
+++ b/service-job/src/main/java/com/java110/job/adapt/hcIot/machine/AddMachineToIotAdapt.java
@@ -18,14 +18,16 @@
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.dto.RoomDto;
-import com.java110.dto.communityLocation.CommunityLocationDto;
+import com.java110.dto.community.CommunityLocationDto;
 import com.java110.dto.file.FileDto;
 import com.java110.dto.file.FileRelDto;
+import com.java110.dto.machine.MachineAttrDto;
 import com.java110.dto.machine.MachineDto;
 import com.java110.dto.owner.OwnerDto;
 import com.java110.entity.order.Business;
 import com.java110.intf.common.IFileInnerServiceSMO;
 import com.java110.intf.common.IFileRelInnerServiceSMO;
+import com.java110.intf.common.IMachineAttrInnerServiceSMO;
 import com.java110.intf.common.IMachineInnerServiceSMO;
 import com.java110.intf.community.ICommunityLocationInnerServiceSMO;
 import com.java110.intf.community.IRoomInnerServiceSMO;
@@ -35,10 +37,9 @@
 import com.java110.po.machine.MachinePo;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -59,6 +60,9 @@
     IMachineInnerServiceSMO machineInnerServiceSMOImpl;
 
     @Autowired
+    private IMachineAttrInnerServiceSMO machineAttrInnerServiceSMOImpl;
+
+    @Autowired
     private ICommunityLocationInnerServiceSMO communityLocationInnerServiceSMOImpl;
 
     @Autowired
@@ -72,6 +76,7 @@
 
     @Autowired
     private IFileInnerServiceSMO fileInnerServiceSMOImpl;
+
 
     /**
      * accessToken={access_token}
@@ -118,28 +123,58 @@
 
         Assert.listOnlyOne(machineDtos, "鏈壘鍒拌澶�");
 
-        if (!"9999".equals(machineDtos.get(0).getMachineTypeCd())) {
-            return;
+        CommunityLocationDto communityLocationDto = new CommunityLocationDto();
+        communityLocationDto.setLocationId(machineDtos.get(0).getLocationTypeCd());
+        communityLocationDto.setCommunityId(machineDtos.get(0).getCommunityId());
+        List<CommunityLocationDto> communityLocationDtos = communityLocationInnerServiceSMOImpl.queryCommunityLocations(communityLocationDto);
+
+        Assert.listOnlyOne(communityLocationDtos, "璁惧浣嶇疆涓嶅瓨鍦�");
+
+        String hmId = getHmId(machineDtos.get(0));
+
+        List<JSONObject> ownerDtos = null;
+        if (MachineDto.MACHINE_TYPE_ACCESS_CONTROL.equals(machineDtos.get(0).getMachineTypeCd())) {
+            ownerDtos = getOwners(machinePo);
+        } else {
+            ownerDtos = new ArrayList<>();
         }
 
-        List<MultiValueMap<String, Object>> ownerDtos = getOwners(machinePo);
+        JSONObject postParameters = new JSONObject();
 
-        MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
-
-        postParameters.add("extCommunityUuid", machinePo.getCommunityId());
-        postParameters.add("devSn", machinePo.getMachineCode());
-        postParameters.add("uuid", machineDtos.get(0).getMachineId());
-        postParameters.add("name", machinePo.getMachineName());
-        postParameters.add("positionType", "0");
-        postParameters.add("positionUuid", machinePo.getCommunityId());
+        postParameters.put("machineCode", machinePo.getMachineCode());
+        postParameters.put("machineName", machinePo.getMachineName());
+        postParameters.put("machineVersion", machinePo.getMachineVersion());
+        postParameters.put("machineTypeCd", machinePo.getMachineTypeCd());
+        postParameters.put("locationType", communityLocationDtos.get(0).getLocationType());
+        postParameters.put("locationObjId", machineDtos.get(0).getLocationObjId());
+        postParameters.put("extMachineId", machineDtos.get(0).getMachineId());
+        postParameters.put("extCommunityId", machinePo.getCommunityId());
+        postParameters.put("machineIp", machinePo.getMachineIp());
+        postParameters.put("machineMac", machinePo.getMachineMac());
+        postParameters.put("direction", machinePo.getDirection());
+        postParameters.put("hmId", hmId);
         hcMachineAsynImpl.addMachine(postParameters, ownerDtos);
     }
 
-    private List<MultiValueMap<String, Object>> getOwners(MachinePo machinePo) {
+    private String getHmId(MachineDto machineDto) {
+        MachineAttrDto machineAttrDto = new MachineAttrDto();
+        machineAttrDto.setCommunityId(machineDto.getCommunityId());
+        machineAttrDto.setMachineId(machineDto.getMachineId());
+        List<MachineAttrDto> machineAttrDtos = machineAttrInnerServiceSMOImpl.queryMachineAttrs(machineAttrDto);
+
+        for (MachineAttrDto tmpMachineAttrDto : machineAttrDtos) {
+            if (MachineAttrDto.SPEC_HM.equals(tmpMachineAttrDto.getSpecCd())) {
+                return tmpMachineAttrDto.getValue();
+            }
+        }
+        return "";
+    }
+
+    private List<JSONObject> getOwners(MachinePo machinePo) {
         //鎷垮埌灏忓尯ID
         String communityId = machinePo.getCommunityId();
 
-        List<MultiValueMap<String, Object>> ownerDtos = new ArrayList<>();
+        List<JSONObject> ownerDtos = new ArrayList<>();
 
         List<OwnerDto> owners = null;
         //鏍规嵁灏忓尯ID鏌ヨ鐜版湁璁惧
@@ -172,6 +207,20 @@
         } else if ("3000".equals(communityLocationDto.getLocationType())) {// 3000 鎴垮眿闂�
             ownerDto.setRoomId(machinePo.getLocationObjId());
             owners = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
+        }else if ("6000".equals(communityLocationDto.getLocationType())) {// 3000 鎴垮眿闂�
+            //鍏堟牴鎹崟鍏冮棬ID 鏌ヨ 鎴垮眿
+            RoomDto roomDto = new RoomDto();
+            roomDto.setFloorId(machinePo.getLocationObjId());
+            roomDto.setCommunityId(machinePo.getCommunityId());
+            List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
+            if (roomDtos == null || roomDtos.size() == 0) { // 妤兼爧涓嬫病鏈夋埧灞�
+                return ownerDtos;
+            }
+            ownerDto.setRoomIds(getRoomIds(roomDtos));
+            owners = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
+        }
+        if (owners == null) {
+            return ownerDtos;
         }
 
         for (OwnerDto tOwnerDto : owners) {
@@ -190,14 +239,17 @@
             if (fileDtos == null || fileDtos.size() != 1) {
                 continue;
             }
-            MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
-
-            postParameters.add("extCommunityUuid", tOwnerDto.getCommunityId());
-            postParameters.add("addAuthorizationDevSn", machinePo.getMachineCode());
-            postParameters.add("uuid", tOwnerDto.getMemberId());
-            postParameters.add("name", tOwnerDto.getName());
-            postParameters.add("faceFileBase64Array", fileDtos.get(0).getContext());
-
+            JSONObject postParameters = new JSONObject();
+            postParameters.put("userId", tOwnerDto.getMemberId());
+            postParameters.put("faceBase64", fileDtos.get(0).getContext());
+            postParameters.put("startTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+            postParameters.put("endTime", DateUtil.LAST_TIME);
+            postParameters.put("name", tOwnerDto.getName());
+            postParameters.put("idNumber", tOwnerDto.getIdCard());
+            postParameters.put("machineCode", machinePo.getMachineCode());
+            postParameters.put("extMachineId", machinePo.getMachineId());
+            postParameters.put("extCommunityId", machinePo.getCommunityId());
+            postParameters.put("attrs",tOwnerDto.getOwnerAttrDtos());
             ownerDtos.add(postParameters);
         }
 

--
Gitblit v1.8.0