Pārlūkot izejas kodu

feat(schedule): 新增定时任务生成未来七天执行计划

- 在 `IScheduleConfigService` 接口中新增 `generateExecutionPlanTask` 方法,用于生成未来一周的执行计划
- 实现类 `ScheduleConfigServiceImpl` 中添加对应实现逻辑,并根据 schemeCode 类型处理不同生成策略- 添加 Mapper 方法 `selectAllScheduleUseConfigs` 查询所有启用的配置项,支持定时任务获取数据源
- 在 `ScheduleExecutionMapper` 中增加去重查询方法 `findTodayPendingExecutionsExit`,避免重复插入执行记录
- 定时任务 `ScheduleTask` 新增 `generateNextSevenDayTask` 方法,每日凌晨执行,为每个启用的配置生成未来七天的执行计划
- 调整部分定时任务执行时间,避免冲突
- 修复盲注结构和报名条件更新时可能存在的空指针问题,增加判空处理
- 更新相关 Mapper XML 文件,补充 SQL 查询语句及字段映射
fugui001 3 mēneši atpakaļ
vecāks
revīzija
e2867a05d5

+ 3 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/ScheduleConfigMapper.java

@@ -77,4 +77,7 @@ public interface ScheduleConfigMapper extends BaseMapperPlus<ScheduleConfig, Sch
     @InterceptorIgnore(tenantLine = "true")
     int selExitConfigByTemplateId(@Param("templateId") Long templateId);
 
+    @InterceptorIgnore(tenantLine = "true")
+    List<ScheduleConfigVo> selectAllScheduleUseConfigs();
+
 }

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/ScheduleExecutionMapper.java

@@ -8,6 +8,7 @@ import org.dromara.business.domain.vo.ScheduleExecutionVo;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 
 import java.time.LocalDate;
+import java.time.LocalTime;
 import java.util.List;
 
 /**
@@ -33,4 +34,8 @@ public interface ScheduleExecutionMapper extends BaseMapperPlus<ScheduleExecutio
     @InterceptorIgnore(tenantLine = "true")
     int deleteScheduleExecutionByConfigId(@Param("configId") Long configId);
 
+    @InterceptorIgnore(tenantLine = "true")
+    ScheduleExecutionVo findTodayPendingExecutionsExit(@Param("dates") LocalDate dates, @Param("executionTime") LocalTime executionTime, @Param("configId") Long configId);
+
+
 }

+ 16 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/IScheduleConfigService.java

@@ -8,6 +8,7 @@ import org.dromara.common.core.domain.R;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.mybatis.core.page.PageQuery;
 
+import java.time.LocalDate;
 import java.time.LocalTime;
 import java.util.Collection;
 import java.util.List;
@@ -120,6 +121,21 @@ public interface IScheduleConfigService {
      */
     Boolean stopScheduleConfig(Long configId,int type);
 
+    /**
+     * 生成未来一周的执行 schedule_execution
+      * @param configId
+     * @param schemeCode
+     * @param startDate
+     * @param endDate
+     * @param repeatTypes
+     * @param execTimes
+     */
+    void generateExecutionPlanTask( Long configId,
+                                    String schemeCode,
+                                    LocalDate startDate,
+                                    LocalDate endDate,
+                                    List<String> repeatTypes,
+                                    List<LocalTime> execTimes);
 
 
 }

+ 28 - 4
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/ScheduleConfigServiceImpl.java

@@ -209,8 +209,8 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
         }
 
 
-        // 6. ✅ 预生成执行计划
-        generateExecutionPlan(configId, dto.getCreationSchemeCode(), startDate, endDate, dto.getRepeatTypes(), dto.getExecTimes());
+        // 6. ✅ 预生成执行计划     todo 暂时走定时任务生成未来一周数据
+        //generateExecutionPlan(configId, dto.getCreationSchemeCode(), startDate, endDate, dto.getRepeatTypes(), dto.getExecTimes());
 
         //7 模版变成 投放中
         tournamentsTemplateMapper.updateUseTournamentTemplate(dto.getTemplateId());
@@ -289,8 +289,12 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
                     e.setConfigId(configId);
                     e.setExecutionDate(d);
                     e.setExecutionTime(t);
-                    scheduleExecutionMapper.insertScheduleExecution(e);
-                }
+                    //判断是否有重复  有重复的就不插入了
+                    ScheduleExecutionVo todayPendingExecutionsExit = scheduleExecutionMapper.findTodayPendingExecutionsExit(d, t, configId);
+                    if(todayPendingExecutionsExit==null){
+                        scheduleExecutionMapper.insertScheduleExecution(e);
+                    }
+                 }
             }
             d = d.plusDays(1);
         }
@@ -599,4 +603,24 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
         return scheduleConfig1>0?true:false;
     }
 
+    @Override
+    public void generateExecutionPlanTask(Long configId, String schemeCode, LocalDate startDate, LocalDate endDate, List<String> repeatTypes, List<LocalTime> execTimes) {
+       log.info("generateExecutionPlanTask Starting schedule generation: configId={}, start={}, end={}", configId, startDate, endDate);
+        switch (schemeCode.toUpperCase()) {
+            case "DAILY":
+                // 初始化为特定日期
+                endDate = LocalDate.of(2028, 12, 30);
+                generateDailyPlan(configId, startDate, endDate, repeatTypes, execTimes);
+                break;
+            case "WEEKLY":
+                generateWeeklyPlan(configId, startDate, endDate, repeatTypes, execTimes);
+                break;
+            case "NEXT_THREE_DAYS":
+                generateNextThreeDaysPlan(configId, startDate, endDate, repeatTypes, execTimes);
+                break;
+        }
+
+    }
+
+
 }

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/TournamentsServiceImpl.java

@@ -466,6 +466,7 @@ public class TournamentsServiceImpl implements ITournamentsService {
             TournamentEntryConditions tournamentEntryConditions=new TournamentEntryConditions();
             tournamentEntryConditions.setItemId(bo.getItemsId());
             tournamentEntryConditions.setRequiredQuantity(bo.getItemsNum());
+            tournamentEntryConditions.setTournamentId(tournamentId);
             tournamentEntryConditionsMapper.updateByTournamentId(tournamentEntryConditions);
 
             //删除奖励排名 同时删除奖励对应信息

+ 1 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/TournamentsTemplateServiceImpl.java

@@ -460,6 +460,7 @@ public class TournamentsTemplateServiceImpl implements ITournamentsTemplateServi
             TournamentEntryConditionsTemplate tournamentEntryConditions=new TournamentEntryConditionsTemplate();
             tournamentEntryConditions.setItemId(bo.getItemsId());
             tournamentEntryConditions.setRequiredQuantity(bo.getItemsNum());
+            tournamentEntryConditions.setTournamentId(tournamentId);
             tournamentEntryConditionsMapper.updateByTournamentIdTemplate(tournamentEntryConditions);
 
             //删除奖励排名 同时删除奖励对应信息

+ 38 - 6
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/job/business/ScheduleTask.java

@@ -6,6 +6,7 @@ import org.dromara.business.domain.dto.ItemsPrizeDto;
 import org.dromara.business.domain.dto.TournamentsDto;
 import org.dromara.business.domain.vo.*;
 import org.dromara.business.mapper.*;
+import org.dromara.business.service.IScheduleConfigService;
 import org.dromara.business.service.ITournamentsService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
@@ -13,6 +14,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -60,10 +62,39 @@ public class ScheduleTask {
     @Autowired
     ScheduleTournamentsReletionMapper scheduleTournamentsReletionMapper;
 
+    @Autowired
+    IScheduleConfigService scheduleConfigService;
+
+
+    /**
+     * 生成 schedule_execution 未来七天任务
+     */
+    @Scheduled(cron = "0 01 00 * * ?")
+    public void generateNextSevenDayTask() {
+        List<ScheduleConfigVo> scheduleConfigVoList = baseMapper.selectAllScheduleUseConfigs();
+        for (ScheduleConfigVo scheduleConfigVo : scheduleConfigVoList) {
+            List<String> repeatTypes=new ArrayList<>();
+            List<ScheduleRepeatVo> scheduleRepeatVos = scheduleRepeatMapper.selectScheduleRepeatByConfigId(scheduleConfigVo.getId());
+            for (ScheduleRepeatVo scheduleRepeatVo : scheduleRepeatVos) {
+                repeatTypes.add(scheduleRepeatVo.getRepeatType());
+            }
+            List<LocalTime> execTimes=new ArrayList<>();
+            List<ScheduleTimeVo> scheduleTimeVos = scheduleTimeMapper.selectScheduleTimeInfoById(scheduleConfigVo.getId());
+            for (ScheduleTimeVo scheduleTimeVo : scheduleTimeVos) {
+                execTimes.add(scheduleTimeVo.getExecTime());
+            }
+            scheduleConfigService.generateExecutionPlanTask(scheduleConfigVo.getId(),"WEEKLY",LocalDate.now(),LocalDate.now().plusDays(7),repeatTypes,execTimes);
+       }
+    }
+
+
+
+
+
     /**
      * 每天  00:10 执行
      */
-    @Scheduled(cron = "0 05 00 * * ?")
+    @Scheduled(cron = "0 15 00 * * ?")
     public void generateMatchesForToday() {
         LocalDate today = LocalDate.now();
         log.info("开始生成今日比赛: {}", today);
@@ -109,7 +140,7 @@ public class ScheduleTask {
     /**
      * 每周一 00:10 执行,生成未来一周的数据
      */
-    @Scheduled(cron = "0 10 00 ? * MON")
+    @Scheduled(cron = "0 20 00 ? * MON")
     public void generateMatchesForNextWeek() {
         LocalDate today = LocalDate.now();
         log.info("开始生成未来一周比赛: {}", today);
@@ -157,7 +188,7 @@ public class ScheduleTask {
     /**
      * 每天 00:10 执行,生成未来三天的数据
      */
-    @Scheduled(cron = "0 10 00 * * ?")
+    //@Scheduled(cron = "0 10 00 * * ?")
     public void generateMatchesForNextThreeDays() {
         LocalDate today = LocalDate.now();
         log.info("开始生成未来三天比赛: {}", today);
@@ -251,9 +282,10 @@ public class ScheduleTask {
                 //查询模版 赛事对应盲注
                 TournamentBlindStructuresVo tournamentBlindStructuresVo = tournamentBlindStructuresMapper.selectTournamentBlindStructureByTournamentIdTemplate(tournamentsVo.getId());
 
-                // 设置盲注结构 ID
-                bo.setBlindStructureId(tournamentBlindStructuresVo.getBlindStructureId());
-
+                if(tournamentBlindStructuresVo!=null){
+                    // 设置盲注结构 ID
+                    bo.setBlindStructureId(tournamentBlindStructuresVo.getBlindStructureId());
+                }
 
                 //查询模版  设置报名条件
                 TournamentEntryConditionsVo tournamentEntryConditionsVo = tournamentEntryConditionsMapper.selectByTournamentInfoTemplate(tournamentsVo.getId());

+ 9 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/ScheduleConfigMapper.xml

@@ -162,4 +162,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update schedule_config set enabled=#{enabled} where id=#{id}
     </update>
 
+
+    <!-- 查询所有字段 -->
+    <select id="selectAllScheduleUseConfigs" resultType="org.dromara.business.domain.vo.ScheduleConfigVo">
+        SELECT id, template_id, creation_scheme_id, start_date, end_date, enabled, created_at, updated_at
+        FROM schedule_config where  enabled=TRUE
+    </select>
+
+
+
 </mapper>

+ 17 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/ScheduleExecutionMapper.xml

@@ -60,4 +60,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
 
+
+    <select id="findTodayPendingExecutionsExit"   resultType="org.dromara.business.domain.vo.ScheduleExecutionVo">
+        SELECT
+            id,
+            config_id,
+            execution_date,
+            execution_time,
+            status,
+            created_at,
+            updated_at
+        FROM
+            schedule_execution
+        WHERE
+            execution_date = #{dates}   and  execution_time=#{executionTime} and config_id=#{configId}  limit 1
+    </select>
+
+
 </mapper>