From 2b439dd73d3fa2d3cf3c579e8c1d48e3f80f433f Mon Sep 17 00:00:00 2001 From: tangwei Date: Thu, 30 Jul 2026 10:43:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=B2=E9=B1=BC=E5=9F=B9=E8=82=B2?= =?UTF-8?q?=E6=B0=B4=E8=B4=A8=E7=9B=91=E6=B5=8B=E8=AE=B0=E5=BD=95=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fb/controller/FbStationController.java | 6 + .../qgc_env/fb/service/FbStationService.java | 6 + .../fb/service/impl/FbStationServiceImpl.java | 249 ++++++++++++++++++ 3 files changed, 261 insertions(+) diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/controller/FbStationController.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/controller/FbStationController.java index 2ffedbe5..892b510f 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/fb/controller/FbStationController.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/controller/FbStationController.java @@ -89,6 +89,12 @@ public class FbStationController { return ResponseResult.successData(fbStationService.getFbbwtRList(dataSourceRequest)); } + @PostMapping("/fbcwqr/GetKendoListCust") + @Operation(summary = "亲鱼培育水质监测记录列表") + public ResponseResult getFbcwqRKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) { + return ResponseResult.successData(fbStationService.getFbcwqRList(dataSourceRequest)); + } + @PostMapping("/bsmfr/qgc/GetKendoListCust") @Operation(summary = "(全过程)增殖站二级页面: 亲鱼选配与培育->亲鱼信息") public ResponseResult getBsmfrQgcKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) { diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java index 8b09efd8..c87c961a 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/FbStationService.java @@ -7,6 +7,7 @@ import com.yfd.platform.qgc_env.fb.entity.vo.FbBsmfRVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsdeathRVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsctmoBVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbFbbwtRVo; +import com.yfd.platform.qgc_env.fb.entity.vo.FbFbcwqRVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsmfRQgcVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsmfRFishTableVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbEngFishVo; @@ -108,4 +109,9 @@ public interface FbStationService { * 亲鱼培育水温观测记录列表 */ DataSourceResult getFbbwtRList(DataSourceRequest dataSourceRequest); + + /** + * 亲鱼培育水质监测记录列表 + */ + DataSourceResult getFbcwqRList(DataSourceRequest dataSourceRequest); } diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java index 9dbc896e..a6fd7a29 100644 --- a/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/service/impl/FbStationServiceImpl.java @@ -16,6 +16,7 @@ import com.yfd.platform.qgc_env.fb.entity.vo.FbBsmfRVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsdeathRVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsctmoBVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbFbbwtRVo; +import com.yfd.platform.qgc_env.fb.entity.vo.FbFbcwqRVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsmfRQgcVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsmfRFishHeadColumnVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbBsmfRFishSummaryVo; @@ -6327,4 +6328,252 @@ public class FbStationServiceImpl implements FbStationService { } return value; } + + // ==================== 亲鱼培育水质监测记录列表 ==================== + + @Override + public DataSourceResult getFbcwqRList(DataSourceRequest dataSourceRequest) { + DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest(); + GroupingInfo[] groups = loadOptions == null ? null : loadOptions.getGroup(); + if (groups != null && groups.length > 0) { + return queryFbcwqRGroupList(dataSourceRequest, loadOptions, groups); + } + return queryFbcwqRDetailList(dataSourceRequest, loadOptions); + } + + private DataSourceResult queryFbcwqRDetailList(DataSourceRequest dataSourceRequest, + DataSourceLoadOptionsBase loadOptions) { + Map paramMap = new HashMap<>(); + StringBuilder sql = new StringBuilder(); + sql.append("SELECT ") + .append(buildFbcwqRDetailSelectSql(dataSourceRequest == null ? null : dataSourceRequest.getSelect())) + .append(" FROM (") + .append(buildFbcwqRCoreSql()) + .append(") t WHERE 1 = 1 "); + String filterSql = buildFbcwqRFilterCondition( + dataSourceRequest == null ? null : dataSourceRequest.getFilter(), + paramMap, new int[]{0}); + if (StrUtil.isNotBlank(filterSql)) { + sql.append(" AND ").append(filterSql).append(" "); + } + sql.append(buildFbcwqROrderBySql(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, FbFbcwqRVo.class); + DataSourceResult result = new DataSourceResult<>(); + result.setData(list); + result.setTotal(page != null ? page.getTotal() : list.size()); + result.setAggregates(new HashMap<>()); + return result; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + private DataSourceResult queryFbcwqRGroupList(DataSourceRequest dataSourceRequest, + DataSourceLoadOptionsBase loadOptions, + GroupingInfo[] groupInfos) { + Map paramMap = new HashMap<>(); + StringBuilder sql = new StringBuilder(); + sql.append("SELECT * FROM (") + .append(buildFbcwqRCoreSql()) + .append(") t WHERE 1 = 1 "); + String filterSql = buildFbcwqRFilterCondition( + dataSourceRequest == null ? null : dataSourceRequest.getFilter(), + paramMap, new int[]{0}); + if (StrUtil.isNotBlank(filterSql)) { + sql.append(" AND ").append(filterSql).append(" "); + } + String groupedSql = buildFbcwqRGroupSql(sql.toString(), + dataSourceRequest == null ? null : dataSourceRequest.getGroup()); + List> rows = microservicDynamicSQLMapper.pageAllList( + null, groupedSql, paramMap); + DataSourceResult result = new DataSourceResult<>(); + if (Boolean.TRUE.equals(dataSourceRequest == null ? false : dataSourceRequest.getGroupResultFlat())) { + result.setData((List) (List) new GroupHelper().faltGroup( + rows, groupInfos == null ? Collections.emptyList() : Arrays.asList(groupInfos))); + } else { + result.setData((List) (List) new GroupHelper().group( + rows, groupInfos == null ? Collections.emptyList() : Arrays.asList(groupInfos))); + } + result.setTotal(rows.size()); + result.setAggregates(new HashMap<>()); + return result; + } + + private String buildFbcwqRCoreSql() { + return "SELECT a.ID AS id, " + + "a.STCD AS stcd, " + + "a.FPNUM AS fpnum, " + + "b.NAME AS fpName, " + + "a.NH3N AS nh3n, " + + "a.NO2 AS no2, " + + "a.DOX AS dox, " + + "a.PH AS ph, " + + "a.RECORDER AS recorder, " + + "a.IFFIT AS iffit, " + + "a.TM AS tm, " + + "a.FID AS fid, " + + "a.RECORD_USER AS recordUser, " + + "a.RECORD_TIME AS recordTime, " + + "a.MODIFY_USER AS modifyUser, " + + "a.MODIFY_TIME AS modifyTime, " + + "a.IS_DELETED AS isDeleted, " + + "a.DELETE_USER AS deleteUser, " + + "a.DELETE_TIME AS deleteTime " + + "FROM SD_FBCWQ_R a " + + "LEFT JOIN SD_FBFISHPOND_B b ON a.FPNUM = b.ID AND NVL(b.IS_DELETED, 0) = 0"; + } + + private String buildFbcwqRDetailSelectSql(List select) { + List fields = CollUtil.isEmpty(select) + ? List.of("id", "stcd", "fpnum", "fpName", "nh3n", "no2", "dox", "ph", + "recorder", "iffit", "tm", "fid", "recordUser", "recordTime", "modifyUser", "modifyTime", + "isDeleted", "deleteUser", "deleteTime") + : select; + List selectParts = new ArrayList<>(); + for (String field : fields) { + String column = mapFbcwqRColumn(field); + if (StrUtil.isNotBlank(column)) { + selectParts.add(column + " AS " + field); + } + } + if (selectParts.isEmpty()) { + selectParts.add("t.id AS id"); + } + return String.join(", ", selectParts); + } + + private String buildFbcwqRFilterCondition(DataSourceRequest.FilterDescriptor filter, + Map paramMap, + int[] indexHolder) { + if (filter == null) return ""; + if (StrUtil.isNotBlank(filter.getField())) return buildFbcwqRLeafCondition(filter, paramMap, indexHolder); + if (CollUtil.isEmpty(filter.getFilters())) return ""; + List conditions = new ArrayList<>(); + for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) { + String childSql = buildFbcwqRFilterCondition(child, paramMap, indexHolder); + if (StrUtil.isNotBlank(childSql)) conditions.add("(" + childSql + ")"); + } + if (conditions.isEmpty()) return ""; + return String.join("or".equalsIgnoreCase(filter.getLogic()) ? " OR " : " AND ", conditions); + } + + private String buildFbcwqRLeafCondition(DataSourceRequest.FilterDescriptor filter, + Map paramMap, + int[] indexHolder) { + String column = mapFbcwqRColumn(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 = normalizeFbcwqRValues(value); + if (values.isEmpty()) return ""; + List placeholders = new ArrayList<>(); + for (Object item : values) { + String key = "cwqP" + indexHolder[0]++; + paramMap.put(key, normalizeFbcwqRValue(filter.getField(), item)); + placeholders.add("#{map." + key + "}"); + } + return column + " IN (" + String.join(", ", placeholders) + ")"; + } + if (value == null) return ""; + String key = "cwqP" + indexHolder[0]++; + Object normalizedValue = normalizeFbcwqRValue(filter.getField(), value); + return switch (operator) { + case "eq" -> { paramMap.put(key, normalizedValue); yield column + " = #{map." + key + "}"; } + case "neq" -> { paramMap.put(key, normalizedValue); yield column + " <> #{map." + key + "}"; } + case "gt" -> { paramMap.put(key, normalizedValue); yield column + " > #{map." + key + "}"; } + case "gte" -> { paramMap.put(key, normalizedValue); yield column + " >= #{map." + key + "}"; } + case "lt" -> { paramMap.put(key, normalizedValue); yield column + " < #{map." + key + "}"; } + case "lte" -> { paramMap.put(key, normalizedValue); yield column + " <= #{map." + key + "}"; } + case "contains" -> { paramMap.put(key, "%" + normalizedValue + "%"); yield column + " LIKE #{map." + key + "}"; } + case "doesnotcontain" -> { paramMap.put(key, "%" + normalizedValue + "%"); yield column + " NOT LIKE #{map." + key + "}"; } + case "startswith" -> { paramMap.put(key, normalizedValue + "%"); yield column + " LIKE #{map." + key + "}"; } + case "endswith" -> { paramMap.put(key, "%" + normalizedValue); yield column + " LIKE #{map." + key + "}"; } + default -> ""; + }; + } + + private String buildFbcwqROrderBySql(List sortDescriptors) { + if (CollUtil.isEmpty(sortDescriptors)) return " ORDER BY t.tm DESC"; + List parts = new ArrayList<>(); + for (DataSourceRequest.SortDescriptor descriptor : sortDescriptors) { + String column = mapFbcwqRColumn(descriptor.getField()); + if (StrUtil.isBlank(column)) continue; + parts.add(column + ("desc".equalsIgnoreCase(descriptor.getDir()) ? " DESC" : " ASC")); + } + if (parts.isEmpty()) return " ORDER BY t.tm DESC"; + return " ORDER BY " + String.join(", ", parts); + } + + private String buildFbcwqRGroupSql(String baseSql, List groups) { + if (CollUtil.isEmpty(groups)) return baseSql; + List validGroups = groups.stream() + .filter(group -> StrUtil.isNotBlank(mapFbcwqRColumn(group.getField()))).toList(); + if (validGroups.isEmpty()) return baseSql; + List groupFields = validGroups.stream().map(DataSourceRequest.GroupDescriptor::getField).toList(); + StringBuilder sql = new StringBuilder("SELECT "); + for (int i = 0; i < groupFields.size(); i++) { + if (i > 0) sql.append(", "); + sql.append("t.").append(groupFields.get(i)).append(" AS ").append(groupFields.get(i)); + } + sql.append(", COUNT(1) AS \"aggregates.count\" FROM (").append(baseSql).append(") t GROUP BY "); + for (int i = 0; i < groupFields.size(); i++) { + if (i > 0) sql.append(", "); + sql.append("t.").append(groupFields.get(i)); + } + return sql.toString(); + } + + private String mapFbcwqRColumn(String field) { + return switch (field) { + case "id" -> "t.id"; + case "stcd" -> "t.stcd"; + case "fpnum" -> "t.fpnum"; + case "fpName" -> "t.fpName"; + case "nh3n" -> "t.nh3n"; + case "no2" -> "t.no2"; + case "dox" -> "t.dox"; + case "ph" -> "t.ph"; + case "recorder" -> "t.recorder"; + case "iffit" -> "t.iffit"; + case "tm" -> "t.tm"; + case "fid" -> "t.fid"; + case "recordUser" -> "t.recordUser"; + case "recordTime" -> "t.recordTime"; + case "modifyUser" -> "t.modifyUser"; + case "modifyTime" -> "t.modifyTime"; + case "isDeleted" -> "t.isDeleted"; + case "deleteUser" -> "t.deleteUser"; + case "deleteTime" -> "t.deleteTime"; + default -> ""; + }; + } + + private List normalizeFbcwqRValues(Object value) { + List values = new ArrayList<>(); + if (value == null) return values; + if (value instanceof Collection collection) { values.addAll(collection); return values; } + if (value instanceof Object[] array) { values.addAll(Arrays.asList(array)); return values; } + String text = String.valueOf(value).trim(); + if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length() - 1); + if (text.contains(",")) { + for (String item : text.split(",")) { + String trimmed = StrUtil.trim(item); + if (StrUtil.isNotBlank(trimmed)) values.add(trimmed); + } + return values; + } + values.add(value); + return values; + } + + private Object normalizeFbcwqRValue(String field, Object value) { + if (value == null) return null; + if (Set.of("tm", "recordTime", "modifyTime", "deleteTime").contains(field) && value instanceof String text) { + return parseDateTimeSafely(text); + } + return value; + } }