Browse Source

tag support sort by tagTypeCode

guozhaoshun 6 years ago
parent
commit
07c6a22cd3

+ 14 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagService.java

@@ -193,6 +193,20 @@ public class TagService {
     @Transactional
     public void sortTag(String groupId, List<String> tagIdList) {
         List<Tag> tagList = tagRepository.findByGroupId(groupId);
+        sortTag(tagIdList, tagList);
+        tagRepository.update(tagList);
+    }
+
+
+
+    @Transactional
+    public void sortTagByTypeCode(String typeCode, List<String> tagIdList) {
+        List<Tag> tagList = tagRepository.findByTypeCode(typeCode);
+        sortTag(tagIdList, tagList);
+        tagRepository.update(tagList);
+    }
+
+    private void sortTag(List<String> tagIdList, List<Tag> tagList) {
         for (Tag tag : tagList) {
             String tagId = tag.getId();
             if (!tagIdList.contains(tagId)) {
@@ -202,6 +216,5 @@ public class TagService {
             Integer index = tagIdList.indexOf(tagId);
             tag.setSort(index);
         }
-        tagRepository.update(tagList);
     }
 }

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

@@ -64,14 +64,14 @@ public class TagTypeService {
 
     @Transactional
     public TagType update(TagTypeDTO tagTypeDTO) {
-        String groupId = tagTypeDTO.getId();
+        String typeCode = tagTypeDTO.getCode();
         TagType tagType = convert(tagTypeDTO);
         // 更新标签组
         TagType result = tagTypeRepository.update(tagType);
         // 给组内的标签排序
         List<String> tagIdList = tagTypeDTO.getTagList();
         if (!CollectionUtils.isEmpty(tagIdList)) {
-            tagService.sortTag(groupId, tagIdList);
+            tagService.sortTagByTypeCode(typeCode, tagIdList);
         }
         return result;
     }