mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 22:57:17 +08:00 
			
		
		
		
	refactor: 日志记录增加对多租户环境的处理逻辑
This commit is contained in:
		| @@ -23,6 +23,7 @@ import cn.hutool.core.convert.Convert; | |||||||
| import cn.hutool.core.map.MapUtil; | import cn.hutool.core.map.MapUtil; | ||||||
| import cn.hutool.core.util.StrUtil; | import cn.hutool.core.util.StrUtil; | ||||||
| import cn.hutool.core.util.URLUtil; | import cn.hutool.core.util.URLUtil; | ||||||
|  | import cn.hutool.extra.spring.SpringUtil; | ||||||
| import cn.hutool.http.HttpStatus; | import cn.hutool.http.HttpStatus; | ||||||
| import cn.hutool.json.JSONUtil; | import cn.hutool.json.JSONUtil; | ||||||
| import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||||
| @@ -41,6 +42,7 @@ import top.continew.admin.system.service.UserService; | |||||||
| import top.continew.starter.core.constant.StringConstants; | import top.continew.starter.core.constant.StringConstants; | ||||||
| import top.continew.starter.core.util.ExceptionUtils; | import top.continew.starter.core.util.ExceptionUtils; | ||||||
| import top.continew.starter.core.util.StrUtils; | import top.continew.starter.core.util.StrUtils; | ||||||
|  | import top.continew.starter.extension.tenant.autoconfigure.TenantProperties; | ||||||
| import top.continew.starter.extension.tenant.context.TenantContextHolder; | import top.continew.starter.extension.tenant.context.TenantContextHolder; | ||||||
| import top.continew.starter.extension.tenant.util.TenantUtils; | import top.continew.starter.extension.tenant.util.TenantUtils; | ||||||
| import top.continew.starter.log.dao.LogDao; | import top.continew.starter.log.dao.LogDao; | ||||||
| @@ -88,7 +90,15 @@ public class LogDaoLocalImpl implements LogDao { | |||||||
|         // 设置操作人 |         // 设置操作人 | ||||||
|         this.setCreateUser(logDO, logRequest, logResponse); |         this.setCreateUser(logDO, logRequest, logResponse); | ||||||
|         // 保存记录 |         // 保存记录 | ||||||
|         TenantUtils.execute(TenantContextHolder.getTenantId(), () -> logMapper.insert(logDO)); |         if (TenantContextHolder.isTenantEnabled()) { | ||||||
|  |             // 异步无法获取租户 ID | ||||||
|  |             String tenantId = logRequest.getHeaders().get(SpringUtil.getBean(TenantProperties.class).getTenantIdHeader()); | ||||||
|  |             if (StrUtil.isNotBlank(tenantId)) { | ||||||
|  |                 TenantUtils.execute(Long.parseLong(tenantId), () -> logMapper.insert(logDO)); | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         logMapper.insert(logDO); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user