新增备份恢复接口
This commit is contained in:
@@ -23,4 +23,6 @@ public interface StorageConverterMapper {
|
||||
|
||||
StorageInfoVo StorageToInfoVo(Storage storage);
|
||||
|
||||
Storage StorageInfoVoToStorage(StorageInfoVo storageInfoVo);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class OpenApiConfiguration {
|
||||
return new OpenAPI()
|
||||
.info(new Info().title("DiyFile")
|
||||
.description("一款好看的在线文件列表程序")
|
||||
.version("v0.3.0")
|
||||
.version("v0.3.1")
|
||||
.license(new License().name("MIT license").url("https://github.com/besscroft/diyfile/blob/main/LICENSE")))
|
||||
.externalDocs(new ExternalDocumentation()
|
||||
.description("DiyFile 文档")
|
||||
|
||||
@@ -12,9 +12,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @Description 系统监控
|
||||
@@ -57,4 +56,17 @@ public class MonitorController {
|
||||
}
|
||||
}
|
||||
|
||||
@SaCheckRole(
|
||||
value = {
|
||||
RoleConstants.PLATFORM_SUPER_ADMIN,
|
||||
},
|
||||
mode = SaMode.OR
|
||||
)
|
||||
@Operation(summary = "恢复数据")
|
||||
@PostMapping("/restoreData")
|
||||
public AjaxResult restoreData(@ModelAttribute MultipartFile file) {
|
||||
systemConfigService.restoreData(file);
|
||||
return AjaxResult.success("恢复数据成功!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -102,4 +102,10 @@ public interface StorageService extends IService<Storage> {
|
||||
*/
|
||||
Long getDefaultStorageId();
|
||||
|
||||
/**
|
||||
* 保存存储列表
|
||||
* @param storageInfoVoList 存储列表
|
||||
*/
|
||||
void saveStorageInfoVoList(List<StorageInfoVo> storageInfoVoList);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.besscroft.diyfile.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.besscroft.diyfile.common.entity.SystemConfig;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -64,4 +65,6 @@ public interface SystemConfigService extends IService<SystemConfig> {
|
||||
*/
|
||||
String getBackupJsonString() throws JsonProcessingException;
|
||||
|
||||
void restoreData(MultipartFile file);
|
||||
|
||||
}
|
||||
|
||||
@@ -214,4 +214,28 @@ public class StorageServiceImpl extends ServiceImpl<StorageMapper, Storage> impl
|
||||
return vo.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = {
|
||||
CacheConstants.DEFAULT_STORAGE,
|
||||
CacheConstants.STORAGE_ID,
|
||||
CacheConstants.STORAGE_KEY,
|
||||
CacheConstants.ENABLE_STORAGE,
|
||||
CacheConstants.STATISTICS
|
||||
}, allEntries = true)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveStorageInfoVoList(List<StorageInfoVo> storageInfoVoList) {
|
||||
for (StorageInfoVo storageInfoVo : storageInfoVoList) {
|
||||
Storage storage = StorageConverterMapper.INSTANCE.StorageInfoVoToStorage(storageInfoVo);
|
||||
if (Objects.isNull(storage)) throw new DiyFileException("存储信息导入失败!");
|
||||
storage.setId(null);
|
||||
this.save(storage);
|
||||
List<StorageConfig> configList = storageInfoVo.getConfigList();
|
||||
for (StorageConfig config : configList) {
|
||||
config.setId(null);
|
||||
config.setStorageId(storage.getId());
|
||||
}
|
||||
storageConfigService.saveBatch(configList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.besscroft.diyfile.mapper.UserMapper;
|
||||
import com.besscroft.diyfile.service.StorageService;
|
||||
import com.besscroft.diyfile.service.SystemConfigService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -21,7 +22,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -107,4 +111,26 @@ public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigMapper, Sys
|
||||
return objectMapper.writeValueAsString(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void restoreData(MultipartFile file) {
|
||||
try {
|
||||
InputStream inputStream = file.getInputStream();
|
||||
Map<String, Object> map = objectMapper.readValue(inputStream, new TypeReference<>() {
|
||||
});
|
||||
if (map.containsKey("systemConfig")) {
|
||||
List<SystemConfig> list = objectMapper.convertValue(map.get("systemConfig"), new TypeReference<>() {
|
||||
});
|
||||
this.saveOrUpdateBatch(list);
|
||||
}
|
||||
if (map.containsKey("storageInfo")) {
|
||||
List<StorageInfoVo> list = objectMapper.convertValue(map.get("storageInfo"), new TypeReference<>() {
|
||||
});
|
||||
storageService.saveStorageInfoVoList(list);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user