package cn.iocoder.yudao.module.member.job;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.member.controller.admin.holiday.vo.HolidayDataVO;
import cn.iocoder.yudao.module.member.controller.admin.holiday.vo.HolidayVO;
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
import cn.iocoder.yudao.module.member.dal.dataobject.storebusiness.StoreBusinessDO;
import cn.iocoder.yudao.module.member.dal.mysql.business.BusinessMapper;
import cn.iocoder.yudao.module.member.dal.mysql.storebusiness.StoreBusinessMapper;
import cn.iocoder.yudao.module.member.service.holiday.HolidayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;

/**
 * @Author:qjq
 * @Date:2024/4/3 14:50
 */
@Slf4j
@Component
public class HolidayJob implements JobHandler {
    @Resource
    private HolidayService holidayService;


    /**
     * 执行任务
     *
     * @param param 参数
     * @return 结果
     * @throws Exception 异常
     */
    @Override
    @TenantIgnore
    public String execute(String param){
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();

        // 获取下一年的年份
        int year = currentDate.getYear();
        int nextYear =  year+ 1;


        String s = HttpUtil.get("https://timor.tech/api/holiday/year/"+nextYear);
        HolidayVO bean = JSONUtil.toBean(s, HolidayVO.class);

        holidayService.getNextYearData(bean);

        log.info("[execute][生成当天统计营业数据 {}条]", 1);
        return String.format("生成当天统计营业数据 %s 条   ", 1);
    }

}
