mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-05 02:47:58 +08:00
[api] Add chunithm profile export and import
[general] Rename some method name and add more docs
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>icu.samnya</groupId>
|
||||
<artifactId>aqua</artifactId>
|
||||
<version>0.0.12-RELEASE</version>
|
||||
<version>0.0.12a-RELEASE</version>
|
||||
<name>Aqua Server</name>
|
||||
<description>A multipurpose game server</description>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package icu.samnyan.aqua.api.controller.sega;
|
||||
|
||||
import icu.samnyan.aqua.sega.general.dao.CardRepository;
|
||||
import icu.samnyan.aqua.sega.general.model.Card;
|
||||
import icu.samnyan.aqua.sega.general.service.CardService;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -11,20 +11,21 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* General Aime actions endpoint
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api/sega/aime")
|
||||
public class ApiAimeController {
|
||||
|
||||
private final CardRepository cardRepository;
|
||||
private final CardService cardService;
|
||||
|
||||
public ApiAimeController(CardRepository cardRepository) {
|
||||
this.cardRepository = cardRepository;
|
||||
public ApiAimeController(CardService cardService) {
|
||||
this.cardService = cardService;
|
||||
}
|
||||
|
||||
@PostMapping("getByAccessCode")
|
||||
public Optional<Card> getByAccessCode(@RequestBody Map<String, String> request) {
|
||||
return cardRepository.findByLuid(request.get("accessCode").replaceAll("-","").replaceAll(" ",""));
|
||||
return cardService.getCardByAccessCode(request.get("accessCode").replaceAll("-", "").replaceAll(" ", ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,22 +6,28 @@ import icu.samnyan.aqua.api.model.ReducedPageResponse;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.ProfileResp;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.RatingItem;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.RecentResp;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.external.ChuniDataExport;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.external.ChuniDataImport;
|
||||
import icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.external.ExternalUserData;
|
||||
import icu.samnyan.aqua.api.util.ApiMapper;
|
||||
import icu.samnyan.aqua.sega.chunithm.model.gamedata.Level;
|
||||
import icu.samnyan.aqua.sega.chunithm.model.gamedata.Music;
|
||||
import icu.samnyan.aqua.sega.chunithm.model.userdata.*;
|
||||
import icu.samnyan.aqua.sega.chunithm.service.*;
|
||||
import icu.samnyan.aqua.sega.general.model.Card;
|
||||
import icu.samnyan.aqua.sega.general.service.CardService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -31,24 +37,45 @@ import java.util.stream.Collectors;
|
||||
@RequestMapping("api/game/chuni/amazon")
|
||||
public class ApiAmazonController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ApiAmazonController.class);
|
||||
|
||||
private final ApiMapper mapper;
|
||||
|
||||
private final UserDataService userDataService;
|
||||
private final UserPlaylogService userPlaylogService;
|
||||
private final UserMusicDetailService userMusicDetailService;
|
||||
private final CardService cardService;
|
||||
|
||||
private final UserActivityService userActivityService;
|
||||
private final UserCharacterService userCharacterService;
|
||||
private final UserChargeService userChargeService;
|
||||
private final UserCourseService userCourseService;
|
||||
private final UserDataService userDataService;
|
||||
private final UserDataExService userDataExService;
|
||||
private final UserDuelService userDuelService;
|
||||
private final UserGameOptionService userGameOptionService;
|
||||
private final UserGameOptionExService userGameOptionExService;
|
||||
private final UserItemService userItemService;
|
||||
private final UserMapService userMapService;
|
||||
private final UserMusicDetailService userMusicDetailService;
|
||||
private final UserPlaylogService userPlaylogService;
|
||||
|
||||
private final GameMusicService gameMusicService;
|
||||
|
||||
@Autowired
|
||||
public ApiAmazonController(ApiMapper mapper, UserDataService userDataService, UserPlaylogService userPlaylogService, UserMusicDetailService userMusicDetailService, UserCourseService userCourseService, UserGameOptionService userGameOptionService, GameMusicService gameMusicService) {
|
||||
public ApiAmazonController(ApiMapper mapper, CardService cardService, UserActivityService userActivityService, UserCharacterService userCharacterService, UserChargeService userChargeService, UserDataService userDataService, UserDataExService userDataExService, UserGameOptionExService userGameOptionExService, UserMapService userMapService, UserPlaylogService userPlaylogService, UserMusicDetailService userMusicDetailService, UserCourseService userCourseService, UserDuelService userDuelService, UserGameOptionService userGameOptionService, UserItemService userItemService, GameMusicService gameMusicService) {
|
||||
this.mapper = mapper;
|
||||
this.cardService = cardService;
|
||||
this.userActivityService = userActivityService;
|
||||
this.userCharacterService = userCharacterService;
|
||||
this.userChargeService = userChargeService;
|
||||
this.userDataService = userDataService;
|
||||
this.userDataExService = userDataExService;
|
||||
this.userGameOptionExService = userGameOptionExService;
|
||||
this.userMapService = userMapService;
|
||||
this.userPlaylogService = userPlaylogService;
|
||||
this.userMusicDetailService = userMusicDetailService;
|
||||
this.userCourseService = userCourseService;
|
||||
this.userDuelService = userDuelService;
|
||||
this.userGameOptionService = userGameOptionService;
|
||||
this.userItemService = userItemService;
|
||||
this.gameMusicService = gameMusicService;
|
||||
}
|
||||
|
||||
@@ -67,7 +94,7 @@ public class ApiAmazonController {
|
||||
public ProfileResp getProfile(@RequestParam String aimeId) {
|
||||
ProfileResp resp = mapper.convert(userDataService.getUserByExtId(aimeId).orElseThrow(), new TypeReference<>() {
|
||||
});
|
||||
UserCourse course = userCourseService.getByUser(aimeId)
|
||||
UserCourse course = userCourseService.getByUserId(aimeId)
|
||||
.stream()
|
||||
.filter(UserCourse::isClear)
|
||||
.max(Comparator.comparingInt(UserCourse::getClassId))
|
||||
@@ -168,12 +195,115 @@ public class ApiAmazonController {
|
||||
|
||||
@GetMapping("song/{id}")
|
||||
public List<UserMusicDetail> getSongDetail(@RequestParam String aimeId, @PathVariable int id) {
|
||||
return userMusicDetailService.getByUserAndMusicId(aimeId, id);
|
||||
return userMusicDetailService.getByUserIdAndMusicId(aimeId, id);
|
||||
}
|
||||
|
||||
@GetMapping("song/{id}/{level}")
|
||||
public List<UserPlaylog> getLevelPlaylog(@RequestParam String aimeId, @PathVariable int id, @PathVariable int level) {
|
||||
return userPlaylogService.getByUserAndMusicIdAndLevel(aimeId, id, level);
|
||||
return userPlaylogService.getByUserIdAndMusicIdAndLevel(aimeId, id, level);
|
||||
}
|
||||
|
||||
@GetMapping("export")
|
||||
public ResponseEntity<Object> exportAllUserData(@RequestParam String aimeId) {
|
||||
ChuniDataExport data = new ChuniDataExport();
|
||||
try {
|
||||
data.setUserData(userDataService.getUserByExtId(aimeId).orElseThrow());
|
||||
data.setUserActivityList(userActivityService.getByUserId(aimeId));
|
||||
data.setUserCharacterList(userCharacterService.getByUserId(aimeId));
|
||||
data.setUserChargeList(userChargeService.getByUserId(aimeId));
|
||||
data.setUserCourseList(userCourseService.getByUserId(aimeId));
|
||||
data.setUserDataEx(userDataExService.getByExtId(aimeId).orElseThrow());
|
||||
data.setUserDuelList(userDuelService.getByUserId(aimeId));
|
||||
data.setUserGameOption(userGameOptionService.getByUserId(aimeId).orElseThrow());
|
||||
data.setUserGameOptionEx(userGameOptionExService.getByUserId(aimeId).orElseThrow());
|
||||
data.setUserItemList(userItemService.getByUserId(aimeId));
|
||||
data.setUserMapList(userMapService.getByUserId(aimeId));
|
||||
data.setUserMusicDetailList(userMusicDetailService.getByUserId(aimeId));
|
||||
data.setUserPlaylogList(userPlaylogService.getByUserId(aimeId));
|
||||
} catch (NoSuchElementException e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body(new MessageResponse("User not found"));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(new MessageResponse("Error during data export. Reason: " + e.getMessage()));
|
||||
}
|
||||
// Set filename
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("content-disposition", "attachment; filename=" + aimeId + "_exported.json");
|
||||
return new ResponseEntity<>(data, headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("import")
|
||||
public ResponseEntity<Object> importAllUserData(@RequestBody ChuniDataImport data) {
|
||||
ExternalUserData exUser = data.getUserData();
|
||||
|
||||
Optional<Card> cardOptional = cardService.getCardByAccessCode(exUser.getAccessCode());
|
||||
Card card;
|
||||
if (cardOptional.isPresent()) {
|
||||
if (userDataService.getUserByCard(cardOptional.get()).isPresent()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body(new MessageResponse("This card already has a chunithm profile."));
|
||||
} else {
|
||||
card = cardOptional.get();
|
||||
}
|
||||
} else {
|
||||
card = cardService.registerByAccessCode(exUser.getAccessCode());
|
||||
}
|
||||
|
||||
UserData userData = mapper.convert(exUser, new TypeReference<>() {
|
||||
});
|
||||
userData.setCard(card);
|
||||
userDataService.saveAndFlushUserData(userData);
|
||||
|
||||
List<UserActivity> userActivityList = data.getUserActivityList();
|
||||
userActivityList.forEach(x -> x.setUser(userData));
|
||||
userActivityService.saveAll(userActivityList);
|
||||
|
||||
List<UserCharacter> userCharacterList = data.getUserCharacterList();
|
||||
userCharacterList.forEach(x -> x.setUser(userData));
|
||||
userCharacterService.saveAll(userCharacterList);
|
||||
|
||||
List<UserCharge> userChargeList = data.getUserChargeList();
|
||||
userCharacterList.forEach(x -> x.setUser(userData));
|
||||
userChargeService.saveAll(userChargeList);
|
||||
|
||||
List<UserCourse> userCourseList = data.getUserCourseList();
|
||||
userCourseList.forEach(x -> x.setUser(userData));
|
||||
userCourseService.saveAll(userCourseList);
|
||||
|
||||
UserDataEx userDataEx = data.getUserDataEx();
|
||||
userDataEx.setUser(userData);
|
||||
userDataExService.save(userDataEx);
|
||||
|
||||
List<UserDuel> userDuelList = data.getUserDuelList();
|
||||
userDuelList.forEach(x -> x.setUser(userData));
|
||||
userDuelService.saveAll(userDuelList);
|
||||
|
||||
UserGameOption userGameOption = data.getUserGameOption();
|
||||
userGameOption.setUser(userData);
|
||||
userGameOptionService.save(userGameOption);
|
||||
|
||||
UserGameOptionEx userGameOptionEx = data.getUserGameOptionEx();
|
||||
userGameOptionEx.setUser(userData);
|
||||
userGameOptionExService.save(userGameOptionEx);
|
||||
|
||||
List<UserItem> userItemList = data.getUserItemList();
|
||||
userItemList.forEach(x -> x.setUser(userData));
|
||||
userItemService.saveAll(userItemList);
|
||||
|
||||
List<UserMap> userMapList = data.getUserMapList();
|
||||
userMapList.forEach(x -> x.setUser(userData));
|
||||
userMapService.saveAll(userMapList);
|
||||
|
||||
List<UserMusicDetail> userMusicDetailList = data.getUserMusicDetailList();
|
||||
userMusicDetailList.forEach(x -> x.setUser(userData));
|
||||
userMusicDetailService.saveAll(userMusicDetailList);
|
||||
|
||||
List<UserPlaylog> userPlaylogList = data.getUserPlaylogList();
|
||||
userPlaylogList.forEach(x -> x.setUser(userData));
|
||||
userPlaylogService.saveAll(userPlaylogList);
|
||||
|
||||
return ResponseEntity.ok(new MessageResponse("Import successfully, aimeId: " + card.getExtId()));
|
||||
}
|
||||
|
||||
private int calculateRating(int levelBase, int score) {
|
||||
|
||||
31
src/main/java/icu/samnyan/aqua/api/model/resp/sega/chuni/amazon/external/ChuniDataExport.java
vendored
Normal file
31
src/main/java/icu/samnyan/aqua/api/model/resp/sega/chuni/amazon/external/ChuniDataExport.java
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.external;
|
||||
|
||||
import icu.samnyan.aqua.sega.chunithm.model.userdata.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is use for exporting CHUNITHM profile
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChuniDataExport {
|
||||
private UserData userData;
|
||||
private List<UserActivity> userActivityList;
|
||||
private List<UserCharacter> userCharacterList;
|
||||
private List<UserCharge> userChargeList;
|
||||
private List<UserCourse> userCourseList;
|
||||
private UserDataEx userDataEx;
|
||||
private List<UserDuel> userDuelList;
|
||||
private UserGameOption userGameOption;
|
||||
private UserGameOptionEx userGameOptionEx;
|
||||
private List<UserItem> userItemList;
|
||||
private List<UserMap> userMapList;
|
||||
private List<UserMusicDetail> userMusicDetailList;
|
||||
private List<UserPlaylog> userPlaylogList;
|
||||
}
|
||||
31
src/main/java/icu/samnyan/aqua/api/model/resp/sega/chuni/amazon/external/ChuniDataImport.java
vendored
Normal file
31
src/main/java/icu/samnyan/aqua/api/model/resp/sega/chuni/amazon/external/ChuniDataImport.java
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.external;
|
||||
|
||||
import icu.samnyan.aqua.sega.chunithm.model.userdata.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is use for importing CHUNITHM profile
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChuniDataImport {
|
||||
private ExternalUserData userData;
|
||||
private List<UserActivity> userActivityList;
|
||||
private List<UserCharacter> userCharacterList;
|
||||
private List<UserCharge> userChargeList;
|
||||
private List<UserCourse> userCourseList;
|
||||
private UserDataEx userDataEx;
|
||||
private List<UserDuel> userDuelList;
|
||||
private UserGameOption userGameOption;
|
||||
private UserGameOptionEx userGameOptionEx;
|
||||
private List<UserItem> userItemList;
|
||||
private List<UserMap> userMapList;
|
||||
private List<UserMusicDetail> userMusicDetailList;
|
||||
private List<UserPlaylog> userPlaylogList;
|
||||
}
|
||||
118
src/main/java/icu/samnyan/aqua/api/model/resp/sega/chuni/amazon/external/ExternalUserData.java
vendored
Normal file
118
src/main/java/icu/samnyan/aqua/api/model/resp/sega/chuni/amazon/external/ExternalUserData.java
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
package icu.samnyan.aqua.api.model.resp.sega.chuni.amazon.external;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* This class is use for exported UserData class. Using access code as identifier
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ExternalUserData {
|
||||
|
||||
// Access Code of the card
|
||||
private String accessCode;
|
||||
|
||||
private String userName;
|
||||
|
||||
private LocalDateTime lastLoginDate;
|
||||
|
||||
private boolean isWebJoin;
|
||||
|
||||
private String webLimitDate;
|
||||
|
||||
private int level;
|
||||
|
||||
private int reincarnationNum;
|
||||
|
||||
private String exp;
|
||||
|
||||
private long point;
|
||||
|
||||
private long totalPoint;
|
||||
|
||||
private int playCount;
|
||||
|
||||
private int multiPlayCount;
|
||||
|
||||
private int multiWinCount;
|
||||
|
||||
private int requestResCount;
|
||||
|
||||
private int acceptResCount;
|
||||
|
||||
private int successResCount;
|
||||
|
||||
private int playerRating;
|
||||
|
||||
private int highestRating;
|
||||
|
||||
private int nameplateId;
|
||||
|
||||
private int frameId;
|
||||
|
||||
private int characterId;
|
||||
|
||||
private int trophyId;
|
||||
|
||||
private int playedTutorialBit;
|
||||
|
||||
private int firstTutorialCancelNum;
|
||||
|
||||
private int masterTutorialCancelNum;
|
||||
|
||||
private int totalRepertoireCount;
|
||||
|
||||
private int totalMapNum;
|
||||
|
||||
private long totalHiScore;
|
||||
|
||||
private long totalBasicHighScore;
|
||||
|
||||
private long totalAdvancedHighScore;
|
||||
|
||||
private long totalExpertHighScore;
|
||||
|
||||
private long totalMasterHighScore;
|
||||
|
||||
private LocalDateTime eventWatchedDate;
|
||||
|
||||
private int friendCount;
|
||||
|
||||
@JsonProperty("isMaimai")
|
||||
private boolean isMaimai;
|
||||
|
||||
private String firstGameId;
|
||||
|
||||
private String firstRomVersion;
|
||||
|
||||
private String firstDataVersion;
|
||||
|
||||
private LocalDateTime firstPlayDate;
|
||||
|
||||
private String lastGameId;
|
||||
|
||||
private String lastRomVersion;
|
||||
|
||||
private String lastDataVersion;
|
||||
|
||||
private LocalDateTime lastPlayDate;
|
||||
|
||||
private int lastPlaceId;
|
||||
|
||||
private String lastPlaceName;
|
||||
|
||||
private String lastRegionId;
|
||||
|
||||
private String lastRegionName;
|
||||
|
||||
private String lastAllNetId;
|
||||
|
||||
private String lastClientId;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import icu.samnyan.aqua.sega.aimedb.util.AimeDbUtil;
|
||||
import icu.samnyan.aqua.sega.aimedb.util.LogMapper;
|
||||
import icu.samnyan.aqua.sega.general.dao.CardRepository;
|
||||
import icu.samnyan.aqua.sega.general.model.Card;
|
||||
import icu.samnyan.aqua.sega.general.service.CardService;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@@ -15,10 +16,8 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
@@ -30,12 +29,12 @@ public class RegisterHandler implements BaseHandler {
|
||||
|
||||
private final LogMapper logMapper;
|
||||
|
||||
private final CardRepository cardRepository;
|
||||
private final CardService cardService;
|
||||
|
||||
@Autowired
|
||||
public RegisterHandler(LogMapper logMapper, CardRepository cardRepository) {
|
||||
public RegisterHandler(LogMapper logMapper, CardService cardService) {
|
||||
this.logMapper = logMapper;
|
||||
this.cardRepository = cardRepository;
|
||||
this.cardService = cardService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,18 +48,8 @@ public class RegisterHandler implements BaseHandler {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("type", "register");
|
||||
|
||||
if(cardRepository.findByLuid((String) requestMap.get("luid")).isEmpty()) {
|
||||
Card card = new Card();
|
||||
card.setLuid((String) requestMap.get("luid"));
|
||||
int extId = ThreadLocalRandom.current().nextInt(99999999);
|
||||
while (cardRepository.findByExtId(extId).isPresent()) {
|
||||
extId = ThreadLocalRandom.current().nextInt(99999999);
|
||||
}
|
||||
card.setExtId(extId);
|
||||
card.setRegisterTime(LocalDateTime.now());
|
||||
card.setAccessTime(LocalDateTime.now());
|
||||
|
||||
cardRepository.save(card);
|
||||
if (cardService.getCardByAccessCode((String) requestMap.get("luid")).isEmpty()) {
|
||||
Card card = cardService.registerByAccessCode((String) requestMap.get("luid"));
|
||||
|
||||
resultMap.put("status", 1);
|
||||
resultMap.put("aimeId", card.getExtId().longValue());
|
||||
|
||||
@@ -17,4 +17,6 @@ public interface UserActivityRepository extends JpaRepository<UserActivity, Long
|
||||
Optional<UserActivity> findTopByUserAndActivityIdAndKindOrderByIdDesc(UserData user, int activityId, int kind);
|
||||
|
||||
List<UserActivity> findAllByUser_Card_ExtIdAndKindOrderBySortNumberDesc(int extId, int kind);
|
||||
|
||||
List<UserActivity> findAllByUser_Card_ExtId(int extId);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -18,4 +19,6 @@ public interface UserCharacterRepository extends JpaRepository<UserCharacter, Lo
|
||||
Optional<UserCharacter> findTopByUserAndCharacterIdOrderByIdDesc(UserData user, int characterId);
|
||||
|
||||
Page<UserCharacter> findByUser_Card_ExtId(int extId, Pageable pageable);
|
||||
|
||||
List<UserCharacter> findByUser_Card_ExtId(int extId);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -18,4 +19,6 @@ public interface UserItemRepository extends JpaRepository<UserItem, Long> {
|
||||
Optional<UserItem> findTopByUserAndItemIdAndItemKindOrderByIdDesc(UserData user, int itemId, int itemKind);
|
||||
|
||||
Page<UserItem> findAllByUser_Card_ExtIdAndItemKind(int extId, int itemKind, Pageable pageable);
|
||||
|
||||
List<UserItem> findAllByUser_Card_ExtId(int extId);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package icu.samnyan.aqua.sega.chunithm.dao.userdata;
|
||||
|
||||
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserPlaylog;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayLog;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@@ -19,4 +18,6 @@ public interface UserPlaylogRepository extends JpaRepository<UserPlaylog, Long>
|
||||
Page<UserPlaylog> findByUser_Card_ExtId(int extId, Pageable page);
|
||||
|
||||
List<UserPlaylog> findByUser_Card_ExtIdAndMusicIdAndLevel(int extId, int musicId, int level);
|
||||
|
||||
List<UserPlaylog> findByUser_Card_ExtId(int extId);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle getUserCharacter request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@@ -42,7 +43,7 @@ public class GetUserCharacterHandler implements BaseHandler {
|
||||
|
||||
int pageNum = nextIndex / maxCount;
|
||||
|
||||
Page<UserCharacter> dbPage = userCharacterService.getByUser(userId, pageNum, maxCount);
|
||||
Page<UserCharacter> dbPage = userCharacterService.getByUserId(userId, pageNum, maxCount);
|
||||
|
||||
long currentIndex = maxCount * pageNum + dbPage.getNumberOfElements();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle GetUserCourse request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@@ -46,7 +47,7 @@ public class GetUserCourseHandler implements BaseHandler {
|
||||
|
||||
int pageNum = nextIndex / maxCount;
|
||||
|
||||
Page<UserCourse> dbPage = userCourseService.getByUser(userId, pageNum, maxCount);
|
||||
Page<UserCourse> dbPage = userCourseService.getByUserId(userId, pageNum, maxCount);
|
||||
|
||||
long currentIndex = maxCount * pageNum + dbPage.getNumberOfElements();
|
||||
|
||||
@@ -54,7 +55,7 @@ public class GetUserCourseHandler implements BaseHandler {
|
||||
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? -1 : currentIndex);
|
||||
resultMap.put("userCourseList", dbPage.getContent());
|
||||
} else {
|
||||
List<UserCourse> courseList = userCourseService.getAllByUser(userId);
|
||||
List<UserCourse> courseList = userCourseService.getByUserId(userId);
|
||||
resultMap.put("length", courseList.size());
|
||||
resultMap.put("userCourseList", courseList);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class GetUserDataExHandler implements BaseHandler {
|
||||
@Override
|
||||
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
Optional<UserDataEx> userDataExOptional = userDataExService.getUserByExtId(userId);
|
||||
Optional<UserDataEx> userDataExOptional = userDataExService.getByExtId(userId);
|
||||
|
||||
if (userDataExOptional.isPresent()) {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle GetUserDuel request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@@ -40,7 +41,7 @@ public class GetUserDuelHandler implements BaseHandler {
|
||||
|
||||
// TODO:
|
||||
|
||||
List<UserDuel> userDuelList = userDuelService.getByUser(userId);
|
||||
List<UserDuel> userDuelList = userDuelService.getByUserId(userId);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handle GetUserMap request
|
||||
* @author samnyan (privateamusement@protonmail.com)
|
||||
*/
|
||||
@Component
|
||||
@@ -36,7 +37,7 @@ public class GetUserMapHandler implements BaseHandler {
|
||||
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
||||
String userId = (String) request.get("userId");
|
||||
|
||||
List<UserMap> userMapList = userMapService.getByUser(userId);
|
||||
List<UserMap> userMapList = userMapService.getByUserId(userId);
|
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("userId", userId);
|
||||
|
||||
@@ -88,7 +88,6 @@ public class UserData implements Serializable {
|
||||
|
||||
private String userName;
|
||||
|
||||
@JsonIgnore
|
||||
private LocalDateTime lastLoginDate;
|
||||
|
||||
@JsonProperty("isWebJoin")
|
||||
|
||||
@@ -37,4 +37,8 @@ public class UserActivityService {
|
||||
public List<UserActivity> getAllByUserIdAndKind(String userId, String kind) {
|
||||
return userActivityRepository.findAllByUser_Card_ExtIdAndKindOrderBySortNumberDesc(Integer.parseInt(userId), Integer.parseInt(kind));
|
||||
}
|
||||
|
||||
public List<UserActivity> getByUserId(String userId) {
|
||||
return userActivityRepository.findAllByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,6 @@ public class UserCharacterService {
|
||||
this.userCharacterRepository = userCharacterRepository;
|
||||
}
|
||||
|
||||
public Optional<UserCharacter> getByUserAndCharacterId(UserData user, String characterId) {
|
||||
return getByUserAndCharacterId(user, Integer.parseInt(characterId));
|
||||
}
|
||||
|
||||
public Optional<UserCharacter> getByUserAndCharacterId(UserData user, int characterId) {
|
||||
return userCharacterRepository.findTopByUserAndCharacterIdOrderByIdDesc(user, characterId);
|
||||
}
|
||||
|
||||
public UserCharacter save(UserCharacter userCharacter) {
|
||||
return userCharacterRepository.save(userCharacter);
|
||||
}
|
||||
@@ -41,8 +33,20 @@ public class UserCharacterService {
|
||||
return userCharacterRepository.saveAll(userCharacter);
|
||||
}
|
||||
|
||||
public Page<UserCharacter> getByUser(String userId, int pageNumber, int maxCount) {
|
||||
public List<UserCharacter> getByUserId(String userId) {
|
||||
return userCharacterRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
public Page<UserCharacter> getByUserId(String userId, int pageNumber, int maxCount) {
|
||||
Pageable pageable = PageRequest.of(pageNumber, maxCount);
|
||||
return userCharacterRepository.findByUser_Card_ExtId(Integer.parseInt(userId), pageable);
|
||||
}
|
||||
|
||||
public Optional<UserCharacter> getByUserAndCharacterId(UserData user, String characterId) {
|
||||
return getByUserAndCharacterId(user, Integer.parseInt(characterId));
|
||||
}
|
||||
|
||||
public Optional<UserCharacter> getByUserAndCharacterId(UserData user, int characterId) {
|
||||
return userCharacterRepository.findTopByUserAndCharacterIdOrderByIdDesc(user, characterId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ public class UserChargeService {
|
||||
return userChargeRepository.save(userCharge);
|
||||
}
|
||||
|
||||
public List<UserCharge> saveAll(List<UserCharge> newUserChargeList) {
|
||||
return userChargeRepository.saveAll(newUserChargeList);
|
||||
}
|
||||
|
||||
public List<UserCharge> getByUserId(String userId) {
|
||||
return userChargeRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
@@ -32,7 +36,4 @@ public class UserChargeService {
|
||||
return userChargeRepository.findByUserAndChargeId(user, Integer.parseInt(chargeId));
|
||||
}
|
||||
|
||||
public List<UserCharge> saveAll(List<UserCharge> newUserChargeList) {
|
||||
return userChargeRepository.saveAll(newUserChargeList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,6 @@ public class UserCourseService {
|
||||
this.userCourseRepository = userCourseRepository;
|
||||
}
|
||||
|
||||
public Optional<UserCourse> getByUserAndCourseId(UserData user, String courseId) {
|
||||
return userCourseRepository.findTopByUserAndCourseIdOrderByIdDesc(user, Integer.parseInt(courseId));
|
||||
}
|
||||
|
||||
public UserCourse save(UserCourse userCourse) {
|
||||
return userCourseRepository.save(userCourse);
|
||||
}
|
||||
@@ -37,16 +33,16 @@ public class UserCourseService {
|
||||
return userCourseRepository.saveAll(userMusicDetail);
|
||||
}
|
||||
|
||||
public List<UserCourse> getByUser(String userId) {
|
||||
public List<UserCourse> getByUserId(String userId) {
|
||||
return userCourseRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
public Page<UserCourse> getByUser(String userId, int pageNum, int maxCount) {
|
||||
public Page<UserCourse> getByUserId(String userId, int pageNum, int maxCount) {
|
||||
Pageable page = PageRequest.of(pageNum, maxCount);
|
||||
return userCourseRepository.findByUser_Card_ExtId(Integer.parseInt(userId), page);
|
||||
}
|
||||
|
||||
public List<UserCourse> getAllByUser(String userId) {
|
||||
return userCourseRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
public Optional<UserCourse> getByUserAndCourseId(UserData user, String courseId) {
|
||||
return userCourseRepository.findTopByUserAndCourseIdOrderByIdDesc(user, Integer.parseInt(courseId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ public class UserDataExService {
|
||||
this.userDataExRepository = userDataExRepository;
|
||||
}
|
||||
|
||||
public Optional<UserDataEx> getByUser(UserData user) {
|
||||
return userDataExRepository.findByUser(user);
|
||||
}
|
||||
|
||||
public UserDataEx save(UserDataEx userDataEx) {
|
||||
return userDataExRepository.save(userDataEx);
|
||||
}
|
||||
|
||||
public Optional<UserDataEx> getUserByExtId(String userId) {
|
||||
public Optional<UserDataEx> getByUser(UserData user) {
|
||||
return userDataExRepository.findByUser(user);
|
||||
}
|
||||
|
||||
public Optional<UserDataEx> getByExtId(String userId) {
|
||||
return userDataExRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package icu.samnyan.aqua.sega.chunithm.service;
|
||||
|
||||
import icu.samnyan.aqua.sega.chunithm.dao.userdata.UserDataRepository;
|
||||
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserData;
|
||||
import icu.samnyan.aqua.sega.general.model.Card;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -21,21 +22,6 @@ public class UserDataService {
|
||||
this.userDataRepository = userDataRepository;
|
||||
}
|
||||
|
||||
public Optional<UserData> getUserByExtId(String aimeId) {
|
||||
return userDataRepository.findByCard_ExtId(Integer.parseInt(aimeId));
|
||||
}
|
||||
|
||||
public String updateLoginTime(UserData userData) {
|
||||
userData.setLastLoginDate(LocalDateTime.now());
|
||||
|
||||
try {
|
||||
userDataRepository.save(userData);
|
||||
return "1";
|
||||
} catch (Exception e) {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
public UserData saveUserData(UserData userData) {
|
||||
return userDataRepository.save(userData);
|
||||
}
|
||||
@@ -43,4 +29,17 @@ public class UserDataService {
|
||||
public UserData saveAndFlushUserData(UserData userData) {
|
||||
return userDataRepository.saveAndFlush(userData);
|
||||
}
|
||||
|
||||
public Optional<UserData> getUserByExtId(String aimeId) {
|
||||
return userDataRepository.findByCard_ExtId(Integer.parseInt(aimeId));
|
||||
}
|
||||
|
||||
public Optional<UserData> getUserByCard(Card card) {
|
||||
return userDataRepository.findByCard(card);
|
||||
}
|
||||
|
||||
public void updateLoginTime(UserData userData) {
|
||||
userData.setLastLoginDate(LocalDateTime.now());
|
||||
userDataRepository.save(userData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ public class UserDuelService {
|
||||
return userDuelRepository.saveAll(userDuel);
|
||||
}
|
||||
|
||||
public List<UserDuel> getByUser(String userId) {
|
||||
public List<UserDuel> getByUserId(String userId) {
|
||||
return userDuelRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ public class UserGameOptionExService {
|
||||
this.userGameOptionExRepository = userGameOptionExRepository;
|
||||
}
|
||||
|
||||
public Optional<UserGameOptionEx> getByUser(UserData userData) {
|
||||
return userGameOptionExRepository.findByUser(userData);
|
||||
}
|
||||
|
||||
public UserGameOptionEx save(UserGameOptionEx userGameOptionEx) {
|
||||
return userGameOptionExRepository.save(userGameOptionEx);
|
||||
}
|
||||
|
||||
public Optional<UserGameOptionEx> getByUser(UserData userData) {
|
||||
return userGameOptionExRepository.findByUser(userData);
|
||||
}
|
||||
|
||||
public Optional<UserGameOptionEx> getByUserId(String userId) {
|
||||
return userGameOptionExRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ public class UserGameOptionService {
|
||||
this.userGameOptionRepository = userGameOptionRepository;
|
||||
}
|
||||
|
||||
public Optional<UserGameOption> getByUserId(String userId) {
|
||||
return userGameOptionRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
public UserGameOption save(UserGameOption userGameOption) {
|
||||
return userGameOptionRepository.save(userGameOption);
|
||||
}
|
||||
|
||||
public Optional<UserGameOption> getByUser(UserData user) {
|
||||
return userGameOptionRepository.findByUser(user);
|
||||
}
|
||||
|
||||
public UserGameOption save(UserGameOption userGameOption) {
|
||||
return userGameOptionRepository.save(userGameOption);
|
||||
public Optional<UserGameOption> getByUserId(String userId) {
|
||||
return userGameOptionRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,6 @@ public class UserItemService {
|
||||
this.userItemRepository = userItemRepository;
|
||||
}
|
||||
|
||||
|
||||
public Optional<UserItem> getByUserAndItemId(UserData user, String itemId, String itemKind) {
|
||||
return userItemRepository.findTopByUserAndItemIdAndItemKindOrderByIdDesc(user, Integer.parseInt(itemId), Integer.parseInt(itemKind));
|
||||
}
|
||||
|
||||
public UserItem save(UserItem userItem) {
|
||||
return userItemRepository.save(userItem);
|
||||
}
|
||||
@@ -37,6 +32,14 @@ public class UserItemService {
|
||||
return userItemRepository.saveAll(userItem);
|
||||
}
|
||||
|
||||
public List<UserItem> getByUserId(String userId) {
|
||||
return userItemRepository.findAllByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
public Optional<UserItem> getByUserAndItemId(UserData user, String itemId, String itemKind) {
|
||||
return userItemRepository.findTopByUserAndItemIdAndItemKindOrderByIdDesc(user, Integer.parseInt(itemId), Integer.parseInt(itemKind));
|
||||
}
|
||||
|
||||
public Page<UserItem> getByUserAndItemKind(String userId, int kind, int pageNumber, int maxCount) {
|
||||
Pageable page = PageRequest.of(pageNumber, maxCount);
|
||||
return userItemRepository.findAllByUser_Card_ExtIdAndItemKind(Integer.parseInt(userId), kind, page);
|
||||
|
||||
@@ -22,18 +22,6 @@ public class UserMapService {
|
||||
this.userMapRepository = userMapRepository;
|
||||
}
|
||||
|
||||
public List<UserMap> getByUser(UserData user) {
|
||||
return userMapRepository.findAllByUser(user);
|
||||
}
|
||||
|
||||
public List<UserMap> getByUser(String userId) {
|
||||
return userMapRepository.findAllByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
public Optional<UserMap> getByUserAndMapId(UserData user, String mapId) {
|
||||
return userMapRepository.findTopByUserAndMapIdOrderByIdDesc(user, Integer.parseInt(mapId));
|
||||
}
|
||||
|
||||
public UserMap save(UserMap userMap) {
|
||||
return userMapRepository.save(userMap);
|
||||
}
|
||||
@@ -41,4 +29,16 @@ public class UserMapService {
|
||||
public List<UserMap> saveAll(Iterable<UserMap> userMap) {
|
||||
return userMapRepository.saveAll(userMap);
|
||||
}
|
||||
|
||||
public List<UserMap> getByUser(UserData user) {
|
||||
return userMapRepository.findAllByUser(user);
|
||||
}
|
||||
|
||||
public List<UserMap> getByUserId(String userId) {
|
||||
return userMapRepository.findAllByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
public Optional<UserMap> getByUserAndMapId(UserData user, String mapId) {
|
||||
return userMapRepository.findTopByUserAndMapIdOrderByIdDesc(user, Integer.parseInt(mapId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,6 @@ public class UserMusicDetailService {
|
||||
this.userMusicDetailRepository = userMusicDetailRepository;
|
||||
}
|
||||
|
||||
public Optional<UserMusicDetail> getByUserAndMusicIdAndLevel(UserData user, String musicId, String level) {
|
||||
return userMusicDetailRepository.findTopByUserAndMusicIdAndLevelOrderByIdDesc(user, Integer.parseInt(musicId), Integer.parseInt(level));
|
||||
}
|
||||
|
||||
public UserMusicDetail save(UserMusicDetail userMusicDetail) {
|
||||
return userMusicDetailRepository.save(userMusicDetail);
|
||||
}
|
||||
@@ -46,7 +42,15 @@ public class UserMusicDetailService {
|
||||
return userMusicDetailRepository.findByUser_Card_ExtId(Integer.parseInt(userId), page);
|
||||
}
|
||||
|
||||
public List<UserMusicDetail> getByUserAndMusicId(String userId, int id) {
|
||||
return userMusicDetailRepository.findByUser_Card_ExtIdAndMusicId(Integer.parseInt(userId), id);
|
||||
public List<UserMusicDetail> getByUserId(String userId) {
|
||||
return userMusicDetailRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
public List<UserMusicDetail> getByUserIdAndMusicId(String userId, int musicId) {
|
||||
return userMusicDetailRepository.findByUser_Card_ExtIdAndMusicId(Integer.parseInt(userId), musicId);
|
||||
}
|
||||
|
||||
public Optional<UserMusicDetail> getByUserAndMusicIdAndLevel(UserData user, String musicId, String level) {
|
||||
return userMusicDetailRepository.findTopByUserAndMusicIdAndLevelOrderByIdDesc(user, Integer.parseInt(musicId), Integer.parseInt(level));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package icu.samnyan.aqua.sega.chunithm.service;
|
||||
|
||||
import icu.samnyan.aqua.sega.chunithm.dao.userdata.UserPlaylogRepository;
|
||||
import icu.samnyan.aqua.sega.chunithm.model.userdata.UserPlaylog;
|
||||
import icu.samnyan.aqua.sega.diva.model.userdata.PlayLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -33,16 +32,20 @@ public class UserPlaylogService {
|
||||
return userPlaylogRepository.saveAll(userPlaylogList);
|
||||
}
|
||||
|
||||
public Page<UserPlaylog> getRecentPlays(String userId, Pageable page) {
|
||||
return userPlaylogRepository.findByUser_Card_ExtId(Integer.parseInt(userId), page);
|
||||
}
|
||||
|
||||
public List<UserPlaylog> getRecent30Plays(String userId) {
|
||||
Pageable page = PageRequest.of(0, 30, Sort.by(Sort.Direction.DESC, "userPlayDate"));
|
||||
return userPlaylogRepository.findByUser_Card_ExtIdAndLevelNot(Integer.parseInt(userId), 4, page);
|
||||
}
|
||||
|
||||
public Page<UserPlaylog> getRecentPlays(String userId, Pageable page) {
|
||||
return userPlaylogRepository.findByUser_Card_ExtId(Integer.parseInt(userId), page);
|
||||
public List<UserPlaylog> getByUserId(String userId) {
|
||||
return userPlaylogRepository.findByUser_Card_ExtId(Integer.parseInt(userId));
|
||||
}
|
||||
|
||||
public List<UserPlaylog> getByUserAndMusicIdAndLevel(String userId, int id, int level) {
|
||||
public List<UserPlaylog> getByUserIdAndMusicIdAndLevel(String userId, int id, int level) {
|
||||
return userPlaylogRepository.findByUser_Card_ExtIdAndMusicIdAndLevel(Integer.parseInt(userId), id, level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class Card implements Serializable {
|
||||
|
||||
@Column(name = "register_time")
|
||||
private LocalDateTime registerTime;
|
||||
|
||||
@Column(name = "access_time")
|
||||
private LocalDateTime accessTime;
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ 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)
|
||||
@@ -20,11 +22,48 @@ public class CardService {
|
||||
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(Integer.parseInt(extId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a card by External Id
|
||||
* @param extId External Id
|
||||
* @return Optional of a Card
|
||||
*/
|
||||
public Optional<Card> getCardByExtId(int 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);
|
||||
int extId = ThreadLocalRandom.current().nextInt(99999999);
|
||||
while (cardRepository.findByExtId(extId).isPresent()) {
|
||||
extId = ThreadLocalRandom.current().nextInt(99999999);
|
||||
}
|
||||
card.setExtId(extId);
|
||||
card.setRegisterTime(LocalDateTime.now());
|
||||
card.setAccessTime(LocalDateTime.now());
|
||||
return cardRepository.save(card);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user