lrj
昨天 93eb6b470773bc49ea6e1a9d4cbd914eb95d525b
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
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