import { API_CONFIG, graphqlRequest } from '@/config/api'
|
|
// GraphQL 查询:获取比赛晋级列表
|
const GET_PROMOTION_COMPETITIONS = `
|
query GetPromotionCompetitions($name: String, $page: Int, $size: Int) {
|
promotionCompetitions(name: $name, page: $page, size: $size) {
|
id
|
competitionName
|
stageName
|
maxParticipants
|
currentCount
|
status
|
startTime
|
endTime
|
sortOrder
|
state
|
}
|
}
|
`
|
|
// GraphQL 查询:获取比赛参赛人员
|
const GET_COMPETITION_PARTICIPANTS = `
|
query GetCompetitionParticipants($competitionId: ID!, $page: Int, $size: Int) {
|
competitionParticipants(competitionId: $competitionId, page: $page, size: $size) {
|
id
|
playerName
|
projectName
|
phone
|
averageScore
|
ratingCount
|
applyTime
|
state
|
}
|
}
|
`
|
|
// GraphQL 查询:获取可晋级参赛者
|
const GET_PROMOTABLE_PARTICIPANTS = `
|
query GetPromotableParticipants($currentStageId: ID!) {
|
promotableParticipants(currentStageId: $currentStageId) {
|
participants {
|
id
|
playerId
|
playerName
|
projectName
|
phone
|
averageScore
|
ratingCount
|
applyTime
|
state
|
}
|
selectableCount
|
totalCount
|
previousStageName
|
currentStageName
|
}
|
}
|
`
|
|
// GraphQL 变更:晋级参赛者
|
const PROMOTE_PARTICIPANTS = `
|
mutation PromoteParticipants($input: PromotionInput!) {
|
promoteParticipants(input: $input) {
|
success
|
message
|
promotedCount
|
}
|
}
|
`
|
|
// 比赛晋级 API
|
export const PromotionApi = {
|
// 获取比赛晋级列表
|
async getPromotionCompetitions(params = {}) {
|
try {
|
const variables = {
|
name: params.name || null,
|
page: params.page || 1,
|
size: params.size || 10
|
}
|
const data = await graphqlRequest(GET_PROMOTION_COMPETITIONS, variables)
|
return data.promotionCompetitions || []
|
} catch (error) {
|
console.error('获取比赛晋级列表失败:', error)
|
throw error
|
}
|
},
|
|
// 获取比赛参赛人员
|
async getCompetitionParticipants(competitionId, params = {}) {
|
try {
|
const variables = {
|
competitionId,
|
page: params.page || 1,
|
size: params.size || 10
|
}
|
const data = await graphqlRequest(GET_COMPETITION_PARTICIPANTS, variables)
|
return data.competitionParticipants || []
|
} catch (error) {
|
console.error('获取比赛参赛人员失败:', error)
|
throw error
|
}
|
},
|
|
// 获取可晋级参赛者列表
|
async getPromotableParticipants(currentStageId) {
|
try {
|
const variables = { currentStageId }
|
const data = await graphqlRequest(GET_PROMOTABLE_PARTICIPANTS, variables)
|
return data.promotableParticipants
|
} catch (error) {
|
console.error('获取可晋级参赛者列表失败:', error)
|
throw error
|
}
|
},
|
|
// 执行晋级操作
|
async promoteParticipants(competitionId, participantIds, targetStageId) {
|
try {
|
const variables = {
|
input: {
|
competitionId,
|
participantIds,
|
targetStageId
|
}
|
}
|
const data = await graphqlRequest(PROMOTE_PARTICIPANTS, variables)
|
return data.promoteParticipants
|
} catch (error) {
|
console.error('执行晋级操作失败:', error)
|
throw error
|
}
|
}
|
}
|
|
export default PromotionApi
|