|  |  |  | 
|---|
|  |  |  | import com.doumee.core.exception.BusinessException; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.HKConstants; | 
|---|
|  |  |  | 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.PrivilegeGroupRequest; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.respose.AcsDeviceInfoResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.respose.AcsDeviceListResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.respose.PrivilegeGroupInfoResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.model.param.respose.PrivilegeGroupListResponse; | 
|---|
|  |  |  | import com.doumee.core.haikang.service.HKService; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.dao.business.DeviceRoleMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Device; | 
|---|
|  |  |  | import com.doumee.dao.business.model.DeviceRole; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | //    @Async | 
|---|
|  |  |  | public String syncPrivilege(PrivilegeGroupRequest param){ | 
|---|
|  |  |  | List<DeviceRole> deleteList = new ArrayList<>(); | 
|---|
|  |  |  | List<DeviceRole> addList = new ArrayList<>(); | 
|---|
|  |  |  | List<DeviceRole> editList = new ArrayList<>(); | 
|---|
|  |  |  | List<PrivilegeGroupInfoResponse> allHkList = new ArrayList<>(); | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | //查询全部现有数据,只管理同步 访客组 | 
|---|
|  |  |  | List<Integer> types = new ArrayList<>(); | 
|---|
|  |  |  | types.add(Constants.DOOR_ROLE_TYPE.fk); | 
|---|
|  |  |  | types.add(Constants.DOOR_ROLE_TYPE.lw); | 
|---|
|  |  |  | List<DeviceRole> allList = DeviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda().in(DeviceRole::getType,types)); | 
|---|
|  |  |  | boolean hasNext = true; | 
|---|
|  |  |  | int curTotal = 0; | 
|---|
|  |  |  | int curPage = 1; | 
|---|
|  |  |  | while (hasNext){ | 
|---|
|  |  |  | //分页遍历循环查询所有门禁设备数据 | 
|---|
|  |  |  | param = new PrivilegeGroupRequest(); | 
|---|
|  |  |  | param.setPageNo(curPage); | 
|---|
|  |  |  | param.setPageSize(10000); | 
|---|
|  |  |  | BaseResponse<PrivilegeGroupListResponse> response = HKService.privilegeGroup(param); | 
|---|
|  |  |  | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | PrivilegeGroupListResponse r = response.getData(); | 
|---|
|  |  |  | curTotal += 10000; | 
|---|
|  |  |  | 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(DeviceRole d : deleteList){ | 
|---|
|  |  |  | DeviceRoleMapper.updateById(d); | 
|---|
|  |  |  | Constants.DEALING_HK_SYNCDEVICE =true; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<DeviceRole> deleteList = new ArrayList<>(); | 
|---|
|  |  |  | List<DeviceRole> addList = new ArrayList<>(); | 
|---|
|  |  |  | List<DeviceRole> editList = new ArrayList<>(); | 
|---|
|  |  |  | List<PrivilegeGroupInfoResponse> allHkList = new ArrayList<>(); | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | //查询全部现有数据,只管理同步 访客组 | 
|---|
|  |  |  | List<Integer> types = new ArrayList<>(); | 
|---|
|  |  |  | types.add(Constants.DOOR_ROLE_TYPE.fk); | 
|---|
|  |  |  | types.add(Constants.DOOR_ROLE_TYPE.lw); | 
|---|
|  |  |  | List<DeviceRole> allList = DeviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda().in(DeviceRole::getType,types).eq(DeviceRole::getIsdeleted,Constants.ZERO)); | 
|---|
|  |  |  | boolean hasNext = true; | 
|---|
|  |  |  | int curTotal = 0; | 
|---|
|  |  |  | int curPage = 1; | 
|---|
|  |  |  | while (hasNext){ | 
|---|
|  |  |  | //分页遍历循环查询所有门禁设备数据 | 
|---|
|  |  |  | param = new PrivilegeGroupRequest(); | 
|---|
|  |  |  | param.setPageNo(curPage); | 
|---|
|  |  |  | param.setPageSize(100); | 
|---|
|  |  |  | BaseResponse<PrivilegeGroupListResponse> response = HKService.privilegeGroup(param); | 
|---|
|  |  |  | if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | PrivilegeGroupListResponse 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){ | 
|---|
|  |  |  | DeviceRoleMapper.insertBatchSomeColumn(addList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(editList.size()>0){ | 
|---|
|  |  |  | for(DeviceRole d : editList){ | 
|---|
|  |  |  | DeviceRoleMapper.updateById(d); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取增删改数据集合 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | getDataChangeList(allList,allHkList,addList,editList,deleteList,date); | 
|---|
|  |  |  | if(deleteList.size()>0){ | 
|---|
|  |  |  | //逻辑删除 | 
|---|
|  |  |  | for(DeviceRole d : deleteList){ | 
|---|
|  |  |  | DeviceRoleMapper.updateById(d); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(addList.size()>0){ | 
|---|
|  |  |  | DeviceRoleMapper.insertBatchSomeColumn(addList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(editList.size()>0){ | 
|---|
|  |  |  | for(DeviceRole d : editList){ | 
|---|
|  |  |  | DeviceRoleMapper.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<DeviceRole> allList, List<PrivilegeGroupInfoResponse> allHkList, List<DeviceRole> addList, List<DeviceRole> editList,List<DeviceRole> deleteList, Date date) { | 
|---|
|  |  |  | 
|---|
|  |  |  | model.setHkId(device.getPrivilegeGroupId()); | 
|---|
|  |  |  | model.setName(device.getPrivilegeGroupName()); | 
|---|
|  |  |  | model.setHkStatus(Constants.ONE); | 
|---|
|  |  |  | model.setIsdeleted(Constants.ONE); | 
|---|
|  |  |  | model.setStatus(Constants.ONE); | 
|---|
|  |  |  | model.setIsDefault(device.getIsDefault()); | 
|---|
|  |  |  | model.setType(Constants.ZERO); | 
|---|
|  |  |  | model.setType(String.valueOf(Constants.ONE)); | 
|---|
|  |  |  | return  model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|