package com.fzm.mall.server.admin.task.goods;

import com.fzm.mall.server.admin.goods_center.enums.status.SpuStatusEnum;
import com.fzm.mall.server.admin.goods_center.model.Spu;
import com.fzm.mall.server.admin.goods_center.service.ISpuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wangp
 * @date 2021/6/18 10:43
 * @description 订单定时任务
 * @since JDK 1.8
 */
@Component
@Slf4j
@Transactional
public class GoodsTask {

    @Autowired
    private ISpuService spuService;

    //预热商品上架
    @Scheduled(cron = "10 * * * * ?")
    public void yrsj() {
        List<Spu> spuList = spuService.listForPreheat();

        spuList.forEach(v -> {
            if (v.getPreheatEndTime() < System.currentTimeMillis()) {
                //修改状态为上架
                spuService.updateStatus(v.getGoodsId(), SpuStatusEnum.ON.getStatus(), "");
            }
        });
    }

}
