huodongdong hace 7 años
padre
commit
ca84c38189

+ 1 - 1
rankin-data-api/src/main/java/cn/rankin/data/api/product/dto/GroupDTO.java

@@ -22,7 +22,7 @@ public class GroupDTO implements Serializable {
 
     private Integer sort;
 
-    private List<TagDTO> tagList;
+    private List<String> tagList;
 
     private BaseStatusEnum status;
 }

+ 8 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagGroupService.java

@@ -13,6 +13,7 @@ import cn.rankin.productservice.repository.TagGroupRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -61,8 +62,15 @@ public class TagGroupService {
 
     @Transactional
     public APIResult<TagGroup> update(GroupDTO groupDTO) {
+        String groupId = groupDTO.getId();
         TagGroup tagGroup = convert(groupDTO);
+        // 更新标签组
         TagGroup result = tagGroupRepository.update(tagGroup);
+        // 给组内的标签排序
+        List<String> tagIdList = groupDTO.getTagList();
+        if (!CollectionUtils.isEmpty(tagIdList)) {
+            tagService.sortTag(groupId, tagIdList);
+        }
         return APIResult.ok(result);
     }
 

+ 16 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagService.java

@@ -3,6 +3,7 @@ package cn.rankin.productservice.service;
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
+import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.util.JpaSortUtil;
 import cn.rankin.common.utils.util.ListUtil;
 import cn.rankin.data.api.product.dto.TagDTO;
@@ -155,4 +156,19 @@ public class TagService {
         }
         return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
     }
+
+    @Transactional
+    public void sortTag(String groupId, List<String> tagIdList) {
+        List<Tag> tagList = tagRepository.findByGroupId(groupId);
+        for (Tag tag : tagList) {
+            String tagId = tag.getId();
+            if (!tagIdList.contains(tagId)) {
+                tag.setStatus(BaseStatusEnum.DEL);
+                continue;
+            }
+            Integer index = tagIdList.indexOf(tagId);
+            tag.setSort(index);
+        }
+        tagRepository.update(tagList);
+    }
 }

+ 6 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/utils/DTOConverter.java

@@ -74,7 +74,12 @@ public class DTOConverter {
 
     public static TagGroup convert(GroupDTO groupDTO) {
         TagGroup tagGroup = new TagGroup();
-        BeanUtils.copyProperties(groupDTO, tagGroup);
+        tagGroup.setId(groupDTO.getId());
+        tagGroup.setCode(groupDTO.getCode());
+        tagGroup.setName(groupDTO.getName());
+        tagGroup.setMerchantId(groupDTO.getMerchantId());
+        tagGroup.setSort(groupDTO.getSort());
+        tagGroup.setStatus(groupDTO.getStatus());
         return tagGroup;
     }