feat: 水生生态调查-水温数据列表

This commit is contained in:
tangwei 2026-07-01 16:36:08 +08:00
parent a8541ad11e
commit 511745c1d0
4 changed files with 229 additions and 0 deletions

View File

@ -167,4 +167,10 @@ public class WeFishController {
public ResponseResult getWeYr(@RequestParam("stcd") String stcd) { public ResponseResult getWeYr(@RequestParam("stcd") String stcd) {
return ResponseResult.successData(weFishService.getWeYr(stcd)); return ResponseResult.successData(weFishService.getWeYr(stcd));
} }
@PostMapping("/we/wewtr/GetKendoListCust")
@Operation(summary = "水生生态调查-水温数据列表")
public ResponseResult getWeWtR(@RequestBody DataSourceRequest dataSourceRequest) {
return ResponseResult.successData(weFishService.getWeWtR(dataSourceRequest));
}
} }

View File

@ -0,0 +1,18 @@
package com.yfd.platform.qgc_env.wte.entity.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class WeWtVo {
private String dcpc;
private String stcd;
private Date tm;
private BigDecimal wt;
}

View File

@ -58,4 +58,6 @@ public interface WeFishService {
List<WeDefaultDataVo> getWeDefaultData(String stcd); List<WeDefaultDataVo> getWeDefaultData(String stcd);
DataSourceResult getWeYr(String stcd); DataSourceResult getWeYr(String stcd);
DataSourceResult<WeWtVo> getWeWtR(DataSourceRequest dataSourceRequest);
} }

View File

@ -12,6 +12,7 @@ import com.yfd.platform.common.GroupingInfo;
import com.yfd.platform.common.MicroservicDynamicSQLMapper; import com.yfd.platform.common.MicroservicDynamicSQLMapper;
import com.yfd.platform.qgc_env.wte.entity.vo.*; import com.yfd.platform.qgc_env.wte.entity.vo.*;
import com.yfd.platform.qgc_env.wte.service.WeFishService; import com.yfd.platform.qgc_env.wte.service.WeFishService;
import com.yfd.platform.utils.KendoUtil;
import com.yfd.platform.utils.QgcQueryWrapperUtil; import com.yfd.platform.utils.QgcQueryWrapperUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -1176,6 +1177,208 @@ public class WeFishServiceImpl implements WeFishService {
return dataSourceResult; return dataSourceResult;
} }
@Override
public DataSourceResult<WeWtVo> getWeWtR(DataSourceRequest dataSourceRequest) {
DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest();
GroupingInfo[] groupInfos = loadOptions == null ? null : loadOptions.getGroup();
Map<String, Object> paramMap = new HashMap<>();
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 ");
String filterSql = buildWeWtFilterCondition(
dataSourceRequest == null ? null : dataSourceRequest.getFilter(),
paramMap,
new int[]{0}
);
if (StrUtil.isNotBlank(filterSql)) {
sql.append("AND ").append(filterSql).append(" ");
}
DataSourceResult<WeWtVo> result = new DataSourceResult<>();
if (CollUtil.isNotEmpty(dataSourceRequest == null ? null : dataSourceRequest.getGroup())) {
String groupBy = KendoUtil.getGroupBy(dataSourceRequest);
if (StrUtil.isNotBlank(groupBy)) {
List<String> 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<Map<String, Object>> rows = microservicDynamicSQLMapper.getAllList(groupedSql, paramMap);
if (Boolean.TRUE.equals(dataSourceRequest.getGroupResultFlat())) {
result.setData((List<WeWtVo>) (List<?>) new GroupHelper().faltGroup(rows, Arrays.asList(groupInfos)));
} else {
result.setData((List<WeWtVo>) (List<?>) new GroupHelper().group(rows, Arrays.asList(groupInfos)));
}
result.setTotal((long) rows.size());
result.setAggregates(new HashMap<>());
return result;
}
}
sql.append(buildWeWtOrderBySql(dataSourceRequest == null ? null : dataSourceRequest.getSort()));
Page<?> page = loadOptions == null ? null
: QgcQueryWrapperUtil.buildPage(loadOptions, loadOptions.getSkip(), loadOptions.getTake());
List<WeWtVo> list = microservicDynamicSQLMapper.pageAllListWithResultType(page, sql.toString(), paramMap, WeWtVo.class);
result.setData(list);
result.setTotal(page != null ? page.getTotal() : list.size());
result.setAggregates(new HashMap<>());
return result;
}
private String buildWeWtFilterCondition(DataSourceRequest.FilterDescriptor filter,
Map<String, Object> paramMap,
int[] indexHolder) {
if (filter == null) {
return "";
}
if (StrUtil.isNotBlank(filter.getField())) {
return buildWeWtLeafCondition(filter, paramMap, indexHolder);
}
if (CollUtil.isEmpty(filter.getFilters())) {
return "";
}
List<String> conditions = new ArrayList<>();
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
String childSql = buildWeWtFilterCondition(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 buildWeWtLeafCondition(DataSourceRequest.FilterDescriptor filter,
Map<String, Object> paramMap,
int[] indexHolder) {
String column = mapWeWtColumn(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<Object> values = normalizeWeFishQgcValues(filter.getValue());
if (values.isEmpty()) {
return "";
}
List<String> placeholders = new ArrayList<>();
boolean isDateField = "t.tm".equals(column);
for (Object value : values) {
String paramKey = "weWtParam" + 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 = "weWtParam" + indexHolder[0]++;
paramMap.put(paramKey, filter.getValue());
boolean isDateField = "t.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 mapWeWtColumn(String field) {
if (StrUtil.isBlank(field)) {
return null;
}
return switch (field.toLowerCase()) {
case "dcpc" -> "t.dcpc";
case "stcd" -> "t.stcd";
case "wt" -> "t1.wt";
case "tm" -> "t.tm";
default -> null;
};
}
private String buildWeWtOrderBySql(List<DataSourceRequest.SortDescriptor> sorts) {
if (CollUtil.isEmpty(sorts)) {
return " ORDER BY t.tm DESC NULLS LAST, t.stcd ASC";
}
List<String> orderByParts = new ArrayList<>();
for (DataSourceRequest.SortDescriptor sort : sorts) {
if (sort == null || StrUtil.isBlank(sort.getField())) {
continue;
}
String column = mapWeWtColumn(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 t.tm DESC NULLS LAST, t.stcd ASC";
}
return " ORDER BY " + String.join(", ", orderByParts);
}
private String buildWeFishQgcGroupSql(String baseSql, GroupingInfo[] groupInfos) { private String buildWeFishQgcGroupSql(String baseSql, GroupingInfo[] groupInfos) {
if (groupInfos == null || groupInfos.length == 0) { if (groupInfos == null || groupInfos.length == 0) {
return baseSql; return baseSql;