feat: 添加 API Keys 批量管理功能的完整规范文档

- 需求文档:批量标签管理、账号分配、状态管理等6个核心需求
- 设计文档:完整的系统架构、组件设计和数据模型
- 任务计划:20个原子化实现任务,支持增量开发

功能包括:
- 批量标签添加/删除和冲突解决
- 批量账号分配(Claude/Gemini/OpenAI/Bedrock)
- 批量启用/禁用API Keys
- 增强的跨搜索持久多选界面
- 实时进度跟踪和操作审计

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
iRubbish
2025-08-20 14:49:20 +08:00
parent 1ee71ffbc9
commit eb92213b17
6 changed files with 587 additions and 0 deletions

View File

@@ -0,0 +1,191 @@
# Implementation Plan
## Task Overview
This implementation plan breaks down the API Keys Batch Management feature into atomic, focused tasks that build incrementally. Each task is designed to be completed in 15-30 minutes by an experienced developer and focuses on a single, testable outcome. The implementation follows test-driven development principles where appropriate and leverages existing codebase patterns.
The tasks are organized to first establish the backend infrastructure, then build the frontend interfaces, and finally integrate all components with comprehensive testing.
## Tasks
- [ ] 1. Create batch operation data models and validation utilities
- File: src/types/batchOperation.js
- Define data structures for BatchOperation, BatchTagUpdate, BatchAccountAssignment, and AuditEntry
- Implement validation functions for batch operation data integrity
- Add error types specific to batch operations
- Purpose: Establish type safety and validation foundation for batch operations
- _Leverage: src/services/apiKeyService.js (existing validation patterns)_
- _Requirements: 1.1, 2.1, 3.1_
- [ ] 2. Implement AuditService for batch operation logging
- File: src/services/auditService.js
- Create audit service with methods for logging batch operations and creating audit entries
- Implement export functionality for audit data in CSV/JSON formats
- Add filtering capabilities for audit data retrieval
- Purpose: Provide comprehensive audit trail for all batch operations
- _Leverage: src/utils/logger.js, src/models/redis.js_
- _Requirements: 6.1, 6.2, 6.3, 6.4_
- [ ] 3. Create BatchTagService for tag management operations
- File: src/services/batchTagService.js
- Implement methods for adding/removing tags from multiple API keys
- Add conflict resolution logic for tag operations
- Include validation for tag formats and constraints
- Purpose: Handle all tag-related batch operations with conflict resolution
- _Leverage: src/services/apiKeyService.js (existing tag parsing logic)_
- _Requirements: 1.1, 1.2, 1.3, 1.4_
- [ ] 4. Create BatchAccountService for account assignment operations
- File: src/services/batchAccountService.js
- Implement batch account assignment with validation for Claude, Gemini, OpenAI, and Bedrock accounts
- Add conflict detection and resolution for account assignments
- Include methods for validating account availability and permissions
- Purpose: Manage batch account assignments with proper validation and conflict handling
- _Leverage: src/services/apiKeyService.js (existing account validation)_
- _Requirements: 2.1, 2.2, 2.3, 2.4_
- [ ] 5. Implement BatchOperationService as main orchestrator
- File: src/services/batchOperationService.js
- Create main service that orchestrates all batch operations with transaction management
- Implement progress tracking and real-time status updates
- Add Redis-based locking mechanism to prevent concurrent operations
- Include rollback functionality for failed operations
- Purpose: Provide centralized batch operation management with atomicity and progress tracking
- _Leverage: src/services/batchTagService.js, src/services/batchAccountService.js, src/services/auditService.js_
- _Requirements: 5.1, 5.2, 5.3, 5.4_
- [ ] 6. Add batch operation API endpoints to admin routes
- File: src/routes/admin.js (modify existing)
- Add POST /admin/api-keys/batch/tags endpoint for tag operations
- Add POST /admin/api-keys/batch/accounts endpoint for account assignments
- Add POST /admin/api-keys/batch/status endpoint for status changes
- Add GET /admin/api-keys/batch/progress/:operationId endpoint for progress tracking
- Purpose: Expose batch operation functionality through secure admin API endpoints
- _Leverage: existing admin routes structure and authenticateAdmin middleware_
- _Requirements: 1.1, 2.1, 3.1, 5.1_
- [ ] 7. Create unit tests for batch services
- File: tests/services/batchOperationService.test.js
- Write comprehensive tests for BatchOperationService, BatchTagService, BatchAccountService
- Test error handling, rollback mechanisms, and progress tracking
- Include tests for concurrent operation prevention
- Purpose: Ensure reliability of all batch operation services
- _Leverage: existing test utilities and mocking patterns_
- _Requirements: All backend requirements_
- [ ] 8. Create BatchOperationPanel Vue component
- File: web/admin-spa/src/components/batch/BatchOperationPanel.vue
- Create main batch operation interface with operation type selection
- Implement progress display and operation status feedback
- Add operation cancellation functionality
- Purpose: Provide centralized UI for initiating and monitoring batch operations
- _Leverage: web/admin-spa/src/views/ApiKeysView.vue (existing UI patterns)_
- _Requirements: 4.1, 5.1, 5.2_
- [ ] 9. Create TagManagementModal Vue component
- File: web/admin-spa/src/components/batch/TagManagementModal.vue
- Implement tag selection interface with add/remove capabilities
- Add tag conflict resolution UI and validation feedback
- Include preview of changes before applying
- Purpose: Provide specialized interface for batch tag management
- _Leverage: existing modal components and form validation patterns_
- _Requirements: 1.1, 1.2, 1.3_
- [ ] 10. Create AccountAssignmentModal Vue component
- File: web/admin-spa/src/components/batch/AccountAssignmentModal.vue
- Implement account selection dropdowns for all supported platforms
- Add conflict detection UI and resolution options
- Include validation for account availability and permissions
- Purpose: Provide interface for batch account assignment operations
- _Leverage: existing dropdown components and account validation_
- _Requirements: 2.1, 2.2, 2.3_
- [ ] 11. Create BatchProgressTracker Vue component
- File: web/admin-spa/src/components/batch/BatchProgressTracker.vue
- Implement real-time progress display with percentage and status
- Add error reporting and detailed failure information
- Include operation summary and results display
- Purpose: Provide real-time feedback during batch operations
- _Leverage: existing progress bar components and notification systems_
- _Requirements: 5.2, 5.3, 5.4_
- [ ] 12. Enhance ApiKeysView with batch operation integration
- File: web/admin-spa/src/views/ApiKeysView.vue (modify existing)
- Integrate BatchOperationPanel component into existing view
- Add batch operation buttons for tags, accounts, and status
- Enhance selection UI with operation-specific feedback
- Purpose: Integrate batch operations into main API keys management interface
- _Leverage: existing multi-select functionality and component patterns_
- _Requirements: 4.1, 4.2, 4.3_
- [ ] 13. Add batch operation API methods to frontend API client
- File: web/admin-spa/src/config/api.js (modify existing)
- Add methods for batch tag operations, account assignments, and status changes
- Implement progress tracking API calls with polling mechanism
- Add error handling specific to batch operations
- Purpose: Provide frontend API interface for all batch operations
- _Leverage: existing API client structure and error handling_
- _Requirements: 1.1, 2.1, 3.1, 5.1_
- [ ] 14. Create batch operation stores for state management
- File: web/admin-spa/src/stores/batchOperations.js
- Implement Pinia store for managing batch operation state
- Add reactive state for operation progress, results, and errors
- Include computed properties for operation status and completion
- Purpose: Centralize batch operation state management across components
- _Leverage: existing Pinia store patterns from other stores_
- _Requirements: 4.4, 5.2, 5.3_
- [ ] 15. Write frontend component unit tests
- File: web/admin-spa/tests/components/batch/BatchOperationPanel.test.js
- Test all batch operation Vue components with various scenarios
- Include tests for user interactions, error states, and progress updates
- Test component integration with stores and API client
- Purpose: Ensure frontend component reliability and user experience
- _Leverage: existing Vue component testing patterns_
- _Requirements: All frontend requirements_
- [ ] 16. Create integration tests for batch operation workflows
- File: tests/integration/batchOperations.test.js
- Test complete batch operation workflows from API to database
- Include tests for concurrent operations, error scenarios, and rollback
- Test audit logging and progress tracking integration
- Purpose: Verify end-to-end functionality of batch operations
- _Leverage: existing integration test infrastructure_
- _Requirements: All requirements_
- [ ] 17. Implement batch operation performance optimization
- File: src/utils/batchOptimization.js
- Add Redis pipeline optimization for bulk operations
- Implement batch size limits and chunking for large operations
- Add memory usage monitoring and optimization
- Purpose: Ensure efficient performance for large-scale batch operations
- _Leverage: existing Redis patterns and performance utilities_
- _Requirements: Performance requirements_
- [ ] 18. Add comprehensive error handling and recovery
- File: src/middleware/batchErrorHandler.js
- Create specialized error handling middleware for batch operations
- Implement automatic retry logic for transient failures
- Add detailed error reporting with user-friendly messages
- Purpose: Provide robust error handling and recovery for batch operations
- _Leverage: existing error handling middleware patterns_
- _Requirements: 5.4, 5.5_
- [ ] 19. Create batch operation documentation and examples
- File: docs/batch-operations.md
- Document API endpoints, request/response formats, and usage examples
- Include troubleshooting guide and common error scenarios
- Add operational procedures for monitoring and maintenance
- Purpose: Provide comprehensive documentation for batch operation features
- _Leverage: existing documentation structure and patterns_
- _Requirements: All requirements_
- [ ] 20. Perform end-to-end testing and user acceptance validation
- File: tests/e2e/batchOperations.spec.js
- Create comprehensive end-to-end tests covering all user workflows
- Test with various data sizes and operation combinations
- Validate user experience and error scenarios
- Purpose: Ensure complete feature functionality and user satisfaction
- _Leverage: existing E2E testing framework and utilities_
- _Requirements: All requirements_