Przeglądaj źródła

collection分页查询添加稀有度标签过滤

sunkean 3 lat temu
rodzic
commit
eac0933659

+ 30 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -3,6 +3,7 @@ package com.izouma.nineth.service;
 import cn.hutool.core.convert.Convert;
 import com.izouma.nineth.TokenHistory;
 import com.izouma.nineth.annotations.Debounce;
+import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.config.RedisKeys;
 import com.izouma.nineth.converter.LongArrayConverter;
@@ -106,6 +107,35 @@ public class CollectionService {
             }
         }
 
+        if (query.containsKey("rarityLabel")) {
+            String rarityLabel = String.valueOf(query.get("rarityLabel"));
+            query.remove("rarityLabel");
+            String not = null;
+            if (StringUtils.isNotBlank(rarityLabel)) {
+                if (Constants.Rarity.SSR.equals(rarityLabel)) {
+                    not = Constants.Rarity.U_LIKE;
+                }
+                if (Constants.Rarity.SR.equals(rarityLabel)) {
+                    not = Constants.Rarity.SSR_LIKE;
+                }
+                if (Constants.Rarity.U.equals(rarityLabel)) {
+                    not = Constants.Rarity.R_LIKE;
+                }
+                if (Constants.Rarity.R.equals(rarityLabel)) {
+                    not = Constants.Rarity.SR_LIKE;
+                }
+                String finalNotLike = not;
+                String finalLike = "%" + rarityLabel + " #%";
+                specification = specification.and((Specification<Collection>) (root, criteriaQuery, criteriaBuilder) -> {
+                    List<Predicate> and = new ArrayList<>();
+                    and.add(criteriaBuilder.like(root.get("name"), finalLike));
+                    and.add(criteriaBuilder.notLike(root.get("name"), finalNotLike));
+                    return criteriaBuilder.and(and.toArray(new Predicate[0]));
+                });
+            }
+        }
+
+
         // 筛选去除指定名称不展示
         if (query.containsKey("notLike")) {
             String notLike = Convert.toStr(query.get("notLike"));