工程后期改造,加了一層首頁展示,該層無需分頁所以想在代碼層次實現(xiàn)排序,而不是數(shù)據(jù)庫sql文章來源:http://www.zghlxwxcb.cn/news/detail-584822.html
1、后端代碼展示如下
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;
// 展示的數(shù)據(jù)集合
List<QcCheckStatVO> homeDataList = new ArrayList<>(16);
if (isAdmin) {
list = baseMapper.selectPageViewList(para);
// list 以instanceId 分組
// 將在sql中聚合函數(shù)操作放到j(luò)ava中計算
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;
}
?文章來源地址http://www.zghlxwxcb.cn/news/detail-584822.html
到了這里,關(guān)于JAVA前端bootstrap-table表格,全量查數(shù)據(jù)后也能字段點擊排序sort的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!