1. 增加jackson配置,缩减json数据长度
2. ExceptionHandler添加SaTokenException检查,用于校验登陆 3. ResponseResult添加invalid和unauthorized静态方法 4. Task模块添加单查询,多查询,更新路由 5. Template添加两个JsonProperty 6. Template模块添加query路由 7.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.realtime.protection;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
||||
@@ -20,17 +20,23 @@ public class Template {
|
||||
@NotNull(message = "default_op should not be empty")
|
||||
private String defaultOp;
|
||||
|
||||
private boolean hasProtectObjectIP;
|
||||
@JsonProperty("template_running_tasks")
|
||||
private Integer templateRunningTasks;
|
||||
|
||||
private boolean hasProtectObjectPort;
|
||||
@JsonProperty("template_used")
|
||||
private Integer templateUsedTimes;
|
||||
|
||||
private boolean hasPeerIP;
|
||||
private Boolean hasProtectObjectIP;
|
||||
|
||||
private boolean hasPeerPort;
|
||||
private Boolean hasProtectObjectPort;
|
||||
|
||||
private boolean hasProtocol;
|
||||
private Boolean hasPeerIP;
|
||||
|
||||
private boolean hasURL;
|
||||
private Boolean hasPeerPort;
|
||||
|
||||
private boolean hasDNS;
|
||||
private Boolean hasProtocol;
|
||||
|
||||
private Boolean hasURL;
|
||||
|
||||
private Boolean hasDNS;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Task {
|
||||
@@ -53,13 +54,13 @@ public class Task {
|
||||
// -----------------------------------------------------------
|
||||
|
||||
@JsonProperty("static_rule_ids")
|
||||
private Integer[] staticRuleIds;
|
||||
private List<Integer> staticRuleIds;
|
||||
|
||||
@JsonProperty("dynamic_rule_ids")
|
||||
private Integer[] dynamicRuleIds;
|
||||
private List<Integer> dynamicRuleIds;
|
||||
|
||||
@JsonProperty("protect_object_ids")
|
||||
private Integer[] protectObjectIds;
|
||||
private List<Integer> protectObjectIds;
|
||||
|
||||
@JsonProperty("task_status")
|
||||
private Integer taskStatus;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.realtime.protection.configuration.exception;
|
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import io.swagger.v3.oas.annotations.ExternalDocumentation;
|
||||
import org.apache.ibatis.exceptions.PersistenceException;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -24,26 +26,30 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = NotLoginException.class)
|
||||
public ResponseResult handleNotLoginException(NotLoginException e) {
|
||||
return new ResponseResult(
|
||||
400,
|
||||
401,
|
||||
e.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = PersistenceException.class)
|
||||
public ResponseResult handleSQLException() {
|
||||
return new ResponseResult(
|
||||
400,
|
||||
public ResponseResult handleSQLException(PersistenceException e) {
|
||||
return ResponseResult.invalid().setMessage(
|
||||
"please check the integrity of the data. check if the json data exists in the database");
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||
public ResponseResult handleBindException(MethodArgumentNotValidException e) {
|
||||
return new ResponseResult(
|
||||
400,
|
||||
return ResponseResult.invalid().setMessage(
|
||||
e.getBindingResult().getAllErrors().stream()
|
||||
.map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining())
|
||||
);
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = SaTokenException.class)
|
||||
public ResponseResult handleSaTokenException(SaTokenException e) {
|
||||
return ResponseResult.unAuthorized().setMessage(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ResponseResult implements Serializable {
|
||||
}
|
||||
|
||||
public static ResponseResult ok() {
|
||||
return new ResponseResult(200, "request succeeded");
|
||||
return new ResponseResult(200, "request succeed");
|
||||
}
|
||||
|
||||
public static ResponseResult ok(String message) {
|
||||
@@ -41,6 +41,14 @@ public class ResponseResult implements Serializable {
|
||||
return new ResponseResult(500, "request failed");
|
||||
}
|
||||
|
||||
public static ResponseResult invalid() {
|
||||
return new ResponseResult(400, "invalid request");
|
||||
}
|
||||
|
||||
public static ResponseResult unAuthorized() {
|
||||
return new ResponseResult(401, "UnAuthorized User");
|
||||
}
|
||||
|
||||
public static ResponseResult error(String message) {
|
||||
return new ResponseResult(500, message);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@ package com.realtime.protection.server.defense.template;
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/deftac")
|
||||
@@ -40,4 +39,18 @@ public class TemplateController {
|
||||
.setData("template_id", null)
|
||||
.setData("success", false);
|
||||
}
|
||||
|
||||
@GetMapping("/query")
|
||||
public ResponseResult queryTemplate(@RequestParam(value = "template_name", required = false) String templateName,
|
||||
@RequestParam("page") Integer page,
|
||||
@RequestParam("page_size") Integer pageSize) {
|
||||
if (page <= 0 || pageSize <= 0) {
|
||||
return ResponseResult.invalid()
|
||||
.setData("template_list", null);
|
||||
}
|
||||
List<Template> templates = templateService.queryTemplates(templateName, page, pageSize);
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("templates", templates);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,13 @@ import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface TemplateMapper {
|
||||
|
||||
void newTemplate(@Param("template") Template template);
|
||||
|
||||
List<Template> queryTemplates(@Param("template_name") String templateName,
|
||||
@Param("page") Integer page,
|
||||
@Param("page_size") Integer pageSize);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class TemplateService {
|
||||
@@ -42,4 +43,8 @@ public class TemplateService {
|
||||
}
|
||||
return template.getTemplateId();
|
||||
}
|
||||
|
||||
public List<Template> queryTemplates(String templateName, Integer page, Integer pageSize) {
|
||||
return templateMapper.queryTemplates(templateName, page, pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ package com.realtime.protection.server.task;
|
||||
import com.realtime.protection.configuration.entity.task.Task;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.apache.coyote.Response;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/task")
|
||||
@@ -17,7 +18,7 @@ public class TaskController {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@RequestMapping("/new")
|
||||
@PostMapping("/new")
|
||||
public ResponseResult newTask(@RequestBody @Valid Task task) {
|
||||
Integer taskId = taskService.newTask(task);
|
||||
|
||||
@@ -33,4 +34,52 @@ public class TaskController {
|
||||
.setData("task_id", 0)
|
||||
.setData("success", false);
|
||||
}
|
||||
|
||||
@GetMapping("/query")
|
||||
public ResponseResult queryTasks(@RequestParam(value = "task_status", required = false) Integer taskStatus,
|
||||
@RequestParam(value = "task_type", required = false) String taskType,
|
||||
@RequestParam(value = "task_name", required = false) String taskName,
|
||||
@RequestParam(value = "task_creator", required = false) String taskCreator,
|
||||
@RequestParam("page") Integer page,
|
||||
@RequestParam("page_size") Integer pageSize) {
|
||||
if (page <= 0 || pageSize <= 0) {
|
||||
return new ResponseResult(400, "page or page_size is invalid")
|
||||
.setData("task_list", null);
|
||||
}
|
||||
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
|
||||
return ResponseResult.ok()
|
||||
.setData("task_list", tasks);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/query")
|
||||
public ResponseResult queryTask(@PathVariable("id") Integer id) {
|
||||
Task task = taskService.queryTask(id);
|
||||
|
||||
if (task == null) {
|
||||
return ResponseResult.invalid().setMessage("Task ID is invalid");
|
||||
}
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("task_id", task.getTaskId())
|
||||
.setData("task_name", task.getTaskName())
|
||||
.setData("task_type", task.getTaskType())
|
||||
.setData("task_status", task.getTaskStatus())
|
||||
.setData("task_creator", task.getTaskCreateUsername())
|
||||
.setData("task_creator_depart", task.getTaskCreateDepart())
|
||||
.setData("task_start_time", task.getTaskStartTime())
|
||||
.setData("task_end_time", task.getTaskEndTime())
|
||||
.setData("task_static_rule_ids", task.getStaticRuleIds())
|
||||
.setData("task_dynamic_rule_ids", task.getDynamicRuleIds())
|
||||
.setData("task_protect_object_ids", task.getProtectObjectIds());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/update")
|
||||
public ResponseResult updateTask(@PathVariable("id") Integer taskId, @RequestBody Task task) {
|
||||
task.setTaskId(taskId);
|
||||
taskService.updateTask(task);
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("task_id", taskId)
|
||||
.setData("success", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,37 @@ import com.realtime.protection.configuration.entity.task.Task;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface TaskMapper {
|
||||
void newTask(@Param("task") Task task);
|
||||
|
||||
void newTaskProobjConcat(@Param("task_id") Integer taskId, @Param("proobj_ids") Integer[] proobjIds);
|
||||
void newTaskProtectObjectConcat(@Param("task_id") Integer taskId, @Param("proobj_ids") List<Integer> proobjIds);
|
||||
|
||||
Integer newTaskStaticRuleConcat(@Param("task_id") Integer taskId,
|
||||
@Param("rule_ids") Integer[] staticRuleIds);
|
||||
void newTaskStaticRuleConcat(@Param("task_id") Integer taskId,
|
||||
@Param("rule_ids") List<Integer> staticRuleIds);
|
||||
|
||||
Integer newTaskDynamicRuleConcat(@Param("task_id") Integer taskId,
|
||||
@Param("rule_ids") Integer[] dynamicRuleIds);
|
||||
void newTaskDynamicRuleConcat(@Param("task_id") Integer taskId,
|
||||
@Param("rule_ids") List<Integer> dynamicRuleIds);
|
||||
|
||||
List<Task> queryTasks(@Param("task_status") Integer taskStatus, @Param("task_type") String task_type,
|
||||
@Param("task_name") String taskName, @Param("task_creator") String taskCreator,
|
||||
@Param("page") Integer page, @Param("page_size") Integer pageSize);
|
||||
|
||||
Task queryTask(@Param("task_id") Integer taskId);
|
||||
|
||||
List<Integer> queryTaskConcatProtectObjectIds(@Param("task_id") Integer taskId);
|
||||
|
||||
List<Integer> queryTaskConcatStaticRuleIds(@Param("task_id") Integer taskId);
|
||||
|
||||
List<Integer> queryTaskConcatDynamicRuleIds(@Param("task_id") Integer taskId);
|
||||
|
||||
void updateTask(@Param("task") Task task);
|
||||
|
||||
void clearTaskProtectObjectConcat(@Param("task_id") Integer taskId);
|
||||
|
||||
void clearTaskConnectedStaticRule(@Param("task_id") Integer taskId);
|
||||
|
||||
void clearTaskConnectedDynamicRule(@Param("task_id") Integer taskId);
|
||||
}
|
||||
|
||||
@@ -5,36 +5,28 @@ import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final SqlSessionFactory sqlSessionFactory;
|
||||
private final TaskMapper taskMapper;
|
||||
|
||||
public TaskService(SqlSessionFactory sqlSessionFactory) {
|
||||
public TaskService(SqlSessionFactory sqlSessionFactory, TaskMapper taskMapper) {
|
||||
this.sqlSessionFactory = sqlSessionFactory;
|
||||
this.taskMapper = taskMapper;
|
||||
}
|
||||
|
||||
public Integer newTask(Task task) {
|
||||
task.setTaskCreateTime(LocalDateTime.now());
|
||||
task.setTaskModifyTime(LocalDateTime.now());
|
||||
|
||||
SqlSession session = sqlSessionFactory.openSession(false);
|
||||
TaskMapper taskMapper = session.getMapper(TaskMapper.class);
|
||||
try {
|
||||
taskMapper.newTask(task);
|
||||
|
||||
taskMapper.newTaskProobjConcat(task.getTaskId(), task.getProtectObjectIds());
|
||||
taskMapper.newTaskProtectObjectConcat(task.getTaskId(), task.getProtectObjectIds());
|
||||
|
||||
|
||||
// if (taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds())
|
||||
// != task.getStaticRuleIds().length)
|
||||
// throw new Exception("update lines is not equal to static_rule_ids size");
|
||||
|
||||
// if (taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds())
|
||||
// != task.getDynamicRuleIds().length)
|
||||
// throw new Exception("update lines is not equal to dynamic_rule_ids size");
|
||||
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
||||
|
||||
session.commit();
|
||||
} catch (Exception e) {
|
||||
@@ -49,4 +41,66 @@ public class TaskService {
|
||||
}
|
||||
return task.getTaskId();
|
||||
}
|
||||
|
||||
public List<Task> queryTasks(Integer taskStatus,
|
||||
String taskType, String taskName, String taskCreator,
|
||||
Integer page, Integer pageSize) {
|
||||
return taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
|
||||
}
|
||||
|
||||
public Task queryTask(Integer id) {
|
||||
SqlSession session = sqlSessionFactory.openSession(false);
|
||||
TaskMapper taskMapper = session.getMapper(TaskMapper.class);
|
||||
Task task;
|
||||
|
||||
try {
|
||||
task = taskMapper.queryTask(id);
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
task.setProtectObjectIds(taskMapper.queryTaskConcatProtectObjectIds(task.getTaskId()));
|
||||
// task.setDynamicRuleIds(taskMapper.queryTaskConcatDynamicRuleIds(task.getTaskId()));
|
||||
task.setStaticRuleIds(taskMapper.queryTaskConcatStaticRuleIds(task.getTaskId()));
|
||||
|
||||
session.commit();
|
||||
} catch (Exception e) {
|
||||
session.rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
session.close();
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
public void updateTask(Task task) {
|
||||
SqlSession session = sqlSessionFactory.openSession(false);
|
||||
TaskMapper taskMapper = session.getMapper(TaskMapper.class);
|
||||
try {
|
||||
taskMapper.updateTask(task);
|
||||
|
||||
taskMapper.clearTaskProtectObjectConcat(task.getTaskId());
|
||||
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
||||
// taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
|
||||
|
||||
if (task.getProtectObjectIds() != null && !task.getProtectObjectIds().isEmpty()) {
|
||||
taskMapper.newTaskProtectObjectConcat(task.getTaskId(), task.getProtectObjectIds());
|
||||
}
|
||||
|
||||
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty()) {
|
||||
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
||||
}
|
||||
|
||||
if (task.getDynamicRuleIds() != null && !task.getDynamicRuleIds().isEmpty()) {
|
||||
taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds());
|
||||
}
|
||||
|
||||
session.commit();
|
||||
} catch (Exception e) {
|
||||
session.rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ spring:
|
||||
mvc:
|
||||
servlet:
|
||||
path: /api/v1
|
||||
jackson:
|
||||
default-property-inclusion: non_null
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mappers/*.xml
|
||||
@@ -11,28 +11,110 @@
|
||||
task_create_userid, task_create_username, task_create_depart)
|
||||
VALUE (#{task.taskName}, #{task.taskStartTime}, #{task.taskEndTime},
|
||||
#{task.taskAct}, #{task.taskType},
|
||||
#{task.taskCreateTime}, #{task.taskModifyTime},
|
||||
NOW(), NOW(),
|
||||
#{task.taskCreateUserId}, #{task.taskCreateUsername}, #{task.taskCreateDepart})
|
||||
</insert>
|
||||
|
||||
<insert id="newTaskProobjConcat">
|
||||
<if test="proobj_ids != null">
|
||||
<insert id="newTaskProtectObjectConcat">
|
||||
INSERT INTO t_task_project_object(task_id, protect_object_id)
|
||||
VALUES
|
||||
<foreach collection="proobj_ids" item="proobj_id" separator=",">
|
||||
<foreach collection="proobj_ids" item="proobj_id" separator="," index="index">
|
||||
(#{task_id}, #{proobj_id})
|
||||
</foreach>
|
||||
</if>
|
||||
</insert>
|
||||
|
||||
<update id="newTaskStaticRuleConcat">
|
||||
UPDATE t_static_rule
|
||||
SET static_rule_used_task_id = #{task_id}
|
||||
<set>
|
||||
<if test="task_id != null"> static_rule_used_task_id = #{task_id}, </if>
|
||||
</set>
|
||||
WHERE static_rule_id IN
|
||||
<foreach collection="rule_ids" item="rule_id" open="(" close=")" separator=",">
|
||||
#{rule_id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="newTaskDynamicRuleConcat"/>
|
||||
<update id="newTaskDynamicRuleConcat">
|
||||
<!-- todo: will be written after fulfilling t_dynamic_rule table -->
|
||||
</update>
|
||||
|
||||
<resultMap id="taskMap" type="com.realtime.protection.configuration.entity.task.Task">
|
||||
<id column="task_id" property="taskId"/>
|
||||
<result column="task_name" property="taskName"/>
|
||||
<result column="task_type" property="taskType"/>
|
||||
|
||||
<result column="task_status" property="taskStatus"/>
|
||||
|
||||
<result column="task_start_time" property="taskStartTime"/>
|
||||
<result column="task_end_time" property="taskEndTime"/>
|
||||
|
||||
<result column="task_create_username" property="taskCreateUsername"/>
|
||||
<result column="task_create_depart" property="taskCreateDepart"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="queryTasks" resultMap="taskMap">
|
||||
SELECT * FROM t_task
|
||||
<where>
|
||||
<if test="task_status != null">
|
||||
AND task_status = #{task_status}
|
||||
</if>
|
||||
<if test="task_type != null">
|
||||
AND task_type = #{task_type}
|
||||
</if>
|
||||
<if test="task_name != null">
|
||||
AND task_name LIKE CONCAT('%', #{task_name}, '%')
|
||||
</if>
|
||||
<if test="task_creator != null">
|
||||
AND task_create_username = #{task_creator}
|
||||
</if>
|
||||
</where>
|
||||
LIMIT ${(page - 1) * page_size}, #{page_size}
|
||||
</select>
|
||||
|
||||
<select id="queryTask" resultMap="taskMap">
|
||||
SELECT * FROM t_task
|
||||
WHERE task_id = #{task_id}
|
||||
</select>
|
||||
|
||||
<select id="queryTaskConcatProtectObjectIds" resultType="java.lang.Integer">
|
||||
SELECT protect_object_id FROM t_task_project_object
|
||||
WHERE task_id = #{task_id}
|
||||
</select>
|
||||
|
||||
<select id="queryTaskConcatDynamicRuleIds" resultType="java.lang.Integer">
|
||||
<!-- todo: will be written after fulfilling t_dynamic_rule table -->
|
||||
</select>
|
||||
|
||||
<select id="queryTaskConcatStaticRuleIds" resultType="java.lang.Integer">
|
||||
SELECT static_rule_id FROM t_static_rule
|
||||
WHERE static_rule_used_task_id = #{task_id}
|
||||
</select>
|
||||
|
||||
<update id="updateTask">
|
||||
UPDATE t_task
|
||||
<set>
|
||||
<if test="task.taskName != null">task_name = #{task.taskName},</if>
|
||||
<if test="task.taskType != null">task_type = #{task.taskType},</if>
|
||||
<if test="task.taskAct != null">task_act = #{task.taskAct},</if>
|
||||
<if test="task.taskCreateTime != null">task_create_time = #{task.taskCreateTime},</if>
|
||||
<if test="task.taskEndTime != null">task_end_time = #{task.taskEndTime},</if>
|
||||
task_modify_time = NOW()
|
||||
</set>
|
||||
WHERE task_id = #{task.taskId}
|
||||
</update>
|
||||
|
||||
<update id="clearTaskProtectObjectConcat">
|
||||
DELETE FROM t_task_project_object
|
||||
WHERE task_id = #{task_id}
|
||||
</update>
|
||||
|
||||
<update id="clearTaskConnectedStaticRule">
|
||||
UPDATE t_static_rule
|
||||
SET static_rule_used_task_id = null
|
||||
WHERE static_rule_used_task_id = #{task_id}
|
||||
</update>
|
||||
|
||||
<update id="clearTaskConnectedDynamicRule">
|
||||
<!-- todo: will be written after fulfilling t_dynamic_rule table -->
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -19,4 +19,21 @@
|
||||
#{template.templateName}, #{template.templateName},
|
||||
#{template.defaultOp})
|
||||
</insert>
|
||||
|
||||
<resultMap id="templateMap" type="com.realtime.protection.configuration.entity.defense.template.Template">
|
||||
<id column="strategy_template_id" property="templateId"/>
|
||||
<result column="strategy_template_name" property="templateName"/>
|
||||
<result column="strategy_template_used_times" property="templateUsedTimes"/>
|
||||
<result column="strategy_template_running_tasks" property="templateRunningTasks"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="queryTemplates" resultMap="templateMap">
|
||||
SELECT * FROM t_strategy_template
|
||||
<where>
|
||||
<if test="template_name != null">
|
||||
AND strategy_template_name LIKE CONCAT('%', #{template_name}, '%')
|
||||
</if>
|
||||
</where>
|
||||
LIMIT ${(page - 1) * page_size}, #{page_size}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.realtime.protection.server.task;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class TaskControllerTest {
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -33,7 +34,7 @@ class TaskServiceTest {
|
||||
task.setTaskEndTime(taskEndTime);
|
||||
task.setTaskAct("阻断");
|
||||
task.setTaskType("静态任务");
|
||||
task.setStaticRuleIds(new Integer[]{1});
|
||||
task.setStaticRuleIds(new Integer[]{1, 2});
|
||||
task.setDynamicRuleIds(new Integer[]{});
|
||||
task.setTaskCreateUserId(1);
|
||||
task.setTaskCreateUsername("xxx");
|
||||
@@ -54,4 +55,11 @@ class TaskServiceTest {
|
||||
assertTrue(taskId > 0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testQueryTasks() {
|
||||
List<Task> tasks = taskService.queryTasks(null, null, null, null, 1, 5);
|
||||
assertEquals(5, tasks.size());
|
||||
assertTrue(tasks.get(0).getTaskId() > 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user