init: 导入RuoYi‑Vue‑Plus 6.X完整代码
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-modules</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>ruoyi-ai</artifactId>
|
||||
|
||||
<description>
|
||||
ai模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 核心模块 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
<!-- api模块 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-api</artifactId>
|
||||
</dependency>
|
||||
<!-- ai模块 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-ai</artifactId>
|
||||
</dependency>
|
||||
<!-- satoken -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-satoken</artifactId>
|
||||
</dependency>
|
||||
<!-- web服务 -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.dromara.ai.controller;
|
||||
|
||||
import com.aizuda.snail.ai.common.execption.SnailAiException;
|
||||
import com.aizuda.snail.ai.common.model.Result;
|
||||
import com.aizuda.snail.ai.common.openapi.dto.OpenApiUserRegisterRequest;
|
||||
import com.aizuda.snail.ai.common.openapi.dto.OpenApiUserVO;
|
||||
import com.aizuda.snail.ai.openapi.client.core.api.OpenApiUserClient;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.system.api.model.LoginUser;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Snail AI OpenAPI 控制器
|
||||
*
|
||||
* @author opensnail
|
||||
* @date 2026-04-25
|
||||
*/
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping("/snail-ai")
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "snail-ai.open-api", name = "enabled", havingValue = "true")
|
||||
public class SnailAiController extends BaseController {
|
||||
|
||||
/**
|
||||
* Snail AI 成功状态码。
|
||||
*/
|
||||
private static final int SNAIL_AI_SUCCESS = 1;
|
||||
private final OpenApiUserClient userClient;
|
||||
|
||||
/**
|
||||
* 注册当前登录用户并返回 OpenAPI 用户信息。
|
||||
*/
|
||||
@PostMapping("/user/register")
|
||||
public R<OpenApiUserVO> registerCurrentUser() {
|
||||
return R.ok(ensureOpenApiUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* 确保当前登录用户已注册为 OpenAPI 用户。
|
||||
*/
|
||||
private OpenApiUserVO ensureOpenApiUser() {
|
||||
Long userId = LoginHelper.getUserId();
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (loginUser == null || userId == null) {
|
||||
throw new SnailAiException("当前登录用户为空");
|
||||
}
|
||||
|
||||
OpenApiUserRegisterRequest registerRequest = new OpenApiUserRegisterRequest();
|
||||
registerRequest.setExternalId(String.valueOf(userId));
|
||||
registerRequest.setNickname(loginUser.getNickname());
|
||||
Result<OpenApiUserVO> registerResult = userClient.register(registerRequest);
|
||||
if (registerResult == null) {
|
||||
throw new SnailAiException("注册 OpenAPI 用户失败,返回为空");
|
||||
}
|
||||
if (registerResult.getStatus() != SNAIL_AI_SUCCESS) {
|
||||
throw new SnailAiException(registerResult.getMessage());
|
||||
}
|
||||
if (registerResult.getData() == null) {
|
||||
throw new SnailAiException("注册 OpenAPI 用户失败,返回为空");
|
||||
}
|
||||
return registerResult.getData();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user