package com.cyksj.mapper.market.sign;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyksj.model.entity.UserPointsRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

public interface UserPointsRecordMapper extends BaseMapper<UserPointsRecord> {
	@Update("update user set active_points = active_points + #{points} where id = #{userId}")
	void updateUserPoints(@Param("userId") Long userId, @Param("points") Integer points);

	@Select("select ifnull(sum(points),0) from user_points_record ur where created_time between #{yesZeroDate} and #{thisZeroDate} and points > 0")
	Integer getTodayNumOfPoints(@Param("yesZeroDate") Date yesZeroDate, @Param("thisZeroDate") Date thisZeroDate);

	@Select("select ifnull(sum(points),0) from user_points_record ur where points > 0")
	Integer getSumOfPoints();

	@Select("select ifnull(sum(points),0) from user_points_record ur where created_time between #{yesZeroDate} and #{thisZeroDate} and points < 0")
	Integer getTodayUseOfPoints(@Param("yesZeroDate") Date yesZeroDate, @Param("thisZeroDate") Date thisZeroDate);

	@Select("select ifnull(sum(points),0) from user_points_record ur where points < 0")
	Integer getSumUseOfPoints();

	@Select("select count(*) from user_points_record ur where created_time between #{yesZeroDate} and #{thisZeroDate} and points < 0 and remark = #{remark}")
	Integer getTodayNumOfLottery(@Param("remark") String remark, @Param("yesZeroDate") Date yesZeroDate, @Param("thisZeroDate") Date thisZeroDate);

	@Select("select count(*) from sign_user where update_time between #{yesZeroDate} and #{thisZeroDate} and day_period = #{dayPeriod}")
	Integer getSignDayByCondition(@Param("dayPeriod") Integer dayPeriod, @Param("yesZeroDate") Date yesZeroDate, @Param("thisZeroDate") Date thisZeroDate);
}
