✨ 角色管理分页,并修复多甲方合同应收明细未生成

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-06 09:32:49 +08:00
parent 4ebf19de64
commit ddd65efdc4
5 changed files with 111 additions and 13 deletions
@@ -1329,6 +1329,7 @@ public class ReceivablePayableDetailServiceImpl
/**
* 应付客商取运单选择的承运商,避免写成项目内其他承运商合同的乙方。
* 应收客商优先取运单客户;多方汇总名称时改用命中计费方案绑定的甲方,避免写入顿号拼接串。
*/
private String resolveCounterpartyName(Waybill waybill, ContractManage contract, String settlementType) {
if ("payable".equals(settlementType)) {
@@ -1338,10 +1339,31 @@ public class ReceivablePayableDetailServiceImpl
}
return contract == null ? null : contract.getPartyB();
}
if (contract != null && Func.isNotEmpty(contract.getPartyA())) {
return contract.getPartyA();
String waybillCustomer = trimToNull(waybill == null ? null : waybill.getCustomerName());
if (waybillCustomer != null && !waybillCustomer.contains("、")) {
return waybillCustomer;
}
return waybill == null ? null : waybill.getCustomerName();
if (contract != null && waybill != null) {
List<Map<String, Object>> plans = billingPlansForWaybill(contract, waybill);
Map<String, Object> plan = resolveDefaultBillingPlan(plans, waybill.getTransportType());
if (plan != null) {
String planCustomer = trimToNull(stringValue(plan, "customerName"));
if (planCustomer != null) {
return planCustomer;
}
}
String firstParty = ContractPartySupport.firstPartyName(contract.getPartyAJson(), null);
if (firstParty != null) {
return firstParty;
}
}
if (contract != null) {
String partyA = trimToNull(contract.getPartyA());
if (partyA != null && !partyA.contains("、")) {
return partyA;
}
}
return waybillCustomer;
}
@Override
@@ -1486,7 +1508,8 @@ public class ReceivablePayableDetailServiceImpl
}
private String matchedPlanId(Waybill waybill, ContractManage contract) {
List<Map<String, Object>> plans = parseList(contract.getBillingPlanJson());
// 与费用计算共用客商过滤,避免多方汇总客户名先判定命中、再按客商滤空后静默跳过
List<Map<String, Object>> plans = billingPlansForWaybill(contract, waybill);
if (plans.isEmpty()) return null;
Map<String, Object> plan = resolveDefaultBillingPlan(plans, waybill.getTransportType());
if (plan == null) return null;
@@ -279,10 +279,39 @@ public final class ContractPartySupport {
if (plans.isEmpty()) {
return plans;
}
List<Map<String, Object>> matched = matchBillingPlans(plans, customerId, customerName, partyRowId);
if (!matched.isEmpty()) {
return matched;
}
// 运单客户名为合同多方汇总(顿号拼接)时,按各客商名称分别匹配绑定方案
if (Func.isEmpty(partyRowId) && customerId == null && Func.isNotEmpty(customerName) && customerName.contains("、")) {
Map<String, Map<String, Object>> deduped = new LinkedHashMap<>();
for (String part : customerName.split("、")) {
String segment = trimToNull(part);
if (Func.isEmpty(segment)) {
continue;
}
for (Map<String, Object> plan : matchBillingPlans(plans, null, segment, null)) {
deduped.putIfAbsent(billingPlanKey(plan), plan);
}
}
if (!deduped.isEmpty()) {
return new ArrayList<>(deduped.values());
}
}
// 历史方案未绑定客商时,不强制过滤,避免老数据无法计费
if (plans.stream().noneMatch(ContractPartySupport::hasCustomerBinding)) {
return plans;
}
return matched;
}
private static List<Map<String, Object>> matchBillingPlans(List<Map<String, Object>> plans, Long customerId,
String customerName, String partyRowId) {
String normalizedName = normalizePartyName(customerName);
String normalizedPartyRowId = trimToNull(partyRowId);
String customerIdText = customerId == null ? null : String.valueOf(customerId);
List<Map<String, Object>> matched = plans.stream()
return plans.stream()
.filter(plan -> {
if (Func.isNotEmpty(normalizedPartyRowId)
&& Objects.equals(trimToNull(plan.get("partyRowId")), normalizedPartyRowId)) {
@@ -296,11 +325,23 @@ public final class ContractPartySupport {
&& Objects.equals(normalizePartyName(trimToNull(plan.get("customerName"))), normalizedName);
})
.collect(Collectors.toCollection(ArrayList::new));
// 历史方案未绑定客商时,不强制过滤,避免老数据无法计费
if (matched.isEmpty() && plans.stream().noneMatch(ContractPartySupport::hasCustomerBinding)) {
return plans;
}
private static String billingPlanKey(Map<String, Object> plan) {
if (plan == null) {
return "";
}
return matched;
String id = trimToNull(plan.get("id"));
if (Func.isNotEmpty(id)) {
return id;
}
String planId = trimToNull(plan.get("planId"));
if (Func.isNotEmpty(planId)) {
return planId;
}
return String.valueOf(trimToNull(plan.get("customerName"))) + "|"
+ String.valueOf(trimToNull(plan.get("name"))) + "|"
+ String.valueOf(trimToNull(plan.get("planName")));
}
public static List<LoadingCarrierContractVO> expandCarrierOptions(Collection<ContractManage> contracts) {