|
|
@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
package com.example.api.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.example.api.model.entity.SystemLog; // 导入SystemLog实体类,代表系统日志信息
|
|
|
|
|
|
|
|
import com.example.api.model.vo.SystemLogVo; // 导入SystemLogVo视图对象,用于封装查询条件
|
|
|
|
|
|
|
|
import com.example.api.repository.SystemLogRepository; // 导入SystemLogRepository接口,用于访问系统日志数据
|
|
|
|
|
|
|
|
import com.example.api.service.SystemLogService; // 导入SystemLogService接口,定义系统日志服务
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入Autowired注解,用于自动注入Bean
|
|
|
|
|
|
|
|
import org.springframework.data.jpa.domain.Specification; // 导入Specification接口,用于构建JPA查询条件
|
|
|
|
|
|
|
|
import org.springframework.security.core.parameters.P; // 导入P注解,用于方法参数注解(此处未使用)
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service; // 导入Service注解,标识服务组件
|
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; // 导入StringUtils工具类,用于字符串操作
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.*;
|
|
|
|
|
|
|
|
import java.util.ArrayList; // 导入ArrayList类,用于创建列表(此处未使用)
|
|
|
|
|
|
|
|
import java.util.List; // 导入List类,用于处理列表数据
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 系统日志服务实现类,提供系统日志相关的业务逻辑。
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
|
|
public class SystemLogServiceImpl implements SystemLogService {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SystemLogRepository systemLogRepository; // 自动注入SystemLogRepository
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 记录系统日志。
|
|
|
|
|
|
|
|
* @param log 系统日志对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void record(SystemLog log) {
|
|
|
|
|
|
|
|
systemLogRepository.save(log); // 调用仓库层方法保存系统日志
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取所有系统日志。
|
|
|
|
|
|
|
|
* @return 系统日志列表
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<SystemLog> getAll() {
|
|
|
|
|
|
|
|
return systemLogRepository.findAll(); // 调用仓库层方法查询所有系统日志
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 删除系统日志。
|
|
|
|
|
|
|
|
* @param id 要删除的系统日志ID
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void delete(String id) {
|
|
|
|
|
|
|
|
systemLogRepository.deleteById(id); // 调用仓库层方法根据ID删除系统日志
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据视图对象查询系统日志。
|
|
|
|
|
|
|
|
* @param systemLogVo 视图对象,封装查询条件
|
|
|
|
|
|
|
|
* @return 符合条件的系统日志列表
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<SystemLog> query(SystemLogVo systemLogVo) {
|
|
|
|
|
|
|
|
// 构造查询条件
|
|
|
|
|
|
|
|
Specification<SystemLog> specification = new Specification<SystemLog>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Predicate toPredicate(Root<SystemLog> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
|
|
|
|
|
|
|
Path<String> account = root.get("account"); // 获取account字段
|
|
|
|
|
|
|
|
Path<String> module = root.get("module"); // 获取module字段
|
|
|
|
|
|
|
|
Predicate res = null; // 初始化查询结果
|
|
|
|
|
|
|
|
// 如果账号不为空,构建账号的模糊查询条件
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(systemLogVo.getAccount())) {
|
|
|
|
|
|
|
|
Predicate like1 = criteriaBuilder.like(account.as(String.class), "%" + systemLogVo.getAccount() + "%");
|
|
|
|
|
|
|
|
// 如果模块不为空,构建模块的模糊查询条件
|
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(systemLogVo.getModule())) {
|
|
|
|
|
|
|
|
Predicate like2 = criteriaBuilder.like(module.as(String.class), "%" + systemLogVo.getModule() + "%");
|
|
|
|
|
|
|
|
// 组合账号和模块的查询条件
|
|
|
|
|
|
|
|
res = criteriaBuilder.and(like1, like2);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 仅组合账号的查询条件
|
|
|
|
|
|
|
|
res = criteriaBuilder.and(like1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!StringUtils.isEmpty(systemLogVo.getModule())) {
|
|
|
|
|
|
|
|
// 如果账号为空但模块不为空,仅构建模块的模糊查询条件
|
|
|
|
|
|
|
|
Predicate like2 = criteriaBuilder.like(module.as(String.class), "%" + systemLogVo.getModule() + "%");
|
|
|
|
|
|
|
|
res = criteriaBuilder.and(like2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return res; // 返回查询条件
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return systemLogRepository.findAll(specification); // 调用仓库层方法执行查询
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|