lyhzzz 1 week ago
parent
commit
552958e873

+ 18 - 1
src/main/java/com/fdkankan/fusion/controller/HotIconController.java

@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -48,11 +49,26 @@ public class HotIconController extends BaseController{
         return ResultData.ok(hotIconService.getListByUserName(getUserName()));
     }
 
+    @GetMapping("/treeList")
+    public ResultData listTree(@RequestParam(required = false) Integer fusionId){
+        List<HotIcon> iconList ;
+        if(fusionId!=null){
+            iconList = hotIconService.getListByFusionId(fusionId);
+        }else {
+            iconList = hotIconService.getListByUserName(getUserName());
+        }
+        List<HotIcon> treeList = hotIconService.treeList(iconList);
+
+        return ResultData.ok(treeList);
+    }
+
     @PostMapping("/add")
     @PushJm(event_content = "添加标注图片")
     public ResultData add(@RequestParam(required = false) MultipartFile file,
                           @RequestParam(required = false) String iconTitle,
-                          @RequestParam(required = false) Integer fusionId) throws IOException {
+                          @RequestParam(required = false) Integer fusionId,
+                          @RequestParam(required = false,defaultValue = "279") Integer parentId) throws IOException {
+
         if(file==null || StringUtils.isEmpty(iconTitle) || fusionId == null){
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }
@@ -63,6 +79,7 @@ public class HotIconController extends BaseController{
         hotIcon.setIconTitle(iconTitle);
         hotIcon.setIconUrl(iconUrl);
         hotIcon.setFusionId(fusionId);
+        hotIcon.setParentId(parentId);
         if(StringUtils.isEmpty(hotIcon.getIconUrl())){
             throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
         }

+ 7 - 0
src/main/java/com/fdkankan/fusion/entity/HotIcon.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.*;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
+
 import lombok.Getter;
 import lombok.Setter;
 
@@ -65,6 +67,9 @@ public class HotIcon implements Serializable {
     @TableField("sort")
     private Integer sort;
 
+    @TableField("parent_id")
+    private Integer parentId;
+
     @TableField("tb_status")
     @TableLogic
     private Integer tbStatus;
@@ -75,5 +80,7 @@ public class HotIcon implements Serializable {
     @TableField("update_time")
     private String updateTime;
 
+    @TableField(exist = false)
+    private List<HotIcon> childrenList;
 
 }

+ 3 - 1
src/main/java/com/fdkankan/fusion/service/IHotIconService.java

@@ -28,5 +28,7 @@ public interface IHotIconService extends IService<HotIcon> {
 
     List<HotIcon> getByIds( HashSet<Integer> hotIconId);
 
-    Object getListByFusionId(Integer fusionId);
+    List<HotIcon> getListByFusionId(Integer fusionId);
+
+    List<HotIcon> treeList(List<HotIcon> iconList);
 }

+ 33 - 3
src/main/java/com/fdkankan/fusion/service/impl/HotIconServiceImpl.java

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -43,7 +44,7 @@ public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> imp
                 .orderByDesc(HotIcon::getIsNew)           // 新增
                 .orderByDesc(HotIcon::getLastUse)         // 上次使用
                 .orderByDesc(HotIcon::getUseNum)          // 使用次数
-                .orderByDesc(HotIcon::getSort)
+                .orderByAsc(HotIcon::getSort)
                 .orderByDesc(HotIcon::getCreateTime);
         return this.list(wrapper);
     }
@@ -109,7 +110,7 @@ public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> imp
     }
 
     @Override
-    public Object getListByFusionId(Integer fusionId) {
+    public List<HotIcon> getListByFusionId(Integer fusionId) {
         HashSet<Integer> hotIconIds = new HashSet<>();
         List<CaseTag> list = caseTagService.getListByFusionId(fusionId);
         if(list.size() >0){
@@ -137,8 +138,37 @@ public class HotIconServiceImpl extends ServiceImpl<IHotIconMapper, HotIcon> imp
         LambdaQueryWrapper<HotIcon> wrapper = new LambdaQueryWrapper<>();
         wrapper.in(HotIcon::getIconId,hotIconIds);
         wrapper.orderByDesc(HotIcon::getIsSystem)           // 官方默认
-                .orderByAsc(HotIcon::getIconTitle)
                 .orderByAsc(HotIcon::getSort);
         return this.list(wrapper);
     }
+
+    @Override
+    public List<HotIcon> treeList(List<HotIcon> iconList) {
+        HashMap<Integer,HotIcon> map = new HashMap<>();
+
+        List<HotIcon> list = new ArrayList<>();
+        List<HotIcon> result = new ArrayList<>();
+
+        for (HotIcon hotIcon : iconList) {
+            if(hotIcon.getParentId() == null){
+                list.add(hotIcon);
+            }
+            map.put(hotIcon.getIconId(),hotIcon);
+        }
+        for (HotIcon hotIcon : iconList) {
+            if(hotIcon.getParentId() == null){
+                continue;
+            }
+            HotIcon parent = map.get(hotIcon.getParentId());
+            if(parent.getChildrenList() == null){
+                parent.setChildrenList(new ArrayList<>());
+            }
+            parent.getChildrenList().add(hotIcon);
+        }
+        for (HotIcon hotIcon : list) {
+            result.add( map.get(hotIcon.getIconId()));
+        }
+
+        return result;
+    }
 }