1. 修改部分逻辑

This commit is contained in:
EnderByEndera
2024-01-22 23:40:48 +08:00
parent 095eb88eb3
commit 7432dbd5be
6 changed files with 31 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ import lombok.Data;
public class FiveTupleWithMask {
@Schema(description = "地址类型(IPv4 or IPv6)", example = "4")
@JsonProperty("addr_type")
private Integer addrType;
private Integer addrType = 4;
@Schema(description = "源IP", example = "192.168.104.14")
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "源IP无效IPv4地址")

View File

@@ -67,6 +67,10 @@ public class TaskCommandInfo {
@JsonProperty("is_valid")
private Boolean isValid = true;
@Schema(description = "指令是否已研判", example = "true")
@JsonProperty("is_judged")
private Boolean isJudged = true;
@Schema(description = "五元组信息")
@NotNull(message = "五元组信息不能为空。")
@JsonProperty("five_tuple_with_mask")

View File

@@ -36,7 +36,6 @@ public class CommandService {
commandInfo.setUUID(UUID.randomUUID().toString());
commandMapper.createCommand(commandInfo);
return commandInfo.getUUID();
}
public void createCommands(List<TaskCommandInfo> taskCommandInfos) {

View File

@@ -48,7 +48,6 @@ public class StateHandler {
}
protected Boolean handleResume(CommandService commandService, Long taskId) {
commandService.startCommandsByTaskId(taskId);
return true;
}

View File

@@ -17,7 +17,8 @@
#{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort},
#{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort},
#{info.fiveTupleWithMask.maskProtocol},
#{info.startTime}, #{info.endTime}, #{info.isValid}, #{info.isJudged},
#{info.startTime}, #{info.endTime}, #{info.isValid},
#{info.isJudged},
0, 0,
NOW(), NOW(), FALSE)
</insert>
@@ -25,7 +26,8 @@
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
insert into t_command(COMMAND_ID, TASK_ID, TASK_ACT, FREQUENCY, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT,
PROTOCOL,
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID, IS_JUDGED,
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID,
IS_JUDGED,
SEND_TIMES, SUCCESS_TIMES, CREATE_TIME, LAST_UPDATE, IS_DELETED)
values
<foreach collection="command_infos" item="info" separator=",">
@@ -37,7 +39,8 @@
#{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort},
#{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort},
#{info.fiveTupleWithMask.maskProtocol},
#{info.startTime}, #{info.endTime}, #{info.isValid}, DEFAULT,
#{info.startTime}, #{info.endTime}, #{info.isValid},
#{info.isJudged},
0, 0,
NOW(), NOW(), FALSE
)
@@ -137,7 +140,12 @@
<select id="queryCommandInfo" resultType="java.lang.String">
SELECT COMMAND_ID FROM t_command
<where>
<if test="command_info.taskId != null">AND TASK_ID = #{command_info.taskId}</if>
<if test="command_info.taskId != null">
AND TASK_ID = #{command_info.taskId}
</if>
<if test="#{command_info.fiveTupleWithMask.addrType} != null">
AND ADDR_TYPE = #{command_info.fiveTupleWithMask.addrType}
</if>
<if test="command_info.fiveTupleWithMask.sourceIP != null">
AND SRC_IP = #{command_info.fiveTupleWithMask.sourceIP}
</if>

View File

@@ -13,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;
import static org.junit.jupiter.api.Assertions.*;
@@ -54,8 +55,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
@Test
void createCommand() {
assertDoesNotThrow(() -> commandService.createCommand(taskCommandInfo));
assertNotNull(taskCommandInfo.getUUID());
assertDoesNotThrow(() -> assertNotNull(commandService.createCommand(taskCommandInfo)));
}
@Test
@@ -85,7 +85,7 @@ class CommandServiceTest extends ProtectionApplicationTests {
}
@Test
void queryCommandByUUID() {
void queryCommandInfos() {
List<TaskCommandInfo> taskCommandInfos = commandService.queryCommandInfos(30L,
null, null, null, null,1, 5);
assertTrue(taskCommandInfos != null && !taskCommandInfos.isEmpty());
@@ -94,4 +94,14 @@ class CommandServiceTest extends ProtectionApplicationTests {
assertNotNull(commandService.queryCommandInfoByUUID(taskCommandInfo.getUUID()));
}
}
@Test
void queryCommandByUUID() {
taskCommandInfo.setTaskId(new Random().nextLong());
String uuid = commandService.createCommand(taskCommandInfo);
TaskCommandInfo taskCommandInfo = commandService.queryCommandInfoByUUID(uuid);
assertNotNull(taskCommandInfo);
assertNotNull(taskCommandInfo.getUUID());
assertEquals(uuid, taskCommandInfo.getUUID());
}
}