mirror of https://github.com/hykilpikonna/AquaDX
[O] Ongeki: Upsert user all
parent
1193192e81
commit
e00bbeadde
|
@ -10,6 +10,7 @@ fun OngekiController.ongekiInit() {
|
||||||
fun <T> List<T>.staticLst(key: String) = mapOf("length" to size, key to this)
|
fun <T> List<T>.staticLst(key: String) = mapOf("length" to size, key to this)
|
||||||
|
|
||||||
initUser()
|
initUser()
|
||||||
|
initUpsertAll()
|
||||||
|
|
||||||
// Has type, but type is always 1
|
// Has type, but type is always 1
|
||||||
"GetGameEvent".static {
|
"GetGameEvent".static {
|
||||||
|
|
|
@ -0,0 +1,188 @@
|
||||||
|
package icu.samnyan.aqua.sega.ongeki
|
||||||
|
|
||||||
|
import ext.invoke
|
||||||
|
import ext.mapApply
|
||||||
|
import ext.minus
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.model.CodeResp
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.model.OngekiUpsertUserAll
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.model.UserData
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.model.UserGeneralData
|
||||||
|
|
||||||
|
|
||||||
|
fun OngekiController.initUpsertAll() {
|
||||||
|
fun saveGeneralData(items: List<Any>, u: UserData, key: String) {
|
||||||
|
db.generalData.save(UserGeneralData().apply {
|
||||||
|
id = db.generalData.findByUserAndPropertyKey(u, key)()?.id ?: 0
|
||||||
|
user = u
|
||||||
|
propertyKey = key
|
||||||
|
propertyValue = items.joinToString(",")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
"UpsertUserAll" api@ {
|
||||||
|
val all: OngekiUpsertUserAll = mapper.convert(data["upsertUserAll"]!!)
|
||||||
|
|
||||||
|
// User data
|
||||||
|
val oldUser = db.data.findByCard_ExtId(uid)()
|
||||||
|
val u: UserData = all.userData?.get(0)?.apply {
|
||||||
|
id = oldUser?.id ?: 0
|
||||||
|
card = oldUser?.card ?: us.cardRepo.findByExtId(uid)() ?: (404 - "Card not found")
|
||||||
|
|
||||||
|
// Set eventWatchedDate with lastPlayDate, because client doesn't update it
|
||||||
|
eventWatchedDate = oldUser?.lastPlayDate ?: ""
|
||||||
|
cmEventWatchedDate = oldUser?.lastPlayDate ?: ""
|
||||||
|
db.data.save(this)
|
||||||
|
} ?: oldUser ?: return@api null
|
||||||
|
|
||||||
|
all.run {
|
||||||
|
// Set users
|
||||||
|
listOfNotNull(
|
||||||
|
userOption, userPlaylogList, userActivityList, userMusicDetailList, userCharacterList
|
||||||
|
).flatten().forEach { it.user = u }
|
||||||
|
|
||||||
|
// UserOption
|
||||||
|
userOption?.get(0)?.let {
|
||||||
|
db.option.save(it.apply {
|
||||||
|
id = db.option.findSingleByUser(u)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserEventMap
|
||||||
|
userEventMap?.let {
|
||||||
|
db.eventMap.save(it.apply {
|
||||||
|
id = db.eventMap.findSingleByUser(u)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserPlaylogList
|
||||||
|
userPlaylogList?.let { db.playlog.saveAll(it) }
|
||||||
|
|
||||||
|
// UserSessionlogList, UserJewelboostlogLost doesn't need to be saved for a private server
|
||||||
|
|
||||||
|
// UserActivityList
|
||||||
|
userActivityList?.let { list ->
|
||||||
|
db.activity.saveAll(list.distinctBy { it.activityId to it.kind }.mapApply {
|
||||||
|
id = db.activity.findByUserAndKindAndActivityId(u, kind, activityId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// Ratings
|
||||||
|
mapOf(
|
||||||
|
"recent_rating_list" to userRecentRatingList, // This thing still need to save to solve the rating drop
|
||||||
|
"battle_point_base" to userBpBaseList, // For calculating Battle point
|
||||||
|
"rating_base_best" to userRatingBaseBestList, // This is the best rating of all charts. Best 30 + 10 after that.
|
||||||
|
"rating_base_next" to userRatingBaseNextList,
|
||||||
|
"rating_base_new_best" to userRatingBaseBestNewList, // This is the best rating of new charts. Best 15 + 10 after that.
|
||||||
|
"rating_base_new_next" to userRatingBaseNextNewList,
|
||||||
|
"rating_base_hot_best" to userRatingBaseHotList, // This is the recent best
|
||||||
|
"rating_base_hot_next" to userRatingBaseHotNextList,
|
||||||
|
|
||||||
|
// Re:Fresh
|
||||||
|
"new_rating_base_best" to userNewRatingBaseBestList,
|
||||||
|
"new_rating_base_next_best" to userNewRatingBaseNextBestList,
|
||||||
|
"new_rating_base_new_best" to userNewRatingBaseBestNewList,
|
||||||
|
"new_rating_base_new_next_best" to userNewRatingBaseNextBestNewList,
|
||||||
|
"new_rating_base_pscore" to userNewRatingBasePScoreList,
|
||||||
|
"new_rating_base_next_pscore" to userNewRatingBaseNextPScoreList
|
||||||
|
).forEach { (k, v) -> v?.let { saveGeneralData(it, u, k) } }
|
||||||
|
|
||||||
|
// UserMusicDetailList
|
||||||
|
userMusicDetailList?.let { list ->
|
||||||
|
db.musicDetail.saveAll(list.distinctBy { it.musicId to it.level }.mapApply {
|
||||||
|
id = db.musicDetail.findByUserAndMusicIdAndLevel(u, musicId, level)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserCharacterList
|
||||||
|
userCharacterList?.let { list ->
|
||||||
|
db.character.saveAll(list.distinctBy { it.characterId }.mapApply {
|
||||||
|
id = db.character.findByUserAndCharacterId(u, characterId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserCardList
|
||||||
|
userCardList?.let { list ->
|
||||||
|
db.card.saveAll(list.distinctBy { it.cardId }.mapApply {
|
||||||
|
id = db.card.findByUserAndCardId(u, cardId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserDeckList
|
||||||
|
userDeckList?.let { list ->
|
||||||
|
db.deck.saveAll(list.distinctBy { it.deckId }.mapApply {
|
||||||
|
id = db.deck.findByUserAndDeckId(u, deckId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserTrainingRoomList
|
||||||
|
userTrainingRoomList?.let { list ->
|
||||||
|
db.trainingRoom.saveAll(list.distinctBy { it.roomId }.mapApply {
|
||||||
|
id = db.trainingRoom.findByUserAndRoomId(u, roomId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserStoryList
|
||||||
|
userStoryList?.let { list ->
|
||||||
|
db.story.saveAll(list.distinctBy { it.storyId }.mapApply {
|
||||||
|
id = db.story.findByUserAndStoryId(u, storyId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserChapterList
|
||||||
|
userChapterList?.let { list ->
|
||||||
|
db.chapter.saveAll(list.distinctBy { it.chapterId }.mapApply {
|
||||||
|
id = db.chapter.findByUserAndChapterId(u, chapterId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserMemoryChapterList
|
||||||
|
userMemoryChapterList?.let { list ->
|
||||||
|
db.memoryChapter.saveAll(list.distinctBy { it.chapterId }.mapApply {
|
||||||
|
id = db.memoryChapter.findByUserAndChapterId(u, chapterId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserItemList
|
||||||
|
userItemList?.let { list ->
|
||||||
|
db.item.saveAll(list.distinctBy { it.itemKind to it.itemId }.mapApply {
|
||||||
|
id = db.item.findByUserAndItemKindAndItemId(u, itemKind, itemId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserMusicItemList
|
||||||
|
userMusicItemList?.let { list ->
|
||||||
|
db.musicItem.saveAll(list.distinctBy { it.musicId }.mapApply {
|
||||||
|
id = db.musicItem.findByUserAndMusicId(u, musicId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserLoginBonusList
|
||||||
|
userLoginBonusList?.let { list ->
|
||||||
|
db.loginBonus.saveAll(list.distinctBy { it.bonusId }.mapApply {
|
||||||
|
id = db.loginBonus.findByUserAndBonusId(u, bonusId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserEventPointList
|
||||||
|
userEventPointList?.let { list ->
|
||||||
|
db.eventPoint.saveAll(list.distinctBy { it.eventId }.mapApply {
|
||||||
|
id = db.eventPoint.findByUserAndEventId(u, eventId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserMissionPointList
|
||||||
|
userMissionPointList?.let { list ->
|
||||||
|
db.missionPoint.saveAll(list.distinctBy { it.eventId }.mapApply {
|
||||||
|
id = db.missionPoint.findByUserAndEventId(u, eventId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserRatinglogList (For the highest rating of each version)
|
||||||
|
|
||||||
|
// UserBossList
|
||||||
|
userBossList?.let { list ->
|
||||||
|
db.boss.saveAll(list.distinctBy { it.musicId }.mapApply {
|
||||||
|
id = db.boss.findByUserAndMusicId(u, musicId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserTechCountList
|
||||||
|
userTechCountList?.let { list ->
|
||||||
|
db.techCount.saveAll(list.distinctBy { it.levelId }.mapApply {
|
||||||
|
id = db.techCount.findByUserAndLevelId(u, levelId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserScenarioList
|
||||||
|
userScenarioList?.let { list ->
|
||||||
|
db.scenario.saveAll(list.distinctBy { it.scenarioId }.mapApply {
|
||||||
|
id = db.scenario.findByUserAndScenarioId(u, scenarioId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserTradeItemList
|
||||||
|
userTradeItemList?.let { list ->
|
||||||
|
db.tradeItem.saveAll(list.distinctBy { it.chapterId to it.tradeItemId }.mapApply {
|
||||||
|
id = db.tradeItem.findByUserAndChapterIdAndTradeItemId(u, chapterId, tradeItemId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserEventMusicList
|
||||||
|
userEventMusicList?.let { list ->
|
||||||
|
db.eventMusic.saveAll(list.distinctBy { it.eventId to it.type to it.musicId }.mapApply {
|
||||||
|
id = db.eventMusic.findByUserAndEventIdAndTypeAndMusicId(u, eventId, type, musicId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserTechEventList
|
||||||
|
userTechEventList?.let { list ->
|
||||||
|
db.techEvent.saveAll(list.distinctBy { it.eventId }.mapApply {
|
||||||
|
id = db.techEvent.findByUserAndEventId(u, eventId)()?.id ?: 0 }) }
|
||||||
|
|
||||||
|
// UserKopList
|
||||||
|
userKopList?.let { list ->
|
||||||
|
db.kop.saveAll(list.distinctBy { it.kopId to it.areaId }.mapApply {
|
||||||
|
id = db.kop.findByUserAndKopIdAndAreaId(u, kopId, areaId)()?.id ?: 0 }) }
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeResp(1, "upsertUserAll")
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,603 +0,0 @@
|
||||||
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.OngekiUserRepos
|
|
||||||
import icu.samnyan.aqua.sega.ongeki.model.*
|
|
||||||
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,
|
|
||||||
val db: OngekiUserRepos
|
|
||||||
) : BaseHandler {
|
|
||||||
override fun handle(request: Map<String, Any>): String? {
|
|
||||||
val userId = (request["userId"] as Number).toLong()
|
|
||||||
val all = 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 = db.data.findByCard_ExtId(userId)
|
|
||||||
|
|
||||||
// UserData might be empty on later runs
|
|
||||||
if (userOptional.isEmpty && all.userData.isNullOrEmpty()) {
|
|
||||||
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 (!all.userData.isNullOrEmpty()) all.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
|
|
||||||
db.data.save(u)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// UserOption
|
|
||||||
val newUserOption = all.userOption!![0]
|
|
||||||
|
|
||||||
val userOptionOptional = db.option.findSingleByUser(u)
|
|
||||||
val userOption = userOptionOptional.orElseGet { UserOption().apply { user = u } }
|
|
||||||
|
|
||||||
newUserOption.id = userOption.id
|
|
||||||
newUserOption.user = userOption.user
|
|
||||||
|
|
||||||
db.option.save(newUserOption)
|
|
||||||
|
|
||||||
|
|
||||||
// UserPlaylogList
|
|
||||||
val userPlaylogList = all.userPlaylogList
|
|
||||||
val newUserPlaylogList: MutableList<UserPlaylog> = ArrayList()
|
|
||||||
|
|
||||||
if (userPlaylogList != null) {
|
|
||||||
for (newUserPlaylog in userPlaylogList) {
|
|
||||||
newUserPlaylog.user = u
|
|
||||||
newUserPlaylogList.add(newUserPlaylog)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
db.playlog.saveAll(newUserPlaylogList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserSessionlogList, UserJewelboostlogLost doesn't need to be saved for a private server
|
|
||||||
|
|
||||||
|
|
||||||
// UserActivityList
|
|
||||||
val userActivityList = all.userActivityList
|
|
||||||
val newUserActivityList: MutableList<UserActivity> = ArrayList()
|
|
||||||
|
|
||||||
if (userActivityList != null) {
|
|
||||||
for (newUserActivity in userActivityList) {
|
|
||||||
val kind = newUserActivity.kind
|
|
||||||
val id = newUserActivity.activityId
|
|
||||||
|
|
||||||
if (kind != 0 && id != 0) {
|
|
||||||
val activityOptional = db.activity.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) }
|
|
||||||
db.activity.saveAll(newUserActivityList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserRecentRatingList
|
|
||||||
// This thing still need to save to solve the rating drop
|
|
||||||
all.userRecentRatingList?.let { this.saveRecentRatingData(it, 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)
|
|
||||||
all.userBpBaseList?.let { this.saveRecentRatingData(it, u, "battle_point_base") }
|
|
||||||
|
|
||||||
// This is the best rating of all charts. Best 30 + 10 after that.
|
|
||||||
// userRatingBaseBestList
|
|
||||||
all.userRatingBaseBestList?.let { this.saveRecentRatingData(it, u, "rating_base_best") }
|
|
||||||
|
|
||||||
// userRatingBaseNextList
|
|
||||||
all.userRatingBaseNextList?.let { this.saveRecentRatingData(it, u, "rating_base_next") }
|
|
||||||
|
|
||||||
// This is the best rating of new charts. Best 15 + 10 after that.
|
|
||||||
// New chart means same version
|
|
||||||
// userRatingBaseBestNewList
|
|
||||||
all.userRatingBaseBestNewList?.let { this.saveRecentRatingData(it, u, "rating_base_new_best") }
|
|
||||||
|
|
||||||
// userRatingBaseNextNewList
|
|
||||||
all.userRatingBaseNextNewList?.let { this.saveRecentRatingData(it, u, "rating_base_new_next") }
|
|
||||||
|
|
||||||
// This is the recent best
|
|
||||||
// userRatingBaseHotList
|
|
||||||
all.userRatingBaseHotList?.let { this.saveRecentRatingData(it, u, "rating_base_hot_best") }
|
|
||||||
|
|
||||||
// userRatingBaseHotNextList
|
|
||||||
all.userRatingBaseHotNextList?.let { this.saveRecentRatingData(it, u, "rating_base_hot_next") }
|
|
||||||
|
|
||||||
// Re:Fresh
|
|
||||||
all.userNewRatingBaseBestList?.let { this.saveFumenScoreData(it, u, "new_rating_base_best") }
|
|
||||||
all.userNewRatingBaseNextBestList?.let { this.saveFumenScoreData(it, u, "new_rating_base_next_best") }
|
|
||||||
all.userNewRatingBaseBestNewList?.let { this.saveFumenScoreData(it, u, "new_rating_base_new_best") }
|
|
||||||
all.userNewRatingBaseNextBestNewList?.let { this.saveFumenScoreData(it, u, "new_rating_base_new_next_best") }
|
|
||||||
all.userNewRatingBasePScoreList?.let { this.saveFumenScoreData(it, u, "new_rating_base_pscore") }
|
|
||||||
all.userNewRatingBaseNextPScoreList?.let { this.saveFumenScoreData(it, u, "new_rating_base_next_pscore") }
|
|
||||||
|
|
||||||
// UserMusicDetailList
|
|
||||||
val userMusicDetailList = all.userMusicDetailList
|
|
||||||
val newUserMusicDetailList: MutableList<UserMusicDetail> = ArrayList()
|
|
||||||
|
|
||||||
if (userMusicDetailList != null) {
|
|
||||||
for (newUserMusicDetail in userMusicDetailList) {
|
|
||||||
val musicId = newUserMusicDetail.musicId
|
|
||||||
val level = newUserMusicDetail.level
|
|
||||||
|
|
||||||
val musicDetailOptional =
|
|
||||||
db.musicDetail.findByUserAndMusicIdAndLevel(u, musicId, level)
|
|
||||||
val userMusicDetail = musicDetailOptional.orElseGet {
|
|
||||||
UserMusicDetail().apply { user = u }
|
|
||||||
}
|
|
||||||
|
|
||||||
newUserMusicDetail.id = userMusicDetail.id
|
|
||||||
newUserMusicDetail.user = u
|
|
||||||
newUserMusicDetailList.add(newUserMusicDetail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.musicDetail.saveAll(newUserMusicDetailList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserCharacterList
|
|
||||||
val userCharacterList = all.userCharacterList
|
|
||||||
val newUserCharacterList: MutableList<UserCharacter> = ArrayList()
|
|
||||||
|
|
||||||
if (userCharacterList != null) {
|
|
||||||
for (newUserCharacter in userCharacterList) {
|
|
||||||
val characterId = newUserCharacter.characterId
|
|
||||||
|
|
||||||
val characterOptional = db.character.findByUserAndCharacterId(u, characterId)
|
|
||||||
val userCharacter = characterOptional.orElseGet {
|
|
||||||
UserCharacter().apply { user = u }
|
|
||||||
}
|
|
||||||
|
|
||||||
newUserCharacter.id = userCharacter.id
|
|
||||||
newUserCharacter.user = u
|
|
||||||
newUserCharacterList.add(newUserCharacter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.character.saveAll(newUserCharacterList)
|
|
||||||
|
|
||||||
// UserCardList
|
|
||||||
val userCardList = all.userCardList
|
|
||||||
val newUserCardList: MutableList<UserCard> = ArrayList()
|
|
||||||
|
|
||||||
if (userCardList != null) {
|
|
||||||
for (newUserCard in userCardList) {
|
|
||||||
val cardId = newUserCard.cardId
|
|
||||||
|
|
||||||
val cardOptional = db.card.findByUserAndCardId(u, cardId)
|
|
||||||
val userCard = cardOptional.orElseGet { UserCard().apply { user = u } }
|
|
||||||
|
|
||||||
newUserCard.id = userCard.id
|
|
||||||
newUserCard.user = u
|
|
||||||
newUserCardList.add(newUserCard)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.card.saveAll(newUserCardList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserDeckList
|
|
||||||
val userDeckList = all.userDeckList
|
|
||||||
val newUserDeckList: MutableList<UserDeck> = ArrayList()
|
|
||||||
|
|
||||||
if (userDeckList != null) {
|
|
||||||
for (newUserDeck in userDeckList) {
|
|
||||||
val deckId = newUserDeck.deckId
|
|
||||||
|
|
||||||
val deckOptional = db.deck.findByUserAndDeckId(u, deckId)
|
|
||||||
val userDeck = deckOptional.orElseGet { UserDeck().apply { user = u } }
|
|
||||||
|
|
||||||
newUserDeck.id = userDeck.id
|
|
||||||
newUserDeck.user = u
|
|
||||||
newUserDeckList.add(newUserDeck)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.deck.saveAll(newUserDeckList)
|
|
||||||
|
|
||||||
|
|
||||||
// userTrainingRoomList
|
|
||||||
val userTrainingRoomList = all.userTrainingRoomList
|
|
||||||
val newUserTrainingRoomList: MutableList<UserTrainingRoom> = ArrayList()
|
|
||||||
|
|
||||||
if (userTrainingRoomList != null) {
|
|
||||||
for (newUserTrainingRoom in userTrainingRoomList) {
|
|
||||||
val roomId = newUserTrainingRoom.roomId
|
|
||||||
|
|
||||||
val trainingRoomOptional = db.trainingRoom.findByUserAndRoomId(u, roomId)
|
|
||||||
val trainingRoom = trainingRoomOptional.orElseGet { UserTrainingRoom().apply { user = u } }
|
|
||||||
|
|
||||||
newUserTrainingRoom.id = trainingRoom.id
|
|
||||||
newUserTrainingRoom.user = u
|
|
||||||
newUserTrainingRoomList.add(newUserTrainingRoom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.trainingRoom.saveAll(newUserTrainingRoomList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserStoryList
|
|
||||||
val userStoryList = all.userStoryList
|
|
||||||
val newUserStoryList: MutableList<UserStory> = ArrayList()
|
|
||||||
|
|
||||||
if (userStoryList != null) {
|
|
||||||
for (newUserStory in userStoryList) {
|
|
||||||
val storyId = newUserStory.storyId
|
|
||||||
|
|
||||||
val storyOptional = db.story.findByUserAndStoryId(u, storyId)
|
|
||||||
val userStory = storyOptional.orElseGet { UserStory().apply { user = u } }
|
|
||||||
|
|
||||||
newUserStory.id = userStory.id
|
|
||||||
newUserStory.user = u
|
|
||||||
newUserStoryList.add(newUserStory)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.story.saveAll(newUserStoryList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserChapterList
|
|
||||||
val userChapterList = all.userChapterList
|
|
||||||
val newUserChapterList: MutableList<UserChapter> = ArrayList()
|
|
||||||
|
|
||||||
if (userChapterList != null) {
|
|
||||||
for (newUserChapter in userChapterList) {
|
|
||||||
val chapterId = newUserChapter.chapterId
|
|
||||||
|
|
||||||
val chapterOptional = db.chapter.findByUserAndChapterId(u, chapterId)
|
|
||||||
val userChapter = chapterOptional.orElseGet { UserChapter().apply { user = u } }
|
|
||||||
|
|
||||||
newUserChapter.id = userChapter.id
|
|
||||||
newUserChapter.user = u
|
|
||||||
newUserChapterList.add(newUserChapter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.chapter.saveAll(newUserChapterList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserMemoryChapterList
|
|
||||||
val userMemoryChapterList = all.userMemoryChapterList
|
|
||||||
|
|
||||||
if (userMemoryChapterList != null) {
|
|
||||||
val newUserMemoryChapterList: MutableList<UserMemoryChapter> = ArrayList()
|
|
||||||
|
|
||||||
for (newUserMemoryChapter in userMemoryChapterList) {
|
|
||||||
val chapterId = newUserMemoryChapter.chapterId
|
|
||||||
|
|
||||||
val chapterOptional = db.memoryChapter.findByUserAndChapterId(u, chapterId)
|
|
||||||
val userChapter = chapterOptional.orElseGet { UserMemoryChapter().apply { user = u } }
|
|
||||||
|
|
||||||
newUserMemoryChapter.id = userChapter.id
|
|
||||||
newUserMemoryChapter.user = u
|
|
||||||
newUserMemoryChapterList.add(newUserMemoryChapter)
|
|
||||||
}
|
|
||||||
db.memoryChapter.saveAll(newUserMemoryChapterList)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserItemList
|
|
||||||
val userItemList = all.userItemList
|
|
||||||
val newUserItemList: MutableList<UserItem> = ArrayList()
|
|
||||||
|
|
||||||
if (userItemList != null) {
|
|
||||||
for (newUserItem in userItemList) {
|
|
||||||
val itemKind = newUserItem.itemKind
|
|
||||||
val itemId = newUserItem.itemId
|
|
||||||
|
|
||||||
val itemOptional = db.item.findByUserAndItemKindAndItemId(u, itemKind, itemId)
|
|
||||||
val userItem = itemOptional.orElseGet { UserItem().apply { user = u } }
|
|
||||||
|
|
||||||
newUserItem.id = userItem.id
|
|
||||||
newUserItem.user = u
|
|
||||||
newUserItemList.add(newUserItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.item.saveAll(newUserItemList)
|
|
||||||
|
|
||||||
// UserMusicItemList
|
|
||||||
val userMusicItemList = all.userMusicItemList
|
|
||||||
val newUserMusicItemList: MutableList<UserMusicItem> = ArrayList()
|
|
||||||
|
|
||||||
if (userMusicItemList != null) {
|
|
||||||
for (newUserMusicItem in userMusicItemList) {
|
|
||||||
val musicId = newUserMusicItem.musicId
|
|
||||||
|
|
||||||
val musicItemOptional = db.musicItem.findByUserAndMusicId(u, musicId)
|
|
||||||
val userMusicItem = musicItemOptional.orElseGet { UserMusicItem().apply { user = u } }
|
|
||||||
|
|
||||||
newUserMusicItem.id = userMusicItem.id
|
|
||||||
newUserMusicItem.user = u
|
|
||||||
newUserMusicItemList.add(newUserMusicItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.musicItem.saveAll(newUserMusicItemList)
|
|
||||||
|
|
||||||
|
|
||||||
// userLoginBonusList
|
|
||||||
val userLoginBonusList = all.userLoginBonusList
|
|
||||||
val newUserLoginBonusList: MutableList<UserLoginBonus> = ArrayList()
|
|
||||||
|
|
||||||
if (userLoginBonusList != null) {
|
|
||||||
for (newUserLoginBonus in userLoginBonusList) {
|
|
||||||
val bonusId = newUserLoginBonus.bonusId
|
|
||||||
|
|
||||||
val loginBonusOptional = db.loginBonus.findByUserAndBonusId(u, bonusId)
|
|
||||||
val userLoginBonus = loginBonusOptional.orElseGet {
|
|
||||||
UserLoginBonus().apply { user = u }
|
|
||||||
}
|
|
||||||
|
|
||||||
newUserLoginBonus.id = userLoginBonus.id
|
|
||||||
newUserLoginBonus.user = u
|
|
||||||
newUserLoginBonusList.add(newUserLoginBonus)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.loginBonus.saveAll(newUserLoginBonusList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserEventPointList
|
|
||||||
val userEventPointList = all.userEventPointList
|
|
||||||
val newUserEventPointList: MutableList<UserEventPoint> = ArrayList()
|
|
||||||
|
|
||||||
if (userEventPointList != null) {
|
|
||||||
for (newUserEventPoint in userEventPointList) {
|
|
||||||
val eventId = newUserEventPoint.eventId
|
|
||||||
|
|
||||||
val eventPointOptional = db.eventPoint.findByUserAndEventId(u, eventId)
|
|
||||||
val userEventPoint = eventPointOptional.orElseGet { UserEventPoint().apply { user = u } }
|
|
||||||
|
|
||||||
newUserEventPoint.id = userEventPoint.id
|
|
||||||
newUserEventPoint.user = u
|
|
||||||
newUserEventPointList.add(newUserEventPoint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.eventPoint.saveAll(newUserEventPointList)
|
|
||||||
|
|
||||||
|
|
||||||
// UserMissionPointList
|
|
||||||
val userMissionPointList = all.userMissionPointList
|
|
||||||
val newUserMissionPointList: MutableList<UserMissionPoint> = ArrayList()
|
|
||||||
|
|
||||||
if (userMissionPointList != null) {
|
|
||||||
for (newUserMissionPoint in userMissionPointList) {
|
|
||||||
val eventId = newUserMissionPoint.eventId
|
|
||||||
|
|
||||||
val userMissionPointOptional = db.missionPoint.findByUserAndEventId(u, eventId)
|
|
||||||
val userMissionPoint = userMissionPointOptional.orElseGet { UserMissionPoint().apply { user = u } }
|
|
||||||
|
|
||||||
newUserMissionPoint.id = userMissionPoint.id
|
|
||||||
newUserMissionPoint.user = u
|
|
||||||
newUserMissionPointList.add(newUserMissionPoint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.missionPoint.saveAll(newUserMissionPointList)
|
|
||||||
|
|
||||||
// UserRatinglogList (For the highest rating of each version)
|
|
||||||
|
|
||||||
// UserBossList
|
|
||||||
val userBossList = all.userBossList
|
|
||||||
if (userBossList != null) {
|
|
||||||
val newUserBossList: MutableList<UserBoss> = ArrayList()
|
|
||||||
for (newUserBoss in userBossList) {
|
|
||||||
val musicId = newUserBoss.musicId
|
|
||||||
|
|
||||||
val userBossOptional = db.boss.findByUserAndMusicId(u, musicId)
|
|
||||||
val userBoss = userBossOptional.orElseGet {
|
|
||||||
UserBoss().apply { user = u }
|
|
||||||
}
|
|
||||||
|
|
||||||
newUserBoss.id = userBoss.id
|
|
||||||
newUserBoss.user = userBoss.user
|
|
||||||
newUserBossList.add(newUserBoss)
|
|
||||||
}
|
|
||||||
db.boss.saveAll(newUserBossList)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserTechCountList
|
|
||||||
val userTechCountList = all.userTechCountList
|
|
||||||
if (userTechCountList != null) {
|
|
||||||
val newUserTechCountList: MutableList<UserTechCount> = ArrayList()
|
|
||||||
for (newUserTechCount in userTechCountList) {
|
|
||||||
val levelId = newUserTechCount.levelId
|
|
||||||
|
|
||||||
val userTechCountOptional = db.techCount.findByUserAndLevelId(u, levelId)
|
|
||||||
val userTechCount = userTechCountOptional.orElseGet { UserTechCount().apply { user = u } }
|
|
||||||
|
|
||||||
newUserTechCount.id = userTechCount.id
|
|
||||||
newUserTechCount.user = userTechCount.user
|
|
||||||
newUserTechCountList.add(newUserTechCount)
|
|
||||||
}
|
|
||||||
db.techCount.saveAll(newUserTechCountList)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserScenarioList
|
|
||||||
val userScenarioList = all.userScenarioList
|
|
||||||
if (userScenarioList != null) {
|
|
||||||
val newUserScenarioList: MutableList<UserScenario> = ArrayList()
|
|
||||||
for (newUserScenario in userScenarioList) {
|
|
||||||
val scenarioId = newUserScenario.scenarioId
|
|
||||||
|
|
||||||
val userScenarioOptional = db.scenario.findByUserAndScenarioId(u, scenarioId)
|
|
||||||
val userScenario = userScenarioOptional.orElseGet { UserScenario().apply { user = u } }
|
|
||||||
|
|
||||||
newUserScenario.id = userScenario.id
|
|
||||||
newUserScenario.user = userScenario.user
|
|
||||||
newUserScenarioList.add(newUserScenario)
|
|
||||||
}
|
|
||||||
db.scenario.saveAll(newUserScenarioList)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserTradeItemList
|
|
||||||
val userTradeItemList = all.userTradeItemList
|
|
||||||
val newUserTradeItemList: MutableList<UserTradeItem> = ArrayList()
|
|
||||||
|
|
||||||
if (userTradeItemList != null) {
|
|
||||||
for (newUserTradeItem in userTradeItemList) {
|
|
||||||
val chapterId = newUserTradeItem.chapterId
|
|
||||||
val tradeItemId = newUserTradeItem.tradeItemId
|
|
||||||
|
|
||||||
val tradeItemOptional =
|
|
||||||
db.tradeItem.findByUserAndChapterIdAndTradeItemId(u, chapterId, tradeItemId)
|
|
||||||
val userTradeItem = tradeItemOptional.orElseGet { UserTradeItem().apply { user = u } }
|
|
||||||
|
|
||||||
newUserTradeItem.id = userTradeItem.id
|
|
||||||
newUserTradeItem.user = u
|
|
||||||
newUserTradeItemList.add(newUserTradeItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.tradeItem.saveAll(newUserTradeItemList)
|
|
||||||
|
|
||||||
// UserEventMusicList
|
|
||||||
val userEventMusicList = all.userEventMusicList
|
|
||||||
val newUserEventMusicList: MutableList<UserEventMusic> = ArrayList()
|
|
||||||
|
|
||||||
if (userEventMusicList != null) {
|
|
||||||
for (newUserEventMusic in userEventMusicList) {
|
|
||||||
val eventId = newUserEventMusic.eventId
|
|
||||||
val type = newUserEventMusic.type
|
|
||||||
val musicId = newUserEventMusic.musicId
|
|
||||||
|
|
||||||
val eventMusicOptional =
|
|
||||||
db.eventMusic.findByUserAndEventIdAndTypeAndMusicId(u, eventId, type, musicId)
|
|
||||||
val userEventMusic = eventMusicOptional.orElseGet { UserEventMusic().apply { user = u } }
|
|
||||||
|
|
||||||
newUserEventMusic.id = userEventMusic.id
|
|
||||||
newUserEventMusic.user = u
|
|
||||||
newUserEventMusicList.add(newUserEventMusic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.eventMusic.saveAll(newUserEventMusicList)
|
|
||||||
|
|
||||||
// UserTechEventList
|
|
||||||
val userTechEventList = all.userTechEventList
|
|
||||||
val newUserTechEventList: MutableList<UserTechEvent> = ArrayList()
|
|
||||||
|
|
||||||
if (userTechEventList != null) {
|
|
||||||
for (newUserTechEvent in userTechEventList) {
|
|
||||||
val eventId = newUserTechEvent.eventId
|
|
||||||
|
|
||||||
val techEventOptional = db.techEvent.findByUserAndEventId(u, eventId)
|
|
||||||
val userTechEvent = techEventOptional.orElseGet { UserTechEvent().apply { user = u } }
|
|
||||||
|
|
||||||
newUserTechEvent.id = userTechEvent.id
|
|
||||||
newUserTechEvent.user = u
|
|
||||||
newUserTechEventList.add(newUserTechEvent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.techEvent.saveAll(newUserTechEventList)
|
|
||||||
|
|
||||||
// UserKopList
|
|
||||||
val userKopList = all.userKopList
|
|
||||||
val newUserKopList: MutableList<UserKop> = ArrayList()
|
|
||||||
|
|
||||||
if (userKopList != null) {
|
|
||||||
for (newUserKop in userKopList) {
|
|
||||||
val kopId = newUserKop.kopId
|
|
||||||
val areaId = newUserKop.areaId
|
|
||||||
|
|
||||||
val kopOptional = db.kop.findByUserAndKopIdAndAreaId(u, kopId, areaId)
|
|
||||||
val userKop = kopOptional.orElseGet { UserKop().apply { user = u } }
|
|
||||||
|
|
||||||
newUserKop.id = userKop.id
|
|
||||||
newUserKop.user = u
|
|
||||||
newUserKopList.add(newUserKop)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.kop.saveAll(newUserKopList)
|
|
||||||
|
|
||||||
// UserEventMap
|
|
||||||
val newUserEventMap = all.userEventMap
|
|
||||||
if (newUserEventMap != null) {
|
|
||||||
val userEventOptional = db.eventMap.findSingleByUser(u)
|
|
||||||
val userEventMap: UserEventMap = userEventOptional.orElseGet { UserEventMap().apply { user = u } }
|
|
||||||
|
|
||||||
newUserEventMap.id = userEventMap.id
|
|
||||||
newUserEventMap.user = u
|
|
||||||
db.eventMap.save(newUserEventMap)
|
|
||||||
}
|
|
||||||
|
|
||||||
val json = mapper.write(CodeResp(1, "upsertUserAll"))
|
|
||||||
logger.info("Response: $json")
|
|
||||||
return json
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun saveRecentRatingData(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.isNotEmpty()) { sb.deleteCharAt(sb.length - 1) }
|
|
||||||
saveGeneralData(newUserData, key, sb.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun saveFumenScoreData(itemList: List<OngekiFumenScore>, newUserData: UserData, key: String) {
|
|
||||||
val sb = StringBuilder()
|
|
||||||
for (item in itemList) {
|
|
||||||
sb.append(item.musicId).append(":")
|
|
||||||
.append(item.difficultId).append(":")
|
|
||||||
.append(item.score).append(":")
|
|
||||||
.append(item.platinumScoreStar).append(":")
|
|
||||||
.append(item.platinumScoreMax)
|
|
||||||
sb.append(",")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sb.isNotEmpty()) { sb.deleteCharAt(sb.length - 1) }
|
|
||||||
saveGeneralData(newUserData, key, sb.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun saveGeneralData(newUserData: UserData, key: String, data: String) {
|
|
||||||
val uOptional = db.generalData.findByUserAndPropertyKey(newUserData, key)
|
|
||||||
val userGeneralData = uOptional.orElseGet {
|
|
||||||
UserGeneralData().apply {
|
|
||||||
user = newUserData
|
|
||||||
propertyKey = key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userGeneralData.propertyValue = data
|
|
||||||
db.generalData.save(userGeneralData)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val logger = logger()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue