tasks.md 7.2 KB

Implementation Plan: Work Statistics System

Overview

本实现计划将工作统计系统分解为可执行的编码任务,按照后端基础设施 → 数据模型 → API接口 → 前端界面的顺序逐步实现。使用Python Flask作为后端,React + Ant Design作为前端,SQLite用于测试。

Tasks

  • [x] 1. Set up backend project structure

    • Create Flask application factory with configuration
    • Set up SQLAlchemy with SQLite for testing
    • Configure Flask-RESTX for Swagger documentation
    • Create requirements.txt with dependencies
    • Requirements: 7.2, 8.1, 8.2
  • [x] 2. Implement Person module

    • 2.1 Create Person model
    • Define Person SQLAlchemy model with id, name, created_at, updated_at
    • Requirements: 1.1, 1.2
    • 2.2 Implement Person service
    • Create PersonService with create, get_all, get_by_id, update, delete methods
    • Add name validation (reject empty/whitespace)
    • Requirements: 1.1, 1.2, 1.3, 1.4, 1.5
    • 2.3 Create Person API routes
    • GET /api/persons - list all
    • GET /api/persons/ - get by id
    • POST /api/persons/create - create
    • POST /api/persons/update - update
    • POST /api/persons/delete - delete
    • Add Swagger documentation
    • Requirements: 1.1, 1.2, 1.3, 1.4, 8.1, 8.2
    • [ ]* 2.4 Write property tests for Person CRUD
    • Property 1: Person CRUD Round-Trip
    • Property 2: Person Name Validation
    • Validates: Requirements 1.1, 1.2, 1.3, 1.4, 1.5
  • [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

    • 9.1 Create PersonList component
    • Display persons in Ant Design Table
    • Add edit and delete buttons
    • Requirements: 9.1
    • 9.2 Create PersonForm component
    • Modal form for add/edit person
    • Form validation for name
    • Requirements: 9.1, 9.6
  • [x] 10. Implement Item management UI

    • 10.1 Create ItemList component
    • Display items in Ant Design Table with name and unit_price
    • Add edit and delete buttons
    • Requirements: 9.2
    • 10.2 Create ItemForm component
    • Modal form for add/edit item
    • Form validation for name and unit_price (positive number with decimals)
    • Requirements: 9.2, 9.6
  • [x] 11. Implement WorkRecord management UI

    • 11.1 Create WorkRecordList component
    • Display work records in Ant Design Table
    • Add DatePicker for date filter
    • Add Select for person filter
    • Show calculated total_price
    • Requirements: 9.3
    • 11.2 Create WorkRecordForm component
    • Modal form for add/edit work record
    • Select components for person and item
    • DatePicker for work_date
    • InputNumber for quantity
    • Requirements: 9.3, 9.6
  • [x] 12. Implement Dashboard and Export UI

    • 12.1 Create Dashboard component
    • Display daily summary statistics using Card and Statistic components
    • Quick links to add work record
    • Requirements: 9.4
    • 12.2 Create Export component
    • DatePicker for month/year selection
    • Export buttons for monthly and yearly reports
    • Requirements: 9.5
  • [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