zhijiezhao 3 лет назад
Родитель
Сommit
3cb81cb064

+ 1 - 0
src/main/java/com/caimei365/commodity/components/SearchOpenService.java

@@ -77,6 +77,7 @@ public class SearchOpenService {
      * @throws OpenSearchException       exp
      */
     public JSONObject getResultJsonObject(String queryStr, SearchParams searchParams) throws OpenSearchClientException, OpenSearchException {
+        log.info("【阿里云开放搜索】查询参数:"+ searchParams.toString());
         // 创建并构造OpenSearch对象
         OpenSearch openSearch = new OpenSearch(accesskey, secret, host);
         // 创建OpenSearchClient对象,并以OpenSearch对象作为构造参数

+ 56 - 23
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -85,19 +85,35 @@ public class SearchProductServiceImpl implements SearchProductService {
                 filter.append("p_brand:'").append(brandIds).append("'");
             }
         }
-        if (newFlag == 1) {
-//            p_time=20201105
-            Calendar c = Calendar.getInstance();
-            c.setTime(new Date());
-            c.add(Calendar.YEAR, -1);
-            String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
-            filter.append("p_time > ").append(time);
-        }
-        if (promotionFlag == 1) {
+        if (!StringUtils.isEmpty(brandIds)) {
             if (newFlag == 1) {
-                filter.append("AND p_promotions_id > 0");
-            } else {
-                filter.append("p_promotions_id > 0");
+                Calendar c = Calendar.getInstance();
+                c.setTime(new Date());
+                c.add(Calendar.YEAR, -1);
+                String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
+                filter.append(" AND p_time > ").append(time);
+            }
+            if (promotionFlag == 1) {
+                if (newFlag == 1) {
+                    filter.append(" AND p_promotions_id > 0");
+                } else {
+                    filter.append("p_promotions_id > 0");
+                }
+            }
+        }else{
+            if (newFlag == 1) {
+                Calendar c = Calendar.getInstance();
+                c.setTime(new Date());
+                c.add(Calendar.YEAR, -1);
+                String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
+                filter.append("p_time > ").append(time);
+            }
+            if (promotionFlag == 1) {
+                if (newFlag == 1) {
+                    filter.append(" AND p_promotions_id > 0");
+                } else {
+                    filter.append("p_promotions_id > 0");
+                }
             }
         }
         // 阿里云搜索
@@ -232,18 +248,35 @@ public class SearchProductServiceImpl implements SearchProductService {
                 filter.append("p_brand:'").append(brandIds).append("'");
             }
         }
-        if (newFlag == 1) {
-            Calendar c = Calendar.getInstance();
-            c.setTime(new Date());
-            c.add(Calendar.YEAR, -1);
-            String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
-            filter.append("p_time > ").append(time);
-        }
-        if (promotionFlag == 1) {
+        if (!StringUtils.isEmpty(brandIds)) {
             if (newFlag == 1) {
-                filter.append("AND p_promotions_id > 0");
-            } else {
-                filter.append("p_promotions_id > 0");
+                Calendar c = Calendar.getInstance();
+                c.setTime(new Date());
+                c.add(Calendar.YEAR, -1);
+                String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
+                filter.append(" AND p_time > ").append(time);
+            }
+            if (promotionFlag == 1) {
+                if (newFlag == 1) {
+                    filter.append(" AND p_promotions_id > 0");
+                } else {
+                    filter.append("p_promotions_id > 0");
+                }
+            }
+        }else{
+            if (newFlag == 1) {
+                Calendar c = Calendar.getInstance();
+                c.setTime(new Date());
+                c.add(Calendar.YEAR, -1);
+                String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
+                filter.append("p_time > ").append(time);
+            }
+            if (promotionFlag == 1) {
+                if (newFlag == 1) {
+                    filter.append(" AND p_promotions_id > 0");
+                } else {
+                    filter.append("p_promotions_id > 0");
+                }
             }
         }
         SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);