|
@@ -1,6 +1,7 @@
|
|
|
package cn.iocoder.yudao.module.infra.service.logger;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
|
|
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
|
|
|
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO;
|
|
|
import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
|
|
@@ -8,6 +9,7 @@ import cn.iocoder.yudao.module.infra.convert.logger.ApiErrorLogConvert;
|
|
|
import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
|
|
|
import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiErrorLogMapper;
|
|
|
import cn.iocoder.yudao.module.infra.enums.logger.ApiErrorLogProcessStatusEnum;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
@@ -24,10 +26,13 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.API_ERROR_L
|
|
|
*
|
|
|
* @author 芋道源码
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@Validated
|
|
|
public class ApiErrorLogServiceImpl implements ApiErrorLogService {
|
|
|
|
|
|
+ private static final Integer DELETE_LIMIT = 100;
|
|
|
+
|
|
|
@Resource
|
|
|
private ApiErrorLogMapper apiErrorLogMapper;
|
|
|
|
|
@@ -62,4 +67,22 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
|
|
|
.processUserId(processUserId).processTime(LocalDateTime.now()).build());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void jobCleanErrorLog(Integer errorLogJobDay) {
|
|
|
+ TenantUtils.executeIgnore(() -> {
|
|
|
+ Integer result = null;
|
|
|
+ int count = 0;
|
|
|
+ while (result == null || DELETE_LIMIT.equals(result)) {
|
|
|
+ result = apiErrorLogMapper.jobCleanErrorLog(errorLogJobDay);
|
|
|
+ count += result;
|
|
|
+ }
|
|
|
+ if (count > 0) {
|
|
|
+ // ALTER TABLE...FORCE 会导致表重建发生,这会根据主键索引对表空间中的物理页进行排序。
|
|
|
+ // 它将行压缩到页面上并消除可用空间,同时确保数据处于主键查找的最佳顺序。
|
|
|
+ apiErrorLogMapper.optimizeTable();
|
|
|
+ }
|
|
|
+ log.info("定时执行清理错误日志数量({})个",count);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|