diff --git a/.gitignore b/.gitignore index 9a07f4457..ddcb065e6 100644 --- a/.gitignore +++ b/.gitignore @@ -158,6 +158,7 @@ my_wakeup_words.mp3 !main/xiaozhi-server/config/assets/bind_code.wav !main/xiaozhi-server/config/assets/bind_not_found.wav !main/xiaozhi-server/config/assets/bind_code/*.wav +!main/xiaozhi-server/config/assets/max_output_size.wav main/manager-api/.vscode # Ignore webpack cache directory diff --git a/README_en.md b/README_en.md deleted file mode 100644 index 1dd705549..000000000 --- a/README_en.md +++ /dev/null @@ -1,302 +0,0 @@ -[![Banners](docs/images/banner1.png)](https://github.com/xinnan-tech/xiaozhi-esp32-server) - -
-

Xiaozhi Backend Server xiaozhi-esp32-server

-
- -

-This project provides backend services for the open-source smart hardware project -xiaozhi-esp32
-Implemented in Python according to the Xiaozhi Communication Protocol
-Helping you quickly set up your Xiaozhi server -

- -

-简体中文 -· English -· Changelog -· Deployment Guide -· Report Issues -

-

- - GitHub Contributors - - - GitHub Contributors - - - Issues - - - GitHub pull requests - - - GitHub pull requests - - - GitHub pull requests - -

- ---- - -## Target Users 👥 - -This project requires ESP32 hardware devices. If you have purchased ESP32-related hardware, successfully connected to Brother Xia's backend service, and wish to set up your own `xiaozhi-esp32` backend service, then this project is perfect for you. - -Want to see it in action? Check out these videos 🎥 - - - - - - - - - - - - - - - - -
- - - Xiaozhi esp32 connecting to your own backend model - - - - - - Custom voice - - - - - - Communicating in Cantonese - - - - - - Control home appliances - - - - - - Lowest cost configuration - - -
- - - Custom voice - - - - - - Play music - - - - - - Weather plugin - - - - - - IOT command control device - - - - - - News broadcast - - -
- ---- - -## System Requirements and Prerequisites 🖥️ - -- **Computer or Server**: Recommended 4-core CPU, 8GB RAM computer. If using ASR with API, can run on a 2-core CPU, 2GB RAM server. -- **Update Client Interface**: Please update the backend service interface address in the client. - ---- - -## Warning ⚠️ - -1. This is open-source software. This software and any third-party API service providers it interfaces with (including but not limited to speech recognition, large language models, speech synthesis, and other platforms) have no commercial partnership. We do not provide any form of guarantee for their service quality or financial security. -We recommend users prioritize service providers with relevant business licenses and carefully read their service agreements and privacy policies. This software does not host any account keys, does not participate in fund transfers, and does not bear the risk of recharge fund losses. - -2. This project is relatively new and has not yet passed network security testing. Please do not use it in production environments. If you deploy this project for learning purposes in a public network environment, please make sure to enable protection in the `config.yaml` configuration file: - -```yaml -server: - auth: - # Enable protection - enabled: true -``` - -After enabling protection, you need to verify the machine's token or MAC address according to actual circumstances. Please refer to the configuration documentation for details. - ---- - -## Deployment Methods 🚀 - -### I. [Deployment Guide](./docs/Deployment.md) - -This project supports three deployment methods. You can choose based on your actual needs. - -1. [Quick Docker Deployment](./docs/Deployment.md) - -Suitable for regular users who want to quickly experience without much environment configuration. The downside is that pulling the image can be slow. Video tutorial available: [Beautiful expert teaches Docker deployment](https://www.bilibili.com/video/BV1RNQnYDE5t) - -2. [Deploy Using Docker Environment](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%BA%8C%E5%80%9F%E5%8A%A9docker%E7%8E%AF%E5%A2%83%E8%BF%90%E8%A1%8C%E9%83%A8%E7%BD%B2) - -For software engineers who have Docker installed and want to make custom code modifications. - -3. [Local Source Code Run](./docs/Deployment.md#%E6%96%B9%E5%BC%8F%E4%B8%89%E6%9C%AC%E5%9C%B0%E6%BA%90%E7%A0%81%E8%BF%90%E8%A1%8C) - -Suitable for users familiar with `Conda` environment or who want to build the running environment from scratch. - -For scenarios requiring higher response speed, we recommend using the local source code run method to reduce additional overhead. Video tutorial available: [Handsome expert teaches source code deployment](https://www.bilibili.com/video/BV1GvQWYZEd2) - -### II. [Firmware Compilation](./docs/firmware-build.md) - -Click here to view the detailed process of [firmware compilation](./docs/firmware-build.md). - -After successful flashing and network connection, wake up Xiaozhi using the wake word and pay attention to the console output on the server side. - ---- - -## Common Questions ❓ - -For issues or product suggestions, please [click here](docs/FAQ.md). - ---- - -## Product Ecosystem 👬 -Xiaozhi is an ecosystem. When using this product, you might want to check out other excellent projects in this ecosystem: - -- [Xiaozhi Android Client](https://github.com/TOM88812/xiaozhi-android-client) - A voice dialogue application based on xiaozhi-server for Android and iOS, supporting real-time voice interaction and text dialogue. Now in Flutter version, supporting both iOS and Android. -- [Xiaozhi PC Client](https://github.com/Huang-junsen/py-xiaozhi) - This project provides a Python-based Xiaobai AI client, allowing you to experience Xiaozhi AI features through code even without physical hardware. Main features include AI voice interaction, visual multimodal recognition, IoT device integration, online music playback, voice wake-up, automatic dialogue mode, graphical interface, command-line mode, cross-platform support, volume control, session management, encrypted audio transmission, automatic verification code processing, etc. -- [Xiaozhi Java Server](https://github.com/joey-zhou/xiaozhi-esp32-server-java) - - The Xiaozhi open-source backend service Java version is a Java-based open-source project that includes both frontend and backend services, aiming to provide users with a complete backend service solution. ---- -## Feature List ✨ - -### Implemented ✅ - -- **Communication Protocol** - Based on `xiaozhi-esp32` protocol, implementing data interaction through WebSocket. -- **Dialogue Interaction** - Supports wake-up dialogue, manual dialogue, and real-time interruption. Automatically sleeps after long periods without dialogue -- **Intent Recognition** - Supports LLM intent recognition and function call, reducing hard-coded intent judgment -- **Multi-language Recognition** - Supports Mandarin, Cantonese, English, Japanese, Korean (default using FunASR). -- **LLM Module** - Supports flexible switching of LLM modules, default using ChatGLMLLM, can also use Alibaba Bailian, DeepSeek, Ollama, and other interfaces. -- **TTS Module** - Supports EdgeTTS (default), Volcano Engine Doubao TTS, and other TTS interfaces to meet speech synthesis needs. -- **Memory Function** - Supports ultra-long memory, local summary memory, and no memory modes to meet different scenario needs. -- **IOT Function** - Supports managing registered device IOT functions, supporting intelligent IoT control based on dialogue context. - -### Under Development 🚧 - -- Multiple mood modes -- Smart control panel webui - -To learn about specific development progress, [click here](https://github.com/users/xinnan-tech/projects/3) - -If you are a software developer, here's an [Open Letter to Developers](docs/contributor_open_letter.md), welcome to join! - ---- - -## Supported Platforms/Components List 📋 - -### LLM Language Models - -| Usage Method | Supported Platforms | Free Platforms | -|:---:|:---:|:---:| -| openai interface call | Alibaba Bailian, Volcano Engine Doubao, DeepSeek, Zhipu ChatGLM, Gemini | Zhipu ChatGLM, Gemini | -| ollama interface call | Ollama | - | -| dify interface call | Dify | - | -| fastgpt interface call | Fastgpt | - | -| coze interface call | Coze | - | - -In fact, any LLM supporting openai interface calls can be integrated. - ---- - -### TTS Speech Synthesis - -| Usage Method | Supported Platforms | Free Platforms | -|:---:|:---:|:---:| -| Interface Call | EdgeTTS, Volcano Engine Doubao TTS, Tencent Cloud, Alibaba Cloud TTS, CosyVoiceSiliconflow, TTS302AI, CozeCnTTS, GizwitsTTS, ACGNTTS, OpenAITTS | EdgeTTS, CosyVoiceSiliconflow(partial) | -| Local Service | FishSpeech, GPT_SOVITS_V2, GPT_SOVITS_V3, MinimaxTTS | FishSpeech, GPT_SOVITS_V2, GPT_SOVITS_V3, MinimaxTTS | - ---- - -### VAD Voice Activity Detection - -| Type | Platform Name | Usage Method | Pricing Model | Notes | -|:---:|:---------:|:----:|:----:|:--:| -| VAD | SileroVAD | Local Use | Free | | - ---- - -### ASR Speech Recognition - -| Usage Method | Supported Platforms | Free Platforms | -|:---:|:---:|:---:| -| Local Use | FunASR, SherpaASR | FunASR, SherpaASR | -| Interface Call | DoubaoASR | - | - ---- - -### Memory Storage - -| Type | Platform Name | Usage Method | Pricing Model | Notes | -|:------:|:---------------:|:----:|:---------:|:--:| -| Memory | mem0ai | Interface Call | 1000 times/month quota | | -| Memory | mem_local_short | Local Summary | Free | | - ---- - -### Intent Recognition - -| Type | Platform Name | Usage Method | Pricing Model | Notes | -|:------:|:-------------:|:----:|:-------:|:---------------------:| -| Intent | intent_llm | Interface Call | Based on LLM pricing | Intent recognition through large models, highly generalizable | -| Intent | function_call | Interface Call | Based on LLM pricing | Intent completion through large model function calls, fast and effective | - ---- - -## Acknowledgments 🙏 - -- This project was inspired by [Bailing Voice Dialogue Robot](https://github.com/wwbin2017/bailing) and implemented based on it. -- Thanks to [Tenclass](https://www.tenclass.com/) for providing detailed documentation support for the Xiaozhi communication protocol. - - - - - - Star History Chart - - \ No newline at end of file diff --git a/docs/firmware-build.md b/docs/firmware-build.md index b73b59773..c3c3347a0 100644 --- a/docs/firmware-build.md +++ b/docs/firmware-build.md @@ -4,7 +4,16 @@ 先按照这个教程配置项目环境[《Windows搭建 ESP IDF 5.3.2开发环境以及编译小智》](https://icnynnzcwou8.feishu.cn/wiki/JEYDwTTALi5s2zkGlFGcDiRknXf) ## 第2步 打开配置文件 -配置好编译环境后,下载虾哥[xiaozhi-esp32](https://github.com/78/xiaozhi-esp32)项目源码,进入虾哥项目,打开`xiaozhi-esp32/main/Kconfig.projbuild`文件。 +配置好编译环境后,下载虾哥iaozhi-esp32项目源码, + +从这里下载虾哥[xiaozhi-esp32项目源码](https://github.com/78/xiaozhi-esp32/archive/refs/tags/v1.6.0.zip)。 + +从这里下载虾哥[xiaozhi-esp32项目源码](https://github.com/78/xiaozhi-esp32/archive/refs/tags/v1.6.0.zip)。 + +从这里下载虾哥[xiaozhi-esp32项目源码](https://github.com/78/xiaozhi-esp32/archive/refs/tags/v1.6.0.zip)。 + +下载后,解压缩包,打开`xiaozhi-esp32/main/Kconfig.projbuild`文件。 + ## 第3步 修改WEBSOCKET地址 找到`WEBSOCKET_URL`的`default`的内容,把`wss://api.tenclass.net/xiaozhi/v1/` diff --git a/docs/images/deploy.png b/docs/images/deploy.png deleted file mode 100644 index e1db8a48b..000000000 Binary files a/docs/images/deploy.png and /dev/null differ diff --git a/main/.vscode/extensions.json b/main/.vscode/extensions.json deleted file mode 100644 index 78227ea83..000000000 --- a/main/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "github.copilot-chat" - ] -} \ No newline at end of file diff --git a/main/.vscode/settings.json b/main/.vscode/settings.json deleted file mode 100644 index 7b016a89f..000000000 --- a/main/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "java.compile.nullAnalysis.mode": "automatic" -} \ No newline at end of file diff --git a/main/README.md b/main/README.md index ba3a499be..a91c9fdca 100644 --- a/main/README.md +++ b/main/README.md @@ -1,8 +1,6 @@ -本文档是开发类文档,如需部署小智服务端,[点击这里查看部署教程](./FAQ.md#%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F-) +本文档是开发类文档,如需部署小智服务端,[点击这里查看部署教程](../README.md#%E9%83%A8%E7%BD%B2%E6%96%87%E6%A1%A3) # 项目目录介绍 -当你看到这份文件的时候,这个这个项目还没完善好。我们还有很多东西要做。 - 如果你是一名软件开发者,这里有一份[《致开发者的公开信》](../docs/contributor_open_letter.md),欢迎归队! ``` @@ -12,9 +10,9 @@ xiaozhi-esp32-server ├─ manager-api 8002 端口 Java语言开发 负责提供控制台的api ``` -# xiaozhi-server 接口协议 +# xiaozhi-server 和ESP32通讯协议 -[虾哥团队通信协议:Websocket 连接](https://ccnphfhqs21z.feishu.cn/wiki/M0XiwldO9iJwHikpXD5cEx71nKh) +https://ccnphfhqs21z.feishu.cn/wiki/M0XiwldO9iJwHikpXD5cEx71nKh # manager-web 、manager-api接口协议 diff --git a/main/manager-api/README.md b/main/manager-api/README.md index bef06b68e..484c28dc0 100644 --- a/main/manager-api/README.md +++ b/main/manager-api/README.md @@ -1,4 +1,5 @@ -本文档是开发类文档,如需部署小智服务端,[点击这里查看部署教程](../../../docs/Deployment.md) +本文档是开发类文档,如需部署小智服务端,[点击这里查看部署教程](../../README.md#%E9%83%A8%E7%BD%B2%E6%96%87%E6%A1%A3) + # 项目介绍 manager-api 该项目基于SpringBoot框架开发。 @@ -12,80 +13,6 @@ MySQL 8.0+ Redis 5.0+ Vue 3.x -# 创建数据库 - -如果本机已经安装了MySQL,可以直接在数据库中创建名为`xiaozhi_esp32_server`的数据库。 - -```sql -CREATE DATABASE xiaozhi_esp32_server CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -``` - -如果还没有MySQL,你可以通过docker安装mysql - -``` -docker run --name xiaozhi-esp32-server-db -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -e MYSQL_DATABASE=xiaozhi_esp32_server -e MYSQL_INITDB_ARGS="--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci" -d mysql:latest -``` - -# 确认项目数据库连接信息 - -在`src/main/resources/application-dev.yml`中配置数据库连接信息 - -``` -spring: - datasource: - username: root - password: 123456 -``` - - -# 连接Redis - -如果还没有Redis,你可以通过docker安装redis - -``` -docker run --name xiaozhi-esp32-server-redis -d -p 6379:6379 redis -``` - -# 确认项目Redis连接信息 - -在`src/main/resources/application-dev.yml`中配置Redis连接信息 - -``` -spring: - data: - redis: - host: localhost - port: 6379 - password: - database: 0 -``` - - -# 测试启动 - -本项目为SpringBoot项目,启动方式为: -打开`Application.java`运行`Main`方法启动 - -``` -路径地址: -src/main/java/xiaozhi/AdminApplication.java -``` - -# 打包编译 - -执行以下命令生产jar包 - -``` -mvn clean install -``` - -把jar包放在服务器上,执行 - -``` -nohup java -jar xiaozhi-esp32-api.jar --spring.profiles.activate=dev -``` - - # 接口文档 启动后打开:http://localhost:8002/xiaozhi/doc.html diff --git a/main/manager-api/firmware/070bf471-54d2-47b4-8f6a-dfe73c2a07b6_bootloader.bin b/main/manager-api/firmware/070bf471-54d2-47b4-8f6a-dfe73c2a07b6_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/070bf471-54d2-47b4-8f6a-dfe73c2a07b6_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/201df61b-684a-46fb-bf3a-24df795e0e74_bootloader.elf b/main/manager-api/firmware/201df61b-684a-46fb-bf3a-24df795e0e74_bootloader.elf deleted file mode 100644 index 75e467596..000000000 Binary files a/main/manager-api/firmware/201df61b-684a-46fb-bf3a-24df795e0e74_bootloader.elf and /dev/null differ diff --git a/main/manager-api/firmware/33c69cb3-fe21-4e85-a854-e726df8979c8_bootloader.bin b/main/manager-api/firmware/33c69cb3-fe21-4e85-a854-e726df8979c8_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/33c69cb3-fe21-4e85-a854-e726df8979c8_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/45d520f8-77b9-441f-8390-b462c21b39ae_bootloader.bin b/main/manager-api/firmware/45d520f8-77b9-441f-8390-b462c21b39ae_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/45d520f8-77b9-441f-8390-b462c21b39ae_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/466e560f-5ec8-4d12-9e6d-9ea139e4f767_bootloader.bin b/main/manager-api/firmware/466e560f-5ec8-4d12-9e6d-9ea139e4f767_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/466e560f-5ec8-4d12-9e6d-9ea139e4f767_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/569f7541-cca4-448b-978e-93bb7f7869cf_bootloader.bin b/main/manager-api/firmware/569f7541-cca4-448b-978e-93bb7f7869cf_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/569f7541-cca4-448b-978e-93bb7f7869cf_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/5fcbc2d9-ab98-4904-be15-31d9c7e4a24d_bootloader.bin b/main/manager-api/firmware/5fcbc2d9-ab98-4904-be15-31d9c7e4a24d_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/5fcbc2d9-ab98-4904-be15-31d9c7e4a24d_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/6149ce45-e14b-4f58-9785-72d2cb4329e7_bootloader.bin b/main/manager-api/firmware/6149ce45-e14b-4f58-9785-72d2cb4329e7_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/6149ce45-e14b-4f58-9785-72d2cb4329e7_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/635205ae-2cf7-4900-abe0-857134fc745d_bootloader.bin b/main/manager-api/firmware/635205ae-2cf7-4900-abe0-857134fc745d_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/635205ae-2cf7-4900-abe0-857134fc745d_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/754b8c2e-e04a-4438-923f-90ccb5a1c93f_bootloader.bin b/main/manager-api/firmware/754b8c2e-e04a-4438-923f-90ccb5a1c93f_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/754b8c2e-e04a-4438-923f-90ccb5a1c93f_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/75b375b8-f349-4c0d-9871-b5fd6ea359e6_bootloader.bin b/main/manager-api/firmware/75b375b8-f349-4c0d-9871-b5fd6ea359e6_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/75b375b8-f349-4c0d-9871-b5fd6ea359e6_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/7787ae88-3def-45f2-b8a1-69e4fab82d6f_bootloader.bin b/main/manager-api/firmware/7787ae88-3def-45f2-b8a1-69e4fab82d6f_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/7787ae88-3def-45f2-b8a1-69e4fab82d6f_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/816ec179-a84c-4ff8-be5e-226bf758d9b7_bootloader.bin b/main/manager-api/firmware/816ec179-a84c-4ff8-be5e-226bf758d9b7_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/816ec179-a84c-4ff8-be5e-226bf758d9b7_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/8e5e3bed-cf35-44b9-9de0-3955db9e4032_bootloader.bin b/main/manager-api/firmware/8e5e3bed-cf35-44b9-9de0-3955db9e4032_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/8e5e3bed-cf35-44b9-9de0-3955db9e4032_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/963e65bd-5dcc-4970-98d9-f4350dce7693_bootloader.bin b/main/manager-api/firmware/963e65bd-5dcc-4970-98d9-f4350dce7693_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/963e65bd-5dcc-4970-98d9-f4350dce7693_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/ae8424be-53fe-4157-9fb4-6abacb024d51_bootloader.bin b/main/manager-api/firmware/ae8424be-53fe-4157-9fb4-6abacb024d51_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/ae8424be-53fe-4157-9fb4-6abacb024d51_bootloader.bin and /dev/null differ diff --git a/main/manager-api/firmware/d8ea28ad-d5aa-401c-9633-b755c7770202_bootloader.elf b/main/manager-api/firmware/d8ea28ad-d5aa-401c-9633-b755c7770202_bootloader.elf deleted file mode 100644 index 75e467596..000000000 Binary files a/main/manager-api/firmware/d8ea28ad-d5aa-401c-9633-b755c7770202_bootloader.elf and /dev/null differ diff --git a/main/manager-api/firmware/df747842-979e-415c-abde-c7deff8b4537_bootloader.bin b/main/manager-api/firmware/df747842-979e-415c-abde-c7deff8b4537_bootloader.bin deleted file mode 100644 index 1681e4fe6..000000000 Binary files a/main/manager-api/firmware/df747842-979e-415c-abde-c7deff8b4537_bootloader.bin and /dev/null differ diff --git a/main/manager-api/pom.xml b/main/manager-api/pom.xml index a77e15176..9ad380432 100644 --- a/main/manager-api/pom.xml +++ b/main/manager-api/pom.xml @@ -195,7 +195,6 @@ org.projectlombok lombok - 1.18.30 true @@ -233,8 +232,10 @@ org.apache.maven.plugins - maven-clean-plugin - 3.2.0 + maven-surefire-plugin + + true + diff --git a/main/manager-api/src/main/java/xiaozhi/common/config/SwaggerConfig.java b/main/manager-api/src/main/java/xiaozhi/common/config/SwaggerConfig.java index 0def65894..8fb316419 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/config/SwaggerConfig.java +++ b/main/manager-api/src/main/java/xiaozhi/common/config/SwaggerConfig.java @@ -71,6 +71,14 @@ public class SwaggerConfig { .build(); } + @Bean + public GroupedOpenApi configApi() { + return GroupedOpenApi.builder() + .group("config") + .pathsToMatch("/config/**") + .build(); + } + @Bean public OpenAPI customOpenAPI() { return new OpenAPI().info(new Info() diff --git a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java index 8daeb25e2..6f9dca2fe 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java +++ b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java @@ -84,6 +84,16 @@ public interface Constant { */ String SERVER_SECRET = "server.secret"; + /** + * 是否允许用户注册 + */ + String SERVER_ALLOW_USER_REGISTER = "server.allow_user_register"; + + /** + * 下发六位验证码时显示的控制面板地址 + */ + String SERVER_FRONTED_URL = "server.fronted_url"; + /** * 路径分割符 */ @@ -153,4 +163,9 @@ public interface Constant { return value; } } + + /** + * 版本号 + */ + public static final String VERSION = "0.3.9"; } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java b/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java index 4497a0958..c59a6a14e 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java +++ b/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java @@ -51,4 +51,8 @@ public interface ErrorCode { int PARAM_NUMBER_INVALID = 10037; int PARAM_BOOLEAN_INVALID = 10038; int PARAM_ARRAY_INVALID = 10039; + int PARAM_JSON_INVALID = 10040; + + int OTA_DEVICE_NOT_FOUND = 10041; + int OTA_DEVICE_NEED_BIND = 10042; } diff --git a/main/manager-api/src/main/java/xiaozhi/common/redis/RedisKeys.java b/main/manager-api/src/main/java/xiaozhi/common/redis/RedisKeys.java index 53aa08dc2..8c266ce4d 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/redis/RedisKeys.java +++ b/main/manager-api/src/main/java/xiaozhi/common/redis/RedisKeys.java @@ -38,7 +38,14 @@ public class RedisKeys { * 模型名称的Key */ public static String getModelNameById(String id) { - return "sys:model:name:" + id; + return "model:name:" + id; + } + + /** + * 模型配置的Key + */ + public static String getModelConfigById(String id) { + return "model:data:" + id; } /** @@ -54,4 +61,25 @@ public class RedisKeys { public static String getAgentDeviceCountById(String id) { return "agent:device:count:" + id; } + + /** + * 获取系统配置缓存key + */ + public static String getServerConfigKey() { + return "server:config"; + } + + /** + * 获取音色详情缓存key + */ + public static String getTimbreDetailsKey(String id) { + return "timbre:details:" + id; + } + + /** + * 获取版本号Key + */ + public static String getVersionKey() { + return "system:version"; + } } diff --git a/main/manager-api/src/main/java/xiaozhi/common/redis/RedisUtils.java b/main/manager-api/src/main/java/xiaozhi/common/redis/RedisUtils.java index 240e1339e..9115e8061 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/redis/RedisUtils.java +++ b/main/manager-api/src/main/java/xiaozhi/common/redis/RedisUtils.java @@ -1,11 +1,14 @@ package xiaozhi.common.redis; import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.script.DefaultRedisScript; import org.springframework.stereotype.Component; import jakarta.annotation.Resource; @@ -27,7 +30,7 @@ public class RedisUtils { /** * 过期时长为1小时,单位:秒 */ - public final static long HOUR_ONE_EXPIRE = 60 * 60 * 1L; + public final static long HOUR_ONE_EXPIRE = (long) 60 * 60; /** * 过期时长为6小时,单位:秒 */ @@ -124,4 +127,24 @@ public class RedisUtils { public Object rightPop(String key) { return redisTemplate.opsForList().rightPop(key); } + + + /** + * 清空所有 Redis 数据库中的所有键 + */ + public void emptyAll() { + // Lua 脚本 FLUSHALL是redis清空所有库的命令 + String luaScript ="redis.call('FLUSHALL')"; + + // 创建 DefaultRedisScript 对象 + DefaultRedisScript redisScript = new DefaultRedisScript<>(); + redisScript.setScriptText(luaScript); // 设置 Lua 脚本内容 + redisScript.setResultType(Void.class); // 设置返回值类型 + + // 执行 Lua 脚本 + List keys = Collections.emptyList(); // 如果脚本不依赖 key,可以传入空列表 + redisTemplate.execute(redisScript, keys); + + } + } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java index eea2d7fe4..123e10ba7 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/controller/AgentController.java @@ -191,4 +191,5 @@ public class AgentController { .list(new QueryWrapper().orderByAsc("sort")); return new Result>().ok(list); } + } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentTemplateService.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentTemplateService.java index 197c860eb..4e279c405 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentTemplateService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/AgentTemplateService.java @@ -17,4 +17,12 @@ public interface AgentTemplateService extends IService { * @return 默认模板实体 */ AgentTemplateEntity getDefaultTemplate(); + + /** + * 更新默认模板中的模型ID + * + * @param modelType 模型类型 + * @param modelId 模型ID + */ + void updateDefaultTemplateModelId(String modelType, String modelId); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java index bb2a3ed0f..ff284ef0c 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java @@ -44,7 +44,7 @@ public class AgentServiceImpl extends BaseServiceImpl imp @Override public PageData adminAgentList(Map params) { IPage page = agentDao.selectPage( - getPage(params, "sort", true), + getPage(params, "agent_name", true), new QueryWrapper<>()); return new PageData<>(page.getRecords(), page.getTotal()); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentTemplateServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentTemplateServiceImpl.java index 949a2f2d1..9ac3de252 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentTemplateServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentTemplateServiceImpl.java @@ -3,6 +3,7 @@ package xiaozhi.modules.agent.service.impl; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import xiaozhi.modules.agent.dao.AgentTemplateDao; @@ -29,4 +30,40 @@ public class AgentTemplateServiceImpl extends ServiceImpl wrapper = new UpdateWrapper<>(); + switch (modelType) { + case "ASR": + wrapper.set("asr_model_id", modelId); + break; + case "VAD": + wrapper.set("vad_model_id", modelId); + break; + case "LLM": + wrapper.set("llm_model_id", modelId); + break; + case "TTS": + wrapper.set("tts_model_id", modelId); + wrapper.set("tts_voice_id", null); + break; + case "MEMORY": + wrapper.set("mem_model_id", modelId); + break; + case "INTENT": + wrapper.set("intent_model_id", modelId); + break; + } + wrapper.ge("sort", 0); + update(wrapper); + } } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/config/init/SystemInitConfig.java b/main/manager-api/src/main/java/xiaozhi/modules/config/init/SystemInitConfig.java index a8e3794e9..e47cd0c75 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/config/init/SystemInitConfig.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/config/init/SystemInitConfig.java @@ -5,6 +5,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; import jakarta.annotation.PostConstruct; +import xiaozhi.common.constant.Constant; +import xiaozhi.common.redis.RedisKeys; +import xiaozhi.common.redis.RedisUtils; import xiaozhi.modules.config.service.ConfigService; import xiaozhi.modules.sys.service.SysParamsService; @@ -18,8 +21,20 @@ public class SystemInitConfig { @Autowired private ConfigService configService; + @Autowired + private RedisUtils redisUtils; + @PostConstruct public void init() { + // 检查版本号 + String redisVersion = (String) redisUtils.get(RedisKeys.getVersionKey()); + if (!Constant.VERSION.equals(redisVersion)) { + // 如果版本不一致,清空Redis + redisUtils.emptyAll(); + // 存储新版本号 + redisUtils.set(RedisKeys.getVersionKey(), Constant.VERSION); + } + sysParamsService.initServerSecret(); configService.getConfig(false); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java index dd2a28810..36aa6bed0 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java @@ -91,6 +91,7 @@ public class ConfigServiceImpl implements ConfigService { } throw new RenException(ErrorCode.OTA_DEVICE_NOT_FOUND, "not found device"); } + // 获取智能体信息 AgentEntity agent = agentService.getAgentById(device.getAgentId()); if (agent == null) { @@ -104,7 +105,9 @@ public class ConfigServiceImpl implements ConfigService { } // 构建返回数据 Map result = new HashMap<>(); - + // 获取单台设备每天最多输出字数 + String deviceMaxOutputSize = sysParamsService.getValue("device_max_output_size", true); + result.put("device_max_output_size", deviceMaxOutputSize); // 如果客户端已实例化模型,则不返回 String alreadySelectedVadModelId = (String) selectedModule.get("VAD"); if (alreadySelectedVadModelId != null && alreadySelectedVadModelId.equals(agent.getVadModelId())) { @@ -288,7 +291,7 @@ public class ConfigServiceImpl implements ConfigService { result.put("selected_module", selectedModule); if (StringUtils.isNotBlank(prompt)) { - prompt = prompt.replace("{{assistant_name}}", "小智"); + prompt = prompt.replace("{{assistant_name}}", StringUtils.isBlank(assistantName) ? "小智" : assistantName); } result.put("prompt", prompt); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/controller/OTAController.java b/main/manager-api/src/main/java/xiaozhi/modules/device/controller/OTAController.java index a7f707c98..e18439a12 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/controller/OTAController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/controller/OTAController.java @@ -1,249 +1,82 @@ package xiaozhi.modules.device.controller; -import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Map; -import java.util.UUID; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; -import xiaozhi.common.page.PageData; -import xiaozhi.common.utils.Result; +import lombok.extern.slf4j.Slf4j; import xiaozhi.modules.device.dto.DeviceReportReqDTO; import xiaozhi.modules.device.dto.DeviceReportRespDTO; -import xiaozhi.modules.device.entity.OtaEntity; +import xiaozhi.modules.device.entity.DeviceEntity; import xiaozhi.modules.device.service.DeviceService; -import xiaozhi.modules.device.service.OtaService; import xiaozhi.modules.device.utils.NetworkUtil; -import xiaozhi.common.constant.Constant; -import io.swagger.v3.oas.annotations.Parameters; -import xiaozhi.common.validator.ValidatorUtils; -@Tag(name = "固件管理", description = "OTA固件管理接口") +@Tag(name = "设备管理", description = "OTA 相关接口") +@Slf4j @RestController @RequiredArgsConstructor -@RequestMapping("/ota") +@RequestMapping("/ota/") public class OTAController { - private static final Logger logger = LoggerFactory.getLogger(OTAController.class); private final DeviceService deviceService; - private final OtaService otaService; - - @GetMapping("/otas") - @Operation(summary = "分页查询 OTA 固件信息") - @Parameters({ - @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true), - @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) - }) - public Result> page(@Parameter(hidden = true) @RequestParam Map params) { - ValidatorUtils.validateEntity(params); - PageData page = otaService.page(params); - return new Result>().ok(page); - } - - @GetMapping("{id}") - @Operation(summary = "信息 OTA 固件信息") - public Result get(@PathVariable("id") String id) { - OtaEntity data = otaService.getById(id); - return new Result().ok(data); - } + @Operation(summary = "OTA版本和设备激活状态检查") @PostMapping - @Operation(summary = "保存 OTA 固件信息") - public Result save(@RequestBody OtaEntity entity) { - if (entity == null) { - return new Result().error("固件信息不能为空"); - } - if (StringUtils.isBlank(entity.getFirmwareName())) { - return new Result().error("固件名称不能为空"); - } - if (StringUtils.isBlank(entity.getType())) { - return new Result().error("固件类型不能为空"); - } - if (StringUtils.isBlank(entity.getVersion())) { - return new Result().error("版本号不能为空"); - } - try { - otaService.save(entity); - return new Result(); - } catch (RuntimeException e) { - return new Result().error(e.getMessage()); - } - } - - @PutMapping("/{id}") - @Operation(summary = "修改 OTA 固件信息") - public Result update(@PathVariable("id") String id, @RequestBody OtaEntity entity) { - if (entity == null) { - return new Result<>().error("固件信息不能为空"); - } - entity.setId(id); - try { - otaService.update(entity); - return new Result<>(); - } catch (RuntimeException e) { - return new Result<>().error(e.getMessage()); - } - } - - @DeleteMapping("/{id}") - @Operation(summary = "OTA 删除") - public Result delete(@PathVariable("id") String[] ids) { - if (ids == null || ids.length == 0) { - return new Result().error("删除的固件ID不能为空"); - } - otaService.delete(ids); - return new Result(); - } - - @Operation(summary = "检查 OTA 版本和设备激活状态") - @PostMapping("check") public ResponseEntity checkOTAVersion( @RequestBody DeviceReportReqDTO deviceReportReqDTO, @Parameter(name = "Device-Id", description = "设备唯一标识", required = true, in = ParameterIn.HEADER) @RequestHeader("Device-Id") String deviceId, - @Parameter(name = "Client-Id", description = "客户端标识", required = true, in = ParameterIn.HEADER) @RequestHeader("Client-Id") String clientId) { - if (StringUtils.isAnyBlank(deviceId, clientId)) { + @Parameter(name = "Client-Id", description = "客户端标识", required = false, in = ParameterIn.HEADER) @RequestHeader(value = "Client-Id", required = false) String clientId) { + if (StringUtils.isBlank(deviceId)) { return createResponse(DeviceReportRespDTO.createError("Device ID is required")); } + if (StringUtils.isBlank(clientId)) { + clientId = deviceId; + } String macAddress = deviceReportReqDTO.getMacAddress(); boolean macAddressValid = NetworkUtil.isMacAddressValid(macAddress); // 设备Id和Mac地址应是一致的, 并且必须需要application字段 if (!deviceId.equals(macAddress) || !macAddressValid || deviceReportReqDTO.getApplication() == null) { return createResponse(DeviceReportRespDTO.createError("Invalid OTA request")); } - return createResponse(deviceService.checkDeviceActive(macAddress, deviceId, clientId, deviceReportReqDTO)); + return createResponse(deviceService.checkDeviceActive(macAddress, clientId, deviceReportReqDTO)); } - @Operation(summary = "获取 OTA 提示信息") - @GetMapping("prompt") - public ResponseEntity getOTAPrompt() { - return createResponse(DeviceReportRespDTO.createError("请提交正确的ota参数")); + @Operation(summary = "设备快速检查激活状态") + @PostMapping("activate") + public ResponseEntity activateDevice( + @Parameter(name = "Device-Id", description = "设备唯一标识", required = true, in = ParameterIn.HEADER) @RequestHeader("Device-Id") String deviceId, + @Parameter(name = "Client-Id", description = "客户端标识", required = false, in = ParameterIn.HEADER) @RequestHeader(value = "Client-Id", required = false) String clientId) { + if (StringUtils.isBlank(deviceId)) { + return ResponseEntity.status(202).build(); + } + DeviceEntity device = deviceService.getDeviceByMacAddress(deviceId); + if (device == null) { + return ResponseEntity.status(202).build(); + } + return ResponseEntity.ok("success"); } - @GetMapping("/download/{id}") - @Operation(summary = "下载固件文件") - public ResponseEntity downloadFirmware(@PathVariable("id") String id) { - try { - // 获取固件信息 - OtaEntity otaEntity = otaService.getById(id); - if (otaEntity == null || StringUtils.isBlank(otaEntity.getFirmwarePath())) { - logger.warn("Firmware not found or path is empty for ID: {}", id); - return ResponseEntity.notFound().build(); - } - - // 获取文件路径 - 确保路径是绝对路径或正确的相对路径 - String firmwarePath = otaEntity.getFirmwarePath(); - Path path; - - // 检查是否是绝对路径 - if (Paths.get(firmwarePath).isAbsolute()) { - path = Paths.get(firmwarePath); - } else { - // 如果是相对路径,则从当前工作目录解析 - path = Paths.get(System.getProperty("user.dir"), firmwarePath); - } - - logger.info("Attempting to download firmware for ID: {}, DB path: {}, resolved path: {}", - id, firmwarePath, path.toAbsolutePath()); - - if (!Files.exists(path) || !Files.isRegularFile(path)) { - // 尝试直接从firmware目录下查找文件名 - String fileName = new File(firmwarePath).getName(); - Path altPath = Paths.get(System.getProperty("user.dir"), "firmware", fileName); - - logger.info("File not found at primary path, trying alternative path: {}", altPath.toAbsolutePath()); - - if (Files.exists(altPath) && Files.isRegularFile(altPath)) { - path = altPath; - } else { - logger.error("Firmware file not found at either path: {} or {}", - path.toAbsolutePath(), altPath.toAbsolutePath()); - return ResponseEntity.notFound().build(); - } - } - - // 读取文件内容 - byte[] fileContent = Files.readAllBytes(path); - - // 设置响应头 - String originalFilename = otaEntity.getFirmwareName() + "_" + otaEntity.getVersion(); - if (firmwarePath.contains(".")) { - String extension = firmwarePath.substring(firmwarePath.lastIndexOf(".")); - originalFilename += extension; - } - - // 清理文件名,移除不安全字符 - String safeFilename = originalFilename.replaceAll("[^a-zA-Z0-9._-]", "_"); - - logger.info("Providing download for firmware ID: {}, filename: {}, size: {} bytes", - id, safeFilename, fileContent.length); - - return ResponseEntity.ok() - .contentType(MediaType.APPLICATION_OCTET_STREAM) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + safeFilename + "\"") - .body(fileContent); - } catch (IOException e) { - logger.error("Error reading firmware file for ID: {}", id, e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } catch (Exception e) { - logger.error("Unexpected error during firmware download for ID: {}", id, e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } - - @PostMapping("/upload") - @Operation(summary = "上传固件文件") - public Result uploadFirmware(@RequestParam("file") MultipartFile file) { - if (file.isEmpty()) { - return new Result().error("上传文件不能为空"); - } - - try { - // 获取文件名 - String originalFilename = file.getOriginalFilename(); - // 生成唯一的文件名 - String uniqueFileName = UUID.randomUUID().toString() + "_" + originalFilename; - // 设置存储路径 - String uploadDir = "firmware"; - Path uploadPath = Paths.get(uploadDir); - System.out.println(uploadPath); - - // 如果目录不存在,创建目录 - if (!Files.exists(uploadPath)) { - Files.createDirectories(uploadPath); - } - - // 完整的文件路径 - Path filePath = uploadPath.resolve(uniqueFileName); - - // 保存文件 - Files.copy(file.getInputStream(), filePath); - - // 返回文件路径 - return new Result().ok(filePath.toString()); - } catch (IOException e) { - return new Result().error("文件上传失败:" + e.getMessage()); - } + @GetMapping + @Hidden + public ResponseEntity getOTA() { + return ResponseEntity.ok("OTA接口运行正常"); } @SneakyThrows diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceReportRespDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceReportRespDTO.java index 9f93a9b76..d7e107927 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceReportRespDTO.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceReportRespDTO.java @@ -44,6 +44,8 @@ public class DeviceReportRespDTO { @Schema(description = "激活码信息: 激活地址") private String message; + @Schema(description = "挑战码") + private String challenge; } @Getter diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java index 37ff8d490..8bb203cc4 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java @@ -19,7 +19,7 @@ public interface DeviceService { /** * 检查设备是否激活 */ - DeviceReportRespDTO checkDeviceActive(String macAddress, String deviceId, String clientId, + DeviceReportRespDTO checkDeviceActive(String macAddress, String clientId, DeviceReportReqDTO deviceReport); /** @@ -66,4 +66,20 @@ public interface DeviceService { * @return 用户列表分页数据 */ PageData page(DevicePageUserDTO dto); + + /** + * 根据MAC地址获取设备信息 + * + * @param macAddress MAC地址 + * @return 设备信息 + */ + DeviceEntity getDeviceByMacAddress(String macAddress); + + /** + * 根据设备ID获取激活码 + * + * @param deviceId 设备ID + * @return 激活码 + */ + String geCodeByDeviceId(String deviceId); } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java index a9797f42c..aef157490 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java @@ -9,7 +9,6 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -34,6 +33,7 @@ import xiaozhi.modules.device.entity.DeviceEntity; import xiaozhi.modules.device.service.DeviceService; import xiaozhi.modules.device.vo.UserShowDeviceListVO; import xiaozhi.modules.security.user.SecurityUser; +import xiaozhi.modules.sys.service.SysParamsService; import xiaozhi.modules.sys.service.SysUserUtilService; @Service @@ -49,11 +49,11 @@ public class DeviceServiceImpl extends BaseServiceImpl // 添加构造函数来初始化 deviceMapper public DeviceServiceImpl(DeviceDao deviceDao, SysUserUtilService sysUserUtilService, - @Value("${app.fronted-url:http://localhost:8001}") String frontedUrl, + SysParamsService sysParamsService, RedisTemplate redisTemplate) { this.deviceDao = deviceDao; this.sysUserUtilService = sysUserUtilService; - this.frontedUrl = frontedUrl; + this.frontedUrl = sysParamsService.getValue(Constant.SERVER_FRONTED_URL, true); this.redisTemplate = redisTemplate; } @@ -120,7 +120,7 @@ public class DeviceServiceImpl extends BaseServiceImpl } @Override - public DeviceReportRespDTO checkDeviceActive(String macAddress, String deviceId, String clientId, + public DeviceReportRespDTO checkDeviceActive(String macAddress, String clientId, DeviceReportReqDTO deviceReport) { DeviceReportRespDTO response = new DeviceReportRespDTO(); response.setServer_time(buildServerTime()); @@ -132,46 +132,12 @@ public class DeviceServiceImpl extends BaseServiceImpl firmware.setUrl("http://localhost:8002/xiaozhi/ota/download"); response.setFirmware(firmware); - DeviceEntity deviceById = getDeviceById(deviceId); + DeviceEntity deviceById = getDeviceById(macAddress); if (deviceById != null) { // 如果设备存在,则更新上次连接时间 deviceById.setLastConnectedAt(new Date()); deviceDao.updateById(deviceById); } else { // 如果设备不存在,则生成激活码 - String safeDeviceId = deviceId.replace(":", "_").toLowerCase(); - String dataKey = String.format("ota:activation:data:%s", safeDeviceId); - - Map cacheMap = redisTemplate.opsForHash().entries(dataKey); - DeviceReportRespDTO.Activation code = new DeviceReportRespDTO.Activation(); - - if (cacheMap != null && cacheMap.containsKey("activation_code")) { - String cachedCode = (String) cacheMap.get("activation_code"); - code.setCode(cachedCode); - code.setMessage(frontedUrl + "\n" + cachedCode); - } else { - String newCode = RandomUtil.randomNumbers(6); - code.setCode(newCode); - code.setMessage(frontedUrl + "\n" + newCode); - - Map dataMap = new HashMap<>(); - dataMap.put("id", deviceId); - dataMap.put("mac_address", macAddress); - dataMap.put("board", (deviceReport.getChipModelName() != null) ? deviceReport.getChipModelName() - : (deviceReport.getBoard() != null ? deviceReport.getBoard().getType() : "unknown")); - dataMap.put("app_version", (deviceReport.getApplication() != null) - ? deviceReport.getApplication().getVersion() - : null); - dataMap.put("deviceId", deviceId); - dataMap.put("activation_code", newCode); - - // 写入主数据 key - redisTemplate.opsForHash().putAll(dataKey, dataMap); - redisTemplate.expire(dataKey, 24, TimeUnit.HOURS); - - // 写入反查激活码 key - String codeKey = "ota:activation:code:" + newCode; - redisTemplate.opsForValue().set(codeKey, deviceId, 24, TimeUnit.HOURS); - } - + DeviceReportRespDTO.Activation code = buildActivation(macAddress, deviceReport); response.setActivation(code); } @@ -221,7 +187,7 @@ public class DeviceServiceImpl extends BaseServiceImpl params.put(Constant.PAGE, dto.getPage()); params.put(Constant.LIMIT, dto.getLimit()); IPage page = baseDao.selectPage( - getPage(params, "sort", true), + getPage(params, "mac_address", true), // 定义查询条件 new QueryWrapper() // 必须设备关键词查找 @@ -240,6 +206,16 @@ public class DeviceServiceImpl extends BaseServiceImpl return new PageData<>(list, page.getTotal()); } + @Override + public DeviceEntity getDeviceByMacAddress(String macAddress) { + if (StringUtils.isBlank(macAddress)) { + return null; + } + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("mac_address", macAddress); + return baseDao.selectOne(wrapper); + } + private DeviceReportRespDTO.ServerTime buildServerTime() { DeviceReportRespDTO.ServerTime serverTime = new DeviceReportRespDTO.ServerTime(); TimeZone tz = TimeZone.getDefault(); @@ -248,4 +224,63 @@ public class DeviceServiceImpl extends BaseServiceImpl serverTime.setTimezone_offset(tz.getOffset(System.currentTimeMillis()) / (60 * 1000)); return serverTime; } + + @Override + public String geCodeByDeviceId(String deviceId) { + String dataKey = getDeviceCacheKey(deviceId); + + Map cacheMap = redisTemplate.opsForHash().entries(dataKey); + if (cacheMap != null && cacheMap.containsKey("activation_code")) { + String cachedCode = (String) cacheMap.get("activation_code"); + return cachedCode; + } + return null; + } + + private String getDeviceCacheKey(String deviceId) { + String safeDeviceId = deviceId.replace(":", "_").toLowerCase(); + String dataKey = String.format("ota:activation:data:%s", safeDeviceId); + return dataKey; + } + + public DeviceReportRespDTO.Activation buildActivation(String deviceId, DeviceReportReqDTO deviceReport) { + DeviceReportRespDTO.Activation code = new DeviceReportRespDTO.Activation(); + + String cachedCode = geCodeByDeviceId(deviceId); + + if (StringUtils.isNotBlank(cachedCode)) { + code.setCode(cachedCode); + code.setMessage(frontedUrl + "\n" + cachedCode); + code.setChallenge(deviceId); + } else { + String newCode = RandomUtil.randomNumbers(6); + code.setCode(newCode); + code.setMessage(frontedUrl + "\n" + newCode); + code.setChallenge(deviceId); + + Map dataMap = new HashMap<>(); + dataMap.put("id", deviceId); + dataMap.put("mac_address", deviceId); + + dataMap.put("board", (deviceReport.getBoard() != null && deviceReport.getBoard().getType() != null) + ? deviceReport.getBoard().getType() + : (deviceReport.getChipModelName() != null ? deviceReport.getChipModelName() : "unknown")); + dataMap.put("app_version", (deviceReport.getApplication() != null) + ? deviceReport.getApplication().getVersion() + : null); + + dataMap.put("deviceId", deviceId); + dataMap.put("activation_code", newCode); + + // 写入主数据 key + String dataKey = getDeviceCacheKey(deviceId); + redisTemplate.opsForHash().putAll(dataKey, dataMap); + redisTemplate.expire(dataKey, 24, TimeUnit.HOURS); + + // 写入反查激活码 key + String codeKey = "ota:activation:code:" + newCode; + redisTemplate.opsForValue().set(codeKey, deviceId, 24, TimeUnit.HOURS); + } + return code; + } } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java index 0ce421572..8baff29d6 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/controller/ModelController.java @@ -19,6 +19,8 @@ import lombok.AllArgsConstructor; import xiaozhi.common.page.PageData; import xiaozhi.common.utils.ConvertUtils; import xiaozhi.common.utils.Result; +import xiaozhi.modules.agent.service.AgentTemplateService; +import xiaozhi.modules.config.service.ConfigService; import xiaozhi.modules.model.dto.ModelBasicInfoDTO; import xiaozhi.modules.model.dto.ModelConfigBodyDTO; import xiaozhi.modules.model.dto.ModelConfigDTO; @@ -38,6 +40,8 @@ public class ModelController { private final ModelProviderService modelProviderService; private final TimbreService timbreService; private final ModelConfigService modelConfigService; + private final ConfigService configService; + private final AgentTemplateService agentTemplateService; @GetMapping("/names") @Operation(summary = "获取所有模型名称") @@ -75,6 +79,7 @@ public class ModelController { @PathVariable String provideCode, @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { ModelConfigDTO modelConfigDTO = modelConfigService.add(modelType, provideCode, modelConfigBodyDTO); + configService.getConfig(false); return new Result().ok(modelConfigDTO); } @@ -86,6 +91,7 @@ public class ModelController { @PathVariable String id, @RequestBody ModelConfigBodyDTO modelConfigBodyDTO) { ModelConfigDTO modelConfigDTO = modelConfigService.edit(modelType, provideCode, id, modelConfigBodyDTO); + configService.getConfig(false); return new Result().ok(modelConfigDTO); } @@ -119,6 +125,27 @@ public class ModelController { return new Result(); } + @PutMapping("/default/{id}") + @Operation(summary = "设置默认模型") + @RequiresPermissions("sys:role:superAdmin") + public Result setDefaultModel(@PathVariable String id) { + ModelConfigEntity entity = modelConfigService.selectById(id); + if (entity == null) { + return new Result().error("模型配置不存在"); + } + // 将其他模型设置为非默认 + modelConfigService.setDefaultModel(entity.getModelType(), 0); + entity.setIsEnabled(1); + entity.setIsDefault(1); + modelConfigService.updateById(entity); + + // 更新模板表中对应的模型ID + agentTemplateService.updateDefaultTemplateModelId(entity.getModelType(), entity.getId()); + + configService.getConfig(false); + return new Result(); + } + @GetMapping("/{modelId}/voices") @Operation(summary = "获取模型音色") @RequiresPermissions("sys:role:normal") diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java index b8cc38b1b..9d15ac6df 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/ModelConfigService.java @@ -28,4 +28,21 @@ public interface ModelConfigService extends BaseService { * @return 模型名称 */ String getModelNameById(String id); + + /** + * 根据ID获取模型配置 + * + * @param id 模型ID + * @param isCache 是否缓存 + * @return 模型配置实体 + */ + ModelConfigEntity getModelById(String id, boolean isCache); + + /** + * 设置默认模型 + * + * @param modelType 模型类型 + * @param isDefault 是否默认 + */ + void setDefaultModel(String modelType, int isDefault); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java index de8cbd4f3..00d484861 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java @@ -42,6 +42,7 @@ public class ModelConfigServiceImpl extends BaseServiceImpl entities = modelConfigDao.selectList( new QueryWrapper() .eq("model_type", modelType) + .eq("is_enabled", 1) .like(StringUtils.isNotBlank(modelName), "model_name", "%" + modelName + "%") .select("id", "model_name")); return ConvertUtils.sourceToTarget(entities, ModelBasicInfoDTO.class); @@ -94,6 +95,8 @@ public class ModelConfigServiceImpl extends BaseServiceImpl() + .eq("model_type", modelType)); + } } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/security/config/ShiroConfig.java b/main/manager-api/src/main/java/xiaozhi/modules/security/config/ShiroConfig.java index e5b89c99f..fdcb62b20 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/security/config/ShiroConfig.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/security/config/ShiroConfig.java @@ -76,8 +76,10 @@ public class ShiroConfig { filterMap.put("/favicon.ico", "anon"); filterMap.put("/user/captcha", "anon"); filterMap.put("/user/login", "anon"); + filterMap.put("/user/pub-config", "anon"); filterMap.put("/user/register", "anon"); - filterMap.put("/device/register", "anon"); + filterMap.put("/config/server-base", "anon"); + filterMap.put("/config/agent-models", "anon"); filterMap.put("/**", "oauth2"); shiroFilter.setFilterChainDefinitionMap(filterMap); diff --git a/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java b/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java index 7db612b5d..7cbaa8af3 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/security/controller/LoginController.java @@ -1,6 +1,8 @@ package xiaozhi.modules.security.controller; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -13,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import lombok.AllArgsConstructor; +import xiaozhi.common.constant.Constant; import xiaozhi.common.exception.ErrorCode; import xiaozhi.common.exception.RenException; import xiaozhi.common.page.TokenDTO; @@ -75,6 +78,9 @@ public class LoginController { @PostMapping("/register") @Operation(summary = "注册") public Result register(@RequestBody LoginDTO login) { + if (!sysUserService.getAllowUserRegister()) { + throw new RenException("当前不允许普通用户注册"); + } // 验证是否正确输入验证码 boolean validate = captchaService.validate(login.getCaptchaId(), login.getCaptcha()); if (!validate) { @@ -111,4 +117,13 @@ public class LoginController { sysUserTokenService.changePassword(userId, passwordDTO); return new Result<>(); } + + @GetMapping("/pub-config") + @Operation(summary = "公共配置") + public Result> pubConfig() { + Map config = new HashMap<>(); + config.put("version", Constant.VERSION); + config.put("allowUserRegister", sysUserService.getAllowUserRegister()); + return new Result>().ok(config); + } } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/sys/controller/SysParamsController.java b/main/manager-api/src/main/java/xiaozhi/modules/sys/controller/SysParamsController.java index c8f955287..1951333fd 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/sys/controller/SysParamsController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/sys/controller/SysParamsController.java @@ -27,6 +27,7 @@ import xiaozhi.common.validator.ValidatorUtils; import xiaozhi.common.validator.group.AddGroup; import xiaozhi.common.validator.group.DefaultGroup; import xiaozhi.common.validator.group.UpdateGroup; +import xiaozhi.modules.config.service.ConfigService; import xiaozhi.modules.sys.dto.SysParamsDTO; import xiaozhi.modules.sys.service.SysParamsService; @@ -42,6 +43,7 @@ import xiaozhi.modules.sys.service.SysParamsService; @AllArgsConstructor public class SysParamsController { private final SysParamsService sysParamsService; + private final ConfigService configService; @GetMapping("page") @Operation(summary = "分页") @@ -77,7 +79,7 @@ public class SysParamsController { ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); sysParamsService.save(dto); - + configService.getConfig(false); return new Result(); } @@ -90,7 +92,7 @@ public class SysParamsController { ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); sysParamsService.update(dto); - + configService.getConfig(false); return new Result(); } @@ -103,7 +105,7 @@ public class SysParamsController { AssertUtils.isArrayEmpty(ids, "id"); sysParamsService.delete(ids); - + configService.getConfig(false); return new Result(); } } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java index d5d103afa..7a35da321 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysUserService.java @@ -65,4 +65,11 @@ public interface SysUserService extends BaseService { * @param userIds 用户ID数组 */ void changeStatus(Integer status, String[] userIds); + + /** + * 获取是否允许用户注册 + * + * @return 是否允许用户注册 + */ + boolean getAllowUserRegister(); } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysParamsServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysParamsServiceImpl.java index 85814975a..15f62816d 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysParamsServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysParamsServiceImpl.java @@ -37,7 +37,7 @@ public class SysParamsServiceImpl extends BaseServiceImpl page(Map params) { IPage page = baseDao.selectPage( - getPage(params, Constant.CREATE_DATE, false), + getPage(params, null, false), getWrapper(params)); return getPageData(page, SysParamsDTO.class); @@ -125,6 +125,13 @@ public class SysParamsServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); @@ -205,4 +208,17 @@ public class SysUserServiceImpl extends BaseServiceImpl()); + if (userCount == 0) { + return true; + } + return false; + } } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java index f7ee176d6..eebd55be0 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/TimbreService.java @@ -31,7 +31,7 @@ public interface TimbreService extends BaseService { * @param timbreId 音色表id * @return 音色信息 */ - TimbreDetailsVO get(Long timbreId); + TimbreDetailsVO get(String timbreId); /** * 保存音色信息 diff --git a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java index 54e5ec045..2ed5b1ab0 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java @@ -47,7 +47,7 @@ public class TimbreServiceImpl extends BaseServiceImpl params.put(Constant.PAGE, dto.getPage()); params.put(Constant.LIMIT, dto.getLimit()); IPage page = baseDao.selectPage( - getPage(params, "sort", true), + getPage(params, null, true), // 定义查询条件 new QueryWrapper() // 必须按照ttsID查找 @@ -59,9 +59,33 @@ public class TimbreServiceImpl extends BaseServiceImpl } @Override - public TimbreDetailsVO get(Long timbreId) { + public TimbreDetailsVO get(String timbreId) { + if (StringUtils.isBlank(timbreId)) { + return null; + } + + // 先从Redis获取缓存 + String key = RedisKeys.getTimbreDetailsKey(timbreId); + TimbreDetailsVO cachedDetails = (TimbreDetailsVO) redisUtils.get(key); + if (cachedDetails != null) { + return cachedDetails; + } + + // 如果缓存中没有,则从数据库获取 TimbreEntity entity = baseDao.selectById(timbreId); - return ConvertUtils.sourceToTarget(entity, TimbreDetailsVO.class); + if (entity == null) { + return null; + } + + // 转换为VO对象 + TimbreDetailsVO details = ConvertUtils.sourceToTarget(entity, TimbreDetailsVO.class); + + // 存入Redis缓存 + if (details != null) { + redisUtils.set(key, details); + } + + return details; } @Override @@ -79,6 +103,8 @@ public class TimbreServiceImpl extends BaseServiceImpl TimbreEntity timbreEntity = ConvertUtils.sourceToTarget(dto, TimbreEntity.class); timbreEntity.setId(timbreId); baseDao.updateById(timbreEntity); + // 删除缓存 + redisUtils.delete(RedisKeys.getTimbreDetailsKey(timbreId)); } @Override diff --git a/main/manager-api/src/main/resources/application-dev.yml b/main/manager-api/src/main/resources/application-dev.yml index 50056d4a0..b49b31ca2 100644 --- a/main/manager-api/src/main/resources/application-dev.yml +++ b/main/manager-api/src/main/resources/application-dev.yml @@ -12,9 +12,9 @@ spring: druid: #MySQL driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3308/xiaozhi_esp32_server?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true + url: jdbc:mysql://127.0.0.1:3306/xiaozhi_esp32_server?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true username: root - password: jky123456 + password: 123456 initial-size: 10 max-active: 100 min-idle: 10 diff --git a/main/manager-api/src/main/resources/application.yml b/main/manager-api/src/main/resources/application.yml index abccb0b55..3daf48a14 100644 --- a/main/manager-api/src/main/resources/application.yml +++ b/main/manager-api/src/main/resources/application.yml @@ -63,7 +63,4 @@ mybatis-plus: configuration-properties: prefix: blobType: BLOB - boolValue: TRUE - -app: - fronted-url: http://localhost:8001 \ No newline at end of file + boolValue: TRUE \ No newline at end of file diff --git a/main/manager-api/src/main/resources/db/changelog/202504181536.sql b/main/manager-api/src/main/resources/db/changelog/202504181536.sql new file mode 100644 index 000000000..327aa605f --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202504181536.sql @@ -0,0 +1,7 @@ +-- 调整意图识别配置 +delete from `ai_model_config` where id = 'Intent_function_call'; +INSERT INTO `ai_model_config` VALUES ('Intent_function_call', 'Intent', 'function_call', '函数调用意图识别', 0, 1, '{\"type\": \"function_call\", \"functions\": \"change_role;get_weather;get_news;play_music\"}', NULL, NULL, 3, NULL, NULL, NULL, NULL); + +-- 增加单台设备每天最多聊天句数 +delete from `sys_params` where id = 105; +INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (105, 'device_max_output_size', '0', 'number', 1, '单台设备每天最多输出字数,0表示不限制'); \ No newline at end of file diff --git a/main/manager-api/src/main/resources/db/changelog/202504211118.sql b/main/manager-api/src/main/resources/db/changelog/202504211118.sql new file mode 100644 index 000000000..6bbdc183d --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202504211118.sql @@ -0,0 +1,19 @@ +-- 删除无用模型供应器 +delete from `ai_model_provider` where id = 'SYSTEM_LLM_doubao'; +delete from `ai_model_provider` where id = 'SYSTEM_LLM_chatglm'; +delete from `ai_model_provider` where id = 'SYSTEM_TTS_302ai'; +delete from `ai_model_provider` where id = 'SYSTEM_TTS_gizwits'; + +-- 添加模型供应器 +delete from `ai_model_provider` where id = 'SYSTEM_ASR_TencentASR'; +INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `fields`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES +('SYSTEM_ASR_TencentASR', 'ASR', 'tencent', '腾讯语音识别', '[{"key":"appid","label":"应用ID","type":"string"},{"key":"secret_id","label":"Secret ID","type":"string"},{"key":"secret_key","label":"Secret Key","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"}]', 4, 1, NOW(), 1, NOW()); + +-- 添加腾讯语音合成模型供应器 +delete from `ai_model_provider` where id = 'SYSTEM_TTS_TencentTTS'; +INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `fields`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES +('SYSTEM_TTS_TencentTTS', 'TTS', 'tencent', '腾讯语音合成', '[{"key":"appid","label":"应用ID","type":"string"},{"key":"secret_id","label":"Secret ID","type":"string"},{"key":"secret_key","label":"Secret Key","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"},{"key":"region","label":"区域","type":"string"},{"key":"voice","label":"音色ID","type":"string"}]', 5, 1, NOW(), 1, NOW()); + +-- 添加腾讯语音合成音色 +delete from `ai_tts_voice` where id = 'TTS_TencentTTS0001'; +INSERT INTO `ai_tts_voice` VALUES ('TTS_TencentTTS0001', 'TTS_TencentTTS', '智瑜', '101001', '中文', NULL, NULL, 1, NULL, NULL, NULL, NULL); diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index f0ac310f1..b84a62253 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -23,13 +23,6 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/2025_tts_voive.sql - - changeSet: - id: 202504082210 - author: John - changes: - - sqlFile: - encoding: utf8 - path: classpath:db/changelog/202504082210.sql - changeSet: id: 202504082211 author: John @@ -37,17 +30,45 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202504082211.sql - - changeSet: - id: 202504092313 - author: John - changes: - - sqlFile: - encoding: utf8 - path: classpath:db/changelog/202504092313.sql - changeSet: id: 202504092335 author: John changes: - sqlFile: encoding: utf8 - path: classpath:db/changelog/202504092335.sql \ No newline at end of file + path: classpath:db/changelog/202504092335.sql + - changeSet: + id: 202504112044 + author: John + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202504112044.sql + - changeSet: + id: 202504112058 + author: John + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202504112058.sql + - changeSet: + id: 202504151206 + author: John + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202504151206.sql + - changeSet: + id: 202504181536 + author: John + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202504181536.sql + - changeSet: + id: 202504211118 + author: John + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202504211118.sql \ No newline at end of file diff --git a/main/manager-api/src/main/resources/i18n/messages.properties b/main/manager-api/src/main/resources/i18n/messages.properties index ce6cf61ba..5126feb2b 100644 --- a/main/manager-api/src/main/resources/i18n/messages.properties +++ b/main/manager-api/src/main/resources/i18n/messages.properties @@ -40,3 +40,7 @@ 10037=\u53C2\u6570\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684\u6570\u5B57 10038=\u53C2\u6570\u503C\u5FC5\u987B\u662Ftrue\u6216false 10039=\u53C2\u6570\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684JSON\u6570\u7EC4\u683C\u5F0F +10040=\u53C2\u6570\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684JSON\u683C\u5F0F + +10041=\u8BBE\u5907\u672A\u627E\u5230 +10042={0} diff --git a/main/manager-api/src/main/resources/i18n/messages_en_US.properties b/main/manager-api/src/main/resources/i18n/messages_en_US.properties index d6c1bc0cb..43781857e 100644 --- a/main/manager-api/src/main/resources/i18n/messages_en_US.properties +++ b/main/manager-api/src/main/resources/i18n/messages_en_US.properties @@ -39,4 +39,8 @@ 10036=Unsupported parameter type 10037=Parameter value must be a valid number 10038=Parameter value must be true or false -10039=Parameter value must be a valid JSON array format \ No newline at end of file +10039=Parameter value must be a valid JSON array format +10040=Parameter value must be a valid JSON format + +10041=Device not found +10042={0} \ No newline at end of file diff --git a/main/manager-api/src/main/resources/i18n/messages_zh_CN.properties b/main/manager-api/src/main/resources/i18n/messages_zh_CN.properties index 566ca0c98..713ab96a2 100644 --- a/main/manager-api/src/main/resources/i18n/messages_zh_CN.properties +++ b/main/manager-api/src/main/resources/i18n/messages_zh_CN.properties @@ -39,4 +39,8 @@ 10036=\u4E0D\u652F\u6301\u7684\u53C2\u6570\u7C7B\u578B 10037=\u53C2\u6570\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684\u6570\u5B57 10038=\u53C2\u6570\u503C\u5FC5\u987B\u662Ftrue\u6216false -10039=\u53C2\u6570\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684JSON\u6570\u7EC4\u683C\u5F0F \ No newline at end of file +10039=\u53C2\u6570\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684JSON\u6570\u7EC4\u683C\u5F0F +10040=\u53C2\u6570\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684JSON\u683C\u5F0F + +10041=\u8BBE\u5907\u672A\u627E\u5230 +10042={0} \ No newline at end of file diff --git a/main/manager-api/src/main/resources/i18n/messages_zh_TW.properties b/main/manager-api/src/main/resources/i18n/messages_zh_TW.properties index a5d81697f..b5847ec49 100644 --- a/main/manager-api/src/main/resources/i18n/messages_zh_TW.properties +++ b/main/manager-api/src/main/resources/i18n/messages_zh_TW.properties @@ -39,4 +39,8 @@ 10036=\u4E0D\u652F\u63F4\u7684\u53C3\u6578\u985E\u578B 10037=\u53C3\u6578\u503C\u5FC5\u9808\u662F\u6709\u6548\u7684\u6578\u5B57 10038=\u53C3\u6578\u503C\u5FC5\u9808\u662Ftrue\u6216false -10039=\u53C3\u6578\u503C\u5FC5\u9808\u662F\u6709\u6548\u7684JSON\u6578\u7D44\u683C\u5F0F \ No newline at end of file +10039=\u53C3\u6578\u503C\u5FC5\u9808\u662F\u6709\u6548\u7684JSON\u6578\u7D44\u683C\u5F0F +10040=\u53C3\u6578\u503C\u5FC5\u9808\u662F\u6709\u6548\u7684JSON\u683C\u5F0F + +10041=\u8A2D\u5099\u672A\u627E\u5230 +10042={0} \ No newline at end of file diff --git a/main/manager-api/src/main/resources/i18n/validation.properties b/main/manager-api/src/main/resources/i18n/validation.properties index dd9b47e8c..652ae2695 100644 --- a/main/manager-api/src/main/resources/i18n/validation.properties +++ b/main/manager-api/src/main/resources/i18n/validation.properties @@ -33,3 +33,5 @@ timbre.ttsModelId.require=\u97F3\u8272\u7684tts\u4E3B\u952E\u4E0D\u53EF\u4EE5\u4 timbre.ttsVoice.require=\u97F3\u8272\u7684\u7F16\u7801\u4E0D\u53EF\u4EE5\u4E3A\u7A7A timbre.voiceDemo.require=\u97F3\u8272\u7684\u64AD\u653EDemo\u4E0D\u53EF\u4EE5\u4E3A\u7A7A +ota.device.not.found=\u8BBE\u5907\u672A\u627E\u5230 +ota.device.need.bind={0} diff --git a/main/manager-api/src/main/resources/i18n/validation_en_US.properties b/main/manager-api/src/main/resources/i18n/validation_en_US.properties index efb2c296b..fb6f38283 100644 --- a/main/manager-api/src/main/resources/i18n/validation_en_US.properties +++ b/main/manager-api/src/main/resources/i18n/validation_en_US.properties @@ -32,3 +32,5 @@ timbre.ttsModelId.require=The TTS model ID of the timbre cannot be empty timbre.ttsVoice.require=The TTS voice of the timbre cannot be empty timbre.voiceDemo.require=The voice demo of the timbre cannot be empty +ota.device.not.found=Device not found +ota.device.need.bind={0} \ No newline at end of file diff --git a/main/manager-api/src/main/resources/i18n/validation_zh_CN.properties b/main/manager-api/src/main/resources/i18n/validation_zh_CN.properties index ebafda82c..1ff8a3bae 100644 --- a/main/manager-api/src/main/resources/i18n/validation_zh_CN.properties +++ b/main/manager-api/src/main/resources/i18n/validation_zh_CN.properties @@ -32,3 +32,5 @@ timbre.ttsModelId.require=\u97F3\u8272\u7684tts\u4E3B\u9375\u4E0D\u53EF\u4EE5\u7 timbre.ttsVoice.require=\u97F3\u8272\u7684\u7DE8\u78BC\u4E0D\u53EF\u4EE5\u70BA\u7A7A timbre.voiceDemo.require=\u97F3\u8272\u7684\u64AD\u653E\u5730\u5740\u4E0D\u53EF\u4EE5\u70BA\u7A7A +ota.device.not.found=\u8A2D\u5099\u672A\u627E\u5230 +ota.device.need.bind={0} \ No newline at end of file diff --git a/main/manager-api/src/main/resources/i18n/validation_zh_TW.properties b/main/manager-api/src/main/resources/i18n/validation_zh_TW.properties index 4a1aabd26..dd6eab900 100644 --- a/main/manager-api/src/main/resources/i18n/validation_zh_TW.properties +++ b/main/manager-api/src/main/resources/i18n/validation_zh_TW.properties @@ -31,3 +31,6 @@ timbre.remark.require=\u97F3\u8272\u7684\u5907\u6CE8\u4E0D\u53EF\u4EE5\u4E3A\u7A timbre.ttsModelId.require=\u97F3\u8272\u7684tts\u4E3B\u952E\u4E0D\u53EF\u4EE5\u4E3A\u7A7A timbre.ttsVoice.require=\u97F3\u8272\u7684\u7F16\u7801\u4E0D\u53EF\u4EE5\u4E3A\u7A7A timbre.voiceDemo.require=\u97F3\u8272\u7684\u64AD\u653EDemo\u4E0D\u53EF\u4EE5\u4E3A\u7A7A + +ota.device.not.found=\u8A2D\u5099\u672A\u627E\u5230 +ota.device.need.bind={0} \ No newline at end of file diff --git a/main/manager-web/src/components/AddModelDialog.vue b/main/manager-web/src/components/AddModelDialog.vue index 9a4a6022c..5add8a77b 100644 --- a/main/manager-web/src/components/AddModelDialog.vue +++ b/main/manager-web/src/components/AddModelDialog.vue @@ -77,7 +77,12 @@
- + 保存
@@ -94,6 +99,7 @@ export default { }, data() { return { + saving: false, providers: [], dialogVisible: false, providersLoaded: false, @@ -175,6 +181,7 @@ export default { }, handleClose() { + this.saving = false; this.$emit('update:visible', false); }, initDynamicConfig() { @@ -185,8 +192,11 @@ export default { this.formData.configJson = newConfig; }, confirm() { + this.saving = true; + if (!this.formData.supplier) { this.$message.error('请选择供应器'); + this.saving = false; return; } @@ -206,11 +216,18 @@ export default { } }; - this.$emit('confirm', submitData); - this.$emit('update:visible', false); - this.resetForm(); + try { + this.$emit('confirm', submitData); + this.$emit('update:visible', false); + this.resetForm(); + } catch (e) { + console.error(e); + } finally { + this.saving = false; + } }, resetForm() { + this.saving = false; this.formData = { modelName: '', modelCode: '', diff --git a/main/manager-web/src/components/AddWisdomBodyDialog.vue b/main/manager-web/src/components/AddWisdomBodyDialog.vue index 66c7a627c..78c19676b 100644 --- a/main/manager-web/src/components/AddWisdomBodyDialog.vue +++ b/main/manager-web/src/components/AddWisdomBodyDialog.vue @@ -11,7 +11,7 @@
-
*
智慧体名称: +
*
智能体名称:
diff --git a/main/manager-web/src/components/DeviceItem.vue b/main/manager-web/src/components/DeviceItem.vue index 80f64f2cb..2ac0bbac7 100644 --- a/main/manager-web/src/components/DeviceItem.vue +++ b/main/manager-web/src/components/DeviceItem.vue @@ -23,12 +23,6 @@
配置角色
- - - - - -
设备管理({{ device.deviceCount }})
@@ -80,7 +74,7 @@ export default { .settings-btn { font-weight: 500; - font-size: 10px; + font-size: 12px; color: #5778ff; background: #e6ebff; width: auto; @@ -95,7 +89,7 @@ export default { display: flex; justify-content: space-between; margin-top: 15px; - font-size: 10px; + font-size: 12px; color: #979db1; font-weight: 400; } diff --git a/main/manager-web/src/components/HeaderBar.vue b/main/manager-web/src/components/HeaderBar.vue index 8fece0a10..c67362ea9 100644 --- a/main/manager-web/src/components/HeaderBar.vue +++ b/main/manager-web/src/components/HeaderBar.vue @@ -32,12 +32,6 @@ :style="{ filter: $route.path === '/params-management' ? 'brightness(0) invert(1)' : 'None' }" /> 参数管理
-
- - OTA管理 -
@@ -111,9 +105,6 @@ export default { goParamManagement() { this.$router.push('/params-management') }, - goOtaManagement() { - this.$router.push('/ota-management') - }, // 获取用户信息 fetchUserInfo() { userApi.getUserInfo(({ data }) => { @@ -179,7 +170,7 @@ export default { .header { background: #f6fcfe66; border: 1px solid #fff; - height: 53px !important; + height: 63px !important; min-width: 900px; /* 设置最小宽度防止过度压缩 */ overflow: hidden; @@ -206,7 +197,7 @@ export default { } .brand-img { - height: 18px; + height: 20px; } .header-center { @@ -228,13 +219,13 @@ export default { .equipment-management { padding: 0 9px; - width: 82px; - height: 24px; - border-radius: 12px; + width: px; + height: 30px; + border-radius: 15px; background: #deeafe; display: flex; justify-content: center; - font-size: 10px; + font-size: 14px; font-weight: 500; gap: 7px; color: #3d4566; @@ -244,6 +235,7 @@ export default { cursor: pointer; flex-shrink: 0; /* 防止导航按钮被压缩 */ + padding: 0px 15px; } .equipment-management.active-tab { diff --git a/main/manager-web/src/components/ModelEditDialog.vue b/main/manager-web/src/components/ModelEditDialog.vue index 9a5341161..f4d582c6c 100644 --- a/main/manager-web/src/components/ModelEditDialog.vue +++ b/main/manager-web/src/components/ModelEditDialog.vue @@ -76,7 +76,12 @@
- + 保存
@@ -102,6 +107,7 @@ export default { dialogVisible: this.visible, providers: [], providersLoaded: false, + saving: false, allProvidersData: null, pendingProviderType: null, pendingModelData: null, @@ -195,6 +201,8 @@ export default { } }, handleSave() { + this.saving = true; // 开始保存加载 + const provideCode = this.form.configJson.type; const formData = { id: this.modelData.id, @@ -209,8 +217,19 @@ export default { ...this.form.configJson, } }; - this.$emit("save", { provideCode, formData }); - this.dialogVisible = false; + + this.$emit("save", { + provideCode, + formData, + done: () => { + this.saving = false; // 保存完成后回调 + } + }); + + // 如果父组件不处理done回调,3秒后自动关闭加载状态 + setTimeout(() => { + this.saving = false; + }, 3000); }, loadProviders() { if (this.providersLoaded) return; diff --git a/main/manager-web/src/components/ParamDialog.vue b/main/manager-web/src/components/ParamDialog.vue index 6fd5d872c..7c126aa50 100644 --- a/main/manager-web/src/components/ParamDialog.vue +++ b/main/manager-web/src/components/ParamDialog.vue @@ -40,7 +40,12 @@