1. 完成新建任务功能,但是未完成静态关键信息功能和动态关键信息功能的关联,需要相关人员沟通

2. 完成新建配置模板功能
3. 修改configuration文件夹中全局异常处理器,添加了几种专门处理数据库异常和Valid异常的处理器。
4. 修改application.yml文件,将hikari自动提交设置为false,此项设置可用于避免数据库发生脏读
This commit is contained in:
松岳 陈
2024-01-03 09:13:22 +08:00
parent 66c710c034
commit 68cd466c9f
16 changed files with 521 additions and 5 deletions

View File

@@ -0,0 +1,52 @@
package com.realtime.protection.server.task;
import com.realtime.protection.configuration.entity.task.Task;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@Service
public class TaskService {
private final SqlSessionFactory sqlSessionFactory;
public TaskService(SqlSessionFactory sqlSessionFactory) {
this.sqlSessionFactory = sqlSessionFactory;
}
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());
// 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");
session.commit();
} catch (Exception e) {
session.rollback();
throw e;
} finally {
session.close();
}
if (task.getTaskId() == null) {
return 0;
}
return task.getTaskId();
}
}