dev #2

Merged
dashixiong merged 349 commits from dev into main 2026-02-11 01:55:46 +00:00
260 changed files with 31548 additions and 1055 deletions
Showing only changes of commit 4ad2cafc5d - Show all commits

View File

@ -9,7 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* *
@ -29,12 +31,15 @@ public class EmsGeneralQueryController extends BaseController{
@GetMapping("/getAllDeviceCategory") @GetMapping("/getAllDeviceCategory")
public AjaxResult getDeviceCategory() public AjaxResult getDeviceCategory()
{ {
// 获取所有枚举的中文信息 // 获取所有枚举的信息
List<String> deviceCategoryName = new ArrayList<>(); List<Map<String, String>> deviceCategoryList = new ArrayList<>();
for (DeviceCategory category : DeviceCategory.values()) { 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 { try {
result = iGeneralQueryService.getPointValueList(request); result = iGeneralQueryService.getPointValueList(request);
} catch (Exception e) { } catch (Exception e) {
logger.error("<UNK>",e);
return error("报错请重试!"); return error("报错请重试!");
} }
return success(result); return success(result);

View File

@ -142,7 +142,7 @@ public class EmsSiteConfigController extends BaseController{
} }
/** /**
* 单个站点单个设备点位查询 * 单个站点单个设备点位查询-点位清单
*/ */
@GetMapping("/getDevicePointList") @GetMapping("/getDevicePointList")
public TableDataInfo getDevicePointList(@Validated PointDataRequest request) public TableDataInfo getDevicePointList(@Validated PointDataRequest request)

View File

@ -21,7 +21,7 @@ public enum DeviceCategory
COOLING("COOLING", "冷却", null), COOLING("COOLING", "冷却", null),
DH("DH", "动环", null), DH("DH", "动环", null),
XF("XF", "消防", null), XF("XF", "消防", null),
BATTERY_GROUP("BATTERY_GROUP", "电池组", null),; BATTERY_GROUP("BATTERY_GROUP", "电池组", null);
private final String code; private final String code;
private final String info; private final String info;

View File

@ -1,5 +1,6 @@
package com.xzzn.ems.domain.vo; package com.xzzn.ems.domain.vo;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@ -13,10 +14,25 @@ public class DevicePointDataList
private String parentDeviceId; private String parentDeviceId;
// 该设备点位数据list // 该设备点位数据list
private List<GeneralQueryDataVo> pointValueList; 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.deviceId = deviceId;
this.pointValueList = pointValueList; this.pointValueList = pointValueList;
this.parentDeviceId = parentDeviceId;
this.maxValue = maxValue;
this.minValue = minValue;
this.avgValue = avgValue;
this.diffValue = diffValue;
} }
public DevicePointDataList() { public DevicePointDataList() {
@ -46,4 +62,36 @@ public class DevicePointDataList
public void setParentDeviceId(String parentDeviceId) { public void setParentDeviceId(String parentDeviceId) {
this.parentDeviceId = 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;
}
} }

View File

@ -14,9 +14,13 @@ public class GeneralQueryResponse {
// 设备数据 // 设备数据
private List<DevicePointDataList> deviceList; 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.siteId = siteId;
this.deviceList = deviceList; this.deviceList = deviceList;
this.dataType = dataType;
} }
public GeneralQueryResponse() { public GeneralQueryResponse() {
@ -38,4 +42,12 @@ public class GeneralQueryResponse {
public void setDeviceList(List<DevicePointDataList> deviceList) { public void setDeviceList(List<DevicePointDataList> deviceList) {
this.deviceList = deviceList; this.deviceList = deviceList;
} }
public Long getDataType() {
return dataType;
}
public void setDataType(Long dataType) {
this.dataType = dataType;
}
} }

View File

@ -11,7 +11,7 @@ public class PointNameRequest {
private List<String> siteIds; private List<String> siteIds;
private String categoryName; private String deviceCategory;
private String pointName; private String pointName;
@ -34,12 +34,12 @@ public class PointNameRequest {
this.siteIds = siteIds; this.siteIds = siteIds;
} }
public String getCategoryName() { public String getDeviceCategory() {
return categoryName; return deviceCategory;
} }
public void setCategoryName(String categoryName) { public void setDeviceCategory(String deviceCategory) {
this.categoryName = categoryName; this.deviceCategory = deviceCategory;
} }
public String getPointName() { public String getPointName() {

View File

@ -11,6 +11,7 @@ import com.xzzn.ems.service.IGeneralQueryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -42,8 +43,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
return Collections.emptyList(); return Collections.emptyList();
} }
String categoryName = request.getCategoryName(); String deviceCategory = request.getDeviceCategory();
String deviceCategory = DeviceCategory.getCodeByInfo(categoryName);
if (deviceCategory == null) { if (deviceCategory == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -83,8 +83,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
List<String> querySiteIds = new ArrayList<>(); List<String> querySiteIds = new ArrayList<>();
List<String> siteIds = request.getSiteIds(); List<String> siteIds = request.getSiteIds();
String categoryName = request.getCategoryName(); String deviceCategory = request.getDeviceCategory();
String deviceCategory = DeviceCategory.getCodeByInfo(categoryName);
// 根据入参获取点位对应的表和字段 // 根据入参获取点位对应的表和字段
List<EmsPointMatch> matchInfo = emsPointMatchMapper.getMatchInfo(siteIds,deviceCategory,request.getPointName()); List<EmsPointMatch> matchInfo = emsPointMatchMapper.getMatchInfo(siteIds,deviceCategory,request.getPointName());
if (matchInfo == null || matchInfo.size() == 0) { if (matchInfo == null || matchInfo.size() == 0) {
@ -108,13 +107,13 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
// 不同的site_id根据设备类型和字段默认取第一个匹配到的表和表字段只会有一个 // 不同的site_id根据设备类型和字段默认取第一个匹配到的表和表字段只会有一个
String tableName = matchInfo.get(0).getMatchTable(); String tableName = matchInfo.get(0).getMatchTable();
String tableField = matchInfo.get(0).getMatchField(); String tableField = matchInfo.get(0).getMatchField();
Long dataType = matchInfo.get(0).getDataType();
if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) { if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
// 单体电池数据特殊处理 // 单体电池数据特殊处理
result = generalQueryBatteryData(querySiteIds,tableName,tableField,request,deviceCategory); result = generalQueryBatteryData(querySiteIds,tableName,tableField,request,deviceCategory,dataType);
} else { } else {
// 其他设备数据 // 其他设备数据
result = generalQueryCommonData(querySiteIds,tableName,tableField,request,deviceCategory); result = generalQueryCommonData(querySiteIds,tableName,tableField,request,deviceCategory,dataType);
} }
} catch (ParseException e) { } catch (ParseException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -122,9 +121,9 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
return result; 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 tableField, PointNameRequest request,
String deviceCategory) throws ParseException { String deviceCategory, Long dataType) throws ParseException {
List<GeneralQueryResponse> result = new ArrayList<>(); List<GeneralQueryResponse> result = new ArrayList<>();
List<GeneralQueryDataVo> dataVoList = 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); dataVoList = emsPointMatchMapper.getCommonPointDataByDays(querySiteIds,tableName,tableField,startDate,endDate,deviceId);
} }
// 数据转换 // 数据转换+计算曲线数据最大最小平均和差值
result = convertCommonToResultList(dataVoList); result = convertCommonToResultList(dataVoList, dataType);
return result; 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 tableField, PointNameRequest request,
String deviceCategory) throws ParseException { String deviceCategory, Long dataType) throws ParseException {
List<GeneralQueryResponse> result = new ArrayList<>(); List<GeneralQueryResponse> result = new ArrayList<>();
List<GeneralQueryDataVo> dataVoList = 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); dataVoList = emsPointMatchMapper.getBatteryPointDataByDays(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap,clusterDeviceId);
} }
// 数据转换 // 数据转换
result = convertBatteryToResultList(dataVoList); result = convertBatteryToResultList(dataVoList,dataType);
return result; return result;
} }
private List<GeneralQueryResponse> convertBatteryToResultList(List<GeneralQueryDataVo> dataVoList) { private List<GeneralQueryResponse> convertBatteryToResultList(List<GeneralQueryDataVo> dataVoList, Long dataType) {
// 先按siteId分组 // 先按siteId分组
return dataVoList.stream() return dataVoList.stream()
.collect(Collectors.groupingBy(GeneralQueryDataVo::getSiteId)) .collect(Collectors.groupingBy(GeneralQueryDataVo::getSiteId))
@ -218,12 +217,12 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
// 4. 计算最大最小平均值
Stats stats = clacStats(pointValueList);
// 4. 构建DeviceItem // 4. 构建DeviceItem
DevicePointDataList deviceItem = new DevicePointDataList(); return new DevicePointDataList(deviceId, pointValueList,parentDeviceId,
deviceItem.setDeviceId(deviceId); stats.max, stats.min,stats.avg,stats.diff);
deviceItem.setParentDeviceId(parentDeviceId);
deviceItem.setPointValueList(pointValueList);
return deviceItem;
})// 关键排序步骤先按deviceId升序再按parentDeviceId升序 })// 关键排序步骤先按deviceId升序再按parentDeviceId升序
.sorted( .sorted(
Comparator.comparing(DevicePointDataList::getDeviceId) // 第一排序键deviceId Comparator.comparing(DevicePointDataList::getDeviceId) // 第一排序键deviceId
@ -232,15 +231,12 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
.collect(Collectors.toList()); .collect(Collectors.toList());
// 5. 构建SiteData // 5. 构建SiteData
GeneralQueryResponse site = new GeneralQueryResponse(); return new GeneralQueryResponse(siteId, deviceList, dataType);
site.setSiteId(siteId);
site.setDeviceList(deviceList);
return site;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private List<GeneralQueryResponse> convertCommonToResultList(List<GeneralQueryDataVo> dataVoList) { private List<GeneralQueryResponse> convertCommonToResultList(List<GeneralQueryDataVo> dataVoList, Long dataType) {
// 数据转换: 先按siteId分组再按deviceId分组 // 数据转换: 先按siteId分组再按deviceId分组
return dataVoList.stream() return dataVoList.stream()
// 第一层分组按siteId分组得到 <siteId, 该站点所有数据> // 第一层分组按siteId分组得到 <siteId, 该站点所有数据>
@ -254,18 +250,46 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
List<DevicePointDataList> deviceList = siteAllData.stream() List<DevicePointDataList> deviceList = siteAllData.stream()
.collect(Collectors.groupingBy(GeneralQueryDataVo::getDeviceId)) .collect(Collectors.groupingBy(GeneralQueryDataVo::getDeviceId))
.entrySet().stream() .entrySet().stream()
.map(deviceEntry -> new DevicePointDataList( .map(deviceEntry -> {
deviceEntry.getKey(), String deviceId = deviceEntry.getKey();
deviceEntry.getValue() 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()); .collect(Collectors.toList());
return new GeneralQueryResponse(siteId, deviceList); return new GeneralQueryResponse(siteId, deviceList, dataType);
}) })
.collect(Collectors.toList()); .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) { private void dealDataTime(PointNameRequest request) {
String startDate = request.getStartDate(); String startDate = request.getStartDate();
String endDate = request.getEndDate(); String endDate = request.getEndDate();
@ -441,4 +465,21 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
return minutes; 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;
}
}
} }

View File

@ -147,7 +147,8 @@
t.match_table as matchTable, t.match_table as matchTable,
t.match_field as matchField, t.match_field as matchField,
t.device_category as deviceCategory, 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 from ems_point_match t
where 1=1 where 1=1
<if test="siteIds != null and siteIds.size() > 0"> <if test="siteIds != null and siteIds.size() > 0">