Skip to content

Commit

Permalink
Merge pull request #31 from gqlin/master
Browse files Browse the repository at this point in the history
解决asyncSaveSystemLog所在子线程在主线程执行完成后,无法获取主线程本次请求相关内容的问题
  • Loading branch information
zhangyd-c authored Jun 23, 2024
2 parents 759bda1 + dcf416d commit cdcd210
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private void handle(ProceedingJoinPoint point) throws Exception {
return;
}

logService.asyncSaveSystemLog(platform, bussinessName);
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
logService.asyncSaveSystemLog(platform, bussinessName, servletRequestAttributes);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.zyd.blog.business.enums.PlatformEnum;
import com.zyd.blog.business.vo.LogConditionVO;
import com.zyd.blog.framework.object.AbstractService;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
* @author yadong.zhang email:yadong.zhang0415(a)gmail.com
Expand All @@ -23,5 +24,5 @@ public interface SysLogService extends AbstractService<Log, Integer> {
*/
PageInfo<Log> findPageBreakByCondition(LogConditionVO vo);

void asyncSaveSystemLog(PlatformEnum platform, String bussinessName);
void asyncSaveSystemLog(PlatformEnum platform, String bussinessName, ServletRequestAttributes servletRequestAttributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -57,7 +59,9 @@ public PageInfo<Log> findPageBreakByCondition(LogConditionVO vo) {

@Async
@Override
public void asyncSaveSystemLog(PlatformEnum platform, String bussinessName) {
public void asyncSaveSystemLog(PlatformEnum platform, String bussinessName, ServletRequestAttributes servletRequestAttributes) {
RequestContextHolder.setRequestAttributes(servletRequestAttributes);

String ua = RequestUtil.getUa();
Log sysLog = new Log();
sysLog.setLogLevel(LogLevelEnum.INFO);
Expand Down

0 comments on commit cdcd210

Please sign in to comment.