完成亲属资产后端联调验证

This commit is contained in:
wkc
2026-03-13 10:55:38 +08:00
parent 4a3ea462b4
commit b6df65706c
3 changed files with 75 additions and 56 deletions

View File

@@ -46,33 +46,32 @@
r.created_by, r.create_time, r.updated_by, r.update_time r.created_by, r.create_time, r.updated_by, r.update_time
FROM ccdi_staff_fmy_relation r FROM ccdi_staff_fmy_relation r
LEFT JOIN ccdi_base_staff s ON r.person_id = s.id_card LEFT JOIN ccdi_base_staff s ON r.person_id = s.id_card
<where> WHERE 1 = 1
AND r.is_emp_family = 1 AND r.is_emp_family = 1
<if test="query.personId != null and query.personId != ''"> <if test="query.personId != null and query.personId != ''">
AND r.person_id = #{query.personId} AND r.person_id = #{query.personId}
</if> </if>
<if test="query.personName != null and query.personName != ''"> <if test="query.personName != null and query.personName != ''">
AND s.name LIKE CONCAT('%', #{query.personName}, '%') AND s.name LIKE CONCAT('%', #{query.personName}, '%')
</if> </if>
<if test="query.relationType != null and query.relationType != ''"> <if test="query.relationType != null and query.relationType != ''">
AND r.relation_type = #{query.relationType} AND r.relation_type = #{query.relationType}
</if> </if>
<if test="query.relationName != null and query.relationName != ''"> <if test="query.relationName != null and query.relationName != ''">
AND r.relation_name LIKE CONCAT('%', #{query.relationName}, '%') AND r.relation_name LIKE CONCAT('%', #{query.relationName}, '%')
</if> </if>
<if test="query.status != null"> <if test="query.status != null">
AND r.status = #{query.status} AND r.status = #{query.status}
</if> </if>
<if test="query.dataSource != null and query.dataSource != ''"> <if test="query.dataSource != null and query.dataSource != ''">
AND r.data_source = #{query.dataSource} AND r.data_source = #{query.dataSource}
</if> </if>
<if test="query.effectiveDateStart != null"> <if test="query.effectiveDateStart != null">
AND r.effective_date &gt;= #{query.effectiveDateStart} AND r.effective_date &gt;= #{query.effectiveDateStart}
</if> </if>
<if test="query.effectiveDateEnd != null"> <if test="query.effectiveDateEnd != null">
AND r.effective_date &lt;= #{query.effectiveDateEnd} AND r.effective_date &lt;= #{query.effectiveDateEnd}
</if> </if>
</where>
ORDER BY r.create_time DESC ORDER BY r.create_time DESC
</select> </select>
@@ -101,33 +100,32 @@
r.created_by, r.create_time, r.updated_by, r.update_time r.created_by, r.create_time, r.updated_by, r.update_time
FROM ccdi_staff_fmy_relation r FROM ccdi_staff_fmy_relation r
LEFT JOIN ccdi_base_staff s ON r.person_id = s.id_card LEFT JOIN ccdi_base_staff s ON r.person_id = s.id_card
<where> WHERE 1 = 1
AND r.is_emp_family = 1 AND r.is_emp_family = 1
<if test="query.personId != null and query.personId != ''"> <if test="query.personId != null and query.personId != ''">
AND r.person_id = #{query.personId} AND r.person_id = #{query.personId}
</if> </if>
<if test="query.personName != null and query.personName != ''"> <if test="query.personName != null and query.personName != ''">
AND s.name LIKE CONCAT('%', #{query.personName}, '%') AND s.name LIKE CONCAT('%', #{query.personName}, '%')
</if> </if>
<if test="query.relationType != null and query.relationType != ''"> <if test="query.relationType != null and query.relationType != ''">
AND r.relation_type = #{query.relationType} AND r.relation_type = #{query.relationType}
</if> </if>
<if test="query.relationName != null and query.relationName != ''"> <if test="query.relationName != null and query.relationName != ''">
AND r.relation_name LIKE CONCAT('%', #{query.relationName}, '%') AND r.relation_name LIKE CONCAT('%', #{query.relationName}, '%')
</if> </if>
<if test="query.status != null"> <if test="query.status != null">
AND r.status = #{query.status} AND r.status = #{query.status}
</if> </if>
<if test="query.dataSource != null and query.dataSource != ''"> <if test="query.dataSource != null and query.dataSource != ''">
AND r.data_source = #{query.dataSource} AND r.data_source = #{query.dataSource}
</if> </if>
<if test="query.effectiveDateStart != null"> <if test="query.effectiveDateStart != null">
AND r.effective_date &gt;= #{query.effectiveDateStart} AND r.effective_date &gt;= #{query.effectiveDateStart}
</if> </if>
<if test="query.effectiveDateEnd != null"> <if test="query.effectiveDateEnd != null">
AND r.effective_date &lt;= #{query.effectiveDateEnd} AND r.effective_date &lt;= #{query.effectiveDateEnd}
</if> </if>
</where>
ORDER BY r.create_time DESC ORDER BY r.create_time DESC
</select> </select>

View File

@@ -1,6 +1,7 @@
package com.ruoyi.info.collection.mapper; package com.ruoyi.info.collection.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.parser.defaults.DefaultCountSqlParser;
import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationQueryDTO; import com.ruoyi.info.collection.domain.dto.CcdiStaffFmyRelationQueryDTO;
import org.apache.ibatis.builder.xml.XMLMapperBuilder; import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.BoundSql;
@@ -35,9 +36,11 @@ class CcdiStaffFmyRelationMapperTest {
"page", new Page<>(1, 10), "page", new Page<>(1, 10),
"query", queryDTO "query", queryDTO
)); ));
String countSql = normalizeSql(new DefaultCountSqlParser().getSmartCountSql(sql, "0"));
assertTrue(sql.contains("WHERE r.is_emp_family = 1 AND r.person_id = ?"), sql); assertTrue(sql.contains("WHERE 1 = 1 AND r.is_emp_family = 1 AND r.person_id = ?"), sql);
assertFalse(sql.contains("1AND"), sql); assertFalse(sql.contains("1AND"), sql);
assertFalse(countSql.contains("1AND"), countSql);
} }
private MappedStatement loadMappedStatement(String statementId) throws Exception { private MappedStatement loadMappedStatement(String statementId) throws Exception {
@@ -57,7 +60,11 @@ class CcdiStaffFmyRelationMapperTest {
private String renderSql(MappedStatement mappedStatement, Map<String, Object> params) { private String renderSql(MappedStatement mappedStatement, Map<String, Object> params) {
BoundSql boundSql = mappedStatement.getBoundSql(new HashMap<>(params)); BoundSql boundSql = mappedStatement.getBoundSql(new HashMap<>(params));
return boundSql.getSql().replaceAll("\\s+", " ").trim(); return normalizeSql(boundSql.getSql());
}
private String normalizeSql(String sql) {
return sql.replaceAll("\\s+", " ").trim();
} }
private void registerTypeAliases(TypeAliasRegistry typeAliasRegistry) { private void registerTypeAliases(TypeAliasRegistry typeAliasRegistry) {

View File

@@ -1,5 +1,6 @@
USE ccdi; USE ccdi;
-- 新建表结构(适用于首次落库)
CREATE TABLE IF NOT EXISTS `ccdi_asset_info` ( CREATE TABLE IF NOT EXISTS `ccdi_asset_info` (
`asset_id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '资产ID', `asset_id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '资产ID',
`family_id` VARCHAR(100) NOT NULL COMMENT '归属员工证件号', `family_id` VARCHAR(100) NOT NULL COMMENT '归属员工证件号',
@@ -23,3 +24,16 @@ CREATE TABLE IF NOT EXISTS `ccdi_asset_info` (
KEY `idx_person_id` (`person_id`), KEY `idx_person_id` (`person_id`),
KEY `idx_family_person` (`family_id`, `person_id`) KEY `idx_family_person` (`family_id`, `person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='亲属资产信息表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='亲属资产信息表';
-- 存量环境迁移说明
-- 如果当前库中的 ccdi_asset_info 仍是旧“员工资产信息表”结构,需要至少执行以下迁移:
-- 1. 将 family_id / person_id 扩容到 VARCHAR(100),以兼容非 18 位证件号
-- 2. 补齐 idx_family_person 联合索引
-- 3. 旧索引 idx_asset_main_type 可按需保留或删除,不影响本次功能
--
-- 示例迁移语句:
-- ALTER TABLE `ccdi_asset_info`
-- MODIFY `family_id` VARCHAR(100) NOT NULL COMMENT '归属员工证件号',
-- MODIFY `person_id` VARCHAR(100) NOT NULL COMMENT '资产实际持有人证件号';
--
-- CREATE INDEX `idx_family_person` ON `ccdi_asset_info` (`family_id`, `person_id`);