fix: 首页环保设施运行状况明细优化
This commit is contained in:
parent
23005d7cfc
commit
dcbe70f5f9
@ -5,6 +5,8 @@ import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Schema(description = "首页环保设施运行状况明细")
|
||||
@ -12,6 +14,17 @@ public class OverviewOpedVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Map<String, Object> _tls = new HashMap<>();
|
||||
|
||||
private String id;
|
||||
private String recordUser;
|
||||
private Date recordTime;
|
||||
private Date modifyTime;
|
||||
private String displayRecordUser;
|
||||
private String repCode;
|
||||
private String pcode;
|
||||
private String pname;
|
||||
private String psttpName;
|
||||
private String sttpName;
|
||||
private String baseId;
|
||||
private String stcd;
|
||||
@ -31,14 +44,22 @@ public class OverviewOpedVo implements Serializable {
|
||||
private String stdStateName;
|
||||
private Integer stdSstate;
|
||||
private String stdSstateName;
|
||||
private Integer runSstate;
|
||||
private String runSstateName;
|
||||
private Integer mway;
|
||||
private String mwayName;
|
||||
private String hbrvcd;
|
||||
private String hbrvcdName;
|
||||
private String addvcdName;
|
||||
private String rvcdName;
|
||||
private Integer baseStepSort;
|
||||
private Integer baseStepsort;
|
||||
private Integer rvcdStepSort;
|
||||
private Integer rstcdStepSort;
|
||||
private Integer rstcdStepsort;
|
||||
private Integer siteStepSort;
|
||||
private Integer count;
|
||||
private Date jcdt;
|
||||
private String departmentId;
|
||||
private String displayDepartment;
|
||||
}
|
||||
|
||||
@ -77,6 +77,9 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
DataSourceLoadOptionsBase loadOptions = dataSourceRequest.toDevRequest();
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("stateYear", resolveOpedStateYear());
|
||||
if (shouldQueryOpedSummary(dataSourceRequest)) {
|
||||
return queryOpedSummaryList(dataSourceRequest, loadOptions, paramMap);
|
||||
}
|
||||
|
||||
String filterSql = buildOpedFilterCondition(dataSourceRequest.getFilter(), paramMap, new int[]{0});
|
||||
if (CollUtil.isNotEmpty(dataSourceRequest.getGroup())) {
|
||||
@ -106,6 +109,39 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private DataSourceResult<OverviewOpedVo> queryOpedSummaryList(DataSourceRequest dataSourceRequest,
|
||||
DataSourceLoadOptionsBase loadOptions,
|
||||
Map<String, Object> paramMap) {
|
||||
String effectiveFilterSql = buildOpedEffectiveFilterCondition(dataSourceRequest.getFilter(), paramMap, new int[]{0});
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ")
|
||||
.append(buildOpedSummarySelectSql(dataSourceRequest.getSelect()))
|
||||
.append(" FROM (")
|
||||
.append(buildOpedCategorySql())
|
||||
.append(") cat ")
|
||||
.append("LEFT JOIN (SELECT * FROM (")
|
||||
.append(buildOpedBaseSql())
|
||||
.append(") t WHERE 1 = 1 ");
|
||||
if (StrUtil.isNotBlank(effectiveFilterSql)) {
|
||||
sql.append(" AND ").append(effectiveFilterSql);
|
||||
}
|
||||
sql.append(") src ON cat.repCode = src.repCode ")
|
||||
.append("GROUP BY cat.repCode, cat.sttpName, cat.orderIndex ")
|
||||
.append(buildOpedSummaryOrderBySql(dataSourceRequest.getSort()));
|
||||
|
||||
Page<?> page = loadOptions == null ? null
|
||||
: QgcQueryWrapperUtil.buildPage(loadOptions, loadOptions.getSkip(), loadOptions.getTake());
|
||||
List<OverviewOpedVo> list = microservicDynamicSQLMapper.pageAllListWithResultType(
|
||||
page, sql.toString(), paramMap, OverviewOpedVo.class
|
||||
);
|
||||
|
||||
DataSourceResult<OverviewOpedVo> result = new DataSourceResult<>();
|
||||
result.setData(list);
|
||||
result.setTotal(page == null ? list.size() : page.getTotal());
|
||||
result.setAggregates(new HashMap<>());
|
||||
return result;
|
||||
}
|
||||
|
||||
private String buildBaseSql() {
|
||||
return buildFbSql() + " UNION ALL " + buildDwSql() + " UNION ALL " + buildFpSql();
|
||||
}
|
||||
@ -639,6 +675,7 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
|
||||
private String buildOpedBaseSql() {
|
||||
return "SELECT " +
|
||||
"src.sttpCode AS repCode, " +
|
||||
"src.sttpName AS sttpName, " +
|
||||
"src.baseId AS baseId, " +
|
||||
"src.stcd AS stcd, " +
|
||||
@ -647,6 +684,8 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
"src.baseName AS baseName, " +
|
||||
"src.rstcd AS rstcd, " +
|
||||
"src.ennm AS ennm, " +
|
||||
"CAST(NULL AS VARCHAR2(255)) AS addvcdName, " +
|
||||
"CAST(NULL AS VARCHAR2(255)) AS rvcdName, " +
|
||||
"src.bldsttCcode AS bldsttCcode, " +
|
||||
"src.bldsttCcodeName AS bldsttCcodeName, " +
|
||||
"src.dtinTm AS dtinTm, " +
|
||||
@ -663,6 +702,10 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
"CASE WHEN state.STD_SSTATE = 1 THEN '正常运行' " +
|
||||
"WHEN state.STD_SSTATE IN (0, 2) THEN '暂无数据' " +
|
||||
"WHEN state.STD_SSTATE = 3 THEN '未正常运行' ELSE NULL END AS stdSstateName, " +
|
||||
"state.STD_SSTATE AS runSstate, " +
|
||||
"CASE WHEN state.STD_SSTATE = 1 THEN '正常运行' " +
|
||||
"WHEN state.STD_SSTATE IN (0, 2) THEN '暂无数据' " +
|
||||
"WHEN state.STD_SSTATE = 3 THEN '未正常运行' ELSE NULL END AS runSstateName, " +
|
||||
"CAST(NULL AS NUMBER(10)) AS mway, " +
|
||||
"CAST(NULL AS VARCHAR2(32)) AS mwayName, " +
|
||||
"src.hbrvcd AS hbrvcd, " +
|
||||
@ -862,6 +905,7 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
|
||||
private Map<String, String> buildOpedSelectMap() {
|
||||
Map<String, String> columnMap = new LinkedHashMap<>();
|
||||
columnMap.put("repCode", "t.repCode AS \"repCode\"");
|
||||
columnMap.put("sttpName", "t.sttpName AS \"sttpName\"");
|
||||
columnMap.put("baseId", "t.baseId AS \"baseId\"");
|
||||
columnMap.put("stcd", "t.stcd AS \"stcd\"");
|
||||
@ -870,6 +914,8 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
columnMap.put("baseName", "t.baseName AS \"baseName\"");
|
||||
columnMap.put("rstcd", "t.rstcd AS \"rstcd\"");
|
||||
columnMap.put("ennm", "t.ennm AS \"ennm\"");
|
||||
columnMap.put("addvcdName", "t.addvcdName AS \"addvcdName\"");
|
||||
columnMap.put("rvcdName", "t.rvcdName AS \"rvcdName\"");
|
||||
columnMap.put("bldsttCcode", "t.bldsttCcode AS \"bldsttCcode\"");
|
||||
columnMap.put("bldsttCcodeName", "t.bldsttCcodeName AS \"bldsttCcodeName\"");
|
||||
columnMap.put("dtinTm", "t.dtinTm AS \"dtinTm\"");
|
||||
@ -881,6 +927,8 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
columnMap.put("stdStateName", "t.stdStateName AS \"stdStateName\"");
|
||||
columnMap.put("stdSstate", "t.stdSstate AS \"stdSstate\"");
|
||||
columnMap.put("stdSstateName", "t.stdSstateName AS \"stdSstateName\"");
|
||||
columnMap.put("runSstate", "t.runSstate AS \"runSstate\"");
|
||||
columnMap.put("runSstateName", "t.runSstateName AS \"runSstateName\"");
|
||||
columnMap.put("mway", "t.mway AS \"mway\"");
|
||||
columnMap.put("mwayName", "t.mwayName AS \"mwayName\"");
|
||||
columnMap.put("hbrvcd", "t.hbrvcd AS \"hbrvcd\"");
|
||||
@ -921,6 +969,35 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
return String.join(logic, conditions);
|
||||
}
|
||||
|
||||
private String buildOpedEffectiveFilterCondition(DataSourceRequest.FilterDescriptor filter,
|
||||
Map<String, Object> paramMap,
|
||||
int[] indexHolder) {
|
||||
if (filter == null) {
|
||||
return "";
|
||||
}
|
||||
if (StrUtil.isNotBlank(filter.getField())) {
|
||||
if ("1".equals(StrUtil.trim(filter.getField()))) {
|
||||
return "";
|
||||
}
|
||||
return buildOpedLeafCondition(filter, paramMap, indexHolder);
|
||||
}
|
||||
if (CollUtil.isEmpty(filter.getFilters())) {
|
||||
return "";
|
||||
}
|
||||
List<String> conditions = new ArrayList<>();
|
||||
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
||||
String childSql = buildOpedEffectiveFilterCondition(child, paramMap, indexHolder);
|
||||
if (StrUtil.isNotBlank(childSql)) {
|
||||
conditions.add("(" + childSql + ")");
|
||||
}
|
||||
}
|
||||
if (conditions.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
String logic = "or".equalsIgnoreCase(filter.getLogic()) ? " OR " : " AND ";
|
||||
return String.join(logic, conditions);
|
||||
}
|
||||
|
||||
private String buildOpedLeafCondition(DataSourceRequest.FilterDescriptor filter,
|
||||
Map<String, Object> paramMap,
|
||||
int[] indexHolder) {
|
||||
@ -1098,6 +1175,147 @@ public class OverviewServiceImpl implements OverviewService {
|
||||
" ORDER BY " + String.join(", ", orderItems);
|
||||
}
|
||||
|
||||
private boolean shouldQueryOpedSummary(DataSourceRequest dataSourceRequest) {
|
||||
return dataSourceRequest != null
|
||||
&& CollUtil.isEmpty(dataSourceRequest.getGroup())
|
||||
&& hasOnlyDummyFilter(dataSourceRequest.getFilter());
|
||||
}
|
||||
|
||||
private boolean hasOnlyDummyFilter(DataSourceRequest.FilterDescriptor filter) {
|
||||
return hasDummyField(filter) && !hasRealField(filter);
|
||||
}
|
||||
|
||||
private boolean hasDummyField(DataSourceRequest.FilterDescriptor filter) {
|
||||
if (filter == null) {
|
||||
return false;
|
||||
}
|
||||
if ("1".equals(StrUtil.trim(filter.getField()))) {
|
||||
return true;
|
||||
}
|
||||
if (CollUtil.isEmpty(filter.getFilters())) {
|
||||
return false;
|
||||
}
|
||||
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
||||
if (hasDummyField(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasRealField(DataSourceRequest.FilterDescriptor filter) {
|
||||
if (filter == null) {
|
||||
return false;
|
||||
}
|
||||
String field = StrUtil.trim(filter.getField());
|
||||
if (StrUtil.isNotBlank(field) && !"1".equals(field)) {
|
||||
return true;
|
||||
}
|
||||
if (CollUtil.isEmpty(filter.getFilters())) {
|
||||
return false;
|
||||
}
|
||||
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
||||
if (hasRealField(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String buildOpedCategorySql() {
|
||||
return "SELECT 'VA' AS repCode, '动物救助站' AS sttpName, 1 AS orderIndex FROM dual " +
|
||||
"UNION ALL SELECT 'FP' AS repCode, '过鱼设施' AS sttpName, 2 AS orderIndex FROM dual " +
|
||||
"UNION ALL SELECT 'FB' AS repCode, '鱼类增殖站' AS sttpName, 3 AS orderIndex FROM dual " +
|
||||
"UNION ALL SELECT 'DW' AS repCode, '低温水减缓设施' AS sttpName, 4 AS orderIndex FROM dual " +
|
||||
"UNION ALL SELECT 'VP' AS repCode, '珍稀植物园' AS sttpName, 5 AS orderIndex FROM dual " +
|
||||
"UNION ALL SELECT 'FH' AS repCode, '鱼类栖息地' AS sttpName, 6 AS orderIndex FROM dual " +
|
||||
"UNION ALL SELECT 'EQ' AS repCode, '生态流量泄放设施' AS sttpName, 7 AS orderIndex FROM dual";
|
||||
}
|
||||
|
||||
private String buildOpedSummarySelectSql(List<String> selectFields) {
|
||||
Map<String, String> columnMap = buildOpedSummarySelectMap();
|
||||
List<String> fields = CollUtil.isEmpty(selectFields)
|
||||
? new ArrayList<>(columnMap.keySet())
|
||||
: new ArrayList<>(selectFields);
|
||||
List<String> selectItems = new ArrayList<>();
|
||||
for (String field : fields) {
|
||||
if (StrUtil.isBlank(field)) {
|
||||
continue;
|
||||
}
|
||||
String column = columnMap.get(field.trim());
|
||||
if (StrUtil.isNotBlank(column)) {
|
||||
selectItems.add(column);
|
||||
}
|
||||
}
|
||||
if (selectItems.isEmpty()) {
|
||||
selectItems.addAll(columnMap.values());
|
||||
}
|
||||
return String.join(", ", selectItems);
|
||||
}
|
||||
|
||||
private Map<String, String> buildOpedSummarySelectMap() {
|
||||
Map<String, String> columnMap = new LinkedHashMap<>();
|
||||
columnMap.put("id", "CAST(NULL AS VARCHAR2(64)) AS \"id\"");
|
||||
columnMap.put("recordUser", "CAST(NULL AS VARCHAR2(64)) AS \"recordUser\"");
|
||||
columnMap.put("recordTime", "CAST(NULL AS DATE) AS \"recordTime\"");
|
||||
columnMap.put("modifyTime", "CAST(NULL AS DATE) AS \"modifyTime\"");
|
||||
columnMap.put("displayRecordUser", "CAST(NULL AS VARCHAR2(128)) AS \"displayRecordUser\"");
|
||||
columnMap.put("repCode", "cat.repCode AS \"repCode\"");
|
||||
columnMap.put("sttpCode", "CAST(NULL AS VARCHAR2(64)) AS \"sttpCode\"");
|
||||
columnMap.put("pcode", "CAST(NULL AS VARCHAR2(64)) AS \"pcode\"");
|
||||
columnMap.put("pname", "CAST(NULL AS VARCHAR2(128)) AS \"pname\"");
|
||||
columnMap.put("psttpName", "CAST(NULL AS VARCHAR2(128)) AS \"psttpName\"");
|
||||
columnMap.put("stcd", "CAST(NULL AS VARCHAR2(64)) AS \"stcd\"");
|
||||
columnMap.put("ennm", "CAST(NULL AS VARCHAR2(255)) AS \"ennm\"");
|
||||
columnMap.put("stnm", "CAST(NULL AS VARCHAR2(255)) AS \"stnm\"");
|
||||
columnMap.put("addvcdName", "CAST(NULL AS VARCHAR2(255)) AS \"addvcdName\"");
|
||||
columnMap.put("rvcdName", "CAST(NULL AS VARCHAR2(255)) AS \"rvcdName\"");
|
||||
columnMap.put("sttpName", "cat.sttpName AS \"sttpName\"");
|
||||
columnMap.put("baseId", "CAST(NULL AS VARCHAR2(64)) AS \"baseId\"");
|
||||
columnMap.put("dtin", "CAST(NULL AS NUMBER(10)) AS \"dtin\"");
|
||||
columnMap.put("dtinName", "CAST(NULL AS VARCHAR2(32)) AS \"dtinName\"");
|
||||
columnMap.put("runState", "CAST(NULL AS NUMBER(10)) AS \"runState\"");
|
||||
columnMap.put("runStateName", "CAST(NULL AS VARCHAR2(32)) AS \"runStateName\"");
|
||||
columnMap.put("stdState", "CAST(NULL AS NUMBER(10)) AS \"stdState\"");
|
||||
columnMap.put("stdStateName", "CAST(NULL AS VARCHAR2(32)) AS \"stdStateName\"");
|
||||
columnMap.put("bldsttCcode", "CAST(NULL AS VARCHAR2(10)) AS \"bldsttCcode\"");
|
||||
columnMap.put("bldsttCcodeName", "CAST(NULL AS VARCHAR2(32)) AS \"bldsttCcodeName\"");
|
||||
columnMap.put("count", "COUNT(src.repCode) AS \"count\"");
|
||||
columnMap.put("jcdt", "CAST(NULL AS DATE) AS \"jcdt\"");
|
||||
columnMap.put("runSstate", "CAST(NULL AS NUMBER(10)) AS \"runSstate\"");
|
||||
columnMap.put("runSstateName", "CAST(NULL AS VARCHAR2(32)) AS \"runSstateName\"");
|
||||
columnMap.put("departmentId", "CAST(NULL AS VARCHAR2(64)) AS \"departmentId\"");
|
||||
columnMap.put("displayDepartment", "CAST(NULL AS VARCHAR2(255)) AS \"displayDepartment\"");
|
||||
return columnMap;
|
||||
}
|
||||
|
||||
private String buildOpedSummaryOrderBySql(List<DataSourceRequest.SortDescriptor> sortList) {
|
||||
if (CollUtil.isEmpty(sortList)) {
|
||||
return " ORDER BY cat.orderIndex ASC, cat.repCode ASC";
|
||||
}
|
||||
List<String> orderItems = new ArrayList<>();
|
||||
for (DataSourceRequest.SortDescriptor sort : sortList) {
|
||||
if (sort == null || StrUtil.isBlank(sort.getField())) {
|
||||
continue;
|
||||
}
|
||||
String column = switch (sort.getField()) {
|
||||
case "repCode" -> "cat.repCode";
|
||||
case "sttpName" -> "cat.sttpName";
|
||||
case "count" -> "COUNT(src.repCode)";
|
||||
default -> null;
|
||||
};
|
||||
if (StrUtil.isBlank(column)) {
|
||||
continue;
|
||||
}
|
||||
String dir = "desc".equalsIgnoreCase(sort.getDir()) || "des".equalsIgnoreCase(sort.getDir()) ? "DESC" : "ASC";
|
||||
orderItems.add(column + " " + dir);
|
||||
}
|
||||
if (orderItems.isEmpty()) {
|
||||
return " ORDER BY cat.orderIndex ASC, cat.repCode ASC";
|
||||
}
|
||||
return " ORDER BY " + String.join(", ", orderItems);
|
||||
}
|
||||
|
||||
private List<Object> normalizeValues(Object value) {
|
||||
List<Object> values = new ArrayList<>();
|
||||
collectValues(value, values);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user