Commit 9ef669141feefd7b314e51f88fc2a1666c7f7c45

Authored by 高高
Committed by Gitee
1 parent d46097a6

优化记录infra_api_access_log方法,截取参数最长8000字符

Signed-off-by: 高高 <171376172@qq.com>
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/logger/ApiAccessLogDO.java
... ... @@ -27,6 +27,16 @@ import java.time.LocalDateTime;
27 27 public class ApiAccessLogDO extends BaseDO {
28 28  
29 29 /**
  30 + * {@link #requestParams} 的最大长度
  31 + */
  32 + public static final Integer REQUEST_PARAMS_MAX_LENGTH = 8000;
  33 +
  34 + /**
  35 + * {@link #resultMsg} 的最大长度
  36 + */
  37 + public static final Integer RESULT_MSG_MAX_LENGTH = 512;
  38 +
  39 + /**
30 40 * 编号
31 41 */
32 42 @TableId
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/logger/ApiErrorLogDO.java
... ... @@ -25,6 +25,12 @@ import java.time.LocalDateTime;
25 25 @KeySequence(value = "infra_api_error_log_seq")
26 26 public class ApiErrorLogDO extends BaseDO {
27 27  
  28 +
  29 + /**
  30 + * {@link #requestParams} 的最大长度
  31 + */
  32 + public static final Integer REQUEST_PARAMS_MAX_LENGTH = 8000;
  33 +
28 34 /**
29 35 * 编号
30 36 */
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.net.redstone.framework.common.util.string.StrUtils;
5 6 import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
6 7 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
7 8 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
... ... @@ -13,6 +14,9 @@ import org.springframework.validation.annotation.Validated;
13 14 import jakarta.annotation.Resource;
14 15 import java.time.LocalDateTime;
15 16  
  17 +import static cn.net.redstone.module.infra.dal.dataobject.logger.ApiAccessLogDO.REQUEST_PARAMS_MAX_LENGTH;
  18 +import static cn.net.redstone.module.infra.dal.dataobject.logger.ApiAccessLogDO.RESULT_MSG_MAX_LENGTH;
  19 +
16 20 /**
17 21 * API 访问日志 Service 实现类
18 22 *
... ... @@ -29,6 +33,8 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
29 33 @Override
30 34 public void createApiAccessLog(ApiAccessLogCreateReqDTO createDTO) {
31 35 ApiAccessLogDO apiAccessLog = BeanUtils.toBean(createDTO, ApiAccessLogDO.class);
  36 + apiAccessLog.setRequestParams(StrUtils.maxLength(apiAccessLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH));
  37 + apiAccessLog.setResultMsg(StrUtils.maxLength(apiAccessLog.getResultMsg(), RESULT_MSG_MAX_LENGTH));
32 38 apiAccessLogMapper.insert(apiAccessLog);
33 39 }
34 40  
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java
... ... @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.net.redstone.framework.common.util.string.StrUtils;
5 6 import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
6 7 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
7 8 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
... ... @@ -15,6 +16,7 @@ import jakarta.annotation.Resource;
15 16 import java.time.LocalDateTime;
16 17  
17 18 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  19 +import static cn.net.redstone.module.infra.dal.dataobject.logger.ApiErrorLogDO.REQUEST_PARAMS_MAX_LENGTH;
18 20 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
19 21  
20 22 /**
... ... @@ -34,6 +36,7 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
34 36 public void createApiErrorLog(ApiErrorLogCreateReqDTO createDTO) {
35 37 ApiErrorLogDO apiErrorLog = BeanUtils.toBean(createDTO, ApiErrorLogDO.class)
36 38 .setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus());
  39 + apiErrorLog.setRequestParams(StrUtils.maxLength(apiErrorLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH));
37 40 apiErrorLogMapper.insert(apiErrorLog);
38 41 }
39 42  
... ...