# 流程列表测算利率展示后端实施计划

> **For agentic workers:** REQUIRED: Use superpowers:executing-plans to implement this plan in this repository. Do not use subagents. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** 让流程列表接口通过联表 SQL 一次返回测算利率 `calculateRate` 和执行利率 `executeRate`。

**Architecture:** 后端为流程列表新增列表专用返回对象，替换当前直接返回 `LoanPricingWorkflow` 实体分页的方式。Mapper 层新增联表 SQL，以 `loan_pricing_workflow` 为主表，左连接个人和企业模型输出表，并统一产出 `calculateRate` 字段供前端直接消费。

**Tech Stack:** Spring Boot、MyBatis Plus、Lombok、Maven、XML Mapper

---

### Task 1: 建立流程列表专用返回对象

**Files:**
- Create: `ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/domain/vo/LoanPricingWorkflowListVO.java`
- Modify: `ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/service/ILoanPricingWorkflowService.java`
- Modify: `ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/controller/LoanPricingWorkflowController.java`

- [ ] **Step 1: 写一个失败测试，约束列表返回对象需要包含测算利率**

Create/Test: `ruoyi-loan-pricing/src/test/java/com/ruoyi/loanpricing/domain/vo/LoanPricingWorkflowListVOTest.java`

测试示例：

```java
@Test
void shouldExposeCalculateRateAndExecuteRateFields() throws Exception {
    LoanPricingWorkflowListVO vo = new LoanPricingWorkflowListVO();
    vo.setCalculateRate("6.15");
    vo.setExecuteRate("5.80");

    assertEquals("6.15", vo.getCalculateRate());
    assertEquals("5.80", vo.getExecuteRate());
}
```

- [ ] **Step 2: 运行测试确认在对象未创建前失败**

Run: `mvn -pl ruoyi-loan-pricing -Dtest=LoanPricingWorkflowListVOTest test`
Expected: FAIL，提示 `LoanPricingWorkflowListVO` 不存在或缺少字段。

- [ ] **Step 3: 新增列表专用 VO**

创建 `LoanPricingWorkflowListVO`，至少包含：

```java
private String serialNum;
private String custName;
private String custType;
private String guarType;
private String applyAmt;
private String calculateRate;
private String executeRate;
private Date createTime;
private String createBy;
```

- [ ] **Step 4: 修改 Service 接口与 Controller 返回类型**

将列表分页返回从：

```java
IPage<LoanPricingWorkflow>
```

调整为：

```java
IPage<LoanPricingWorkflowListVO>
```

并同步更新 Controller 列表接口使用的新分页结果类型。

- [ ] **Step 5: 再次运行测试确认返回对象字段已可用**

Run: `mvn -pl ruoyi-loan-pricing -Dtest=LoanPricingWorkflowListVOTest test`
Expected: PASS

- [ ] **Step 6: 提交这一小步**

Run: `git add ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/domain/vo/LoanPricingWorkflowListVO.java ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/service/ILoanPricingWorkflowService.java ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/controller/LoanPricingWorkflowController.java ruoyi-loan-pricing/src/test/java/com/ruoyi/loanpricing/domain/vo/LoanPricingWorkflowListVOTest.java && git commit -m "新增流程列表测算利率返回对象"`
Expected: 生成仅包含 VO 与接口调整的中文提交。

### Task 2: 新增联表 SQL 返回统一测算利率

**Files:**
- Modify: `ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/mapper/LoanPricingWorkflowMapper.java`
- Create: `ruoyi-loan-pricing/src/main/resources/mapper/loanpricing/LoanPricingWorkflowMapper.xml`
- Modify: `ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/service/impl/LoanPricingWorkflowServiceImpl.java`
- Test: `ruoyi-loan-pricing/src/test/java/com/ruoyi/loanpricing/service/impl/LoanPricingWorkflowServiceImplTest.java`

- [ ] **Step 1: 写一个失败测试，约束服务层返回的列表对象要透传 `calculateRate`**

Create/Test: `ruoyi-loan-pricing/src/test/java/com/ruoyi/loanpricing/service/impl/LoanPricingWorkflowServiceImplTest.java`

测试示例：

```java
@Test
void shouldReturnPagedWorkflowListWithCalculateRate() {
    Page<LoanPricingWorkflowListVO> page = new Page<>(1, 10);
    LoanPricingWorkflow query = new LoanPricingWorkflow();
    LoanPricingWorkflowListVO row = new LoanPricingWorkflowListVO();
    row.setCalculateRate("6.15");

    when(loanPricingWorkflowMapper.selectWorkflowPageWithRates(any(), any())).thenReturn(new Page<LoanPricingWorkflowListVO>().setRecords(List.of(row)));

    IPage<LoanPricingWorkflowListVO> result = service.selectLoanPricingPage(page, query);

    assertEquals("6.15", result.getRecords().get(0).getCalculateRate());
}
```

- [ ] **Step 2: 运行测试确认在方法未接入前失败**

Run: `mvn -pl ruoyi-loan-pricing -Dtest=LoanPricingWorkflowServiceImplTest test`
Expected: FAIL，提示方法签名不匹配或 Mapper 自定义方法不存在。

- [ ] **Step 3: 在 Mapper 接口声明列表专用分页方法**

在 `LoanPricingWorkflowMapper` 中新增类似方法：

```java
IPage<LoanPricingWorkflowListVO> selectWorkflowPageWithRates(
        Page<LoanPricingWorkflowListVO> page,
        @Param("query") LoanPricingWorkflow query);
```

- [ ] **Step 4: 在 XML 中实现联表 SQL**

创建 `LoanPricingWorkflowMapper.xml`，编写列表专用查询，关键逻辑至少包含：

```xml
SELECT
  lpw.serial_num AS serialNum,
  lpw.cust_name AS custName,
  lpw.cust_type AS custType,
  lpw.guar_type AS guarType,
  lpw.apply_amt AS applyAmt,
  CASE
    WHEN lpw.cust_type = '个人' THEN mr.calculate_rate
    WHEN lpw.cust_type = '企业' THEN mc.calculate_rate
    ELSE NULL
  END AS calculateRate,
  lpw.execute_rate AS executeRate,
  lpw.create_time AS createTime,
  lpw.create_by AS createBy
FROM loan_pricing_workflow lpw
LEFT JOIN model_retail_output_fields mr ON lpw.model_output_id = mr.id
LEFT JOIN model_corp_output_fields mc ON lpw.model_output_id = mc.id
```

并保留当前筛选条件和按更新时间倒序。

- [ ] **Step 5: 在 ServiceImpl 中改为调用联表分页方法**

将列表分页实现从：

```java
return loanPricingWorkflowMapper.selectPage(page, wrapper);
```

切换为调用新的 Mapper 联表分页方法，保留查询参数透传。

- [ ] **Step 6: 运行服务层测试确认通过**

Run: `mvn -pl ruoyi-loan-pricing -Dtest=LoanPricingWorkflowServiceImplTest test`
Expected: PASS

- [ ] **Step 7: 如需补充 XML 级验证，再运行模块测试**

Run: `mvn -pl ruoyi-loan-pricing test`
Expected: 至少本次新增测试通过；若存在其他失败，需先区分是否为既有问题。

- [ ] **Step 8: 提交这一小步**

Run: `git add ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/mapper/LoanPricingWorkflowMapper.java ruoyi-loan-pricing/src/main/resources/mapper/loanpricing/LoanPricingWorkflowMapper.xml ruoyi-loan-pricing/src/main/java/com/ruoyi/loanpricing/service/impl/LoanPricingWorkflowServiceImpl.java ruoyi-loan-pricing/src/test/java/com/ruoyi/loanpricing/service/impl/LoanPricingWorkflowServiceImplTest.java && git commit -m "新增流程列表测算利率联表查询"`
Expected: 生成包含联表 SQL 与服务切换的中文提交。

### Task 3: 完成后端留档与接口验证

**Files:**
- Create: `doc/implementation-report-2026-03-28-workflow-calculate-rate-list-backend.md`

- [ ] **Step 1: 补充后端实施记录**

实施记录至少写明：

```markdown
- 列表接口返回类型已调整为列表专用 VO
- 后端通过联表 SQL 一次返回 `calculateRate` 与 `executeRate`
- 个人客户测算利率来自 `model_retail_output_fields.calculate_rate`
- 企业客户测算利率来自 `model_corp_output_fields.calculate_rate`
```

- [ ] **Step 2: 验证列表接口返回结构**

Run: 按项目现有方式启动后端后，请求 `/loanPricing/workflow/list`
Expected: 返回行数据中包含 `calculateRate` 和 `executeRate`。

- [ ] **Step 3: 核对个人和企业记录的测算利率来源**

Run: 使用已有测试数据各抽取一条个人和企业记录，对比接口返回与模型输出表数据。
Expected: 个人记录取自零售模型输出表，企业记录取自对公模型输出表。

- [ ] **Step 4: 如果为验证启动了后端进程，结束对应进程**

Run: `ps -ef | rg 'RuoYiApplication|java'`
Expected: 对本次验证启动的后端进程执行停止；对非本次启动进程不做处理。

- [ ] **Step 5: 提交后端实施记录**

Run: `git add doc/implementation-report-2026-03-28-workflow-calculate-rate-list-backend.md && git commit -m "补充测算利率列表后端实施记录"`
Expected: 生成仅包含后端留档内容的中文提交。
