-- 外观专利检测模块复用通用任务表: -- biz_file_task 保存任务主记录,module_type = APPEARANCE_PATENT -- biz_file_result 保存最终 xlsx 结果文件和历史记录 -- biz_task_scope_state 保存解析载荷 OSS 指针、scope 状态和心跳辅助状态 -- biz_task_chunk 保存 Python 回传分片和 Java/Coze 处理后的分片结果 -- 兼容老库:如果通用任务表缺少 user_id,则补齐用户归属字段。 SET @biz_file_task_user_id_exists := ( SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'biz_file_task' AND COLUMN_NAME = 'user_id' ); SET @sql_add_biz_file_task_user_id := IF( @biz_file_task_user_id_exists = 0, 'ALTER TABLE biz_file_task ADD COLUMN user_id BIGINT NULL COMMENT ''用户ID'' AFTER created_by', 'SELECT 1' ); PREPARE stmt_add_biz_file_task_user_id FROM @sql_add_biz_file_task_user_id; EXECUTE stmt_add_biz_file_task_user_id; DEALLOCATE PREPARE stmt_add_biz_file_task_user_id; SET @biz_file_result_user_id_exists := ( SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'biz_file_result' AND COLUMN_NAME = 'user_id' ); SET @sql_add_biz_file_result_user_id := IF( @biz_file_result_user_id_exists = 0, 'ALTER TABLE biz_file_result ADD COLUMN user_id BIGINT NULL COMMENT ''用户ID'' AFTER error_message', 'SELECT 1' ); PREPARE stmt_add_biz_file_result_user_id FROM @sql_add_biz_file_result_user_id; EXECUTE stmt_add_biz_file_result_user_id; DEALLOCATE PREPARE stmt_add_biz_file_result_user_id; -- 外观专利检测常用查询索引:按用户查任务、按用户查历史。 SET @idx_file_task_module_user_created_exists := ( SELECT COUNT(1) FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'biz_file_task' AND INDEX_NAME = 'idx_biz_file_task_module_user_created' ); SET @sql_add_idx_file_task_module_user_created := IF( @idx_file_task_module_user_created_exists = 0, 'ALTER TABLE biz_file_task ADD INDEX idx_biz_file_task_module_user_created (module_type, user_id, created_at)', 'SELECT 1' ); PREPARE stmt_add_idx_file_task_module_user_created FROM @sql_add_idx_file_task_module_user_created; EXECUTE stmt_add_idx_file_task_module_user_created; DEALLOCATE PREPARE stmt_add_idx_file_task_module_user_created; SET @idx_file_result_module_user_created_exists := ( SELECT COUNT(1) FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'biz_file_result' AND INDEX_NAME = 'idx_biz_file_result_module_user_created' ); SET @sql_add_idx_file_result_module_user_created := IF( @idx_file_result_module_user_created_exists = 0, 'ALTER TABLE biz_file_result ADD INDEX idx_biz_file_result_module_user_created (module_type, user_id, created_at)', 'SELECT 1' ); PREPARE stmt_add_idx_file_result_module_user_created FROM @sql_add_idx_file_result_module_user_created; EXECUTE stmt_add_idx_file_result_module_user_created; DEALLOCATE PREPARE stmt_add_idx_file_result_module_user_created; -- 前端栏目权限兜底:外观专利检测属于前端工具下的页面。 INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`) SELECT '外观专利检测', 'appearance_patent', 'app', 'appearance-patent', 111 WHERE NOT EXISTS ( SELECT 1 FROM `columns` WHERE `column_key` = 'appearance_patent' ); UPDATE `columns` SET `name` = '外观专利检测', `menu_type` = 'app', `route_path` = 'appearance-patent', `sort_order` = 111 WHERE `column_key` = 'appearance_patent';