diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java index d7240ae..80c5519 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java +++ b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java @@ -79,9 +79,9 @@ public class TaskCommandInfo { @JsonProperty("is_valid") private Boolean isValid = true; - @Schema(description = "指令是否已研判", example = "true") + @Schema(description = "指令是否已研判,0待研判,1下发,2本次忽略,3永久忽略", example = "true") @JsonProperty("is_judged") - private Boolean isJudged = true; + private Integer isJudged = 1; @Schema(description = "五元组信息") @NotNull(message = "五元组信息不能为空。") diff --git a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java index fd49573..88fce67 100644 --- a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java +++ b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java @@ -65,10 +65,10 @@ public class AlertMessageService { if (taskType == TaskTypeEnum.DYNAMIC.getTaskType())//实时 switch (StateEnum.getStateEnumByNum(taskStatus)) { case RUNNING: - insertCommandAndAlertMessage(dynamicTaskCommandInfoList, true, true, alertMessage); + insertCommandAndAlertMessage(dynamicTaskCommandInfoList, true, 1, alertMessage); break; case PAUSED: - insertCommandAndAlertMessage(dynamicTaskCommandInfoList, false, true, alertMessage); + insertCommandAndAlertMessage(dynamicTaskCommandInfoList, false, 1, alertMessage); break; default://主要是stop //command不入库 @@ -79,10 +79,10 @@ public class AlertMessageService { else if (taskType == TaskTypeEnum.JUDGED.getTaskType())//研判后 switch (StateEnum.getStateEnumByNum(taskStatus)) { case RUNNING: - insertCommandAndAlertMessage(dynamicTaskCommandInfoList, true, false, alertMessage); + insertCommandAndAlertMessage(dynamicTaskCommandInfoList, true, 0, alertMessage); break; case PAUSED: - insertCommandAndAlertMessage(dynamicTaskCommandInfoList, false, false, alertMessage); + insertCommandAndAlertMessage(dynamicTaskCommandInfoList, false, 0, alertMessage); break; default://主要是stop //command不入库 @@ -131,7 +131,7 @@ public class AlertMessageService { @DSTransactional private void insertCommandAndAlertMessage(List dynamicTaskCommandInfoList, Boolean isValid, - Boolean isJudged, + Integer isJudged, AlertMessage alertMessage){ List commandUUIDs = new ArrayList<>(); @@ -139,7 +139,7 @@ public class AlertMessageService { //command入库 dynamicTaskCommandInfo.setIsValid(isValid); dynamicTaskCommandInfo.setIsJudged(isJudged); - String commandUUID = commandService.createCommand(dynamicTaskCommandInfo); + String commandUUID = commandService.createCommand2(dynamicTaskCommandInfo, isJudged); //alertmessage入库 @@ -156,26 +156,7 @@ public class AlertMessageService { ); alertMessageMapper.insertAlertMessage(alertMessage); } - //发送指令新建信号...实时任务 isJudged=1 才首次立刻下发 - try { - if (isJudged){ - stateHandler.sendCommandDistributeSignal(commandUUIDs); - } - }catch (Exception e) { - log.info(String.format("动态任务首次指令下发c3出错,任务id: %d,commandUUIDs: %s", - dynamicTaskCommandInfoList.get(0).getTaskId(), - commandUUIDs)); - } - //发送RCP查询信号 - try { - if (isJudged){ - stateHandler.sendCommandRcpQuerySignal(commandUUIDs); - } - }catch (Exception e) { - log.info(String.format("动态任务首次指令查询RCP出错,任务id: %d,commandUUIDs: %s", - dynamicTaskCommandInfoList.get(0).getTaskId(), - commandUUIDs)); - } + } private String insertAlertMessageOnly(AlertMessage alertMessage){ //alertmessage入库 diff --git a/src/main/java/com/realtime/protection/server/command/CommandMapper.java b/src/main/java/com/realtime/protection/server/command/CommandMapper.java index a7c8693..c73c8e4 100644 --- a/src/main/java/com/realtime/protection/server/command/CommandMapper.java +++ b/src/main/java/com/realtime/protection/server/command/CommandMapper.java @@ -58,4 +58,6 @@ public interface CommandMapper { List whiteListCommandCheck(@Param("command") FiveTupleWithMask fiveTupleWithMask); @DS("mysql") void createCommandWhiteListConnect(@Param("command_id") String uuid, @Param("whiteLists") List whiteListsHit); + + void updateCommandIsJudgedIfIgnoreThisTime(@Param("command_id") String commandUUID); } diff --git a/src/main/java/com/realtime/protection/server/command/CommandService.java b/src/main/java/com/realtime/protection/server/command/CommandService.java index a2691e3..456aa30 100644 --- a/src/main/java/com/realtime/protection/server/command/CommandService.java +++ b/src/main/java/com/realtime/protection/server/command/CommandService.java @@ -70,6 +70,61 @@ public class CommandService { return commandInfo.getUUID(); } + @DSTransactional + public String createCommand2(TaskCommandInfo commandInfo, Integer isJudged) { + String uuid = commandMapper.queryCommandInfo(commandInfo); + if (uuid != null) { + if (isJudged == 0){ + //研判后任务,将本次忽略的指令设置为待研判 + commandMapper.updateCommandIsJudgedIfIgnoreThisTime(uuid); + } + return uuid; + } + commandInfo.setDisplayId( + "ZL-" + + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + + "-" + + String.format("%06d", counter.generateId("command")) + ); + + //指令:白名单检查 + List whiteListsHit = commandMapper.whiteListCommandCheck(commandInfo.getFiveTupleWithMask()); + if (!whiteListsHit.isEmpty()) { + commandInfo.setUUID(UUID.randomUUID().toString()); + commandMapper.createCommandInWhiteListHit(commandInfo); + commandMapper.createCommandWhiteListConnect(commandInfo.getUUID(), whiteListsHit); + //写入历史表 + insertCommandHistory(commandInfo.getUUID()); + return commandInfo.getUUID(); + } + + commandInfo.setUUID(UUID.randomUUID().toString()); + commandMapper.createCommand(commandInfo); + //写入历史表 + insertCommandHistory(commandInfo.getUUID()); + + //发送指令新建信号...实时任务 isJudged=1 才首次立刻下发 + try { + if (isJudged == 1){ + stateHandler.sendCommandDistributeSignal(Collections.singletonList(commandInfo.getUUID())); + } + }catch (Exception e) { + log.info(String.format("实时任务首次指令下发c3出错,commandUUIDs: %s", + commandInfo.getUUID())); + } + //发送RCP查询信号 + try { + if (isJudged == 1){ + stateHandler.sendCommandRcpQuerySignal(Collections.singletonList(commandInfo.getUUID())); + } + }catch (Exception e) { + log.info(String.format("实时任务首次指令查询RCP出错,commandUUIDs: %s", + commandInfo.getUUID())); + } + + return commandInfo.getUUID(); + } + public List createCommands(List taskCommandInfos) { List commandUUIDs = ListUtils.newArrayListWithExpectedSize(taskCommandInfos.size()); @@ -137,6 +192,8 @@ public class CommandService { } public Boolean setCommandJudged(String commandId, Integer isJudged) { + //查詢指令当前is_judged状态,如果为0才可以被修改 + //设置指令是否已经研判 Boolean success = commandMapper.setCommandJudged(commandId, isJudged); @@ -145,6 +202,7 @@ public class CommandService { if (isJudged != 1) { return success; } + //如果isJudged=1,则发送指令首次下发信号和RCP首次查询信号 //指令首次下发 try { stateHandler.sendCommandDistributeSignal(commandUUIDs); diff --git a/src/main/resources/mappers/CommandMapper.xml b/src/main/resources/mappers/CommandMapper.xml index eb06ee7..dd5cbf7 100644 --- a/src/main/resources/mappers/CommandMapper.xml +++ b/src/main/resources/mappers/CommandMapper.xml @@ -421,6 +421,12 @@ and expire_time = NULL + + update t_command + set IS_JUDGED = 0 + where COMMAND_ID = #{command_id} + and IS_JUDGED = 2 +