forked from Cookies_Github_mirror/AquaDX
[api] Add chunithm profile export and import
[general] Rename some method name and add more docs
This commit is contained in:
@@ -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