代码提交
This commit is contained in:
parent
2bd50f4462
commit
11c17eb3bc
@ -19,4 +19,6 @@ public interface TsFilesMapper extends BaseMapper<TsFiles> {
|
||||
int batchInsertTsFiles(List<TsFiles> tsFilesToCreate);
|
||||
|
||||
int updateParentIdByPathHierarchy(@Param("taskId") String taskId, @Param("nodeId") String nodeId);
|
||||
|
||||
int countFiles(@Param("id") String id);
|
||||
}
|
||||
|
@ -250,4 +250,6 @@ public interface ITsFilesService extends IService<TsFiles> {
|
||||
void automaticFileBackupAsyncByIds(List<String> dataset,String taskId, String nodeId) throws IOException;
|
||||
|
||||
IPage<TsFiles> getCachedTsFilesPage(String taskId, String nodeId, int currentPage,String id);
|
||||
|
||||
int countFiles(String id);
|
||||
}
|
||||
|
@ -328,6 +328,12 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
// return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countFiles(String id) {
|
||||
int count = tsFilesMapper.countFiles(id);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
private boolean isValidPage(IPage<TsFiles> page) {
|
||||
return page.getRecords() != null
|
||||
|
@ -7,6 +7,7 @@ import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.yfd.platform.component.TaskStatusHolder;
|
||||
import com.yfd.platform.component.WebSocketServer;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
@ -458,32 +459,36 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
List<String> nodeIds = tsNodesList.stream()
|
||||
.map(TsNodes::getNodeId) // 获取每个节点的 ID
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
//查询所有的文件
|
||||
QueryWrapper<TsFiles> queryWrapper1 = new QueryWrapper<>();
|
||||
queryWrapper1.in("node_id", nodeIds);
|
||||
queryWrapper1.eq("task_id", tsNodes.getTaskId());
|
||||
List<TsFiles> tsFiles = tsFilesMapper.selectList(queryWrapper1);
|
||||
//获取所有文件的ID集合
|
||||
List<String> dataset = new ArrayList<>();
|
||||
if (tsFiles != null && !tsFiles.isEmpty()) {
|
||||
dataset.addAll(tsFiles.stream()
|
||||
.map(TsFiles::getId)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
if (dataset.size() > 0) {
|
||||
//批量修改
|
||||
//修改项目ID 和所有节点id的workPath字段为空
|
||||
if (CollectionUtils.isNotEmpty(nodeIds)) {
|
||||
// 4. 批量更新:将这些节点的文件工作路径置空
|
||||
LambdaUpdateWrapper<TsFiles> updateWrapper1 = new LambdaUpdateWrapper<>();
|
||||
updateWrapper1.in(TsFiles::getId, dataset).set(TsFiles::getWorkPath, "");
|
||||
updateWrapper1.in(TsFiles::getNodeId, nodeIds).eq(TsFiles::getTaskId, tsNodes.getTaskId()).set(TsFiles::getWorkPath, "");
|
||||
tsFilesMapper.update(null, updateWrapper1);
|
||||
|
||||
|
||||
// 5. 删除符合条件的文件记录
|
||||
LambdaQueryWrapper<TsFiles> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.in(TsFiles::getId, dataset)
|
||||
deleteWrapper.in(TsFiles::getNodeId, nodeIds)
|
||||
.eq(TsFiles::getTaskId, tsNodes.getTaskId())
|
||||
.and(wrapper -> wrapper.isNull(TsFiles::getBackupPath).or().eq(TsFiles::getBackupPath, ""))
|
||||
.and(wrapper -> wrapper.isNull(TsFiles::getWorkPath).or().eq(TsFiles::getWorkPath, ""));
|
||||
tsFilesMapper.delete(deleteWrapper);
|
||||
}
|
||||
|
||||
// //查询所有的文件
|
||||
// QueryWrapper<TsFiles> queryWrapper1 = new QueryWrapper<>();
|
||||
// queryWrapper1.in("node_id", nodeIds);
|
||||
// queryWrapper1.eq("task_id", tsNodes.getTaskId());
|
||||
// List<TsFiles> tsFiles = tsFilesMapper.selectList(queryWrapper1);
|
||||
// //获取所有文件的ID集合
|
||||
// List<String> dataset = new ArrayList<>();
|
||||
// if (tsFiles != null && !tsFiles.isEmpty()) {
|
||||
// dataset.addAll(tsFiles.stream()
|
||||
// .map(TsFiles::getId)
|
||||
// .collect(Collectors.toList()));
|
||||
// }
|
||||
|
||||
//删除当前节点的文件夹 todo 这个地方改动
|
||||
// 删除 sdlocal 中的文件夹
|
||||
List<BatchDeleteRequest.DeleteItem> deleteItemList = new ArrayList<>();
|
||||
@ -521,8 +526,8 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
}
|
||||
if (deleteSuccessCount >= 1) {
|
||||
// 删除当前节点
|
||||
int deleteCount = tsNodesMapper.deleteById(id);
|
||||
if (deleteCount == 1) {
|
||||
int deleteCount = tsNodesMapper.deleteBatchIds(nodeIds);
|
||||
if (deleteCount >= 1) {
|
||||
LOGGER.info("tsnodes表结删除改成功");
|
||||
return true;
|
||||
} else {
|
||||
@ -697,19 +702,23 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
jsonObject.putOpt("status", "1");
|
||||
return ResponseResult.successData(jsonObject);
|
||||
}
|
||||
//递归查询所有的子节点
|
||||
List<TsNodes> tsNodesList = selectChildrentsNodes(tsNodes.getNodeId(), tsNodes.getTaskId());
|
||||
// 提取所有节点的 ID
|
||||
List<String> nodeIds = tsNodesList.stream()
|
||||
.map(TsNodes::getNodeId) // 获取每个节点的 ID
|
||||
.collect(Collectors.toList());
|
||||
// //递归查询所有的子节点
|
||||
// List<TsNodes> tsNodesList = selectChildrentsNodes(tsNodes.getNodeId(), tsNodes.getTaskId());
|
||||
// // 提取所有节点的 ID
|
||||
// List<String> nodeIds = tsNodesList.stream()
|
||||
// .map(TsNodes::getNodeId) // 获取每个节点的 ID
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
//
|
||||
// LambdaQueryWrapper<TsFiles> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.eq(TsFiles::getTaskId, tsNodes.getTaskId())
|
||||
// .in(TsFiles::getNodeId, nodeIds)
|
||||
// .and(wrapper -> wrapper.isNotNull(TsFiles::getBackupPath)
|
||||
// .or().ne(TsFiles::getBackupPath, ""));
|
||||
|
||||
LambdaQueryWrapper<TsFiles> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TsFiles::getTaskId, tsNodes.getTaskId())
|
||||
.in(TsFiles::getNodeId, nodeIds)
|
||||
.and(wrapper -> wrapper.isNotNull(TsFiles::getBackupPath)
|
||||
.or().ne(TsFiles::getBackupPath, ""));
|
||||
int count = tsFilesService.count(queryWrapper);
|
||||
|
||||
//SQL通过节点ID 递归查询节点下面的所有子节点 以及files表中 backup_path IS NOT NULL
|
||||
int count = tsFilesService.countFiles(id);
|
||||
//如果大于0不让删
|
||||
if (count > 0) {
|
||||
jsonObject.putOpt("status", "0");
|
||||
@ -786,7 +795,18 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
*/
|
||||
private void otherLevelsData(String taskId, String nodeId, String nodeName, String path, String parentId) throws Exception {
|
||||
|
||||
|
||||
//获取当前登录用户 上传人是当前登录人
|
||||
UsernamePasswordAuthenticationToken authentication =
|
||||
(UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
LoginUser loginuser = null;
|
||||
if (authentication != null) {
|
||||
loginuser = (LoginUser) authentication.getPrincipal();
|
||||
}
|
||||
//登录人
|
||||
String uploader = null;
|
||||
if (loginuser != null) {
|
||||
uploader = loginuser.getUsername();
|
||||
}
|
||||
// 存储所有目录和文件的列表
|
||||
List<TsFiles> tsFilesToCreate = new ArrayList<>();
|
||||
|
||||
@ -828,7 +848,7 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
//工作空间路径
|
||||
tsFiles1.setWorkPath(ensurePathFormat(finalPath));
|
||||
tsFiles1.setUploadTime(currentTime);
|
||||
|
||||
tsFiles1.setUploader(uploader);
|
||||
|
||||
if ("null".equals(String.valueOf(subDir.length()))) {
|
||||
tsFiles1.setFileSize("0.001");
|
||||
@ -875,8 +895,7 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
//工作空间路径
|
||||
tsFiles1.setWorkPath(ensurePathFormat(finalPath));
|
||||
tsFiles1.setUploadTime(currentTime);
|
||||
|
||||
|
||||
tsFiles1.setUploader(uploader);
|
||||
if ("null".equals(String.valueOf(file.length()))) {
|
||||
tsFiles1.setFileSize("0.001");
|
||||
} else {
|
||||
|
@ -538,7 +538,6 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
public boolean deleteNodesById(String id, String path) {
|
||||
Boolean value = false;
|
||||
|
||||
|
||||
// 根据ID 查询当前数据
|
||||
Nodes nodes = nodesMapper.selectById(id);
|
||||
|
||||
|
@ -5,11 +5,11 @@
|
||||
<!-- 批量插入试验任务文件表(存在唯一键冲突时忽略) -->
|
||||
<insert id="batchInsertTsFiles">
|
||||
INSERT INTO ts_files
|
||||
(id,node_id, task_id, is_file, parent_id, file_name, file_size, work_path,upload_time)
|
||||
(id,node_id, task_id, is_file, parent_id, file_name, file_size, work_path,upload_time,uploader)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id},#{item.nodeId}, #{item.taskId}, #{item.isFile}, #{item.parentId},
|
||||
#{item.fileName}, #{item.fileSize}, #{item.workPath}, #{item.uploadTime})
|
||||
#{item.fileName}, #{item.fileSize}, #{item.workPath}, #{item.uploadTime},#{item.uploader})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
@ -25,4 +25,20 @@
|
||||
AND b.node_id = #{nodeId}
|
||||
</update>
|
||||
|
||||
<select id="countFiles" resultType="java.lang.Integer">
|
||||
WITH RECURSIVE node_tree AS (SELECT node_id
|
||||
FROM ts_nodes
|
||||
WHERE node_id = #{id}
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT n.node_id
|
||||
FROM ts_nodes n
|
||||
INNER JOIN node_tree t ON n.parent_id = t.node_id)
|
||||
SELECT count(*)
|
||||
FROM ts_files
|
||||
WHERE node_id IN (SELECT node_id FROM node_tree)
|
||||
AND backup_path IS NOT NULL
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user