[-] BaseHandler

This commit is contained in:
Azalea 2025-10-25 07:31:17 +08:00
parent 8d48ab0d3f
commit 419e22cc49
33 changed files with 39 additions and 56 deletions

View File

@ -1,5 +1,6 @@
package icu.samnyan.aqua.sega.diva
import ext.JDict
import ext.MutJDict
import ext.logger
import icu.samnyan.aqua.sega.diva.handler.AttendHandler
@ -84,6 +85,10 @@ class DivaController(
val logger = logger()
val mapper = DivaMapper()
fun buildResultMap(map: JDict) =
map.filterValues { it != null && !(it is String && it == "") }
.map { (k, v) -> "$k=$v" }.joinToString("&")
@PostMapping(value = ["/"], consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE])
fun formRequest(request: HttpServletRequest): String? {
val bodyStr = String(request.inputStream.readAllBytes())

View File

@ -1,20 +0,0 @@
package icu.samnyan.aqua.sega.diva.handler
import ext.JDict
import icu.samnyan.aqua.sega.diva.util.DivaMapper
import org.springframework.stereotype.Component
fun buildResultMap(map: JDict) =
map.filterValues { it != null && !(it is String && it == "") }
.map { (k, v) -> "$k=$v" }.joinToString("&")
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BaseHandler {
@JvmField
final var mapper = DivaMapper()
fun build(map: JDict) = buildResultMap(map)
}

View File

@ -1,6 +1,5 @@
package icu.samnyan.aqua.sega.diva.handler
import ext.logger
import icu.samnyan.aqua.sega.diva.model.common.attend.DispersalParameter
import icu.samnyan.aqua.sega.diva.model.common.attend.EtcParameter
import icu.samnyan.aqua.sega.diva.model.common.attend.GameBalanceParameter
@ -41,9 +40,7 @@ class AttendHandler {
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PingHandler(val rp: PropertyEntryRepository) : BaseHandler() {
val logger = logger()
class PingHandler(val rp: PropertyEntryRepository) {
fun handle(request: BaseRequest): Any {
val news: PropertyEntry = rp.findByPropertyKey("diva_news") ?: PropertyEntry("diva_news", "xxx")
val warning: PropertyEntry = rp.findByPropertyKey("diva_warning") ?: PropertyEntry("diva_warning", "xxx")

View File

@ -10,7 +10,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BannerDataHandler : BaseHandler() {
class BannerDataHandler {
fun handle(request: BannerDataRequest) = BannerDataResponse(
request.cmd,
request.req_id,

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BannerInfoHandler : BaseHandler() {
class BannerInfoHandler {
fun handle(request: BaseRequest) = BannerInfoResponse(
request.cmd,
request.req_id,

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class CmPlyInfoHandler : BaseHandler() {
class CmPlyInfoHandler {
fun handle(request: BaseRequest) = BaseResponse(
request.cmd,
request.req_id,

View File

@ -15,7 +15,7 @@ import kotlin.math.max
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ContestInfoHandler(private val contestRepository: ContestRepository) : BaseHandler() {
class ContestInfoHandler(private val contestRepository: ContestRepository) {
fun handle(request: BaseRequest): Any {
val contestList = contestRepository.findTop8ByEnable(true)
var ci_str = "***"

View File

@ -13,7 +13,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class CstmzItmCtlgHandler(private val customizeRepository: DivaCustomizeRepository) : BaseHandler() {
class CstmzItmCtlgHandler(private val customizeRepository: DivaCustomizeRepository) {
fun handle(request: BaseRequest): Any {
val customizeList = customizeRepository.findAll()

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class CstmzItmNgMdlListHandler : BaseHandler() {
class CstmzItmNgMdlListHandler {
fun handle(request: BaseRequest) = CstmzItmNgMdlListResponse(
request.cmd,
request.req_id,

View File

@ -11,7 +11,7 @@ import org.springframework.stereotype.Component
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class FestaInfoHandler(private val festaRepository: FestaRepository) : BaseHandler() {
class FestaInfoHandler(private val festaRepository: FestaRepository) {
fun handle(request: BaseRequest): Any {
val festaList = festaRepository.findTop2ByEnableOrderByCreateDateDesc(true)
val collection = FestaCollection(festaList)

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class NgWordHandler : BaseHandler() {
class NgWordHandler {
fun handle(request: BaseRequest) = BaseResponse(
request.cmd,
request.req_id,

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Component
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class NvRankingHandler : BaseHandler() {
class NvRankingHandler {
fun handle(request: BaseRequest) = NvRankingResponse(
request.cmd,
request.req_id,

View File

@ -17,7 +17,7 @@ import java.util.stream.Collectors
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PsRankingHandler(private val playerPvRecordRepository: PlayerPvRecordRepository) : BaseHandler() {
class PsRankingHandler(private val playerPvRecordRepository: PlayerPvRecordRepository) {
fun handle(request: PsRankingRequest): Any {
var edition = Edition.ORIGINAL
var difficulty = Difficulty.HARD

View File

@ -13,7 +13,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PstdHCtrlHandler : BaseHandler() {
class PstdHCtrlHandler {
fun handle(request: BaseRequest) = PstdHCtrlResponse(
request.cmd,
request.req_id,

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PstdItemNgLstHandler : BaseHandler() {
class PstdItemNgLstHandler {
fun handle(request: BaseRequest) = PstdItemNgLstResponse(
request.cmd,
request.req_id,

View File

@ -13,7 +13,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PvDefChrLstHandler : BaseHandler() {
class PvDefChrLstHandler {
fun handle(request: BaseRequest) = PvDefChrLstResponse(
request.cmd,
request.req_id,

View File

@ -16,7 +16,7 @@ import java.util.function.Consumer
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PvListHandler(private val pvEntryRepository: PvEntryRepository) : BaseHandler() {
class PvListHandler(private val pvEntryRepository: PvEntryRepository) {
private val df: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
fun handle(request: BaseRequest): Any {

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PvNgMdlLstHandler : BaseHandler() {
class PvNgMdlLstHandler {
fun handle(request: BaseRequest) = PvNgMdlLstResponse(
request.cmd,
request.req_id,

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class QstInfHandler : BaseHandler() {
class QstInfHandler {
fun handle(request: BaseRequest) = QstInfResponse(
request.cmd,
request.req_id,

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class RmtWpLstHandler : BaseHandler() {
class RmtWpLstHandler {
fun handle(request: BaseRequest) = RmtWpLstResponse(
request.cmd,
request.req_id,

View File

@ -12,7 +12,7 @@ import java.time.LocalDateTime
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ShopCatalogHandler(private val moduleRepository: DivaModuleRepository) : BaseHandler() {
class ShopCatalogHandler(private val moduleRepository: DivaModuleRepository) {
fun handle(request: BaseRequest): Any {
val moduleList = moduleRepository.findAll()

View File

@ -23,7 +23,7 @@ class BuyCstmzItmHandler(
private val playerProfileService: PlayerProfileService,
private val playerCustomizeService: PlayerCustomizeService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
) {
fun handle(request: BuyCstmzItmRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow(
Supplier { ProfileNotFoundException() })

View File

@ -23,7 +23,7 @@ class BuyModuleHandler(
private val playerProfileService: PlayerProfileService,
private val playerModuleService: PlayerModuleService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
) {
fun handle(request: BuyModuleRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })

View File

@ -24,7 +24,7 @@ class GetPvPdHandler(
private val pvRecordRepository: PlayerPvRecordRepository,
private val pvCustomizeRepository: PlayerPvCustomizeRepository,
private val playerProfileService: PlayerProfileService
) : BaseHandler() {
) {
fun handle(request: GetPvPdRequest): Any {
val profileO = playerProfileService.findByPdId(request.pd_id)
val pd = StringBuilder()

View File

@ -19,7 +19,7 @@ import java.util.function.Supplier
class ShopExitHandler(
private val playerProfileService: PlayerProfileService,
private val pvCustomizeRepository: PlayerPvCustomizeRepository
) : BaseHandler() {
) {
fun handle(request: ShopExitRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })

View File

@ -44,7 +44,7 @@ class StageResultHandler(
private val playerCustomizeRepository: PlayerCustomizeRepository,
private val playerInventoryRepository: PlayerInventoryRepository,
private val divaCalculator: DivaCalculator
) : BaseHandler() {
) {
private var currentProfile: PlayerProfile? = null
val logger = logger()

View File

@ -18,7 +18,7 @@ import java.util.function.Supplier
class StageStartHandler(
private val gameSessionRepository: GameSessionRepository,
private val playerProfileService: PlayerProfileService
) : BaseHandler() {
) {
fun handle(request: StageStartRequest): Any {
if (request.getPd_id() != -1L) {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(

View File

@ -25,7 +25,7 @@ import java.util.function.Supplier
class StoreSsHandler(
private val playerProfileService: PlayerProfileService,
private val screenShotRepository: PlayerScreenShotRepository
) : BaseHandler() {
) {
val logger = logger()
fun handle(request: StoreSsRequest, file: MultipartFile): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(

View File

@ -33,7 +33,7 @@ class EndHandler(
private val playerProfileService: PlayerProfileService,
private val playerContestRepository: PlayerContestRepository,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
) {
fun handle(request: StageResultRequest): Any {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })

View File

@ -17,7 +17,7 @@ import java.util.function.Supplier
class PdUnlockHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
) {
fun handle(request: PdUnlockRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })

View File

@ -20,7 +20,7 @@ import java.util.concurrent.ThreadLocalRandom
class PreStartHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository
) : BaseHandler() {
) {
var logger = logger()
fun handle(request: PreStartRequest): Any {
val profileOptional = playerProfileService.findByPdId(request.aime_id)

View File

@ -12,7 +12,7 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class SpendCreditHandler(private val playerProfileService: PlayerProfileService) : BaseHandler() {
class SpendCreditHandler(private val playerProfileService: PlayerProfileService) {
fun handle(request: SpendCreditRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })

View File

@ -1,7 +1,8 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.*
import icu.samnyan.aqua.sega.diva.handler.BaseHandler
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.PlayerContestRepository
import icu.samnyan.aqua.sega.diva.PlayerPvRecordRepository
import icu.samnyan.aqua.sega.diva.model.common.*
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearSet
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearTally
@ -35,7 +36,7 @@ class StartHandler(
private val playerModuleService: PlayerModuleService,
private val playerPvRecordRepository: PlayerPvRecordRepository,
private val playerContestRepository: PlayerContestRepository
) : BaseHandler() {
) {
fun handle(request: StartRequest): Any {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException>(
Supplier { ProfileNotFoundException() })