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

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

1、后端代码展示如下

private List getQcCheckStatList(Map para, String orderByColumn, String isAsc, int pageNum, int pageSize, boolean isAdmin) throws Exception {
   initializeSearch(para);

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

 

你可能感兴趣的:(bootstrap,前端,java)