From 4328ca32807a20496c1bcf0ccafd267718672907 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Fri, 17 Jan 2025 08:19:04 -0500 Subject: [PATCH] [+] Insert Kaleidx on upsert --- src/main/java/ext/Ext.kt | 2 ++ .../aqua/sega/maimai2/handler/UpsertUserAllHandler.kt | 6 ++++++ src/main/java/icu/samnyan/aqua/sega/maimai2/model/Repos.kt | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/src/main/java/ext/Ext.kt b/src/main/java/ext/Ext.kt index c4f24d5e..2c3c28d1 100644 --- a/src/main/java/ext/Ext.kt +++ b/src/main/java/ext/Ext.kt @@ -208,6 +208,8 @@ val List.mut get() = toMutableList() val Map.mut get() = toMutableMap() val Set.mut get() = toMutableSet() +fun List.unique(fn: (T) -> Any) = distinctBy(fn).ifEmpty { null } + // Optionals operator fun Optional.invoke(): T? = orElse(null) fun Optional.expect(message: Str = "Value is not present") = orElseGet { (400 - message) } diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/UpsertUserAllHandler.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/UpsertUserAllHandler.kt index 8fd42c47..b3ee05ef 100644 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/UpsertUserAllHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/UpsertUserAllHandler.kt @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException import ext.invoke import ext.mapApply import ext.minus +import ext.unique import icu.samnyan.aqua.sega.general.BaseHandler import icu.samnyan.aqua.sega.general.service.CardService import icu.samnyan.aqua.sega.maimai2.handler.UploadUserPlaylogHandler.Companion.playBacklog @@ -127,6 +128,11 @@ class UpsertUserAllHandler( repos.userFavorite.saveAll(news.mapApply { id = repos.userFavorite.findByUserAndItemKind(u, itemKind)()?.id ?: 0 }) } + // Added on 1.50 + req.userKaleidxScopeList?.unique { it.gateId }?.let { lst -> + repos.userKaleidx.saveAll(lst.mapApply { + id = repos.userKaleidx.findByUserAndGateId(u, gateId)?.id ?: 0 }) } + // 2024/10/31 Found some user data findByUserAndKindAndActivityId is not unique // I think userActivityList is not important, so I will ignore it try { diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/model/Repos.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/model/Repos.kt index 84371be5..1e3115c1 100644 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/model/Repos.kt +++ b/src/main/java/icu/samnyan/aqua/sega/maimai2/model/Repos.kt @@ -109,6 +109,10 @@ interface Mai2UserPrintDetailRepo : JpaRepository interface Mai2UserUdemaeRepo : Mai2UserLinked +interface MAi2UserKaleidxRepo : Mai2UserLinked { + fun findByUserAndGateId(user: Mai2UserDetail, gateId: Int): Mai2UserKaleidx? +} + interface Mai2GameChargeRepo : JpaRepository interface Mai2GameEventRepo : JpaRepository { @@ -138,6 +142,7 @@ class Mai2Repos( val userPlaylog: Mai2UserPlaylogRepo, val userPrintDetail: Mai2UserPrintDetailRepo, val userUdemae: Mai2UserUdemaeRepo, + val userKaleidx: MAi2UserKaleidxRepo, val gameCharge: Mai2GameChargeRepo, val gameEvent: Mai2GameEventRepo, val gameSellingCard: Mai2GameSellingCardRepo