增加:综合浏览资源查询首页增自定义排序功能

master
Guo XIn 1 year ago
parent 63ef1c294e
commit 8f3e158c11
  1. 8
      shandan-browser/src/main/java/com/keyware/shandan/browser/entity/SearchConditionVo.java
  2. 16
      shandan-browser/src/main/java/com/keyware/shandan/browser/service/MetadataSearchService.java
  3. 23
      shandan-browser/src/main/resources/static/js/browser.js

@ -125,14 +125,6 @@ public class SearchConditionVo extends PageVo implements Serializable {
//排序方式 //排序方式
private String sort; private String sort;
public String getField() {
return " " + field;
}
public String getSort() {
return " " + sort;
}
/** /**
* @return order by sql语句 * @return order by sql语句
*/ */

@ -1,5 +1,7 @@
package com.keyware.shandan.browser.service; package com.keyware.shandan.browser.service;
import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keyware.shandan.bianmu.entity.DirectoryResource; import com.keyware.shandan.bianmu.entity.DirectoryResource;
@ -16,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.lang.reflect.Field;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -96,6 +99,19 @@ public class MetadataSearchService {
} }
}); });
}); });
// 排序设置
SearchConditionVo.Sort sort = condition.getSort();
if(sort != null && sort.getSort() != null ){
// 通过反射获取资源类字段注解中的数据库表相关的列名
Field field = ReflectUtil.getField(DirectoryResource.class, sort.getField().trim());
if(field != null){
TableField tableField = field.getAnnotation(TableField.class);
if(tableField != null && StringUtils.hasText(tableField.value())){
queryWrapper.orderBy(true, sort.getSort().equalsIgnoreCase("asc"), tableField.value());
}
}
}
return queryWrapper; return queryWrapper;
} }

@ -134,6 +134,7 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
url: `${ctx}/search/metadata/all/page/${id}`, url: `${ctx}/search/metadata/all/page/${id}`,
height: 'full-110', height: 'full-110',
method: 'post', method: 'post',
autoSort: false,
defaultToolbar: [{ defaultToolbar: [{
title: '导出' //标题 title: '导出' //标题
, layEvent: 'export' //事件名,用于 toolbar 事件中使用 , layEvent: 'export' //事件名,用于 toolbar 事件中使用
@ -143,17 +144,17 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
limit: 30, limit: 30,
cols: [[ cols: [[
{field: 'id', title: 'ID', hide: true}, {field: 'id', title: 'ID', hide: true},
{field: 'resourceName', title: '数据名称', width: 300}, {field: 'resourceName', title: '数据名称', width: 300,sort: true},
{field: 'resourceComment', title: '中文注释/描述'}, {field: 'resourceComment', title: '中文注释/描述',sort: true},
{field: 'directoryPath', title: '资源路径'}, {field: 'directoryPath', title: '资源路径',sort: true},
{field: 'themeTask', title: '主题任务', hide: true}, {field: 'themeTask', title: '主题任务', hide: true,sort: true},
{ {
field: 'dataSource', field: 'dataSource',
title: '数据来源', title: '数据来源',
width: 160, width: 160,
templet: (data) => DICT.getText("data_source", data.dataSource) || data.dataSource || '' templet: (data) => DICT.getText("data_source", data.dataSource) || data.dataSource || '',sort: true
}, },
{field: 'taskTime', title: '任务时间', width: 180, align: 'center'}, {field: 'taskTime', title: '任务时间', width: 180, align: 'center',sort: true},
{field: 'modifyTime', title: '注册时间', width: 160, align: 'center', hide: true}, {field: 'modifyTime', title: '注册时间', width: 160, align: 'center', hide: true},
{fixed: 'right', title: '操作', toolbar: '#rowToolBar', width: 100, align: 'center'} {fixed: 'right', title: '操作', toolbar: '#rowToolBar', width: 100, align: 'center'}
]], ]],
@ -172,6 +173,16 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop
} }
}, },
}); });
metaListTable.gtable.on('sort', function(data){
console.info(data);
const {field, type} = data;
let sort = type;
if(!sort || sort === 'null'){
sort = undefined;
}
metaListTable.where.sort={field: field.trim(), sort: sort}
beginSearch();
})
metaListTable.addTableRowEvent('export', function (obj) { metaListTable.addTableRowEvent('export', function (obj) {
if (id === DIR_ROOT_ID) { if (id === DIR_ROOT_ID) {
showErrorMsg('不允许导出根目录数据'); showErrorMsg('不允许导出根目录数据');