统计逻辑修改

This commit is contained in:
dy
2025-09-06 01:14:38 +08:00
parent e70e245cdd
commit c565114c4c
2 changed files with 39 additions and 16 deletions

View File

@@ -58,7 +58,7 @@ public class IndexCountVo {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor(access = AccessLevel.PRIVATE)
public static class StatusChartVo { public static class StatusChartVo {
private String type; // 类型名称(如:维修、咨询 private String state; // 使用状态(如:使用中,停用中,已报废,闲置中
private Integer quantity; // 数量 private Integer quantity; // 数量
public static StatusChartVoBuilder builder() { public static StatusChartVoBuilder builder() {
@@ -66,11 +66,11 @@ public class IndexCountVo {
} }
public static class StatusChartVoBuilder { public static class StatusChartVoBuilder {
private String type; private String state;
private Integer quantity; private Integer quantity;
public StatusChartVoBuilder type(String type) { public StatusChartVoBuilder state(String state) {
this.type = type; this.state = state;
return this; return this;
} }
@@ -80,7 +80,7 @@ public class IndexCountVo {
} }
public StatusChartVo build() { public StatusChartVo build() {
return new StatusChartVo(type, quantity); return new StatusChartVo(state, quantity);
} }
} }
} }

View File

@@ -74,6 +74,17 @@ public class IndexServiceImpl implements IndexService {
//查询设备各状态数量 //查询设备各状态数量
List<IndexCountVo.StatusChartVo> statusChartVos = new ArrayList<>(); List<IndexCountVo.StatusChartVo> statusChartVos = new ArrayList<>();
indexCountVo.setStatusChartVoChartList(statusChartVos);
//查询设备总数
List<Machine> machineList = machineMapper.selectList();
//查询设备各状态数量
List<IndexCountVo.StatusChartVo> machineStatusChartVos = calculateMachineTypeDistribution(machineList);
statusChartVos.addAll(machineStatusChartVos);
indexCountVo.setStatusChartVoChartList(statusChartVos);
//查询各种工单状态
return indexCountVo; return indexCountVo;
} }
// 计算工单类型分布 // 计算工单类型分布
@@ -104,21 +115,33 @@ public class IndexServiceImpl implements IndexService {
// 计算设备类型分布 // 计算设备类型分布
private List<IndexCountVo.StatusChartVo> calculateMachineTypeDistribution(List<Machine> machinesList) { private List<IndexCountVo.StatusChartVo> calculateMachineTypeDistribution(List<Machine> machinesList) {
// 按 typeId 分组统计数量 // // 按 typeId 分组统计数量
Map<Long, Long> machineTypeCounts = machinesList.stream() // Map<Long, Long> machineTypeCounts = machinesList.stream()
.collect(Collectors.groupingBy(Machine::getMachineTypeId, Collectors.counting())); // .collect(Collectors.groupingBy(Machine::getMachineTypeId, Collectors.counting()));
List<IndexCountVo.StatusChartVo> result = new ArrayList<>(); List<IndexCountVo.StatusChartVo> result = new ArrayList<>();
for (Map.Entry<Long, Long> entry : machineTypeCounts.entrySet()) { // for (Map.Entry<Long, Long> entry : machineTypeCounts.entrySet()) {
Long typeId = entry.getKey(); // Long typeId = entry.getKey();
Integer count = entry.getValue().intValue(); // Integer count = entry.getValue().intValue();
//
// // 查询类型名称
// MachineType machineType = machineTypeMapper.selectById(typeId);
// String type = machineType != null ? machineType.getMachineTypeName() : "未知类型";
// // 添加到结果中
// result.add(IndexCountVo.StatusChartVo.builder()
// .type(type)
// .quantity(count)
// .build());
// }
// 查询类型名称 //计算状态分布
MachineType machineType = machineTypeMapper.selectById(typeId); Map<String, Long> machineStateCounts = machinesList.stream()
String type = machineType != null ? machineType.getMachineTypeName() : "未知类型"; .collect(Collectors.groupingBy(Machine::getState, Collectors.counting()));
// 添加到结果中 for (Map.Entry<String, Long> entry : machineStateCounts.entrySet()) {
String state = entry.getKey();
Integer count = entry.getValue().intValue();
result.add(IndexCountVo.StatusChartVo.builder() result.add(IndexCountVo.StatusChartVo.builder()
.type(type) .state(state)
.quantity(count) .quantity(count)
.build()); .build());
} }