Browse Source

Merge remote-tracking branch 'origin/dev' into dev

赵冬冬 4 năm trước cách đây
mục cha
commit
4483222447

+ 13 - 1
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/controller/web/GoodsManageTwoController.java

@@ -33,7 +33,7 @@ public class GoodsManageTwoController extends BaseController {
      * @param goodsManageQueryForm
      * @return
      */
-    @ApiOperation(value = "按类型分页查询商品信息",notes = "获取用户信息,按类型分页查询")
+    @ApiOperation(value = "按类型分页查询商品信息",notes = "按类型分页查询商品信息")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "goodsManageQueryForm",value = "商品查询信息", dataType = "GoodsManageQueryForm")
     })
@@ -61,4 +61,16 @@ public class GoodsManageTwoController extends BaseController {
         resultVO.setData(list);
         return responseSuccess(resultVO);
     }
+
+    @ApiOperation(value = "推荐碳汇产品",notes = "推荐碳汇产品")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "goodsManageQueryForm",value = "商品查询信息", dataType = "GoodsManageQueryForm")
+    })
+    @ApiResponse(code =0,message = "查询成功")
+    @PostMapping("/pushGoods")
+    @AuthCarbonValidate
+    public ResponseBase pushGoods(@RequestBody GoodsManageQueryForm goodsManageQueryForm){
+        PageInfo pageInfo = goodsManageService.pushGoods(goodsManageQueryForm);
+        return responseSuccess(pageInfo);
+    }
 }

+ 8 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/GoodsManageService.java

@@ -23,4 +23,12 @@ public interface GoodsManageService {
      * @return
      */
     List<GoodsInfoForm> getGoodsInfoByCarbon(Integer carbonNum);
+
+    /**
+     * 推荐碳汇产品
+     * lym
+     * @param goodsManageQueryForm
+     * @return
+     */
+    PageInfo pushGoods(GoodsManageQueryForm goodsManageQueryForm);
 }

+ 80 - 3
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/GoodsManageServiceImpl.java

@@ -43,7 +43,7 @@ public class GoodsManageServiceImpl implements GoodsManageService {
     }
 
     /**
-     * 查询农户随机集
+     * 查询商品随机集
      * lym
      * @return
      */
@@ -96,14 +96,14 @@ public class GoodsManageServiceImpl implements GoodsManageService {
     private List<GoodsInfoForm> getRandomPY(Map<String,GoodsInfoForm> resultMap,Map<String,List<GoodsInfoForm>> helpMap,int buyNum
             ,Integer pageNo) {
         Collection<String> resultKeys = resultMap.keySet();
-        //随机用户
+        //随机商品
         List<GoodsInfoForm> list = new ArrayList<>();
         if (helpMap.size() <= 2){
             Collection<List<GoodsInfoForm>> values = helpMap.values();
             for (List<GoodsInfoForm> valueList:values) {
                 list.addAll(valueList);
             }
-        }else {//获取随机农户
+        }else {//获取随机商品
             list = getGoodsInfos(helpMap,resultKeys);
         }
         List<GoodsInfoForm> resultList = getRandom(resultMap,list,buyNum,pageNo);
@@ -196,4 +196,81 @@ public class GoodsManageServiceImpl implements GoodsManageService {
         resultList = new ArrayList<>(resultMap.values());
         return resultList;
     }
+
+    @Override
+    public PageInfo pushGoods(GoodsManageQueryForm goodsManageQueryForm) {
+        //随机分配商品
+        Map<String,List<GoodsInfoForm>> helpMap = getGoodsInfo(goodsManageQueryForm.getPageNo(),goodsManageQueryForm.getPageSize());
+        List<GoodsInfoForm> resultList = new ArrayList<>();
+        Map<String,GoodsInfoForm> resultMap = new HashMap<>();
+        if (helpMap != null && helpMap.size() > 0){
+            resultList = getGoodsRandomPY(resultMap,helpMap,goodsManageQueryForm.getPageNo(),goodsManageQueryForm.getPageSize());
+        }
+
+        PageInfo pageInfo = new PageInfo();
+        pageInfo.setList(resultList);
+        return pageInfo;
+    }
+
+    /**
+     * 查询商品随机集
+     * lym
+     * @return
+     */
+    private Map<String,List<GoodsInfoForm>> getGoodsInfo(Integer pageNo, int pageSize){
+        String orderStr = null;
+        if (pageNo > 20){ //加载超过20页多的排前
+            orderStr = "ORDER BY tmp.unsaledCarbonSkin DESC";
+        }else {
+            orderStr = "ORDER BY tmp.saledCarbonSkin ASC,tmp.unsaledCarbonSkin DESC";
+        }
+
+        List<String> RandomStrings = getRandomString(pageSize); //开发主体首字母
+        Map<String,List<GoodsInfoForm>> helpMap = new HashMap();
+        for (String namePy:RandomStrings){ //循环获取
+            PageHelper.startPage(pageNo,pageSize);
+            List<GoodsInfoForm> list = goodsManageMapper.getBuyGoodsInfo(namePy,orderStr);
+            if (list != null && list.size() > 0)
+                helpMap.put(namePy,list);
+        }
+        return helpMap;
+    }
+
+    /**
+     * lym
+     * 主体首字母随机推荐展示
+     * @return
+     */
+    private List<GoodsInfoForm> getGoodsRandomPY(Map<String,GoodsInfoForm> resultMap,Map<String,List<GoodsInfoForm>> helpMap,int pageNo
+            ,Integer pageSize) {
+        Collection<String> resultKeys = resultMap.keySet();
+        //随机商品集
+        List<GoodsInfoForm> list = new ArrayList<>(resultMap.values());
+        if (helpMap.size() <= 2){
+            Collection<List<GoodsInfoForm>> values = helpMap.values();
+            for (List<GoodsInfoForm> valueList:values) {
+                list.addAll(valueList);
+            }
+        }else {//获取随机商品集
+            list.addAll(getGoodsInfos(helpMap,resultKeys));
+        }
+
+        if (list != null && list.size() > 0){ //在返回集的数据
+            for (GoodsInfoForm form:list){
+                if (!resultKeys.contains(form.getGuid())) //去重复
+                    resultMap.put(form.getGuid(),form);
+            }
+            list = new ArrayList<>(resultMap.values());
+        }
+
+        if (list != null && list.size() < pageSize && pageNo < 5){ //未达返回数
+            pageNo = pageNo + 1;
+            helpMap = getGoodsInfo(pageNo,pageSize);
+            getGoodsRandomPY(resultMap,helpMap,pageNo,pageSize);
+        }
+
+        list = new ArrayList<>(resultMap.values());
+        if (list.size() > pageSize) list = list.subList(0,pageSize);
+        return list;
+    }
 }