[DIVA] Fix ranking being reversed

pull/1/head
samnyan 2020-01-21 20:52:04 +08:00
parent 5fa287ffb6
commit 0f37346fdc
5 changed files with 82 additions and 5 deletions

View File

@ -1,16 +1,17 @@
package icu.samnyan.aqua.api.controller.sega.diva;
import icu.samnyan.aqua.api.model.ReducedPageResponse;
import icu.samnyan.aqua.api.model.resp.sega.diva.PvRankRecord;
import icu.samnyan.aqua.sega.diva.dao.userdata.*;
import icu.samnyan.aqua.sega.diva.model.common.Difficulty;
import icu.samnyan.aqua.sega.diva.model.common.Edition;
import icu.samnyan.aqua.sega.diva.model.userdata.*;
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.*;
/**
* @author samnyan (privateamusement@protonmail.com)
@ -41,6 +42,23 @@ public class ApiDivaPlayerDataController {
return playerProfileService.findByPdId(pdId);
}
@GetMapping("playerInfo/rival")
public Map<String, String> getRivalInfo(@RequestParam int pdId) {
int rId = playerProfileService.findByPdId(pdId).orElseThrow().getRivalPdId();
Map<String, String> result = new HashMap<>();
if (rId == -1) {
result.put("rival", "Not Set");
} else {
Optional<PlayerProfile> profile = playerProfileService.findByPdId(rId);
if (profile.isPresent()) {
result.put("rival", profile.get().getPlayerName());
} else {
result.put("rival", "Player Not Found");
}
}
return result;
}
@PutMapping("playerInfo/playerName")
public PlayerProfile updateName(@RequestBody Map<String, Object> request) {
PlayerProfile profile = playerProfileService.findByPdId((Integer) request.get("pdId")).orElseThrow();
@ -172,6 +190,46 @@ public class ApiDivaPlayerDataController {
return playerPvCustomizeRepository.save(playerPvCustomize);
}
@GetMapping("pvRecord/{pvId}/ranking/{difficulty}")
public ReducedPageResponse<PvRankRecord> getPvRanking(@PathVariable int pvId,
@PathVariable String difficulty,
@RequestParam(required = false, defaultValue = "0") int page,
@RequestParam(required = false, defaultValue = "10") int size) {
Difficulty diff = null;
Edition edition = Edition.ORIGINAL;
switch (difficulty) {
case "EASY":
diff = Difficulty.EASY;
break;
case "NORMAL":
diff = Difficulty.NORMAL;
break;
case "HARD":
diff = Difficulty.HARD;
break;
case "EXTREME":
diff = Difficulty.EXTREME;
break;
case "EXTRA_EXTREME": {
diff = Difficulty.EXTREME;
edition = Edition.EXTRA;
break;
}
}
if(diff != null) {
Page<PlayerPvRecord> pvRecords = playerPvRecordRepository.findByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(pvId, edition,diff, PageRequest.of(page, size));
List<PvRankRecord> rankList = new LinkedList<>();
pvRecords.forEach(x ->{
rankList.add(new PvRankRecord(x.getId(),x.getPdId().getPlayerName(),x.getMaxScore(),x.getMaxAttain()));
});
return new ReducedPageResponse<>(rankList, pvRecords.getPageable().getPageNumber(), pvRecords.getTotalPages(), pvRecords.getTotalElements());
}
return null;
}
@GetMapping("module")
public ReducedPageResponse<PlayerModule> getModules(@RequestParam int pdId,
@RequestParam(required = false, defaultValue = "0") int page,

View File

@ -0,0 +1,16 @@
package icu.samnyan.aqua.api.model.resp.sega.diva;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author sam_nya (samnya@outlook.com)
*/
@Data
@AllArgsConstructor
public class PvRankRecord {
private long id;
private String playerName;
private int score;
private int attain;
}

View File

@ -39,7 +39,9 @@ public interface PlayerPvRecordRepository extends JpaRepository<PlayerPvRecord,
List<PlayerPvRecord> findByPdIdAndEdition(PlayerProfile profile, Edition edition);
List<PlayerPvRecord> findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScore(int pvId, Edition edition, Difficulty difficulty);
List<PlayerPvRecord> findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(int pvId, Edition edition, Difficulty difficulty);
Page<PlayerPvRecord> findByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(int pvId, Edition edition, Difficulty difficulty, Pageable page);
Page<PlayerPvRecord> findByPdId_PdIdOrderByPvId(int pdId, Pageable page);

View File

@ -59,7 +59,7 @@ public class PsRankingHandler extends BaseHandler {
for (int i :
list) {
List<PlayerPvRecord> records = playerPvRecordRepository.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScore(i, Edition.ORIGINAL, difficulty);
List<PlayerPvRecord> records = playerPvRecordRepository.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(i, Edition.ORIGINAL, difficulty);
resultCollections.put(i, new PsRankingCollection(i, edition, records));
}

View File

@ -155,6 +155,7 @@ public class PlayerProfile implements Serializable {
private String myList2 = getDummyString("-1", 40);
@JsonIgnore
private int rivalPdId = -1;
public PlayerProfile(int pdId, String playerName) {