package org.springblade.modules.api.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

import static org.springblade.modules.api.task.ConsignSchedulingTask.isStartTask;

@Component
public class ScoreSchedulingTask implements SchedulingConfigurer {

	private static final Logger log = LoggerFactory.getLogger(ScoreSchedulingTask.class);
	@Override
	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
		if(!isStartTask){
			return;
		}

		Runnable task = new Runnable() {
			@Override
			public void run() {
				String taskName = "【团队积分收益】：";
				//任务逻辑代码部分.
				log.info(taskName + "定时任务开始: " + LocalDateTime.now());
				teamScores();
				log.info(taskName + "定时任务开始: " + LocalDateTime.now());
			}
		};

		Trigger trigger = new Trigger() {
			@Override
			public Date nextExecutionTime(TriggerContext triggerContext) {
				//任务触发，可修改任务的执行周期.
				//每一次任务触发，都会执行这里的方法一次，重新获取下一次的执行时间
				//cron = timerQueryMapper.getCronTime();
				//0/5 * * * * ?
				//0 0 1 * * ?
				String cron = "0 5 1 * * ?";
				CronTrigger trigger = new CronTrigger(cron);
				return trigger.nextExecutionTime(triggerContext);
			}
		};
		taskRegistrar.addTriggerTask(task, trigger);
	}

	/**
	 * 团队积分收益
	 * 	手续费的 10%
	 * 1、直接对接人             市场
	 *   人数： 15  收益 10%      50    3%
	 *   	   30  收益 10%      100   6%
	 *   	   60  收益 10%      200   9%
	 *   	   120 收益 10%      500   12%
	 *   	   240 收益 10%      1000  15%
	 *
	 */
	private void teamScores(){



	}
}
