Commit f3dbcf46bbbbf50998e8b8dc511609f2f3636650

Authored by YunaiV
1 parent 6380a81f

【代码评审】INFRA:优化记录 infra_api_access_log 方法,截取参数最长 8000 字符

yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
  3 +import cn.hutool.core.util.StrUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5   -import cn.net.redstone.framework.common.util.string.StrUtils;
6 6 import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
7 7 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
8 8 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
9 9 import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiAccessLogMapper;
  10 +import jakarta.annotation.Resource;
10 11 import lombok.extern.slf4j.Slf4j;
11 12 import org.springframework.stereotype.Service;
12 13 import org.springframework.validation.annotation.Validated;
13 14  
14   -import jakarta.annotation.Resource;
15 15 import java.time.LocalDateTime;
16 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;
  17 +import static cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO.REQUEST_PARAMS_MAX_LENGTH;
  18 +import static cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO.RESULT_MSG_MAX_LENGTH;
19 19  
20 20 /**
21 21 * API 访问日志 Service 实现类
... ... @@ -33,8 +33,8 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
33 33 @Override
34 34 public void createApiAccessLog(ApiAccessLogCreateReqDTO createDTO) {
35 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));
  36 + apiAccessLog.setRequestParams(StrUtil.maxLength(apiAccessLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH));
  37 + apiAccessLog.setResultMsg(StrUtil.maxLength(apiAccessLog.getResultMsg(), RESULT_MSG_MAX_LENGTH));
38 38 apiAccessLogMapper.insert(apiAccessLog);
39 39 }
40 40  
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
  3 +import cn.hutool.core.util.StrUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5   -import cn.net.redstone.framework.common.util.string.StrUtils;
6 6 import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
7 7 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
8 8 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
9 9 import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiErrorLogMapper;
10 10 import cn.iocoder.yudao.module.infra.enums.logger.ApiErrorLogProcessStatusEnum;
  11 +import jakarta.annotation.Resource;
11 12 import lombok.extern.slf4j.Slf4j;
12 13 import org.springframework.stereotype.Service;
13 14 import org.springframework.validation.annotation.Validated;
14 15  
15   -import jakarta.annotation.Resource;
16 16 import java.time.LocalDateTime;
17 17  
18 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;
20   -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*;
  19 +import static cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO.REQUEST_PARAMS_MAX_LENGTH;
  20 +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.API_ERROR_LOG_NOT_FOUND;
  21 +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.API_ERROR_LOG_PROCESSED;
21 22  
22 23 /**
23 24 * API 错误日志 Service 实现类
... ... @@ -36,7 +37,7 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
36 37 public void createApiErrorLog(ApiErrorLogCreateReqDTO createDTO) {
37 38 ApiErrorLogDO apiErrorLog = BeanUtils.toBean(createDTO, ApiErrorLogDO.class)
38 39 .setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus());
39   - apiErrorLog.setRequestParams(StrUtils.maxLength(apiErrorLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH));
  40 + apiErrorLog.setRequestParams(StrUtil.maxLength(apiErrorLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH));
40 41 apiErrorLogMapper.insert(apiErrorLog);
41 42 }
42 43  
... ...