Implementation Plan: Work Statistics System
Overview
本实现计划将工作统计系统分解为可执行的编码任务,按照后端基础设施 → 数据模型 → API接口 → 前端界面的顺序逐步实现。使用Python Flask作为后端,React + Ant Design作为前端,SQLite用于测试。
Tasks
[x] 3. Implement Item module
- 3.1 Create Item model
- Define Item SQLAlchemy model with id, name, unit_price (float), created_at, updated_at
- Requirements: 2.1, 2.2
- 3.2 Implement Item service
- Create ItemService with create, get_all, get_by_id, update, delete methods
- Add validation (reject empty name, non-positive price)
- Requirements: 2.1, 2.2, 2.3, 2.4, 2.5
- 3.3 Create Item API routes
- GET /api/items - list all
- GET /api/items/ - get by id
- POST /api/items/create - create
- POST /api/items/update - update
- POST /api/items/delete - delete
- Add Swagger documentation
- Requirements: 2.1, 2.2, 2.3, 2.4, 8.1, 8.2
- [ ]* 3.4 Write property tests for Item CRUD
- Property 3: Item CRUD Round-Trip
- Property 4: Item Validation
- Validates: Requirements 2.1, 2.2, 2.3, 2.4, 2.5
[x] 4. Checkpoint - Backend Person and Item modules
- Ensure all tests pass, ask the user if questions arise.
[x] 5. Implement WorkRecord module
- 5.1 Create WorkRecord model
- Define WorkRecord SQLAlchemy model with id, person_id, item_id, work_date, quantity, created_at, updated_at
- Add total_price computed property
- Set up foreign key relationships
- Requirements: 3.1, 3.2
- 5.2 Implement WorkRecord service
- Create WorkRecordService with create, get_all, get_by_id, update, delete methods
- Add filtering by person_id and date_range
- Add validation (positive quantity, valid references)
- Requirements: 3.1, 3.2, 3.3, 3.4, 3.5, 3.6
- 5.3 Create WorkRecord API routes
- GET /api/work-records - list with filters
- GET /api/work-records/ - get by id
- POST /api/work-records/create - create
- POST /api/work-records/update - update
- POST /api/work-records/delete - delete
- GET /api/work-records/daily-summary - daily summary
- Add Swagger documentation
- Requirements: 3.1, 3.2, 3.3, 3.4, 4.1, 4.2, 8.1, 8.2
- [ ]* 5.4 Write property tests for WorkRecord
- Property 5: Work Record Total Price Calculation
- Property 6: Work Record Filter Consistency
- Property 7: Work Record Quantity Validation
- Property 8: Work Record Reference Validation
- Property 9: Daily Summary Consistency
- Validates: Requirements 3.1, 3.2, 3.3, 3.5, 3.6, 4.1, 4.2
[x] 6. Implement Excel Export module
- 6.1 Implement Export service
- Create ExportService with export_monthly and export_yearly methods
- Generate Excel with detail sheet (Person, Date, Item, Unit_Price, Quantity, Total_Price)
- Generate summary sheet with totals
- Requirements: 5.1, 5.2, 5.3, 6.1, 6.2, 6.3
- 6.2 Create Export API routes
- GET /api/export/monthly?year=&month= - monthly export
- GET /api/export/yearly?year= - yearly export
- Return Excel as downloadable attachment
- Add Swagger documentation
- Requirements: 5.1, 5.4, 6.1, 6.4, 8.1
- [ ]* 6.3 Write property tests for Export
- Property 10: Monthly Export Completeness
- Property 11: Yearly Export Completeness
- Validates: Requirements 5.1, 5.3, 6.1, 6.3
[x] 7. Checkpoint - Backend complete
- Ensure all backend tests pass, ask the user if questions arise.
[x] 8. Set up frontend project structure
- Initialize React project with Vite
- Install Ant Design, Axios, React Router
- Create basic Layout component with sidebar navigation
- Set up API service module
- Requirements: 9.1, 9.2, 9.3, 9.4, 9.5
[x] 9. Implement Person management UI
[x] 10. Implement Item management UI
[x] 11. Implement WorkRecord management UI
[x] 12. Implement Dashboard and Export UI
[x] 13. Wire frontend components together
- Set up React Router with all pages
- Connect all components to API
- Add loading states and error handling
- Requirements: 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
[x] 14. Final checkpoint - Full system integration
- Ensure all tests pass, ask the user if questions arise.
- Verify Swagger documentation is accessible
- Test end-to-end workflow
Notes
- Tasks marked with
* are optional property-based tests and can be skipped for faster MVP
- Each task references specific requirements for traceability
- Checkpoints ensure incremental validation
- Backend uses SQLite for testing, PostgreSQL configuration is ready for production
- Frontend uses Ant Design for consistent, professional UI