|
|
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import com.fasterxml.jackson.annotation.JsonClassDescription;
|
|
|
+import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
+import com.fasterxml.jackson.annotation.JsonPropertyDescription;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Data;
|
|
|
@@ -17,7 +19,7 @@ import org.springframework.stereotype.Component;
|
|
|
import java.util.function.BiFunction;
|
|
|
|
|
|
/**
|
|
|
- * 工具:当前用户信息查询
|
|
|
+ * 工具:用户信息查询
|
|
|
*
|
|
|
* 同时,也是展示 ToolContext 上下文的使用
|
|
|
*
|
|
|
@@ -31,8 +33,17 @@ public class UserProfileQueryToolFunction
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
|
@Data
|
|
|
- @JsonClassDescription("当前用户信息查询")
|
|
|
- public static class Request { }
|
|
|
+ @JsonClassDescription("用户信息查询")
|
|
|
+ public static class Request {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户编号
|
|
|
+ */
|
|
|
+ @JsonProperty(value = "id")
|
|
|
+ @JsonPropertyDescription("用户编号,例如说:1。如果查询自己,则 id 为空")
|
|
|
+ private Long id;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
@Data
|
|
|
@AllArgsConstructor
|
|
|
@@ -61,13 +72,19 @@ public class UserProfileQueryToolFunction
|
|
|
|
|
|
@Override
|
|
|
public Response apply(Request request, ToolContext toolContext) {
|
|
|
- LoginUser loginUser = (LoginUser) toolContext.getContext().get(AiUtils.TOOL_CONTEXT_LOGIN_USER);
|
|
|
Long tenantId = (Long) toolContext.getContext().get(AiUtils.TOOL_CONTEXT_TENANT_ID);
|
|
|
- if (loginUser == null | tenantId == null) {
|
|
|
- return null;
|
|
|
+ if (tenantId == null) {
|
|
|
+ return new Response();
|
|
|
+ }
|
|
|
+ if (request.getId() == null) {
|
|
|
+ LoginUser loginUser = (LoginUser) toolContext.getContext().get(AiUtils.TOOL_CONTEXT_LOGIN_USER);
|
|
|
+ if (loginUser == null) {
|
|
|
+ return new Response();
|
|
|
+ }
|
|
|
+ request.setId(loginUser.getId());
|
|
|
}
|
|
|
return TenantUtils.execute(tenantId, () -> {
|
|
|
- AdminUserRespDTO user = adminUserApi.getUser(loginUser.getId());
|
|
|
+ AdminUserRespDTO user = adminUserApi.getUser(request.getId());
|
|
|
return BeanUtils.toBean(user, Response.class);
|
|
|
});
|
|
|
}
|