🐛 修复变更审批通过合同因多方客商名称无法选入结算单

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-06 14:48:02 +08:00
co-authored by Cursor
parent dbc7f3718b
commit c1113f869f
2 changed files with 54 additions and 14 deletions
@@ -72,6 +72,7 @@ import org.springblade.transport.service.IPreSettlementService;
import org.springblade.transport.service.IProjectApplyService;
import org.springblade.transport.service.ISettlementProjectAdvanceWriteOffService;
import org.springblade.transport.service.IWaybillService;
import org.springblade.transport.support.ContractPartySupport;
import org.springblade.transport.support.TransportBusinessSupport;
import org.springblade.transport.wrapper.PreSettlementWrapper;
import org.springblade.system.cache.UserCache;
@@ -280,10 +281,14 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
.collect(Collectors.toSet());
Map<Long, ProjectApply> projectById = projectApplyService.listByIds(projectIds).stream()
.collect(Collectors.toMap(ProjectApply::getId, Function.identity()));
// 多方客商汇总名(顿号拼接)需拆开后再匹配客商档案全称,避免变更通过后合同被误过滤
Set<String> partyNames = contracts.stream()
.flatMap(contract -> Stream.of(contract.getPartyA(), contract.getPartyB()))
.flatMap(contract -> Stream.concat(
ContractPartySupport.splitCustomerNames(contract.getPartyA()).stream(),
ContractPartySupport.splitCustomerNames(contract.getPartyB()).stream()))
.filter(Func::isNotEmpty).collect(Collectors.toSet());
Set<String> approvedCustomers = customerArchiveService.list(Wrappers.<CustomerArchive>lambdaQuery()
Set<String> approvedCustomers = partyNames.isEmpty() ? Set.of() : customerArchiveService.list(
Wrappers.<CustomerArchive>lambdaQuery()
.eq(CustomerArchive::getIsDeleted, 0)
.eq(CustomerArchive::getStatus, 1)
.eq(CustomerArchive::getApprovalStatus, "approved")
@@ -294,8 +299,8 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
ProjectApply project = projectById.get(contract.getProjectId());
return project != null && !Objects.equals(project.getIsDeleted(), 1)
&& List.of("approved", "change_approved").contains(project.getApprovalStatus())
&& approvedCustomers.contains(contract.getPartyA())
&& approvedCustomers.contains(contract.getPartyB());
&& isApprovedPartySummary(contract.getPartyA(), approvedCustomers)
&& isApprovedPartySummary(contract.getPartyB(), approvedCustomers);
})
.map(contract -> {
ProjectApply project = projectById.get(contract.getProjectId());
@@ -1424,12 +1429,29 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
}
private boolean isApprovedCustomer(String customerName) {
if (Func.isEmpty(customerName)) return false;
return customerArchiveService.count(Wrappers.<CustomerArchive>lambdaQuery()
List<String> names = ContractPartySupport.splitCustomerNames(customerName);
if (names.isEmpty()) {
return false;
}
for (String name : names) {
long count = customerArchiveService.count(Wrappers.<CustomerArchive>lambdaQuery()
.eq(CustomerArchive::getIsDeleted, 0)
.eq(CustomerArchive::getStatus, 1)
.eq(CustomerArchive::getApprovalStatus, "approved")
.eq(CustomerArchive::getFullName, customerName)) > 0;
.eq(CustomerArchive::getFullName, name));
if (count <= 0) {
return false;
}
}
return true;
}
private boolean isApprovedPartySummary(String partySummary, Set<String> approvedCustomers) {
List<String> names = ContractPartySupport.splitCustomerNames(partySummary);
if (names.isEmpty()) {
return false;
}
return names.stream().allMatch(approvedCustomers::contains);
}
private void validateContractRelations(ContractManage contract) {
@@ -548,6 +548,24 @@ public final class ContractPartySupport {
return names.isEmpty() ? null : String.join("、", names);
}
/**
* 拆分合同甲/乙/丙方汇总名称(顿号拼接的多方客商)。
*/
public static List<String> splitCustomerNames(String joinedNames) {
String text = trimToNull(joinedNames);
if (Func.isEmpty(text)) {
return List.of();
}
List<String> names = new ArrayList<>();
for (String part : text.split("、")) {
String name = trimToNull(part);
if (Func.isNotEmpty(name) && !names.contains(name)) {
names.add(name);
}
}
return names;
}
private static String toJsonOrNull(List<Map<String, Object>> rows) {
return rows == null || rows.isEmpty() ? null : JsonUtil.toJson(rows);
}