Browse Source

搜索bugfix

chao 3 years ago
parent
commit
b00feccaef

+ 24 - 22
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -81,20 +81,21 @@ public class SearchProductServiceImpl implements SearchProductService {
         if (promotionFlag == 1) {
             filterList.add("p_promotions_id > 0");
         }
-        log.info("brandIds = " + brandIds + "------------------------------------------------------------------------");
         if (!StringUtils.isEmpty(brandIds) && !"null".equals(brandIds)) {
             StringBuffer brandBuilder = new StringBuffer();
-            if (brandIds.contains(",")) {
-                String[] split = brandIds.split(",");
-                for (int i = 0; i < split.length; i++) {
-                    if (i == 0 && !"null".equals(split[i]) && split[i] != null) {
-                        brandBuilder.append("p_brand_id=").append(split[i]);
-                    } else {
-                        brandBuilder.append(" OR p_brand_id=").append(split[i]);
-                    }
+            List<String> brandList = new ArrayList<>();
+            String[] split = brandIds.split(",");
+            for (String s : split) {
+                if (!StringUtils.isEmpty(s) && !"null".equals(s)) {
+                    brandList.add(s);
+                }
+            }
+            for (int i = 0; i < brandList.size(); i++) {
+                if (i == 0) {
+                    brandBuilder.append(brandList.get(i));
+                } else {
+                    brandBuilder.append(" OR ").append(brandList.get(i));
                 }
-            } else {
-                brandBuilder.append("p_brand_id=").append(brandIds);
             }
             String brandFilter = brandBuilder.toString();
             if (brandFilter.contains("OR")) {
@@ -241,20 +242,21 @@ public class SearchProductServiceImpl implements SearchProductService {
         if (promotionFlag == 1) {
             filterList.add("p_promotions_id > 0");
         }
-        log.info("brandIds = " + brandIds + "------------------------------------------------------------------------");
         if (!StringUtils.isEmpty(brandIds) && !"null".equals(brandIds)) {
             StringBuffer brandBuilder = new StringBuffer();
-            if (brandIds.contains(",")) {
-                String[] split = brandIds.split(",");
-                for (int i = 0; i < split.length; i++) {
-                    if (i == 0 && !"null".equals(split[i]) && split[i] != null) {
-                        brandBuilder.append("p_brand_id=").append(split[i]);
-                    } else {
-                        brandBuilder.append(" OR p_brand_id=").append(split[i]);
-                    }
+            List<String> brandList = new ArrayList<>();
+            String[] split = brandIds.split(",");
+            for (String s : split) {
+                if (!StringUtils.isEmpty(s) && !"null".equals(s)) {
+                    brandList.add(s);
+                }
+            }
+            for (int i = 0; i < brandList.size(); i++) {
+                if (i == 0) {
+                    brandBuilder.append(brandList.get(i));
+                } else {
+                    brandBuilder.append(" OR ").append(brandList.get(i));
                 }
-            } else {
-                brandBuilder.append("p_brand_id=").append(brandIds);
             }
             String brandFilter = brandBuilder.toString();
             if (brandFilter.contains("OR")) {