mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-12 12:17:26 +08:00
[O] Refactor code
This commit is contained in:
@@ -1,70 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.general.service;
|
|
||||||
|
|
||||||
import icu.samnyan.aqua.sega.general.dao.CardRepository;
|
|
||||||
import icu.samnyan.aqua.sega.general.model.Card;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class CardService {
|
|
||||||
|
|
||||||
private final CardRepository cardRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public CardService(CardRepository cardRepository) {
|
|
||||||
this.cardRepository = cardRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a card by External Id
|
|
||||||
* @param extId External Id
|
|
||||||
* @return Optional of a Card
|
|
||||||
*/
|
|
||||||
public Optional<Card> getCardByExtId(String extId) {
|
|
||||||
return cardRepository.findByExtId(Long.parseLong(extId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a card by External Id
|
|
||||||
*
|
|
||||||
* @param extId External Id
|
|
||||||
* @return Optional of a Card
|
|
||||||
*/
|
|
||||||
public Optional<Card> getCardByExtId(Long extId) {
|
|
||||||
return cardRepository.findByExtId(extId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find a card by it's access code
|
|
||||||
* @param accessCode String represent of a access code
|
|
||||||
* @return Optional of a Card
|
|
||||||
*/
|
|
||||||
public Optional<Card> getCardByAccessCode(String accessCode) {
|
|
||||||
return cardRepository.findByLuid(accessCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new card with access code
|
|
||||||
* @param accessCode String represent of a access code
|
|
||||||
* @return a new registered Card
|
|
||||||
*/
|
|
||||||
public Card registerByAccessCode(String accessCode) {
|
|
||||||
Card card = new Card();
|
|
||||||
card.setLuid(accessCode);
|
|
||||||
long extId = ThreadLocalRandom.current().nextLong(99999999);
|
|
||||||
while (cardRepository.findByExtId(extId).isPresent()) {
|
|
||||||
extId = ThreadLocalRandom.current().nextLong(99999999);
|
|
||||||
}
|
|
||||||
card.setExtId(extId);
|
|
||||||
card.setRegisterTime(LocalDateTime.now());
|
|
||||||
card.setAccessTime(LocalDateTime.now());
|
|
||||||
return cardRepository.save(card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package icu.samnyan.aqua.sega.general.service
|
||||||
|
|
||||||
|
import icu.samnyan.aqua.sega.general.dao.CardRepository
|
||||||
|
import icu.samnyan.aqua.sega.general.model.Card
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.util.*
|
||||||
|
import java.util.concurrent.ThreadLocalRandom
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
class CardService(val cardRepo: CardRepository) {
|
||||||
|
/**
|
||||||
|
* Find a card by External Id
|
||||||
|
* @param extId External Id
|
||||||
|
* @return Optional of a Card
|
||||||
|
*/
|
||||||
|
fun getCardByExtId(extId: String): Optional<Card> = cardRepo.findByExtId(extId.toLong())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a card by External Id
|
||||||
|
*
|
||||||
|
* @param extId External Id
|
||||||
|
* @return Optional of a Card
|
||||||
|
*/
|
||||||
|
fun getCardByExtId(extId: Long?): Optional<Card> = cardRepo.findByExtId(extId)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a card by it's access code
|
||||||
|
* @param accessCode String represent of a access code
|
||||||
|
* @return Optional of a Card
|
||||||
|
*/
|
||||||
|
fun getCardByAccessCode(accessCode: String?): Optional<Card> = cardRepo.findByLuid(accessCode)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new card with access code
|
||||||
|
* @param accessCode String represent of a access code
|
||||||
|
* @return a new registered Card
|
||||||
|
*/
|
||||||
|
fun registerByAccessCode(accessCode: String?): Card {
|
||||||
|
val card = Card()
|
||||||
|
card.luid = accessCode
|
||||||
|
var extId = ThreadLocalRandom.current().nextLong(99999999)
|
||||||
|
while (cardRepo.findByExtId(extId).isPresent) {
|
||||||
|
extId = ThreadLocalRandom.current().nextLong(99999999)
|
||||||
|
}
|
||||||
|
card.extId = extId
|
||||||
|
card.registerTime = LocalDateTime.now()
|
||||||
|
card.accessTime = LocalDateTime.now()
|
||||||
|
return cardRepo.save(card)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package icu.samnyan.aqua.sega.maimai2.controller;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.handler.impl.*;
|
import icu.samnyan.aqua.sega.maimai2.handler.impl.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -10,6 +11,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
*/
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping({ "/Maimai2Servlet/Maimai2Servlet", "/Maimai2Servlet" })
|
@RequestMapping({ "/Maimai2Servlet/Maimai2Servlet", "/Maimai2Servlet" })
|
||||||
public class Maimai2ServletController {
|
public class Maimai2ServletController {
|
||||||
@@ -57,93 +59,6 @@ public class Maimai2ServletController {
|
|||||||
private final GetUserRivalDataHandler getUserRivalDataHandler;
|
private final GetUserRivalDataHandler getUserRivalDataHandler;
|
||||||
private final GetUserRivalMusicHandler getUserRivalMusicHandler;
|
private final GetUserRivalMusicHandler getUserRivalMusicHandler;
|
||||||
|
|
||||||
public Maimai2ServletController(
|
|
||||||
GetGameSettingHandler getGameSettingHandler,
|
|
||||||
GetGameEventHandler getGameEventHandler,
|
|
||||||
GetGameRankingHandler getGameRankingHandler,
|
|
||||||
GetGameTournamentInfoHandler getGameTournamentInfoHandler,
|
|
||||||
GetTransferFriendHandler getTransferFriendHandler,
|
|
||||||
GetUserActivityHandler getUserActivityHandler,
|
|
||||||
UserLoginHandler userLoginHandler,
|
|
||||||
UserLogoutHandler userLogoutHandler,
|
|
||||||
GetUserDataHandler getUserDataHandler,
|
|
||||||
UpsertUserAllHandler upsertUserAllHandler,
|
|
||||||
GetUserPreviewHandler getUserPreviewHandler,
|
|
||||||
GetUserCharacterHandler getUserCharacterHandler,
|
|
||||||
GetUserOptionHandler getUserOptionHandler,
|
|
||||||
GetUserItemHandler getUserItemHandler,
|
|
||||||
GetUserExtendHandler getUserExtendHandler,
|
|
||||||
GetUserGhostHandler getUserGhostHandler,
|
|
||||||
GetUserLoginBonusHandler getUserLoginBonusHandler,
|
|
||||||
GetUserMapHandler getUserMapHandler,
|
|
||||||
GetUserFavoriteHandler getUserFavoriteHandler,
|
|
||||||
GetUserCardHandler getUserCardHandler,
|
|
||||||
GetUserMusicHandler getUserMusicHandler,
|
|
||||||
GetUserRatingHandler getUserRatingHandler,
|
|
||||||
GetUserRegionHandler getUserRegionHandler,
|
|
||||||
GetGameChargeHandler getGameChargeHandler,
|
|
||||||
GetUserChargeHandler getUserChargeHandler,
|
|
||||||
GetUserCourseHandler getUserCourseHandler,
|
|
||||||
UploadUserPhotoHandler uploadUserPhotoHandler,
|
|
||||||
UploadUserPlaylogHandler uploadUserPlaylogHandler,
|
|
||||||
UploadUserPortraitHandler uploadUserPortraitHandler,
|
|
||||||
GetGameNgMusicIdHandler getGameNgMusicIdHandler,
|
|
||||||
GetUserPortraitHandler getUserPortraitHandler,
|
|
||||||
GetUserFriendSeasonRankingHandler getUserFriendSeasonRankingHandler,
|
|
||||||
CMGetUserPreviewHandler cmGetUserPreviewHandler,
|
|
||||||
CMGetSellingCardHandler cmGetSellingCardHandler,
|
|
||||||
GetUserCardPrintErrorHandler getUserCardPrintErrorHandler,
|
|
||||||
CMGetUserCharacterHandler cmGetUserCharacterHandler,
|
|
||||||
UpsertUserPrintHandler upsertUserPrintHandler,
|
|
||||||
GetUserRecommendRateMusicHandler getUserRecommendRateMusicHandler,
|
|
||||||
GetUserRecommendSelectMusicHandler getUserRecommendSelectMusicHandler,
|
|
||||||
GetUserFavoriteItemHandler getUserFavoriteItemHandler,
|
|
||||||
GetUserRivalDataHandler getUserRivalDataHandler,
|
|
||||||
GetUserRivalMusicHandler getUserRivalMusicHandler) {
|
|
||||||
this.getGameSettingHandler = getGameSettingHandler;
|
|
||||||
this.getGameEventHandler = getGameEventHandler;
|
|
||||||
this.getGameRankingHandler = getGameRankingHandler;
|
|
||||||
this.getGameTournamentInfoHandler = getGameTournamentInfoHandler;
|
|
||||||
this.getTransferFriendHandler = getTransferFriendHandler;
|
|
||||||
this.getUserActivityHandler = getUserActivityHandler;
|
|
||||||
this.userLoginHandler = userLoginHandler;
|
|
||||||
this.userLogoutHandler = userLogoutHandler;
|
|
||||||
this.getUserDataHandler = getUserDataHandler;
|
|
||||||
this.upsertUserAllHandler = upsertUserAllHandler;
|
|
||||||
this.getUserPreviewHandler = getUserPreviewHandler;
|
|
||||||
this.getUserCharacterHandler = getUserCharacterHandler;
|
|
||||||
this.getUserOptionHandler = getUserOptionHandler;
|
|
||||||
this.getUserItemHandler = getUserItemHandler;
|
|
||||||
this.getUserExtendHandler = getUserExtendHandler;
|
|
||||||
this.getUserGhostHandler = getUserGhostHandler;
|
|
||||||
this.getUserLoginBonusHandler = getUserLoginBonusHandler;
|
|
||||||
this.getUserMapHandler = getUserMapHandler;
|
|
||||||
this.getUserFavoriteHandler = getUserFavoriteHandler;
|
|
||||||
this.getUserCardHandler = getUserCardHandler;
|
|
||||||
this.getUserMusicHandler = getUserMusicHandler;
|
|
||||||
this.getUserRatingHandler = getUserRatingHandler;
|
|
||||||
this.getUserRegionHandler = getUserRegionHandler;
|
|
||||||
this.getGameChargeHandler = getGameChargeHandler;
|
|
||||||
this.getUserChargeHandler = getUserChargeHandler;
|
|
||||||
this.getUserCourseHandler = getUserCourseHandler;
|
|
||||||
this.uploadUserPhotoHandler = uploadUserPhotoHandler;
|
|
||||||
this.uploadUserPlaylogHandler = uploadUserPlaylogHandler;
|
|
||||||
this.getGameNgMusicIdHandler = getGameNgMusicIdHandler;
|
|
||||||
this.getUserFriendSeasonRankingHandler = getUserFriendSeasonRankingHandler;
|
|
||||||
this.getUserPortraitHandler = getUserPortraitHandler;
|
|
||||||
this.uploadUserPortraitHandler = uploadUserPortraitHandler;
|
|
||||||
this.cmGetUserPreviewHandler = cmGetUserPreviewHandler;
|
|
||||||
this.cmGetSellingCardHandler = cmGetSellingCardHandler;
|
|
||||||
this.getUserCardPrintErrorHandler = getUserCardPrintErrorHandler;
|
|
||||||
this.cmGetUserCharacterHandler = cmGetUserCharacterHandler;
|
|
||||||
this.upsertUserPrintHandler = upsertUserPrintHandler;
|
|
||||||
this.getUserRecommendRateMusicHandler = getUserRecommendRateMusicHandler;
|
|
||||||
this.getUserRecommendSelectMusicHandler = getUserRecommendSelectMusicHandler;
|
|
||||||
this.getUserFavoriteItemHandler = getUserFavoriteItemHandler;
|
|
||||||
this.getUserRivalDataHandler = getUserRivalDataHandler;
|
|
||||||
this.getUserRivalMusicHandler = getUserRivalMusicHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mandatory for boot
|
// Mandatory for boot
|
||||||
@PostMapping("GetGameEventApi")
|
@PostMapping("GetGameEventApi")
|
||||||
public String getGameEvent(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
|
public String getGameEvent(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
|
||||||
|
|||||||
Reference in New Issue
Block a user