新增亲属资产领域对象与映射

This commit is contained in:
wkc
2026-03-13 09:47:21 +08:00
parent 472457c69b
commit 70bdce7bda
9 changed files with 105 additions and 80 deletions

View File

@@ -26,37 +26,33 @@ class CcdiAssetInfoMapperTest {
private static final String RESOURCE = "mapper/info/collection/CcdiAssetInfoMapper.xml";
@Test
void selectByFamilyId_shouldFilterByFamilyId() throws Exception {
void selectByFamilyIdAndPersonId_shouldFilterByOwnershipKey() throws Exception {
MappedStatement mappedStatement = loadMappedStatement(
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.selectByFamilyId");
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.selectByFamilyIdAndPersonId");
String sql = renderSql(mappedStatement, Map.of("familyId", "320101199001010011"));
String sql = renderSql(mappedStatement, Map.of(
"familyId", "320101199001010011",
"personId", "320101199201010022"
));
assertTrue(sql.contains("FROM ccdi_asset_info"), sql);
assertTrue(sql.contains("WHERE family_id = ?"), sql);
assertTrue(sql.contains("AND person_id = ?"), sql);
}
@Test
void selectByPersonId_shouldFilterByPersonId() throws Exception {
void deleteByFamilyIdAndPersonId_shouldFilterByOwnershipKey() throws Exception {
MappedStatement mappedStatement = loadMappedStatement(
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.selectByPersonId");
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.deleteByFamilyIdAndPersonId");
String sql = renderSql(mappedStatement, Map.of("personId", "320101199201010022"));
assertTrue(sql.contains("FROM ccdi_asset_info"), sql);
assertTrue(sql.contains("WHERE person_id = ?"), sql);
}
@Test
void deleteByFamilyIds_shouldRenderInClause() throws Exception {
MappedStatement mappedStatement = loadMappedStatement(
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.deleteByFamilyIds");
String sql = renderSql(mappedStatement, Map.of("familyIds", List.of("A", "B")));
String sql = renderSql(mappedStatement, Map.of(
"familyId", "320101199001010011",
"personId", "320101199201010022"
));
assertTrue(sql.contains("DELETE FROM ccdi_asset_info"), sql);
assertTrue(sql.contains("family_id IN"), sql);
assertFalse(sql.contains("IN ()"), sql);
assertTrue(sql.contains("WHERE family_id = ?"), sql);
assertTrue(sql.contains("AND person_id = ?"), sql);
}
@Test
@@ -84,23 +80,18 @@ class CcdiAssetInfoMapperTest {
}
@Test
void ownerLookupQueries_shouldResolveFromEmployeeAndFamilyRelation() throws Exception {
MappedStatement employeeStatement = loadMappedStatement(
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.selectOwnerByEmployeeIdCards");
void ownerLookupQuery_shouldResolveFromFamilyRelationOnly() throws Exception {
MappedStatement familyStatement = loadMappedStatement(
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.selectOwnerByFamilyRelationIdCards");
"com.ruoyi.info.collection.mapper.CcdiAssetInfoMapper.selectOwnerCandidatesByRelationCertNos");
String employeeSql = renderSql(employeeStatement, Map.of("personIds", List.of("A")));
String familySql = renderSql(familyStatement, Map.of("personIds", List.of("B")));
assertTrue(employeeSql.contains("FROM ccdi_base_staff"), employeeSql);
assertTrue(employeeSql.contains("id_card AS personId"), employeeSql);
assertTrue(employeeSql.contains("id_card AS familyId"), employeeSql);
String familySql = renderSql(familyStatement, Map.of("relationCertNos", List.of("B")));
assertTrue(familySql.contains("FROM ccdi_staff_fmy_relation"), familySql);
assertTrue(familySql.contains("relation_cert_no AS personId"), familySql);
assertTrue(familySql.contains("person_id AS familyId"), familySql);
assertTrue(familySql.contains("relation_cert_no IN"), familySql);
assertTrue(familySql.contains("is_emp_family = 1"), familySql);
assertFalse(familySql.contains("FROM ccdi_base_staff"), familySql);
}
private MappedStatement loadMappedStatement(String statementId) throws Exception {

View File

@@ -0,0 +1,33 @@
package com.ruoyi.info.collection.service;
import com.ruoyi.info.collection.domain.dto.CcdiAssetInfoDTO;
import com.ruoyi.info.collection.domain.excel.CcdiAssetInfoExcel;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class CcdiAssetInfoDesignContractTest {
@Test
void aggregateSaveDto_shouldNotExposePersonId() {
Set<String> fieldNames = Arrays.stream(CcdiAssetInfoDTO.class.getDeclaredFields())
.map(field -> field.getName())
.collect(Collectors.toSet());
assertFalse(fieldNames.contains("personId"));
}
@Test
void importExcel_shouldStillExposePersonIdForRelationCertNoMatching() {
Set<String> fieldNames = Arrays.stream(CcdiAssetInfoExcel.class.getDeclaredFields())
.map(field -> field.getName())
.collect(Collectors.toSet());
assertTrue(fieldNames.contains("personId"));
}
}