[monitor]feature dashboard仪表盘重构 (#13)
This commit is contained in:
@@ -55,11 +55,11 @@ public interface MonitorDao extends JpaRepository<Monitor, Long>, JpaSpecificati
|
||||
Optional<Monitor> findMonitorByNameEquals(String name);
|
||||
|
||||
/**
|
||||
* 查询监控类别及其对应的监控数量
|
||||
* @return 监控类别与监控数量映射
|
||||
* 查询监控类别-状态对应的监控数量
|
||||
* @return 监控类别-状态与监控数量映射
|
||||
*/
|
||||
@Query("select new com.usthe.manager.pojo.dto.AppCount(mo.app, COUNT(mo.id)) from Monitor mo group by mo.app")
|
||||
List<AppCount> findAppsCount();
|
||||
@Query("select new com.usthe.manager.pojo.dto.AppCount(mo.app, mo.status, COUNT(mo.id)) from Monitor mo group by mo.app, mo.status")
|
||||
List<AppCount> findAppsStatusCount();
|
||||
|
||||
/**
|
||||
* 更新指定监控的状态
|
||||
|
||||
@@ -12,8 +12,43 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class AppCount {
|
||||
/**监控类型**/
|
||||
|
||||
public AppCount(String app, byte status, Long size) {
|
||||
this.app = app;
|
||||
this.status = status;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* 监控大类别
|
||||
*/
|
||||
private String category;
|
||||
/**
|
||||
* 监控类型
|
||||
*/
|
||||
private String app;
|
||||
/**监控数量**/
|
||||
private Long size;
|
||||
/**
|
||||
* 监控状态
|
||||
*/
|
||||
private transient byte status;
|
||||
/**
|
||||
* 监控数量
|
||||
*/
|
||||
private long size;
|
||||
/**
|
||||
* 监控状态可用的数量
|
||||
*/
|
||||
private long availableSize;
|
||||
/**
|
||||
* 监控状态未管理的数量
|
||||
*/
|
||||
private long unManageSize;
|
||||
/**
|
||||
* 监控状态不可用的数量
|
||||
*/
|
||||
private long unAvailableSize;
|
||||
/**
|
||||
* 监控状态不可达的数量
|
||||
*/
|
||||
private long unReachableSize;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -379,8 +380,40 @@ public class MonitorServiceImpl implements MonitorService {
|
||||
|
||||
@Override
|
||||
public List<AppCount> getAllAppMonitorsCount() {
|
||||
return monitorDao.findAppsCount();
|
||||
|
||||
List<AppCount> appCounts = monitorDao.findAppsStatusCount();
|
||||
if (appCounts == null) {
|
||||
return null;
|
||||
}
|
||||
// 关联大类别信息 计算每个状态对应数量
|
||||
Map<String, AppCount> appCountMap = new HashMap<>(appCounts.size());
|
||||
for (AppCount item : appCounts) {
|
||||
AppCount appCount = appCountMap.getOrDefault(item.getApp(), new AppCount());
|
||||
appCount.setApp(item.getApp());
|
||||
switch (item.getStatus()) {
|
||||
case CommonConstants.AVAILABLE_CODE:
|
||||
appCount.setAvailableSize(appCount.getAvailableSize() + item.getSize());
|
||||
break;
|
||||
case CommonConstants.UN_AVAILABLE_CODE:
|
||||
appCount.setUnAvailableSize(appCount.getUnAvailableSize() + item.getSize());
|
||||
break;
|
||||
case CommonConstants.UN_MANAGE_CODE:
|
||||
appCount.setUnManageSize(appCount.getUnManageSize() + item.getSize());
|
||||
break;
|
||||
case CommonConstants.UN_REACHABLE_CODE:
|
||||
appCount.setUnReachableSize(appCount.getUnReachableSize() + item.getSize());
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
appCountMap.put(item.getApp(), appCount);
|
||||
}
|
||||
return appCountMap.values().stream().peek(item -> {
|
||||
item.setSize(item.getAvailableSize() + item.getUnManageSize()
|
||||
+ item.getUnReachableSize() + item.getUnAvailableSize());
|
||||
Job job = appService.getAppDefine(item.getApp());
|
||||
if (job != null) {
|
||||
item.setCategory(job.getCategory());
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user