From 29fc6f5b1981775be5d2f0f9f8e61fec2f550252 Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期一, 29 九月 2025 19:29:11 +0800
Subject: [PATCH] 删除所有test开头的测试文件
---
backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java | 104 ++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 76 insertions(+), 28 deletions(-)
diff --git a/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java b/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java
index 216689c..508e233 100644
--- a/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java
+++ b/backend/src/main/java/com/rongyichuang/activity/service/ActivityService.java
@@ -2,12 +2,15 @@
import com.rongyichuang.activity.dto.ActivityInput;
import com.rongyichuang.activity.dto.ActivityJudgeInput;
+import com.rongyichuang.activity.dto.ActivityJudgeResponse;
import com.rongyichuang.activity.dto.ActivityResponse;
import com.rongyichuang.activity.dto.ActivityStageInput;
import com.rongyichuang.activity.entity.Activity;
import com.rongyichuang.activity.entity.ActivityJudge;
import com.rongyichuang.activity.repository.ActivityJudgeRepository;
import com.rongyichuang.activity.repository.ActivityRepository;
+import com.rongyichuang.judge.entity.Judge;
+import com.rongyichuang.judge.repository.JudgeRepository;
import com.rongyichuang.common.dto.PageRequest;
import com.rongyichuang.common.dto.PageResponse;
import com.rongyichuang.rating.entity.RatingScheme;
@@ -19,6 +22,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -35,12 +39,15 @@
private ActivityJudgeRepository activityJudgeRepository;
@Autowired
+ private JudgeRepository judgeRepository;
+
+ @Autowired
private RatingSchemeRepository ratingSchemeRepository;
/**
* 鍒嗛〉鏌ヨ姣旇禌鍒楄〃
*/
- public PageResponse<ActivityResponse> findCompetitions(PageRequest pageRequest, String name) {
+ public PageResponse<ActivityResponse> findActivities(PageRequest pageRequest, String name) {
Pageable pageable = pageRequest.toPageable();
Page<Activity> page;
@@ -67,13 +74,17 @@
ActivityResponse response = new ActivityResponse(activity);
// 濡傛灉鏄瘮璧涳紝鍔犺浇鍏堕樁娈�
- if (activity.isCompetition()) {
+ if (activity.isMainActivity()) {
List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(id, 1);
List<ActivityResponse> stageResponses = stages.stream()
.map(ActivityResponse::new)
.collect(Collectors.toList());
response.setStages(stageResponses);
}
+
+ // 鍔犺浇璇勫鏁版嵁
+ List<ActivityJudgeResponse> judges = loadActivityJudges(id);
+ response.setJudges(judges);
return response;
}
@@ -122,12 +133,12 @@
activity = activityRepository.save(activity);
// 濡傛灉鏄瘮璧涗笖鏈夐樁娈典俊鎭紝淇濆瓨闃舵
- if (input.isCompetition() && input.getStages() != null && !input.getStages().isEmpty()) {
+ if (input.isMainActivity() && input.getStages() != null && !input.getStages().isEmpty()) {
saveActivityStages(activity.getId(), input.getStages());
}
// 濡傛灉鏄瘮璧涗笖鏈夎瘎濮斾俊鎭紝淇濆瓨璇勫
- if (input.isCompetition() && input.getJudges() != null && !input.getJudges().isEmpty()) {
+ if (input.isMainActivity() && input.getJudges() != null && !input.getJudges().isEmpty()) {
saveActivityJudges(activity.getId(), input.getJudges());
}
@@ -138,9 +149,9 @@
/**
* 淇濆瓨姣旇禌闃舵
*/
- private void saveActivityStages(Long competitionId, List<ActivityStageInput> stageInputs) {
+ private void saveActivityStages(Long activityId, List<ActivityStageInput> stageInputs) {
// 鑾峰彇鐜版湁鐨勬墍鏈夐樁娈�
- List<Activity> existingStages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(competitionId, 1);
+ List<Activity> existingStages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(activityId, 1);
// 鏀堕泦浼犲叆鐨勯樁娈礗D
List<Long> inputStageIds = stageInputs.stream()
@@ -157,11 +168,11 @@
}
// 鑾峰彇姣旇禌淇℃伅锛岀敤浜庣户鎵挎姤鍚嶆埅姝㈡椂闂村拰璇勫垎妯℃澘
- Optional<Activity> competitionOpt = activityRepository.findById(competitionId);
- if (!competitionOpt.isPresent()) {
+ Optional<Activity> activityOpt = activityRepository.findById(activityId);
+ if (!activityOpt.isPresent()) {
throw new RuntimeException("姣旇禌涓嶅瓨鍦�");
}
- Activity competition = competitionOpt.get();
+ Activity activity = activityOpt.get();
// 澶勭悊浼犲叆鐨勯樁娈碉紙鏂板鎴栨洿鏂帮級
for (ActivityStageInput stageInput : stageInputs) {
@@ -170,8 +181,8 @@
if (stageInput.isNew()) {
// 鏂板闃舵
stage = new Activity();
- stage.setPid(competitionId);
- stage.setPath(generatePath(competitionId));
+ stage.setPid(activityId);
+ stage.setPath(generatePath(activityId));
} else {
// 缂栬緫闃舵
Optional<Activity> existingOpt = activityRepository.findById(stageInput.getId());
@@ -190,13 +201,13 @@
stage.setState(stageInput.getState());
// 闃舵缁ф壙姣旇禌鐨勬姤鍚嶆埅姝㈡椂闂�
- stage.setSignupDeadline(competition.getSignupDeadline());
+ stage.setSignupDeadline(activity.getSignupDeadline());
// 闃舵鐨勮瘎鍒嗘ā鏉匡細濡傛灉鎸囧畾浜嗗垯浣跨敤鎸囧畾鐨勶紝鍚﹀垯缁ф壙姣旇禌鐨勮瘎鍒嗘ā鏉�
if (stageInput.getRatingSchemeId() != null) {
stage.setRatingSchemeId(stageInput.getRatingSchemeId());
} else {
- stage.setRatingSchemeId(competition.getRatingSchemeId());
+ stage.setRatingSchemeId(activity.getRatingSchemeId());
}
activityRepository.save(stage);
@@ -206,36 +217,36 @@
/**
* 淇濆瓨姣旇禌璇勫
*/
- private void saveActivityJudges(Long competitionId, List<ActivityJudgeInput> judgeInputs) {
+ private void saveActivityJudges(Long activityId, List<ActivityJudgeInput> judgeInputs) {
if (judgeInputs == null || judgeInputs.isEmpty()) {
return;
}
// 鑾峰彇姣旇禌鐨勬墍鏈夐樁娈碉紙濡傛灉鏈夌殑璇濓級
- List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(competitionId, 1);
+ List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(activityId, 1);
// 淇濆瓨璇勫鍏宠仈
for (ActivityJudgeInput judgeInput : judgeInputs) {
// 鍏堝垹闄よ璇勫鐨勭幇鏈夊叧鑱�
- activityJudgeRepository.deleteByActivityIdAndJudgeId(competitionId, judgeInput.getJudgeId());
+ activityJudgeRepository.deleteByActivityIdAndJudgeId(activityId, judgeInput.getJudgeId());
if (judgeInput.getStageIds() == null || judgeInput.getStageIds().isEmpty()) {
// 濡傛灉娌℃湁鎸囧畾闃舵锛屽垱寤哄叧鑱斿埌鎵�鏈夐樁娈碉紙濡傛灉鏈夐樁娈碉級鎴栫洿鎺ュ叧鑱斿埌姣旇禌锛堝鏋滄病鏈夐樁娈碉級
if (stages.isEmpty()) {
// 姣旇禌娌℃湁闃舵锛岀洿鎺ュ叧鑱斿埌姣旇禌锛坰tage_id涓簄ull琛ㄧず鎵�鏈夐樁娈碉級
- ActivityJudge activityJudge = new ActivityJudge(competitionId, judgeInput.getJudgeId(), null);
+ ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), null);
activityJudgeRepository.save(activityJudge);
} else {
// 涓烘瘡涓樁娈靛垱寤哄叧鑱�
for (Activity stage : stages) {
- ActivityJudge activityJudge = new ActivityJudge(competitionId, judgeInput.getJudgeId(), stage.getId());
+ ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), stage.getId());
activityJudgeRepository.save(activityJudge);
}
}
} else {
// 涓烘瘡涓寚瀹氱殑闃舵鍒涘缓鍏宠仈
for (Long stageId : judgeInput.getStageIds()) {
- ActivityJudge activityJudge = new ActivityJudge(competitionId, judgeInput.getJudgeId(), stageId);
+ ActivityJudge activityJudge = new ActivityJudge(activityId, judgeInput.getJudgeId(), stageId);
activityJudgeRepository.save(activityJudge);
}
}
@@ -251,7 +262,7 @@
Activity activity = activityOpt.get();
// 濡傛灉鏄瘮璧涳紝鍏堝垹闄ゅ叾鎵�鏈夐樁娈�
- if (activity.isCompetition()) {
+ if (activity.isMainActivity()) {
List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(id, 1);
for (Activity stage : stages) {
stage.setState(0); // 杞垹闄�
@@ -275,7 +286,7 @@
List<Activity> activities = activityRepository.findByStateOrderByPidAscNameAsc(1);
// 鍒涘缓姣旇禌ID鍒版瘮璧涘璞$殑鏄犲皠锛岀敤浜庡揩閫熸煡鎵剧埗姣旇禌
- Map<Long, Activity> competitionMap = activities.stream()
+ Map<Long, Activity> mainActivityMap = activities.stream()
.filter(activity -> activity.getPid() == 0)
.collect(Collectors.toMap(Activity::getId, activity -> activity));
@@ -285,7 +296,7 @@
ActivityResponse response = new ActivityResponse(activity);
// 濡傛灉鏄樁娈碉紙pid > 0锛夛紝濉厖parent淇℃伅
if (activity.getPid() > 0) {
- Activity parentActivity = competitionMap.get(activity.getPid());
+ Activity parentActivity = mainActivityMap.get(activity.getPid());
if (parentActivity != null) {
response.setParent(new ActivityResponse(parentActivity));
}
@@ -330,8 +341,8 @@
/**
* 鑾峰彇姣旇禌鐨勬墍鏈夐樁娈�
*/
- public List<ActivityResponse> findStagesByCompetitionId(Long competitionId) {
- List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(competitionId, 1);
+ public List<ActivityResponse> findStagesByActivityId(Long activityId) {
+ List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(activityId, 1);
return stages.stream()
.map(ActivityResponse::new)
.collect(Collectors.toList());
@@ -340,15 +351,15 @@
/**
* 缁熻姣旇禌鏁伴噺
*/
- public long countActiveCompetitions() {
- return activityRepository.countActiveCompetitions();
+ public long countActiveActivities() {
+ return activityRepository.countActiveActivities();
}
/**
* 鑾峰彇杩涜涓殑姣旇禌
*/
- public List<ActivityResponse> findOngoingCompetitions() {
- List<Activity> activities = activityRepository.findOngoingCompetitions();
+ public List<ActivityResponse> findOngoingActivities() {
+ List<Activity> activities = activityRepository.findOngoingActivities();
return activities.stream()
.map(ActivityResponse::new)
.collect(Collectors.toList());
@@ -368,4 +379,41 @@
return "/" + pid + "/";
}
}
+
+ /**
+ * 鍔犺浇娲诲姩鐨勮瘎濮旀暟鎹�
+ */
+ private List<ActivityJudgeResponse> loadActivityJudges(Long activityId) {
+ // 鏌ヨ娲诲姩鐨勮瘎濮斿叧鑱�
+ List<ActivityJudge> activityJudges = activityJudgeRepository.findByActivityId(activityId);
+
+ // 鎸夎瘎濮擨D鍒嗙粍锛屾敹闆嗘瘡涓瘎濮旇礋璐g殑闃舵
+ Map<Long, List<Long>> judgeStageMap = activityJudges.stream()
+ .collect(Collectors.groupingBy(
+ ActivityJudge::getJudgeId,
+ Collectors.mapping(ActivityJudge::getStageId, Collectors.toList())
+ ));
+
+ // 鏌ヨ璇勫璇︾粏淇℃伅骞舵瀯寤哄搷搴�
+ List<ActivityJudgeResponse> result = new ArrayList<>();
+ for (Map.Entry<Long, List<Long>> entry : judgeStageMap.entrySet()) {
+ Long judgeId = entry.getKey();
+ List<Long> stageIds = entry.getValue();
+
+ Optional<Judge> judgeOpt = judgeRepository.findById(judgeId);
+ if (judgeOpt.isPresent()) {
+ Judge judge = judgeOpt.get();
+ ActivityJudgeResponse judgeResponse = new ActivityJudgeResponse(
+ judge.getId(),
+ judge.getName(),
+ judge.getPhone(),
+ judge.getDescription(),
+ stageIds
+ );
+ result.add(judgeResponse);
+ }
+ }
+
+ return result;
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0