商品关注、收藏、浏览记录接口完善

This commit is contained in:
macro 2020-05-23 16:35:51 +08:00
parent ea2737396e
commit 4befc2f514
13 changed files with 102 additions and 52 deletions

View File

@ -1,11 +1,13 @@
package com.macro.mall.portal.controller; package com.macro.mall.portal.controller;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult; import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.MemberBrandAttention; import com.macro.mall.portal.domain.MemberBrandAttention;
import com.macro.mall.portal.service.MemberAttentionService; import com.macro.mall.portal.service.MemberAttentionService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -36,8 +38,8 @@ public class MemberAttentionController {
@ApiOperation("取消关注") @ApiOperation("取消关注")
@RequestMapping(value = "/delete", method = RequestMethod.POST) @RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public CommonResult delete(Long memberId, Long brandId) { public CommonResult delete(Long brandId) {
int count = memberAttentionService.delete(memberId,brandId); int count = memberAttentionService.delete(brandId);
if(count>0){ if(count>0){
return CommonResult.success(count); return CommonResult.success(count);
}else{ }else{
@ -46,10 +48,11 @@ public class MemberAttentionController {
} }
@ApiOperation("显示关注列表") @ApiOperation("显示关注列表")
@RequestMapping(value = "/list/{memberId}", method = RequestMethod.GET) @RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public CommonResult<List<MemberBrandAttention>> list(@PathVariable Long memberId) { public CommonResult<CommonPage<MemberBrandAttention>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
List<MemberBrandAttention> memberBrandAttentionList = memberAttentionService.list(memberId); @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
return CommonResult.success(memberBrandAttentionList); Page<MemberBrandAttention> page = memberAttentionService.list(pageNum,pageSize);
return CommonResult.success(CommonPage.restPage(page));
} }
} }

View File

@ -1,11 +1,13 @@
package com.macro.mall.portal.controller; package com.macro.mall.portal.controller;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult; import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.MemberProductCollection; import com.macro.mall.portal.domain.MemberProductCollection;
import com.macro.mall.portal.service.MemberCollectionService; import com.macro.mall.portal.service.MemberCollectionService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -17,16 +19,16 @@ import java.util.List;
*/ */
@Controller @Controller
@Api(tags = "MemberCollectionController", description = "会员收藏管理") @Api(tags = "MemberCollectionController", description = "会员收藏管理")
@RequestMapping("/member/collection") @RequestMapping("/member/productCollection")
public class MemberCollectionController { public class MemberProductCollectionController {
@Autowired @Autowired
private MemberCollectionService memberCollectionService; private MemberCollectionService memberCollectionService;
@ApiOperation("添加商品收藏") @ApiOperation("添加商品收藏")
@RequestMapping(value = "/addProduct", method = RequestMethod.POST) @RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public CommonResult addProduct(@RequestBody MemberProductCollection productCollection) { public CommonResult add(@RequestBody MemberProductCollection productCollection) {
int count = memberCollectionService.addProduct(productCollection); int count = memberCollectionService.add(productCollection);
if (count > 0) { if (count > 0) {
return CommonResult.success(count); return CommonResult.success(count);
} else { } else {
@ -35,10 +37,10 @@ public class MemberCollectionController {
} }
@ApiOperation("删除收藏商品") @ApiOperation("删除收藏商品")
@RequestMapping(value = "/deleteProduct", method = RequestMethod.POST) @RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public CommonResult deleteProduct(Long memberId, Long productId) { public CommonResult delete(Long productId) {
int count = memberCollectionService.deleteProduct(memberId, productId); int count = memberCollectionService.delete(productId);
if (count > 0) { if (count > 0) {
return CommonResult.success(count); return CommonResult.success(count);
} else { } else {
@ -47,10 +49,11 @@ public class MemberCollectionController {
} }
@ApiOperation("显示关注列表") @ApiOperation("显示关注列表")
@RequestMapping(value = "/listProduct/{memberId}", method = RequestMethod.GET) @RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public CommonResult<List<MemberProductCollection>> listProduct(@PathVariable Long memberId) { public CommonResult<CommonPage<MemberProductCollection>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
List<MemberProductCollection> memberProductCollectionList = memberCollectionService.listProduct(memberId); @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
return CommonResult.success(memberProductCollectionList); Page<MemberProductCollection> page = memberCollectionService.list(pageNum,pageSize);
return CommonResult.success(CommonPage.restPage(page));
} }
} }

View File

@ -1,11 +1,13 @@
package com.macro.mall.portal.controller; package com.macro.mall.portal.controller;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult; import com.macro.mall.common.api.CommonResult;
import com.macro.mall.portal.domain.MemberReadHistory; import com.macro.mall.portal.domain.MemberReadHistory;
import com.macro.mall.portal.service.MemberReadHistoryService; import com.macro.mall.portal.service.MemberReadHistoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -46,11 +48,12 @@ public class MemberReadHistoryController {
} }
} }
@ApiOperation("展示浏览记录") @ApiOperation("分页获取用户浏览记录")
@RequestMapping(value = "/list", method = RequestMethod.GET) @RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public CommonResult<List<MemberReadHistory>> list(Long memberId) { public CommonResult<CommonPage<MemberReadHistory>> list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
List<MemberReadHistory> memberReadHistoryList = memberReadHistoryService.list(memberId); @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
return CommonResult.success(memberReadHistoryList); Page<MemberReadHistory> page = memberReadHistoryService.list(pageNum, pageSize);
return CommonResult.success(CommonPage.restPage(page));
} }
} }

View File

@ -23,7 +23,6 @@ public class MemberBrandAttention {
private String brandName; private String brandName;
private String brandLogo; private String brandLogo;
private String brandCity; private String brandCity;
private Integer brandAttentionCount;
private Date createTime; private Date createTime;
public String getId() { public String getId() {
@ -90,14 +89,6 @@ public class MemberBrandAttention {
this.brandCity = brandCity; this.brandCity = brandCity;
} }
public Integer getBrandAttentionCount() {
return brandAttentionCount;
}
public void setBrandAttentionCount(Integer brandAttentionCount) {
this.brandAttentionCount = brandAttentionCount;
}
public Date getCreateTime() { public Date getCreateTime() {
return createTime; return createTime;
} }

View File

@ -1,6 +1,8 @@
package com.macro.mall.portal.repository; package com.macro.mall.portal.repository;
import com.macro.mall.portal.domain.MemberBrandAttention; import com.macro.mall.portal.domain.MemberBrandAttention;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
@ -12,5 +14,5 @@ import java.util.List;
public interface MemberBrandAttentionRepository extends MongoRepository<MemberBrandAttention,String> { public interface MemberBrandAttentionRepository extends MongoRepository<MemberBrandAttention,String> {
MemberBrandAttention findByMemberIdAndBrandId(Long memberId, Long brandId); MemberBrandAttention findByMemberIdAndBrandId(Long memberId, Long brandId);
int deleteByMemberIdAndBrandId(Long memberId,Long brandId); int deleteByMemberIdAndBrandId(Long memberId,Long brandId);
List<MemberBrandAttention> findByMemberId(Long memberId); Page<MemberBrandAttention> findByMemberId(Long memberId, Pageable pageable);
} }

View File

@ -1,6 +1,8 @@
package com.macro.mall.portal.repository; package com.macro.mall.portal.repository;
import com.macro.mall.portal.domain.MemberProductCollection; import com.macro.mall.portal.domain.MemberProductCollection;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
@ -12,5 +14,5 @@ import java.util.List;
public interface MemberProductCollectionRepository extends MongoRepository<MemberProductCollection,String> { public interface MemberProductCollectionRepository extends MongoRepository<MemberProductCollection,String> {
MemberProductCollection findByMemberIdAndProductId(Long memberId, Long productId); MemberProductCollection findByMemberIdAndProductId(Long memberId, Long productId);
int deleteByMemberIdAndProductId(Long memberId,Long productId); int deleteByMemberIdAndProductId(Long memberId,Long productId);
List<MemberProductCollection> findByMemberId(Long memberId); Page<MemberProductCollection> findByMemberId(Long memberId, Pageable pageable);
} }

View File

@ -1,6 +1,8 @@
package com.macro.mall.portal.repository; package com.macro.mall.portal.repository;
import com.macro.mall.portal.domain.MemberReadHistory; import com.macro.mall.portal.domain.MemberReadHistory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
@ -10,5 +12,5 @@ import java.util.List;
* Created by macro on 2018/8/3. * Created by macro on 2018/8/3.
*/ */
public interface MemberReadHistoryRepository extends MongoRepository<MemberReadHistory,String> { public interface MemberReadHistoryRepository extends MongoRepository<MemberReadHistory,String> {
List<MemberReadHistory> findByMemberIdOrderByCreateTimeDesc(Long memberId); Page<MemberReadHistory> findByMemberIdOrderByCreateTimeDesc(Long memberId, Pageable pageable);
} }

View File

@ -1,6 +1,7 @@
package com.macro.mall.portal.service; package com.macro.mall.portal.service;
import com.macro.mall.portal.domain.MemberBrandAttention; import com.macro.mall.portal.domain.MemberBrandAttention;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
@ -17,10 +18,10 @@ public interface MemberAttentionService {
/** /**
* 取消关注 * 取消关注
*/ */
int delete(Long memberId, Long brandId); int delete(Long brandId);
/** /**
* 获取用户关注列表 * 获取用户关注列表
*/ */
List<MemberBrandAttention> list(Long memberId); Page<MemberBrandAttention> list(Integer pageNum,Integer pageSize);
} }

View File

@ -1,6 +1,7 @@
package com.macro.mall.portal.service; package com.macro.mall.portal.service;
import com.macro.mall.portal.domain.MemberProductCollection; import com.macro.mall.portal.domain.MemberProductCollection;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
@ -9,9 +10,9 @@ import java.util.List;
* Created by macro on 2018/8/2. * Created by macro on 2018/8/2.
*/ */
public interface MemberCollectionService { public interface MemberCollectionService {
int addProduct(MemberProductCollection productCollection); int add(MemberProductCollection productCollection);
int deleteProduct(Long memberId, Long productId); int delete(Long productId);
List<MemberProductCollection> listProduct(Long memberId); Page<MemberProductCollection> list(Integer pageNum, Integer pageSize);
} }

View File

@ -1,6 +1,7 @@
package com.macro.mall.portal.service; package com.macro.mall.portal.service;
import com.macro.mall.portal.domain.MemberReadHistory; import com.macro.mall.portal.domain.MemberReadHistory;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
@ -20,7 +21,7 @@ public interface MemberReadHistoryService {
int delete(List<String> ids); int delete(List<String> ids);
/** /**
* 获取用户浏览历史记录 * 分页获取用户浏览历史记录
*/ */
List<MemberReadHistory> list(Long memberId); Page<MemberReadHistory> list(Integer pageNum, Integer pageSize);
} }

View File

@ -1,9 +1,14 @@
package com.macro.mall.portal.service.impl; package com.macro.mall.portal.service.impl;
import com.macro.mall.model.UmsMember;
import com.macro.mall.portal.domain.MemberBrandAttention; import com.macro.mall.portal.domain.MemberBrandAttention;
import com.macro.mall.portal.repository.MemberBrandAttentionRepository; import com.macro.mall.portal.repository.MemberBrandAttentionRepository;
import com.macro.mall.portal.service.MemberAttentionService; import com.macro.mall.portal.service.MemberAttentionService;
import com.macro.mall.portal.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -16,10 +21,16 @@ import java.util.List;
public class MemberAttentionServiceImpl implements MemberAttentionService { public class MemberAttentionServiceImpl implements MemberAttentionService {
@Autowired @Autowired
private MemberBrandAttentionRepository memberBrandAttentionRepository; private MemberBrandAttentionRepository memberBrandAttentionRepository;
@Autowired
private UmsMemberService memberService;
@Override @Override
public int add(MemberBrandAttention memberBrandAttention) { public int add(MemberBrandAttention memberBrandAttention) {
int count = 0; int count = 0;
UmsMember member = memberService.getCurrentMember();
memberBrandAttention.setMemberId(member.getId());
memberBrandAttention.setMemberNickname(member.getNickname());
memberBrandAttention.setMemberIcon(member.getIcon());
MemberBrandAttention findAttention = memberBrandAttentionRepository.findByMemberIdAndBrandId(memberBrandAttention.getMemberId(), memberBrandAttention.getBrandId()); MemberBrandAttention findAttention = memberBrandAttentionRepository.findByMemberIdAndBrandId(memberBrandAttention.getMemberId(), memberBrandAttention.getBrandId());
if (findAttention == null) { if (findAttention == null) {
memberBrandAttentionRepository.save(memberBrandAttention); memberBrandAttentionRepository.save(memberBrandAttention);
@ -29,12 +40,15 @@ public class MemberAttentionServiceImpl implements MemberAttentionService {
} }
@Override @Override
public int delete(Long memberId, Long brandId) { public int delete(Long brandId) {
return memberBrandAttentionRepository.deleteByMemberIdAndBrandId(memberId,brandId); UmsMember member = memberService.getCurrentMember();
return memberBrandAttentionRepository.deleteByMemberIdAndBrandId(member.getId(),brandId);
} }
@Override @Override
public List<MemberBrandAttention> list(Long memberId) { public Page<MemberBrandAttention> list(Integer pageNum, Integer pageSize) {
return memberBrandAttentionRepository.findByMemberId(memberId); UmsMember member = memberService.getCurrentMember();
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
return memberBrandAttentionRepository.findByMemberId(member.getId(),pageable);
} }
} }

View File

@ -1,9 +1,14 @@
package com.macro.mall.portal.service.impl; package com.macro.mall.portal.service.impl;
import com.macro.mall.model.UmsMember;
import com.macro.mall.portal.domain.MemberProductCollection; import com.macro.mall.portal.domain.MemberProductCollection;
import com.macro.mall.portal.repository.MemberProductCollectionRepository; import com.macro.mall.portal.repository.MemberProductCollectionRepository;
import com.macro.mall.portal.service.MemberCollectionService; import com.macro.mall.portal.service.MemberCollectionService;
import com.macro.mall.portal.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -16,10 +21,16 @@ import java.util.List;
public class MemberCollectionServiceImpl implements MemberCollectionService { public class MemberCollectionServiceImpl implements MemberCollectionService {
@Autowired @Autowired
private MemberProductCollectionRepository productCollectionRepository; private MemberProductCollectionRepository productCollectionRepository;
@Autowired
private UmsMemberService memberService;
@Override @Override
public int addProduct(MemberProductCollection productCollection) { public int add(MemberProductCollection productCollection) {
int count = 0; int count = 0;
UmsMember member = memberService.getCurrentMember();
productCollection.setMemberId(member.getId());
productCollection.setMemberNickname(member.getNickname());
productCollection.setMemberIcon(member.getIcon());
MemberProductCollection findCollection = productCollectionRepository.findByMemberIdAndProductId(productCollection.getMemberId(), productCollection.getProductId()); MemberProductCollection findCollection = productCollectionRepository.findByMemberIdAndProductId(productCollection.getMemberId(), productCollection.getProductId());
if (findCollection == null) { if (findCollection == null) {
productCollectionRepository.save(productCollection); productCollectionRepository.save(productCollection);
@ -29,12 +40,15 @@ public class MemberCollectionServiceImpl implements MemberCollectionService {
} }
@Override @Override
public int deleteProduct(Long memberId, Long productId) { public int delete(Long productId) {
return productCollectionRepository.deleteByMemberIdAndProductId(memberId, productId); UmsMember member = memberService.getCurrentMember();
return productCollectionRepository.deleteByMemberIdAndProductId(member.getId(), productId);
} }
@Override @Override
public List<MemberProductCollection> listProduct(Long memberId) { public Page<MemberProductCollection> list(Integer pageNum, Integer pageSize) {
return productCollectionRepository.findByMemberId(memberId); UmsMember member = memberService.getCurrentMember();
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
return productCollectionRepository.findByMemberId(member.getId(),pageable);
} }
} }

View File

@ -1,9 +1,14 @@
package com.macro.mall.portal.service.impl; package com.macro.mall.portal.service.impl;
import com.macro.mall.model.UmsMember;
import com.macro.mall.portal.domain.MemberReadHistory; import com.macro.mall.portal.domain.MemberReadHistory;
import com.macro.mall.portal.repository.MemberReadHistoryRepository; import com.macro.mall.portal.repository.MemberReadHistoryRepository;
import com.macro.mall.portal.service.MemberReadHistoryService; import com.macro.mall.portal.service.MemberReadHistoryService;
import com.macro.mall.portal.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -18,8 +23,14 @@ import java.util.List;
public class MemberReadHistoryServiceImpl implements MemberReadHistoryService { public class MemberReadHistoryServiceImpl implements MemberReadHistoryService {
@Autowired @Autowired
private MemberReadHistoryRepository memberReadHistoryRepository; private MemberReadHistoryRepository memberReadHistoryRepository;
@Autowired
private UmsMemberService memberService;
@Override @Override
public int create(MemberReadHistory memberReadHistory) { public int create(MemberReadHistory memberReadHistory) {
UmsMember member = memberService.getCurrentMember();
memberReadHistory.setMemberId(member.getId());
memberReadHistory.setMemberNickname(member.getNickname());
memberReadHistory.setMemberIcon(member.getIcon());
memberReadHistory.setId(null); memberReadHistory.setId(null);
memberReadHistory.setCreateTime(new Date()); memberReadHistory.setCreateTime(new Date());
memberReadHistoryRepository.save(memberReadHistory); memberReadHistoryRepository.save(memberReadHistory);
@ -39,7 +50,9 @@ public class MemberReadHistoryServiceImpl implements MemberReadHistoryService {
} }
@Override @Override
public List<MemberReadHistory> list(Long memberId) { public Page<MemberReadHistory> list(Integer pageNum, Integer pageSize) {
return memberReadHistoryRepository.findByMemberIdOrderByCreateTimeDesc(memberId); UmsMember member = memberService.getCurrentMember();
Pageable pageable = PageRequest.of(pageNum-1, pageSize);
return memberReadHistoryRepository.findByMemberIdOrderByCreateTimeDesc(member.getId(),pageable);
} }
} }