123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- const express = require('express');
- const router = express.Router();
- const { executeQuery } = require('../config/database');
- router.get('/', async (req, res) => {
- try {
- const { page = 1, pageSize = 10 } = req.query;
- const offset = (page - 1) * pageSize;
- const sql = `
- SELECT access_task_id, search_task_id, tools_name, tools_function_name,
- access_type, tools_function_desc, api_doc, api_class_name,
- operate_path_data, origin_content_link, status, fail_reason,
- create_time, update_time
- FROM tools_auto_access_task
- ORDER BY create_time DESC
- LIMIT ? OFFSET ?
- `;
- const countSql = `SELECT COUNT(*) as total FROM tools_auto_access_task`;
- const [data, countResult] = await Promise.all([
- executeQuery(sql, [parseInt(pageSize), offset]),
- executeQuery(countSql)
- ]);
- res.json({
- data,
- total: countResult[0].total,
- page: parseInt(page),
- pageSize: parseInt(pageSize)
- });
- } catch (error) {
- console.error('Error fetching auto access tasks:', error);
- res.status(500).json({ error: 'Internal server error' });
- }
- });
- router.get('/:id', async (req, res) => {
- try {
- const { id } = req.params;
- const sql = `
- SELECT access_task_id, search_task_id, tools_name, tools_function_name,
- access_type, tools_function_desc, api_doc, api_class_name,
- operate_path_data, origin_content_link, status, fail_reason,
- create_time, update_time
- FROM tools_auto_access_task
- WHERE access_task_id = ?
- `;
- const data = await executeQuery(sql, [id]);
- if (data.length === 0) {
- return res.status(404).json({ error: 'Task not found' });
- }
- res.json(data[0]);
- } catch (error) {
- console.error('Error fetching auto access task detail:', error);
- res.status(500).json({ error: 'Internal server error' });
- }
- });
- router.put('/:id', async (req, res) => {
- try {
- const { id } = req.params;
- const {
- search_task_id, tools_name, tools_function_name, access_type,
- tools_function_desc, api_doc, api_class_name, operate_path_data,
- origin_content_link, status, fail_reason
- } = req.body;
- const sql = `
- UPDATE tools_auto_access_task
- SET search_task_id = ?, tools_name = ?, tools_function_name = ?,
- access_type = ?, tools_function_desc = ?, api_doc = ?,
- api_class_name = ?, operate_path_data = ?, origin_content_link = ?,
- status = ?, fail_reason = ?, update_time = NOW()
- WHERE access_task_id = ?
- `;
- await executeQuery(sql, [
- search_task_id, tools_name, tools_function_name, access_type,
- tools_function_desc, api_doc, api_class_name, operate_path_data,
- origin_content_link, status, fail_reason, id
- ]);
- res.json({ message: 'Task updated successfully' });
- } catch (error) {
- console.error('Error updating auto access task:', error);
- res.status(500).json({ error: 'Internal server error' });
- }
- });
- module.exports = router;
|