Quellcode durchsuchen

阿里云搜索增加品牌/促销商品/新品筛选项

zhijiezhao vor 3 Jahren
Ursprung
Commit
e427b7a803

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

@@ -97,7 +97,7 @@ public class PriceUtilService {
         // 如果身份不是机构,并且促销活动不可见,直接把促销置空
         if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 2 && flag == 1) {
             promotions = null;
-        }else if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 2 && identity == 1) {
+        }else if (promotions != null && promotions.getSeen() != null && identity!=null && promotions.getSeen() == 2 && identity == 1) {
             promotions = null;
         }
         price.setRepurchaseFlag(0);

+ 71 - 37
src/main/java/com/caimei365/commodity/components/SearchOpenService.java

@@ -42,16 +42,17 @@ public class SearchOpenService {
     @Value("${aliyunConfig.searchHost}")
     private String host;
 
-    public String getAppName(){
+    public String getAppName() {
         return this.appName;
     }
+
     /**
      * 推送操作
      *
      * @param document doc
      * @return result
      * @throws OpenSearchClientException exp
-     * @throws OpenSearchException exp
+     * @throws OpenSearchException       exp
      */
     public String pushDocument(String document, String tableName) throws OpenSearchClientException, OpenSearchException {
         // 创建并构造OpenSearch对象
@@ -69,8 +70,8 @@ public class SearchOpenService {
     /**
      * 获取查询结果
      *
-     * @param queryStr      查询类型及参数串
-     * @param searchParams  搜索参数obj
+     * @param queryStr     查询类型及参数串
+     * @param searchParams 搜索参数obj
      * @return JSONObject
      * @throws OpenSearchClientException exp
      * @throws OpenSearchException       exp
@@ -98,7 +99,7 @@ public class SearchOpenService {
         String tracer = jsonObj.getString("tracer");
         JSONObject result = jsonObj.getJSONObject("result");
         JSONArray errors = jsonObj.getJSONArray("errors");
-        log.info(">>>>>>query("+queryStr+"): " + status + ",request_id=" +requestId+ ",errors=" + errors.toString() + ",tracer="+tracer);
+        log.info(">>>>>>query(" + queryStr + "): " + status + ",request_id=" + requestId + ",errors=" + errors.toString() + ",tracer=" + tracer);
         if ("OK".equals(status)) {
             result.put("status", 1);
         } else {
@@ -120,7 +121,7 @@ public class SearchOpenService {
     public SearchParams getSearchParams(String queryStr, ArrayList<String> fetchFields, List<Map<String, String>> summaryFields, String rankName, int num, int size, String sortField, Integer sortType) {
         // 定义Config对象,用于设定config子句参数,指定应用名,分页,数据返回格式等等
         Config config = new Config(Lists.newArrayList(appName));
-        config.setStart(num-1);
+        config.setStart(num - 1);
         config.setHits(size);
         // 设置搜索结果返回应用中哪些字段
         config.setFetchFields(fetchFields);
@@ -177,9 +178,9 @@ public class SearchOpenService {
     /**
      * 获取默认滚动查询参数
      *
-     * @param queryStr      查询类型及参数
-     * @param fetchFields   返回字段
-     * @param size          每页数量
+     * @param queryStr    查询类型及参数
+     * @param fetchFields 返回字段
+     * @param size        每页数量
      * @return searchParams
      */
     public SearchParams getScrollParams(String queryStr, ArrayList<String> fetchFields, int size, String sortField, Integer sortType) {
@@ -219,10 +220,10 @@ public class SearchOpenService {
     public SearchParams getProductParams(String queryStr, String filter, Integer identity, int num, int size, String sortField, Integer sortType) {
         // 定义Config对象,用于设定config子句参数,指定应用名,分页,数据返回格式等等
         Config config = new Config(Lists.newArrayList(appName));
-        config.setStart(num-1);
+        config.setStart(num - 1);
         config.setHits(size);
         // 设置搜索结果返回应用中哪些字段
-        config.setFetchFields(Lists.newArrayList("id", "p_id", "p_name", "p_image", "p_brand_name", "p_unit", "p_code", "p_price_flag", "p_price_grade", "p_supplier_id", "p_keyword", "p_act_flag"));
+        config.setFetchFields(Lists.newArrayList("id", "p_id", "p_name", "p_image", "p_brand_name", "p_unit", "p_code", "p_price_flag", "p_price_grade", "p_supplier_id", "p_keyword", "p_act_flag", "p_brand_id"));
         // 注意:config子句中的rerank_size参数,在Rank类对象中设置
         // 设置返回格式为json格式
         config.setSearchFormat(SearchFormat.JSON);
@@ -285,7 +286,7 @@ public class SearchOpenService {
         if (StringUtils.isNotEmpty(sortField) && Arrays.asList(sortFields).contains(sortField)) {
             Order order = (1 == sortType) ? Order.DECREASE : Order.INCREASE;
             // 设置排序字段
-            sorter.addToSortFields(new SortField("p_"+sortField, order));
+            sorter.addToSortFields(new SortField("p_" + sortField, order));
         }
         // 以RANK相关性算分降序
         sorter.addToSortFields(new SortField("RANK", Order.DECREASE));
@@ -326,7 +327,7 @@ public class SearchOpenService {
         // config.setStart(0) scroll该参数不起作用,默认为0
         config.setHits(size);
         // 设置搜索结果返回应用中哪些字段
-        config.setFetchFields(Lists.newArrayList("id", "p_id", "p_name", "p_image", "p_brand_name", "p_unit", "p_code", "p_price_flag", "p_price_grade", "p_supplier_id", "p_keyword", "p_act_flag"));
+        config.setFetchFields(Lists.newArrayList("id", "p_id", "p_name", "p_image", "p_brand_name", "p_unit", "p_code", "p_price_flag", "p_price_grade", "p_supplier_id", "p_keyword", "p_act_flag", "p_brand_id"));
         // 设置返回格式为json格式
         config.setSearchFormat(SearchFormat.JSON);
         // 创建参数对象
@@ -361,7 +362,7 @@ public class SearchOpenService {
             Order order = (1 == sortType) ? Order.DECREASE : Order.INCREASE;
             // 设置排序字段
             sorter.addToSortFields(new SortField(sortField, order));
-        }else{
+        } else {
             // 默认商品ID倒序
             sorter.addToSortFields(new SortField("p_id", Order.DECREASE));
         }
@@ -374,16 +375,16 @@ public class SearchOpenService {
     /**
      * 滚动查询
      *
-     * @param searchParams  查询参数对象
-     * @param queryStr 查询类型及参数串
-     * @param pageNum       页码
-     * @param pageSize      每页数量
-     * @param requestPageSize  每次scroll数量
+     * @param searchParams    查询参数对象
+     * @param queryStr        查询类型及参数串
+     * @param pageNum         页码
+     * @param pageSize        每页数量
+     * @param requestPageSize 每次scroll数量
      * @return list
      */
     public JSONObject deepPagingForParams(SearchParams searchParams, String queryStr, int maxSearchNum, int requestPageSize, int pageNum, int pageSize) throws OpenSearchClientException, OpenSearchException {
         //设置scroll方式查询
-        DeepPaging deep =new DeepPaging();
+        DeepPaging deep = new DeepPaging();
         //不设置默认为1m表示1分钟,该参数表示本次返回的scrollid的有效期
         deep.setScrollExpire("3m");
         //添加DeepPaging对象参数
@@ -394,12 +395,12 @@ public class SearchOpenService {
         int status = result.getInt("status");
         pageObj.put("status", status);
         if (1 == status) {
-            int requestSize = pageNum*pageSize;
+            int requestSize = pageNum * pageSize;
             int total = result.getInt("total");
-            int totalPage = (int) Math.ceil( (double)total/pageSize);
+            int totalPage = (int) Math.ceil((double) total / pageSize);
             JSONArray pageData = new JSONArray();
-            int loop = (int)Math.ceil((double) requestSize / requestPageSize);
-            for (int l=1; l<=loop; l++) {
+            int loop = (int) Math.ceil((double) requestSize / requestPageSize);
+            for (int l = 1; l <= loop; l++) {
                 //第一次执行不返回数据,主要返回scroll_id值,第二次调用查询时设置scroll_id
                 deep.setScrollId(result.getString("scroll_id"));
                 //不设置默认为1m表示1分钟,如不想使用默认值,每次重新调用前必须要重新设置下
@@ -408,15 +409,15 @@ public class SearchOpenService {
                 result = getResultJsonObject(queryStr, searchParams);
                 if (1 == status) {
                     JSONArray resultArr = result.getJSONArray("items");
-                    if (resultArr.length()>0){
-                        if (requestSize > maxSearchNum){
-                            if (l==loop) {
-                                int baseSize = Math.min(requestSize - (requestPageSize*(loop-1)), resultArr.length());
+                    if (resultArr.length() > 0) {
+                        if (requestSize > maxSearchNum) {
+                            if (l == loop) {
+                                int baseSize = Math.min(requestSize - (requestPageSize * (loop - 1)), resultArr.length());
                                 // 上一页数量往前总数量 - 上一轮循环后总数量 = 当前循环的上一页之前数量
-                                int baseNum = pageSize*(pageNum-1) - requestPageSize*(loop-1);
-                                for (int i=0; i<pageSize; i++) {
+                                int baseNum = pageSize * (pageNum - 1) - requestPageSize * (loop - 1);
+                                for (int i = 0; i < pageSize; i++) {
                                     int index = baseNum + i;
-                                    if (index<baseSize){
+                                    if (index < baseSize) {
                                         JSONObject item = resultArr.getJSONObject(index);
                                         pageData.put(i, item);
                                     } else {
@@ -425,14 +426,14 @@ public class SearchOpenService {
                                 }
                             }
                         } else {
-                            int baseNum = (pageNum-1)*pageSize;
+                            int baseNum = (pageNum - 1) * pageSize;
                             int currentTotal = requestSize;
-                            if (totalPage == pageNum){
+                            if (totalPage == pageNum) {
                                 currentTotal = total;
                             }
-                            for (int i=0; i<pageSize; i++) {
+                            for (int i = 0; i < pageSize; i++) {
                                 int index = baseNum + i;
-                                if (index<currentTotal){
+                                if (index < currentTotal) {
                                     JSONObject item = resultArr.getJSONObject(index);
                                     pageData.put(i, item);
                                 } else {
@@ -445,12 +446,45 @@ public class SearchOpenService {
             }
             pageObj.put("total", total);
             pageObj.put("items", pageData);
-            log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + pageSize +"),pageNum("+pageNum+"),total("+total+")");
+            log.info(">>>>>>pageResult(" + queryStr + "): pageSize(" + pageSize + "),pageNum(" + pageNum + "),total(" + total + ")");
         }
         return pageObj;
     }
 
 
-
+    public SearchParams getParams(String queryStr, Integer identity, String filter) {
+        // 定义Config对象,用于设定config子句参数,指定应用名,分页,数据返回格式等等
+        Config config = new Config(Lists.newArrayList(appName));
+        // 设置搜索结果返回应用中哪些字段
+        config.setFetchFields(Lists.newArrayList("p_brand_name", "p_brand_id"));
+        // 设置返回格式为json格式
+        config.setSearchFormat(SearchFormat.JSON);
+        // 创建参数对象
+        SearchParams searchParams = new SearchParams(config);
+        // 设置查询子句,若需多个索引组合查询,需要setQuery处合并,否则若设置多个setQuery后面的会替换前面查询
+        searchParams.setQuery(queryStr);
+        // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
+        // p_valid:0逻辑删除 1待审核 2已上架 3已下架 8审核未通过 9已隐身 10已冻结
+        // p_visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
+        String thisFilter = "";
+        if (identity == 1) {
+            // 协销 | 综合供应商
+            thisFilter += "(p_valid=2 OR p_valid=3 OR p_valid=9) AND p_type=1";
+        } else if (identity == 2) {
+            // 会员机构
+            thisFilter += "p_valid=2 AND p_type=1";
+        } else if (identity == 4) {
+            // 普通机构
+            thisFilter += "(p_visibility=2 OR p_visibility=3) AND p_valid=2 AND p_type=1";
+        } else {
+            // 游客|所有人
+            thisFilter += "p_visibility=3 AND p_valid=2 AND p_type=1";
+        }
+        if (StringUtils.isNotEmpty(filter)) {
+            thisFilter = thisFilter + " AND " + filter;
+        }
+        searchParams.setFilter(thisFilter);
+        return searchParams;
+    }
 
 }

+ 78 - 50
src/main/java/com/caimei365/commodity/controller/SearchProductApi.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -23,7 +24,7 @@ import java.util.Map;
  * @author : Charles
  * @date : 2021/4/7
  */
-@Api(tags="搜索商品API")
+@Api(tags = "搜索商品API")
 @RestController
 @RequiredArgsConstructor
 @RequestMapping("/commodity/search/query")
@@ -31,9 +32,27 @@ public class SearchProductApi {
 
     private final SearchProductService searchProductService;
 
+
+    @ApiOperation("根据keyword或分类搜品牌")
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
+            @ApiImplicitParam(required = false, name = "id", value = "bigTypeID/smallTypeID/tinyTypeID"),
+            @ApiImplicitParam(required = false, name = "newFlag", value = "查询新品标记,默认0,新品1"),
+            @ApiImplicitParam(required = false, name = "promotionFlag", value = "查询促销标记,默认0,促销1"),
+            @ApiImplicitParam(required = false, name = "idType", value = "id类型:1一级分类,2二级分类,3三级分类"),
+            @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构")
+    })
+    @GetMapping("/brand")
+    public ResponseJson<List<HashMap<String, Object>>> queryBrand(String keyword, Integer id, Integer idType,
+                                                                  @RequestParam(value = "newFlag", defaultValue = "0") Integer newFlag,
+                                                                  @RequestParam(value = "promotionFlag", defaultValue = "0") Integer promotionFlag,
+                                                                  @RequestParam(value = "identity", defaultValue = "0") Integer identity) {
+        return searchProductService.queryBrand(keyword, id, idType, newFlag, promotionFlag, identity);
+    }
+
     /**
      * 根据关键词搜索商品
-     *
+     * <p>
      * spi旧接口:/search/query/product
      *
      * @param keyword 搜索关键字
@@ -41,25 +60,30 @@ public class SearchProductApi {
      */
     @ApiOperation("根据keyword搜索商品")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
-        @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
-        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
-        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
-        @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
-        @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
+            @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
+            @ApiImplicitParam(required = false, name = "brandIds", value = "品牌id字符串,逗号隔开"),
+            @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
+            @ApiImplicitParam(required = false, name = "newFlag", value = "查询新品标记,默认0,新品1"),
+            @ApiImplicitParam(required = false, name = "promotionFlag", value = "查询促销标记,默认0,促销1"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
+            @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
+            @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
     })
     @GetMapping("/product")
-    public ResponseJson<String> queryProductByKeyword(String keyword,
+    public ResponseJson<String> queryProductByKeyword(String keyword, String brandIds,
                                                       @RequestParam(value = "identity", defaultValue = "0") Integer identity,
+                                                      @RequestParam(value = "newFlag", defaultValue = "0") Integer newFlag,
+                                                      @RequestParam(value = "promotionFlag", defaultValue = "0") Integer promotionFlag,
                                                       @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                                       @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
                                                       String sortField, Integer sortType) {
-        return searchProductService.queryProductByKeyword(keyword, identity, pageNum, pageSize, sortField, sortType);
+        return searchProductService.queryProductByKeyword(keyword, brandIds, identity, newFlag, promotionFlag, pageNum, pageSize, sortField, sortType);
     }
 
     /**
      * 根据分类Id搜索商品
-     *
+     * <p>
      * spi旧接口:/search/query/product/type
      *
      * @param id     bigTypeID/smallTypeID/tinyTypeID
@@ -67,73 +91,77 @@ public class SearchProductApi {
      */
     @ApiOperation("根据分类Id搜索商品")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = true, name = "id", value = "bigTypeID/smallTypeID/tinyTypeID"),
-        @ApiImplicitParam(required = true, name = "idType", value = "id类型:1一级分类,2二级分类,3三级分类"),
-        @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
-        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
-        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
-        @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
-        @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
+            @ApiImplicitParam(required = true, name = "id", value = "bigTypeID/smallTypeID/tinyTypeID"),
+            @ApiImplicitParam(required = true, name = "idType", value = "id类型:1一级分类,2二级分类,3三级分类"),
+            @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
+            @ApiImplicitParam(required = false, name = "newFlag", value = "查询新品标记,默认0,新品1"),
+            @ApiImplicitParam(required = false, name = "promotionFlag", value = "查询促销标记,默认0,促销1"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
+            @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
+            @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
     })
     @GetMapping("/product/type")
     public ResponseJson<String> queryProductByType(Integer id, Integer idType,
-                                            @RequestParam(value = "identity", defaultValue = "0") Integer identity,
-                                            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
-                                            @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
-                                            String sortField, Integer sortType) {
-        return searchProductService.queryProductByType(id, idType, identity, pageNum, pageSize, sortField, sortType);
+                                                   @RequestParam(value = "identity", defaultValue = "0") Integer identity,
+                                                   @RequestParam(value = "newFlag", defaultValue = "0") Integer newFlag,
+                                                   @RequestParam(value = "promotionFlag", defaultValue = "0") Integer promotionFlag,
+                                                   @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                   @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
+                                                   String sortField, Integer sortType) {
+        return searchProductService.queryProductByType(id, idType, identity, newFlag, promotionFlag, pageNum, pageSize, sortField, sortType);
     }
 
     /**
      * 根据小程序运营分类Id搜索商品
-     *
+     * <p>
      * spi旧接口:/search/query/product/classify
      *
-     * @param id        运营级分类Id
-     * @param identity  用户身份 1:协销, 2:会员机构
+     * @param id       运营级分类Id
+     * @param identity 用户身份 1:协销, 2:会员机构
      */
     @ApiOperation("根据小程序运营分类Id搜索商品")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = true, name = "id", value = "运营级分类Id"),
-        @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
-        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
-        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
-        @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
-        @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
+            @ApiImplicitParam(required = true, name = "id", value = "运营级分类Id"),
+            @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
+            @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
+            @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
     })
     @GetMapping("/product/classify")
     public ResponseJson<String> queryProductByClassify(Integer id,
-                                            @RequestParam(value = "identity", defaultValue = "0") Integer identity,
-                                            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
-                                            @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
-                                            String sortField, Integer sortType) {
+                                                       @RequestParam(value = "identity", defaultValue = "0") Integer identity,
+                                                       @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                       @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
+                                                       String sortField, Integer sortType) {
         return searchProductService.queryProductByClassify(id, identity, pageNum, pageSize, sortField, sortType);
     }
 
     /**
      * 根据供应商Id搜索商品(商铺内搜索)
-     *
+     * <p>
      * spi旧接口:/search/query/product/supplier
      *
-     * @param id       供应商Id
-     * @param keyword  搜索关键字
+     * @param id      供应商Id
+     * @param keyword 搜索关键字
      */
     @ApiOperation("根据供应商Id搜索商品(商铺内搜索)")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = true, name = "id", value = "供应商Id"),
-        @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
-        @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
-        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
-        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
-        @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
-        @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
+            @ApiImplicitParam(required = true, name = "id", value = "供应商Id"),
+            @ApiImplicitParam(required = false, name = "keyword", value = "搜索关键字"),
+            @ApiImplicitParam(required = false, name = "identity", value = "用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量"),
+            @ApiImplicitParam(required = false, name = "sortField", value = "排序字段:价格price,销量sales,人气favorite"),
+            @ApiImplicitParam(required = false, name = "sortType", value = "排序规则:1降序,其他升序")
     })
     @GetMapping("/product/shop")
     public ResponseJson<String> querySupplierProduct(Integer id, String keyword,
-                                           @RequestParam(value = "identity", defaultValue = "0") Integer identity,
-                                           @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
-                                           @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
-                                           String sortField, Integer sortType) {
+                                                     @RequestParam(value = "identity", defaultValue = "0") Integer identity,
+                                                     @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                     @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
+                                                     String sortField, Integer sortType) {
         return searchProductService.querySupplierProduct(id, keyword, identity, pageNum, pageSize, sortField, sortType);
     }
 

+ 60 - 15
src/main/java/com/caimei365/commodity/mapper/SearchMapper.java

@@ -2,10 +2,6 @@ package com.caimei365.commodity.mapper;
 
 import com.caimei365.commodity.model.po.SearchHistoryPo;
 import com.caimei365.commodity.model.search.*;
-import com.caimei365.commodity.model.search.ArticleListVo;
-import com.caimei365.commodity.model.search.EquipmentListVo;
-import com.caimei365.commodity.model.search.ProductListVo;
-import com.caimei365.commodity.model.search.ShopListVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -22,41 +18,51 @@ import java.util.List;
 public interface SearchMapper {
     /**
      * 根据商品id查找文档数据
+     *
      * @param productId
      */
     ProductDO searchProductById(Integer productId);
+
     /**
      * 获取商品数量
      */
     Integer findProductCount();
+
     /**
      * 获取商品列表
      */
     List<ProductDO> searchProductList();
+
     /**
      * 根据商品id查找 星范商品数量
      */
     Integer countMallProduct(Integer productId);
+
     /**
      * 根据商品id查找 星范商品
      */
     MallProductDO searchMallProductByProductId(Integer productId);
+
     /**
      * 根据商品id查找 星范阶梯价标志
      */
     Integer getMallLadderPriceFlag(Integer productId);
+
     /**
      * 根据商品id查找 星范最小阶梯价
      */
     Double getMallLowerLadderPrice(Integer productId);
+
     /**
      * 获取供应商数量
      */
     Integer findSupplierCount();
+
     /**
      * 获取供应商列表
      */
     List<SupplierDO> searchSupplierList();
+
     /**
      * 根据供应商Id查找文档数据
      */
@@ -66,10 +72,12 @@ public interface SearchMapper {
      * 获取项目仪器数量
      */
     Integer findEquipmentCount();
+
     /**
      * 获取项目仪器列表
      */
     List<EquipmentDO> searchEquipmentList();
+
     /**
      * 根据项目仪器Id查找文档数据
      */
@@ -79,73 +87,89 @@ public interface SearchMapper {
      * 获取文章数量
      */
     Integer findArticleCount();
+
     /**
      * 获取文章列表
      */
     List<ArticleDO> searchArticleList();
+
     /**
      * 根据文章Id查找文档数据
      */
     ArticleDO searchArticleById(Integer articleId);
+
     /**
      * 根据文章标签查找标签Id
      */
     List<Integer> findLabelIdsByName(@Param("labelTexts") String[] labelTexts);
+
     /**
      * 根据文章Id查找标签文本
      */
     String findLabelNameById(@Param("labelId") Integer labelId);
+
     /**
      * 获取所有失效商品数量
      */
     Integer findProductInvalidCount();
+
     /**
      * 获取失效商品IDs
      */
     List<Integer> findProductInvalidIds();
+
     /**
      * 根据商品ID获取星范ID
      */
     Integer findMallIdByProductId(Integer productId);
+
     /**
      * 根据商品IDs获取星范IDs
      */
     List<Integer> findMallInvalidIdsByProductIds(@Param("invalidIds") List<Integer> invalidIds);
+
     /**
      * 获取所有失效供应商数量
      */
     Integer findSupplierInvalidCount();
+
     /**
      * 获取失效供应商IDs
      */
     List<Integer> findSupplierInvalidIds();
+
     /**
      * 获取所有失效项目仪器数量
      */
     Integer findEquipmentInvalidCount();
+
     /**
      * 获取失效项目仪器IDs
      */
     List<Integer> findEquipmentInvalidIds();
+
     /**
      * 获取所有失效文章数量
      */
     Integer findArticleInvalidCount();
+
     /**
      * 获取失效文章IDs
      */
     List<Integer> findArticleInvalidIds();
+
     /**
      * 获取数据库商品
-     * @param identity  用户身份
-     * @param keyword   关键词
-     * @param shopId    供应商id
-     * @param bigTypeId 一级分类id
+     *
+     * @param identity    用户身份
+     * @param keyword     关键词
+     * @param shopId      供应商id
+     * @param bigTypeId   一级分类id
      * @param smallTypeId 二级分类id
-     * @param tinyTypeId 三级分类id
-     * @param classifyId 运营分类id
-     * @param sortField 排序类型
-     * @param sortType  排序顺序
+     * @param tinyTypeId  三级分类id
+     * @param classifyId  运营分类id
+     * @param sortField   排序类型
+     * @param sortType    排序顺序
      * @return list
      */
     List<ProductListVo> queryProduct(@Param("identity") Integer identity,
@@ -157,51 +181,72 @@ public interface SearchMapper {
                                      @Param("classifyId") Integer classifyId,
                                      @Param("sortField") String sortField,
                                      @Param("sortType") Integer sortType);
+
     /**
      * 获取数据库供应商
-     * @param keyword   关键词
+     *
+     * @param keyword 关键词
      * @return list
      */
     List<ShopListVo> querySupplier(@Param("keyword") String keyword);
+
     /**
      * 获取数据库项目仪器
-     * @param keyword   关键词
+     *
+     * @param keyword 关键词
      * @return list
      */
     List<EquipmentListVo> queryEquipment(@Param("keyword") String keyword);
+
     /**
      * 获取数据库文章
-     * @param keyword   关键词
+     *
+     * @param keyword 关键词
      * @return list
      */
     List<ArticleListVo> queryArticle(@Param("keyword") String keyword, @Param("articleId") Integer articleId, @Param("typeId") Integer typeId, @Param("labelText") String labelText);
+
     /**
      * 根据用户ID查找历史记录
      */
     List<SearchHistoryPo> getHistoryList(Integer userId);
+
     /**
      * 根据关键字获取历史记录Id
+     *
      * @param keyword 关键词
      */
     Integer getHistoryIdByWord(String keyword);
+
     /**
      * 更新历史记录
      */
     void updateSearchHistoryById(SearchHistoryPo historyRecord);
+
     /**
      * 新增取历史记录
      */
     void insertSearchHistory(SearchHistoryPo historyRecord);
+
     /**
      * 历史记录数量
      */
     int getHistoryCount(Integer userId);
+
     /**
      * 删除大于10条的历史记录
      */
     void deleteSearchHistory(Integer userId);
+
     /**
      * 删除用户所有历史记录
      */
     void deleteAllSearchHistory(Integer userId);
+
+    List<Integer> findNew(@Param("productIds") List<Integer> productIds, @Param("n") String n);
+
+    List<Integer> findPromotion(List<Integer> productIds);
+
+    List<Integer> findPromotionId(Integer p_id);
+
 }

+ 3 - 0
src/main/java/com/caimei365/commodity/model/search/ProductDO.java

@@ -71,5 +71,8 @@ public class ProductDO implements Serializable {
     /** 美博会商品活动状态 */
     private Integer p_act_flag;
 
+    private Integer p_time;
+
+    private Integer p_promotions_id;
     private static final long serialVersionUID = 1L;
 }

+ 4 - 0
src/main/java/com/caimei365/commodity/model/search/ProductListVo.java

@@ -12,6 +12,10 @@ import java.io.Serializable;
  */
 @Data
 public class ProductListVo implements Serializable {
+    /**
+     * 品牌id
+     */
+    private Integer brandId;
     /**
      * 阿里云索引Id
      */

+ 5 - 2
src/main/java/com/caimei365/commodity/service/SearchProductService.java

@@ -3,6 +3,7 @@ package com.caimei365.commodity.service;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.po.SearchHistoryPo;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -24,7 +25,7 @@ public interface SearchProductService {
      * @param sortType  升降序0/1
      * @return JsonStr(list)
      */
-    ResponseJson<String> queryProductByKeyword(String keyword, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType);
+    ResponseJson<String> queryProductByKeyword(String keyword, String brandIds,Integer identity,Integer newFlag,Integer promotionFlag, int pageNum, int pageSize, String sortField, Integer sortType);
 
     /**
      * 根据分类Id搜索商品
@@ -38,7 +39,7 @@ public interface SearchProductService {
      * @param sortType  升降序0/1
      * @return JsonStr(list)
      */
-    ResponseJson<String> queryProductByType(Integer id, Integer idType, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType);
+    ResponseJson<String> queryProductByType(Integer id, Integer idType, Integer identity,Integer newFlag,Integer promotionFlag, int pageNum, int pageSize, String sortField, Integer sortType);
 
     /**
      * 根据小程序运营分类Id搜索商品
@@ -87,4 +88,6 @@ public interface SearchProductService {
      * 产品仪器热搜词
      */
     ResponseJson<Map<String, Object>> getHotSearchTerms();
+
+    ResponseJson<List<HashMap<String, Object>>> queryBrand(String keyword, Integer id, Integer idType,Integer newFlag ,Integer promotionFlag, Integer identity);
 }

+ 152 - 121
src/main/java/com/caimei365/commodity/service/impl/SearchIndexServiceImpl.java

@@ -8,6 +8,7 @@ import com.aliyun.opensearch.sdk.generated.commons.OpenSearchClientException;
 import com.aliyun.opensearch.sdk.generated.commons.OpenSearchException;
 import com.aliyun.opensearch.sdk.generated.document.Command;
 import com.aliyun.opensearch.sdk.generated.document.DocumentConstants;
+import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.components.SearchOpenService;
 import com.caimei365.commodity.mapper.SearchMapper;
 import com.caimei365.commodity.model.ResponseJson;
@@ -15,7 +16,6 @@ import com.caimei365.commodity.model.search.*;
 import com.caimei365.commodity.service.SearchIndexService;
 import com.caimei365.commodity.service.SearchQueryService;
 import com.caimei365.commodity.utils.ImageUtils;
-import com.caimei365.commodity.components.PriceUtilService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -46,6 +46,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
     private SearchQueryService searchQueryService;
     @Resource
     private PriceUtilService priceUtilService;
+
     /**
      * 初始化(添加)所有索引
      *
@@ -61,7 +62,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         if (productCount > productRecord) {
             log.warn("【初始化】批量添加商品文档异常,部分商品未添加。");
         }
-        log.info(">>>>>>【商品】应加:"+productCount+",实加:"+productRecord);
+        log.info(">>>>>>【商品】应加:" + productCount + ",实加:" + productRecord);
         mainId += productRecord;
         // 从数据库获取供应商数量
         Integer supplierCount = searchMapper.findSupplierCount();
@@ -69,7 +70,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         if (supplierCount > supplierRecord) {
             log.warn("【初始化】批量添加供应商文档异常,部分供应商未添加。");
         }
-        log.info(">>>>>>【供应商】应加:"+supplierCount+",实加:"+supplierRecord);
+        log.info(">>>>>>【供应商】应加:" + supplierCount + ",实加:" + supplierRecord);
         mainId += supplierRecord;
         // 从数据库获取项目仪器数量
         Integer equipmentCount = searchMapper.findEquipmentCount();
@@ -77,7 +78,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         if (equipmentCount > equipmentRecord) {
             log.warn("批量添加项目仪器文档异常,部分项目仪器未添加。");
         }
-        log.info(">>>>>>【项目仪器】应加:"+equipmentCount+",实加:"+equipmentRecord);
+        log.info(">>>>>>【项目仪器】应加:" + equipmentCount + ",实加:" + equipmentRecord);
         mainId += equipmentRecord;
         // 从数据库获取文章数量
         Integer articleCount = searchMapper.findArticleCount();
@@ -85,7 +86,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         if (articleCount > articleRecord) {
             log.warn("批量添加文章文档异常,部分文章未添加。");
         }
-        log.info(">>>>>>【文章】应加:"+articleCount+",实加:"+articleRecord);
+        log.info(">>>>>>【文章】应加:" + articleCount + ",实加:" + articleRecord);
         mainId += articleRecord;
 
         log.info(">>>>>>>>>>>>添加总记录:" + mainId);
@@ -94,6 +95,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 更新所有商品
+     *
      * @return json
      */
     @Override
@@ -112,12 +114,13 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         if (productCount > productRecord) {
             log.warn("批量添加商品文档异常,部分商品未添加。");
         }
-        log.info(">>>>>>【商品】应加:"+productCount+",实加:"+productRecord);
+        log.info(">>>>>>【商品】应加:" + productCount + ",实加:" + productRecord);
         return ResponseJson.success(productRecord);
     }
 
     /**
      * 更新所有供应商
+     *
      * @return json
      */
     @Override
@@ -141,6 +144,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 更新所有项目仪器
+     *
      * @return json
      */
     @Override
@@ -165,6 +169,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 更新所有文章
+     *
      * @return json
      */
     @Override
@@ -188,16 +193,22 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 根据商品Id更新
+     *
      * @param productId int
      * @return json
      */
     @Override
-    public ResponseJson<Integer> updateProductIndexById(Integer productId){
+    public ResponseJson<Integer> updateProductIndexById(Integer productId) {
         if (null == productId) {
             log.info(">>>更新商品,商品Id不能为空!");
             return ResponseJson.error("商品Id不能为空", null);
         }
         ProductDO product = searchMapper.searchProductById(productId);
+        List<Integer> promotionIds = searchMapper.findPromotionId(product.getP_id());
+        if (promotionIds != null && promotionIds.size() > 0) {
+            product.setP_promotions_id(promotionIds.get(0));
+        }
+        // product p_promotions_id
         if (null != product) {
             // 定义星范商品数据
             List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
@@ -213,7 +224,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             Integer mainId = searchQueryService.getIdByDocId("product", productId);
             if (mainId == -1) {
                 mainId = searchQueryService.getIdByDocId("", null);
-                mainId = mainId == -1 ? 0 : mainId+1;
+                mainId = mainId == -1 ? 0 : mainId + 1;
                 //  新增主文档, 商品:type=1
                 setMainDocument(1, mainList, mainId, productId);
             }
@@ -221,7 +232,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 查询商品数量是否唯一,不唯一则删除后更新索引
                 Integer count = searchQueryService.getCountByDocId("product", productId);
                 if (count > 1) {
-                    log.info("商品重复,重复商品>>>>>>>>>>>" + productId +"重复数量:" + count);
+                    log.info("商品重复,重复商品>>>>>>>>>>>" + productId + "重复数量:" + count);
                     // 删除主文档记录
                     deleteDocByTypeId("id", mainId, "search_main");
                     return updateProductIndexById(productId);
@@ -253,8 +264,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             return ResponseJson.error("供应商Id不能为空", null);
         }
         SupplierDO supplier = searchMapper.searchSupplierById(shopId);
-        if(null != supplier){
-             // 定义供应商文档数据
+        if (null != supplier) {
+            // 定义供应商文档数据
             List<DocumentDTO<SupplierDO>> supplierList = new ArrayList<>();
             // 供应商文档设值
             setSupplierDocument(supplierList, supplier);
@@ -264,7 +275,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             Integer mainId = searchQueryService.getIdByDocId("shop", shopId);
             if (mainId == -1) {
                 mainId = searchQueryService.getIdByDocId("", null);
-                mainId = mainId == -1 ? 0 : mainId+1;
+                mainId = mainId == -1 ? 0 : mainId + 1;
                 //  新增主文档, 供应商:type=2
                 setMainDocument(2, mainList, mainId, shopId);
             }
@@ -272,7 +283,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 查询供应商是否唯一,不唯一则删除后重新更新索引
                 Integer count = searchQueryService.getCountByDocId("shop", shopId);
                 if (count > 1) {
-                    log.info("供应商重复,重复供应商>>>>>>>>>>>" + shopId +"重复数量:" + count);;
+                    log.info("供应商重复,重复供应商>>>>>>>>>>>" + shopId + "重复数量:" + count);
+                    ;
                     // 删除主文档记录
                     deleteDocByTypeId("id", mainId, "search_main");
                     return updateSupplierIndexById(shopId);
@@ -286,7 +298,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 log.error("添加供应商文档异常:" + e);
                 return ResponseJson.error("添加供应商文档异常", null);
             }
-        }else{
+        } else {
             return deleteSupplierIndexById(shopId);
         }
     }
@@ -304,7 +316,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             return ResponseJson.error("项目仪器Id不能为空", null);
         }
         EquipmentDO equipment = searchMapper.searchEquipmentById(equipmentId);
-        if(null != equipment){
+        if (null != equipment) {
             // 定义项目仪器文档数据
             List<DocumentDTO<EquipmentDO>> equipmentList = new ArrayList<>();
             // 项目仪器文档设值
@@ -315,7 +327,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             Integer mainId = searchQueryService.getIdByDocId("equipment", equipmentId);
             if (mainId == -1) {
                 mainId = searchQueryService.getIdByDocId("", null);
-                mainId = mainId == -1 ? 0 : mainId+1;
+                mainId = mainId == -1 ? 0 : mainId + 1;
                 // 新增主文档, 项目仪器:type=3
                 setMainDocument(3, mainList, mainId, equipmentId);
             }
@@ -323,7 +335,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 查询项目仪器数量是否唯一,不唯一则删除后重新更新索引
                 Integer count = searchQueryService.getCountByDocId("equipment", equipmentId);
                 if (count > 1) {
-                    log.info("项目仪器重复,重复项目仪器>>>>>>>>>>>" + equipmentId+"重复数量:" + count);
+                    log.info("项目仪器重复,重复项目仪器>>>>>>>>>>>" + equipmentId + "重复数量:" + count);
                     // 删除主文档记录
                     deleteDocByTypeId("id", mainId, "search_main");
                     return updateEquipmentIndexById(equipmentId);
@@ -337,7 +349,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 log.error("添加项目仪器文档异常:" + e);
                 return ResponseJson.error("添加项目仪器文档异常", null);
             }
-        }else{
+        } else {
             return deleteEquipmentIndexById(equipmentId);
         }
     }
@@ -355,7 +367,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             return ResponseJson.error("文章Id不能为空", null);
         }
         ArticleDO article = searchMapper.searchArticleById(articleId);
-        if(null != article){
+        if (null != article) {
             // 定义文章文档数据
             List<DocumentDTO<ArticleDO>> articleList = new ArrayList<>();
             // 文章文档设值
@@ -366,7 +378,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             Integer mainId = searchQueryService.getIdByDocId("article", articleId);
             if (mainId == -1) {
                 mainId = searchQueryService.getIdByDocId("", null);
-                mainId = mainId == -1 ? 0 : mainId+1;
+                mainId = mainId == -1 ? 0 : mainId + 1;
                 // 新增主文档, 文章 type=4
                 setMainDocument(4, mainList, mainId, articleId);
             }
@@ -375,7 +387,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 查询文章数量是否唯一,不唯一则删除后重新更新索引
                 Integer count = searchQueryService.getCountByDocId("article", articleId);
                 if (count > 1) {
-                    log.info("文章重复,重复文章>>>>>>>>>>>" + articleId +"重复数量:" + count);
+                    log.info("文章重复,重复文章>>>>>>>>>>>" + articleId + "重复数量:" + count);
                     // 删除主文档记录
                     deleteDocByTypeId("id", mainId, "search_main");
                     return updateArticleIndexById(articleId);
@@ -389,7 +401,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 log.error("添加文章文档异常:" + e);
                 return ResponseJson.error("添加文章文档异常", null);
             }
-        }else{
+        } else {
             return deleteArticleIndexById(articleId);
         }
     }
@@ -406,7 +418,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 根据商品ID获取星范ID
         Integer mallId = searchMapper.findMallIdByProductId(productId);
         try {
-            if (null != mallId){
+            if (null != mallId) {
                 deleteDocByTypeId("m_id", mallId, "search_product_mall");
             }
             deleteDocByTypeId("p_id", productId, "search_product");
@@ -505,11 +517,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 根据文档类型key与类型Id删除
-     * @param type 类型key
-     * @param id 类型Id
+     *
+     * @param type  类型key
+     * @param id    类型Id
      * @param table 表名
      * @throws OpenSearchClientException exp
-     * @throws OpenSearchException exp
+     * @throws OpenSearchException       exp
      */
     private void deleteDocByTypeId(String type, Integer id, String table) throws OpenSearchClientException, OpenSearchException {
         // 删除文档只需要设置需删除文档主键值即可
@@ -519,19 +532,18 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         String deleteJsonStr = setDeleteDocument(deleteDoc);
         // 推送到阿里云
         String deleteResult = searchOpenService.pushDocument(deleteJsonStr, table);
-        log.info(">>>>>>>>>>>>>>>delete document: 【"+ table +"("+ type +":" + id + "):" + deleteResult + "】");
+        log.info(">>>>>>>>>>>>>>>delete document: 【" + table + "(" + type + ":" + id + "):" + deleteResult + "】");
     }
 
 
-
-
     /**
      * 批量删除失效商品
+     *
      * @param invalidCount int
      */
     private void batchDeleteProductDoc(Integer invalidCount) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
         // 定义返回结果
         for (int i = 1; i <= loop; i++) {
             PageHelper.startPage(i, 100);
@@ -551,7 +563,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 根据ID(主键)删除文档
                 deleteDoc.put("p_id", invalidId);
                 Integer mainId = searchQueryService.getIdByDocId("product", invalidId);
-                if (mainId > -1){
+                if (mainId > -1) {
                     deleteDoc.put("id", mainId);
                 }
             }
@@ -568,18 +580,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 设置所有商品数据
-     * @param mainId int
+     *
+     * @param mainId       int
      * @param productCount int
-     * @param initFlag int
+     * @param initFlag     int
      * @return int
      */
     private Integer setAllProductData(Integer mainId, Integer productCount, boolean initFlag) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(productCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(productCount.doubleValue() / 100);
         Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
         if (!initFlag) {
             Integer record = searchQueryService.getRecordByDocType("product");
-            int l = (int)Math.ceil(record.doubleValue() / 500);
+            int l = (int) Math.ceil(record.doubleValue() / 500);
             for (int i = 1; i <= l; i++) {
                 Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("product", i, 500);
                 idsMap.putAll(idsTemp);
@@ -591,6 +604,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             PageHelper.startPage(i, 100);
             // 获取数据库商品列表的分页数据
             List<ProductDO> dbList = searchMapper.searchProductList();
+
             // 定义星范商品数据
             List<DocumentDTO<MallProductDO>> mallProductList = new ArrayList<>();
             // 定义商品文档数据
@@ -606,19 +620,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 setProductDocument(productList, product, null);
                 // 主文档设值
                 Integer productId = product.getP_id();
-                if(initFlag){
-                    productMainId = mainId+1;
-                    mainId+=1;
-                }else{
+                if (initFlag) {
+                    productMainId = mainId + 1;
+                    mainId += 1;
+                } else {
                     Integer tempId = idsMap.get(productId);
-                    if (null==tempId || tempId<=0){
+                    if (null == tempId || tempId <= 0) {
                         tempId = searchQueryService.getIdByDocId("product", productId);
                     }
-                    if (null!=tempId && tempId>0) {
+                    if (null != tempId && tempId > 0) {
                         productMainId = tempId;
-                    }else{
-                        productMainId = mainId+1;
-                        mainId+=1;
+                    } else {
+                        productMainId = mainId + 1;
+                        mainId += 1;
                     }
                 }
                 // 商品文档 type=1
@@ -639,14 +653,15 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 推送所有商品
-     * @param mainList list
-     * @param productList list
+     *
+     * @param mainList        list
+     * @param productList     list
      * @param mallProductList list
      * @throws OpenSearchClientException exp
-     * @throws OpenSearchException exp
+     * @throws OpenSearchException       exp
      */
     private void pushProductDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ProductDO>> productList, List<DocumentDTO<MallProductDO>> mallProductList) throws OpenSearchClientException, OpenSearchException {
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 将主文档列表转换成Json串,并推送到阿里云
             String mainDocStr = new JSONArray(mainList).toString();
             String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
@@ -655,7 +670,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 将商品文档推送到阿里云
         String productDocStr = new JSONArray(productList).toString();
         String productResult = searchOpenService.pushDocument(productDocStr, "search_product");
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 新增
             log.info(">>>>>>>>>>>>>>>add document: 【search_product(" + productList.size() + "个):" + productResult + "】");
         } else {
@@ -663,7 +678,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             log.info(">>>>>>>>>>>>>>>update document: 【search_product(" + productList.size() + "个):" + productResult + "】");
         }
         // 将星范商品推送到阿里云
-        if (mallProductList.size()>0) {
+        if (mallProductList.size() > 0) {
             String mallProductStr = new JSONArray(mallProductList).toString();
             String mallProductResult = searchOpenService.pushDocument(mallProductStr, "search_product_mall");
             log.info(">>>>>>>>>>>>>>>add document: 【search_product_mall(" + mallProductList.size() + "):" + mallProductResult + "】");
@@ -672,11 +687,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 批量删除失效供应商
+     *
      * @param invalidCount int
      */
     private void batchDeleteSupplierDoc(Integer invalidCount) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
         // 定义返回结果
         for (int i = 1; i <= loop; i++) {
             PageHelper.startPage(i, 100);
@@ -688,7 +704,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 根据ID(主键)删除文档
                 deleteDoc.put("s_id", invalidId);
                 Integer mainId = searchQueryService.getIdByDocId("shop", invalidId);
-                if (mainId > -1){
+                if (mainId > -1) {
                     deleteDoc.put("id", mainId);
                 }
             }
@@ -705,18 +721,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 设置所有供应商数据
-     * @param mainId int
+     *
+     * @param mainId        int
      * @param supplierCount int
-     * @param initFlag int
+     * @param initFlag      int
      * @return int
      */
     private Integer setAllSupplierData(Integer mainId, Integer supplierCount, boolean initFlag) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(supplierCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(supplierCount.doubleValue() / 100);
         Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
         if (!initFlag) {
             Integer record = searchQueryService.getRecordByDocType("shop");
-            int l = (int)Math.ceil(record.doubleValue() / 500);
+            int l = (int) Math.ceil(record.doubleValue() / 500);
             for (int i = 1; i <= l; i++) {
                 Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("shop", i, 500);
                 idsMap.putAll(idsTemp);
@@ -734,24 +751,24 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
 
             int supplierMainId;
-            for (SupplierDO supplier: dbList){
+            for (SupplierDO supplier : dbList) {
                 // 供应商文档设值
                 setSupplierDocument(supplierList, supplier);
                 // 主文档设值
                 Integer shopId = supplier.getS_id();
-                if(initFlag){
-                    supplierMainId = mainId+1;
-                    mainId+=1;
-                }else{
+                if (initFlag) {
+                    supplierMainId = mainId + 1;
+                    mainId += 1;
+                } else {
                     Integer tempId = idsMap.get(shopId);
-                    if (null==tempId || tempId<=0){
+                    if (null == tempId || tempId <= 0) {
                         tempId = searchQueryService.getIdByDocId("shop", shopId);
                     }
-                    if (null!=tempId && tempId>0) {
+                    if (null != tempId && tempId > 0) {
                         supplierMainId = tempId;
-                    }else{
-                        supplierMainId = mainId+1;
-                        mainId+=1;
+                    } else {
+                        supplierMainId = mainId + 1;
+                        mainId += 1;
                     }
                 }
                 // 供应商文档 type=2
@@ -772,13 +789,14 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 推送所有供应商
-     * @param mainList list
+     *
+     * @param mainList     list
      * @param supplierList list
      * @throws OpenSearchClientException exp
-     * @throws OpenSearchException exp
+     * @throws OpenSearchException       exp
      */
     private void pushSupplierDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<SupplierDO>> supplierList) throws OpenSearchClientException, OpenSearchException {
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 将主文档列表转换成Json串,并推送到阿里云
             String mainDocStr = new JSONArray(mainList).toString();
             String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
@@ -787,7 +805,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 将商品文档推送到阿里云
         String supplierDocStr = new JSONArray(supplierList).toString();
         String supplierResult = searchOpenService.pushDocument(supplierDocStr, "search_supplier");
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 新增
             log.info(">>>>>>>>>>>>>>>add document: 【search_supplier(" + supplierList.size() + "个):" + supplierResult + "】");
         } else {
@@ -798,11 +816,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 批量删除失效项目仪器
+     *
      * @param invalidCount int
      */
     private void batchDeleteEquipmentDoc(Integer invalidCount) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
         // 定义返回结果
         for (int i = 1; i <= loop; i++) {
             PageHelper.startPage(i, 100);
@@ -814,7 +833,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 根据ID(主键)删除文档
                 deleteDoc.put("e_id", invalidId);
                 Integer mainId = searchQueryService.getIdByDocId("equipment", invalidId);
-                if (mainId > -1){
+                if (mainId > -1) {
                     deleteDoc.put("id", mainId);
                 }
             }
@@ -831,18 +850,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 设置所有项目仪器数据
-     * @param mainId int
+     *
+     * @param mainId         int
      * @param equipmentCount int
-     * @param initFlag int
+     * @param initFlag       int
      * @return int
      */
     private Integer setAllEquipmentData(Integer mainId, Integer equipmentCount, boolean initFlag) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(equipmentCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(equipmentCount.doubleValue() / 100);
         Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
         if (!initFlag) {
             Integer record = searchQueryService.getRecordByDocType("equipment");
-            int l = (int)Math.ceil(record.doubleValue() / 500);
+            int l = (int) Math.ceil(record.doubleValue() / 500);
             for (int i = 1; i <= l; i++) {
                 Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("equipment", i, 500);
                 idsMap.putAll(idsTemp);
@@ -860,24 +880,24 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
 
             int equipmentMainId;
-            for (EquipmentDO equipment: dbList){
+            for (EquipmentDO equipment : dbList) {
                 // 项目仪器文档设值
                 setEquipmentDocument(equipmentList, equipment);
                 // 主文档设值
                 Integer equipmentId = equipment.getE_id();
-                if(initFlag){
-                    equipmentMainId = mainId+1;
-                    mainId+=1;
-                }else{
+                if (initFlag) {
+                    equipmentMainId = mainId + 1;
+                    mainId += 1;
+                } else {
                     Integer tempId = idsMap.get(equipmentId);
-                    if (null==tempId || tempId<=0){
+                    if (null == tempId || tempId <= 0) {
                         tempId = searchQueryService.getIdByDocId("equipment", equipmentId);
                     }
-                    if (null!=tempId && tempId>0) {
+                    if (null != tempId && tempId > 0) {
                         equipmentMainId = tempId;
-                    }else{
-                        equipmentMainId = mainId+1;
-                        mainId+=1;
+                    } else {
+                        equipmentMainId = mainId + 1;
+                        mainId += 1;
                     }
                 }
                 // 项目仪器文档 type=3
@@ -898,13 +918,14 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 推送所有项目仪器
-     * @param mainList list
+     *
+     * @param mainList      list
      * @param equipmentList list
      * @throws OpenSearchClientException exp
-     * @throws OpenSearchException exp
+     * @throws OpenSearchException       exp
      */
     private void pushEquipmentDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<EquipmentDO>> equipmentList) throws OpenSearchClientException, OpenSearchException {
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 将主文档列表转换成Json串,并推送到阿里云
             String mainDocStr = new JSONArray(mainList).toString();
             String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
@@ -913,7 +934,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 将商品文档推送到阿里云
         String equipmentDocStr = new JSONArray(equipmentList).toString();
         String equipmentResult = searchOpenService.pushDocument(equipmentDocStr, "search_equipment");
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 新增
             log.info(">>>>>>>>>>>>>>>add document: 【search_equipment(" + equipmentList.size() + "个):" + equipmentResult + "】");
         } else {
@@ -924,11 +945,12 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 批量删除失效文章
+     *
      * @param invalidCount int
      */
     private void batchDeleteArticleDoc(Integer invalidCount) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(invalidCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(invalidCount.doubleValue() / 100);
         // 定义返回结果
         for (int i = 1; i <= loop; i++) {
             PageHelper.startPage(i, 100);
@@ -940,7 +962,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
                 // 根据ID(主键)删除文档
                 deleteDoc.put("a_id", invalidId);
                 Integer mainId = searchQueryService.getIdByDocId("article", invalidId);
-                if (mainId > -1){
+                if (mainId > -1) {
                     deleteDoc.put("id", mainId);
                 }
             }
@@ -957,18 +979,19 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 设置所有文章数据
-     * @param mainId int
+     *
+     * @param mainId       int
      * @param articleCount int
-     * @param initFlag int
+     * @param initFlag     int
      * @return int
      */
     private Integer setAllArticleData(Integer mainId, Integer articleCount, boolean initFlag) {
         // 批量推送,每100条推送一次
-        int loop = (int)Math.ceil(articleCount.doubleValue() / 100);
+        int loop = (int) Math.ceil(articleCount.doubleValue() / 100);
         Map<Integer, Integer> idsMap = Maps.newLinkedHashMap();
         if (!initFlag) {
             Integer record = searchQueryService.getRecordByDocType("article");
-            int l = (int)Math.ceil(record.doubleValue() / 500);
+            int l = (int) Math.ceil(record.doubleValue() / 500);
             for (int i = 1; i <= l; i++) {
                 Map<Integer, Integer> idsTemp = searchQueryService.getMainIdsByDocType("article", i, 500);
                 idsMap.putAll(idsTemp);
@@ -986,24 +1009,24 @@ public class SearchIndexServiceImpl implements SearchIndexService {
             List<DocumentDTO<MainDO>> mainList = new ArrayList<>();
 
             int articleMainId;
-            for (ArticleDO article: dbList){
+            for (ArticleDO article : dbList) {
                 // 文章文档设值
                 setArticleDocument(articleList, article);
                 // 主文档设值
                 Integer articleId = article.getA_id();
-                if(initFlag){
-                    articleMainId = mainId+1;
-                    mainId+=1;
-                }else{
+                if (initFlag) {
+                    articleMainId = mainId + 1;
+                    mainId += 1;
+                } else {
                     Integer tempId = idsMap.get(articleId);
-                    if (null==tempId || tempId<=0){
+                    if (null == tempId || tempId <= 0) {
                         tempId = searchQueryService.getIdByDocId("article", articleId);
                     }
-                    if (null!=tempId && tempId>0) {
+                    if (null != tempId && tempId > 0) {
                         articleMainId = tempId;
-                    }else{
-                        articleMainId = mainId+1;
-                        mainId+=1;
+                    } else {
+                        articleMainId = mainId + 1;
+                        mainId += 1;
                     }
                 }
                 // 文章文档 type=4
@@ -1024,13 +1047,14 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 推送所有文章数据
-     * @param mainList list
+     *
+     * @param mainList    list
      * @param articleList list
      * @throws OpenSearchClientException exp
-     * @throws OpenSearchException exp
+     * @throws OpenSearchException       exp
      */
     private void pushArticleDocument(List<DocumentDTO<MainDO>> mainList, List<DocumentDTO<ArticleDO>> articleList) throws OpenSearchClientException, OpenSearchException {
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 将主文档列表转换成Json串,并推送到阿里云
             String mainDocStr = new JSONArray(mainList).toString();
             String mainResult = searchOpenService.pushDocument(mainDocStr, "search_main");
@@ -1039,7 +1063,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 将商品文档推送到阿里云
         String articleDocStr = new JSONArray(articleList).toString();
         String articleResult = searchOpenService.pushDocument(articleDocStr, "search_article");
-        if (mainList.size()>0) {
+        if (mainList.size() > 0) {
             // 新增
             log.info(">>>>>>>>>>>>>>>add document: 【search_article(" + articleList.size() + "个):" + articleResult + "】");
         } else {
@@ -1050,6 +1074,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 删除文档设值
+     *
      * @return docsJson
      */
     private String setDeleteDocument(Map<String, Object> deleteDoc) {
@@ -1066,7 +1091,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
      * 商品星范商品设值
      *
      * @param mallProductList list
-     * @param productId int
+     * @param productId       int
      */
     private Integer setMallProductDocument(List<DocumentDTO<MallProductDO>> mallProductList, Integer productId) {
         // 是否是星范商品
@@ -1093,9 +1118,10 @@ public class SearchIndexServiceImpl implements SearchIndexService {
 
     /**
      * 商品文档设值
-     *  @param productList list
-     * @param product ProductDO
-     * @param mallId int
+     *
+     * @param productList list
+     * @param product     ProductDO
+     * @param mallId      int
      */
     private void setProductDocument(List<DocumentDTO<ProductDO>> productList, ProductDO product, Integer mallId) {
         String imagePath = ImageUtils.getImageURL("product", product.getP_image(), 0, domain);
@@ -1106,6 +1132,11 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         // 价格等级
         product.setP_price_grade(priceUtilService.getPriceGrade(product.getP_price().doubleValue()));
         DocumentDTO<ProductDO> productDoc = new DocumentDTO<>();
+        // 设促销id
+        List<Integer> promotionIds = searchMapper.findPromotionId(product.getP_id());
+        if (promotionIds != null && promotionIds.size() > 0) {
+            product.setP_promotions_id(promotionIds.get(0));
+        }
         productDoc.setCmd("add");
         productDoc.setFields(product);
         productList.add(productDoc);
@@ -1115,7 +1146,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
      * 供应商文档设值
      *
      * @param supplierList list
-     * @param supplier supplierDO
+     * @param supplier     supplierDO
      */
     private void setSupplierDocument(List<DocumentDTO<SupplierDO>> supplierList, SupplierDO supplier) {
         String imagePath = ImageUtils.getImageURL("supplierLogo", supplier.getS_logo(), 0, domain);
@@ -1132,7 +1163,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
      * 项目仪器文档设值
      *
      * @param equipmentList list
-     * @param equipment EquipmentDO
+     * @param equipment     EquipmentDO
      */
     private void setEquipmentDocument(List<DocumentDTO<EquipmentDO>> equipmentList, EquipmentDO equipment) {
         // 搜索供应商文档数据
@@ -1147,15 +1178,15 @@ public class SearchIndexServiceImpl implements SearchIndexService {
      * 文章文档设值
      *
      * @param articleList list
-     * @param article ArticleDO
+     * @param article     ArticleDO
      */
     private void setArticleDocument(List<DocumentDTO<ArticleDO>> articleList, ArticleDO article) {
         String imagePath = ImageUtils.getImageURL("", article.getA_image(), 0, domain);
         // 搜索供应商文档数据
         String[] labelTexts = article.getA_label().split(",");
-        if(labelTexts.length > 0){
+        if (labelTexts.length > 0) {
             boolean notEmpty = StringUtil.isNotEmpty(labelTexts[0]);
-            if(notEmpty){
+            if (notEmpty) {
                 List<Integer> labelIdList = searchMapper.findLabelIdsByName(labelTexts);
                 Integer[] labelIds = labelIdList.toArray(new Integer[labelTexts.length]);
                 article.setA_label_text(labelTexts);
@@ -1174,8 +1205,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
      * 商品主文档设值
      *
      * @param mainList list
-     * @param mainId int
-     * @param docId int
+     * @param mainId   int
+     * @param docId    int
      */
     private void setMainDocument(Integer type, List<DocumentDTO<MainDO>> mainList, Integer mainId, Integer docId) {
         // 搜索主文档数据

+ 169 - 52
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -6,18 +6,18 @@ import com.aliyun.opensearch.sdk.dependencies.org.json.JSONObject;
 import com.aliyun.opensearch.sdk.generated.commons.OpenSearchClientException;
 import com.aliyun.opensearch.sdk.generated.commons.OpenSearchException;
 import com.aliyun.opensearch.sdk.generated.search.SearchParams;
+import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.components.SearchOpenService;
 import com.caimei365.commodity.mapper.PageMapper;
 import com.caimei365.commodity.mapper.SearchMapper;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.po.SearchHistoryPo;
+import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.HotSearchVo;
 import com.caimei365.commodity.model.vo.PaginationVo;
-import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.service.SearchProductService;
 import com.caimei365.commodity.utils.AppletsLinkUtil;
 import com.caimei365.commodity.utils.Json2PojoUtil;
-import com.caimei365.commodity.components.PriceUtilService;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -48,24 +49,52 @@ public class SearchProductServiceImpl implements SearchProductService {
     private SearchOpenService searchOpenService;
     @Resource
     private PriceUtilService priceUtilService;
+
     /**
      * 根据关键词搜索商品
      *
-     * @param keyword   搜索关键字
-     * @param pageNum   页码
-     * @param pageSize  每页数量
-     * @param sortField 排序字段
-     * @param sortType  升降序0/1
+     * @param keyword       搜索关键字
+     * @param brandIds      品牌id字符串,逗号隔开
+     * @param newFlag       查询新品标记
+     * @param promotionFlag 查询促销活动标记
+     * @param pageNum       页码
+     * @param pageSize      每页数量
+     * @param sortField     排序字段
+     * @param sortType      升降序0/1
      * @return JsonStr(list)
      */
     @Override
-    public ResponseJson<String> queryProductByKeyword(String keyword, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType) {
+    public ResponseJson<String> queryProductByKeyword(String keyword, String brandIds, Integer identity, Integer newFlag, Integer promotionFlag,
+                                                      int pageNum, int pageSize, String sortField, Integer sortType) {
         String queryStr = "product:'" + keyword + "'";
+        String filter = "";
         if (StringUtils.isEmpty(keyword)) {
             queryStr = "p_all:'1'";
         }
+        if (!StringUtils.isEmpty(brandIds)) {
+            if (brandIds.contains(",")) {
+                String[] split = brandIds.split(",");
+                for (int i = 0; i < split.length; i++) {
+                    queryStr += " OR p_brand:'" + split[i] + "'";
+                }
+            } else {
+                queryStr += " AND p_brand:'" + brandIds + "'";
+            }
+        }
+        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 += "p_time > " + time;
+        }
+        if (promotionFlag == 1) {
+//            p_promotions_id > 0
+            filter += "AND p_promotions_id > 0";
+        }
         // 阿里云搜索
-        ResponseJson<String> result = queryProduct(queryStr, "", identity, pageNum, pageSize, sortField, sortType);
+        ResponseJson<String> result = queryProduct(queryStr, filter, identity, pageNum, pageSize, sortField, sortType);
         if (0 == result.getCode()) {
             return result;
         } else {
@@ -74,6 +103,77 @@ public class SearchProductServiceImpl implements SearchProductService {
         }
     }
 
+
+    @Override
+    public ResponseJson<List<HashMap<String, Object>>> queryBrand(String keyword, Integer id, Integer idType, Integer newFlag, Integer promotionFlag, Integer identity) {
+        String queryStr = "";
+        String filter = "";
+        if (!StringUtils.isEmpty(keyword) && idType == null && id == null) {
+            queryStr = "product:'" + keyword + "'";
+        } else if (StringUtils.isEmpty(keyword) && idType != null && id != null) {
+            if (idType == 1) {
+                queryStr = "p_bigtype:'" + id + "'";
+            } else if (idType == 2) {
+                queryStr = "p_smalltype:'" + id + "'";
+            } else if (idType == 3) {
+                queryStr = "p_tinytype:'" + id + "'";
+            }
+        } else if ((!StringUtils.isEmpty(keyword)) && idType != null && id != null) {
+            if (idType == 1) {
+                queryStr = "product:'" + keyword + "' AND " + "p_bigtype:'" + id + "'";
+            }
+            if (idType == 2) {
+                queryStr = "product:'" + keyword + "' AND " + "p_smalltype:'" + id + "'";
+            }
+            if (idType == 3) {
+                queryStr = "product:'" + keyword + "' AND " + "p_tinytype:'" + id + "'";
+            }
+        } else {
+            queryStr = "p_all:'1'";
+        }
+        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 += "p_time > " + time;
+        }
+        if (promotionFlag == 1) {
+//            p_promotions_id > 0
+            filter += "AND p_promotions_id > 0";
+        }
+        SearchParams searchParams = searchOpenService.getParams(queryStr, identity, filter);
+        ResponseJson<List<HashMap<String, Object>>> result = getBrandResult(searchParams, queryStr);
+        return result;
+    }
+
+    private ResponseJson<List<HashMap<String, Object>>> getBrandResult(SearchParams searchParams, String queryStr) {
+        ResponseJson<List<HashMap<String, Object>>> result;
+        try {
+            JSONObject resultJson = searchOpenService.getResultJsonObject(queryStr, searchParams);
+            List<HashMap<String, Object>> maps = new ArrayList<>();
+            if (1 == resultJson.getInt("status")) {
+                JSONArray pageData = resultJson.getJSONArray("items");
+                for (int i = 0; i < pageData.length(); i++) {
+                    HashMap<String, Object> map = new HashMap<>();
+                    JSONObject json = pageData.getJSONObject(i);
+                    map.put("id", json.getInt("p_brand_id"));
+                    map.put("name", json.getString("p_brand_name"));
+                    maps.add(map);
+                }
+                // 阿里云查询出json转换成商品pojo
+                result = ResponseJson.success(maps);
+            } else {
+                result = ResponseJson.error("未查询到文档记录", null);
+            }
+        } catch (Exception e) {
+            log.error("查询文档异常:" + e.getMessage());
+            result = ResponseJson.error("查询文档异常:" + e.getMessage(), null);
+        }
+        return result;
+    }
+
     /**
      * 根据分类Id搜索商品
      *
@@ -87,8 +187,9 @@ public class SearchProductServiceImpl implements SearchProductService {
      * @return JsonStr(list)
      */
     @Override
-    public ResponseJson<String> queryProductByType(Integer id, Integer idType, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType) {
+    public ResponseJson<String> queryProductByType(Integer id, Integer idType, Integer identity, Integer newFlag, Integer promotionFlag, int pageNum, int pageSize, String sortField, Integer sortType) {
         String queryStr = "";
+        String filter = "";
         if (idType == 1) {
             queryStr = "p_bigtype:'" + id + "'";
         } else if (idType == 2) {
@@ -98,12 +199,27 @@ public class SearchProductServiceImpl implements SearchProductService {
         } else {
             return ResponseJson.error("idType参数错误", null);
         }
-        int requestSize = pageNum*pageSize;
+        int requestSize = pageNum * pageSize;
         int requestPageSize = requestSize;
-        if (requestSize > SEARCH_MAX_NUM){
-            requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
+        if (requestSize > SEARCH_MAX_NUM) {
+            requestPageSize = (int) Math.floor(SEARCH_MAX_NUM / pageSize) * pageSize;
+        }
+        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 += "p_time > " + time;
+        }
+        if (promotionFlag == 1) {
+            filter += "AND p_promotions_id > 0";
         }
         SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
+        String thisFilter = searchParams.getFilter();
+        if (StringUtils.isNotEmpty(thisFilter)) {
+            thisFilter = thisFilter + " AND " + filter;
+        }
+        searchParams.setFilter(thisFilter);
         // 阿里云搜索(滚动查询)
         ResponseJson<String> result = getScrollProductResult(searchParams, queryStr, requestPageSize, pageNum, pageSize);
         if (0 == result.getCode()) {
@@ -134,10 +250,10 @@ public class SearchProductServiceImpl implements SearchProductService {
     @Override
     public ResponseJson<String> queryProductByClassify(Integer id, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType) {
         String queryStr = "p_classify:'" + id + "'";
-        int requestSize = pageNum*pageSize;
+        int requestSize = pageNum * pageSize;
         int requestPageSize = requestSize;
-        if (requestSize > SEARCH_MAX_NUM){
-            requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
+        if (requestSize > SEARCH_MAX_NUM) {
+            requestPageSize = (int) Math.floor(SEARCH_MAX_NUM / pageSize) * pageSize;
         }
         SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
         // 阿里云搜索(滚动查询)
@@ -164,16 +280,16 @@ public class SearchProductServiceImpl implements SearchProductService {
      */
     @Override
     public ResponseJson<String> querySupplierProduct(Integer id, String keyword, Integer identity, int pageNum, int pageSize, String sortField, Integer sortType) {
-        if (null == id){
-            return ResponseJson.error("请提供供应商id" ,null);
+        if (null == id) {
+            return ResponseJson.error("请提供供应商id", null);
         }
         ResponseJson<String> result;
         if (StringUtils.isEmpty(keyword)) {
             String queryStr = "p_supplier:'" + id + "'";
-            int requestSize = pageNum*pageSize;
+            int requestSize = pageNum * pageSize;
             int requestPageSize = requestSize;
-            if (requestSize > SEARCH_MAX_NUM){
-                requestPageSize = (int) Math.floor(SEARCH_MAX_NUM/pageSize) * pageSize;
+            if (requestSize > SEARCH_MAX_NUM) {
+                requestPageSize = (int) Math.floor(SEARCH_MAX_NUM / pageSize) * pageSize;
             }
             SearchParams searchParams = searchOpenService.getScrollProductParams(queryStr, identity, requestPageSize, sortField, sortType);
             result = getScrollProductResult(searchParams, queryStr, requestPageSize, pageNum, pageSize);
@@ -193,20 +309,20 @@ public class SearchProductServiceImpl implements SearchProductService {
     /**
      * 获取数据库商品
      *
-     * @param num       页码
-     * @param size      每页数量
-     * @param identity  用户身份
-     * @param keyword   关键词
-     * @param shopId    供应商id
-     * @param bigTypeId 一级分类id
+     * @param num         页码
+     * @param size        每页数量
+     * @param identity    用户身份
+     * @param keyword     关键词
+     * @param shopId      供应商id
+     * @param bigTypeId   一级分类id
      * @param smallTypeId 二级分类id
-     * @param tinyTypeId 三级分类id
-     * @param classifyId 小程序运营分类id
-     * @param sortField 排序类型
-     * @param sortType  排序顺序
+     * @param tinyTypeId  三级分类id
+     * @param classifyId  小程序运营分类id
+     * @param sortField   排序类型
+     * @param sortType    排序顺序
      */
     private ResponseJson<String> queryProductFromDatabase(int num, int size, Integer identity, String keyword, Integer shopId,
-                             Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, Integer classifyId, String sortField, Integer sortType){
+                                                          Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, Integer classifyId, String sortField, Integer sortType) {
         PageHelper.startPage(num, size);
         List<ProductListVo> productList = searchMapper.queryProduct(identity, keyword, shopId, bigTypeId, smallTypeId, tinyTypeId, classifyId, sortField, sortType);
         productList.forEach(product -> {
@@ -218,8 +334,8 @@ public class SearchProductServiceImpl implements SearchProductService {
         JSONObject pageObj = new JSONObject();
         pageObj.put("total", total);
         pageObj.put("items", productList);
-        log.info(">>>>>>数据库容错查询: pageSize(" + size +"),pageNum("+size+"),total("+total+")");
-        if (productList.size()>0) {
+        log.info(">>>>>>数据库容错查询: pageSize(" + size + "),pageNum(" + size + "),total(" + total + ")");
+        if (productList.size() > 0) {
             return ResponseJson.success(pageObj.toString());
         } else {
             return ResponseJson.error("未查询到文档记录(数据库)", null);
@@ -237,33 +353,33 @@ public class SearchProductServiceImpl implements SearchProductService {
      */
     private ResponseJson<String> queryProduct(String queryStr, String filter, Integer identity, int num, int size, String sortField, Integer sortType) {
         SearchParams searchParams;
-        int requestSize = num*size;
-        if (requestSize > SEARCH_MAX_NUM){
-            searchParams = searchOpenService.getProductParams(queryStr, filter, identity,num, size, sortField, sortType);
+        int requestSize = num * size;
+        if (requestSize > SEARCH_MAX_NUM) {
+            searchParams = searchOpenService.getProductParams(queryStr, filter, identity, num, size, sortField, sortType);
         } else {
             // 由于阿里云搜索机制问题(分页数据重复),搜索500条以内数据手动分页。
-            searchParams = searchOpenService.getProductParams(queryStr, filter, identity,1, requestSize, sortField, sortType);
+            searchParams = searchOpenService.getProductParams(queryStr, filter, identity, 1, requestSize, sortField, sortType);
         }
         try {
             // 查询推送
             JSONObject result = searchOpenService.getResultJsonObject(queryStr, searchParams);
             if (1 == result.getInt("status")) {
                 int total = result.getInt("total");
-                int totalPage = (int) Math.ceil( (double)total/size);
+                int totalPage = (int) Math.ceil((double) total / size);
                 JSONArray resultArr = result.getJSONArray("items");
                 JSONArray pageData = new JSONArray();
                 if (requestSize > SEARCH_MAX_NUM) {
                     pageData = resultArr;
                 } else {
-                    if (resultArr.length()>0){
-                        int baseNum = (num-1)*size;
-                        for (int i=0; i<size; i++) {
+                    if (resultArr.length() > 0) {
+                        int baseNum = (num - 1) * size;
+                        for (int i = 0; i < size; i++) {
                             int index = baseNum + i;
                             int currentTotal = requestSize;
-                            if (totalPage == num){
+                            if (totalPage == num) {
                                 currentTotal = total;
                             }
-                            if (index<currentTotal){
+                            if (index < currentTotal) {
                                 JSONObject item = resultArr.getJSONObject(index);
                                 pageData.put(i, item);
                             } else {
@@ -277,7 +393,7 @@ public class SearchProductServiceImpl implements SearchProductService {
                 JSONObject pageObj = new JSONObject();
                 pageObj.put("total", total);
                 pageObj.put("items", productList);
-                log.info(">>>>>>pageResult("+queryStr+"): pageSize(" + size +"),pageNum("+num+"),total("+total+")");
+                log.info(">>>>>>pageResult(" + queryStr + "): pageSize(" + size + "),pageNum(" + num + "),total(" + total + ")");
                 return ResponseJson.success(pageObj.toString());
             } else {
                 return ResponseJson.error("未查询到文档记录", null);
@@ -291,18 +407,18 @@ public class SearchProductServiceImpl implements SearchProductService {
     /**
      * 滚动查询
      *
-     * @param searchParams  查询参数对象
-     * @param queryStr      查询类型及参数串
-     * @param requestPageSize  每次scroll数量
-     * @param pageNum       页码
-     * @param pageSize      每页数量
+     * @param searchParams    查询参数对象
+     * @param queryStr        查询类型及参数串
+     * @param requestPageSize 每次scroll数量
+     * @param pageNum         页码
+     * @param pageSize        每页数量
      * @return list
      */
     private ResponseJson<String> getScrollProductResult(SearchParams searchParams, String queryStr, int requestPageSize, int pageNum, int pageSize) {
         ResponseJson<String> result;
         try {
             JSONObject pageObj = searchOpenService.deepPagingForParams(searchParams, queryStr, SEARCH_MAX_NUM, requestPageSize, pageNum, pageSize);
-            if (1 == pageObj.getInt("status")){
+            if (1 == pageObj.getInt("status")) {
                 JSONArray pageData = pageObj.getJSONArray("items");
                 // 阿里云查询出json转换成商品pojo
                 List<ProductListVo> productList = Json2PojoUtil.toProductList(pageData);
@@ -353,7 +469,7 @@ public class SearchProductServiceImpl implements SearchProductService {
             searchMapper.insertSearchHistory(historyRecord);
         }
         int count = searchMapper.getHistoryCount(userId);
-        if (count>10){
+        if (count > 10) {
             // 删除大于10条的历史记录
             searchMapper.deleteSearchHistory(userId);
         }
@@ -387,6 +503,7 @@ public class SearchProductServiceImpl implements SearchProductService {
         return ResponseJson.success(map);
     }
 
+
     private List<HotSearchVo> getHotSearch(Integer typeSort, Integer source) {
         List<Integer> pageIds = pageMapper.getPageIdByTypeSort(typeSort);
         List<HotSearchVo> productHotSearch = new ArrayList<>();

+ 10 - 5
src/main/java/com/caimei365/commodity/utils/Json2PojoUtil.java

@@ -19,12 +19,13 @@ import java.util.List;
 public class Json2PojoUtil {
     /**
      * 阿里云查询出json转换成商品pojo
+     *
      * @param jsonArray json
      * @return ProductListVo
      */
     public static List<ProductListVo> toProductList(JSONArray jsonArray) {
         List<ProductListVo> productList = new ArrayList<>();
-        for (int i=0; i<jsonArray.length(); i++) {
+        for (int i = 0; i < jsonArray.length(); i++) {
             JSONObject json = jsonArray.getJSONObject(i);
             ProductListVo product = new ProductListVo();
             /* 主键Id */
@@ -51,7 +52,8 @@ public class Json2PojoUtil {
             product.setShopId(json.getInt("p_supplier_id"));
             /* 美博会商品活动状态 */
             product.setBeautyActFlag(json.getInt("p_act_flag"));
-
+            /* 品牌id*/
+            product.setBrandId(json.getInt("p_brand_id"));
             productList.add(product);
         }
         return productList;
@@ -59,12 +61,13 @@ public class Json2PojoUtil {
 
     /**
      * 阿里云查询出json转换成供应商pojo
+     *
      * @param jsonArray json
      * @return ShopListVo
      */
     public static List<ShopListVo> toShopList(JSONArray jsonArray) {
         List<ShopListVo> shopList = new ArrayList<>();
-        for (int i=0; i<jsonArray.length(); i++) {
+        for (int i = 0; i < jsonArray.length(); i++) {
             ShopListVo shop = new ShopListVo();
             JSONObject json = jsonArray.getJSONObject(i);
             /* 主键Id */
@@ -94,12 +97,13 @@ public class Json2PojoUtil {
 
     /**
      * 阿里云查询出json转换项目仪器pojo
+     *
      * @param jsonArray json
      * @return ShopListVo
      */
     public static List<EquipmentListVo> toEquipmentList(JSONArray jsonArray) {
         List<EquipmentListVo> equipmentList = new ArrayList<>();
-        for (int i=0; i<jsonArray.length(); i++) {
+        for (int i = 0; i < jsonArray.length(); i++) {
             EquipmentListVo equipment = new EquipmentListVo();
             JSONObject json = jsonArray.getJSONObject(i);
             /* 阿里云索引Id */
@@ -118,12 +122,13 @@ public class Json2PojoUtil {
 
     /**
      * 阿里云查询出json转换成文章pojo
+     *
      * @param jsonArray json
      * @return ShopListVo
      */
     public static List<ArticleListVo> toArticleList(JSONArray jsonArray) {
         List<ArticleListVo> articleList = new ArrayList<>();
-        for (int i=0; i<jsonArray.length(); i++) {
+        for (int i = 0; i < jsonArray.length(); i++) {
             ArticleListVo article = new ArticleListVo();
             JSONObject json = jsonArray.getJSONObject(i);
             /* 阿里云索引Id */

+ 158 - 101
src/main/resources/mapper/SearchMapper.xml

@@ -29,6 +29,7 @@
         p.preferredFlag as p_preferred,
         p.productCategory as p_type,
         p.validFlag as p_valid,
+        DATE_FORMAT(p.ADDTIME,'%Y%m%d') as p_time,
         IFNULL(p.visibility,3) as p_visibility,
         p.price8Text as p_act_flag
     </sql>
@@ -41,7 +42,7 @@
         left join shop as sh on p.shopID = sh.shopID
     </sql>
     <select id="searchProductById" resultType="com.caimei365.commodity.model.search.ProductDO">
-        select <include refid="Search_Product_List"/>, p.productCategory
+        select<include refid="Search_Product_List"/>, p.productCategory
         from product p
         <include refid="Product_Joins"/>
         where p.validFlag in (2,3,9) and p.productCategory = 1
@@ -50,54 +51,61 @@
     <select id="findProductCount" resultType="java.lang.Integer">
         select count(*)
         from product
-        where validFlag in (2,3,9) and productCategory = 1
+        where validFlag in (2, 3, 9)
+          and productCategory = 1
     </select>
     <select id="findProductInvalidCount" resultType="java.lang.Integer">
         select count(*)
         from product
-        where validFlag not in (2,3,9) or productCategory != 1
+        where validFlag not in (2, 3, 9)
+           or productCategory != 1
     </select>
     <select id="findProductInvalidIds" resultType="java.lang.Integer">
         select productID
         from product
-        where validFlag not in (2,3,9) or productCategory != 1
+        where validFlag not in (2, 3, 9)
+           or productCategory != 1
     </select>
     <select id="searchProductList" resultType="com.caimei365.commodity.model.search.ProductDO">
-        select <include refid="Search_Product_List"/>
+        select
+        <include refid="Search_Product_List"/>
         from product p
         <include refid="Product_Joins"/>
         where p.validFlag in (2,3,9) and productCategory = 1
         order by productID desc
     </select>
     <select id="countMallProduct" resultType="java.lang.Integer">
-        select COUNT(*) from cm_mall_organize_products
-        where productID=#{productId} and organizeID=1
+        select COUNT(*)
+        from cm_mall_organize_products
+        where productID = #{productId}
+          and organizeID = 1
     </select>
     <select id="searchMallProductByProductId" resultType="com.caimei365.commodity.model.search.MallProductDO">
-        select
-        m.id as m_id,
-        m.organizeID as m_organize_id,
-        m.productID as m_product_id,
-        m.retailPrice as m_price,
-        m.classifyID as m_classify_id,
-        m.delFlag as m_valid,
-        c.classifyName as m_classify_name
+        select m.id           as m_id,
+               m.organizeID   as m_organize_id,
+               m.productID    as m_product_id,
+               m.retailPrice  as m_price,
+               m.classifyID   as m_classify_id,
+               m.delFlag      as m_valid,
+               c.classifyName as m_classify_name
         from cm_mall_organize_products as m
-        left join cm_mall_products_classify as c on m.classifyId = c.id
-        where m.productID = #{productId} and m.organizeID = 1
+                 left join cm_mall_products_classify as c on m.classifyId = c.id
+        where m.productID = #{productId}
+          and m.organizeID = 1
         limit 1
     </select>
     <select id="getMallLadderPriceFlag" resultType="java.lang.Integer">
         select ladderPriceFlag
         from cm_mall_organize_products
-        where productID = #{productId} and organizeID=1
+        where productID = #{productId}
+          and organizeID = 1
         limit 1
     </select>
     <select id="getMallLowerLadderPrice" resultType="java.lang.Double">
         select MIN(buyPrice)
         from cm_mall_product_ladder_price
         where delFlag = '0'
-        and productId = #{productId}
+          and productId = #{productId}
     </select>
     <select id="findMallIdByProductId" resultType="java.lang.Integer">
         select id
@@ -109,9 +117,9 @@
         select id
         from cm_mall_organize_products
         where productID IN
-          <foreach collection="invalidIds" open="(" separator="," close=")" item="productId">
-              #{productId}
-          </foreach>
+        <foreach collection="invalidIds" open="(" separator="," close=")" item="productId">
+            #{productId}
+        </foreach>
     </select>
 
     <!-- 供应商 -->
@@ -135,20 +143,23 @@
         select count(*)
         from shop
         where (status = 90 or status = 9)
-        and shopID != 1252
+          and shopID != 1252
     </select>
     <select id="findSupplierInvalidCount" resultType="java.lang.Integer">
         select count(*)
         from shop
-        where status not in (90,9) or shopID = 1252
+        where status not in (90, 9)
+           or shopID = 1252
     </select>
     <select id="findSupplierInvalidIds" resultType="java.lang.Integer">
         select shopID
         from shop
-        where status not in (90,9) or shopID = 1252
+        where status not in (90, 9)
+           or shopID = 1252
     </select>
     <select id="searchSupplierList" resultType="com.caimei365.commodity.model.search.SupplierDO">
-        select <include refid="Search_Supplier_List"/>
+        select
+        <include refid="Search_Supplier_List"/>
         from shop as s
         <include refid="Supplier_Joins"/>
         where (status = 90 or status = 9)
@@ -156,7 +167,8 @@
         order by s.sortIndex
     </select>
     <select id="searchSupplierById" resultType="com.caimei365.commodity.model.search.SupplierDO">
-        select <include refid="Search_Supplier_List"/>
+        select
+        <include refid="Search_Supplier_List"/>
         from shop as s
         <include refid="Supplier_Joins"/>
         where (status = 90 or status = 9)
@@ -175,26 +187,31 @@
     <select id="findEquipmentCount" resultType="java.lang.Integer">
         select count(*)
         from cm_page
-        where type = 2 and enabledStatus = 1
+        where type = 2
+          and enabledStatus = 1
     </select>
     <select id="findEquipmentInvalidCount" resultType="java.lang.Integer">
         select count(*)
         from cm_page
-        where type != 2 or enabledStatus != 1
+        where type != 2
+           or enabledStatus != 1
     </select>
     <select id="findEquipmentInvalidIds" resultType="java.lang.Integer">
         select id
         from cm_page
-        where type != 2 or enabledStatus != 1
+        where type != 2
+           or enabledStatus != 1
     </select>
     <select id="searchEquipmentList" resultType="com.caimei365.commodity.model.search.EquipmentDO">
-        select <include refid="Search_Equipment_List"/>
+        select
+        <include refid="Search_Equipment_List"/>
         from cm_page as e
         where e.type = 2 and e.enabledStatus = 1
         order by e.docBoost desc
     </select>
     <select id="searchEquipmentById" resultType="com.caimei365.commodity.model.search.EquipmentDO">
-        select <include refid="Search_Equipment_List"/>
+        select
+        <include refid="Search_Equipment_List"/>
         from cm_page as e
         where e.id = #{equipmentId}
         and e.type = 2 and e.enabledStatus = 1
@@ -215,10 +232,10 @@
         b.name as a_type_text,
         a.priorityIndex as a_sort
     </sql>
-	<sql id="Article_Joins">
-		left join info_type b on a.typeId = b.id
+    <sql id="Article_Joins">
+        left join info_type b on a.typeId = b.id
 		left join info_praise c on a.id = c.infoId
-	</sql>
+    </sql>
     <select id="findArticleCount" resultType="java.lang.Integer">
         select count(*)
         from info
@@ -235,52 +252,54 @@
         where enabledStatus != 1
     </select>
     <select id="searchArticleList" resultType="com.caimei365.commodity.model.search.ArticleDO">
-        select <include refid="Search_Article_List"/>
+        select
+        <include refid="Search_Article_List"/>
         from info as a
         <include refid="Article_Joins"/>
         where a.enabledStatus = 1
         order by a.priorityIndex desc
     </select>
     <select id="searchArticleById" resultType="com.caimei365.commodity.model.search.ArticleDO">
-        select <include refid="Search_Article_List"/>
+        select
+        <include refid="Search_Article_List"/>
         from info as a
         <include refid="Article_Joins"/>
         where a.id = #{articleId}
         and a.enabledStatus = 1
     </select>
     <select id="findLabelIdsByName" resultType="java.lang.Integer">
-		select id
-		from info_label
-		where  infoLabelStatus = 1
-		and name in
-		<foreach collection="labelTexts" item="label" open="(" close=")" index="index" separator=",">
-			#{label}
-		</foreach>
-		group by name
-		order by clickRate desc
+        select id
+        from info_label
+        where infoLabelStatus = 1
+        and name in
+        <foreach collection="labelTexts" item="label" open="(" close=")" index="index" separator=",">
+            #{label}
+        </foreach>
+        group by name
+        order by clickRate desc
     </select>
     <select id="findLabelNameById" resultType="java.lang.String">
-		select name
-		from info_label
-		where  infoLabelStatus = 1
-		and id = #{labelId}
-		limit 1
+        select name
+        from info_label
+        where infoLabelStatus = 1
+          and id = #{labelId}
+        limit 1
     </select>
     <!-- 搜索容错 商品列表 -->
     <select id="queryProduct" resultType="com.caimei365.commodity.model.search.ProductListVo">
         select
-            p.productID as productId,
-            p.actStatus,
-            p.`name` as name,
-            p.mainImage as image,
-            br.name as brandName,
-            p.unit as unit,
-            p.productCode as code,
-            p.price1TextFlag as priceFlag,
-            p.price1 as price,
-            p.shopID as shopId,
-            p.searchKey as keyword,
-            p.price8Text as beautyActFlag
+        p.productID as productId,
+        p.actStatus,
+        p.`name` as name,
+        p.mainImage as image,
+        br.name as brandName,
+        p.unit as unit,
+        p.productCode as code,
+        p.price1TextFlag as priceFlag,
+        p.price1 as price,
+        p.shopID as shopId,
+        p.searchKey as keyword,
+        p.price8Text as beautyActFlag
         from product p
         left join cm_brand as br on p.brandID = br.id
         where p.productCategory = 1
@@ -348,49 +367,48 @@
     </select>
     <!-- 搜索容错 供应商列表 -->
     <select id="querySupplier" resultType="com.caimei365.commodity.model.search.ShopListVo">
-        select
-            s.shopID as shopId,
-            s.name as name,
-            s.logo as logo,
-            s.authorizationCertificateImage as license,
-            s.businessScope as business,
-            CONCAT(p.name, c.name) as address
+        select s.shopID                        as shopId,
+               s.name                          as name,
+               s.logo                          as logo,
+               s.authorizationCertificateImage as license,
+               s.businessScope                 as business,
+               CONCAT(p.name, c.name)          as address
         from shop as s
-        left join town as t on s.townId = t.townID
-        left join city as c on t.cityID = c.cityID
-        left join province as p on c.provinceID = p.provinceID
+                 left join town as t on s.townId = t.townID
+                 left join city as c on t.cityID = c.cityID
+                 left join province as p on c.provinceID = p.provinceID
         where (status = 90 or status = 9)
-        and shopID != 1252
-        and s.name like concat('%',#{keyword},'%')
+          and shopID != 1252
+          and s.name like concat('%', #{keyword}, '%')
     </select>
     <!-- 搜索容错 项目仪器列表 -->
     <select id="queryEquipment" resultType="com.caimei365.commodity.model.search.EquipmentListVo">
-        select
-            e.id as id,
-            e.title as name,
-            e.precisehKey as keyword,
-            e.headImage as image
+        select e.id          as id,
+               e.title       as name,
+               e.precisehKey as keyword,
+               e.headImage   as image
         from cm_page as e
-        where e.type = 2 and e.enabledStatus = 1
-        and e.title like concat('%',#{keyword},'%')
+        where e.type = 2
+          and e.enabledStatus = 1
+          and e.title like concat('%', #{keyword}, '%')
         order by e.docBoost desc
     </select>
     <!-- 搜索容错 文章列表 -->
     <select id="queryArticle" resultType="com.caimei365.commodity.model.search.ArticleListVo">
         select
-            a.id as articleId,
-            a.title as title,
-            a.guidanceImage as image,
-            a.publisher as publisher,
-            a.pubdate as publishDate,
-            a.recommendContent as intro,
-            (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
-            a.typeId as typeId,
-            b.name as typeText,
-            a.label as labelText
+        a.id as articleId,
+        a.title as title,
+        a.guidanceImage as image,
+        a.publisher as publisher,
+        a.pubdate as publishDate,
+        a.recommendContent as intro,
+        (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
+        a.typeId as typeId,
+        b.name as typeText,
+        a.label as labelText
         from info as a
-		left join info_type b on a.typeId = b.id
-		left join info_praise c on a.id = c.infoId
+        left join info_type b on a.typeId = b.id
+        left join info_praise c on a.id = c.infoId
         <where>
             a.enabledStatus = 1
             <if test="articleId != null">
@@ -422,11 +440,16 @@
         order by id desc
     </select>
     <select id="getHistoryIdByWord" resultType="java.lang.Integer">
-        select id from user_search_history where searchWord = #{keyword} limit 1
+        select id
+        from user_search_history
+        where searchWord = #{keyword}
+        limit 1
     </select>
     <select id="getHistoryCount" resultType="java.lang.Integer">
-        select COUNT(*) from user_search_history
-        where userId = #{userId} AND delFlag = 0
+        select COUNT(*)
+        from user_search_history
+        where userId = #{userId}
+          AND delFlag = 0
     </select>
     <update id="updateSearchHistoryById">
         update user_search_history
@@ -478,12 +501,46 @@
         </trim>
     </insert>
     <delete id="deleteSearchHistory">
-        DELETE FROM user_search_history
-        WHERE userId=#{userId} AND id NOT IN (
-            SELECT temp.id FROM ( SELECT id FROM user_search_history WHERE userId=#{userId} ORDER BY searchDate DESC LIMIT 10 ) AS temp
+        DELETE
+        FROM user_search_history
+        WHERE userId = #{userId}
+          AND id NOT IN (
+            SELECT temp.id
+            FROM (SELECT id FROM user_search_history WHERE userId = #{userId} ORDER BY searchDate DESC LIMIT 10) AS temp
         )
     </delete>
     <delete id="deleteAllSearchHistory">
-        DELETE FROM user_search_history WHERE userId=#{userId}
+        DELETE
+        FROM user_search_history
+        WHERE userId = #{userId}
     </delete>
+
+    <select id="findNew" resultType="java.lang.Integer">
+        select productID from product
+        where TIMESTAMP(ADDTIME) <![CDATA[ > ]]> TIMESTAMP(#{n})
+        <if test="productIds != null">
+            and productID in
+            <foreach collection="productIds" item="productId" index="index" open="(" separator="," close=")">
+                #{productId}
+            </foreach>
+        </if>
+    </select>
+    <select id="findPromotion" resultType="java.lang.Integer">
+        select cpp.productID from cm_promotions_product cpp
+        left join cm_promotions cp on cpp.promotionsId = cp.id
+        where cpp.productId in
+        <foreach collection="productIds" item="productId" index="index" open="(" separator="," close=")">
+            #{productId}
+        </foreach>
+        and cp.endTime>now() or (cp.status='1')
+        and cp.delflag = 0
+    </select>
+    <select id="findPromotionId" resultType="java.lang.Integer">
+        select cpp.promotionsId
+        from cm_promotions_product cpp
+        left join cm_promotions cp on cp.id=cpp.promotionsId
+        where cpp.productId = #{p_id}
+        and cp.endTime>now() or (cp.status='1')
+        and cp.delflag = 0
+    </select>
 </mapper>