JAVA前端bootstrap-table表格,全量查数据后也能字段点击排序sort

工程后期改造,加了一层首页展示,该层无需分页所以想在代码层次实现排序,而不是数据库sql

1、后端代码展示如下

java 复制代码
private List<QcCheckStatVO> getQcCheckStatList(Map<String, Object> para, String orderByColumn, String isAsc, int pageNum, int pageSize, boolean isAdmin) throws Exception {
   initializeSearch(para);

   List<QcCheckStatVO> list;
   // 展示的数据集合
   List<QcCheckStatVO> homeDataList = new ArrayList<>(16);
        if (isAdmin) {
            list = baseMapper.selectPageViewList(para);
            // list 以instanceId 分组
            // 将在sql中聚合函数操作放到java中计算
            Map<String, List<QcCheckStatVO>> collect = list.stream().collect(Collectors.groupingBy(o -> o.getInstanceId()));
            for (String s : collect.keySet()) {
                extracted(homeDataList, collect, s);
            }
            // 组装排序字段
            if (StrUtil.isAllNotBlank(orderByColumn, isAsc)) {
                Comparator<QcCheckStatVO> qcCheckStatVOComparator = Comparator.comparing(QcCheckStatVO::getCreateTime).reversed().thenComparing(QcCheckStatVO::getReqFieldErrorCount);
                Map<Key, Comparator<QcCheckStatVO>> map = new HashMap<>(16);
                map.put(new Key("expectCount", SqlKeyword.ASC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getErrorCount));
                map.put(new Key("expectCount", SqlKeyword.DESC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getErrorCount).reversed());

                map.put(new Key("actualCount", SqlKeyword.ASC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getActualCount));
                map.put(new Key("actualCount", SqlKeyword.DESC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getActualCount).reversed());

                map.put(new Key("errorCount", SqlKeyword.ASC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getErrorCount));
                map.put(new Key("errorCount", SqlKeyword.DESC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getErrorCount).reversed());

                map.put(new Key("integrity", SqlKeyword.ASC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getReqFieldErrorCount));
                map.put(new Key("integrity", SqlKeyword.DESC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getReqFieldErrorCount).reversed());

                map.put(new Key("foreignRate", SqlKeyword.ASC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getForeignErrorCount));
                map.put(new Key("foreignRate", SqlKeyword.DESC.getSqlSegment()), Comparator.comparing(QcCheckStatVO::getForeignErrorCount).reversed());
                for (Key key : map.keySet()) {
                    if (key.getField().equalsIgnoreCase(orderByColumn) && key.getDirection().equalsIgnoreCase(isAsc)) {
                        qcCheckStatVOComparator = map.get(key);
                    }
                }
                final List<QcCheckStatVO> sortedList = homeDataList.stream().sorted(qcCheckStatVOComparator).collect(Collectors.toList());
                homeDataList = sortedList;
            }
        } else {
            // 首页不分页,第二层才分页,所以将排序条件加上去
            // 组装排序字段
            String orderBy = "";
            if (StrUtil.isAllNotBlank(orderByColumn, isAsc)) {
                orderBy = " " + EnumExtUtil.getEnumOnValue(QcCheckStatConstants.SortFieldEnum.class, orderByColumn, "key").getValue() + " " + isAsc;
                para.put("sortKey", orderByColumn);
                if (StrUtil.equalsIgnoreCase(SqlKeyword.ASC.getSqlSegment(), isAsc)) {
                    para.put("sortType", SqlKeyword.ASC.getSqlSegment());
                } else {
                    para.put("sortType", SqlKeyword.DESC.getSqlSegment());
                }
            } else {
                if (isAdmin) {
                    orderBy = " REQ_FIELD_ERROR_COUNT asc";
                } else {
                    orderBy = " t1.CREATE_TIME desc ,t1.REQ_FIELD_ERROR_COUNT asc";
                }
            }
            try {
                PageHelper.startPage(pageNum, pageSize, orderBy);
                list = baseMapper.selectPageViewList(para);
                homeDataList = list;
            } finally {
                PageHelper.clearPage();
            }
        }

        if (CollUtil.isEmpty(list)) {
            return new ArrayList<>();
        }

        for (QcCheckStatVO vo : homeDataList) {
            // 前置机名
            if (ProjectConstant.ProjectName.RONGDA_DEQC.equals(projectConfig.getName())) {
                vo.setInstanceName(ConfigUtil.get("deqc.check.instance.name", "未知"));
            } else if (ProjectConstant.ProjectName.RONGDA_DESYS.equals(projectConfig.getName())) {
                final Instance instance = instanceCoreMapper.selectById(vo.getInstanceId());
                if (ObjectUtil.isNotNull(instance)) {
                    vo.setInstanceName(instance.getInstanceName());
                }
            }
            // 判断实传是否为0 有的话,则显示'异常'
            boolean actualCountErrorFlag = false;
            if (ObjectUtil.isNull(vo.getActualCount()) || vo.getActualCount().equals("0")) {
                actualCountErrorFlag = true;
            }
            vo.setActualCountErrorFlag(actualCountErrorFlag);
            // 完整性
            vo.setIntegrity(StrUtil.format("{}/{}", vo.getReqFieldErrorCount(), vo.getReqFieldCount()));
            // 饱和度
            // 饱和度率
            vo.setSaturation(StrUtil.format("{}/{}", vo.getReqFieldCount(), vo.getReqFieldErrorCount()));
            vo.setSaturationRate(countRate(vo.getReqFieldErrorCount().toString(), vo.getReqFieldCount().toString()));

            // 及时性
            // 及时性率
            if (vo.getActualCount() > 0 && !vo.getActualCountErrorFlag()) {
                vo.setTimeliness("正常");
            } else {
                vo.setTimeliness("异常");
            }

            // 错误率
            final String errorRate = countRate(vo.getErrorCount().toString(), vo.getCheckCount().toString());
            vo.setErrorRate(errorRate);

            // 外键错误率
            final String foreignRate = countRate(vo.getForeignErrorCount().toString(), vo.getCheckCount().toString());
            vo.setForeignRate(foreignRate);
        }


        return homeDataList;
    }
相关推荐
程序员海军3 分钟前
沪漂五周年了:我越来越迷茫了
前端·人工智能·后端
biubiubiu070611 分钟前
SpringBoot3.5.4 AOP环绕通知使用
java·spring boot
一天 24h16 分钟前
Vue3父子组件传值:从零到精通
前端·javascript·vue.js·pycharm·npm·学习方法
西安邮电大学20 分钟前
Redis四大经典缓存问题
java·redis·后端·其他·面试
大家的林语冰24 分钟前
CSS 新函数上市,一行代码让文本自动变色,无需 JS 也能符合 W3C 无障碍对比度标准
前端·javascript·css
爱勇宝24 分钟前
前端工程师的下一站:不是失业,而是 AI Engineer
前端·javascript·架构
超梦dasgg28 分钟前
Redisson解锁失败,WatchDog会不会一直续期下去?
java·redis
小雨下雨的雨34 分钟前
电池电量检测工具 - 鸿蒙PC用Electron框架技术实现详解
前端·javascript·华为·electron·鸿蒙·鸿蒙系统
Chase_______38 分钟前
【Java基础 | 11】异常处理进阶:throw、throws、自定义异常与异常链讲清楚
java·开发语言·python
DFT计算杂谈39 分钟前
VASP 磁性结构可视化:一键生成完美 VESTA / MCIF
java·前端·css·html·css3