|
@@ -1,6 +1,7 @@
|
|
|
package com.izouma.nineth.service;
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
|
|
import com.izouma.nineth.domain.*;
|
|
import com.izouma.nineth.domain.*;
|
|
|
|
|
+import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.dto.CollectionDTO;
|
|
import com.izouma.nineth.dto.CollectionDTO;
|
|
|
import com.izouma.nineth.dto.CreateBlindBox;
|
|
import com.izouma.nineth.dto.CreateBlindBox;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
@@ -13,6 +14,7 @@ import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
import org.apache.commons.lang3.Range;
|
|
import org.apache.commons.lang3.Range;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.data.domain.PageImpl;
|
|
@@ -25,10 +27,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.transaction.Transactional;
|
|
import javax.transaction.Transactional;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -44,6 +43,9 @@ public class CollectionService {
|
|
|
|
|
|
|
|
public Page<Collection> all(PageQuery pageQuery) {
|
|
public Page<Collection> all(PageQuery pageQuery) {
|
|
|
pageQuery.getQuery().put("del", false);
|
|
pageQuery.getQuery().put("del", false);
|
|
|
|
|
+ String type = MapUtils.getString(pageQuery.getQuery(), "type", "DEFAULT");
|
|
|
|
|
+ pageQuery.getQuery().remove("type");
|
|
|
|
|
+
|
|
|
Specification<Collection> specification = JpaUtils.toSpecification(pageQuery, Collection.class);
|
|
Specification<Collection> specification = JpaUtils.toSpecification(pageQuery, Collection.class);
|
|
|
PageRequest pageRequest = JpaUtils.toPageRequest(pageQuery);
|
|
PageRequest pageRequest = JpaUtils.toPageRequest(pageQuery);
|
|
|
if (pageRequest.getSort().stream().noneMatch(order -> order.getProperty().equals("createdAt"))) {
|
|
if (pageRequest.getSort().stream().noneMatch(order -> order.getProperty().equals("createdAt"))) {
|
|
@@ -53,8 +55,19 @@ public class CollectionService {
|
|
|
|
|
|
|
|
specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
List<Predicate> and = new ArrayList<>();
|
|
List<Predicate> and = new ArrayList<>();
|
|
|
- if (!MapUtils.getString(pageQuery.getQuery(), "type", "").equals("BLIND_BOX")) {
|
|
|
|
|
- and.add(criteriaBuilder.notEqual(root.get("type"), CollectionType.BLIND_BOX));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotEmpty(type) && !"all".equalsIgnoreCase(type)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (type.contains(",")) {
|
|
|
|
|
+ and.add(root.get("type")
|
|
|
|
|
+ .in(Arrays.stream(type.split(",")).map(s -> Enum.valueOf(CollectionType.class, s))
|
|
|
|
|
+ .collect(Collectors.toList())));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ and.add(criteriaBuilder.equal(root.get("type"), Enum.valueOf(CollectionType.class, type)));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
});
|
|
});
|