forked from Cookies_Github_mirror/AquaDX
[F] Fix CM
This commit is contained in:
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user