lrj
14 小时以前 f04f35b562760afbac0c477357e2a29f77aec3b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
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());
        }
    }
}