package org.dromara.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.dromara.system.domain.SysIntegralHistory;

import java.util.List;
import java.util.Map;

public interface SysIntegralHistoryMapper extends BaseMapper<SysIntegralHistory> {

    @Select("SELECT " +
        "DATE_FORMAT(create_time, '%Y-%m') AS month, " +
        "SUM(CASE WHEN op_type = 1 THEN amount ELSE 0 END) AS income_amount, " +
        "SUM(CASE WHEN op_type = 2 THEN amount ELSE 0 END) AS expense_amount " +
        "FROM act_integral_history " +
        "GROUP BY DATE_FORMAT(create_time, '%Y-%m') " +
        "ORDER BY DATE_FORMAT(create_time, '%Y-%m')")
    List<Map<String, Object>> getIncomeExpense();
}
