REM:
1. 解决空指针异常错误
This commit is contained in:
chenlinghy 2021-04-25 11:04:39 +08:00
parent d3271ef065
commit 1dd48cd195
2 changed files with 42 additions and 34 deletions

View File

@ -4,6 +4,7 @@ import com.dispose.common.DisposeCapacityType;
import com.dispose.common.ObjectStatus; import com.dispose.common.ObjectStatus;
import com.dispose.pojo.entity.DisposeCapacity; import com.dispose.pojo.entity.DisposeCapacity;
import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.AbilityInfo;
import com.dispose.service.AreaCodeManagerService; import com.dispose.service.AreaCodeManagerService;
import com.dispose.service.DisposeAbilityRouterService; import com.dispose.service.DisposeAbilityRouterService;
import com.dispose.service.DisposeDeviceManagerService; import com.dispose.service.DisposeDeviceManagerService;
@ -11,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -46,8 +48,8 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
public Map<Integer, List<DisposeDevice>> getAreaCodeGroup() { public Map<Integer, List<DisposeDevice>> getAreaCodeGroup() {
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice(); List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
return disposeDevices.stream() return disposeDevices.stream()
.filter(k -> k.getStatus() == ObjectStatus.NORMAL) .filter(k -> k.getStatus() == ObjectStatus.NORMAL)
.collect(Collectors.groupingBy(DisposeDevice::getAreaCode)); .collect(Collectors.groupingBy(DisposeDevice::getAreaCode));
} }
/** /**
@ -60,12 +62,12 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
public long getAreaCodeGroupReserveNetflow(Integer areaCode) { public long getAreaCodeGroupReserveNetflow(Integer areaCode) {
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice(); List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
return disposeDevices.stream() return disposeDevices.stream()
.filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL) .filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL)
.mapToLong(v -> v.getDevCapacity().stream() .mapToLong(v -> v.getDevCapacity().stream()
.filter(k -> k.getCapacityType() == DisposeCapacityType.CLEANUP) .filter(k -> k.getCapacityType() == DisposeCapacityType.CLEANUP)
.mapToLong(m -> Optional.ofNullable(m.getReserveNetflow()).orElse(0L)) .mapToLong(m -> Optional.ofNullable(m.getReserveNetflow()).orElse(0L))
.sum()) .sum())
.sum(); .sum();
} }
/** /**
@ -76,13 +78,20 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
*/ */
@Override @Override
public int getAreaCodeOnlineDeviceNum(Integer areaCode) { public int getAreaCodeOnlineDeviceNum(Integer areaCode) {
List<AbilityInfo> devs = new ArrayList<>();
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice(); List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
return (int) disposeDevices.stream()
.filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL) List<DisposeDevice> disDevs = disposeDevices.stream()
.filter(k -> disposeAbilityRouterService.getAbilityDevice(k.getId()) .filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL)
.getDb() .collect(Collectors.toList());
.getDeviceLinkStatus())
.count(); disDevs.forEach(v -> {
if (disposeAbilityRouterService.getAbilityDevice(v.getId()) != null) {
devs.add(disposeAbilityRouterService.getAbilityDevice(v.getId()));
}
});
return (int) devs.stream().filter(v -> v.getDb().getDeviceLinkStatus()).count();
} }
/** /**
@ -95,8 +104,8 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
public int getAreaCodeTotalDeviceNum(Integer areaCode) { public int getAreaCodeTotalDeviceNum(Integer areaCode) {
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice(); List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
return (int) disposeDevices.stream() return (int) disposeDevices.stream()
.filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL) .filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL)
.count(); .count();
} }
/** /**
@ -109,10 +118,10 @@ public class AreaCodeManagerServiceImpl implements AreaCodeManagerService {
public DisposeCapacityType[] getAreaCodeSupportCapacity(Integer areaCode) { public DisposeCapacityType[] getAreaCodeSupportCapacity(Integer areaCode) {
List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice(); List<DisposeDevice> disposeDevices = disposeDeviceManagerService.getAllDisposeDevice();
return disposeDevices.stream() return disposeDevices.stream()
.filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL) .filter(v -> v.getAreaCode().equals(areaCode) && v.getStatus() == ObjectStatus.NORMAL)
.flatMap(k -> k.getDevCapacity().stream() .flatMap(k -> k.getDevCapacity().stream()
.map(DisposeCapacity::getCapacityType)) .map(DisposeCapacity::getCapacityType))
.distinct() .distinct()
.toArray(DisposeCapacityType[]::new); .toArray(DisposeCapacityType[]::new);
} }
} }

View File

@ -104,11 +104,11 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
Collections.addAll(usedId, CommonEnvironment.commonIdFilter); Collections.addAll(usedId, CommonEnvironment.commonIdFilter);
return TestCaseRun.getAllTestCase().stream() return TestCaseRun.getAllTestCase().stream()
.filter(k -> k.getCaseJsonValue() != null && k.getCaseJsonValue().length() > 0) .filter(k -> k.getCaseJsonValue() != null && k.getCaseJsonValue().length() > 0)
.filter(k -> usedId.size() == 0 || usedId.stream().anyMatch(v -> Objects.equals(v, k.getId()))) .filter(k -> usedId.size() == 0 || usedId.stream().anyMatch(v -> Objects.equals(v, k.getId())))
.filter(k -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v)) .filter(k -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v))
//.filter(k -> k.getId() >= 1300) //.filter(k -> k.getId() == 700)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/** /**
@ -120,20 +120,19 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
public void runQaJsonTestCase() throws Exception { public void runQaJsonTestCase() throws Exception {
log.info("[{}] Run json test: ({}) [{}] '{}' {} ", rspObject.getPriority(), rspObject.getId(), log.info("[{}] Run json test: ({}) [{}] '{}' {} ", rspObject.getPriority(), rspObject.getId(),
rspObject.getMethod(), rspObject.getUrlPath(), rspObject.getName()); rspObject.getMethod(), rspObject.getUrlPath(), rspObject.getName());
if (rspObject.getPrepareCallback() != null) { if (rspObject.getPrepareCallback() != null) {
rspObject.getPrepareCallback().prepareCallback(this); rspObject.getPrepareCallback().prepareCallback(this);
} }
ProtocolRespDTO<? extends BaseRespStatus> o = performanceRestful(rspObject.getCaseJsonValue(), ProtocolRespDTO<? extends BaseRespStatus> o = performanceRestful(rspObject.getCaseJsonValue(),
rspObject.getUrlPath(), rspObject.getUrlPath(),
rspObject.getRspClass(), rspObject.getRspClass(),
rspObject.getRspCode(), rspObject.getRspCode(),
rspObject.getAutoLogin() ? getLoginToken() : rspObject.getAutoLogin() ? getLoginToken() : "",
"", true,
true, rspObject.getMethod());
rspObject.getMethod());
Assert.assertNotNull(o); Assert.assertNotNull(o);