REM:
1. 增加用户认证的打印日志
2. 增加获取能力节点信息的打印日志
3. 增加能力节点管理的打印日志
4. 增加处置任务接口的打印日志,修改处置任务接口
5. 停止指定能力节点全部处置任务接口中入参Id不能为空,必须指定deviceId
6. 修改测试代码
This commit is contained in:
chenlinghy 2020-05-18 17:00:48 +08:00
parent 4556a2936f
commit a5350348d6
8 changed files with 144 additions and 57 deletions

View File

@ -56,16 +56,17 @@ public class AuthController {
ErrorCode err = mr.verifyRequest();
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, err{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
LoginReq reqInfo = mr.getRequestObject(LoginReq.class);
MReturnType<ErrorCode, String> ret = userAccountService.loginService(reqInfo.getUserName(),
reqInfo.getPassword());
if (ret.getFirstParam() != ErrorCode.ERR_OK) {
log.error("User login failed, err{}", ret.getFirstParam().getMsg());
return ProtocolRespDTO.result(ret.getFirstParam());
}
@ -100,6 +101,7 @@ public class AuthController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, err{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -108,6 +110,7 @@ public class AuthController {
err = userAccountService.logoutService(reqInfo.getUserName(), mr.getAuthToken());
if (err != ErrorCode.ERR_OK) {
log.error("User logout failed, err{}", err.getMsg());
return ProtocolRespDTO.result(err);
}

View File

@ -85,6 +85,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -114,6 +115,7 @@ public class DisposeNodeInfoController {
.message(ErrorCode.ERR_OK.getMsg())
.build());
} else {
log.error("device not exist, deviceId:{}", v);
linkStatusListRsp.getItems().add(LinkStatusRsp.builder()
.online(0)
.id(v)
@ -144,6 +146,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -153,7 +156,6 @@ public class DisposeNodeInfoController {
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())
@ -173,13 +175,13 @@ public class DisposeNodeInfoController {
.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());
}
}
}
@ -203,6 +205,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -246,6 +249,7 @@ public class DisposeNodeInfoController {
ErrorCode.ERR_OK
));
} else {
log.error("device not exist, deviceId:{}", v);
rspInfo.getItems().add(new DeviceInfoData(v, ErrorCode.ERR_NOSUCHDEVICE));
}
}
@ -272,6 +276,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -302,6 +307,7 @@ public class DisposeNodeInfoController {
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());
@ -336,6 +342,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -366,6 +373,7 @@ public class DisposeNodeInfoController {
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());
@ -402,6 +410,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -449,6 +458,7 @@ public class DisposeNodeInfoController {
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());
@ -477,6 +487,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -527,6 +538,7 @@ public class DisposeNodeInfoController {
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());
@ -555,6 +567,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -577,6 +590,7 @@ public class DisposeNodeInfoController {
List<TaskInfoDetail> runTasks = taskService.getNodeAllRunningTask(v.getId());
if (runTasks == null || runTasks.size() == 0) {
log.error("No tasks in progress");
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
} else {
@ -604,6 +618,7 @@ public class DisposeNodeInfoController {
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
@ -632,6 +647,7 @@ public class DisposeNodeInfoController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -654,6 +670,7 @@ public class DisposeNodeInfoController {
List<TaskInfoDetail> runTasks = taskService.getNodeAllTask(v.getId());
if (runTasks == null || runTasks.size() == 0) {
log.error("No such tasks");
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
} else {
@ -682,6 +699,7 @@ public class DisposeNodeInfoController {
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("device not exist, deviceId:{}", v);
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);

View File

@ -69,17 +69,18 @@ public class DisposeNodeManagerController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
err = userAccountCacheManager.verifyPermission(mr.getAuthToken());
if (err != ErrorCode.ERR_OK) {
log.error("User not enough permissions, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
AddNodeReq reqInfo = mr.getRequestObject(AddNodeReq.class);
AddNodeRsp rspInfo = new AddNodeRsp();
reqInfo.getItems().forEach(v -> {
@ -96,6 +97,7 @@ public class DisposeNodeManagerController {
try {
ret = disposeNodeManager.addNewDisposeDevice(dev);
} catch (Exception ex) {
log.error(ex.getMessage());
ret = new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, v.getIpAddr());
}
@ -127,12 +129,14 @@ public class DisposeNodeManagerController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
err = userAccountCacheManager.verifyPermission(mr.getAuthToken());
if (err != ErrorCode.ERR_OK) {
log.error("User not enough permissions, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -140,6 +144,7 @@ public class DisposeNodeManagerController {
List<IDReturnStatus> rspInfo = new ArrayList<>();
if (reqInfo == null || reqInfo.getId().length > 1) {
log.error("Prohibit deleting multiple devices at the same time");
return ProtocolRespDTO.result(ErrorCode.ERR_REMOVEMORE);
}

View File

@ -93,12 +93,12 @@ public class DisposeTaskController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class);
StartTaskRsp rspInfo = new StartTaskRsp();
TaskInfoDetail task = TaskInfoDetail.builder()
@ -119,6 +119,7 @@ public class DisposeTaskController {
rspInfo.setId(String.valueOf(tf.getDeviceId()));
rspInfo.setTaskId(String.valueOf(ret.getSecondParam()));
} else {
log.error("Failed to create task, error:{}", ret.getFirstParam().getMsg());
rspInfo.setId("-1");
rspInfo.setTaskId("-1");
}
@ -146,6 +147,7 @@ public class DisposeTaskController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -158,6 +160,7 @@ public class DisposeTaskController {
List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByTaskId(Long.parseLong(v));
if (ret.size() == 0) {
log.error("No such dispose task, taskId:{}", v);
taskData.setId("-1");
taskData.setTaskId(v);
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
@ -165,19 +168,28 @@ public class DisposeTaskController {
rspInfo.getItems().add(taskData);
} else {
ret.forEach(k -> {
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
if(k.getFirstParam() == ErrorCode.ERR_OK){
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime(Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime())) / 60);
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
rspInfo.getItems().add(taskData);
}else{
log.error("Stop task: taskId:{}, error:{}", v, k.getFirstParam().getMsg());
taskData.setId("-1");
taskData.setTaskId("-1");
taskData.setStatus(k.getFirstParam().getCode());
taskData.setMessage(k.getFirstParam().getMsg());
}
rspInfo.getItems().add(taskData);
});
}
});
@ -203,6 +215,7 @@ public class DisposeTaskController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -215,6 +228,7 @@ public class DisposeTaskController {
List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByDisposeIp(Long.parseLong(v.getId()), v.getType(), v.getDisposeIp());
if (ret.size() == 0) {
log.error("No such dispose task, taskId:{}", v);
taskData.setId(v.getId());
taskData.setTaskId("-1");
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
@ -235,6 +249,8 @@ public class DisposeTaskController {
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
} else {
log.error("Stop task: taskId:{}, type:{}, disposeIp:{}, error:{}", v.getId(), v.getType(), v.getDisposeIp(),
k.getFirstParam().getMsg());
taskData.setId("-1");
taskData.setTaskId("-1");
taskData.setStatus(k.getFirstParam().getCode());
@ -266,6 +282,7 @@ public class DisposeTaskController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -276,6 +293,7 @@ public class DisposeTaskController {
List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByDisposeNode(Long.parseLong(v.getId()), v.getType());
if (ret.size() == 0) {
log.error("No such dispose task, taskId:{}", v);
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
taskData.setId("-1");
taskData.setTaskId("-1");
@ -284,20 +302,30 @@ public class DisposeTaskController {
rspInfo.getItems().add(taskData);
} else {
ret.forEach(k -> {
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
if (k.getFirstParam() == ErrorCode.ERR_OK) {
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
rspInfo.getItems().add(taskData);
rspInfo.getItems().add(taskData);
}else{
log.error("Stop task: deviceId:{}, type:{}, error:{}", v.getId(),
v.getType(), k.getFirstParam().getMsg());
TaskInfoData taskData = TaskInfoData.builder().type(v.getType()).build();
taskData.setId("-1");
taskData.setTaskId("-1");
taskData.setStatus(k.getFirstParam().getCode());
taskData.setMessage(k.getFirstParam().getMsg());
}
});
}
});
@ -323,6 +351,7 @@ public class DisposeTaskController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -332,6 +361,7 @@ public class DisposeTaskController {
List<MReturnType<ErrorCode, TaskInfoDetail>> ret = taskService.stopTaskByType(reqInfo.getType());
if (ret.size() == 0) {
log.error("No such dispose task");
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
taskData.setId("-1");
taskData.setTaskId("-1");
@ -340,20 +370,30 @@ public class DisposeTaskController {
rspInfo.getItems().add(taskData);
} else {
ret.forEach(k -> {
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
if(k.getFirstParam() == ErrorCode.ERR_OK){
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
ErrorCode retError = k.getFirstParam();
TaskInfoDetail taskInfo = k.getSecondParam();
taskData.setId(String.valueOf(taskInfo.getDeviceId()));
taskData.setTaskId(String.valueOf(taskInfo.getId()));
taskData.setType(taskInfo.getType());
taskData.setDisposeIp(taskInfo.getDisposeIp());
taskData.setLeftTime((Math.abs(Helper.getTimestampDiffNow(taskInfo.getBeginTime())
- Helper.getTimestampDiffNow(taskInfo.getPlanEndTime()))) / 60);
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
taskData.setStatus(retError.getCode());
taskData.setMessage(retError.getMsg());
rspInfo.getItems().add(taskData);
}else{
log.error("No task to stop: error:{}", k.getFirstParam().getMsg());
TaskInfoData taskData = TaskInfoData.builder().type(reqInfo.getType()).build();
taskData.setId("-1");
taskData.setTaskId("-1");
taskData.setStatus(k.getFirstParam().getCode());
taskData.setMessage(k.getFirstParam().getMsg());
}
rspInfo.getItems().add(taskData);
});
}
@ -376,6 +416,7 @@ public class DisposeTaskController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -416,6 +457,7 @@ public class DisposeTaskController {
taskData.setStatus(ErrorCode.ERR_OK.getCode());
taskData.setMessage(ErrorCode.ERR_OK.getMsg());
} else {
log.error("No such task, deviceId:{}", v);
taskData.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
taskData.setMessage(ErrorCode.ERR_NOSUCHTASK.getMsg());
taskData.setTaskArray(null);
@ -428,6 +470,7 @@ public class DisposeTaskController {
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("No such task, deviceId:{}", v);
NodeTaskData taskData = new NodeTaskData();
rspInfo.getItems().add(taskData);
taskData.setId(v);
@ -457,6 +500,7 @@ public class DisposeTaskController {
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
log.error("Request header error, error:{}", err.getMsg());
return ProtocolRespDTO.result(err);
}
@ -497,6 +541,7 @@ public class DisposeTaskController {
.collect(Collectors.toList());
unExists.forEach(v -> {
log.error("No such task, taskId:{}", v);
TaskInfoData taskData = new TaskInfoData();
rspInfo.getItems().add(taskData);
taskData.setTaskId(v);

View File

@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import java.util.Objects;
@ -19,6 +20,7 @@ import java.util.Objects;
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@Slf4j
public class ProtocolReqDTO extends ProtocolDTO {
/**
* The constant OBJECT_MAPPER.
@ -64,11 +66,13 @@ public class ProtocolReqDTO extends ProtocolDTO {
ErrorCode err = verifyRequest();
if (err != ErrorCode.ERR_OK) {
log.error("headers error, error:{}", err.getMsg());
return err;
}
// 是否有必要的HTTP Head字段
if (headers == null) {
log.error("Http request is missing authentication header");
return ErrorCode.ERR_MISSAUTHHEAD;
}
@ -77,6 +81,7 @@ public class ProtocolReqDTO extends ProtocolDTO {
ProtocolReqDTO.token = Objects.requireNonNull(headers.get("Authorization"))
.get(0).replaceFirst("Bearer ", "");
} catch (Exception ex) {
log.error(ex.getMessage());
return ErrorCode.ERR_MISSAUTHHEAD;
}
@ -91,17 +96,20 @@ public class ProtocolReqDTO extends ProtocolDTO {
public ErrorCode verifyRequest() {
if(this.getVer() == null || this.getCryptoType() == null || this.getTimeStamp() == null) {
log.error("request params error: ver:{}, cryptoType:{}, TimeStamp:{}", this.getVer(), this.getCryptoType(), this.getTimeStamp());
return ErrorCode.ERR_PARAMEXCEPTION;
}
// 校验版本
if (this.getVer() < ConstValue.Protocol.VERSION) {
log.error("version error: ver:{}", this.getVer());
return ErrorCode.ERR_VERSION;
}
// 校验时间错
if (GlobalVar.IS_CHECK_REQUEST_TIMEOUT
&& Math.abs(System.currentTimeMillis() - this.getTimeStamp()) >= ConstValue.Protocol.REQUEST_TIMEOUT_MS) {
log.error("request timeout: diffTimeMillis:{}", Math.abs(System.currentTimeMillis() - this.getTimeStamp()));
return ErrorCode.ERR_REQUESTTIMEOUT;
}

View File

@ -483,7 +483,7 @@ public class TaskServiceImpl implements TaskService {
// 根据处置IP拿出所有正在处置的任务
List<TaskInfoDetail> taskList = taskCacheManager.getAllTask().stream()
.filter(v -> ((devId == null || devId == -1L) || Objects.equals(v.getDeviceId(), devId))
.filter(v -> ((devId == -1L) || Objects.equals(v.getDeviceId(), devId))
&& (Objects.equals(v.getType(), type) || type == -1)
&& taskIsRunning(v))
.collect(Collectors.toList());

View File

@ -191,7 +191,7 @@ public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
@Test
public void t2_delDevice() throws Exception {
IDArrayReq reqData = IDArrayReq.builder()
.id(new String[]{"330"})
.id(new String[]{"1"})
.build();
Long reqTimeStamp = System.currentTimeMillis();

View File

@ -769,7 +769,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void d3_stopTaskByNodeNoIdExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"\\\",\\\"type\\\":0}}\"}";
"[{\\\"id\\\":\\\"\\\",\\\"type\\\":0}]}\"}";
String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_node")
@ -797,7 +797,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void d4_stopTaskByNodeNullIdExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":null,\\\"type\\\":0}}\"}";
"[{\\\"id\\\":null,\\\"type\\\":0}]}\"}";
String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_node")
@ -825,7 +825,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void d5_stopTaskByNodeNoTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":}}\"}";
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":}]}\"}";
String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_node")
@ -853,7 +853,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void d6_stopTaskByNodeNullTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":null}}\"}";
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":null}]}\"}";
String taskStopByNode = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_node")
@ -989,8 +989,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/
@Test
public void e4_stopTaskAllNoTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":}}\"}";
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
@ -1017,8 +1016,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/
@Test
public void e5_stopTaskAllNullTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":null}}\"}";
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":null}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
@ -1045,8 +1043,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/
@Test
public void e6_stopTaskAllStringTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":\\\"0\\\"}}\"}";
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":\\\"0\\\"}\"}";
String taskStopAll = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
@ -1054,16 +1051,27 @@ public class TaskControllerQATest extends InitTestEnvironment {
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(taskStopAll), ReturnStatus.class);
TaskInfoRsp taskStopByIpRsp = objectMapper.readValue(verifyResp(taskStopAll), TaskInfoRsp.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
List<TaskInfoData> taskInfoList = taskStopByIpRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
} else {
Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
}
}
}
/**