REM:
1. Fix import checkstyle error
2. 更改实体类数据类型为包装类
3. 更改获取节点信息接口请求参数验证逻辑
This commit is contained in:
HuangXin 2020-05-28 19:36:24 +08:00
parent 59cec3860a
commit 286d511469
3 changed files with 296 additions and 382 deletions

View File

@ -1,12 +1,10 @@
package com.dispose.controller;
import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode;
import com.dispose.common.Helper;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.vo.common.DisposeCapacity;
import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.common.TaskInfoData;
import com.dispose.pojo.vo.common.TaskInfoDetail;
@ -25,7 +23,6 @@ import com.dispose.pojo.vo.information.VersionRsp;
import com.dispose.service.DisposeNodeManager;
import com.dispose.service.TaskService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@ -85,57 +82,47 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
LinkStatusListRsp linkStatusListRsp = new LinkStatusListRsp();
linkStatusListRsp.setItems(new ArrayList<>());
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
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())
.id(v.getId().toString())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build()));
}
} else {
for (String v : reqInfo.getId()) {
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());
}
}
}
}
LinkStatusListRsp rspInfo = new LinkStatusListRsp();
rspInfo.setItems(new ArrayList<>());
return ProtocolRespDTO.result(ErrorCode.ERR_OK, linkStatusListRsp);
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.forEach(v -> rspInfo.getItems().add(LinkStatusRsp.builder()
.online(v.getLinkStatus())
.id(v.getId().toString())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build()));
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
rspInfo.getItems().add(LinkStatusRsp.builder()
.online(0)
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
});
return ProtocolRespDTO.result(err, rspInfo);
}
/**
@ -160,55 +147,45 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
VersionListRsp versionListRsp = new VersionListRsp();
versionListRsp.setItems(new ArrayList<>());
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
if (reqInfo.getId().length == 0) {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
if (devList != null && devList.size() > 0) {
devList.forEach(v -> versionListRsp.getItems().add(VersionRsp.builder()
.id(v.getId().toString())
.version(v.getVersion())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build()));
}
} else {
for (String v : reqInfo.getId()) {
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());
}
}
}
}
VersionListRsp rspInfo = new VersionListRsp();
rspInfo.setItems(new ArrayList<>());
return ProtocolRespDTO.result(ErrorCode.ERR_OK, versionListRsp);
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.forEach(v -> rspInfo.getItems().add(VersionRsp.builder()
.id(v.getId().toString())
.version(v.getVersion())
.status(ErrorCode.ERR_OK.getCode())
.message(ErrorCode.ERR_OK.getMsg())
.build()));
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
rspInfo.getItems().add(VersionRsp.builder()
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
});
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}
/**
@ -233,59 +210,46 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
DeviceInfoRsp rspInfo = new DeviceInfoRsp();
rspInfo.setItems(new ArrayList<>());
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
if (reqInfo.getId().length == 0) {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
DeviceInfoRsp rspInfo = new DeviceInfoRsp();
rspInfo.setItems(new ArrayList<>());
if (devList != null && devList.size() > 0) {
devList.forEach(v -> rspInfo.getItems().add(new DeviceInfoData(
v.getId().toString(),
v.getDevInfo().getVendor(),
v.getDevInfo().getModel(),
v.getDevInfo().getFirmware(),
v.getDevInfo().getOs(),
v.getDevInfo().getKernel(),
v.getDevInfo().getArch(),
v.getDevInfo().getMemory(),
v.getDevInfo().getFreeMemory(),
v.getDevInfo().getCpuUsed(),
ErrorCode.ERR_OK
)));
}
} else {
for (String v : reqInfo.getId()) {
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));
}
}
}
}
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.forEach(v -> rspInfo.getItems().add(new DeviceInfoData(
v.getId().toString(),
v.getDevInfo().getVendor(),
v.getDevInfo().getModel(),
v.getDevInfo().getFirmware(),
v.getDevInfo().getOs(),
v.getDevInfo().getKernel(),
v.getDevInfo().getArch(),
v.getDevInfo().getMemory(),
v.getDevInfo().getFreeMemory(),
v.getDevInfo().getCpuUsed(),
ErrorCode.ERR_OK
)));
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
rspInfo.getItems().add(new DeviceInfoData(v, ErrorCode.ERR_NOSUCHDEVICE));
});
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}
@ -312,60 +276,49 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
DeviceCapacityRsp rspInfo = new DeviceCapacityRsp();
rspInfo.setItems(new ArrayList<>());
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
if (reqInfo.getId().length == 0) {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
DeviceCapacityRsp rspInfo = new DeviceCapacityRsp();
rspInfo.setItems(new ArrayList<>());
if (devList != null && devList.size() > 0) {
devList.forEach(v -> {
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
cpData.setId(v.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
});
}
} else {
for (String v : reqInfo.getId()) {
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);
}
}
}
}
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
String rspMessage = new ObjectMapper()
.writerWithView(DisposeCapacity.CapacityView.class)
.writeValueAsString(rspInfo);
valuableData.forEach(v -> {
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
cpData.setId(v.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
});
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspMessage, ConstValue.Protocol.CRYPTO_NONE);
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setCapacity(null);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(cpData);
});
return ProtocolRespDTO.result(err, rspInfo);
}
/**
@ -390,59 +343,48 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
DeviceCapacityRsp rspInfo = new DeviceCapacityRsp();
rspInfo.setItems(new ArrayList<>());
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
if (reqInfo.getId().length == 0) {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
DeviceCapacityRsp rspInfo = new DeviceCapacityRsp();
rspInfo.setItems(new ArrayList<>());
if (devList != null && devList.size() > 0) {
devList.forEach(v -> {
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
cpData.setId(v.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
});
}
} else {
for (String v : reqInfo.getId()) {
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);
}
}
}
}
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
String rspMessage = new ObjectMapper().writerWithView(DisposeCapacity.DependIpView.class)
.writeValueAsString(rspInfo);
valuableData.forEach(v -> {
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
cpData.setId(v.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(cpData);
});
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspMessage, ConstValue.Protocol.CRYPTO_NONE);
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setCapacity(null);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(cpData);
});
return ProtocolRespDTO.result(err, rspInfo);
}
/**
@ -472,67 +414,55 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
DisposeNodeListRsp rspInfo = new DisposeNodeListRsp();
rspInfo.setItems(new ArrayList<>());
for (String deviceId : reqInfo.getId()
) {
if (deviceId == null || deviceId.length() == 0) {
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.forEach(v -> {
DisposeNodeData dpData = DisposeNodeData.builder()
.type(v.getType())
.name(v.getName())
.ip(v.getIpAddr())
.build();
dpData.setId(v.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
});
if (reqInfo.getId().length != 0) {
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
dpData.setCapacity(null);
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(dpData);
});
}
if (reqInfo.getId().length == 0) {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
if (devList != null && devList.size() > 0) {
devList.forEach(v -> {
DisposeNodeData dpData = DisposeNodeData.builder()
.type(v.getType())
.name(v.getName())
.ip(v.getIpAddr())
.build();
dpData.setId(v.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
});
}
} else {
for (String v : reqInfo.getId()) {
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);
return ProtocolRespDTO.result(err, rspInfo);
}
/**
@ -557,75 +487,52 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
DisposeNodeListRsp rspInfo = new DisposeNodeListRsp();
rspInfo.setItems(new ArrayList<>());
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
if (reqInfo.getId().length == 0) {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
DisposeNodeListRsp rspInfo = new DisposeNodeListRsp();
rspInfo.setItems(new ArrayList<>());
if (devList != null && devList.size() > 0) {
devList.forEach(v -> {
DisposeNodeData dpData = new DisposeNodeData(
v.getType(),
v.getName(),
v.getIpAddr(),
v.getAreaCode(),
v.getManufacturer(),
v.getModel(),
v.getVersion(),
v.getReadme(),
v.getDevCaps()
);
dpData.setId(v.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
});
}
} else {
for (String v : reqInfo.getId()) {
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);
}
}
}
}
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.forEach(v -> {
DisposeNodeData dpData = new DisposeNodeData(
v.getType(), v.getName(), v.getIpAddr(),
v.getAreaCode(), v.getManufacturer(), v.getModel(),
v.getVersion(), v.getReadme(), v.getDevCaps());
dpData.setId(v.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems().add(dpData);
});
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
dpData.setCapacity(null);
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems().add(dpData);
});
return ProtocolRespDTO.result(err, rspInfo);
}
/**
@ -650,16 +557,18 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
NodeTaskRsp rspInfo = new NodeTaskRsp();
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
NodeTaskRsp rspInfo = new NodeTaskRsp();
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
@ -695,21 +604,21 @@ public class DisposeNodeInfoController {
}
});
if (reqInfo.getId().length != 0) {
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> (!StringUtils.isNumeric(v) || v.length() == 0)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
});
}
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
taskData.setTaskArray(null);
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
});
return ProtocolRespDTO.result(err, rspInfo);
}
@ -736,16 +645,18 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
NodeTaskRsp rspInfo = new NodeTaskRsp();
if (Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
if (reqInfo.getId() == null || Arrays.stream(reqInfo.getId()).anyMatch(Objects::isNull)) {
log.error("Request params error, error:{}", mr.getMsgContent());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
NodeTaskRsp rspInfo = new NodeTaskRsp();
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| reqInfo.getId()[0].length() == 0
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
@ -782,21 +693,21 @@ public class DisposeNodeInfoController {
}
});
if (reqInfo.getId().length != 0) {
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> (!StringUtils.isNumeric(v) || v.length() == 0)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
List<String> unExists = Arrays.stream(reqInfo.getId())
.filter(v -> v.length() > 0)
.filter(v -> !StringUtils.isNumeric(v)
|| valuableData.stream().noneMatch(k -> k.getId() == Long.parseLong(v)))
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
});
}
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
taskData.setTaskArray(null);
taskData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
});
return ProtocolRespDTO.result(err, rspInfo);
}

View File

@ -25,7 +25,7 @@ import java.util.List;
@JsonPropertyOrder({"id", "type", "name", "ip", "areaCode", "manufacturer", "model", "version", "readme", "status",
"message"})
public class DisposeNodeData extends DeviceCapacityData {
private int type;
private Integer type;
private String name;
private String ip;
private Integer areaCode;

View File

@ -1,7 +1,10 @@
package com.dispose.pojo.vo.task;
import com.dispose.pojo.vo.common.IDArrayReq;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* The type Get task req.