/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.platform.task;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.bean.bo.PayInfoBo;
import com.yami.shop.bean.enums.OrderStatus;
import com.yami.shop.bean.model.Order;
import com.yami.shop.bean.model.OrderItem;
import com.yami.shop.bean.model.OrderSettlement;
import com.yami.shop.common.enums.PayType;
import com.yami.shop.service.*;
import com.yami.shop.service.hb.IHBOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 积分过期定时任务执行
 */
@Component("expiredPointsTask")
public class ExpiredPointsTask {


    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PointsRecordService pointsRecordService;

    /**
     * 过期积分定时任务规则
     */
    public void expiredPoints(){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 获取当天0点
        LocalDateTime todayStartLocal = LocalDate.now().atStartOfDay();
        String todayStr = todayStartLocal.format(formatter);

        //获取前一天0点
        LocalDateTime yesterday = LocalDate.now().minusDays(1).atStartOfDay();
        String yesterdayStr = yesterday.format(formatter);
        logger.info("积分过期定时任务执行开始");
        pointsRecordService.expiredPoints(todayStr,yesterdayStr);
        logger.info("积分过期定时任务执行完成");

    }

}
