Redis代码提交
This commit is contained in:
parent
476d3cd454
commit
1e925a2e61
11
java/pom.xml
11
java/pom.xml
@ -41,6 +41,17 @@
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- spring-security -->
|
||||
<dependency>
|
||||
|
@ -1,29 +1,79 @@
|
||||
package com.yfd.platform.modules.config.redis;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
||||
import com.yfd.platform.modules.specialDocument.domain.Files;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
// @Bean
|
||||
// public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
// RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
// template.setConnectionFactory(connectionFactory);
|
||||
//
|
||||
// // 使用 String 序列化器作为 Key 的序列化器
|
||||
// template.setKeySerializer(new StringRedisSerializer());
|
||||
// template.setHashKeySerializer(new StringRedisSerializer());
|
||||
//
|
||||
// // 使用 GenericJackson2JsonRedisSerializer 作为 Value 的序列化器,并配置 ObjectMapper
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// // 启用类型信息,用于反序列化时识别对象类型
|
||||
// objectMapper.activateDefaultTyping(
|
||||
// BasicPolymorphicTypeValidator.builder()
|
||||
// .allowIfBaseType(Object.class)
|
||||
// .build(),
|
||||
// ObjectMapper.DefaultTyping.NON_FINAL,
|
||||
// JsonTypeInfo.As.PROPERTY);
|
||||
// // 注册 Java 8 时间支持模块
|
||||
// objectMapper.registerModule(new JavaTimeModule());
|
||||
// objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
//
|
||||
// GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(objectMapper);
|
||||
// template.setValueSerializer(serializer);
|
||||
// template.setHashValueSerializer(serializer);
|
||||
//
|
||||
// template.afterPropertiesSet();
|
||||
// return template;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(factory);
|
||||
|
||||
// Key使用String序列化
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
// Value使用JSON序列化(需引入Jackson依赖)
|
||||
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
|
||||
// Hash Key/Value序列化同理
|
||||
template.setHashKeySerializer(new StringRedisSerializer());
|
||||
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// 启用完整的泛型类型支持,并强制记录嵌套类型
|
||||
objectMapper.activateDefaultTyping(
|
||||
objectMapper.getPolymorphicTypeValidator(),
|
||||
ObjectMapper.DefaultTyping.EVERYTHING,
|
||||
JsonTypeInfo.As.PROPERTY
|
||||
);
|
||||
// 注册 Java 8 时间模块
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
// 禁用日期序列化为时间戳
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
// 注册实体类
|
||||
objectMapper.registerSubtypes(TsFiles.class, Files.class);
|
||||
// 启用二进制字段 Base64 编码(若存在二进制字段)
|
||||
objectMapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN);
|
||||
|
||||
GenericJackson2JsonRedisSerializer serializer =
|
||||
new GenericJackson2JsonRedisSerializer(objectMapper);
|
||||
template.setValueSerializer(serializer);
|
||||
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.yfd.platform.modules.experimentalData.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.annotation.Log;
|
||||
import com.yfd.platform.component.TaskStatusHolder;
|
||||
@ -62,6 +63,13 @@ public class TsFilesController {
|
||||
@PreAuthorize("@el.check('select:tsfiles')")
|
||||
public ResponseResult getTsFilesPage(String id, String fileName, String startDate, String endDate, String keywords, String nodeId, String taskId, String childNode, Page<TsFiles> page) throws Exception {
|
||||
//分页查询
|
||||
int currentPage = (int) page.getCurrent();
|
||||
// 先尝试从缓存获取
|
||||
IPage<TsFiles> cachedPage = tsFilesService.getCachedTsFilesPage(taskId, nodeId, currentPage);
|
||||
if (cachedPage != null) {
|
||||
return ResponseResult.successData(cachedPage);
|
||||
}
|
||||
|
||||
Page<TsFiles> tsfilesPage = tsFilesService.getTsFilesPage(id, fileName, startDate, endDate, keywords, nodeId, taskId, fileName, childNode, page);
|
||||
return ResponseResult.successData(tsfilesPage);
|
||||
}
|
||||
@ -199,13 +207,13 @@ public class TsFilesController {
|
||||
@Log(module = "实验数据管理", value = "压缩文件夹接口!")
|
||||
@PostMapping("/compress")
|
||||
@ApiOperation("压缩文件夹接口")
|
||||
public ResponseResult compressFolder(String ids, String compressedFormat, String compressedName, String compressedPath, String covered, String parentId,String path) {
|
||||
public ResponseResult compressFolder(String ids, String compressedFormat, String compressedName, String compressedPath, String covered, String parentId, String path) {
|
||||
try {
|
||||
if (StrUtil.isBlank(ids) && StrUtil.isBlank(compressedFormat) && StrUtil.isBlank(compressedName) && StrUtil.isBlank(compressedPath)&& StrUtil.isBlank(path)) {
|
||||
if (StrUtil.isBlank(ids) && StrUtil.isBlank(compressedFormat) && StrUtil.isBlank(compressedName) && StrUtil.isBlank(compressedPath) && StrUtil.isBlank(path)) {
|
||||
return ResponseResult.error("参数为空");
|
||||
}
|
||||
|
||||
return ResponseResult.success(tsFilesService.compressFolder(ids, compressedFormat, compressedName, compressedPath, covered, parentId, path));
|
||||
return ResponseResult.success(tsFilesService.compressFolder(ids, compressedFormat, compressedName, compressedPath, covered, parentId, path));
|
||||
} catch (Exception e) {
|
||||
System.out.print("压缩异常原因" + e);
|
||||
return ResponseResult.error("压缩失败");
|
||||
@ -223,13 +231,14 @@ public class TsFilesController {
|
||||
@Log(module = "实验数据管理", value = "解压缩接口!")
|
||||
@PostMapping("/decompression")
|
||||
@ApiOperation("解压缩接口")
|
||||
public ResponseResult decompressionFolder(String id, String decompressionPath, String parentId,String path) {
|
||||
public ResponseResult decompressionFolder(String id, String decompressionPath, String parentId, String path) {
|
||||
try {
|
||||
if (StrUtil.isBlank(id)) {
|
||||
return ResponseResult.error("参数为空");
|
||||
}
|
||||
|
||||
return ResponseResult.success(tsFilesService.decompressionFolder(id, decompressionPath, parentId,path));
|
||||
|
||||
return ResponseResult.success(tsFilesService.decompressionFolder(id, decompressionPath, parentId, path));
|
||||
} catch (Exception e) {
|
||||
System.out.print("解压缩异常原因" + e);
|
||||
return ResponseResult.error("解压缩失败");
|
||||
@ -564,6 +573,7 @@ public class TsFilesController {
|
||||
return ResponseResult.success("任务已由其他请求启动");
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 获取异步信息
|
||||
* 参数说明 taskId 所属项目ID
|
||||
@ -605,7 +615,7 @@ public class TsFilesController {
|
||||
@PostMapping("/automaticFileBackupByIds")
|
||||
@ApiOperation("自动备份本地文件到备份空间通过ID")
|
||||
public ResponseResult automaticFileBackupByIds(String id) throws IOException {
|
||||
if (StrUtil.isEmpty(id) ) {
|
||||
if (StrUtil.isEmpty(id)) {
|
||||
return ResponseResult.error("参数为空");
|
||||
}
|
||||
List<String> dataset = StrUtil.split(id, ",");
|
||||
@ -631,7 +641,6 @@ public class TsFilesController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 实时获取轨迹数据
|
||||
* 参数说明 id 文件的ID
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.yfd.platform.modules.experimentalData.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.modules.experimentalData.domain.*;
|
||||
@ -247,4 +248,6 @@ public interface ITsFilesService extends IService<TsFiles> {
|
||||
Object compareMd5List(List<String> dataset, String nodeId, String taskId);
|
||||
|
||||
void automaticFileBackupAsyncByIds(List<String> dataset);
|
||||
|
||||
IPage<TsFiles> getCachedTsFilesPage(String taskId, String nodeId, int currentPage);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import com.amazonaws.services.s3.model.S3Object;
|
||||
import com.amazonaws.services.s3.model.S3ObjectInputStream;
|
||||
import com.amazonaws.util.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.opencsv.CSVReader;
|
||||
@ -78,7 +79,7 @@ import java.io.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.zip.*;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
|
||||
|
||||
@ -131,8 +132,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
private TaskStatusHolder taskStatusHolder;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("myCustomRedisTemplate") // 指定自定义的 Bean 名称
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/**********************************
|
||||
@ -151,20 +152,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
***********************************/
|
||||
@Override
|
||||
public Page<TsFiles> getTsFilesPage(String id, String fileName, String startDate, String endDate, String keywords, String nodeId, String taskId, String fileName1, String childNode, Page<TsFiles> page) throws Exception {
|
||||
|
||||
// int currentPage = (int) page.getCurrent(); // 获取当前页码
|
||||
// // 判断是否是前五页
|
||||
// if (currentPage >= 1 && currentPage <= 5) {
|
||||
// // 生成带页码的完整RedisKey
|
||||
// String redisKey = "tsfiles_" + taskId + "_" + nodeId + "_page_" + currentPage;
|
||||
//
|
||||
// // 尝试从Redis获取缓存
|
||||
// Page<TsFiles> cachedPage = (Page<TsFiles>) redisTemplate.opsForValue().get(redisKey);
|
||||
// if (cachedPage != null) {
|
||||
// return cachedPage; // 直接返回缓存数据
|
||||
// }
|
||||
// }
|
||||
|
||||
//查询字典表获取压缩文件后缀
|
||||
QueryWrapper<SysDictionaryItems> queryWrapperSysDictionary = new QueryWrapper<>();
|
||||
queryWrapperSysDictionary.eq("parentcode", "compressType");
|
||||
@ -275,18 +262,48 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
|
||||
tsFilesPage.setRecords(records); // 同步到 tsFilesPage
|
||||
|
||||
|
||||
System.out.println("Updated records: " + records);
|
||||
// // 如果是前五页,将结果存入Redis(有效期建议30分钟)
|
||||
// if (currentPage >= 1 && currentPage <= 5) {
|
||||
// String redisKey = "tsfiles_" + taskId + "_" + nodeId + "_page_" + currentPage;
|
||||
// redisTemplate.opsForValue().set(redisKey, tsFilesPage, 2 * 60 * 60);
|
||||
// }
|
||||
int currentPage = (int) page.getCurrent();
|
||||
// 如果是前五页,将结果存入Redis(有效期建议30分钟)
|
||||
if (currentPage >= 1 && currentPage <= 5) {
|
||||
String redisKey = "tsfiles_" + taskId + "_" + nodeId + "_page_" + currentPage;
|
||||
redisTemplate.opsForValue().set(redisKey, tsFilesPage, 2, TimeUnit.HOURS);
|
||||
}
|
||||
return tsFilesPage;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis缓存获取
|
||||
* @param taskId
|
||||
* @param nodeId
|
||||
* @param currentPage
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<TsFiles> getCachedTsFilesPage(String taskId, String nodeId, int currentPage) {
|
||||
String redisKey = "tsfiles_" + taskId + "_" + nodeId + "_page_" + currentPage;
|
||||
Object data = redisTemplate.opsForValue().get(redisKey);
|
||||
|
||||
if (data instanceof IPage<?>) {
|
||||
// 由于启用了类型信息,可以直接强制转换
|
||||
@SuppressWarnings("unchecked")
|
||||
IPage<TsFiles> page = (IPage<TsFiles>) data;
|
||||
// 检查 records 是否已正确反序列化
|
||||
if (page.getRecords() != null && !page.getRecords().isEmpty()
|
||||
&& page.getRecords().get(0) instanceof TsFiles) {
|
||||
return page;
|
||||
} else {
|
||||
// 处理可能的反序列化异常
|
||||
throw new IllegalStateException("反序列化失败,records 类型不正确");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void cachePageData(String taskId, String nodeId, int currentPage, Page<TsFiles> pageData) {
|
||||
String redisKey = "tsfiles_" + taskId + "_" + nodeId + "_page_" + currentPage;
|
||||
redisTemplate.opsForValue().set(redisKey, pageData, 2, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
public boolean hasValidExtension(String name, List<SysDictionaryItems> sysDictionaryItems) {
|
||||
// 如果传入的文件名为空,返回 false
|
||||
if (name == null) {
|
||||
@ -388,12 +405,12 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
@Override
|
||||
public ResponseResult addTsFiles(TsFiles tsFiles) {
|
||||
|
||||
// //todo 新增成功以后 删除redis
|
||||
// for (int page = 1; page <= 5; page++) {
|
||||
// String redisKey = "tsfiles_" + tsFiles.getTaskId() + "_" + tsFiles.getNodeId() + "_page_" + page;
|
||||
// redisTemplate.delete(redisKey);
|
||||
// }
|
||||
// LOGGER.info("已清理缓存:taskid={}, node={}, pages=1-5", tsFiles.getTaskId(), tsFiles.getNodeId());
|
||||
//todo 新增成功以后 删除redis
|
||||
for (int page = 1; page <= 5; page++) {
|
||||
String redisKey = "tsfiles_" + tsFiles.getTaskId() + "_" + tsFiles.getNodeId() + "_page_" + page;
|
||||
redisTemplate.delete(redisKey);
|
||||
}
|
||||
LOGGER.info("已清理缓存:taskid={}, node={}, pages=1-5", tsFiles.getTaskId(), tsFiles.getNodeId());
|
||||
|
||||
Boolean value = true;
|
||||
//文件名称和大小 因为支持多个上传所以用,分隔
|
||||
@ -520,12 +537,12 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
@Transactional(rollbackFor = Exception.class)// 添加事务注解,遇到异常时回滚
|
||||
public ResponseResult addTsFile(TsFiles tsFiles) throws IOException {
|
||||
|
||||
// //todo 新增成功以后 删除redis
|
||||
// for (int page = 1; page <= 5; page++) {
|
||||
// String redisKey = "tsfiles_" + tsFiles.getTaskId() + "_" + tsFiles.getNodeId() + "_page_" + page;
|
||||
// redisTemplate.delete(redisKey);
|
||||
// }
|
||||
// LOGGER.info("已清理缓存:taskid={}, node={}, pages=1-5", tsFiles.getTaskId(), tsFiles.getNodeId());
|
||||
//todo 新增成功以后 删除redis
|
||||
for (int page = 1; page <= 5; page++) {
|
||||
String redisKey = "tsfiles_" + tsFiles.getTaskId() + "_" + tsFiles.getNodeId() + "_page_" + page;
|
||||
redisTemplate.delete(redisKey);
|
||||
}
|
||||
LOGGER.info("已清理缓存:taskid={}, node={}, pages=1-5", tsFiles.getTaskId(), tsFiles.getNodeId());
|
||||
|
||||
if (tsFiles.getIsFile().equals("FILE")) {
|
||||
StorageSourceConfig config = getStorageConfig("filePath", "local");
|
||||
@ -630,12 +647,12 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
@Transactional(rollbackFor = Exception.class)// 添加事务注解,遇到异常时回滚
|
||||
public ResponseResult updateTsFiles(TsFiles tsFiles) {
|
||||
|
||||
// //todo 新增成功以后 删除redis
|
||||
// for (int page = 1; page <= 5; page++) {
|
||||
// String redisKey = "tsfiles_" + tsFiles.getTaskId() + "_" + tsFiles.getNodeId() + "_page_" + page;
|
||||
// redisTemplate.delete(redisKey);
|
||||
// }
|
||||
// LOGGER.info("已清理缓存:taskid={}, node={}, pages=1-5", tsFiles.getTaskId(), tsFiles.getNodeId());
|
||||
//todo 新增成功以后 删除redis
|
||||
for (int page = 1; page <= 5; page++) {
|
||||
String redisKey = "tsfiles_" + tsFiles.getTaskId() + "_" + tsFiles.getNodeId() + "_page_" + page;
|
||||
redisTemplate.delete(redisKey);
|
||||
}
|
||||
LOGGER.info("已清理缓存:taskid={}, node={}, pages=1-5", tsFiles.getTaskId(), tsFiles.getNodeId());
|
||||
// 校验文件名是否包含非法字符
|
||||
String fileName = tsFiles.getFileName();
|
||||
if (containsInvalidCharacters(fileName)) {
|
||||
@ -3373,6 +3390,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 文件自动备份通过节点和任务
|
||||
* 参数说明 taskId 节点ID
|
||||
|
@ -3,9 +3,11 @@ package com.yfd.platform.modules.specialDocument.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.annotation.Log;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
||||
import com.yfd.platform.modules.specialDocument.domain.Files;
|
||||
import com.yfd.platform.modules.specialDocument.service.IFilesService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -53,6 +55,13 @@ public class FilesController {
|
||||
@PreAuthorize("@el.check('select:files')")
|
||||
public ResponseResult getFilesPage(String fileName, String startDate, String endDate, String keywords, String nodeId,String projectId, Page<Files> page) throws Exception {
|
||||
//分页查询
|
||||
int currentPage = (int) page.getCurrent();
|
||||
// 先尝试从缓存获取
|
||||
IPage<Files> cachedFilesPage = filesService.getCachedFilesPage(projectId, nodeId,currentPage );
|
||||
if (cachedFilesPage != null){
|
||||
return ResponseResult.successData(cachedFilesPage);
|
||||
}
|
||||
|
||||
Page<Files> filesPage = filesService.getFilesPage(fileName, startDate, endDate, keywords, nodeId, projectId, fileName, page);
|
||||
return ResponseResult.successData(filesPage);
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.yfd.platform.modules.specialDocument.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
||||
import com.yfd.platform.modules.specialDocument.domain.Files;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -56,4 +58,6 @@ public interface IFilesService extends IService<Files> {
|
||||
**********************************
|
||||
* @return*/
|
||||
String deleteFilesByIds(List<String> dataset);
|
||||
|
||||
IPage<Files> getCachedFilesPage(String projectId, String nodeId, int currentPage);
|
||||
}
|
||||
|
@ -5,10 +5,13 @@ import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.exception.file.InvalidStorageSourceException;
|
||||
import com.yfd.platform.modules.config.model.request.FileListRequest;
|
||||
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
||||
import com.yfd.platform.modules.specialDocument.domain.Files;
|
||||
import com.yfd.platform.modules.specialDocument.mapper.FilesMapper;
|
||||
import com.yfd.platform.modules.specialDocument.service.IFilesService;
|
||||
@ -35,7 +38,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
@ -43,6 +46,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -75,7 +79,7 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
private FileChain fileChain;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
|
||||
/**********************************
|
||||
@ -92,22 +96,6 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
***********************************/
|
||||
@Override
|
||||
public Page<Files> getFilesPage(String fileName, String startDate, String endDate, String keywords, String nodeId, String projectId, String fileName1, Page<Files> page) throws Exception {
|
||||
// 生成Redis缓存Key的基础部分(nodeId + projectId)
|
||||
|
||||
|
||||
// int currentPage = (int) page.getCurrent(); // 获取当前页码
|
||||
// // 判断是否是前五页
|
||||
// if (currentPage >= 1 && currentPage <= 5) {
|
||||
// // 生成带页码的完整RedisKey
|
||||
// String redisKey = "sdfiles_" + projectId + "_" + nodeId + "_page_" + currentPage;
|
||||
//
|
||||
// // 尝试从Redis获取缓存
|
||||
// Page<Files> cachedPage = (Page<Files>) redisTemplate.opsForValue().get(redisKey);
|
||||
// if (cachedPage != null) {
|
||||
// return cachedPage; // 直接返回缓存数据
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//先查询路径下的所有文件
|
||||
//首先通过项目ID 和节点ID去查询表 获取一个路径 如果不是空 就调用minio的获取文件列表接口 查询的数据放在集合中
|
||||
@ -198,16 +186,50 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
}
|
||||
}
|
||||
filesPage.setRecords(records);
|
||||
|
||||
// // 如果是前五页,将结果存入Redis(有效期建议30分钟)
|
||||
// if (currentPage >= 1 && currentPage <= 5) {
|
||||
// String redisKey = "sdfiles:" + projectId + ":" + nodeId + ":page:" + currentPage;
|
||||
// redisTemplate.opsForValue().set(redisKey, filesPage, 2 * 60 * 60);
|
||||
// }
|
||||
|
||||
int currentPage = (int) page.getCurrent();
|
||||
// 如果是前五页,将结果存入Redis(有效期建议30分钟)
|
||||
if (currentPage >= 1 && currentPage <= 5) {
|
||||
String redisKey = "sdfiles_" + projectId + "_" + nodeId + "_page_" + currentPage;
|
||||
redisTemplate.opsForValue().set(redisKey, filesPage, 2, TimeUnit.HOURS);
|
||||
}
|
||||
return filesPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存中获取节点文件
|
||||
*
|
||||
* @param projectId
|
||||
* @param nodeId
|
||||
* @param currentPage
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<Files> getCachedFilesPage(String projectId, String nodeId, int currentPage) {
|
||||
String redisKeyff = "sdfiles_" + projectId + "_" + nodeId + "_page_" + currentPage;
|
||||
|
||||
Object data = redisTemplate.opsForValue().get(redisKeyff);
|
||||
|
||||
// if (data != null) {
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
// // 明确指定目标类型为 Page<Files>
|
||||
// return mapper.convertValue(data, new TypeReference<Page<Files>>() {});
|
||||
// }
|
||||
|
||||
if (data instanceof IPage<?>) {
|
||||
// 由于启用了类型信息,可以直接强制转换
|
||||
@SuppressWarnings("unchecked")
|
||||
IPage<Files> page = (IPage<Files>) data;
|
||||
// 检查 records 是否已正确反序列化
|
||||
if (page.getRecords() != null && !page.getRecords().isEmpty()
|
||||
&& page.getRecords().get(0) instanceof Files) {
|
||||
return page;
|
||||
} else {
|
||||
// 处理可能的反序列化异常
|
||||
throw new IllegalStateException("反序列化失败,records 类型不正确");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明:新增专项文档管理-文档内容
|
||||
@ -222,6 +244,13 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
List<String> names = Arrays.asList(files.getFileName().split(","));
|
||||
List<String> sizes = Arrays.asList(files.getFileSize().split(","));
|
||||
|
||||
//todo 新增成功以后 删除redis
|
||||
for (int page = 1; page <= 5; page++) {
|
||||
String redisKey = "sdfiles_" + files.getProjectId() + "_" + files.getNodeId() + "_page_" + page;
|
||||
redisTemplate.delete(redisKey);
|
||||
}
|
||||
LOGGER.info("已清理缓存:project={}, node={}, pages=1-5", files.getProjectId(), files.getNodeId());
|
||||
|
||||
// 差不多的流程 就是提出来 然后判断 如果两个 中有一个是true
|
||||
//获取当前登录用户 上传人是当前登录人
|
||||
UsernamePasswordAuthenticationToken authentication =
|
||||
@ -281,12 +310,6 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
for (Files filess : filesToSave) {
|
||||
int valueAdded = filesMapper.insert(filess);
|
||||
if (valueAdded == 1) {
|
||||
// //todo 新增成功以后 删除redis
|
||||
// for (int page = 1; page <= 5; page++) {
|
||||
// String redisKey = "sdfiles_" + filess.getProjectId() + "_" + filess.getNodeId() + "_page_" + page;
|
||||
// redisTemplate.delete(redisKey);
|
||||
// }
|
||||
// LOGGER.info("已清理缓存:project={}, node={}, pages=1-5", filess.getProjectId(), filess.getNodeId());
|
||||
|
||||
|
||||
value = true;
|
||||
@ -316,12 +339,12 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
if (containsInvalidCharacters(fileName)) {
|
||||
return false;
|
||||
}
|
||||
// //todo 修改删除redis
|
||||
// for (int page = 1; page <= 5; page++) {
|
||||
// String redisKey = "sdfiles_" + files.getProjectId() + "_" + files.getNodeId() + "_page_" + page;
|
||||
// redisTemplate.delete(redisKey);
|
||||
// }
|
||||
// LOGGER.info("已清理缓存:project={}, node={}, pages=1-5", files.getProjectId(), files.getNodeId());
|
||||
//todo 修改删除redis
|
||||
for (int page = 1; page <= 5; page++) {
|
||||
String redisKey = "sdfiles_" + files.getProjectId() + "_" + files.getNodeId() + "_page_" + page;
|
||||
redisTemplate.delete(redisKey);
|
||||
}
|
||||
LOGGER.info("已清理缓存:project={}, node={}, pages=1-5", files.getProjectId(), files.getNodeId());
|
||||
|
||||
// 修改之前查询表中的文件名是否修改,如果发生变动先修改 minio 然后再修改表结构
|
||||
Files filesData = filesMapper.selectById(files.getId());
|
||||
@ -375,15 +398,15 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
public String deleteFilesByIds(List<String> dataset) {
|
||||
|
||||
List<Files> filesList = filesMapper.selectBatchIds(dataset);
|
||||
|
||||
//todo 删除的时候删除redis
|
||||
for (int page = 1; page <= 5; page++) {
|
||||
String redisKey = "sdfiles_" + filesList.get(0).getProjectId() + "_" + filesList.get(0).getNodeId() + "_page_" + page;
|
||||
redisTemplate.delete(redisKey);
|
||||
}
|
||||
int SuccessCount = 0, FailCount = 0, total = CollUtil.size(dataset);
|
||||
//Todo 最直接的办法 循环出来 一条一条删除
|
||||
for (Files files : filesList) {
|
||||
// //todo 删除的时候删除redis
|
||||
// for (int page = 1; page <= 5; page++) {
|
||||
// String redisKey = "sdfiles_" + files.getProjectId() + "_" + files.getNodeId() + "_page_" + page;
|
||||
// redisTemplate.delete(redisKey);
|
||||
// }
|
||||
|
||||
|
||||
List<BatchDeleteRequest.DeleteItem> deleteItemList = new ArrayList<>();
|
||||
BatchDeleteRequest.DeleteItem deleteItemData = new BatchDeleteRequest.DeleteItem();
|
||||
|
Loading…
Reference in New Issue
Block a user