1098226878
2021-08-31 9cf55daaafbdf49b6e7eee8298f81a3c2e602112
service-job/src/main/java/com/java110/job/adapt/hcIot/machine/AddMachineToIotAdapt.java
old mode 100644 new mode 100755
@@ -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);
        }