综合查询页面

This commit is contained in:
2025-09-05 20:31:30 +08:00
parent aa37e2a881
commit 2344cc458c
7 changed files with 423 additions and 85 deletions

View File

@ -9,7 +9,8 @@ public class DevicePointDataList
{
// 设备id
private String deviceId;
// 父类设备id
private String parentDeviceId;
// 该设备点位数据list
private List<GeneralQueryDataVo> pointValueList;
@ -18,6 +19,10 @@ public class DevicePointDataList
this.pointValueList = pointValueList;
}
public DevicePointDataList() {
}
public String getDeviceId() {
return deviceId;
}
@ -33,4 +38,12 @@ public class DevicePointDataList
public void setPointValueList(List<GeneralQueryDataVo> pointValueList) {
this.pointValueList = pointValueList;
}
public String getParentDeviceId() {
return parentDeviceId;
}
public void setParentDeviceId(String parentDeviceId) {
this.parentDeviceId = parentDeviceId;
}
}

View File

@ -12,6 +12,7 @@ public class GeneralQueryDataVo {
private String deviceId;
private String valueDate;
private Object pointValue;
private String parentDeviceId;
public String getSiteId() {
return siteId;
@ -44,4 +45,12 @@ public class GeneralQueryDataVo {
public void setPointValue(Object pointValue) {
this.pointValue = pointValue;
}
public String getParentDeviceId() {
return parentDeviceId;
}
public void setParentDeviceId(String parentDeviceId) {
this.parentDeviceId = parentDeviceId;
}
}

View File

@ -19,6 +19,10 @@ public class GeneralQueryResponse {
this.deviceList = deviceList;
}
public GeneralQueryResponse() {
}
public String getSiteId() {
return siteId;
}

View File

@ -73,25 +73,44 @@ public interface EmsPointMatchMapper
public List<EmsPointMatch> getMatchInfo(@Param("siteIds") List<String> siteIds,
@Param("deviceCategory")String deviceCategory,
@Param("pointName") String pointName);
// 根据条件查询数据-按分钟
public List<GeneralQueryDataVo> getPointDataListByMinutes(@Param("siteIds")List<String> siteIds,
// 根据条件查询数据-按分钟-单体电池特殊处理
public List<GeneralQueryDataVo> getBatteryPointDataByMinutes(@Param("siteIds")List<String> siteIds,
@Param("tableName")String tableName,
@Param("tableField")String tableField,
@Param("startDate")Date startDate,
@Param("endDate")Date endDate,
@Param("params") Map<String, List<String>> params);
// 根据条件查询数据-按小时
public List<GeneralQueryDataVo> getPointDataListByHours(@Param("siteIds")List<String> siteIds,
// 根据条件查询数据-按小时-单体电池特殊处理
public List<GeneralQueryDataVo> getBatteryPointDataByHours(@Param("siteIds")List<String> siteIds,
@Param("tableName")String tableName,
@Param("tableField")String tableField,
@Param("startDate") Date startDate,
@Param("endDate")Date endDate,
@Param("params") Map<String, List<String>> params);
// 根据条件查询数据-按天
public List<GeneralQueryDataVo> getPointDataListByDays(@Param("siteIds")List<String> siteIds,
// 根据条件查询数据-按天-单体电池特殊处理
public List<GeneralQueryDataVo> getBatteryPointDataByDays(@Param("siteIds")List<String> siteIds,
@Param("tableName")String tableName,
@Param("tableField")String tableField,
@Param("startDate")Date startDate,
@Param("endDate")Date endDate,
@Param("params") Map<String, List<String>> params);
@Param("params") Map<String, List<String>> params);
// 根据条件查询数据-按分钟-其他设备
public List<GeneralQueryDataVo> getCommonPointDataByMinutes(@Param("siteIds")List<String> siteIds,
@Param("tableName")String tableName,
@Param("tableField")String tableField,
@Param("startDate")Date startDate,
@Param("endDate")Date endDate);
// 根据条件查询数据-按小时-其他设备
public List<GeneralQueryDataVo> getCommonPointDataByHours(@Param("siteIds")List<String> siteIds,
@Param("tableName")String tableName,
@Param("tableField")String tableField,
@Param("startDate") Date startDate,
@Param("endDate")Date endDate);
// 根据条件查询数据-按天-其他设备
public List<GeneralQueryDataVo> getCommonPointDataByDays(@Param("siteIds")List<String> siteIds,
@Param("tableName")String tableName,
@Param("tableField")String tableField,
@Param("startDate")Date startDate,
@Param("endDate")Date endDate);
}

View File

@ -95,69 +95,175 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
}
}
// 单体电池特殊校验
Map<String,List<String>> siteDeviceMap = request.getSiteDeviceMap();
if (DeviceCategory.BATTERY.getCode().equals(deviceCategory) && (siteDeviceMap == null || siteDeviceMap.size() == 0)) {
return result;
}
// 处理时间范围,如果未传根据单位设默认值
// 处理时间范围,如果未传根据数据单位设默认值
dealDataTime(request);
int dataUnit = request.getDataUnit();
Date startDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,request.getStartDate());
Date endDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,request.getEndDate());
try {
// 不同的site_id根据设备类型和字段默认取第一个匹配到的表和表字段只会有一个
String tableName = matchInfo.get(0).getMatchTable();
String tableField = matchInfo.get(0).getMatchField();
List<GeneralQueryDataVo> dataVoList = new ArrayList<>();
if (dataUnit == 1) { // 分钟
dataVoList = emsPointMatchMapper.getPointDataListByMinutes(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap);
if (dataVoList != null && dataVoList.size() > 0) {
dataVoList = dealWithMinutesData(querySiteIds,dataVoList,deviceCategory,
request.getStartDate(),request.getEndDate(),siteDeviceMap);
}
} else if (dataUnit == 2) { // 小时
if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
// 单体电池特殊处理,已经提前按小时分表
tableName = "ems_battery_data_hour";
}
dataVoList = emsPointMatchMapper.getPointDataListByHours(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap);
} else if (dataUnit == 3) { // 天
if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
tableName = "ems_battery_data_day";
}
dataVoList = emsPointMatchMapper.getPointDataListByDays(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap);
if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
// 单体电池数据特殊处理
result = generalQueryBatteryData(querySiteIds,tableName,tableField,request,deviceCategory);
} else {
// 其他设备数据
result = generalQueryCommonData(querySiteIds,tableName,tableField,request,deviceCategory);
}
// 数据转换: 先按siteId分组再按deviceId分组
result = dataVoList.stream()
// 第一层分组按siteId分组得到 <siteId, 该站点所有数据>
.collect(Collectors.groupingBy(GeneralQueryDataVo::getSiteId))
.entrySet().stream()
.map(siteEntry -> {
String siteId = siteEntry.getKey();
List<GeneralQueryDataVo> siteAllData = siteEntry.getValue();
// 第二层分组在当前站点下按deviceId分组得到 <deviceId, 该设备所有数据>
List<DevicePointDataList> deviceList = siteAllData.stream()
.collect(Collectors.groupingBy(GeneralQueryDataVo::getDeviceId))
.entrySet().stream()
.map(deviceEntry -> new DevicePointDataList(
deviceEntry.getKey(),
deviceEntry.getValue()
))
.collect(Collectors.toList());
return new GeneralQueryResponse(siteId, deviceList);
})
.collect(Collectors.toList());
} catch (ParseException e) {
throw new RuntimeException(e);
}
return result;
}
private List<GeneralQueryResponse> generalQueryCommonData(List<String> querySiteIds,String tableName,
String tableField, PointNameRequest request,
String deviceCategory) throws ParseException {
List<GeneralQueryResponse> result = new ArrayList<>();
List<GeneralQueryDataVo> dataVoList = new ArrayList<>();
int dataUnit = request.getDataUnit();
Date startDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,request.getStartDate());
Date endDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,request.getEndDate());
if (dataUnit == 1) { // 分钟yyyy-MM-dd HH:mm:ss
startDate = DateUtils.adjustToStartOfMinutes(request.getStartDate());
dataVoList = emsPointMatchMapper.getCommonPointDataByMinutes(querySiteIds,tableName,tableField,startDate,endDate);
if (dataVoList != null && dataVoList.size() > 0) {
dataVoList = dealWithMinutesData(querySiteIds,dataVoList,deviceCategory,
request.getStartDate(),request.getEndDate());
}
} else if (dataUnit == 2) { // 小时yyyy-MM-dd HH:mm:ss
dataVoList = emsPointMatchMapper.getCommonPointDataByHours(querySiteIds,tableName,tableField,startDate,endDate);
} else if (dataUnit == 3) { // 天yyyy-MM-dd 00:00:00
endDate = DateUtils.adjustToEndOfDay(request.getEndDate());
dataVoList = emsPointMatchMapper.getCommonPointDataByDays(querySiteIds,tableName,tableField,startDate,endDate);
}
// 数据转换
result = convertCommonToResultList(dataVoList);
return result;
}
private List<GeneralQueryResponse> generalQueryBatteryData(List<String> querySiteIds,String tableName,
String tableField, PointNameRequest request,
String deviceCategory) throws ParseException {
List<GeneralQueryResponse> result = new ArrayList<>();
List<GeneralQueryDataVo> dataVoList = new ArrayList<>();
int dataUnit = request.getDataUnit();
Date startDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,request.getStartDate());
Date endDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,request.getEndDate());
Map<String,List<String>> siteDeviceMap = request.getSiteDeviceMap();
if (dataUnit == 1) { // 分钟
startDate = DateUtils.adjustToStartOfMinutes(request.getStartDate());
dataVoList = emsPointMatchMapper.getBatteryPointDataByMinutes(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap);
if (dataVoList != null && dataVoList.size() > 0) {
dataVoList = dealWithBatteryMinutesData(querySiteIds,dataVoList,deviceCategory,
request.getStartDate(),request.getEndDate(),siteDeviceMap);
}
} else if (dataUnit == 2) { // 小时
startDate = DateUtils.adjustToStartOfHour(request.getStartDate());
tableName = "ems_battery_data_hour";
dataVoList = emsPointMatchMapper.getBatteryPointDataByHours(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap);
} else if (dataUnit == 3) { // 天
endDate = DateUtils.adjustToEndOfDay(request.getEndDate());
tableName = "ems_battery_data_day";
dataVoList = emsPointMatchMapper.getBatteryPointDataByDays(querySiteIds,tableName,tableField,startDate,endDate,siteDeviceMap);
}
// 数据转换
result = convertBatteryToResultList(dataVoList);
return result;
}
private List<GeneralQueryResponse> convertBatteryToResultList(List<GeneralQueryDataVo> dataVoList) {
// 先按siteId分组
return dataVoList.stream()
.collect(Collectors.groupingBy(GeneralQueryDataVo::getSiteId))
.entrySet().stream()
.map(siteEntry -> {
String siteId = siteEntry.getKey();
List<GeneralQueryDataVo> siteData = siteEntry.getValue();
// 2. 按(deviceId + parentDeviceId)组合分组生成deviceList
List<DevicePointDataList> deviceList = siteData.stream()
// 分组键deviceId + parentDeviceId确保唯一设备
.collect(Collectors.groupingBy(data ->
data.getDeviceId() + "_" + data.getParentDeviceId()
))
.entrySet().stream()
.map(deviceEntry -> {
// 解析分组键获取deviceId和parentDeviceId
String[] keyParts = deviceEntry.getKey().split("_");
String deviceId = keyParts[0];
String parentDeviceId = keyParts[1];
// 3. 转换为PointValue列表
List<GeneralQueryDataVo> pointValueList = deviceEntry.getValue().stream()
.map(data -> {
GeneralQueryDataVo pv = new GeneralQueryDataVo();
pv.setSiteId(siteId);
pv.setDeviceId(deviceId);
pv.setValueDate(data.getValueDate());
pv.setPointValue(data.getPointValue());
pv.setParentDeviceId(parentDeviceId);
return pv;
})
.collect(Collectors.toList());
// 4. 构建DeviceItem
DevicePointDataList deviceItem = new DevicePointDataList();
deviceItem.setDeviceId(deviceId);
deviceItem.setParentDeviceId(parentDeviceId);
deviceItem.setPointValueList(pointValueList);
return deviceItem;
})// 关键排序步骤先按deviceId升序再按parentDeviceId升序
.sorted(
Comparator.comparing(DevicePointDataList::getDeviceId) // 第一排序键deviceId
.thenComparing(DevicePointDataList::getParentDeviceId) // 第二排序键parentDeviceId
)
.collect(Collectors.toList());
// 5. 构建SiteData
GeneralQueryResponse site = new GeneralQueryResponse();
site.setSiteId(siteId);
site.setDeviceList(deviceList);
return site;
})
.collect(Collectors.toList());
}
private List<GeneralQueryResponse> convertCommonToResultList(List<GeneralQueryDataVo> dataVoList) {
// 数据转换: 先按siteId分组再按deviceId分组
return dataVoList.stream()
// 第一层分组按siteId分组得到 <siteId, 该站点所有数据>
.collect(Collectors.groupingBy(GeneralQueryDataVo::getSiteId))
.entrySet().stream()
.map(siteEntry -> {
String siteId = siteEntry.getKey();
List<GeneralQueryDataVo> siteAllData = siteEntry.getValue();
// 第二层分组在当前站点下按deviceId分组得到 <deviceId, 该设备所有数据>
List<DevicePointDataList> deviceList = siteAllData.stream()
.collect(Collectors.groupingBy(GeneralQueryDataVo::getDeviceId))
.entrySet().stream()
.map(deviceEntry -> new DevicePointDataList(
deviceEntry.getKey(),
deviceEntry.getValue()
))
.collect(Collectors.toList());
return new GeneralQueryResponse(siteId, deviceList);
})
.collect(Collectors.toList());
}
private void dealDataTime(PointNameRequest request) {
String startDate = request.getStartDate();
String endDate = request.getEndDate();
@ -192,28 +298,22 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
}
private List<GeneralQueryDataVo> dealWithMinutesData(List<String> querySiteIds, List<GeneralQueryDataVo> dataVoList,
String deviceCategory, String startDate, String endDate, Map<String, List<String>> siteDeviceMap) throws ParseException {
String deviceCategory, String startDate, String endDate) throws ParseException {
List<GeneralQueryDataVo> fullData = new ArrayList<>();
Map<String, GeneralQueryDataVo> dataMap = new HashMap<>();
List<String> deviceIds = new ArrayList<>();
for (GeneralQueryDataVo data : dataVoList) {
String key = data.getSiteId() + "_" + data.getDeviceId() + "_" + data.getValueDate();
dataMap.put(key, data);
if (!deviceIds.contains(data.getDeviceId())) {
deviceIds.add(data.getDeviceId());
}
}
// 生成分钟序列
Set<String> minuteSeries = generateMinuteSeries(startDate, endDate);
// 遍历每个站点,动态获取该站点下的所有设备
// 遍历每个站点,查看设备
for (String siteId : querySiteIds) {
List<String> deviceIds = new ArrayList<>();
// 单体电池deviceId特殊处理
if (DeviceCategory.BATTERY.getCode().equals(deviceCategory) && (siteDeviceMap != null || siteDeviceMap.size() > 0)) {
deviceIds = siteDeviceMap.get(siteId);
} else {
deviceIds = emsDevicesSettingMapper.getDeviceIdsBySiteIdAndCategory(siteId,deviceCategory);
}
if (deviceIds.isEmpty()) {
continue; // 跳过无设备的站点
}
// 处理该站点下的所有设备
for (String deviceId : deviceIds) {
Object lastValue = null;
@ -228,7 +328,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
data.setValueDate(minute);
data.setSiteId(siteId);
data.setDeviceId(deviceId);
data.setPointValue(lastValue); // 用上一分钟值填充
data.setPointValue(lastValue==null? 0 : lastValue); // 用上一分钟值填充
} else {
lastValue = data.getPointValue(); // 更新最新值
}
@ -245,6 +345,64 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
return fullData;
}
private List<GeneralQueryDataVo> dealWithBatteryMinutesData(List<String> querySiteIds, List<GeneralQueryDataVo> dataVoList,
String deviceCategory, String startDate, String endDate,
Map<String, List<String>> siteDeviceMap) throws ParseException {
List<GeneralQueryDataVo> fullData = new ArrayList<>();
Map<String, GeneralQueryDataVo> dataMap = new HashMap<>();
List<String> clusterIds = new ArrayList<>();
for (GeneralQueryDataVo data : dataVoList) {
String key = data.getParentDeviceId() + "_" + data.getDeviceId() + "_" + data.getValueDate();
dataMap.put(key, data);
if (!clusterIds.contains(data.getParentDeviceId())) {
clusterIds.add(data.getParentDeviceId());
}
}
// 生成分钟序列
Set<String> minuteSeries = generateMinuteSeries(startDate, endDate);
Map<String, Object> lastValueMap = new HashMap<>();
String siteId = querySiteIds.get(0);
// 单站-先处理站点下的簇id
for (String clusterId : clusterIds) {
List<String> deviceIds = siteDeviceMap.get(siteId);
if (deviceIds.isEmpty()) {
continue;
}
for (String deviceId : deviceIds) {
String deviceKey = clusterId + "_" + deviceId;
for (String minute : minuteSeries) {
Object lastValue = lastValueMap.get(deviceKey);
String dataKey = clusterId + "_" + deviceId + "_" + minute;
GeneralQueryDataVo data = dataMap.get(dataKey);
// 空值填充逻辑
if (data == null) {
data = new GeneralQueryDataVo();
data.setValueDate(minute);
data.setSiteId(siteId);
data.setDeviceId(deviceId);
data.setParentDeviceId(clusterId);
data.setPointValue(lastValue == null ? 0 : lastValue); // 上一分钟数据不存在默认0
} else {
lastValueMap.put(deviceKey,data.getPointValue());// 更新最新值
}
fullData.add(data);
}
}
}
fullData.sort(Comparator.comparing(GeneralQueryDataVo::getValueDate)
.thenComparing(GeneralQueryDataVo::getSiteId)
.thenComparing(GeneralQueryDataVo::getDeviceId));
return fullData;
}
/**
* 根据前端传递的startDate和endDate生成所有分钟点的序列
* @param startDate 起始时间格式yyyy-MM-dd HH:mm:00
@ -256,7 +414,7 @@ public class GeneralQueryServiceImpl implements IGeneralQueryService
Set<String> minutes = new TreeSet<>(); // TreeSet保证时间有序
// 解析起止时间
startDate = DateUtils.adjustToNextMinute(startDate);
//startDate = DateUtils.adjustToNextMinute(startDate);
Date startTime = TIME_FORMAT.parse(startDate.substring(0, 16) + ":00");
Date endTime = TIME_FORMAT.parse(endDate.substring(0, 16) + ":00");

View File

@ -158,7 +158,74 @@
</choose>
</sql>
<select id="getPointDataListByMinutes" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
<select id="getBatteryPointDataByMinutes" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
SELECT DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:00') AS valueDate,
site_id as siteId,
device_id as deviceId,
cluster_device_id as parentDeviceId,
${tableField} as pointValue
FROM ${tableName}
WHERE create_time &gt;= #{startDate}
AND create_time &lt;= #{endDate}
AND ${tableField} is not null
<include refid="commonFilter"/>
GROUP BY valueDate, site_id, device_id,cluster_device_id,pointValue
ORDER BY site_id,device_id,cluster_device_id, valueDate ASC
</select>
<select id="getBatteryPointDataByHours" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
SELECT DATE_FORMAT(t.create_time, '%Y-%m-%d %H:00') AS valueDate,
t.site_id as siteId,
t.device_id as deviceId,
t.${tableField} as pointValue,
t.cluster_device_id as parentDeviceId,
t.create_time AS last_update_time
FROM ${tableName} t
INNER JOIN ( SELECT site_id, device_id, cluster_device_id,
DATE_FORMAT(create_time, '%Y-%m-%d %H:00') AS hour_group,
MAX(create_time) AS max_time
FROM ${tableName}
WHERE create_time &gt;= #{startDate}
AND create_time &lt;= #{endDate}
AND ${tableField} is not null
<include refid="commonFilter"/>
GROUP BY site_id, device_id,cluster_device_id, hour_group
) tmp ON t.site_id = tmp.site_id
AND t.device_id = tmp.device_id
AND t.cluster_device_id = tmp.cluster_device_id
AND DATE_FORMAT(t.create_time, '%Y-%m-%d %H:00') = tmp.hour_group
AND t.create_time = tmp.max_time
where ${tableField} is not null
ORDER BY t.site_id, t.device_id, t.cluster_device_id, valueDate ASC
</select>
<select id="getBatteryPointDataByDays" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
SELECT DATE_FORMAT(t.create_time, '%Y-%m-%d') AS valueDate,
t.site_id as siteId,
t.device_id as deviceId,
t.cluster_device_id as parentDeviceId,
t.${tableField} as pointValue,
t.create_time AS last_update_time
FROM ${tableName} t
INNER JOIN ( SELECT site_id, device_id, cluster_device_id,
DATE_FORMAT(create_time, '%Y-%m-%d') AS day_group,
MAX(create_time) AS max_time
FROM ${tableName}
WHERE create_time &gt;= #{startDate}
AND create_time &lt;= #{endDate}
AND ${tableField} is not null
<include refid="commonFilter"/>
GROUP BY site_id, device_id, cluster_device_id, day_group
) tmp ON t.site_id = tmp.site_id
AND t.device_id = tmp.device_id
AND t.cluster_device_id = tmp.cluster_device_id
AND DATE_FORMAT(t.create_time, '%Y-%m-%d') = tmp.day_group
AND t.create_time = tmp.max_time
WHERE t.${tableField} is not null
ORDER BY t.site_id, t.device_id, t.cluster_device_id, valueDate ASC
</select>
<select id="getCommonPointDataByMinutes" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
SELECT DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:00') AS valueDate,
site_id as siteId,
device_id as deviceId,
@ -167,12 +234,15 @@
WHERE create_time &gt;= #{startDate}
AND create_time &lt;= #{endDate}
AND ${tableField} is not null
<include refid="commonFilter"/>
GROUP BY valueDate, site_id, device_id,pointValue
ORDER BY site_id, valueDate ASC
AND site_id IN
<foreach collection="siteIds" item="siteId" open="(" close=")" separator=",">
#{siteId}
</foreach>
GROUP BY valueDate, site_id, device_id,pointValue
ORDER BY site_id,device_id, valueDate ASC
</select>
<select id="getPointDataListByHours" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
<select id="getCommonPointDataByHours" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
SELECT DATE_FORMAT(t.create_time, '%Y-%m-%d %H:00') AS valueDate,
t.site_id as siteId,
t.device_id as deviceId,
@ -181,12 +251,15 @@
FROM ${tableName} t
INNER JOIN ( SELECT site_id, device_id, DATE_FORMAT(create_time, '%Y-%m-%d %H:00') AS hour_group,
MAX(create_time) AS max_time
FROM ${tableName}
WHERE create_time &gt;= #{startDate}
AND create_time &lt; #{endDate}
FROM ${tableName}
WHERE create_time &gt;= #{startDate}
AND create_time &lt;= #{endDate}
AND ${tableField} is not null
<include refid="commonFilter"/>
GROUP BY site_id, device_id, hour_group
AND site_id IN
<foreach collection="siteIds" item="siteId" open="(" close=")" separator=",">
#{siteId}
</foreach>
GROUP BY site_id, device_id, hour_group
) tmp ON t.site_id = tmp.site_id
AND t.device_id = tmp.device_id
AND DATE_FORMAT(t.create_time, '%Y-%m-%d %H:00') = tmp.hour_group
@ -195,7 +268,7 @@
ORDER BY t.site_id, t.device_id, valueDate ASC
</select>
<select id="getPointDataListByDays" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
<select id="getCommonPointDataByDays" resultType="com.xzzn.ems.domain.vo.GeneralQueryDataVo">
SELECT DATE_FORMAT(t.create_time, '%Y-%m-%d') AS valueDate,
t.site_id as siteId,
t.device_id as deviceId,
@ -203,12 +276,15 @@
t.create_time AS last_update_time
FROM ${tableName} t
INNER JOIN ( SELECT site_id, device_id, DATE_FORMAT(create_time, '%Y-%m-%d') AS day_group,
MAX(create_time) AS max_time
FROM ${tableName}
WHERE create_time &gt;= #{startDate}
AND create_time &lt;= #{endDate}
AND ${tableField} is not null
<include refid="commonFilter"/>
MAX(create_time) AS max_time
FROM ${tableName}
WHERE create_time &gt;= #{startDate}
AND create_time &lt;= #{endDate}
AND ${tableField} is not null
AND site_id IN
<foreach collection="siteIds" item="siteId" open="(" close=")" separator=",">
#{siteId}
</foreach>
GROUP BY site_id, device_id, day_group
) tmp ON t.site_id = tmp.site_id
AND t.device_id = tmp.device_id