package com.rongyichuang.player.api;
|
|
import com.rongyichuang.common.dto.PageResponse;
|
import com.rongyichuang.player.dto.input.ActivityPlayerRatingInput;
|
import com.rongyichuang.player.dto.ActivityRegistrationInput;
|
import com.rongyichuang.player.dto.response.ActivityPlayerApplicationResponse;
|
import com.rongyichuang.player.dto.response.ActivityPlayerDetailResponse;
|
import com.rongyichuang.player.dto.response.ProjectReviewApplicationPageResponse;
|
import com.rongyichuang.player.dto.response.PlayerApplicationPageResponse;
|
import com.rongyichuang.player.dto.ActivityRegistrationResponse;
|
import com.rongyichuang.player.dto.response.JudgeRatingStatusResponse;
|
import com.rongyichuang.player.dto.response.CurrentJudgeRatingResponse;
|
import com.rongyichuang.player.dto.response.CurrentJudgeInfoResponse;
|
import com.rongyichuang.player.dto.response.PlayerRegistrationResponse;
|
import com.rongyichuang.player.dto.PromotionCompetitionResponse;
|
import com.rongyichuang.player.dto.CompetitionParticipantResponse;
|
import com.rongyichuang.player.dto.PromotionInput;
|
import com.rongyichuang.player.dto.PromotionResult;
|
import com.rongyichuang.player.dto.PromotableParticipantsResponse;
|
import com.rongyichuang.player.service.PlayerApplicationService;
|
import com.rongyichuang.player.service.ActivityPlayerDetailService;
|
import com.rongyichuang.player.service.ActivityPlayerRatingService;
|
import com.rongyichuang.player.service.ActivityPlayerService;
|
import com.rongyichuang.player.service.PromotionService;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.graphql.data.method.annotation.Argument;
|
import org.springframework.graphql.data.method.annotation.MutationMapping;
|
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
import org.springframework.stereotype.Controller;
|
|
import java.math.BigDecimal;
|
import java.util.List;
|
|
@Controller
|
public class PlayerGraphqlApi {
|
|
private static final Logger log = LoggerFactory.getLogger(PlayerGraphqlApi.class);
|
|
private final PlayerApplicationService service;
|
private final ActivityPlayerDetailService detailService;
|
private final ActivityPlayerRatingService ratingService;
|
private final ActivityPlayerService activityPlayerService;
|
private final PromotionService promotionService;
|
|
public PlayerGraphqlApi(PlayerApplicationService service,
|
ActivityPlayerDetailService detailService,
|
ActivityPlayerRatingService ratingService,
|
ActivityPlayerService activityPlayerService,
|
PromotionService promotionService) {
|
this.service = service;
|
this.detailService = detailService;
|
this.ratingService = ratingService;
|
this.activityPlayerService = activityPlayerService;
|
this.promotionService = promotionService;
|
}
|
|
@QueryMapping
|
public PlayerApplicationPageResponse activityPlayerApplications(
|
@Argument String name,
|
@Argument Long activityId,
|
@Argument Integer state,
|
@Argument Integer page,
|
@Argument Integer size
|
) {
|
PageResponse<ActivityPlayerApplicationResponse> pageResponse =
|
service.listApplications(name, activityId, state, page, size);
|
return PlayerApplicationPageResponse.from(pageResponse);
|
}
|
|
/**
|
* 项目评审专用查询,包含所有阶段数据(包括复赛、决赛)
|
*/
|
@QueryMapping
|
public ProjectReviewApplicationPageResponse projectReviewApplications(
|
@Argument String name,
|
@Argument Long activityId,
|
@Argument Integer state,
|
@Argument Integer page,
|
@Argument Integer size
|
) {
|
PageResponse<ActivityPlayerApplicationResponse> pageResponse =
|
service.listProjectReviewApplications(name, activityId, state, page, size);
|
return ProjectReviewApplicationPageResponse.from(pageResponse);
|
}
|
|
/**
|
* 获取比赛报名详情(用于评分)
|
*/
|
@QueryMapping
|
public ActivityPlayerDetailResponse activityPlayerDetail(@Argument Long id) {
|
return detailService.getDetailForRating(id);
|
}
|
|
/**
|
* 查询玩家在指定活动中的报名状态
|
*/
|
@QueryMapping
|
public PlayerRegistrationResponse playerRegistration(@Argument Long activityId) {
|
return activityPlayerService.getPlayerRegistration(activityId);
|
}
|
|
/**
|
* 保存比赛报名评分
|
*/
|
@MutationMapping
|
public Boolean saveActivityPlayerRating(@Argument ActivityPlayerRatingInput input) {
|
log.info("收到评分保存请求,activityPlayerId: {}, ratings count: {}",
|
input.getActivityPlayerId(), input.getRatings() != null ? input.getRatings().size() : 0);
|
try {
|
Boolean result = ratingService.saveRating(input);
|
log.info("评分保存结果: {}", result);
|
return result;
|
} catch (Exception e) {
|
log.error("GraphQL API 层捕获异常: {}", e.getMessage(), e);
|
throw e;
|
}
|
}
|
|
/**
|
* 获取指定选手的所有评委评分状态
|
*/
|
@QueryMapping
|
public List<JudgeRatingStatusResponse> judgeRatingsForPlayer(@Argument Long activityPlayerId) {
|
log.info("获取选手评委评分状态,activityPlayerId: {}", activityPlayerId);
|
return ratingService.getAllJudgeRatingsForPlayer(activityPlayerId);
|
}
|
|
/**
|
* 获取当前评委对指定选手的评分
|
*/
|
@QueryMapping
|
public CurrentJudgeRatingResponse currentJudgeRating(@Argument Long activityPlayerId) {
|
log.info("获取当前评委评分,activityPlayerId: {}", activityPlayerId);
|
return ratingService.getCurrentJudgeRating(activityPlayerId);
|
}
|
|
/**
|
* 获取指定选手的平均分
|
*/
|
@QueryMapping
|
public BigDecimal averageScoreForPlayer(@Argument Long activityPlayerId) {
|
log.info("获取选手平均分,activityPlayerId: {}", activityPlayerId);
|
return ratingService.getAverageScoreForPlayer(activityPlayerId);
|
}
|
|
/**
|
* 获取当前评委信息
|
*/
|
@QueryMapping
|
public CurrentJudgeInfoResponse currentJudgeInfo() {
|
log.info("获取当前评委信息");
|
return ratingService.getCurrentJudgeInfo();
|
}
|
|
/**
|
* 检查评委是否在指定比赛阶段的评委列表中
|
*/
|
@QueryMapping
|
public Boolean isJudgeInActivity(@Argument Long stageId, @Argument Long judgeId) {
|
log.info("检查评委权限,stageId: {}, judgeId: {}", stageId, judgeId);
|
return ratingService.isJudgeInActivity(stageId, judgeId);
|
}
|
|
/**
|
* 获取指定评委的评分明细
|
*/
|
@QueryMapping
|
public CurrentJudgeRatingResponse judgeRatingDetail(@Argument Long activityPlayerId, @Argument Long judgeId) {
|
log.info("获取指定评委评分明细,activityPlayerId: {}, judgeId: {}", activityPlayerId, judgeId);
|
return ratingService.getJudgeRatingDetail(activityPlayerId, judgeId);
|
}
|
|
/**
|
* 提交活动报名
|
*/
|
@MutationMapping
|
public ActivityRegistrationResponse submitActivityRegistration(@Argument ActivityRegistrationInput input) {
|
log.info("收到活动报名请求,activityId: {}, playerName: {}",
|
input.getActivityId(), input.getPlayerInfo().getName());
|
try {
|
ActivityRegistrationResponse result = activityPlayerService.submitActivityRegistration(input);
|
log.info("活动报名结果: {}", result.getSuccess());
|
return result;
|
} catch (Exception e) {
|
log.error("活动报名失败: {}", e.getMessage(), e);
|
// 返回失败响应
|
ActivityRegistrationResponse response = new ActivityRegistrationResponse();
|
response.setSuccess(false);
|
response.setMessage("报名失败: " + e.getMessage());
|
return response;
|
}
|
}
|
|
/**
|
* 审核通过
|
*/
|
@MutationMapping
|
public Boolean approveActivityPlayer(@Argument Long activityPlayerId, @Argument String feedback) {
|
log.info("审核通过请求,activityPlayerId: {}, feedback: {}", activityPlayerId, feedback);
|
try {
|
return activityPlayerService.approveActivityPlayer(activityPlayerId, feedback);
|
} catch (Exception e) {
|
log.error("审核通过失败: {}", e.getMessage(), e);
|
throw e;
|
}
|
}
|
|
/**
|
* 审核驳回
|
*/
|
@MutationMapping
|
public Boolean rejectActivityPlayer(@Argument Long activityPlayerId, @Argument String feedback) {
|
log.info("审核驳回请求,activityPlayerId: {}, feedback: {}", activityPlayerId, feedback);
|
try {
|
return activityPlayerService.rejectActivityPlayer(activityPlayerId, feedback);
|
} catch (Exception e) {
|
log.error("审核驳回失败: {}", e.getMessage(), e);
|
throw e;
|
}
|
}
|
|
/**
|
* 更新审核意见
|
*/
|
@MutationMapping
|
public Boolean updatePlayerFeedback(@Argument Long activityPlayerId, @Argument String feedback) {
|
log.info("更新审核意见请求,activityPlayerId: {}, feedback: {}", activityPlayerId, feedback);
|
try {
|
return activityPlayerService.updateFeedback(activityPlayerId, feedback);
|
} catch (Exception e) {
|
log.error("更新审核意见失败: {}", e.getMessage(), e);
|
throw e;
|
}
|
}
|
|
@MutationMapping
|
public ActivityRegistrationResponse updateActivityRegistration(@Argument Long activityPlayerId, @Argument ActivityRegistrationInput input) {
|
try {
|
log.info("收到更新报名请求,报名ID: {}", activityPlayerId);
|
return activityPlayerService.updateActivityRegistration(activityPlayerId, input);
|
} catch (Exception e) {
|
log.error("更新报名失败", e);
|
ActivityRegistrationResponse response = new ActivityRegistrationResponse();
|
response.setSuccess(false);
|
response.setMessage("更新报名失败: " + e.getMessage());
|
return response;
|
}
|
}
|
|
/**
|
* 获取比赛晋级列表
|
*/
|
@QueryMapping
|
public List<PromotionCompetitionResponse> promotionCompetitions(
|
@Argument String name,
|
@Argument Integer page,
|
@Argument Integer size) {
|
try {
|
log.info("获取比赛晋级列表,名称过滤: {}, 页码: {}, 页大小: {}", name, page, size);
|
return promotionService.getPromotionCompetitions(name, page, size);
|
} catch (Exception e) {
|
log.error("获取比赛晋级列表失败: {}", e.getMessage(), e);
|
throw e;
|
}
|
}
|
|
/**
|
* 获取比赛参赛人员
|
*/
|
@QueryMapping
|
public List<CompetitionParticipantResponse> competitionParticipants(
|
@Argument Long competitionId,
|
@Argument Integer page,
|
@Argument Integer size) {
|
try {
|
log.info("获取比赛参赛人员,比赛ID: {}, 页码: {}, 页大小: {}", competitionId, page, size);
|
return promotionService.getCompetitionParticipants(competitionId, page, size);
|
} catch (Exception e) {
|
log.error("获取比赛参赛人员失败: {}", e.getMessage(), e);
|
throw e;
|
}
|
}
|
|
/**
|
* 获取可晋级参赛者列表
|
*/
|
@QueryMapping
|
public PromotableParticipantsResponse promotableParticipants(@Argument Long currentStageId) {
|
try {
|
log.info("获取可晋级参赛者列表,当前阶段ID: {}", currentStageId);
|
return promotionService.getPromotableParticipants(currentStageId);
|
} catch (Exception e) {
|
log.error("获取可晋级参赛者列表失败: {}", e.getMessage(), e);
|
throw e;
|
}
|
}
|
|
/**
|
* 执行晋级操作
|
*/
|
@MutationMapping
|
public PromotionResult promoteParticipants(@Argument PromotionInput input) {
|
try {
|
log.info("执行晋级操作,比赛ID: {}, 参赛者数量: {}",
|
input.getCompetitionId(),
|
input.getParticipantIds() != null ? input.getParticipantIds().size() : 0);
|
return promotionService.promoteParticipants(input);
|
} catch (Exception e) {
|
log.error("执行晋级操作失败: {}", e.getMessage(), e);
|
return PromotionResult.failure("晋级操作失败: " + e.getMessage());
|
}
|
}
|
}
|