1. 增加jackson配置,缩减json数据长度

2. ExceptionHandler添加SaTokenException检查,用于校验登陆
3. ResponseResult添加invalid和unauthorized静态方法
4. Task模块添加单查询,多查询,更新路由
5. Template添加两个JsonProperty
6. Template模块添加query路由
7.
This commit is contained in:
松岳 陈
2024-01-03 22:53:02 +08:00
parent b0c1700bd3
commit 06886de328
16 changed files with 342 additions and 73 deletions

View File

@@ -5,36 +5,28 @@ import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
@Service
public class TaskService {
private final SqlSessionFactory sqlSessionFactory;
private final TaskMapper taskMapper;
public TaskService(SqlSessionFactory sqlSessionFactory) {
public TaskService(SqlSessionFactory sqlSessionFactory, TaskMapper taskMapper) {
this.sqlSessionFactory = sqlSessionFactory;
this.taskMapper = taskMapper;
}
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());
taskMapper.newTaskProtectObjectConcat(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");
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
session.commit();
} catch (Exception e) {
@@ -49,4 +41,66 @@ public class TaskService {
}
return task.getTaskId();
}
public List<Task> queryTasks(Integer taskStatus,
String taskType, String taskName, String taskCreator,
Integer page, Integer pageSize) {
return taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
}
public Task queryTask(Integer id) {
SqlSession session = sqlSessionFactory.openSession(false);
TaskMapper taskMapper = session.getMapper(TaskMapper.class);
Task task;
try {
task = taskMapper.queryTask(id);
if (task == null) {
return null;
}
task.setProtectObjectIds(taskMapper.queryTaskConcatProtectObjectIds(task.getTaskId()));
// task.setDynamicRuleIds(taskMapper.queryTaskConcatDynamicRuleIds(task.getTaskId()));
task.setStaticRuleIds(taskMapper.queryTaskConcatStaticRuleIds(task.getTaskId()));
session.commit();
} catch (Exception e) {
session.rollback();
throw e;
} finally {
session.close();
}
return task;
}
public void updateTask(Task task) {
SqlSession session = sqlSessionFactory.openSession(false);
TaskMapper taskMapper = session.getMapper(TaskMapper.class);
try {
taskMapper.updateTask(task);
taskMapper.clearTaskProtectObjectConcat(task.getTaskId());
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
// taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
if (task.getProtectObjectIds() != null && !task.getProtectObjectIds().isEmpty()) {
taskMapper.newTaskProtectObjectConcat(task.getTaskId(), task.getProtectObjectIds());
}
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());
}
session.commit();
} catch (Exception e) {
session.rollback();
throw e;
} finally {
session.close();
}
}
}