|  |  | 
 |  |  | 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; | 
 |  |  | 
 |  |  | public class HkSyncPrivilegeServiceImpl extends HkSyncBaseServiceImpl { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private DeviceRoleMapper DeviceRoleMapper; | 
 |  |  |     private DeviceRoleMapper deviceRoleMapper; | 
 |  |  |     /** | 
 |  |  |      * 同步海康访客组权限数据 | 
 |  |  |      * @param param | 
 |  |  | 
 |  |  |             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)); | 
 |  |  |             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; | 
 |  |  | 
 |  |  |                 param = new PrivilegeGroupRequest(); | 
 |  |  |                 param.setPageNo(curPage); | 
 |  |  |                 param.setPageSize(100); | 
 |  |  |                 BaseResponse<PrivilegeGroupListResponse> response = HKService.privilegeGroup(param); | 
 |  |  | //                BaseResponse<PrivilegeGroupListResponse> response = HKService.privilegeGroup(param); | 
 |  |  | //                if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ | 
 |  |  | //                    response = HKService.privilegIccmeGroup(param);//接口V1版本不存在,调用iccm版本接口 | 
 |  |  | //                } | 
 |  |  |                 BaseResponse<PrivilegeGroupListResponse> response = HKService.privilegIccmeGroup(param);//接口V1版本不存在,调用iccm版本接口 | 
 |  |  |                 if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ | 
 |  |  |                     response = HKService.privilegIccmeGroup(param);//接口V1版本不存在,调用iccm版本接口 | 
 |  |  |                 } | 
 |  |  |                 if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){ | 
 |  |  |                     response = HKService.privilegIccmeGroup(param); | 
 |  |  |                     throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~"); | 
 |  |  |                 } | 
 |  |  |                 PrivilegeGroupListResponse r = response.getData(); | 
 |  |  | 
 |  |  |             if(deleteList.size()>0){ | 
 |  |  |                 //逻辑删除 | 
 |  |  |                 for(DeviceRole d : deleteList){ | 
 |  |  |                     DeviceRoleMapper.updateById(d); | 
 |  |  |                     deviceRoleMapper.updateById(d); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if(addList.size()>0){ | 
 |  |  |                 DeviceRoleMapper.insert(addList); | 
 |  |  |                 deviceRoleMapper.insert(addList); | 
 |  |  |             } | 
 |  |  |             if(editList.size()>0){ | 
 |  |  |                 for(DeviceRole d : editList){ | 
 |  |  |                     DeviceRoleMapper.updateById(d); | 
 |  |  |                     deviceRoleMapper.updateById(d); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             return "同步数据:新增【"+addList.size()+"】条,更新【"+editList.size()+"】条,删除【"+deleteList.size()+"】条"; | 
 |  |  | 
 |  |  |                 if(model !=null){ | 
 |  |  |                     //如果已存在,则更新数据 | 
 |  |  |                     model =  initDataByHkData(model,device,date); | 
 |  |  |                     if(allHkList.size()==1){ | 
 |  |  |                         model.setIsDefault(Constants.ZERO); | 
 |  |  |                     } | 
 |  |  |                     editList.add(model); | 
 |  |  |                 }else{ | 
 |  |  |                     //如果不存在,则新增数据 | 
 |  |  |                     model = new DeviceRole(); | 
 |  |  |                     model =  initDataByHkData(model,device,date); | 
 |  |  |                     if(allHkList.size()==1){ | 
 |  |  |                         model.setIsDefault(Constants.ZERO); | 
 |  |  |                     } | 
 |  |  |                     addList.add(model); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private boolean isDeletedData(DeviceRole device, List<PrivilegeGroupInfoResponse> allHkList) { | 
 |  |  |         if(allHkList.size()>0){ | 
 |  |  |             for(PrivilegeGroupInfoResponse r : allHkList){ | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return  true; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |      | 
 |  |  | } |