优化逻辑
This commit is contained in:
parent
72267a9c9b
commit
2ba0005426
@ -15,11 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
@ -40,55 +38,74 @@ public class DeviceWorkDataController {
|
||||
private IDeviceWorkDataService deviceWorkDataService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页查询变电站辅控设备告警记录")
|
||||
public ResponseResult getDeviceWorkDataPage(Page<DeviceWorkData> page, String stationId, String startDate,
|
||||
@ApiOperation("分页查询变电站设备运行记录")
|
||||
public ResponseResult getDeviceWorkDataPage(Page<DeviceWorkData> page, String signalId, String startDate,
|
||||
String endDate) {
|
||||
Page<DeviceWorkData> deviceWorkDataPage = deviceWorkDataService.getDeviceWorkDataPage(page, stationId,
|
||||
Page<DeviceWorkData> deviceWorkDataPage = deviceWorkDataService.getDeviceWorkDataPage(page, signalId,
|
||||
startDate, endDate);
|
||||
return ResponseResult.successData(deviceWorkDataPage);
|
||||
}
|
||||
|
||||
public List<DeviceWorkData> processMinuteDataOptimized(List<DeviceWorkData> deviceWorkDataList) {
|
||||
return null;
|
||||
public Map<String, Object> processDeviceData(List<DeviceWorkData> deviceWorkDataList) {
|
||||
// 生成过去60分钟的分钟时间槽
|
||||
LocalDateTime now = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
|
||||
LocalDateTime startTime = now.minusMinutes(59);
|
||||
List<LocalDateTime> minuteSlots = new ArrayList<>();
|
||||
for (int i = 0; i < 60; i++) {
|
||||
minuteSlots.add(startTime.plusMinutes(i));
|
||||
}
|
||||
|
||||
// 按分钟分组数据
|
||||
Map<LocalDateTime, BigDecimal> minuteDataMap = new HashMap<>();
|
||||
for (DeviceWorkData data : deviceWorkDataList) {
|
||||
LocalDateTime minuteKey = data.getStartTime().truncatedTo(ChronoUnit.MINUTES);
|
||||
minuteDataMap.put(minuteKey, data.getValue());
|
||||
}
|
||||
|
||||
// 构建xAxis和series数据
|
||||
List<String> xAxisData = new ArrayList<>();
|
||||
List<Double> seriesData = new ArrayList<>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH分mm秒");
|
||||
for (LocalDateTime slot : minuteSlots) {
|
||||
xAxisData.add(slot.format(formatter));
|
||||
BigDecimal value = minuteDataMap.getOrDefault(slot, BigDecimal.ZERO);
|
||||
seriesData.add(value.doubleValue());
|
||||
}
|
||||
|
||||
// 构建ECharts数据结构
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
Map<String, Object> xAxis = new HashMap<>();
|
||||
xAxis.put("type", "category");
|
||||
xAxis.put("data", xAxisData);
|
||||
result.put("xAxis", xAxis);
|
||||
|
||||
Map<String, Object> yAxis = new HashMap<>();
|
||||
yAxis.put("type", "value");
|
||||
result.put("yAxis", yAxis);
|
||||
|
||||
List<Map<String, Object>> seriesList = new ArrayList<>();
|
||||
Map<String, Object> series = new HashMap<>();
|
||||
series.put("name", "Step Start");
|
||||
series.put("type", "line");
|
||||
series.put("step", "start");
|
||||
series.put("data", seriesData);
|
||||
seriesList.add(series);
|
||||
|
||||
// 如果需要多个系列,可以继续添加
|
||||
// 例如复制series并修改name和step
|
||||
|
||||
result.put("series", seriesList);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/getHistoricalCurve")
|
||||
@ApiOperation("查询历史曲线")
|
||||
public ResponseResult getHistoricalCurve(String stationId, String type) {
|
||||
List<DeviceWorkData> deviceWorkDataList = deviceWorkDataService.getHistoricalCurve(stationId);
|
||||
|
||||
Map<String, Object> historicalCurve = new HashMap<>();
|
||||
historicalCurve.put("xAxis", JSONUtil.parseObj("{\n" +
|
||||
" type: 'category',\n" +
|
||||
" data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']\n" +
|
||||
" }"));
|
||||
|
||||
historicalCurve.put("yAxis", JSONUtil.parseObj("{\n" +
|
||||
" type: 'value'\n" +
|
||||
" }"));
|
||||
|
||||
historicalCurve.put("series", JSONUtil.parseArray("[\n" +
|
||||
" {\n" +
|
||||
" name: 'Step Start',\n" +
|
||||
" type: 'line',\n" +
|
||||
" step: 'start',\n" +
|
||||
" data: [120, 132, 101, 134, 90, 230, 210]\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" name: 'Step Middle',\n" +
|
||||
" type: 'line',\n" +
|
||||
" step: 'middle',\n" +
|
||||
" data: [220, 282, 201, 234, 290, 430, 410]\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" name: 'Step End',\n" +
|
||||
" type: 'line',\n" +
|
||||
" step: 'end',\n" +
|
||||
" data: [450, 432, 401, 454, 590, 530, 510]\n" +
|
||||
" }\n" +
|
||||
" ]"));
|
||||
|
||||
return ResponseResult.successData(historicalCurve);
|
||||
public ResponseResult getHistoricalCurve(String signalId, String type) {
|
||||
List<DeviceWorkData> deviceWorkDataList = deviceWorkDataService.getHistoricalCurve(signalId);
|
||||
Map<String, Object> map = processDeviceData(deviceWorkDataList);
|
||||
return ResponseResult.successData(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@ -40,6 +42,7 @@ public class DeviceAlarmRecord implements Serializable {
|
||||
/**
|
||||
* 告警时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime alarmTime;
|
||||
|
||||
/**
|
||||
@ -135,6 +138,7 @@ public class DeviceAlarmRecord implements Serializable {
|
||||
/**
|
||||
* 故障消除时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime fixTime;
|
||||
|
||||
/**
|
||||
@ -155,6 +159,7 @@ public class DeviceAlarmRecord implements Serializable {
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime operationTime;
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,8 @@ import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@ -60,6 +62,7 @@ public class DeviceWorkData implements Serializable {
|
||||
/**
|
||||
* 采集时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
|
@ -16,9 +16,9 @@ import java.util.List;
|
||||
*/
|
||||
public interface DeviceWorkDataMapper extends BaseMapper<DeviceWorkData> {
|
||||
|
||||
Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page,String stationId, String startDate, String endDate);
|
||||
Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page,String signalId, String startDate, String endDate);
|
||||
|
||||
List<DeviceWorkData> getHistoricalCurve(String stationId);
|
||||
List<DeviceWorkData> getHistoricalCurve(String signalId);
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ public interface IDeviceWorkDataService extends IService<DeviceWorkData> {
|
||||
***********************************/
|
||||
void insertData(String from, String slave_ip, String address, String value, String dateTimeString);
|
||||
|
||||
Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page,String stationId, String startDate, String endDate);
|
||||
Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page,String signalId, String startDate, String endDate);
|
||||
|
||||
List<DeviceWorkData> getHistoricalCurve(String stationId);
|
||||
List<DeviceWorkData> getHistoricalCurve(String signalId);
|
||||
|
||||
}
|
||||
|
@ -72,13 +72,13 @@ public class DeviceWorkDataServiceImpl extends ServiceImpl<DeviceWorkDataMapper,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page,String stationId, String startDate, String endDate) {
|
||||
return deviceWorkDataMapper.getDeviceWorkDataPage(page,stationId,startDate,endDate);
|
||||
public Page<DeviceWorkData> getDeviceWorkDataPage(Page<DeviceWorkData> page,String signalId, String startDate, String endDate) {
|
||||
return deviceWorkDataMapper.getDeviceWorkDataPage(page,signalId,startDate,endDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceWorkData> getHistoricalCurve(String stationId) {
|
||||
return deviceWorkDataMapper.getHistoricalCurve(stationId);
|
||||
public List<DeviceWorkData> getHistoricalCurve(String signalId) {
|
||||
return deviceWorkDataMapper.getHistoricalCurve(signalId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -106,6 +106,7 @@
|
||||
fgd.ip_addr,
|
||||
fgd.Protocol,
|
||||
fgd.frequency,
|
||||
fgd.device_name,
|
||||
fgd.device_type
|
||||
FROM
|
||||
fk_device_signal fds
|
||||
|
@ -15,7 +15,7 @@
|
||||
FROM
|
||||
fk_device_work_data
|
||||
WHERE 1=1
|
||||
AND station_id=#{stationId}
|
||||
AND signal_id=#{signalId}
|
||||
<if test="startDate != null and startDate != ''">
|
||||
AND start_time >= #{startDate}
|
||||
</if>
|
||||
@ -33,7 +33,7 @@
|
||||
FROM
|
||||
fk_device_work_data
|
||||
WHERE
|
||||
station_id=#{stationId}
|
||||
signal_id=#{signalId}
|
||||
AND start_time >= NOW() - INTERVAL 1 HOUR
|
||||
ORDER BY
|
||||
start_time DESC
|
||||
|
Loading…
Reference in New Issue
Block a user