Files
yidaima/RuoYi-Vue/docs/superpowers/specs/2026-06-18-qing-business-action-runtime-design.md

49 lines
2.8 KiB
Markdown
Raw Normal View History

# Qing Business Action Runtime Design
## Goal
Make business-action buttons generated by the Qing runnable templates call real backend endpoints instead of returning HTTP 404.
## Root Cause
The portal frontend serializes `BusinessActionDesign.path` and sends requests such as:
- `POST /library/borrow/borrow`
- `POST /library/reservation/reserve`
The Qing backend templates currently generate only CRUD controllers and empty MyBatis-Plus services. No endpoint or executable DSL implementation is generated for `tableBusinessActions`.
## Architecture
Each table remains the owner of its business actions. Its generated controller exposes CRUD routes with complete `/module/business` mappings and exposes business actions using the absolute path stored in the blueprint. Its generated service interface and implementation render deterministic methods from the validated business-action DSL.
The service implementation uses `JdbcTemplate` inside `@Transactional` methods for rule checks and effects. It supports the existing validated rule/effect set and resolves `${param.field}`, `${now}`, and `${current_user.id}` without executing arbitrary AI-generated SQL.
The controller reads the authenticated portal user from `PortalAuthTokenStore` and puts the user ID into an internal parameter used by `${current_user.id}`. The frontend resolves fields available on the selected/detail record and prompts for any remaining required fields before sending the action.
## Template Synchronization
The source-of-truth bundled templates are:
- `ruoyi-generator/src/main/resources/qing/controller.java.vm`
- `ruoyi-generator/src/main/resources/qing/service.java.vm`
- `ruoyi-generator/src/main/resources/qing/serviceImpl.java.vm`
- `ruoyi-generator/src/main/resources/qing/index.vue.vm`
The runnable database seed copies in `sql/qing_templates.sql` and `sql/db.sql` must contain the same behavior. `GenProjectServiceImpl` falls back to bundled backend service/controller templates when an installed template record is stale, so existing local databases gain the fix without requiring an immediate SQL migration.
## Error Handling
- Missing action parameters return a business error rather than a 404.
- Missing authenticated portal users return “请先登录”.
- Invalid rules/effects throw a runtime business error and roll back the transaction.
- The frontend displays backend business messages and does not report success unless the response code is `200`.
## Testing
- Template rendering tests prove controller mappings, current-user injection, transactional service methods, DSL helpers, and frontend parameter collection are emitted.
- Generator service tests prove stale runnable backend templates are replaced by bundled controller/service templates.
- The generated project must compile.
- Authenticated HTTP requests to borrow and reserve must no longer return 404.