package com.hfkj.schedule;

import com.hfkj.entity.BsDiscount;
import com.hfkj.entity.CmsContent;
import com.hfkj.service.cms.CmsContentService;
import com.hfkj.service.discount.BsDiscountService;
import com.hfkj.service.discount.BsDiscountUserService;
import com.hfkj.sysenum.cms.CmsStatusEnum;
import com.hfkj.sysenum.discount.DiscountStatusEnum;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @className: DiscountSchedule
 * @author: HuRui
 * @date: 2024/9/4
 **/
@Component
public class CmsSchedule {

    @Resource
    private CmsContentService cmsContentService;

    /**
     * CMS上线
     */
    @Scheduled(cron="0 0/1 * * * ?")   //每分钟执行一次
    public void online() {
        try {
            Map<String,Object> param = new HashMap<>();
            param.put("status", CmsStatusEnum.status1.getStatus());
            param.put("startTimeE", new Date().getTime());
            List<CmsContent> list = cmsContentService.getList(param);
            for (CmsContent data : list) {
                cmsContentService.online(data.getId());
            }
        } catch (Exception e) {
            System.out.println("更新失败！！！");
        }
    }

    /**
     * CMS上线
     */
    @Scheduled(cron="0 0/1 * * * ?")   //每30分钟执行一次
    public void offline() {
        try {
            Map<String,Object> param = new HashMap<>();
            param.put("status", CmsStatusEnum.status2.getStatus());
            param.put("endTimeE", new Date().getTime());
            List<CmsContent> list = cmsContentService.getList(param);
            for (CmsContent data : list) {
                cmsContentService.offline(data.getId());
            }
        } catch (Exception e) {
            System.out.println("更新失败！！！");
        }
    }

}
