Parcourir la source

左侧分类顺序 未按照 [后台管理-基础资料-知识分类]中的排序号进行排序

danch il y a 3 mois
Parent
commit
0331328232

+ 1 - 0
jeecg-boot-base-core/src/main/java/org/jeecg/common/system/vo/SelectTreeModel.java

@@ -16,6 +16,7 @@ public class SelectTreeModel implements Serializable {
     private String key;
     private String title;
     private String value;
+    private Integer sort;
     /**
      * 父Id
      */

+ 9 - 6
jeecg-module-kms/src/main/java/org/jeecg/modules/kms/bas/controller/CategoryController.java

@@ -23,7 +23,9 @@ import org.springframework.web.servlet.ModelAndView;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 基础资料-知识-分类
@@ -58,12 +60,13 @@ public class CategoryController extends JeecgController<Category, ICategoryServi
                                                  HttpServletRequest req) {
         String hasQuery = req.getParameter("hasQuery");
 //        if (hasQuery != null && "true".equals(hasQuery)) {
-            QueryWrapper<Category> queryWrapper = QueryGenerator.initQueryWrapper(category, req.getParameterMap());
-            List<Category> list = categoryService.queryTreeListNoPage(queryWrapper);
-            IPage<Category> pageList = new Page<>(1, 10, list.size());
-            pageList.setRecords(list);
-            System.out.println("hasQuery:" + hasQuery);
-            return Result.OK(pageList);
+        QueryWrapper<Category> queryWrapper = QueryGenerator.initQueryWrapper(category, req.getParameterMap());
+        List<Category> list1 = categoryService.queryTreeListNoPage(queryWrapper);
+        IPage<Category> pageList = new Page<>(1, 10, list1.size());
+        List<Category> list = list1.stream().sorted(Comparator.comparingInt(p -> p.getSortNo())).collect(Collectors.toList());
+        pageList.setRecords(list);
+        System.out.println("hasQuery:" + hasQuery);
+        return Result.OK(pageList);
 //        } else {
 //            System.out.println("hasQuery:" + hasQuery);
 //            String parentId = category.getPid();

+ 2 - 0
jeecg-module-kms/src/main/java/org/jeecg/modules/kms/bas/mapper/xml/KmsCategoryMapper.xml

@@ -33,6 +33,7 @@
         id as "key",
         name as "title",
         id as "value",
+        sort_no as "sort",
         (case when has_child = '1' then 0 else 1 end) as isLeaf,
         pid as parentId
         from kms_bas_article_category
@@ -52,6 +53,7 @@
         id as "key",
         name as "title",
         id as "value",
+        sort_no as "sort",
         (case when has_child = '1' then 0 else 1 end) as isLeaf,
         pid as parentId
         from kms_bas_article_category

+ 6 - 2
jeecg-module-kms/src/main/java/org/jeecg/modules/kms/bas/service/impl/CategoryServiceImpl.java

@@ -16,7 +16,9 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 基础资料-知识-分类
@@ -104,7 +106,8 @@ public class CategoryServiceImpl extends ServiceImpl<KmsCategoryMapper, Category
 
     @Override
     public List<Category> queryTreeListNoPage(QueryWrapper<Category> queryWrapper) {
-        List<Category> dataList = baseMapper.selectList(queryWrapper);
+        List<Category> dataList1 = baseMapper.selectList(queryWrapper);
+        List<Category> dataList = dataList1.stream().sorted(Comparator.comparingInt(p -> p.getSortNo())).collect(Collectors.toList());
         List<Category> mapList = new ArrayList<>();
         for (Category data : dataList) {
             String pidVal = data.getPid();
@@ -145,7 +148,7 @@ public class CategoryServiceImpl extends ServiceImpl<KmsCategoryMapper, Category
         List<SelectTreeModel> selectTreeModels = baseMapper.queryListByPidPrivilege(pid, null, sql);
         //获取公共数据
         selectTreeModels.addAll(baseMapper.queryListByPidNoPrivilege(pid, null));
-
+        selectTreeModels.stream().sorted(Comparator.comparingInt(p -> p.getSort())).collect(Collectors.toList());
         return selectTreeModels;
     }
 
@@ -161,6 +164,7 @@ public class CategoryServiceImpl extends ServiceImpl<KmsCategoryMapper, Category
         List<SelectTreeModel> selectTreeModels = baseMapper.queryListByPidPrivilege(pid, null, sql);
         //获取公共数据
         selectTreeModels.addAll(baseMapper.queryListByPidNoPrivilege(pid, null));
+        selectTreeModels.stream().sorted(Comparator.comparingInt(p -> p.getSort())).collect(Collectors.toList());
         return selectTreeModels;
     }