1、新增任务批量审核接口
This commit is contained in:
@@ -12,7 +12,9 @@ import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/task")
|
||||
@@ -155,4 +157,28 @@ public class TaskController implements TaskControllerApi {
|
||||
.setData("success", commandService.setCommandJudged(commandId, isJudged))
|
||||
.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 java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface TaskMapper {
|
||||
@@ -58,4 +59,6 @@ public interface TaskMapper {
|
||||
|
||||
Integer queryTaskTotalNum(@Param("task_status") Integer taskStatus, @Param("task_type") Integer task_type,
|
||||
@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.Task;
|
||||
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.audit.AuditStatusEnum;
|
||||
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.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@DS("mysql")
|
||||
public class TaskService {
|
||||
private final TaskMapper taskMapper;
|
||||
private final SqlSessionWrapper sqlSessionWrapper;
|
||||
|
||||
public TaskService(TaskMapper taskMapper) {
|
||||
public TaskService(TaskMapper taskMapper,SqlSessionWrapper sqlSessionWrapper) {
|
||||
this.taskMapper = taskMapper;
|
||||
this.sqlSessionWrapper = sqlSessionWrapper;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -153,4 +159,32 @@ public class TaskService {
|
||||
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String 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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user