mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-10 17:37:27 +08:00
[M] Static endpoints
This commit is contained in:
@@ -3,14 +3,22 @@ package icu.samnyan.aqua.sega.chusan
|
|||||||
import ext.*
|
import ext.*
|
||||||
import icu.samnyan.aqua.net.utils.simpleDescribe
|
import icu.samnyan.aqua.net.utils.simpleDescribe
|
||||||
import icu.samnyan.aqua.sega.chusan.handler.*
|
import icu.samnyan.aqua.sega.chusan.handler.*
|
||||||
|
import icu.samnyan.aqua.sega.chusan.model.Chu3Repos
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
import icu.samnyan.aqua.sega.general.BaseHandler
|
||||||
|
import icu.samnyan.aqua.sega.maimai2.handler.UserReqHandler
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper
|
import icu.samnyan.aqua.sega.util.jackson.StringMapper
|
||||||
|
import icu.samnyan.aqua.sega.wacca.empty
|
||||||
import icu.samnyan.aqua.spring.Metrics
|
import icu.samnyan.aqua.spring.Metrics
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
import kotlin.reflect.full.declaredMemberProperties
|
import kotlin.reflect.full.declaredMemberProperties
|
||||||
|
|
||||||
|
fun interface Chu3UserHandler : BaseHandler {
|
||||||
|
override fun handle(request: Map<String, Any>) = handleThis(request, parsing { request["userId"]?.long })
|
||||||
|
fun handleThis(request: Map<String, Any>, extId: Long?): Any
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
*/
|
*/
|
||||||
@@ -19,10 +27,7 @@ import kotlin.reflect.full.declaredMemberProperties
|
|||||||
@API(value = ["/g/chu3/{version}/ChuniServlet", "/g/chu3/{version}"])
|
@API(value = ["/g/chu3/{version}/ChuniServlet", "/g/chu3/{version}"])
|
||||||
class ChusanServletController(
|
class ChusanServletController(
|
||||||
val gameLogin: GameLoginHandler,
|
val gameLogin: GameLoginHandler,
|
||||||
val getGameCharge: GetGameChargeHandler,
|
|
||||||
val getGameEvent: GetGameEventHandler,
|
|
||||||
val getGameSetting: GetGameSettingHandler,
|
val getGameSetting: GetGameSettingHandler,
|
||||||
val getUserActivity: GetUserActivityHandler,
|
|
||||||
val getUserCharacter: GetUserCharacterHandler,
|
val getUserCharacter: GetUserCharacterHandler,
|
||||||
val getUserCharge: GetUserChargeHandler,
|
val getUserCharge: GetUserChargeHandler,
|
||||||
val getUserCourse: GetUserCourseHandler,
|
val getUserCourse: GetUserCourseHandler,
|
||||||
@@ -39,8 +44,6 @@ class ChusanServletController(
|
|||||||
val getUserTeam: GetUserTeamHandler,
|
val getUserTeam: GetUserTeamHandler,
|
||||||
val upsertUserAll: UpsertUserAllHandler,
|
val upsertUserAll: UpsertUserAllHandler,
|
||||||
val upsertUserChargelog: UpsertUserChargelogHandler,
|
val upsertUserChargelog: UpsertUserChargelogHandler,
|
||||||
val getGameGacha: GetGameGachaHandler,
|
|
||||||
val getGameGachaCardById: GetGameGachaCardByIdHandler,
|
|
||||||
val getUserCardPrintError: GetUserCardPrintErrorHandler,
|
val getUserCardPrintError: GetUserCardPrintErrorHandler,
|
||||||
val cmGetUserPreview: CMGetUserPreviewHandler,
|
val cmGetUserPreview: CMGetUserPreviewHandler,
|
||||||
val cmGetUserData: CMGetUserDataHandler,
|
val cmGetUserData: CMGetUserDataHandler,
|
||||||
@@ -57,9 +60,14 @@ class ChusanServletController(
|
|||||||
val getUserCMission: GetUserCMissionHandler,
|
val getUserCMission: GetUserCMissionHandler,
|
||||||
val getGameMapAreaCondition: GetGameMapAreaConditionHandler,
|
val getGameMapAreaCondition: GetGameMapAreaConditionHandler,
|
||||||
|
|
||||||
val mapper: StringMapper
|
val mapper: StringMapper,
|
||||||
|
val repos: Chu3Repos,
|
||||||
) {
|
) {
|
||||||
|
fun static(o: Any) = mapper.write(o).let { resp -> BaseHandler { resp } }
|
||||||
|
|
||||||
val logger = LoggerFactory.getLogger(ChusanServletController::class.java)
|
val logger = LoggerFactory.getLogger(ChusanServletController::class.java)
|
||||||
|
val events = resJson<List<Map<Str, Int>>>("/static/chusan_game_event.json")!!.filter { it["enable"].truthy }
|
||||||
|
.map { it.filterKeys { it != "enable" } + mapOf("startDate" to "2019-01-01 00:00:00", "endDate" to "2029-01-01 00:00:00") }
|
||||||
|
|
||||||
val getGameRanking = BaseHandler { """{"type":"${it["type"]}","length":"0","gameRankingList":[]}""" }
|
val getGameRanking = BaseHandler { """{"type":"${it["type"]}","length":"0","gameRankingList":[]}""" }
|
||||||
val getGameIdlist = BaseHandler { """{"type":"${it["type"]}","length":"0","gameRankingList":[]}""" }
|
val getGameIdlist = BaseHandler { """{"type":"${it["type"]}","length":"0","gameRankingList":[]}""" }
|
||||||
@@ -82,6 +90,22 @@ class ChusanServletController(
|
|||||||
val endMatching = BaseHandler { """{"matchingResult":{"matchingMemberInfoList":[],"matchingMemberRoleList":[],"reflectorUri":""}}""" }
|
val endMatching = BaseHandler { """{"matchingResult":{"matchingMemberInfoList":[],"matchingMemberRoleList":[],"reflectorUri":""}}""" }
|
||||||
val getMatchingState = BaseHandler { """{"matchingWaitState":{"restMSec":"30000","pollingInterval":"10","matchingMemberInfoList":[],"isFinish":"true"}}""" }
|
val getMatchingState = BaseHandler { """{"matchingWaitState":{"restMSec":"30000","pollingInterval":"10","matchingMemberInfoList":[],"isFinish":"true"}}""" }
|
||||||
|
|
||||||
|
// Actual handlers
|
||||||
|
val getUserActivity = UserReqHandler { req, u ->
|
||||||
|
val kind = parsing { req["kind"]!!.int }
|
||||||
|
val a = repos.userActivity.findAllByUser_Card_ExtIdAndKind(u, kind).sortedBy { it.sortNumber }
|
||||||
|
mapOf("userId" to u, "length" to a.size, "kind" to kind, "userActivityList" to a)
|
||||||
|
}
|
||||||
|
val getGameEvent = static(mapOf("type" to 1, "length" to events.size, "gameEventList" to events))
|
||||||
|
val getGameCharge = static(repos.gameCharge.findAll().let { mapOf("length" to it.size, "gameChargeList" to it) })
|
||||||
|
val getGameGacha = static(repos.gameGacha.findAll()
|
||||||
|
.let { mapOf("length" to it.size, "gameGachaList" to it, "registIdList" to empty) }
|
||||||
|
)
|
||||||
|
val getGameGachaCardById = BaseHandler {
|
||||||
|
val id = parsing { it["gachaId"]!!.int }
|
||||||
|
val cards = repos.gameGachaCard.findAllByGachaId(id)
|
||||||
|
mapOf("gachaId" to id, "length" to cards.size, "isPickup" to false, "gameGachaCardList" to cards, "emissionList" to empty, "afterCalcList" to empty)
|
||||||
|
}
|
||||||
|
|
||||||
// Below are code related to handling the handlers
|
// Below are code related to handling the handlers
|
||||||
val endpointList = mutableListOf(
|
val endpointList = mutableListOf(
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.chusan.handler;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.Chu3GameChargeRepo;
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameCharge;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Component("ChusanGetGameChargeHandler")
|
|
||||||
public class GetGameChargeHandler implements BaseHandler {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GetGameChargeHandler.class);
|
|
||||||
private final Chu3GameChargeRepo gameChargeRepository;
|
|
||||||
private final StringMapper mapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public GetGameChargeHandler(Chu3GameChargeRepo gameChargeRepository, StringMapper mapper) {
|
|
||||||
this.gameChargeRepository = gameChargeRepository;
|
|
||||||
this.mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
|
||||||
|
|
||||||
List<GameCharge> gameChargeList = gameChargeRepository.findAll();
|
|
||||||
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("length", gameChargeList.size());
|
|
||||||
resultMap.put("gameChargeList", gameChargeList);
|
|
||||||
|
|
||||||
String json = mapper.write(resultMap);
|
|
||||||
logger.info("Response: " + json);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.chusan.handler;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.Chu3GameEventRepo;
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameEvent;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Component("ChusanGetGameEventHandler")
|
|
||||||
public class GetGameEventHandler implements BaseHandler {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GetGameEventHandler.class);
|
|
||||||
|
|
||||||
private final Chu3GameEventRepo gameEventRepository;
|
|
||||||
|
|
||||||
private final StringMapper mapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public GetGameEventHandler(Chu3GameEventRepo gameEventRepository, StringMapper mapper) {
|
|
||||||
this.gameEventRepository = gameEventRepository;
|
|
||||||
this.mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
|
||||||
String type = (String) request.get("type");
|
|
||||||
|
|
||||||
List<GameEvent> gameEventList = gameEventRepository.findByEnable(true);
|
|
||||||
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("type", type);
|
|
||||||
resultMap.put("length", gameEventList.size());
|
|
||||||
resultMap.put("gameEventList", gameEventList);
|
|
||||||
|
|
||||||
String json = mapper.write(resultMap);
|
|
||||||
logger.info("Response: {} events", gameEventList.size());
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.chusan.handler;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameGachaCard;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.service.GameGachaCardService;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Component("ChusanGetGameGachaCardByIdHandler")
|
|
||||||
public class GetGameGachaCardByIdHandler implements BaseHandler {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GetGameGachaCardByIdHandler.class);
|
|
||||||
private final GameGachaCardService gameGachaCardService;
|
|
||||||
private final BasicMapper mapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public GetGameGachaCardByIdHandler(GameGachaCardService gameGachaCardService, BasicMapper mapper) {
|
|
||||||
this.gameGachaCardService = gameGachaCardService;
|
|
||||||
this.mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
|
||||||
int gachaId = ((Number) request.get("gachaId")).intValue();
|
|
||||||
|
|
||||||
List<GameGachaCard> gameGachaCardList = gameGachaCardService.getByGachaId(gachaId);
|
|
||||||
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("gachaId", gachaId);
|
|
||||||
resultMap.put("length", gameGachaCardList.size());
|
|
||||||
resultMap.put("isPickup", false);
|
|
||||||
resultMap.put("gameGachaCardList", gameGachaCardList);
|
|
||||||
resultMap.put("emissionList", List.of());
|
|
||||||
resultMap.put("afterCalcList", List.of());
|
|
||||||
|
|
||||||
String json = mapper.write(resultMap);
|
|
||||||
logger.info("Response: " + json);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.chusan.handler;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.Chu3GameGachaRepo;
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.gamedata.GameGacha;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Component("ChusanGetGameGachaHandler")
|
|
||||||
public class GetGameGachaHandler implements BaseHandler {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GetGameGachaHandler.class);
|
|
||||||
private final Chu3GameGachaRepo gameGachaRepository;
|
|
||||||
private final BasicMapper mapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public GetGameGachaHandler(Chu3GameGachaRepo gameGachaRepository, BasicMapper mapper) {
|
|
||||||
this.gameGachaRepository = gameGachaRepository;
|
|
||||||
this.mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
|
||||||
|
|
||||||
List<GameGacha> gameGachaList = gameGachaRepository.findAll();
|
|
||||||
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("length", gameGachaList.size());
|
|
||||||
resultMap.put("gameGachaList", gameGachaList);
|
|
||||||
resultMap.put("registIdList", List.of());
|
|
||||||
|
|
||||||
String json = mapper.write(resultMap);
|
|
||||||
logger.info("Response: " + json);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package icu.samnyan.aqua.sega.chusan.handler;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import icu.samnyan.aqua.sega.general.BaseHandler;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.model.userdata.UserActivity;
|
|
||||||
import icu.samnyan.aqua.sega.chusan.service.UserActivityService;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Component("ChusanGetUserActivityHandler")
|
|
||||||
public class GetUserActivityHandler implements BaseHandler {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GetUserActivityHandler.class);
|
|
||||||
|
|
||||||
private final StringMapper mapper;
|
|
||||||
|
|
||||||
private final UserActivityService userActivityService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public GetUserActivityHandler(StringMapper mapper, UserActivityService userActivityService) {
|
|
||||||
this.mapper = mapper;
|
|
||||||
this.userActivityService = userActivityService;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
|
||||||
String userId = (String) request.get("userId");
|
|
||||||
String kind = (String) request.get("kind");
|
|
||||||
|
|
||||||
List<UserActivity> userActivityList = userActivityService.getAllByUserIdAndKind(userId, kind);
|
|
||||||
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("userId", userId);
|
|
||||||
resultMap.put("length", userActivityList.size());
|
|
||||||
resultMap.put("kind", kind);
|
|
||||||
resultMap.put("userActivityList", userActivityList);
|
|
||||||
|
|
||||||
String json = mapper.write(resultMap);
|
|
||||||
logger.info("Response: " + json);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -44,6 +44,7 @@ interface Chu3UserActivityRepo : Chu3UserLinked<UserActivity> {
|
|||||||
fun findTopByUserAndActivityIdAndKindOrderByIdDesc(user: Chu3UserData, activityId: Int, kind: Int): Optional<UserActivity>
|
fun findTopByUserAndActivityIdAndKindOrderByIdDesc(user: Chu3UserData, activityId: Int, kind: Int): Optional<UserActivity>
|
||||||
|
|
||||||
fun findAllByUser_Card_ExtIdAndKindOrderBySortNumberDesc(extId: Long, kind: Int): List<UserActivity>
|
fun findAllByUser_Card_ExtIdAndKindOrderBySortNumberDesc(extId: Long, kind: Int): List<UserActivity>
|
||||||
|
fun findAllByUser_Card_ExtIdAndKind(extId: Long, kind: Int): List<UserActivity>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Chu3UserCardPrintStateRepo : Chu3UserLinked<UserCardPrintState> {
|
interface Chu3UserCardPrintStateRepo : Chu3UserLinked<UserCardPrintState> {
|
||||||
|
|||||||
1191
src/main/resources/static/chusan_game_event.json
Normal file
1191
src/main/resources/static/chusan_game_event.json
Normal file
File diff suppressed because it is too large
Load Diff
8
src/main/resources/static/format.py
Normal file
8
src/main/resources/static/format.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import json
|
||||||
|
|
||||||
|
for f in Path(__file__).parent.glob('*.json'):
|
||||||
|
obj = json.loads(f.read_text('utf-8'))
|
||||||
|
blacklist = ['end_date', 'start_date']
|
||||||
|
obj = [{k: v for k, v in o.items() if k not in blacklist} for o in obj]
|
||||||
|
f.write_text('[\n' + ',\n'.join(json.dumps(o, ensure_ascii=False) for o in obj) + '\n]\n', 'utf-8')
|
||||||
Reference in New Issue
Block a user