package com.palmnest.webapp.quartz;

import com.palmnest.application.core.util.DateHelper;
import com.palmnest.service.dinner.service.PlaceAnOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * 自动充值
 * 每个月1号2点充值所有用户的积分 充值本月内的积分数  2020-03-30日弃用
 * 改用  每周一0点10分执行一次充值积分
 * 充值本周内的积分数
 * 0 10 0 ? * MON
 *
 * @author longmeizhen
 */
@Slf4j
@Component("orderDinnerRechargeTimerTask")
public class OrderDinnerRechargeTimerTask {


	@Autowired
	private PlaceAnOrderService placeAnOrderService;

	private void run() {

		log.info("quartz into OrderDinnerRechargeTimerTask start ...");
		log.info("--------placeAnOrderService.automaticRecharge start ...");

		SimpleDateFormat sdf  = new SimpleDateFormat(DateHelper.TIME_HOUR_MINUTE);
		Calendar         cal  = Calendar.getInstance();
		String           time = sdf.format(cal.getTime());

		log.info("quartz into OrderDinnerRechargeTimerTask time:" + time);

		//当前获取的时间等于00:10分时才执行  避免修改系统时间导致重复执行的问题
		if ("00:10".equals(time)) {
			placeAnOrderService.automaticRecharge();
		}

		log.info("quartz into OrderDinnerRechargeTimerTask end ...");
	}
}
