| | |
| | | List<Device> deleteList = new ArrayList<>(); |
| | | List<Device> addList = new ArrayList<>(); |
| | | List<Device> editList = new ArrayList<>(); |
| | | List<AcsDeviceInfoResponse> allHkList = new ArrayList<>(); |
| | | Date date = new Date(); |
| | | //查询全部门禁设备数据 |
| | | List<Device> allList = deviceMapper.selectList(null); |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | while (hasNext){ |
| | | //分页遍历循环查询所有门禁设备数据 |
| | | param = new AcsDeviceListRequest(); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<AcsDeviceListResponse> response = HKService.acsDeviceList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | AcsDeviceListResponse r = response.getData(); |
| | | curTotal += 100; |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | | } |
| | | if(r.getList() == null || r.getList().size()==0){ |
| | | hasNext =false; |
| | | }else{ |
| | | allHkList.addAll(r.getList()); |
| | | } |
| | | curPage++; |
| | | } |
| | | List<DoorsInfoResponse> allDoors = getAllDoorList(); |
| | | List<AcsDeviceInfoResponse> allHkList = getAllDeViceList(); |
| | | /** |
| | | * 获取增删改数据集合 |
| | | */ |
| | | getDataChangeList(allList,allHkList,addList,editList,deleteList,date); |
| | | getDataChangeList(allList,allDoors,allHkList,addList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //逻辑删除 |
| | | for(Device d : deleteList){ |
| | |
| | | }finally { |
| | | Constants.DEALING_HK_SYNCDEVICE =false; |
| | | } |
| | | } |
| | | |
| | | private List<AcsDeviceInfoResponse> getAllDeViceList() { |
| | | AcsDeviceListRequest param = new AcsDeviceListRequest(); |
| | | List<AcsDeviceInfoResponse> allHkList = new ArrayList<>(); |
| | | boolean hasNext = true; |
| | | int curTotal = 0; |
| | | int curPage = 1; |
| | | while (hasNext){ |
| | | //分页遍历循环查询所有门禁设备数据 |
| | | param = new AcsDeviceListRequest(); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<AcsDeviceListResponse> response = HKService.acsDeviceList(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | AcsDeviceListResponse r = response.getData(); |
| | | curTotal += 100; |
| | | if(curTotal >= r.getTotal()){ |
| | | hasNext = false; |
| | | } |
| | | if(r.getList() == null || r.getList().size()==0){ |
| | | hasNext =false; |
| | | }else{ |
| | | allHkList.addAll(r.getList()); |
| | | } |
| | | curPage++; |
| | | } |
| | | return allHkList; |
| | | } |
| | | |
| | | public List<DoorsInfoResponse> getAllDoorList(){ |
| | |
| | | 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){ |
| | | //获取海康全部门禁组数据 |
| | | for(DoorsInfoResponse device : hkDoorList){ |
| | | Device model = getExistedDoor(device,allList); |
| | | if(model !=null){ |
| | | //如果已存在,则更新数据 |
| | | model = initDoorDataByHkData(model,device,date,allHkList); |
| | | editList.add(model); |
| | | }else{ |
| | | //如果不存在,则新增数据 |
| | | model = new Device(); |
| | | model = initDoorDataByHkData(model,device,date,allHkList); |
| | | addList.add(model); |
| | | } |
| | | } |
| | | } |
| | | //判断获取删除的门禁设备,逻辑删除 |
| | | getDeleteDoorList(allList,hkDoorList,deleteList,date); |
| | | } |
| | | |
| | | private Device initDoorDataByHkData(Device model, DoorsInfoResponse door, Date date, List<AcsDeviceInfoResponse> allHkList) { |
| | | AcsDeviceInfoResponse device = getDeviceByDoorid(door.getParentIndexCode(),allHkList); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setIp(device.getIp()); |
| | | model.setHkDate(date); |
| | | model.setCreateDate(DateUtil.getISO8601DateByStr(device.getCreateTime())); |
| | | model.setEditDate(DateUtil.getISO8601DateByStr(device.getUpdateTime())); |
| | | model.setNo(device.getDevSerialNum()); |
| | | model.setHkId(device.getIndexCode()); |
| | | model.setName(device.getName()); |
| | | model.setHkStatus(Constants.ONE); |
| | | model.setManufature(device.getManufacturer()); |
| | | model.setType(Constants.ZERO); |
| | | // model.setNo(device.getDevSerialNum()); |
| | | // model.setChannelNo(getChannelNo(device.getIndexCode(),hkDoorList,model)); |
| | | model.setChannelNo(door.getChannelNo()); |
| | | model.setChannelInfo(door.getName()); |
| | | model.setResourceType(device.getResourceType()); |
| | | model.setDevTypeCode(device.getDevTypeCode()); |
| | | model.setDevTypeDesc(device.getDevTypeDesc()); |
| | | model.setManufature(device.getManufacturer()); |
| | | model.setPort(device.getPort()); |
| | | model.setRemark(JSONObject.toJSONString(device)); |
| | | model.setDoorId(door.getIndexCode()); |
| | | model.setDoorName(door.getName()); |
| | | model.setRegionName(door.getRegionName()); |
| | | model.setRegionPathName(door.getRegionPathName()); |
| | | model.setDoorNo(door.getDoorNo()); |
| | | return model; |
| | | } |
| | | private AcsDeviceInfoResponse getDeviceByDoorid(String indexCode, List<AcsDeviceInfoResponse> allHkList ) { |
| | | if(allHkList!=null && allHkList.size()>0){ |
| | | for(AcsDeviceInfoResponse info : allHkList){ |
| | | if(StringUtils.equals(indexCode,info.getIndexCode())){ |
| | | return info; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return new AcsDeviceInfoResponse(); |
| | | } |
| | | private void getDataChangeList(List<Device> allList, List<AcsDeviceInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) { |
| | | if(allHkList!=null && allHkList.size()>0){ |
| | | //获取海康全部门禁组数据 |
| | |
| | | return str; |
| | | } |
| | | |
| | | private Device getExistedDoor(DoorsInfoResponse device, List<Device> allList) { |
| | | if(allList.size()>0){ |
| | | for(Device r : allList){ |
| | | if(StringUtils.equals(r.getDoorId(), device.getIndexCode())){ |
| | | //表示未删除 |
| | | return r; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | private Device getExistedDevice(AcsDeviceInfoResponse device, List<Device> allList) { |
| | | if(allList.size()>0){ |
| | | for(Device r : allList){ |
| | |
| | | } |
| | | } |
| | | } |
| | | private void getDeleteDoorList(List<Device> allList, List<DoorsInfoResponse> allHkList,List<Device> deleteList ,Date date) { |
| | | if(allList!=null && allList.size()>0){ |
| | | for(Device device : allList){ |
| | | if(isDeletedDoorDevice(device,allHkList)){ |
| | | device.setIsdeleted(Constants.ONE); |
| | | device.setEditDate(date); |
| | | deleteList.add(device); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean isDeletedDoorDevice(Device device, List<DoorsInfoResponse> allHkList) { |
| | | if(allHkList.size()>0){ |
| | | for(DoorsInfoResponse r : allHkList){ |
| | | if(StringUtils.equals(device.getDoorId(), r.getIndexCode())){ |
| | | //表示未删除 |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | |
| | | } |
| | | private boolean isDeletedDevice(Device device, List<AcsDeviceInfoResponse> allHkList) { |
| | | if(allHkList.size()>0){ |
| | | for(AcsDeviceInfoResponse r : allHkList){ |
| | |
| | | return true; |
| | | |
| | | } |
| | | |
| | | |
| | | } |