|
@@ -2,14 +2,9 @@ package cn.rankin.userservice.service;
|
|
|
|
|
|
import cn.rankin.common.utils.enums.BaseStatusEnum;
|
|
|
import cn.rankin.common.utils.util.ListUtil;
|
|
|
-import cn.rankin.data.api.product.entity.Course;
|
|
|
+
|
|
|
import cn.rankin.data.api.product.entity.MerchantProduct;
|
|
|
-import cn.rankin.data.api.product.entity.Product;
|
|
|
-import cn.rankin.data.api.product.entity.Recommend;
|
|
|
import cn.rankin.data.api.user.entity.UserRecommend;
|
|
|
-//import cn.rankin.productservice.repository.CourseRepository;
|
|
|
-//import cn.rankin.productservice.repository.MerchantProductRepository;
|
|
|
-//import cn.rankin.productservice.repository.ProductRepository;
|
|
|
import cn.rankin.userservice.repository.UserRecommendRepository;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -22,15 +17,6 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class UserRecommendService {
|
|
|
|
|
|
-// @Autowired
|
|
|
-// private MerchantProductRepository merchantProductRepository;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private ProductRepository productRepository;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private CourseRepository courseRepository;
|
|
|
-
|
|
|
@Autowired
|
|
|
private UserRecommendRepository userRecommendRepository;
|
|
|
|
|
@@ -43,104 +29,50 @@ public class UserRecommendService {
|
|
|
return recommendList;
|
|
|
}
|
|
|
|
|
|
- /*public List<Recommend> setProductInfo(List<Recommend> recommendList) {
|
|
|
- if (CollectionUtils.isEmpty(recommendList)) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
- List<String> productIdList = new ArrayList<>();
|
|
|
- recommendList.forEach(recommend -> productIdList.add(recommend.getPid()));
|
|
|
-// List<MerchantProduct> merchantProductList = merchantProductRepository.findByPidIn(productIdList);
|
|
|
-// Map<String, MerchantProduct> merchantProductMap = ListUtil.convert(merchantProductList, "pid", MerchantProduct.class);
|
|
|
- List<Product> productList = productRepository.findByPids(productIdList);
|
|
|
- Map<String, Product> productMap = ListUtil.convert(productList, "pid", Product.class);
|
|
|
-
|
|
|
- List<Recommend> result = new ArrayList<>();
|
|
|
- for (Recommend recommend : recommendList) {
|
|
|
- Product product = productMap.get(recommend.getPid());
|
|
|
- if (product == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- recommend.setName(product.getName());
|
|
|
- recommend.setCode(product.getCode());
|
|
|
- result.add(recommend);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }*/
|
|
|
-
|
|
|
- /*public List<Recommend> setCourseInfo(List<Recommend> recommendList) {
|
|
|
- if (CollectionUtils.isEmpty(recommendList)) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
+ public List<UserRecommend> put(String uid, List<MerchantProduct> products) {
|
|
|
List<String> productIdList = new ArrayList<>();
|
|
|
- recommendList.forEach(recommend -> productIdList.add(recommend.getPid()));
|
|
|
- List<Course> courseList = courseRepository.findByIds(productIdList);
|
|
|
- Map<String, Course> courseMap = ListUtil.convert(courseList, "id", Course.class);
|
|
|
-
|
|
|
- List<Recommend> result = new ArrayList<>();
|
|
|
- for (Recommend recommend : recommendList) {
|
|
|
- Course course = courseMap.get(recommend.getPid());
|
|
|
- if (course == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- recommend.setName(course.getName());
|
|
|
- recommend.setCode(course.getCode());
|
|
|
- recommend.setBreadCrumb(course.getBreadCrumb());
|
|
|
- recommend.setTitle(course.getTitle());
|
|
|
- recommend.setSubTitle(course.getSubTitle());
|
|
|
- recommend.setCoverUrl(course.getCoverUrl());
|
|
|
- result.add(recommend);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }*/
|
|
|
-
|
|
|
- public List<UserRecommend> put(String uid, List<String> productIdList) {
|
|
|
- if (CollectionUtils.isEmpty(productIdList)) {
|
|
|
- return null;
|
|
|
+ if (!CollectionUtils.isEmpty(products)) {
|
|
|
+ products.forEach(product -> productIdList.add(product.getPid()) );
|
|
|
}
|
|
|
|
|
|
- List<UserRecommend> recommendList = userRecommendRepository.findByUid(uid);
|
|
|
+ List<UserRecommend> userRecommendList = userRecommendRepository.findByUid(uid);
|
|
|
List<String> existRecommendIdList = new ArrayList<>();
|
|
|
|
|
|
// 更新现存的
|
|
|
- recommendList.forEach(recommend -> {
|
|
|
- String productId = recommend.getPid();
|
|
|
- if (productIdList.contains(productId)) {
|
|
|
+ userRecommendList.forEach(recommend -> {
|
|
|
+ String pid = recommend.getPid();
|
|
|
+ if (productIdList.contains(pid)) {
|
|
|
recommend.setStatus(BaseStatusEnum.NORMAL);
|
|
|
}else {
|
|
|
recommend.setStatus(BaseStatusEnum.DEL);
|
|
|
}
|
|
|
- existRecommendIdList.add(productId);
|
|
|
+ existRecommendIdList.add(pid);
|
|
|
});
|
|
|
|
|
|
// 更新新加的
|
|
|
- /* List<String> notExistsRecommendIdList = ListUtil.subtract(productIdList, existRecommendIdList);
|
|
|
+ List<String> notExistsRecommendIdList = ListUtil.subtract(productIdList, existRecommendIdList);
|
|
|
if (notExistsRecommendIdList != null && notExistsRecommendIdList.size() > 0) {
|
|
|
- List<MerchantProduct> merchantProductList = merchantProductRepository.findByPidIn(notExistsRecommendIdList);
|
|
|
- Map<String, MerchantProduct> merchantProductMap = ListUtil.convert(merchantProductList, "pid", MerchantProduct.class);
|
|
|
+ Map<String, MerchantProduct> merchantProductMap = ListUtil.convert(products, "pid", MerchantProduct.class);
|
|
|
for (String productId : notExistsRecommendIdList) {
|
|
|
MerchantProduct merchantProduct = merchantProductMap.get(productId);
|
|
|
- *//*if (merchantProduct == null || !merchantProduct.getMerchantId().equals(merchantId)) {
|
|
|
- continue;
|
|
|
- }*//*
|
|
|
UserRecommend recommend = new UserRecommend();
|
|
|
recommend.setPid(productId);
|
|
|
- recommend.setStatus(BaseStatusEnum.NORMAL);
|
|
|
recommend.setUid(uid);
|
|
|
+ recommend.setStatus(BaseStatusEnum.NORMAL);
|
|
|
recommend.setType(merchantProduct.getType());
|
|
|
- recommendList.add(recommend);
|
|
|
+ userRecommendList.add(recommend);
|
|
|
}
|
|
|
- }*/
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
// 排序
|
|
|
- recommendList.forEach( recommend -> {
|
|
|
+ userRecommendList.forEach( recommend -> {
|
|
|
String productId = recommend.getPid();
|
|
|
Integer sort = productIdList.indexOf(productId);
|
|
|
recommend.setSort(sort);
|
|
|
});
|
|
|
|
|
|
- userRecommendRepository.save(recommendList);
|
|
|
+ userRecommendRepository.save(userRecommendList);
|
|
|
List<UserRecommend> result = userRecommendRepository.findByUid(uid);
|
|
|
return result;
|
|
|
}
|