Jelajahi Sumber

optimize userTag copy

guozhaoshun 6 tahun lalu
induk
melakukan
49d03ed008

+ 19 - 3
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserTagController.java

@@ -137,11 +137,27 @@ public class UserTagController {
         dto.setProductList(productIdList);
 
         UserTag userTag = userTagService.update(dto);
-        if (userTag != null) {
+        if (userTag == null) {
             log.error("{copyTag}  update UserTag is error, id={}", dto.getId());
-            return APIResult.ok(userTag);
+            return APIResult.error(APICode.OPERATE_ERROR);
         }else{
-            return APIResult.error(APICode.NOT_EXISTS);
+            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);
         }
     }
 }