|
|
@@ -2,8 +2,10 @@ package com.miekir.shibei.controller.api;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.miekir.shibei.bean.*;
|
|
|
+import com.miekir.shibei.bean.db.FavBean;
|
|
|
import com.miekir.shibei.bean.db.GoodsBean;
|
|
|
import com.miekir.shibei.bean.db.SystemBean;
|
|
|
+import com.miekir.shibei.repository.FavRepository;
|
|
|
import com.miekir.shibei.repository.GoodsRepository;
|
|
|
import com.miekir.shibei.repository.SystemRepository;
|
|
|
import com.miekir.shibei.repository.UserRepository;
|
|
|
@@ -31,6 +33,9 @@ public class GoodsController {
|
|
|
@Autowired
|
|
|
private SystemRepository systemRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FavRepository favRepository;
|
|
|
+
|
|
|
private final Random mRandom = new Random();
|
|
|
|
|
|
/**
|
|
|
@@ -121,7 +126,7 @@ public class GoodsController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/api/getGoodsList", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
@ResponseBody
|
|
|
- public String getGoodsList(int pageNum, int pageSize) {
|
|
|
+ public String getGoodsList(@RequestHeader HttpHeaders header, int pageNum, int pageSize) {
|
|
|
ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
|
|
|
responseResult.setMessage("获取失败");
|
|
|
|
|
|
@@ -131,6 +136,8 @@ public class GoodsController {
|
|
|
responseResult.setMessage("休息时间到");
|
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
|
+ String email = header.getFirst("email");
|
|
|
+ List<Long> favBeanList = favRepository.findFavListByEmail(email);
|
|
|
|
|
|
// 自带的分页查询。这里不使用分页查询,而是返回随机的数据
|
|
|
List<GoodsBean> goodsBeanList;
|
|
|
@@ -142,6 +149,13 @@ public class GoodsController {
|
|
|
try {
|
|
|
Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
|
|
|
goodsBeanList = goodsRepository.findAll(new PageRequest(randomPageNum, pageSize, sort)).getContent();
|
|
|
+
|
|
|
+ // 当前商品是否已收藏
|
|
|
+ for (GoodsBean goodsBean : goodsBeanList) {
|
|
|
+ if (favBeanList.contains(goodsBean.id)) {
|
|
|
+ goodsBean.isFavorite = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return JSON.toJSONString(responseResult);
|