java110
2020-12-10 44b18c5c1e44895eb4bcf8e809a44a5ff9154fd1
优化代码
4个文件已添加
4个文件已修改
750 ■■■■■ 已修改文件
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoAddMachineTransactionIotAdapt.java 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoDeleteOwnerTransactionIotAdapt.java 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoEditOwnerTransactionIotAdapt.java 153 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoIotConstant.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoOwnerBindRoomTransactionIotAdapt.java 171 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoOwnerUnBindRoomTransactionIotAdapt.java 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/asyn/IXimoMachineAsyn.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/asyn/impl/XimoMachineAsynImpl.java 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoAddMachineTransactionIotAdapt.java
@@ -17,9 +17,19 @@
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.file.FileDto;
import com.java110.dto.file.FileRelDto;
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.IMachineInnerServiceSMO;
import com.java110.intf.community.ICommunityLocationInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.user.IOwnerInnerServiceSMO;
import com.java110.job.adapt.DatabusAdaptImpl;
import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn;
import com.java110.po.machine.MachinePo;
@@ -30,6 +40,7 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.ArrayList;
import java.util.List;
/**
@@ -44,6 +55,21 @@
    private IXimoMachineAsyn ximoMachineAsynImpl;
    @Autowired
    IMachineInnerServiceSMO machineInnerServiceSMOImpl;
    @Autowired
    private ICommunityLocationInnerServiceSMO communityLocationInnerServiceSMOImpl;
    @Autowired
    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
    @Autowired
    private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
    @Autowired
    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
    /**
     * accessToken={access_token}
@@ -90,6 +116,12 @@
        Assert.listOnlyOne(machineDtos, "未找到设备");
        if (!"9999".equals(machineDtos.get(0).getMachineTypeCd())) {
            return;
        }
        List<MultiValueMap<String, Object>> ownerDtos = getOwners(machinePo);
        MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
        postParameters.add("extCommunityUuid", machinePo.getCommunityId());
@@ -98,6 +130,83 @@
        postParameters.add("name", machinePo.getMachineName());
        postParameters.add("positionType", "0");
        postParameters.add("positionUuid", machinePo.getCommunityId());
        ximoMachineAsynImpl.send(postParameters);
        ximoMachineAsynImpl.send(postParameters, ownerDtos);
    }
    private List<MultiValueMap<String, Object>> getOwners(MachinePo machinePo) {
        //拿到小区ID
        String communityId = machinePo.getCommunityId();
        List<MultiValueMap<String, Object>> ownerDtos = new ArrayList<>();
        List<OwnerDto> owners = null;
        //根据小区ID查询现有设备
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setCommunityId(communityId);
        String locationTypeCd = machinePo.getLocationTypeCd();
        CommunityLocationDto communityLocationDto = new CommunityLocationDto();
        communityLocationDto.setLocationId(locationTypeCd);
        communityLocationDto.setCommunityId(machinePo.getCommunityId());
        List<CommunityLocationDto> communityLocationDtos = communityLocationInnerServiceSMOImpl.queryCommunityLocations(communityLocationDto);
        if (communityLocationDtos == null || communityLocationDtos.size() < 1) {
            return ownerDtos;
        }
        communityLocationDto = communityLocationDtos.get(0);
        if ("1000".contains(communityLocationDto.getLocationType())) {//查询整个小区的业主
            owners = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
        } else if ("2000".equals(communityLocationDto.getLocationType())) {//2000 单元门 ,则这个单元下的业主同步
            //先根据单元门ID 查询 房屋
            RoomDto roomDto = new RoomDto();
            roomDto.setUnitId(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);
        } else if ("3000".equals(communityLocationDto.getLocationType())) {// 3000 房屋门
            ownerDto.setRoomId(machinePo.getLocationObjId());
            owners = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
        }
        for (OwnerDto tOwnerDto : owners) {
            FileRelDto fileRelDto = new FileRelDto();
            fileRelDto.setObjId(tOwnerDto.getMemberId());
            fileRelDto.setRelTypeCd("10000");
            List<FileRelDto> fileRelDtos = fileRelInnerServiceSMOImpl.queryFileRels(fileRelDto);
            if (fileRelDtos == null || fileRelDtos.size() != 1) {
                continue;
            }
            FileDto fileDto = new FileDto();
            fileDto.setFileId(fileRelDtos.get(0).getFileSaveName());
            fileDto.setFileSaveName(fileRelDtos.get(0).getFileSaveName());
            fileDto.setCommunityId(tOwnerDto.getCommunityId());
            List<FileDto> fileDtos = fileInnerServiceSMOImpl.queryFiles(fileDto);
            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());
            ownerDtos.add(postParameters);
        }
        return ownerDtos;
    }
    private String[] getRoomIds(List<RoomDto> roomDtos) {
        List<String> roomIds = new ArrayList<String>();
        for (RoomDto roomDto : roomDtos) {
            roomIds.add(roomDto.getRoomId());
        }
        return roomIds.toArray(new String[roomIds.size()]);
    }
}
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoDeleteOwnerTransactionIotAdapt.java
New file
@@ -0,0 +1,110 @@
/*
 * 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.job.adapt.ximoIot;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.machine.MachineDto;
import com.java110.entity.order.Business;
import com.java110.intf.common.IMachineInnerServiceSMO;
import com.java110.job.adapt.DatabusAdaptImpl;
import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn;
import com.java110.po.owner.OwnerPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
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;
/**
 * HC iot 添加业主同步细末
 *
 * @desc add by 吴学文 18:58
 */
@Component(value = "ximoDeleteOwnerTransactionIotAdapt")
public class XimoDeleteOwnerTransactionIotAdapt extends DatabusAdaptImpl {
    @Autowired
    private IXimoMachineAsyn ximoMachineAsynImpl;
    @Autowired
    IMachineInnerServiceSMO machineInnerServiceSMOImpl;
    /**
     * accessToken={access_token}
     * &extCommunityUuid=01000
     * &extCommunityId=1
     * &devSn=111111111
     * &name=设备名称
     * &positionType=0
     * &positionUuid=1
     *
     * @param business   当前处理业务
     * @param businesses 所有业务信息
     */
    @Override
    public void execute(Business business, List<Business> businesses) {
        JSONObject data = business.getData();
        if (data.containsKey(OwnerPo.class.getSimpleName())) {
            Object bObj = data.get(OwnerPo.class.getSimpleName());
            JSONArray businessMachines = null;
            if (bObj instanceof JSONObject) {
                businessMachines = new JSONArray();
                businessMachines.add(bObj);
            } else if (bObj instanceof List) {
                businessMachines = JSONArray.parseArray(JSONObject.toJSONString(bObj));
            } else {
                businessMachines = (JSONArray) bObj;
            }
            for (int bOwnerIndex = 0; bOwnerIndex < businessMachines.size(); bOwnerIndex++) {
                JSONObject businessOwner = businessMachines.getJSONObject(bOwnerIndex);
                doSendMachine(business, businessOwner);
            }
        }
    }
    private void doSendMachine(Business business, JSONObject businessOwner) {
        OwnerPo ownerPo = BeanConvertUtil.covertBean(businessOwner, OwnerPo.class);
        //拿到小区ID
        String communityId = ownerPo.getCommunityId();
        //根据小区ID查询现有设备
        MachineDto machineDto = new MachineDto();
        machineDto.setCommunityId(communityId);
        //String[] locationObjIds = new String[]{communityId};
        List<String> locationObjIds = new ArrayList<>();
        locationObjIds.add(communityId);
        machineDto.setLocationObjIds(locationObjIds.toArray(new String[locationObjIds.size()]));
        List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto);
        Assert.listOnlyOne(machineDtos, "未找到设备");
        for (MachineDto tmpMachineDto : machineDtos) {
            if (!"9999".equals(tmpMachineDto.getMachineTypeCd())) {
                continue;
            }
            MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
            postParameters.add("extCommunityUuid", ownerPo.getCommunityId());
            postParameters.add("uuids", ownerPo.getMemberId());
            ximoMachineAsynImpl.sendDeleteOwner(postParameters);
        }
    }
}
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoEditOwnerTransactionIotAdapt.java
New file
@@ -0,0 +1,153 @@
/*
 * 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.job.adapt.ximoIot;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.RoomDto;
import com.java110.dto.file.FileDto;
import com.java110.dto.file.FileRelDto;
import com.java110.dto.machine.MachineDto;
import com.java110.entity.order.Business;
import com.java110.intf.common.IFileInnerServiceSMO;
import com.java110.intf.common.IFileRelInnerServiceSMO;
import com.java110.intf.common.IMachineInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.job.adapt.DatabusAdaptImpl;
import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn;
import com.java110.po.owner.OwnerPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
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;
/**
 * HC iot 添加业主同步细末
 *
 * @desc add by 吴学文 18:58
 */
@Component(value = "ximoEditOwnerTransactionIotAdapt")
public class XimoEditOwnerTransactionIotAdapt extends DatabusAdaptImpl {
    @Autowired
    private IXimoMachineAsyn ximoMachineAsynImpl;
    @Autowired
    IMachineInnerServiceSMO machineInnerServiceSMOImpl;
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
    @Autowired
    private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
    @Autowired
    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
    /**
     * accessToken={access_token}
     * &extCommunityUuid=01000
     * &extCommunityId=1
     * &devSn=111111111
     * &name=设备名称
     * &positionType=0
     * &positionUuid=1
     *
     * @param business   当前处理业务
     * @param businesses 所有业务信息
     */
    @Override
    public void execute(Business business, List<Business> businesses) {
        JSONObject data = business.getData();
        if (data.containsKey(OwnerPo.class.getSimpleName())) {
            Object bObj = data.get(OwnerPo.class.getSimpleName());
            JSONArray businessMachines = null;
            if (bObj instanceof JSONObject) {
                businessMachines = new JSONArray();
                businessMachines.add(bObj);
            } else if (bObj instanceof List) {
                businessMachines = JSONArray.parseArray(JSONObject.toJSONString(bObj));
            } else {
                businessMachines = (JSONArray) bObj;
            }
            for (int bOwnerIndex = 0; bOwnerIndex < businessMachines.size(); bOwnerIndex++) {
                JSONObject businessOwner = businessMachines.getJSONObject(bOwnerIndex);
                doSendMachine(business, businessOwner);
            }
        }
    }
    private void doSendMachine(Business business, JSONObject businessOwner) {
        OwnerPo ownerPo = BeanConvertUtil.covertBean(businessOwner, OwnerPo.class);
        FileRelDto fileRelDto = new FileRelDto();
        fileRelDto.setObjId(ownerPo.getMemberId());
        fileRelDto.setRelTypeCd("10000");
        List<FileRelDto> fileRelDtos = fileRelInnerServiceSMOImpl.queryFileRels(fileRelDto);
        if (fileRelDtos == null || fileRelDtos.size() != 1) {
            return;
        }
        FileDto fileDto = new FileDto();
        fileDto.setFileId(fileRelDtos.get(0).getFileSaveName());
        fileDto.setFileSaveName(fileRelDtos.get(0).getFileSaveName());
        fileDto.setCommunityId(ownerPo.getCommunityId());
        List<FileDto> fileDtos = fileInnerServiceSMOImpl.queryFiles(fileDto);
        if (fileDtos == null || fileDtos.size() != 1) {
            return;
        }
        RoomDto roomDto = new RoomDto();
        roomDto.setOwnerId(ownerPo.getOwnerId());
        //这种情况说明 业主已经删掉了 需要查询状态为 1 的数据
        List<RoomDto> rooms = roomInnerServiceSMOImpl.queryRoomsByOwner(roomDto);
        //拿到小区ID
        String communityId = ownerPo.getCommunityId();
        //根据小区ID查询现有设备
        MachineDto machineDto = new MachineDto();
        machineDto.setCommunityId(communityId);
        //String[] locationObjIds = new String[]{communityId};
        List<String> locationObjIds = new ArrayList<>();
        locationObjIds.add(communityId);
        for (RoomDto tRoomDto : rooms) {
            locationObjIds.add(tRoomDto.getUnitId());
            locationObjIds.add(tRoomDto.getRoomId());
        }
        machineDto.setLocationObjIds(locationObjIds.toArray(new String[locationObjIds.size()]));
        List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto);
        Assert.listOnlyOne(machineDtos, "未找到设备");
        for (MachineDto tmpMachineDto : machineDtos) {
            if (!"9999".equals(tmpMachineDto.getMachineTypeCd())) {
                continue;
            }
            MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
            postParameters.add("extCommunityUuid", ownerPo.getCommunityId());
            postParameters.add("addAuthorizationDevSn", tmpMachineDto.getMachineCode());
            postParameters.add("uuid", ownerPo.getMemberId());
            postParameters.add("name", ownerPo.getName());
            postParameters.add("faceFileBase64Array", fileDtos.get(0).getContext());
            ximoMachineAsynImpl.sendUpdateOwner(postParameters);
        }
    }
}
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoIotConstant.java
@@ -42,4 +42,6 @@
    //添加业主
    public static final String ADD_OWNER = "/persEmpHousehold/extapi/add";
    public static final String EDIT_OWNER = "/persEmpHousehold/extapi/update";
    public static final String DELETE_OWNER = "/persEmpHousehold/extapi/delete";
}
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoOwnerBindRoomTransactionIotAdapt.java
New file
@@ -0,0 +1,171 @@
/*
 * 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.job.adapt.ximoIot;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.RoomDto;
import com.java110.dto.file.FileDto;
import com.java110.dto.file.FileRelDto;
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.IMachineInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.user.IOwnerInnerServiceSMO;
import com.java110.job.adapt.DatabusAdaptImpl;
import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn;
import com.java110.po.owner.OwnerPo;
import com.java110.po.owner.OwnerRoomRelPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
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;
/**
 * HC iot 添加业主同步细末
 *
 * @desc add by 吴学文 18:58
 */
@Component(value = "ximoOwnerBindRoomTransactionIotAdapt")
public class XimoOwnerBindRoomTransactionIotAdapt extends DatabusAdaptImpl {
    @Autowired
    private IXimoMachineAsyn ximoMachineAsynImpl;
    @Autowired
    IMachineInnerServiceSMO machineInnerServiceSMOImpl;
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
    @Autowired
    private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
    @Autowired
    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
    @Autowired
    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
    /**
     * accessToken={access_token}
     * &extCommunityUuid=01000
     * &extCommunityId=1
     * &devSn=111111111
     * &name=设备名称
     * &positionType=0
     * &positionUuid=1
     *
     * @param business   当前处理业务
     * @param businesses 所有业务信息
     */
    @Override
    public void execute(Business business, List<Business> businesses) {
        JSONObject data = business.getData();
        if (data.containsKey(OwnerPo.class.getSimpleName())) {
            Object bObj = data.get(OwnerPo.class.getSimpleName());
            JSONArray businessMachines = null;
            if (bObj instanceof JSONObject) {
                businessMachines = new JSONArray();
                businessMachines.add(bObj);
            } else if (bObj instanceof List) {
                businessMachines = JSONArray.parseArray(JSONObject.toJSONString(bObj));
            } else {
                businessMachines = (JSONArray) bObj;
            }
            for (int bOwnerIndex = 0; bOwnerIndex < businessMachines.size(); bOwnerIndex++) {
                JSONObject businessOwner = businessMachines.getJSONObject(bOwnerIndex);
                doSendMachine(business, businessOwner);
            }
        }
    }
    private void doSendMachine(Business business, JSONObject businessOwner) {
        OwnerRoomRelPo ownerRoomRelPo = BeanConvertUtil.covertBean(businessOwner, OwnerRoomRelPo.class);
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setOwnerId(ownerRoomRelPo.getOwnerId());
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        for (OwnerDto tOwnerDto : ownerDtos) {
            dealOwnerData(tOwnerDto, ownerRoomRelPo);
        }
    }
    private void dealOwnerData(OwnerDto tOwnerDto, OwnerRoomRelPo ownerRoomRelPo) {
        FileRelDto fileRelDto = new FileRelDto();
        fileRelDto.setObjId(tOwnerDto.getMemberId());
        fileRelDto.setRelTypeCd("10000");
        List<FileRelDto> fileRelDtos = fileRelInnerServiceSMOImpl.queryFileRels(fileRelDto);
        if (fileRelDtos == null || fileRelDtos.size() != 1) {
            return;
        }
        FileDto fileDto = new FileDto();
        fileDto.setFileId(fileRelDtos.get(0).getFileSaveName());
        fileDto.setFileSaveName(fileRelDtos.get(0).getFileSaveName());
        fileDto.setCommunityId(tOwnerDto.getCommunityId());
        List<FileDto> fileDtos = fileInnerServiceSMOImpl.queryFiles(fileDto);
        if (fileDtos == null || fileDtos.size() != 1) {
            return;
        }
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomId(ownerRoomRelPo.getRoomId());
        roomDto.setCommunityId(tOwnerDto.getCommunityId());
        //这种情况说明 业主已经删掉了 需要查询状态为 1 的数据
        List<RoomDto> rooms = roomInnerServiceSMOImpl.queryRoomsByOwner(roomDto);
        //拿到小区ID
        String communityId = tOwnerDto.getCommunityId();
        //根据小区ID查询现有设备
        MachineDto machineDto = new MachineDto();
        machineDto.setCommunityId(communityId);
        //String[] locationObjIds = new String[]{communityId};
        List<String> locationObjIds = new ArrayList<>();
        locationObjIds.add(communityId);
        for (RoomDto tRoomDto : rooms) {
            locationObjIds.add(tRoomDto.getUnitId());
            locationObjIds.add(tRoomDto.getRoomId());
        }
        machineDto.setLocationObjIds(locationObjIds.toArray(new String[locationObjIds.size()]));
        List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto);
        Assert.listOnlyOne(machineDtos, "未找到设备");
        for (MachineDto tmpMachineDto : machineDtos) {
            if (!"9999".equals(tmpMachineDto.getMachineTypeCd())) {
                continue;
            }
            MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
            postParameters.add("extCommunityUuid", tOwnerDto.getCommunityId());
            postParameters.add("addAuthorizationDevSn", tmpMachineDto.getMachineCode());
            postParameters.add("uuid", tOwnerDto.getMemberId());
            postParameters.add("name", tOwnerDto.getName());
            postParameters.add("faceFileBase64Array", fileDtos.get(0).getContext());
            ximoMachineAsynImpl.sendOwner(postParameters);
        }
    }
}
service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoOwnerUnBindRoomTransactionIotAdapt.java
New file
@@ -0,0 +1,150 @@
/*
 * 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.job.adapt.ximoIot;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.RoomDto;
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.IMachineInnerServiceSMO;
import com.java110.intf.community.IRoomInnerServiceSMO;
import com.java110.intf.user.IOwnerInnerServiceSMO;
import com.java110.job.adapt.DatabusAdaptImpl;
import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn;
import com.java110.po.owner.OwnerPo;
import com.java110.po.owner.OwnerRoomRelPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
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;
/**
 * HC iot 添加业主同步细末
 *
 * @desc add by 吴学文 18:58
 */
@Component(value = "ximoOwnerUnBindRoomTransactionIotAdapt")
public class XimoOwnerUnBindRoomTransactionIotAdapt extends DatabusAdaptImpl {
    @Autowired
    private IXimoMachineAsyn ximoMachineAsynImpl;
    @Autowired
    IMachineInnerServiceSMO machineInnerServiceSMOImpl;
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
    @Autowired
    private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
    @Autowired
    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
    @Autowired
    private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
    /**
     * accessToken={access_token}
     * &extCommunityUuid=01000
     * &extCommunityId=1
     * &devSn=111111111
     * &name=设备名称
     * &positionType=0
     * &positionUuid=1
     *
     * @param business   当前处理业务
     * @param businesses 所有业务信息
     */
    @Override
    public void execute(Business business, List<Business> businesses) {
        JSONObject data = business.getData();
        if (data.containsKey(OwnerPo.class.getSimpleName())) {
            Object bObj = data.get(OwnerPo.class.getSimpleName());
            JSONArray businessMachines = null;
            if (bObj instanceof JSONObject) {
                businessMachines = new JSONArray();
                businessMachines.add(bObj);
            } else if (bObj instanceof List) {
                businessMachines = JSONArray.parseArray(JSONObject.toJSONString(bObj));
            } else {
                businessMachines = (JSONArray) bObj;
            }
            for (int bOwnerIndex = 0; bOwnerIndex < businessMachines.size(); bOwnerIndex++) {
                JSONObject businessOwner = businessMachines.getJSONObject(bOwnerIndex);
                doSendMachine(business, businessOwner);
            }
        }
    }
    private void doSendMachine(Business business, JSONObject businessOwner) {
        OwnerRoomRelPo ownerRoomRelPo = BeanConvertUtil.covertBean(businessOwner, OwnerRoomRelPo.class);
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setOwnerId(ownerRoomRelPo.getOwnerId());
        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
        for (OwnerDto tOwnerDto : ownerDtos) {
            dealOwnerData(tOwnerDto, ownerRoomRelPo);
        }
    }
    private void dealOwnerData(OwnerDto tOwnerDto, OwnerRoomRelPo ownerRoomRelPo) {
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomId(ownerRoomRelPo.getRoomId());
        roomDto.setCommunityId(tOwnerDto.getCommunityId());
        //这种情况说明 业主已经删掉了 需要查询状态为 1 的数据
        List<RoomDto> rooms = roomInnerServiceSMOImpl.queryRoomsByOwner(roomDto);
        //拿到小区ID
        String communityId = tOwnerDto.getCommunityId();
        //根据小区ID查询现有设备
        MachineDto machineDto = new MachineDto();
        machineDto.setCommunityId(communityId);
        //String[] locationObjIds = new String[]{communityId};
        List<String> locationObjIds = new ArrayList<>();
        locationObjIds.add(communityId);
        for (RoomDto tRoomDto : rooms) {
            locationObjIds.add(tRoomDto.getUnitId());
            locationObjIds.add(tRoomDto.getRoomId());
        }
        machineDto.setLocationObjIds(locationObjIds.toArray(new String[locationObjIds.size()]));
        List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto);
        Assert.listOnlyOne(machineDtos, "未找到设备");
        for (MachineDto tmpMachineDto : machineDtos) {
            if (!"9999".equals(tmpMachineDto.getMachineTypeCd())) {
                continue;
            }
            MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>();
            postParameters.add("extCommunityUuid", tOwnerDto.getCommunityId());
            postParameters.add("uuids", tOwnerDto.getMemberId());
            ximoMachineAsynImpl.sendDeleteOwner(postParameters);
        }
    }
}
service-job/src/main/java/com/java110/job/adapt/ximoIot/asyn/IXimoMachineAsyn.java
@@ -16,13 +16,27 @@
import org.springframework.util.MultiValueMap;
import java.util.List;
public interface IXimoMachineAsyn {
    public void send(MultiValueMap<String, Object> postParameters);
    public void send(MultiValueMap<String, Object> postParameters, List<MultiValueMap<String, Object>> ownerDtos);
    void updateSend(MultiValueMap<String, Object> postParameters);
    void deleteSend(MultiValueMap<String, Object> postParameters);
    public void sendOwner(MultiValueMap<String, Object> postParameters);
    /**
     * 修改业主
     * @param postParameters
     */
    void sendUpdateOwner(MultiValueMap<String, Object> postParameters);
    /**
     * 删除业主
     * @param postParameters
     */
    void sendDeleteOwner(MultiValueMap<String, Object> postParameters);
}
service-job/src/main/java/com/java110/job/adapt/ximoIot/asyn/impl/XimoMachineAsynImpl.java
@@ -22,13 +22,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import java.util.List;
/**
 * @desc add by 吴学文 11:55
@@ -43,7 +42,7 @@
    @Override
    @Async
    public void send(MultiValueMap<String, Object> postParameters) {
    public void send(MultiValueMap<String, Object> postParameters, List<MultiValueMap<String, Object>> ownerDtos) {
        postParameters.add("accessToken", GetToken.get(formRestTemplate));
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Content-Type", "application/x-www-form-urlencoded");
@@ -52,6 +51,10 @@
        ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.ADD_MACHINE_URL, HttpMethod.POST, httpEntity, String.class);
        logger.debug("调用吸墨信息:" + responseEntity);
        if (responseEntity.getStatusCode() != HttpStatus.OK) {
            return;
        }
    }
    @Override
@@ -90,4 +93,28 @@
        logger.debug("调用吸墨信息:" + responseEntity);
    }
    @Override
    public void sendUpdateOwner(MultiValueMap<String, Object> postParameters) {
        postParameters.add("accessToken", GetToken.get(formRestTemplate));
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Content-Type", "application/x-www-form-urlencoded");
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders);
        ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.EDIT_OWNER, HttpMethod.POST, httpEntity, String.class);
        logger.debug("调用吸墨信息:" + responseEntity);
    }
    @Override
    public void sendDeleteOwner(MultiValueMap<String, Object> postParameters) {
        postParameters.add("accessToken", GetToken.get(formRestTemplate));
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Content-Type", "application/x-www-form-urlencoded");
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders);
        ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.DELETE_OWNER, HttpMethod.POST, httpEntity, String.class);
        logger.debug("调用吸墨信息:" + responseEntity);
    }
}