OCT
REM: 1.修改获取全部处置任务接口单元测试 2.修改controller层获取全部处置任务接口,增加入参字段 3.修改manager层、service层分页获取处置任务方法,增加获取全部任务方法 4.修改查询处置任务类
This commit is contained in:
parent
74b8508e83
commit
14e1bb35c3
|
@ -45,9 +45,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Dispose task controller.
|
||||
|
@ -260,16 +262,24 @@ public class DisposeTaskController {
|
|||
@Validated(ValidGroups.ProtocolCommonValid.class)
|
||||
@RequestBody ProtocolReqDTO<BasePagesGetReq> mr
|
||||
) {
|
||||
GetTaskRsp rspInfo = new GetTaskRsp();
|
||||
GetTaskRsp rspInfo = GetTaskRsp.builder().build();
|
||||
List<GetTaskDetail> getTaskDetail = new ArrayList<>();
|
||||
|
||||
//获取TaskId列表
|
||||
List<Long> reqTaskIds = Arrays.stream(mr.getMsgContent().getTaskId()).
|
||||
map(Long::parseLong).collect(Collectors.toList());
|
||||
|
||||
//获取所有可用处置任务
|
||||
List<DisposeTask> taskList = disposeTaskService.getAllDisposeTask();
|
||||
List<Long> idArray = taskList.stream().filter(v -> reqTaskIds.size() == 0 || reqTaskIds.contains(v.getId()))
|
||||
.map(DisposeTask::getId).collect(Collectors.toList());
|
||||
|
||||
if (idArray.size() > 0) {
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> ret =
|
||||
disposeTaskService.getPageDisposeTask(mr.getMsgContent().getStartPage(),
|
||||
disposeTaskService.getPageDisposeTask(idArray,
|
||||
mr.getMsgContent().getStartPage(),
|
||||
mr.getMsgContent().getPageSize());
|
||||
|
||||
// 拼装返回数据
|
||||
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||
rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
|
||||
|
||||
// 分页信息
|
||||
rspInfo.setCurPageNumber(ret.getFirstParam().getPageNum());
|
||||
rspInfo.setPageSize(ret.getFirstParam().getPageSize());
|
||||
|
@ -289,6 +299,8 @@ public class DisposeTaskController {
|
|||
.attackType(v.getAttackType().toString())
|
||||
.flowBandWidth(v.getFlowBandWidth())
|
||||
.currentStatus(v.getCurrentStatus().getValue())
|
||||
.status(ErrorCode.ERR_OK.getCode())
|
||||
.message(new String[]{ErrorCode.ERR_OK.getMsg()})
|
||||
.deviceTask(new ArrayList<>())
|
||||
.build();
|
||||
v.getDeviceTask().forEach(k -> {
|
||||
|
@ -302,8 +314,24 @@ public class DisposeTaskController {
|
|||
taskDetail.getDeviceTask().add(deviceTaskDetail);
|
||||
});
|
||||
|
||||
rspInfo.getItems().add(taskDetail);
|
||||
getTaskDetail.add(taskDetail);
|
||||
});
|
||||
}
|
||||
|
||||
// 设置不存在taskId的错误码
|
||||
if (reqTaskIds.stream().anyMatch(v -> taskList.stream().noneMatch(k -> k.getId().equals(v)))) {
|
||||
reqTaskIds.stream()
|
||||
.filter(v -> taskList.stream().noneMatch(k -> k.getId().equals(v)))
|
||||
.forEach(v -> {
|
||||
GetTaskDetail td = GetTaskDetail.builder().build();
|
||||
td.setTaskId(String.valueOf(v));
|
||||
td.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode());
|
||||
td.setMessage(new String[]{ErrorCode.ERR_NOSUCHTASK.getMsg()});
|
||||
getTaskDetail.add(td);
|
||||
});
|
||||
}
|
||||
|
||||
rspInfo.setItems(getTaskDetail);
|
||||
|
||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||
}
|
||||
|
|
|
@ -64,13 +64,22 @@ public interface DisposeTaskManager {
|
|||
*/
|
||||
DisposeTask getDisposeTaskById(Long taskId);
|
||||
|
||||
/**
|
||||
* Gets dispose task by id.
|
||||
*
|
||||
* @return the dispose task list
|
||||
*/
|
||||
List<DisposeTask> getDisposeTasks();
|
||||
|
||||
/**
|
||||
* Gets pages of task.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param startPage the start page
|
||||
* @param pageSize the page size
|
||||
* @return the pages of task
|
||||
*/
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPagesOfTask(Integer startPage,
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPagesOfTask(List<Long> taskId,
|
||||
Integer startPage,
|
||||
Integer pageSize);
|
||||
}
|
||||
|
|
|
@ -109,20 +109,35 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager {
|
|||
return disposeTaskMapper.getDisposeTaskById(taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose task by id.
|
||||
*
|
||||
* @return the dispose task list
|
||||
*/
|
||||
@Override
|
||||
public List<DisposeTask> getDisposeTasks() {
|
||||
return disposeTaskMapper.selectAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets pages of task.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param startPage the start page
|
||||
* @param pageSize the page size
|
||||
* @return the pages of task
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPagesOfTask(Integer startPage,
|
||||
public MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPagesOfTask(List<Long> taskId,
|
||||
Integer startPage,
|
||||
Integer pageSize) {
|
||||
List<DisposeTask> rspList = new ArrayList<>();
|
||||
// 设置分页信息
|
||||
PageHelper.startPage(startPage, pageSize);
|
||||
List<DisposeTask> taskList = disposeTaskMapper.selectPageAll();
|
||||
|
||||
//获取所有可用处置任务
|
||||
List<DisposeTask> taskList = disposeTaskMapper.selectPageAll().stream().
|
||||
filter(v->taskId.size() == 0 || taskId.contains(v.getId())).collect(Collectors.toList());
|
||||
|
||||
if (taskList == null) {
|
||||
taskList = new ArrayList<>();
|
||||
|
|
|
@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Positive;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* The type Get device req.
|
||||
|
@ -22,6 +23,12 @@ import javax.validation.constraints.Positive;
|
|||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class BasePagesGetReq {
|
||||
/**
|
||||
* The Task Id.
|
||||
*/
|
||||
@NotNull(message = "taskId 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class)
|
||||
@Size(min = 1, message = "taskId 字段必须指定明确任务id编号", groups = ValidGroups.ExplicitIdArrayValid.class)
|
||||
private String[] taskId;
|
||||
/**
|
||||
* The Start page.
|
||||
*/
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"taskId", "accountId", "disposeCapacity", "disposeIp", "createTime", "planEndTime", "endTime",
|
||||
"flowDirection", "attackType", "flowBandWidth", "currentStatus", "deviceTask"})
|
||||
"flowDirection", "attackType", "flowBandWidth", "currentStatus", "deviceTask", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class GetTaskDetail {
|
||||
|
||||
|
@ -67,6 +67,15 @@ public class GetTaskDetail {
|
|||
* The Current status.
|
||||
*/
|
||||
private Integer currentStatus;
|
||||
/**
|
||||
* 0:成功;其它:失败原因.
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 登录消息: status状态码对应的提示信息
|
||||
*/
|
||||
private String[] message;
|
||||
|
||||
/**
|
||||
* The Device task.
|
||||
*/
|
||||
|
|
|
@ -38,13 +38,22 @@ public interface DisposeTaskService {
|
|||
*/
|
||||
DisposeTask getDisposeTask(Long taskId);
|
||||
|
||||
/**
|
||||
* Gets dispose task.
|
||||
*
|
||||
* @return the dispose task list
|
||||
*/
|
||||
List<DisposeTask> getAllDisposeTask();
|
||||
|
||||
/**
|
||||
* Gets page dispose task.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @param startPage the start page
|
||||
* @param pageSize the page size
|
||||
* @return the page dispose task
|
||||
*/
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPageDisposeTask(Integer startPage,
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPageDisposeTask(List<Long> taskId,
|
||||
Integer startPage,
|
||||
Integer pageSize);
|
||||
}
|
||||
|
|
|
@ -95,6 +95,15 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
|
|||
return disposeTaskManager.getDisposeTaskById(taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose task.
|
||||
*
|
||||
* @return the dispose task list
|
||||
*/
|
||||
public List<DisposeTask> getAllDisposeTask() {
|
||||
return disposeTaskManager.getDisposeTasks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets page dispose task.
|
||||
*
|
||||
|
@ -103,8 +112,9 @@ public class DisposeTaskServiceImpl implements DisposeTaskService {
|
|||
* @return the page dispose task
|
||||
*/
|
||||
@Override
|
||||
public MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPageDisposeTask(Integer startPage,
|
||||
public MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> getPageDisposeTask(List<Long> taskId,
|
||||
Integer startPage,
|
||||
Integer pageSize) {
|
||||
return disposeTaskManager.getPagesOfTask(startPage, pageSize);
|
||||
return disposeTaskManager.getPagesOfTask(taskId, startPage, pageSize);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -347,7 +348,9 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Test
|
||||
public void a5_getAllDisposeTask() throws Exception {
|
||||
String[] taskId = {};
|
||||
BasePagesGetReq req = BasePagesGetReq.builder()
|
||||
.taskId(taskId)
|
||||
.startPage(1)
|
||||
.pageSize(20)
|
||||
.build();
|
||||
|
@ -379,9 +382,9 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
|
||||
Assert.assertNotNull(rspInfo.getMsgContent());
|
||||
Assert.assertTrue(rspInfo.getMsgContent().getCurPageNumber() <= req.getPageSize());
|
||||
Assert.assertEquals(rspInfo.getMsgContent().getPageSize(), req.getPageSize());
|
||||
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> result = disposeTaskService.getPageDisposeTask(req.getStartPage(), req.getPageSize());
|
||||
List<Long> taskIds = Arrays.stream(req.getTaskId()).map(Long::parseLong).collect(Collectors.toList());
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> result = disposeTaskService.getPageDisposeTask(taskIds, req.getStartPage(), req.getPageSize());
|
||||
Assert.assertTrue(rspInfo.getMsgContent().getTotalItems() >= result.getSecondParam().size());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue