|
|
@@ -6,6 +6,7 @@ import com.izouma.nineth.domain.MetaGameBoxPoints;
|
|
|
import com.izouma.nineth.dto.MetaGameBoxPointsDTO;
|
|
|
import com.izouma.nineth.dto.MetaRestResult;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.enums.MetaPointTypeEnum;
|
|
|
import com.izouma.nineth.repo.MetaGameBoxPointsRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -26,21 +27,22 @@ public class MetaGameBoxPointsService {
|
|
|
return metaGameBoxPointsRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaGameBoxPoints.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
- public MetaRestResult<MetaGameBoxPointsDTO> get(Long userId) {
|
|
|
+ public MetaRestResult<MetaGameBoxPointsDTO> get(Long userId, MetaPointTypeEnum type) {
|
|
|
MetaGameBoxPointsDTO metaGameBoxPointsDTO = new MetaGameBoxPointsDTO();
|
|
|
- MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserId(userId);
|
|
|
+ MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserIdAndType(userId, type);
|
|
|
if (Objects.isNull(metaGameBoxPoints)) {
|
|
|
metaGameBoxPoints = new MetaGameBoxPoints();
|
|
|
metaGameBoxPoints.setUserId(userId);
|
|
|
+ metaGameBoxPoints.setType(type);
|
|
|
metaGameBoxPoints.setScore(0);
|
|
|
metaGameBoxPointsRepo.save(metaGameBoxPoints);
|
|
|
}
|
|
|
- Map<String, Object> metaGameBoxPointsMap = metaGameBoxPointsRepo.findInfoByUserId(userId);
|
|
|
+ Map<String, Object> metaGameBoxPointsMap = metaGameBoxPointsRepo.findInfoByUserIdAndType(userId, type.toString());
|
|
|
String jsonStr = JSONObject.toJSONString(metaGameBoxPointsMap);
|
|
|
metaGameBoxPoints = JSONObject.parseObject(jsonStr, MetaGameBoxPoints.class);
|
|
|
metaGameBoxPointsDTO.setSelfHiScore(metaGameBoxPoints.getScore());
|
|
|
metaGameBoxPointsDTO.setSelfRank(metaGameBoxPoints.getScoreRank());
|
|
|
- List<Map<String, Object>> map = metaGameBoxPointsRepo.findTopFifty();
|
|
|
+ List<Map<String, Object>> map = metaGameBoxPointsRepo.findTopFiftyByType(type.toString());
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
jsonArray.addAll(map);
|
|
|
List<MetaGameBoxPoints> data = jsonArray.toJavaList(MetaGameBoxPoints.class);
|
|
|
@@ -55,9 +57,13 @@ public class MetaGameBoxPointsService {
|
|
|
if (Objects.isNull(record.getUserId())) {
|
|
|
return MetaRestResult.returnError("Illegal parameter : userId can not be null");
|
|
|
}
|
|
|
- MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserId(record.getUserId());
|
|
|
+ if (Objects.isNull(record.getType())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : type can not be null");
|
|
|
+ }
|
|
|
+ MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserIdAndType(record.getUserId(), record.getType());
|
|
|
if (Objects.isNull(metaGameBoxPoints)) {
|
|
|
metaGameBoxPoints = new MetaGameBoxPoints();
|
|
|
+ metaGameBoxPoints.setType(record.getType());
|
|
|
metaGameBoxPoints.setUserId(record.getUserId());
|
|
|
metaGameBoxPoints.setScore(record.getScore());
|
|
|
metaGameBoxPointsRepo.save(metaGameBoxPoints);
|