diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/vap/controller/VpConstructionController.java b/backend/src/main/java/com/yfd/platform/qgc_env/vap/controller/VpConstructionController.java index faae8d6e..70eb01fc 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/vap/controller/VpConstructionController.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/vap/controller/VpConstructionController.java @@ -26,4 +26,10 @@ public class VpConstructionController { public ResponseResult getKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) { return ResponseResult.successData(vpConstructionService.processKendoList(dataSourceRequest)); } + + @PostMapping("/vmsstbprpt/GetKendoList") + @Operation(summary = "植物园统计查询") + public ResponseResult getVmsstbprptList(@RequestBody DataSourceRequest dataSourceRequest) { + return ResponseResult.successData(vpConstructionService.processVmsstbprptList(dataSourceRequest)); + } } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/vap/entity/vo/VpVmsstbprptVo.java b/backend/src/main/java/com/yfd/platform/qgc_env/vap/entity/vo/VpVmsstbprptVo.java new file mode 100644 index 00000000..12bbfcad --- /dev/null +++ b/backend/src/main/java/com/yfd/platform/qgc_env/vap/entity/vo/VpVmsstbprptVo.java @@ -0,0 +1,159 @@ +package com.yfd.platform.qgc_env.vap.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +@Data +@Schema(description = "植物园统计查询") +public class VpVmsstbprptVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键") + private String id; + + @Schema(description = "创建人") + private String recordUser; + + @Schema(description = "创建时间") + private Date recordTime; + + @Schema(description = "修改时间") + private Date modifyTime; + + @Schema(description = "创建人展示") + private String displayRecordUser; + + @Schema(description = "流域排序") + private Integer rvcdStepSort; + + @Schema(description = "电站排序") + private Integer rstcdStepSort; + + @Schema(description = "站点排序") + private Integer siteStepSort; + + @Schema(description = "基地排序") + private Integer baseStepSort; + + @Schema(description = "站点编码") + private String stcd; + + @Schema(description = "站点名称") + private String stnm; + + @Schema(description = "站类") + private String sttp; + + @Schema(description = "站类编码") + private String sttpCode; + + @Schema(description = "站类名称") + private String sttpName; + + @Schema(description = "站类全路径") + private String sttpFullPath; + + @Schema(description = "站类层级") + private Integer sttpTreeLevel; + + @Schema(description = "经度") + private Double lgtd; + + @Schema(description = "纬度") + private Double lttd; + + @Schema(description = "站址") + private String stlc; + + @Schema(description = "是否启用") + private Integer usfl; + + @Schema(description = "所属电站编码") + private String rstcd; + + @Schema(description = "所属电站名称") + private String ennm; + + @Schema(description = "所属基地编码") + private String baseId; + + @Schema(description = "所属基地名称") + private String baseName; + + @Schema(description = "所属基地流域编码") + private String hbrvcd; + + @Schema(description = "所属基地流域名称") + private String hbrvcdName; + + @Schema(description = "所属流域编码") + private String rvcd; + + @Schema(description = "所属流域名称") + private String rvcdName; + + @Schema(description = "规划设计日期") + private Date stdsdt; + + @Schema(description = "计划开工日期") + private Date pststdt; + + @Schema(description = "计划完工日期") + private Date pesstdt; + + @Schema(description = "开工日期") + private Date ststdt; + + @Schema(description = "建成日期") + private Date jcdt; + + @Schema(description = "简介") + private String introduce; + + @Schema(description = "LOGO") + private String logo; + + @Schema(description = "介绍图") + private String inffile; + + @Schema(description = "是否接入") + private Integer dtin; + + @Schema(description = "是否接入名称") + private String dtinName; + + @Schema(description = "接入时间") + private Date dtinTm; + + @Schema(description = "建设状态") + private String bldstt; + + @Schema(description = "建设状态名称") + private String bldsttName; + + @Schema(description = "建设状态分类") + private String bldsttCcode; + + @Schema(description = "建设状态分类名称") + private String bldsttCcodeName; + + @Schema(description = "投资") + private BigDecimal inv; + + @Schema(description = "总工期") + private BigDecimal aptl; + + @Schema(description = "面积") + private BigDecimal area; + + @Schema(description = "运行状态") + private Integer runState; + + @Schema(description = "运行状态名称") + private String runStateName; +} diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/VpConstructionService.java b/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/VpConstructionService.java index ddaeee38..e2c99950 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/VpConstructionService.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/VpConstructionService.java @@ -6,4 +6,6 @@ import com.yfd.platform.common.DataSourceResult; public interface VpConstructionService { DataSourceResult processKendoList(DataSourceRequest dataSourceRequest); + + DataSourceResult processVmsstbprptList(DataSourceRequest dataSourceRequest); } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/impl/VpConstructionServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/impl/VpConstructionServiceImpl.java index 0b1c4305..84a1995d 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/impl/VpConstructionServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/vap/service/impl/VpConstructionServiceImpl.java @@ -10,6 +10,7 @@ import com.yfd.platform.common.GroupingInfo; import com.yfd.platform.common.MicroservicDynamicSQLMapper; import com.yfd.platform.common.PageInfo; import com.yfd.platform.qgc_env.vap.entity.vo.VpConstructionSituationVo; +import com.yfd.platform.qgc_env.vap.entity.vo.VpVmsstbprptVo; import com.yfd.platform.qgc_env.vap.service.VpConstructionService; import com.yfd.platform.utils.KendoUtil; import com.yfd.platform.utils.QgcQueryWrapperUtil; @@ -80,6 +81,53 @@ public class VpConstructionServiceImpl implements VpConstructionService { return result; } + @Override + public DataSourceResult processVmsstbprptList(DataSourceRequest dataSourceRequest) { + DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest(); + PageInfo pageInfo = loadOptions == null ? new PageInfo() : QgcQueryWrapperUtil.getPageInfo(loadOptions); + Page page = pageInfo.getHasPageInfo() ? pageInfo.getPage() : null; + + Map paramMap = new HashMap<>(); + StringBuilder sql = new StringBuilder(buildVmsstbprptBaseSql()); + String filterSql = buildVmsstbprptFilterCondition( + dataSourceRequest == null ? null : dataSourceRequest.getFilter(), + paramMap, + new int[]{0} + ); + if (StrUtil.isNotBlank(filterSql)) { + sql.append(" AND ").append(filterSql); + } + + String groupBy = dataSourceRequest == null ? null : KendoUtil.getGroupBy(dataSourceRequest); + GroupingInfo[] groupInfos = loadOptions == null ? null : loadOptions.getGroup(); + if (StrUtil.isNotBlank(groupBy) && groupInfos != null && groupInfos.length > 0) { + String groupedSql = buildVmsstbprptGroupSql(sql.toString(), groupInfos); + List> rows = microservicDynamicSQLMapper.pageAllList(null, groupedSql, paramMap); + DataSourceResult result = new DataSourceResult(); + if (Boolean.TRUE.equals(dataSourceRequest.getGroupResultFlat())) { + result.setData(new GroupHelper().faltGroup(rows, Arrays.asList(groupInfos))); + } else { + result.setData(new GroupHelper().group(rows, Arrays.asList(groupInfos))); + } + result.setTotal(0L); + result.setAggregates(new HashMap<>()); + return result; + } + + sql.append(buildVmsstbprptOrderBySql(dataSourceRequest == null ? null : dataSourceRequest.getSort())); + List list = microservicDynamicSQLMapper.pageAllListWithResultType( + page, + sql.toString(), + paramMap, + VpVmsstbprptVo.class + ); + DataSourceResult result = new DataSourceResult<>(); + result.setData(list); + result.setTotal(page != null ? page.getTotal() : list.size()); + result.setAggregates(new HashMap<>()); + return result; + } + private String buildBaseSql(boolean botanicalGarden, boolean nationwide) { String baseIdExpr = botanicalGarden ? "CASE WHEN vp.BASE_ID IS NULL THEN 'null' ELSE vp.BASE_ID END" @@ -371,4 +419,273 @@ public class VpConstructionServiceImpl implements VpConstructionService { } return values; } + + private String buildVmsstbprptBaseSql() { + return "SELECT " + + "vp.STCD AS id, " + + "vp.RECORD_USER AS recordUser, " + + "vp.RECORD_TIME AS recordTime, " + + "vp.MODIFY_TIME AS modifyTime, " + + "CAST(NULL AS VARCHAR2(100)) AS displayRecordUser, " + + "NVL(eng.ORDER_INDEX, 999999) AS rvcdStepSort, " + + "NVL(eng.ORDER_INDEX, 999999) AS rstcdStepSort, " + + "NVL(vp.ORDER_INDEX, 999999) AS siteStepSort, " + + "NVL(hb.ORDER_INDEX, 999999) AS baseStepSort, " + + "vp.STCD AS stcd, " + + "vp.STNM AS stnm, " + + "vp.STTP AS sttp, " + + "vp.STTP AS sttpCode, " + + "sttp.STTP_NAME AS sttpName, " + + "sttp.FULL_PATH AS sttpFullPath, " + + "sttp.TREE_LEVEL AS sttpTreeLevel, " + + "vp.LGTD AS lgtd, " + + "vp.LTTD AS lttd, " + + "vp.STLC AS stlc, " + + "vp.USFL AS usfl, " + + "vp.RSTCD AS rstcd, " + + "eng.ENNM AS ennm, " + + "vp.BASE_ID AS baseId, " + + "hb.BASENAME AS baseName, " + + "vp.HBRVCD AS hbrvcd, " + + "CAST(NULL AS VARCHAR2(100)) AS hbrvcdName, " + + "eng.REACHCD AS rvcd, " + + "eng.REACHCD_NAME AS rvcdName, " + + "vp.STDSDT AS stdsdt, " + + "vp.PSTSTDT AS pststdt, " + + "vp.PESSTDT AS pesstdt, " + + "vp.SWDT AS ststdt, " + + "vp.JCDT AS jcdt, " + + "vp.INTRODUCE AS introduce, " + + "vp.LOGO AS logo, " + + "vp.INFFILE AS inffile, " + + "vp.DTIN AS dtin, " + + "CASE WHEN NVL(vp.DTIN, 0) = 1 THEN '已接入' ELSE '未接入' END AS dtinName, " + + "vp.DTIN_TM AS dtinTm, " + + "TO_CHAR(vp.BLPRD) AS bldstt, " + + "CAST(NULL AS VARCHAR2(100)) AS bldsttName, " + + "TO_CHAR(vp.BLDSTT_CODE) AS bldsttCcode, " + + "CASE WHEN NVL(vp.BLDSTT_CODE, 0) = 2 THEN '已建' " + + "WHEN NVL(vp.BLDSTT_CODE, 0) = 1 THEN '在建' ELSE '未建/规划' END AS bldsttCcodeName, " + + "vp.INV AS inv, " + + "vp.APTL AS aptl, " + + "vp.AREA AS area, " + + "eng.RUN_STATE AS runState, " + + "CASE WHEN eng.RUN_STATE = 1 THEN '运行中' WHEN eng.RUN_STATE = 2 THEN '未运行' ELSE NULL END AS runStateName " + + "FROM SD_VP_B_H vp " + + "LEFT JOIN SD_ENGINFO_B_H eng ON eng.STCD = vp.RSTCD AND NVL(eng.IS_DELETED, 0) = 0 " + + "LEFT JOIN SD_HYDROBASE hb ON hb.BASEID = vp.BASE_ID AND NVL(hb.IS_DELETED, 0) = 0 " + + "LEFT JOIN SD_STTP_B sttp ON sttp.STTP_CODE = vp.STTP " + + " AND NVL(sttp.IS_DELETED, 0) = 0 AND NVL(sttp.ENABLE, 1) = 1 " + + "WHERE NVL(vp.IS_DELETED, 0) = 0"; + } + + private String buildVmsstbprptFilterCondition(DataSourceRequest.FilterDescriptor filter, + Map paramMap, + int[] indexHolder) { + if (filter == null) { + return ""; + } + if (StrUtil.isNotBlank(filter.getField())) { + return buildVmsstbprptLeafCondition(filter, paramMap, indexHolder); + } + if (CollectionUtils.isEmpty(filter.getFilters())) { + return ""; + } + List conditions = new ArrayList<>(); + for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) { + String childSql = buildVmsstbprptFilterCondition(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 buildVmsstbprptLeafCondition(DataSourceRequest.FilterDescriptor filter, + Map paramMap, + int[] indexHolder) { + String column = mapVmsstbprptColumn(filter.getField()); + if (StrUtil.isBlank(column)) { + return ""; + } + String operator = StrUtil.blankToDefault(filter.getOperator(), "eq").toLowerCase(); + Object value = filter.getValue(); + if ("isnull".equals(operator)) { + return column + " IS NULL"; + } + if ("isnotnull".equals(operator)) { + return column + " IS NOT NULL"; + } + if ("in".equals(operator)) { + List values = normalizeValues(value); + if (values.isEmpty()) { + return ""; + } + List placeholders = new ArrayList<>(); + for (Object item : values) { + String key = "vpMsParam" + indexHolder[0]++; + paramMap.put(key, item); + placeholders.add("#{map." + key + "}"); + } + return column + " IN (" + String.join(", ", placeholders) + ")"; + } + if (value == null) { + return ""; + } + String key = "vpMsParam" + indexHolder[0]++; + return switch (operator) { + case "eq" -> { + paramMap.put(key, value); + yield column + " = #{map." + key + "}"; + } + case "neq" -> { + paramMap.put(key, value); + yield column + " <> #{map." + key + "}"; + } + case "contains" -> { + paramMap.put(key, "%" + value + "%"); + yield column + " LIKE #{map." + key + "}"; + } + case "startswith" -> { + paramMap.put(key, value + "%"); + yield column + " LIKE #{map." + key + "}"; + } + case "endswith" -> { + paramMap.put(key, "%" + value); + yield column + " LIKE #{map." + key + "}"; + } + case "gt" -> { + paramMap.put(key, value); + yield column + " > #{map." + key + "}"; + } + case "gte" -> { + paramMap.put(key, value); + yield column + " >= #{map." + key + "}"; + } + case "lt" -> { + paramMap.put(key, value); + yield column + " < #{map." + key + "}"; + } + case "lte" -> { + paramMap.put(key, value); + yield column + " <= #{map." + key + "}"; + } + default -> ""; + }; + } + + private String mapVmsstbprptColumn(String field) { + if (StrUtil.isBlank(field)) { + return null; + } + Map columnMap = new HashMap<>(); + columnMap.put("stcd", "vp.STCD"); + columnMap.put("stnm", "vp.STNM"); + columnMap.put("sttp", "vp.STTP"); + columnMap.put("sttpCode", "vp.STTP"); + columnMap.put("sttpName", "sttp.STTP_NAME"); + columnMap.put("baseId", "vp.BASE_ID"); + columnMap.put("baseName", "hb.BASENAME"); + columnMap.put("rstcd", "vp.RSTCD"); + columnMap.put("ennm", "eng.ENNM"); + columnMap.put("hbrvcd", "vp.HBRVCD"); + columnMap.put("rvcd", "eng.REACHCD"); + columnMap.put("dtin", "vp.DTIN"); + columnMap.put("bldstt", "vp.BLPRD"); + columnMap.put("bldsttCcode", "vp.BLDSTT_CODE"); + return columnMap.get(field); + } + + private String buildVmsstbprptGroupSql(String detailSql, GroupingInfo[] groupInfos) { + List groupFields = new ArrayList<>(); + List orderItems = new ArrayList<>(); + StringBuilder sql = new StringBuilder("SELECT "); + boolean first = true; + for (GroupingInfo item : groupInfos) { + if (item == null || StrUtil.isBlank(item.getSelector())) { + continue; + } + String selector = item.getSelector(); + if (!isVmsstbprptGroupSupported(selector)) { + continue; + } + if (!first) { + sql.append(", "); + } + sql.append("t.").append(selector).append(" AS ").append(selector); + sql.append(", COUNT(*) AS count_").append(selector); + groupFields.add("t." + selector); + orderItems.add("t." + selector + ("desc".equalsIgnoreCase(item.getDesc() ? "desc" : "asc") ? " DESC" : " ASC")); + first = false; + } + if (groupFields.isEmpty()) { + return "SELECT * FROM (" + detailSql + ") t WHERE 1 = 0"; + } + sql.append(" FROM (").append(detailSql).append(") t GROUP BY ") + .append(String.join(", ", groupFields)); + if (!orderItems.isEmpty()) { + sql.append(" ORDER BY ").append(String.join(", ", orderItems)); + } + return sql.toString(); + } + + private boolean isVmsstbprptGroupSupported(String selector) { + return "stcd".equals(selector) + || "stnm".equals(selector) + || "sttpCode".equals(selector) + || "sttpName".equals(selector) + || "baseId".equals(selector) + || "baseName".equals(selector) + || "rstcd".equals(selector) + || "ennm".equals(selector) + || "dtin".equals(selector) + || "bldstt".equals(selector) + || "bldsttCcode".equals(selector); + } + + private String buildVmsstbprptOrderBySql(List sorts) { + if (sorts == null || sorts.isEmpty()) { + return " ORDER BY NVL(eng.ORDER_INDEX, 999999) ASC, NVL(eng.ORDER_INDEX, 999999) ASC, " + + "NVL(vp.ORDER_INDEX, 999999) ASC, vp.STCD ASC"; + } + Map sortMap = new HashMap<>(); + sortMap.put("stcd", "vp.STCD"); + sortMap.put("stnm", "vp.STNM"); + sortMap.put("sttp", "vp.STTP"); + sortMap.put("sttpCode", "vp.STTP"); + sortMap.put("sttpName", "sttp.STTP_NAME"); + sortMap.put("baseId", "vp.BASE_ID"); + sortMap.put("baseName", "hb.BASENAME"); + sortMap.put("rstcd", "vp.RSTCD"); + sortMap.put("ennm", "eng.ENNM"); + sortMap.put("dtin", "vp.DTIN"); + sortMap.put("bldstt", "vp.BLPRD"); + sortMap.put("bldsttCcode", "vp.BLDSTT_CODE"); + sortMap.put("rvcdStepSort", "eng.ORDER_INDEX"); + sortMap.put("rstcdStepSort", "eng.ORDER_INDEX"); + sortMap.put("siteStepSort", "vp.ORDER_INDEX"); + sortMap.put("baseStepSort", "hb.ORDER_INDEX"); + + List orderItems = new ArrayList<>(); + for (DataSourceRequest.SortDescriptor sort : sorts) { + if (sort == null || StrUtil.isBlank(sort.getField())) { + continue; + } + String column = sortMap.get(sort.getField()); + if (StrUtil.isBlank(column)) { + continue; + } + String direction = "desc".equalsIgnoreCase(sort.getDir()) ? "DESC" : "ASC"; + orderItems.add(column + " " + direction); + } + if (orderItems.isEmpty()) { + return " ORDER BY NVL(eng.ORDER_INDEX, 999999) ASC, NVL(eng.ORDER_INDEX, 999999) ASC, " + + "NVL(vp.ORDER_INDEX, 999999) ASC, vp.STCD ASC"; + } + return " ORDER BY " + String.join(", ", orderItems); + } }