package org.security.trans.taskCheck.busi;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.security.common.Constant;
import org.security.common.util.DataFormatUtil;
import org.security.ht.entity.basic.Device;
import org.security.trans.applyAndReport.entity.NoteRemind;
import org.security.trans.applyAndReport.service.INoteRemindService;
import org.springblade.core.tool.utils.Func;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author nantian.yangzhengyu
 * @date 2023/1/5 16:08
 */
@Slf4j
@Component
@AllArgsConstructor
public class NoteRemindCheck {
	private final INoteRemindService noteRemindService;
	/**
	 *检查工作提醒是否超过提醒结束日期
	 */
	@Async("securityThreadPool")
	@Scheduled(cron = "0 0 1 * * ?")
	public void noteRemindStateCheck() throws ParseException {
		log.info("=============检查【工作提醒是否超过提醒结束日期】 开始处理=============");
		List<NoteRemind> noteReminds = noteRemindService.getUsingList();
		ArrayList<NoteRemind> noteRemindsChecks = new ArrayList<>();
		Date today = DataFormatUtil.getLocalDate();
		if (Func.isNotEmpty(noteReminds)) {
			noteReminds.forEach(item -> {
				if (Func.isNotEmpty(item.getEndTime()) && today.after(item.getEndTime())) {
					item.setState(Constant.REMINDER_STATE_END);
					noteRemindsChecks.add(item);
				}
			});
			noteRemindService.updateBatchById(noteRemindsChecks);
		}
		log.info("=============检查【工作提醒是否超过提醒结束日期】 处理结束=============");
	}
}
