Commit 12ce87b3056718a28d2f5d9c0e5344bab6dacc8a
1 parent
c8ebad91
【功能修复】框架:操作日志异步记录时,丢失 request 的问题
Showing
4 changed files
with
13 additions
and
6 deletions
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/LogRecordServiceImpl.java
| ... | ... | @@ -11,7 +11,6 @@ import com.mzt.logapi.service.ILogRecordService; |
| 11 | 11 | import jakarta.annotation.Resource; |
| 12 | 12 | import jakarta.servlet.http.HttpServletRequest; |
| 13 | 13 | import lombok.extern.slf4j.Slf4j; |
| 14 | -import org.springframework.scheduling.annotation.Async; | |
| 15 | 14 | |
| 16 | 15 | import java.util.List; |
| 17 | 16 | |
| ... | ... | @@ -29,7 +28,6 @@ public class LogRecordServiceImpl implements ILogRecordService { |
| 29 | 28 | private OperateLogApi operateLogApi; |
| 30 | 29 | |
| 31 | 30 | @Override |
| 32 | - @Async | |
| 33 | 31 | public void record(LogRecord logRecord) { |
| 34 | 32 | OperateLogCreateReqDTO reqDTO = new OperateLogCreateReqDTO(); |
| 35 | 33 | try { |
| ... | ... | @@ -42,7 +40,7 @@ public class LogRecordServiceImpl implements ILogRecordService { |
| 42 | 40 | fillRequestFields(reqDTO); |
| 43 | 41 | |
| 44 | 42 | // 2. 异步记录日志 |
| 45 | - operateLogApi.createOperateLog(reqDTO); | |
| 43 | + operateLogApi.createOperateLogAsync(reqDTO); | |
| 46 | 44 | } catch (Throwable ex) { |
| 47 | 45 | // 由于 @Async 异步调用,这里打印下日志,更容易跟进 |
| 48 | 46 | log.error("[record][url({}) log({}) 发生异常]", reqDTO.getRequestUrl(), reqDTO, ex); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/receivable/CrmReceivableMapper.java
| ... | ... | @@ -92,7 +92,7 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> { |
| 92 | 92 | List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmReceivableDO>() |
| 93 | 93 | .select("contract_id, SUM(price) AS total_price") |
| 94 | 94 | .in("audit_status", CrmAuditStatusEnum.DRAFT.getStatus(), // 草稿 + 审批中 + 审批通过 |
| 95 | - CrmAuditStatusEnum.PROCESS, CrmAuditStatusEnum.APPROVE.getStatus()) | |
| 95 | + CrmAuditStatusEnum.PROCESS.getStatus(), CrmAuditStatusEnum.APPROVE.getStatus()) | |
| 96 | 96 | .groupBy("contract_id") |
| 97 | 97 | .in("contract_id", contractIds)); |
| 98 | 98 | // 获得金额 | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/OperateLogApi.java
| ... | ... | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogPageReqDTO; |
| 6 | 6 | import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogRespDTO; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | +import org.springframework.scheduling.annotation.Async; | |
| 8 | 9 | |
| 9 | 10 | /** |
| 10 | 11 | * 操作日志 API 接口 |
| ... | ... | @@ -21,6 +22,16 @@ public interface OperateLogApi { |
| 21 | 22 | void createOperateLog(@Valid OperateLogCreateReqDTO createReqDTO); |
| 22 | 23 | |
| 23 | 24 | /** |
| 25 | + * 【异步】创建操作日志 | |
| 26 | + * | |
| 27 | + * @param createReqDTO 请求 | |
| 28 | + */ | |
| 29 | + @Async | |
| 30 | + default void createOperateLogAsync(OperateLogCreateReqDTO createReqDTO) { | |
| 31 | + createOperateLog(createReqDTO); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 24 | 35 | * 获取指定模块的指定数据的操作日志分页 |
| 25 | 36 | * |
| 26 | 37 | * @param pageReqDTO 请求 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/logger/OperateLogApiImpl.java
| ... | ... | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO; |
| 9 | 9 | import cn.iocoder.yudao.module.system.service.logger.OperateLogService; |
| 10 | 10 | import com.fhs.core.trans.anno.TransMethodResult; |
| 11 | 11 | import jakarta.annotation.Resource; |
| 12 | -import org.springframework.scheduling.annotation.Async; | |
| 13 | 12 | import org.springframework.stereotype.Service; |
| 14 | 13 | import org.springframework.validation.annotation.Validated; |
| 15 | 14 | |
| ... | ... | @@ -26,7 +25,6 @@ public class OperateLogApiImpl implements OperateLogApi { |
| 26 | 25 | private OperateLogService operateLogService; |
| 27 | 26 | |
| 28 | 27 | @Override |
| 29 | - @Async | |
| 30 | 28 | public void createOperateLog(OperateLogCreateReqDTO createReqDTO) { |
| 31 | 29 | operateLogService.createOperateLog(createReqDTO); |
| 32 | 30 | } | ... | ... |