|
@@ -1,8 +1,8 @@
|
|
-const express = require('express');
|
|
|
|
|
|
+const express = require("express");
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
-const { executeQuery } = require('../config/database');
|
|
|
|
|
|
+const { executeQuery } = require("../config/database");
|
|
|
|
|
|
-router.get('/', async (req, res) => {
|
|
|
|
|
|
+router.get("/", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { search, toolsName, status, page = 1, pageSize = 10 } = req.query;
|
|
const { search, toolsName, status, page = 1, pageSize = 10 } = req.query;
|
|
const offset = (page - 1) * pageSize;
|
|
const offset = (page - 1) * pageSize;
|
|
@@ -17,25 +17,25 @@ router.get('/', async (req, res) => {
|
|
|
|
|
|
// 添加工具名称搜索条件
|
|
// 添加工具名称搜索条件
|
|
if (toolsName) {
|
|
if (toolsName) {
|
|
- whereConditions.push('tools_name LIKE ?');
|
|
|
|
|
|
+ whereConditions.push("tools_name LIKE ?");
|
|
params.push(`%${toolsName}%`);
|
|
params.push(`%${toolsName}%`);
|
|
}
|
|
}
|
|
|
|
|
|
// 添加状态搜索条件
|
|
// 添加状态搜索条件
|
|
- if (status !== undefined && status !== '') {
|
|
|
|
- whereConditions.push('status = ?');
|
|
|
|
|
|
+ if (status !== undefined && status !== "") {
|
|
|
|
+ whereConditions.push("status = ?");
|
|
params.push(parseInt(status));
|
|
params.push(parseInt(status));
|
|
}
|
|
}
|
|
|
|
|
|
// 添加全文搜索条件
|
|
// 添加全文搜索条件
|
|
if (search) {
|
|
if (search) {
|
|
- whereConditions.push('(tools_name LIKE ? OR tools_function_name LIKE ? OR tools_function_desc LIKE ?)');
|
|
|
|
|
|
+ whereConditions.push("(tools_name LIKE ? OR tools_function_name LIKE ? OR tools_function_desc LIKE ?)");
|
|
params.push(`%${search}%`, `%${search}%`, `%${search}%`);
|
|
params.push(`%${search}%`, `%${search}%`, `%${search}%`);
|
|
}
|
|
}
|
|
|
|
|
|
// 构建WHERE子句
|
|
// 构建WHERE子句
|
|
if (whereConditions.length > 0) {
|
|
if (whereConditions.length > 0) {
|
|
- sql += ` WHERE ${whereConditions.join(' AND ')}`;
|
|
|
|
|
|
+ sql += ` WHERE ${whereConditions.join(" AND ")}`;
|
|
}
|
|
}
|
|
|
|
|
|
sql += ` ORDER BY create_time DESC LIMIT ? OFFSET ?`;
|
|
sql += ` ORDER BY create_time DESC LIMIT ? OFFSET ?`;
|
|
@@ -46,12 +46,12 @@ router.get('/', async (req, res) => {
|
|
let countParams = [];
|
|
let countParams = [];
|
|
|
|
|
|
if (whereConditions.length > 0) {
|
|
if (whereConditions.length > 0) {
|
|
- countSql += ` WHERE ${whereConditions.join(' AND ')}`;
|
|
|
|
|
|
+ countSql += ` WHERE ${whereConditions.join(" AND ")}`;
|
|
// 重新构建计数查询的参数
|
|
// 重新构建计数查询的参数
|
|
if (toolsName) {
|
|
if (toolsName) {
|
|
countParams.push(`%${toolsName}%`);
|
|
countParams.push(`%${toolsName}%`);
|
|
}
|
|
}
|
|
- if (status !== undefined && status !== '') {
|
|
|
|
|
|
+ if (status !== undefined && status !== "") {
|
|
countParams.push(parseInt(status));
|
|
countParams.push(parseInt(status));
|
|
}
|
|
}
|
|
if (search) {
|
|
if (search) {
|
|
@@ -59,50 +59,41 @@ router.get('/', async (req, res) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- const [data, countResult] = await Promise.all([
|
|
|
|
- executeQuery(sql, params),
|
|
|
|
- executeQuery(countSql, countParams)
|
|
|
|
- ]);
|
|
|
|
|
|
+ const [data, countResult] = await Promise.all([executeQuery(sql, params), executeQuery(countSql, countParams)]);
|
|
|
|
|
|
res.json({
|
|
res.json({
|
|
data,
|
|
data,
|
|
total: countResult[0].total,
|
|
total: countResult[0].total,
|
|
page: parseInt(page),
|
|
page: parseInt(page),
|
|
- pageSize: parseInt(pageSize)
|
|
|
|
|
|
+ pageSize: parseInt(pageSize),
|
|
});
|
|
});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error fetching pending tools:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error fetching pending tools:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
// 新增待接入工具
|
|
// 新增待接入工具
|
|
-router.post('/', async (req, res) => {
|
|
|
|
|
|
+router.post("/", async (req, res) => {
|
|
try {
|
|
try {
|
|
- const {
|
|
|
|
- search_task_id,
|
|
|
|
- tools_name,
|
|
|
|
- tools_function_name,
|
|
|
|
- tools_function_desc,
|
|
|
|
- status = 0
|
|
|
|
- } = req.body;
|
|
|
|
|
|
+ const { search_task_id, tools_name, tools_function_name, tools_function_desc } = req.body;
|
|
|
|
|
|
// 验证必填字段
|
|
// 验证必填字段
|
|
if (!search_task_id || !tools_name || !tools_function_name || !tools_function_desc) {
|
|
if (!search_task_id || !tools_name || !tools_function_name || !tools_function_desc) {
|
|
return res.status(400).json({
|
|
return res.status(400).json({
|
|
success: false,
|
|
success: false,
|
|
- message: '缺少必填字段'
|
|
|
|
|
|
+ message: "缺少必填字段",
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
// 检查search_task_id是否已存在
|
|
// 检查search_task_id是否已存在
|
|
- const checkSql = 'SELECT search_task_id FROM tools_info_search_task WHERE search_task_id = ?';
|
|
|
|
|
|
+ const checkSql = "SELECT search_task_id FROM tools_info_search_task WHERE search_task_id = ?";
|
|
const existingTool = await executeQuery(checkSql, [search_task_id]);
|
|
const existingTool = await executeQuery(checkSql, [search_task_id]);
|
|
-
|
|
|
|
|
|
+
|
|
if (existingTool.length > 0) {
|
|
if (existingTool.length > 0) {
|
|
return res.status(400).json({
|
|
return res.status(400).json({
|
|
success: false,
|
|
success: false,
|
|
- message: '工具ID已存在'
|
|
|
|
|
|
+ message: "工具ID已存在",
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -112,36 +103,34 @@ router.post('/', async (req, res) => {
|
|
(search_task_id, tools_name, tools_function_name, tools_function_desc, status, create_time, update_time)
|
|
(search_task_id, tools_name, tools_function_name, tools_function_desc, status, create_time, update_time)
|
|
VALUES (?, ?, ?, ?, ?, NOW(), NOW())
|
|
VALUES (?, ?, ?, ?, ?, NOW(), NOW())
|
|
`;
|
|
`;
|
|
-
|
|
|
|
|
|
+
|
|
const result = await executeQuery(insertSql, [
|
|
const result = await executeQuery(insertSql, [
|
|
search_task_id,
|
|
search_task_id,
|
|
tools_name,
|
|
tools_name,
|
|
tools_function_name,
|
|
tools_function_name,
|
|
tools_function_desc,
|
|
tools_function_desc,
|
|
- status
|
|
|
|
]);
|
|
]);
|
|
|
|
|
|
res.json({
|
|
res.json({
|
|
success: true,
|
|
success: true,
|
|
- message: '新增工具成功',
|
|
|
|
|
|
+ message: "新增工具成功",
|
|
data: {
|
|
data: {
|
|
search_task_id,
|
|
search_task_id,
|
|
tools_name,
|
|
tools_name,
|
|
tools_function_name,
|
|
tools_function_name,
|
|
tools_function_desc,
|
|
tools_function_desc,
|
|
- status
|
|
|
|
- }
|
|
|
|
|
|
+ },
|
|
});
|
|
});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('新增工具失败:', error);
|
|
|
|
|
|
+ console.error("新增工具失败:", error);
|
|
res.status(500).json({
|
|
res.status(500).json({
|
|
success: false,
|
|
success: false,
|
|
- message: '服务器内部错误'
|
|
|
|
|
|
+ message: "服务器内部错误",
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.get('/:id', async (req, res) => {
|
|
|
|
|
|
+router.get("/:id", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
|
|
|
|
@@ -153,32 +142,29 @@ router.get('/:id', async (req, res) => {
|
|
`;
|
|
`;
|
|
|
|
|
|
const detailSql = `
|
|
const detailSql = `
|
|
- SELECT search_task_id, search_channel, search_result, fail_reason,
|
|
|
|
- create_time, update_time
|
|
|
|
|
|
+ SELECT id, search_task_id, search_channel, query, status,
|
|
|
|
+ search_result, fail_reason, create_time, update_time
|
|
FROM tools_info_search_task_detail
|
|
FROM tools_info_search_task_detail
|
|
WHERE search_task_id = ?
|
|
WHERE search_task_id = ?
|
|
`;
|
|
`;
|
|
|
|
|
|
- const [taskData, detailData] = await Promise.all([
|
|
|
|
- executeQuery(taskSql, [id]),
|
|
|
|
- executeQuery(detailSql, [id])
|
|
|
|
- ]);
|
|
|
|
|
|
+ const [taskData, detailData] = await Promise.all([executeQuery(taskSql, [id]), executeQuery(detailSql, [id])]);
|
|
|
|
|
|
if (taskData.length === 0) {
|
|
if (taskData.length === 0) {
|
|
- return res.status(404).json({ error: 'Tool not found' });
|
|
|
|
|
|
+ return res.status(404).json({ error: "Tool not found" });
|
|
}
|
|
}
|
|
|
|
|
|
res.json({
|
|
res.json({
|
|
task: taskData[0],
|
|
task: taskData[0],
|
|
- detail: detailData[0] || null
|
|
|
|
|
|
+ detail: detailData.length > 0 ? detailData : null,
|
|
});
|
|
});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error fetching pending tool detail:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error fetching pending tool detail:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.put('/:id', async (req, res) => {
|
|
|
|
|
|
+router.put("/:id", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
const { tools_name, tools_function_name, tools_function_desc, status, fail_reason } = req.body;
|
|
const { tools_name, tools_function_name, tools_function_desc, status, fail_reason } = req.body;
|
|
@@ -190,27 +176,93 @@ router.put('/:id', async (req, res) => {
|
|
WHERE search_task_id = ?
|
|
WHERE search_task_id = ?
|
|
`;
|
|
`;
|
|
|
|
|
|
- await executeQuery(sql, [tools_name, tools_function_name, tools_function_desc, status, fail_reason, id]);
|
|
|
|
|
|
+ await executeQuery(sql, [
|
|
|
|
+ tools_name ?? null,
|
|
|
|
+ tools_function_name ?? null,
|
|
|
|
+ tools_function_desc ?? null,
|
|
|
|
+ status ?? null,
|
|
|
|
+ fail_reason ?? null,
|
|
|
|
+ id,
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ res.json({ message: "Tool updated successfully" });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("Error updating pending tool:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+// 创建详情信息
|
|
|
|
+router.post("/detail", async (req, res) => {
|
|
|
|
+ try {
|
|
|
|
+ const { search_task_id, search_channel, query, status, search_result, fail_reason } = req.body;
|
|
|
|
+
|
|
|
|
+ const sql = `
|
|
|
|
+ INSERT INTO tools_info_search_task_detail
|
|
|
|
+ (search_task_id, search_channel, query, status, search_result, fail_reason, create_time, update_time)
|
|
|
|
+ VALUES (?, ?, ?, ?, ?, ?, NOW(), NOW())
|
|
|
|
+ `;
|
|
|
|
+
|
|
|
|
+ const result = await executeQuery(sql, [
|
|
|
|
+ search_task_id,
|
|
|
|
+ search_channel ?? null,
|
|
|
|
+ query ?? null,
|
|
|
|
+ status ?? 1,
|
|
|
|
+ search_result ?? null,
|
|
|
|
+ fail_reason ?? null,
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ res.json({
|
|
|
|
+ message: "Detail created successfully",
|
|
|
|
+ id: result.insertId,
|
|
|
|
+ });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("Error creating detail:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+// 更新详情信息
|
|
|
|
+router.put("/detail/:detailId", async (req, res) => {
|
|
|
|
+ try {
|
|
|
|
+ const { detailId } = req.params;
|
|
|
|
+ const { search_channel, query, status, search_result, fail_reason } = req.body;
|
|
|
|
+
|
|
|
|
+ const sql = `
|
|
|
|
+ UPDATE tools_info_search_task_detail
|
|
|
|
+ SET search_channel = ?, query = ?, status = ?,
|
|
|
|
+ search_result = ?, fail_reason = ?, update_time = NOW()
|
|
|
|
+ WHERE id = ?
|
|
|
|
+ `;
|
|
|
|
+
|
|
|
|
+ await executeQuery(sql, [
|
|
|
|
+ search_channel ?? null,
|
|
|
|
+ query ?? null,
|
|
|
|
+ status ?? null,
|
|
|
|
+ search_result ?? null,
|
|
|
|
+ fail_reason ?? null,
|
|
|
|
+ detailId,
|
|
|
|
+ ]);
|
|
|
|
|
|
- res.json({ message: 'Tool updated successfully' });
|
|
|
|
|
|
+ res.json({ message: "Detail updated successfully" });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error updating pending tool:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error updating detail:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.delete('/:id', async (req, res) => {
|
|
|
|
|
|
+router.delete("/:id", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
|
|
|
|
- await executeQuery('DELETE FROM tools_info_search_task_detail WHERE search_task_id = ?', [id]);
|
|
|
|
- await executeQuery('DELETE FROM tools_info_search_task WHERE search_task_id = ?', [id]);
|
|
|
|
|
|
+ await executeQuery("DELETE FROM tools_info_search_task_detail WHERE search_task_id = ?", [id]);
|
|
|
|
+ await executeQuery("DELETE FROM tools_info_search_task WHERE search_task_id = ?", [id]);
|
|
|
|
|
|
- res.json({ message: 'Tool deleted successfully' });
|
|
|
|
|
|
+ res.json({ message: "Tool deleted successfully" });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error deleting pending tool:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error deleting pending tool:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-module.exports = router;
|
|
|
|
|
|
+module.exports = router;
|