feat: 全流域增殖站概况

This commit is contained in:
tangwei 2026-06-15 18:16:26 +08:00
parent 95e6a5271b
commit 6f81e82002
3 changed files with 223 additions and 2 deletions

View File

@ -32,4 +32,10 @@ public class FbStationController {
public ResponseResult getOverviewSecond(@RequestBody DataSourceRequest dataSourceRequest) {
return ResponseResult.successData(fbStationService.getOverviewSecond(dataSourceRequest));
}
@PostMapping("/overview/GetKendoListCust")
@Operation(summary = "全流域增殖站概况")
public ResponseResult getOverviewKendoListCust(@RequestBody DataSourceRequest dataSourceRequest) {
return ResponseResult.successData(fbStationService.getOverviewKendoListCust(dataSourceRequest));
}
}

View File

@ -6,6 +6,8 @@ import com.yfd.platform.qgc_env.fb.entity.vo.FbStationOverviewSecondVo;
public interface FbStationService {
DataSourceResult<FbStationOverviewSecondVo> getOverviewKendoListCust(DataSourceRequest dataSourceRequest);
DataSourceResult<FbStationOverviewSecondVo> getOverviewSecond(DataSourceRequest dataSourceRequest);
DataSourceResult<FbStationOverviewSecondVo> getQgcOverviewSecond(DataSourceRequest dataSourceRequest);

View File

@ -1,5 +1,6 @@
package com.yfd.platform.qgc_env.fb.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.yfd.platform.common.DataSourceLoadOptionsBase;
@ -13,11 +14,15 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collections;
@Service
public class FbStationServiceImpl implements FbStationService {
@ -25,6 +30,72 @@ public class FbStationServiceImpl implements FbStationService {
@Resource
private MicroservicDynamicSQLMapper microservicDynamicSQLMapper;
@Override
public DataSourceResult<FbStationOverviewSecondVo> getOverviewKendoListCust(DataSourceRequest dataSourceRequest) {
DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest();
String startTime = loadOptions == null ? null : QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "startTime");
String endTime = loadOptions == null ? null : QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "endTime");
String baseId = loadOptions == null ? null : QgcQueryWrapperUtil.getFilterFieldValue(loadOptions, "baseId");
List<String> stcdList = resolveStcdList(dataSourceRequest, loadOptions);
DataSourceResult<FbStationOverviewSecondVo> result = new DataSourceResult<>();
FbStationOverviewSecondVo vo = new FbStationOverviewSecondVo();
Date startDate = StrUtil.isBlank(startTime) ? null : DateUtil.parse(startTime);
Date endDate = StrUtil.isBlank(endTime) ? null : DateUtil.parse(endTime);
Map<String, Object> stationParamMap = new HashMap<>();
String stationSql = buildOverviewStationListSql(baseId, stcdList, stationParamMap);
List<FbStationOverviewSecondVo> stationList = microservicDynamicSQLMapper.pageAllListWithResultType(
null, stationSql, stationParamMap, FbStationOverviewSecondVo.class
);
if (CollUtil.isEmpty(stationList)) {
result.setData(Collections.emptyList());
result.setTotal(0);
result.setAggregates(new HashMap<>());
return result;
}
List<String> rstcdList = stationList.stream()
.map(FbStationOverviewSecondVo::getStcd)
.filter(StrUtil::isNotBlank)
.distinct()
.toList();
vo.setCount(stationList.size());
BigDecimal inv = BigDecimal.ZERO;
for (FbStationOverviewSecondVo station : stationList) {
if (station.getTotalInv() != null) {
inv = inv.add(station.getTotalInv());
}
}
vo.setTotalInv(inv.divide(BigDecimal.ONE, 2, RoundingMode.HALF_UP));
if (startDate != null && endDate != null) {
vo.setYear(startTime.substring(0, 4));
} else {
String latestYear = queryLatestOverviewYear(rstcdList);
if (StrUtil.isBlank(latestYear)) {
result.setData(Collections.emptyList());
result.setTotal(0);
result.setAggregates(new HashMap<>());
return result;
}
vo.setYear(latestYear);
startDate = DateUtil.parse(latestYear + "-01-01");
endDate = DateUtil.parse(latestYear + "-12-31");
}
fillPlanOverviewStat(vo, rstcdList, stcdList, startDate, endDate);
fillActualOverviewStat(vo, rstcdList, stcdList, startDate, endDate);
vo.setTotalFtpCount(queryAccumulateCount(rstcdList, stcdList, endDate));
result.setData(Collections.singletonList(vo));
result.setTotal(1);
result.setAggregates(new HashMap<>());
return result;
}
@Override
public DataSourceResult<FbStationOverviewSecondVo> getOverviewSecond(DataSourceRequest dataSourceRequest) {
DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest();
@ -46,6 +117,148 @@ public class FbStationServiceImpl implements FbStationService {
return result;
}
private String buildOverviewStationListSql(String baseId,
List<String> stcdList,
Map<String, Object> paramMap) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT fb.STCD AS stcd, fb.STNM AS stnm, fb.INV AS totalInv ")
.append("FROM SD_FBRD_B_H fb WHERE 1 = 1 ");
if (StrUtil.isNotBlank(baseId)) {
paramMap.put("stationBaseId", baseId.trim());
sql.append("AND fb.BASE_ID = #{map.stationBaseId} ");
}
appendLikeAnyCondition(sql, paramMap, "fb.RSTCD", stcdList, "stationStcdFilter");
return sql.toString();
}
private String queryLatestOverviewYear(List<String> rstcdList) {
if (CollUtil.isEmpty(rstcdList)) {
return null;
}
Map<String, Object> paramMap = new HashMap<>();
StringBuilder sql = new StringBuilder();
sql.append("SELECT yr FROM (")
.append("SELECT yr FROM (")
.append("SELECT plan.RSTCD, TO_CHAR(plan.PLANSD, 'YYYY') AS yr, plan.PLANSD AS sortTm ")
.append("FROM SD_ENGFRPLAN_B plan ")
.append("LEFT JOIN SD_ENGFRPLANDET_B det ON plan.ID = det.RPJH_ID ")
.append("WHERE NVL(plan.IS_DELETED, 0) = 0 AND NVL(det.IS_DELETED, 0) = 0 ")
.append("UNION ALL ")
.append("SELECT run.RSTCD, TO_CHAR(run.TM, 'YYYY') AS yr, run.TM AS sortTm ")
.append("FROM SD_ENGFR_R run ")
.append("LEFT JOIN SD_RPIMNFISH_R det ON run.ID = det.RPIMN_ID ")
.append("WHERE NVL(run.IS_DELETED, 0) = 0 AND NVL(det.IS_DELETED, 0) = 0 ")
.append(") src WHERE 1 = 1 ");
appendInCondition(sql, paramMap, "src.RSTCD", rstcdList, "latestRstcd");
sql.append("AND yr IS NOT NULL ORDER BY sortTm DESC) WHERE ROWNUM = 1");
List<Map<String, Object>> rows = microservicDynamicSQLMapper.pageAllList(null, sql.toString(), paramMap);
if (CollUtil.isEmpty(rows) || rows.get(0) == null || rows.get(0).get("YR") == null) {
return null;
}
return String.valueOf(rows.get(0).get("YR"));
}
private void fillPlanOverviewStat(FbStationOverviewSecondVo vo,
List<String> rstcdList,
List<String> stcdList,
Date startDate,
Date endDate) {
Map<String, Object> paramMap = new HashMap<>();
StringBuilder sql = new StringBuilder();
sql.append("SELECT det.FTP AS ftp, SUM(det.FCNT) AS fcntjh ")
.append("FROM SD_ENGFRPLAN_B plan ")
.append("LEFT JOIN SD_ENGFRPLANDET_B det ON plan.ID = det.RPJH_ID ")
.append("WHERE det.FTP IS NOT NULL ")
.append("AND NVL(plan.IS_DELETED, 0) = 0 AND NVL(det.IS_DELETED, 0) = 0 ");
appendInCondition(sql, paramMap, "plan.RSTCD", rstcdList, "planOverviewRstcd");
appendInCondition(sql, paramMap, "plan.STCD", stcdList, "planOverviewStcd");
if (startDate != null) {
paramMap.put("planOverviewStartDate", startDate);
sql.append("AND plan.PLANSD >= #{map.planOverviewStartDate} ");
}
if (endDate != null) {
paramMap.put("planOverviewEndDate", endDate);
sql.append("AND plan.PLANED <= #{map.planOverviewEndDate} ");
}
sql.append("GROUP BY det.FTP");
List<Map<String, Object>> rows = microservicDynamicSQLMapper.pageAllList(null, sql.toString(), paramMap);
if (CollUtil.isEmpty(rows)) {
return;
}
vo.setFtpCount(rows.size());
BigDecimal sum = BigDecimal.ZERO;
for (Map<String, Object> row : rows) {
sum = sum.add(toBigDecimal(row.get("FCNTJH")));
}
vo.setFcntjh(sum);
}
private void fillActualOverviewStat(FbStationOverviewSecondVo vo,
List<String> rstcdList,
List<String> stcdList,
Date startDate,
Date endDate) {
Map<String, Object> paramMap = new HashMap<>();
StringBuilder sql = new StringBuilder();
sql.append("SELECT det.FTP AS ftp, SUM(det.FCNT) AS fcntjc ")
.append("FROM SD_ENGFR_R run ")
.append("LEFT JOIN SD_RPIMNFISH_R det ON run.ID = det.RPIMN_ID ")
.append("WHERE det.FTP IS NOT NULL ")
.append("AND NVL(run.IS_DELETED, 0) = 0 AND NVL(det.IS_DELETED, 0) = 0 ");
appendInCondition(sql, paramMap, "run.STCD", stcdList, "actualOverviewStcd");
appendInCondition(sql, paramMap, "run.RSTCD", rstcdList, "actualOverviewRstcd");
if (startDate != null) {
paramMap.put("actualOverviewStartDate", startDate);
sql.append("AND run.TM >= #{map.actualOverviewStartDate} ");
}
if (endDate != null) {
paramMap.put("actualOverviewEndDate", endDate);
sql.append("AND run.TM <= #{map.actualOverviewEndDate} ");
}
sql.append("GROUP BY det.FTP");
List<Map<String, Object>> rows = microservicDynamicSQLMapper.pageAllList(null, sql.toString(), paramMap);
if (CollUtil.isEmpty(rows)) {
return;
}
vo.setRealftpCount(rows.size());
BigDecimal sum = BigDecimal.ZERO;
for (Map<String, Object> row : rows) {
sum = sum.add(toBigDecimal(row.get("FCNTJC")));
}
vo.setRealfcnt(sum);
}
private Long queryAccumulateCount(List<String> rstcdList, List<String> stcdList, Date endDate) {
Map<String, Object> paramMap = new HashMap<>();
StringBuilder sql = new StringBuilder();
sql.append("SELECT SUM(det.FCNT) AS fcnt ")
.append("FROM SD_ENGFR_R run ")
.append("LEFT JOIN SD_RPIMNFISH_R det ON run.ID = det.RPIMN_ID ")
.append("WHERE det.FTP IS NOT NULL ")
.append("AND NVL(run.IS_DELETED, 0) = 0 AND NVL(det.IS_DELETED, 0) = 0 ");
appendInCondition(sql, paramMap, "run.RSTCD", rstcdList, "accRstcd");
appendInCondition(sql, paramMap, "run.STCD", stcdList, "accStcd");
if (endDate != null) {
paramMap.put("accEndDate", endDate);
sql.append("AND run.TM <= #{map.accEndDate} ");
}
List<Map<String, Object>> rows = microservicDynamicSQLMapper.pageAllList(null, sql.toString(), paramMap);
if (CollUtil.isEmpty(rows) || rows.get(0) == null || rows.get(0).get("FCNT") == null) {
return null;
}
return toBigDecimal(rows.get(0).get("FCNT")).longValue();
}
private BigDecimal toBigDecimal(Object value) {
if (value == null) {
return BigDecimal.ZERO;
}
if (value instanceof BigDecimal bigDecimal) {
return bigDecimal;
}
return new BigDecimal(String.valueOf(value));
}
@Override
public DataSourceResult<FbStationOverviewSecondVo> getQgcOverviewSecond(DataSourceRequest dataSourceRequest) {
DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest();
@ -100,7 +313,7 @@ public class FbStationServiceImpl implements FbStationService {
paramMap.put("overviewBaseId", baseId.trim());
sql.append("AND fb.BASE_ID = #{map.overviewBaseId} ");
}
appendLikeAnyCondition(sql, paramMap, "NVL(fb.RENGCD, fb.RSTCD)", stcdList, "overviewStationFilter");
appendLikeAnyCondition(sql, paramMap, "fb.RSTCD", stcdList, "overviewStationFilter");
sql.append("GROUP BY fb.STCD, fb.STNM, eng.ENNM, t.YEAR, fb.INV ")
.append("ORDER BY fb.STCD ASC");
@ -143,7 +356,7 @@ public class FbStationServiceImpl implements FbStationService {
paramMap.put("hbrvcd", hbrvcd.trim());
sql.append("AND fb.HBRVCD = #{map.hbrvcd} ");
}
appendLikeAnyCondition(sql, paramMap, "NVL(fb.RENGCD, fb.RSTCD)", stcdList, "stationFilter");
appendLikeAnyCondition(sql, paramMap, "fb.RSTCD", stcdList, "stationFilter");
sql.append("GROUP BY fb.STCD, fb.STNM, eng.ENNM, t.YEAR, fb.INV ")
.append("ORDER BY fb.STCD ASC");