REM:
1. 删除无效变量,优化代码
This commit is contained in:
HuangXin 2020-05-14 17:47:21 +08:00
parent 44e3c6e284
commit 41029fd9c3
2 changed files with 85 additions and 165 deletions

View File

@ -59,12 +59,6 @@ public class DisposeNodeInfoController {
@Resource
private TaskService taskService;
/**
* The Object mapper.
*/
@Resource
private ObjectMapper objectMapper;
/**
* The Dispose node manager.
*/
@ -102,8 +96,7 @@ public class DisposeNodeInfoController {
List<DisposeDevice> devs = disposeNodeManager.getAllDisposeDevice();
if (devs != null && devs.size() > 0) {
devs.forEach(v -> linkStatusListRsp.getItems()
.add(LinkStatusRsp.builder()
devs.forEach(v -> linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(v.getLinkStatus())
.id(v.getId().toString())
.status(ErrorCode.ERR_OK.getCode())
@ -113,23 +106,20 @@ 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());
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 {
linkStatusListRsp.getItems()
.add(LinkStatusRsp.builder()
.online(0)
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg()).
build());
linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(0)
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
}
}
}
@ -158,7 +148,6 @@ public class DisposeNodeInfoController {
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
List<VersionRsp> rspInfo = new ArrayList<>();
VersionListRsp versionListRsp = new VersionListRsp();
versionListRsp.setItems(new ArrayList<>());
@ -166,8 +155,7 @@ public class DisposeNodeInfoController {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
if (devList != null && devList.size() > 0) {
devList.forEach(v -> versionListRsp.getItems()
.add(VersionRsp.builder()
devList.forEach(v -> versionListRsp.getItems().add(VersionRsp.builder()
.id(v.getId().toString())
.version(v.getVersion())
.status(ErrorCode.ERR_OK.getCode())
@ -177,23 +165,19 @@ public class DisposeNodeInfoController {
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
VersionRsp ver;
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());
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 {
versionListRsp.getItems()
.add(VersionRsp.builder()
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
versionListRsp.getItems().add(VersionRsp.builder()
.id(v)
.status(ErrorCode.ERR_NOSUCHDEVICE.getCode())
.message(ErrorCode.ERR_NOSUCHDEVICE.getMsg())
.build());
}
}
@ -231,68 +215,38 @@ public class DisposeNodeInfoController {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
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
)));
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()) {
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
));
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 {
rspInfo.getItems()
.add(new DeviceInfoData(
v,
ErrorCode.ERR_NOSUCHDEVICE
));
rspInfo.getItems().add(new DeviceInfoData(v, ErrorCode.ERR_NOSUCHDEVICE));
}
}
}
@ -332,40 +286,34 @@ public class DisposeNodeInfoController {
if (devList != null && devList.size() > 0) {
devList.forEach(v -> {
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
cpData.setId(v.getId()
.toString());
cpData.setId(v.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(cpData);
rspInfo.getItems().add(cpData);
});
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId()
.equals(Long.valueOf(v))) {
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DeviceCapacityData cpData = new DeviceCapacityData(dev.getDevCaps());
cpData.setId(dev.getId()
.toString());
cpData.setId(dev.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(cpData);
rspInfo.getItems().add(cpData);
} else {
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems()
.add(cpData);
rspInfo.getItems().add(cpData);
}
}
}
String rspMessage =
new ObjectMapper().writerWithView(DisposeCapacity.CapacityView.class)
.writeValueAsString(rspInfo);
String rspMessage = new ObjectMapper()
.writerWithView(DisposeCapacity.CapacityView.class)
.writeValueAsString(rspInfo);
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspMessage, ConstValue.Protocol.CRYPTO_NONE);
}
@ -402,40 +350,33 @@ public class DisposeNodeInfoController {
if (devList != null && devList.size() > 0) {
devList.forEach(v -> {
DeviceCapacityData cpData = new DeviceCapacityData(v.getDevCaps());
cpData.setId(v.getId()
.toString());
cpData.setId(v.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(cpData);
rspInfo.getItems().add(cpData);
});
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId()
.equals(Long.valueOf(v))) {
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DeviceCapacityData cpData = new DeviceCapacityData(dev.getDevCaps());
cpData.setId(dev.getId()
.toString());
cpData.setId(dev.getId().toString());
cpData.setStatus(ErrorCode.ERR_OK.getCode());
cpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(cpData);
rspInfo.getItems().add(cpData);
} else {
DeviceCapacityData cpData = new DeviceCapacityData();
cpData.setId(v);
cpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
cpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems()
.add(cpData);
rspInfo.getItems().add(cpData);
}
}
}
String rspMessage =
new ObjectMapper().writerWithView(DisposeCapacity.DependIpView.class)
.writeValueAsString(rspInfo);
String rspMessage = new ObjectMapper().writerWithView(DisposeCapacity.DependIpView.class)
.writeValueAsString(rspInfo);
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspMessage, ConstValue.Protocol.CRYPTO_NONE);
}
@ -488,30 +429,25 @@ public class DisposeNodeInfoController {
.ip(v.getIpAddr())
.build();
dpData.setId(v.getId()
.toString());
dpData.setId(v.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(dpData);
rspInfo.getItems().add(dpData);
});
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId()
.equals(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.setId(dev.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(dpData);
rspInfo.getItems().add(dpData);
} else {
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
@ -565,19 +501,16 @@ public class DisposeNodeInfoController {
v.getReadme(),
v.getDevCaps()
);
dpData.setId(v.getId()
.toString());
dpData.setId(v.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(dpData);
rspInfo.getItems().add(dpData);
});
}
} else {
for (String v : reqInfo.getId()) {
DisposeDevice dev = disposeNodeManager.getDisposeDeviceById(Long.valueOf(v));
if (dev != null && dev.getId()
.equals(Long.valueOf(v))) {
if (dev != null && dev.getId().equals(Long.valueOf(v))) {
DisposeNodeData dpData = new DisposeNodeData(
dev.getType(),
dev.getName(),
@ -589,19 +522,16 @@ public class DisposeNodeInfoController {
dev.getReadme(),
dev.getDevCaps()
);
dpData.setId(dev.getId()
.toString());
dpData.setId(dev.getId().toString());
dpData.setStatus(ErrorCode.ERR_OK.getCode());
dpData.setMessage(ErrorCode.ERR_OK.getMsg());
rspInfo.getItems()
.add(dpData);
rspInfo.getItems().add(dpData);
} else {
DisposeNodeData dpData = new DisposeNodeData();
dpData.setId(v);
dpData.setStatus(ErrorCode.ERR_NOSUCHDEVICE.getCode());
dpData.setMessage(ErrorCode.ERR_NOSUCHDEVICE.getMsg());
rspInfo.getItems()
.add(dpData);
rspInfo.getItems().add(dpData);
}
}
}
@ -634,8 +564,7 @@ public class DisposeNodeInfoController {
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| Arrays.stream(reqInfo.getId())
.anyMatch(s -> s.equals(v.getId().toString())))
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.forEach(v -> {
@ -712,9 +641,7 @@ public class DisposeNodeInfoController {
List<DisposeDevice> valuableData = disposeNodeManager.getAllDisposeDevice()
.stream()
.filter(v -> reqInfo.getId().length == 0
|| Arrays.stream(reqInfo.getId())
.anyMatch(s -> s.equals(v.getId()
.toString())))
|| Arrays.stream(reqInfo.getId()).anyMatch(s -> s.equals(v.getId().toString())))
.collect(Collectors.toList());
valuableData.forEach(v -> {

View File

@ -5,7 +5,6 @@ import com.dispose.common.ErrorCode;
import com.dispose.common.FlowDirection;
import com.dispose.common.Helper;
import com.dispose.manager.TaskCacheManager;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.entity.DisposeDevice;
@ -77,12 +76,6 @@ public class DisposeTaskController {
@Resource
private UserAccountService userAccountService;
/**
* The Dispose task manager.
*/
@Resource
private DisposeTaskMapper disposeTaskMapper;
/**
* Task start protocol resp dto.
*
@ -229,7 +222,7 @@ public class DisposeTaskController {
rspInfo.getItems().add(taskData);
} else {
ret.forEach(k -> {
if(k.getFirstParam() == ErrorCode.ERR_OK) {
if (k.getFirstParam() == ErrorCode.ERR_OK) {
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));