mirror of https://github.com/hykilpikonna/AquaDX
[F] Fix CM
parent
b421b4476b
commit
0f14326449
|
@ -16,6 +16,7 @@ import icu.samnyan.aqua.sega.general.RequestContext
|
|||
import icu.samnyan.aqua.sega.general.SpecialHandler
|
||||
import icu.samnyan.aqua.sega.general.model.response.UserRecentRating
|
||||
import icu.samnyan.aqua.sega.general.toSpecial
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper
|
||||
import icu.samnyan.aqua.sega.util.jackson.StringMapper
|
||||
import icu.samnyan.aqua.spring.Metrics
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
|
@ -35,12 +36,12 @@ import kotlin.reflect.full.declaredMemberProperties
|
|||
class ChusanServletController(
|
||||
val gameLogin: GameLoginHandler,
|
||||
val upsertUserAll: UpsertUserAllHandler,
|
||||
val cmGetUserCharacter: CMGetUserCharacterHandler,
|
||||
val cmUpsertUserGacha: CMUpsertUserGachaHandler,
|
||||
val cmUpsertUserPrintSubtract: CMUpsertUserPrintSubtractHandler,
|
||||
val cmUpsertUserPrintCancel: CMUpsertUserPrintCancelHandler,
|
||||
|
||||
val mapper: StringMapper,
|
||||
val cmMapper: BasicMapper,
|
||||
val db: Chu3Repos,
|
||||
val us: AquaUserServices,
|
||||
val versionHelper: ChusanVersionHelper,
|
||||
|
@ -49,7 +50,7 @@ class ChusanServletController(
|
|||
val log = LoggerFactory.getLogger(ChusanServletController::class.java)
|
||||
|
||||
// Below are code related to handling the handlers
|
||||
val externalHandlers = mutableListOf("GameLoginApi", "UpsertUserAllApi", "CMGetUserCharacterApi",
|
||||
val externalHandlers = mutableListOf("GameLoginApi", "UpsertUserAllApi",
|
||||
"CMUpsertUserGachaApi", "CMUpsertUserPrintCancelApi", "CMUpsertUserPrintSubtractApi")
|
||||
|
||||
val noopEndpoint = setOf("UpsertClientBookkeepingApi", "UpsertClientDevelopApi", "UpsertClientErrorApi",
|
||||
|
@ -95,10 +96,11 @@ class ChusanServletController(
|
|||
return """{"returnCode":"1"}"""
|
||||
}
|
||||
log.info("Chu3 < $api : ${data.toJson()}")
|
||||
val map = if ("CM" in api) cmMapper else mapper
|
||||
|
||||
return try {
|
||||
Metrics.timer("aquadx_chusan_api_latency", "api" to api).recordCallable {
|
||||
handlers[api]!!(ctx).let { if (it is String) it else mapper.write(it) }.also {
|
||||
handlers[api]!!(ctx).let { if (it is String) it else map.write(it) }.also {
|
||||
if (api !in setOf("GetUserItemApi", "GetGameEventApi"))
|
||||
log.info("Chu3 > $api : $it")
|
||||
}
|
||||
|
@ -201,7 +203,7 @@ fun ChusanServletController.init() {
|
|||
mapOf("userId" to uid, "length" to lst.size, "userCardPrintStateList" to lst)
|
||||
}
|
||||
|
||||
"GetUserCharacter" {
|
||||
ls("GetUserCharacter", "CMGetUserCharacter") all {
|
||||
// Let's try not paging at all
|
||||
val lst = db.userCharacter.findByUser_Card_ExtId(uid)
|
||||
mapOf("userId" to uid, "length" to lst.size, "nextIndex" to -1, "userCharacterList" to lst)
|
||||
|
|
|
@ -1,68 +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.UserCharacter;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserCharacterService;
|
||||
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.data.domain.Page;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle getUserCharacter request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component("ChusanCMGetUserCharacterHandler")
|
||||
public class CMGetUserCharacterHandler implements BaseHandler {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CMGetUserCharacterHandler.class);
|
||||
|
||||
private final BasicMapper mapper;
|
||||
|
||||
private final UserCharacterService userCharacterService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public CMGetUserCharacterHandler(BasicMapper mapper, UserCharacterService userCharacterService) {
|
||||
this.mapper = mapper;
|
||||
this.userCharacterService = userCharacterService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = String.valueOf(request.get("userId"));
|
||||
int nextIndex = ((Number) request.get("nextIndex")).intValue();
|
||||
int maxCount = ((Number) request.get("maxCount")).intValue();
|
||||
|
||||
int pageNum = nextIndex / maxCount;
|
||||
|
||||
Page<UserCharacter> dbPage = userCharacterService.getByUserId(userId, pageNum, maxCount);
|
||||
|
||||
long currentIndex = maxCount * pageNum + dbPage.getNumberOfElements();
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
resultMap.put("length", dbPage.getNumberOfElements());
|
||||
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
|
||||
List<Integer> userCharacterIdList = new ArrayList<>();
|
||||
|
||||
dbPage.getContent().forEach(userCharacter -> {
|
||||
userCharacterIdList.add(userCharacter.getCharacterId());
|
||||
});
|
||||
|
||||
resultMap.put("userCharacterList", userCharacterIdList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import icu.samnyan.aqua.sega.chusan.model.userdata.UserItem;
|
|||
import icu.samnyan.aqua.sega.chusan.service.UserDataService;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserItemService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -24,6 +25,7 @@ import java.util.*;
|
|||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Component("ChusanCMUpsertUserGachaHandler")
|
||||
public class CMUpsertUserGachaHandler implements BaseHandler {
|
||||
|
||||
|
@ -34,19 +36,8 @@ public class CMUpsertUserGachaHandler implements BaseHandler {
|
|||
private final UserItemService userItemService;
|
||||
private final BasicMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public CMUpsertUserGachaHandler(UserItemService userItemService, UserDataService userDataService,
|
||||
Chu3UserCardPrintStateRepo userCardPrintStateRepository, BasicMapper mapper,
|
||||
Chu3UserGachaRepo userGachaRepository) {
|
||||
this.userCardPrintStateRepository = userCardPrintStateRepository;
|
||||
this.userGachaRepository = userGachaRepository;
|
||||
this.userDataService = userDataService;
|
||||
this.userItemService = userItemService;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
public Object handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = String.valueOf(request.get("userId"));
|
||||
int gachaId = ((Number) request.get("gachaId")).intValue();
|
||||
int placeId = ((Number) request.get("placeId")).intValue();
|
||||
|
@ -105,8 +96,6 @@ public class CMUpsertUserGachaHandler implements BaseHandler {
|
|||
resultMap.put("apiName", "CMUpsertUserGachaApi");
|
||||
resultMap.put("userCardPrintStateList", userCardPrintStateList);
|
||||
|
||||
String json = mapper.write(resultMap);
|
||||
logger.info("Response: " + json);
|
||||
return json;
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import icu.samnyan.aqua.sega.chusan.model.userdata.UserItem;
|
|||
import icu.samnyan.aqua.sega.chusan.service.UserDataService;
|
||||
import icu.samnyan.aqua.sega.chusan.service.UserItemService;
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -20,6 +21,7 @@ import java.util.*;
|
|||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Component("ChusanCMUpsertUserPrintSubtractHandler")
|
||||
public class CMUpsertUserPrintSubtractHandler implements BaseHandler {
|
||||
|
||||
|
@ -29,14 +31,6 @@ public class CMUpsertUserPrintSubtractHandler implements BaseHandler {
|
|||
private final UserDataService userDataService;
|
||||
private final BasicMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public CMUpsertUserPrintSubtractHandler(UserItemService userItemService, UserDataService userDataService, Chu3UserCardPrintStateRepo userCardPrintStateRepository, BasicMapper mapper) {
|
||||
this.userCardPrintStateRepository = userCardPrintStateRepository;
|
||||
this.userItemService = userItemService;
|
||||
this.userDataService = userDataService;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handle(Map<String, ?> request) throws JsonProcessingException {
|
||||
String userId = String.valueOf(request.get("userId"));
|
||||
|
|
Loading…
Reference in New Issue