package org.dromara.web.mapper;

import org.apache.ibatis.annotations.Select;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.web.domain.ChargeRecord;
import org.dromara.web.domain.vo.ChargeRecordTotalizeVo;
import org.dromara.web.domain.vo.ChargeRecordVo;
import org.springframework.stereotype.Repository;

/**
 * 收费记录Mapper接口
 *
 * @author Lion Li
 * @date 2025-08-06
 */
@Repository
public interface ChargeRecordMapper extends BaseMapperPlus<ChargeRecord, ChargeRecordVo> {

    @Select(
        """
        SELECT
            SUM(CASE WHEN whether_invoice = 0 THEN funds_received ELSE 0 END) AS availableAmount,
            SUM(CASE WHEN whether_invoice = 1 THEN funds_received ELSE 0 END) AS invoicedAmount,
            COUNT(CASE WHEN whether_invoice = 1 THEN 1 END) AS count
        FROM charge_record;
        """
    )
    ChargeRecordTotalizeVo totalize();
}
