From 034881e4de11192dc2ec5bfa5922563d63b84ae8 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 30 Oct 2020 15:46:44 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=90=AF=E5=8A=A8=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E8=AE=BE=E5=A4=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DisposeTaskController.java | 3 + .../dispose/manager/DisposeTaskManager.java | 9 +-- .../manager/impl/DisposeTaskManagerImpl.java | 17 +++--- .../com/dispose/mapper/DisposeTaskMapper.java | 1 + .../pojo/dto/protocol/task/DisposeObject.java | 5 ++ .../com/dispose/pojo/entity/DisposeTask.java | 4 ++ .../impl/DeviceTaskManagerServiceImpl.java | 3 + .../service/impl/DisposeTaskServiceImpl.java | 2 +- src/main/resources/db/schema.sql | 1 + src/main/resources/mappers/DisposeTask.xml | 4 ++ .../dev/manager/DisposeTaskManagerTest.java | 4 +- .../dev/mapper/DisposeTaskMapperTest.java | 8 +-- .../dev/service/DisposeTaskServiceTest.java | 56 ++++++++++--------- 13 files changed, 72 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index b8c3086c..f4dcef9e 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -120,6 +120,7 @@ public class DisposeTaskController { DisposeTask task = DisposeTask.builder() .deviceId(devId) .accountId(aId) + .areaCode(v.getAreaCode() == null ? -1 : v.getAreaCode()) .disposeCapacity(capType) .disposeObject(Helper.ipAddressNormalize(v.getDisposeObject())) .objectType(t) @@ -172,6 +173,7 @@ public class DisposeTaskController { // 构造处置任务参数 DisposeTask task = DisposeTask.builder() .deviceId(Long.parseLong(Optional.ofNullable(req.getId()).orElse("-1"))) + .areaCode(-1) .accountId(userAccountService.getUserIdByAuthHead(Objects.requireNonNull(headers.get("Authorization")) .get(0))) .disposeCapacity(CommonEnumHandler.codeOf(DisposeCapacityType.class, @@ -248,6 +250,7 @@ public class DisposeTaskController { DisposeTask task = DisposeTask.builder() .deviceId(devId) .accountId(aId) + .areaCode(-1) .disposeCapacity(capType) .disposeObject(Helper.ipAddressNormalize(ip)) .objectType(DisposeObjectType.IP) diff --git a/src/main/java/com/dispose/manager/DisposeTaskManager.java b/src/main/java/com/dispose/manager/DisposeTaskManager.java index a828f33b..63dd59fe 100644 --- a/src/main/java/com/dispose/manager/DisposeTaskManager.java +++ b/src/main/java/com/dispose/manager/DisposeTaskManager.java @@ -19,11 +19,12 @@ public interface DisposeTaskManager { * Gets dispose task. * * @param deviceId the device id + * @param areaCode the area code * @param disposeIp the dispose ip * @param capType the cap type * @return the dispose task */ - DisposeTask getDisposeTask(Long deviceId, String disposeIp, DisposeCapacityType capType); + DisposeTask getDisposeTask(Long deviceId, Integer areaCode, String disposeIp, DisposeCapacityType capType); /** * Add dispose task error code. @@ -65,16 +66,16 @@ public interface DisposeTaskManager { DisposeTask getDisposeTaskById(Long taskId); /** - * Gets dispose task by id. + * Gets dispose tasks. * - * @return the dispose task list + * @return the dispose tasks */ List getDisposeTasks(); /** * Gets pages of task. * - * @param taskId the task id + * @param taskId the task id * @param startPage the start page * @param pageSize the page size * @return the pages of task diff --git a/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java index 0759b9c2..0239af82 100644 --- a/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DisposeTaskManagerImpl.java @@ -34,13 +34,14 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager { * Gets dispose task. * * @param deviceId the device id + * @param areaCode the area code * @param disposeIp the dispose ip * @param capType the cap type * @return the dispose task */ @Override - public DisposeTask getDisposeTask(Long deviceId, String disposeIp, DisposeCapacityType capType) { - return disposeTaskMapper.getRunningTask(deviceId, capType, disposeIp); + public DisposeTask getDisposeTask(Long deviceId, Integer areaCode, String disposeIp, DisposeCapacityType capType) { + return disposeTaskMapper.getRunningTask(deviceId, areaCode, capType, disposeIp); } /** @@ -102,9 +103,9 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager { } /** - * Gets dispose task by id. + * Gets dispose tasks. * - * @return the dispose task list + * @return the dispose tasks */ @Override public List getDisposeTasks() { @@ -114,7 +115,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager { /** * Gets pages of task. * - * @param taskId the task id + * @param taskId the task id * @param startPage the start page * @param pageSize the page size * @return the pages of task @@ -129,7 +130,7 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager { // 设置分页信息 PageHelper.startPage(startPage, pageSize); - if(taskId.size() > 0) { + if (taskId.size() > 0) { preList = disposeTaskMapper.selectPageById(taskId); } else { preList = disposeTaskMapper.selectPageAll(); @@ -138,8 +139,8 @@ public class DisposeTaskManagerImpl implements DisposeTaskManager { pageInfo = new PageInfo<>(preList); - if(taskId.size() == 0){ - return new MulReturnType<>(pageInfo, new ArrayList<>()); + if (taskId.size() == 0) { + return new MulReturnType<>(pageInfo, new ArrayList<>()); } List taskList = new ArrayList<>(disposeTaskMapper.selectByIdSet(taskId)); diff --git a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java index 4c9bb3d8..3bdbdc4e 100644 --- a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java +++ b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java @@ -86,6 +86,7 @@ public interface DisposeTaskMapper { * @return the running task */ DisposeTask getRunningTask(@Param("deviceId") Long deviceId, + @Param("areaCode") Integer areaCode, @Param("capType") DisposeCapacityType capType, @Param("disposeObject") String disposeObject); diff --git a/src/main/java/com/dispose/pojo/dto/protocol/task/DisposeObject.java b/src/main/java/com/dispose/pojo/dto/protocol/task/DisposeObject.java index a0c6fee8..e17ac115 100644 --- a/src/main/java/com/dispose/pojo/dto/protocol/task/DisposeObject.java +++ b/src/main/java/com/dispose/pojo/dto/protocol/task/DisposeObject.java @@ -38,4 +38,9 @@ public class DisposeObject { @NotNull(message = "objectType 处置类型不能为空", groups = ValidGroups.TaskStartReqValid.class) @ValidBaseEnum(enumClass = DisposeObjectType.class, groups = ValidGroups.TaskStartReqValid.class) private Integer objectType; + + /** + * The Area code. + */ + private Integer areaCode; } diff --git a/src/main/java/com/dispose/pojo/entity/DisposeTask.java b/src/main/java/com/dispose/pojo/entity/DisposeTask.java index 679bdeb1..6d0c01b4 100644 --- a/src/main/java/com/dispose/pojo/entity/DisposeTask.java +++ b/src/main/java/com/dispose/pojo/entity/DisposeTask.java @@ -52,6 +52,10 @@ public class DisposeTask implements Serializable { * The Account id. */ private Long accountId; + /** + * The Area code. + */ + private Integer areaCode; /** * The Dispose capacity. */ diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 515bf466..e2034e2f 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -531,9 +531,12 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { disposeAbilityRouterService.getAllAbilityDevices().stream() // 判断是否是当前设备的处置任务 .filter(f -> v.getDeviceId() == -1 || f.getDev().getId().equals(v.getDeviceId())) + // 判断是否是当前区域处置 + .filter(f -> v.getAreaCode() == -1 || f.getDev().getAreaCode().equals(v.getAreaCode())) // 当前设备是否支持该处置能力 .filter(c -> c.getDev().getDevCapacity().stream().anyMatch(m -> m.getCapacityType() == v .getDisposeCapacity())) + // 当前设备是否支持处置该IP .filter(c -> c.getDb().isCarryProtectIp(v.getDisposeObject())) .forEach(d -> { log.info("Add dispose task for device: {}", d.getDev()); diff --git a/src/main/java/com/dispose/service/impl/DisposeTaskServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeTaskServiceImpl.java index e245668e..b1a90e32 100644 --- a/src/main/java/com/dispose/service/impl/DisposeTaskServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeTaskServiceImpl.java @@ -40,7 +40,7 @@ public class DisposeTaskServiceImpl implements DisposeTaskService { */ @Override public MulReturnType createTask(DisposeTask task) { - DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), + DisposeTask exitTask = disposeTaskManager.getDisposeTask(task.getDeviceId(), task.getAreaCode(), task.getDisposeObject(), task.getDisposeCapacity()); if (exitTask != null) { diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index a3d9064c..f2cbf521 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -107,6 +107,7 @@ CREATE TABLE `dispose_task` `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符', `deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符', `accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符', + `areaCode` int(11) NOT NULL DEFAULT -1 COMMENT '设备物理位置区域码', `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测', `disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象', `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', diff --git a/src/main/resources/mappers/DisposeTask.xml b/src/main/resources/mappers/DisposeTask.xml index 6970f96a..102b3010 100644 --- a/src/main/resources/mappers/DisposeTask.xml +++ b/src/main/resources/mappers/DisposeTask.xml @@ -5,6 +5,7 @@ + @@ -121,6 +122,9 @@ AND dt.deviceId = #{deviceId} + + AND dt.areaCode = #{areaCode} +