mirror of https://github.com/hykilpikonna/AquaDX
[-] Remove unused
parent
806e24b9f1
commit
18554ec439
|
@ -3,20 +3,12 @@ package icu.samnyan.aqua.api.controller.sega.game.chuni.v2;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import icu.samnyan.aqua.api.model.MessageResponse;
|
import icu.samnyan.aqua.api.model.MessageResponse;
|
||||||
import icu.samnyan.aqua.api.model.ReducedPageResponse;
|
import icu.samnyan.aqua.api.model.ReducedPageResponse;
|
||||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.v2.RatingItem;
|
|
||||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.v2.RecentResp;
|
import icu.samnyan.aqua.api.model.resp.sega.chuni.v2.RecentResp;
|
||||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.v2.external.Chu3DataExport;
|
import icu.samnyan.aqua.api.model.resp.sega.chuni.v2.external.Chu3DataExport;
|
||||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.v2.external.ChuniDataImport;
|
|
||||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.v2.external.ExternalUserData;
|
|
||||||
import icu.samnyan.aqua.api.util.ApiMapper;
|
import icu.samnyan.aqua.api.util.ApiMapper;
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.Level;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.Music;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.userdata.*;
|
import icu.samnyan.aqua.sega.chusan.model.userdata.*;
|
||||||
import icu.samnyan.aqua.sega.chusan.service.*;
|
import icu.samnyan.aqua.sega.chusan.service.*;
|
||||||
import icu.samnyan.aqua.sega.general.model.Card;
|
|
||||||
import icu.samnyan.aqua.sega.general.service.CardService;
|
import icu.samnyan.aqua.sega.general.service.CardService;
|
||||||
import icu.samnyan.aqua.sega.util.VersionInfo;
|
|
||||||
import icu.samnyan.aqua.sega.util.VersionUtil;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -31,7 +23,6 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For all aimeId parameter, should use String
|
* For all aimeId parameter, should use String
|
||||||
|
@ -61,7 +52,6 @@ public class ApiChuniV2PlayerDataController {
|
||||||
private final UserMusicDetailService userMusicDetailService;
|
private final UserMusicDetailService userMusicDetailService;
|
||||||
private final UserPlaylogService userPlaylogService;
|
private final UserPlaylogService userPlaylogService;
|
||||||
private final UserGeneralDataService userGeneralDataService;
|
private final UserGeneralDataService userGeneralDataService;
|
||||||
private final GameMusicService gameMusicService;
|
|
||||||
|
|
||||||
@PutMapping("profile/username")
|
@PutMapping("profile/username")
|
||||||
public Chu3UserData updateName(@RequestBody Map<String, Object> request) {
|
public Chu3UserData updateName(@RequestBody Map<String, Object> request) {
|
||||||
|
@ -171,90 +161,6 @@ public class ApiChuniV2PlayerDataController {
|
||||||
}), playLogs.getPageable().getPageNumber(), playLogs.getTotalPages(), playLogs.getTotalElements());
|
}), playLogs.getPageable().getPageNumber(), playLogs.getTotalPages(), playLogs.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("rating")
|
|
||||||
public List<RatingItem> getRating(@RequestParam String aimeId) {
|
|
||||||
|
|
||||||
Map<Integer, Music> musicMap = gameMusicService.getIdMap();
|
|
||||||
List<UserMusicDetail> details = userMusicDetailService.getByUserId(aimeId);
|
|
||||||
|
|
||||||
var user = userDataService.getUserByExtId(aimeId).orElseThrow();
|
|
||||||
var version = VersionUtil.parseVersion(user.getLastRomVersion());
|
|
||||||
|
|
||||||
List<RatingItem> result = new ArrayList<>();
|
|
||||||
for (UserMusicDetail detail : details) {
|
|
||||||
Music music = musicMap.get(detail.getMusicId());
|
|
||||||
if (music != null) {
|
|
||||||
Level level = music.getLevels().get(detail.getLevel());
|
|
||||||
if (level != null) {
|
|
||||||
int levelBase = level.getLevel() * 100 + level.getLevelDecimal();
|
|
||||||
int score = detail.getScoreMax();
|
|
||||||
int rating = calculateRating(levelBase, score, version);
|
|
||||||
result.add(new RatingItem(music.getMusicId(), music.getName(), music.getArtistName(), level.getDiff(), score, levelBase, rating));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.stream()
|
|
||||||
.filter(detail -> detail.getLevel() != 5)
|
|
||||||
.sorted(Comparator.comparingInt(RatingItem::getRating).reversed())
|
|
||||||
.limit(30)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("rating/recent")
|
|
||||||
public List<RatingItem> getRecentRating(@RequestParam String aimeId) {
|
|
||||||
Map<Integer, Music> musicMap = gameMusicService.getIdMap();
|
|
||||||
Optional<UserGeneralData> recentOptional = userGeneralDataService.getByUserIdAndKey(aimeId, "recent_rating_list");
|
|
||||||
|
|
||||||
|
|
||||||
var user = userDataService.getUserByExtId(aimeId).orElseThrow();
|
|
||||||
var version = VersionUtil.parseVersion(user.getLastRomVersion());
|
|
||||||
|
|
||||||
List<RatingItem> result = new LinkedList<>();
|
|
||||||
if (recentOptional.isPresent()) {
|
|
||||||
// Read from recent_rating_list
|
|
||||||
String val = recentOptional.get().getPropertyValue();
|
|
||||||
if (StringUtils.isNotBlank(val) && val.contains(",")) {
|
|
||||||
String[] records = val.split(",");
|
|
||||||
for (String record :
|
|
||||||
records) {
|
|
||||||
String[] value = record.split(":");
|
|
||||||
Music music = musicMap.get(Integer.parseInt(value[0]));
|
|
||||||
if (music != null) {
|
|
||||||
Level level = music.getLevels().get(Integer.parseInt(value[1]));
|
|
||||||
if (level != null) {
|
|
||||||
int levelBase = getLevelBase(level.getLevel(), level.getLevelDecimal());
|
|
||||||
int score = Integer.parseInt(value[2]);
|
|
||||||
int rating = calculateRating(levelBase, score, version);
|
|
||||||
result.add(new RatingItem(music.getMusicId(), music.getName(), music.getArtistName(), level.getDiff(), score, levelBase, rating));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Use old method
|
|
||||||
List<UserPlaylog> logList = userPlaylogService.getRecent30Plays(aimeId);
|
|
||||||
for (UserPlaylog log : logList) {
|
|
||||||
Music music = musicMap.get(log.getMusicId());
|
|
||||||
if (music != null) {
|
|
||||||
Level level = music.getLevels().get(log.getLevel());
|
|
||||||
if (level != null) {
|
|
||||||
int levelBase = getLevelBase(level.getLevel(), level.getLevelDecimal());
|
|
||||||
int score = log.getScore();
|
|
||||||
int rating = calculateRating(levelBase, score, version);
|
|
||||||
result.add(new RatingItem(music.getMusicId(), music.getName(), music.getArtistName(), level.getDiff(), score, levelBase, rating));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.stream()
|
|
||||||
.filter(detail -> detail.getLevel() != 5)
|
|
||||||
.sorted(Comparator.comparingInt(RatingItem::getRating).reversed())
|
|
||||||
.limit(10)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("song/{id}")
|
@GetMapping("song/{id}")
|
||||||
public List<UserMusicDetail> getSongDetail(@RequestParam String aimeId, @PathVariable int id) {
|
public List<UserMusicDetail> getSongDetail(@RequestParam String aimeId, @PathVariable int id) {
|
||||||
return userMusicDetailService.getByUserIdAndMusicId(aimeId, id);
|
return userMusicDetailService.getByUserIdAndMusicId(aimeId, id);
|
||||||
|
@ -407,20 +313,4 @@ public class ApiChuniV2PlayerDataController {
|
||||||
headers.set("content-disposition", "attachment; filename=chusan_" + aimeId + "_exported.json");
|
headers.set("content-disposition", "attachment; filename=chusan_" + aimeId + "_exported.json");
|
||||||
return new ResponseEntity<>(data, headers, HttpStatus.OK);
|
return new ResponseEntity<>(data, headers, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getLevelBase(int level, int levelDecimal) {
|
|
||||||
return level * 100 + levelDecimal;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calculateRating(int lv, int score, VersionInfo version) {
|
|
||||||
if (score >= 1009000) return lv + 215; //SSS+
|
|
||||||
if (score >= 1007500) return lv + 200 + (score - 1007500) / 100; //SSS
|
|
||||||
if (score >= 1005000) return lv + 150 + (score - 1005000) / 50; //SS+
|
|
||||||
if (score >= 1000000) return lv + 100 + (score - 1000000) / 100; //SS
|
|
||||||
if (score >= 975000) return lv + (score - 975000) / 250; //S+, S
|
|
||||||
if (score >= 925000) return lv - 300 + (score - 925000) * 3 / 500; //AA
|
|
||||||
if (score >= 900000) return lv - 500 + (score - 900000) * 4 / 500; //A
|
|
||||||
if (score >= 800000) return ((lv - 500) / 2 + (score - 800000) * ((lv - 500) / 2) / (100000)); //BBB
|
|
||||||
return 0; //C
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package icu.samnyan.aqua.sega.chusan.handler;
|
package icu.samnyan.aqua.sega.chusan.handler;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import icu.samnyan.aqua.sega.chusan.ChusanProps;
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
import icu.samnyan.aqua.sega.general.BaseHandler;
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameLoginBonus;
|
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameLoginBonus;
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameLoginBonusPreset;
|
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameLoginBonusPreset;
|
||||||
|
@ -8,10 +9,9 @@ import icu.samnyan.aqua.sega.chusan.model.userdata.Chu3UserData;
|
||||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserItem;
|
import icu.samnyan.aqua.sega.chusan.model.userdata.UserItem;
|
||||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserLoginBonus;
|
import icu.samnyan.aqua.sega.chusan.model.userdata.UserLoginBonus;
|
||||||
import icu.samnyan.aqua.sega.chusan.service.*;
|
import icu.samnyan.aqua.sega.chusan.service.*;
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
import lombok.AllArgsConstructor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -23,39 +23,17 @@ import java.util.Optional;
|
||||||
/**
|
/**
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
*/
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
@Component("ChusanGameLoginHandler")
|
@Component("ChusanGameLoginHandler")
|
||||||
public class GameLoginHandler implements BaseHandler {
|
public class GameLoginHandler implements BaseHandler {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GameLoginHandler.class);
|
private static final Logger logger = LoggerFactory.getLogger(GameLoginHandler.class);
|
||||||
|
private final ChusanProps props;
|
||||||
private boolean enableLoginBonus = false;
|
|
||||||
|
|
||||||
private final UserDataService userDataService;
|
private final UserDataService userDataService;
|
||||||
|
|
||||||
private final UserItemService userItemService;
|
private final UserItemService userItemService;
|
||||||
|
|
||||||
private final GameLoginBonusPresetService gameLoginBonusPresetService;
|
private final GameLoginBonusPresetService gameLoginBonusPresetService;
|
||||||
|
|
||||||
private final GameLoginBonusService gameLoginBonusService;
|
private final GameLoginBonusService gameLoginBonusService;
|
||||||
|
|
||||||
private final UserLoginBonusService userLoginBonusService;
|
private final UserLoginBonusService userLoginBonusService;
|
||||||
|
|
||||||
public GameLoginHandler(StringMapper mapper,
|
|
||||||
@Value("${game.chusan.loginbonus-enable:}") boolean enableLoginBonus,
|
|
||||||
UserDataService userDataService,
|
|
||||||
UserItemService userItemService,
|
|
||||||
GameLoginBonusPresetService gameLoginBonusPresetService,
|
|
||||||
GameLoginBonusService gameLoginBonusService,
|
|
||||||
UserLoginBonusService userLoginBonusService
|
|
||||||
) {
|
|
||||||
this.enableLoginBonus = enableLoginBonus;
|
|
||||||
this.userDataService = userDataService;
|
|
||||||
this.userItemService = userItemService;
|
|
||||||
this.gameLoginBonusPresetService = gameLoginBonusPresetService;
|
|
||||||
this.gameLoginBonusService = gameLoginBonusService;
|
|
||||||
this.userLoginBonusService = userLoginBonusService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||||
String userId = (String) request.get("userId");
|
String userId = (String) request.get("userId");
|
||||||
|
@ -63,7 +41,7 @@ public class GameLoginHandler implements BaseHandler {
|
||||||
boolean userPresent = userDataOptional.isPresent();
|
boolean userPresent = userDataOptional.isPresent();
|
||||||
if (userPresent){
|
if (userPresent){
|
||||||
userDataService.updateLoginTime(userDataOptional.get());
|
userDataService.updateLoginTime(userDataOptional.get());
|
||||||
if(this.enableLoginBonus){
|
if(props.getLoginBonusEnable()){
|
||||||
List<GameLoginBonusPreset> gameLoginBonusList = this.gameLoginBonusPresetService.getGameLoginBonusPresets(1);
|
List<GameLoginBonusPreset> gameLoginBonusList = this.gameLoginBonusPresetService.getGameLoginBonusPresets(1);
|
||||||
|
|
||||||
for (GameLoginBonusPreset preset: gameLoginBonusList) {
|
for (GameLoginBonusPreset preset: gameLoginBonusList) {
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package icu.samnyan.aqua.sega.chusan.service;
|
|
||||||
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.Chu3GameMusicRepo;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.Music;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Service("ChusanGameMusicService")
|
|
||||||
public class GameMusicService {
|
|
||||||
|
|
||||||
private final Chu3GameMusicRepo gameMusicRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public GameMusicService(Chu3GameMusicRepo gameMusicRepository) {
|
|
||||||
this.gameMusicRepository = gameMusicRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Music save(Music music) {
|
|
||||||
return gameMusicRepository.save(music);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Music> saveAll(List<Music> musicList) {
|
|
||||||
return gameMusicRepository.saveAll(musicList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cacheable("music")
|
|
||||||
public List<Music> getAll() {
|
|
||||||
return gameMusicRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, Music> getIdMap() {
|
|
||||||
Map<Integer, Music> musicMap = new LinkedHashMap<>();
|
|
||||||
getAll().forEach(music -> musicMap.put(music.getMusicId(), music));
|
|
||||||
return musicMap;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,18 +22,6 @@ public class UserActivityService {
|
||||||
this.userActivityRepository = userActivityRepository;
|
this.userActivityRepository = userActivityRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserActivity save(UserActivity userActivity) {
|
|
||||||
return userActivityRepository.save(userActivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UserActivity> saveAll(List<UserActivity> userActivityList) {
|
|
||||||
return userActivityRepository.saveAll(userActivityList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<UserActivity> getByUserAndActivityIdAndKind(Chu3UserData user, int activityId, int kind) {
|
|
||||||
return userActivityRepository.findTopByUserAndActivityIdAndKindOrderByIdDesc(user, activityId, kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UserActivity> getByUserId(String userId) {
|
public List<UserActivity> getByUserId(String userId) {
|
||||||
return userActivityRepository.findByUser_Card_ExtId(Long.parseLong(userId));
|
return userActivityRepository.findByUser_Card_ExtId(Long.parseLong(userId));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue