feat: 查询出库水温日数据
This commit is contained in:
parent
8240bf65c0
commit
9fdac17bb5
@ -0,0 +1,37 @@
|
||||
package com.yfd.platform.qgc_env.wt.entity.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(description = "出库水温日数据")
|
||||
public class SdAlongDayDetailVO {
|
||||
@Schema(description = "日期")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||
private Date dt;
|
||||
|
||||
@Schema(description = "温度")
|
||||
private BigDecimal wt;
|
||||
|
||||
@Schema(description = "编码")
|
||||
private String stcd;
|
||||
|
||||
@Schema(description = "电站编码")
|
||||
private String rstcd;
|
||||
|
||||
@Schema(description = "电站名称")
|
||||
private String ennm;
|
||||
|
||||
@Schema(description = "站点名称")
|
||||
private String stnm;
|
||||
|
||||
@Schema(description = "基地编码")
|
||||
private String baseId;
|
||||
|
||||
@Schema(description = "基地名称")
|
||||
private String baseName;
|
||||
}
|
||||
@ -12,6 +12,7 @@ import com.yfd.platform.qgc_env.wt.mapper.AlongDetailMapper;
|
||||
import com.yfd.platform.qgc_env.wt.mapper.SdWtrvdrtpSMapper;
|
||||
import com.yfd.platform.qgc_env.wt.service.AlongDetailService;
|
||||
import com.yfd.platform.qgc_env.wt.entity.vo.SdAlongDetailVO;
|
||||
import com.yfd.platform.qgc_env.wt.entity.vo.SdAlongDayDetailVO;
|
||||
import com.yfd.platform.qgc_env.wt.entity.vo.WtrvInfo;
|
||||
import com.yfd.platform.qgc_base.entity.vo.BatchDeleteAo;
|
||||
import com.yfd.platform.qgc_base.entity.vo.DataParam;
|
||||
@ -129,33 +130,50 @@ public class AlongDetailServiceImpl extends ServiceImpl<AlongDetailMapper, SdAlo
|
||||
|
||||
@Override
|
||||
public DataSourceResult processDayKendoList(DataSourceRequest dataSourceRequest, Map<String, GroupResult> filterResult, Page page, String groupBy) {
|
||||
DataSourceResult dataSourceResult = new DataSourceResult();
|
||||
StringBuilder sql = new StringBuilder();
|
||||
DataSourceResult<SdAlongDayDetailVO> dataSourceResult = new DataSourceResult<>();
|
||||
DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest();
|
||||
StringBuilder sql = new StringBuilder()
|
||||
.append("SELECT ")
|
||||
.append("t.DT AS dt, ")
|
||||
.append("t.WT AS wt, ")
|
||||
.append("t.STCD AS stcd, ")
|
||||
.append("t.RSTCD AS rstcd, ")
|
||||
.append("t.ENNM AS ennm, ")
|
||||
.append("t.STNM AS stnm, ")
|
||||
.append("t.BASE_ID AS baseId, ")
|
||||
.append("t.BASENAME AS baseName ")
|
||||
.append("FROM (")
|
||||
.append("SELECT day.DT, day.WT, day.STCD, wt.RSTCD, eng.ENNM, wt.STNM, eng.BASE_ID, hb.BASENAME ")
|
||||
.append("FROM SD_WTRVDAY_S day ")
|
||||
.append("INNER JOIN SD_WT_B_H wt ON wt.STCD = day.STCD ")
|
||||
.append(" AND NVL(wt.IS_DELETED, 0) = 0 ")
|
||||
.append(" AND wt.STTP = 'WTRV' ")
|
||||
.append("LEFT JOIN SD_ENGINFO_B_H eng ON eng.STCD = wt.RSTCD AND NVL(eng.IS_DELETED, 0) = 0 ")
|
||||
.append("LEFT JOIN SD_HYDROBASE hb ON hb.BASEID = eng.BASE_ID AND NVL(hb.IS_DELETED, 0) = 0 ")
|
||||
.append("WHERE NVL(day.IS_DELETED, 0) = 0")
|
||||
.append(") t WHERE 1 = 1 ");
|
||||
|
||||
if(StrUtil.isNotBlank(filterResult.get("default").getSelectSql())){
|
||||
sql.append(filterResult.get("default").getSelectSql());
|
||||
sql.append(" from ");
|
||||
sql.append(" SD_WTRVDAY_S a inner join MS_STBPRP_T b on a.STCD=b.STCD and b.STTP_CODE='WTRV' ");
|
||||
sql.append(" where 1=1 ");
|
||||
if (ObjectUtil.isNotEmpty(filterResult.get(CommonConstant.DEFAULT))) {
|
||||
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getGroupSql())) {
|
||||
sql.append(" and ").append(filterResult.get(CommonConstant.DEFAULT).getGroupSql());
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
String filterSql = buildAlongDayFilterCondition(
|
||||
dataSourceRequest == null ? null : dataSourceRequest.getFilter(),
|
||||
paramMap,
|
||||
new int[]{0}
|
||||
);
|
||||
if (StrUtil.isNotBlank(filterSql)) {
|
||||
sql.append(" AND ").append(filterSql);
|
||||
}
|
||||
sql.append(buildAlongDayOrderBySql(dataSourceRequest == null ? null : dataSourceRequest.getSort()));
|
||||
|
||||
if (StrUtil.isNotBlank(filterResult.get(CommonConstant.DEFAULT).getOrderBySql())) {
|
||||
sql.append(" ").append(filterResult.get(CommonConstant.DEFAULT).getOrderBySql());
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Object> map = new HashMap();
|
||||
Iterator iterator = filterResult.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String key = (String) iterator.next();
|
||||
map.putAll(filterResult.get(key).getParamMap());
|
||||
}
|
||||
List< Map<String, Object>> resultList = this.dynamicSQLMapper.pageAllList(page, sql.toString(), map);
|
||||
Page<?> currentPage = loadOptions == null ? page : QgcQueryWrapperUtil.buildPage(loadOptions, loadOptions.getSkip(), loadOptions.getTake());
|
||||
List<SdAlongDayDetailVO> resultList = this.microservicDynamicSQLMapper.pageAllListWithResultType(
|
||||
currentPage,
|
||||
sql.toString(),
|
||||
paramMap,
|
||||
SdAlongDayDetailVO.class
|
||||
);
|
||||
dataSourceResult.setData(resultList);
|
||||
dataSourceResult.setTotal(ObjectUtil.isNotEmpty(page) ? page.getTotal() : (long) resultList.size());
|
||||
dataSourceResult.setTotal(ObjectUtil.isNotEmpty(currentPage) ? currentPage.getTotal() : (long) resultList.size());
|
||||
dataSourceResult.setAggregates(new HashMap<>());
|
||||
return dataSourceResult;
|
||||
}
|
||||
|
||||
@ -191,6 +209,169 @@ public class AlongDetailServiceImpl extends ServiceImpl<AlongDetailMapper, SdAlo
|
||||
return dataSourceResult;
|
||||
}
|
||||
|
||||
private String buildAlongDayFilterCondition(DataSourceRequest.FilterDescriptor filter,
|
||||
Map<String, Object> paramMap,
|
||||
int[] indexHolder) {
|
||||
if (filter == null) {
|
||||
return "";
|
||||
}
|
||||
if (StrUtil.isNotBlank(filter.getField())) {
|
||||
return buildAlongDayLeafCondition(filter, paramMap, indexHolder);
|
||||
}
|
||||
if (CollUtil.isEmpty(filter.getFilters())) {
|
||||
return "";
|
||||
}
|
||||
List<String> conditions = new ArrayList<>();
|
||||
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
||||
String childSql = buildAlongDayFilterCondition(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 buildAlongDayLeafCondition(DataSourceRequest.FilterDescriptor filter,
|
||||
Map<String, Object> paramMap,
|
||||
int[] indexHolder) {
|
||||
String column = mapAlongDayColumn(filter.getField());
|
||||
if (StrUtil.isBlank(column) || filter.getValue() == null) {
|
||||
return "";
|
||||
}
|
||||
String operator = StrUtil.blankToDefault(filter.getOperator(), "eq").toLowerCase();
|
||||
boolean dateField = "tm".equalsIgnoreCase(filter.getField()) || "dt".equalsIgnoreCase(filter.getField());
|
||||
String key = "alongDayParam" + indexHolder[0]++;
|
||||
switch (operator) {
|
||||
case "eq":
|
||||
paramMap.put(key, filter.getValue());
|
||||
return dateField
|
||||
? column + " = TO_DATE(SUBSTR(#{map." + key + "}, 1, 10), 'YYYY-MM-DD')"
|
||||
: column + " = #{map." + key + "}";
|
||||
case "neq":
|
||||
paramMap.put(key, filter.getValue());
|
||||
return dateField
|
||||
? column + " <> TO_DATE(SUBSTR(#{map." + key + "}, 1, 10), 'YYYY-MM-DD')"
|
||||
: column + " <> #{map." + key + "}";
|
||||
case "gt":
|
||||
paramMap.put(key, filter.getValue());
|
||||
return dateField
|
||||
? column + " > TO_DATE(SUBSTR(#{map." + key + "}, 1, 10), 'YYYY-MM-DD')"
|
||||
: column + " > #{map." + key + "}";
|
||||
case "gte":
|
||||
paramMap.put(key, filter.getValue());
|
||||
return dateField
|
||||
? column + " >= TO_DATE(SUBSTR(#{map." + key + "}, 1, 10), 'YYYY-MM-DD')"
|
||||
: column + " >= #{map." + key + "}";
|
||||
case "lt":
|
||||
paramMap.put(key, filter.getValue());
|
||||
return dateField
|
||||
? column + " < TO_DATE(SUBSTR(#{map." + key + "}, 1, 10), 'YYYY-MM-DD')"
|
||||
: column + " < #{map." + key + "}";
|
||||
case "lte":
|
||||
paramMap.put(key, filter.getValue());
|
||||
return dateField
|
||||
? column + " <= TO_DATE(SUBSTR(#{map." + key + "}, 1, 10), 'YYYY-MM-DD')"
|
||||
: column + " <= #{map." + key + "}";
|
||||
case "contains":
|
||||
paramMap.put(key, "%" + filter.getValue() + "%");
|
||||
return column + " LIKE #{map." + key + "}";
|
||||
case "in": {
|
||||
List<String> values = splitAlongDayFilterValues(filter.getValue());
|
||||
if (CollUtil.isEmpty(values)) {
|
||||
return "";
|
||||
}
|
||||
List<String> placeholders = new ArrayList<>();
|
||||
for (String item : values) {
|
||||
String itemKey = "alongDayParam" + indexHolder[0]++;
|
||||
paramMap.put(itemKey, item);
|
||||
placeholders.add(dateField
|
||||
? "TO_DATE(SUBSTR(#{map." + itemKey + "}, 1, 10), 'YYYY-MM-DD')"
|
||||
: "#{map." + itemKey + "}");
|
||||
}
|
||||
return column + " IN (" + String.join(", ", placeholders) + ")";
|
||||
}
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private String mapAlongDayColumn(String field) {
|
||||
if (StrUtil.isBlank(field)) {
|
||||
return null;
|
||||
}
|
||||
return switch (field) {
|
||||
case "tm", "dt" -> "t.DT";
|
||||
case "stcd" -> "t.STCD";
|
||||
case "rstcd" -> "t.RSTCD";
|
||||
case "wt" -> "t.WT";
|
||||
case "stnm" -> "t.STNM";
|
||||
case "baseName", "basename" -> "t.BASENAME";
|
||||
case "baseId" -> "t.BASE_ID";
|
||||
case "ennm" -> "t.ENNM";
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private String buildAlongDayOrderBySql(List<DataSourceRequest.SortDescriptor> sortList) {
|
||||
if (CollUtil.isEmpty(sortList)) {
|
||||
return " ORDER BY t.DT DESC NULLS LAST, t.STCD ASC";
|
||||
}
|
||||
List<String> orderItems = new ArrayList<>();
|
||||
for (DataSourceRequest.SortDescriptor sortDescriptor : sortList) {
|
||||
if (sortDescriptor == null || StrUtil.isBlank(sortDescriptor.getField())) {
|
||||
continue;
|
||||
}
|
||||
String column = mapAlongDayColumn(sortDescriptor.getField());
|
||||
if (StrUtil.isBlank(column)) {
|
||||
continue;
|
||||
}
|
||||
String dir = "desc".equalsIgnoreCase(sortDescriptor.getDir()) ? "DESC" : "ASC";
|
||||
orderItems.add(column + " " + dir + " NULLS LAST");
|
||||
}
|
||||
return CollUtil.isEmpty(orderItems) ? " ORDER BY t.DT DESC NULLS LAST, t.STCD ASC" : " ORDER BY " + String.join(", ", orderItems);
|
||||
}
|
||||
|
||||
private List<String> splitAlongDayFilterValues(Object value) {
|
||||
if (value == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (value instanceof List<?> listValue) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Object item : listValue) {
|
||||
if (item != null && StrUtil.isNotBlank(String.valueOf(item))) {
|
||||
result.add(String.valueOf(item).trim());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (value instanceof Object[] arrayValue) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Object item : arrayValue) {
|
||||
if (item != null && StrUtil.isNotBlank(String.valueOf(item))) {
|
||||
result.add(String.valueOf(item).trim());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
String text = String.valueOf(value).trim();
|
||||
if (StrUtil.isBlank(text)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
text = text.replace("[", "").replace("]", "").replace("\"", "").replace("'", "");
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String item : text.split(",")) {
|
||||
String trimmed = item == null ? null : item.trim();
|
||||
if (StrUtil.isNotBlank(trimmed) && !result.contains(trimmed)) {
|
||||
result.add(trimmed);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceResult processQgcKendList(DataSourceResult dataSourceResult, WtrvInfo wtrvInfo) {
|
||||
DataSourceResult dr = new DataSourceResult();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user