Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tabulator-another
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
tabulator-another
Commits
8c220d79
Commit
8c220d79
authored
May 22, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add participant seq
parent
82191785
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
5 deletions
+94
-5
src/match/match.service.ts
src/match/match.service.ts
+8
-3
src/participant/entities/participant.entity.ts
src/participant/entities/participant.entity.ts
+11
-2
src/participant/participant.service.ts
src/participant/participant.service.ts
+2
-0
src/tournament/entities/Tournament.entity.ts
src/tournament/entities/Tournament.entity.ts
+2
-0
src/tournament/tournament.controller.ts
src/tournament/tournament.controller.ts
+12
-0
src/tournament/tournament.service.ts
src/tournament/tournament.service.ts
+52
-0
src/utility/shuffle-array.ts
src/utility/shuffle-array.ts
+7
-0
No files found.
src/match/match.service.ts
View file @
8c220d79
...
@@ -95,6 +95,13 @@ export class MatchService extends CrudService(Match, {
...
@@ -95,6 +95,13 @@ export class MatchService extends CrudService(Match, {
if
(
dto
.
winnerId
!==
undefined
)
{
if
(
dto
.
winnerId
!==
undefined
)
{
dto
.
status
=
MatchStatus
.
Finished
;
dto
.
status
=
MatchStatus
.
Finished
;
}
}
if
(
dto
.
player1Score
===
0
&&
dto
.
player2Score
===
0
&&
dto
.
winnerId
===
undefined
)
{
dto
.
status
=
MatchStatus
.
Pending
;
}
if
(
if
(
match
.
status
===
MatchStatus
.
Finished
&&
match
.
status
===
MatchStatus
.
Finished
&&
(
dto
.
winnerId
!==
undefined
||
(
dto
.
winnerId
!==
undefined
||
...
@@ -114,9 +121,7 @@ export class MatchService extends CrudService(Match, {
...
@@ -114,9 +121,7 @@ export class MatchService extends CrudService(Match, {
);
);
}
}
dto
.
winnerId
||=
null
;
dto
.
winnerId
||=
null
;
if
(
dto
.
player1Score
===
0
&&
dto
.
player2Score
===
0
)
{
dto
.
status
=
MatchStatus
.
Pending
;
}
const
result
=
await
this
.
update
(
id
,
dto
);
const
result
=
await
this
.
update
(
id
,
dto
);
await
this
.
tournamentService
.
afterMatchUpdate
(
match
.
tournamentId
);
await
this
.
tournamentService
.
afterMatchUpdate
(
match
.
tournamentId
);
return
result
;
return
result
;
...
...
src/participant/entities/participant.entity.ts
View file @
8c220d79
import
{
Entity
,
ManyToOne
,
OneToMany
}
from
'
typeorm
'
;
import
{
Entity
,
Index
,
ManyToOne
,
OneToMany
}
from
'
typeorm
'
;
import
{
NamedBase
}
from
'
../../utility/NamedBase.entity
'
;
import
{
NamedBase
}
from
'
../../utility/NamedBase.entity
'
;
import
{
import
{
BoolColumn
,
BoolColumn
,
IntColumn
,
NotChangeable
,
NotChangeable
,
NotColumn
,
NotColumn
,
NotQueryable
,
NotQueryable
,
...
@@ -34,7 +35,7 @@ export class ParticipantScore {
...
@@ -34,7 +35,7 @@ export class ParticipantScore {
tieBreaker
:
number
;
tieBreaker
:
number
;
}
}
@
Entity
(
{
orderBy
:
{
id
:
'
ASC
'
}
}
)
@
Entity
()
export
class
Participant
extends
NamedBase
{
export
class
Participant
extends
NamedBase
{
@
QueryMatchBoolean
()
@
QueryMatchBoolean
()
@
BoolColumn
({
default
:
false
,
description
:
'
是否已经退赛
'
})
@
BoolColumn
({
default
:
false
,
description
:
'
是否已经退赛
'
})
...
@@ -67,6 +68,14 @@ export class Participant extends NamedBase {
...
@@ -67,6 +68,14 @@ export class Participant extends NamedBase {
})
})
score
:
ParticipantScore
;
score
:
ParticipantScore
;
@
Index
()
@
QueryEqual
()
@
IntColumn
(
'
int
'
,
{
description
:
'
该选手的排序,小号在前
'
,
default
:
1000
,
})
seq
:
number
;
getMatches
()
{
getMatches
()
{
return
this
.
matches1
.
concat
(
this
.
matches2
);
return
this
.
matches1
.
concat
(
this
.
matches2
);
}
}
...
...
src/participant/participant.service.ts
View file @
8c220d79
...
@@ -12,6 +12,8 @@ import { TournamentService } from '../tournament/tournament.service';
...
@@ -12,6 +12,8 @@ import { TournamentService } from '../tournament/tournament.service';
@
Injectable
()
@
Injectable
()
export
class
ParticipantService
extends
CrudService
(
Participant
,
{
export
class
ParticipantService
extends
CrudService
(
Participant
,
{
relations
:
[
Inner
(
'
tournament
'
)],
relations
:
[
Inner
(
'
tournament
'
)],
extraGetQuery
:
(
qb
)
=>
qb
.
orderBy
(
'
participant.seq
'
,
'
ASC
'
).
addOrderBy
(
'
participant.id
'
,
'
ASC
'
),
})
{
})
{
constructor
(
constructor
(
@
InjectRepository
(
Participant
)
repo
,
@
InjectRepository
(
Participant
)
repo
,
...
...
src/tournament/entities/Tournament.entity.ts
View file @
8c220d79
...
@@ -256,6 +256,8 @@ export class Tournament extends DescBase {
...
@@ -256,6 +256,8 @@ export class Tournament extends DescBase {
this
.
participants
,
this
.
participants
,
(
p
)
=>
-
p
.
score
.
score
,
(
p
)
=>
-
p
.
score
.
score
,
(
p
)
=>
-
p
.
score
.
tieBreaker
,
(
p
)
=>
-
p
.
score
.
tieBreaker
,
(
p
)
=>
p
.
seq
,
(
p
)
=>
p
.
id
,
(
p
)
=>
p
.
id
,
);
);
this
.
participants
.
forEach
((
p
,
i
)
=>
{
this
.
participants
.
forEach
((
p
,
i
)
=>
{
...
...
src/tournament/tournament.controller.ts
View file @
8c220d79
...
@@ -196,4 +196,16 @@ export class TournamentController {
...
@@ -196,4 +196,16 @@ export class TournamentController {
)
{
)
{
return
this
.
tournamentService
.
importParticipantsFrom
(
id
,
dto
,
user
);
return
this
.
tournamentService
.
importParticipantsFrom
(
id
,
dto
,
user
);
}
}
@
Post
(
'
:id/shuffle-participants
'
)
@
HttpCode
(
200
)
@
ApiOperation
({
summary
:
'
打乱比赛选手
'
})
@
ApiParam
({
name
:
'
id
'
,
description
:
'
Tournament ID
'
})
@
ApiOkResponse
({
type
:
BlankReturnMessageDto
})
async
shuffleParticipants
(
@
factory
.
idParam
()
id
:
number
,
@
PutMycardUser
()
user
:
MycardUser
,
)
{
return
this
.
tournamentService
.
shuffleParticipants
(
id
,
user
);
}
}
}
src/tournament/tournament.service.ts
View file @
8c220d79
...
@@ -15,6 +15,7 @@ import { filter, lastValueFrom, mergeMap, tap } from 'rxjs';
...
@@ -15,6 +15,7 @@ import { filter, lastValueFrom, mergeMap, tap } from 'rxjs';
import
{
Readable
}
from
'
stream
'
;
import
{
Readable
}
from
'
stream
'
;
import
{
parseZipStream
}
from
'
../utility/parse-zip-stream
'
;
import
{
parseZipStream
}
from
'
../utility/parse-zip-stream
'
;
import
YGOProDeck
from
'
ygopro-deck-encode
'
;
import
YGOProDeck
from
'
ygopro-deck-encode
'
;
import
{
shuffleArray
}
from
'
../utility/shuffle-array
'
;
@
Injectable
()
@
Injectable
()
export
class
TournamentService
extends
CrudService
(
Tournament
,
{
export
class
TournamentService
extends
CrudService
(
Tournament
,
{
...
@@ -25,6 +26,13 @@ export class TournamentService extends CrudService(Tournament, {
...
@@ -25,6 +26,13 @@ export class TournamentService extends CrudService(Tournament, {
'
matches.player2
'
,
'
matches.player2
'
,
'
matches.winner
'
,
'
matches.winner
'
,
],
],
extraGetQuery
:
(
qb
)
=>
qb
.
addOrderBy
(
'
participants.seq
'
,
'
ASC
'
)
.
addOrderBy
(
'
participants.id
'
,
'
ASC
'
)
.
addOrderBy
(
'
matches.round
'
,
'
ASC
'
)
.
addOrderBy
(
'
matches.isThirdPlaceMatch
'
,
'
ASC
'
)
.
addOrderBy
(
'
matches.id
'
,
'
ASC
'
),
})
{
})
{
constructor
(
constructor
(
@
InjectRepository
(
Tournament
)
repo
,
@
InjectRepository
(
Tournament
)
repo
,
...
@@ -348,4 +356,48 @@ export class TournamentService extends CrudService(Tournament, {
...
@@ -348,4 +356,48 @@ export class TournamentService extends CrudService(Tournament, {
}
}
return
this
.
participantService
.
importParticipants
(
participants
,
user
);
return
this
.
participantService
.
importParticipants
(
participants
,
user
);
}
}
async
shuffleParticipants
(
id
:
number
,
user
:
MycardUser
|
number
)
{
const
tournament
=
await
this
.
checkPermissionOfTournament
(
id
,
user
,
[
'
status
'
],
[
'
participants
'
],
);
if
(
tournament
.
status
!==
TournamentStatus
.
Ready
)
{
throw
new
BlankReturnMessageDto
(
403
,
'
比赛已经开始,不能打乱参赛者。
'
,
).
toException
();
}
if
(
!
tournament
.
participants
.
length
)
{
throw
new
BlankReturnMessageDto
(
404
,
'
没有选手,不能打乱参赛者。
'
,
).
toException
();
}
const
participants
=
[...
tournament
.
participants
];
// shuffle
shuffleArray
(
participants
);
participants
.
forEach
((
p
,
i
)
=>
{
p
.
seq
=
1000
+
100
*
i
;
});
const
ids
=
participants
.
map
((
p
)
=>
p
.
id
);
const
cases
=
participants
.
map
((
p
)
=>
`WHEN
${
p
.
id
}
THEN
${
p
.
seq
}
`
)
.
join
(
'
\n
'
);
await
this
.
repo
.
manager
.
createQueryBuilder
()
.
update
(
Participant
)
.
set
({
seq
:
()
=>
`
CASE id
${
cases
}
END
`
,
})
.
whereInIds
(
ids
)
.
execute
();
return
new
BlankReturnMessageDto
(
200
,
'
success
'
);
}
}
}
src/utility/shuffle-array.ts
0 → 100644
View file @
8c220d79
export
function
shuffleArray
<
T
>
(
arr
:
T
[]):
T
[]
{
for
(
let
i
=
arr
.
length
-
1
;
i
>
0
;
i
--
)
{
const
j
=
Math
.
floor
(
Math
.
random
()
*
(
i
+
1
));
// 0 ≤ j ≤ i
[
arr
[
i
],
arr
[
j
]]
=
[
arr
[
j
],
arr
[
i
]];
// swap elements
}
return
arr
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment