fix: 优化逻辑
This commit is contained in:
parent
2e69b3e73c
commit
d2199e47b8
@ -3,15 +3,7 @@ package com.yfd.platform.qgc_env.wq.service.impl;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.yfd.platform.common.CommonConstant;
|
import com.yfd.platform.common.*;
|
||||||
import com.yfd.platform.common.DataSourceLoadOptionsBase;
|
|
||||||
import com.yfd.platform.common.DataSourceRequest;
|
|
||||||
import com.yfd.platform.common.DataSourceResult;
|
|
||||||
import com.yfd.platform.common.Group;
|
|
||||||
import com.yfd.platform.common.GroupHelper;
|
|
||||||
import com.yfd.platform.common.GroupingInfo;
|
|
||||||
import com.yfd.platform.common.MicroservicDynamicSQLMapper;
|
|
||||||
import com.yfd.platform.common.PageInfo;
|
|
||||||
import com.yfd.platform.common.exception.BizException;
|
import com.yfd.platform.common.exception.BizException;
|
||||||
import com.yfd.platform.qgc_base.entity.vo.BatchDeleteAo;
|
import com.yfd.platform.qgc_base.entity.vo.BatchDeleteAo;
|
||||||
import com.yfd.platform.qgc_base.entity.vo.DataParam;
|
import com.yfd.platform.qgc_base.entity.vo.DataParam;
|
||||||
@ -694,6 +686,7 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
|||||||
baseSql.append("SELECT ")
|
baseSql.append("SELECT ")
|
||||||
.append("NVL(t.IS_DELETED, 0) AS isDeleted, ")
|
.append("NVL(t.IS_DELETED, 0) AS isDeleted, ")
|
||||||
.append("t.STTP AS sttpCode, ")
|
.append("t.STTP AS sttpCode, ")
|
||||||
|
.append("t.WARN_STATE AS warnState, ")
|
||||||
.append("t.MWAY AS mway, ")
|
.append("t.MWAY AS mway, ")
|
||||||
.append("t.DTIN_TYPE AS dtinType, ")
|
.append("t.DTIN_TYPE AS dtinType, ")
|
||||||
.append("t.STCD AS stcd, ")
|
.append("t.STCD AS stcd, ")
|
||||||
@ -731,6 +724,8 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
|||||||
DataSourceResult result = new DataSourceResult();
|
DataSourceResult result = new DataSourceResult();
|
||||||
if (Boolean.TRUE.equals(dataSourceRequest.getGroupResultFlat())) {
|
if (Boolean.TRUE.equals(dataSourceRequest.getGroupResultFlat())) {
|
||||||
result.setData(new GroupHelper().faltGroup(rows, Arrays.asList(groupInfos)));
|
result.setData(new GroupHelper().faltGroup(rows, Arrays.asList(groupInfos)));
|
||||||
|
} else if (groupInfos != null && groupInfos.length == 1 && groupInfos[0] != null && StrUtil.isNotBlank(groupInfos[0].getSelector())) {
|
||||||
|
result.setData(toMsstbprptLegacyGroups(rows, groupInfos[0].getSelector()));
|
||||||
} else {
|
} else {
|
||||||
result.setData(toLegacyGroupResult(new GroupHelper().group(rows, Arrays.asList(groupInfos)), 0));
|
result.setData(toLegacyGroupResult(new GroupHelper().group(rows, Arrays.asList(groupInfos)), 0));
|
||||||
}
|
}
|
||||||
@ -3181,14 +3176,17 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
String upperField = groupField == null ? "DTINTYPE" : groupField.toUpperCase();
|
String upperField = groupField == null ? "DTINTYPE" : groupField.toUpperCase();
|
||||||
String countField = "COUNT_" + upperField;
|
|
||||||
String aggregateKey = "count_" + groupField;
|
|
||||||
for (Map<String, Object> row : rows) {
|
for (Map<String, Object> row : rows) {
|
||||||
Object key = row.get(upperField);
|
Object key = row.get(upperField);
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
key = row.get(groupField);
|
key = row.get(groupField);
|
||||||
}
|
}
|
||||||
|
String countField = row.containsKey("COUNT_STCD") ? "COUNT_STCD" : "COUNT_" + upperField;
|
||||||
|
String aggregateKey = "COUNT_STCD".equals(countField) ? "count_stcd" : "count_" + groupField;
|
||||||
Object countValue = row.get(countField);
|
Object countValue = row.get(countField);
|
||||||
|
if (countValue == null) {
|
||||||
|
countValue = row.get("count_stcd");
|
||||||
|
}
|
||||||
if (countValue == null) {
|
if (countValue == null) {
|
||||||
countValue = row.get("count_" + upperField);
|
countValue = row.get("count_" + upperField);
|
||||||
}
|
}
|
||||||
@ -3208,7 +3206,7 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
|||||||
detail.put(upperField, key);
|
detail.put(upperField, key);
|
||||||
detail.put(countField, count);
|
detail.put(countField, count);
|
||||||
item.put("items", List.of(detail));
|
item.put("items", List.of(detail));
|
||||||
item.put("count", count);
|
item.put("count", 0);
|
||||||
item.put("summary", new Object[0]);
|
item.put("summary", new Object[0]);
|
||||||
|
|
||||||
Map<String, Object> aggregates = new LinkedHashMap<>();
|
Map<String, Object> aggregates = new LinkedHashMap<>();
|
||||||
@ -3224,23 +3222,48 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
|||||||
return baseSql;
|
return baseSql;
|
||||||
}
|
}
|
||||||
List<String> groupFields = new ArrayList<>();
|
List<String> groupFields = new ArrayList<>();
|
||||||
|
List<String> selectItems = new ArrayList<>();
|
||||||
List<String> orderByItems = new ArrayList<>();
|
List<String> orderByItems = new ArrayList<>();
|
||||||
for (GroupingInfo item : groupInfos) {
|
for (GroupingInfo item : groupInfos) {
|
||||||
if (item == null || StrUtil.isBlank(item.getSelector())) {
|
if (item == null || StrUtil.isBlank(item.getSelector())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
groupFields.add(item.getSelector());
|
String selector = item.getSelector();
|
||||||
|
groupFields.add(selector);
|
||||||
|
selectItems.add(selector + " AS " + selector.toUpperCase());
|
||||||
String dir = Boolean.TRUE.equals(item.getDesc()) ? "DESC" : "ASC";
|
String dir = Boolean.TRUE.equals(item.getDesc()) ? "DESC" : "ASC";
|
||||||
orderByItems.add(item.getSelector() + " " + dir);
|
orderByItems.add(selector + " " + dir);
|
||||||
|
boolean hasCountStcd = false;
|
||||||
|
if (CollUtil.isNotEmpty(item.getSummaryInfos())) {
|
||||||
|
for (SummaryInfo summaryInfo : item.getSummaryInfos()) {
|
||||||
|
if (summaryInfo == null || StrUtil.isBlank(summaryInfo.getSelector()) || StrUtil.isBlank(summaryInfo.getSummaryType())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String summaryType = summaryInfo.getSummaryType().toUpperCase();
|
||||||
|
String summarySelector = summaryInfo.getSelector().toUpperCase();
|
||||||
|
if ("count".equalsIgnoreCase(summaryInfo.getSummaryType()) && "stcd".equalsIgnoreCase(summaryInfo.getSelector())) {
|
||||||
|
hasCountStcd = true;
|
||||||
|
}
|
||||||
|
switch (summaryInfo.getSummaryType().toLowerCase()) {
|
||||||
|
case "count" -> selectItems.add("COUNT(" + summaryInfo.getSelector() + ") AS " + summaryType + "_" + summarySelector);
|
||||||
|
case "sum" -> selectItems.add("SUM(" + summaryInfo.getSelector() + ") AS " + summaryType + "_" + summarySelector);
|
||||||
|
case "avg", "average" -> selectItems.add("AVG(" + summaryInfo.getSelector() + ") AS AVG_" + summarySelector);
|
||||||
|
case "min" -> selectItems.add("MIN(" + summaryInfo.getSelector() + ") AS " + summaryType + "_" + summarySelector);
|
||||||
|
case "max" -> selectItems.add("MAX(" + summaryInfo.getSelector() + ") AS " + summaryType + "_" + summarySelector);
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasCountStcd) {
|
||||||
|
selectItems.add("COUNT(*) AS COUNT_STCD");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (groupFields.isEmpty()) {
|
if (groupFields.isEmpty()) {
|
||||||
return baseSql;
|
return baseSql;
|
||||||
}
|
}
|
||||||
StringBuilder sql = new StringBuilder("SELECT ");
|
StringBuilder sql = new StringBuilder("SELECT ");
|
||||||
sql.append(String.join(", ", groupFields));
|
sql.append(String.join(", ", selectItems));
|
||||||
for (String groupField : groupFields) {
|
|
||||||
sql.append(", COUNT(*) AS count_").append(groupField).append(" ");
|
|
||||||
}
|
|
||||||
sql.append(" FROM (").append(baseSql).append(") T ")
|
sql.append(" FROM (").append(baseSql).append(") T ")
|
||||||
.append(" GROUP BY ").append(String.join(", ", groupFields)).append(" ");
|
.append(" GROUP BY ").append(String.join(", ", groupFields)).append(" ");
|
||||||
if (!orderByItems.isEmpty()) {
|
if (!orderByItems.isEmpty()) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user