查询管理员备份数据
<p>@GetMapping("/queryBackupsByAdminIdByPage")
public Result<Object> queryBackupsByAdminIdByPage(QueryRequest queryRequest, Admin admin, HttpServletRequest request) {
//权限验证
String token = (String) request.getAttribute("claims_admin");
if (StringUtils.isEmpty(token)) {
throw new RuntimeException("权限不足!");
}</p>
<pre><code>Map<String, Object> map = new HashMap<>();
// 查询备份数据
IPage<Backup> backupIPage = backupService.queryBackupsByAdminIdByPage(queryRequest, admin.getAdminId());
List<Backup> backups = backupIPage.getRecords();
List<BackupDto> backupDtoList = new ArrayList<>();
// 遍历备份数据
for (Backup backup : backups) {
BackupDto backupDto = new BackupDto();
BeanUtils.copyProperties(backup, backupDto);//数据拷贝
backupDto.setIsRecover(true);
String deleteMessage = backup.getDeleteMessage();
if (!StringUtils.isEmpty(deleteMessage)) {
JSONObject jsonObject = JSON.parseObject(deleteMessage);
DeviceEntity baseDevice = jsonObject.getObject('baseDevice', DeviceEntity.class);
if (baseDevice != null) {
backupDto.setBaseDevice(baseDevice);
//1.在数据库通过uniqueId查询此设备
DeviceEntity oldBaseDevice = deviceEntityService.queryOneDeviceEntityByUniqueIDByAll(baseDevice.getUniqueId());
//2.检查是否都为被删除状态
if (oldBaseDevice.getBindingId() != -1) {
backupDto.setIsRecover(false);
}
}
DeviceEntity mobileDevice = jsonObject.getObject('mobileDevice', DeviceEntity.class);
if (mobileDevice != null) {
backupDto.setMobileDevice(mobileDevice);
//1.在数据库通过uniqueId查询此设备
DeviceEntity oldMobileDevice = deviceEntityService.queryOneDeviceEntityByUniqueIDByAll(mobileDevice.getUniqueId());
//2.检查是否都为被删除状态
if (oldMobileDevice.getBindingId() != -1) {
//备份数据与数据库中bindingId有不为-1的存在
backupDto.setIsRecover(false);
}
}
List<DeviceEntity> mobileDevices = jsonObject.getObject('mobileDevices', new TypeReference<List<DeviceEntity>>() {});
if (mobileDevices != null) {
backupDto.setMobileDevices(mobileDevices);
List<String> uniqueIds = mobileDevices.stream().map(DeviceEntity::getUniqueId).toList();
List<DeviceEntity> deviceEntityList = deviceEntityService.queryDeviceEntitiesByUniqueIds(uniqueIds);
for (DeviceEntity mobileDevice1 : deviceEntityList) {
//2.检查是否都为被删除
if (mobileDevice1.getBindingId() != -1) {
//备份数据与数据库中bindingId有不为-1的存在
backupDto.setIsRecover(false);
}
}
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String deleteDate = sdf.format(backup.getDeleteDate());
backupDto.setDate(deleteDate);
backupDtoList.add(backupDto);
}
map.put("backups", backupDtoList);
map.put("total", backupIPage.getTotal());
log.info("分页查询备份数据成功!");
return new Result<>(ResultCode.SUCCESS, map);
</code></pre>
<p>}</p>
原文地址: https://www.cveoy.top/t/topic/lRCC 著作权归作者所有。请勿转载和采集!