This commit is contained in:
2026-09-03 21:34:28 +08:00
2 changed files with 6 additions and 8 deletions
@@ -108,7 +108,8 @@ public class InboundMeasurementService {
request.items().stream().map(InboundMeasurementRequests.ItemRequest::chargeRuleId)
.filter(java.util.Objects::nonNull).distinct().forEach(ruleId -> {
var rule = fbaMasterDataService.rule(tenantId, ruleId);
if (!"ACTIVE".equals(rule.getStatus()) || !java.util.Objects.equals(rule.getCustomerId(), inbound.getCustomerId())) {
long inboundCustomerId = inbound.getCustomerId() == null ? tenantId : inbound.getCustomerId();
if (!"ACTIVE".equals(rule.getStatus()) || !java.util.Objects.equals(rule.getCustomerId(), inboundCustomerId)) {
throw new BizException(ResultCode.VALIDATION_FAILED, "测量明细绑定的计费规则不属于当前客户或已停用");
}
});
@@ -263,16 +263,13 @@ public class MeasurementBatchService {
}
private CustomerChargeRuleEntity requireCoefficientRule(long tenantId, Long customerId, Long ruleId) {
if (customerId == null || customerId <= 0) {
if (ruleId == null) return null;
throw new BizException(ResultCode.VALIDATION_FAILED, "入库单客户无效,不能应用计费系数");
}
Long effectiveCustomerId = customerId == null || customerId <= 0 ? tenantId : customerId;
CustomerChargeRuleEntity rule = ruleId == null
? pricingRepository.findDefaultRule(tenantId, customerId)
? pricingRepository.findDefaultRule(tenantId, effectiveCustomerId)
: pricingRepository.findRule(tenantId, ruleId);
if (rule == null || !"ACTIVE".equals(rule.getStatus())
|| !Boolean.TRUE.equals(rule.getDefaultRule()) || !customerId.equals(rule.getCustomerId())) {
throw new BizException(ResultCode.VALIDATION_FAILED, "计费规则不属于当前客户、未启用或未设置默认规则");
|| !effectiveCustomerId.equals(rule.getCustomerId())) {
throw new BizException(ResultCode.VALIDATION_FAILED, "计费规则不属于当前客户或已停用");
}
return rule;
}