nidapeng
2024-03-28 d16520069e7a89b5ac0d13d0c8ba4e30af023279
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/hksync/HkSyncDeviceServiceImpl.java
@@ -2,11 +2,14 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseListPageResponse;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.AcsDeviceListRequest;
import com.doumee.core.haikang.model.param.request.AcsDeviceStatusListRequest;
import com.doumee.core.haikang.model.param.request.DoorsListRequest;
import com.doumee.core.haikang.model.param.request.ParkListRequest;
import com.doumee.core.haikang.model.param.respose.*;
@@ -83,6 +86,37 @@
            Constants.DEALING_HK_SYNCDEVICE =false;
        }
    }
    @Override
//    @Async
    public void getAscDeviceStatus(){
        if(Constants.DEALING_HK_SYNCDEVICE_STATUS){
            return;
        }
        Constants.DEALING_HK_SYNCDEVICE_STATUS =true;
        try {
            List<Device> editList = new ArrayList<>();
            Date date = new Date();
            //查询全部门禁设备数据
            List<AscDeviceStatusInfoResponse> allHkList = getAllDeviceStatusList();
            if(allHkList.size()>0){
                //逻辑删除
                for(AscDeviceStatusInfoResponse d : allHkList){
                    deviceMapper.update(null,new UpdateWrapper<Device>().lambda()
                            .set(Device::getOnline,d.getOnline())
                            .set(Device::getIp,d.getIp())
                            .set(Device::getPort,d.getPort())
                            .set(Device::getManufature,d.getManufacturer())
                            .set(Device::getEditDate,date)
                            .eq(Device::getHkId,d.getIndexCode()));
                }
            }
        }catch (Exception e){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "同步设备状态失败!");
        }finally {
            Constants.DEALING_HK_SYNCDEVICE_STATUS =false;
        }
    }
    private List<AcsDeviceInfoResponse> getAllDeViceList() {
        AcsDeviceListRequest param = new AcsDeviceListRequest();
@@ -143,6 +177,35 @@
        }
        return  allDoorList;
    }
    public  List<AscDeviceStatusInfoResponse>  getAllDeviceStatusList(){
        List<AscDeviceStatusInfoResponse> allDoorList = new ArrayList<>();
        Date date = new Date();
        boolean hasNext = true;
        int curTotal = 0;
        int curPage = 1;
        while (hasNext){
            //分页遍历循环查询所有门禁设备数据
            AcsDeviceStatusListRequest param = new AcsDeviceStatusListRequest();
            param.setPageNo(curPage);
            param.setPageSize(100);
            BaseResponse<BaseListPageResponse<AscDeviceStatusInfoResponse>> response = HKService.acsDeviceStatus(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
            }
            BaseListPageResponse r = response.getData();
            curTotal += 100;
            if(curTotal >= r.getTotal()){
                hasNext = false;
            }
            if(r.getList() == null || r.getList().size()==0){
                hasNext =false;
            }else{
                allDoorList.addAll(r.getList());
            }
            curPage++;
        }
        return  allDoorList;
    }
    private void getDataChangeList(List<Device> allList, List<DoorsInfoResponse> hkDoorList , List<AcsDeviceInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) {
        if(hkDoorList!=null && hkDoorList.size()>0){