2024-01-11 19:49:07 +08:00
|
|
|
|
package com.realtime.protection.server.command;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.util.ListUtils;
|
2024-01-12 14:31:34 +08:00
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
2024-01-22 15:40:03 +08:00
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
2024-06-06 03:28:50 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
|
2024-06-04 20:07:29 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.Counter;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
2024-08-21 02:18:43 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.enums.CommandStatusEnum;
|
2024-06-10 02:49:25 +08:00
|
|
|
|
import com.realtime.protection.server.task.status.StateHandler;
|
2024-06-06 03:28:50 +08:00
|
|
|
|
import com.realtime.protection.server.whitelist.WhiteListMapper;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
2024-06-04 20:07:29 +08:00
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
2024-06-10 02:49:25 +08:00
|
|
|
|
import java.util.Collections;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
import java.util.List;
|
2024-01-19 15:09:23 +08:00
|
|
|
|
import java.util.UUID;
|
2024-06-18 22:52:37 +08:00
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
@Slf4j
|
2024-01-15 20:40:55 +08:00
|
|
|
|
@DS("doris")
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public class CommandService {
|
|
|
|
|
|
|
|
|
|
|
|
private final CommandMapper commandMapper;
|
|
|
|
|
|
private final SqlSessionWrapper sqlSessionWrapper;
|
2024-06-04 20:07:29 +08:00
|
|
|
|
private final Counter counter;
|
2024-06-06 03:28:50 +08:00
|
|
|
|
private final WhiteListMapper whiteListMapper;
|
2024-01-12 14:31:34 +08:00
|
|
|
|
private static final int BatchSize = 100;
|
2024-06-10 02:49:25 +08:00
|
|
|
|
private final StateHandler stateHandler;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
|
2024-06-10 02:49:25 +08:00
|
|
|
|
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter, WhiteListMapper whiteListMapper, StateHandler stateHandler) {
|
2024-01-11 19:49:07 +08:00
|
|
|
|
this.commandMapper = commandMapper;
|
|
|
|
|
|
this.sqlSessionWrapper = sqlSessionWrapper;
|
2024-06-04 20:07:29 +08:00
|
|
|
|
this.counter = counter;
|
2024-06-06 03:28:50 +08:00
|
|
|
|
this.whiteListMapper = whiteListMapper;
|
2024-06-10 02:49:25 +08:00
|
|
|
|
this.stateHandler = stateHandler;
|
2024-01-15 20:40:55 +08:00
|
|
|
|
}
|
2024-01-11 19:49:07 +08:00
|
|
|
|
|
2024-07-17 10:48:16 +08:00
|
|
|
|
public static long ipToLong(String ipAddress) {
|
|
|
|
|
|
String[] parts = ipAddress.split("\\.");
|
|
|
|
|
|
if (parts.length != 4) {
|
|
|
|
|
|
throw new IllegalArgumentException("Invalid IP address: " + ipAddress);
|
|
|
|
|
|
}
|
|
|
|
|
|
long result = 0;
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
|
|
int part = Integer.parseInt(parts[i]);
|
|
|
|
|
|
result |= (long)part << (24 - (i * 8));
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-22 15:40:03 +08:00
|
|
|
|
@DSTransactional
|
2024-01-19 15:09:23 +08:00
|
|
|
|
public String createCommand(TaskCommandInfo commandInfo) {
|
2024-01-22 20:10:54 +08:00
|
|
|
|
String uuid = commandMapper.queryCommandInfo(commandInfo);
|
|
|
|
|
|
if (uuid != null) {
|
|
|
|
|
|
return uuid;
|
|
|
|
|
|
}
|
2024-06-04 20:07:29 +08:00
|
|
|
|
commandInfo.setDisplayId(
|
|
|
|
|
|
"ZL-"
|
|
|
|
|
|
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
|
|
|
|
|
|
+ "-"
|
|
|
|
|
|
+ String.format("%06d", counter.generateId("command"))
|
|
|
|
|
|
);
|
2024-01-22 20:10:54 +08:00
|
|
|
|
|
2024-07-17 10:48:16 +08:00
|
|
|
|
if (commandInfo.getFiveTupleWithMask().getSourceIP()!= null){
|
|
|
|
|
|
commandInfo.setSipInt(ipToLong(commandInfo.getFiveTupleWithMask().getSourceIP()));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (commandInfo.getFiveTupleWithMask().getDestinationIP()!= null){
|
|
|
|
|
|
commandInfo.setDipInt(ipToLong(commandInfo.getFiveTupleWithMask().getDestinationIP()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-06 03:28:50 +08:00
|
|
|
|
//指令:白名单检查
|
|
|
|
|
|
List<WhiteListObject> whiteListsHit = commandMapper.whiteListCommandCheck(commandInfo.getFiveTupleWithMask());
|
|
|
|
|
|
if (!whiteListsHit.isEmpty()) {
|
|
|
|
|
|
commandInfo.setUUID(UUID.randomUUID().toString());
|
|
|
|
|
|
commandMapper.createCommandInWhiteListHit(commandInfo);
|
|
|
|
|
|
commandMapper.createCommandWhiteListConnect(commandInfo.getUUID(), whiteListsHit);
|
|
|
|
|
|
//写入历史表
|
2024-06-18 22:52:37 +08:00
|
|
|
|
//insertCommandHistory(commandInfo.getUUID());
|
2024-06-06 03:28:50 +08:00
|
|
|
|
return commandInfo.getUUID();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-19 15:09:23 +08:00
|
|
|
|
commandInfo.setUUID(UUID.randomUUID().toString());
|
|
|
|
|
|
commandMapper.createCommand(commandInfo);
|
2024-07-17 10:48:16 +08:00
|
|
|
|
commandMapper.insertCommandDistribute(commandInfo);
|
|
|
|
|
|
commandMapper.insertCommandRCPQuery(commandInfo);
|
|
|
|
|
|
commandMapper.insertCommandTraffic(commandInfo);
|
|
|
|
|
|
|
2024-06-06 03:28:50 +08:00
|
|
|
|
//写入历史表
|
2024-08-21 02:18:43 +08:00
|
|
|
|
insertCommandHistory(commandInfo.getUUID(), CommandStatusEnum.START.getCommandStatusNum());
|
2024-01-19 15:09:23 +08:00
|
|
|
|
return commandInfo.getUUID();
|
2024-01-15 20:40:55 +08:00
|
|
|
|
}
|
2024-01-11 19:49:07 +08:00
|
|
|
|
|
2024-06-16 01:10:36 +08:00
|
|
|
|
@DSTransactional
|
|
|
|
|
|
public String createCommand2(TaskCommandInfo commandInfo, Integer isJudged) {
|
|
|
|
|
|
String uuid = commandMapper.queryCommandInfo(commandInfo);
|
2024-08-21 02:18:43 +08:00
|
|
|
|
|
2024-06-18 22:52:37 +08:00
|
|
|
|
//如果指令已经存在,除了研判状态为2,时需要改为0,其他情况都直接返回uuid
|
2024-06-16 01:10:36 +08:00
|
|
|
|
if (uuid != null) {
|
|
|
|
|
|
if (isJudged == 0){
|
2024-06-18 22:52:37 +08:00
|
|
|
|
//研判后任务,查询指令当前研判状态
|
|
|
|
|
|
Integer originalIsJudged = commandMapper.queryCommandIsJudged(uuid);
|
|
|
|
|
|
//如果研判状态为2,表示之前设置了本次忽略,那这次生成指令后,将其研判状态改为0,需要再次研判
|
|
|
|
|
|
if (originalIsJudged == 2){
|
|
|
|
|
|
commandMapper.updateCommandIsJudgedIfIgnoreThisTime(uuid);
|
2024-08-21 02:18:43 +08:00
|
|
|
|
//写入历史表
|
|
|
|
|
|
insertCommandHistory(commandInfo.getUUID(), CommandStatusEnum.START.getCommandStatusNum());
|
2024-06-18 22:52:37 +08:00
|
|
|
|
}
|
2024-06-16 01:10:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
return uuid;
|
|
|
|
|
|
}
|
|
|
|
|
|
commandInfo.setDisplayId(
|
|
|
|
|
|
"ZL-"
|
|
|
|
|
|
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
|
|
|
|
|
|
+ "-"
|
|
|
|
|
|
+ String.format("%06d", counter.generateId("command"))
|
|
|
|
|
|
);
|
2024-07-17 10:48:16 +08:00
|
|
|
|
if (commandInfo.getFiveTupleWithMask().getSourceIP()!= null){
|
|
|
|
|
|
commandInfo.setSipInt(ipToLong(commandInfo.getFiveTupleWithMask().getSourceIP()));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (commandInfo.getFiveTupleWithMask().getDestinationIP()!= null){
|
|
|
|
|
|
commandInfo.setDipInt(ipToLong(commandInfo.getFiveTupleWithMask().getDestinationIP()));
|
|
|
|
|
|
}
|
2024-06-16 01:10:36 +08:00
|
|
|
|
//指令:白名单检查
|
|
|
|
|
|
List<WhiteListObject> whiteListsHit = commandMapper.whiteListCommandCheck(commandInfo.getFiveTupleWithMask());
|
|
|
|
|
|
if (!whiteListsHit.isEmpty()) {
|
|
|
|
|
|
commandInfo.setUUID(UUID.randomUUID().toString());
|
|
|
|
|
|
commandMapper.createCommandInWhiteListHit(commandInfo);
|
|
|
|
|
|
commandMapper.createCommandWhiteListConnect(commandInfo.getUUID(), whiteListsHit);
|
|
|
|
|
|
//写入历史表
|
2024-06-18 22:52:37 +08:00
|
|
|
|
//insertCommandHistory(commandInfo.getUUID());
|
2024-06-16 01:10:36 +08:00
|
|
|
|
return commandInfo.getUUID();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
commandInfo.setUUID(UUID.randomUUID().toString());
|
|
|
|
|
|
commandMapper.createCommand(commandInfo);
|
2024-07-17 10:48:16 +08:00
|
|
|
|
commandMapper.insertCommandDistribute(commandInfo);
|
|
|
|
|
|
commandMapper.insertCommandRCPQuery(commandInfo);
|
|
|
|
|
|
commandMapper.insertCommandTraffic(commandInfo);
|
|
|
|
|
|
//写入历史表
|
2024-08-21 02:18:43 +08:00
|
|
|
|
insertCommandHistory(commandInfo.getUUID(), CommandStatusEnum.START.getCommandStatusNum());
|
|
|
|
|
|
|
2024-06-16 01:10:36 +08:00
|
|
|
|
|
|
|
|
|
|
//发送指令新建信号...实时任务 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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-08 15:01:38 +08:00
|
|
|
|
public List<String> createCommands(List<TaskCommandInfo> taskCommandInfos) {
|
|
|
|
|
|
|
|
|
|
|
|
List<String> commandUUIDs = ListUtils.newArrayListWithExpectedSize(taskCommandInfos.size());
|
2024-06-18 22:52:37 +08:00
|
|
|
|
AtomicInteger i = new AtomicInteger();
|
2024-01-15 20:40:55 +08:00
|
|
|
|
Function<CommandMapper, Function<List<TaskCommandInfo>, Boolean>> function = mapper -> list -> {
|
|
|
|
|
|
List<TaskCommandInfo> taskCommandInfoBatch = ListUtils.newArrayListWithExpectedSize(BatchSize);
|
|
|
|
|
|
for (TaskCommandInfo info : list) {
|
2024-01-19 15:09:23 +08:00
|
|
|
|
info.setUUID(UUID.randomUUID().toString());
|
2024-06-08 15:01:38 +08:00
|
|
|
|
commandUUIDs.add(info.getUUID());
|
|
|
|
|
|
info.setDisplayId(
|
|
|
|
|
|
"ZL-"
|
|
|
|
|
|
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
|
|
|
|
|
|
+ "-"
|
|
|
|
|
|
+ String.format("%06d", counter.generateId("command"))
|
|
|
|
|
|
);
|
2024-07-17 10:48:16 +08:00
|
|
|
|
if (info.getFiveTupleWithMask().getSourceIP()!= null){
|
|
|
|
|
|
info.setSipInt(ipToLong(info.getFiveTupleWithMask().getSourceIP()));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (info.getFiveTupleWithMask().getDestinationIP()!= null){
|
|
|
|
|
|
info.setDipInt(ipToLong(info.getFiveTupleWithMask().getDestinationIP()));
|
|
|
|
|
|
}
|
2024-01-15 20:40:55 +08:00
|
|
|
|
taskCommandInfoBatch.add(info);
|
2024-06-08 15:01:38 +08:00
|
|
|
|
|
2024-01-15 20:40:55 +08:00
|
|
|
|
if (taskCommandInfoBatch.size() < BatchSize) {
|
2024-01-11 19:49:07 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2024-06-18 22:52:37 +08:00
|
|
|
|
System.out.println("batch insert " + i.getAndIncrement());
|
2024-06-06 03:28:50 +08:00
|
|
|
|
//因为createCommands只用于静态规则生成command,静态规则已经检查了白名单,所以不检查了
|
2024-01-15 20:40:55 +08:00
|
|
|
|
commandMapper.createCommands(taskCommandInfoBatch);
|
2024-07-17 10:48:16 +08:00
|
|
|
|
commandMapper.insertCommandDistributeBatch(taskCommandInfoBatch);
|
|
|
|
|
|
commandMapper.insertCommandRCPQueryBatch(taskCommandInfoBatch);
|
|
|
|
|
|
commandMapper.insertCommandTrafficBatch(taskCommandInfoBatch);
|
|
|
|
|
|
insertCommandHistoryBatch(taskCommandInfoBatch);
|
2024-01-15 20:40:55 +08:00
|
|
|
|
taskCommandInfoBatch.clear();
|
2024-01-11 19:49:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-15 20:40:55 +08:00
|
|
|
|
if (!taskCommandInfoBatch.isEmpty()) {
|
|
|
|
|
|
commandMapper.createCommands(taskCommandInfoBatch);
|
2024-07-17 10:48:16 +08:00
|
|
|
|
commandMapper.insertCommandDistributeBatch(taskCommandInfoBatch);
|
|
|
|
|
|
commandMapper.insertCommandRCPQueryBatch(taskCommandInfoBatch);
|
|
|
|
|
|
commandMapper.insertCommandTrafficBatch(taskCommandInfoBatch);
|
|
|
|
|
|
insertCommandHistoryBatch(taskCommandInfoBatch);
|
2024-01-15 20:40:55 +08:00
|
|
|
|
taskCommandInfoBatch.clear();
|
2024-01-11 19:49:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-15 20:40:55 +08:00
|
|
|
|
return true;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-01-15 20:40:55 +08:00
|
|
|
|
sqlSessionWrapper.startBatchSession(CommandMapper.class, function, taskCommandInfos);
|
2024-06-08 15:01:38 +08:00
|
|
|
|
|
|
|
|
|
|
return commandUUIDs;
|
2024-01-15 20:40:55 +08:00
|
|
|
|
}
|
2024-01-11 19:49:07 +08:00
|
|
|
|
|
2024-01-22 20:10:54 +08:00
|
|
|
|
public List<TaskCommandInfo> queryCommandInfos(Long taskId,
|
|
|
|
|
|
String sourceIP, String sourcePort,
|
|
|
|
|
|
String destinationIP, String destinationPort,
|
|
|
|
|
|
Integer page, Integer pageNum) {
|
|
|
|
|
|
return commandMapper.queryCommandInfos(taskId,
|
|
|
|
|
|
sourceIP, sourcePort,
|
|
|
|
|
|
destinationIP, destinationPort,
|
|
|
|
|
|
page, pageNum);
|
2024-01-11 19:49:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-19 15:09:23 +08:00
|
|
|
|
public TaskCommandInfo queryCommandInfoByUUID(String uuid) {
|
|
|
|
|
|
return commandMapper.queryCommandInfoByUUID(uuid);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-21 02:18:43 +08:00
|
|
|
|
|
2024-08-19 03:18:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public Boolean startCommandsByTaskId(Long taskId) {
|
|
|
|
|
|
return commandMapper.startCommandsByTaskId(taskId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Boolean stopCommandsByTaskId(Long taskId) {
|
|
|
|
|
|
return commandMapper.stopCommandsByTaskId(taskId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Boolean removeCommandsByTaskId(Long taskId) {
|
2024-08-21 02:18:43 +08:00
|
|
|
|
Boolean ok = commandMapper.removeCommandsByTaskId(taskId);
|
|
|
|
|
|
//查询任务下的指令,将指令写入历史表
|
|
|
|
|
|
List<String> taskCommandIds = commandMapper.queryCommandInfosByTaskId(taskId);
|
|
|
|
|
|
for (String commandId : taskCommandIds) {
|
|
|
|
|
|
insertCommandHistory(commandId, CommandStatusEnum.END.getCommandStatusNum());
|
|
|
|
|
|
}
|
|
|
|
|
|
return ok;
|
|
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
|
}
|
2024-01-21 00:51:10 +08:00
|
|
|
|
|
2024-06-14 17:05:08 +08:00
|
|
|
|
public Boolean setCommandJudged(String commandId, Integer isJudged) {
|
2024-06-16 01:10:36 +08:00
|
|
|
|
//查詢指令当前is_judged状态,如果为0才可以被修改
|
|
|
|
|
|
|
2024-06-10 02:49:25 +08:00
|
|
|
|
//设置指令是否已经研判
|
|
|
|
|
|
Boolean success = commandMapper.setCommandJudged(commandId, isJudged);
|
2024-08-19 03:18:18 +08:00
|
|
|
|
//研判状态也写入历史表
|
2024-08-21 02:18:43 +08:00
|
|
|
|
switch (isJudged){
|
|
|
|
|
|
case 1:
|
2024-08-23 02:43:52 +08:00
|
|
|
|
insertCommandHistory(commandId, CommandStatusEnum.JUDGED.getCommandStatusNum());
|
2024-08-21 02:18:43 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
insertCommandHistory(commandId, CommandStatusEnum.IGNORE.getCommandStatusNum());
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
insertCommandHistory(commandId, CommandStatusEnum.WHOLEIGNORE.getCommandStatusNum());
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2024-06-10 02:49:25 +08:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
List<String> commandUUIDs = Collections.singletonList(commandId);
|
2024-06-14 17:05:08 +08:00
|
|
|
|
if (isJudged != 1) {
|
2024-06-11 00:05:53 +08:00
|
|
|
|
return success;
|
|
|
|
|
|
}
|
2024-06-16 01:10:36 +08:00
|
|
|
|
//如果isJudged=1,则发送指令首次下发信号和RCP首次查询信号
|
2024-06-11 00:05:53 +08:00
|
|
|
|
//指令首次下发
|
|
|
|
|
|
try {
|
2024-06-10 02:49:25 +08:00
|
|
|
|
stateHandler.sendCommandDistributeSignal(commandUUIDs);
|
2024-06-11 00:05:53 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.info(String.format("动态任务研判后任务首次指令下发c3出错,任务id: %d,commandUUIDs: %s",
|
|
|
|
|
|
queryCommandInfoByUUID(commandId).getTaskId(),
|
|
|
|
|
|
commandId));
|
|
|
|
|
|
}
|
|
|
|
|
|
//指令首次查询RCP
|
|
|
|
|
|
try {
|
|
|
|
|
|
stateHandler.sendCommandRcpQuerySignal(commandUUIDs);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.info(String.format("动态任务研判后任务首次查询RCP出错,任务id: %d,commandUUIDs: %s",
|
|
|
|
|
|
queryCommandInfoByUUID(commandId).getTaskId(),
|
|
|
|
|
|
commandId));
|
2024-06-10 02:49:25 +08:00
|
|
|
|
}
|
2024-06-11 00:05:53 +08:00
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
throw new IllegalArgumentException("指令研判状态修改失败,无效的指令");
|
2024-06-10 02:49:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
return success;
|
2024-01-21 00:51:10 +08:00
|
|
|
|
}
|
2024-01-23 12:17:10 +08:00
|
|
|
|
|
|
|
|
|
|
public Integer queryCommandTotalNum(Long taskId, String sourceIP, String sourcePort,
|
|
|
|
|
|
String destinationIP, String destinationPort){
|
|
|
|
|
|
return commandMapper.queryCommandTotalNum(taskId, sourceIP, sourcePort, destinationIP, destinationPort);
|
|
|
|
|
|
}
|
2024-06-06 03:28:50 +08:00
|
|
|
|
|
|
|
|
|
|
public void insertCommandHistory(String commandUUID) {
|
2024-06-26 02:16:11 +08:00
|
|
|
|
//todo: 不update, insert加入uuid
|
|
|
|
|
|
// commandMapper.updateCommandHistoryExpireTime(commandUUID);
|
|
|
|
|
|
String logId = UUID.randomUUID().toString();
|
|
|
|
|
|
commandMapper.insertCommandHistory(commandUUID, logId);
|
2024-06-06 03:28:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-21 02:18:43 +08:00
|
|
|
|
public void insertCommandHistory(String commandUUID,Integer commandStatus) {
|
|
|
|
|
|
//todo: 不update, insert加入uuid
|
|
|
|
|
|
// commandMapper.updateCommandHistoryExpireTime(commandUUID);
|
|
|
|
|
|
String logId = UUID.randomUUID().toString();
|
|
|
|
|
|
commandMapper.insertCommandHistoryWithStatus(commandUUID, logId, commandStatus);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-06 03:28:50 +08:00
|
|
|
|
public void insertCommandHistoryBatch(List<TaskCommandInfo> commandIdList) {
|
|
|
|
|
|
List<String> commandIds = ListUtils.newArrayListWithExpectedSize(commandIdList.size());
|
|
|
|
|
|
commandIdList.forEach(item -> commandIds.add(item.getUUID()));
|
2024-06-26 02:16:11 +08:00
|
|
|
|
//todo: 不update, insert加入uuid
|
|
|
|
|
|
// commandMapper.updateCommandHistoryExpireTimeBatch(commandIds);
|
|
|
|
|
|
// List<String> logIds;
|
|
|
|
|
|
// logIds = ListUtils.newArrayListWithExpectedSize(commandIds.size());
|
|
|
|
|
|
// for (int i = 0; i < commandIds.size(); i++) {
|
|
|
|
|
|
// logIds.add(UUID.randomUUID().toString());
|
|
|
|
|
|
// }
|
|
|
|
|
|
//新建的loguuid拿commannd_id来定顶一会吧
|
2024-08-21 02:18:43 +08:00
|
|
|
|
commandMapper.insertCommandHistoryBatch(commandIds, CommandStatusEnum.START.getCommandStatusNum());
|
2024-06-06 03:28:50 +08:00
|
|
|
|
}
|
2024-08-01 10:24:49 +08:00
|
|
|
|
|
2024-08-19 03:18:18 +08:00
|
|
|
|
//指令提前撤回下发
|
|
|
|
|
|
public Boolean setCommandValid(String commandId, Integer isValid) {
|
|
|
|
|
|
Boolean isture = commandMapper.setCommandValid(commandId, isValid);
|
2024-08-21 02:18:43 +08:00
|
|
|
|
insertCommandHistory(commandId, CommandStatusEnum.CANCEL.getCommandStatusNum());
|
2024-08-19 03:18:18 +08:00
|
|
|
|
return isture;
|
2024-08-01 10:24:49 +08:00
|
|
|
|
}
|
2024-08-21 02:18:43 +08:00
|
|
|
|
|
|
|
|
|
|
public List<Integer> queryRunningCommandsDistributeStatusByTaskId(Long taskId) {
|
|
|
|
|
|
List<Integer> commandStatusList = commandMapper.queryRunningCommandsDistributeStatusByTaskId(taskId);
|
|
|
|
|
|
return commandStatusList;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-23 02:43:52 +08:00
|
|
|
|
public List<TaskCommandInfo> queryRunningCommands() {
|
|
|
|
|
|
return commandMapper.queryRunningCommands();
|
2024-08-21 02:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Integer queryCommandLogRcpHitCountByCommandId(String commandI) {
|
|
|
|
|
|
return commandMapper.queryCommandLogRcpHitCountByCommandId(commandI);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<TaskCommandInfo> queryRunningCommandsTotalPacketNum() {
|
|
|
|
|
|
return commandMapper.queryRunningCommandsTotalPacketNum();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Integer queryCommandLogTotalPacketNumByCommandId(String uuid) {
|
|
|
|
|
|
return commandMapper.queryCommandLogTotalPacketNumByCommandId(uuid);
|
|
|
|
|
|
}
|
2024-08-23 02:43:52 +08:00
|
|
|
|
|
|
|
|
|
|
public List<TaskCommandInfo> queryCommandLogLastTwoRecord(String uuid) {
|
|
|
|
|
|
return commandMapper.queryCommandLogLastTwoRecord(uuid);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void insertCommandHistoryWithTime(String commandUUID, Integer commandStatus, LocalDateTime lastTrafficQueryTime) {
|
|
|
|
|
|
String logId = UUID.randomUUID().toString();
|
|
|
|
|
|
commandMapper.insertCommandHistoryWithStatusWithTime(commandUUID, logId, commandStatus, lastTrafficQueryTime);
|
|
|
|
|
|
}
|
2024-01-11 19:49:07 +08:00
|
|
|
|
}
|