添加类型
This commit is contained in:
parent
14ee33aecd
commit
c0172fda51
@ -21,6 +21,12 @@ import jakarta.annotation.Resource;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/scenario-results")
|
@RequestMapping("/scenario-results")
|
||||||
@ -71,6 +77,28 @@ public class ScenarioResultController {
|
|||||||
}
|
}
|
||||||
Page<ScenarioResult> page = new Page<>(pageNum, pageSize);
|
Page<ScenarioResult> page = new Page<>(pageNum, pageSize);
|
||||||
Page<ScenarioResult> data = scenarioResultService.page(page, qw.orderByAsc("step").orderByAsc("device_id"));
|
Page<ScenarioResult> data = scenarioResultService.page(page, qw.orderByAsc("step").orderByAsc("device_id"));
|
||||||
|
List<ScenarioResult> records = data.getRecords();
|
||||||
|
if (records != null && !records.isEmpty()) {
|
||||||
|
Set<String> deviceIds = records.stream()
|
||||||
|
.map(ScenarioResult::getDeviceId)
|
||||||
|
.filter(id -> id != null && !id.isBlank())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
if (!deviceIds.isEmpty()) {
|
||||||
|
List<Device> devices = deviceService.list(new QueryWrapper<Device>()
|
||||||
|
.select("device_id", "name", "type")
|
||||||
|
.in("device_id", deviceIds));
|
||||||
|
Map<String, Device> deviceMap = devices.stream()
|
||||||
|
.filter(d -> d.getDeviceId() != null && !d.getDeviceId().isBlank())
|
||||||
|
.collect(Collectors.toMap(Device::getDeviceId, d -> d, (a, b) -> a));
|
||||||
|
for (ScenarioResult r : records) {
|
||||||
|
Device d = deviceMap.get(r.getDeviceId());
|
||||||
|
if (d != null) {
|
||||||
|
r.setDeviceName(d.getName());
|
||||||
|
r.setDeviceType(d.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return ResponseEntity.ok(java.util.Map.of(
|
return ResponseEntity.ok(java.util.Map.of(
|
||||||
"code", 0,
|
"code", 0,
|
||||||
"msg", "查询成功",
|
"msg", "查询成功",
|
||||||
@ -121,6 +149,21 @@ public class ScenarioResultController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<ScenarioResult> results = scenarioResultService.list(queryWrapper.orderByAsc("device_id").orderByAsc("step"));
|
List<ScenarioResult> results = scenarioResultService.list(queryWrapper.orderByAsc("device_id").orderByAsc("step"));
|
||||||
|
Set<String> deviceIds = results.stream()
|
||||||
|
.map(ScenarioResult::getDeviceId)
|
||||||
|
.filter(id -> id != null && !id.isBlank())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
Map<String, Device> deviceMap;
|
||||||
|
if (deviceIds.isEmpty()) {
|
||||||
|
deviceMap = java.util.Map.of();
|
||||||
|
} else {
|
||||||
|
List<Device> devices = deviceService.list(new QueryWrapper<Device>()
|
||||||
|
.select("device_id", "name", "type")
|
||||||
|
.in("device_id", deviceIds));
|
||||||
|
deviceMap = devices.stream()
|
||||||
|
.filter(d -> d.getDeviceId() != null && !d.getDeviceId().isBlank())
|
||||||
|
.collect(Collectors.toMap(Device::getDeviceId, d -> d, (a, b) -> a));
|
||||||
|
}
|
||||||
|
|
||||||
// 创建Excel工作簿
|
// 创建Excel工作簿
|
||||||
Workbook workbook = new XSSFWorkbook();
|
Workbook workbook = new XSSFWorkbook();
|
||||||
@ -149,11 +192,12 @@ public class ScenarioResultController {
|
|||||||
dataStyle.setWrapText(true);
|
dataStyle.setWrapText(true);
|
||||||
|
|
||||||
// 创建表头
|
// 创建表头
|
||||||
String[] headers = {"场景名称", "设备名称", "时点", "属性值", "Keff值"};
|
String[] headers = {"场景名称", "设备名称", "设备类型", "时点", "属性值", "Keff值"};
|
||||||
|
|
||||||
if (deviceId != null && !deviceId.isEmpty()) {
|
if (deviceId != null && !deviceId.isEmpty()) {
|
||||||
Device dev = deviceService.getById(deviceId);
|
Device dev = deviceMap.get(deviceId);
|
||||||
String deviceName = dev != null && dev.getName() != null ? dev.getName() : deviceId;
|
String deviceName = dev != null && dev.getName() != null ? dev.getName() : deviceId;
|
||||||
|
String deviceType = dev != null && dev.getType() != null ? dev.getType() : "";
|
||||||
Sheet sheet = workbook.createSheet(deviceName);
|
Sheet sheet = workbook.createSheet(deviceName);
|
||||||
Row headerRow = sheet.createRow(0);
|
Row headerRow = sheet.createRow(0);
|
||||||
for (int i = 0; i < headers.length; i++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
@ -171,14 +215,17 @@ public class ScenarioResultController {
|
|||||||
cell1.setCellValue(deviceName);
|
cell1.setCellValue(deviceName);
|
||||||
cell1.setCellStyle(dataStyle);
|
cell1.setCellStyle(dataStyle);
|
||||||
Cell cell2 = row.createCell(2);
|
Cell cell2 = row.createCell(2);
|
||||||
cell2.setCellValue(result.getStep());
|
cell2.setCellValue(deviceType);
|
||||||
cell2.setCellStyle(dataStyle);
|
cell2.setCellStyle(dataStyle);
|
||||||
Cell cell3 = row.createCell(3);
|
Cell cell3 = row.createCell(3);
|
||||||
cell3.setCellValue(result.getAttrState());
|
cell3.setCellValue(result.getStep());
|
||||||
cell3.setCellStyle(dataStyle);
|
cell3.setCellStyle(dataStyle);
|
||||||
Cell cell4 = row.createCell(4);
|
Cell cell4 = row.createCell(4);
|
||||||
cell4.setCellValue(result.getKeffValue() == null ? 0.0 : result.getKeffValue().doubleValue());
|
cell4.setCellValue(result.getAttrState());
|
||||||
cell4.setCellStyle(dataStyle);
|
cell4.setCellStyle(dataStyle);
|
||||||
|
Cell cell5 = row.createCell(5);
|
||||||
|
cell5.setCellValue(result.getKeffValue() == null ? 0.0 : result.getKeffValue().doubleValue());
|
||||||
|
cell5.setCellStyle(dataStyle);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < headers.length; i++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
sheet.autoSizeColumn(i);
|
sheet.autoSizeColumn(i);
|
||||||
@ -196,8 +243,9 @@ public class ScenarioResultController {
|
|||||||
}
|
}
|
||||||
for (java.util.Map.Entry<String, java.util.List<ScenarioResult>> entry : byDevice.entrySet()) {
|
for (java.util.Map.Entry<String, java.util.List<ScenarioResult>> entry : byDevice.entrySet()) {
|
||||||
String did = entry.getKey();
|
String did = entry.getKey();
|
||||||
Device dev = deviceService.getById(did);
|
Device dev = deviceMap.get(did);
|
||||||
String deviceName = dev != null && dev.getName() != null ? dev.getName() : did;
|
String deviceName = dev != null && dev.getName() != null ? dev.getName() : did;
|
||||||
|
String deviceType = dev != null && dev.getType() != null ? dev.getType() : "";
|
||||||
Sheet sheet = workbook.createSheet(deviceName);
|
Sheet sheet = workbook.createSheet(deviceName);
|
||||||
Row headerRow = sheet.createRow(0);
|
Row headerRow = sheet.createRow(0);
|
||||||
for (int i = 0; i < headers.length; i++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
@ -215,14 +263,17 @@ public class ScenarioResultController {
|
|||||||
cell1.setCellValue(deviceName);
|
cell1.setCellValue(deviceName);
|
||||||
cell1.setCellStyle(dataStyle);
|
cell1.setCellStyle(dataStyle);
|
||||||
Cell cell2 = row.createCell(2);
|
Cell cell2 = row.createCell(2);
|
||||||
cell2.setCellValue(result.getStep());
|
cell2.setCellValue(deviceType);
|
||||||
cell2.setCellStyle(dataStyle);
|
cell2.setCellStyle(dataStyle);
|
||||||
Cell cell3 = row.createCell(3);
|
Cell cell3 = row.createCell(3);
|
||||||
cell3.setCellValue(result.getAttrState());
|
cell3.setCellValue(result.getStep());
|
||||||
cell3.setCellStyle(dataStyle);
|
cell3.setCellStyle(dataStyle);
|
||||||
Cell cell4 = row.createCell(4);
|
Cell cell4 = row.createCell(4);
|
||||||
cell4.setCellValue(result.getKeffValue() == null ? 0.0 : result.getKeffValue().doubleValue());
|
cell4.setCellValue(result.getAttrState());
|
||||||
cell4.setCellStyle(dataStyle);
|
cell4.setCellStyle(dataStyle);
|
||||||
|
Cell cell5 = row.createCell(5);
|
||||||
|
cell5.setCellValue(result.getKeffValue() == null ? 0.0 : result.getKeffValue().doubleValue());
|
||||||
|
cell5.setCellStyle(dataStyle);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < headers.length; i++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
sheet.autoSizeColumn(i);
|
sheet.autoSizeColumn(i);
|
||||||
|
|||||||
@ -27,4 +27,10 @@ public class ScenarioResult implements Serializable {
|
|||||||
|
|
||||||
@TableField("keff_value")
|
@TableField("keff_value")
|
||||||
private BigDecimal keffValue;
|
private BigDecimal keffValue;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String deviceName;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String deviceType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,9 +22,10 @@ file-space:
|
|||||||
model-path: D:/keff_dataSpace/models/
|
model-path: D:/keff_dataSpace/models/
|
||||||
dataset-path: D:/keff_dataSpace/datasets/
|
dataset-path: D:/keff_dataSpace/datasets/
|
||||||
upload-path: D:/keff_dataSpace/upload/
|
upload-path: D:/keff_dataSpace/upload/
|
||||||
|
# 安全配置 生产环境需要关闭permit
|
||||||
security:
|
security:
|
||||||
dev:
|
dev:
|
||||||
permit: true
|
permit: false
|
||||||
# 注释掉这里的 file.name,由 logback-spring.xml 接管,防止覆盖
|
# 注释掉这里的 file.name,由 logback-spring.xml 接管,防止覆盖
|
||||||
# logging:
|
# logging:
|
||||||
# file:
|
# file:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user