package com.talentcard.server.mapper; import java.time.LocalDateTime; import java.util.List; import java.util.Map; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.talentcard.server.entity.BenefitOrder; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @Mapper public interface MerchantSettlementStatisticsMapper extends BaseMapper { @Select(""" """) List> selectPeriodSummaries(@Param("merchantId") Long merchantId, @Param("merchantType") String merchantType, @Param("periodType") String periodType, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime, @Param("size") int size, @Param("offset") int offset); @Select(""" """) Long countPeriodSummaries(@Param("merchantId") Long merchantId, @Param("merchantType") String merchantType, @Param("periodType") String periodType, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); @Select(""" """) List> selectMerchantOverviews(@Param("merchantId") Long merchantId, @Param("merchantType") String merchantType, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); @Select(""" """) List> selectSettlementExportDetails(@Param("merchantId") Long merchantId, @Param("orderStatus") Integer orderStatus, @Param("verifyStatus") Integer verifyStatus, @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime, @Param("limit") int limit); @Select(""" select coalesce(( select sum(o.pay_amount) from benefit_order o where o.deleted = 0 and o.order_status = 1 and o.merchant_id = #{merchantId} ), 0) as transactionAmountCents, coalesce(( select count(*) from verify_record r where r.status = 1 and r.merchant_id = #{merchantId} and r.verify_time >= #{todayStart} and r.verify_time < #{todayEnd} ), 0) as todayVerificationCount, coalesce(( select count(*) from verify_record r where r.status = 1 and r.merchant_id = #{merchantId} and r.verify_time >= #{weekStart} and r.verify_time < #{weekEnd} ), 0) as weekVerificationCount, coalesce(( select sum( case when coalesce(o.subsidy_amount, 0) > 0 and (o.product_id is null or coalesce(p.is_government_subsidy, 0) = 1) then coalesce(o.subsidy_amount, 0) else 0 end + case when coalesce(o.coupon_amount, 0) > 0 and coalesce(c.government_subsidy, 0) = 1 then coalesce(o.coupon_amount, 0) else 0 end ) from benefit_order o left join merchant_product p on p.id = o.product_id and p.deleted = 0 left join merchant_coupon c on c.id = o.coupon_id and c.deleted = 0 where o.deleted = 0 and o.order_status = 1 and o.merchant_id = #{merchantId} ), 0) as subsidyAmountCents """) Map selectDashboardCards(@Param("merchantId") Long merchantId, @Param("todayStart") LocalDateTime todayStart, @Param("todayEnd") LocalDateTime todayEnd, @Param("weekStart") LocalDateTime weekStart, @Param("weekEnd") LocalDateTime weekEnd); }