1、新增任务批量审核接口
This commit is contained in:
@@ -12,7 +12,9 @@ import jakarta.validation.constraints.Min;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/task")
|
@RequestMapping("/task")
|
||||||
@@ -155,4 +157,28 @@ public class TaskController implements TaskControllerApi {
|
|||||||
.setData("success", commandService.setCommandJudged(commandId, isJudged))
|
.setData("success", commandService.setCommandJudged(commandId, isJudged))
|
||||||
.setData("command_id", commandId);
|
.setData("command_id", commandId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量修改审核状态
|
||||||
|
*/
|
||||||
|
@PostMapping("/auditbatch")
|
||||||
|
public ResponseResult updateTaskAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||||
|
List<Integer> errorIds = new ArrayList<>();
|
||||||
|
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||||
|
Integer id = entry.getKey();
|
||||||
|
Integer auditStatus = entry.getValue();
|
||||||
|
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||||
|
errorIds.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!errorIds.isEmpty()){
|
||||||
|
return new ResponseResult(400, "id or status is invalid")
|
||||||
|
.setData("tasks_id", errorIds)
|
||||||
|
.setData("success", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseResult.ok()
|
||||||
|
.setData("success", taskService.updateAuditStatusBatch(idsWithAuditStatusMap));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface TaskMapper {
|
public interface TaskMapper {
|
||||||
@@ -58,4 +59,6 @@ public interface TaskMapper {
|
|||||||
|
|
||||||
Integer queryTaskTotalNum(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
|
Integer queryTaskTotalNum(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
|
||||||
@Param("task_name") String taskName, @Param("task_creator") String taskCreator);
|
@Param("task_name") String taskName, @Param("task_creator") String taskCreator);
|
||||||
|
|
||||||
|
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
|
|||||||
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
|
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
|
||||||
import com.realtime.protection.configuration.entity.task.Task;
|
import com.realtime.protection.configuration.entity.task.Task;
|
||||||
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
||||||
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||||
@@ -11,17 +12,22 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@DS("mysql")
|
@DS("mysql")
|
||||||
public class TaskService {
|
public class TaskService {
|
||||||
private final TaskMapper taskMapper;
|
private final TaskMapper taskMapper;
|
||||||
|
private final SqlSessionWrapper sqlSessionWrapper;
|
||||||
|
|
||||||
public TaskService(TaskMapper taskMapper) {
|
public TaskService(TaskMapper taskMapper,SqlSessionWrapper sqlSessionWrapper) {
|
||||||
this.taskMapper = taskMapper;
|
this.taskMapper = taskMapper;
|
||||||
|
this.sqlSessionWrapper = sqlSessionWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -153,4 +159,32 @@ public class TaskService {
|
|||||||
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String taskCreator) {
|
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String taskCreator) {
|
||||||
return taskMapper.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator);
|
return taskMapper.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||||
|
Function<TaskMapper, Function<Map<Integer, Integer>, Boolean>> updateTaskAuditStatusFunction =
|
||||||
|
mapper -> map -> {
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, Integer> idWithAuditStatusBatch = new HashMap<>();
|
||||||
|
for (Map.Entry<Integer, Integer> item : map.entrySet()) {
|
||||||
|
idWithAuditStatusBatch.put(item.getKey(), item.getValue());
|
||||||
|
if (idWithAuditStatusBatch.size() < 100) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//mapper指的就是外层函数输入的参数,也就是WhiteListMapper
|
||||||
|
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||||
|
idWithAuditStatusBatch.clear();
|
||||||
|
}
|
||||||
|
if (!idWithAuditStatusBatch.isEmpty()) {
|
||||||
|
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
//实现事务操作
|
||||||
|
return sqlSessionWrapper.startBatchSession(TaskMapper.class, updateTaskAuditStatusFunction, idsWithAuditStatusMap);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,21 @@
|
|||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 批量审核 -->
|
||||||
|
<update id="updateAuditStatusByIdBatch">
|
||||||
|
update t_task
|
||||||
|
set task_audit_status = CASE task_id
|
||||||
|
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
|
||||||
|
WHEN #{id} THEN #{auditStatus}
|
||||||
|
</foreach>
|
||||||
|
ELSE task_audit_status
|
||||||
|
END
|
||||||
|
WHERE task_id IN
|
||||||
|
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
|
|
||||||
<delete id="deleteTask">
|
<delete id="deleteTask">
|
||||||
DELETE
|
DELETE
|
||||||
FROM t_task
|
FROM t_task
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ import org.springframework.dao.DataIntegrityViolationException;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewTaskSuccess() {
|
void testNewTaskSuccess() {
|
||||||
for (int i = 1; i < 1000; i++) {
|
for (int i = 1; i < 10; i++) {
|
||||||
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
|
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(
|
||||||
null, null, null, null, i, 2);
|
null, null, null, null, i, 2);
|
||||||
List<Integer> staticRuleIds = new ArrayList<>();
|
List<Integer> staticRuleIds = new ArrayList<>();
|
||||||
@@ -175,4 +177,16 @@ class TaskServiceTest extends ProtectionApplicationTests {
|
|||||||
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(38L);
|
List<TaskCommandInfo> taskCommandInfos = taskService.getStaticCommandInfos(38L);
|
||||||
assertNotNull(taskCommandInfos);
|
assertNotNull(taskCommandInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUpdateTaskAuditStatusBatch(){
|
||||||
|
Map<Integer, Integer> map = new HashMap<>();
|
||||||
|
map.put(43830, 1);
|
||||||
|
map.put(43831, 1);
|
||||||
|
map.put(43832, 1);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(taskService.updateAuditStatusBatch(map));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user