refactor(util): 重构工具类
This commit is contained in:
+1
-1
@@ -165,7 +165,7 @@ public interface KitMpMapper<E> extends BaseMapper<E> {
|
||||
pageSize = pageSize <= 0 ? 10 : pageSize;
|
||||
IPage<E> pageInfo = wrapper.page(new Page<>(pageNumber, pageSize));
|
||||
if (CollUtil.isEmpty(pageInfo.getRecords())) {
|
||||
return KitPageUtil.emptyListData();
|
||||
return KitPageUtil.emptyData();
|
||||
}
|
||||
return new KitPageResult<>(KitBeanUtil.copyToList(pageInfo.getRecords(), clazz), pageInfo.getTotal());
|
||||
}
|
||||
|
||||
+3
-3
@@ -76,12 +76,12 @@ public final class KitBigDecimalUtil {
|
||||
*
|
||||
* @param a 乘数
|
||||
* @param b 乘数
|
||||
* @return 两个乘数的积, 保留两位小数
|
||||
* @return 两个乘数的积, 保留6位小数
|
||||
*/
|
||||
public static BigDecimal multiply(Object a, Object b) {
|
||||
BigDecimal bdA = toBigDecimal(a);
|
||||
BigDecimal bdB = toBigDecimal(b);
|
||||
return bdA.multiply(bdB).setScale(2, RoundingMode.HALF_UP);
|
||||
return bdA.multiply(bdB).setScale(6, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ public final class KitBigDecimalUtil {
|
||||
public static BigDecimal divide(Object a, Object b) {
|
||||
BigDecimal bdA = toBigDecimal(a);
|
||||
BigDecimal bdB = toBigDecimal(b);
|
||||
return bdA.divide(bdB, 2, RoundingMode.HALF_UP);
|
||||
return bdA.divide(bdB, 6, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-4
@@ -30,7 +30,7 @@ import lombok.experimental.UtilityClass;
|
||||
public class KitDateUtil {
|
||||
|
||||
/**
|
||||
* 获取当前时间毫秒数
|
||||
* 获取当前时间毫秒数 yyyyMMddHHmmssSSS
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ public class KitDateUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间,但不包括毫秒数
|
||||
* 获取当前时间,但不包括毫秒数 yyyyMMddHHmmss
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ public class KitDateUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间,但不包括毫秒数
|
||||
* 获取当前时间,但不包括毫秒数 yyyyMMdd
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ public class KitDateUtil {
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 格式化后的时间,X天X时X分X秒X毫秒
|
||||
* @return 格式化后的时间,X天X时X分X秒
|
||||
*/
|
||||
public static String formatMillsDuration(Date startTime, Date endTime) {
|
||||
if (startTime == null || endTime == null) {
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* @author odboy
|
||||
* @date 2025-04-05
|
||||
*/
|
||||
@Deprecated
|
||||
public final class KitDistributedIdUtil {
|
||||
|
||||
/**
|
||||
|
||||
+8
-7
@@ -20,6 +20,7 @@ import static cn.odboy.constant.SystemConst.SYMBOL_AT;
|
||||
import static cn.odboy.constant.SystemConst.SYMBOL_EQUAL;
|
||||
import static cn.odboy.constant.SystemConst.SYMBOL_SUBTRACT;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
@@ -27,6 +28,9 @@ import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.odboy.constant.FileTypeEnum;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.framework.exception.BadRequestException;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -41,9 +45,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
@@ -55,7 +56,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*/
|
||||
@Slf4j
|
||||
@UtilityClass
|
||||
public final class KitFileUtil extends cn.hutool.core.io.FileUtil {
|
||||
public final class KitFileUtil {
|
||||
|
||||
/**
|
||||
* 系统临时目录
|
||||
@@ -92,7 +93,7 @@ public final class KitFileUtil extends cn.hutool.core.io.FileUtil {
|
||||
// 获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 获取文件后缀
|
||||
String prefix = "." + getSuffix(fileName);
|
||||
String prefix = "." + FileUtil.getSuffix(fileName);
|
||||
File file = null;
|
||||
try {
|
||||
// 用uuid作为文件名, 防止生成的临时文件重复
|
||||
@@ -158,8 +159,8 @@ public final class KitFileUtil extends cn.hutool.core.io.FileUtil {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssS");
|
||||
// 过滤非法文件名
|
||||
String name = getPrefix(verifyFilename(file.getOriginalFilename()));
|
||||
String suffix = getSuffix(file.getOriginalFilename());
|
||||
String name = FileUtil.getPrefix(verifyFilename(file.getOriginalFilename()));
|
||||
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
|
||||
String nowStr = "-" + format.format(date);
|
||||
try {
|
||||
String fileName = name + nowStr + "." + suffix;
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
package cn.odboy.util;
|
||||
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -62,13 +59,6 @@ public final class KitPageUtil extends cn.hutool.core.util.PageUtil {
|
||||
return new KitPageResult<>(list, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回空数据
|
||||
*/
|
||||
public static <T> KitPageResult<T> emptyListData() {
|
||||
return new KitPageResult<>(new ArrayList<>(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回空数据
|
||||
*/
|
||||
@@ -82,8 +72,4 @@ public final class KitPageUtil extends cn.hutool.core.util.PageUtil {
|
||||
public static <T> KitPageResult<T> toPage(List<T> list, long totalElements) {
|
||||
return new KitPageResult<>(list, totalElements);
|
||||
}
|
||||
|
||||
public static <T> Page<T> getCount(BaseMapper<T> baseMapper) {
|
||||
return new Page<>(1, baseMapper.selectCount(null));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ public class OperationLogAspect {
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
bizName = "默认业务";
|
||||
bizName = "Default";
|
||||
}
|
||||
String method = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
Object[] args = joinPoint.getArgs();
|
||||
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.system.framework.operalog;
|
||||
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.framework.context.KitRequestHolder;
|
||||
import cn.odboy.system.dal.dataobject.SystemOperationLogTb;
|
||||
import cn.odboy.system.dal.mysql.SystemOperationLogMapper;
|
||||
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
|
||||
import cn.odboy.util.KitBrowserUtil;
|
||||
import cn.odboy.util.KitIPUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.lang.reflect.Method;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 捕捉操作日志
|
||||
*
|
||||
* @author odboy
|
||||
* @date 2025-05-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class SystemOperationLogAspect {
|
||||
|
||||
@Autowired
|
||||
private SystemOperationLogMapper systemOperationLogMapper;
|
||||
|
||||
@Around("@annotation(operationLog)")
|
||||
public Object operationLogCatch(ProceedingJoinPoint joinPoint, OperationLog operationLog) throws Throwable {
|
||||
return handleLog(joinPoint, operationLog);
|
||||
}
|
||||
|
||||
private Object handleLog(ProceedingJoinPoint joinPoint, OperationLog annotation) throws Throwable {
|
||||
TimeInterval timeInterval = new TimeInterval();
|
||||
try {
|
||||
Object result = joinPoint.proceed();
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// log.error("保存审计日志失败", e);
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} catch (Throwable exception) {
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
|
||||
record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception));
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// log.error("保存审计日志失败", e);
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private SystemOperationLogTb getOperationLogTb(ProceedingJoinPoint joinPoint, OperationLog annotation,
|
||||
TimeInterval timeInterval) {
|
||||
long executeTime = timeInterval.intervalMs();
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
String bizName = annotation.bizName();
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
Method method = signature.getMethod();
|
||||
ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
|
||||
if (apiOperation != null) {
|
||||
bizName = apiOperation.value();
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
bizName = "默认业务";
|
||||
}
|
||||
String method = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
Object[] args = joinPoint.getArgs();
|
||||
String params = JSON.toJSONString(args);
|
||||
HttpServletRequest request = KitRequestHolder.getHttpServletRequest();
|
||||
String requestIp = KitBrowserUtil.getIp(request);
|
||||
String browserInfo = KitBrowserUtil.getVersion(request);
|
||||
String address = KitIPUtil.getCityInfo(requestIp);
|
||||
String username = KitSecurityHelper.getCurrentUsername();
|
||||
SystemOperationLogTb record = new SystemOperationLogTb();
|
||||
record.setBizName(bizName);
|
||||
record.setMethod(method);
|
||||
record.setParams(params);
|
||||
record.setRequestIp(requestIp);
|
||||
record.setExecuteTime(executeTime);
|
||||
record.setUsername(username);
|
||||
record.setAddress(address);
|
||||
record.setBrowserInfo(browserInfo);
|
||||
return record;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/captcha")
|
||||
@Api(tags = "系统:验证码管理")
|
||||
public class SystemCaptchaOpenController {
|
||||
public class OpenCaptchaController {
|
||||
|
||||
@Autowired
|
||||
private SystemCaptchaService systemCaptchaService;
|
||||
+1
-1
@@ -165,7 +165,7 @@ public interface KitMpMapper<E> extends BaseMapper<E> {
|
||||
pageSize = pageSize <= 0 ? 10 : pageSize;
|
||||
IPage<E> pageInfo = wrapper.page(new Page<>(pageNumber, pageSize));
|
||||
if (CollUtil.isEmpty(pageInfo.getRecords())) {
|
||||
return KitPageUtil.emptyListData();
|
||||
return KitPageUtil.emptyData();
|
||||
}
|
||||
return new KitPageResult<>(KitBeanUtil.copyToList(pageInfo.getRecords(), clazz), pageInfo.getTotal());
|
||||
}
|
||||
|
||||
@@ -76,12 +76,12 @@ public final class KitBigDecimalUtil {
|
||||
*
|
||||
* @param a 乘数
|
||||
* @param b 乘数
|
||||
* @return 两个乘数的积, 保留两位小数
|
||||
* @return 两个乘数的积, 保留6位小数
|
||||
*/
|
||||
public static BigDecimal multiply(Object a, Object b) {
|
||||
BigDecimal bdA = toBigDecimal(a);
|
||||
BigDecimal bdB = toBigDecimal(b);
|
||||
return bdA.multiply(bdB).setScale(2, RoundingMode.HALF_UP);
|
||||
return bdA.multiply(bdB).setScale(6, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ public final class KitBigDecimalUtil {
|
||||
public static BigDecimal divide(Object a, Object b) {
|
||||
BigDecimal bdA = toBigDecimal(a);
|
||||
BigDecimal bdB = toBigDecimal(b);
|
||||
return bdA.divide(bdB, 2, RoundingMode.HALF_UP);
|
||||
return bdA.divide(bdB, 6, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,7 +30,7 @@ import lombok.experimental.UtilityClass;
|
||||
public class KitDateUtil {
|
||||
|
||||
/**
|
||||
* 获取当前时间毫秒数
|
||||
* 获取当前时间毫秒数 yyyyMMddHHmmssSSS
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ public class KitDateUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间,但不包括毫秒数
|
||||
* 获取当前时间,但不包括毫秒数 yyyyMMddHHmmss
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ public class KitDateUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间,但不包括毫秒数
|
||||
* 获取当前时间,但不包括毫秒数 yyyyMMdd
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ public class KitDateUtil {
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 格式化后的时间,X天X时X分X秒X毫秒
|
||||
* @return 格式化后的时间,X天X时X分X秒
|
||||
*/
|
||||
public static String formatMillsDuration(Date startTime, Date endTime) {
|
||||
if (startTime == null || endTime == null) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* @author odboy
|
||||
* @date 2025-04-05
|
||||
*/
|
||||
@Deprecated
|
||||
public final class KitDistributedIdUtil {
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ import static cn.odboy.constant.SystemConst.SYMBOL_AT;
|
||||
import static cn.odboy.constant.SystemConst.SYMBOL_EQUAL;
|
||||
import static cn.odboy.constant.SystemConst.SYMBOL_SUBTRACT;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.poi.excel.BigExcelWriter;
|
||||
@@ -55,7 +56,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*/
|
||||
@Slf4j
|
||||
@UtilityClass
|
||||
public final class KitFileUtil extends cn.hutool.core.io.FileUtil {
|
||||
public final class KitFileUtil {
|
||||
|
||||
/**
|
||||
* 系统临时目录
|
||||
@@ -92,7 +93,7 @@ public final class KitFileUtil extends cn.hutool.core.io.FileUtil {
|
||||
// 获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 获取文件后缀
|
||||
String prefix = "." + getSuffix(fileName);
|
||||
String prefix = "." + FileUtil.getSuffix(fileName);
|
||||
File file = null;
|
||||
try {
|
||||
// 用uuid作为文件名, 防止生成的临时文件重复
|
||||
@@ -158,8 +159,8 @@ public final class KitFileUtil extends cn.hutool.core.io.FileUtil {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssS");
|
||||
// 过滤非法文件名
|
||||
String name = getPrefix(verifyFilename(file.getOriginalFilename()));
|
||||
String suffix = getSuffix(file.getOriginalFilename());
|
||||
String name = FileUtil.getPrefix(verifyFilename(file.getOriginalFilename()));
|
||||
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
|
||||
String nowStr = "-" + format.format(date);
|
||||
try {
|
||||
String fileName = name + nowStr + "." + suffix;
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
package cn.odboy.util;
|
||||
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@@ -62,13 +59,6 @@ public final class KitPageUtil extends cn.hutool.core.util.PageUtil {
|
||||
return new KitPageResult<>(list, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回空数据
|
||||
*/
|
||||
public static <T> KitPageResult<T> emptyListData() {
|
||||
return new KitPageResult<>(new ArrayList<>(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回空数据
|
||||
*/
|
||||
@@ -82,8 +72,4 @@ public final class KitPageUtil extends cn.hutool.core.util.PageUtil {
|
||||
public static <T> KitPageResult<T> toPage(List<T> list, long totalElements) {
|
||||
return new KitPageResult<>(list, totalElements);
|
||||
}
|
||||
|
||||
public static <T> Page<T> getCount(BaseMapper<T> baseMapper) {
|
||||
return new Page<>(1, baseMapper.selectCount(null));
|
||||
}
|
||||
}
|
||||
|
||||
+120
-120
@@ -1,120 +1,120 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.system.framework.operalog;
|
||||
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.framework.context.KitRequestHolder;
|
||||
import cn.odboy.system.dal.dataobject.SystemOperationLogTb;
|
||||
import cn.odboy.system.dal.mysql.SystemOperationLogMapper;
|
||||
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
|
||||
import cn.odboy.util.KitBrowserUtil;
|
||||
import cn.odboy.util.KitIPUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 捕捉操作日志
|
||||
*
|
||||
* @author odboy
|
||||
* @date 2025-05-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class OperationLogAspect {
|
||||
|
||||
@Autowired
|
||||
private SystemOperationLogMapper systemOperationLogMapper;
|
||||
|
||||
@Around("@annotation(operationLog)")
|
||||
public Object operationLogCatch(ProceedingJoinPoint joinPoint, OperationLog operationLog) throws Throwable {
|
||||
return handleLog(joinPoint, operationLog);
|
||||
}
|
||||
|
||||
private Object handleLog(ProceedingJoinPoint joinPoint, OperationLog annotation) throws Throwable {
|
||||
TimeInterval timeInterval = new TimeInterval();
|
||||
try {
|
||||
Object result = joinPoint.proceed();
|
||||
long interval = timeInterval.interval();
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, interval);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} catch (Throwable exception) {
|
||||
long interval = timeInterval.interval();
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, interval);
|
||||
record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception));
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private SystemOperationLogTb getOperationLogTb(ProceedingJoinPoint joinPoint, OperationLog annotation, long executeTime) {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
String bizName = annotation.bizName();
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
Method method = signature.getMethod();
|
||||
ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
|
||||
if (apiOperation != null) {
|
||||
bizName = apiOperation.value();
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
bizName = "默认业务";
|
||||
}
|
||||
String method = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
Object[] args = joinPoint.getArgs();
|
||||
String params = JSON.toJSONString(args);
|
||||
HttpServletRequest request = KitRequestHolder.getHttpServletRequest();
|
||||
String requestIp = KitBrowserUtil.getIp(request);
|
||||
String browserInfo = KitBrowserUtil.getVersion(request);
|
||||
String address = KitIPUtil.getCityInfo(requestIp);
|
||||
String username = KitSecurityHelper.getCurrentUsername();
|
||||
SystemOperationLogTb record = new SystemOperationLogTb();
|
||||
record.setBizName(bizName);
|
||||
record.setMethod(method);
|
||||
record.setParams(params);
|
||||
record.setRequestIp(requestIp);
|
||||
record.setExecuteTime(executeTime);
|
||||
record.setUsername(username);
|
||||
record.setAddress(address);
|
||||
record.setBrowserInfo(browserInfo);
|
||||
return record;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.system.framework.operalog;
|
||||
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.framework.context.KitRequestHolder;
|
||||
import cn.odboy.system.dal.dataobject.SystemOperationLogTb;
|
||||
import cn.odboy.system.dal.mysql.SystemOperationLogMapper;
|
||||
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
|
||||
import cn.odboy.util.KitBrowserUtil;
|
||||
import cn.odboy.util.KitIPUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 捕捉操作日志
|
||||
*
|
||||
* @author odboy
|
||||
* @date 2025-05-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class OperationLogAspect {
|
||||
|
||||
@Autowired
|
||||
private SystemOperationLogMapper systemOperationLogMapper;
|
||||
|
||||
@Around("@annotation(operationLog)")
|
||||
public Object operationLogCatch(ProceedingJoinPoint joinPoint, OperationLog operationLog) throws Throwable {
|
||||
return handleLog(joinPoint, operationLog);
|
||||
}
|
||||
|
||||
private Object handleLog(ProceedingJoinPoint joinPoint, OperationLog annotation) throws Throwable {
|
||||
TimeInterval timeInterval = new TimeInterval();
|
||||
try {
|
||||
Object result = joinPoint.proceed();
|
||||
long interval = timeInterval.interval();
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, interval);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} catch (Throwable exception) {
|
||||
long interval = timeInterval.interval();
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, interval);
|
||||
record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception));
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private SystemOperationLogTb getOperationLogTb(ProceedingJoinPoint joinPoint, OperationLog annotation, long executeTime) {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
String bizName = annotation.bizName();
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
Method method = signature.getMethod();
|
||||
ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
|
||||
if (apiOperation != null) {
|
||||
bizName = apiOperation.value();
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
bizName = "默认业务";
|
||||
}
|
||||
String method = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
Object[] args = joinPoint.getArgs();
|
||||
String params = JSON.toJSONString(args);
|
||||
HttpServletRequest request = KitRequestHolder.getHttpServletRequest();
|
||||
String requestIp = KitBrowserUtil.getIp(request);
|
||||
String browserInfo = KitBrowserUtil.getVersion(request);
|
||||
String address = KitIPUtil.getCityInfo(requestIp);
|
||||
String username = KitSecurityHelper.getCurrentUsername();
|
||||
SystemOperationLogTb record = new SystemOperationLogTb();
|
||||
record.setBizName(bizName);
|
||||
record.setMethod(method);
|
||||
record.setParams(params);
|
||||
record.setRequestIp(requestIp);
|
||||
record.setExecuteTime(executeTime);
|
||||
record.setUsername(username);
|
||||
record.setAddress(address);
|
||||
record.setBrowserInfo(browserInfo);
|
||||
return record;
|
||||
}
|
||||
}
|
||||
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021-2025 Odboy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.system.framework.operalog;
|
||||
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.framework.context.KitRequestHolder;
|
||||
import cn.odboy.system.dal.dataobject.SystemOperationLogTb;
|
||||
import cn.odboy.system.dal.mysql.SystemOperationLogMapper;
|
||||
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
|
||||
import cn.odboy.util.KitBrowserUtil;
|
||||
import cn.odboy.util.KitIPUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 捕捉操作日志
|
||||
*
|
||||
* @author odboy
|
||||
* @date 2025-05-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class SystemOperationLogAspect {
|
||||
|
||||
@Autowired
|
||||
private SystemOperationLogMapper systemOperationLogMapper;
|
||||
|
||||
@Around("@annotation(operationLog)")
|
||||
public Object operationLogCatch(ProceedingJoinPoint joinPoint, OperationLog operationLog) throws Throwable {
|
||||
return handleLog(joinPoint, operationLog);
|
||||
}
|
||||
|
||||
private Object handleLog(ProceedingJoinPoint joinPoint, OperationLog annotation) throws Throwable {
|
||||
TimeInterval timeInterval = new TimeInterval();
|
||||
try {
|
||||
Object result = joinPoint.proceed();
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// log.error("保存审计日志失败", e);
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} catch (Throwable exception) {
|
||||
SystemOperationLogTb record = getOperationLogTb(joinPoint, annotation, timeInterval);
|
||||
record.setExceptionDetail(ExceptionUtil.stacktraceToString(exception));
|
||||
ThreadUtil.execAsync(() -> {
|
||||
try {
|
||||
systemOperationLogMapper.insert(record);
|
||||
} catch (Exception e) {
|
||||
// log.error("保存审计日志失败", e);
|
||||
// 忽略
|
||||
}
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private SystemOperationLogTb getOperationLogTb(ProceedingJoinPoint joinPoint, OperationLog annotation,
|
||||
TimeInterval timeInterval) {
|
||||
long executeTime = timeInterval.intervalMs();
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
String bizName = annotation.bizName();
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
Method method = signature.getMethod();
|
||||
ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
|
||||
if (apiOperation != null) {
|
||||
bizName = apiOperation.value();
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(bizName)) {
|
||||
bizName = "默认业务";
|
||||
}
|
||||
String method = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
Object[] args = joinPoint.getArgs();
|
||||
String params = JSON.toJSONString(args);
|
||||
HttpServletRequest request = KitRequestHolder.getHttpServletRequest();
|
||||
String requestIp = KitBrowserUtil.getIp(request);
|
||||
String browserInfo = KitBrowserUtil.getVersion(request);
|
||||
String address = KitIPUtil.getCityInfo(requestIp);
|
||||
String username = KitSecurityHelper.getCurrentUsername();
|
||||
SystemOperationLogTb record = new SystemOperationLogTb();
|
||||
record.setBizName(bizName);
|
||||
record.setMethod(method);
|
||||
record.setParams(params);
|
||||
record.setRequestIp(requestIp);
|
||||
record.setExecuteTime(executeTime);
|
||||
record.setUsername(username);
|
||||
record.setAddress(address);
|
||||
record.setBrowserInfo(browserInfo);
|
||||
return record;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/captcha")
|
||||
@Api(tags = "系统:验证码管理")
|
||||
public class SystemCaptchaOpenController {
|
||||
public class OpenCaptchaController {
|
||||
|
||||
@Autowired
|
||||
private SystemCaptchaService systemCaptchaService;
|
||||
Reference in New Issue
Block a user