Browse Source

add
/tagType/{code}

guozhaoshun 6 years ago
parent
commit
150ce1a65d

+ 2 - 2
rankin-api-web/src/main/resources/bootstrap.yml

@@ -3,9 +3,9 @@ spring:
     name: api-web
   cloud:
     config:
-      uri: http://config.rankin.com:8921
+      uri: http://127.0.0.1:8921
       label: master
-      profile: ${profile:dev}
+      profile: ${profile:local}
 
 server:
   port: 8600

+ 4 - 3
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/product/TagTypeController.java

@@ -48,15 +48,16 @@ public class TagTypeController {
         return tagTypeServiceInterface.delete(id);
     }
 
+/*
     @RequestMapping(value = "/{id}", method = RequestMethod.GET)
     public APIResult<TagTypeVo> getTagType(@PathVariable("id") String id) {
         return tagTypeServiceInterface.getTagType(id);
-    }
+    }*/
 
-    @RequestMapping(value = "/code/{typeCode}", method = RequestMethod.GET)
+/*    @RequestMapping(value = "/code/{typeCode}", method = RequestMethod.GET)
     public APIResult<TagTypeVo> getTagTypeByCode(@PathVariable("typeCode") String typeCode) {
         return tagTypeServiceInterface.getTagTypeByCode(typeCode);
-    }
+    }*/
 
 
 }

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

@@ -3,12 +3,19 @@ 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.data.api.product.entity.TagType;
+import cn.rankin.productservice.code.ProductServiceAPICode;
+import cn.rankin.productservice.service.TagService;
+import cn.rankin.productservice.service.TagTypeService;
 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 {
@@ -17,6 +24,12 @@ public class AppTagController {
     private TagGroupService tagGroupService;
 
     @Autowired
+    private TagTypeService tagTypeService;
+
+    @Autowired
+    private TagService tagService;
+
+    @Autowired
     private ItemService itemService;
 
     @RequestMapping(value = "/tagGroup/code/{code}", method = RequestMethod.GET)
@@ -29,4 +42,31 @@ public class AppTagController {
                                                    @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
         return itemService.findPageByTagId(tagId, merchantId, pageNo, pageSize);
     }
+
+
+    @RequestMapping(value = "/tagType/code/{typeCode}", method = RequestMethod.GET)
+    public APIResult<TagType> getTagTypeByCode(@PathVariable("typeCode") String typeCode, @RequestParam("merchantId") String merchantId) {
+        TagType tagType = tagTypeService.getTagTypeByCode(typeCode);
+
+        if (tagType == null) {
+            return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
+        }else{
+            //开始组装数据
+
+            //标签列表数据
+            List<Tag> tagList = tagService.findByTypeCode(typeCode,merchantId);
+
+            //标签下   课程数据
+            tagList.forEach(tag -> {
+                String tagId = tag.getId();
+                List<ItemVo> itemVoList = itemService.findPageByTagId(tagId, merchantId);
+                tag.setRecs(itemVoList);
+
+            });
+            tagType.setTagList(tagList);
+
+            return APIResult.ok(tagType);
+        }
+
+    }
 }

+ 33 - 4
rankin-product-service/src/main/java/cn/rankin/productservice/controller/cms/TagTypeController.java

@@ -5,10 +5,14 @@ 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;
 import cn.rankin.productservice.code.ProductServiceAPICode;
+import cn.rankin.productservice.service.TagService;
 import cn.rankin.productservice.service.TagTypeService;
+import cn.rankin.productservice.service.app.ItemService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -16,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.util.LinkedHashMap;
+import java.util.List;
 
 @RestController
 @RequestMapping(value = "tagType")
@@ -24,6 +29,9 @@ public class TagTypeController {
     @Autowired
     private TagTypeService tagTypeService;
 
+    @Autowired
+    private TagService tagService;
+
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     public APIResult<Page<TagType>> search(TagTypeSearchDTO searchDTO) {
         TagType tagType = new TagType();
@@ -84,26 +92,47 @@ public class TagTypeController {
     }
 
     @RequestMapping(value = "/{tagTypeId}", method = RequestMethod.GET)
-    public APIResult<TagType> getTagType(@PathVariable("tagTypeId") String tagTypeId) {
+    public APIResult<TagType> getTagType(@PathVariable("tagTypeId") String tagTypeId, @RequestParam("merchantId") String merchantId) {
         TagType tagType = tagTypeService.getTagType(tagTypeId);
 
         if (tagType == null) {
             return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
         }else{
+
+            //开始组装数据
+            List<Tag> tagList = tagService.findByTypeCode(tagType.getCode(),merchantId);
+            tagType.setTagList(tagList);
+
+
             return APIResult.ok(tagType);
         }
 
     }
 
-    @RequestMapping(value = "/code/{typeCode}", method = RequestMethod.GET)
-    public APIResult<TagType> getTagTypeByCode(@PathVariable("typeCode") String typeCode) {
+/*    @RequestMapping(value = "/code/{typeCode}", method = RequestMethod.GET)
+    public APIResult<TagType> getTagTypeByCode(@PathVariable("typeCode") String typeCode, @RequestParam("merchantId") String merchantId) {
         TagType tagType = tagTypeService.getTagTypeByCode(typeCode);
 
         if (tagType == null) {
             return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
         }else{
+
+            //开始组装数据
+
+            //标签列表数据
+            List<Tag> tagList = tagService.findByTypeCode(typeCode,merchantId);
+
+            //标签下   课程数据
+            tagList.forEach(tag -> {
+                String tagId = tag.getId();
+                List<ItemVo> itemVoList = itemService.findPageByTagId(tagId, merchantId);
+                tag.setRecs(itemVoList);
+
+            });
+            tagType.setTagList(tagList);
+
             return APIResult.ok(tagType);
         }
 
-    }
+    }*/
 }

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

@@ -18,8 +18,8 @@ public interface TagRepository extends BasicJpaRepository<Tag, String> {
     List<Tag> findByTagTypeId(String tagTypeId);
 
 
-    @Query(value = "select t from Tag t where t.typeCode = ?1 order by t.sort")
-    List<Tag> findByTypeCode(String typeCode);
+    @Query(value = "select t from Tag t where t.typeCode = ?1 and t.merchantId = ?2 order by t.sort")
+    List<Tag> findByTypeCode(String typeCode,String merchantId);
 
     @Query(value = "select t from Tag t where t.id in (?1) and t.status = ?2")
     List<Tag> findByIds(List<String> tagIdList, BaseStatusEnum status);

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

@@ -11,7 +11,7 @@ public interface TagTypeRepository extends BasicJpaRepository<TagType, String> {
 
     Long countByCode(String code);
 
-    @Query(value = "select t from TagType t where t.code = ?1 ")
+    @Query(value = "select t from TagType t where t.code = ?1  order by t.sort ")
     TagType findFirstByCode(String code);
 
     @Modifying

+ 2 - 27
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagService.java

@@ -51,9 +51,8 @@ public class TagService {
     }
 
     /*add    2018-05-17 */
-    public List<Tag> findByTypeCode(String typeCode) {
-        List<Tag> tagList = tagRepository.findByTypeCode(typeCode);
-        setGroupInfo(tagList);
+    public List<Tag> findByTypeCode(String typeCode,String merchantId) {
+        List<Tag> tagList = tagRepository.findByTypeCode(typeCode,merchantId);
         return tagList;
     }
 
@@ -101,30 +100,6 @@ public class TagService {
         return sortMerchantProductList;
     }
 
-    public List<MerchantProduct> getMerchantProductList2(String tagId, String merchantId) {
-        List<MerchantProductTagRelation> relationList = merchantProductTagRelationService.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.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) {
-                List<Goods> goodsList = goodsService.findByPidAndMerchantId(merchantProduct.getPid(), merchantProduct.getMerchantId());
-                merchantProduct.setGoods(goodsList);
-                sortMerchantProductList.add(merchantProduct);
-            }
-        }
-        return sortMerchantProductList;
-    }
-
     // 搜索标签
     public APIResult<Page<Tag>> search(Tag tag, Integer pageNo, Integer pageSize, LinkedHashMap<String, BaseOrderEnum> sort) {
         Long count = tagRepository.count(tag);

+ 0 - 26
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagTypeService.java

@@ -29,8 +29,6 @@ public class TagTypeService {
     @Autowired
     private TagService tagService;
 
-    @Autowired
-    private ItemService itemService;
 
     public boolean exists(String code) {
         Long count = tagTypeRepository.countByCode(code);
@@ -89,35 +87,11 @@ public class TagTypeService {
 
     public TagType getTagType(String tagTypeId) {
         TagType tagType = tagTypeRepository.find(tagTypeId);
-        if (tagType == null) {
-            return null;
-        }
-
-        List<Tag> tagList = tagService.findByTypeCode(tagType.getCode());
-        tagType.setTagList(tagList);
         return tagType;
     }
 
     public TagType getTagTypeByCode(String typeCode) {
         TagType tagType = tagTypeRepository.findFirstByCode(typeCode);
-        if (tagType == null) {
-            return null;
-        }
-
-        List<Tag> tagList = tagService.findByTypeCode(typeCode);
-
-        tagList.forEach(tag -> {
-            String tagId = tag.getId();
-            String merchantId = tag.getMerchantId();
-            List<ItemVo> itemVoList = itemService.findPageByTagId(tagId, merchantId);
-//            List<MerchantProduct> merchantProductList = tagService.getMerchantProductList2(tagId, merchantId);
-//            tag.setProductList(merchantProductList);
-            tag.setRecs(itemVoList);
-            
-        });
-        
-        
-        tagType.setTagList(tagList);
         return tagType;
     }