fix:修复我的报名列表
This commit is contained in:
parent
63c564a03b
commit
d68322f24a
@ -49,6 +49,15 @@ public class PublicActivityController {
|
||||
return Result.success(publicActivityService.getMyRegistration(id, userId));
|
||||
}
|
||||
|
||||
@GetMapping("/mine/registrations")
|
||||
@Operation(summary = "我的报名列表")
|
||||
public Result<Map<String, Object>> 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<BizContestRegistration> register(
|
||||
|
||||
@ -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<String, Object> getMyRegistrations(Long userId, int page, int pageSize) {
|
||||
// 查询报名列表
|
||||
LambdaQueryWrapper<BizContestRegistration> regWrapper = new LambdaQueryWrapper<>();
|
||||
regWrapper.eq(BizContestRegistration::getUserId, userId)
|
||||
.orderByDesc(BizContestRegistration::getRegistrationTime);
|
||||
|
||||
IPage<BizContestRegistration> regPage = contestRegistrationMapper.selectPage(new Page<>(page, pageSize), regWrapper);
|
||||
|
||||
// 获取所有 contestId
|
||||
List<Long> contestIds = regPage.getRecords().stream()
|
||||
.map(BizContestRegistration::getContestId)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
// 批量查询活动信息
|
||||
Map<Long, BizContest> contestMap = new HashMap<>();
|
||||
if (!contestIds.isEmpty()) {
|
||||
List<BizContest> contests = contestMapper.selectBatchIds(contestIds);
|
||||
for (BizContest contest : contests) {
|
||||
contestMap.put(contest.getId(), contest);
|
||||
}
|
||||
}
|
||||
|
||||
// 查询所有报名对应的作品
|
||||
List<BizContestRegistration> registrations = regPage.getRecords();
|
||||
List<Long> registrationIds = registrations.stream()
|
||||
.map(BizContestRegistration::getId)
|
||||
.toList();
|
||||
|
||||
Map<Long, List<BizContestWork>> worksMap = new HashMap<>();
|
||||
if (!registrationIds.isEmpty()) {
|
||||
LambdaQueryWrapper<BizContestWork> workWrapper = new LambdaQueryWrapper<>();
|
||||
workWrapper.in(BizContestWork::getRegistrationId, registrationIds);
|
||||
List<BizContestWork> works = contestWorkMapper.selectList(workWrapper);
|
||||
for (BizContestWork work : works) {
|
||||
worksMap.computeIfAbsent(work.getRegistrationId(), k -> new ArrayList<>()).add(work);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有 childId
|
||||
List<Long> childIds = registrations.stream()
|
||||
.map(BizContestRegistration::getChildId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
// 批量查询子女信息
|
||||
Map<Long, UserChild> childMap = new HashMap<>();
|
||||
if (!childIds.isEmpty()) {
|
||||
List<UserChild> children = userChildMapper.selectBatchIds(childIds);
|
||||
for (UserChild child : children) {
|
||||
childMap.put(child.getId(), child);
|
||||
}
|
||||
}
|
||||
|
||||
// 组装返回数据
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (BizContestRegistration reg : registrations) {
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> 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<BizContestWork> works = worksMap.get(reg.getId());
|
||||
if (works != null && !works.isEmpty()) {
|
||||
List<Map<String, Object>> worksList = new ArrayList<>();
|
||||
for (BizContestWork work : works) {
|
||||
Map<String, Object> 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<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("list", list);
|
||||
result.put("total", regPage.getTotal());
|
||||
result.put("page", regPage.getCurrent());
|
||||
result.put("pageSize", regPage.getSize());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 报名活动
|
||||
*/
|
||||
|
||||
@ -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 }),
|
||||
}
|
||||
|
||||
// ==================== 点赞 & 收藏 ====================
|
||||
|
||||
Loading…
Reference in New Issue
Block a user