Răsfoiți Sursa

feat(system): 增强盲注结构更新功能和赛事生成逻辑

- 在盲注结构更新接口中添加使用状态检查,防止正在使用的盲注被修改
- 增加详细的日志记录,覆盖更新流程的关键步骤
- 优化Excel文件解析与数据校验逻辑,提升数据导入的准确性
- 修改赛事生成任务,将默认生成时间范围从3天调整为7天- 更新相关接口路径和方法名,保持命名一致性与语义清晰
- 修复原代码中注释不规范的问题,提高代码可读性
fugui001 2 luni în urmă
părinte
comite
6ae7c0b20c

+ 5 - 5
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/controller/JobController.java

@@ -30,7 +30,7 @@ public class JobController extends BaseController {
         scheduleTask.generateMatchesForToday();
     }
 
-    /**
+   /**
      * 批量生成比赛 下一周
      */
     @PostMapping("/generateMatchesForNextWeek")
@@ -39,11 +39,11 @@ public class JobController extends BaseController {
     }
 
     /**
-     * 批量生成比赛 未来
+     * 批量生成比赛 未来7
      */
-    @PostMapping("/generateMatchesForNextThreeDays")
-    public void generateMatchesForNextThreeDays() {
-        scheduleTask.generateMatchesForNextThreeDays();
+    @PostMapping("/generateMatchesForNextSevenDays")
+    public void generateMatchesForNextSevenDays() {
+        scheduleTask.generateMatchesForNextSevenDays();
     }
 
 

+ 26 - 16
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/BlindStructuresServiceImpl.java

@@ -225,22 +225,28 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
     //@Transactional(rollbackFor = Exception.class) // 开启事务
     public R<Boolean> updateByBo(BlindStructuresBo bo, MultipartFile file) {
         try {
+            log.info("开始更新盲注结构,ID: {}", bo.getId());
 
+            // 1. 检查是否正在使用中
             List<TournamentBlindStructuresVo> tournamentBlindStructuresVo = tournamentBlindStructuresMapper.selectTournamentBlindStructureByBlindStructureId(bo.getId());
-            //TODO已经在比赛中使用的盲注禁止删除和修改
-            if(tournamentBlindStructuresVo!=null && tournamentBlindStructuresVo.size()>0){
+            log.info("查询到使用该盲注的赛事数量: {}", tournamentBlindStructuresVo == null ? 0 : tournamentBlindStructuresVo.size());
+
+            if(tournamentBlindStructuresVo != null && tournamentBlindStructuresVo.size() > 0){
+                log.warn("发现该盲注正在使用中,禁止修改");
                 return R.fail("该盲注正在使用中,请勿修改");
             }
 
-            // 1. 转换 BO -> PO
+            // 2. 转换 BO -> PO
             BlindStructures update = MapstructUtils.convert(bo, BlindStructures.class);
             validEntityBeforeSave(update);
             Long userId = LoginHelper.getUserId();
             update.setUpdateUserId(userId);
+            log.info("准备更新盲注结构,用户ID: {}", userId);
 
-            // 1. 解析 Excel 文件
+            // 3. 解析 Excel 文件
             List<BlindLevelsImportVo> dataList = List.of();
             if (file != null) {
+                log.info("开始解析上传的Excel文件");
                 try (InputStream inputStream = file.getInputStream()) {
                     dataList = parseExcel(inputStream);
                 } catch (IOException e) {
@@ -249,33 +255,35 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
                 }
 
                 if (CollectionUtils.isEmpty(dataList)) {
+                    log.warn("导入数据为空");
                     return R.fail("导入数据为空");
                 }
 
-                // 校验数据逻辑(可选)
+                // 4. 校验数据逻辑(可选)
                 BlindLevelsValidatorUtils.ValidationResult validationResult = BlindLevelsValidatorUtils.validateBlindLevels(dataList);
                 if (validationResult.isValid()) {
-                    System.out.println("数据校验通过");
+                    log.info("数据校验通过,共{}条数据", dataList.size());
                 } else {
+                    log.warn("数据校验失败: {}", validationResult.getErrorMessage());
                     return R.fail(validationResult.getErrorMessage());
                 }
             }
 
-
-
-            // 2. 更新主表
+            // 5. 更新主表
+            log.info("开始更新主表数据");
             int i = baseMapper.updateBlindStructuresById(update);
             if (i <= 0) {
+                log.error("更新主表失败");
                 return R.fail("更新失败");
             }
+            log.info("主表更新成功");
+
+            // 6. 处理等级数据
             if (file != null) {
-                // 3. 删除原有等级数据
+                log.info("开始处理等级数据,删除原有数据");
                 Boolean b = blindLevelsService.deleteBlindLevelByBlindStructureId(update.getId());
-                   /* if (!b) {
-                        return R.fail("删除历史等级失败");
-                    }*/
 
-                // 5. 插入新等级数据
+                log.info("开始插入新等级数据,共{}条", dataList.size());
                 for (BlindLevelsImportVo vo : dataList) {
                     BlindLevelsBo levelBo = new BlindLevelsBo();
                     levelBo.setBlindStructureId(update.getId());
@@ -287,12 +295,14 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
                     levelBo.setCreateUserId(userId);
                     blindLevelsService.insertByBo(levelBo);
                 }
-
+                log.info("等级数据处理完成");
             }
+
+            log.info("盲注结构更新成功,ID: {}", bo.getId());
             return R.ok(true); // 成功返回 true
 
         } catch (Exception e) {
-            log.error("更新盲注结构失败", e);
+            log.error("更新盲注结构失败,ID: {}, 错误信息: {}", bo.getId(), e.getMessage(), e);
             throw e; // 抛出异常触发事务回滚
         }
     }

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

@@ -306,7 +306,7 @@ public class ScheduleConfigServiceImpl implements IScheduleConfigService {
             d = d.plusDays(1);
         }
          //TODO提前生成未来一周赛事数据
-        scheduleTask.generateMatchesForNextThreeDays();
+        scheduleTask.generateMatchesForNextSevenDays();
     }
 
     private void generateNextThreeDaysPlan(Long configId, LocalDate start, LocalDate end, List<String> repeatTypes, List<LocalTime> execTimes) {

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

@@ -232,10 +232,10 @@ public class ScheduleTask {
 
 
     /**
-     * 每天 00:10 执行,生成未来天的数据
+     * 每天 00:10 执行,生成未来7天的数据
      */
     //@Scheduled(cron = "0 20 16 * * ?")
-    public void generateMatchesForNextThreeDays() {
+    public void generateMatchesForNextSevenDays() {
         LocalDate today = LocalDate.now();
         log.info("开始生成未来七天比赛: {}", today);