|
|
@@ -1,5 +1,6 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
+import com.izouma.nineth.config.Constants;
|
|
|
import com.izouma.nineth.domain.BlindBoxItem;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.dto.PageWrapper;
|
|
|
@@ -10,7 +11,10 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -18,10 +22,6 @@ public class BlindBoxItemService {
|
|
|
|
|
|
private BlindBoxItemRepo blindBoxItemRepo;
|
|
|
|
|
|
- private final String SSR = "SSR";
|
|
|
- private final String SR = "SR";
|
|
|
- private final String U = "U";
|
|
|
-
|
|
|
@Cacheable(value = "blindBoxList", key = "#pageQuery.hashCode()")
|
|
|
public PageWrapper<BlindBoxItem> all(PageQuery pageQuery) {
|
|
|
return PageWrapper.of(blindBoxItemRepo.findAll(JpaUtils.toSpecification(pageQuery, BlindBoxItem.class), JpaUtils.toPageRequest(pageQuery)));
|
|
|
@@ -29,18 +29,31 @@ public class BlindBoxItemService {
|
|
|
|
|
|
public HashMap<String, String> getBlindBoxRare(Long blindBoxId) {
|
|
|
HashMap<String, String> rare = new HashMap<>();
|
|
|
- String ssr = blindBoxItemRepo.getBlindBoxRare(blindBoxId, "%" + SSR + " #%", "%" + U + " #%");
|
|
|
+ Map<String, BigDecimal> ssrMap = blindBoxItemRepo.getBlindBoxRare(blindBoxId, "%" + Constants.Rarity.SSR + " #%", "%" + Constants.Rarity.U + " #%");
|
|
|
+ String ssr = convertToStr(ssrMap);
|
|
|
if (StringUtil.isNotBlank(ssr)) {
|
|
|
- rare.put(SSR, ssr);
|
|
|
+ rare.put(Constants.Rarity.SSR, ssr);
|
|
|
}
|
|
|
- String sr = blindBoxItemRepo.getBlindBoxRare(blindBoxId, "%" + SR + " #%", "%" + SSR + " #%");
|
|
|
+ Map<String, BigDecimal> srMap = blindBoxItemRepo.getBlindBoxRare(blindBoxId, "%" + Constants.Rarity.SR + " #%", "%" + Constants.Rarity.SSR + " #%");
|
|
|
+ String sr = convertToStr(srMap);
|
|
|
if (StringUtil.isNotBlank(sr)) {
|
|
|
- rare.put(SR, sr);
|
|
|
+ rare.put(Constants.Rarity.SR, sr);
|
|
|
}
|
|
|
- String u = blindBoxItemRepo.getBlindBoxRare(blindBoxId, "%" + U + " #%", "%" + SR + " #%");
|
|
|
+ Map<String, BigDecimal> uMap = blindBoxItemRepo.getBlindBoxRare(blindBoxId, "%" + Constants.Rarity.U + " #%", "%" + Constants.Rarity.SR + " #%");
|
|
|
+ String u = convertToStr(uMap);
|
|
|
if (StringUtil.isNotBlank(u)) {
|
|
|
- rare.put(U, u);
|
|
|
+ rare.put(Constants.Rarity.U, u);
|
|
|
}
|
|
|
return rare;
|
|
|
}
|
|
|
+
|
|
|
+ private String convertToStr(Map<String, BigDecimal> map) {
|
|
|
+ if (map.containsKey("total") && Objects.nonNull(map.get("total"))) {
|
|
|
+ if (map.containsKey("stock") && Objects.nonNull(map.get("stock"))) {
|
|
|
+ return map.get("stock").toString().concat("/").concat(map.get("total").toString());
|
|
|
+ }
|
|
|
+ return "0/" + map.get("total").toString();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|