<p>@GetMapping(&quot;/queryBackupsByAdminIdByPage&quot;)
public Result<Object> queryBackupsByAdminIdByPage(QueryRequest queryRequest, Admin admin, HttpServletRequest request) {
//权限验证
String token = (String) request.getAttribute(&quot;claims_admin&quot;);
if (StringUtils.isEmpty(token)) {
throw new RuntimeException(&quot;权限不足!&quot;);
}</p>
<pre><code>Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();

// 查询备份数据
IPage&lt;Backup&gt; backupIPage = backupService.queryBackupsByAdminIdByPage(queryRequest, admin.getAdminId());
List&lt;Backup&gt; backups = backupIPage.getRecords();
List&lt;BackupDto&gt; backupDtoList = new ArrayList&lt;&gt;();

// 遍历备份数据
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&lt;DeviceEntity&gt; mobileDevices = jsonObject.getObject('mobileDevices', new TypeReference&lt;List&lt;DeviceEntity&gt;&gt;() {});
        if (mobileDevices != null) {
            backupDto.setMobileDevices(mobileDevices);

            List&lt;String&gt; uniqueIds = mobileDevices.stream().map(DeviceEntity::getUniqueId).toList();
            List&lt;DeviceEntity&gt; deviceEntityList = deviceEntityService.queryDeviceEntitiesByUniqueIds(uniqueIds);

            for (DeviceEntity mobileDevice1 : deviceEntityList) {
                //2.检查是否都为被删除
                if (mobileDevice1.getBindingId() != -1) {
                    //备份数据与数据库中bindingId有不为-1的存在
                    backupDto.setIsRecover(false);
                }
            }
        }
    }

    SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
    String deleteDate = sdf.format(backup.getDeleteDate());
    backupDto.setDate(deleteDate);
    backupDtoList.add(backupDto);
}

map.put(&quot;backups&quot;, backupDtoList);
map.put(&quot;total&quot;, backupIPage.getTotal());

log.info(&quot;分页查询备份数据成功!&quot;);
return new Result&lt;&gt;(ResultCode.SUCCESS, map);
</code></pre>
<p>}</p>
查询管理员备份数据

原文地址: https://www.cveoy.top/t/topic/lRCC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录