查询根据节点名称条件搜索

This commit is contained in:
lilin 2026-01-07 16:53:50 +08:00
parent 6da5da86af
commit f1bd6e05c1
3 changed files with 97 additions and 14 deletions

View File

@ -1,30 +1,43 @@
package com.yfd.platform.modules.experimentalData.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.experimentalData.domain.TsNodes;
import com.yfd.platform.modules.experimentalData.domain.TsTask;
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.utils.StringUtils;
import com.yfd.platform.utils.TableNameContextHolder;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -48,6 +61,17 @@ public class TsTaskController {
@Resource
private ITsTaskService tsTaskService;
//试验任务节点服务类
@Resource
private ITsNodesService tsNodesService;
//实验任务文档表
@Resource
private ITsFilesService tsFilesService;
@Autowired
private DataSource dataSource;
/**********************************
* 用途说明: 分页查询试验数据管理-试验任务管理
* 参数说明
@ -93,8 +117,57 @@ public class TsTaskController {
//分页查询
Page<TsTask> sdProjectPage = tsTaskService.getTsTaskPage(keyword, startDate, endDate, fieldNameData, page, attributeContent);
// 循环处理每条数据
if (sdProjectPage != null && CollectionUtil.isNotEmpty(sdProjectPage.getRecords())) {
for (TsTask task : sdProjectPage.getRecords()) {
//根据任务ID 查询是否存在节点 如果存在不能修改1 如果不存在可以修改0
LambdaQueryWrapper<TsNodes> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TsNodes::getTaskId,task.getId());
int count = tsNodesService.count(queryWrapper);
//如果存在不能修改1
if (count>0){
task.setModifiableStatus("1");
}else {
task.setModifiableStatus("0");
}
//
if (tableExists("ts_files_" + task.getTaskCode())) {
TableNameContextHolder.setTaskCode(task.getTaskCode());
LambdaQueryWrapper<TsFiles> queryWrapperTsFiles = new LambdaQueryWrapper<>();
queryWrapperTsFiles.eq(TsFiles::getTaskId,task.getId());
int countTsFiles = tsFilesService.count(queryWrapperTsFiles);
//如果存在不能修改1
if (countTsFiles>0){
task.setModifiableStatus("1");
}else {
task.setModifiableStatus("0");
}
}
}
}
return ResponseResult.successData(sdProjectPage);
}
private boolean tableExists(String tableName) {
try (Connection conn = dataSource.getConnection()) {
DatabaseMetaData meta = conn.getMetaData();
// 获取当前数据库信息
String catalog = conn.getCatalog();
String schema = conn.getSchema();
// 查询表是否存在
try (ResultSet rs = meta.getTables(catalog, schema, tableName, new String[]{"TABLE"})) {
return rs.next();
}
} catch (SQLException e) {
LOGGER.error("检查表存在失败: {}", tableName, e);
return false;
}
}
/***********************************
* 用途说明新增试验数据管理-试验任务管理

View File

@ -155,5 +155,11 @@ public class TsTask implements Serializable {
@TableField(exist = false)
private String key;
/**
* 是否可修改TODO 增加用于前端展示
*/
@TableField(exist = false)
private String modifiableStatus;
}

View File

@ -205,24 +205,28 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
// 向上查找直到根节点
while (currentNode != null) {
path.add(0, new HashMap<>(currentNode)); // 添加到路径开头
String parentId = (String) currentNode.get("parentId");
String taskId = (String) currentNode.get("taskId");
TsTask task = tsTaskMapper.selectOne(new QueryWrapper<TsTask>().eq("id", taskId));
currentNode.put("taskName",task.getTaskName());
path.add(0, new HashMap<>(currentNode)); // 添加到路径开头
if ("00".equals(parentId)) {
// 找到根节点添加任务信息
String taskId = (String) currentNode.get("taskId");
TsTask task = tsTaskMapper.selectOne(new QueryWrapper<TsTask>().eq("id", taskId));
if (task != null) {
Map<String, Object> taskNode = new HashMap<>();
taskNode.put("nodeName", "根节点");
taskNode.put("path", "/" + task.getTaskName() + "/");
taskNode.put("nodeId", task.getId());
taskNode.put("nodeOrder", "0");
taskNode.put("taskId", task.getId());
taskNode.put("taskName", task.getTaskName());
taskNode.put("parentId", "00");
path.add(0, taskNode);
}
// String taskId = (String) currentNode.get("taskId");
// TsTask task = tsTaskMapper.selectOne(new QueryWrapper<TsTask>().eq("id", taskId));
// currentNode.put("taskName",task.getTaskName());
// if (task != null) {
// Map<String, Object> taskNode = new HashMap<>();
// taskNode.put("nodeName", "根节点");
// taskNode.put("path", "/" + task.getTaskName() + "/");
// taskNode.put("nodeId", task.getId());
// taskNode.put("nodeOrder", "0");
// taskNode.put("taskId", task.getId());
// taskNode.put("taskName", task.getTaskName());
// taskNode.put("parentId", "00");
// path.add(0, taskNode);
// }
break;
}