提交代码删除、以及异步自动备份
This commit is contained in:
parent
1622d4cfac
commit
ba94e48c35
@ -0,0 +1,31 @@
|
|||||||
|
package com.yfd.platform.component;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class TaskStatusHolder {
|
||||||
|
|
||||||
|
private final ConcurrentHashMap<String, String> taskStatusMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
// 生成唯一Key:taskId + nodeId
|
||||||
|
public String generateKey(String taskId, String nodeId) {
|
||||||
|
return taskId + ":" + nodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 原子性检查并标记任务开始
|
||||||
|
public boolean startTaskIfAbsent(String key) {
|
||||||
|
return taskStatusMap.putIfAbsent(key, "IN_PROGRESS") == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标记任务结束
|
||||||
|
public void finishTask(String key) {
|
||||||
|
taskStatusMap.put(key, "COMPLETED");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取任务状态
|
||||||
|
public String getStatus(String key) {
|
||||||
|
return taskStatusMap.getOrDefault(key, "TASK_NOT_FOUND");
|
||||||
|
}
|
||||||
|
}
|
@ -5,11 +5,13 @@ import cn.hutool.core.util.ObjUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.annotation.Log;
|
import com.yfd.platform.annotation.Log;
|
||||||
|
import com.yfd.platform.component.TaskStatusHolder;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.config.ResponseResult;
|
||||||
import com.yfd.platform.modules.experimentalData.domain.*;
|
import com.yfd.platform.modules.experimentalData.domain.*;
|
||||||
import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
|
import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
|
||||||
import com.yfd.platform.modules.storage.model.result.FileItemResult;
|
import com.yfd.platform.modules.storage.model.result.FileItemResult;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -37,6 +39,9 @@ public class TsFilesController {
|
|||||||
@Resource
|
@Resource
|
||||||
private ITsFilesService tsFilesService;
|
private ITsFilesService tsFilesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskStatusHolder taskStatusHolder;
|
||||||
|
|
||||||
/**********************************
|
/**********************************
|
||||||
* 用途说明: 分页查询试验数据管理-文档内容
|
* 用途说明: 分页查询试验数据管理-文档内容
|
||||||
* 参数说明
|
* 参数说明
|
||||||
@ -462,13 +467,38 @@ public class TsFilesController {
|
|||||||
@Log(module = "实验数据管理", value = "文件自动备份!")
|
@Log(module = "实验数据管理", value = "文件自动备份!")
|
||||||
@PostMapping("/automaticFileBackup")
|
@PostMapping("/automaticFileBackup")
|
||||||
@ApiOperation("自动备份本地文件到备份空间")
|
@ApiOperation("自动备份本地文件到备份空间")
|
||||||
public ResponseResult automaticFileBackup(String taskId, String nodeId) {
|
public ResponseResult automaticFileBackup(String taskId, String nodeId) throws IOException {
|
||||||
|
|
||||||
|
|
||||||
if (StrUtil.isEmpty(taskId) || StrUtil.isEmpty(nodeId)) {
|
if (StrUtil.isEmpty(taskId) || StrUtil.isEmpty(nodeId)) {
|
||||||
return ResponseResult.error("参数为空");
|
return ResponseResult.error("参数为空");
|
||||||
}
|
}
|
||||||
return ResponseResult.success(tsFilesService.automaticFileBackup(taskId, nodeId));
|
|
||||||
|
// 生成唯一Key
|
||||||
|
String asyncKey = taskStatusHolder.generateKey(taskId, nodeId);
|
||||||
|
|
||||||
|
// 检查任务是否已存在
|
||||||
|
String existingStatus = taskStatusHolder.getStatus(asyncKey);
|
||||||
|
if ("IN_PROGRESS".equals(existingStatus)) {
|
||||||
|
return ResponseResult.success("任务正在处理中!");
|
||||||
|
} else if ("COMPLETED".equals(existingStatus)) {
|
||||||
|
return ResponseResult.success("任务已完成!");
|
||||||
|
}
|
||||||
|
// 原子性启动新任务
|
||||||
|
if (taskStatusHolder.startTaskIfAbsent(asyncKey)) {
|
||||||
|
// 直接异步执行并推送结果
|
||||||
|
tsFilesService.automaticFileBackupAsync(taskId, nodeId);
|
||||||
|
return ResponseResult.success("任务开始处理!");
|
||||||
|
} else {
|
||||||
|
return ResponseResult.success("任务已由其他请求启动");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// return ResponseResult.success(tsFilesService.automaticFileBackup(taskId, nodeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************
|
/**********************************
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -116,7 +117,9 @@ public class TsTaskController {
|
|||||||
if (StrUtil.isBlank(id)) {
|
if (StrUtil.isBlank(id)) {
|
||||||
return ResponseResult.error("参数为空");
|
return ResponseResult.error("参数为空");
|
||||||
}
|
}
|
||||||
boolean isOk = tsTaskService.removeById(id);
|
List<String> dataset = new ArrayList<>();
|
||||||
|
dataset.add(id);
|
||||||
|
boolean isOk = tsTaskService.deleteTstaskByIds(dataset);
|
||||||
if (isOk) {
|
if (isOk) {
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
} else {
|
} else {
|
||||||
@ -140,7 +143,7 @@ public class TsTaskController {
|
|||||||
String[] splitIds = ids.split(",");
|
String[] splitIds = ids.split(",");
|
||||||
// 数组转集合
|
// 数组转集合
|
||||||
List<String> dataset = Arrays.asList(splitIds);
|
List<String> dataset = Arrays.asList(splitIds);
|
||||||
boolean isOk = tsTaskService.removeByIds(dataset);
|
boolean isOk = tsTaskService.deleteTstaskByIds(dataset);
|
||||||
if (isOk) {
|
if (isOk) {
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
} else {
|
} else {
|
||||||
|
@ -230,5 +230,7 @@ public interface ITsFilesService extends IService<TsFiles> {
|
|||||||
Page<TsFiles> compareMd5(List<String> dataset, String nodeId, String taskId, Page<TsFiles> page);
|
Page<TsFiles> compareMd5(List<String> dataset, String nodeId, String taskId, Page<TsFiles> page);
|
||||||
|
|
||||||
|
|
||||||
|
void automaticFileBackupAsync(String taskId, String nodeId) throws IOException;
|
||||||
|
|
||||||
|
Boolean deleteTsFilesByNodeId(String nodeId, String taskId);
|
||||||
}
|
}
|
||||||
|
@ -46,4 +46,7 @@ public interface ITsNodesService extends IService<TsNodes> {
|
|||||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回删除成功或者失败
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回删除成功或者失败
|
||||||
***********************************/
|
***********************************/
|
||||||
boolean deleteTsNodesById(String id);
|
boolean deleteTsNodesById(String id);
|
||||||
|
|
||||||
|
|
||||||
|
boolean deleteTsNodesByTaskId(String taskId);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.yfd.platform.modules.experimentalData.domain.TsTask;
|
import com.yfd.platform.modules.experimentalData.domain.TsTask;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 试验任务表 服务类
|
* 试验任务表 服务类
|
||||||
@ -44,4 +46,11 @@ public interface ITsTaskService extends IService<TsTask> {
|
|||||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回修改成功或者失败
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回修改成功或者失败
|
||||||
***********************************/
|
***********************************/
|
||||||
boolean updatetsTask(TsTask tsTask);
|
boolean updatetsTask(TsTask tsTask);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 批量删除试验数据管理-试验任务管理
|
||||||
|
* 参数说明 ids 试验数据管理id数组
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回批量删除成功或失败
|
||||||
|
***********************************/
|
||||||
|
boolean deleteTstaskByIds(List<String> dataset);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import com.opencsv.CSVReader;
|
|||||||
import com.opencsv.CSVWriter;
|
import com.opencsv.CSVWriter;
|
||||||
import com.opencsv.exceptions.CsvValidationException;
|
import com.opencsv.exceptions.CsvValidationException;
|
||||||
import com.yfd.platform.component.ServerSendEventServer;
|
import com.yfd.platform.component.ServerSendEventServer;
|
||||||
|
import com.yfd.platform.component.TaskStatusHolder;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.config.ResponseResult;
|
||||||
import com.yfd.platform.modules.experimentalData.domain.*;
|
import com.yfd.platform.modules.experimentalData.domain.*;
|
||||||
import com.yfd.platform.modules.experimentalData.mapper.TsFilesMapper;
|
import com.yfd.platform.modules.experimentalData.mapper.TsFilesMapper;
|
||||||
@ -36,6 +37,8 @@ import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yfd.platform.modules.storage.context.StorageSourceContext;
|
import com.yfd.platform.modules.storage.context.StorageSourceContext;
|
||||||
import com.yfd.platform.modules.storage.mapper.StorageSourceConfigMapper;
|
import com.yfd.platform.modules.storage.mapper.StorageSourceConfigMapper;
|
||||||
|
import com.yfd.platform.modules.storage.mapper.StorageSourceMapper;
|
||||||
|
import com.yfd.platform.modules.storage.model.entity.StorageSource;
|
||||||
import com.yfd.platform.modules.storage.model.entity.StorageSourceConfig;
|
import com.yfd.platform.modules.storage.model.entity.StorageSourceConfig;
|
||||||
import com.yfd.platform.modules.storage.model.enums.FileTypeEnum;
|
import com.yfd.platform.modules.storage.model.enums.FileTypeEnum;
|
||||||
import com.yfd.platform.modules.storage.model.request.BatchDeleteRequest;
|
import com.yfd.platform.modules.storage.model.request.BatchDeleteRequest;
|
||||||
@ -54,13 +57,12 @@ import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;
|
|||||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
|
||||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
||||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
|
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -100,6 +102,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
@Resource
|
@Resource
|
||||||
private StorageSourceConfigMapper storageSourceConfigMapper;
|
private StorageSourceConfigMapper storageSourceConfigMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private StorageSourceMapper storageSourceMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SysDictionaryItemsMapper sysDictionaryItemsMapper;
|
private SysDictionaryItemsMapper sysDictionaryItemsMapper;
|
||||||
// 全局变量,用于存储当前任务的 Future
|
// 全局变量,用于存储当前任务的 Future
|
||||||
@ -111,6 +116,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
private List<String> compressSuffixes;
|
private List<String> compressSuffixes;
|
||||||
private final Set<String> addedEntries = new HashSet<>();
|
private final Set<String> addedEntries = new HashSet<>();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskStatusHolder taskStatusHolder;
|
||||||
|
|
||||||
|
|
||||||
/**********************************
|
/**********************************
|
||||||
* 用途说明: 分页查询试验数据管理-文档内容
|
* 用途说明: 分页查询试验数据管理-文档内容
|
||||||
@ -2712,6 +2720,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 递归查询所有子节点
|
// 递归查询所有子节点
|
||||||
private List<TsFiles> getChildFilesRecursiveMd5(String parentId, List<TsFiles> allFiles) {
|
private List<TsFiles> getChildFilesRecursiveMd5(String parentId, List<TsFiles> allFiles) {
|
||||||
// 构建查询条件,获取当前parentId的所有子节点
|
// 构建查询条件,获取当前parentId的所有子节点
|
||||||
@ -3023,6 +3032,23 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Async("asyncExecutor")
|
||||||
|
public void automaticFileBackupAsync(String taskId, String nodeId) throws IOException {
|
||||||
|
try {
|
||||||
|
// 执行实际备份逻辑
|
||||||
|
this.automaticFileBackup(taskId, nodeId);
|
||||||
|
} finally {
|
||||||
|
// 生成唯一Key
|
||||||
|
String asyncKey = taskStatusHolder.generateKey(taskId, nodeId);
|
||||||
|
// 无论成功失败都标记完成
|
||||||
|
taskStatusHolder.finishTask(asyncKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************
|
/**********************************
|
||||||
* 用途说明: 文件自动备份
|
* 用途说明: 文件自动备份
|
||||||
* 参数说明 taskId 节点ID
|
* 参数说明 taskId 节点ID
|
||||||
@ -4460,6 +4486,78 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 删除整个节点以及数据库的数据-物理删除
|
||||||
|
* 参数说明 nodeId 节点ID
|
||||||
|
* 参数说明 taskId 任务ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回批量删除成功或失败
|
||||||
|
***********************************/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)// 添加事务注解,遇到异常时回滚
|
||||||
|
public Boolean deleteTsFilesByNodeId(String nodeId, String taskId) {
|
||||||
|
List<StorageSource> storageSourceList = storageSourceMapper.selectList(new QueryWrapper<StorageSource>());
|
||||||
|
int deleteSuccessCount = 0, deleteFailCount = 0;
|
||||||
|
Boolean value = false;
|
||||||
|
|
||||||
|
for (StorageSource storageSource : storageSourceList){
|
||||||
|
//如果是文件夹
|
||||||
|
List<BatchDeleteRequest.DeleteItem> deleteItemList = new ArrayList<>();
|
||||||
|
BatchDeleteRequest.DeleteItem deleteItemData = new BatchDeleteRequest.DeleteItem();
|
||||||
|
deleteItemData.setName(nodeId);
|
||||||
|
deleteItemData.setPassword("");
|
||||||
|
deleteItemData.setPath(File.separator);
|
||||||
|
|
||||||
|
deleteItemData.setType(FileTypeEnum.FOLDER);
|
||||||
|
deleteItemList.add(deleteItemData);
|
||||||
|
//首先通过ID集合查询所有的内容 然后放到List<DeleteItem> deleteItems里面 放好以后删除数据库 然后删除minio
|
||||||
|
BatchDeleteRequest batchDeleteRequest = new BatchDeleteRequest();
|
||||||
|
batchDeleteRequest.setDeleteItems(deleteItemList);
|
||||||
|
batchDeleteRequest.setStorageKey(storageSource.getKey());
|
||||||
|
|
||||||
|
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(batchDeleteRequest.getStorageKey());
|
||||||
|
List<BatchDeleteRequest.DeleteItem> deleteItems = batchDeleteRequest.getDeleteItems();
|
||||||
|
|
||||||
|
for (BatchDeleteRequest.DeleteItem deleteItem : deleteItems) {
|
||||||
|
|
||||||
|
boolean flag = false;
|
||||||
|
try {
|
||||||
|
if (deleteItem.getType() == FileTypeEnum.FILE) {
|
||||||
|
flag = fileService.deleteFile(deleteItem.getPath(), deleteItem.getName());
|
||||||
|
} else if (deleteItem.getType() == FileTypeEnum.FOLDER) {
|
||||||
|
flag = fileService.deleteFile(deleteItem.getPath(), deleteItem.getName());
|
||||||
|
}
|
||||||
|
if (flag) {
|
||||||
|
deleteSuccessCount++;
|
||||||
|
} else {
|
||||||
|
deleteFailCount++;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("删除文件/文件夹失败, 文件路径: {}, 文件名称: {}", deleteItem.getPath(), deleteItem.getName(), e);
|
||||||
|
deleteFailCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//如果是1 说明成功删除
|
||||||
|
if (deleteSuccessCount >= 1) {
|
||||||
|
//删除数据库
|
||||||
|
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("node_id",nodeId);
|
||||||
|
queryWrapper.eq("task_id",taskId);
|
||||||
|
int valueDelete = tsFilesMapper.delete(queryWrapper);
|
||||||
|
if (valueDelete > 0) {
|
||||||
|
value = true;
|
||||||
|
LOGGER.info("物理删除表结构成功");
|
||||||
|
} else {
|
||||||
|
value = false;
|
||||||
|
System.out.println("物理删除表结构");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,11 +65,6 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
|||||||
@Resource
|
@Resource
|
||||||
private ITsFilesService tsFilesService;
|
private ITsFilesService tsFilesService;
|
||||||
|
|
||||||
|
|
||||||
//数据源Mapper
|
|
||||||
@Resource
|
|
||||||
private StorageSourceMapper storageSourceMapper;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private StorageSourceContext storageSourceContext;
|
private StorageSourceContext storageSourceContext;
|
||||||
|
|
||||||
@ -445,4 +440,39 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 根据任务ID删除下面所有的节点以及节点下面所有的文件
|
||||||
|
* 参数说明 taskId 试验任务ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回删除成功或者失败
|
||||||
|
***********************************/
|
||||||
|
@Override
|
||||||
|
public boolean deleteTsNodesByTaskId(String taskId) {
|
||||||
|
Boolean value = false;
|
||||||
|
//根据任务ID 查询所有的集合 不管层级结构全部都删除
|
||||||
|
QueryWrapper<TsNodes> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("task_id",taskId);
|
||||||
|
List<TsNodes> tsNodesList = tsNodesMapper.selectList(queryWrapper);
|
||||||
|
if(tsNodesList == null && tsNodesList.isEmpty()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(TsNodes tsNodes : tsNodesList){
|
||||||
|
//删除文件表
|
||||||
|
Boolean deleteTsFiles = tsFilesService.deleteTsFilesByNodeId(tsNodes.getNodeId(),tsNodes.getTaskId());
|
||||||
|
//如果删除成功 接着删除节点表数据
|
||||||
|
if(deleteTsFiles){
|
||||||
|
// 删除当前节点
|
||||||
|
int deleteCount = tsNodesMapper.deleteById(tsNodes.getNodeId());
|
||||||
|
if (deleteCount == 1) {
|
||||||
|
LOGGER.info("tsnodes表结删除改成功");
|
||||||
|
value = true;
|
||||||
|
} else {
|
||||||
|
LOGGER.error("tsnodes表结构删除失败");
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,21 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.modules.experimentalData.domain.TsTask;
|
import com.yfd.platform.modules.experimentalData.domain.TsTask;
|
||||||
import com.yfd.platform.modules.experimentalData.mapper.TsTaskMapper;
|
import com.yfd.platform.modules.experimentalData.mapper.TsTaskMapper;
|
||||||
|
import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
|
||||||
|
import com.yfd.platform.modules.experimentalData.service.ITsNodesService;
|
||||||
import com.yfd.platform.modules.experimentalData.service.ITsTaskService;
|
import com.yfd.platform.modules.experimentalData.service.ITsTaskService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yfd.platform.utils.StringUtils;
|
import com.yfd.platform.utils.StringUtils;
|
||||||
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -26,10 +33,17 @@ import java.time.LocalDateTime;
|
|||||||
@Service
|
@Service
|
||||||
public class TsTaskServiceImpl extends ServiceImpl<TsTaskMapper, TsTask> implements ITsTaskService {
|
public class TsTaskServiceImpl extends ServiceImpl<TsTaskMapper, TsTask> implements ITsTaskService {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ChannelInboundHandlerAdapter.class);
|
||||||
|
|
||||||
|
|
||||||
//试验任务Mapper
|
//试验任务Mapper
|
||||||
@Resource
|
@Resource
|
||||||
private TsTaskMapper tsTaskMapper;
|
private TsTaskMapper tsTaskMapper;
|
||||||
|
|
||||||
|
//实验数据管理
|
||||||
|
@Resource
|
||||||
|
private ITsNodesService tsNodesService;
|
||||||
|
|
||||||
/**********************************
|
/**********************************
|
||||||
* 用途说明: 分页查询试验数据管理-试验任务管理
|
* 用途说明: 分页查询试验数据管理-试验任务管理
|
||||||
* 参数说明
|
* 参数说明
|
||||||
@ -121,4 +135,39 @@ public class TsTaskServiceImpl extends ServiceImpl<TsTaskMapper, TsTask> impleme
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 批量删除试验数据管理-试验任务管理
|
||||||
|
* 参数说明 ids 试验数据管理id数组
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回批量删除成功或失败
|
||||||
|
***********************************/
|
||||||
|
@Override
|
||||||
|
public boolean deleteTstaskByIds(List<String> dataset) {
|
||||||
|
Boolean value = false;
|
||||||
|
|
||||||
|
//循环所有的ID
|
||||||
|
for(String taskId : dataset){
|
||||||
|
//调用删除节点 根据任务ID
|
||||||
|
Boolean deleteTsnodes = tsNodesService.deleteTsNodesByTaskId(taskId);
|
||||||
|
//如果删除成功 接着删除节点表数据
|
||||||
|
if(deleteTsnodes){
|
||||||
|
LOGGER.info("tsNodes表结删除改成功");
|
||||||
|
value = true;
|
||||||
|
}else {
|
||||||
|
LOGGER.error("tsNodes表结构删除失败");
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int deleteCount = tsTaskMapper.deleteById(taskId);
|
||||||
|
if (deleteCount == 1) {
|
||||||
|
LOGGER.info("tstask表结删除改成功");
|
||||||
|
value = true;
|
||||||
|
} else {
|
||||||
|
LOGGER.error("tstask表结构删除失败");
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -114,7 +115,9 @@ public class ProjectController {
|
|||||||
if (StrUtil.isBlank(id)) {
|
if (StrUtil.isBlank(id)) {
|
||||||
return ResponseResult.error("参数为空");
|
return ResponseResult.error("参数为空");
|
||||||
}
|
}
|
||||||
boolean isOk = projectService.removeById(id);
|
List<String> dataset = new ArrayList<>();
|
||||||
|
dataset.add(id);
|
||||||
|
boolean isOk = projectService.deleteProjectByIds(dataset);
|
||||||
if (isOk) {
|
if (isOk) {
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
} else {
|
} else {
|
||||||
@ -139,7 +142,7 @@ public class ProjectController {
|
|||||||
String[] splitIds = ids.split(",");
|
String[] splitIds = ids.split(",");
|
||||||
// 数组转集合
|
// 数组转集合
|
||||||
List<String> dataset = Arrays.asList(splitIds);
|
List<String> dataset = Arrays.asList(splitIds);
|
||||||
boolean isOk = projectService.removeByIds(dataset);
|
boolean isOk = projectService.deleteProjectByIds(dataset);
|
||||||
if (isOk) {
|
if (isOk) {
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.yfd.platform.modules.specialDocument.domain.Project;
|
import com.yfd.platform.modules.specialDocument.domain.Project;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 专项项目表 服务类
|
* 专项项目表 服务类
|
||||||
@ -40,4 +42,6 @@ public interface IProjectService extends IService<Project> {
|
|||||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回修改成功或者失败
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回修改成功或者失败
|
||||||
***********************************/
|
***********************************/
|
||||||
boolean updateSdproject(Project project);
|
boolean updateSdproject(Project project);
|
||||||
|
|
||||||
|
boolean deleteProjectByIds(List<String> dataset);
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,18 @@ package com.yfd.platform.modules.specialDocument.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yfd.platform.modules.specialDocument.domain.Nodes;
|
||||||
import com.yfd.platform.modules.specialDocument.domain.Project;
|
import com.yfd.platform.modules.specialDocument.domain.Project;
|
||||||
import com.yfd.platform.modules.specialDocument.mapper.ProjectMapper;
|
import com.yfd.platform.modules.specialDocument.mapper.ProjectMapper;
|
||||||
|
import com.yfd.platform.modules.specialDocument.service.INodesService;
|
||||||
import com.yfd.platform.modules.specialDocument.service.IProjectService;
|
import com.yfd.platform.modules.specialDocument.service.IProjectService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yfd.platform.system.domain.SysDictionaryItems;
|
import com.yfd.platform.system.domain.SysDictionaryItems;
|
||||||
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
|
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
|
||||||
import com.yfd.platform.utils.StringUtils;
|
import com.yfd.platform.utils.StringUtils;
|
||||||
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -27,12 +32,18 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements IProjectService {
|
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements IProjectService {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ChannelInboundHandlerAdapter.class);
|
||||||
|
|
||||||
|
|
||||||
//专项项目表Mapper
|
//专项项目表Mapper
|
||||||
@Resource
|
@Resource
|
||||||
private ProjectMapper projectMapper;
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
|
|
||||||
|
//专项文档节点服务类
|
||||||
|
@Resource
|
||||||
|
private INodesService nodesService;
|
||||||
|
|
||||||
//字典表Mapper
|
//字典表Mapper
|
||||||
@Resource
|
@Resource
|
||||||
private SysDictionaryItemsMapper sysDictionaryItemsMapper;
|
private SysDictionaryItemsMapper sysDictionaryItemsMapper;
|
||||||
@ -150,4 +161,48 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 批量删除专项文档管理-项目管理
|
||||||
|
* 参数说明 ids 项目管理id数组
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回批量删除成功或失败
|
||||||
|
***********************************/
|
||||||
|
@Override
|
||||||
|
public boolean deleteProjectByIds(List<String> dataset) {
|
||||||
|
Boolean value = false;
|
||||||
|
|
||||||
|
//循环所有的ID
|
||||||
|
for (String id : dataset) {
|
||||||
|
QueryWrapper<Nodes> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("project_id", id);
|
||||||
|
queryWrapper.eq("parent_id", "00");
|
||||||
|
List<Nodes> nodesList = nodesService.list(queryWrapper);
|
||||||
|
//如果为空 跳过当前项目 接着下一个项目
|
||||||
|
if (nodesList == null || nodesList.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (Nodes nodes : nodesList) {
|
||||||
|
//调用删除节点 根据任务ID
|
||||||
|
Boolean deleteTsnodes = nodesService.deleteNodesById(nodes.getParentId());
|
||||||
|
//如果删除成功 接着删除节点表数据
|
||||||
|
if (deleteTsnodes) {
|
||||||
|
LOGGER.info("nodes表结删除改成功");
|
||||||
|
value = true;
|
||||||
|
} else {
|
||||||
|
LOGGER.error("nodes表结构删除失败");
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 删除当前项目
|
||||||
|
int deleteCount = projectMapper.deleteById(id);
|
||||||
|
if (deleteCount == 1) {
|
||||||
|
LOGGER.info("project表结删除改成功");
|
||||||
|
value = true;
|
||||||
|
} else {
|
||||||
|
LOGGER.error("project表结构删除失败");
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,7 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
|||||||
List<Map<String, Object>> listMap = new ArrayList<>();
|
List<Map<String, Object>> listMap = new ArrayList<>();
|
||||||
QueryWrapper<SysOrganization> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysOrganization> queryWrapper = new QueryWrapper<>();
|
||||||
//根据父级id查询
|
//根据父级id查询
|
||||||
queryWrapper.eq("parentid", parentid);
|
queryWrapper.eq("parentid", parentid); // 根据 部门名称
|
||||||
if (StrUtil.isNotEmpty(params)) {
|
|
||||||
queryWrapper.like("orgname", params); // 根据 部门名称
|
|
||||||
}
|
|
||||||
SysUser userInfo = userService.getUserInfo();
|
SysUser userInfo = userService.getUserInfo();
|
||||||
if (userInfo.getUsertype() != 0) {
|
if (userInfo.getUsertype() != 0) {
|
||||||
List<SysRole> roleByUserId =
|
List<SysRole> roleByUserId =
|
||||||
@ -86,7 +83,7 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
|||||||
ids.addAll(stringList);
|
ids.addAll(stringList);
|
||||||
ids.addAll(set);
|
ids.addAll(set);
|
||||||
}
|
}
|
||||||
if(ids.size()>0){
|
if (ids.size() > 0) {
|
||||||
queryWrapper.in("id", ids);
|
queryWrapper.in("id", ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +91,15 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
|||||||
listMap = this.listMaps(queryWrapper.orderByAsc("orgcode"));
|
listMap = this.listMaps(queryWrapper.orderByAsc("orgcode"));
|
||||||
for (int i = 0; i < listMap.size(); i++) {
|
for (int i = 0; i < listMap.size(); i++) {
|
||||||
List<Map<String, Object>> childList = child(listMap.get(i).get(
|
List<Map<String, Object>> childList = child(listMap.get(i).get(
|
||||||
"id").toString());//查询下一子集
|
"id").toString(), params);//查询下一子集
|
||||||
listMap.get(i).put("childList", childList); //添加新列 子集
|
listMap.get(i).put("childList", childList); //添加新列 子集
|
||||||
|
// 检查 childList 是否为空,如果为空则删除该条目
|
||||||
|
if (childList == null || childList.isEmpty()) {
|
||||||
|
listMap.remove(i);
|
||||||
|
i--; // 移除元素后,需要调整索引,避免跳过元素
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return listMap;
|
return listMap;
|
||||||
}
|
}
|
||||||
@ -107,15 +111,19 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
|||||||
* params (根据参数查询 组织名称 负责人 描述)
|
* params (根据参数查询 组织名称 负责人 描述)
|
||||||
* 返回值说明: 组织树集合
|
* 返回值说明: 组织树集合
|
||||||
***********************************/
|
***********************************/
|
||||||
private List<Map<String, Object>> child(String parentid) {
|
private List<Map<String, Object>> child(String parentid, String params) {
|
||||||
List<Map<String, Object>> listMap = new ArrayList<>();
|
List<Map<String, Object>> listMap = new ArrayList<>();
|
||||||
QueryWrapper<SysOrganization> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysOrganization> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("parentid", parentid); //根据上级id 查询
|
queryWrapper.eq("parentid", parentid); //根据上级id 查询
|
||||||
|
if (StrUtil.isNotEmpty(params)) {
|
||||||
|
queryWrapper.like("orgname", params); // 根据 部门名称
|
||||||
|
}
|
||||||
|
|
||||||
listMap = this.listMaps(queryWrapper.orderByAsc("orgcode"));
|
listMap = this.listMaps(queryWrapper.orderByAsc("orgcode"));
|
||||||
if (listMap.size() > 0) { //判断是否存在子集
|
if (listMap.size() > 0) { //判断是否存在子集
|
||||||
for (int i = 0; i < listMap.size(); i++) { //遍历表数据
|
for (int i = 0; i < listMap.size(); i++) { //遍历表数据
|
||||||
List<Map<String, Object>> childList =
|
List<Map<String, Object>> childList =
|
||||||
child(listMap.get(i).get("id").toString()); //循环获取下一子集
|
child(listMap.get(i).get("id").toString(), params); //循环获取下一子集
|
||||||
listMap.get(i).put("childList", childList); //添加新列 子集
|
listMap.get(i).put("childList", childList); //添加新列 子集
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user