提交代码
This commit is contained in:
parent
4e0d660338
commit
5d8f4b1db9
|
|
@ -220,4 +220,14 @@ public class DataSetBasicFileController extends BaseController
|
||||||
return dataSetBasicFileService.copyFile(entity);
|
return dataSetBasicFileService.copyFile(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/moveFile")
|
||||||
|
public AjaxResult moveFile(@RequestBody DataSetBasicFileEntity entity){
|
||||||
|
return dataSetBasicFileService.moveFile(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/emptyRecycleBin")
|
||||||
|
public AjaxResult emptyRecycleBin(){
|
||||||
|
return dataSetBasicFileService.emptyRecycleBin();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bonus.ai.mapper;
|
package com.bonus.ai.mapper;
|
||||||
|
|
||||||
import com.bonus.ai.domain.DataSetBasicFileEntity;
|
import com.bonus.ai.domain.DataSetBasicFileEntity;
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -12,8 +13,7 @@ import java.util.Set;
|
||||||
* @author bonus
|
* @author bonus
|
||||||
* @date 2024-11-14
|
* @date 2024-11-14
|
||||||
*/
|
*/
|
||||||
public interface DataSetBasicFileMapper
|
public interface DataSetBasicFileMapper {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 查询文件基础
|
* 查询文件基础
|
||||||
*
|
*
|
||||||
|
|
@ -22,6 +22,10 @@ public interface DataSetBasicFileMapper
|
||||||
*/
|
*/
|
||||||
public DataSetBasicFileEntity selectDataSetBasicFileByFileId(Long fileId);
|
public DataSetBasicFileEntity selectDataSetBasicFileByFileId(Long fileId);
|
||||||
|
|
||||||
|
public DataSetBasicFileEntity selectDataSetBasicFile(Long fileId);
|
||||||
|
|
||||||
|
public DataSetBasicFileEntity selectDataSetBasicFileByFileName(@Param("parentId") Long parentId,@Param("fileName")String fileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询文件基础
|
* 查询文件基础
|
||||||
*
|
*
|
||||||
|
|
@ -88,7 +92,10 @@ public interface DataSetBasicFileMapper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改文件共享状态
|
* 修改文件共享状态
|
||||||
|
*
|
||||||
* @param ancestors
|
* @param ancestors
|
||||||
*/
|
*/
|
||||||
void updateSharedFilesByIds(@Param("ancestors")Set<Long> ancestors ,@Param("isPublic") String isPublic);
|
void updateSharedFilesByIds(@Param("ancestors") Set<Long> ancestors, @Param("isPublic") String isPublic);
|
||||||
|
|
||||||
|
void emptyRecycleBin();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,4 +114,8 @@ public interface DataSetBasicFileService
|
||||||
AjaxResult getFileTerr(Long fileId);
|
AjaxResult getFileTerr(Long fileId);
|
||||||
|
|
||||||
AjaxResult copyFile(DataSetBasicFileEntity entity);
|
AjaxResult copyFile(DataSetBasicFileEntity entity);
|
||||||
|
|
||||||
|
AjaxResult moveFile(DataSetBasicFileEntity entity);
|
||||||
|
|
||||||
|
AjaxResult emptyRecycleBin();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ import java.io.*;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
|
@ -159,13 +161,68 @@ public class DataSetBasicFileServiceImpl implements DataSetBasicFileService {
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult dataRecoveryFileByFileIds(Long[] fileIds) {
|
public AjaxResult dataRecoveryFileByFileIds(Long[] fileIds) {
|
||||||
try {
|
try {
|
||||||
int rows = dataSetBasicFileMapper.dataRecoveryFileByFileIds(fileIds);
|
int rows = 0;
|
||||||
|
for (Long fileId : fileIds) {
|
||||||
|
DataSetBasicFileEntity entity = dataSetBasicFileMapper.selectDataSetBasicFile(fileId);
|
||||||
|
DataSetBasicFileEntity basicFile = new DataSetBasicFileEntity();
|
||||||
|
int num = getNumberFromFileName(entity.getFileName());
|
||||||
|
do {
|
||||||
|
basicFile = dataSetBasicFileMapper.selectDataSetBasicFileByFileName(entity.getParentId(), entity.getFileName());
|
||||||
|
// 如果存在,则修改文件名并递增 num
|
||||||
|
if (ObjectUtils.isNotEmpty(basicFile)) {
|
||||||
|
num++; // 递增 num
|
||||||
|
entity.setFileName(changeNumberInName(entity.getFileName(),num ));
|
||||||
|
|
||||||
|
}
|
||||||
|
} while (ObjectUtils.isNotEmpty(basicFile));
|
||||||
|
entity.setDelFlag("0");
|
||||||
|
entity.setCreateBy(SecurityUtils.getUserId().toString());
|
||||||
|
rows += dataSetBasicFileMapper.updateDataSetBasicFile(entity);
|
||||||
|
}
|
||||||
|
//int rows = dataSetBasicFileMapper.dataRecoveryFileByFileIds(fileIds);
|
||||||
return rows > 0 ? AjaxResult.success() : AjaxResult.error();
|
return rows > 0 ? AjaxResult.success() : AjaxResult.error();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return AjaxResult.error();
|
return AjaxResult.error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 改变文件夹或文件名最后()里的数字,同时保留原始后缀
|
||||||
|
public static String changeNumberInName(String name, int newNumber) {
|
||||||
|
// 提取文件扩展名
|
||||||
|
String extension = "";
|
||||||
|
int dotIndex = name.lastIndexOf(".");
|
||||||
|
if (dotIndex != -1) {
|
||||||
|
extension = name.substring(dotIndex); // 获取文件后缀
|
||||||
|
name = name.substring(0, dotIndex); // 去掉文件后缀
|
||||||
|
}
|
||||||
|
|
||||||
|
// 正则表达式:匹配最后一个括号里的数字
|
||||||
|
Pattern pattern = Pattern.compile(".*\\((\\d+)\\)$");
|
||||||
|
Matcher matcher = pattern.matcher(name);
|
||||||
|
|
||||||
|
if (matcher.matches()) {
|
||||||
|
// 替换括号中的数字为新的数字
|
||||||
|
String newName = name.substring(0, matcher.start(1)) +newNumber + name.substring(matcher.end(1));
|
||||||
|
return newName + extension; // 加上原始文件扩展名
|
||||||
|
} else {
|
||||||
|
// 如果没有找到括号中的数字,返回原文件夹/文件名和扩展名
|
||||||
|
return name + "(" + newNumber + ")" + extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取文件名最后()里的数字
|
||||||
|
public static Integer getNumberFromFileName(String fileName) {
|
||||||
|
// 正则表达式:匹配最后一个括号里的数字
|
||||||
|
Pattern pattern = Pattern.compile(".*\\((\\d+)\\)$");
|
||||||
|
Matcher matcher = pattern.matcher(fileName);
|
||||||
|
|
||||||
|
if (matcher.matches()) {
|
||||||
|
// 返回括号中的数字
|
||||||
|
return Integer.parseInt(matcher.group(1));
|
||||||
|
} else {
|
||||||
|
// 如果没有找到括号中的数字,返回 null 或者其他默认值
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 文件分片上传
|
* 文件分片上传
|
||||||
*
|
*
|
||||||
|
|
@ -233,20 +290,20 @@ public class DataSetBasicFileServiceImpl implements DataSetBasicFileService {
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult sharedFilesByIds(Long[] fileIds) {
|
public AjaxResult sharedFilesByIds(Long[] fileIds) {
|
||||||
List<DataSetBasicFileEntity> list = getFilesByIds(fileIds);
|
List<DataSetBasicFileEntity> list = getFilesByIds(fileIds);
|
||||||
for (DataSetBasicFileEntity entity :list){
|
for (DataSetBasicFileEntity entity : list) {
|
||||||
if ("1".equals(entity.getIsDirectory())){
|
if ("1".equals(entity.getIsDirectory())) {
|
||||||
for (Long fileId : fileIds) {
|
for (Long fileId : fileIds) {
|
||||||
Set<Long> ancestors = getAncestorsByFileIds(fileId);
|
Set<Long> ancestors = getAncestorsByFileIds(fileId);
|
||||||
Set<Long> children = getFileWithChildren(fileId);
|
Set<Long> children = getFileWithChildren(fileId);
|
||||||
ancestors.addAll(children);
|
ancestors.addAll(children);
|
||||||
ancestors.add(fileId);
|
ancestors.add(fileId);
|
||||||
dataSetBasicFileMapper.updateSharedFilesByIds(ancestors,"1");
|
dataSetBasicFileMapper.updateSharedFilesByIds(ancestors, "1");
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
for (Long fileId : fileIds) {
|
for (Long fileId : fileIds) {
|
||||||
Set<Long> ancestors = getAncestorsByFileIds(fileId);
|
Set<Long> ancestors = getAncestorsByFileIds(fileId);
|
||||||
ancestors.add(fileId);
|
ancestors.add(fileId);
|
||||||
dataSetBasicFileMapper.updateSharedFilesByIds(ancestors,"1");
|
dataSetBasicFileMapper.updateSharedFilesByIds(ancestors, "1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -261,25 +318,25 @@ public class DataSetBasicFileServiceImpl implements DataSetBasicFileService {
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult changeIsPublic(DataSetBasicFileEntity entity) {
|
public AjaxResult changeIsPublic(DataSetBasicFileEntity entity) {
|
||||||
DataSetBasicFileEntity file = dataSetBasicFileMapper.selectDataSetBasicFileByFileId(entity.getFileId());
|
DataSetBasicFileEntity file = dataSetBasicFileMapper.selectDataSetBasicFileByFileId(entity.getFileId());
|
||||||
if ("1".equals(file.getIsDirectory())){
|
if ("1".equals(file.getIsDirectory())) {
|
||||||
Set<Long> ancestors = getAncestorsByFileIds(entity.getFileId());
|
Set<Long> ancestors = getAncestorsByFileIds(entity.getFileId());
|
||||||
Set<Long> children = getFileWithChildren(entity.getFileId());
|
Set<Long> children = getFileWithChildren(entity.getFileId());
|
||||||
children.add(entity.getFileId());
|
children.add(entity.getFileId());
|
||||||
dataSetBasicFileMapper.updateSharedFilesByIds(children,entity.getIsPublic());
|
dataSetBasicFileMapper.updateSharedFilesByIds(children, entity.getIsPublic());
|
||||||
Set<Long> isPublic = getIsPublic(ancestors);
|
Set<Long> isPublic = getIsPublic(ancestors);
|
||||||
if (!isPublic.isEmpty()){
|
if (!isPublic.isEmpty()) {
|
||||||
dataSetBasicFileMapper.updateSharedFilesByIds(isPublic,entity.getIsPublic());
|
dataSetBasicFileMapper.updateSharedFilesByIds(isPublic, entity.getIsPublic());
|
||||||
}
|
}
|
||||||
|
|
||||||
}else {
|
} else {
|
||||||
Set<Long> fileId = new HashSet<>();
|
Set<Long> fileId = new HashSet<>();
|
||||||
fileId.add(entity.getFileId());
|
fileId.add(entity.getFileId());
|
||||||
Set<Long> ancestors = getAncestorsByFileIds(entity.getFileId());
|
Set<Long> ancestors = getAncestorsByFileIds(entity.getFileId());
|
||||||
fileId.addAll(ancestors);
|
fileId.addAll(ancestors);
|
||||||
dataSetBasicFileMapper.updateSharedFilesByIds(fileId,entity.getIsPublic());
|
dataSetBasicFileMapper.updateSharedFilesByIds(fileId, entity.getIsPublic());
|
||||||
Set<Long> isPublic = getIsPublic(ancestors);
|
Set<Long> isPublic = getIsPublic(ancestors);
|
||||||
if (!isPublic.isEmpty()){
|
if (!isPublic.isEmpty()) {
|
||||||
dataSetBasicFileMapper.updateSharedFilesByIds(isPublic,entity.getIsPublic());
|
dataSetBasicFileMapper.updateSharedFilesByIds(isPublic, entity.getIsPublic());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
|
|
@ -311,19 +368,39 @@ public class DataSetBasicFileServiceImpl implements DataSetBasicFileService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取同级目录是否是否存在共享数据
|
* @param entity
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Long> getIsPublic(Set<Long> ancestors){
|
@Override
|
||||||
|
public AjaxResult moveFile(DataSetBasicFileEntity entity) {
|
||||||
|
DataSetBasicFileEntity entity1 = dataSetBasicFileMapper.selectDataSetBasicFileByFileId(entity.getParentId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult emptyRecycleBin() {
|
||||||
|
dataSetBasicFileMapper.emptyRecycleBin();
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取同级目录是否是否存在共享数据
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Long> getIsPublic(Set<Long> ancestors) {
|
||||||
// 将 Set 转换为 List
|
// 将 Set 转换为 List
|
||||||
List<Long> ancestorList = new ArrayList<>(ancestors);
|
List<Long> ancestorList = new ArrayList<>(ancestors);
|
||||||
Set<Long> isPublic = new HashSet<>();
|
Set<Long> isPublic = new HashSet<>();
|
||||||
for (int i = ancestorList.size() - 1; i >= 0; i--) {
|
for (int i = ancestorList.size() - 1; i >= 0; i--) {
|
||||||
List<DataSetBasicFileEntity> list = dataSetBasicFileMapper.selectDataSetBasicFileByParentId(ancestorList.get(i));
|
List<DataSetBasicFileEntity> list = dataSetBasicFileMapper.selectDataSetBasicFileByParentId(ancestorList.get(i));
|
||||||
boolean exists = list.stream().anyMatch(file -> "1".equals(file.getIsPublic()));
|
boolean exists = list.stream().anyMatch(file -> "1".equals(file.getIsPublic()));
|
||||||
if (exists){
|
if (exists) {
|
||||||
return isPublic;
|
return isPublic;
|
||||||
}else {
|
} else {
|
||||||
isPublic.add(ancestorList.get(i));
|
isPublic.add(ancestorList.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -332,12 +409,13 @@ public class DataSetBasicFileServiceImpl implements DataSetBasicFileService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件及其子节点
|
* 获取文件及其子节点
|
||||||
|
*
|
||||||
* @param fileId 文件 ID
|
* @param fileId 文件 ID
|
||||||
* @return 当前文件及其所有子节点
|
* @return 当前文件及其所有子节点
|
||||||
*/
|
*/
|
||||||
public Set<Long> getFileWithChildren(Long fileId) {
|
public Set<Long> getFileWithChildren(Long fileId) {
|
||||||
// 查询所有文件数据,假设你已经根据需求修改了查询方法
|
// 查询所有文件数据,假设你已经根据需求修改了查询方法
|
||||||
DataSetBasicFileEntity entity =new DataSetBasicFileEntity();
|
DataSetBasicFileEntity entity = new DataSetBasicFileEntity();
|
||||||
entity.setCreateBy(SecurityUtils.getUserId().toString());
|
entity.setCreateBy(SecurityUtils.getUserId().toString());
|
||||||
List<DataSetBasicFileEntity> allFiles = dataSetBasicFileMapper.selectDataSetBasicFileList(entity);
|
List<DataSetBasicFileEntity> allFiles = dataSetBasicFileMapper.selectDataSetBasicFileList(entity);
|
||||||
// 构建父子关系映射
|
// 构建父子关系映射
|
||||||
|
|
@ -370,11 +448,12 @@ public class DataSetBasicFileServiceImpl implements DataSetBasicFileService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据多个 fileId 查询所有祖先节点
|
* 根据多个 fileId 查询所有祖先节点
|
||||||
|
*
|
||||||
* @param fileId 起始节点 ID
|
* @param fileId 起始节点 ID
|
||||||
* @return 每个文件对应的祖先节点列表 Map
|
* @return 每个文件对应的祖先节点列表 Map
|
||||||
*/
|
*/
|
||||||
public Set<Long> getAncestorsByFileIds(Long fileId) {
|
public Set<Long> getAncestorsByFileIds(Long fileId) {
|
||||||
Set<Long> ancestors = new HashSet<>();
|
Set<Long> ancestors = new HashSet<>();
|
||||||
Long currentId = fileId;
|
Long currentId = fileId;
|
||||||
while (currentId != null && currentId != 0) {
|
while (currentId != null && currentId != 0) {
|
||||||
DataSetBasicFileEntity entity = dataSetBasicFileMapper.selectDataSetBasicFileByFileId(currentId);
|
DataSetBasicFileEntity entity = dataSetBasicFileMapper.selectDataSetBasicFileByFileId(currentId);
|
||||||
|
|
@ -538,7 +617,7 @@ public class DataSetBasicFileServiceImpl implements DataSetBasicFileService {
|
||||||
InputStream fileStream = minioUtil.downloadFile(item.objectName());
|
InputStream fileStream = minioUtil.downloadFile(item.objectName());
|
||||||
// 在 ZIP 中创建对应的条目,保持目录结构
|
// 在 ZIP 中创建对应的条目,保持目录结构
|
||||||
String result = objectName.replace(entity.getFileUrl(), "");
|
String result = objectName.replace(entity.getFileUrl(), "");
|
||||||
ZipEntry zipEntry = new ZipEntry(entity.getFileName()+File.separator+result);
|
ZipEntry zipEntry = new ZipEntry(entity.getFileName() + File.separator + result);
|
||||||
zos.putNextEntry(zipEntry);
|
zos.putNextEntry(zipEntry);
|
||||||
IOUtils.copy(fileStream, zos);
|
IOUtils.copy(fileStream, zos);
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,13 @@
|
||||||
ORDER BY abf.is_directory DESC ,abf.create_time DESC
|
ORDER BY abf.is_directory DESC ,abf.create_time DESC
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectDataSetBasicFile" parameterType="Long" resultMap="DataSetBasicFileResult">
|
||||||
|
<include refid="selectDataSetBasicFileVo"/>
|
||||||
|
where abf.file_id = #{fileId}
|
||||||
|
ORDER BY abf.is_directory DESC ,abf.create_time DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectDataSetBasicFileByParentId" resultMap="DataSetBasicFileResult">
|
<select id="selectDataSetBasicFileByParentId" resultMap="DataSetBasicFileResult">
|
||||||
<include refid="selectDataSetBasicFileVo"/>
|
<include refid="selectDataSetBasicFileVo"/>
|
||||||
where abf.parent_id = #{parentId} AND abf.del_flag ='0'
|
where abf.parent_id = #{parentId} AND abf.del_flag ='0'
|
||||||
|
|
@ -67,6 +74,12 @@
|
||||||
|
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectDataSetBasicFileByFileName" resultType="com.bonus.ai.domain.DataSetBasicFileEntity" resultMap="DataSetBasicFileResult">
|
||||||
|
<include refid="selectDataSetBasicFileVo"/>
|
||||||
|
where abf.parent_id = #{parentId} AND abf.del_flag ='0'
|
||||||
|
<if test="fileName != null and fileName != ''"> and abf.file_name like concat('%', #{fileName}, '%')</if>
|
||||||
|
ORDER BY abf.is_directory DESC ,abf.create_time DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertDataSetBasicFile" parameterType="com.bonus.ai.domain.DataSetBasicFileEntity" useGeneratedKeys="true" keyProperty="fileId">
|
<insert id="insertDataSetBasicFile" parameterType="com.bonus.ai.domain.DataSetBasicFileEntity" useGeneratedKeys="true" keyProperty="fileId">
|
||||||
insert into ai_basic_file
|
insert into ai_basic_file
|
||||||
|
|
@ -144,6 +157,11 @@
|
||||||
#{fileId}
|
#{fileId}
|
||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
<update id="emptyRecycleBin">
|
||||||
|
update ai_basic_file
|
||||||
|
set del_flag='2'
|
||||||
|
where del_flag = '1'
|
||||||
|
</update>
|
||||||
|
|
||||||
<delete id="deleteDataSetBasicFileByFileIds" parameterType="String">
|
<delete id="deleteDataSetBasicFileByFileIds" parameterType="String">
|
||||||
update ai_basic_file set del_flag='1' , update_time = now() where file_id in
|
update ai_basic_file set del_flag='1' , update_time = now() where file_id in
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue