|
@@ -1,7 +1,9 @@
|
|
|
package cn.rankin.apiweb.service.collection;
|
|
|
|
|
|
import cn.rankin.apiweb.code.ApiWebCode;
|
|
|
+import cn.rankin.apiweb.service.product.ProductClient;
|
|
|
import cn.rankin.apiweb.service.product.ProductService;
|
|
|
+import cn.rankin.apiweb.service.user.UserService;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
import cn.rankin.common.utils.api.model.BaseCode;
|
|
|
import cn.rankin.common.utils.api.page.Page;
|
|
@@ -11,6 +13,7 @@ import cn.rankin.data.api.app.vo.ItemVo;
|
|
|
import cn.rankin.data.api.product.entity.MerchantProduct;
|
|
|
import cn.rankin.data.api.user.dto.CollectionDTO;
|
|
|
import cn.rankin.data.api.user.entity.Collection;
|
|
|
+import cn.rankin.data.api.user.entity.UserTagProductRelation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,8 +33,14 @@ public class CollectionService {
|
|
|
private CollectionClient collectionClient;
|
|
|
|
|
|
@Autowired
|
|
|
+ private ProductClient productClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private ProductService productService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
public Boolean isCollected(String userId, String productId) {
|
|
|
APIResult<Collection> apiResult = collectionClient.getCollection(userId, productId);
|
|
|
if (apiResult.getSuccess() && apiResult.getData() != null) {
|
|
@@ -115,4 +124,46 @@ public class CollectionService {
|
|
|
return productService.findItemPageByIds(itemSearchDTO);
|
|
|
}
|
|
|
|
|
|
+ public APIResult<Page<ItemVo>> getUserConllectionByUserTag(String userId, String merchantId, String userTagId,
|
|
|
+ Integer pageNo, Integer pageSize) {
|
|
|
+ APIResult<List<Collection>> collectionApiResult = collectionClient.getUserCollections(userId, MAX_SIZE);
|
|
|
+ if (!collectionApiResult.getSuccess()) {
|
|
|
+ return APIResult.error(new BaseCode(collectionApiResult.getCode(), collectionApiResult.getMessage()));
|
|
|
+ }
|
|
|
+ List<Collection> collectionList = collectionApiResult.getData();
|
|
|
+ if (CollectionUtils.isEmpty(collectionList)) {
|
|
|
+ return APIResult.ok(new ArrayList<>());
|
|
|
+ }
|
|
|
+ List<String> productIdList = new ArrayList<>();
|
|
|
+ for (Collection collection : collectionList) {
|
|
|
+ String productId = collection.getPid();
|
|
|
+ productIdList.add(productId);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<UserTagProductRelation> resultPage = userService.findRelations(userTagId, productIdList, pageNo, pageSize);
|
|
|
+
|
|
|
+ if(resultPage == null){
|
|
|
+ return APIResult.ok(new ArrayList());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ItemVo> itemVos = new ArrayList<>();
|
|
|
+ List<UserTagProductRelation> userTagProductRelations = resultPage.getList();
|
|
|
+ userTagProductRelations.forEach(userTagProductRelation -> {
|
|
|
+ String pid = userTagProductRelation.getPid();
|
|
|
+ ItemVo itemVo = productClient.findItemByPid(merchantId, pid);
|
|
|
+ if(itemVo == null){
|
|
|
+ log.info("not found item by pid , pid={}",pid);
|
|
|
+ }else{
|
|
|
+ itemVos.add(itemVo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Page<ItemVo> page = new Page<>();
|
|
|
+ page.setPageSize(pageSize);
|
|
|
+ page.setPageNo(pageNo);
|
|
|
+ page.setTotalSize((int)resultPage.getTotalSize());
|
|
|
+ page.setList(itemVos);
|
|
|
+
|
|
|
+ return APIResult.ok(page);
|
|
|
+ }
|
|
|
}
|