336 lines
10 KiB
Markdown
336 lines
10 KiB
Markdown
# Employee Asset Maintenance Backend Implementation Plan
|
|
|
|
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
|
|
|
|
**Goal:** Add backend support for employee asset maintenance, including aggregated employee detail/save, employee-asset cascade delete, and asynchronous asset import based on employee ID card linkage.
|
|
|
|
**Architecture:** Keep employee maintenance on the existing `CcdiBaseStaff` aggregate, and introduce a new `CcdiAssetInfo` resource in `ccdi-info-collection`. Employee add/edit/detail/delete will orchestrate asset persistence inside transactions, while asset import will mirror the existing employee import flow with a dedicated controller, service, Redis task keys, and failure records.
|
|
|
|
**Tech Stack:** Java 21, Spring Boot 3, MyBatis Plus, XML mapper SQL, EasyExcel, Redis, Maven
|
|
|
|
---
|
|
|
|
### Task 1: Add the asset table SQL and document the data contract
|
|
|
|
**Files:**
|
|
- Create: `sql/2026-03-12_ccdi_asset_info.sql`
|
|
- Review: `assets/资产信息表.csv`
|
|
- Review: `docs/plans/2026-03-12-employee-asset-maintenance-design.md`
|
|
|
|
**Step 1: Write the SQL script**
|
|
|
|
Create `ccdi_asset_info` with:
|
|
|
|
- `asset_id BIGINT` auto increment primary key
|
|
- `person_id VARCHAR(18)` storing employee `id_card`
|
|
- business columns from the approved design
|
|
- audit columns `create_by`, `create_time`, `update_by`, `update_time`
|
|
- indexes `idx_person_id` and `idx_asset_main_type`
|
|
|
|
**Step 2: Verify the script matches the approved constraints**
|
|
|
|
Confirm the script:
|
|
|
|
- does not include `asset_id` in any import-facing note
|
|
- keeps the field name `person_id`
|
|
- links by employee `id_card`, not `staff_id`
|
|
|
|
**Step 3: Commit**
|
|
|
|
```bash
|
|
git add sql/2026-03-12_ccdi_asset_info.sql docs/plans/2026-03-12-employee-asset-maintenance-design.md
|
|
git commit -m "新增员工资产信息设计与建表脚本"
|
|
```
|
|
|
|
### Task 2: Add the asset domain, DTO, VO, Excel, and mapper skeletons
|
|
|
|
**Files:**
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/CcdiAssetInfo.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/dto/CcdiAssetInfoDTO.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/vo/CcdiAssetInfoVO.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/excel/CcdiAssetInfoExcel.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/vo/AssetImportFailureVO.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/mapper/CcdiAssetInfoMapper.java`
|
|
- Create: `ccdi-info-collection/src/main/resources/mapper/info/collection/CcdiAssetInfoMapper.xml`
|
|
|
|
**Step 1: Create the entity**
|
|
|
|
Model `CcdiAssetInfo` with MyBatis Plus annotations and audit fields consistent with existing `CcdiBaseStaff`.
|
|
|
|
**Step 2: Create request and response objects**
|
|
|
|
Add one DTO for nested employee-form submission and one VO for employee detail response.
|
|
|
|
**Step 3: Create the Excel and failure record objects**
|
|
|
|
`CcdiAssetInfoExcel` must exclude `asset_id` and include `person_id`.
|
|
|
|
**Step 4: Create mapper methods**
|
|
|
|
Define methods for:
|
|
|
|
- query by `person_id`
|
|
- delete by `person_id`
|
|
- delete by `person_id` list
|
|
- batch insert
|
|
- import lookup by employee `id_card`
|
|
|
|
### Task 3: Extend employee DTO and VO aggregation
|
|
|
|
**Files:**
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/dto/CcdiBaseStaffAddDTO.java`
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/dto/CcdiBaseStaffEditDTO.java`
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/domain/vo/CcdiBaseStaffVO.java`
|
|
- Test: `ccdi-info-collection/src/test/java/com/ruoyi/info/collection/service/CcdiBaseStaffServiceAssetAggregationTest.java`
|
|
|
|
**Step 1: Write the failing test**
|
|
|
|
Add a focused service test that asserts employee detail, add DTO, and edit DTO support `assetInfoList`.
|
|
|
|
**Step 2: Run test to verify it fails**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiBaseStaffServiceAssetAggregationTest
|
|
```
|
|
|
|
Expected: FAIL because `assetInfoList` does not exist yet.
|
|
|
|
**Step 3: Add the aggregate fields**
|
|
|
|
Add `List<CcdiAssetInfoDTO>` to add/edit DTOs and `List<CcdiAssetInfoVO>` to the employee VO.
|
|
|
|
**Step 4: Run test to verify it passes**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiBaseStaffServiceAssetAggregationTest
|
|
```
|
|
|
|
Expected: PASS
|
|
|
|
### Task 4: Add asset service interfaces and focused persistence methods
|
|
|
|
**Files:**
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/service/ICcdiAssetInfoService.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/service/ICcdiAssetInfoImportService.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/service/impl/CcdiAssetInfoServiceImpl.java`
|
|
- Test: `ccdi-info-collection/src/test/java/com/ruoyi/info/collection/service/CcdiAssetInfoServiceImplTest.java`
|
|
|
|
**Step 1: Write the failing test**
|
|
|
|
Cover these behaviors:
|
|
|
|
- query all assets by `person_id`
|
|
- replace all assets for one employee
|
|
- delete assets by one or more employee ID cards
|
|
- ignore empty rows when replacing assets
|
|
|
|
**Step 2: Run test to verify it fails**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiAssetInfoServiceImplTest
|
|
```
|
|
|
|
Expected: FAIL because the asset service does not exist yet.
|
|
|
|
**Step 3: Implement minimal service logic**
|
|
|
|
Implement methods:
|
|
|
|
- `selectByPersonId`
|
|
- `replaceByPersonId`
|
|
- `deleteByPersonId`
|
|
- `deleteByPersonIds`
|
|
|
|
Use batch delete + batch insert.
|
|
|
|
**Step 4: Run test to verify it passes**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiAssetInfoServiceImplTest
|
|
```
|
|
|
|
Expected: PASS
|
|
|
|
### Task 5: Update employee service to aggregate asset query and transactional save
|
|
|
|
**Files:**
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/service/ICcdiBaseStaffService.java`
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/service/impl/CcdiBaseStaffServiceImpl.java`
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/controller/CcdiBaseStaffController.java`
|
|
- Test: `ccdi-info-collection/src/test/java/com/ruoyi/info/collection/service/CcdiBaseStaffServiceImplTest.java`
|
|
|
|
**Step 1: Write the failing test**
|
|
|
|
Add or extend service tests for:
|
|
|
|
- add employee with multiple assets
|
|
- edit employee and replace assets
|
|
- edit employee with changed `id_card`
|
|
- detail query returns `assetInfoList`
|
|
- delete employee cascades asset deletion
|
|
|
|
**Step 2: Run test to verify it fails**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiBaseStaffServiceImplTest
|
|
```
|
|
|
|
Expected: FAIL because employee service does not yet coordinate asset persistence.
|
|
|
|
**Step 3: Implement the aggregate behavior**
|
|
|
|
Update `CcdiBaseStaffServiceImpl` to:
|
|
|
|
- inject `ICcdiAssetInfoService`
|
|
- load assets during detail query
|
|
- save employee first, then replace assets by current employee `id_card`
|
|
- capture old `id_card` during edit and clean old asset records when it changes
|
|
- delete asset rows before deleting employee rows
|
|
|
|
**Step 4: Run the focused test again**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiBaseStaffServiceImplTest
|
|
```
|
|
|
|
Expected: PASS
|
|
|
|
### Task 6: Add asset import controller and async import service
|
|
|
|
**Files:**
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/controller/CcdiAssetInfoController.java`
|
|
- Create: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/service/impl/CcdiAssetInfoImportServiceImpl.java`
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/service/ICcdiAssetInfoImportService.java`
|
|
- Test: `ccdi-info-collection/src/test/java/com/ruoyi/info/collection/service/CcdiAssetInfoImportServiceImplTest.java`
|
|
|
|
**Step 1: Write the failing test**
|
|
|
|
Cover:
|
|
|
|
- import template entity excludes `asset_id`
|
|
- import fails when `person_id` does not match an employee `id_card`
|
|
- import stores failure records only for bad rows
|
|
- import status and failure list use dedicated asset task keys
|
|
|
|
**Step 2: Run test to verify it fails**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiAssetInfoImportServiceImplTest
|
|
```
|
|
|
|
Expected: FAIL because no asset import pipeline exists yet.
|
|
|
|
**Step 3: Implement the import flow**
|
|
|
|
Mirror the employee import design with asset-specific names:
|
|
|
|
- Redis key prefix `import:assetInfo:`
|
|
- asynchronous import execution
|
|
- failure record caching for 7 days
|
|
- controller endpoints for template, upload, status, and failures
|
|
|
|
**Step 4: Run the focused test again**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiAssetInfoImportServiceImplTest
|
|
```
|
|
|
|
Expected: PASS
|
|
|
|
### Task 7: Add mapper XML SQL for batch asset operations
|
|
|
|
**Files:**
|
|
- Modify: `ccdi-info-collection/src/main/resources/mapper/info/collection/CcdiAssetInfoMapper.xml`
|
|
- Test: `ccdi-info-collection/src/test/java/com/ruoyi/info/collection/mapper/CcdiAssetInfoMapperTest.java`
|
|
|
|
**Step 1: Write the failing test**
|
|
|
|
Verify:
|
|
|
|
- select by `person_id`
|
|
- batch insert multiple assets
|
|
- delete by one `person_id`
|
|
- delete by multiple `person_id` values
|
|
- employee existence lookup by `id_card`
|
|
|
|
**Step 2: Run test to verify it fails**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiAssetInfoMapperTest
|
|
```
|
|
|
|
Expected: FAIL because the mapper XML SQL is incomplete.
|
|
|
|
**Step 3: Implement minimal XML SQL**
|
|
|
|
Add:
|
|
|
|
- result map
|
|
- select by `person_id`
|
|
- delete by `person_id`
|
|
- delete by `person_id` list
|
|
- batch insert
|
|
- employee existence lookup
|
|
|
|
**Step 4: Run the mapper test**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiAssetInfoMapperTest
|
|
```
|
|
|
|
Expected: PASS
|
|
|
|
### Task 8: Verify the backend changes end to end
|
|
|
|
**Files:**
|
|
- Modify: `ccdi-info-collection/src/main/java/com/ruoyi/info/collection/`
|
|
- Modify: `ccdi-info-collection/src/main/resources/mapper/info/collection/`
|
|
- Modify: `sql/2026-03-12_ccdi_asset_info.sql`
|
|
|
|
**Step 1: Run focused backend tests**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn test -Dtest=CcdiBaseStaffServiceAssetAggregationTest,CcdiAssetInfoServiceImplTest,CcdiBaseStaffServiceImplTest,CcdiAssetInfoImportServiceImplTest,CcdiAssetInfoMapperTest
|
|
```
|
|
|
|
Expected: all focused tests pass.
|
|
|
|
**Step 2: Run module compile verification**
|
|
|
|
Run:
|
|
|
|
```bash
|
|
mvn clean compile
|
|
```
|
|
|
|
Expected: compile succeeds without Java or mapper XML errors.
|
|
|
|
**Step 3: Commit**
|
|
|
|
```bash
|
|
git add sql/2026-03-12_ccdi_asset_info.sql ccdi-info-collection/src/main/java/com/ruoyi/info/collection ccdi-info-collection/src/main/resources/mapper/info/collection docs/plans/2026-03-12-employee-asset-maintenance-backend-implementation.md
|
|
git commit -m "新增员工资产信息后端实施计划"
|
|
```
|