优化资金图谱主题节点检索

This commit is contained in:
wkc
2026-06-03 17:11:09 +08:00
parent d45e9410ef
commit c5b2033a3d
5 changed files with 240 additions and 29 deletions

View File

@@ -20,6 +20,10 @@ public interface CcdiFundGraphMapper {
List<CcdiFundGraphNodeVO> selectFundGraphSubjects(@Param("query") CcdiFundGraphQueryDTO query);
List<CcdiFundGraphNodeVO> selectFundGraphSubjectsByExactKeyword(@Param("query") CcdiFundGraphQueryDTO query);
List<CcdiFundGraphNodeVO> selectFundGraphSubjectsByName(@Param("query") CcdiFundGraphQueryDTO query);
List<CcdiFundGraphEdgeVO> selectFundGraphEdges(@Param("query") CcdiFundGraphQueryDTO query);
List<CcdiFundGraphEdgeVO> selectFundGraphManualEdges(@Param("query") CcdiFundGraphQueryDTO query);

View File

@@ -48,7 +48,7 @@ public class CcdiFundGraphServiceImpl implements ICcdiFundGraphService {
if (isBlank(query.getKeyword()) && isBlank(query.getObjectKey())) {
return Collections.emptyList();
}
return fundGraphMapper.selectFundGraphSubjects(query);
return selectSubjects(query);
}
@Override
@@ -134,13 +134,30 @@ public class CcdiFundGraphServiceImpl implements ICcdiFundGraphService {
if (isBlank(query.getObjectKey()) && isBlank(query.getKeyword())) {
return null;
}
List<CcdiFundGraphNodeVO> subjects = fundGraphMapper.selectFundGraphSubjects(query);
List<CcdiFundGraphNodeVO> subjects = selectSubjects(query);
if (subjects == null || subjects.isEmpty()) {
return null;
}
return subjects.get(0);
}
private List<CcdiFundGraphNodeVO> selectSubjects(CcdiFundGraphQueryDTO query) {
if (query == null) {
return Collections.emptyList();
}
if (!isBlank(query.getObjectKey())) {
return fundGraphMapper.selectFundGraphSubjects(query);
}
if (isBlank(query.getKeyword())) {
return Collections.emptyList();
}
List<CcdiFundGraphNodeVO> exactSubjects = fundGraphMapper.selectFundGraphSubjectsByExactKeyword(query);
if (exactSubjects != null && !exactSubjects.isEmpty()) {
return exactSubjects;
}
return fundGraphMapper.selectFundGraphSubjectsByName(query);
}
private List<CcdiFundGraphNodeVO> buildNodes(CcdiFundGraphNodeVO centerNode, List<CcdiFundGraphEdgeVO> edges) {
Map<String, CcdiFundGraphNodeVO> nodeMap = new LinkedHashMap<>();
Map<String, CcdiFundGraphNodeVO> subjectCache = new LinkedHashMap<>();

View File

@@ -116,17 +116,79 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
INNER JOIN lx_fund_flow_subject_node to_subject
ON CONCAT('idno_node/', to_subject.object_key) = to_own.from_key
WHERE 1 = 1
<if test="query.objectKey != null and query.objectKey != ''">
AND (
from_subject.object_key = (#{query.objectKey} COLLATE utf8mb4_general_ci)
OR to_subject.object_key = (#{query.objectKey} COLLATE utf8mb4_general_ci)
)
</if>
<include refid="detailFilter"/>
</sql>
<select id="selectFundGraphSubjects" resultMap="FundGraphNodeResultMap">
<sql id="subjectJoinRowsByCenter">
SELECT
d.object_key AS detailObjectKey,
d.bank_statement_id AS bankStatementId,
d.trx_date AS trxDate,
d.le_account_no AS leAccountNo,
d.le_account_name AS leAccountName,
d.customer_account_name AS customerAccountName,
d.customer_account_no AS customerAccountNo,
d.cash_type AS cashType,
d.user_memo AS userMemo,
d.amount,
d.flag AS direction,
d.family_relation_type AS familyRelationType,
center_subject.object_key AS fromObjectKey,
to_subject.object_key AS toObjectKey,
CONCAT('idno_node/', center_subject.object_key) AS fromKey,
CONCAT('idno_node/', to_subject.object_key) AS toKey,
center_subject.name AS fromName,
to_subject.name AS toName,
center_subject.idnocfno AS fromIdNo,
to_subject.idnocfno AS toIdNo
FROM lx_fund_flow_subject_node center_subject
INNER JOIN lx_fund_flow_own_account_edge from_own
ON from_own.from_key = CONCAT('idno_node/', center_subject.object_key)
INNER JOIN lx_fund_flow_detail_edge d
ON d.from_key = from_own.to_key
INNER JOIN lx_fund_flow_own_account_edge to_own
ON to_own.to_key = d.to_key
INNER JOIN lx_fund_flow_subject_node to_subject
ON to_subject.object_key = SUBSTRING(to_own.from_key, 11)
WHERE center_subject.object_key = (#{query.objectKey} COLLATE utf8mb4_general_ci)
<include refid="detailFilter"/>
UNION ALL
SELECT
d.object_key AS detailObjectKey,
d.bank_statement_id AS bankStatementId,
d.trx_date AS trxDate,
d.le_account_no AS leAccountNo,
d.le_account_name AS leAccountName,
d.customer_account_name AS customerAccountName,
d.customer_account_no AS customerAccountNo,
d.cash_type AS cashType,
d.user_memo AS userMemo,
d.amount,
d.flag AS direction,
d.family_relation_type AS familyRelationType,
from_subject.object_key AS fromObjectKey,
center_subject.object_key AS toObjectKey,
CONCAT('idno_node/', from_subject.object_key) AS fromKey,
CONCAT('idno_node/', center_subject.object_key) AS toKey,
from_subject.name AS fromName,
center_subject.name AS toName,
from_subject.idnocfno AS fromIdNo,
center_subject.idnocfno AS toIdNo
FROM lx_fund_flow_subject_node center_subject
INNER JOIN lx_fund_flow_own_account_edge to_own
ON to_own.from_key = CONCAT('idno_node/', center_subject.object_key)
INNER JOIN lx_fund_flow_detail_edge d
ON d.to_key = to_own.to_key
INNER JOIN lx_fund_flow_own_account_edge from_own
ON from_own.to_key = d.from_key
INNER JOIN lx_fund_flow_subject_node from_subject
ON from_subject.object_key = SUBSTRING(from_own.from_key, 11)
WHERE center_subject.object_key = (#{query.objectKey} COLLATE utf8mb4_general_ci)
AND from_subject.object_key != center_subject.object_key
<include refid="detailFilter"/>
</sql>
<sql id="fundGraphSubjectColumns">
n.object_key AS objectKey,
CONCAT('idno_node/', n.object_key) AS nodeKey,
n.name AS nodeName,
@@ -165,28 +227,57 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
0 AS depth,
0 AS totalAmount,
0 AS transactionCount
</sql>
<select id="selectFundGraphSubjects" resultMap="FundGraphNodeResultMap">
SELECT
<include refid="fundGraphSubjectColumns"/>
FROM lx_fund_flow_subject_node n
WHERE 1 = 1
<if test="query.objectKey != null and query.objectKey != ''">
AND n.object_key = (#{query.objectKey} COLLATE utf8mb4_general_ci)
</if>
<if test="query.objectKey == null or query.objectKey == ''">
<if test="query.keyword != null and query.keyword != ''">
AND (
n.idnocfno = (TRIM(#{query.keyword}) COLLATE utf8mb4_general_ci)
OR n.name LIKE (CONCAT('%', TRIM(#{query.keyword}), '%') COLLATE utf8mb4_general_ci)
OR n.object_key = (TRIM(#{query.keyword}) COLLATE utf8mb4_general_ci)
)
</if>
</if>
WHERE n.object_key = (#{query.objectKey} COLLATE utf8mb4_general_ci)
</select>
<select id="selectFundGraphSubjectsByExactKeyword" resultMap="FundGraphNodeResultMap">
SELECT exact_rows.*
FROM (
SELECT
<include refid="fundGraphSubjectColumns"/>,
0 AS matchOrder
FROM lx_fund_flow_subject_node n
WHERE n.idnocfno = (TRIM(#{query.keyword}) COLLATE utf8mb4_general_ci)
UNION ALL
SELECT
<include refid="fundGraphSubjectColumns"/>,
1 AS matchOrder
FROM lx_fund_flow_subject_node n
WHERE n.object_key = (TRIM(#{query.keyword}) COLLATE utf8mb4_general_ci)
AND (
n.idnocfno IS NULL
OR n.idnocfno != (TRIM(#{query.keyword}) COLLATE utf8mb4_general_ci)
)
) exact_rows
ORDER BY exact_rows.matchOrder, exact_rows.nodeName
LIMIT
<choose>
<when test="query.limit != null and query.limit > 0">
#{query.limit}
</when>
<otherwise>
20
</otherwise>
</choose>
</select>
<select id="selectFundGraphSubjectsByName" resultMap="FundGraphNodeResultMap">
SELECT
<include refid="fundGraphSubjectColumns"/>
FROM lx_fund_flow_subject_node n
WHERE n.name LIKE (CONCAT('%', TRIM(#{query.keyword}), '%') COLLATE utf8mb4_general_ci)
ORDER BY
CASE
WHEN n.idnocfno = (TRIM(IFNULL(#{query.keyword}, '')) COLLATE utf8mb4_general_ci) THEN 0
WHEN n.object_key = (TRIM(IFNULL(#{query.keyword}, '')) COLLATE utf8mb4_general_ci) THEN 1
WHEN n.staff_id IS NOT NULL AND TRIM(n.staff_id) != '' THEN 2
WHEN UPPER(IFNULL(n.source_type, '')) LIKE '%EMPLOYEE%' THEN 2
WHEN n.source_type LIKE '%员工%' THEN 2
ELSE 3
WHEN n.staff_id IS NOT NULL AND TRIM(n.staff_id) != '' THEN 0
WHEN UPPER(IFNULL(n.source_type, '')) LIKE '%EMPLOYEE%' THEN 0
WHEN n.source_type LIKE '%员工%' THEN 0
ELSE 1
END,
n.name
LIMIT
@@ -247,7 +338,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ELSE 0
END AS canTrace
FROM (
<include refid="subjectJoinRows"/>
<include refid="subjectJoinRowsByCenter"/>
) graph_rows
WHERE 1 = 1
GROUP BY