mirror of https://github.com/hykilpikonna/AquaDX
[F] Ongeki: Fix constructor inconsistencies
parent
7320a982f6
commit
57d83439f3
|
@ -1,586 +0,0 @@
|
|||
package icu.samnyan.aqua.sega.ongeki.handler.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.ongeki.*;
|
||||
import icu.samnyan.aqua.sega.general.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.userdata.*;
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The handler for saving all data of a ONGEKI profile
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("OngekiUserAllHandler")
|
||||
public class UpsertUserAllHandler implements BaseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(UpsertUserAllHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
|
||||
private final CardService cardService;
|
||||
|
||||
private final OgkUserDataRepo userDataRepository;
|
||||
private final OgkUserOptionRepo userOptionRepository;
|
||||
private final OgkUserPlaylogRepo userPlaylogRepository;
|
||||
private final OgkUserActivityRepo userActivityRepository;
|
||||
private final OgkUserMusicDetailRepo userMusicDetailRepository;
|
||||
private final OgkUserCharacterRepo userCharacterRepository;
|
||||
private final OgkUserCardRepo userCardRepository;
|
||||
private final OgkUserDeckRepo userDeckRepository;
|
||||
private final OgkUserStoryRepo userStoryRepository;
|
||||
private final OgkUserChapterRepo userChapterRepository;
|
||||
private final OgkUserMemoryChapterRepo userMemoryChapterRepository;
|
||||
private final OgkUserItemRepo userItemRepository;
|
||||
private final OgkUserMusicItemRepo userMusicItemRepository;
|
||||
private final OgkUserLoginBonusRepo userLoginBonusRepository;
|
||||
private final OgkUserEventPointRepo userEventPointRepository;
|
||||
private final OgkUserMissionPointRepo userMissionPointRepository;
|
||||
private final OgkUserTrainingRoomRepo userTrainingRoomRepository;
|
||||
private final OgkUserGeneralDataRepo userGeneralDataRepository;
|
||||
private final OgkUserBossRepo userBossRepository;
|
||||
private final OgkUserScenarioRepo userScenarioRepository;
|
||||
private final OgkUserTechCountRepo userTechCountRepository;
|
||||
private final OgkUserTradeItemRepo userTradeItemRepository;
|
||||
private final OgkUserEventMusicRepo userEventMusicRepository;
|
||||
private final OgkUserTechEventRepo userTechEventRepository;
|
||||
private final OgkUserKopRepo userKopRepository;
|
||||
|
||||
@Autowired
|
||||
public UpsertUserAllHandler(BasicMapper mapper,
|
||||
CardService cardService, OgkUserDataRepo userDataRepository, OgkUserOptionRepo userOptionRepository, OgkUserPlaylogRepo userPlaylogRepository, OgkUserActivityRepo userActivityRepository, OgkUserMusicDetailRepo userMusicDetailRepository, OgkUserCharacterRepo userCharacterRepository, OgkUserCardRepo userCardRepository, OgkUserDeckRepo userDeckRepository, OgkUserStoryRepo userStoryRepository, OgkUserChapterRepo userChapterRepository, OgkUserItemRepo userItemRepository, OgkUserMusicItemRepo userMusicItemRepository, OgkUserLoginBonusRepo userLoginBonusRepository, OgkUserEventPointRepo userEventPointRepository, OgkUserMissionPointRepo userMissionPointRepository, OgkUserTrainingRoomRepo userTrainingRoomRepository, OgkUserGeneralDataRepo userGeneralDataRepository, OgkUserBossRepo userBossRepository, OgkUserScenarioRepo userScenarioRepository, OgkUserTechCountRepo userTechCountRepository, OgkUserTradeItemRepo userTradeItemRepository, OgkUserEventMusicRepo userEventMusicRepository, OgkUserTechEventRepo userTechEventRepository, OgkUserKopRepo userKopRepository, OgkUserMemoryChapterRepo userMemoryChapterRepository) {
|
||||
this.mapper = mapper;
|
||||
this.cardService = cardService;
|
||||
this.userDataRepository = userDataRepository;
|
||||
this.userOptionRepository = userOptionRepository;
|
||||
this.userPlaylogRepository = userPlaylogRepository;
|
||||
this.userActivityRepository = userActivityRepository;
|
||||
this.userMusicDetailRepository = userMusicDetailRepository;
|
||||
this.userCharacterRepository = userCharacterRepository;
|
||||
this.userCardRepository = userCardRepository;
|
||||
this.userDeckRepository = userDeckRepository;
|
||||
this.userStoryRepository = userStoryRepository;
|
||||
this.userChapterRepository = userChapterRepository;
|
||||
this.userMemoryChapterRepository = userMemoryChapterRepository;
|
||||
this.userItemRepository = userItemRepository;
|
||||
this.userMusicItemRepository = userMusicItemRepository;
|
||||
this.userLoginBonusRepository = userLoginBonusRepository;
|
||||
this.userEventPointRepository = userEventPointRepository;
|
||||
this.userMissionPointRepository = userMissionPointRepository;
|
||||
this.userTrainingRoomRepository = userTrainingRoomRepository;
|
||||
this.userGeneralDataRepository = userGeneralDataRepository;
|
||||
this.userBossRepository = userBossRepository;
|
||||
this.userScenarioRepository = userScenarioRepository;
|
||||
this.userTechCountRepository = userTechCountRepository;
|
||||
this.userTradeItemRepository = userTradeItemRepository;
|
||||
this.userEventMusicRepository = userEventMusicRepository;
|
||||
this.userTechEventRepository = userTechEventRepository;
|
||||
this.userKopRepository = userKopRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
long userId = ((Number) request.get("userId")).longValue();
|
||||
UpsertUserAll upsertUserAll = mapper.convert(request.get("upsertUserAll"), UpsertUserAll.class);
|
||||
|
||||
// All the field should exist, no need to check now.
|
||||
// UserData
|
||||
UserData newUserData;
|
||||
{
|
||||
UserData userData;
|
||||
|
||||
Optional<UserData> userOptional = userDataRepository.findByCard_ExtId(userId);
|
||||
|
||||
// UserData might be empty on later runs
|
||||
if (userOptional.isEmpty() && upsertUserAll.getUserData().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (userOptional.isPresent()) {
|
||||
userData = userOptional.get();
|
||||
} else {
|
||||
userData = new UserData();
|
||||
Card card = cardService.getCardByExtId(userId).orElseThrow();
|
||||
userData.setCard(card);
|
||||
}
|
||||
|
||||
// If new data exists, use new data. Otherwise, use old data
|
||||
newUserData = !upsertUserAll.getUserData().isEmpty() ? upsertUserAll.getUserData().get(0) : userData;
|
||||
|
||||
newUserData.setId(userData.getId());
|
||||
newUserData.setCard(userData.getCard());
|
||||
|
||||
// Set eventWatchedDate with lastPlayDate, because client doesn't update it
|
||||
newUserData.setEventWatchedDate(userData.getLastPlayDate());
|
||||
newUserData.setCmEventWatchedDate(userData.getLastPlayDate());
|
||||
|
||||
userDataRepository.save(newUserData);
|
||||
}
|
||||
|
||||
|
||||
// UserOption
|
||||
UserOption newUserOption = upsertUserAll.getUserOption().get(0);
|
||||
|
||||
Optional<UserOption> userOptionOptional = userOptionRepository.findSingleByUser(newUserData);
|
||||
UserOption userOption = userOptionOptional.orElseGet(() -> new UserOption(newUserData));
|
||||
|
||||
newUserOption.setId(userOption.getId());
|
||||
newUserOption.setUser(userOption.getUser());
|
||||
|
||||
userOptionRepository.save(newUserOption);
|
||||
|
||||
|
||||
// UserPlaylogList
|
||||
List<UserPlaylog> userPlaylogList = upsertUserAll.getUserPlaylogList();
|
||||
List<UserPlaylog> newUserPlaylogList = new ArrayList<>();
|
||||
|
||||
for (UserPlaylog newUserPlaylog : userPlaylogList) {
|
||||
newUserPlaylog.setUser(newUserData);
|
||||
newUserPlaylogList.add(newUserPlaylog);
|
||||
}
|
||||
|
||||
userPlaylogRepository.saveAll(newUserPlaylogList);
|
||||
|
||||
|
||||
// UserSessionlogList, UserJewelboostlogLost doesn't need to be saved for a private server
|
||||
|
||||
|
||||
// UserActivityList
|
||||
List<UserActivity> userActivityList = upsertUserAll.getUserActivityList();
|
||||
List<UserActivity> newUserActivityList = new ArrayList<>();
|
||||
|
||||
for (UserActivity newUserActivity : userActivityList) {
|
||||
int kind = newUserActivity.getKind();
|
||||
int id = newUserActivity.getActivityId();
|
||||
|
||||
if (kind != 0 && id != 0) {
|
||||
Optional<UserActivity> activityOptional = userActivityRepository.findByUserAndKindAndActivityId(newUserData, kind, id);
|
||||
UserActivity userActivity = activityOptional.orElseGet(() -> new UserActivity(newUserData));
|
||||
|
||||
newUserActivity.setId(userActivity.getId());
|
||||
newUserActivity.setUser(newUserData);
|
||||
newUserActivityList.add(newUserActivity);
|
||||
}
|
||||
}
|
||||
newUserActivityList.sort((a, b) -> Integer.compare(b.getSortNumber(), a.getSortNumber()));
|
||||
userActivityRepository.saveAll(newUserActivityList);
|
||||
|
||||
|
||||
// UserRecentRatingList
|
||||
// This thing still need to save to solve the rating drop
|
||||
this.saveGeneralData(upsertUserAll.getUserRecentRatingList(), newUserData, "recent_rating_list");
|
||||
|
||||
|
||||
/*
|
||||
* The rating and battle point calculation is little bit complex.
|
||||
* So I just create a UserGeneralData class to store this value
|
||||
* into a csv format for convenience
|
||||
*/
|
||||
// UserBpBaseList (For calculating Battle point)
|
||||
this.saveGeneralData(upsertUserAll.getUserBpBaseList(), newUserData, "battle_point_base");
|
||||
|
||||
|
||||
// This is the best rating of all charts. Best 30 + 10 after that.
|
||||
// userRatingBaseBestList
|
||||
this.saveGeneralData(upsertUserAll.getUserRatingBaseBestList(), newUserData, "rating_base_best");
|
||||
|
||||
|
||||
// userRatingBaseNextList
|
||||
this.saveGeneralData(upsertUserAll.getUserRatingBaseNextList(), newUserData, "rating_base_next");
|
||||
|
||||
|
||||
// This is the best rating of new charts. Best 15 + 10 after that.
|
||||
// New chart means same version
|
||||
// userRatingBaseBestNewList
|
||||
this.saveGeneralData(upsertUserAll.getUserRatingBaseBestNewList(), newUserData, "rating_base_new_best");
|
||||
|
||||
// userRatingBaseNextNewList
|
||||
this.saveGeneralData(upsertUserAll.getUserRatingBaseNextNewList(), newUserData, "rating_base_new_next");
|
||||
|
||||
// This is the recent best
|
||||
// userRatingBaseHotList
|
||||
this.saveGeneralData(upsertUserAll.getUserRatingBaseHotList(), newUserData, "rating_base_hot_best");
|
||||
|
||||
// userRatingBaseHotNextList
|
||||
this.saveGeneralData(upsertUserAll.getUserRatingBaseHotNextList(), newUserData, "rating_base_hot_next");
|
||||
|
||||
|
||||
// UserMusicDetailList
|
||||
List<UserMusicDetail> userMusicDetailList = upsertUserAll.getUserMusicDetailList();
|
||||
List<UserMusicDetail> newUserMusicDetailList = new ArrayList<>();
|
||||
|
||||
for (UserMusicDetail newUserMusicDetail : userMusicDetailList) {
|
||||
int musicId = newUserMusicDetail.getMusicId();
|
||||
int level = newUserMusicDetail.getLevel();
|
||||
|
||||
Optional<UserMusicDetail> musicDetailOptional = userMusicDetailRepository.findByUserAndMusicIdAndLevel(newUserData, musicId, level);
|
||||
UserMusicDetail userMusicDetail = musicDetailOptional.orElseGet(() -> new UserMusicDetail(newUserData));
|
||||
|
||||
newUserMusicDetail.setId(userMusicDetail.getId());
|
||||
newUserMusicDetail.setUser(newUserData);
|
||||
newUserMusicDetailList.add(newUserMusicDetail);
|
||||
}
|
||||
userMusicDetailRepository.saveAll(newUserMusicDetailList);
|
||||
|
||||
|
||||
// UserCharacterList
|
||||
List<UserCharacter> userCharacterList = upsertUserAll.getUserCharacterList();
|
||||
List<UserCharacter> newUserCharacterList = new ArrayList<>();
|
||||
|
||||
for (UserCharacter newUserCharacter : userCharacterList) {
|
||||
int characterId = newUserCharacter.getCharacterId();
|
||||
|
||||
Optional<UserCharacter> characterOptional = userCharacterRepository.findByUserAndCharacterId(newUserData, characterId);
|
||||
UserCharacter userCharacter = characterOptional.orElseGet(() -> new UserCharacter(newUserData));
|
||||
|
||||
newUserCharacter.setId(userCharacter.getId());
|
||||
newUserCharacter.setUser(newUserData);
|
||||
newUserCharacterList.add(newUserCharacter);
|
||||
}
|
||||
userCharacterRepository.saveAll(newUserCharacterList);
|
||||
|
||||
// UserCardList
|
||||
List<UserCard> userCardList = upsertUserAll.getUserCardList();
|
||||
List<UserCard> newUserCardList = new ArrayList<>();
|
||||
|
||||
for (UserCard newUserCard : userCardList) {
|
||||
int cardId = newUserCard.getCardId();
|
||||
|
||||
Optional<UserCard> cardOptional = userCardRepository.findByUserAndCardId(newUserData, cardId);
|
||||
UserCard userCard = cardOptional.orElseGet(() -> new UserCard(newUserData));
|
||||
|
||||
newUserCard.setId(userCard.getId());
|
||||
newUserCard.setUser(newUserData);
|
||||
newUserCardList.add(newUserCard);
|
||||
}
|
||||
userCardRepository.saveAll(newUserCardList);
|
||||
|
||||
|
||||
// UserDeckList
|
||||
List<UserDeck> userDeckList = upsertUserAll.getUserDeckList();
|
||||
List<UserDeck> newUserDeckList = new ArrayList<>();
|
||||
|
||||
for (UserDeck newUserDeck : userDeckList) {
|
||||
int deckId = newUserDeck.getDeckId();
|
||||
|
||||
Optional<UserDeck> deckOptional = userDeckRepository.findByUserAndDeckId(newUserData, deckId);
|
||||
UserDeck userDeck = deckOptional.orElseGet(() -> new UserDeck(newUserData));
|
||||
|
||||
newUserDeck.setId(userDeck.getId());
|
||||
newUserDeck.setUser(newUserData);
|
||||
newUserDeckList.add(newUserDeck);
|
||||
}
|
||||
userDeckRepository.saveAll(newUserDeckList);
|
||||
|
||||
|
||||
// userTrainingRoomList
|
||||
List<UserTrainingRoom> userTrainingRoomList = upsertUserAll.getUserTrainingRoomList();
|
||||
List<UserTrainingRoom> newUserTrainingRoomList = new ArrayList<>();
|
||||
|
||||
for (UserTrainingRoom newUserTrainingRoom : userTrainingRoomList) {
|
||||
int roomId = newUserTrainingRoom.getRoomId();
|
||||
|
||||
Optional<UserTrainingRoom> trainingRoomOptional = userTrainingRoomRepository.findByUserAndRoomId(newUserData, roomId);
|
||||
UserTrainingRoom trainingRoom = trainingRoomOptional.orElseGet(() -> new UserTrainingRoom(newUserData));
|
||||
|
||||
newUserTrainingRoom.setId(trainingRoom.getId());
|
||||
newUserTrainingRoom.setUser(newUserData);
|
||||
newUserTrainingRoomList.add(newUserTrainingRoom);
|
||||
}
|
||||
userTrainingRoomRepository.saveAll(newUserTrainingRoomList);
|
||||
|
||||
|
||||
// UserStoryList
|
||||
List<UserStory> userStoryList = upsertUserAll.getUserStoryList();
|
||||
List<UserStory> newUserStoryList = new ArrayList<>();
|
||||
|
||||
for (UserStory newUserStory : userStoryList) {
|
||||
int storyId = newUserStory.getStoryId();
|
||||
|
||||
Optional<UserStory> storyOptional = userStoryRepository.findByUserAndStoryId(newUserData, storyId);
|
||||
UserStory userStory = storyOptional.orElseGet(() -> new UserStory(newUserData));
|
||||
|
||||
newUserStory.setId(userStory.getId());
|
||||
newUserStory.setUser(newUserData);
|
||||
newUserStoryList.add(newUserStory);
|
||||
}
|
||||
userStoryRepository.saveAll(newUserStoryList);
|
||||
|
||||
|
||||
// UserChapterList
|
||||
List<UserChapter> userChapterList = upsertUserAll.getUserChapterList();
|
||||
List<UserChapter> newUserChapterList = new ArrayList<>();
|
||||
|
||||
for (UserChapter newUserChapter : userChapterList) {
|
||||
int chapterId = newUserChapter.getChapterId();
|
||||
|
||||
Optional<UserChapter> chapterOptional = userChapterRepository.findByUserAndChapterId(newUserData, chapterId);
|
||||
UserChapter userChapter = chapterOptional.orElseGet(() -> new UserChapter(newUserData));
|
||||
|
||||
newUserChapter.setId(userChapter.getId());
|
||||
newUserChapter.setUser(newUserData);
|
||||
newUserChapterList.add(newUserChapter);
|
||||
}
|
||||
userChapterRepository.saveAll(newUserChapterList);
|
||||
|
||||
|
||||
// UserMemoryChapterList
|
||||
List<UserMemoryChapter> userMemoryChapterList = upsertUserAll.getUserMemoryChapterList();
|
||||
|
||||
if (userMemoryChapterList != null) {
|
||||
List<UserMemoryChapter> newUserMemoryChapterList = new ArrayList<>();
|
||||
|
||||
for (UserMemoryChapter newUserMemoryChapter : userMemoryChapterList) {
|
||||
int chapterId = newUserMemoryChapter.getChapterId();
|
||||
|
||||
Optional<UserMemoryChapter> chapterOptional = userMemoryChapterRepository.findByUserAndChapterId(newUserData, chapterId);
|
||||
UserMemoryChapter userChapter = chapterOptional.orElseGet(() -> new UserMemoryChapter(newUserData));
|
||||
|
||||
newUserMemoryChapter.setId(userChapter.getId());
|
||||
newUserMemoryChapter.setUser(newUserData);
|
||||
newUserMemoryChapterList.add(newUserMemoryChapter);
|
||||
}
|
||||
userMemoryChapterRepository.saveAll(newUserMemoryChapterList);
|
||||
}
|
||||
|
||||
// UserItemList
|
||||
List<UserItem> userItemList = upsertUserAll.getUserItemList();
|
||||
List<UserItem> newUserItemList = new ArrayList<>();
|
||||
|
||||
for (UserItem newUserItem : userItemList) {
|
||||
int itemKind = newUserItem.getItemKind();
|
||||
int itemId = newUserItem.getItemId();
|
||||
|
||||
Optional<UserItem> itemOptional = userItemRepository.findByUserAndItemKindAndItemId(newUserData, itemKind, itemId);
|
||||
UserItem userItem = itemOptional.orElseGet(() -> new UserItem(newUserData));
|
||||
|
||||
newUserItem.setId(userItem.getId());
|
||||
newUserItem.setUser(newUserData);
|
||||
newUserItemList.add(newUserItem);
|
||||
}
|
||||
userItemRepository.saveAll(newUserItemList);
|
||||
|
||||
// UserMusicItemList
|
||||
List<UserMusicItem> userMusicItemList = upsertUserAll.getUserMusicItemList();
|
||||
List<UserMusicItem> newUserMusicItemList = new ArrayList<>();
|
||||
|
||||
for (UserMusicItem newUserMusicItem : userMusicItemList) {
|
||||
int musicId = newUserMusicItem.getMusicId();
|
||||
|
||||
Optional<UserMusicItem> musicItemOptional = userMusicItemRepository.findByUserAndMusicId(newUserData, musicId);
|
||||
UserMusicItem userMusicItem = musicItemOptional.orElseGet(() -> new UserMusicItem(newUserData));
|
||||
|
||||
newUserMusicItem.setId(userMusicItem.getId());
|
||||
newUserMusicItem.setUser(newUserData);
|
||||
newUserMusicItemList.add(newUserMusicItem);
|
||||
}
|
||||
userMusicItemRepository.saveAll(newUserMusicItemList);
|
||||
|
||||
|
||||
// userLoginBonusList
|
||||
List<UserLoginBonus> userLoginBonusList = upsertUserAll.getUserLoginBonusList();
|
||||
List<UserLoginBonus> newUserLoginBonusList = new ArrayList<>();
|
||||
|
||||
for (UserLoginBonus newUserLoginBonus : userLoginBonusList) {
|
||||
int bonusId = newUserLoginBonus.getBonusId();
|
||||
|
||||
Optional<UserLoginBonus> loginBonusOptional = userLoginBonusRepository.findByUserAndBonusId(newUserData, bonusId);
|
||||
UserLoginBonus userLoginBonus = loginBonusOptional.orElseGet(() -> new UserLoginBonus(newUserData));
|
||||
|
||||
newUserLoginBonus.setId(userLoginBonus.getId());
|
||||
newUserLoginBonus.setUser(newUserData);
|
||||
newUserLoginBonusList.add(newUserLoginBonus);
|
||||
}
|
||||
userLoginBonusRepository.saveAll(newUserLoginBonusList);
|
||||
|
||||
|
||||
// UserEventPointList
|
||||
List<UserEventPoint> userEventPointList = upsertUserAll.getUserEventPointList();
|
||||
List<UserEventPoint> newUserEventPointList = new ArrayList<>();
|
||||
|
||||
for (UserEventPoint newUserEventPoint : userEventPointList) {
|
||||
int eventId = newUserEventPoint.getEventId();
|
||||
|
||||
Optional<UserEventPoint> eventPointOptional = userEventPointRepository.findByUserAndEventId(newUserData, eventId);
|
||||
UserEventPoint userEventPoint = eventPointOptional.orElseGet(() -> new UserEventPoint(newUserData));
|
||||
|
||||
newUserEventPoint.setId(userEventPoint.getId());
|
||||
newUserEventPoint.setUser(newUserData);
|
||||
newUserEventPointList.add(newUserEventPoint);
|
||||
}
|
||||
userEventPointRepository.saveAll(newUserEventPointList);
|
||||
|
||||
|
||||
// UserMissionPointList
|
||||
List<UserMissionPoint> userMissionPointList = upsertUserAll.getUserMissionPointList();
|
||||
List<UserMissionPoint> newUserMissionPointList = new ArrayList<>();
|
||||
|
||||
for (UserMissionPoint newUserMissionPoint : userMissionPointList) {
|
||||
int eventId = newUserMissionPoint.getEventId();
|
||||
|
||||
Optional<UserMissionPoint> userMissionPointOptional = userMissionPointRepository.findByUserAndEventId(newUserData, eventId);
|
||||
UserMissionPoint userMissionPoint = userMissionPointOptional.orElseGet(() -> new UserMissionPoint(newUserData));
|
||||
|
||||
newUserMissionPoint.setId(userMissionPoint.getId());
|
||||
newUserMissionPoint.setUser(newUserData);
|
||||
newUserMissionPointList.add(newUserMissionPoint);
|
||||
}
|
||||
userMissionPointRepository.saveAll(newUserMissionPointList);
|
||||
|
||||
// UserRatinglogList (For the highest rating of each version)
|
||||
|
||||
// UserBossList
|
||||
List<UserBoss> userBossList = upsertUserAll.getUserBossList();
|
||||
if (userBossList != null) {
|
||||
List<UserBoss> newUserBossList = new ArrayList<>();
|
||||
for (UserBoss newUserBoss : userBossList) {
|
||||
int musicId = newUserBoss.getMusicId();
|
||||
|
||||
Optional<UserBoss> userBossOptional = userBossRepository.findByUserAndMusicId(newUserData, musicId);
|
||||
UserBoss userBoss = userBossOptional.orElseGet(() -> new UserBoss(newUserData));
|
||||
|
||||
newUserBoss.setId(userBoss.getId());
|
||||
newUserBoss.setUser(userBoss.getUser());
|
||||
newUserBossList.add(newUserBoss);
|
||||
}
|
||||
userBossRepository.saveAll(newUserBossList);
|
||||
}
|
||||
|
||||
// UserTechCountList
|
||||
List<UserTechCount> userTechCountList = upsertUserAll.getUserTechCountList();
|
||||
if (userTechCountList != null) {
|
||||
List<UserTechCount> newUserTechCountList = new ArrayList<>();
|
||||
for (UserTechCount newUserTechCount : userTechCountList) {
|
||||
int levelId = newUserTechCount.getLevelId();
|
||||
|
||||
Optional<UserTechCount> userTechCountOptional = userTechCountRepository.findByUserAndLevelId(newUserData, levelId);
|
||||
UserTechCount userTechCount = userTechCountOptional.orElseGet(() -> new UserTechCount(newUserData));
|
||||
|
||||
newUserTechCount.setId(userTechCount.getId());
|
||||
newUserTechCount.setUser(userTechCount.getUser());
|
||||
newUserTechCountList.add(newUserTechCount);
|
||||
}
|
||||
userTechCountRepository.saveAll(newUserTechCountList);
|
||||
}
|
||||
|
||||
// UserScenarioList
|
||||
List<UserScenario> userScenarioList = upsertUserAll.getUserScenarioList();
|
||||
if (userScenarioList != null) {
|
||||
List<UserScenario> newUserScenarioList = new ArrayList<>();
|
||||
for (UserScenario newUserScenario : userScenarioList) {
|
||||
int scenarioId = newUserScenario.getScenarioId();
|
||||
|
||||
Optional<UserScenario> userScenarioOptional = userScenarioRepository.findByUserAndScenarioId(newUserData, scenarioId);
|
||||
UserScenario userScenario = userScenarioOptional.orElseGet(() -> new UserScenario(newUserData));
|
||||
|
||||
newUserScenario.setId(userScenario.getId());
|
||||
newUserScenario.setUser(userScenario.getUser());
|
||||
newUserScenarioList.add(newUserScenario);
|
||||
}
|
||||
userScenarioRepository.saveAll(newUserScenarioList);
|
||||
}
|
||||
|
||||
// UserTradeItemList
|
||||
List<UserTradeItem> userTradeItemList = upsertUserAll.getUserTradeItemList();
|
||||
List<UserTradeItem> newUserTradeItemList = new ArrayList<>();
|
||||
|
||||
for (UserTradeItem newUserTradeItem : userTradeItemList) {
|
||||
int chapterId = newUserTradeItem.getChapterId();
|
||||
int tradeItemId = newUserTradeItem.getTradeItemId();
|
||||
|
||||
Optional<UserTradeItem> tradeItemOptional = userTradeItemRepository.findByUserAndChapterIdAndTradeItemId(newUserData, chapterId, tradeItemId);
|
||||
UserTradeItem userTradeItem = tradeItemOptional.orElseGet(() -> new UserTradeItem(newUserData));
|
||||
|
||||
newUserTradeItem.setId(userTradeItem.getId());
|
||||
newUserTradeItem.setUser(newUserData);
|
||||
newUserTradeItemList.add(newUserTradeItem);
|
||||
}
|
||||
userTradeItemRepository.saveAll(newUserTradeItemList);
|
||||
|
||||
// UserEventMusicList
|
||||
List<UserEventMusic> userEventMusicList = upsertUserAll.getUserEventMusicList();
|
||||
List<UserEventMusic> newUserEventMusicList = new ArrayList<>();
|
||||
|
||||
for (UserEventMusic newUserEventMusic : userEventMusicList) {
|
||||
int eventId = newUserEventMusic.getEventId();
|
||||
int type = newUserEventMusic.getType();
|
||||
int musicId = newUserEventMusic.getMusicId();
|
||||
|
||||
Optional<UserEventMusic> eventMusicOptional = userEventMusicRepository.findByUserAndEventIdAndTypeAndMusicId(newUserData, eventId, type, musicId);
|
||||
UserEventMusic userEventMusic = eventMusicOptional.orElseGet(() -> new UserEventMusic(newUserData));
|
||||
|
||||
newUserEventMusic.setId(userEventMusic.getId());
|
||||
newUserEventMusic.setUser(newUserData);
|
||||
newUserEventMusicList.add(newUserEventMusic);
|
||||
}
|
||||
userEventMusicRepository.saveAll(newUserEventMusicList);
|
||||
|
||||
// UserTechEventList
|
||||
List<UserTechEvent> userTechEventList = upsertUserAll.getUserTechEventList();
|
||||
List<UserTechEvent> newUserTechEventList = new ArrayList<>();
|
||||
|
||||
for (UserTechEvent newUserTechEvent : userTechEventList) {
|
||||
int eventId = newUserTechEvent.getEventId();
|
||||
|
||||
Optional<UserTechEvent> techEventOptional = userTechEventRepository.findByUserAndEventId(newUserData, eventId);
|
||||
UserTechEvent userTechEvent = techEventOptional.orElseGet(() -> new UserTechEvent(newUserData));
|
||||
|
||||
newUserTechEvent.setId(userTechEvent.getId());
|
||||
newUserTechEvent.setUser(newUserData);
|
||||
newUserTechEventList.add(newUserTechEvent);
|
||||
}
|
||||
userTechEventRepository.saveAll(newUserTechEventList);
|
||||
|
||||
// UserKopList
|
||||
List<UserKop> userKopList = upsertUserAll.getUserKopList();
|
||||
List<UserKop> newUserKopList = new ArrayList<>();
|
||||
|
||||
for (UserKop newUserKop : userKopList) {
|
||||
int kopId = newUserKop.getKopId();
|
||||
int areaId = newUserKop.getAreaId();
|
||||
|
||||
Optional<UserKop> kopOptional = userKopRepository.findByUserAndKopIdAndAreaId(newUserData, kopId, areaId);
|
||||
UserKop userKop = kopOptional.orElseGet(() -> new UserKop(newUserData));
|
||||
|
||||
newUserKop.setId(userKop.getId());
|
||||
newUserKop.setUser(newUserData);
|
||||
newUserKopList.add(newUserKop);
|
||||
}
|
||||
userKopRepository.saveAll(newUserKopList);
|
||||
|
||||
String json = mapper.write(new CodeResp(1, "upsertUserAll"));
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
|
||||
}
|
||||
|
||||
private void saveGeneralData(List<UserRecentRating> itemList, UserData newUserData, String key) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// Convert to a string
|
||||
for (UserRecentRating item :
|
||||
itemList) {
|
||||
sb.append(item.getMusicId()).append(":").append(item.getDifficultId()).append(":").append(item.getScore());
|
||||
sb.append(",");
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
}
|
||||
Optional<UserGeneralData> uOptional = userGeneralDataRepository.findByUserAndPropertyKey(newUserData, key);
|
||||
UserGeneralData userGeneralData = uOptional.orElseGet(() -> new UserGeneralData(newUserData, key));
|
||||
userGeneralData.setPropertyValue(sb.toString());
|
||||
userGeneralDataRepository.save(userGeneralData);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,561 @@
|
|||
package icu.samnyan.aqua.sega.ongeki.handler.impl
|
||||
|
||||
import ext.logger
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
||||
import icu.samnyan.aqua.sega.general.model.response.UserRecentRating
|
||||
import icu.samnyan.aqua.sega.general.service.CardService
|
||||
import icu.samnyan.aqua.sega.ongeki.*
|
||||
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.userdata.*
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
/**
|
||||
* The handler for saving all data of a ONGEKI profile
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("OngekiUserAllHandler")
|
||||
class UpsertUserAllHandler @Autowired constructor(
|
||||
private val mapper: BasicMapper,
|
||||
private val cardService: CardService,
|
||||
private val userDataRepository: OgkUserDataRepo,
|
||||
private val userOptionRepository: OgkUserOptionRepo,
|
||||
private val userPlaylogRepository: OgkUserPlaylogRepo,
|
||||
private val userActivityRepository: OgkUserActivityRepo,
|
||||
private val userMusicDetailRepository: OgkUserMusicDetailRepo,
|
||||
private val userCharacterRepository: OgkUserCharacterRepo,
|
||||
private val userCardRepository: OgkUserCardRepo,
|
||||
private val userDeckRepository: OgkUserDeckRepo,
|
||||
private val userStoryRepository: OgkUserStoryRepo,
|
||||
private val userChapterRepository: OgkUserChapterRepo,
|
||||
private val userItemRepository: OgkUserItemRepo,
|
||||
private val userMusicItemRepository: OgkUserMusicItemRepo,
|
||||
private val userLoginBonusRepository: OgkUserLoginBonusRepo,
|
||||
private val userEventPointRepository: OgkUserEventPointRepo,
|
||||
private val userMissionPointRepository: OgkUserMissionPointRepo,
|
||||
private val userTrainingRoomRepository: OgkUserTrainingRoomRepo,
|
||||
private val userGeneralDataRepository: OgkUserGeneralDataRepo,
|
||||
private val userBossRepository: OgkUserBossRepo,
|
||||
private val userScenarioRepository: OgkUserScenarioRepo,
|
||||
private val userTechCountRepository: OgkUserTechCountRepo,
|
||||
private val userTradeItemRepository: OgkUserTradeItemRepo,
|
||||
private val userEventMusicRepository: OgkUserEventMusicRepo,
|
||||
private val userTechEventRepository: OgkUserTechEventRepo,
|
||||
private val userKopRepository: OgkUserKopRepo,
|
||||
private val userMemoryChapterRepository: OgkUserMemoryChapterRepo
|
||||
) : BaseHandler {
|
||||
override fun handle(request: Map<String, Any>): Any? {
|
||||
val userId = (request["userId"] as Number).toLong()
|
||||
val upsertUserAll = mapper.convert(
|
||||
request["upsertUserAll"]!!,
|
||||
UpsertUserAll::class.java
|
||||
)
|
||||
|
||||
// All the field should exist, no need to check now.
|
||||
// UserData
|
||||
val u: UserData
|
||||
run {
|
||||
val userData: UserData
|
||||
val userOptional = userDataRepository.findByCard_ExtId(userId)
|
||||
|
||||
// UserData might be empty on later runs
|
||||
if (userOptional.isEmpty && upsertUserAll.userData.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (userOptional.isPresent) {
|
||||
userData = userOptional.get()
|
||||
} else {
|
||||
userData = UserData()
|
||||
val card = cardService.getCardByExtId(userId).orElseThrow()
|
||||
userData.card = card
|
||||
}
|
||||
|
||||
// If new data exists, use new data. Otherwise, use old data
|
||||
u = if (!upsertUserAll.userData.isEmpty()) upsertUserAll.userData[0] else userData
|
||||
|
||||
u.id = userData.id
|
||||
u.card = userData.card
|
||||
|
||||
// Set eventWatchedDate with lastPlayDate, because client doesn't update it
|
||||
u.eventWatchedDate = userData.lastPlayDate
|
||||
u.cmEventWatchedDate = userData.lastPlayDate
|
||||
userDataRepository.save<UserData>(u)
|
||||
}
|
||||
|
||||
|
||||
// UserOption
|
||||
val newUserOption = upsertUserAll.userOption[0]
|
||||
|
||||
val userOptionOptional = userOptionRepository.findSingleByUser(u)
|
||||
val userOption = userOptionOptional.orElseGet { UserOption().apply { user = u } }
|
||||
|
||||
newUserOption.id = userOption.id
|
||||
newUserOption.user = userOption.user
|
||||
|
||||
userOptionRepository.save(newUserOption)
|
||||
|
||||
|
||||
// UserPlaylogList
|
||||
val userPlaylogList = upsertUserAll.userPlaylogList
|
||||
val newUserPlaylogList: MutableList<UserPlaylog> = ArrayList()
|
||||
|
||||
for (newUserPlaylog in userPlaylogList) {
|
||||
newUserPlaylog.user = u
|
||||
newUserPlaylogList.add(newUserPlaylog)
|
||||
}
|
||||
|
||||
userPlaylogRepository.saveAll(newUserPlaylogList)
|
||||
|
||||
|
||||
// UserSessionlogList, UserJewelboostlogLost doesn't need to be saved for a private server
|
||||
|
||||
|
||||
// UserActivityList
|
||||
val userActivityList = upsertUserAll.userActivityList
|
||||
val newUserActivityList: MutableList<UserActivity> = ArrayList()
|
||||
|
||||
for (newUserActivity in userActivityList) {
|
||||
val kind = newUserActivity.kind
|
||||
val id = newUserActivity.activityId
|
||||
|
||||
if (kind != 0 && id != 0) {
|
||||
val activityOptional = userActivityRepository.findByUserAndKindAndActivityId(u, kind, id)
|
||||
val userActivity = activityOptional.orElseGet {
|
||||
UserActivity().apply { user = u }
|
||||
}
|
||||
|
||||
newUserActivity.id = userActivity.id
|
||||
newUserActivity.user = u
|
||||
newUserActivityList.add(newUserActivity)
|
||||
}
|
||||
}
|
||||
newUserActivityList.sortWith { a, b -> b.sortNumber.compareTo(a.sortNumber) }
|
||||
userActivityRepository.saveAll(newUserActivityList)
|
||||
|
||||
|
||||
// UserRecentRatingList
|
||||
// This thing still need to save to solve the rating drop
|
||||
this.saveGeneralData(upsertUserAll.userRecentRatingList, u, "recent_rating_list")
|
||||
|
||||
|
||||
/*
|
||||
* The rating and battle point calculation is little bit complex.
|
||||
* So I just create a UserGeneralData class to store this value
|
||||
* into a csv format for convenience
|
||||
*/
|
||||
// UserBpBaseList (For calculating Battle point)
|
||||
this.saveGeneralData(upsertUserAll.userBpBaseList, u, "battle_point_base")
|
||||
|
||||
|
||||
// This is the best rating of all charts. Best 30 + 10 after that.
|
||||
// userRatingBaseBestList
|
||||
this.saveGeneralData(upsertUserAll.userRatingBaseBestList, u, "rating_base_best")
|
||||
|
||||
|
||||
// userRatingBaseNextList
|
||||
this.saveGeneralData(upsertUserAll.userRatingBaseNextList, u, "rating_base_next")
|
||||
|
||||
|
||||
// This is the best rating of new charts. Best 15 + 10 after that.
|
||||
// New chart means same version
|
||||
// userRatingBaseBestNewList
|
||||
this.saveGeneralData(upsertUserAll.userRatingBaseBestNewList, u, "rating_base_new_best")
|
||||
|
||||
// userRatingBaseNextNewList
|
||||
this.saveGeneralData(upsertUserAll.userRatingBaseNextNewList, u, "rating_base_new_next")
|
||||
|
||||
// This is the recent best
|
||||
// userRatingBaseHotList
|
||||
this.saveGeneralData(upsertUserAll.userRatingBaseHotList, u, "rating_base_hot_best")
|
||||
|
||||
// userRatingBaseHotNextList
|
||||
this.saveGeneralData(upsertUserAll.userRatingBaseHotNextList, u, "rating_base_hot_next")
|
||||
|
||||
|
||||
// UserMusicDetailList
|
||||
val userMusicDetailList = upsertUserAll.userMusicDetailList
|
||||
val newUserMusicDetailList: MutableList<UserMusicDetail> = ArrayList()
|
||||
|
||||
for (newUserMusicDetail in userMusicDetailList) {
|
||||
val musicId = newUserMusicDetail.musicId
|
||||
val level = newUserMusicDetail.level
|
||||
|
||||
val musicDetailOptional =
|
||||
userMusicDetailRepository.findByUserAndMusicIdAndLevel(u, musicId, level)
|
||||
val userMusicDetail = musicDetailOptional.orElseGet {
|
||||
UserMusicDetail().apply { user = u }
|
||||
}
|
||||
|
||||
newUserMusicDetail.id = userMusicDetail.id
|
||||
newUserMusicDetail.user = u
|
||||
newUserMusicDetailList.add(newUserMusicDetail)
|
||||
}
|
||||
userMusicDetailRepository.saveAll(newUserMusicDetailList)
|
||||
|
||||
|
||||
// UserCharacterList
|
||||
val userCharacterList = upsertUserAll.userCharacterList
|
||||
val newUserCharacterList: MutableList<UserCharacter> = ArrayList()
|
||||
|
||||
for (newUserCharacter in userCharacterList) {
|
||||
val characterId = newUserCharacter.characterId
|
||||
|
||||
val characterOptional = userCharacterRepository.findByUserAndCharacterId(u, characterId)
|
||||
val userCharacter = characterOptional.orElseGet {
|
||||
UserCharacter().apply { user = u }
|
||||
}
|
||||
|
||||
newUserCharacter.id = userCharacter.id
|
||||
newUserCharacter.user = u
|
||||
newUserCharacterList.add(newUserCharacter)
|
||||
}
|
||||
userCharacterRepository.saveAll(newUserCharacterList)
|
||||
|
||||
// UserCardList
|
||||
val userCardList = upsertUserAll.userCardList
|
||||
val newUserCardList: MutableList<UserCard> = ArrayList()
|
||||
|
||||
for (newUserCard in userCardList) {
|
||||
val cardId = newUserCard.cardId
|
||||
|
||||
val cardOptional = userCardRepository.findByUserAndCardId(u, cardId)
|
||||
val userCard = cardOptional.orElseGet { UserCard().apply { user = u } }
|
||||
|
||||
newUserCard.id = userCard.id
|
||||
newUserCard.user = u
|
||||
newUserCardList.add(newUserCard)
|
||||
}
|
||||
userCardRepository.saveAll(newUserCardList)
|
||||
|
||||
|
||||
// UserDeckList
|
||||
val userDeckList = upsertUserAll.userDeckList
|
||||
val newUserDeckList: MutableList<UserDeck> = ArrayList()
|
||||
|
||||
for (newUserDeck in userDeckList) {
|
||||
val deckId = newUserDeck.deckId
|
||||
|
||||
val deckOptional = userDeckRepository.findByUserAndDeckId(u, deckId)
|
||||
val userDeck = deckOptional.orElseGet { UserDeck().apply { user = u } }
|
||||
|
||||
newUserDeck.id = userDeck.id
|
||||
newUserDeck.user = u
|
||||
newUserDeckList.add(newUserDeck)
|
||||
}
|
||||
userDeckRepository.saveAll(newUserDeckList)
|
||||
|
||||
|
||||
// userTrainingRoomList
|
||||
val userTrainingRoomList = upsertUserAll.userTrainingRoomList
|
||||
val newUserTrainingRoomList: MutableList<UserTrainingRoom> = ArrayList()
|
||||
|
||||
for (newUserTrainingRoom in userTrainingRoomList) {
|
||||
val roomId = newUserTrainingRoom.roomId
|
||||
|
||||
val trainingRoomOptional = userTrainingRoomRepository.findByUserAndRoomId(u, roomId)
|
||||
val trainingRoom = trainingRoomOptional.orElseGet { UserTrainingRoom().apply { user = u } }
|
||||
|
||||
newUserTrainingRoom.id = trainingRoom.id
|
||||
newUserTrainingRoom.user = u
|
||||
newUserTrainingRoomList.add(newUserTrainingRoom)
|
||||
}
|
||||
userTrainingRoomRepository.saveAll(newUserTrainingRoomList)
|
||||
|
||||
|
||||
// UserStoryList
|
||||
val userStoryList = upsertUserAll.userStoryList
|
||||
val newUserStoryList: MutableList<UserStory> = ArrayList()
|
||||
|
||||
for (newUserStory in userStoryList) {
|
||||
val storyId = newUserStory.storyId
|
||||
|
||||
val storyOptional = userStoryRepository.findByUserAndStoryId(u, storyId)
|
||||
val userStory = storyOptional.orElseGet { UserStory().apply { user = u } }
|
||||
|
||||
newUserStory.id = userStory.id
|
||||
newUserStory.user = u
|
||||
newUserStoryList.add(newUserStory)
|
||||
}
|
||||
userStoryRepository.saveAll(newUserStoryList)
|
||||
|
||||
|
||||
// UserChapterList
|
||||
val userChapterList = upsertUserAll.userChapterList
|
||||
val newUserChapterList: MutableList<UserChapter> = ArrayList()
|
||||
|
||||
for (newUserChapter in userChapterList) {
|
||||
val chapterId = newUserChapter.chapterId
|
||||
|
||||
val chapterOptional = userChapterRepository.findByUserAndChapterId(u, chapterId)
|
||||
val userChapter = chapterOptional.orElseGet { UserChapter().apply { user = u } }
|
||||
|
||||
newUserChapter.id = userChapter.id
|
||||
newUserChapter.user = u
|
||||
newUserChapterList.add(newUserChapter)
|
||||
}
|
||||
userChapterRepository.saveAll(newUserChapterList)
|
||||
|
||||
|
||||
// UserMemoryChapterList
|
||||
val userMemoryChapterList = upsertUserAll.userMemoryChapterList
|
||||
|
||||
if (userMemoryChapterList != null) {
|
||||
val newUserMemoryChapterList: MutableList<UserMemoryChapter> = ArrayList()
|
||||
|
||||
for (newUserMemoryChapter in userMemoryChapterList) {
|
||||
val chapterId = newUserMemoryChapter.chapterId
|
||||
|
||||
val chapterOptional = userMemoryChapterRepository.findByUserAndChapterId(u, chapterId)
|
||||
val userChapter = chapterOptional.orElseGet { UserMemoryChapter().apply { user = u } }
|
||||
|
||||
newUserMemoryChapter.id = userChapter.id
|
||||
newUserMemoryChapter.user = u
|
||||
newUserMemoryChapterList.add(newUserMemoryChapter)
|
||||
}
|
||||
userMemoryChapterRepository.saveAll(newUserMemoryChapterList)
|
||||
}
|
||||
|
||||
// UserItemList
|
||||
val userItemList = upsertUserAll.userItemList
|
||||
val newUserItemList: MutableList<UserItem> = ArrayList()
|
||||
|
||||
for (newUserItem in userItemList) {
|
||||
val itemKind = newUserItem.itemKind
|
||||
val itemId = newUserItem.itemId
|
||||
|
||||
val itemOptional = userItemRepository.findByUserAndItemKindAndItemId(u, itemKind, itemId)
|
||||
val userItem = itemOptional.orElseGet { UserItem().apply { user = u } }
|
||||
|
||||
newUserItem.id = userItem.id
|
||||
newUserItem.user = u
|
||||
newUserItemList.add(newUserItem)
|
||||
}
|
||||
userItemRepository.saveAll(newUserItemList)
|
||||
|
||||
// UserMusicItemList
|
||||
val userMusicItemList = upsertUserAll.userMusicItemList
|
||||
val newUserMusicItemList: MutableList<UserMusicItem> = ArrayList()
|
||||
|
||||
for (newUserMusicItem in userMusicItemList) {
|
||||
val musicId = newUserMusicItem.musicId
|
||||
|
||||
val musicItemOptional = userMusicItemRepository.findByUserAndMusicId(u, musicId)
|
||||
val userMusicItem = musicItemOptional.orElseGet { UserMusicItem().apply { user = u } }
|
||||
|
||||
newUserMusicItem.id = userMusicItem.id
|
||||
newUserMusicItem.user = u
|
||||
newUserMusicItemList.add(newUserMusicItem)
|
||||
}
|
||||
userMusicItemRepository.saveAll(newUserMusicItemList)
|
||||
|
||||
|
||||
// userLoginBonusList
|
||||
val userLoginBonusList = upsertUserAll.userLoginBonusList
|
||||
val newUserLoginBonusList: MutableList<UserLoginBonus> = ArrayList()
|
||||
|
||||
for (newUserLoginBonus in userLoginBonusList) {
|
||||
val bonusId = newUserLoginBonus.bonusId
|
||||
|
||||
val loginBonusOptional = userLoginBonusRepository.findByUserAndBonusId(u, bonusId)
|
||||
val userLoginBonus = loginBonusOptional.orElseGet {
|
||||
UserLoginBonus().apply { user = u }
|
||||
}
|
||||
|
||||
newUserLoginBonus.id = userLoginBonus.id
|
||||
newUserLoginBonus.user = u
|
||||
newUserLoginBonusList.add(newUserLoginBonus)
|
||||
}
|
||||
userLoginBonusRepository.saveAll(newUserLoginBonusList)
|
||||
|
||||
|
||||
// UserEventPointList
|
||||
val userEventPointList = upsertUserAll.userEventPointList
|
||||
val newUserEventPointList: MutableList<UserEventPoint> = ArrayList()
|
||||
|
||||
for (newUserEventPoint in userEventPointList) {
|
||||
val eventId = newUserEventPoint.eventId
|
||||
|
||||
val eventPointOptional = userEventPointRepository.findByUserAndEventId(u, eventId)
|
||||
val userEventPoint = eventPointOptional.orElseGet { UserEventPoint().apply { user = u } }
|
||||
|
||||
newUserEventPoint.id = userEventPoint.id
|
||||
newUserEventPoint.user = u
|
||||
newUserEventPointList.add(newUserEventPoint)
|
||||
}
|
||||
userEventPointRepository.saveAll(newUserEventPointList)
|
||||
|
||||
|
||||
// UserMissionPointList
|
||||
val userMissionPointList = upsertUserAll.userMissionPointList
|
||||
val newUserMissionPointList: MutableList<UserMissionPoint> = ArrayList()
|
||||
|
||||
for (newUserMissionPoint in userMissionPointList) {
|
||||
val eventId = newUserMissionPoint.eventId
|
||||
|
||||
val userMissionPointOptional = userMissionPointRepository.findByUserAndEventId(u, eventId)
|
||||
val userMissionPoint = userMissionPointOptional.orElseGet { UserMissionPoint().apply { user = u } }
|
||||
|
||||
newUserMissionPoint.id = userMissionPoint.id
|
||||
newUserMissionPoint.user = u
|
||||
newUserMissionPointList.add(newUserMissionPoint)
|
||||
}
|
||||
userMissionPointRepository.saveAll(newUserMissionPointList)
|
||||
|
||||
// UserRatinglogList (For the highest rating of each version)
|
||||
|
||||
// UserBossList
|
||||
val userBossList = upsertUserAll.userBossList
|
||||
if (userBossList != null) {
|
||||
val newUserBossList: MutableList<UserBoss> = ArrayList()
|
||||
for (newUserBoss in userBossList) {
|
||||
val musicId = newUserBoss.musicId
|
||||
|
||||
val userBossOptional = userBossRepository.findByUserAndMusicId(u, musicId)
|
||||
val userBoss = userBossOptional.orElseGet {
|
||||
UserBoss().apply { user = u }
|
||||
}
|
||||
|
||||
newUserBoss.id = userBoss.id
|
||||
newUserBoss.user = userBoss.user
|
||||
newUserBossList.add(newUserBoss)
|
||||
}
|
||||
userBossRepository.saveAll(newUserBossList)
|
||||
}
|
||||
|
||||
// UserTechCountList
|
||||
val userTechCountList = upsertUserAll.userTechCountList
|
||||
if (userTechCountList != null) {
|
||||
val newUserTechCountList: MutableList<UserTechCount> = ArrayList()
|
||||
for (newUserTechCount in userTechCountList) {
|
||||
val levelId = newUserTechCount.levelId
|
||||
|
||||
val userTechCountOptional = userTechCountRepository.findByUserAndLevelId(u, levelId)
|
||||
val userTechCount = userTechCountOptional.orElseGet { UserTechCount().apply { user = u } }
|
||||
|
||||
newUserTechCount.id = userTechCount.id
|
||||
newUserTechCount.user = userTechCount.user
|
||||
newUserTechCountList.add(newUserTechCount)
|
||||
}
|
||||
userTechCountRepository.saveAll(newUserTechCountList)
|
||||
}
|
||||
|
||||
// UserScenarioList
|
||||
val userScenarioList = upsertUserAll.userScenarioList
|
||||
if (userScenarioList != null) {
|
||||
val newUserScenarioList: MutableList<UserScenario> = ArrayList()
|
||||
for (newUserScenario in userScenarioList) {
|
||||
val scenarioId = newUserScenario.scenarioId
|
||||
|
||||
val userScenarioOptional = userScenarioRepository.findByUserAndScenarioId(u, scenarioId)
|
||||
val userScenario = userScenarioOptional.orElseGet { UserScenario().apply { user = u } }
|
||||
|
||||
newUserScenario.id = userScenario.id
|
||||
newUserScenario.user = userScenario.user
|
||||
newUserScenarioList.add(newUserScenario)
|
||||
}
|
||||
userScenarioRepository.saveAll(newUserScenarioList)
|
||||
}
|
||||
|
||||
// UserTradeItemList
|
||||
val userTradeItemList = upsertUserAll.userTradeItemList
|
||||
val newUserTradeItemList: MutableList<UserTradeItem> = ArrayList()
|
||||
|
||||
for (newUserTradeItem in userTradeItemList) {
|
||||
val chapterId = newUserTradeItem.chapterId
|
||||
val tradeItemId = newUserTradeItem.tradeItemId
|
||||
|
||||
val tradeItemOptional =
|
||||
userTradeItemRepository.findByUserAndChapterIdAndTradeItemId(u, chapterId, tradeItemId)
|
||||
val userTradeItem = tradeItemOptional.orElseGet { UserTradeItem().apply { user = u } }
|
||||
|
||||
newUserTradeItem.id = userTradeItem.id
|
||||
newUserTradeItem.user = u
|
||||
newUserTradeItemList.add(newUserTradeItem)
|
||||
}
|
||||
userTradeItemRepository.saveAll(newUserTradeItemList)
|
||||
|
||||
// UserEventMusicList
|
||||
val userEventMusicList = upsertUserAll.userEventMusicList
|
||||
val newUserEventMusicList: MutableList<UserEventMusic> = ArrayList()
|
||||
|
||||
for (newUserEventMusic in userEventMusicList) {
|
||||
val eventId = newUserEventMusic.eventId
|
||||
val type = newUserEventMusic.type
|
||||
val musicId = newUserEventMusic.musicId
|
||||
|
||||
val eventMusicOptional =
|
||||
userEventMusicRepository.findByUserAndEventIdAndTypeAndMusicId(u, eventId, type, musicId)
|
||||
val userEventMusic = eventMusicOptional.orElseGet { UserEventMusic().apply { user = u } }
|
||||
|
||||
newUserEventMusic.id = userEventMusic.id
|
||||
newUserEventMusic.user = u
|
||||
newUserEventMusicList.add(newUserEventMusic)
|
||||
}
|
||||
userEventMusicRepository.saveAll(newUserEventMusicList)
|
||||
|
||||
// UserTechEventList
|
||||
val userTechEventList = upsertUserAll.userTechEventList
|
||||
val newUserTechEventList: MutableList<UserTechEvent> = ArrayList()
|
||||
|
||||
for (newUserTechEvent in userTechEventList) {
|
||||
val eventId = newUserTechEvent.eventId
|
||||
|
||||
val techEventOptional = userTechEventRepository.findByUserAndEventId(u, eventId)
|
||||
val userTechEvent = techEventOptional.orElseGet { UserTechEvent().apply { user = u } }
|
||||
|
||||
newUserTechEvent.id = userTechEvent.id
|
||||
newUserTechEvent.user = u
|
||||
newUserTechEventList.add(newUserTechEvent)
|
||||
}
|
||||
userTechEventRepository.saveAll(newUserTechEventList)
|
||||
|
||||
// UserKopList
|
||||
val userKopList = upsertUserAll.userKopList
|
||||
val newUserKopList: MutableList<UserKop> = ArrayList()
|
||||
|
||||
for (newUserKop in userKopList) {
|
||||
val kopId = newUserKop.kopId
|
||||
val areaId = newUserKop.areaId
|
||||
|
||||
val kopOptional = userKopRepository.findByUserAndKopIdAndAreaId(u, kopId, areaId)
|
||||
val userKop = kopOptional.orElseGet { UserKop().apply { user = u } }
|
||||
|
||||
newUserKop.id = userKop.id
|
||||
newUserKop.user = u
|
||||
newUserKopList.add(newUserKop)
|
||||
}
|
||||
userKopRepository.saveAll(newUserKopList)
|
||||
|
||||
val json = mapper.write(CodeResp(1, "upsertUserAll"))
|
||||
logger.info("Response: $json")
|
||||
return json
|
||||
}
|
||||
|
||||
private fun saveGeneralData(itemList: List<UserRecentRating>, newUserData: UserData, key: String) {
|
||||
val sb = StringBuilder()
|
||||
// Convert to a string
|
||||
for (item in itemList) {
|
||||
sb.append(item.musicId).append(":").append(item.difficultId).append(":").append(item.score)
|
||||
sb.append(",")
|
||||
}
|
||||
if (sb.length > 0) {
|
||||
sb.deleteCharAt(sb.length - 1)
|
||||
}
|
||||
val uOptional = userGeneralDataRepository.findByUserAndPropertyKey(newUserData, key)
|
||||
val userGeneralData = uOptional.orElseGet {
|
||||
UserGeneralData().apply {
|
||||
user = newUserData
|
||||
propertyKey = key
|
||||
}
|
||||
}
|
||||
userGeneralData.propertyValue = sb.toString()
|
||||
userGeneralDataRepository.save(userGeneralData)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = logger()
|
||||
}
|
||||
}
|
|
@ -104,7 +104,7 @@ class UserData : IUserData {
|
|||
uniqueConstraints = [UniqueConstraint(columnNames = ["user_id", "kind", "activity_id"])]
|
||||
)
|
||||
@JsonPropertyOrder("kind", "id", "sortNumber", "param1", "param2", "param3", "param4")
|
||||
class UserActivity: OngekiUserEntity() {
|
||||
class UserActivity : OngekiUserEntity() {
|
||||
var kind = 0
|
||||
@JsonProperty("id")
|
||||
@Column(name = "activity_id")
|
||||
|
@ -118,7 +118,7 @@ class UserActivity: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserBoss")
|
||||
@Table(name = "ongeki_user_boss")
|
||||
class UserBoss: OngekiUserEntity() {
|
||||
class UserBoss : OngekiUserEntity() {
|
||||
var musicId = 0
|
||||
var damage = 0
|
||||
@JsonProperty("isClear")
|
||||
|
@ -128,7 +128,7 @@ class UserBoss: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserCard")
|
||||
@Table(name = "ongeki_user_card")
|
||||
class UserCard(): OngekiUserEntity() {
|
||||
class UserCard: OngekiUserEntity() {
|
||||
var cardId = -1
|
||||
|
||||
var digitalStock = 1
|
||||
|
@ -148,22 +148,11 @@ class UserCard(): OngekiUserEntity() {
|
|||
@JsonProperty("isAcquired")
|
||||
var isAcquired = true
|
||||
var created = "0000-00-00 00:00:00.0"
|
||||
|
||||
constructor(userData: UserData) : this() {
|
||||
this.user = userData
|
||||
}
|
||||
|
||||
constructor(userData: UserData, cardId: Int, skillId: Int, created: String) : this() {
|
||||
this.user = userData
|
||||
this.cardId = cardId
|
||||
this.skillId = skillId
|
||||
this.created = created
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "OngekiUserChapter")
|
||||
@Table(name = "ongeki_user_chapter")
|
||||
class UserChapter: OngekiUserEntity() {
|
||||
class UserChapter : OngekiUserEntity() {
|
||||
var chapterId = 0
|
||||
var jewelCount = 0
|
||||
var lastPlayMusicCategory = 0
|
||||
|
@ -179,7 +168,7 @@ class UserChapter: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserCharacter")
|
||||
@Table(name = "ongeki_user_character")
|
||||
class UserCharacter: OngekiUserEntity() {
|
||||
class UserCharacter : OngekiUserEntity() {
|
||||
var characterId = 0
|
||||
var costumeId = 0
|
||||
var attachmentId = 0
|
||||
|
@ -194,7 +183,7 @@ class UserCharacter: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserDeck")
|
||||
@Table(name = "ongeki_user_deck")
|
||||
class UserDeck: OngekiUserEntity() {
|
||||
class UserDeck : OngekiUserEntity() {
|
||||
var deckId = 0
|
||||
var cardId1 = 0
|
||||
var cardId2 = 0
|
||||
|
@ -203,7 +192,7 @@ class UserDeck: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserEventMusic")
|
||||
@Table(name = "ongeki_user_event_music")
|
||||
class UserEventMusic: OngekiUserEntity() {
|
||||
class UserEventMusic : OngekiUserEntity() {
|
||||
var eventId = 0
|
||||
var type = 0
|
||||
var musicId = 0
|
||||
|
@ -218,7 +207,7 @@ class UserEventMusic: OngekiUserEntity() {
|
|||
@Entity(name = "OngekiUserEventPoint")
|
||||
@Table(name = "ongeki_user_event_point")
|
||||
|
||||
class UserEventPoint: OngekiUserEntity() {
|
||||
class UserEventPoint : OngekiUserEntity() {
|
||||
var eventId = 0
|
||||
var point: Long = 0
|
||||
@JsonProperty("isRankingRewarded")
|
||||
|
@ -227,14 +216,15 @@ class UserEventPoint: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserGeneralData")
|
||||
@Table(name = "ongeki_user_general_data")
|
||||
class UserGeneralData(var propertyKey: String): OngekiUserEntity() {
|
||||
class UserGeneralData : OngekiUserEntity() {
|
||||
var propertyKey = ""
|
||||
@Column(columnDefinition = "TEXT")
|
||||
var propertyValue = ""
|
||||
}
|
||||
|
||||
@Entity(name = "OngekiUserItem")
|
||||
@Table(name = "ongeki_user_item")
|
||||
class UserItem: OngekiUserEntity() {
|
||||
class UserItem : OngekiUserEntity() {
|
||||
var itemKind = 0
|
||||
var itemId = 0
|
||||
var stock = 0
|
||||
|
@ -244,7 +234,7 @@ class UserItem: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserKop")
|
||||
@Table(name = "ongeki_user_kop")
|
||||
class UserKop: OngekiUserEntity() {
|
||||
class UserKop : OngekiUserEntity() {
|
||||
var authKey: String = ""
|
||||
var kopId = 0
|
||||
var areaId = 0
|
||||
|
@ -257,7 +247,7 @@ class UserKop: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserLoginBonus")
|
||||
@Table(name = "ongeki_user_login_bonus")
|
||||
class UserLoginBonus: OngekiUserEntity() {
|
||||
class UserLoginBonus : OngekiUserEntity() {
|
||||
var bonusId = 0
|
||||
var bonusCount = 0
|
||||
var lastUpdateDate: String = ""
|
||||
|
@ -265,7 +255,7 @@ class UserLoginBonus: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserMemoryChapter")
|
||||
@Table(name = "ongeki_user_memory_chapter")
|
||||
class UserMemoryChapter: OngekiUserEntity() {
|
||||
class UserMemoryChapter : OngekiUserEntity() {
|
||||
var chapterId = 0
|
||||
var jewelCount = 0
|
||||
var lastPlayMusicCategory = 0
|
||||
|
@ -285,14 +275,14 @@ class UserMemoryChapter: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserMissionPoint")
|
||||
@Table(name = "ongeki_user_mission_point")
|
||||
class UserMissionPoint: OngekiUserEntity() {
|
||||
class UserMissionPoint : OngekiUserEntity() {
|
||||
var eventId = 0
|
||||
var point: Long = 0
|
||||
}
|
||||
|
||||
@Entity(name = "OngekiUserMusicDetail")
|
||||
@Table(name = "ongeki_user_music_detail")
|
||||
class UserMusicDetail: OngekiUserEntity(), IGenericUserMusic {
|
||||
class UserMusicDetail : OngekiUserEntity(), IGenericUserMusic {
|
||||
override var musicId: Int = 0
|
||||
var level = 0
|
||||
var playCount = 0
|
||||
|
@ -318,14 +308,14 @@ class UserMusicDetail: OngekiUserEntity(), IGenericUserMusic {
|
|||
|
||||
@Entity(name = "OngekiUserMusicItem")
|
||||
@Table(name = "ongeki_user_music_item")
|
||||
class UserMusicItem: OngekiUserEntity() {
|
||||
class UserMusicItem : OngekiUserEntity() {
|
||||
var musicId = 0
|
||||
var status = 0
|
||||
}
|
||||
|
||||
@Entity(name = "OngekiUserOption")
|
||||
@Table(name = "ongeki_user_option")
|
||||
class UserOption: OngekiUserEntity() {
|
||||
class UserOption : OngekiUserEntity() {
|
||||
var optionSet = 0
|
||||
var speed = 0
|
||||
var mirror = 0
|
||||
|
@ -449,7 +439,7 @@ class UserPlaylog : OngekiUserEntity(), IGenericGamePlaylog {
|
|||
|
||||
@Entity(name = "OngekiUserRival")
|
||||
@Table(name = "ongeki_user_rival")
|
||||
class UserRival: OngekiUserEntity() {
|
||||
class UserRival : OngekiUserEntity() {
|
||||
@JoinColumn(name = "rival_user_ext_id")
|
||||
@JsonProperty("rivalUserId")
|
||||
var rivalUserExtId: Long = 0
|
||||
|
@ -457,14 +447,14 @@ class UserRival: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserScenario")
|
||||
@Table(name = "ongeki_user_scenario")
|
||||
class UserScenario: OngekiUserEntity() {
|
||||
class UserScenario : OngekiUserEntity() {
|
||||
var scenarioId = 0
|
||||
var playCount = 0
|
||||
}
|
||||
|
||||
@Entity(name = "OngekiUserStory")
|
||||
@Table(name = "ongeki_user_story")
|
||||
class UserStory: OngekiUserEntity() {
|
||||
class UserStory : OngekiUserEntity() {
|
||||
var storyId = 0
|
||||
var lastChapterId = 0
|
||||
var jewelCount = 0
|
||||
|
@ -475,7 +465,7 @@ class UserStory: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserTechCount")
|
||||
@Table(name = "ongeki_user_tech_count")
|
||||
class UserTechCount: OngekiUserEntity() {
|
||||
class UserTechCount : OngekiUserEntity() {
|
||||
var levelId = 0
|
||||
var allBreakCount = 0
|
||||
var allBreakPlusCount = 0
|
||||
|
@ -483,7 +473,7 @@ class UserTechCount: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserTechEvent")
|
||||
@Table(name = "ongeki_user_tech_event")
|
||||
class UserTechEvent: OngekiUserEntity() {
|
||||
class UserTechEvent : OngekiUserEntity() {
|
||||
var eventId = 0
|
||||
var totalTechScore = 0
|
||||
var totalPlatinumScore = 0
|
||||
|
@ -496,7 +486,7 @@ class UserTechEvent: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiUserTradeItem")
|
||||
@Table(name = "ongeki_user_trade_item")
|
||||
class UserTradeItem: OngekiUserEntity() {
|
||||
class UserTradeItem : OngekiUserEntity() {
|
||||
var chapterId = 0
|
||||
var tradeItemId = 0
|
||||
var tradeCount = 0
|
||||
|
@ -504,7 +494,7 @@ class UserTradeItem: OngekiUserEntity() {
|
|||
|
||||
@Entity(name = "OngekiTrainingRoom")
|
||||
@Table(name = "ongeki_user_training_room")
|
||||
class UserTrainingRoom: OngekiUserEntity() {
|
||||
class UserTrainingRoom : OngekiUserEntity() {
|
||||
var authKey: String = ""
|
||||
var roomId: Int = 0
|
||||
var cardId: Int = 0
|
||||
|
|
Loading…
Reference in New Issue