add mai2 fields

This commit is contained in:
Menci 2025-06-25 02:12:03 +08:00 committed by Azalea
parent 5c1f659437
commit ac6cbb9dd3
2 changed files with 51 additions and 18 deletions

View File

@ -58,7 +58,8 @@ abstract class ImportController<ExportModel: IExportClass<UserModel>, UserModel:
val exportFields: Map<String, Var<ExportModel, Any>>, val exportFields: Map<String, Var<ExportModel, Any>>,
val exportRepos: Map<Var<ExportModel, Any>, IUserRepo<UserModel, *>>, val exportRepos: Map<Var<ExportModel, Any>, IUserRepo<UserModel, *>>,
val artemisRenames: Map<String, ImportClass<*>>, val artemisRenames: Map<String, ImportClass<*>>,
val customExporters: Map<Var<ExportModel, Any>, (UserModel, ExportOptions) -> Any?> = emptyMap() val customExporters: Map<Var<ExportModel, Any>, (UserModel, ExportOptions) -> Any?> = emptyMap(),
val customImporters: Map<Var<ExportModel, Any>, (ExportModel, UserModel) -> Unit> = emptyMap()
) { ) {
abstract fun createEmpty(): ExportModel abstract fun createEmpty(): ExportModel
abstract val userDataRepo: GenericUserDataRepo<UserModel> abstract val userDataRepo: GenericUserDataRepo<UserModel>
@ -105,8 +106,8 @@ abstract class ImportController<ExportModel: IExportClass<UserModel>, UserModel:
val export = json.parseJackson(exportClass.java) val export = json.parseJackson(exportClass.java)
if (!export.gameId.equals(game, true)) 400 - "Invalid game ID" if (!export.gameId.equals(game, true)) 400 - "Invalid game ID"
val lists = listRepos.toList().associate { (f, r) -> r to f.get(export) as List<IUserEntity<UserModel>> }.vNotNull() val lists = listRepos.toList().filter { (f, _) -> f !in customImporters }.associate { (f, r) -> r to f.get(export) as List<IUserEntity<UserModel>> }.vNotNull()
val singles = singleRepos.toList().associate { (f, r) -> r to f.get(export) as IUserEntity<UserModel> }.vNotNull() val singles = singleRepos.toList().filter { (f, _) -> f !in customImporters }.associate { (f, r) -> r to f.get(export) as IUserEntity<UserModel> }.vNotNull()
// Validate new user data // Validate new user data
// Check that all ids are 0 (this should be true since all ids are @JsonIgnore) // Check that all ids are 0 (this should be true since all ids are @JsonIgnore)
@ -138,6 +139,10 @@ abstract class ImportController<ExportModel: IExportClass<UserModel>, UserModel:
// Save new data // Save new data
singles.forEach { (repo, single) -> (repo as IUserRepo<UserModel, Any>).save(single) } singles.forEach { (repo, single) -> (repo as IUserRepo<UserModel, Any>).save(single) }
lists.forEach { (repo, list) -> (repo as IUserRepo<UserModel, Any>).saveAll(list) } lists.forEach { (repo, list) -> (repo as IUserRepo<UserModel, Any>).saveAll(list) }
// Handle custom importers
customImporters.forEach { (field, importer) ->
importer(export, nu)
}
} }
SUCCESS SUCCESS

View File

@ -9,6 +9,7 @@ import icu.samnyan.aqua.net.games.ImportClass
import icu.samnyan.aqua.net.games.ImportController import icu.samnyan.aqua.net.games.ImportController
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserLinked import icu.samnyan.aqua.sega.maimai2.model.Mai2UserLinked
import icu.samnyan.aqua.sega.maimai2.model.request.Mai2UserFavoriteItem
import icu.samnyan.aqua.sega.maimai2.model.userdata.* import icu.samnyan.aqua.sega.maimai2.model.userdata.*
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
import kotlin.reflect.full.declaredMembers import kotlin.reflect.full.declaredMembers
@ -24,10 +25,15 @@ class Mai2Import(
}, },
exportRepos = Maimai2DataExport::class.vars() exportRepos = Maimai2DataExport::class.vars()
.filter { f -> f.name !in setOf("gameId", "userData") } .filter { f -> f.name !in setOf("gameId", "userData") }
.associateWith { Mai2Repos::class.declaredMembers .associateWith { field ->
.filter { f -> f returns Mai2UserLinked::class } val repoName = when (field.name) {
.firstOrNull { f -> f.name == it.name || f.name == it.name.replace("List", "") } "userKaleidxScopeList" -> "userKaleidx"
?.call(repos) as Mai2UserLinked<*>? ?: error("No matching field found for ${it.name}") else -> field.name.replace("List", "")
}
Mai2Repos::class.declaredMembers
.filter { f -> f returns Mai2UserLinked::class }
.firstOrNull { f -> f.name == repoName }
?.call(repos) as Mai2UserLinked<*>? ?: error("No matching field found for ${field.name}")
}, },
artemisRenames = mapOf( artemisRenames = mapOf(
"mai2_item_character" to ImportClass(Mai2UserCharacter::class), "mai2_item_character" to ImportClass(Mai2UserCharacter::class),
@ -46,17 +52,36 @@ class Mai2Import(
"mai2_score_best" to ImportClass(Mai2UserMusicDetail::class), "mai2_score_best" to ImportClass(Mai2UserMusicDetail::class),
"mai2_score_course" to ImportClass(Mai2UserCourse::class), "mai2_score_course" to ImportClass(Mai2UserCourse::class),
), ),
customExporters = run { customExporters = mapOf(
mapOf( Maimai2DataExport::userPlaylogList to { user: Mai2UserDetail, options: ExportOptions ->
Maimai2DataExport::userPlaylogList to { user: Mai2UserDetail, options: ExportOptions -> if (options.playlogSince != null) {
if (options.playlogSince != null) { repos.userPlaylog.findByUserAndUserPlayDateAfter(user, options.playlogSince)
repos.userPlaylog.findByUserAndUserPlayDateAfter(user, options.playlogSince) } else {
} else { repos.userPlaylog.findByUser(user)
repos.userPlaylog.findByUser(user)
}
} }
) as Map<kotlin.reflect.KMutableProperty1<Maimai2DataExport, Any>, (Mai2UserDetail, ExportOptions) -> Any?> },
} Maimai2DataExport::userFavoriteMusicList to { user: Mai2UserDetail, _: ExportOptions ->
repos.userGeneralData.findByUserAndPropertyKey(user, "favorite_music").orElse(null)
?.propertyValue
?.takeIf { it.isNotEmpty() }
?.split(",")
?.mapIndexed { index, id -> Mai2UserFavoriteItem().apply { orderId = index; this.id = id.toInt() } }
?: emptyList()
}
) as Map<kotlin.reflect.KMutableProperty1<Maimai2DataExport, Any>, (Mai2UserDetail, ExportOptions) -> Any?>,
customImporters = mapOf(
Maimai2DataExport::userFavoriteMusicList to { export: Maimai2DataExport, user: Mai2UserDetail ->
val favoriteMusicList = export.userFavoriteMusicList
if (favoriteMusicList.isNotEmpty()) {
val key = "favorite_music"
val data = repos.userGeneralData.findByUserAndPropertyKey(user, key).orElse(null)
?: Mai2UserGeneralData().apply { this.user = user; propertyKey = key }
repos.userGeneralData.save(data.apply {
propertyValue = favoriteMusicList.map { it.id }.joinToString(",")
})
}
}
) as Map<kotlin.reflect.KMutableProperty1<Maimai2DataExport, Any>, (Maimai2DataExport, Mai2UserDetail) -> Unit>
) { ) {
override fun createEmpty() = Maimai2DataExport() override fun createEmpty() = Maimai2DataExport()
override val userDataRepo = repos.userData override val userDataRepo = repos.userData
@ -79,11 +104,14 @@ data class Maimai2DataExport(
var userLoginBonusList: List<Mai2UserLoginBonus>, var userLoginBonusList: List<Mai2UserLoginBonus>,
var userMapList: List<Mai2UserMap>, var userMapList: List<Mai2UserMap>,
var userMusicDetailList: List<Mai2UserMusicDetail>, var userMusicDetailList: List<Mai2UserMusicDetail>,
var userIntimateList: List<Mai2UserIntimate>,
var userFavoriteMusicList: List<Mai2UserFavoriteItem>,
var userKaleidxScopeList: List<Mai2UserKaleidx>,
var userPlaylogList: List<Mai2UserPlaylog>, var userPlaylogList: List<Mai2UserPlaylog>,
override var gameId: String = "SDEZ", override var gameId: String = "SDEZ",
): IExportClass<Mai2UserDetail> { ): IExportClass<Mai2UserDetail> {
constructor() : this(Mai2UserDetail(), Mai2UserExtend(), Mai2UserOption(), Mai2UserUdemae(), constructor() : this(Mai2UserDetail(), Mai2UserExtend(), Mai2UserOption(), Mai2UserUdemae(),
mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(),
mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf(),
mutableListOf()) mutableListOf(), mutableListOf(), mutableListOf(), mutableListOf())
} }