mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-12 18:47:28 +08:00
[ongeki] Move UpsertUserAll to a class
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
package icu.samnyan.aqua.sega.ongeki.handler.impl;
|
package icu.samnyan.aqua.sega.ongeki.handler.impl;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import icu.samnyan.aqua.sega.general.model.response.UserRecentRating;
|
|
||||||
import icu.samnyan.aqua.sega.general.model.Card;
|
import icu.samnyan.aqua.sega.general.model.Card;
|
||||||
|
import icu.samnyan.aqua.sega.general.model.response.UserRecentRating;
|
||||||
import icu.samnyan.aqua.sega.general.service.CardService;
|
import icu.samnyan.aqua.sega.general.service.CardService;
|
||||||
import icu.samnyan.aqua.sega.ongeki.dao.userdata.*;
|
import icu.samnyan.aqua.sega.ongeki.dao.userdata.*;
|
||||||
import icu.samnyan.aqua.sega.ongeki.handler.BaseHandler;
|
import icu.samnyan.aqua.sega.ongeki.handler.BaseHandler;
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.model.request.UpsertUserAll;
|
||||||
import icu.samnyan.aqua.sega.ongeki.model.response.CodeResp;
|
import icu.samnyan.aqua.sega.ongeki.model.response.CodeResp;
|
||||||
import icu.samnyan.aqua.sega.ongeki.model.userdata.*;
|
import icu.samnyan.aqua.sega.ongeki.model.userdata.*;
|
||||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||||
@@ -78,91 +78,81 @@ public class UpsertUserAllHandler implements BaseHandler {
|
|||||||
@Override
|
@Override
|
||||||
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
||||||
Integer userId = (Integer) request.get("userId");
|
Integer userId = (Integer) request.get("userId");
|
||||||
Map<String, Object> upsertUserAll = (Map<String, Object>) request.get("upsertUserAll");
|
UpsertUserAll upsertUserAll = mapper.convert(request.get("upsertUserAll"), UpsertUserAll.class);
|
||||||
|
|
||||||
|
// All the field should exist, no need to check now.
|
||||||
// UserData
|
// UserData
|
||||||
UserData userData;
|
UserData userData;
|
||||||
UserData newUserData;
|
UserData newUserData = upsertUserAll.getUserData().get(0);
|
||||||
if (!upsertUserAll.containsKey("userData")) {
|
|
||||||
return null;
|
Optional<UserData> userOptional = userDataRepository.findByCard_ExtId(userId);
|
||||||
|
|
||||||
|
if (userOptional.isPresent()) {
|
||||||
|
userData = userOptional.get();
|
||||||
} else {
|
} else {
|
||||||
Map<String, Object> userDataMap = ((List<Map<String, Object>>) upsertUserAll.get("userData")).get(0);
|
userData = new UserData();
|
||||||
|
Card card = cardService.getCardByExtId(userId).orElseThrow();
|
||||||
Optional<UserData> userOptional = userDataRepository.findByCard_ExtId(userId);
|
userData.setCard(card);
|
||||||
|
|
||||||
if (userOptional.isPresent()) {
|
|
||||||
userData = userOptional.get();
|
|
||||||
} else {
|
|
||||||
userData = new UserData();
|
|
||||||
Card card = cardService.getCardByExtId(userId).orElseThrow();
|
|
||||||
userData.setCard(card);
|
|
||||||
}
|
|
||||||
newUserData = mapper.convert(userDataMap, UserData.class);
|
|
||||||
|
|
||||||
newUserData.setId(userData.getId());
|
|
||||||
newUserData.setCard(userData.getCard());
|
|
||||||
|
|
||||||
userDataRepository.save(newUserData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newUserData.setId(userData.getId());
|
||||||
|
newUserData.setCard(userData.getCard());
|
||||||
|
|
||||||
|
userDataRepository.save(newUserData);
|
||||||
|
|
||||||
|
|
||||||
// UserOption
|
// UserOption
|
||||||
if (upsertUserAll.containsKey("userOption")) {
|
UserOption newUserOption = upsertUserAll.getUserOption().get(0);
|
||||||
Map<String, Object> userOptionMap = ((List<Map<String, Object>>) upsertUserAll.get("userOption")).get(0);
|
|
||||||
|
|
||||||
Optional<UserOption> userOptionOptional = userOptionRepository.findByUser(newUserData);
|
Optional<UserOption> userOptionOptional = userOptionRepository.findByUser(newUserData);
|
||||||
UserOption userOption = userOptionOptional.orElseGet(() -> new UserOption(newUserData));
|
UserOption userOption = userOptionOptional.orElseGet(() -> new UserOption(newUserData));
|
||||||
|
|
||||||
UserOption newUserOption = mapper.convert(userOptionMap, UserOption.class);
|
newUserOption.setId(userOption.getId());
|
||||||
newUserOption.setId(userOption.getId());
|
newUserOption.setUser(userOption.getUser());
|
||||||
newUserOption.setUser(userOption.getUser());
|
|
||||||
|
userOptionRepository.save(newUserOption);
|
||||||
|
|
||||||
userOptionRepository.save(newUserOption);
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserPlaylogList
|
// UserPlaylogList
|
||||||
if (upsertUserAll.containsKey("userPlaylogList")) {
|
List<UserPlaylog> userPlaylogList = upsertUserAll.getUserPlaylogList();
|
||||||
List<Map<String, Object>> userPlaylogList = ((List<Map<String, Object>>) upsertUserAll.get("userPlaylogList"));
|
List<UserPlaylog> newUserPlaylogList = new ArrayList<>();
|
||||||
List<UserPlaylog> newUserPlaylogList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userPlayLogMap : userPlaylogList) {
|
for (UserPlaylog newUserPlaylog : userPlaylogList) {
|
||||||
UserPlaylog newUserPlaylog = mapper.convert(userPlayLogMap, UserPlaylog.class);
|
newUserPlaylog.setUser(newUserData);
|
||||||
newUserPlaylog.setUser(newUserData);
|
newUserPlaylogList.add(newUserPlaylog);
|
||||||
newUserPlaylogList.add(newUserPlaylog);
|
|
||||||
}
|
|
||||||
|
|
||||||
userPlaylogRepository.saveAll(newUserPlaylogList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userPlaylogRepository.saveAll(newUserPlaylogList);
|
||||||
|
|
||||||
|
|
||||||
// UserSessionlogList doesn't need to save for a private server
|
// UserSessionlogList doesn't need to save for a private server
|
||||||
|
|
||||||
|
|
||||||
// UserActivityList
|
// UserActivityList
|
||||||
if (upsertUserAll.containsKey("userActivityList")) {
|
List<UserActivity> userActivityList = upsertUserAll.getUserActivityList();
|
||||||
List<Map<String, Object>> userActivityList = ((List<Map<String, Object>>) upsertUserAll.get("userActivityList"));
|
List<UserActivity> newUserActivityList = new ArrayList<>();
|
||||||
List<UserActivity> newUserActivityList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userActivityMap : userActivityList) {
|
for (UserActivity newUserActivity : userActivityList) {
|
||||||
Integer kind = (Integer) userActivityMap.get("kind");
|
int kind = newUserActivity.getKind();
|
||||||
Integer id = (Integer) userActivityMap.get("id");
|
int id = newUserActivity.getActivityId();
|
||||||
|
|
||||||
if (kind != 0 && id != 0) {
|
if (kind != 0 && id != 0) {
|
||||||
Optional<UserActivity> activityOptional = userActivityRepository.findByUserAndKindAndActivityId(newUserData, kind, id);
|
Optional<UserActivity> activityOptional = userActivityRepository.findByUserAndKindAndActivityId(newUserData, kind, id);
|
||||||
UserActivity userActivity = activityOptional.orElseGet(() -> new UserActivity(newUserData));
|
UserActivity userActivity = activityOptional.orElseGet(() -> new UserActivity(newUserData));
|
||||||
|
|
||||||
UserActivity newUserActivity = mapper.convert(userActivityMap, UserActivity.class);
|
newUserActivity.setId(userActivity.getId());
|
||||||
newUserActivity.setId(userActivity.getId());
|
newUserActivity.setUser(newUserData);
|
||||||
newUserActivity.setUser(newUserData);
|
newUserActivityList.add(newUserActivity);
|
||||||
newUserActivityList.add(newUserActivity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
newUserActivityList.sort((a, b) -> Integer.compare(b.getSortNumber(), a.getSortNumber()));
|
|
||||||
userActivityRepository.saveAll(newUserActivityList);
|
|
||||||
}
|
}
|
||||||
|
newUserActivityList.sort((a, b) -> Integer.compare(b.getSortNumber(), a.getSortNumber()));
|
||||||
|
userActivityRepository.saveAll(newUserActivityList);
|
||||||
|
|
||||||
|
|
||||||
// UserRecentRatingList
|
// UserRecentRatingList
|
||||||
// This thing still need to save to solve the rating drop
|
// This thing still need to save to solve the rating drop
|
||||||
if (upsertUserAll.containsKey("userRecentRatingList")) {
|
this.saveGeneralData(upsertUserAll.getUserRecentRatingList(), newUserData, "recent_rating_list");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userRecentRatingList", "recent_rating_list");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The rating and battle point calculation is little bit complex.
|
* The rating and battle point calculation is little bit complex.
|
||||||
@@ -170,275 +160,236 @@ public class UpsertUserAllHandler implements BaseHandler {
|
|||||||
* into a csv format for convenience
|
* into a csv format for convenience
|
||||||
*/
|
*/
|
||||||
// UserBpBaseList (For calculating Battle point)
|
// UserBpBaseList (For calculating Battle point)
|
||||||
if (upsertUserAll.containsKey("userBpBaseList")) {
|
this.saveGeneralData(upsertUserAll.getUserBpBaseList(), newUserData, "battle_point_base");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userBpBaseList", "battle_point_base");
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the best rating of all charts. Best 30 + 10 after that.
|
// This is the best rating of all charts. Best 30 + 10 after that.
|
||||||
// userRatingBaseBestList
|
// userRatingBaseBestList
|
||||||
if (upsertUserAll.containsKey("userRatingBaseBestList")) {
|
this.saveGeneralData(upsertUserAll.getUserRatingBaseBestList(), newUserData, "rating_base_best");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userRatingBaseBestList", "rating_base_best");
|
|
||||||
}
|
|
||||||
// userRatingBaseNextList
|
// userRatingBaseNextList
|
||||||
if (upsertUserAll.containsKey("userRatingBaseNextList")) {
|
this.saveGeneralData(upsertUserAll.getUserRatingBaseNextList(), newUserData, "rating_base_next");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userRatingBaseNextList", "rating_base_next");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// This is the best rating of new charts. Best 15 + 10 after that.
|
// This is the best rating of new charts. Best 15 + 10 after that.
|
||||||
// New chart means same version
|
// New chart means same version
|
||||||
// userRatingBaseBestNewList
|
// userRatingBaseBestNewList
|
||||||
if (upsertUserAll.containsKey("userRatingBaseBestNewList")) {
|
this.saveGeneralData(upsertUserAll.getUserRatingBaseBestNewList(), newUserData, "rating_base_new_best");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userRatingBaseBestNewList", "rating_base_new_best");
|
|
||||||
}
|
|
||||||
// userRatingBaseNextNewList
|
// userRatingBaseNextNewList
|
||||||
if (upsertUserAll.containsKey("userRatingBaseNextNewList")) {
|
this.saveGeneralData(upsertUserAll.getUserRatingBaseNextNewList(), newUserData, "rating_base_new_next");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userRatingBaseNextNewList", "rating_base_new_next");
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the recent best
|
// This is the recent best
|
||||||
// userRatingBaseHotList
|
// userRatingBaseHotList
|
||||||
if (upsertUserAll.containsKey("userRatingBaseHotList")) {
|
this.saveGeneralData(upsertUserAll.getUserRatingBaseHotList(), newUserData, "rating_base_hot_best");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userRatingBaseHotList", "rating_base_hot_best");
|
|
||||||
}
|
|
||||||
// userRatingBaseHotNextList
|
// userRatingBaseHotNextList
|
||||||
if (upsertUserAll.containsKey("userRatingBaseHotNextList")) {
|
this.saveGeneralData(upsertUserAll.getUserRatingBaseHotNextList(), newUserData, "rating_base_hot_next");
|
||||||
this.saveGeneralData(upsertUserAll, newUserData, "userRatingBaseHotNextList", "rating_base_hot_next");
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserMusicDetailList
|
// UserMusicDetailList
|
||||||
if (upsertUserAll.containsKey("userMusicDetailList")) {
|
List<UserMusicDetail> userMusicDetailList = upsertUserAll.getUserMusicDetailList();
|
||||||
List<Map<String, Object>> userMusicDetailList = ((List<Map<String, Object>>) upsertUserAll.get("userMusicDetailList"));
|
List<UserMusicDetail> newUserMusicDetailList = new ArrayList<>();
|
||||||
List<UserMusicDetail> newUserMusicDetailList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userMusicDetailMap : userMusicDetailList) {
|
for (UserMusicDetail newUserMusicDetail : userMusicDetailList) {
|
||||||
Integer musicId = (Integer) userMusicDetailMap.get("musicId");
|
int musicId = newUserMusicDetail.getMusicId();
|
||||||
Integer level = (Integer) userMusicDetailMap.get("level");
|
int level = newUserMusicDetail.getLevel();
|
||||||
|
|
||||||
Optional<UserMusicDetail> musicDetailOptional = userMusicDetailRepository.findByUserAndMusicIdAndLevel(newUserData, musicId, level);
|
Optional<UserMusicDetail> musicDetailOptional = userMusicDetailRepository.findByUserAndMusicIdAndLevel(newUserData, musicId, level);
|
||||||
UserMusicDetail userMusicDetail = musicDetailOptional.orElseGet(() -> new UserMusicDetail(newUserData));
|
UserMusicDetail userMusicDetail = musicDetailOptional.orElseGet(() -> new UserMusicDetail(newUserData));
|
||||||
|
|
||||||
UserMusicDetail newUserMusicDetail = mapper.convert(userMusicDetailMap, UserMusicDetail.class);
|
newUserMusicDetail.setId(userMusicDetail.getId());
|
||||||
newUserMusicDetail.setId(userMusicDetail.getId());
|
newUserMusicDetail.setUser(newUserData);
|
||||||
newUserMusicDetail.setUser(newUserData);
|
newUserMusicDetailList.add(newUserMusicDetail);
|
||||||
newUserMusicDetailList.add(newUserMusicDetail);
|
|
||||||
}
|
|
||||||
userMusicDetailRepository.saveAll(newUserMusicDetailList);
|
|
||||||
}
|
}
|
||||||
|
userMusicDetailRepository.saveAll(newUserMusicDetailList);
|
||||||
|
|
||||||
|
|
||||||
// UserCharacterList
|
// UserCharacterList
|
||||||
if (upsertUserAll.containsKey("userCharacterList")) {
|
List<UserCharacter> userCharacterList = upsertUserAll.getUserCharacterList();
|
||||||
List<Map<String, Object>> userCharacterList = ((List<Map<String, Object>>) upsertUserAll.get("userCharacterList"));
|
List<UserCharacter> newUserCharacterList = new ArrayList<>();
|
||||||
List<UserCharacter> newUserCharacterList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userCharacterMap : userCharacterList) {
|
for (UserCharacter newUserCharacter : userCharacterList) {
|
||||||
Integer characterId = (Integer) userCharacterMap.get("characterId");
|
int characterId = newUserCharacter.getCharacterId();
|
||||||
|
|
||||||
Optional<UserCharacter> characterOptional = userCharacterRepository.findByUserAndCharacterId(newUserData, characterId);
|
Optional<UserCharacter> characterOptional = userCharacterRepository.findByUserAndCharacterId(newUserData, characterId);
|
||||||
UserCharacter userCharacter = characterOptional.orElseGet(() -> new UserCharacter(newUserData));
|
UserCharacter userCharacter = characterOptional.orElseGet(() -> new UserCharacter(newUserData));
|
||||||
|
|
||||||
UserCharacter newUserCharacter = mapper.convert(userCharacterMap, UserCharacter.class);
|
newUserCharacter.setId(userCharacter.getId());
|
||||||
newUserCharacter.setId(userCharacter.getId());
|
newUserCharacter.setUser(newUserData);
|
||||||
newUserCharacter.setUser(newUserData);
|
newUserCharacterList.add(newUserCharacter);
|
||||||
newUserCharacterList.add(newUserCharacter);
|
|
||||||
}
|
|
||||||
userCharacterRepository.saveAll(newUserCharacterList);
|
|
||||||
}
|
}
|
||||||
|
userCharacterRepository.saveAll(newUserCharacterList);
|
||||||
|
|
||||||
// UserCardList
|
// UserCardList
|
||||||
if (upsertUserAll.containsKey("userCardList")) {
|
List<UserCard> userCardList = upsertUserAll.getUserCardList();
|
||||||
List<Map<String, Object>> userCardList = ((List<Map<String, Object>>) upsertUserAll.get("userCardList"));
|
List<UserCard> newUserCardList = new ArrayList<>();
|
||||||
List<UserCard> newUserCardList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userCardMap : userCardList) {
|
for (UserCard newUserCard : userCardList) {
|
||||||
Integer cardId = (Integer) userCardMap.get("cardId");
|
int cardId = newUserCard.getCardId();
|
||||||
|
|
||||||
Optional<UserCard> cardOptional = userCardRepository.findByUserAndCardId(newUserData, cardId);
|
Optional<UserCard> cardOptional = userCardRepository.findByUserAndCardId(newUserData, cardId);
|
||||||
UserCard userCard = cardOptional.orElseGet(() -> new UserCard(newUserData));
|
UserCard userCard = cardOptional.orElseGet(() -> new UserCard(newUserData));
|
||||||
|
|
||||||
UserCard newUserCard = mapper.convert(userCardMap, UserCard.class);
|
newUserCard.setId(userCard.getId());
|
||||||
newUserCard.setId(userCard.getId());
|
newUserCard.setUser(newUserData);
|
||||||
newUserCard.setUser(newUserData);
|
newUserCardList.add(newUserCard);
|
||||||
newUserCardList.add(newUserCard);
|
|
||||||
}
|
|
||||||
userCardRepository.saveAll(newUserCardList);
|
|
||||||
}
|
}
|
||||||
|
userCardRepository.saveAll(newUserCardList);
|
||||||
|
|
||||||
|
|
||||||
// UserDeckList
|
// UserDeckList
|
||||||
if (upsertUserAll.containsKey("userDeckList")) {
|
List<UserDeck> userDeckList = upsertUserAll.getUserDeckList();
|
||||||
List<Map<String, Object>> userDeckList = ((List<Map<String, Object>>) upsertUserAll.get("userDeckList"));
|
List<UserDeck> newUserDeckList = new ArrayList<>();
|
||||||
List<UserDeck> newUserDeckList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userDeckMap : userDeckList) {
|
for (UserDeck newUserDeck : userDeckList) {
|
||||||
Integer deckId = (Integer) userDeckMap.get("deckId");
|
int deckId = newUserDeck.getDeckId();
|
||||||
|
|
||||||
Optional<UserDeck> deckOptional = userDeckRepository.findByUserAndDeckId(newUserData, deckId);
|
Optional<UserDeck> deckOptional = userDeckRepository.findByUserAndDeckId(newUserData, deckId);
|
||||||
UserDeck userDeck = deckOptional.orElseGet(() -> new UserDeck(newUserData));
|
UserDeck userDeck = deckOptional.orElseGet(() -> new UserDeck(newUserData));
|
||||||
|
|
||||||
UserDeck newUserDeck = mapper.convert(userDeckMap, UserDeck.class);
|
newUserDeck.setId(userDeck.getId());
|
||||||
newUserDeck.setId(userDeck.getId());
|
newUserDeck.setUser(newUserData);
|
||||||
newUserDeck.setUser(newUserData);
|
newUserDeckList.add(newUserDeck);
|
||||||
newUserDeckList.add(newUserDeck);
|
|
||||||
}
|
|
||||||
userDeckRepository.saveAll(newUserDeckList);
|
|
||||||
}
|
}
|
||||||
|
userDeckRepository.saveAll(newUserDeckList);
|
||||||
|
|
||||||
|
|
||||||
// userTrainingRoomList
|
// userTrainingRoomList
|
||||||
if (upsertUserAll.containsKey("userTrainingRoomList")) {
|
List<UserTrainingRoom> userTrainingRoomList = upsertUserAll.getUserTrainingRoomList();
|
||||||
List<Map<String, Object>> userTrainingRoomList = ((List<Map<String, Object>>) upsertUserAll.get("userTrainingRoomList"));
|
List<UserTrainingRoom> newUserTrainingRoomList = new ArrayList<>();
|
||||||
List<UserTrainingRoom> newUserTrainingRoomList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userTrainingRoomMap : userTrainingRoomList) {
|
for (UserTrainingRoom newUserTrainingRoom : userTrainingRoomList) {
|
||||||
Integer roomId = (Integer) userTrainingRoomMap.get("roomId");
|
int roomId = newUserTrainingRoom.getRoomId();
|
||||||
|
|
||||||
Optional<UserTrainingRoom> trainingRoomOptional = userTrainingRoomRepository.findByUserAndRoomId(newUserData, roomId);
|
Optional<UserTrainingRoom> trainingRoomOptional = userTrainingRoomRepository.findByUserAndRoomId(newUserData, roomId);
|
||||||
UserTrainingRoom trainingRoom = trainingRoomOptional.orElseGet(() -> new UserTrainingRoom(newUserData));
|
UserTrainingRoom trainingRoom = trainingRoomOptional.orElseGet(() -> new UserTrainingRoom(newUserData));
|
||||||
|
|
||||||
UserTrainingRoom newUserTrainingRoom = mapper.convert(userTrainingRoomMap, UserTrainingRoom.class);
|
newUserTrainingRoom.setId(trainingRoom.getId());
|
||||||
newUserTrainingRoom.setId(trainingRoom.getId());
|
newUserTrainingRoom.setUser(newUserData);
|
||||||
newUserTrainingRoom.setUser(newUserData);
|
newUserTrainingRoomList.add(newUserTrainingRoom);
|
||||||
newUserTrainingRoomList.add(newUserTrainingRoom);
|
|
||||||
}
|
|
||||||
userTrainingRoomRepository.saveAll(newUserTrainingRoomList);
|
|
||||||
}
|
}
|
||||||
|
userTrainingRoomRepository.saveAll(newUserTrainingRoomList);
|
||||||
|
|
||||||
|
|
||||||
// UserStoryList
|
// UserStoryList
|
||||||
if (upsertUserAll.containsKey("userStoryList")) {
|
List<UserStory> userStoryList = upsertUserAll.getUserStoryList();
|
||||||
List<Map<String, Object>> userStoryList = ((List<Map<String, Object>>) upsertUserAll.get("userStoryList"));
|
List<UserStory> newUserStoryList = new ArrayList<>();
|
||||||
List<UserStory> newUserStoryList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userStoryMap : userStoryList) {
|
for (UserStory newUserStory : userStoryList) {
|
||||||
Integer storyId = (Integer) userStoryMap.get("storyId");
|
int storyId = newUserStory.getStoryId();
|
||||||
|
|
||||||
Optional<UserStory> storyOptional = userStoryRepository.findByUserAndStoryId(newUserData, storyId);
|
Optional<UserStory> storyOptional = userStoryRepository.findByUserAndStoryId(newUserData, storyId);
|
||||||
UserStory userStory = storyOptional.orElseGet(() -> new UserStory(newUserData));
|
UserStory userStory = storyOptional.orElseGet(() -> new UserStory(newUserData));
|
||||||
|
|
||||||
UserStory newUserStory = mapper.convert(userStoryMap, UserStory.class);
|
newUserStory.setId(userStory.getId());
|
||||||
newUserStory.setId(userStory.getId());
|
newUserStory.setUser(newUserData);
|
||||||
newUserStory.setUser(newUserData);
|
newUserStoryList.add(newUserStory);
|
||||||
newUserStoryList.add(newUserStory);
|
|
||||||
}
|
|
||||||
userStoryRepository.saveAll(newUserStoryList);
|
|
||||||
}
|
}
|
||||||
|
userStoryRepository.saveAll(newUserStoryList);
|
||||||
|
|
||||||
|
|
||||||
// UserChapterList
|
// UserChapterList
|
||||||
if (upsertUserAll.containsKey("userChapterList")) {
|
List<UserChapter> userChapterList = upsertUserAll.getUserChapterList();
|
||||||
List<Map<String, Object>> userChapterList = ((List<Map<String, Object>>) upsertUserAll.get("userChapterList"));
|
List<UserChapter> newUserChapterList = new ArrayList<>();
|
||||||
List<UserChapter> newUserChapterList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userChapterMap : userChapterList) {
|
for (UserChapter newUserChapter : userChapterList) {
|
||||||
Integer chapterId = (Integer) userChapterMap.get("chapterId");
|
int chapterId = newUserChapter.getChapterId();
|
||||||
|
|
||||||
Optional<UserChapter> chapterOptional = userChapterRepository.findByUserAndChapterId(newUserData, chapterId);
|
Optional<UserChapter> chapterOptional = userChapterRepository.findByUserAndChapterId(newUserData, chapterId);
|
||||||
UserChapter userChapter = chapterOptional.orElseGet(() -> new UserChapter(newUserData));
|
UserChapter userChapter = chapterOptional.orElseGet(() -> new UserChapter(newUserData));
|
||||||
|
|
||||||
UserChapter newUserChapter = mapper.convert(userChapterMap, UserChapter.class);
|
newUserChapter.setId(userChapter.getId());
|
||||||
newUserChapter.setId(userChapter.getId());
|
newUserChapter.setUser(newUserData);
|
||||||
newUserChapter.setUser(newUserData);
|
newUserChapterList.add(newUserChapter);
|
||||||
newUserChapterList.add(newUserChapter);
|
|
||||||
}
|
|
||||||
userChapterRepository.saveAll(newUserChapterList);
|
|
||||||
}
|
}
|
||||||
|
userChapterRepository.saveAll(newUserChapterList);
|
||||||
|
|
||||||
|
|
||||||
// UserItemList
|
// UserItemList
|
||||||
if (upsertUserAll.containsKey("userItemList")) {
|
List<UserItem> userItemList = upsertUserAll.getUserItemList();
|
||||||
List<Map<String, Object>> userItemList = ((List<Map<String, Object>>) upsertUserAll.get("userItemList"));
|
List<UserItem> newUserItemList = new ArrayList<>();
|
||||||
List<UserItem> newUserItemList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userItemMap : userItemList) {
|
for (UserItem newUserItem : userItemList) {
|
||||||
Integer itemKind = (Integer) userItemMap.get("itemKind");
|
int itemKind = newUserItem.getItemKind();
|
||||||
Integer itemId = (Integer) userItemMap.get("itemId");
|
int itemId = newUserItem.getItemId();
|
||||||
|
|
||||||
Optional<UserItem> itemOptional = userItemRepository.findByUserAndItemKindAndItemId(newUserData, itemKind, itemId);
|
Optional<UserItem> itemOptional = userItemRepository.findByUserAndItemKindAndItemId(newUserData, itemKind, itemId);
|
||||||
UserItem userItem = itemOptional.orElseGet(() -> new UserItem(newUserData));
|
UserItem userItem = itemOptional.orElseGet(() -> new UserItem(newUserData));
|
||||||
|
|
||||||
UserItem newUserItem = mapper.convert(userItemMap, UserItem.class);
|
newUserItem.setId(userItem.getId());
|
||||||
newUserItem.setId(userItem.getId());
|
newUserItem.setUser(newUserData);
|
||||||
newUserItem.setUser(newUserData);
|
newUserItemList.add(newUserItem);
|
||||||
newUserItemList.add(newUserItem);
|
|
||||||
}
|
|
||||||
userItemRepository.saveAll(newUserItemList);
|
|
||||||
}
|
}
|
||||||
|
userItemRepository.saveAll(newUserItemList);
|
||||||
|
|
||||||
// UserMusicItemList
|
// UserMusicItemList
|
||||||
if (upsertUserAll.containsKey("userMusicItemList")) {
|
List<UserMusicItem> userMusicItemList = upsertUserAll.getUserMusicItemList();
|
||||||
List<Map<String, Object>> userMusicItemList = ((List<Map<String, Object>>) upsertUserAll.get("userMusicItemList"));
|
List<UserMusicItem> newUserMusicItemList = new ArrayList<>();
|
||||||
List<UserMusicItem> newUserMusicItemList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userMusicItemMap : userMusicItemList) {
|
for (UserMusicItem newUserMusicItem : userMusicItemList) {
|
||||||
Integer musicId = (Integer) userMusicItemMap.get("musicId");
|
int musicId = newUserMusicItem.getMusicId();
|
||||||
|
|
||||||
Optional<UserMusicItem> musicItemOptional = userMusicItemRepository.findByUserAndMusicId(newUserData, musicId);
|
Optional<UserMusicItem> musicItemOptional = userMusicItemRepository.findByUserAndMusicId(newUserData, musicId);
|
||||||
UserMusicItem userMusicItem = musicItemOptional.orElseGet(() -> new UserMusicItem(newUserData));
|
UserMusicItem userMusicItem = musicItemOptional.orElseGet(() -> new UserMusicItem(newUserData));
|
||||||
|
|
||||||
UserMusicItem newUserMusicItem = mapper.convert(userMusicItemMap, UserMusicItem.class);
|
newUserMusicItem.setId(userMusicItem.getId());
|
||||||
newUserMusicItem.setId(userMusicItem.getId());
|
newUserMusicItem.setUser(newUserData);
|
||||||
newUserMusicItem.setUser(newUserData);
|
newUserMusicItemList.add(newUserMusicItem);
|
||||||
newUserMusicItemList.add(newUserMusicItem);
|
|
||||||
}
|
|
||||||
userMusicItemRepository.saveAll(newUserMusicItemList);
|
|
||||||
}
|
}
|
||||||
|
userMusicItemRepository.saveAll(newUserMusicItemList);
|
||||||
|
|
||||||
|
|
||||||
// userLoginBonusList
|
// userLoginBonusList
|
||||||
if (upsertUserAll.containsKey("userLoginBonusList")) {
|
List<UserLoginBonus> userLoginBonusList = upsertUserAll.getUserLoginBonusList();
|
||||||
List<Map<String, Object>> userLoginBonusList = ((List<Map<String, Object>>) upsertUserAll.get("userLoginBonusList"));
|
List<UserLoginBonus> newUserLoginBonusList = new ArrayList<>();
|
||||||
List<UserLoginBonus> newUserLoginBonusList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userLoginBonusMap : userLoginBonusList) {
|
for (UserLoginBonus newUserLoginBonus : userLoginBonusList) {
|
||||||
Integer bonusId = (Integer) userLoginBonusMap.get("bonusId");
|
int bonusId = newUserLoginBonus.getBonusId();
|
||||||
|
|
||||||
Optional<UserLoginBonus> loginBonusOptional = userLoginBonusRepository.findByUserAndBonusId(newUserData, bonusId);
|
Optional<UserLoginBonus> loginBonusOptional = userLoginBonusRepository.findByUserAndBonusId(newUserData, bonusId);
|
||||||
UserLoginBonus userLoginBonus = loginBonusOptional.orElseGet(() -> new UserLoginBonus(newUserData));
|
UserLoginBonus userLoginBonus = loginBonusOptional.orElseGet(() -> new UserLoginBonus(newUserData));
|
||||||
|
|
||||||
UserLoginBonus newUserLoginBonus = mapper.convert(userLoginBonusMap, UserLoginBonus.class);
|
newUserLoginBonus.setId(userLoginBonus.getId());
|
||||||
newUserLoginBonus.setId(userLoginBonus.getId());
|
newUserLoginBonus.setUser(newUserData);
|
||||||
newUserLoginBonus.setUser(newUserData);
|
newUserLoginBonusList.add(newUserLoginBonus);
|
||||||
newUserLoginBonusList.add(newUserLoginBonus);
|
|
||||||
}
|
|
||||||
userLoginBonusRepository.saveAll(newUserLoginBonusList);
|
|
||||||
}
|
}
|
||||||
|
userLoginBonusRepository.saveAll(newUserLoginBonusList);
|
||||||
|
|
||||||
|
|
||||||
// UserEventPointList
|
// UserEventPointList
|
||||||
if (upsertUserAll.containsKey("userEventPointList")) {
|
List<UserEventPoint> userEventPointList = upsertUserAll.getUserEventPointList();
|
||||||
List<Map<String, Object>> userEventPointList = ((List<Map<String, Object>>) upsertUserAll.get("userEventPointList"));
|
List<UserEventPoint> newUserEventPointList = new ArrayList<>();
|
||||||
List<UserEventPoint> newUserEventPointList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userEventPointMap : userEventPointList) {
|
for (UserEventPoint newUserEventPoint : userEventPointList) {
|
||||||
Integer eventId = (Integer) userEventPointMap.get("eventId");
|
int eventId = newUserEventPoint.getEventId();
|
||||||
|
|
||||||
Optional<UserEventPoint> eventPointOptional = userEventPointRepository.findByUserAndEventId(newUserData, eventId);
|
Optional<UserEventPoint> eventPointOptional = userEventPointRepository.findByUserAndEventId(newUserData, eventId);
|
||||||
UserEventPoint userEventPoint = eventPointOptional.orElseGet(() -> new UserEventPoint(newUserData));
|
UserEventPoint userEventPoint = eventPointOptional.orElseGet(() -> new UserEventPoint(newUserData));
|
||||||
|
|
||||||
UserEventPoint newUserEventPoint = mapper.convert(userEventPointMap, UserEventPoint.class);
|
newUserEventPoint.setId(userEventPoint.getId());
|
||||||
newUserEventPoint.setId(userEventPoint.getId());
|
newUserEventPoint.setUser(newUserData);
|
||||||
newUserEventPoint.setUser(newUserData);
|
newUserEventPointList.add(newUserEventPoint);
|
||||||
newUserEventPointList.add(newUserEventPoint);
|
|
||||||
}
|
|
||||||
userEventPointRepository.saveAll(newUserEventPointList);
|
|
||||||
}
|
}
|
||||||
|
userEventPointRepository.saveAll(newUserEventPointList);
|
||||||
|
|
||||||
|
|
||||||
// UserMissionPointList
|
// UserMissionPointList
|
||||||
if (upsertUserAll.containsKey("userMissionPointList")) {
|
List<UserMissionPoint> userMissionPointList = upsertUserAll.getUserMissionPointList();
|
||||||
List<Map<String, Object>> userMissionPointList = ((List<Map<String, Object>>) upsertUserAll.get("userMissionPointList"));
|
List<UserMissionPoint> newUserMissionPointList = new ArrayList<>();
|
||||||
List<UserMissionPoint> newUserMissionPointList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Map<String, Object> userMissionPointMap : userMissionPointList) {
|
for (UserMissionPoint newUserMissionPoint : userMissionPointList) {
|
||||||
Integer eventId = (Integer) userMissionPointMap.get("eventId");
|
int eventId = newUserMissionPoint.getEventId();
|
||||||
|
|
||||||
Optional<UserMissionPoint> userMissionPointOptional = userMissionPointRepository.findByUserAndEventId(newUserData, eventId);
|
Optional<UserMissionPoint> userMissionPointOptional = userMissionPointRepository.findByUserAndEventId(newUserData, eventId);
|
||||||
UserMissionPoint userMissionPoint = userMissionPointOptional.orElseGet(() -> new UserMissionPoint(newUserData));
|
UserMissionPoint userMissionPoint = userMissionPointOptional.orElseGet(() -> new UserMissionPoint(newUserData));
|
||||||
|
|
||||||
UserMissionPoint newUserEventPoint = mapper.convert(userMissionPointMap, UserMissionPoint.class);
|
newUserMissionPoint.setId(userMissionPoint.getId());
|
||||||
newUserEventPoint.setId(userMissionPoint.getId());
|
newUserMissionPoint.setUser(newUserData);
|
||||||
newUserEventPoint.setUser(newUserData);
|
newUserMissionPointList.add(newUserMissionPoint);
|
||||||
newUserMissionPointList.add(newUserEventPoint);
|
|
||||||
}
|
|
||||||
userMissionPointRepository.saveAll(newUserMissionPointList);
|
|
||||||
}
|
}
|
||||||
|
userMissionPointRepository.saveAll(newUserMissionPointList);
|
||||||
|
|
||||||
// UserRatinglogList (For the highest rating of each version)
|
// UserRatinglogList (For the highest rating of each version)
|
||||||
|
|
||||||
@@ -449,11 +400,7 @@ public class UpsertUserAllHandler implements BaseHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveGeneralData(Map<String, Object> upsertUserAll, UserData newUserData, String jsonName, String key) {
|
private void saveGeneralData(List<UserRecentRating> itemList, UserData newUserData, String key) {
|
||||||
List<Map<String, Object>> recordList = ((List<Map<String, Object>>) upsertUserAll.get(jsonName));
|
|
||||||
|
|
||||||
List<UserRecentRating> itemList = mapper.convert(recordList, new TypeReference<>() {
|
|
||||||
});
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
// Convert to a string
|
// Convert to a string
|
||||||
for (UserRecentRating item :
|
for (UserRecentRating item :
|
||||||
@@ -461,7 +408,7 @@ public class UpsertUserAllHandler implements BaseHandler {
|
|||||||
sb.append(item.getMusicId()).append(":").append(item.getDifficultId()).append(":").append(item.getScore());
|
sb.append(item.getMusicId()).append(":").append(item.getDifficultId()).append(":").append(item.getScore());
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
}
|
||||||
if(sb.length() > 0) {
|
if (sb.length() > 0) {
|
||||||
sb.deleteCharAt(sb.length() - 1);
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
}
|
}
|
||||||
Optional<UserGeneralData> uOptional = userGeneralDataRepository.findByUserAndPropertyKey(newUserData, key);
|
Optional<UserGeneralData> uOptional = userGeneralDataRepository.findByUserAndPropertyKey(newUserData, key);
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package icu.samnyan.aqua.sega.ongeki.model.request;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import icu.samnyan.aqua.sega.general.model.response.UserRecentRating;
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.model.userdata.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UpsertUserAll implements Serializable {
|
||||||
|
|
||||||
|
private List<UserData> userData;
|
||||||
|
|
||||||
|
private List<UserOption> userOption;
|
||||||
|
|
||||||
|
private List<UserPlaylog> userPlaylogList;
|
||||||
|
|
||||||
|
private List<Map<String, Object>> userSessionlogList;
|
||||||
|
|
||||||
|
private List<UserActivity> userActivityList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userRecentRatingList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userBpBaseList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userRatingBaseBestNewList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userRatingBaseBestList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userRatingBaseHotList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userRatingBaseNextNewList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userRatingBaseNextList;
|
||||||
|
|
||||||
|
private List<UserRecentRating> userRatingBaseHotNextList;
|
||||||
|
|
||||||
|
private List<UserMusicDetail> userMusicDetailList;
|
||||||
|
|
||||||
|
private List<UserCharacter> userCharacterList;
|
||||||
|
|
||||||
|
private List<UserCard> userCardList;
|
||||||
|
|
||||||
|
private List<UserDeck> userDeckList;
|
||||||
|
|
||||||
|
private List<UserTrainingRoom> userTrainingRoomList;
|
||||||
|
|
||||||
|
private List<UserStory> userStoryList;
|
||||||
|
|
||||||
|
private List<UserChapter> userChapterList;
|
||||||
|
|
||||||
|
private List<UserItem> userItemList;
|
||||||
|
|
||||||
|
private List<UserMusicItem> userMusicItemList;
|
||||||
|
|
||||||
|
private List<UserLoginBonus> userLoginBonusList;
|
||||||
|
|
||||||
|
private List<UserEventPoint> userEventPointList;
|
||||||
|
|
||||||
|
private List<UserMissionPoint> userMissionPointList;
|
||||||
|
|
||||||
|
private List<Map<String, Object>> userRatinglogList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewMusicDetailList")
|
||||||
|
private String isNewMusicDetailList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewCharacterList")
|
||||||
|
private String isNewCharacterList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewCardList")
|
||||||
|
private String isNewCardList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewDeckList")
|
||||||
|
private String isNewDeckList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewTrainingRoomList")
|
||||||
|
private String isNewTrainingRoomList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewStoryList")
|
||||||
|
private String isNewStoryList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewChapterList")
|
||||||
|
private String isNewChapterList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewItemList")
|
||||||
|
private String isNewItemList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewMusicItemList")
|
||||||
|
private String isNewMusicItemList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewLoginBonusList")
|
||||||
|
private String isNewLoginBonusList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewEventPointList")
|
||||||
|
private String isNewEventPointList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewMissionPointList")
|
||||||
|
private String isNewMissionPointList;
|
||||||
|
|
||||||
|
@JsonProperty("isNewRatinglogList")
|
||||||
|
private String isNewRatinglogList;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user