144 lines
7.0 KiB
Java
144 lines
7.0 KiB
Java
package com.baiyue.finance.mapper;
|
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Select;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.List;
|
|
|
|
@Mapper
|
|
public interface FinanceContainerSettlementQueryMapper {
|
|
|
|
@Select("""
|
|
SELECT COUNT(*) AS customerLinkCount
|
|
FROM (
|
|
SELECT customer_id, container_booking_id AS container_id FROM fin_fee_source
|
|
WHERE customer_id = #{customerId} AND container_booking_id = #{containerBookingId}
|
|
UNION ALL
|
|
SELECT tenant_id AS customer_id, container_id FROM fin_cost
|
|
WHERE tenant_id = #{customerId} AND container_id = #{containerBookingId}
|
|
) links
|
|
""")
|
|
OwnershipRow ownership(@Param("customerId") long customerId,
|
|
@Param("containerBookingId") long containerBookingId);
|
|
|
|
@Select("""
|
|
SELECT DISTINCT settled.source_fee_id
|
|
FROM (
|
|
SELECT f.source_fee_id
|
|
FROM fin_settlement s
|
|
JOIN fin_settlement_line sl ON sl.tenant_id = s.tenant_id AND sl.settlement_id = s.id
|
|
JOIN fin_fee_source f ON f.id = sl.fee_source_id AND f.customer_id = sl.tenant_id
|
|
WHERE s.tenant_id = #{customerId}
|
|
AND s.status = 'PAID'
|
|
AND f.customer_id = #{customerId}
|
|
AND f.container_booking_id = #{containerBookingId}
|
|
AND f.source_system = 'FIRSTLEG'
|
|
AND f.source_type = 'CONTAINER_FEE'
|
|
UNION ALL
|
|
SELECT c.source_fee_id
|
|
FROM fin_cost c
|
|
WHERE c.tenant_id = #{customerId}
|
|
AND c.container_id = #{containerBookingId}
|
|
AND c.cost_origin = 'FIRSTLEG_DIRECT_PAID'
|
|
AND c.source_system = 'FIRSTLEG'
|
|
AND c.source_type = 'CONTAINER_FEE'
|
|
AND c.status = 'CONFIRMED'
|
|
AND c.source_fee_id IS NOT NULL
|
|
) settled
|
|
ORDER BY settled.source_fee_id
|
|
""")
|
|
List<Long> settledSourceFeeIds(@Param("customerId") long customerId,
|
|
@Param("containerBookingId") long containerBookingId);
|
|
|
|
@Select("""
|
|
SELECT c.id AS costId, c.cost_no AS costNo, c.cost_type AS costType, c.cost_origin AS costOrigin,
|
|
c.source_fee_id AS sourceFeeId, c.source_fee_version AS sourceFeeVersion,
|
|
c.container_id AS containerBookingId, c.supplier_name_snapshot AS supplierName,
|
|
c.fee_item_name AS feeItemName, c.cost_amount AS amount, c.currency_code AS currency,
|
|
c.status,
|
|
a.id AS allocationId, a.order_id AS orderId, a.inbound_id AS inboundId,
|
|
a.volume_cbm AS volumeCbm, a.total_volume_cbm AS totalVolumeCbm,
|
|
a.allocation_rate AS allocationRate, a.allocated_amount AS allocatedAmount,
|
|
a.rounding_adjustment AS roundingAdjustment
|
|
FROM fin_cost c
|
|
LEFT JOIN fin_cost_allocation a ON a.tenant_id = c.tenant_id AND a.cost_id = c.id
|
|
WHERE c.tenant_id = #{customerId} AND c.container_id = #{containerBookingId}
|
|
ORDER BY c.created_at DESC, c.id DESC, a.id
|
|
""")
|
|
List<CostAllocationRow> costs(@Param("customerId") long customerId,
|
|
@Param("containerBookingId") long containerBookingId);
|
|
|
|
final class OwnershipRow {
|
|
private long customerLinkCount;
|
|
|
|
public long getCustomerLinkCount() { return customerLinkCount; }
|
|
public void setCustomerLinkCount(long value) { this.customerLinkCount = value; }
|
|
}
|
|
|
|
final class CostAllocationRow {
|
|
private long costId;
|
|
private String costNo;
|
|
private String costType;
|
|
private String costOrigin;
|
|
private Long sourceFeeId;
|
|
private Integer sourceFeeVersion;
|
|
private long containerBookingId;
|
|
private String supplierName;
|
|
private String feeItemName;
|
|
private BigDecimal amount;
|
|
private String currency;
|
|
private String status;
|
|
private Long allocationId;
|
|
private Long orderId;
|
|
private Long inboundId;
|
|
private BigDecimal volumeCbm;
|
|
private BigDecimal totalVolumeCbm;
|
|
private BigDecimal allocationRate;
|
|
private BigDecimal allocatedAmount;
|
|
private boolean roundingAdjustment;
|
|
|
|
public long getCostId() { return costId; }
|
|
public void setCostId(long value) { this.costId = value; }
|
|
public String getCostNo() { return costNo; }
|
|
public void setCostNo(String value) { this.costNo = value; }
|
|
public String getCostType() { return costType; }
|
|
public void setCostType(String value) { this.costType = value; }
|
|
public String getCostOrigin() { return costOrigin; }
|
|
public void setCostOrigin(String value) { this.costOrigin = value; }
|
|
public Long getSourceFeeId() { return sourceFeeId; }
|
|
public void setSourceFeeId(Long value) { this.sourceFeeId = value; }
|
|
public Integer getSourceFeeVersion() { return sourceFeeVersion; }
|
|
public void setSourceFeeVersion(Integer value) { this.sourceFeeVersion = value; }
|
|
public long getContainerBookingId() { return containerBookingId; }
|
|
public void setContainerBookingId(long value) { this.containerBookingId = value; }
|
|
public String getSupplierName() { return supplierName; }
|
|
public void setSupplierName(String value) { this.supplierName = value; }
|
|
public String getFeeItemName() { return feeItemName; }
|
|
public void setFeeItemName(String value) { this.feeItemName = value; }
|
|
public BigDecimal getAmount() { return amount; }
|
|
public void setAmount(BigDecimal value) { this.amount = value; }
|
|
public String getCurrency() { return currency; }
|
|
public void setCurrency(String value) { this.currency = value; }
|
|
public String getStatus() { return status; }
|
|
public void setStatus(String value) { this.status = value; }
|
|
public Long getAllocationId() { return allocationId; }
|
|
public void setAllocationId(Long value) { this.allocationId = value; }
|
|
public Long getOrderId() { return orderId; }
|
|
public void setOrderId(Long value) { this.orderId = value; }
|
|
public Long getInboundId() { return inboundId; }
|
|
public void setInboundId(Long value) { this.inboundId = value; }
|
|
public BigDecimal getVolumeCbm() { return volumeCbm; }
|
|
public void setVolumeCbm(BigDecimal value) { this.volumeCbm = value; }
|
|
public BigDecimal getTotalVolumeCbm() { return totalVolumeCbm; }
|
|
public void setTotalVolumeCbm(BigDecimal value) { this.totalVolumeCbm = value; }
|
|
public BigDecimal getAllocationRate() { return allocationRate; }
|
|
public void setAllocationRate(BigDecimal value) { this.allocationRate = value; }
|
|
public BigDecimal getAllocatedAmount() { return allocatedAmount; }
|
|
public void setAllocatedAmount(BigDecimal value) { this.allocatedAmount = value; }
|
|
public boolean isRoundingAdjustment() { return roundingAdjustment; }
|
|
public void setRoundingAdjustment(boolean value) { this.roundingAdjustment = value; }
|
|
}
|
|
}
|