diff --git a/backend-java/src/main/java/com/competition/modules/pub/controller/PublicActivityController.java b/backend-java/src/main/java/com/competition/modules/pub/controller/PublicActivityController.java index e2c60d6..c99cfdd 100644 --- a/backend-java/src/main/java/com/competition/modules/pub/controller/PublicActivityController.java +++ b/backend-java/src/main/java/com/competition/modules/pub/controller/PublicActivityController.java @@ -49,6 +49,15 @@ public class PublicActivityController { return Result.success(publicActivityService.getMyRegistration(id, userId)); } + @GetMapping("/mine/registrations") + @Operation(summary = "我的报名列表") + public Result> getMyRegistrations( + @RequestParam(defaultValue = "1") int page, + @RequestParam(defaultValue = "10") int pageSize) { + Long userId = SecurityUtil.getCurrentUserId(); + return Result.success(publicActivityService.getMyRegistrations(userId, page, pageSize)); + } + @PostMapping("/{id}/register") @Operation(summary = "报名活动") public Result register( diff --git a/backend-java/src/main/java/com/competition/modules/pub/service/PublicActivityService.java b/backend-java/src/main/java/com/competition/modules/pub/service/PublicActivityService.java index dfde102..85d0674 100644 --- a/backend-java/src/main/java/com/competition/modules/pub/service/PublicActivityService.java +++ b/backend-java/src/main/java/com/competition/modules/pub/service/PublicActivityService.java @@ -12,6 +12,8 @@ import com.competition.modules.biz.contest.mapper.ContestMapper; import com.competition.modules.biz.contest.mapper.ContestRegistrationMapper; import com.competition.modules.biz.contest.mapper.ContestWorkMapper; import com.competition.modules.pub.dto.PublicRegisterActivityDto; +import com.competition.modules.user.entity.UserChild; +import com.competition.modules.user.mapper.UserChildMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -29,6 +31,7 @@ public class PublicActivityService { private final ContestMapper contestMapper; private final ContestRegistrationMapper contestRegistrationMapper; private final ContestWorkMapper contestWorkMapper; + private final UserChildMapper userChildMapper; /** * 活动列表(公开) @@ -123,6 +126,137 @@ public class PublicActivityService { return result; } + /** + * 我的报名列表 + */ + public Map getMyRegistrations(Long userId, int page, int pageSize) { + // 查询报名列表 + LambdaQueryWrapper regWrapper = new LambdaQueryWrapper<>(); + regWrapper.eq(BizContestRegistration::getUserId, userId) + .orderByDesc(BizContestRegistration::getRegistrationTime); + + IPage regPage = contestRegistrationMapper.selectPage(new Page<>(page, pageSize), regWrapper); + + // 获取所有 contestId + List contestIds = regPage.getRecords().stream() + .map(BizContestRegistration::getContestId) + .distinct() + .toList(); + + // 批量查询活动信息 + Map contestMap = new HashMap<>(); + if (!contestIds.isEmpty()) { + List contests = contestMapper.selectBatchIds(contestIds); + for (BizContest contest : contests) { + contestMap.put(contest.getId(), contest); + } + } + + // 查询所有报名对应的作品 + List registrations = regPage.getRecords(); + List registrationIds = registrations.stream() + .map(BizContestRegistration::getId) + .toList(); + + Map> worksMap = new HashMap<>(); + if (!registrationIds.isEmpty()) { + LambdaQueryWrapper workWrapper = new LambdaQueryWrapper<>(); + workWrapper.in(BizContestWork::getRegistrationId, registrationIds); + List works = contestWorkMapper.selectList(workWrapper); + for (BizContestWork work : works) { + worksMap.computeIfAbsent(work.getRegistrationId(), k -> new ArrayList<>()).add(work); + } + } + + // 获取所有 childId + List childIds = registrations.stream() + .map(BizContestRegistration::getChildId) + .filter(Objects::nonNull) + .distinct() + .toList(); + + // 批量查询子女信息 + Map childMap = new HashMap<>(); + if (!childIds.isEmpty()) { + List children = userChildMapper.selectBatchIds(childIds); + for (UserChild child : children) { + childMap.put(child.getId(), child); + } + } + + // 组装返回数据 + List> list = new ArrayList<>(); + for (BizContestRegistration reg : registrations) { + Map item = new LinkedHashMap<>(); + item.put("id", reg.getId()); + item.put("contestId", reg.getContestId()); + item.put("userId", reg.getUserId()); + item.put("registrationType", reg.getRegistrationType()); + item.put("registrationState", reg.getRegistrationState()); + item.put("registrationTime", reg.getRegistrationTime()); + item.put("participantType", reg.getParticipantType()); + item.put("childId", reg.getChildId()); + item.put("teamId", reg.getTeamId()); + + // 关联子女信息 + if (reg.getChildId() != null) { + UserChild child = childMap.get(reg.getChildId()); + if (child != null) { + Map childInfo = new LinkedHashMap<>(); + childInfo.put("id", child.getId()); + childInfo.put("name", child.getName()); + childInfo.put("gender", child.getGender()); + childInfo.put("grade", child.getGrade()); + item.put("child", childInfo); + } + } + + // 关联活动信息 + BizContest contest = contestMap.get(reg.getContestId()); + if (contest != null) { + Map contestInfo = new LinkedHashMap<>(); + contestInfo.put("id", contest.getId()); + contestInfo.put("contestName", contest.getContestName()); + contestInfo.put("contestType", contest.getContestType()); + contestInfo.put("coverUrl", contest.getCoverUrl()); + contestInfo.put("posterUrl", contest.getPosterUrl()); + contestInfo.put("startTime", contest.getStartTime()); + contestInfo.put("endTime", contest.getEndTime()); + contestInfo.put("submitStartTime", contest.getSubmitStartTime()); + contestInfo.put("submitEndTime", contest.getSubmitEndTime()); + item.put("contest", contestInfo); + } + + // 关联作品信息 + List works = worksMap.get(reg.getId()); + if (works != null && !works.isEmpty()) { + List> worksList = new ArrayList<>(); + for (BizContestWork work : works) { + Map workInfo = new LinkedHashMap<>(); + workInfo.put("id", work.getId()); + workInfo.put("title", work.getTitle()); + workInfo.put("description", work.getDescription()); + workInfo.put("previewUrl", work.getPreviewUrl()); + workInfo.put("previewUrls", work.getPreviewUrls()); + workInfo.put("attachments", work.getFiles()); + workInfo.put("createTime", work.getCreateTime()); + worksList.add(workInfo); + } + item.put("works", worksList); + } + + list.add(item); + } + + Map result = new LinkedHashMap<>(); + result.put("list", list); + result.put("total", regPage.getTotal()); + result.put("page", regPage.getCurrent()); + result.put("pageSize", regPage.getSize()); + + return result; + } + /** * 报名活动 */ diff --git a/frontend/src/api/public.ts b/frontend/src/api/public.ts index 03b982d..d3e1f0b 100644 --- a/frontend/src/api/public.ts +++ b/frontend/src/api/public.ts @@ -277,7 +277,7 @@ export const publicActivitiesApi = { export const publicMineApi = { registrations: (params?: { page?: number; pageSize?: number }) => - publicApi.get("/public/mine/registrations", { params }), + publicApi.get("/public/activities/mine/registrations", { params }), } // ==================== 点赞 & 收藏 ====================