Add staff role mapping, display role in UI, and enhance staff playtime calculations
This commit is contained in:
parent
1d76895cbb
commit
fb01fc7571
|
|
@ -1,6 +1,6 @@
|
|||
package com.alttd.altitudeweb.mappers;
|
||||
|
||||
import com.alttd.altitudeweb.database.luckperms.Player;
|
||||
import com.alttd.altitudeweb.database.luckperms.PlayerWithGroup;
|
||||
import com.alttd.altitudeweb.database.proxyplaytime.StaffPt;
|
||||
import com.alttd.altitudeweb.model.StaffPlaytimeDto;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -15,10 +15,10 @@ import java.util.concurrent.TimeUnit;
|
|||
public final class StaffPtToStaffPlaytimeMapper {
|
||||
private record PlaytimeInfo(long totalPlaytime, long lastPlayed) {}
|
||||
|
||||
public List<StaffPlaytimeDto> map(List<StaffPt> sessions, List<Player> staffMembers, long from, long to) {
|
||||
public List<StaffPlaytimeDto> map(List<StaffPt> sessions, List<PlayerWithGroup> staffMembers, long from, long to, HashMap<String, String> staffGroupsMap) {
|
||||
Map<UUID, PlaytimeInfo> playtimeData = getUuidPlaytimeInfoMap(sessions, from, to);
|
||||
|
||||
for (Player staffMember : staffMembers) {
|
||||
for (PlayerWithGroup staffMember : staffMembers) {
|
||||
if (!playtimeData.containsKey(staffMember.uuid())) {
|
||||
playtimeData.put(staffMember.uuid(), new PlaytimeInfo(0L, Long.MIN_VALUE));
|
||||
}
|
||||
|
|
@ -28,14 +28,22 @@ public final class StaffPtToStaffPlaytimeMapper {
|
|||
for (Map.Entry<UUID, PlaytimeInfo> entry : playtimeData.entrySet()) {
|
||||
long lastPlayedMillis = entry.getValue().lastPlayed() == Long.MIN_VALUE ? 0L : entry.getValue().lastPlayed();
|
||||
StaffPlaytimeDto dto = new StaffPlaytimeDto();
|
||||
Optional<PlayerWithGroup> first = staffMembers.stream()
|
||||
.filter(player -> player.uuid().equals(entry.getKey())).findFirst();
|
||||
dto.setStaffMember(first.isPresent() ? first.get().username() : entry.getKey().toString());
|
||||
dto.setStaffMember(staffMembers.stream()
|
||||
.filter(player -> player.uuid().equals(entry.getKey()))
|
||||
.map(Player::username)
|
||||
.map(PlayerWithGroup::username)
|
||||
.findFirst()
|
||||
.orElse(entry.getKey().toString())
|
||||
);
|
||||
dto.setLastPlayed(OffsetDateTime.ofInstant(Instant.ofEpochMilli(lastPlayedMillis), ZoneOffset.UTC));
|
||||
dto.setPlaytime((int) TimeUnit.MILLISECONDS.toMinutes(entry.getValue().totalPlaytime()));
|
||||
if (first.isPresent()) {
|
||||
dto.setRole(staffGroupsMap.getOrDefault(first.get().group(), "Unknown"));
|
||||
} else {
|
||||
dto.setRole("Unknown");
|
||||
}
|
||||
results.add(dto);
|
||||
}
|
||||
return results;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.alttd.altitudeweb.services.site;
|
|||
|
||||
import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.luckperms.Player;
|
||||
import com.alttd.altitudeweb.database.luckperms.PlayerWithGroup;
|
||||
import com.alttd.altitudeweb.database.luckperms.TeamMemberMapper;
|
||||
import com.alttd.altitudeweb.database.proxyplaytime.StaffPlaytimeMapper;
|
||||
import com.alttd.altitudeweb.database.proxyplaytime.StaffPt;
|
||||
|
|
@ -14,6 +15,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -23,17 +25,30 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class StaffPtService {
|
||||
private final static String STAFF_GROUPS = "'group.admin', 'group.developer', 'group.headmod', 'group.manager', 'group.moderator', 'group.owner', 'group.trainee'";
|
||||
private final static HashMap<String, String> STAFF_GROUPS_MAP = new HashMap<>();
|
||||
private final static String STAFF_GROUPS;
|
||||
static {
|
||||
STAFF_GROUPS_MAP.put("group.owner", "Owner");
|
||||
STAFF_GROUPS_MAP.put("group.manager", "Manager");
|
||||
STAFF_GROUPS_MAP.put("group.admin", "Admin");
|
||||
STAFF_GROUPS_MAP.put("group.headmod", "Head Mod");
|
||||
STAFF_GROUPS_MAP.put("group.moderator", "Moderator");
|
||||
STAFF_GROUPS_MAP.put("group.trainee", "Trainee");
|
||||
STAFF_GROUPS_MAP.put("group.developer", "Developer");
|
||||
STAFF_GROUPS = STAFF_GROUPS_MAP.keySet().stream()
|
||||
.map(group -> "'" + group + "'")
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
private final StaffPtToStaffPlaytimeMapper staffPtToStaffPlaytimeMapper;
|
||||
|
||||
public Optional<List<StaffPlaytimeDto>> getStaffPlaytime(Instant from, Instant to) {
|
||||
CompletableFuture<List<Player>> staffMembersFuture = new CompletableFuture<>();
|
||||
CompletableFuture<List<PlayerWithGroup>> staffMembersFuture = new CompletableFuture<>();
|
||||
CompletableFuture<List<StaffPt>> staffPlaytimeFuture = new CompletableFuture<>();
|
||||
Connection.getConnection(Databases.LUCK_PERMS)
|
||||
.runQuery(sqlSession -> {
|
||||
log.debug("Loading staff members");
|
||||
try {
|
||||
List<Player> staffMemberList = sqlSession.getMapper(TeamMemberMapper.class)
|
||||
List<PlayerWithGroup> staffMemberList = sqlSession.getMapper(TeamMemberMapper.class)
|
||||
.getTeamMembersOfGroupList(STAFF_GROUPS);
|
||||
staffMembersFuture.complete(staffMemberList);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -41,14 +56,14 @@ public class StaffPtService {
|
|||
staffMembersFuture.completeExceptionally(e);
|
||||
}
|
||||
});
|
||||
List<Player> staffMembers = staffMembersFuture.join().stream()
|
||||
List<PlayerWithGroup> staffMembers = staffMembersFuture.join().stream()
|
||||
.collect(Collectors.collectingAndThen(
|
||||
Collectors.toMap(Player::uuid, player -> player, (player1, player2) -> player1),
|
||||
Collectors.toMap(PlayerWithGroup::uuid, player -> player, (player1, player2) -> player1),
|
||||
m -> new ArrayList<>(m.values())));
|
||||
Connection.getConnection(Databases.PROXY_PLAYTIME)
|
||||
.runQuery(sqlSession -> {
|
||||
String staffUUIDs = staffMembers.stream()
|
||||
.map(Player::uuid)
|
||||
.map(PlayerWithGroup::uuid)
|
||||
.map(uuid -> "'" + uuid + "'")
|
||||
.collect(Collectors.joining(","));
|
||||
log.debug("Loading staff playtime for group");
|
||||
|
|
@ -62,7 +77,7 @@ public class StaffPtService {
|
|||
}
|
||||
});
|
||||
List<StaffPt> join = staffPlaytimeFuture.join();
|
||||
|
||||
return Optional.of(staffPtToStaffPlaytimeMapper.map(join, staffMembers, from.toEpochMilli(), to.toEpochMilli()));
|
||||
HashMap<String, String> staffGroupsMap = new HashMap<>(STAFF_GROUPS_MAP);
|
||||
return Optional.of(staffPtToStaffPlaytimeMapper.map(join, staffMembers, from.toEpochMilli(), to.toEpochMilli(), staffGroupsMap));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package com.alttd.altitudeweb.database.luckperms;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record PlayerWithGroup(UUID uuid, String username, String group) {
|
||||
}
|
||||
|
|
@ -25,13 +25,13 @@ public interface TeamMemberMapper {
|
|||
@Arg(column = "uuid", javaType = UUID.class, typeHandler = UUIDTypeHandler.class)
|
||||
})
|
||||
@Select("""
|
||||
SELECT players.username, players.uuid
|
||||
SELECT players.username, players.uuid, players.primary_group AS 'group'
|
||||
FROM luckperms_user_permissions AS permissions
|
||||
INNER JOIN luckperms_players AS players ON players.uuid = permissions.uuid
|
||||
WHERE permission IN (${groupPermissions})
|
||||
AND server = 'global'
|
||||
AND world = 'global'
|
||||
""")
|
||||
List<Player> getTeamMembersOfGroupList(@Param("groupPermissions") String groupPermissions);
|
||||
List<PlayerWithGroup> getTeamMembersOfGroupList(@Param("groupPermissions") String groupPermissions);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,22 @@
|
|||
|
||||
<table mat-table [dataSource]="staffPt()" class="mat-elevation-z2 full-width">
|
||||
<ng-container matColumnDef="staff_member">
|
||||
<th mat-header-cell *matHeaderCellDef> Staff Member</th>
|
||||
<th mat-header-cell *matHeaderCellDef>Staff Member</th>
|
||||
<td mat-cell *matCellDef="let row"> {{ row.staff_member }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="playtime">
|
||||
<th mat-header-cell *matHeaderCellDef> Playtime</th>
|
||||
<th mat-header-cell *matHeaderCellDef>Playtime</th>
|
||||
<td mat-cell *matCellDef="let row"
|
||||
[style.color]="row.playtime < 420 ? 'red' : ''"> {{ minutesToHm(row.playtime) }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="role">
|
||||
<th mat-header-cell *matHeaderCellDef>Rank</th>
|
||||
<td mat-cell *matCellDef="let row"> {{ row.role }}</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ export class StaffPtComponent implements OnInit {
|
|||
parts.push(`${d}d`);
|
||||
}
|
||||
if (h > 0 || d > 0) {
|
||||
parts.push(`${h}h`);
|
||||
parts.push(`${h}hr`);
|
||||
}
|
||||
if (m > 0 || (h === 0 && d === 0)) {
|
||||
parts.push(`${m}m`);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ components:
|
|||
$ref: '#/components/schemas/StaffPlaytime'
|
||||
StaffPlaytime:
|
||||
type: object
|
||||
required:
|
||||
- staff_member
|
||||
- playtime
|
||||
- last_played
|
||||
- role
|
||||
properties:
|
||||
staff_member:
|
||||
type: string
|
||||
|
|
@ -51,3 +56,6 @@ components:
|
|||
type: string
|
||||
format: date-time
|
||||
description: Last played timestamp
|
||||
role:
|
||||
type: string
|
||||
description: The role of the staff member
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user