<p>@GetMapping(&quot;/queryBackupsByAdminIdByParam&quot;)
public Result<Object> queryBackupsByAdminIdByParam(Admin admin, String text, HttpServletRequest request) {
//权限验证
String token = (String) request.getAttribute(&quot;claims_admin&quot;);
if (token == null || &quot;&quot;.equals(token)) {
throw new RuntimeException(&quot;权限不足!&quot;);
}</p>
<pre><code>List&lt;BackupDto&gt; result = new ArrayList&lt;&gt;();//存放结果
List&lt;Backup&gt; backups;
if (StringUtils.isEmpty(text)) {
    backups = backupService.queryBackupsByAdminId(admin.getAdminId());
} else {
    backups = backupService.queryBackupsByAdminIdByDate(admin.getAdminId(), text);
}

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(&quot;baseDevice&quot;, DeviceEntity.class);
        if (baseDevice != null) {
            backupDto.setBaseDevice(baseDevice);
            DeviceEntity oldBaseDevice = deviceEntityService.queryOneDeviceEntityByUniqueIDByAll(baseDevice.getUniqueId());
            if (oldBaseDevice.getBindingId() != -1) {
                backupDto.setIsRecover(false);
            }
        }

        DeviceEntity mobileDevice = jsonObject.getObject(&quot;mobileDevice&quot;, DeviceEntity.class);
        if (mobileDevice != null) {
            backupDto.setMobileDevice(mobileDevice);
            DeviceEntity oldMobileDevice = deviceEntityService.queryOneDeviceEntityByUniqueIDByAll(mobileDevice.getUniqueId());
            if (oldMobileDevice.getBindingId() != -1) {
                backupDto.setIsRecover(false);
            }
        }

        List&lt;DeviceEntity&gt; mobileDevices = jsonObject.getObject(&quot;mobileDevices&quot;, 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) {
                if (mobileDevice1.getBindingId() != -1) {
                    backupDto.setIsRecover(false);
                }
            }
        }
    }

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

log.info(&quot;查询备份信息成功!&quot;);
Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
map.put(&quot;total&quot;, result.size());
map.put(&quot;result&quot;, result);
return new Result&lt;&gt;(ResultCode.SUCCESS, map);
</code></pre>
<p>}</p>

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

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