# Model Param Save Trigger Rebuild Backend Implementation Plan

> **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** 让项目参数保存成功后由后端自动异步触发项目内流水重新打标，避免前端额外串联重打标接口。

**Architecture:** 保持 `CcdiModelParamController` 的保存接口不变，把“保存参数成功后触发重打标”收敛到 `CcdiModelParamServiceImpl`，复用现有 `ICcdiBankTagService.submitAutoRebuild` 异步提交能力，并新增专用触发类型区分来源；仅在项目级参数保存成功且实际存在更新时触发，默认配置与保存失败场景不进入重打标链路。

**Tech Stack:** Java 21, Spring Boot 3, MyBatis Plus, JUnit 5, Mockito, Maven

---

### Task 1: 补齐参数保存后触发自动重打标的失败测试

**Files:**
- Modify: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiModelParamServiceImplTest.java`

- [ ] **Step 1: Write the failing test**

补充两个核心用例：

```java
@Mock
private ICcdiBankTagService bankTagService;

@Test
void saveAllParams_shouldSubmitAutoRebuildAfterProjectParamsUpdated() {
    when(projectMapper.selectById(40L)).thenReturn(buildProject(40L, "custom"));
    when(modelParamMapper.selectOne(any())).thenReturn(buildParam(1L, 40L, "LARGE_TRANSACTION", "大额交易模型", "SINGLE_TRANSACTION_AMOUNT", "1000"));

    service.saveAllParams(buildSaveAllDto());

    verify(bankTagService).submitAutoRebuild(40L, TriggerType.AUTO_PARAM_CHANGE);
}

@Test
void saveAllParams_shouldNotSubmitAutoRebuildForGlobalDefaults() {
    ModelParamSaveAllDTO dto = buildSaveAllDto();
    dto.setProjectId(0L);
    when(modelParamMapper.selectOne(any())).thenReturn(buildParam(1L, 0L, "LARGE_TRANSACTION", "大额交易模型", "SINGLE_TRANSACTION_AMOUNT", "1000"));

    service.saveAllParams(dto);

    verify(bankTagService, never()).submitAutoRebuild(anyLong(), any());
}
```

- [ ] **Step 2: Run test to verify it fails**

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiModelParamServiceImplTest test
```

Expected:

- `FAIL`
- 原因是当前服务尚未注入 `ICcdiBankTagService`，也不会在保存成功后触发自动重打标

- [ ] **Step 3: Write minimal implementation**

最小实现包括：

1. 在 `CcdiModelParamServiceImpl` 注入 `ICcdiBankTagService`
2. 在 `saveAllParams` 成功批量更新后，若 `projectId > 0` 且 `updateList` 非空，则调用：

```java
bankTagService.submitAutoRebuild(projectId, TriggerType.AUTO_PARAM_CHANGE);
```

3. `saveParams` 同步补齐相同语义，保证单模型保存与批量保存行为一致

- [ ] **Step 4: Run test to verify it passes**

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiModelParamServiceImplTest test
```

Expected:

- `PASS`
- 说明参数保存成功后会自动进入异步重打标链路

- [ ] **Step 5: Commit**

```bash
git add ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiModelParamServiceImplTest.java ccdi-project/src/main/java/com/ruoyi/ccdi/project/service/impl/CcdiModelParamServiceImpl.java
git commit -m "实现参数保存后自动触发项目重打标"
```

### Task 2: 扩展重打标触发类型并保持异步链路可观测

**Files:**
- Modify: `ccdi-project/src/main/java/com/ruoyi/ccdi/project/domain/enums/TriggerType.java`
- Modify: `ccdi-project/src/main/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImpl.java`
- Modify: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImplTest.java`

- [ ] **Step 1: Write the failing test**

补一个触发类型透传校验，锁定参数保存来源不会被误记成上传或拉取：

```java
@Test
void submitAutoRebuild_shouldKeepAutoParamChangeTriggerType() {
    service.submitAutoRebuild(40L, TriggerType.AUTO_PARAM_CHANGE);

    verify(coordinator).submitAuto(40L, TriggerType.AUTO_PARAM_CHANGE);
}
```

- [ ] **Step 2: Run test to verify it fails**

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiBankTagServiceImplTest test
```

Expected:

- `FAIL`
- 原因是当前 `TriggerType` 还没有 `AUTO_PARAM_CHANGE`

- [ ] **Step 3: Write minimal implementation**

在 `TriggerType` 新增：

```java
AUTO_PARAM_CHANGE
```

同时检查 `CcdiBankTagServiceImpl` 的日志和调用链，确保新增枚举值无需额外分支即可沿现有异步协调器执行。

- [ ] **Step 4: Run test to verify it passes**

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiBankTagServiceImplTest test
```

Expected:

- `PASS`

- [ ] **Step 5: Commit**

```bash
git add ccdi-project/src/main/java/com/ruoyi/ccdi/project/domain/enums/TriggerType.java ccdi-project/src/main/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImpl.java ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImplTest.java
git commit -m "补充参数修改触发的自动重打标类型"
```

### Task 3: 记录服务端验证结果与边界

**Files:**
- Create: `docs/tests/records/2026-03-18-model-param-save-trigger-rebuild-backend-verification.md`
- Create: `docs/reports/implementation/2026-03-18-model-param-save-trigger-rebuild-record.md`

- [ ] **Step 1: Write verification skeleton**

先记录本次服务端验证点：

```markdown
# 参数保存触发项目流水重打标后端验证记录

## 验证范围
- 项目参数保存成功后自动异步触发重打标
- 默认参数保存不触发项目重打标
- 保存失败时不触发重打标
```

- [ ] **Step 2: Run focused tests**

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiModelParamServiceImplTest,CcdiBankTagServiceImplTest test
```

Expected:

- 相关测试全部通过

- [ ] **Step 3: Write implementation record**

把实际改动、测试命令和结果写入实施记录，覆盖：

- 新增 `AUTO_PARAM_CHANGE` 触发类型
- `saveParams/saveAllParams` 成功更新后触发异步重打标
- 不触发场景与异常场景说明

- [ ] **Step 4: Commit**

```bash
git add docs/tests/records/2026-03-18-model-param-save-trigger-rebuild-backend-verification.md docs/reports/implementation/2026-03-18-model-param-save-trigger-rebuild-record.md
git commit -m "补充参数保存触发重打标后端实施记录"
```
