mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-04 22:47:26 +08:00
[O] Rewrite GetUserRecentRating
This commit is contained in:
@@ -13,6 +13,7 @@ import icu.samnyan.aqua.sega.chusan.model.userdata.UserCharge
|
|||||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
import icu.samnyan.aqua.sega.general.BaseHandler
|
||||||
import icu.samnyan.aqua.sega.general.RequestContext
|
import icu.samnyan.aqua.sega.general.RequestContext
|
||||||
import icu.samnyan.aqua.sega.general.SpecialHandler
|
import icu.samnyan.aqua.sega.general.SpecialHandler
|
||||||
|
import icu.samnyan.aqua.sega.general.model.response.UserRecentRating
|
||||||
import icu.samnyan.aqua.sega.general.toSpecial
|
import icu.samnyan.aqua.sega.general.toSpecial
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper
|
import icu.samnyan.aqua.sega.util.jackson.StringMapper
|
||||||
import icu.samnyan.aqua.spring.Metrics
|
import icu.samnyan.aqua.spring.Metrics
|
||||||
@@ -50,7 +51,7 @@ class ChusanServletController(
|
|||||||
|
|
||||||
// Below are code related to handling the handlers
|
// Below are code related to handling the handlers
|
||||||
val externalHandlers = mutableListOf(
|
val externalHandlers = mutableListOf(
|
||||||
"GameLoginApi", "GetUserMusicApi", "GetUserRecentRatingApi", "UpsertUserAllApi",
|
"GameLoginApi", "GetUserMusicApi", "UpsertUserAllApi",
|
||||||
"CMGetUserCharacterApi", "CMUpsertUserGachaApi",
|
"CMGetUserCharacterApi", "CMUpsertUserGachaApi",
|
||||||
"CMUpsertUserPrintCancelApi", "CMUpsertUserPrintSubtractApi")
|
"CMUpsertUserPrintCancelApi", "CMUpsertUserPrintSubtractApi")
|
||||||
|
|
||||||
@@ -269,6 +270,16 @@ fun ChusanServletController.init() {
|
|||||||
mapOf("userId" to uid, "length" to lst.size, "userLoginBonusList" to lst)
|
mapOf("userId" to uid, "length" to lst.size, "userLoginBonusList" to lst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"GetUserRecentRating" {
|
||||||
|
val lst = db.userGeneralData.findByUser_Card_ExtIdAndPropertyKey(uid, "recent_rating_list")()
|
||||||
|
?.propertyValue?.ifBlank { null }
|
||||||
|
?.split(',')?.dropLastWhile { it.isEmpty() }?.map { it.split(':') }
|
||||||
|
?.map { (musicId, level, ver, score) -> UserRecentRating(musicId.int, level.int, ver, score.int) }
|
||||||
|
?: listOf()
|
||||||
|
|
||||||
|
mapOf("userId" to uid, "length" to lst.size, "userRecentRatingList" to lst)
|
||||||
|
}
|
||||||
|
|
||||||
"GetUserMapArea" {
|
"GetUserMapArea" {
|
||||||
val maps = parsing { data["mapAreaIdList"] as List<Map<String, String>> }
|
val maps = parsing { data["mapAreaIdList"] as List<Map<String, String>> }
|
||||||
.mapNotNull { it["mapAreaId"]?.toIntOrNull() }
|
.mapNotNull { it["mapAreaId"]?.toIntOrNull() }
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.chusan.handler;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserGeneralData;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserPlaylog;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.service.UserGeneralDataService;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.service.UserPlaylogService;
|
|
||||||
import icu.samnyan.aqua.sega.general.model.response.UserRecentRating;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the recent play to calculate rating. Rating base on top 30 songs plus top 10 in recent 30 plays.
|
|
||||||
*
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Component("ChusanGetUserRecentRatingHandler")
|
|
||||||
public class GetUserRecentRatingHandler implements BaseHandler {
|
|
||||||
private final UserPlaylogService userPlaylogService;
|
|
||||||
private final UserGeneralDataService userGeneralDataService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object handle(Map<String, ?> request) throws JsonProcessingException {
|
|
||||||
String userId = (String) request.get("userId");
|
|
||||||
|
|
||||||
Optional<UserGeneralData> recentOptional = userGeneralDataService.getByUserIdAndKey(userId, "recent_rating_list");
|
|
||||||
|
|
||||||
List<UserRecentRating> ratingList;
|
|
||||||
if(recentOptional.isPresent()) {
|
|
||||||
ratingList = new LinkedList<>();
|
|
||||||
String val = recentOptional.get().getPropertyValue();
|
|
||||||
if(StringUtils.isNotBlank(val) && val.contains(",")) {
|
|
||||||
String[] records = val.split(",");
|
|
||||||
for (String record :
|
|
||||||
records) {
|
|
||||||
String[] value = record.split(":");
|
|
||||||
ratingList.add(new UserRecentRating(
|
|
||||||
Integer.parseInt(value[0]),
|
|
||||||
Integer.parseInt(value[1]),
|
|
||||||
"2000001",
|
|
||||||
Integer.parseInt(value[2])
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
List<UserPlaylog> top = userPlaylogService.getRecent30Plays(userId);
|
|
||||||
ratingList = top.stream().map(log -> new UserRecentRating(log.getMusicId(), log.getLevel(), "2000001", log.getScore()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("userId", userId);
|
|
||||||
resultMap.put("length", ratingList.size());
|
|
||||||
resultMap.put("userRecentRatingList", ratingList);
|
|
||||||
|
|
||||||
return resultMap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user