package com.ruoyi.novel.mapper;

// RoyaltySummaryMapper.java
@Mapper
public interface RoyaltySummaryMapper extends BaseMapper<RoyaltySummary> {

    @Select("SELECT * FROM novel_royalty_summary " +
            "WHERE author_id = #{authorId} AND month = #{month}")
    RoyaltySummary selectByAuthorAndMonth(
            @Param("authorId") Long authorId,
            @Param("month") String month
    );

    @Update("INSERT INTO novel_royalty_summary (author_id, month, total_reads, last_sync_time) " +
            "VALUES (#{authorId}, #{month}, #{totalReads}, NOW()) " +
            "ON DUPLICATE KEY UPDATE total_reads = #{totalReads}, last_sync_time = NOW()")
    int upsertSummary(RoyaltySummary summary);
}