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 6b12aa0f..b623c33d 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 @@ -42,6 +42,12 @@ public class FbStationController { return ResponseResult.successData(fbStationService.getOverviewKendoListCust(dataSourceRequest)); } + @PostMapping("/qgc/getFbStaticsData") + @Operation(summary = "增殖站放流数据统计") + public ResponseResult getQgcFbStaticsData(@RequestBody DataSourceRequest dataSourceRequest) { + return ResponseResult.successData(fbStationService.getQgcFbStaticsData(dataSourceRequest)); + } + @GetMapping("/rpimnr/qgc/year/GetYearRpStatistics") @Operation(summary = "全过程放流统计总数,根据基地流域分组") public ResponseResult getYearRpStatistics(@Parameter(description = "年份") @RequestParam("year") String year) { diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbStationStaticsDataVo.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbStationStaticsDataVo.java new file mode 100644 index 00000000..d95d7f63 --- /dev/null +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbStationStaticsDataVo.java @@ -0,0 +1,35 @@ +package com.yfd.platform.qgc_env.fb.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Data +@Schema(description = "增殖站放流统计结果") +public class FbStationStaticsDataVo { + + @Schema(description = "流域编码") + private String hbrvcd; + + @Schema(description = "流域名称") + private String hbrvcdName; + + @Schema(description = "基地编码") + private String baseId; + + @Schema(description = "基地名称") + private String baseName; + + @Schema(description = "鱼类种数") + private Integer ftp; + + @Schema(description = "放流数量") + private Long fcnt; + + @Schema(description = "增殖站数量") + private Integer stcdCnt; + + @Schema(description = "增殖站编码列表") + private List stcdList; +} diff --git a/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbStationStaticsRawVo.java b/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbStationStaticsRawVo.java new file mode 100644 index 00000000..4526cfa4 --- /dev/null +++ b/backend/src/main/java/com/yfd/platform/qgc_env/fb/entity/vo/FbStationStaticsRawVo.java @@ -0,0 +1,36 @@ +package com.yfd.platform.qgc_env.fb.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "增殖站放流统计明细") +public class FbStationStaticsRawVo { + + @Schema(description = "流域编码") + private String hbrvcd; + + @Schema(description = "流域名称") + private String hbrvcdName; + + @Schema(description = "基地编码") + private String baseId; + + @Schema(description = "基地名称") + private String baseName; + + @Schema(description = "增殖站编码") + private String stcd; + + @Schema(description = "增殖站名称") + private String stnm; + + @Schema(description = "鱼类编码") + private String ftp; + + @Schema(description = "鱼类名称") + private String ftpName; + + @Schema(description = "放流数量") + private Long fcnt; +} 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 e6b79eeb..9a594d62 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 @@ -2,6 +2,7 @@ package com.yfd.platform.qgc_env.fb.service; import com.yfd.platform.common.DataSourceRequest; import com.yfd.platform.common.DataSourceResult; +import com.yfd.platform.qgc_env.fb.entity.vo.FbStationStaticsDataVo; import com.yfd.platform.qgc_env.fb.entity.vo.YearRpStatisticsVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbStationOverviewSecondVo; @@ -13,6 +14,8 @@ public interface FbStationService { DataSourceResult getOverviewKendoListCust(DataSourceRequest dataSourceRequest); + DataSourceResult getQgcFbStaticsData(DataSourceRequest dataSourceRequest); + DataSourceResult getOverviewSecond(DataSourceRequest dataSourceRequest); DataSourceResult getQgcOverviewSecond(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 a9027e60..64da7827 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 @@ -9,6 +9,8 @@ import com.yfd.platform.common.DataSourceResult; import com.yfd.platform.common.MicroservicDynamicSQLMapper; import com.yfd.platform.qgc_env.fb.entity.vo.FbFtpStatisticsVo; import com.yfd.platform.qgc_env.fb.entity.vo.FbStationOverviewSecondVo; +import com.yfd.platform.qgc_env.fb.entity.vo.FbStationStaticsDataVo; +import com.yfd.platform.qgc_env.fb.entity.vo.FbStationStaticsRawVo; import com.yfd.platform.qgc_env.fb.entity.vo.YearRpStatisticsVo; import com.yfd.platform.qgc_env.fb.service.FbStationService; import com.yfd.platform.utils.QgcQueryWrapperUtil; @@ -56,6 +58,79 @@ public class FbStationServiceImpl implements FbStationService { return result; } + @Override + public DataSourceResult getQgcFbStaticsData(DataSourceRequest dataSourceRequest) { + DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest(); + String baseId = loadOptions == null ? null : QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "baseId"); + String startTime = loadOptions == null ? null : QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "startTime"); + String endTime = loadOptions == null ? null : QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "endTime"); + String hbrvcd = loadOptions == null ? null : QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "hbrvcd"); + + Map paramMap = new HashMap<>(); + String sql = buildQgcFbStaticsDataSql( + baseId, + hbrvcd, + parseDateTime(startTime), + parseDateTime(endTime), + paramMap + ); + List rows = microservicDynamicSQLMapper.pageAllListWithResultType( + null, sql, paramMap, FbStationStaticsRawVo.class + ); + + DataSourceResult result = new DataSourceResult<>(); + result.setAggregates(new HashMap<>()); + if (CollUtil.isEmpty(rows)) { + result.setData(Collections.emptyList()); + result.setTotal(0); + return result; + } + + Map> grouped = rows.stream() + .filter(item -> StrUtil.isNotBlank(item.getHbrvcd())) + .collect(Collectors.groupingBy( + FbStationStaticsRawVo::getHbrvcd, + LinkedHashMap::new, + Collectors.toList() + )); + + List data = new ArrayList<>(); + for (Map.Entry> entry : grouped.entrySet()) { + List value = entry.getValue(); + if (CollUtil.isEmpty(value)) { + continue; + } + FbStationStaticsRawVo first = value.get(0); + Set stcdSet = value.stream() + .map(FbStationStaticsRawVo::getStcd) + .filter(StrUtil::isNotBlank) + .collect(Collectors.toCollection(LinkedHashSet::new)); + + FbStationStaticsDataVo vo = new FbStationStaticsDataVo(); + vo.setHbrvcd(entry.getKey()); + vo.setHbrvcdName(first.getHbrvcdName()); + vo.setBaseId(first.getBaseId()); + vo.setBaseName(first.getBaseName()); + vo.setFtp((int) value.stream() + .map(FbStationStaticsRawVo::getFtp) + .filter(StrUtil::isNotBlank) + .distinct() + .count()); + vo.setFcnt(value.stream() + .map(FbStationStaticsRawVo::getFcnt) + .filter(Objects::nonNull) + .mapToLong(Long::longValue) + .sum()); + vo.setStcdList(new ArrayList<>(stcdSet)); + vo.setStcdCnt(stcdSet.size()); + data.add(vo); + } + + result.setData(data); + result.setTotal(data.size()); + return result; + } + @Override public DataSourceResult getOverviewKendoListCust(DataSourceRequest dataSourceRequest) { DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest(); @@ -285,6 +360,13 @@ public class FbStationServiceImpl implements FbStationService { return new BigDecimal(String.valueOf(value)); } + private Date parseDateTime(String value) { + if (StrUtil.isBlank(value)) { + return null; + } + return DateUtil.parse(value.trim(), "yyyy-MM-dd HH:mm:ss"); + } + private String buildYearRpStatisticsSql(String year, Map paramMap) { StringBuilder sql = new StringBuilder(); sql.append("SELECT stat.BASE_ID AS baseId, ") @@ -331,6 +413,60 @@ public class FbStationServiceImpl implements FbStationService { return sql.toString(); } + private String buildQgcFbStaticsDataSql(String baseId, + String hbrvcd, + Date startDate, + Date endDate, + Map paramMap) { + String fishNameExpr = buildFishNameExpr("fish.FTP"); + StringBuilder sql = new StringBuilder(); + sql.append("SELECT fb.HBRVCD AS hbrvcd, ") + .append("NVL(hbrv.HBRVNM, fb.HBRVCD) AS hbrvcdName, ") + .append("fb.BASE_ID AS baseId, ") + .append("hb.BASENAME AS baseName, ") + .append("fb.STCD AS stcd, ") + .append("fb.STNM AS stnm, ") + .append("fish.FTP AS ftp, ") + .append(fishNameExpr).append(" AS ftpName, ") + .append("fish.FCNT AS fcnt ") + .append("FROM SD_ENGFR_R run ") + .append("INNER JOIN SD_RPIMNFISH_R fish ON run.ID = fish.RPIMN_ID ") + .append(" AND NVL(fish.IS_DELETED, 0) = 0 ") + .append(" AND fish.FTP IS NOT NULL ") + .append("INNER JOIN SD_FBRD_B_H fb ON fb.STCD = run.RSTCD ") + .append("LEFT JOIN SD_HYDROBASE hb ON hb.BASEID = fb.BASE_ID ") + .append(" AND NVL(hb.IS_DELETED, 0) = 0 ") + .append(" AND NVL(hb.ENABLED, 1) = 1 ") + .append("LEFT JOIN SD_HBRV_DIC hbrv ON hbrv.HBRVCD = fb.HBRVCD ") + .append(" AND hbrv.BASEID = fb.BASE_ID ") + .append(" AND NVL(hbrv.IS_DELETED, 0) = 0 ") + .append(" AND NVL(hbrv.ENABLED, 1) = 1 ") + .append(buildFishJoinSql("fish.FTP", "fb.HBRVCD")) + .append("WHERE NVL(run.IS_DELETED, 0) = 0 "); + if (StrUtil.isNotBlank(baseId)) { + paramMap.put("fbStaticsBaseId", baseId.trim()); + sql.append("AND fb.BASE_ID = #{map.fbStaticsBaseId} "); + } + if (StrUtil.isNotBlank(hbrvcd)) { + paramMap.put("fbStaticsHbrvcd", hbrvcd.trim()); + sql.append("AND fb.HBRVCD = #{map.fbStaticsHbrvcd} "); + } + if (startDate != null) { + paramMap.put("fbStaticsStartDate", startDate); + sql.append("AND run.TM >= #{map.fbStaticsStartDate} "); + } + if (endDate != null) { + paramMap.put("fbStaticsEndDate", endDate); + sql.append("AND run.TM <= #{map.fbStaticsEndDate} "); + } + sql.append("ORDER BY NVL(hbrv.ORDER_INDEX, 9999), ") + .append("NVL(hb.ORDER_INDEX, 9999), ") + .append("NVL(fb.ORDER_INDEX, 9999), ") + .append("fb.STCD, ") + .append(fishNameExpr); + return sql.toString(); + } + @Override public DataSourceResult getQgcOverviewSecond(DataSourceRequest dataSourceRequest) { DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest();