package org.jeecg.modules.quartz.job;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * @author wzq
 * @date 2025/7/14 15:20
 * @description 是否教学日自动生成-定时任务
 */
@AllArgsConstructor
@Slf4j
public class OrTeachingJob implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info(" Job Execution key："+jobExecutionContext.getJobDetail().getKey());

        int year = DateUtils.getYear();

//        // 设置开始日期和结束日期
//        LocalDate beginDate = LocalDate.of(year + 1, 1, 1);
//        LocalDate endDate = LocalDate.of(year + 1, 12, 31);
//
//        // 获取开始日期和结束日期之间的所有日期
//        List<LocalDate> dateList = HolidayUtil.getDatesBetween(beginDate, endDate);
//
//        //部门、场地、教学日（teaching）、
//        //1、查询所有的学校
//        LambdaQueryWrapper<AppSite> wrapper = Wrappers.<AppSite>lambdaQuery().eq(AppSite::getType, 0).eq(AppSite::getStatus, 0);
//
//        List<AppSite> appSiteList = appSiteService.list(wrapper);
//
//        //教学日列表
//        List<AppTeachingTime> appteachingList = new ArrayList<>();
//
//        //2、遍历查询所有的学校
//        for (AppSite site : appSiteList) {
//
//            // 遍历生成一对多教学时段
//            for (LocalDate localDate : dateList) {
//
//                AppTeachingTime appTeachingTime = new AppTeachingTime();
//
//                appTeachingTime
//                        .setTenantId(site.getTenantId())
//                        //localDate 转 Date
//                        .setDay(Date.from(localDate.atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant()))
//                        .setOrgCode(site.getOrgCode())
//                ;
//
//                //格式‘yyyy-MM-dd’
//                String yearHoliday = null;
//                try {
//                    yearHoliday = HolidayUtil.isWorkingDay(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
//                } catch (ParseException e) {
//                    throw new RuntimeException(e);
//                }
//                if("0".equals(yearHoliday)){
//                    log.info("是教学日");
//                    appTeachingTime.setIsTeaching(0);
//                }else{
//                    log.info("非教学日");
//                    appTeachingTime.setIsTeaching(1);
//                }
//
//                appteachingList.add(appTeachingTime);
//            }
//                appTeachingTimeService.saveBatch(appteachingList);
//        }
//        log.info( String.format("welcome %s! 是否教学日自动生成-定时任务 OrTeachingJob !   时间:" + DateUtils.now()));
    }
}