添加品牌关注和商品收藏功能
This commit is contained in:
parent
cfe5c0fe80
commit
02b555c519
@ -0,0 +1,55 @@
|
||||
package com.macro.mall.portal.controller;
|
||||
|
||||
import com.macro.mall.portal.domain.CommonResult;
|
||||
import com.macro.mall.portal.domain.MemberBrandAttention;
|
||||
import com.macro.mall.portal.service.MemberAttentionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员关注品牌管理Controller
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "MemberAttentionController", description = "会员关注品牌管理")
|
||||
@RequestMapping("/member/attention")
|
||||
public class MemberAttentionController {
|
||||
@Autowired
|
||||
private MemberAttentionService memberAttentionService;
|
||||
@ApiOperation("添加品牌关注")
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object add(@RequestBody MemberBrandAttention memberBrandAttention) {
|
||||
int count = memberAttentionService.add(memberBrandAttention);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}else{
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("取消关注")
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object delete(Long memberId, Long brandId) {
|
||||
int count = memberAttentionService.delete(memberId,brandId);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}else{
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("显示关注列表")
|
||||
@RequestMapping(value = "/list/{memberId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object list(@PathVariable Long memberId) {
|
||||
List<MemberBrandAttention> memberBrandAttentionList = memberAttentionService.list(memberId);
|
||||
return new CommonResult().success(memberBrandAttentionList);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.macro.mall.portal.controller;
|
||||
|
||||
import com.macro.mall.portal.domain.CommonResult;
|
||||
import com.macro.mall.portal.domain.MemberProductCollection;
|
||||
import com.macro.mall.portal.service.MemberCollectionService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员收藏管理Controller
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "MemberCollectionController", description = "会员收藏管理")
|
||||
@RequestMapping("/member/collection")
|
||||
public class MemberCollectionController {
|
||||
@Autowired
|
||||
private MemberCollectionService memberCollectionService;
|
||||
@ApiOperation("添加商品收藏")
|
||||
@RequestMapping(value = "/addProduct", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object addProduct(@RequestBody MemberProductCollection productCollection) {
|
||||
int count = memberCollectionService.addProduct(productCollection);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}else{
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("删除收藏商品")
|
||||
@RequestMapping(value = "/deleteProduct", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object deleteProduct(Long memberId, Long productId) {
|
||||
int count = memberCollectionService.deleteProduct(memberId,productId);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}else{
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("显示关注列表")
|
||||
@RequestMapping(value = "/listProduct/{memberId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object list(@PathVariable Long memberId) {
|
||||
List<MemberProductCollection> memberProductCollectionList = memberCollectionService.listProduct(memberId);
|
||||
return new CommonResult().success(memberProductCollectionList);
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.macro.mall.portal.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 会员关注的品牌
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
@Document
|
||||
public class MemberBrandAttention {
|
||||
@Id
|
||||
private String id;
|
||||
@Indexed
|
||||
private Long memberId;
|
||||
private String memberNickname;
|
||||
private String memberIcon;
|
||||
@Indexed
|
||||
private Long brandId;
|
||||
private String brandName;
|
||||
private String brandLogo;
|
||||
private String brandCity;
|
||||
private Integer brandAttentionCount;
|
||||
private Date createTime;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getMemberId() {
|
||||
return memberId;
|
||||
}
|
||||
|
||||
public void setMemberId(Long memberId) {
|
||||
this.memberId = memberId;
|
||||
}
|
||||
|
||||
public String getMemberNickname() {
|
||||
return memberNickname;
|
||||
}
|
||||
|
||||
public void setMemberNickname(String memberNickname) {
|
||||
this.memberNickname = memberNickname;
|
||||
}
|
||||
|
||||
public String getMemberIcon() {
|
||||
return memberIcon;
|
||||
}
|
||||
|
||||
public void setMemberIcon(String memberIcon) {
|
||||
this.memberIcon = memberIcon;
|
||||
}
|
||||
|
||||
public Long getBrandId() {
|
||||
return brandId;
|
||||
}
|
||||
|
||||
public void setBrandId(Long brandId) {
|
||||
this.brandId = brandId;
|
||||
}
|
||||
|
||||
public String getBrandName() {
|
||||
return brandName;
|
||||
}
|
||||
|
||||
public void setBrandName(String brandName) {
|
||||
this.brandName = brandName;
|
||||
}
|
||||
|
||||
public String getBrandLogo() {
|
||||
return brandLogo;
|
||||
}
|
||||
|
||||
public void setBrandLogo(String brandLogo) {
|
||||
this.brandLogo = brandLogo;
|
||||
}
|
||||
|
||||
public String getBrandCity() {
|
||||
return brandCity;
|
||||
}
|
||||
|
||||
public void setBrandCity(String brandCity) {
|
||||
this.brandCity = brandCity;
|
||||
}
|
||||
|
||||
public Integer getBrandAttentionCount() {
|
||||
return brandAttentionCount;
|
||||
}
|
||||
|
||||
public void setBrandAttentionCount(Integer brandAttentionCount) {
|
||||
this.brandAttentionCount = brandAttentionCount;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package com.macro.mall.portal.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户收藏的商品
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
public class MemberProductCollection {
|
||||
@Id
|
||||
private String id;
|
||||
@Indexed
|
||||
private Long memberId;
|
||||
private String memberNickname;
|
||||
private String memberIcon;
|
||||
@Indexed
|
||||
private Long productId;
|
||||
private String productName;
|
||||
private String productPic;
|
||||
private String productSubTitle;
|
||||
private String productPrice;
|
||||
private Date createTime;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getMemberId() {
|
||||
return memberId;
|
||||
}
|
||||
|
||||
public void setMemberId(Long memberId) {
|
||||
this.memberId = memberId;
|
||||
}
|
||||
|
||||
public String getMemberNickname() {
|
||||
return memberNickname;
|
||||
}
|
||||
|
||||
public void setMemberNickname(String memberNickname) {
|
||||
this.memberNickname = memberNickname;
|
||||
}
|
||||
|
||||
public String getMemberIcon() {
|
||||
return memberIcon;
|
||||
}
|
||||
|
||||
public void setMemberIcon(String memberIcon) {
|
||||
this.memberIcon = memberIcon;
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Long productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
|
||||
public String getProductPic() {
|
||||
return productPic;
|
||||
}
|
||||
|
||||
public void setProductPic(String productPic) {
|
||||
this.productPic = productPic;
|
||||
}
|
||||
|
||||
public String getProductSubTitle() {
|
||||
return productSubTitle;
|
||||
}
|
||||
|
||||
public void setProductSubTitle(String productSubTitle) {
|
||||
this.productSubTitle = productSubTitle;
|
||||
}
|
||||
|
||||
public String getProductPrice() {
|
||||
return productPrice;
|
||||
}
|
||||
|
||||
public void setProductPrice(String productPrice) {
|
||||
this.productPrice = productPrice;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.macro.mall.portal.repository;
|
||||
|
||||
import com.macro.mall.portal.domain.MemberBrandAttention;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员关注Repository
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
public interface MemberBrandAttentionRepository extends MongoRepository<MemberBrandAttention,String> {
|
||||
MemberBrandAttention findByMemberIdAndBrandId(Long memberId, Long brandId);
|
||||
int deleteByMemberIdAndBrandId(Long memberId,Long brandId);
|
||||
List<MemberBrandAttention> findByMemberId(Long memberId);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.macro.mall.portal.repository;
|
||||
|
||||
import com.macro.mall.portal.domain.MemberProductCollection;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品收藏Repository
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
public interface MemberProductCollectionRepository extends MongoRepository<MemberProductCollection,String> {
|
||||
MemberProductCollection findByMemberIdAndProductId(Long memberId, Long productId);
|
||||
int deleteByMemberIdAndProductId(Long memberId,Long productId);
|
||||
List<MemberProductCollection> findByMemberId(Long memberId);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.macro.mall.portal.service;
|
||||
|
||||
import com.macro.mall.portal.domain.MemberBrandAttention;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员关注Service
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
public interface MemberAttentionService {
|
||||
/**
|
||||
* 添加关注
|
||||
*/
|
||||
int add(MemberBrandAttention memberBrandAttention);
|
||||
|
||||
/**
|
||||
* 取消关注
|
||||
*/
|
||||
int delete(Long memberId, Long brandId);
|
||||
|
||||
/**
|
||||
* 获取用户关注列表
|
||||
*/
|
||||
List<MemberBrandAttention> list(Long memberId);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.macro.mall.portal.service;
|
||||
|
||||
import com.macro.mall.portal.domain.MemberProductCollection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员收藏Service
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
public interface MemberCollectionService {
|
||||
int addProduct(MemberProductCollection productCollection);
|
||||
|
||||
int deleteProduct(Long memberId, Long productId);
|
||||
|
||||
List<MemberProductCollection> listProduct(Long memberId);
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.macro.mall.portal.service.impl;
|
||||
|
||||
import com.macro.mall.portal.domain.MemberBrandAttention;
|
||||
import com.macro.mall.portal.repository.MemberBrandAttentionRepository;
|
||||
import com.macro.mall.portal.service.MemberAttentionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员关注Service实现类
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
@Service
|
||||
public class MemberAttentionServiceImpl implements MemberAttentionService {
|
||||
@Autowired
|
||||
private MemberBrandAttentionRepository memberBrandAttentionRepository;
|
||||
|
||||
@Override
|
||||
public int add(MemberBrandAttention memberBrandAttention) {
|
||||
int count = 0;
|
||||
MemberBrandAttention findAttention = memberBrandAttentionRepository.findByMemberIdAndBrandId(memberBrandAttention.getMemberId(), memberBrandAttention.getBrandId());
|
||||
if (findAttention == null) {
|
||||
memberBrandAttentionRepository.save(memberBrandAttention);
|
||||
count = 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long memberId, Long brandId) {
|
||||
return memberBrandAttentionRepository.deleteByMemberIdAndBrandId(memberId,brandId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MemberBrandAttention> list(Long memberId) {
|
||||
return memberBrandAttentionRepository.findByMemberId(memberId);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.macro.mall.portal.service.impl;
|
||||
|
||||
import com.macro.mall.portal.domain.MemberProductCollection;
|
||||
import com.macro.mall.portal.repository.MemberProductCollectionRepository;
|
||||
import com.macro.mall.portal.service.MemberCollectionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员收藏Service实现类
|
||||
* Created by macro on 2018/8/2.
|
||||
*/
|
||||
@Service
|
||||
public class MemberCollectionServiceImpl implements MemberCollectionService {
|
||||
@Autowired
|
||||
private MemberProductCollectionRepository productCollectionRepository;
|
||||
|
||||
@Override
|
||||
public int addProduct(MemberProductCollection productCollection) {
|
||||
int count = 0;
|
||||
MemberProductCollection findCollection = productCollectionRepository.findByMemberIdAndProductId(productCollection.getMemberId(), productCollection.getProductId());
|
||||
if (findCollection == null) {
|
||||
productCollectionRepository.save(productCollection);
|
||||
count = 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteProduct(Long memberId, Long productId) {
|
||||
return productCollectionRepository.deleteByMemberIdAndProductId(memberId, productId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MemberProductCollection> listProduct(Long memberId) {
|
||||
return productCollectionRepository.findByMemberId(memberId);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user