REM:
1. 判断相关接口中入参是否为数字类型,如果非数字类型(如"adb"),则修改返回结果为设备不存在,而不是参数异常
This commit is contained in:
chenlinghy 2020-05-28 09:44:28 +08:00
parent 096eea083b
commit f2fc1bfd90
1 changed files with 152 additions and 89 deletions

View File

@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
@ -94,7 +95,6 @@ public class DisposeNodeInfoController {
if (reqInfo.getId().length == 0) {
List<DisposeDevice> devs = disposeNodeManager.getAllDisposeDevice();
if (devs != null && devs.size() > 0) {
devs.forEach(v -> linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(v.getLinkStatus())
@ -105,22 +105,32 @@ public class DisposeNodeInfoController {
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(dev.getLinkStatus())
.id(dev.getId().toString())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build());
} else {
log.error("device not exist, deviceId:{}", v);
if (!StringUtils.isNumeric(v)) {
log.error("id params type error, deviceId:{}", v);
linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(0)
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
} else {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(dev.getLinkStatus())
.id(dev.getId().toString())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build());
} else {
log.error("device not exist, deviceId:{}", v);
linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(0)
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
}
}
}
}
@ -170,21 +180,30 @@ public class DisposeNodeInfoController {
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
versionListRsp.getItems().add(VersionRsp.builder()
.id(dev.getId().toString())
.version(dev.getVersion())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build());
} else {
log.error("device not exist, deviceId:{}", v);
if (!StringUtils.isNumeric(v)) {
log.error("id params type error, deviceId:{}", v);
versionListRsp.getItems().add(VersionRsp.builder()
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
} else {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
versionListRsp.getItems().add(VersionRsp.builder()
.id(dev.getId().toString())
.version(dev.getVersion())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build());
} else {
log.error("device not exist, deviceId:{}", v);
versionListRsp.getItems().add(VersionRsp.builder()
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
}
}
}
}
@ -242,23 +261,28 @@ public class DisposeNodeInfoController {
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v)) && dev.getDevInfo() != null) {
rspInfo.getItems().add(new DeviceInfoData(dev.getId().toString(),
dev.getDevInfo().getVendor(),
dev.getDevInfo().getModel(),
dev.getDevInfo().getFirmware(),
dev.getDevInfo().getOs(),
dev.getDevInfo().getKernel(),
dev.getDevInfo().getArch(),
dev.getDevInfo().getMemory(),
dev.getDevInfo().getFreeMemory(),
dev.getDevInfo().getCpuUsed(),
ErrorCode.ERR_OK
));
} else {
log.error("device not exist, deviceId:{}", v);
if (!StringUtils.isNumeric(v)) {
log.error("id params type error, deviceId:{}", v);
rspInfo.getItems().add(new DeviceInfoData(v, ErrorCode.ERR_NOSUCHDEVICE));
} else {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v)) && dev.getDevInfo() != null) {
rspInfo.getItems().add(new DeviceInfoData(dev.getId().toString(),
dev.getDevInfo().getVendor(),
dev.getDevInfo().getModel(),
dev.getDevInfo().getFirmware(),
dev.getDevInfo().getOs(),
dev.getDevInfo().getKernel(),
dev.getDevInfo().getArch(),
dev.getDevInfo().getMemory(),
dev.getDevInfo().getFreeMemory(),
dev.getDevInfo().getCpuUsed(),
ErrorCode.ERR_OK
));
} else {
log.error("device not exist, deviceId:{}", v);
rspInfo.getItems().add(new DeviceInfoData(v, ErrorCode.ERR_NOSUCHDEVICE));
}
}
}
}
@ -310,20 +334,29 @@ public class DisposeNodeInfoController {
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DeviceCapacityData cpData = new DeviceCapacityData(dev.getDevCaps());
cpData.setId(dev.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
} else {
log.error("device not exist, deviceId:{}", v);
if (!StringUtils.isNumeric(v)) {
log.error("id params type error, deviceId:{}", v);
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(cpData);
} else {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DeviceCapacityData cpData = new DeviceCapacityData(dev.getDevCaps());
cpData.setId(dev.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
} else {
log.error("device not exist, deviceId:{}", v);
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(cpData);
}
}
}
}
@ -379,20 +412,29 @@ public class DisposeNodeInfoController {
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DeviceCapacityData cpData = new DeviceCapacityData(dev.getDevCaps());
cpData.setId(dev.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
} else {
log.error("device not exist, deviceId:{}", v);
if (!StringUtils.isNumeric(v)) {
log.error("id params type error, deviceId:{}", v);
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(cpData);
} else {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DeviceCapacityData cpData = new DeviceCapacityData(dev.getDevCaps());
cpData.setId(dev.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
} else {
log.error("device not exist, deviceId:{}", v);
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(cpData);
}
}
}
}
@ -459,27 +501,37 @@ public class DisposeNodeInfoController {
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DisposeNodeData dpData = DisposeNodeData.builder()
.type(dev.getType())
.name(dev.getName())
.ip(dev.getIpAddr())
.build();
dpData.setId(dev.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
} else {
log.error("device not exist, deviceId:{}", v);
if (!StringUtils.isNumeric(v)) {
log.error("id params error, error:{}", v);
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(dpData);
} else {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DisposeNodeData dpData = DisposeNodeData.builder()
.type(dev.getType())
.name(dev.getName())
.ip(dev.getIpAddr())
.build();
dpData.setId(dev.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
} else {
log.error("device not exist, deviceId:{}", v);
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(dpData);
}
}
}
}
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}
@ -537,30 +589,39 @@ public class DisposeNodeInfoController {
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DisposeNodeData dpData = new DisposeNodeData(
dev.getType(),
dev.getName(),
dev.getIpAddr(),
dev.getAreaCode(),
dev.getManufacturer(),
dev.getModel(),
dev.getVersion(),
dev.getReadme(),
dev.getDevCaps()
);
dpData.setId(dev.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
} else {
log.error("device not exist, deviceId:{}", v);
if (!StringUtils.isNumeric(v)) {
log.error("id params type error, deviceId:{}", v);
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(dpData);
} else {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DisposeNodeData dpData = new DisposeNodeData(
dev.getType(),
dev.getName(),
dev.getIpAddr(),
dev.getAreaCode(),
dev.getManufacturer(),
dev.getModel(),
dev.getVersion(),
dev.getReadme(),
dev.getDevCaps()
);
dpData.setId(dev.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
} else {
log.error("device not exist, deviceId:{}", v);
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(dpData);
}
}
}
}
@ -636,7 +697,8 @@ public class DisposeNodeInfoController {
if (reqInfo.getId().length != 0) {
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.filter(v -> (!StringUtils.isNumeric(v) || v.length() == 0)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
@ -722,7 +784,8 @@ public class DisposeNodeInfoController {
if (reqInfo.getId().length != 0) {
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.filter(v -> (!StringUtils.isNumeric(v) || v.length() == 0)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {