0918优化-综合查询显示曲线最大最小平均值和差值
This commit is contained in:
@ -9,7 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -29,12 +31,15 @@ public class EmsGeneralQueryController extends BaseController{
|
||||
@GetMapping("/getAllDeviceCategory")
|
||||
public AjaxResult getDeviceCategory()
|
||||
{
|
||||
// 获取所有枚举的中文信息
|
||||
List<String> deviceCategoryName = new ArrayList<>();
|
||||
// 获取所有枚举的信息
|
||||
List<Map<String, String>> deviceCategoryList = new ArrayList<>();
|
||||
for (DeviceCategory category : DeviceCategory.values()) {
|
||||
deviceCategoryName.add(category.getInfo());
|
||||
Map<String, String> categoryMap = new HashMap<>();
|
||||
categoryMap.put("name", category.getInfo());
|
||||
categoryMap.put("code", category.getCode());
|
||||
deviceCategoryList.add(categoryMap);
|
||||
}
|
||||
return success(deviceCategoryName);
|
||||
return success(deviceCategoryList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,6 +61,7 @@ public class EmsGeneralQueryController extends BaseController{
|
||||
try {
|
||||
result = iGeneralQueryService.getPointValueList(request);
|
||||
} catch (Exception e) {
|
||||
logger.error("<UNK>",e);
|
||||
return error("报错请重试!");
|
||||
}
|
||||
return success(result);
|
||||
|
||||
@ -142,7 +142,7 @@ public class EmsSiteConfigController extends BaseController{
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个站点单个设备点位查询
|
||||
* 单个站点单个设备点位查询-点位清单
|
||||
*/
|
||||
@GetMapping("/getDevicePointList")
|
||||
public TableDataInfo getDevicePointList(@Validated PointDataRequest request)
|
||||
|
||||
@ -21,7 +21,7 @@ public enum DeviceCategory
|
||||
COOLING("COOLING", "冷却", null),
|
||||
DH("DH", "动环", null),
|
||||
XF("XF", "消防", null),
|
||||
BATTERY_GROUP("BATTERY_GROUP", "电池组", null),;
|
||||
BATTERY_GROUP("BATTERY_GROUP", "电池组", null);
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.xzzn.ems.domain.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -13,10 +14,25 @@ public class DevicePointDataList
|
||||
private String parentDeviceId;
|
||||
// 该设备点位数据list
|
||||
private List<GeneralQueryDataVo> pointValueList;
|
||||
// 最大值
|
||||
private BigDecimal maxValue;
|
||||
// 最小值
|
||||
private BigDecimal minValue;
|
||||
// 平均值(保留4位小数)
|
||||
private BigDecimal avgValue;
|
||||
// 差值(max - min)
|
||||
private BigDecimal diffValue;
|
||||
|
||||
public DevicePointDataList(String deviceId, List<GeneralQueryDataVo> pointValueList) {
|
||||
public DevicePointDataList(String deviceId, List<GeneralQueryDataVo> pointValueList,String parentDeviceId,
|
||||
BigDecimal maxValue, BigDecimal minValue,
|
||||
BigDecimal avgValue, BigDecimal diffValue) {
|
||||
this.deviceId = deviceId;
|
||||
this.pointValueList = pointValueList;
|
||||
this.parentDeviceId = parentDeviceId;
|
||||
this.maxValue = maxValue;
|
||||
this.minValue = minValue;
|
||||
this.avgValue = avgValue;
|
||||
this.diffValue = diffValue;
|
||||
}
|
||||
|
||||
public DevicePointDataList() {
|
||||
@ -46,4 +62,36 @@ public class DevicePointDataList
|
||||
public void setParentDeviceId(String parentDeviceId) {
|
||||
this.parentDeviceId = parentDeviceId;
|
||||
}
|
||||
|
||||
public BigDecimal getMaxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public void setMaxValue(BigDecimal maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public BigDecimal getMinValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public void setMinValue(BigDecimal minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
public BigDecimal getAvgValue() {
|
||||
return avgValue;
|
||||
}
|
||||
|
||||
public void setAvgValue(BigDecimal avgValue) {
|
||||
this.avgValue = avgValue;
|
||||
}
|
||||
|
||||
public BigDecimal getDiffValue() {
|
||||
return diffValue;
|
||||
}
|
||||
|
||||
public void setDiffValue(BigDecimal diffValue) {
|
||||
this.diffValue = diffValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,9 +14,13 @@ public class GeneralQueryResponse {
|
||||
// 设备数据
|
||||
private List<DevicePointDataList> deviceList;
|
||||
|
||||
public GeneralQueryResponse(String siteId, List<DevicePointDataList> deviceList) {
|
||||
// 点位数据类型,1-瞬时值,2-累计值
|
||||
private Long dataType;
|
||||
|
||||
public GeneralQueryResponse(String siteId, List<DevicePointDataList> deviceList, Long dataType) {
|
||||
this.siteId = siteId;
|
||||
this.deviceList = deviceList;
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public GeneralQueryResponse() {
|
||||
@ -38,4 +42,12 @@ public class GeneralQueryResponse {
|
||||
public void setDeviceList(List<DevicePointDataList> deviceList) {
|
||||
this.deviceList = deviceList;
|
||||
}
|
||||
|
||||
public Long getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(Long dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ public class PointNameRequest {
|
||||
|
||||
private List<String> siteIds;
|
||||
|
||||
private String categoryName;
|
||||
private String deviceCategory;
|
||||
|
||||
private String pointName;
|
||||
|
||||
@ -34,12 +34,12 @@ public class PointNameRequest {
|
||||
this.siteIds = siteIds;
|
||||
}
|
||||
|
||||
public String getCategoryName() {
|
||||
return categoryName;
|
||||
public String getDeviceCategory() {
|
||||
return deviceCategory;
|
||||
}
|
||||
|
||||
public void setCategoryName(String categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
public void setDeviceCategory(String deviceCategory) {
|
||||
this.deviceCategory = deviceCategory;
|
||||
}
|
||||
|
||||
public String getPointName() {
|
||||
|
||||
@ -11,6 +11,7 @@ import com.xzzn.ems.service.IGeneralQueryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
@ -42,8 +43,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String categoryName = request.getCategoryName();
|
||||
String deviceCategory = DeviceCategory.getCodeByInfo(categoryName);
|
||||
String deviceCategory = request.getDeviceCategory();
|
||||
if (deviceCategory == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@ -83,8 +83,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
List<String> querySiteIds = new ArrayList<>();
|
||||
|
||||
List<String> siteIds = request.getSiteIds();
|
||||
String categoryName = request.getCategoryName();
|
||||
String deviceCategory = DeviceCategory.getCodeByInfo(categoryName);
|
||||
String deviceCategory = request.getDeviceCategory();
|
||||
// 根据入参获取点位对应的表和字段
|
||||
List<EmsPointMatch> matchInfo = emsPointMatchMapper.getMatchInfo(siteIds,deviceCategory,request.getPointName());
|
||||
if (matchInfo == null || matchInfo.size() == 0) {
|
||||
@ -108,13 +107,13 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
// 不同的site_id根据设备类型和字段,默认取第一个匹配到的表和表字段只会有一个,
|
||||
String tableName = matchInfo.get(0).getMatchTable();
|
||||
String tableField = matchInfo.get(0).getMatchField();
|
||||
|
||||
Long dataType = matchInfo.get(0).getDataType();
|
||||
if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
|
||||
// 单体电池数据特殊处理
|
||||
result = generalQueryBatteryData(querySiteIds,tableName,tableField,request,deviceCategory);
|
||||
result = generalQueryBatteryData(querySiteIds,tableName,tableField,request,deviceCategory,dataType);
|
||||
} else {
|
||||
// 其他设备数据
|
||||
result = generalQueryCommonData(querySiteIds,tableName,tableField,request,deviceCategory);
|
||||
result = generalQueryCommonData(querySiteIds,tableName,tableField,request,deviceCategory,dataType);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
@ -122,9 +121,9 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<GeneralQueryResponse> generalQueryCommonData(List<String> querySiteIds,String tableName,
|
||||
private List<GeneralQueryResponse> generalQueryCommonData(List<String> querySiteIds, String tableName,
|
||||
String tableField, PointNameRequest request,
|
||||
String deviceCategory) throws ParseException {
|
||||
String deviceCategory, Long dataType) throws ParseException {
|
||||
List<GeneralQueryResponse> result = new ArrayList<>();
|
||||
List<GeneralQueryDataVo> dataVoList = new ArrayList<>();
|
||||
|
||||
@ -146,14 +145,14 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
dataVoList = emsPointMatchMapper.getCommonPointDataByDays(querySiteIds,tableName,tableField,startDate,endDate,deviceId);
|
||||
}
|
||||
|
||||
// 数据转换
|
||||
result = convertCommonToResultList(dataVoList);
|
||||
// 数据转换+计算曲线数据最大最小平均和差值
|
||||
result = convertCommonToResultList(dataVoList, dataType);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<GeneralQueryResponse> generalQueryBatteryData(List<String> querySiteIds,String tableName,
|
||||
private List<GeneralQueryResponse> generalQueryBatteryData(List<String> querySiteIds, String tableName,
|
||||
String tableField, PointNameRequest request,
|
||||
String deviceCategory) throws ParseException {
|
||||
String deviceCategory, Long dataType) throws ParseException {
|
||||
List<GeneralQueryResponse> result = new ArrayList<>();
|
||||
List<GeneralQueryDataVo> dataVoList = new ArrayList<>();
|
||||
|
||||
@ -179,11 +178,11 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
dataVoList = emsPointMatchMapper.getBatteryPointDataByDays(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap,clusterDeviceId);
|
||||
}
|
||||
// 数据转换
|
||||
result = convertBatteryToResultList(dataVoList);
|
||||
result = convertBatteryToResultList(dataVoList,dataType);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<GeneralQueryResponse> convertBatteryToResultList(List<GeneralQueryDataVo> dataVoList) {
|
||||
private List<GeneralQueryResponse> convertBatteryToResultList(List<GeneralQueryDataVo> dataVoList, Long dataType) {
|
||||
// 先按siteId分组
|
||||
return dataVoList.stream()
|
||||
.collect(Collectors.groupingBy(GeneralQueryDataVo::getSiteId))
|
||||
@ -218,12 +217,12 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 4. 计算最大最小平均值
|
||||
Stats stats = clacStats(pointValueList);
|
||||
|
||||
// 4. 构建DeviceItem
|
||||
DevicePointDataList deviceItem = new DevicePointDataList();
|
||||
deviceItem.setDeviceId(deviceId);
|
||||
deviceItem.setParentDeviceId(parentDeviceId);
|
||||
deviceItem.setPointValueList(pointValueList);
|
||||
return deviceItem;
|
||||
return new DevicePointDataList(deviceId, pointValueList,parentDeviceId,
|
||||
stats.max, stats.min,stats.avg,stats.diff);
|
||||
})// 关键排序步骤:先按deviceId升序,再按parentDeviceId升序
|
||||
.sorted(
|
||||
Comparator.comparing(DevicePointDataList::getDeviceId) // 第一排序键:deviceId
|
||||
@ -232,15 +231,12 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 5. 构建SiteData
|
||||
GeneralQueryResponse site = new GeneralQueryResponse();
|
||||
site.setSiteId(siteId);
|
||||
site.setDeviceList(deviceList);
|
||||
return site;
|
||||
return new GeneralQueryResponse(siteId, deviceList, dataType);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<GeneralQueryResponse> convertCommonToResultList(List<GeneralQueryDataVo> dataVoList) {
|
||||
private List<GeneralQueryResponse> convertCommonToResultList(List<GeneralQueryDataVo> dataVoList, Long dataType) {
|
||||
// 数据转换: 先按siteId分组,再按deviceId分组
|
||||
return dataVoList.stream()
|
||||
// 第一层分组:按siteId分组,得到 <siteId, 该站点所有数据>
|
||||
@ -254,18 +250,46 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
List<DevicePointDataList> deviceList = siteAllData.stream()
|
||||
.collect(Collectors.groupingBy(GeneralQueryDataVo::getDeviceId))
|
||||
.entrySet().stream()
|
||||
.map(deviceEntry -> new DevicePointDataList(
|
||||
deviceEntry.getKey(),
|
||||
deviceEntry.getValue()
|
||||
))
|
||||
.map(deviceEntry -> {
|
||||
String deviceId = deviceEntry.getKey();
|
||||
List<GeneralQueryDataVo> deviceDataList = deviceEntry.getValue();
|
||||
|
||||
// 计算当前设备数据的统计值(最大,最小,平均,差值)
|
||||
Stats stats = clacStats(deviceDataList);
|
||||
|
||||
return new DevicePointDataList(deviceId, deviceDataList,null,
|
||||
stats.max, stats.min,stats.avg,stats.diff);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new GeneralQueryResponse(siteId, deviceList);
|
||||
return new GeneralQueryResponse(siteId, deviceList, dataType);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
private Stats clacStats(List<GeneralQueryDataVo> deviceDataList) {
|
||||
// 提取有效数值(过滤null)
|
||||
List<BigDecimal> values = deviceDataList.stream()
|
||||
.map(vo -> (BigDecimal) vo.getPointValue())
|
||||
.filter(value -> value != null) // 过滤null值
|
||||
.collect(Collectors.toList());
|
||||
if (values.isEmpty()) {
|
||||
return new Stats(null, null, null, null);
|
||||
}
|
||||
|
||||
// 计算最大最小值
|
||||
BigDecimal maxValue = values.stream().max(BigDecimal::compareTo).get();
|
||||
BigDecimal minValue = values.stream().min(BigDecimal::compareTo).get();
|
||||
// 计算平均值,四舍五入保留4为小数
|
||||
BigDecimal sum = values.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal avgValue = sum.divide(BigDecimal.valueOf(values.size()), 4, BigDecimal.ROUND_HALF_UP);
|
||||
// 增量数据,计算差值
|
||||
BigDecimal diff = maxValue.subtract(minValue);
|
||||
|
||||
return new Stats(maxValue,minValue,avgValue,diff);
|
||||
}
|
||||
|
||||
private void dealDataTime(PointNameRequest request) {
|
||||
String startDate = request.getStartDate();
|
||||
String endDate = request.getEndDate();
|
||||
@ -441,4 +465,21 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
|
||||
|
||||
return minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部辅助类:存储统计结果
|
||||
*/
|
||||
private static class Stats {
|
||||
private final BigDecimal max;
|
||||
private final BigDecimal min;
|
||||
private final BigDecimal avg;
|
||||
private final BigDecimal diff;
|
||||
|
||||
public Stats(BigDecimal max, BigDecimal min, BigDecimal avg, BigDecimal diff) {
|
||||
this.max = max;
|
||||
this.min = min;
|
||||
this.avg = avg;
|
||||
this.diff = diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +147,8 @@
|
||||
t.match_table as matchTable,
|
||||
t.match_field as matchField,
|
||||
t.device_category as deviceCategory,
|
||||
t.point_name as pointName
|
||||
t.point_name as pointName,
|
||||
t.data_type as dataType
|
||||
from ems_point_match t
|
||||
where 1=1
|
||||
<if test="siteIds != null and siteIds.size() > 0">
|
||||
|
||||
Reference in New Issue
Block a user