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

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.IProjectApplyService;
import org.springblade.transport.service.ISettlementProjectAdvanceWriteOffService; import org.springblade.transport.service.ISettlementProjectAdvanceWriteOffService;
import org.springblade.transport.service.IWaybillService; import org.springblade.transport.service.IWaybillService;
import org.springblade.transport.support.ContractPartySupport;
import org.springblade.transport.support.TransportBusinessSupport; import org.springblade.transport.support.TransportBusinessSupport;
import org.springblade.transport.wrapper.PreSettlementWrapper; import org.springblade.transport.wrapper.PreSettlementWrapper;
import org.springblade.system.cache.UserCache; import org.springblade.system.cache.UserCache;
@@ -280,22 +281,26 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Map<Long, ProjectApply> projectById = projectApplyService.listByIds(projectIds).stream() Map<Long, ProjectApply> projectById = projectApplyService.listByIds(projectIds).stream()
.collect(Collectors.toMap(ProjectApply::getId, Function.identity())); .collect(Collectors.toMap(ProjectApply::getId, Function.identity()));
// 多方客商汇总名(顿号拼接)需拆开后再匹配客商档案全称,避免变更通过后合同被误过滤
Set<String> partyNames = contracts.stream() 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()); .filter(Func::isNotEmpty).collect(Collectors.toSet());
Set<String> approvedCustomers = customerArchiveService.list(Wrappers.<CustomerArchive>lambdaQuery() Set<String> approvedCustomers = partyNames.isEmpty() ? Set.of() : customerArchiveService.list(
.eq(CustomerArchive::getIsDeleted, 0) Wrappers.<CustomerArchive>lambdaQuery()
.eq(CustomerArchive::getStatus, 1) .eq(CustomerArchive::getIsDeleted, 0)
.eq(CustomerArchive::getApprovalStatus, "approved") .eq(CustomerArchive::getStatus, 1)
.in(CustomerArchive::getFullName, partyNames)) .eq(CustomerArchive::getApprovalStatus, "approved")
.in(CustomerArchive::getFullName, partyNames))
.stream().map(CustomerArchive::getFullName).collect(Collectors.toSet()); .stream().map(CustomerArchive::getFullName).collect(Collectors.toSet());
return contracts.stream() return contracts.stream()
.filter(contract -> { .filter(contract -> {
ProjectApply project = projectById.get(contract.getProjectId()); ProjectApply project = projectById.get(contract.getProjectId());
return project != null && !Objects.equals(project.getIsDeleted(), 1) return project != null && !Objects.equals(project.getIsDeleted(), 1)
&& List.of("approved", "change_approved").contains(project.getApprovalStatus()) && List.of("approved", "change_approved").contains(project.getApprovalStatus())
&& approvedCustomers.contains(contract.getPartyA()) && isApprovedPartySummary(contract.getPartyA(), approvedCustomers)
&& approvedCustomers.contains(contract.getPartyB()); && isApprovedPartySummary(contract.getPartyB(), approvedCustomers);
}) })
.map(contract -> { .map(contract -> {
ProjectApply project = projectById.get(contract.getProjectId()); ProjectApply project = projectById.get(contract.getProjectId());
@@ -1424,12 +1429,29 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
} }
private boolean isApprovedCustomer(String customerName) { private boolean isApprovedCustomer(String customerName) {
if (Func.isEmpty(customerName)) return false; List<String> names = ContractPartySupport.splitCustomerNames(customerName);
return customerArchiveService.count(Wrappers.<CustomerArchive>lambdaQuery() if (names.isEmpty()) {
.eq(CustomerArchive::getIsDeleted, 0) return false;
.eq(CustomerArchive::getStatus, 1) }
.eq(CustomerArchive::getApprovalStatus, "approved") for (String name : names) {
.eq(CustomerArchive::getFullName, customerName)) > 0; long count = customerArchiveService.count(Wrappers.<CustomerArchive>lambdaQuery()
.eq(CustomerArchive::getIsDeleted, 0)
.eq(CustomerArchive::getStatus, 1)
.eq(CustomerArchive::getApprovalStatus, "approved")
.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) { private void validateContractRelations(ContractManage contract) {
@@ -548,6 +548,24 @@ public final class ContractPartySupport {
return names.isEmpty() ? null : String.join("、", names); 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) { private static String toJsonOrNull(List<Map<String, Object>> rows) {
return rows == null || rows.isEmpty() ? null : JsonUtil.toJson(rows); return rows == null || rows.isEmpty() ? null : JsonUtil.toJson(rows);
} }