From 00c3fddbf1a779f0f3186bc41c7142feb18c20ca Mon Sep 17 00:00:00 2001 From: Odboy Date: Thu, 8 Jan 2026 21:02:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(util):=20=E9=87=8D=E6=9E=84=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/interfaces/KitMpMapper.java | 2 +- .../java/cn/odboy/util/KitBigDecimalUtil.java | 6 +- .../main/java/cn/odboy/util/KitDateUtil.java | 8 +- .../cn/odboy/util/KitDistributedIdUtil.java | 1 + .../main/java/cn/odboy/util/KitFileUtil.java | 15 +- .../main/java/cn/odboy/util/KitPageUtil.java | 14 - .../operalog/OperationLogAspect.java | 2 +- .../operalog/SystemOperationLogAspect.java | 122 --------- ...roller.java => OpenCaptchaController.java} | 2 +- .../core/interfaces/KitMpMapper.java | 2 +- .../java/cn/odboy/util/KitBigDecimalUtil.java | 6 +- .../main/java/cn/odboy/util/KitDateUtil.java | 8 +- .../cn/odboy/util/KitDistributedIdUtil.java | 1 + .../main/java/cn/odboy/util/KitFileUtil.java | 9 +- .../main/java/cn/odboy/util/KitPageUtil.java | 14 - .../operalog/OperationLogAspect.java | 240 +++++++++--------- .../operalog/SystemOperationLogAspect.java | 122 --------- ...roller.java => OpenCaptchaController.java} | 2 +- 18 files changed, 154 insertions(+), 422 deletions(-) delete mode 100644 cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java rename cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/openapi/{SystemCaptchaOpenController.java => OpenCaptchaController.java} (97%) delete mode 100644 cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java rename cutejava/cutejava-module-system/src/main/java/cn/odboy/system/openapi/{SystemCaptchaOpenController.java => OpenCaptchaController.java} (97%) diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java index 8278a0b6..2bd4a2c9 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java @@ -165,7 +165,7 @@ public interface KitMpMapper extends BaseMapper { pageSize = pageSize <= 0 ? 10 : pageSize; IPage 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()); } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java index d23d1685..bc215343 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java @@ -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); } /** diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java index 2e4b1d9c..139d006e 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java @@ -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) { diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java index 6f02d687..82f5ec29 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicLong; * @author odboy * @date 2025-04-05 */ +@Deprecated public final class KitDistributedIdUtil { /** diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java index f8d6e7f9..d3589e7b 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java @@ -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; diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java index f1d888aa..abb3cdcf 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java @@ -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 KitPageResult emptyListData() { - return new KitPageResult<>(new ArrayList<>(), 0); - } - /** * 返回空数据 */ @@ -82,8 +72,4 @@ public final class KitPageUtil extends cn.hutool.core.util.PageUtil { public static KitPageResult toPage(List list, long totalElements) { return new KitPageResult<>(list, totalElements); } - - public static Page getCount(BaseMapper baseMapper) { - return new Page<>(1, baseMapper.selectCount(null)); - } } diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java index 2ef520c7..0f7b91b2 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java @@ -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(); diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java deleted file mode 100644 index a168de67..00000000 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java +++ /dev/null @@ -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; - } -} diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/openapi/SystemCaptchaOpenController.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/openapi/OpenCaptchaController.java similarity index 97% rename from cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/openapi/SystemCaptchaOpenController.java rename to cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/openapi/OpenCaptchaController.java index 973d6d2a..88ef9508 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/openapi/SystemCaptchaOpenController.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/openapi/OpenCaptchaController.java @@ -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; diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java index 8278a0b6..2bd4a2c9 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/mybatisplus/core/interfaces/KitMpMapper.java @@ -165,7 +165,7 @@ public interface KitMpMapper extends BaseMapper { pageSize = pageSize <= 0 ? 10 : pageSize; IPage 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()); } diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java index d23d1685..bc215343 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitBigDecimalUtil.java @@ -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); } /** diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java index 2e4b1d9c..139d006e 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDateUtil.java @@ -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) { diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java index 6f02d687..82f5ec29 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitDistributedIdUtil.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicLong; * @author odboy * @date 2025-04-05 */ +@Deprecated public final class KitDistributedIdUtil { /** diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java index 6b17973d..438bd017 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitFileUtil.java @@ -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; diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java index f1d888aa..abb3cdcf 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/util/KitPageUtil.java @@ -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 KitPageResult emptyListData() { - return new KitPageResult<>(new ArrayList<>(), 0); - } - /** * 返回空数据 */ @@ -82,8 +72,4 @@ public final class KitPageUtil extends cn.hutool.core.util.PageUtil { public static KitPageResult toPage(List list, long totalElements) { return new KitPageResult<>(list, totalElements); } - - public static Page getCount(BaseMapper baseMapper) { - return new Page<>(1, baseMapper.selectCount(null)); - } } diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java index 42256389..69fc85eb 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/OperationLogAspect.java @@ -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; + } +} diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java deleted file mode 100644 index 31ca343c..00000000 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/operalog/SystemOperationLogAspect.java +++ /dev/null @@ -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; - } -} diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/openapi/SystemCaptchaOpenController.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/openapi/OpenCaptchaController.java similarity index 97% rename from cutejava/cutejava-module-system/src/main/java/cn/odboy/system/openapi/SystemCaptchaOpenController.java rename to cutejava/cutejava-module-system/src/main/java/cn/odboy/system/openapi/OpenCaptchaController.java index 973d6d2a..88ef9508 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/openapi/SystemCaptchaOpenController.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/openapi/OpenCaptchaController.java @@ -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;