fix: 优化智能装备模块-各基地设备数量统计(堆叠条形图)
This commit is contained in:
parent
0576189e08
commit
8a97706ab7
@ -26,4 +26,10 @@ public class ImeController {
|
|||||||
public ResponseResult getVmsstbprptList(@RequestBody DataSourceRequest dataSourceRequest) {
|
public ResponseResult getVmsstbprptList(@RequestBody DataSourceRequest dataSourceRequest) {
|
||||||
return ResponseResult.successData(imeService.getVmsstbprptList(dataSourceRequest));
|
return ResponseResult.successData(imeService.getVmsstbprptList(dataSourceRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/base/device/stat")
|
||||||
|
@Operation(summary = "各基地设备数量统计(堆叠条形图)")
|
||||||
|
public ResponseResult getBaseDeviceStat(@RequestBody DataSourceRequest dataSourceRequest) {
|
||||||
|
return ResponseResult.successData(imeService.getBaseDeviceStat(dataSourceRequest));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.yfd.platform.qgc_env.ime.entity.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "智能装备-各基地设备数量统计(堆叠条形图)返回")
|
||||||
|
public class ImeBaseDeviceStatResultVo {
|
||||||
|
|
||||||
|
@Schema(description = "按基地统计的堆叠数据(横轴为基地, 内层 sttpCountMap 为堆叠系列)")
|
||||||
|
private List<ImeBaseDeviceStatVo> data = new ArrayList<>();
|
||||||
|
|
||||||
|
@Schema(description = "堆叠系列顺序(去重后的 sttpCode 集合)")
|
||||||
|
private List<String> sttpCodes = new ArrayList<>();
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.yfd.platform.qgc_env.ime.entity.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "智能装备-各基地设备数量(堆叠条形图单基地)")
|
||||||
|
public class ImeBaseDeviceStatVo {
|
||||||
|
|
||||||
|
@Schema(description = "基地编码")
|
||||||
|
private String baseId;
|
||||||
|
|
||||||
|
@Schema(description = "基地名称")
|
||||||
|
private String baseName;
|
||||||
|
|
||||||
|
@Schema(description = "各站类(设备)数量,key=sttpCode,value=数量")
|
||||||
|
private Map<String, Long> sttpCountMap = new LinkedHashMap<>();
|
||||||
|
}
|
||||||
@ -2,9 +2,15 @@ package com.yfd.platform.qgc_env.ime.service;
|
|||||||
|
|
||||||
import com.yfd.platform.common.DataSourceRequest;
|
import com.yfd.platform.common.DataSourceRequest;
|
||||||
import com.yfd.platform.common.DataSourceResult;
|
import com.yfd.platform.common.DataSourceResult;
|
||||||
|
import com.yfd.platform.qgc_env.ime.entity.vo.ImeBaseDeviceStatResultVo;
|
||||||
import com.yfd.platform.qgc_env.ime.entity.vo.ImeVmsstbprptVo;
|
import com.yfd.platform.qgc_env.ime.entity.vo.ImeVmsstbprptVo;
|
||||||
|
|
||||||
public interface ImeService {
|
public interface ImeService {
|
||||||
|
|
||||||
DataSourceResult<ImeVmsstbprptVo> getVmsstbprptList(DataSourceRequest dataSourceRequest);
|
DataSourceResult<ImeVmsstbprptVo> getVmsstbprptList(DataSourceRequest dataSourceRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按基地统计设备(sttpCode)数量,用于堆叠条形图展示
|
||||||
|
*/
|
||||||
|
ImeBaseDeviceStatResultVo getBaseDeviceStat(DataSourceRequest dataSourceRequest);
|
||||||
}
|
}
|
||||||
@ -9,6 +9,8 @@ import com.yfd.platform.common.DataSourceResult;
|
|||||||
import com.yfd.platform.common.GroupHelper;
|
import com.yfd.platform.common.GroupHelper;
|
||||||
import com.yfd.platform.common.GroupingInfo;
|
import com.yfd.platform.common.GroupingInfo;
|
||||||
import com.yfd.platform.common.MicroservicDynamicSQLMapper;
|
import com.yfd.platform.common.MicroservicDynamicSQLMapper;
|
||||||
|
import com.yfd.platform.qgc_env.ime.entity.vo.ImeBaseDeviceStatResultVo;
|
||||||
|
import com.yfd.platform.qgc_env.ime.entity.vo.ImeBaseDeviceStatVo;
|
||||||
import com.yfd.platform.qgc_env.ime.entity.vo.ImeVmsstbprptVo;
|
import com.yfd.platform.qgc_env.ime.entity.vo.ImeVmsstbprptVo;
|
||||||
import com.yfd.platform.qgc_env.ime.service.ImeService;
|
import com.yfd.platform.qgc_env.ime.service.ImeService;
|
||||||
import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
||||||
@ -19,6 +21,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -46,6 +49,266 @@ public class ImeServiceImpl implements ImeService {
|
|||||||
return buildDetailVmsstbprptResult(dataSourceRequest, loadOptions, filterSql, paramMap);
|
return buildDetailVmsstbprptResult(dataSourceRequest, loadOptions, filterSql, paramMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImeBaseDeviceStatResultVo getBaseDeviceStat(DataSourceRequest dataSourceRequest) {
|
||||||
|
Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
// 解析前端传递的 sttpCode 集合(STTP 为原始站类,STTP_CODE 依赖字典,故用 STTP 统计)
|
||||||
|
List<String> sttpCodes = resolveImeSttpCodes(
|
||||||
|
dataSourceRequest == null ? null : dataSourceRequest.getFilter());
|
||||||
|
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
// 以基地表为主表左连接设备统计,保证没有设备的基地也返回,数量为 0;sttpCode 类型在子查询内过滤
|
||||||
|
sql.append("SELECT h.BASEID AS baseId, h.BASENAME AS baseName, ")
|
||||||
|
.append("s.sttpCode AS sttpCode, NVL(s.cnt, 0) AS cnt ")
|
||||||
|
.append("FROM SD_HYDROBASE h ")
|
||||||
|
.append("LEFT JOIN ( ")
|
||||||
|
.append(" SELECT t.BASE_ID AS baseId, t.STTP AS sttpCode, COUNT(1) AS cnt ")
|
||||||
|
.append(" FROM V_MS_STBPRP_T t ")
|
||||||
|
.append(" WHERE 1 = 1 ")
|
||||||
|
.append(" AND t.BASE_ID IS NOT NULL ");
|
||||||
|
if (CollUtil.isNotEmpty(sttpCodes)) {
|
||||||
|
List<String> placeholders = new ArrayList<>();
|
||||||
|
for (int i = 0; i < sttpCodes.size(); i++) {
|
||||||
|
String key = "imeBaseStatSttp_" + i;
|
||||||
|
paramMap.put(key, sttpCodes.get(i));
|
||||||
|
placeholders.add("#{map." + key + "}");
|
||||||
|
}
|
||||||
|
sql.append(" AND t.STTP IN (").append(String.join(", ", placeholders)).append(") ");
|
||||||
|
}
|
||||||
|
sql.append(" GROUP BY t.BASE_ID, t.STTP ")
|
||||||
|
.append(") s ON s.baseId = h.BASEID ")
|
||||||
|
.append("WHERE 1 = 1 ")
|
||||||
|
.append("AND NVL(h.IS_DELETED, 0) = 0 ")
|
||||||
|
.append("AND NVL(h.ENABLED, 1) = 1 ");
|
||||||
|
// baseId / baseName 等其它前端过滤(除 sttpCode 外)
|
||||||
|
String filterSql = buildImeBaseStatFilterCondition(
|
||||||
|
dataSourceRequest == null ? null : dataSourceRequest.getFilter(),
|
||||||
|
paramMap,
|
||||||
|
new int[]{0}
|
||||||
|
);
|
||||||
|
if (StrUtil.isNotBlank(filterSql)) {
|
||||||
|
sql.append("AND ").append(filterSql).append(" ");
|
||||||
|
}
|
||||||
|
sql.append("ORDER BY h.BASEID");
|
||||||
|
|
||||||
|
List<Map<String, Object>> rows = microservicDynamicSQLMapper.getAllList(sql.toString(), paramMap);
|
||||||
|
|
||||||
|
LinkedHashMap<String, ImeBaseDeviceStatVo> groupMap = new LinkedHashMap<>();
|
||||||
|
for (Map<String, Object> row : rows) {
|
||||||
|
String baseId = strVal(rowValue(row, "baseId"));
|
||||||
|
if (StrUtil.isBlank(baseId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String baseName = strVal(rowValue(row, "baseName"));
|
||||||
|
String sttpCode = strVal(rowValue(row, "sttpCode"));
|
||||||
|
long cnt = longVal(rowValue(row, "cnt"));
|
||||||
|
ImeBaseDeviceStatVo vo = groupMap.computeIfAbsent(baseId, k -> {
|
||||||
|
ImeBaseDeviceStatVo v = new ImeBaseDeviceStatVo();
|
||||||
|
v.setBaseId(baseId);
|
||||||
|
v.setBaseName(baseName);
|
||||||
|
// 预填前端传入的 sttpCode,缺失类型的数量为 0
|
||||||
|
if (CollUtil.isNotEmpty(sttpCodes)) {
|
||||||
|
for (String code : sttpCodes) {
|
||||||
|
v.getSttpCountMap().merge(code, 0L, Long::sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
if (vo.getBaseName() == null) {
|
||||||
|
vo.setBaseName(baseName);
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(sttpCode)) {
|
||||||
|
vo.getSttpCountMap().merge(sttpCode, cnt, Long::sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImeBaseDeviceStatResultVo result = new ImeBaseDeviceStatResultVo();
|
||||||
|
result.setData(new ArrayList<>(groupMap.values()));
|
||||||
|
// 堆叠系列顺序:优先保留前端传入的 sttpCode,再补充实际存在的类型
|
||||||
|
LinkedHashSet<String> series = new LinkedHashSet<>();
|
||||||
|
if (CollUtil.isNotEmpty(sttpCodes)) {
|
||||||
|
series.addAll(sttpCodes);
|
||||||
|
}
|
||||||
|
for (ImeBaseDeviceStatVo vo : result.getData()) {
|
||||||
|
series.addAll(vo.getSttpCountMap().keySet());
|
||||||
|
}
|
||||||
|
result.setSttpCodes(new ArrayList<>(series));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从过滤条件中提取前端传递的 sttpCode 集合(用于 IN 过滤)
|
||||||
|
*/
|
||||||
|
private List<String> resolveImeSttpCodes(DataSourceRequest.FilterDescriptor filter) {
|
||||||
|
List<String> codes = new ArrayList<>();
|
||||||
|
collectImeSttpCodes(filter, codes);
|
||||||
|
LinkedHashSet<String> distinct = new LinkedHashSet<>();
|
||||||
|
for (String code : codes) {
|
||||||
|
if (StrUtil.isNotBlank(code)) {
|
||||||
|
distinct.add(code.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>(distinct);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectImeSttpCodes(DataSourceRequest.FilterDescriptor filter, List<String> out) {
|
||||||
|
if (filter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(filter.getField())) {
|
||||||
|
if ("sttpCode".equals(filter.getField()) || "sttp".equalsIgnoreCase(filter.getField())) {
|
||||||
|
for (Object value : normalizeImeVmsstbprptValues(filter.getValue())) {
|
||||||
|
if (value != null) {
|
||||||
|
out.add(String.valueOf(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(filter.getFilters())) {
|
||||||
|
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
||||||
|
collectImeSttpCodes(child, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建按基地统计设备数量的动态过滤条件(baseId/baseName 等,sttpCode 已由 resolveImeSttpCodes 提取)
|
||||||
|
*/
|
||||||
|
private String buildImeBaseStatFilterCondition(DataSourceRequest.FilterDescriptor filter,
|
||||||
|
Map<String, Object> paramMap,
|
||||||
|
int[] indexHolder) {
|
||||||
|
if (filter == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(filter.getField())) {
|
||||||
|
return buildImeBaseStatLeafCondition(filter, paramMap, indexHolder);
|
||||||
|
}
|
||||||
|
if (CollUtil.isEmpty(filter.getFilters())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
List<String> conditions = new ArrayList<>();
|
||||||
|
for (DataSourceRequest.FilterDescriptor child : filter.getFilters()) {
|
||||||
|
String childSql = buildImeBaseStatFilterCondition(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 buildImeBaseStatLeafCondition(DataSourceRequest.FilterDescriptor filter,
|
||||||
|
Map<String, Object> paramMap,
|
||||||
|
int[] indexHolder) {
|
||||||
|
String column = mapImeBaseStatColumn(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 ("in".equals(operator) || "ni".equals(operator)) {
|
||||||
|
List<Object> values = normalizeImeVmsstbprptValues(filter.getValue());
|
||||||
|
List<String> placeholders = new ArrayList<>();
|
||||||
|
for (Object value : values) {
|
||||||
|
if (value == null || StrUtil.isBlank(String.valueOf(value).trim())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String key = "imeBaseStatP" + indexHolder[0]++;
|
||||||
|
paramMap.put(key, String.valueOf(value).trim());
|
||||||
|
placeholders.add("#{map." + key + "}");
|
||||||
|
}
|
||||||
|
if (placeholders.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return column + ("ni".equals(operator) ? " NOT IN (" : " IN (") + String.join(", ", placeholders) + ")";
|
||||||
|
}
|
||||||
|
Object rawValue = filter.getValue();
|
||||||
|
if (rawValue == null || StrUtil.isBlank(String.valueOf(rawValue).trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String key = "imeBaseStatP" + indexHolder[0]++;
|
||||||
|
String text = String.valueOf(rawValue).trim();
|
||||||
|
return switch (operator) {
|
||||||
|
case "eq" -> {
|
||||||
|
paramMap.put(key, text);
|
||||||
|
yield column + " = #{map." + key + "}";
|
||||||
|
}
|
||||||
|
case "neq" -> {
|
||||||
|
paramMap.put(key, text);
|
||||||
|
yield column + " <> #{map." + key + "}";
|
||||||
|
}
|
||||||
|
case "gt" -> {
|
||||||
|
paramMap.put(key, text);
|
||||||
|
yield column + " > #{map." + key + "}";
|
||||||
|
}
|
||||||
|
case "gte" -> {
|
||||||
|
paramMap.put(key, text);
|
||||||
|
yield column + " >= #{map." + key + "}";
|
||||||
|
}
|
||||||
|
case "lt" -> {
|
||||||
|
paramMap.put(key, text);
|
||||||
|
yield column + " < #{map." + key + "}";
|
||||||
|
}
|
||||||
|
case "lte" -> {
|
||||||
|
paramMap.put(key, text);
|
||||||
|
yield column + " <= #{map." + key + "}";
|
||||||
|
}
|
||||||
|
case "contains" -> {
|
||||||
|
paramMap.put(key, "%" + text + "%");
|
||||||
|
yield column + " LIKE #{map." + key + "}";
|
||||||
|
}
|
||||||
|
case "doesnotcontain" -> {
|
||||||
|
paramMap.put(key, "%" + text + "%");
|
||||||
|
yield column + " NOT LIKE #{map." + key + "}";
|
||||||
|
}
|
||||||
|
default -> "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mapImeBaseStatColumn(String field) {
|
||||||
|
if (StrUtil.isBlank(field)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return switch (field) {
|
||||||
|
case "sttpCode", "sttp" -> null; // 已由 resolveImeSttpCodes 提取并在子查询 IN 中过滤,此处跳过
|
||||||
|
case "baseId" -> "h.BASEID";
|
||||||
|
case "baseName" -> "h.BASENAME";
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object rowValue(Map<String, Object> row, String key) {
|
||||||
|
Object value = row.get(key);
|
||||||
|
if (value == null && StrUtil.isNotBlank(key)) {
|
||||||
|
value = row.get(key.toUpperCase());
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String strVal(Object value) {
|
||||||
|
return value == null ? "" : String.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private long longVal(Object value) {
|
||||||
|
if (value == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Long.parseLong(String.valueOf(value).trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private DataSourceResult<ImeVmsstbprptVo> buildDetailVmsstbprptResult(DataSourceRequest dataSourceRequest,
|
private DataSourceResult<ImeVmsstbprptVo> buildDetailVmsstbprptResult(DataSourceRequest dataSourceRequest,
|
||||||
DataSourceLoadOptionsBase loadOptions,
|
DataSourceLoadOptionsBase loadOptions,
|
||||||
String filterSql,
|
String filterSql,
|
||||||
@ -347,6 +610,7 @@ public class ImeServiceImpl implements ImeService {
|
|||||||
case "ennm" -> "t.ennm";
|
case "ennm" -> "t.ennm";
|
||||||
case "baseId" -> "t.baseId";
|
case "baseId" -> "t.baseId";
|
||||||
case "hbrvcd" -> "t.hbrvcd";
|
case "hbrvcd" -> "t.hbrvcd";
|
||||||
|
case "fhstcd" -> "t.fhstcd";
|
||||||
case "rvcd" -> "t.rvcd";
|
case "rvcd" -> "t.rvcd";
|
||||||
case "orderIndex" -> "t.orderIndex";
|
case "orderIndex" -> "t.orderIndex";
|
||||||
case "lgtd" -> "t.lgtd";
|
case "lgtd" -> "t.lgtd";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user