lrj
昨天 ae3349d2ff53767b5bc9cb30e1bf7e15f9e814ee
backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java
@@ -16,6 +16,8 @@
import com.rongyichuang.common.dto.PageResponse;
import com.rongyichuang.rating.entity.RatingScheme;
import com.rongyichuang.rating.repository.RatingSchemeRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
@@ -37,6 +39,8 @@
@Service
@Transactional
public class ActivityService {
    private static final Logger log = LoggerFactory.getLogger(ActivityService.class);
    
    @Autowired
    private ActivityRepository activityRepository;
@@ -67,6 +71,16 @@
            page = activityRepository.findByPidOrderByCreateTimeDesc(0L, pageable);
        }
        // 调试:打印分页原始活动的报名截止时间
        try {
            log.info("分页查询比赛列表:总数={}, 当前页={}, 每页={}", page.getTotalElements(), page.getNumber(), page.getSize());
            page.getContent().stream().limit(10).forEach(a ->
                log.info("Activity(id={}, name={}) signupDeadline={}, matchTime={}", a.getId(), a.getName(), a.getSignupDeadline(), a.getMatchTime())
            );
        } catch (Exception e) {
            log.warn("打印活动报名截止时间日志失败: {}", e.getMessage());
        }
        List<ActivityResponse> content = page.getContent().stream()
            .map(activity -> {
                ActivityResponse response = new ActivityResponse(activity);
@@ -86,6 +100,15 @@
                return response;
            })
            .collect(Collectors.toList());
        // 调试:打印返回给前端的响应对象中的报名截止
        try {
            content.stream().limit(10).forEach(r ->
                log.info("Response(id={}, name={}) signupDeadline={}, matchTime={}", r.getId(), r.getName(), r.getSignupDeadline(), r.getMatchTime())
            );
        } catch (Exception e) {
            log.warn("打印ActivityResponse日志失败: {}", e.getMessage());
        }
        
        return new PageResponse<>(content, page.getTotalElements(), page.getNumber(), page.getSize());
    }
@@ -185,6 +208,9 @@
        // 保存比赛
        activity = activityRepository.save(activity);
        
        // 记录日志以便调试
        log.info("保存比赛成功,比赛ID: {}, 比赛名称: {}", activity.getId(), activity.getName());
        // 如果是比赛且有阶段信息,保存阶段
        if (input.isMainActivity() && input.getStages() != null && !input.getStages().isEmpty()) {
            saveActivityStages(activity.getId(), input.getStages());
@@ -264,7 +290,11 @@
                stage.setRatingSchemeId(activity.getRatingSchemeId());
            }
            
            activityRepository.save(stage);
            // 保存阶段并获取自增ID
            stage = activityRepository.save(stage);
            // 记录日志以便调试
            log.info("保存阶段成功,阶段ID: {}, 阶段名称: {}", stage.getId(), stage.getName());
        }
    }
    
@@ -273,14 +303,20 @@
     */
    private void saveActivityJudges(Long activityId, List<ActivityJudgeInput> judgeInputs) {
        if (judgeInputs == null || judgeInputs.isEmpty()) {
            log.info("没有评委需要保存,比赛ID: {}", activityId);
            return;
        }
        log.info("开始保存评委,比赛ID: {}, 评委数量: {}", activityId, judgeInputs.size());
        
        // 获取比赛的所有阶段(如果有的话)
        List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(activityId, 1);
        
        // 保存评委关联
        for (ActivityJudgeInput judgeInput : judgeInputs) {
            log.info("处理评委: ID={}, 姓名={}, 阶段IDs={}",
                judgeInput.getJudgeId(), judgeInput.getJudgeName(), judgeInput.getStageIds());
            // 先删除该评委的现有关联
            activityJudgeRepository.deleteByActivityIdAndJudgeId(activityId, judgeInput.getJudgeId());
            
@@ -289,12 +325,14 @@
                if (stages.isEmpty()) {
                    // 比赛没有阶段,直接关联到比赛(stage_id为null表示所有阶段)
                    ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), null);
                    activityJudgeRepository.save(activityJudge);
                    activityJudge = activityJudgeRepository.save(activityJudge);
                    log.info("保存评委关联成功: 比赛ID={}, 评委ID={}, 阶段ID=null", activityId, judgeInput.getJudgeId());
                } else {
                    // 为每个阶段创建关联
                    for (Activity stage : stages) {
                        ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), stage.getId());
                        activityJudgeRepository.save(activityJudge);
                        activityJudge = activityJudgeRepository.save(activityJudge);
                        log.info("保存评委关联成功: 比赛ID={}, 评委ID={}, 阶段ID={}", activityId, judgeInput.getJudgeId(), stage.getId());
                    }
                }
            } else {
@@ -303,7 +341,8 @@
                    // 如果stageId等于当前比赛ID,表示评委负责整个比赛,stage_id设为null
                    Long actualStageId = stageId.equals(activityId) ? null : stageId;
                    ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), actualStageId);
                    activityJudgeRepository.save(activityJudge);
                    activityJudge = activityJudgeRepository.save(activityJudge);
                    log.info("保存评委关联成功: 比赛ID={}, 评委ID={}, 阶段ID={}", activityId, judgeInput.getJudgeId(), actualStageId);
                }
            }
        }