Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多个column排序不同顺序的补充修改 #5715

Closed
157677678 opened this issue Dec 26, 2023 · 1 comment
Closed

多个column排序不同顺序的补充修改 #5715

157677678 opened this issue Dec 26, 2023 · 1 comment

Comments

@157677678
Copy link

版本号:

当前最新版(3.6.1)

问题描述:

前端传过来的column 如果是有多个 比如“id,createTime” 只能有一个顺序 多个顺序不支持

截图&代码:

https://github.com/jeecgboot/jeecg-boot/blob/master/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/query/QueryGenerator.java里 283行
image

修改代码为:
           //有多个order且有多个顺序
           if (column.contains(",") && order.contains(",")) {
               String[] columnArray = column.split(",");

               String[] orderArray = order.split(",");
               for (int i = 0; i < columnArray.length; i++) {
                   String columnStr = oConvertUtils.camelToUnderline(columnArray[i]);
                   if (i<orderArray.length){
                       //有一一对应的升序或降序
                       if (orderArray[i].toUpperCase().indexOf(ORDER_TYPE_ASC) >= 0) {
                           queryWrapper.orderByAsc(columnStr);
                       }else {
                           queryWrapper.orderByDesc(columnStr);
                       }
                   }else{
                       //没有设定,默认为降序
                       queryWrapper.orderByDesc(columnStr);
                   }

               }
           } else {
               //update-begin--Author:scott  Date:20210531 for:36 多条件排序无效问题修正-------
               // 排序规则修改
               // 将现有排序 _ 前端传递排序条件{....,column: 'column1,column2',order: 'desc'} 翻译成sql "column1,column2 desc"
               // 修改为 _ 前端传递排序条件{....,column: 'column1,column2',order: 'desc'} 翻译成sql "column1 desc,column2 desc"

               if (order.toUpperCase().indexOf(ORDER_TYPE_ASC) >= 0) {
                   //queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
                   String columnStr = oConvertUtils.camelToUnderline(column);
                   String[] columnArray = columnStr.split(",");
                   queryWrapper.orderByAsc(Arrays.asList(columnArray));
               } else {
                   //queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
                   String columnStr = oConvertUtils.camelToUnderline(column);
                   String[] columnArray = columnStr.split(",");
                   queryWrapper.orderByDesc(Arrays.asList(columnArray));
               }
               //update-end--Author:scott  Date:20210531 for:36 多条件排序无效问题修正-------
           }
@zhangdaiscott
Copy link
Member

暂时收录到 “新需求汇总”
#1312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants