Add executable business blueprint workflow

This commit is contained in:
王鹏
2026-05-24 13:29:42 +08:00
parent ecdc015c2f
commit 6682a44a43
40 changed files with 4756 additions and 113 deletions

View File

@@ -0,0 +1,63 @@
# Executable Business Blueprint Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Generate runnable workflow, status, insert, update, and numeric inventory/amount business code from business blueprints.
**Architecture:** Extend the current safe DSL instead of letting AI write Java. The backend validates `ruleChecks` and expanded `effects` against saved schema, then Velocity templates render deterministic Java/Vue code.
**Tech Stack:** Java 8, Spring Boot, MyBatis, Fastjson2/Jackson, Velocity, JUnit 4, Mockito, Vue.
---
### Task 1: Extend Blueprint DTO And AI Normalization
**Files:**
- Create: `ruoyi-generator/src/main/java/com/ruoyi/generator/domain/front/dto/BusinessActionRuleDesign.java`
- Modify: `ruoyi-generator/src/main/java/com/ruoyi/generator/domain/front/dto/BusinessActionDesign.java`
- Modify: `ruoyi-generator/src/main/java/com/ruoyi/generator/domain/front/dto/BusinessActionEffectDesign.java`
- Modify: `ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/AiGenerateServiceImpl.java`
- Test: `ruoyi-generator/src/test/java/com/ruoyi/generator/service/front/AiGenerateServiceImplTest.java`
- [ ] Add a failing test proving `ruleChecks`, `INSERT_ROW`, and `DECREASE_NUMBER` parse and persist.
- [ ] Run `mvn -pl ruoyi-generator -Dtest=AiGenerateServiceImplTest test` and verify RED.
- [ ] Add DTO fields and normalization helpers.
- [ ] Re-run the targeted test and verify GREEN.
### Task 2: Validate Executable DSL Safely
**Files:**
- Modify: `ruoyi-generator/src/main/java/com/ruoyi/generator/service/front/AiBusinessBlueprintValidator.java`
- Test: `ruoyi-generator/src/test/java/com/ruoyi/generator/service/front/AiGenerateServiceImplTest.java`
- [ ] Add tests for unknown rule/effect fields and unsafe values.
- [ ] Run the targeted test and verify RED.
- [ ] Validate action tables, rule tables/fields, effect tables/fields, map keys, placeholders, and numeric amounts.
- [ ] Re-run tests and verify GREEN.
### Task 3: Render Full Runnable Workflow Helpers
**Files:**
- Modify: `sql/business_blueprint_templates.sql`
- Modify: `sql/db.sql`
- Test: `ruoyi-generator/src/test/java/com/ruoyi/generator/service/GenProjectServiceImplTest.java`
- [ ] Add a failing template test for `assertExists`, `insertRow`, `updateFields`, `setStatus`, `increaseNumberField`, and `decreaseNumberField`.
- [ ] Run the targeted test and verify RED.
- [ ] Extend the backend Velocity template to render rule checks and executable effects.
- [ ] Sync the template block into `sql/db.sql`.
- [ ] Re-run template tests and verify GREEN.
### Task 4: Frontend Display Compatibility
**Files:**
- Modify: `easycode-web/src/views/GenerateView.vue`
- [ ] Render structured `ruleChecks` and expanded effect details without breaking old string `rules`.
- [ ] Run existing frontend tests if available.
### Task 5: Full Verification
- [ ] Run `mvn -pl ruoyi-generator -Dtest=AiGenerateServiceImplTest,GenProjectServiceImplTest test`.
- [ ] Run any impacted frontend tests.
- [ ] Inspect generated template snippets for one sample action.

View File

@@ -0,0 +1,52 @@
# Executable Business Blueprint Design
## Goal
Generate runnable business workflow code from EasyCode business blueprints without allowing AI to emit arbitrary Java source.
## Scope
This phase covers general workflow actions plus inventory and amount style numeric changes. Generated projects should get Controller endpoints, transactional Service methods, rule checks, row inserts, field updates, status updates, numeric increase/decrease helpers, and frontend buttons/API calls.
This phase does not cover arbitrary Java snippets, complex accounting ledgers, permissions beyond the existing generated shell, distributed locks, or idempotency keys.
## Architecture
AI returns a structured DSL in `businessActions`. The backend normalizes and validates that DSL against the saved database schema, stores it in `front_project.business_blueprint`, and passes it into Velocity templates. Templates render deterministic Java and Vue code from the DSL.
Existing `rules: List<String>` remains as human-readable notes. New executable checks live in `ruleChecks`.
## DSL
Each action may include:
- `code`, `name`, `ownerTable`, `method`, `path`, `transaction`, `requestFields`
- `rules`: human-readable notes
- `ruleChecks`: executable checks
- `effects`: executable data mutations
Supported `ruleChecks`:
- `EXISTS`
- `NOT_EXISTS`
- `FIELD_EQUALS`
- `FIELD_NOT_EQUALS`
- `FIELD_IN`
- `NUMBER_GTE`
Supported `effects`:
- `INSERT_ROW`
- `UPDATE_FIELDS`
- `SET_STATUS`
- `INCREASE_NUMBER`
- `DECREASE_NUMBER`
- legacy `UPDATE_FIELD`
## Safety
All table and column identifiers must exist in the saved schema. Effect value placeholders are limited to safe forms: literals, `${param.field}`, and `${now}`. Numeric amounts may be literals or `${param.field}`. SQL fragments from AI are not accepted except the existing legacy `UPDATE_FIELD.value`, which remains bounded by the template helper.
## Testing
Backend tests cover parsing and persistence of structured checks/effects, validation of unknown tables or fields, and template rendering markers for the generated helper methods. Existing tests must remain green.