|
@@ -9,6 +9,8 @@ import com.miekir.shibei.repository.*;
|
|
|
import com.miekir.shibei.tool.RequestTool;
|
|
import com.miekir.shibei.tool.RequestTool;
|
|
|
import com.miekir.shibei.tool.email.EmailTool;
|
|
import com.miekir.shibei.tool.email.EmailTool;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
@@ -23,6 +25,10 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Iterator;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
|
public class FavController {
|
|
public class FavController {
|
|
@@ -35,12 +41,15 @@ public class FavController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FavRepository favRepository;
|
|
private FavRepository favRepository;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SystemRepository systemRepository;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 设置API是否为会员专属
|
|
* 设置API是否为会员专属
|
|
|
*/
|
|
*/
|
|
|
@RequestMapping(value = "/api/favGoods", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
@RequestMapping(value = "/api/favGoods", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String favGoods(@RequestHeader HttpHeaders header, long goodsId) {
|
|
|
|
|
|
|
+ public String favGoods(@RequestHeader HttpHeaders header, Long goodsId) {
|
|
|
ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
responseResult.setMessage("操作失败");
|
|
responseResult.setMessage("操作失败");
|
|
|
|
|
|
|
@@ -76,4 +85,56 @@ public class FavController {
|
|
|
responseResult.setCode(ResultCode.SUCCESS);
|
|
responseResult.setCode(ResultCode.SUCCESS);
|
|
|
return JSON.toJSONString(responseResult);
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询京东商品
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "/api/getMyFavGoods", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String getMyFavGoods(@RequestHeader HttpHeaders header, int pageNum, int pageSize) {
|
|
|
|
|
+ ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
|
|
|
|
|
+ responseResult.setMessage("获取失败");
|
|
|
|
|
+
|
|
|
|
|
+ if (!RequestTool.isRequestValid(header, userRepository)) {
|
|
|
|
|
+ responseResult.setMessage("请重新登录");
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 关闭通道
|
|
|
|
|
+ SystemBean systemBean = systemRepository.findSystemBean();
|
|
|
|
|
+ if (systemBean != null && systemBean.isVipLimit) {
|
|
|
|
|
+ responseResult.setMessage("休息时间到");
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String email = header.getFirst("email");
|
|
|
|
|
+ // 原生查询出来是List<BigInteger>,要转换成List<Long>才行,或者使用JPQL
|
|
|
|
|
+ List<BigInteger> goodsIdList = favRepository.getFavList(email, pageNum*pageSize, pageSize);
|
|
|
|
|
+ List<Long> realGoodsIdList = new ArrayList<Long>();
|
|
|
|
|
+ if (goodsIdList != null && goodsIdList.size() >0) {
|
|
|
|
|
+ for (BigInteger integer : goodsIdList) {
|
|
|
|
|
+ realGoodsIdList.add(integer.longValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ responseResult.setContent(null);
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
|
|
+ responseResult.setMessage("没有更多数据");
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
|
|
+ Iterable<GoodsBean> favGoodsIterator = goodsRepository.findAll(realGoodsIdList);
|
|
|
|
|
+ List<GoodsBean> goodsBeanList = new ArrayList<GoodsBean>();
|
|
|
|
|
+ if (favGoodsIterator != null) {
|
|
|
|
|
+ for (GoodsBean currentBean : favGoodsIterator) {
|
|
|
|
|
+ currentBean.isFavorite = true;
|
|
|
|
|
+ goodsBeanList.add(currentBean);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ responseResult.setContent(goodsBeanList);
|
|
|
|
|
+
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
|
|
+ responseResult.setMessage("获取成功");
|
|
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|