diff --git a/src/main/java/com/realtime/protection/server/v1/controller/TCommandController.java b/src/main/java/com/realtime/protection/server/v1/controller/TCommandController.java new file mode 100644 index 0000000..4812e1f --- /dev/null +++ b/src/main/java/com/realtime/protection/server/v1/controller/TCommandController.java @@ -0,0 +1,59 @@ +package com.realtime.protection.server.v1.controller; + + +import com.realtime.protection.configuration.response.ResponseResult; +import com.realtime.protection.server.v1.entity.TCommandTask; +import com.realtime.protection.server.v1.service.TCommandService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@CrossOrigin(origins = "*") +@RestController +@RequestMapping("/t_command") +public class TCommandController { + + @Autowired + private TCommandService tCommandService; + + @GetMapping("/task_list") + public ResponseResult commandList(@RequestParam(value = "page", defaultValue = "1") Integer pageNum, + @RequestParam(value = "page_size", defaultValue = "20") Integer pageSize, + @RequestParam(value = "taskName", required = false) String taskName, + @RequestParam(value = "eventType", required = false) String eventType + ) { + TCommandTask tCommandTask = new TCommandTask(); + tCommandTask.setTaskName(taskName); + tCommandTask.setEventType(eventType); + Long count = tCommandService.countCommandTasks(tCommandTask); + pageNum = (pageNum - 1) * pageSize; + List tCommandTasks = tCommandService.queryCommandTasks(tCommandTask, pageNum, pageSize); + return ResponseResult.ok() + .setData("task_list", tCommandTasks) + .setData("total_num", count); + } + + /** + * 查询所有未被关联的任务 + * + * @param pageNum + * @param pageSize + * @return + */ + @GetMapping("/task_list_no_verify") + public ResponseResult commandList1(@RequestParam(value = "page", defaultValue = "1") Integer pageNum, + @RequestParam(value = "page_size", defaultValue = "20") Integer pageSize, + @RequestParam(value = "taskName", required = false) String taskName, + @RequestParam(value = "eventType", required = false) String eventType) { + TCommandTask tCommandTask = new TCommandTask(); + tCommandTask.setTaskName(taskName); + tCommandTask.setEventType(eventType); + Long count = tCommandService.countCommandTasks1(tCommandTask); + pageNum = (pageNum - 1) * pageSize; + List tCommandTasks = tCommandService.queryCommandTasks1(tCommandTask, pageNum, pageSize); + return ResponseResult.ok() + .setData("task_list", tCommandTasks) + .setData("total_num", count); + } +} diff --git a/src/main/java/com/realtime/protection/server/v1/mapper/TCommandTaskMapper.java b/src/main/java/com/realtime/protection/server/v1/mapper/TCommandTaskMapper.java new file mode 100644 index 0000000..a553ed1 --- /dev/null +++ b/src/main/java/com/realtime/protection/server/v1/mapper/TCommandTaskMapper.java @@ -0,0 +1,81 @@ +package com.realtime.protection.server.v1.mapper; + +import com.realtime.protection.server.v1.entity.TCommandTask; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import java.util.List; + +/** + * (TCommandTask)表数据库访问层 + * + * @author makejava + * @since 2024-08-27 15:36:46 + */ +@Mapper +public interface TCommandTaskMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TCommandTask queryById(Long id); + + /** + * 查询指定行数据 + * + * @param tCommandTask 查询条件 + * @return 对象列表 + */ + List queryAllByLimit(TCommandTask tCommandTask, + @Param("page") int page, + @Param("pageSize") Integer pageSize); + + /** + * 统计总行数 + * + * @param tCommandTask 查询条件 + * @return 总行数 + */ + long count(TCommandTask tCommandTask); + + /** + * 新增数据 + * + * @param tCommandTask 实例对象 + * @return 影响行数 + */ + int insert(TCommandTask tCommandTask); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param tCommandTask 实例对象 + * @return 影响行数 + */ + int update(TCommandTask tCommandTask); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(Long id); + + Long count1(TCommandTask tCommandTask); + + List queryAllByLimit1(TCommandTask tCommandTask, + @Param("page") int page, + @Param("pageSize") Integer pageSize); +} + diff --git a/src/main/java/com/realtime/protection/server/v1/service/TCommandService.java b/src/main/java/com/realtime/protection/server/v1/service/TCommandService.java new file mode 100644 index 0000000..b5ca571 --- /dev/null +++ b/src/main/java/com/realtime/protection/server/v1/service/TCommandService.java @@ -0,0 +1,16 @@ +package com.realtime.protection.server.v1.service; + +import com.realtime.protection.server.v1.entity.TCommandTask; + +import java.util.List; + +public interface TCommandService { + + Long countCommandTasks(TCommandTask tCommandTask); + + List queryCommandTasks(TCommandTask tCommandTask, Integer pageNum, Integer pageSize); + + Long countCommandTasks1(TCommandTask tCommandTask); + + List queryCommandTasks1(TCommandTask tCommandTask, Integer pageNum, Integer pageSize); +} diff --git a/src/main/java/com/realtime/protection/server/v1/service/impl/TCommandServiceImpl.java b/src/main/java/com/realtime/protection/server/v1/service/impl/TCommandServiceImpl.java new file mode 100644 index 0000000..b02d78d --- /dev/null +++ b/src/main/java/com/realtime/protection/server/v1/service/impl/TCommandServiceImpl.java @@ -0,0 +1,39 @@ +package com.realtime.protection.server.v1.service.impl; + +import com.realtime.protection.server.v1.entity.TCommandTask; +import com.realtime.protection.server.v1.mapper.TCommandTaskMapper; +import com.realtime.protection.server.v1.service.TCommandService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Slf4j +@Service +public class TCommandServiceImpl implements TCommandService { + + + @Autowired + private TCommandTaskMapper tCommandTaskMapper; + + @Override + public Long countCommandTasks(TCommandTask tCommandTask) { + return tCommandTaskMapper.count(tCommandTask); + } + + @Override + public List queryCommandTasks(TCommandTask tCommandTask, Integer pageNum, Integer pageSize) { + return tCommandTaskMapper.queryAllByLimit(tCommandTask, pageNum, pageSize); + } + + @Override + public Long countCommandTasks1(TCommandTask tCommandTask) { + return tCommandTaskMapper.count1(tCommandTask); + } + + @Override + public List queryCommandTasks1(TCommandTask tCommandTask, Integer pageNum, Integer pageSize) { + return tCommandTaskMapper.queryAllByLimit1(tCommandTask, pageNum, pageSize); + } +}