package com.cyksj.mapper.market.task;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyksj.model.entity.TaskUserCompleteRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/*
 *项目名: netflix
 *文件名: TaskUserCompleteRecordMapper
 *创建者: JavaZou
 *创建时间:2022/12/28 17:15
 */
public interface TaskUserCompleteRecordMapper extends BaseMapper<TaskUserCompleteRecord> {
	@Select("select ifnull(sum(points),0) from task_user_complete_record where task_id = #{taskId} and status = 'received' and created_time between #{beginOfDay} and #{endOfDay}")
	Integer sumTodayPoints(@Param("taskId") Long taskId, @Param("beginOfDay") DateTime beginOfDay, @Param("endOfDay") DateTime endOfDay);

	@Select("select ifnull(sum(points),0) from task_user_complete_record where task_id = #{taskId} and status = 'received'")
	Integer sumPoints(Long taskId);

	@Select("select count(distinct user_id) from task_user_complete_record where task_id = #{taskId} and created_time between #{beginOfDay} and #{endOfDay}")
	Integer getTodayCompleteNum(@Param("taskId") Long taskId, @Param("beginOfDay") DateTime beginOfDay, @Param("endOfDay") DateTime endOfDay);

	@Select("select count(distinct user_id) from task_user_complete_record where task_id = #{taskId}")
	Integer getSumCompleteNum(Long taskId);

	@Select("select ifnull(sum(balance),0) from task_user_complete_record where task_id = #{taskId} and status = 'received' and created_time between #{beginOfDay} and #{endOfDay}")
	BigDecimal sumTodayBalance(@Param("taskId") Long taskId, @Param("beginOfDay") DateTime beginOfDay, @Param("endOfDay") DateTime endOfDay);

	@Select("select ifnull(sum(balance),0) from task_user_complete_record where task_id = #{taskId} and status = 'received'")
	BigDecimal sumBalance(Long taskId);
}
