新增信息维护年收入字段全链路支持

This commit is contained in:
wkc
2026-03-17 18:07:57 +08:00
parent 82cb751b8f
commit 8f9fc09338
33 changed files with 542 additions and 23 deletions

View File

@@ -0,0 +1,22 @@
package com.ruoyi.info.collection.mapper;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertTrue;
class CcdiBaseStaffMapperTest {
@Test
void mapperXml_shouldContainAnnualIncomeColumnsInCustomSql() throws Exception {
try (InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream("mapper/info/collection/CcdiBaseStaffMapper.xml")) {
String xml = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
assertTrue(xml.contains("annual_income"), xml);
assertTrue(xml.contains("#{item.annualIncome}"), xml);
}
}
}

View File

@@ -41,6 +41,16 @@ class CcdiStaffFmyRelationMapperTest {
assertTrue(sql.contains("WHERE 1 = 1 AND r.is_emp_family = 1 AND r.person_id = ?"), sql);
assertFalse(sql.contains("1AND"), sql);
assertFalse(countSql.contains("1AND"), countSql);
assertTrue(sql.contains("r.annual_income"), sql);
}
@Test
void mapperXml_shouldContainAnnualIncomeInBatchInsert() throws Exception {
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(RESOURCE)) {
String xml = new String(inputStream.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
assertTrue(xml.contains("annual_income"), xml);
assertTrue(xml.contains("#{item.annualIncome}"), xml);
}
}
private MappedStatement loadMappedStatement(String statementId) throws Exception {

View File

@@ -0,0 +1,57 @@
package com.ruoyi.info.collection.service;
import com.ruoyi.info.collection.domain.dto.CcdiBaseStaffAddDTO;
import com.ruoyi.info.collection.service.impl.CcdiBaseStaffImportServiceImpl;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class CcdiBaseStaffImportServiceImplTest {
private final CcdiBaseStaffImportServiceImpl service = new CcdiBaseStaffImportServiceImpl();
@Test
void validateStaffData_shouldAllowEmptyAnnualIncome() {
assertDoesNotThrow(() -> service.validateStaffData(buildDto(null), false, Collections.emptySet(), Collections.emptySet()));
}
@Test
void validateStaffData_shouldAllowZeroAndTwoDecimalAnnualIncome() {
assertDoesNotThrow(() -> service.validateStaffData(buildDto(new BigDecimal("0.00")), false, Collections.emptySet(), Collections.emptySet()));
assertDoesNotThrow(() -> service.validateStaffData(buildDto(new BigDecimal("12345.67")), false, Collections.emptySet(), Collections.emptySet()));
}
@Test
void validateStaffData_shouldRejectNegativeAnnualIncome() {
RuntimeException exception = assertThrows(RuntimeException.class,
() -> service.validateStaffData(buildDto(new BigDecimal("-1.00")), false, Set.of(), Set.of()));
assertEquals("年收入不能为负数", exception.getMessage());
}
@Test
void validateStaffData_shouldRejectAnnualIncomeWithMoreThanTwoDecimals() {
RuntimeException exception = assertThrows(RuntimeException.class,
() -> service.validateStaffData(buildDto(new BigDecimal("12.345")), false, Set.of(), Set.of()));
assertEquals("年收入最多保留2位小数", exception.getMessage());
}
private CcdiBaseStaffAddDTO buildDto(BigDecimal annualIncome) {
CcdiBaseStaffAddDTO dto = new CcdiBaseStaffAddDTO();
dto.setName("张三");
dto.setStaffId(1001L);
dto.setDeptId(10L);
dto.setIdCard("320101199001010014");
dto.setPhone("13812345678");
dto.setStatus("0");
dto.setAnnualIncome(annualIncome);
return dto;
}
}

View File

@@ -55,6 +55,7 @@ class CcdiBaseStaffServiceImplTest {
addDTO.setIdCard("320101199001010011");
addDTO.setPhone("13812345678");
addDTO.setStatus("0");
addDTO.setAnnualIncome(new BigDecimal("12345.67"));
addDTO.setAssetInfoList(List.of(
buildAssetDto("房产"),
buildAssetDto("车辆")
@@ -67,6 +68,9 @@ class CcdiBaseStaffServiceImplTest {
int result = service.insertBaseStaff(addDTO);
assertEquals(1, result);
ArgumentCaptor<CcdiBaseStaff> staffCaptor = ArgumentCaptor.forClass(CcdiBaseStaff.class);
verify(baseStaffMapper).insert(staffCaptor.capture());
assertEquals(new BigDecimal("12345.67"), staffCaptor.getValue().getAnnualIncome());
ArgumentCaptor<List<CcdiAssetInfoDTO>> captor = ArgumentCaptor.forClass(List.class);
verify(assetInfoService).replaceByFamilyId(eq("320101199001010011"), captor.capture());
List<CcdiAssetInfoDTO> savedAssets = captor.getValue();
@@ -88,6 +92,7 @@ class CcdiBaseStaffServiceImplTest {
editDTO.setIdCard("320101199001010011");
editDTO.setPhone("13812345678");
editDTO.setStatus("0");
editDTO.setAnnualIncome(new BigDecimal("45678.90"));
editDTO.setAssetInfoList(List.of(buildAssetDto("车辆")));
when(baseStaffMapper.selectById(1001L)).thenReturn(existing);
@@ -97,6 +102,9 @@ class CcdiBaseStaffServiceImplTest {
int result = service.updateBaseStaff(editDTO);
assertEquals(1, result);
ArgumentCaptor<CcdiBaseStaff> staffCaptor = ArgumentCaptor.forClass(CcdiBaseStaff.class);
verify(baseStaffMapper).updateById(staffCaptor.capture());
assertEquals(new BigDecimal("45678.90"), staffCaptor.getValue().getAnnualIncome());
verify(assetInfoService, never()).deleteByFamilyId("320101199001010011");
verify(assetInfoService).replaceByFamilyId("320101199001010011", editDTO.getAssetInfoList());
}
@@ -133,6 +141,7 @@ class CcdiBaseStaffServiceImplTest {
staff.setName("张三");
staff.setIdCard("320101199001010011");
staff.setStatus("0");
staff.setAnnualIncome(new BigDecimal("88888.88"));
CcdiAssetInfo assetInfo = new CcdiAssetInfo();
assetInfo.setFamilyId("320101199001010011");
@@ -149,6 +158,7 @@ class CcdiBaseStaffServiceImplTest {
CcdiBaseStaffVO result = service.selectBaseStaffById(1001L);
assertNotNull(result.getAssetInfoList());
assertEquals(new BigDecimal("88888.88"), result.getAnnualIncome());
assertEquals(1, result.getAssetInfoList().size());
assertEquals("320101199201010022", result.getAssetInfoList().get(0).getPersonId());
assertEquals("车辆", result.getAssetInfoList().get(0).getAssetMainType());

View File

@@ -0,0 +1,59 @@
package com.ruoyi.info.collection.service;
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationAddDTO;
import com.ruoyi.info.collection.service.impl.CcdiStaffFmyRelationImportServiceImpl;
import org.junit.jupiter.api.Test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class CcdiStaffFmyRelationImportServiceImplTest {
private final CcdiStaffFmyRelationImportServiceImpl service = new CcdiStaffFmyRelationImportServiceImpl();
@Test
void validateRelationData_shouldRejectNegativeAnnualIncome() throws Exception {
RuntimeException exception = assertThrows(RuntimeException.class,
() -> invokeValidateRelationData(buildDto(new BigDecimal("-1.00"))));
assertEquals("家庭成员年收入不能为负数", exception.getMessage());
}
@Test
void validateRelationData_shouldRejectAnnualIncomeWithMoreThanTwoDecimals() throws Exception {
RuntimeException exception = assertThrows(RuntimeException.class,
() -> invokeValidateRelationData(buildDto(new BigDecimal("12.345"))));
assertEquals("家庭成员年收入最多保留2位小数", exception.getMessage());
}
private void invokeValidateRelationData(CcdiStaffFmyRelationAddDTO dto) throws Exception {
Method method = CcdiStaffFmyRelationImportServiceImpl.class
.getDeclaredMethod("validateRelationData", CcdiStaffFmyRelationAddDTO.class);
method.setAccessible(true);
try {
method.invoke(service, dto);
} catch (InvocationTargetException ex) {
Throwable targetException = ex.getTargetException();
if (targetException instanceof RuntimeException runtimeException) {
throw runtimeException;
}
throw ex;
}
}
private CcdiStaffFmyRelationAddDTO buildDto(BigDecimal annualIncome) {
CcdiStaffFmyRelationAddDTO dto = new CcdiStaffFmyRelationAddDTO();
dto.setPersonId("320101199001010014");
dto.setRelationType("配偶");
dto.setRelationName("李四");
dto.setRelationCertType("护照");
dto.setRelationCertNo("A123456789");
dto.setAnnualIncome(annualIncome);
return dto;
}
}

View File

@@ -77,6 +77,7 @@ class CcdiStaffFmyRelationServiceImplTest {
addDTO.setRelationName("李四");
addDTO.setRelationCertType("护照");
addDTO.setRelationCertNo("A123456789");
addDTO.setAnnualIncome(new BigDecimal("23456.78"));
addDTO.setAssetInfoList(List.of(buildAssetDto("房产")));
when(relationMapper.insert(any(CcdiStaffFmyRelation.class))).thenReturn(1);
@@ -89,6 +90,7 @@ class CcdiStaffFmyRelationServiceImplTest {
assertEquals("MANUAL", relationCaptor.getValue().getDataSource());
assertEquals(Boolean.TRUE, relationCaptor.getValue().getIsEmpFamily());
assertEquals(Boolean.FALSE, relationCaptor.getValue().getIsCustFamily());
assertEquals(new BigDecimal("23456.78"), relationCaptor.getValue().getAnnualIncome());
verify(assetInfoService).replaceByFamilyIdAndPersonId("320101199001010011", "A123456789", addDTO.getAssetInfoList());
}
@@ -154,6 +156,7 @@ class CcdiStaffFmyRelationServiceImplTest {
editDTO.setRelationName("李四");
editDTO.setRelationCertType("护照");
editDTO.setRelationCertNo("A123456789");
editDTO.setAnnualIncome(new BigDecimal("76543.21"));
editDTO.setAssetInfoList(List.of(buildAssetDto("车辆")));
when(relationMapper.selectById(10L)).thenReturn(existing);
@@ -162,6 +165,9 @@ class CcdiStaffFmyRelationServiceImplTest {
int result = service.updateRelation(editDTO);
assertEquals(1, result);
ArgumentCaptor<CcdiStaffFmyRelation> relationCaptor = ArgumentCaptor.forClass(CcdiStaffFmyRelation.class);
verify(relationMapper).updateById(relationCaptor.capture());
assertEquals(new BigDecimal("76543.21"), relationCaptor.getValue().getAnnualIncome());
verify(assetInfoService).replaceByFamilyIdAndPersonId("320101199001010011", "A123456789", editDTO.getAssetInfoList());
}