完成收藏功能针对topic的实现 (#456)
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package org.linlinjava.litemall.wx.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -9,18 +16,19 @@ import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallCollect;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoods;
|
||||
import org.linlinjava.litemall.db.domain.LitemallTopic;
|
||||
import org.linlinjava.litemall.db.service.LitemallCollectService;
|
||||
import org.linlinjava.litemall.db.service.LitemallGoodsService;
|
||||
import org.linlinjava.litemall.db.service.LitemallTopicService;
|
||||
import org.linlinjava.litemall.wx.annotation.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 用户收藏服务
|
||||
@@ -35,6 +43,8 @@ public class WxCollectController {
|
||||
private LitemallCollectService collectService;
|
||||
@Autowired
|
||||
private LitemallGoodsService goodsService;
|
||||
@Autowired
|
||||
private LitemallTopicService topicService;
|
||||
|
||||
/**
|
||||
* 用户收藏列表
|
||||
@@ -64,13 +74,21 @@ public class WxCollectController {
|
||||
c.put("id", collect.getId());
|
||||
c.put("type", collect.getType());
|
||||
c.put("valueId", collect.getValueId());
|
||||
|
||||
LitemallGoods goods = goodsService.findById(collect.getValueId());
|
||||
c.put("name", goods.getName());
|
||||
c.put("brief", goods.getBrief());
|
||||
c.put("picUrl", goods.getPicUrl());
|
||||
c.put("retailPrice", goods.getRetailPrice());
|
||||
|
||||
if (type == (byte)0){
|
||||
//查询商品信息
|
||||
LitemallGoods goods = goodsService.findById(collect.getValueId());
|
||||
c.put("name", goods.getName());
|
||||
c.put("brief", goods.getBrief());
|
||||
c.put("picUrl", goods.getPicUrl());
|
||||
c.put("retailPrice", goods.getRetailPrice());
|
||||
} else {
|
||||
//查询专题信息
|
||||
LitemallTopic topic = topicService.findById(collect.getValueId());
|
||||
c.put("title", topic.getTitle());
|
||||
c.put("subtitle", topic.getTitle());
|
||||
c.put("price", topic.getPrice());
|
||||
c.put("picUrl", topic.getPicUrl());
|
||||
}
|
||||
collects.add(c);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.linlinjava.litemall.wx.web;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mysql.jdbc.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.core.system.SystemConfig;
|
||||
@@ -12,6 +11,7 @@ import org.linlinjava.litemall.db.domain.*;
|
||||
import org.linlinjava.litemall.db.service.*;
|
||||
import org.linlinjava.litemall.wx.annotation.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -147,7 +147,7 @@ public class WxGoodsController {
|
||||
// 用户收藏
|
||||
int userHasCollect = 0;
|
||||
if (userId != null) {
|
||||
userHasCollect = collectService.count(userId, id);
|
||||
userHasCollect = collectService.count(userId, (byte)0, id);
|
||||
}
|
||||
|
||||
// 记录用户的足迹 异步处理
|
||||
@@ -259,7 +259,7 @@ public class WxGoodsController {
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
|
||||
//添加到搜索历史
|
||||
if (userId != null && !StringUtils.isNullOrEmpty(keyword)) {
|
||||
if (userId != null && !StringUtils.isEmpty(keyword)) {
|
||||
LitemallSearchHistory searchHistoryVo = new LitemallSearchHistory();
|
||||
searchHistoryVo.setKeyword(keyword);
|
||||
searchHistoryVo.setUserId(userId);
|
||||
|
||||
@@ -7,8 +7,10 @@ import org.linlinjava.litemall.core.validator.Order;
|
||||
import org.linlinjava.litemall.core.validator.Sort;
|
||||
import org.linlinjava.litemall.db.domain.LitemallGoods;
|
||||
import org.linlinjava.litemall.db.domain.LitemallTopic;
|
||||
import org.linlinjava.litemall.db.service.LitemallCollectService;
|
||||
import org.linlinjava.litemall.db.service.LitemallGoodsService;
|
||||
import org.linlinjava.litemall.db.service.LitemallTopicService;
|
||||
import org.linlinjava.litemall.wx.annotation.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -35,6 +37,8 @@ public class WxTopicController {
|
||||
private LitemallTopicService topicService;
|
||||
@Autowired
|
||||
private LitemallGoodsService goodsService;
|
||||
@Autowired
|
||||
private LitemallCollectService collectService;
|
||||
|
||||
/**
|
||||
* 专题列表
|
||||
@@ -59,7 +63,7 @@ public class WxTopicController {
|
||||
* @return 专题详情
|
||||
*/
|
||||
@GetMapping("detail")
|
||||
public Object detail(@NotNull Integer id) {
|
||||
public Object detail(@LoginUser Integer userId, @NotNull Integer id) {
|
||||
LitemallTopic topic = topicService.findById(id);
|
||||
List<LitemallGoods> goods = new ArrayList<>();
|
||||
for (Integer i : topic.getGoods()) {
|
||||
@@ -67,10 +71,17 @@ public class WxTopicController {
|
||||
if (null != good)
|
||||
goods.add(good);
|
||||
}
|
||||
|
||||
// 用户收藏
|
||||
int userHasCollect = 0;
|
||||
if (userId != null) {
|
||||
userHasCollect = collectService.count(userId, (byte)1, id);
|
||||
}
|
||||
|
||||
Map<String, Object> entity = new HashMap<String, Object>();
|
||||
entity.put("topic", topic);
|
||||
entity.put("goods", goods);
|
||||
entity.put("userHasCollect", userHasCollect);
|
||||
return ResponseUtil.ok(entity);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user