Browse Source

CMS support UserTag UserRecommend module

guozhaoshun 6 years ago
parent
commit
b7f7ae4fbd
17 changed files with 217 additions and 238 deletions
  1. 57 18
      rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserController.java
  2. 31 9
      rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserTagController.java
  3. 7 0
      rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/MerchantProductService.java
  4. 8 0
      rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/ProductService.java
  5. 2 1
      rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/UserRecommendService.java
  6. 16 0
      rankin-data-api/src/main/java/cn/rankin/data/api/user/entity/UserRecommend.java
  7. 4 0
      rankin-data-api/src/main/java/cn/rankin/data/api/user/entity/UserTag.java
  8. 5 0
      rankin-product-service/src/main/java/cn/rankin/productservice/controller/ProductController.java
  9. 10 0
      rankin-product-service/src/main/java/cn/rankin/productservice/controller/cms/MerchantProductController.java
  10. 2 1
      rankin-product-service/src/main/java/cn/rankin/productservice/repository/MerchantProductRepository.java
  11. 27 0
      rankin-product-service/src/main/java/cn/rankin/productservice/service/MerchantProductService.java
  12. 4 0
      rankin-product-service/src/main/java/cn/rankin/productservice/service/ProductService.java
  13. 5 7
      rankin-user-service/src/main/java/cn/rankin/userservice/controller/UserRecommendController.java
  14. 11 42
      rankin-user-service/src/main/java/cn/rankin/userservice/controller/UserTagController.java
  15. 10 8
      rankin-user-service/src/main/java/cn/rankin/userservice/repository/UserTagProductRelationRepository.java
  16. 17 85
      rankin-user-service/src/main/java/cn/rankin/userservice/service/UserRecommendService.java
  17. 1 67
      rankin-user-service/src/main/java/cn/rankin/userservice/service/UserTagProductRelationService.java

+ 57 - 18
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserController.java

@@ -1,19 +1,26 @@
 package cn.rankin.cmsweb.controller.user;
 
+import cn.rankin.cmsweb.service.product.MerchantProductService;
+import cn.rankin.cmsweb.service.product.ProductService;
 import cn.rankin.cmsweb.service.user.UserRecommendService;
 import cn.rankin.cmsweb.service.user.UserTagServiceInterface;
 import cn.rankin.common.utils.api.model.APICode;
 import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.data.api.product.entity.MerchantProduct;
+import cn.rankin.data.api.product.vo.ProductVo;
 import cn.rankin.data.api.product.vo.UserRecommendVo;
 import cn.rankin.data.api.user.entity.UserRecommend;
 import cn.rankin.data.api.user.entity.UserTag;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.List;
 
+@Slf4j
 @RestController
 @RequestMapping(value = "/user")
 public class UserController {
@@ -24,6 +31,12 @@ public class UserController {
     @Autowired
     private UserTagServiceInterface userTagService;
 
+    @Autowired
+    private ProductService productService;
+
+    @Autowired
+    private MerchantProductService merchantProductService;
+
     // 用户推荐位设置
     @RequestMapping(value = "/userRecommend/uid/{uid}", method = RequestMethod.GET)
     public APIResult<List<UserRecommendVo>> getUserRecommend(@PathVariable("uid") String uid) {
@@ -31,16 +44,31 @@ public class UserController {
             return APIResult.error(APICode.PARAMETER_ERROR);
         }
         List<UserRecommend> userRecommendList = userRecommendService.get(uid);
+
+        setProductInfo(userRecommendList);
         return APIResult.ok(userRecommendList);
     }
 
+
+
     @RequestMapping(value = "/userRecommend/uid/{uid}", method = RequestMethod.PUT)
     public APIResult<List<UserRecommendVo>> updateUserRecommend(@PathVariable("uid") String uid, @RequestBody List<String> productIdList) {
         if (StringUtils.isEmpty(uid) || CollectionUtils.isEmpty(productIdList)) {
             return APIResult.error(APICode.PARAMETER_ERROR);
         }
-
-        List<UserRecommend> userRecommendList = userRecommendService.put(uid, productIdList);
+        List<MerchantProduct> merchantProducts = new ArrayList<>();
+        productIdList.forEach(pid -> {
+            MerchantProduct merchantProduct = merchantProductService.findMerchantProductByPid(pid);
+            if(null != merchantProduct){
+                merchantProducts.add(merchantProduct);
+            }else{
+                log.info("Not found MerchantProduct by pid , pid={}",pid);
+            }
+        });
+
+        List<UserRecommend> userRecommendList = userRecommendService.put(uid, merchantProducts);
+
+        setProductInfo(userRecommendList);
         return APIResult.ok(userRecommendList);
     }
 
@@ -48,26 +76,37 @@ public class UserController {
     @RequestMapping(value = "/userTag/uid/{uid}", method = RequestMethod.GET)
     public APIResult<UserTag> getUserTagsByUid(@PathVariable("uid") String uid) {
         List<UserTag> userTags = userTagService.findUserTagByUid(uid);
-        if (userTags != null) {
-//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
-
-            userTags.forEach(userTag -> {
-                userTag.getRelationList();
-
-
-
-
-
-            });
-
-
-            /*public List<ItemVo> findItemByPids(List<String> productIdList, String merchantId) {
-                return productClient.findItemByPids(productIdList,merchantId);
-            }*/
+        if (userTags != null && userTags.size() > 0) {
+            /*userTags.forEach(userTag -> {
+                List<UserTagProductRelation> relationList = userTagProductRelationServiceInterface.findByUserTagId(userTag.getId());
+                List<String>  productIdList = new ArrayList<>();
+                if(null != relationList && relationList.size() > 0){
+                    relationList.forEach(relation -> {
+                        productIdList.add(relation.getPid());
+                    });
+                    List<ItemVo> itemVoList = productService.findItemByPids(productIdList, merchantId);
+                    userTag.setRecs(itemVoList);
+                }
+
+            });*/
             return APIResult.ok(userTags);
         }else{
             return APIResult.error(APICode.NOT_EXISTS);
         }
     }
 
+
+
+    private void setProductInfo(List<UserRecommend> userRecommendList) {
+        userRecommendList.forEach(userRecommend -> {
+            ProductVo productVo = productService.findProductByPid(userRecommend.getPid());
+            if(null != productVo){
+                userRecommend.setName(productVo.getName());
+                userRecommend.setCode(productVo.getCode());
+            }else{
+                log.info("Not found Product by pid , pid={}",userRecommend.getPid());
+            }
+        });
+    }
+
 }

+ 31 - 9
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserTagController.java

@@ -2,21 +2,27 @@ package cn.rankin.cmsweb.controller.user;
 
 import cn.rankin.cmsweb.assist.resolver.NeedUser;
 import cn.rankin.cmsweb.entity.UserDetails;
-import cn.rankin.cmsweb.service.user.MerchantInfoSetService;
+import cn.rankin.cmsweb.service.product.MerchantProductService;
+import cn.rankin.cmsweb.service.user.UserTagProductRelationServiceInterface;
 import cn.rankin.cmsweb.service.user.UserTagServiceInterface;
 import cn.rankin.common.utils.api.model.APICode;
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.util.BeanUtil;
-import cn.rankin.data.api.product.vo.TagVo;
+import cn.rankin.data.api.product.entity.MerchantProduct;
 import cn.rankin.data.api.user.dto.UserTagDTO;
 import cn.rankin.data.api.user.dto.UserTagSearchDTO;
 import cn.rankin.data.api.user.entity.UserTag;
+import cn.rankin.data.api.user.entity.UserTagProductRelation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
+import java.util.List;
+
 @Slf4j
 @RestController
 @RequestMapping(value = "/userTag")
@@ -26,7 +32,10 @@ public class UserTagController {
     private UserTagServiceInterface userTagService;
 
     @Autowired
-    private MerchantInfoSetService<TagVo> merchantInfoSetService;
+    private UserTagProductRelationServiceInterface userTagProductRelationServiceInterface;
+
+    @Autowired
+    private MerchantProductService merchantProductService;
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     public APIResult<Page<UserTag>> search(@NeedUser UserDetails user, UserTagSearchDTO searchDTO) {
@@ -35,7 +44,6 @@ public class UserTagController {
         }
         Page<UserTag> userTagPage = userTagService.search(BeanUtil.convertToMap(searchDTO));
         if (userTagPage != null) {
-            //merchantInfoSetService.setMerchantInfo(apiResult.getData().getList());
             return APIResult.ok(userTagPage);
         }else{
             return APIResult.error(APICode.NOT_EXISTS);
@@ -46,9 +54,25 @@ public class UserTagController {
     public APIResult<UserTag> getUserTag(@PathVariable("id") String id) {
         UserTag userTag = userTagService.getUserTag(id);
         if (userTag != null) {
-//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
+            List<UserTagProductRelation> relationList = userTagProductRelationServiceInterface.findByUserTagId(userTag.getId());
+            if( !CollectionUtils.isEmpty(relationList)){
+                //开始组装产品数据
+                List<MerchantProduct> merchantProductList = new ArrayList<>();
+                relationList.forEach(relation -> {
+                    String pid = relation.getPid();
+                    MerchantProduct merchantProduct = merchantProductService.findMerchantProductByPid(pid);
+                    if(null != merchantProduct){
+                        merchantProductList.add(merchantProduct);
+                    }else{
+                        log.error("not found MerchantProduct by pid, pid={}", pid);
+                    }
+                });
+
+                userTag.setProductList(merchantProductList);
+            }
             return APIResult.ok(userTag);
         }else{
+            log.error("not found UserTag by id, id={}", id);
             return APIResult.error(APICode.NOT_EXISTS);
         }
     }
@@ -57,7 +81,6 @@ public class UserTagController {
     public APIResult<UserTag> create(@RequestBody UserTagDTO dto) {
         UserTag userTag = userTagService.create(dto);
         if (userTag != null) {
-//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
             return APIResult.ok(userTag);
         }else{
             return APIResult.error(APICode.NOT_EXISTS);
@@ -71,8 +94,7 @@ public class UserTagController {
         }
         UserTag userTag = userTagService.update(dto);
         if (userTag != null) {
-            log.error("update UserTag is error, pid={}", dto.getId());
-//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
+            log.error("update UserTag is error, id={}", dto.getId());
             return APIResult.ok(userTag);
         }else{
             return APIResult.error(APICode.NOT_EXISTS);
@@ -88,7 +110,7 @@ public class UserTagController {
         if(flag){
             return APIResult.ok();
         }else{
-            log.error("delete UserTag is error, pid={}", id);
+            log.error("delete UserTag is error, id={}", id);
             return APIResult.error(APICode.OPERATE_ERROR);
         }
     }

+ 7 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/MerchantProductService.java

@@ -31,4 +31,11 @@ public interface MerchantProductService {
 
     @RequestMapping(value = "/merchant/product/list", method = RequestMethod.POST)
     APIResult<List<MerchantProductVo>> getList(@RequestBody List<String> productIdList, @RequestParam("merchantId") String merchantId);
+
+    @RequestMapping(value = "/merchant/product/pids", method = RequestMethod.POST)
+    List<MerchantProduct> findMerchantProductList(@RequestBody List<String> productIdList, @RequestParam("merchantId") String merchantId);
+
+    @RequestMapping(value = "/merchant/product/pid", method = RequestMethod.GET)
+    MerchantProduct findMerchantProductByPid(@RequestParam("pid") String pid);
+
 }

+ 8 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/ProductService.java

@@ -2,6 +2,7 @@ package cn.rankin.cmsweb.service.product;
 
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.app.vo.ItemVo;
 import cn.rankin.data.api.product.dto.CourseDTO;
 import cn.rankin.data.api.product.dto.PackageDTO;
 import cn.rankin.data.api.product.dto.SupportDTO;
@@ -53,6 +54,13 @@ public interface ProductService {
     @RequestMapping(value = "/product/ids", method = RequestMethod.GET)
     APIResult<List<ProductVo>> findProductByIds(@RequestParam("id") List<String> ids);
 
+    @RequestMapping(value = "/product/pid/{pid}", method = RequestMethod.GET)
+    ProductVo findProductByPid(@PathVariable("pid") String pid);
+
     @RequestMapping(value = "/product/ids/info", method = RequestMethod.PUT)
     List<UserRecommend> setProductInfo(List<UserRecommend> userRecommendList);
+
+    @RequestMapping(value = "/item/pids", method = RequestMethod.POST)
+    List<ItemVo> findItemByPids(@RequestBody List<String> productIdList,
+                                @RequestParam("merchantId") String merchantId );
 }

+ 2 - 1
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/UserRecommendService.java

@@ -1,5 +1,6 @@
 package cn.rankin.cmsweb.service.user;
 
+import cn.rankin.data.api.product.entity.MerchantProduct;
 import cn.rankin.data.api.user.entity.UserRecommend;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -16,5 +17,5 @@ public interface UserRecommendService {
     List<UserRecommend> get(@RequestParam("uid") String uid);
 
     @RequestMapping(value = "/userRecommend/uid", method = RequestMethod.PUT)
-    List<UserRecommend> put(@RequestParam("uid") String uid, @RequestBody List<String> productIdList);
+    List<UserRecommend> put(@RequestParam("uid") String uid, @RequestBody List<MerchantProduct> productList);
 }

+ 16 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/entity/UserRecommend.java

@@ -52,7 +52,23 @@ public class UserRecommend implements Serializable {
 	@Temporal(TemporalType.TIMESTAMP)
 	private Date gmtModified;
 
+	@Transient
+	private String name;
 
+	@Transient
+	private String code;
+
+	@Transient
+	private String title;
+
+	@Transient
+	private String subTitle;
+
+	@Transient
+	private String breadCrumb;
+
+	@Transient
+	private String coverUrl;
 
 
 }

+ 4 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/entity/UserTag.java

@@ -1,6 +1,7 @@
 package cn.rankin.data.api.user.entity;
 
 import cn.rankin.common.utils.enums.BaseStatusEnum;
+import cn.rankin.data.api.app.vo.ItemVo;
 import cn.rankin.data.api.product.entity.MerchantProduct;
 import lombok.Data;
 import lombok.ToString;
@@ -59,4 +60,7 @@ public class UserTag implements Serializable {
 	@Transient
 	private List<UserTagProductRelation> relationList;
 
+	@Transient
+	private List<ItemVo> recs;
+
 }

+ 5 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/controller/ProductController.java

@@ -128,6 +128,11 @@ public class ProductController {
         return productService.findByPids(pidList);
     }
 
+    @RequestMapping(value = "/pid/{pid}", method = RequestMethod.GET)
+    public Product findProductsByPid(@PathVariable("pid") String pid) {
+        return productService.findProductByPid(pid);
+    }
+
     /**
      *
      * @param pid

+ 10 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/controller/cms/MerchantProductController.java

@@ -97,6 +97,16 @@ public class MerchantProductController {
         return APIResult.ok(merchantProductList);
     }
 
+    @RequestMapping(value = "/pids", method = RequestMethod.POST)
+    public List<MerchantProduct> findByPidsAndMerchantId(@RequestBody List<String> productIdList, @RequestParam("merchantId") String merchantId){
+        return merchantProductService.findByPidsAndMerchantId(productIdList, merchantId);
+    }
+
+    @RequestMapping(value = "/pid", method = RequestMethod.GET)
+    public MerchantProduct findByPid(@RequestParam("pid") String pid){
+        return merchantProductService.findByPid(pid);
+    }
+
 
 
 }

+ 2 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/repository/MerchantProductRepository.java

@@ -19,7 +19,8 @@ public interface MerchantProductRepository extends BasicJpaRepository<MerchantPr
     @Query(value = "select m from MerchantProduct m where m.pid in (?1) and m.merchantId = ?2 order by m.sort")
     List<MerchantProduct> findByPidsAndMerchantId(List<String> pids, String merchantId);
 
-
+    @Query(value = "select m from MerchantProduct m where m.pid in (?1) order by m.sort")
+    List<MerchantProduct> findByPids(List<String> pids);
 
     @Query(value = "select m from MerchantProduct m where m.pid in (?1) and m.merchantId = ?2 and m.status = ?3 order by m.sort")
     List<MerchantProduct> findByPidsAndMerchantId(List<String> pids, String merchantId, BaseStatusEnum status);

+ 27 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/service/MerchantProductService.java

@@ -6,6 +6,7 @@ import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.enums.ProductTypeEnum;
 import cn.rankin.common.utils.util.JpaSortUtil;
+import cn.rankin.common.utils.util.ListUtil;
 import cn.rankin.data.api.product.entity.*;
 import cn.rankin.data.api.product.vo.PackageProductVo;
 import cn.rankin.productservice.code.ProductServiceAPICode;
@@ -14,6 +15,7 @@ import cn.rankin.productservice.repository.MerchantProductRepository;
 import cn.rankin.productservice.repository.ProductRepository;
 import cn.rankin.productservice.repository.TagRepository;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -318,4 +320,29 @@ public class MerchantProductService {
 
         return merchantProductList;
     }
+
+
+    public List<MerchantProduct> findByPidsAndMerchantId(List<String> productIdList, String merchantId){
+        List<MerchantProduct> merchantProductList = merchantProductRepository.findByPidsAndMerchantId(productIdList, merchantId);
+
+        Map<String, MerchantProduct> merchantProductMap = ListUtil.convert(merchantProductList, "pid", MerchantProduct.class);
+
+        List<MerchantProduct> sortMerchantProductList = new ArrayList<>();
+        for (String productId : productIdList) {
+            MerchantProduct merchantProduct = merchantProductMap.get(productId);
+            if (merchantProduct != null) {
+                sortMerchantProductList.add(merchantProduct);
+            }
+        }
+        return sortMerchantProductList;
+    }
+
+    public MerchantProduct findByPid(String pid) {
+        List<MerchantProduct> merchantProductList = merchantProductRepository.findByPid(pid);
+        if(null != merchantProductList && merchantProductList.size() > 0 ){
+            return merchantProductList.get(0);
+        }else{
+            return null;
+        }
+    }
 }

+ 4 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/service/ProductService.java

@@ -312,5 +312,9 @@ public class ProductService {
         List<Product> productList = productRepository.findByPids(pidList);
         return APIResult.ok(productList);
     }
+
+    public Product findProductByPid(String pid) {
+        return productRepository.findByPid(pid);
+    }
 }
 

+ 5 - 7
rankin-user-service/src/main/java/cn/rankin/userservice/controller/UserRecommendController.java

@@ -1,5 +1,6 @@
 package cn.rankin.userservice.controller;
 
+import cn.rankin.data.api.product.entity.MerchantProduct;
 import cn.rankin.data.api.user.entity.UserRecommend;
 import cn.rankin.userservice.service.UserRecommendService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,19 +17,16 @@ public class UserRecommendController {
 
     @RequestMapping(value = "/uid",method = RequestMethod.GET)
     public List<UserRecommend> get(@RequestParam("uid") String uid) {
-        List<UserRecommend> recommendList = userRecommendService.get(uid);
-        return recommendList;
+        return userRecommendService.get(uid);
     }
 
     @RequestMapping(value = "/uid",method = RequestMethod.PUT)
-    public List<UserRecommend> put(@RequestParam("uid") String uid, @RequestBody List<String> productIdList) {
-        List<UserRecommend> recommendList = userRecommendService.put(uid, productIdList);
-        return recommendList;
+    public List<UserRecommend> put(@RequestParam("uid") String uid, @RequestBody List<MerchantProduct> products) {
+        return userRecommendService.put(uid, products);
     }
 
     @RequestMapping(value = "/courses/uid/{uid}", method = RequestMethod.GET)
     public List<UserRecommend> getUserRecommendCourses(@RequestParam("uid") String uid) {
-        List<UserRecommend> recommendList = userRecommendService.getUserRecommendCourses(uid);
-        return recommendList;
+        return userRecommendService.getUserRecommendCourses(uid);
     }
 }

+ 11 - 42
rankin-user-service/src/main/java/cn/rankin/userservice/controller/UserTagController.java

@@ -3,9 +3,6 @@ package cn.rankin.userservice.controller;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.enums.BaseStatusEnum;
-import cn.rankin.common.utils.util.ListUtil;
-import cn.rankin.data.api.app.vo.ItemVo;
-import cn.rankin.data.api.product.entity.MerchantProduct;
 import cn.rankin.data.api.user.dto.UserTagDTO;
 import cn.rankin.data.api.user.dto.UserTagSearchDTO;
 import cn.rankin.data.api.user.entity.UserTag;
@@ -17,10 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
 
 @Slf4j
 @RestController
@@ -33,19 +28,16 @@ public class UserTagController {
     @Autowired
     private UserTagProductRelationService userTagProductRelationService;
 
-/*    @Autowired
-    private MerchantProductRepository merchantProductRepository;*/
-
     @RequestMapping(value = "/{id}", method = RequestMethod.GET)
     public UserTag getUserTag(@PathVariable("id") String id) {
 
         UserTag userTag = userTagService.getUserTag(id);
 
-        if(null != userTag){
+ /*       if(null != userTag){
             String userTagId = userTag.getId();
             List<UserTagProductRelation> userTagProductRelations = userTagProductRelationService.findByTagId(userTagId);
             userTag.setRelationList(userTagProductRelations);
-        }
+        }*/
 
         return userTag;
     }
@@ -56,8 +48,7 @@ public class UserTagController {
 
         //标签下   课程数据
         userTagList.forEach(userTag -> {
-            String userTagId = userTag.getId();
-            List<UserTagProductRelation> userTagProductRelations = userTagProductRelationService.findByTagId(userTagId);
+            List<UserTagProductRelation> userTagProductRelations = userTagProductRelationService.findByTagId(userTag.getId(), BaseStatusEnum.NORMAL);
             userTag.setRelationList(userTagProductRelations);
         });
 
@@ -69,11 +60,11 @@ public class UserTagController {
         List<UserTag> userTagList = userTagService.findUserTagByUid(uid);
 
         //标签下   课程数据
-        userTagList.forEach(userTag -> {
+       /* userTagList.forEach(userTag -> {
             String userTagId = userTag.getId();
             List<UserTagProductRelation> userTagProductRelations = userTagProductRelationService.findByTagId(userTagId);
             userTag.setRelationList(userTagProductRelations);
-        });
+        });*/
 
         return userTagList;
     }
@@ -101,10 +92,10 @@ public class UserTagController {
 
         String userTagId = userTag.getId();
         List<String> productIdList = userTagDTO.getProductList();
-        userTagProductRelationService.updateByTagId(userTagId,productIdList);
+        if( !CollectionUtils.isEmpty(productIdList)){
+            userTagProductRelationService.updateByTagId(userTagId,productIdList);
+        }
 
-       /* List<MerchantProduct> merchantProductList = getMerchantProductList(userTagId);
-        userTag.setProductList(merchantProductList);*/
         return userTag;
     }
 
@@ -117,10 +108,9 @@ public class UserTagController {
 
         String userTagId = result.getId();
         List<String> productIdList = userTagDTO.getProductList();
-        userTagProductRelationService.updateByTagId(userTagId,productIdList);
-
-        /*List<MerchantProduct> merchantProductList = getMerchantProductList(userTagId);
-        result.setProductList(merchantProductList);*/
+        if( null != productIdList){
+            userTagProductRelationService.updateByTagId(userTagId,productIdList);
+        }
 
         return result;
     }
@@ -131,25 +121,4 @@ public class UserTagController {
     }
 
 
-/*    public List<MerchantProduct> getMerchantProductList(String tagId) {
-        List<UserTagProductRelation> relationList = userTagProductRelationService.findByTagId(tagId, BaseStatusEnum.NORMAL);
-        if (CollectionUtils.isEmpty(relationList)) {
-            return new ArrayList<>();
-        }
-
-        List<String> productIdList = new ArrayList<>();
-        relationList.forEach(relation -> productIdList.add(relation.getPid()));
-        List<MerchantProduct> merchantProductList = merchantProductRepository.findByPidIn(productIdList);
-        Map<String, MerchantProduct> merchantProductMap = ListUtil.convert(merchantProductList, "pid", MerchantProduct.class);
-
-        List<MerchantProduct> sortMerchantProductList = new ArrayList<>();
-        for (String productId : productIdList) {
-            MerchantProduct merchantProduct = merchantProductMap.get(productId);
-            if (merchantProduct != null) {
-                sortMerchantProductList.add(merchantProduct);
-            }
-        }
-        return sortMerchantProductList;
-    }*/
-
 }

+ 10 - 8
rankin-user-service/src/main/java/cn/rankin/userservice/repository/UserTagProductRelationRepository.java

@@ -2,7 +2,6 @@ package cn.rankin.userservice.repository;
 
 import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.jpa.BasicJpaRepository;
-import cn.rankin.data.api.product.entity.MerchantProductTagRelation;
 import cn.rankin.data.api.user.entity.UserTagProductRelation;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
@@ -17,6 +16,15 @@ public interface UserTagProductRelationRepository extends BasicJpaRepository<Use
 
     List<UserTagProductRelation> findByTagId(String tagId);
 
+    @Modifying
+    @Query(value = "update UserTagProductRelation r set r.status = 1 where r.tagId = :tagId")
+    Integer deleteByTagId(@Param("tagId") String tagId);
+
+/*
+    @Modifying
+    @Query(value = "update UserTagProductRelation r set r.status = 1 where r.pid = :productId and r.tagId = :tagId")
+    Integer deleteByPidAndTagId(@Param("productId") String productId, @Param("tagId") String tagId);
+
     List<UserTagProductRelation> findByTagIdIn(List<String> tagIds);
 
     @Query(value = "select r from UserTagProductRelation r where r.pid in (?1) and r.tagId in (?2) and r.status = 0")
@@ -29,12 +37,6 @@ public interface UserTagProductRelationRepository extends BasicJpaRepository<Use
 
     @Query(value = "select r from UserTagProductRelation r where r.tagId = ?1 and r.pid in (?2) and r.status = 0 order by r.sort limit ?3, ?4", nativeQuery = true)
     List<UserTagProductRelation> findByTagIdAndPids(String tagId, List<String> productIdList, Long start, Integer size);
+*/
 
-    @Modifying
-    @Query(value = "update UserTagProductRelation r set r.status = 1 where r.tagId = :tagId")
-    Integer deleteByTagId(@Param("tagId") String tagId);
-
-    @Modifying
-    @Query(value = "update UserTagProductRelation r set r.status = 1 where r.pid = :productId and r.tagId = :tagId")
-    Integer deleteByPidAndTagId(@Param("productId") String productId, @Param("tagId") String tagId);
 }

+ 17 - 85
rankin-user-service/src/main/java/cn/rankin/userservice/service/UserRecommendService.java

@@ -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;
     }

+ 1 - 67
rankin-user-service/src/main/java/cn/rankin/userservice/service/UserTagProductRelationService.java

@@ -4,16 +4,12 @@ import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.util.JpaSortUtil;
 import cn.rankin.common.utils.util.ListUtil;
-import cn.rankin.data.api.app.vo.ItemVo;
-import cn.rankin.data.api.product.entity.MerchantProductTagRelation;
 import cn.rankin.data.api.user.entity.UserTagProductRelation;
-//import cn.rankin.productservice.repository.MerchantProductTagRelationRepository;
 import cn.rankin.userservice.repository.UserTagProductRelationRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -26,7 +22,7 @@ public class UserTagProductRelationService {
     @Autowired
     private UserTagProductRelationRepository relationRepository;
 
-    public List<UserTagProductRelation> findByTagId(String tagId) {
+    public List<UserTagProductRelation> findByUserTagId(String tagId) {
         UserTagProductRelation relation = new UserTagProductRelation();
         relation.setTagId(tagId);
         relation.setStatus(BaseStatusEnum.NORMAL);
@@ -37,76 +33,14 @@ public class UserTagProductRelationService {
             this.put("sort", BaseOrderEnum.ASC);
         }};
         List<UserTagProductRelation> relationList = relationRepository.find(relation, JpaSortUtil.sort(sort));
-/*
-        if (CollectionUtils.isEmpty(relationList)) {
-            return relationList;
-        }
-
-        List<String> productIdList = new ArrayList<>();
-
-        relationList.forEach(userTagProductRelation -> {
-            String productId = userTagProductRelation.getPid();
-            productIdList.add(productId);
-        });
-*/
 
         return relationList;
     }
 
-/*    public List<UserTagProductRelation> findByTagId(String tagId) {
-        return relationRepository.findByTagId(tagId);
-    }*/
-
     public List<UserTagProductRelation> findByTagId(String tagId, BaseStatusEnum status) {
         return relationRepository.findByTagId(tagId, status);
     }
 
-    public List<UserTagProductRelation> findByPidsAndTagIds(List<String> pids, List<String> tagIds) {
-        List<UserTagProductRelation> userTagProductRelationList = relationRepository.findByPidsAndTagIds(pids, tagIds);
-        return userTagProductRelationList;
-    }
-
-    public List<UserTagProductRelation> findByPidAndTagId(String pid, String tagId) {
-        return relationRepository.findByPidAndTagId(pid, tagId, BaseStatusEnum.NORMAL);
-    }
-
-    @Transactional
-    public void updateByPid(String productId, String tagId, List<String> tagIdList) {
-        if (tagIdList == null) {
-            return;
-        }else if (tagIdList.size() == 0) {
-            relationRepository.deleteByPidAndTagId(productId, tagId);
-            return;
-        }
-
-        List<UserTagProductRelation> relationList = relationRepository.findByPidAndTagId(productId, tagId);
-
-        List<String> currentIdList = new ArrayList<>();
-        relationList.forEach( relation -> {
-            String tid = relation.getTagId();
-            if (!tagIdList.contains(tid)) {
-                relation.setStatus(BaseStatusEnum.DEL);
-            }else {
-                relation.setStatus(BaseStatusEnum.NORMAL);
-            }
-            currentIdList.add(tid);
-        });
-
-        List<String> notExistTagIdList = ListUtil.subtract(tagIdList, currentIdList);
-        if (notExistTagIdList != null && notExistTagIdList.size() > 0) {
-            notExistTagIdList.forEach( tid -> {
-                UserTagProductRelation relation = new UserTagProductRelation();
-                relation.setPid(productId);
-                relation.setTagId(tid);
-                relation.setSort(0);
-                relation.setStatus(BaseStatusEnum.NORMAL);
-                relationList.add(relation);
-            });
-        }
-
-        relationRepository.save(relationList);
-    }
-
     @Transactional
     public void updateByTagId(String tagId, List<String> productIdList) {
         if (productIdList == null) {