add finance cost allocation detail

This commit is contained in:
2026-08-12 14:40:05 +08:00
parent fcb7c11af4
commit c4e6c28da0
4 changed files with 41 additions and 2 deletions
@@ -162,6 +162,12 @@ public class PlatformFinanceController {
return FinanceResponses.success(queryService.payableSettlements(customerId));
}
@GetMapping("/cost-entries/{costId}")
@PreAuthorize("hasAuthority('platform:finance:cost:view')")
public ApiResponse<?> cost(@PathVariable long costId, @RequestParam long customerId) {
return FinanceResponses.success(queryService.cost(customerId, costId));
}
@PostMapping("/cost-entries")
@PreAuthorize("hasAuthority('platform:finance:cost:create')")
@BusinessAudit(event = "FINANCE_COST_CREATE", resourceType = "FINANCE_COST")
@@ -102,6 +102,19 @@ public final class FinanceReadModels {
LocalDateTime createdAt,
int version) {}
public record CostDetail(PayableSettlement cost, List<CostAllocation> allocations) {}
public record CostAllocation(
long id,
long costId,
long orderId,
Long inboundId,
BigDecimal volumeCbm,
BigDecimal totalVolumeCbm,
BigDecimal allocationRate,
BigDecimal allocatedAmount,
boolean roundingAdjustment) {}
/** Client-safe receipt view. Voucher and operator/internal fields are deliberately absent. */
public record ClientReceipt(
long id,
@@ -7,6 +7,8 @@ import com.baiyue.finance.dto.FinanceReadModels.ClientReceipt;
import com.baiyue.finance.dto.FinanceReadModels.ClientReceiptAllocation;
import com.baiyue.finance.dto.FinanceReadModels.BillRevision;
import com.baiyue.finance.dto.FinanceReadModels.CustomerAccount;
import com.baiyue.finance.dto.FinanceReadModels.CostAllocation;
import com.baiyue.finance.dto.FinanceReadModels.CostDetail;
import com.baiyue.finance.dto.FinanceReadModels.FeePoolItem;
import com.baiyue.finance.dto.FinanceReadModels.PayableSettlement;
import com.baiyue.finance.dto.FinanceReadModels.PlatformReceipt;
@@ -143,6 +145,19 @@ public class FinanceQueryService {
}, customerId);
}
public CostDetail cost(long customerId, long costId) {
PayableSettlement cost = payableSettlements(customerId).stream()
.filter(item -> item.id() == costId).findFirst()
.orElseThrow(() -> new BizException(ResultCode.NOT_FOUND, "成本不存在或不属于客户"));
List<CostAllocation> allocations = jdbc.query(
"SELECT id,cost_id,order_id,inbound_id,volume_cbm,total_volume_cbm,allocation_rate,allocated_amount,rounding_adjustment FROM fin_cost_allocation WHERE tenant_id=? AND cost_id=? ORDER BY id",
(rs, rowNum) -> new CostAllocation(rs.getLong("id"), rs.getLong("cost_id"), rs.getLong("order_id"),
nullableLong(rs, "inbound_id"), rs.getBigDecimal("volume_cbm"), rs.getBigDecimal("total_volume_cbm"),
rs.getBigDecimal("allocation_rate"), rs.getBigDecimal("allocated_amount"), rs.getBoolean("rounding_adjustment")),
customerId, costId);
return new CostDetail(cost, allocations);
}
public List<ClientReceipt> clientReceipts(long customerId) {
requireCustomer(customerId);
return jdbc.query("SELECT id,receipt_no,received_amount,received_at,payment_method,currency_code,status FROM fin_receipt WHERE tenant_id=? AND status='CONFIRMED' ORDER BY received_at DESC,id DESC",