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

View File

@ -104,11 +104,11 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
Collections.addAll(usedId, CommonEnvironment.commonIdFilter);
return TestCaseRun.getAllTestCase().stream()
.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 -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v))
//.filter(k -> k.getId() >= 1300)
.collect(Collectors.toList());
.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 -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v))
//.filter(k -> k.getId() == 700)
.collect(Collectors.toList());
}
/**
@ -120,20 +120,19 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
public void runQaJsonTestCase() throws Exception {
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) {
rspObject.getPrepareCallback().prepareCallback(this);
}
ProtocolRespDTO<? extends BaseRespStatus> o = performanceRestful(rspObject.getCaseJsonValue(),
rspObject.getUrlPath(),
rspObject.getRspClass(),
rspObject.getRspCode(),
rspObject.getAutoLogin() ? getLoginToken() :
"",
true,
rspObject.getMethod());
rspObject.getUrlPath(),
rspObject.getRspClass(),
rspObject.getRspCode(),
rspObject.getAutoLogin() ? getLoginToken() : "",
true,
rspObject.getMethod());
Assert.assertNotNull(o);