单价列表重复

This commit is contained in:
秦鸿展
2026-05-13 15:47:24 +08:00
parent c60dca7fe0
commit bc2a040b80
@@ -427,8 +427,10 @@ public class ContractManageApplicationService {
/** /**
* 按单据类型取合同结算行上的计费单价(计费策略展开的 isFee 项)。 * 按单据类型取合同结算行上的计费单价(计费策略展开的 isFee 项)。
* <p>多条结算明细共用同一计费策略(accounting_strategy_id 相同)时,只展开一次策略参数 * <p>多条结算明细共用同一计费策略(与 {@link #getSubjectAndPrice} 一致:按计费策略 id 先解析 {@link BillingRulesPO}
* 避免前端出现重复单价列。</p> * 再以 {@code billing_rules_id} 取计费参数)时只展开一次,避免前端重复单价列。</p>
* <p>同一策略的参数 JSON 中若存在重复的 isFee 槽位(相同 sort/chargingId),或历史数据多套规则 id 实际等价,
* 返回列表会再做一次槽位级去重,避免出现两条「进出仓操作费单价」等同名列。</p>
*/ */
public List<SubjectAndPriceReturn> getPrice(String documentTypeCode, String settlementCustomersCode,Long organizationId,Long topOrganizationId) { public List<SubjectAndPriceReturn> getPrice(String documentTypeCode, String settlementCustomersCode,Long organizationId,Long topOrganizationId) {
List<SubjectAndPriceReturn> result = new ArrayList<>(); List<SubjectAndPriceReturn> result = new ArrayList<>();
@@ -442,48 +444,64 @@ public class ContractManageApplicationService {
.filter(item -> contractDetailContainsDocumentType(item.getDocumentTypeCode(), documentTypeCode)) .filter(item -> contractDetailContainsDocumentType(item.getDocumentTypeCode(), documentTypeCode))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (contractManageDetailPOs != null && contractManageDetailPOs.size() > 0) { if (contractManageDetailPOs != null && contractManageDetailPOs.size() > 0) {
Set<Long> expandedAccountingStrategyIds = new HashSet<>(); Set<Long> expandedBillingRulesIds = new HashSet<>();
/* 计费规则 + 公式槽位,避免参数 JSON 或多次展开重复同一单价列 */
Set<String> addedFeeSlots = new HashSet<>();
for (ContractManageDetailPO contractManageDetailPO : contractManageDetailPOs) { for (ContractManageDetailPO contractManageDetailPO : contractManageDetailPOs) {
Long accountingStrategyId = contractManageDetailPO.getAccountingStrategyId(); Long accountingStrategyId = contractManageDetailPO.getAccountingStrategyId();
if (accountingStrategyId == null || !expandedAccountingStrategyIds.add(accountingStrategyId)) { if (accountingStrategyId == null) {
continue; continue;
} }
List<BillingParamsPO> billingParams = contractManageDetailMapper.getBillingParams(accountingStrategyId); BillingRulesPO billingRulesPO = contractManageDetailMapper.getBillingRules(accountingStrategyId);
if (billingRulesPO == null || billingRulesPO.getBillingRulesId() == null) {
continue;
}
Long billingRulesId = billingRulesPO.getBillingRulesId();
if (!expandedBillingRulesIds.add(billingRulesId)) {
continue;
}
List<BillingParamsPO> billingParams = contractManageDetailMapper.getBillingParams(billingRulesId);
if (billingParams != null && billingParams.size() > 0) { if (billingParams != null && billingParams.size() > 0) {
//if (billingParams != null && billingParams.size() > 0) { BillingParamsPO billingParam = billingParams.get(0);
BillingParamsPO billingParam = billingParams.get(0); String billingParamsJson = billingParam.getBillingParamsJson();
String billingParamsJson = billingParam.getBillingParamsJson(); String preSetRules = billingParam.getPreSetRules();
String preSetRules = billingParam.getPreSetRules(); Long billingParamsId = billingParam.getBillingParamsId();
Long billingParamsId = billingParam.getBillingParamsId(); List<Map<String, Object>> preSetRulesList = JSON.parseObject(preSetRules, new TypeReference<List<Map<String, Object>>>() {});
List<Map<String, Object>> preSetRulesList = JSON.parseObject(preSetRules, new TypeReference<List<Map<String, Object>>>() {}); List<Map<String, Object>> billingParamsList = JSON.parseObject(billingParamsJson, new TypeReference<List<Map<String, Object>>>() {});
List<Map<String, Object>> billingParamsList = JSON.parseObject(billingParamsJson, new TypeReference<List<Map<String, Object>>>() {}); if (preSetRulesList != null && preSetRulesList.size() > 0 && billingParamsList != null) {
if (preSetRulesList != null && preSetRulesList.size() > 0) { Map<String, Object> stringObjectMap1 = preSetRulesList.get(0);
Map<String, Object> stringObjectMap1 = preSetRulesList.get(0); for (Map<String, Object> stringObjectMap : billingParamsList) {
for (Map<String, Object> stringObjectMap : billingParamsList) { String fieldsName = (String) stringObjectMap.get("fieldsName");
String fieldsName = (String) stringObjectMap.get("fieldsName"); String isShow = (String) stringObjectMap.get("isShow");
String isShow = (String) stringObjectMap.get("isShow"); String isFee = (String) stringObjectMap.get("isFee");
String isFee = (String) stringObjectMap.get("isFee"); String isPush = (String) stringObjectMap.get("isPush");
String isPush = (String) stringObjectMap.get("isPush"); if ("1".equals(isFee)) {
if ("1".equals(isFee)) { Integer sort = (Integer) stringObjectMap.get("sort");
Integer sort = (Integer) stringObjectMap.get("sort"); String chargingId = (String) stringObjectMap.get("chargingId");
String chargingId = (String) stringObjectMap.get("chargingId"); String fields = (String) stringObjectMap.get("fields");
String fields = (String) stringObjectMap.get("fields"); String feeSlotKey = billingRulesId + "|" + Objects.toString(sort, "") + "|" + Objects.toString(chargingId, "");
String price = (String) stringObjectMap1.get("fields" + sort); if (!addedFeeSlots.add(feeSlotKey)) {
SubjectAndPriceReturn subjectAndPriceReturn = new SubjectAndPriceReturn(); continue;
subjectAndPriceReturn.setName(fieldsName);
subjectAndPriceReturn.setPrice(new BigDecimal(price));
subjectAndPriceReturn.setChargingId(chargingId);
subjectAndPriceReturn.setFields(fields);
subjectAndPriceReturn.setBillingRulesId(accountingStrategyId);
subjectAndPriceReturn.setIsShow(isShow);
subjectAndPriceReturn.setIsFee(isFee);
subjectAndPriceReturn.setIsPush(isPush);
subjectAndPriceReturn.setRulesId(billingParamsId);
result.add(subjectAndPriceReturn);
} }
Object rawPrice = stringObjectMap1.get("fields" + sort);
if (rawPrice == null) {
continue;
}
String price = String.valueOf(rawPrice);
SubjectAndPriceReturn subjectAndPriceReturn = new SubjectAndPriceReturn();
subjectAndPriceReturn.setName(fieldsName);
subjectAndPriceReturn.setPrice(new BigDecimal(price));
subjectAndPriceReturn.setChargingId(chargingId);
subjectAndPriceReturn.setFields(fields);
subjectAndPriceReturn.setBillingRulesId(billingRulesId);
subjectAndPriceReturn.setIsShow(isShow);
subjectAndPriceReturn.setIsFee(isFee);
subjectAndPriceReturn.setIsPush(isPush);
subjectAndPriceReturn.setRulesId(billingParamsId);
result.add(subjectAndPriceReturn);
} }
} }
//} }
} else { } else {
throw new ServiceException("计费参数不存在"); throw new ServiceException("计费参数不存在");
} }