| | |
| | | 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.DoorsListRequest; |
| | | import com.doumee.core.haikang.model.param.respose.*; |
| | | import com.doumee.core.haikang.model.param.respose.DoorsInfoResponse; |
| | | import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse; |
| | | import com.doumee.core.haikang.model.param.respose.DoorsInfoResponse; |
| | | import com.doumee.core.haikang.model.param.respose.DoorsListResponse; |
| | | import com.doumee.core.haikang.service.HKService; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | |
| | | @Override |
| | | // @Async |
| | | public String syncDoors(DoorsListRequest param){ |
| | | List<Device> deleteList = new ArrayList<>(); |
| | | List<Device> addList = new ArrayList<>(); |
| | | List<Device> editList = new ArrayList<>(); |
| | | List<DoorsInfoResponse> 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 DoorsListRequest(); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<DoorsListResponse> response = HKService.doorSearch(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | DoorsListResponse 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++; |
| | | if(Constants.DEALING_HK_SYNCDEVICE){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "同步任务正在执行哦,请稍后查看结果!") ; |
| | | } |
| | | /** |
| | | * 获取增删改数据集合 |
| | | */ |
| | | getDataChangeList(allList,allHkList,addList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //逻辑删除 |
| | | for(Device d : deleteList){ |
| | | deviceMapper.updateById(d); |
| | | Constants.DEALING_HK_SYNCDEVICE =true; |
| | | try { |
| | | List<Device> deleteList = new ArrayList<>(); |
| | | List<Device> addList = new ArrayList<>(); |
| | | List<Device> editList = new ArrayList<>(); |
| | | List<DoorsInfoResponse> 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 DoorsListRequest(); |
| | | param.setPageNo(curPage); |
| | | param.setPageSize(100); |
| | | BaseResponse<DoorsListResponse> response = HKService.doorSearch(param); |
| | | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); |
| | | } |
| | | DoorsListResponse 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++; |
| | | } |
| | | } |
| | | if(addList.size()>0){ |
| | | deviceMapper.insertBatchSomeColumn(addList); |
| | | } |
| | | if(editList.size()>0){ |
| | | for(Device d : editList){ |
| | | deviceMapper.updateById(d); |
| | | /** |
| | | * 获取增删改数据集合 |
| | | */ |
| | | getDataChangeList(allList,allHkList,addList,editList,deleteList,date); |
| | | if(deleteList.size()>0){ |
| | | //逻辑删除 |
| | | for(Device d : deleteList){ |
| | | deviceMapper.updateById(d); |
| | | } |
| | | } |
| | | if(addList.size()>0){ |
| | | deviceMapper.insertBatchSomeColumn(addList); |
| | | } |
| | | if(editList.size()>0){ |
| | | for(Device d : editList){ |
| | | deviceMapper.updateById(d); |
| | | } |
| | | } |
| | | return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条"; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "同步失败!"); |
| | | }finally { |
| | | Constants.DEALING_HK_SYNCDEVICE =false; |
| | | } |
| | | return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条"; |
| | | |
| | | } |
| | | |
| | | private void getDataChangeList(List<Device> allList, List<DoorsInfoResponse> allHkList, List<Device> addList, List<Device> editList,List<Device> deleteList, Date date) { |