|
@@ -130,14 +130,17 @@ public class GoodsController {
|
|
|
ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
|
|
ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
|
|
|
responseResult.setMessage("获取失败");
|
|
responseResult.setMessage("获取失败");
|
|
|
|
|
|
|
|
|
|
+ if (!RequestTool.isRequestValid(header, userRepository)) {
|
|
|
|
|
+ responseResult.setMessage("请重新登录");
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 关闭通道
|
|
// 关闭通道
|
|
|
SystemBean systemBean = systemRepository.findSystemBean();
|
|
SystemBean systemBean = systemRepository.findSystemBean();
|
|
|
if (systemBean != null && systemBean.isVipLimit) {
|
|
if (systemBean != null && systemBean.isVipLimit) {
|
|
|
responseResult.setMessage("休息时间到");
|
|
responseResult.setMessage("休息时间到");
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
|
- String email = header.getFirst("email");
|
|
|
|
|
- List<Long> favBeanList = favRepository.findFavListByEmail(email);
|
|
|
|
|
|
|
|
|
|
// 自带的分页查询。这里不使用分页查询,而是返回随机的数据
|
|
// 自带的分页查询。这里不使用分页查询,而是返回随机的数据
|
|
|
List<GoodsBean> goodsBeanList;
|
|
List<GoodsBean> goodsBeanList;
|
|
@@ -150,10 +153,14 @@ public class GoodsController {
|
|
|
Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
|
|
Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
|
|
|
goodsBeanList = goodsRepository.findAll(new PageRequest(randomPageNum, pageSize, sort)).getContent();
|
|
goodsBeanList = goodsRepository.findAll(new PageRequest(randomPageNum, pageSize, sort)).getContent();
|
|
|
|
|
|
|
|
- // 当前商品是否已收藏
|
|
|
|
|
- for (GoodsBean goodsBean : goodsBeanList) {
|
|
|
|
|
- if (favBeanList.contains(goodsBean.id)) {
|
|
|
|
|
- goodsBean.isFavorite = true;
|
|
|
|
|
|
|
+ if (goodsBeanList != null) {
|
|
|
|
|
+ String email = header.getFirst("email");
|
|
|
|
|
+ List<Long> favBeanList = favRepository.findFavListByEmail(email);
|
|
|
|
|
+ // 当前商品是否已收藏
|
|
|
|
|
+ for (GoodsBean goodsBean : goodsBeanList) {
|
|
|
|
|
+ if (favBeanList.contains(goodsBean.id)) {
|
|
|
|
|
+ goodsBean.isFavorite = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -178,12 +185,17 @@ public class GoodsController {
|
|
|
*/
|
|
*/
|
|
|
@RequestMapping(value = "/api/getGoodsListByKeyword", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
@RequestMapping(value = "/api/getGoodsListByKeyword", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String getGoodsListByKeyword(String keywords, int pageNum, int pageSize) {
|
|
|
|
|
|
|
+ public String getGoodsListByKeyword(@RequestHeader HttpHeaders header, String keywords, int pageNum, int pageSize) {
|
|
|
String keywordsUtf8 = StringTool.getUtf8String(keywords);
|
|
String keywordsUtf8 = StringTool.getUtf8String(keywords);
|
|
|
|
|
|
|
|
ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
|
|
ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
|
|
|
responseResult.setMessage("获取失败");
|
|
responseResult.setMessage("获取失败");
|
|
|
|
|
|
|
|
|
|
+ if (!RequestTool.isRequestValid(header, userRepository)) {
|
|
|
|
|
+ responseResult.setMessage("请重新登录");
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 关闭通道
|
|
// 关闭通道
|
|
|
SystemBean systemBean = systemRepository.findSystemBean();
|
|
SystemBean systemBean = systemRepository.findSystemBean();
|
|
|
if (systemBean != null && systemBean.isVipLimit) {
|
|
if (systemBean != null && systemBean.isVipLimit) {
|
|
@@ -198,6 +210,17 @@ public class GoodsController {
|
|
|
// 模糊查询,要拼上%%
|
|
// 模糊查询,要拼上%%
|
|
|
keywordsUtf8 = "%"+keywordsUtf8+"%";
|
|
keywordsUtf8 = "%"+keywordsUtf8+"%";
|
|
|
goodsBeanList = goodsRepository.getGoodsListByKeyword(keywordsUtf8, pageNum*pageSize, pageSize);
|
|
goodsBeanList = goodsRepository.getGoodsListByKeyword(keywordsUtf8, pageNum*pageSize, pageSize);
|
|
|
|
|
+
|
|
|
|
|
+ if (goodsBeanList != null) {
|
|
|
|
|
+ String email = header.getFirst("email");
|
|
|
|
|
+ List<Long> favBeanList = favRepository.findFavListByEmail(email);
|
|
|
|
|
+ // 当前商品是否已收藏
|
|
|
|
|
+ for (GoodsBean goodsBean : goodsBeanList) {
|
|
|
|
|
+ if (favBeanList.contains(goodsBean.id)) {
|
|
|
|
|
+ goodsBean.isFavorite = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|