forked from Cookies_Github_mirror/AquaDX
[O] Rewrite GetUserRecentRating
This commit is contained in:
@@ -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