2024-01-03 09:13:22 +08:00
|
|
|
|
package com.realtime.protection.server.task;
|
|
|
|
|
|
|
2024-04-24 14:15:08 +08:00
|
|
|
|
import com.alibaba.excel.util.MapUtils;
|
2024-01-12 14:31:34 +08:00
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
2024-04-24 14:15:08 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
|
|
|
|
|
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
2024-01-17 19:07:04 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.task.DynamicTaskInfo;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.task.Task;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
2024-04-23 21:05:04 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
2024-01-17 09:44:29 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
2024-04-22 15:07:49 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
2024-04-17 14:01:46 +08:00
|
|
|
|
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
2024-04-24 14:15:08 +08:00
|
|
|
|
import com.realtime.protection.server.rule.dynamicrule.DynamicRuleMapper;
|
|
|
|
|
|
import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
|
2024-01-17 09:44:29 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
2024-01-05 09:32:19 +08:00
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
|
2024-04-23 21:05:04 +08:00
|
|
|
|
import java.util.HashMap;
|
2024-01-03 22:53:02 +08:00
|
|
|
|
import java.util.List;
|
2024-04-23 21:05:04 +08:00
|
|
|
|
import java.util.Map;
|
2024-04-22 15:07:49 +08:00
|
|
|
|
import java.util.Objects;
|
2024-04-23 21:05:04 +08:00
|
|
|
|
import java.util.function.Function;
|
2024-04-24 14:15:08 +08:00
|
|
|
|
import java.util.stream.Collectors;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
|
|
|
|
|
|
@Service
|
2024-01-17 09:44:29 +08:00
|
|
|
|
@Slf4j
|
2024-01-15 20:40:55 +08:00
|
|
|
|
@DS("mysql")
|
2024-01-03 09:13:22 +08:00
|
|
|
|
public class TaskService {
|
2024-01-03 22:53:02 +08:00
|
|
|
|
private final TaskMapper taskMapper;
|
2024-04-24 14:15:08 +08:00
|
|
|
|
private final StaticRuleMapper staticRuleMapper;
|
2024-04-23 21:05:04 +08:00
|
|
|
|
private final SqlSessionWrapper sqlSessionWrapper;
|
2024-04-24 14:15:08 +08:00
|
|
|
|
private static final int BATCH_SIZE = 100;
|
|
|
|
|
|
private final DynamicRuleMapper dynamicRuleMapper;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
|
2024-04-24 14:15:08 +08:00
|
|
|
|
public TaskService(TaskMapper taskMapper, StaticRuleMapper staticRuleMapper, SqlSessionWrapper sqlSessionWrapper, DynamicRuleMapper dynamicRuleMapper) {
|
2024-01-03 22:53:02 +08:00
|
|
|
|
this.taskMapper = taskMapper;
|
2024-04-24 14:15:08 +08:00
|
|
|
|
this.staticRuleMapper = staticRuleMapper;
|
2024-04-23 21:05:04 +08:00
|
|
|
|
this.sqlSessionWrapper = sqlSessionWrapper;
|
2024-04-24 14:15:08 +08:00
|
|
|
|
this.dynamicRuleMapper = dynamicRuleMapper;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-08 20:01:20 +08:00
|
|
|
|
@Transactional
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public Long newTask(Task task) {
|
2024-01-15 20:40:55 +08:00
|
|
|
|
task.setTaskCreateUserId(1);
|
|
|
|
|
|
task.setTaskCreateUsername("xxx");
|
|
|
|
|
|
task.setTaskCreateDepart("xxx");
|
|
|
|
|
|
|
2024-01-08 20:01:20 +08:00
|
|
|
|
taskMapper.newTask(task);
|
|
|
|
|
|
|
2024-04-24 14:15:08 +08:00
|
|
|
|
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty()) {
|
|
|
|
|
|
staticRuleMapper.queryStaticRuleByIds(task.getStaticRuleIds()).forEach(staticRuleObject -> {
|
|
|
|
|
|
if (!staticRuleObject.getAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) {
|
|
|
|
|
|
throw new IllegalArgumentException("部分规则审批状态错误");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (staticRuleObject.getStaticRuleUsedTaskId() != null) {
|
|
|
|
|
|
throw new IllegalArgumentException("部分静态规则已被其他任务使用");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-01-12 14:31:34 +08:00
|
|
|
|
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
2024-04-24 14:15:08 +08:00
|
|
|
|
}
|
2024-01-12 14:31:34 +08:00
|
|
|
|
|
2024-04-24 14:15:08 +08:00
|
|
|
|
if (task.getDynamicRuleIds() != null && !task.getDynamicRuleIds().isEmpty()) {
|
|
|
|
|
|
dynamicRuleMapper.queryDynamicRuleByIds(task.getDynamicRuleIds()).forEach(dynamicRuleObject -> {
|
|
|
|
|
|
if (!dynamicRuleObject.getAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) {
|
|
|
|
|
|
throw new IllegalArgumentException("部分规则审批状态错误");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dynamicRuleObject.getDynamicRuleUsedTaskId() != null) {
|
|
|
|
|
|
throw new IllegalArgumentException("部分动态规则已被其他任务使用");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-01-12 14:31:34 +08:00
|
|
|
|
taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds());
|
2024-04-24 14:15:08 +08:00
|
|
|
|
}
|
2024-01-08 20:01:20 +08:00
|
|
|
|
|
2024-01-03 09:13:22 +08:00
|
|
|
|
return task.getTaskId();
|
|
|
|
|
|
}
|
2024-01-03 22:53:02 +08:00
|
|
|
|
|
2024-04-24 14:15:08 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 更新任务关联的静态规则审批状态,用于任务新建/停止时候,修改审批状态为已使用/已审批,不能用于其他审批状态修改
|
2024-04-24 14:33:42 +08:00
|
|
|
|
* @param taskId 与静态规则关联的任务ID
|
2024-04-24 14:15:08 +08:00
|
|
|
|
* @param newAuditStatus 需要修改的审批状态
|
|
|
|
|
|
*/
|
2024-04-24 14:33:42 +08:00
|
|
|
|
public void updateStaticRuleAuditStatusInTask(Long taskId, AuditStatusEnum newAuditStatus) {
|
|
|
|
|
|
if (taskId == null) {
|
2024-04-24 14:15:08 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 限制该函数仅能用于将规则修改为已审批/使用中
|
|
|
|
|
|
if (!List.of(AuditStatusEnum.AUDITED, AuditStatusEnum.USING).contains(newAuditStatus)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-25 12:09:23 +08:00
|
|
|
|
List<Integer> staticRuleIds = taskMapper.queryStaticRuleIdsFromTaskId(taskId);
|
|
|
|
|
|
if (staticRuleIds == null || staticRuleIds.isEmpty()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<StaticRuleObject> staticRuleObjects = staticRuleMapper.queryStaticRuleByIds(staticRuleIds);
|
2024-04-24 14:15:08 +08:00
|
|
|
|
if (staticRuleObjects == null || staticRuleObjects.isEmpty()) {
|
|
|
|
|
|
throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查所有的静态规则审批状态是否正确,如果不正确则报错
|
|
|
|
|
|
staticRuleObjects.forEach(staticRuleObject -> staticRuleObject.checkAuditStatusValidate(newAuditStatus));
|
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Integer> staticRuleAuditStatusBatch = staticRuleObjects
|
|
|
|
|
|
.stream()
|
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
|
StaticRuleObject::getStaticRuleId,
|
|
|
|
|
|
k -> newAuditStatus.getNum(), // 将审核状态全部修改为使用中状态
|
|
|
|
|
|
(existing, replacement) -> existing)); // 如果有重复字段,默认使用先前值
|
|
|
|
|
|
|
|
|
|
|
|
sqlSessionWrapper.startBatchSession(
|
|
|
|
|
|
StaticRuleMapper.class,
|
|
|
|
|
|
|
|
|
|
|
|
(Function<StaticRuleMapper, Function<Map<Integer, Integer>, Void>>) mapper -> staticRuleBatch -> {
|
|
|
|
|
|
Map<Integer, Integer> batchMap = MapUtils.newHashMapWithExpectedSize(BATCH_SIZE);
|
|
|
|
|
|
for (Map.Entry<Integer, Integer> auditStatusEntry : staticRuleBatch.entrySet()) {
|
|
|
|
|
|
batchMap.put(auditStatusEntry.getKey(), auditStatusEntry.getValue());
|
|
|
|
|
|
if (batchMap.size() < BATCH_SIZE) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mapper.updateAuditStatusByIdBatch(batchMap);
|
|
|
|
|
|
batchMap.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mapper.updateAuditStatusByIdBatch(batchMap);
|
|
|
|
|
|
batchMap.clear();
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
staticRuleAuditStatusBatch
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新任务关联的动态规则审批状态,用于任务新建/停止时候,修改审批状态为已使用/已审批,不能用于其他审批状态修改
|
2024-04-24 14:33:42 +08:00
|
|
|
|
* @param taskId 与动态规则关联的任务ID
|
2024-04-24 14:15:08 +08:00
|
|
|
|
* @param newAuditStatus 需要修改的审批状态
|
|
|
|
|
|
*/
|
2024-04-24 14:33:42 +08:00
|
|
|
|
public void updateDynamicRuleAuditStatusInTask(Long taskId, AuditStatusEnum newAuditStatus) {
|
|
|
|
|
|
if (taskId == null) {
|
2024-04-24 14:15:08 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 限制该函数仅能用于将规则修改为已审批/使用中
|
|
|
|
|
|
if (!List.of(AuditStatusEnum.AUDITED, AuditStatusEnum.USING).contains(newAuditStatus)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-25 12:09:23 +08:00
|
|
|
|
List<Integer> dynamicRuleIds = taskMapper.queryDynamicRuleIdsFromTaskId(taskId);
|
|
|
|
|
|
if (dynamicRuleIds == null || dynamicRuleIds.isEmpty()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<DynamicRuleObject> dynamicRuleObjects = dynamicRuleMapper.queryDynamicRuleByIds(dynamicRuleIds);
|
2024-04-24 14:15:08 +08:00
|
|
|
|
if (dynamicRuleObjects == null || dynamicRuleObjects.isEmpty()) {
|
|
|
|
|
|
throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查所有的动态规则列表的审批状态是否正确,如不正确则报错
|
|
|
|
|
|
dynamicRuleObjects.forEach(dynamicRuleObject -> dynamicRuleObject.checkAuditStatusValidate(newAuditStatus));
|
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, Integer> dynamicRuleAuditStatusBatch = dynamicRuleObjects
|
|
|
|
|
|
.stream()
|
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
|
DynamicRuleObject::getDynamicRuleId,
|
|
|
|
|
|
k -> newAuditStatus.getNum(),
|
|
|
|
|
|
(existing, replacement) -> existing));
|
|
|
|
|
|
|
|
|
|
|
|
sqlSessionWrapper.startBatchSession(
|
|
|
|
|
|
DynamicRuleMapper.class,
|
|
|
|
|
|
|
|
|
|
|
|
(Function<DynamicRuleMapper, Function<Map<Integer, Integer>, Void>>) mapper -> batch -> {
|
|
|
|
|
|
Map<Integer, Integer> batchMap = MapUtils.newHashMapWithExpectedSize(BATCH_SIZE);
|
|
|
|
|
|
for (Map.Entry<Integer, Integer> auditStatusEntry : batch.entrySet()) {
|
|
|
|
|
|
batchMap.put(auditStatusEntry.getKey(), auditStatusEntry.getValue());
|
|
|
|
|
|
if (batchMap.size() < BATCH_SIZE) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mapper.updateAuditStatusByIdBatch(batchMap);
|
|
|
|
|
|
batchMap.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mapper.updateAuditStatusByIdBatch(batchMap);
|
|
|
|
|
|
batchMap.clear();
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
dynamicRuleAuditStatusBatch
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-15 20:40:55 +08:00
|
|
|
|
@Transactional
|
2024-01-03 22:53:02 +08:00
|
|
|
|
public List<Task> queryTasks(Integer taskStatus,
|
2024-01-23 12:17:10 +08:00
|
|
|
|
Integer taskType, String taskName, String taskCreator,
|
2024-04-23 12:15:07 +08:00
|
|
|
|
Integer auditStatus,
|
2024-01-03 22:53:02 +08:00
|
|
|
|
Integer page, Integer pageSize) {
|
2024-04-22 15:07:49 +08:00
|
|
|
|
List<Task> tasks = taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, auditStatus, page, pageSize);
|
2024-01-15 20:40:55 +08:00
|
|
|
|
for (Task task : tasks) {
|
|
|
|
|
|
if (task == null) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
task.setStaticRuleIds(taskMapper.queryStaticRuleIdsFromTaskId(task.getTaskId()));
|
|
|
|
|
|
task.setDynamicRuleIds(taskMapper.queryDynamicRuleIdsFromTaskId(task.getTaskId()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tasks;
|
2024-01-03 22:53:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-15 20:40:55 +08:00
|
|
|
|
@Transactional
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public Task queryTask(Long id) {
|
2024-01-15 20:40:55 +08:00
|
|
|
|
Task task = taskMapper.queryTask(id);
|
|
|
|
|
|
if (task == null) {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
task.setStaticRuleIds(taskMapper.queryStaticRuleIdsFromTaskId(task.getTaskId()));
|
|
|
|
|
|
task.setDynamicRuleIds(taskMapper.queryDynamicRuleIdsFromTaskId(task.getTaskId()));
|
|
|
|
|
|
|
|
|
|
|
|
return task;
|
2024-01-03 22:53:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-05 09:32:19 +08:00
|
|
|
|
@Transactional
|
2024-01-08 20:01:20 +08:00
|
|
|
|
public Boolean updateTask(Task task) {
|
2024-04-22 15:07:49 +08:00
|
|
|
|
if (!Objects.equals(taskMapper.queryTaskAuditStatus(task.getTaskId()), AuditStatusEnum.AUDITED.getNum())) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
task.setTaskAuditStatus(AuditStatusEnum.PENDING.getNum());
|
|
|
|
|
|
|
2024-01-05 09:32:19 +08:00
|
|
|
|
taskMapper.updateTask(task);
|
2024-01-03 22:53:02 +08:00
|
|
|
|
|
2024-01-05 09:32:19 +08:00
|
|
|
|
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
2024-01-08 20:01:20 +08:00
|
|
|
|
taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
|
2024-01-03 22:53:02 +08:00
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
|
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());
|
2024-01-08 20:01:20 +08:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public Boolean changeTaskAuditStatus(Long taskId, Integer taskAuditStatus) {
|
|
|
|
|
|
Integer originalAuditStatus = taskMapper.queryTaskAuditStatus(taskId);
|
|
|
|
|
|
if (originalAuditStatus == null) {
|
2024-01-13 10:23:48 +08:00
|
|
|
|
throw new IllegalArgumentException("无法找到任务ID为" + taskId + "的任务,也许任务不存在?");
|
2024-01-11 19:49:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
|
2024-01-08 20:01:20 +08:00
|
|
|
|
taskMapper.changeTaskAuditStatus(taskId, taskAuditStatus);
|
|
|
|
|
|
else return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public Boolean deleteTask(Long taskId) {
|
2024-04-24 14:15:08 +08:00
|
|
|
|
Task task = taskMapper.queryTask(taskId);
|
|
|
|
|
|
if (task == null) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-24 14:33:42 +08:00
|
|
|
|
updateStaticRuleAuditStatusInTask(taskId, AuditStatusEnum.AUDITED);
|
|
|
|
|
|
updateDynamicRuleAuditStatusInTask(taskId, AuditStatusEnum.AUDITED);
|
|
|
|
|
|
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
|
|
|
|
|
taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
|
2024-01-08 20:01:20 +08:00
|
|
|
|
return taskMapper.deleteTask(taskId);
|
2024-01-03 22:53:02 +08:00
|
|
|
|
}
|
2024-01-09 09:20:13 +08:00
|
|
|
|
|
2024-01-15 20:40:55 +08:00
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public Boolean changeTaskStatus(Long taskId, Integer stateNum) {
|
|
|
|
|
|
return taskMapper.changeTaskStatus(taskId, stateNum);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<TaskCommandInfo> getStaticCommandInfos(Long taskId) {
|
2024-04-10 15:45:09 +08:00
|
|
|
|
List<TaskCommandInfo> staticCommandInfos = taskMapper.getStaticCommandInfos(taskId);
|
2024-04-11 08:56:35 +08:00
|
|
|
|
|
|
|
|
|
|
staticCommandInfos.forEach(taskCommandInfo -> {
|
|
|
|
|
|
taskCommandInfo.setProtocolNum();
|
|
|
|
|
|
taskCommandInfo.setMask();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-04-10 15:45:09 +08:00
|
|
|
|
return staticCommandInfos;
|
2024-01-11 19:49:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-17 19:07:04 +08:00
|
|
|
|
public List<DynamicTaskInfo> getDynamicTaskInfos(Long taskId) {
|
|
|
|
|
|
return taskMapper.getDynamicTaskInfos(taskId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
|
public Integer queryTaskAuditStatus(Long taskId) {
|
|
|
|
|
|
return taskMapper.queryTaskAuditStatus(taskId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Integer queryTaskStatus(Long taskId) {
|
|
|
|
|
|
return taskMapper.queryTaskStatus(taskId);
|
2024-01-09 09:20:13 +08:00
|
|
|
|
}
|
2024-01-15 20:40:55 +08:00
|
|
|
|
|
|
|
|
|
|
public Long newTaskUsingCommandInfo(TaskCommandInfo taskCommandInfo) {
|
|
|
|
|
|
taskMapper.newTaskUsingCommandInfo(taskCommandInfo);
|
|
|
|
|
|
return taskCommandInfo.getTaskId();
|
|
|
|
|
|
}
|
2024-01-17 09:44:29 +08:00
|
|
|
|
|
|
|
|
|
|
public List<Long> getFinishedTasks() {
|
|
|
|
|
|
return taskMapper.queryTasksByStatus(StateEnum.FINISHED.getStateNum());
|
|
|
|
|
|
}
|
2024-01-22 15:40:03 +08:00
|
|
|
|
|
2024-04-22 15:07:49 +08:00
|
|
|
|
public Integer queryTaskTotalNum(Integer taskStatus, Integer taskType, String taskName, String taskCreator) {
|
2024-01-23 12:17:10 +08:00
|
|
|
|
return taskMapper.queryTaskTotalNum(taskStatus, taskType, taskName, taskCreator);
|
2024-01-22 15:40:03 +08:00
|
|
|
|
}
|
2024-04-23 21:05:04 +08:00
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-25 01:41:28 +08:00
|
|
|
|
|
|
|
|
|
|
public Integer queryAuditTaskTotalNum(Integer auditState) {
|
|
|
|
|
|
return taskMapper.queryAuditTaskTotalNum(auditState);
|
|
|
|
|
|
}
|
2024-01-03 09:13:22 +08:00
|
|
|
|
}
|