Procházet zdrojové kódy

API优化 标签逻辑

guozhaoshun před 6 roky
rodič
revize
0c9f0f3d6d

+ 34 - 4
rankin-api-web/src/main/java/cn/rankin/apiweb/controller/TagController.java

@@ -15,7 +15,6 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 @Slf4j
 @RestController
@@ -43,8 +42,8 @@ public class TagController {
         return tagService.findPageByTagId(tagId, merchantId, pageNo, pageSize);
     }
 
-    @RequestMapping(value = "/tagType/{code}", method = RequestMethod.GET)
-    public APIResult<List<TagVo>> getTagType(@NeedUser DeviceUserVo user,@PathVariable("code") String code) {
+    @RequestMapping(value = "/tagType/v1/{code}", method = RequestMethod.GET)
+    public APIResult<List<TagVo>> getTags(@NeedUser DeviceUserVo user,@PathVariable("code") String code) {
         List<TagVo> result = new ArrayList<>();
 
         //先去取用户标签,没有用户标签再使用渠道标签
@@ -75,7 +74,38 @@ public class TagController {
         }
 
         //没有用户标签数据,使用渠道标签数据
-        return tagService.findTagTypeByCode(code, merchantId);
+        return tagService.findTagByTypeCode(code, merchantId);
+    }
+
+    @RequestMapping(value = "/tagType/{code}", method = RequestMethod.GET)
+    public APIResult<TagTypeVo> getTagTypeByCode(@NeedUser DeviceUserVo user,@PathVariable("code") String code) {
+        TagTypeVo tagTypeVo = tagService.findTagTypeByCode(code);
+
+        //先去取用户标签,没有用户标签再使用渠道标签
+        String uid = user.getUid();
+        String merchantId = user.getMerchantId();
+
+        //用户标签列表
+        List<UserTag> userTagList = userService.findUserTagByCodeUid(code,uid);
+        if(null != userTagList && userTagList.size() > 0){
+            List<TagVo> tagVos = new ArrayList<>();
+            log.info("get userTag By code and uid, size={}", userTagList.size());
+            //组装数据   用户标签
+            userTagList.forEach(userTag -> {
+                TagVo vo = new TagVo();
+                vo.setId(userTag.getId());
+                vo.setName(userTag.getName());
+                tagVos.add(vo);
+            });
+            tagTypeVo.setList(tagVos);
+        }else{
+            //没有用户标签数据,使用渠道标签数据
+            List<TagVo> tagVos = tagService.findTagByTypeCodeMerchant(code, merchantId);
+            tagTypeVo.setList(tagVos);
+        }
+
+        return APIResult.ok(tagTypeVo);
+
     }
 
 }

+ 9 - 2
rankin-api-web/src/main/java/cn/rankin/apiweb/service/tag/TagClient.java

@@ -3,6 +3,7 @@ package cn.rankin.apiweb.service.tag;
 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.app.vo.TagTypeVo;
 import cn.rankin.data.api.app.vo.TagVo;
 import cn.rankin.data.api.product.entity.TagGroup;
 import cn.rankin.data.api.product.entity.TagType;
@@ -20,10 +21,16 @@ public interface TagClient {
     @RequestMapping(value = "/app/tagGroup/code/{code}", method = RequestMethod.GET)
     APIResult<TagGroup> findTagGroupByCode(@PathVariable("code") String code, @RequestParam("merchantId") String merchantId);
 
-    @RequestMapping(value = "/tagType/code/{code}", method = RequestMethod.GET)
-    APIResult<List<TagVo>> findTagTypeByCode(@PathVariable("code") String code, @RequestParam("merchantId") String merchantId);
+    @RequestMapping(value = "/app/tagType/code/{code}", method = RequestMethod.GET)
+    APIResult<List<TagVo>> findTagByTypeCode(@PathVariable("code") String code, @RequestParam("merchantId") String merchantId);
 
     @RequestMapping(value = "/app/tag/item/{tagId}", method = RequestMethod.GET)
     APIResult<Page<ItemVo>> findPageByTagId(@PathVariable("tagId") String tagId, @RequestParam("merchantId") String merchantId,
                                             @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize);
+
+    @RequestMapping(value = "/tagType/app/code/{code}", method = RequestMethod.GET)
+    TagTypeVo findTagTypeByCode(@PathVariable("code") String code);
+
+    @RequestMapping(value = "/tagType/app/tag/code/{code}", method = RequestMethod.GET)
+    List<TagVo> findTagByTypeCodeMerchant(@PathVariable("code") String code, @RequestParam("merchantId") String merchantId);
 }

+ 9 - 3
rankin-api-web/src/main/java/cn/rankin/apiweb/service/tag/TagService.java

@@ -8,7 +8,6 @@ import cn.rankin.data.api.app.vo.TagGroupVo;
 import cn.rankin.data.api.app.vo.TagTypeVo;
 import cn.rankin.data.api.app.vo.TagVo;
 import cn.rankin.data.api.product.entity.TagGroup;
-import cn.rankin.data.api.product.entity.TagType;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -32,8 +31,8 @@ public class TagService {
         return APIResult.ok(tagGroupVo);
     }
 
-    public APIResult<List<TagVo>> findTagTypeByCode(String code, String merchantId) {
-        APIResult<List<TagVo>> apiResult = tagClient.findTagTypeByCode(code,merchantId);
+    public APIResult<List<TagVo>> findTagByTypeCode(String code, String merchantId) {
+        APIResult<List<TagVo>> apiResult = tagClient.findTagByTypeCode(code,merchantId);
         if (!apiResult.getSuccess()) {
             return APIResult.error(new BaseCode(apiResult.getCode(), apiResult.getMessage()));
         }
@@ -45,5 +44,12 @@ public class TagService {
     }
 
 
+    public TagTypeVo findTagTypeByCode(String code) {
+        TagTypeVo tagTypeVo = tagClient.findTagTypeByCode(code);
+        return tagTypeVo;
+    }
 
+    public List<TagVo> findTagByTypeCodeMerchant(String code, String merchantId) {
+        return tagClient.findTagByTypeCodeMerchant(code,merchantId);
+    }
 }

+ 18 - 20
rankin-product-service/src/main/java/cn/rankin/productservice/controller/TagTypeController.java

@@ -5,7 +5,6 @@ import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.dto.search.TagTypeSearchDTO;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
-import cn.rankin.data.api.app.vo.ItemVo;
 import cn.rankin.data.api.product.dto.TagTypeDTO;
 import cn.rankin.data.api.product.entity.Tag;
 import cn.rankin.data.api.product.entity.TagType;
@@ -32,9 +31,6 @@ public class TagTypeController {
     @Autowired
     private TagService tagService;
 
-    @Autowired
-    private ItemService itemService;
-
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     public APIResult<Page<TagType>> search(TagTypeSearchDTO searchDTO) {
         TagType tagType = new TagType();
@@ -106,25 +102,27 @@ public class TagTypeController {
 
     }
 
-    @RequestMapping(value = "/code/{typeCode}", method = RequestMethod.GET)
-    public APIResult<List<Tag>> getTagTypeByCode(@PathVariable("typeCode") String typeCode, @RequestParam("merchantId") String merchantId) {
-
-        //开始组装数据
+    /**
+     * 根据typeCode  查询tagType
+     * @param typeCode
+     * @return
+     */
+    @RequestMapping(value = "/app/code/{typeCode}", method = RequestMethod.GET)
+    public TagType getTagTypeByCode(@PathVariable("typeCode") String typeCode) {
+        return tagTypeService.findTagTypeByCode(typeCode);
+    }
 
+    /**
+     * 根据typeCode  查询tag集合
+     * @param typeCode
+     * @param merchantId
+     * @return
+     */
+    @RequestMapping(value = "/app/tag/code/{typeCode}", method = RequestMethod.GET)
+    public List<Tag> getTagByTypeCode(@PathVariable("typeCode") String typeCode, @RequestParam("merchantId") String merchantId) {
         //标签列表数据
         List<Tag> tagList = tagService.findByTypeCode(typeCode,merchantId);
-
-        //标签下   课程数据
-        tagList.forEach(tag -> {
-            String tagId = tag.getId();
-            List<ItemVo> itemVoList = itemService.findPageByTagId(tagId, merchantId);
-            tag.setRecs(itemVoList);
-        });
-
-        return APIResult.ok(tagList);
-
+        return tagList;
     }
 
-
-
 }

+ 21 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/controller/app/AppTagController.java

@@ -3,12 +3,16 @@ package cn.rankin.productservice.controller.app;
 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.entity.Tag;
 import cn.rankin.data.api.product.entity.TagGroup;
+import cn.rankin.productservice.service.TagService;
 import cn.rankin.productservice.service.app.ItemService;
 import cn.rankin.productservice.service.TagGroupService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 @RestController
 @RequestMapping(value = "/app")
 public class AppTagController {
@@ -19,6 +23,9 @@ public class AppTagController {
     @Autowired
     private ItemService itemService;
 
+    @Autowired
+    private TagService tagService;
+
     @RequestMapping(value = "/tagGroup/code/{code}", method = RequestMethod.GET)
     public APIResult<TagGroup> findTagGroupByCode(@PathVariable("code") String code, @RequestParam("merchantId") String merchantId) {
         return tagGroupService.findTagGroupByCode(code, merchantId);
@@ -30,4 +37,18 @@ public class AppTagController {
         return itemService.findPageByTagId(tagId, merchantId, pageNo, pageSize);
     }
 
+    @RequestMapping(value = "/tagType/code/{typeCode}", method = RequestMethod.GET)
+    public APIResult<List<Tag>> getTagsByTypeCode(@PathVariable("typeCode") String typeCode, @RequestParam("merchantId") String merchantId) {
+        //开始组装数据
+        //标签列表数据
+        List<Tag> tagList = tagService.findByTypeCode(typeCode,merchantId);
+
+        //标签下   课程数据
+        tagList.forEach(tag -> {
+            String tagId = tag.getId();
+            List<ItemVo> itemVoList = itemService.findPageByTagId(tagId, merchantId);
+            tag.setRecs(itemVoList);
+        });
+        return APIResult.ok(tagList);
+    }
 }

+ 1 - 15
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagTypeService.java

@@ -3,13 +3,9 @@ package cn.rankin.productservice.service;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.util.JpaSortUtil;
-import cn.rankin.data.api.app.vo.ItemVo;
 import cn.rankin.data.api.product.dto.TagTypeDTO;
-import cn.rankin.data.api.product.entity.MerchantProduct;
-import cn.rankin.data.api.product.entity.Tag;
 import cn.rankin.data.api.product.entity.TagType;
 import cn.rankin.productservice.repository.TagTypeRepository;
-import cn.rankin.productservice.service.app.ItemService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -90,17 +86,7 @@ public class TagTypeService {
         return tagType;
     }
 
-    public TagType getTagTypeByCode(String typeCode) {
-        TagType tagType = tagTypeRepository.findFirstByCode(typeCode);
-        return tagType;
-    }
-
     public TagType findTagTypeByCode(String code) {
-        TagType tagType = tagTypeRepository.findFirstByCode(code);
-        if (tagType == null) {
-            return null;
-        }
-        String tagTypeId = tagType.getId();
-        return this.getTagType(tagTypeId);
+        return tagTypeRepository.findFirstByCode(code);
     }
 }