package org.security.trans.taskCheck.task.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.security.common.eum.FrequencyEnum;
import org.security.trans.task.entity.Task;
import org.security.trans.taskCheck.task.ITaskCheck;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author zj 2022/4/11
 * 按周
 */
@Slf4j
@AllArgsConstructor
@Service
public class ByWeekTaskCheck implements ITaskCheck {
	private final BaseTaskCheck baseTaskCheck;

	@Override
	public void handle(Task task) {
		log.info("=============任务类型[按周]开始处理==============");
		DateTime date = DateUtil.date();
		Date startDate = DateUtil.beginOfWeek(date);
		Date endDate = DateUtil.endOfWeek(date);
		baseTaskCheck.handle(task, startDate, endDate);
		log.info("=============任务类型[按周]处理结束==============");
	}

	@Override
	public boolean support(FrequencyEnum frequencyEnum) {
		return FrequencyEnum.BY_WEEK.equals(frequencyEnum);
	}
}
