From 2b0709036cb7d62ef488c1dd3012632fb213f702 Mon Sep 17 00:00:00 2001 From: tangwei Date: Wed, 1 Jul 2026 16:56:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B0=B4=E7=94=9F=E7=94=9F=E6=80=81?= =?UTF-8?q?=E8=B0=83=E6=9F=A5-=E6=B0=B4=E8=B4=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wte/controller/WeFishController.java | 6 + .../qgc_env/wte/entity/vo/WeWqVo.java | 51 ++++ .../qgc_env/wte/service/WeFishService.java | 2 + .../wte/service/impl/WeFishServiceImpl.java | 247 +++++++++++++++++- 4 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/com/yfd/platform/qgc_env/wte/entity/vo/WeWqVo.java diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/wte/controller/WeFishController.java b/backend/src/main/java/com/yfd/platform/qgc_env/wte/controller/WeFishController.java index 4dcbfecd..eb3f9084 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/wte/controller/WeFishController.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/wte/controller/WeFishController.java @@ -173,4 +173,10 @@ public class WeFishController { public ResponseResult getWeWtR(@RequestBody DataSourceRequest dataSourceRequest) { return ResponseResult.successData(weFishService.getWeWtR(dataSourceRequest)); } + + @PostMapping("/we/wewqr/GetKendoListCust") + @Operation(summary = "水生生态调查-水质数据列表") + public ResponseResult getWeWqR(@RequestBody DataSourceRequest dataSourceRequest) { + return ResponseResult.successData(weFishService.getWeWqR(dataSourceRequest)); + } } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/wte/entity/vo/WeWqVo.java b/backend/src/main/java/com/yfd/platform/qgc_env/wte/entity/vo/WeWqVo.java new file mode 100644 index 00000000..6600e9c2 --- /dev/null +++ b/backend/src/main/java/com/yfd/platform/qgc_env/wte/entity/vo/WeWqVo.java @@ -0,0 +1,51 @@ +package com.yfd.platform.qgc_env.wte.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class WeWqVo { + private String stcd; + private String dcpc; + private String name; + private Date tm; + private BigDecimal ph; + private BigDecimal dox; + private BigDecimal codmn; + private BigDecimal codcr; + private BigDecimal bod5; + private BigDecimal nh3n; + private BigDecimal tp; + private BigDecimal tn; + private BigDecimal cu; + private BigDecimal zn; + private BigDecimal f; + private BigDecimal se; + private BigDecimal ars; + private BigDecimal hg; + private BigDecimal cd; + private BigDecimal cr6; + private BigDecimal pb; + private BigDecimal cn; + private BigDecimal vlph; + private BigDecimal oil; + private BigDecimal las; + private BigDecimal s2; + private BigDecimal fcg; + private BigDecimal cl; + private BigDecimal so4; + private BigDecimal no3; + private BigDecimal thrd; + private BigDecimal cond; + private BigDecimal fe; + private BigDecimal mn; + private BigDecimal al; + private BigDecimal chla; + private BigDecimal clarity; + private BigDecimal tu; + private BigDecimal cyano; + private String fid; + private Integer parameter; +} \ No newline at end of file diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/WeFishService.java b/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/WeFishService.java index bbedae64..554ff54f 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/WeFishService.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/WeFishService.java @@ -60,4 +60,6 @@ public interface WeFishService { DataSourceResult getWeYr(String stcd); DataSourceResult getWeWtR(DataSourceRequest dataSourceRequest); + + DataSourceResult getWeWqR(DataSourceRequest dataSourceRequest); } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/impl/WeFishServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/impl/WeFishServiceImpl.java index 89db2a0f..ec0c1ed3 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/impl/WeFishServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/wte/service/impl/WeFishServiceImpl.java @@ -1186,7 +1186,7 @@ public class WeFishServiceImpl implements WeFishService { StringBuilder sql = new StringBuilder(); sql.append("SELECT t.DCPC, t.STCD, t1.WT AS wt, t.TM FROM SD_WE_R t ") .append("INNER JOIN SD_WEWT_R t1 ON t.ID = t1.WER_ID ") - .append("WHERE NVL(t.IS_DELETED, 0) = 0 AND NVL(t.STATUS, 1) = 1 AND NVL(t1.IS_DELETED, 0) = 0 "); + .append("WHERE NVL(t.IS_DELETED, 0) = 0 AND NVL(t1.IS_DELETED, 0) = 0 "); String filterSql = buildWeWtFilterCondition( dataSourceRequest == null ? null : dataSourceRequest.getFilter(), @@ -1379,6 +1379,251 @@ public class WeFishServiceImpl implements WeFishService { return " ORDER BY " + String.join(", ", orderByParts); } + @Override + public DataSourceResult getWeWqR(DataSourceRequest dataSourceRequest) { + DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest(); + GroupingInfo[] groupInfos = loadOptions == null ? null : loadOptions.getGroup(); + Map paramMap = new HashMap<>(); + + StringBuilder sql = new StringBuilder(); + sql.append("SELECT t.DCPC, t.STCD, t1.TM, t1.NAME, t1.PH, t1.DOX, t1.CODMN, t1.CODCR, t1.BOD5, t1.NH3N ") + .append(", t1.TP, t1.TN, t1.CU, t1.ZN, t1.F, t1.SE, t1.ARS, t1.HG, t1.CD, t1.CR6, t1.PB, t1.CN, t1.VLPH, t1.OIL ") + .append(", t1.LAS, t1.S2, t1.FCG, t1.CL, t1.SO4, t1.NO3, t1.THRD, t1.COND, t1.FE, t1.MN, t1.AL, t1.CHLA ") + .append(", t1.CLARITY, t1.TU, t1.CYANO, t1.FID, t1.PARAMETER ") + .append("FROM SD_WE_R t ") + .append("INNER JOIN SD_WEWQ_R t1 ON t.ID = t1.WER_ID ") + .append("WHERE NVL(t.IS_DELETED, 0) = 0 AND NVL(t1.IS_DELETED, 0) = 0 "); + + String filterSql = buildWeWqFilterCondition( + dataSourceRequest == null ? null : dataSourceRequest.getFilter(), + paramMap, + new int[]{0} + ); + if (StrUtil.isNotBlank(filterSql)) { + sql.append("AND ").append(filterSql).append(" "); + } + + DataSourceResult result = new DataSourceResult<>(); + if (CollUtil.isNotEmpty(dataSourceRequest == null ? null : dataSourceRequest.getGroup())) { + String groupBy = KendoUtil.getGroupBy(dataSourceRequest); + if (StrUtil.isNotBlank(groupBy)) { + List groupFields = new ArrayList<>(); + for (GroupingInfo item : groupInfos) { + if (item != null && StrUtil.isNotBlank(item.getSelector())) { + groupFields.add(item.getSelector()); + } + } + StringBuilder temp = new StringBuilder(); + temp.append("SELECT ").append(String.join(",", groupFields)).append(", count(*) as "); + if (groupInfos.length > 1) { + temp.append("count"); + } else { + temp.append("count_").append(String.join("_", groupFields)); + } + String groupedSql = temp.append(" FROM ( ").append(sql).append(" ) ").append(groupBy).toString(); + List> rows = microservicDynamicSQLMapper.getAllList(groupedSql, paramMap); + if (Boolean.TRUE.equals(dataSourceRequest.getGroupResultFlat())) { + result.setData((List) (List) new GroupHelper().faltGroup(rows, Arrays.asList(groupInfos))); + } else { + result.setData((List) (List) new GroupHelper().group(rows, Arrays.asList(groupInfos))); + } + result.setTotal((long) rows.size()); + result.setAggregates(new HashMap<>()); + return result; + } + } + + sql.append(buildWeWqOrderBySql(dataSourceRequest == null ? null : dataSourceRequest.getSort())); + + Page page = loadOptions == null ? null + : QgcQueryWrapperUtil.buildPage(loadOptions, loadOptions.getSkip(), loadOptions.getTake()); + List list = microservicDynamicSQLMapper.pageAllListWithResultType(page, sql.toString(), paramMap, WeWqVo.class); + + result.setData(list); + result.setTotal(page != null ? page.getTotal() : list.size()); + result.setAggregates(new HashMap<>()); + return result; + } + + private String buildWeWqFilterCondition(DataSourceRequest.FilterDescriptor filter, + Map paramMap, + int[] indexHolder) { + if (filter == null) { + return ""; + } + List conditions = new ArrayList<>(); + List filters = filter.getFilters(); + if (CollUtil.isNotEmpty(filters)) { + for (DataSourceRequest.FilterDescriptor child : filters) { + String condition = buildWeWqFilterCondition(child, paramMap, indexHolder); + if (StrUtil.isNotBlank(condition)) { + conditions.add(condition); + } + } + } else { + String leafCondition = buildWeWqLeafCondition(filter, paramMap, indexHolder); + if (StrUtil.isNotBlank(leafCondition)) { + conditions.add(leafCondition); + } + } + if (conditions.isEmpty()) { + return ""; + } + String logic = "or".equalsIgnoreCase(filter.getLogic()) ? " OR " : " AND "; + return "(" + String.join(logic, conditions) + ")"; + } + + private String buildWeWqLeafCondition(DataSourceRequest.FilterDescriptor filter, + Map paramMap, + int[] indexHolder) { + String column = mapWeWqColumn(filter.getField()); + if (StrUtil.isBlank(column)) { + return ""; + } + String operator = StrUtil.blankToDefault(filter.getOperator(), "eq").toLowerCase(); + if ("isnull".equals(operator)) { + return column + " IS NULL"; + } + if ("isnotnull".equals(operator)) { + return column + " IS NOT NULL"; + } + if ("isempty".equals(operator)) { + return "(" + column + " IS NULL OR " + column + " = '')"; + } + if ("isnotempty".equals(operator)) { + return "(" + column + " IS NOT NULL AND " + column + " <> '')"; + } + if ("in".equals(operator) || "ni".equals(operator)) { + List values = normalizeWeFishQgcValues(filter.getValue()); + if (values.isEmpty()) { + return ""; + } + List placeholders = new ArrayList<>(); + boolean isDateField = "t1.tm".equals(column); + for (Object value : values) { + String paramKey = "weWqParam" + indexHolder[0]++; + paramMap.put(paramKey, value); + if (isDateField) { + String text = String.valueOf(value).trim(); + if (text.length() <= 10) { + placeholders.add("TO_DATE(#{map." + paramKey + "}, 'YYYY-MM-DD')"); + } else { + placeholders.add("TO_DATE(#{map." + paramKey + "}, 'YYYY-MM-DD HH24:MI:SS')"); + } + } else { + placeholders.add("#{map." + paramKey + "}"); + } + } + String prefix = "ni".equals(operator) ? "NOT " : ""; + return column + " " + prefix + "IN (" + String.join(", ", placeholders) + ")"; + } + String paramKey = "weWqParam" + indexHolder[0]++; + paramMap.put(paramKey, filter.getValue()); + boolean isDateField = "t1.tm".equals(column); + String valueExpr; + if (isDateField) { + String text = String.valueOf(filter.getValue()).trim(); + if (text.length() <= 10) { + valueExpr = "TO_DATE(#{map." + paramKey + "}, 'YYYY-MM-DD')"; + } else { + valueExpr = "TO_DATE(#{map." + paramKey + "}, 'YYYY-MM-DD HH24:MI:SS')"; + } + } else { + valueExpr = "#{map." + paramKey + "}"; + } + return switch (operator) { + case "lt", "lessthan" -> column + " < " + valueExpr; + case "lte", "lessthanorequals" -> column + " <= " + valueExpr; + case "gt", "greaterthan" -> column + " > " + valueExpr; + case "gte", "greaterthanorequals" -> column + " >= " + valueExpr; + case "ne", "notequals" -> column + " <> " + valueExpr; + case "contains", "doesnotcontain", "startswith", "endswith" -> { + String pattern = switch (operator) { + case "contains" -> "%#{map." + paramKey + "}%"; + case "doesnotcontain" -> "%#{map." + paramKey + "}%"; + case "startswith" -> "#{map." + paramKey + "}%"; + case "endswith" -> "%#{map." + paramKey + "}"; + default -> "%#{map." + paramKey + "}%"; + }; + String likePrefix = "doesnotcontain".equals(operator) ? "NOT " : ""; + yield column + " " + likePrefix + "LIKE " + pattern; + } + default -> column + " = " + valueExpr; + }; + } + + private String mapWeWqColumn(String field) { + if (StrUtil.isBlank(field)) { + return null; + } + return switch (field.toLowerCase()) { + case "dcpc" -> "t.dcpc"; + case "stcd" -> "t.stcd"; + case "name" -> "t1.name"; + case "tm" -> "t1.tm"; + case "ph" -> "t1.ph"; + case "dox" -> "t1.dox"; + case "codmn" -> "t1.codmn"; + case "codcr" -> "t1.codcr"; + case "bod5" -> "t1.bod5"; + case "nh3n" -> "t1.nh3n"; + case "tp" -> "t1.tp"; + case "tn" -> "t1.tn"; + case "cu" -> "t1.cu"; + case "zn" -> "t1.zn"; + case "f" -> "t1.f"; + case "se" -> "t1.se"; + case "ars" -> "t1.ars"; + case "hg" -> "t1.hg"; + case "cd" -> "t1.cd"; + case "cr6" -> "t1.cr6"; + case "pb" -> "t1.pb"; + case "cn" -> "t1.cn"; + case "vlph" -> "t1.vlph"; + case "oil" -> "t1.oil"; + case "las" -> "t1.las"; + case "s2" -> "t1.s2"; + case "fcg" -> "t1.fcg"; + case "cl" -> "t1.cl"; + case "so4" -> "t1.so4"; + case "no3" -> "t1.no3"; + case "thrd" -> "t1.thrd"; + case "cond" -> "t1.cond"; + case "fe" -> "t1.fe"; + case "mn" -> "t1.mn"; + case "al" -> "t1.al"; + case "chla" -> "t1.chla"; + case "clarity" -> "t1.clarity"; + case "tu" -> "t1.tu"; + case "cyano" -> "t1.cyano"; + case "fid" -> "t1.fid"; + case "parameter" -> "t1.parameter"; + default -> null; + }; + } + + private String buildWeWqOrderBySql(List sorts) { + if (CollUtil.isEmpty(sorts)) { + return " ORDER BY t1.tm DESC NULLS LAST, t.stcd ASC"; + } + List orderByParts = new ArrayList<>(); + for (DataSourceRequest.SortDescriptor sort : sorts) { + if (sort == null || StrUtil.isBlank(sort.getField())) { + continue; + } + String column = mapWeWqColumn(sort.getField()); + if (StrUtil.isBlank(column)) { + continue; + } + String direction = "desc".equalsIgnoreCase(sort.getDir()) ? "DESC" : "ASC"; + orderByParts.add(column + " " + direction + " NULLS LAST"); + } + if (orderByParts.isEmpty()) { + return " ORDER BY t1.tm DESC NULLS LAST, t.stcd ASC"; + } + return " ORDER BY " + String.join(", ", orderByParts); + } + private String buildWeFishQgcGroupSql(String baseSql, GroupingInfo[] groupInfos) { if (groupInfos == null || groupInfos.length == 0) { return baseSql;