mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
admin服务列表在线/离线筛选(在线靠前)
This commit is contained in:
@@ -1,24 +1,16 @@
|
||||
package com.gitee.sop.registryapi.bean;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Data
|
||||
public class ServiceInfo {
|
||||
/** 服务名称 */
|
||||
private String serviceId;
|
||||
/** 实例列表 */
|
||||
private List<ServiceInstance> instances = Collections.emptyList();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "服务名称: " + serviceId + ", 实例数:" + instances.size();
|
||||
}
|
||||
private List<ServiceInstance> instances;
|
||||
}
|
||||
|
@@ -18,6 +18,8 @@ import org.springframework.util.CollectionUtils;
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -51,7 +53,9 @@ public class RegistryServiceNacos implements RegistryService {
|
||||
ServiceInfo serviceInfo = new ServiceInfo();
|
||||
serviceInfo.setServiceId(serviceName);
|
||||
List<Instance> instanceList = namingService.getAllInstances(serviceName);
|
||||
if (!CollectionUtils.isEmpty(instanceList)) {
|
||||
if (CollectionUtils.isEmpty(instanceList)) {
|
||||
serviceInfo.setInstances(Collections.emptyList());
|
||||
} else {
|
||||
serviceInfo.setInstances(new ArrayList<>(instanceList.size()));
|
||||
for (Instance instance : instanceList) {
|
||||
ServiceInstance serviceInstance = new ServiceInstance();
|
||||
@@ -68,6 +72,7 @@ public class RegistryServiceNacos implements RegistryService {
|
||||
}
|
||||
serviceInfoList.add(serviceInfo);
|
||||
}
|
||||
serviceInfoList.sort(Comparator.comparingInt(o -> o.getInstances().size()));
|
||||
return serviceInfoList;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user