# Project Upload File Delete Trigger Retag 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:** 保持现有删除主链路不变，只在 `CcdiFileUploadServiceImpl.deleteFileUploadRecord` 的“平台删除成功、本地流水删除成功、上传记录状态更新成功”之后追加一次自动重打标提交。为避免触发语义混淆，新增独立触发类型 `AUTO_FILE_DELETE`，并通过现有 `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/CcdiFileUploadServiceImplTest.java`
- Modify: `ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImplTest.java`
- Modify: `ccdi-project/src/main/java/com/ruoyi/ccdi/project/domain/enums/TriggerType.java`

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

在 `CcdiFileUploadServiceImplTest` 的删除成功用例中增加断言：

```java
verify(bankTagService).submitAutoRebuild(PROJECT_ID, TriggerType.AUTO_FILE_DELETE);
```

在 `CcdiBankTagServiceImplTest` 中增加触发类型透传测试：

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

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

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

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiFileUploadServiceImplTest#deleteFileUploadRecord_shouldDeletePlatformFileBankStatementsAndMarkDeleted,CcdiBankTagServiceImplTest#submitAutoRebuild_shouldKeepAutoFileDeleteTriggerType test
```

Expected:

- `FAIL`
- 原因是还没有 `AUTO_FILE_DELETE` 触发类型，也没有在文件删除成功后触发自动重打标

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

1. 在 `TriggerType` 中新增：

```java
AUTO_FILE_DELETE
```

2. 在 `CcdiFileUploadServiceImpl.deleteFileUploadRecord` 的状态更新成功后追加：

```java
bankTagService.submitAutoRebuild(record.getProjectId(), TriggerType.AUTO_FILE_DELETE);
```

3. 返回成功提示改为能体现重打标已开始的文案。

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

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiFileUploadServiceImplTest#deleteFileUploadRecord_shouldDeletePlatformFileBankStatementsAndMarkDeleted,CcdiBankTagServiceImplTest#submitAutoRebuild_shouldKeepAutoFileDeleteTriggerType 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/CcdiFileUploadServiceImpl.java ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiFileUploadServiceImplTest.java ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiBankTagServiceImplTest.java
git commit -m "删除上传文件后自动触发项目重打标"
```

### Task 2: 验证删除失败分支不会误触发重打标

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

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

在“流水分析平台删除失败”用例中增加断言：

```java
verify(bankTagService, never()).submitAutoRebuild(any(), any());
```

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

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiFileUploadServiceImplTest#deleteFileUploadRecord_shouldStopWhenLsfxDeleteFails test
```

Expected:

- 如果实现位置不正确，测试会失败

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

确保仅在删除主链路全部成功后，才触发自动重打标；任何异常都直接抛出，不补触发。

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

Run:

```bash
mvn -pl ccdi-project -Dtest=CcdiFileUploadServiceImplTest#deleteFileUploadRecord_shouldStopWhenLsfxDeleteFails test
```

Expected:

- `PASS`

- [ ] **Step 5: Commit**

```bash
git add ccdi-project/src/main/java/com/ruoyi/ccdi/project/service/impl/CcdiFileUploadServiceImpl.java ccdi-project/src/test/java/com/ruoyi/ccdi/project/service/impl/CcdiFileUploadServiceImplTest.java
git commit -m "补充文件删除触发重打标失败保护"
```
