From 15744e668bf612961e541e26fd2a73a4951e789c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sun, 8 Feb 2026 13:15:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(controller):=20=E6=89=B9=E9=87=8F=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=94=AF=E6=8C=81=E6=96=B0=E5=A2=9E=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E5=AE=9A=E5=88=B6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BatchImportSupport 中添加了新的重载方法 refreshCompanyIdByCompanyNameContainedInText - 新增 companyQueryCustomizer 参数用于自定义 CreditCompany 查询条件 - 在 CreditJudgmentDebtorController 中添加 topLevelOnly 参数控制是否只匹配一级企业 - 支持通过 parentId 条件过滤一级企业(parentId=0 或 NULL) - 优化了企业名称匹配逻辑,专注于 name 字段进行匹配 --- .../credit/controller/BatchImportSupport.java | 47 ++++++++++++++++++- .../CreditJudgmentDebtorController.java | 18 ++++--- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gxwebsoft/credit/controller/BatchImportSupport.java b/src/main/java/com/gxwebsoft/credit/controller/BatchImportSupport.java index 7464b36..bdaf481 100644 --- a/src/main/java/com/gxwebsoft/credit/controller/BatchImportSupport.java +++ b/src/main/java/com/gxwebsoft/credit/controller/BatchImportSupport.java @@ -2,6 +2,7 @@ package com.gxwebsoft.credit.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.IService; import com.gxwebsoft.credit.entity.CreditCompany; import com.gxwebsoft.credit.service.CreditCompanyService; @@ -363,6 +364,44 @@ public class BatchImportSupport { SFunction tenantIdGetter, Supplier patchFactory, SFunction... textGetters) { + return refreshCompanyIdByCompanyNameContainedInText( + service, + creditCompanyService, + currentTenantId, + onlyNull, + limit, + idGetter, + idSetter, + companyIdGetter, + companyIdSetter, + hasDataGetter, + hasDataSetter, + tenantIdGetter, + patchFactory, + null, + textGetters + ); + } + + /** + * refreshCompanyIdByCompanyNameContainedInText 的增强版:支持对 CreditCompany 查询追加条件(例如仅匹配一级企业)。 + */ + @SafeVarargs + public final CompanyIdRefreshStats refreshCompanyIdByCompanyNameContainedInText(IService service, + CreditCompanyService creditCompanyService, + Integer currentTenantId, + Boolean onlyNull, + Integer limit, + SFunction idGetter, + BiConsumer idSetter, + SFunction companyIdGetter, + BiConsumer companyIdSetter, + SFunction hasDataGetter, + BiConsumer hasDataSetter, + SFunction tenantIdGetter, + Supplier patchFactory, + Consumer> companyQueryCustomizer, + SFunction... textGetters) { boolean onlyNullFlag = (onlyNull == null) || Boolean.TRUE.equals(onlyNull); if (textGetters == null || textGetters.length == 0) { return new CompanyIdRefreshStats(false, 0, 0, 0, 0); @@ -433,10 +472,14 @@ public class BatchImportSupport { } // 2.1) 构建当前租户的企业名匹配器 - List companies = creditCompanyService.lambdaQuery() + LambdaQueryChainWrapper companyQuery = creditCompanyService.lambdaQuery() .select(CreditCompany::getId, CreditCompany::getName, CreditCompany::getMatchName, CreditCompany::getTenantId) .eq(CreditCompany::getTenantId, tenantId) - .list(); + ; + if (companyQueryCustomizer != null) { + companyQueryCustomizer.accept(companyQuery); + } + List companies = companyQuery.list(); CompanyNameMatcher matcher = CompanyNameMatcher.build(companies); // 2.2) 匹配并回填 diff --git a/src/main/java/com/gxwebsoft/credit/controller/CreditJudgmentDebtorController.java b/src/main/java/com/gxwebsoft/credit/controller/CreditJudgmentDebtorController.java index 6ac8405..d42a309 100644 --- a/src/main/java/com/gxwebsoft/credit/controller/CreditJudgmentDebtorController.java +++ b/src/main/java/com/gxwebsoft/credit/controller/CreditJudgmentDebtorController.java @@ -164,12 +164,13 @@ public class CreditJudgmentDebtorController extends BaseController { @PostMapping("/company-id/refresh") public ApiResult> refreshCompanyIdByCompanyName( @RequestParam(value = "onlyNull", required = false, defaultValue = "true") Boolean onlyNull, - @RequestParam(value = "limit", required = false) Integer limit + @RequestParam(value = "limit", required = false) Integer limit, + @RequestParam(value = "topLevelOnly", required = false, defaultValue = "true") Boolean topLevelOnly ) { User loginUser = getLoginUser(); Integer currentTenantId = loginUser != null ? loginUser.getTenantId() : null; - // Party columns may contain multiple roles/names; match if any company name is contained in the text. + // Match only on "name" column: debtor.name contains a (top-level) CreditCompany name/matchName. BatchImportSupport.CompanyIdRefreshStats stats = batchImportSupport.refreshCompanyIdByCompanyNameContainedInText( creditJudgmentDebtorService, creditCompanyService, @@ -184,10 +185,15 @@ public class CreditJudgmentDebtorController extends BaseController { CreditJudgmentDebtor::setHasData, CreditJudgmentDebtor::getTenantId, CreditJudgmentDebtor::new, - // Priority: 原告/上诉人 > 被告/被上诉人 > 其他当事人/第三人; fall back to "name" if party columns are empty. - CreditJudgmentDebtor::getPlaintiffAppellant, - CreditJudgmentDebtor::getAppellee, - CreditJudgmentDebtor::getOtherPartiesThirdParty, + q -> { + if (!Boolean.TRUE.equals(topLevelOnly)) { + return; + } + // "一级企业":parentId=0(部分历史数据可能为 NULL,兼容处理) + q.and(w -> w.eq(com.gxwebsoft.credit.entity.CreditCompany::getParentId, 0) + .or() + .isNull(com.gxwebsoft.credit.entity.CreditCompany::getParentId)); + }, CreditJudgmentDebtor::getName );