feat(controller): 批量导入支持新增企业查询条件定制功能
- 在 BatchImportSupport 中添加了新的重载方法 refreshCompanyIdByCompanyNameContainedInText - 新增 companyQueryCustomizer 参数用于自定义 CreditCompany 查询条件 - 在 CreditJudgmentDebtorController 中添加 topLevelOnly 参数控制是否只匹配一级企业 - 支持通过 parentId 条件过滤一级企业(parentId=0 或 NULL) - 优化了企业名称匹配逻辑,专注于 name 字段进行匹配
This commit is contained in:
@@ -2,6 +2,7 @@ package com.gxwebsoft.credit.controller;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
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.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.gxwebsoft.credit.entity.CreditCompany;
|
import com.gxwebsoft.credit.entity.CreditCompany;
|
||||||
import com.gxwebsoft.credit.service.CreditCompanyService;
|
import com.gxwebsoft.credit.service.CreditCompanyService;
|
||||||
@@ -363,6 +364,44 @@ public class BatchImportSupport {
|
|||||||
SFunction<T, Integer> tenantIdGetter,
|
SFunction<T, Integer> tenantIdGetter,
|
||||||
Supplier<T> patchFactory,
|
Supplier<T> patchFactory,
|
||||||
SFunction<T, String>... textGetters) {
|
SFunction<T, String>... textGetters) {
|
||||||
|
return refreshCompanyIdByCompanyNameContainedInText(
|
||||||
|
service,
|
||||||
|
creditCompanyService,
|
||||||
|
currentTenantId,
|
||||||
|
onlyNull,
|
||||||
|
limit,
|
||||||
|
idGetter,
|
||||||
|
idSetter,
|
||||||
|
companyIdGetter,
|
||||||
|
companyIdSetter,
|
||||||
|
hasDataGetter,
|
||||||
|
hasDataSetter,
|
||||||
|
tenantIdGetter,
|
||||||
|
patchFactory,
|
||||||
|
null,
|
||||||
|
textGetters
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* refreshCompanyIdByCompanyNameContainedInText 的增强版:支持对 CreditCompany 查询追加条件(例如仅匹配一级企业)。
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public final <T> CompanyIdRefreshStats refreshCompanyIdByCompanyNameContainedInText(IService<T> service,
|
||||||
|
CreditCompanyService creditCompanyService,
|
||||||
|
Integer currentTenantId,
|
||||||
|
Boolean onlyNull,
|
||||||
|
Integer limit,
|
||||||
|
SFunction<T, Integer> idGetter,
|
||||||
|
BiConsumer<T, Integer> idSetter,
|
||||||
|
SFunction<T, Integer> companyIdGetter,
|
||||||
|
BiConsumer<T, Integer> companyIdSetter,
|
||||||
|
SFunction<T, Boolean> hasDataGetter,
|
||||||
|
BiConsumer<T, Boolean> hasDataSetter,
|
||||||
|
SFunction<T, Integer> tenantIdGetter,
|
||||||
|
Supplier<T> patchFactory,
|
||||||
|
Consumer<LambdaQueryChainWrapper<CreditCompany>> companyQueryCustomizer,
|
||||||
|
SFunction<T, String>... textGetters) {
|
||||||
boolean onlyNullFlag = (onlyNull == null) || Boolean.TRUE.equals(onlyNull);
|
boolean onlyNullFlag = (onlyNull == null) || Boolean.TRUE.equals(onlyNull);
|
||||||
if (textGetters == null || textGetters.length == 0) {
|
if (textGetters == null || textGetters.length == 0) {
|
||||||
return new CompanyIdRefreshStats(false, 0, 0, 0, 0);
|
return new CompanyIdRefreshStats(false, 0, 0, 0, 0);
|
||||||
@@ -433,10 +472,14 @@ public class BatchImportSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2.1) 构建当前租户的企业名匹配器
|
// 2.1) 构建当前租户的企业名匹配器
|
||||||
List<CreditCompany> companies = creditCompanyService.lambdaQuery()
|
LambdaQueryChainWrapper<CreditCompany> companyQuery = creditCompanyService.lambdaQuery()
|
||||||
.select(CreditCompany::getId, CreditCompany::getName, CreditCompany::getMatchName, CreditCompany::getTenantId)
|
.select(CreditCompany::getId, CreditCompany::getName, CreditCompany::getMatchName, CreditCompany::getTenantId)
|
||||||
.eq(CreditCompany::getTenantId, tenantId)
|
.eq(CreditCompany::getTenantId, tenantId)
|
||||||
.list();
|
;
|
||||||
|
if (companyQueryCustomizer != null) {
|
||||||
|
companyQueryCustomizer.accept(companyQuery);
|
||||||
|
}
|
||||||
|
List<CreditCompany> companies = companyQuery.list();
|
||||||
CompanyNameMatcher matcher = CompanyNameMatcher.build(companies);
|
CompanyNameMatcher matcher = CompanyNameMatcher.build(companies);
|
||||||
|
|
||||||
// 2.2) 匹配并回填
|
// 2.2) 匹配并回填
|
||||||
|
|||||||
@@ -164,12 +164,13 @@ public class CreditJudgmentDebtorController extends BaseController {
|
|||||||
@PostMapping("/company-id/refresh")
|
@PostMapping("/company-id/refresh")
|
||||||
public ApiResult<Map<String, Object>> refreshCompanyIdByCompanyName(
|
public ApiResult<Map<String, Object>> refreshCompanyIdByCompanyName(
|
||||||
@RequestParam(value = "onlyNull", required = false, defaultValue = "true") Boolean onlyNull,
|
@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();
|
User loginUser = getLoginUser();
|
||||||
Integer currentTenantId = loginUser != null ? loginUser.getTenantId() : null;
|
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(
|
BatchImportSupport.CompanyIdRefreshStats stats = batchImportSupport.refreshCompanyIdByCompanyNameContainedInText(
|
||||||
creditJudgmentDebtorService,
|
creditJudgmentDebtorService,
|
||||||
creditCompanyService,
|
creditCompanyService,
|
||||||
@@ -184,10 +185,15 @@ public class CreditJudgmentDebtorController extends BaseController {
|
|||||||
CreditJudgmentDebtor::setHasData,
|
CreditJudgmentDebtor::setHasData,
|
||||||
CreditJudgmentDebtor::getTenantId,
|
CreditJudgmentDebtor::getTenantId,
|
||||||
CreditJudgmentDebtor::new,
|
CreditJudgmentDebtor::new,
|
||||||
// Priority: 原告/上诉人 > 被告/被上诉人 > 其他当事人/第三人; fall back to "name" if party columns are empty.
|
q -> {
|
||||||
CreditJudgmentDebtor::getPlaintiffAppellant,
|
if (!Boolean.TRUE.equals(topLevelOnly)) {
|
||||||
CreditJudgmentDebtor::getAppellee,
|
return;
|
||||||
CreditJudgmentDebtor::getOtherPartiesThirdParty,
|
}
|
||||||
|
// "一级企业":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
|
CreditJudgmentDebtor::getName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user