32 lines
913 B
Java
32 lines
913 B
Java
package com.ruoyi.lsfx.domain;
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
/**
|
|
* 业务外部接口调用发起人快照。
|
|
*/
|
|
public record CallerContext(Long userId, String username) {
|
|
|
|
public CallerContext {
|
|
if (!StringUtils.hasText(username)) {
|
|
throw new IllegalArgumentException("接口调用账号不能为空");
|
|
}
|
|
}
|
|
|
|
public static CallerContext from(LoginUser loginUser) {
|
|
if (loginUser == null) {
|
|
throw new IllegalArgumentException("登录用户不能为空");
|
|
}
|
|
return new CallerContext(loginUser.getUserId(), loginUser.getUsername());
|
|
}
|
|
|
|
public static CallerContext of(Long userId, String username) {
|
|
return new CallerContext(userId, username);
|
|
}
|
|
|
|
public static CallerContext system() {
|
|
return new CallerContext(null, "system");
|
|
}
|
|
}
|