diff --git a/.github/workflows/pushdocker.yml b/.github/workflows/pushdocker.yml index 0c8ef52bf..74a208ca9 100644 --- a/.github/workflows/pushdocker.yml +++ b/.github/workflows/pushdocker.yml @@ -1,4 +1,4 @@ -# 在标签发布的时候 做2个事情 +# When tagging a release, do two things # 1. name: Push To Docker @@ -21,7 +21,7 @@ jobs: - name: Check out git repository uses: actions/checkout@main - # 获取版本号 workflow不支持 所以用插件 + # Unable to obtain version number. Since the workflow doesn't support it, we'll use a plugin - name: Create version id: chat2db_version uses: bhowell2/github-substring-action@1.0.1 @@ -30,12 +30,12 @@ jobs: index_of_str: "refs/tags/v" - # 输出基础信息 + # Outputting basic information - name: Print basic information run: | echo "current version: ${{ steps.chat2db_version.outputs.substring }}" - # 安装node + # Install Node.js - name: Install Node.js uses: actions/setup-node@main with: @@ -43,7 +43,7 @@ jobs: cache: "yarn" cache-dependency-path: chat2db-client/yarn.lock - # 构建静态文件信息 + # Build static file information - name: Yarn install & build & copy run: | cd chat2db-client @@ -52,7 +52,7 @@ jobs: cp -r dist ../chat2db-server/chat2db-server-web-start/src/main/resources/static/front cp -r dist/index.html ../chat2db-server/chat2db-server-web-start/src/main/resources/thymeleaf/ - # 安装java + # Install java and maven - name: Install Java and Maven uses: actions/setup-java@main with: @@ -60,7 +60,7 @@ jobs: distribution: "adopt" cache: "maven" - # 编译服务端java版本 + # Compile server-side Java version - name: Build Java run: mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml @@ -72,14 +72,14 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - # 登录docker hub + # Log in docker hub - name: Log in to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # 打包发送到docker + # Packaging and sending to Docker - name: Build and push uses: docker/build-push-action@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 976204772..a510dad51 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,14 +2,14 @@ name: Build Client # Workflow's trigger -# 在创建标签的时候打包 +# Pack when creating tags on: push: tags: - v* # Workflow's jobs -# 一共需要3台电脑运行 +# A total of 3 computers are required to run # windows # macos-latest x86_64 # macos-latest arm64 @@ -31,7 +31,7 @@ jobs: - name: Check out git repository uses: actions/checkout@main - # 获取版本号 workflow不支持 所以用插件 + # Obtaining the version number is not supported by workflow, so a plug-in is used. - name: Create version id: chat2db_version uses: bhowell2/github-substring-action@1.0.1 @@ -39,13 +39,13 @@ jobs: value: ${{ github.ref }} index_of_str: "refs/tags/v" - # 输出基础信息 + # Output basic information - name: Print basic information run: | echo "current environment: ${{ env.CHAT2DB_ENVIRONMENT }}" echo "current version: ${{ steps.chat2db_version.outputs.substring }}" - # 安装jre Windows + # Install jre Windows - name: Install Jre for Windows if: ${{ runner.os == 'Windows' }} uses: actions/setup-java@main @@ -54,7 +54,7 @@ jobs: distribution: "temurin" java-package: "jre" - # 安装jre MacOS X64 + # Install jre MacOS X64 - name: Install Jre MacOS X64 if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }} uses: actions/setup-java@main @@ -63,7 +63,7 @@ jobs: distribution: "temurin" java-package: "jre" - # 安装jre MacOS arm64 + # Install jre MacOS arm64 - name: Install Jre MacOS arm64 if: ${{ runner.os == 'macOS' && matrix.arch == 'arm64' }} uses: actions/setup-java@main @@ -73,7 +73,7 @@ jobs: java-package: "jre" architecture: "aarch64" - # 安装jre Linux + # Install jre Linux - name: Install Jre for Linux if: ${{ runner.os == 'Linux' }} uses: actions/setup-java@main @@ -82,26 +82,26 @@ jobs: distribution: "temurin" java-package: "jre" - # java.security 开放tls1 Windows + # java.security open tls1 Windows - name: Enable tls1 if: ${{ runner.os == 'Windows' }} run: | sed -i '' "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\( TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "${{ env.JAVA_HOME }}/conf/security/java.security" - # java.security 开放tls1 macOS + # java.security open tls1 macOS - name: Enable tls1 if: ${{ runner.os == 'macOS' }} run: | sed -i '' "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\( TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" $JAVA_HOME/conf/security/java.security - # 复制jre Windows + # Copy jre Windows - name: Copy Jre for Windows if: ${{ runner.os == 'Windows' }} run: | mkdir chat2db-client/static cp -r "${{ env.JAVA_HOME }}" chat2db-client/static/jre - # 复制jre macOS + # Copy jre macOS - name: Copy Jre for macOS if: ${{ runner.os == 'macOS' }} run: | @@ -109,7 +109,7 @@ jobs: cp -r $JAVA_HOME chat2db-client/static/jre chmod -R 777 chat2db-client/static/jre/ - # 复制jre Linux + # Copy jre Linux - name: Copy Jre for Linux if: ${{ runner.os == 'Linux' }} run: | @@ -117,7 +117,7 @@ jobs: cp -r $JAVA_HOME chat2db-client/static/jre chmod -R 777 chat2db-client/static/jre/ - # 安装node + # Install node - name: Install Node.js uses: actions/setup-node@main with: @@ -125,7 +125,7 @@ jobs: cache: "yarn" cache-dependency-path: chat2db-client/yarn.lock - # 安装java + # Install java - name: Install Java and Maven uses: actions/setup-java@main with: @@ -133,7 +133,7 @@ jobs: distribution: "temurin" cache: "maven" - # 构建静态文件信息 + # Build static file information - name: Yarn install & build & copy run: | cd chat2db-client @@ -145,7 +145,7 @@ jobs: yarn yarn run build - # 编译服务端java版本 + # Compile server-side java version - name: Build Java run: mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml @@ -160,7 +160,7 @@ jobs: echo -n ${{ steps.chat2db_version.outputs.substring }} > version cp -r version ./versions/ - # 复制服务端java 到指定位置 + # Copy server-side java to the specified location - name: Copy App run: | cp chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-client/versions/${{ steps.chat2db_version.outputs.substring }}/static/ @@ -245,14 +245,14 @@ jobs: args: "-c.extraMetadata.version=${{ steps.chat2db_version.outputs.substring }} --linux" release: true - # 准备要需要的数据 Windows + # Prepare the required data Windows - name: Prepare upload for Windows if: runner.os == 'Windows' run: | mkdir oss_temp_file cp -r chat2db-client/release/*Setup*.exe ./oss_temp_file - # 准备要需要的数据 MacOS x86_64 + # Prepare the required data MacOS x86_64 - name: Prepare upload for MacOS x86_64 if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }} run: | @@ -265,21 +265,21 @@ jobs: cd static/ && zip -r chat2db-server-start.zip ./ cp -r chat2db-server-start.zip ../../../../oss_temp_file - # 准备要需要的数据 MacOS arm64 + # Prepare the required data MacOS arm64 - name: Prepare upload for MacOS arm64 if: ${{ runner.os == 'macOS' && matrix.arch == 'arm64' }} run: | mkdir oss_temp_file cp -r chat2db-client/release/*.dmg ./oss_temp_file - # 准备要需要的数据 Linux + # Prepare the required data Linux - name: Prepare upload for Linux if: runner.os == 'Linux' run: | mkdir oss_temp_file cp -r chat2db-client/release/*.AppImage ./oss_temp_file - # 把文件上传到OSS 方便下载 + # Upload files to OSS for easy downloading - name: Set up oss utils uses: yizhoumo/setup-ossutil@v1 with: @@ -291,7 +291,7 @@ jobs: run: | ossutil cp -rf --acl=public-read ./oss_temp_file/ oss://chat2db-client/release/${{ steps.chat2db_version.outputs.substring }}/ - # 构建完成通知 + # Build completion notification - name: Send dingtalk message for Windows if: ${{ runner.os == 'Windows' }} uses: ghostoy/dingtalk-action@master @@ -304,7 +304,7 @@ jobs: "text": "# Windows-release-打包完成通知 \n ![bang](https://oss.sqlgpt.cn/static/happy100.jpg) \n ### 任务id:[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }}) \n ### Windows下载地址:[https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB%20Setup%20${{ steps.chat2db_version.outputs.substring }}.exe](https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB%20Setup%20${{ steps.chat2db_version.outputs.substring }}.exe) " } - # 构建完成通知 + # Build completion notification - name: Send dingtalk message for MacOS x86_64 if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }} uses: ghostoy/dingtalk-action@master @@ -317,7 +317,7 @@ jobs: "text": "# MacOS-x86_64-release-打包完成通知 \n ![bang](https://oss.sqlgpt.cn/static/happy100.jpg) \n ### 任务id:[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }}) \n ### Intel芯片下载地址:[https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB-${{ steps.chat2db_version.outputs.substring }}.dmg](https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB-${{ steps.chat2db_version.outputs.substring }}.dmg) \n ### jar包下载地址:[https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/chat2db-server-start.zip](https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/chat2db-server-start.zip) " } - # 构建完成通知 + # Build completion notification - name: Send dingtalk message for MacOS arm64 if: ${{ runner.os == 'macOS' && matrix.arch == 'arm64' }} uses: ghostoy/dingtalk-action@master @@ -330,7 +330,7 @@ jobs: "text": "# MacOS-arm64-release-打包完成通知 \n ![bang](https://oss.sqlgpt.cn/static/happy100.jpg) \n ### 任务id:[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }}) \n ### Apple芯片下载地址:[https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB-${{ steps.chat2db_version.outputs.substring }}-arm64.dmg](https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB-${{ steps.chat2db_version.outputs.substring }}-arm64.dmg) " } - # 构建完成通知 + # Build completion notification - name: Send dingtalk message for Linux if: ${{ runner.os == 'Linux' }} uses: ghostoy/dingtalk-action@master diff --git a/.github/workflows/release_test.yml b/.github/workflows/release_test.yml index 8ffe99e57..5ea5012f3 100644 --- a/.github/workflows/release_test.yml +++ b/.github/workflows/release_test.yml @@ -35,7 +35,7 @@ jobs: - name: Check out git repository uses: actions/checkout@main - # 安装JRE + # Install JRE - name: Install JRE uses: actions/setup-java@main with: @@ -44,7 +44,7 @@ jobs: java-package: "jre" # architecture: ${{ matrix.arch == 'arm64' && 'aarch64' || 'x64' }} - # 开放TLS + # OpenTLS - name: Enable TLS 1.0 and 1.1 in java.security run: | if [ "$RUNNER_OS" = "Windows" ]; then @@ -59,7 +59,7 @@ jobs: RUNNER_OS: ${{ runner.os }} JAVA_HOME: ${{ env.JAVA_HOME }} - # JRE拷贝到前端静态目录 + # Copy JRE to the front-end static directory - name: Copy JRE to static directory run: | mkdir -p chat2db-client/static @@ -71,7 +71,7 @@ jobs: env: JAVA_HOME: ${{ env.JAVA_HOME }} - # Linux中删除jre中相关文件 + # Delete related files in jre in Linux - if: ${{ runner.os == 'Linux' }} name: Delete File on Linux run: | @@ -80,7 +80,7 @@ jobs: rm -rf legal ls -la - # 安装Node.js + # Install Node.js - name: Install Node.js uses: actions/setup-node@main with: @@ -88,7 +88,7 @@ jobs: cache: "yarn" cache-dependency-path: chat2db-client/yarn.lock - # 安装Java + # Install Java - name: Install Java and Maven uses: actions/setup-java@main with: @@ -96,7 +96,7 @@ jobs: distribution: "temurin" cache: "maven" - # 打包Web前端资源 + # Packaging web front-end resources - name: Build FE Static run: | cd chat2db-client @@ -109,7 +109,7 @@ jobs: yarn run build - # 打包后端工程 & 发送到前端 + # Package backend project & send to frontend - name: Build BE Static run: | mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml @@ -118,7 +118,7 @@ jobs: cp -r chat2db-client/version chat2db-client/versions/ cp chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-client/versions/99.0.${{ github.run_id }}/static/ - # 打包桌面端前端资源 + # Packaging desktop front-end resources - name: Prepare Build Electron run: | cd chat2db-client @@ -126,7 +126,7 @@ jobs: cp -r dist ./versions/99.0.${{ github.run_id }}/ rm -r dist - # 打包Electron + # Packaging Electron - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: @@ -143,7 +143,7 @@ jobs: -c.extraMetadata.version=99.0.${{ github.run_id }}-Test ${{ matrix.build_arg}} - # 公证&签名 Mac App + # Notarization & Signature Mac App - name: Notarize MacOS x86_64 App if: matrix.os == 'macos-latest' && matrix.arch == 'x86_64' run: | @@ -159,7 +159,7 @@ jobs: - # Build Jar包 + # Build Jar - name: Prepare upload for Jar if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }} run: | @@ -172,13 +172,13 @@ jobs: cd static/ && zip -r chat2db-server-start.zip ./ cp -r chat2db-server-start.zip ../../../../oss_temp_file - # 准备发往OSS的文件 + # Prepare files to be sent to OSS - name: Prepare upload for OSS run: | mkdir -p oss_temp_file cp -r chat2db-client/release/*${{ matrix.file_extension }} ./oss_temp_file - # 设置OSS + # Set up OSS - name: Set up oss utils uses: yizhoumo/setup-ossutil@v1 with: @@ -187,12 +187,12 @@ jobs: access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }} ossutil-version: "1.7.16" - # 上传到OSS + # Upload to OSS - name: Upload to OSS run: | ossutil cp -rf --acl=public-read ./oss_temp_file/ oss://chat2db-client/test/99.0.${{ github.run_id }}/ - # 配置SSH 待上传到服务器 + # Configure SSH to be uploaded to the server - name: Install ssh key run: | mkdir -p ~/.ssh @@ -201,14 +201,14 @@ jobs: ssh-keyscan -t rsa ${{ secrets.SERVER_DOWNLOAD_HOST }} >> ~/.ssh/known_hosts eval `ssh-agent -s` ssh-add ~/.ssh/id_rsa - # 上传到服务器 + # upload to server - name: Upload package run: | ssh -t ${{ secrets.SERVER_DOWNLOAD_USERNAME }}@${{ secrets.SERVER_DOWNLOAD_HOST }} "mkdir -p ${{ secrets.SERVER_DOWNLOAD_PATH }}/test//99.0.${{ github.run_id }}" scp ./oss_temp_file/* ${{ secrets.SERVER_DOWNLOAD_USERNAME }}@${{ secrets.SERVER_DOWNLOAD_HOST }}:${{ secrets.SERVER_DOWNLOAD_PATH }}/test//99.0.${{ github.run_id }}/ - # 发送到DingTalk + # Send to DingTalk - name: Send dingtalk message uses: ghostoy/dingtalk-action@master with: @@ -220,7 +220,7 @@ jobs: "text": "# ${{ matrix.os }}-test-打包完成通知\n !\n ### 任务id:[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }})\n ### 下载地址:[${{matrix.file_name}}](${{matrix.file_name}})" } - # 发送Jar包地址到DingTalk + # Send Jar package address to DingTalk - if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }} name: Send dingtalk message uses: ghostoy/dingtalk-action@master diff --git a/.github/workflows/release_test_2.yml b/.github/workflows/release_test_2.yml index 4bfcf9050..0e8d3ddc8 100644 --- a/.github/workflows/release_test_2.yml +++ b/.github/workflows/release_test_2.yml @@ -1,4 +1,4 @@ -name: Build Test Client +name: Build Test Client 2 on: push: @@ -11,31 +11,31 @@ jobs: fail-fast: false matrix: include: - - os: windows-latest - file_extension: ".exe" - file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test%20Setup%2099.0.${{ github.run_id }}-Test.exe" - build_arg: "--win --x64" - - os: macos-latest - arch: x86_64 - file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.dmg" - file_extension: ".dmg" - build_arg: "--mac --x64" + # - os: windows-latest + # file_extension: ".exe" + # file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test%20Setup%2099.0.${{ github.run_id }}-Test.exe" + # build_arg: "--win --x64" + # - os: macos-latest + # arch: x86_64 + # file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.dmg" + # file_extension: ".dmg" + # build_arg: "--mac --x64" - os: macos-latest arch: arm64 file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test-arm64.dmg" file_extension: ".dmg" - build_arg: "--mac --arm64" - - os: ubuntu-latest - file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.AppImage" - file_extension: ".AppImage" - build_arg: "--linux" + # build_arg: "--mac --arm64" + # - os: ubuntu-latest + # file_name: "https://oss.sqlgpt.cn/test/99.0.${{ github.run_id }}/Chat2DB-Test-99.0.${{ github.run_id }}-Test.AppImage" + # file_extension: ".AppImage" + # build_arg: "--linux" runs-on: ${{ matrix.os }} steps: - name: Check out git repository uses: actions/checkout@main - # 安装JRE + # Install JRE - name: Install JRE uses: actions/setup-java@main with: @@ -44,7 +44,7 @@ jobs: java-package: "jre" # architecture: ${{ matrix.arch == 'arm64' && 'aarch64' || 'x64' }} - # 开放TLS + # Open TLS - name: Enable TLS 1.0 and 1.1 in java.security run: | if [ "$RUNNER_OS" = "Windows" ]; then @@ -59,7 +59,7 @@ jobs: RUNNER_OS: ${{ runner.os }} JAVA_HOME: ${{ env.JAVA_HOME }} - # JRE拷贝到前端静态目录 + # Copy JRE to the front-end static directory - name: Copy JRE to static directory run: | mkdir -p chat2db-client/static @@ -71,7 +71,7 @@ jobs: env: JAVA_HOME: ${{ env.JAVA_HOME }} - # Linux中删除jre中相关文件 + # Delete related files in jre in Linux - if: ${{ runner.os == 'Linux' }} name: Delete File on Linux run: | @@ -80,7 +80,7 @@ jobs: rm -rf legal ls -la - # 安装Node.js + # Install Node.js - name: Install Node.js uses: actions/setup-node@main with: @@ -88,7 +88,7 @@ jobs: cache: "yarn" cache-dependency-path: chat2db-client/yarn.lock - # 安装Java + # Install Java - name: Install Java and Maven uses: actions/setup-java@main with: @@ -96,7 +96,7 @@ jobs: distribution: "temurin" cache: "maven" - # 打包Web前端资源 + # Packaging web front-end resources - name: Build FE Static run: | cd chat2db-client @@ -108,7 +108,7 @@ jobs: yarn yarn run build - # 打包后端工程 & 发送到前端 + # Package backend project & send to frontend - name: Build BE Static run: | mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml @@ -117,7 +117,7 @@ jobs: cp -r chat2db-client/version chat2db-client/versions/ cp chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-client/versions/99.0.${{ github.run_id }}/static/ - # 打包桌面端前端资源 + # Packaging desktop front-end resources - name: Prepare Build Electron run: | cd chat2db-client @@ -125,7 +125,7 @@ jobs: cp -r dist ./versions/99.0.${{ github.run_id }}/ rm -r dist - # 打包Electron + # Packing Electron - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 with: @@ -142,14 +142,14 @@ jobs: -c.extraMetadata.version=99.0.${{ github.run_id }}-Test ${{ matrix.build_arg}} - # 公证&签名 Mac App + # Notarization & Signature Mac App - name: Notarize MacOS x86_64 App if: matrix.os == 'macos-latest' && matrix.arch == 'x86_64' run: | xcrun notarytool store-credentials "Chat2DB" --apple-id "${{ secrets.MAC_APPLE_ID }}" --password "${{ secrets.MAC_APPLE_PASSWORD }}" --team-id "${{ secrets.MAC_TEAM_ID }}" xcrun notarytool submit chat2db-client/release/Chat2DB-Test-99.0.${{ github.run_id }}-Test.dmg --keychain-profile "Chat2DB" - # Build Jar包 + # Build Jar - name: Prepare upload for Jar if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }} run: | @@ -162,13 +162,13 @@ jobs: cd static/ && zip -r chat2db-server-start.zip ./ cp -r chat2db-server-start.zip ../../../../oss_temp_file - # 准备发往OSS的文件 + # Prepare files to be sent to OSS - name: Prepare upload for OSS run: | mkdir -p oss_temp_file cp -r chat2db-client/release/*${{ matrix.file_extension }} ./oss_temp_file - # 设置OSS + # Set up OSS - name: Set up oss utils uses: yizhoumo/setup-ossutil@v1 with: @@ -177,12 +177,12 @@ jobs: access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }} ossutil-version: "1.7.16" - # 上传到OSS + # Upload to OSS - name: Upload to OSS run: | ossutil cp -rf --acl=public-read ./oss_temp_file/ oss://chat2db-client/test/99.0.${{ github.run_id }}/ - # 发送到DingTalk + # Send to DingTalk - name: Send dingtalk message uses: ghostoy/dingtalk-action@master with: @@ -194,7 +194,7 @@ jobs: "text": "# ${{ matrix.os }}-test-打包完成通知\n ![bang](https://oss.sqlgpt.cn/static/bang100.gif)\n ### 任务id:[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }})\n ### 下载地址:[${{matrix.file_name}}](${{matrix.file_name}})" } - # 发送Jar包地址到DingTalk + # Send Jar address to DingTalk - if: ${{ runner.os == 'macOS' && matrix.arch == 'x86_64' }} name: Send dingtalk message uses: ghostoy/dingtalk-action@master diff --git a/CHAT2DB_AI_SQL.md b/CHAT2DB_AI_SQL.md index 8f5ce9ffa..840bdfb13 100644 --- a/CHAT2DB_AI_SQL.md +++ b/CHAT2DB_AI_SQL.md @@ -1,21 +1,21 @@ # Chat2DB AI SQL功能使用说明 Chat2DB包含一系列基于ChatGPT的AI SQL使用功能,主要包括自然语言转SQL、SQL解释、SQL优化和SQL转换。 使用这些AI功能,可以将自然语言转换成本地查询SQL,而不仅仅是SQL查询伪代码;可以将SQL解释成自然语言,帮助用户理解复杂的SQL;可以针对慢SQL提供全方位的优化建议,提升查询效率;可以转换不同数据库类型的SQL语言,降低数据库迁移难度等等。 ## 使用配置 -### 点击设置 +### 点击设置【UI旧】 ### 配置AI -#### 配置OPENAI +#### 配置OPENAI【UI旧】 使用OPENAI的ChatSql功能需要满足两个条件 - 配置OPENAI_API_KEY,如没有OPENAI_API_KEY可加入答疑群根据群公告指引获取chat2db自定义key - 客户端网络可以连接到OPENAI官网,如果本地VPN未能全局生效,可以通过在客户端中设置网络代理HOST和PORT来保证网络连通性 -#### 配置自定义AI +#### 配置自定义AI【UI旧】 - 自定义AI可以是用户自己部署的任意AI模型,例如ChatGLM、ChatGPT、文心一言、通义千问等等,但是自定义的接口输入和输出需要符合自定义的协议规范才可快速使用,否则可能需要二次开发。代码中提供了两个DEMO,只需要配置自定义AI接口地址,以及接口是否流式输出即可查看。具体使用中可以参考DEMO接口来编写自定义接口,或者直接在DEMO接口中进行二次开发,封装自己的自定义接口 - 自定义的流式输出接口配置DEMO - 自定义的非流式输出接口配置DEMO -## 自然语言转SQL +## 自然语言转SQL【UI旧】 ### 功能描述 输入自然语言,选中执行并传入查询相关的表结构信息,则会返回相应的SQL - 输入样例:查询学生小明的各科目成绩,并传入关联数据表course,score,student,student_course diff --git a/README.md b/README.md index 3c576a5de..3d854876c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Languages: English | [中文](README_CN.md) Official website:[Chat2DB](https://sqlgpt.cn/en)
- If you find Chat2DB helpful, please helpgithub starClick ⭐ Star and Fork in the top right corner, and your support is the biggest motivation for Chat2DB to get bette + If you find Chat2DB helpful, please helpgithub starClick ⭐ Star and Fork in the top right corner, and your support is the biggest motivation for Chat2DB to get better
@@ -108,7 +108,6 @@ Redis and MongoDB are partially supported , Hbase、Elasticsearch、openGauss、 ## 📦 Docker installation -```bash ```bash // Pull the latest client, then run Docker with the name 'chat2db', and mount 'root. chat2db' to '~. chat2db Docker'` docker run --name=chat2db -ti -p 10824:10824 -v ~/.chat2db-docker:/root/.chat2db chat2db/chat2db:latest @@ -119,7 +118,6 @@ Redis and MongoDB are partially supported , Hbase、Elasticsearch、openGauss、 // If you want to update chat2db, you need to first rm docker rm chat2db ``` -``` ## 🎯 Operating Environment @@ -180,11 +178,11 @@ $ npm run build:web:prod / cp -r dist ../chat2db-server/chat2db-server-start/src ### WeChat - + ### Discord -[![Discord](https://img.shields.io/badge/-Join%20us%20on%20Discord-%237289DA.svg?style=flat&logo=discord&logoColor=white)](https://discord.gg/N6JscF7q) +[![Discord](https://img.shields.io/badge/-Join%20us%20on%20Discord-%237289DA.svg?style=flat&logo=discord&logoColor=white)](https://discord.com/invite/Zn9dFQKSJa) ## LICENSE @@ -193,7 +191,7 @@ The primary license used by this software is the [Apache License 2.0](https://ww ## ❤️ Acknowledgements -Thanks to all the students who contributed to Chat2DB~ +Thanks to all the students who contributed to Chat2DB~~ diff --git a/README_CN.md b/README_CN.md index 57e2cf3b0..8dfd9b363 100644 --- a/README_CN.md +++ b/README_CN.md @@ -175,15 +175,15 @@ $ cp -r dist/index.html ../chat2db-server/chat2db-server-start/src/main/resource 下载链接 参考:Application jdbc-jar-downLoad-urls -- https://oss.sqlgpt.cn/lib/mysql-connector-java-8.0.30.jar -- https://oss.sqlgpt.cn/lib/mysql-connector-java-5.1.47.jar -- https://oss.sqlgpt.cn/lib/clickhouse-jdbc-0.3.2-patch8-http.jar -- https://oss.sqlgpt.cn/lib/mariadb-java-client-3.0.8.jar -- https://oss.sqlgpt.cn/lib/mssql-jdbc-11.2.1.jre17.jar -- https://oss.sqlgpt.cn/lib/oceanbase-client-2.4.2.jar -- https://oss.sqlgpt.cn/lib/postgresql-42.5.1.jar -- https://oss.sqlgpt.cn/lib/sqlite-jdbc-3.39.3.0.jar -- https://oss.sqlgpt.cn/lib/ojdbc11.jar +- https://cdn.chat2db-ai.com/lib/mysql-connector-java-8.0.30.jar +- https://cdn.chat2db-ai.com/lib/mysql-connector-java-5.1.47.jar +- https://cdn.chat2db-ai.com/lib/clickhouse-jdbc-0.3.2-patch8-http.jar +- https://cdn.chat2db-ai.com/lib/mariadb-java-client-3.0.8.jar +- https://cdn.chat2db-ai.com/lib/mssql-jdbc-11.2.1.jre17.jar +- https://cdn.chat2db-ai.com/lib/oceanbase-client-2.4.2.jar +- https://cdn.chat2db-ai.com/lib/postgresql-42.5.1.jar +- https://cdn.chat2db-ai.com/lib/sqlite-jdbc-3.39.3.0.jar +- https://cdn.chat2db-ai.com/lib/ojdbc11.jar ## Stargazers @@ -197,11 +197,11 @@ $ cp -r dist/index.html ../chat2db-server/chat2db-server-start/src/main/resource 加群前请先 Star 和 Fork,谢谢~关注微信公众号可加入微信、钉钉、QQ 群一起讨论,并可以获取 Chat2DB 最新动态和更新。 - + ## ❤️ 致谢 -感谢所有为 Chat2DB 贡献力量的同学们~ +感谢所有为 Chat2DB 贡献力量的同学们~~ diff --git a/chat2db-client/src/blocks/Tree/index.tsx b/chat2db-client/src/blocks/Tree/index.tsx index b26f0825e..ed0ffa756 100644 --- a/chat2db-client/src/blocks/Tree/index.tsx +++ b/chat2db-client/src/blocks/Tree/index.tsx @@ -9,7 +9,7 @@ import { treeConfig, switchIcon, ITreeConfigItem } from './treeConfig'; import { useCommonStore } from '@/store/common'; import { setCurrentWorkspaceGlobalExtend } from '@/pages/main/workspace/store/common'; import LoadingGracile from '@/components/Loading/LoadingGracile'; -import { setFocusId, useTreeStore } from './treeStore'; +import { setFocusId, setFocusTreeNode, useTreeStore, clearTreeStore } from './treeStore'; import { useGetRightClickMenu } from './hooks/useGetRightClickMenu'; import MenuLabel from '@/components/MenuLabel'; import LoadingContent from '@/components/Loading/LoadingContent'; @@ -124,6 +124,13 @@ const Tree = (props: IProps) => { const top = itemHeight * startIdx; // 第一个渲染的 item 到顶部距离 + // 清空treeStore + useEffect(() => { + return () => { + clearTreeStore(); + } + }, [searchValue]); + useEffect(() => { setTreeData(outerTreeData); setScrollTop(0); @@ -336,6 +343,14 @@ const TreeNode = memo((props: TreeNodeIProps) => { }); } setFocusId(treeNodeData.uuid || ''); + + setFocusTreeNode({ + dataSourceId: treeNodeData.extraParams!.dataSourceId, + dataSourceName: treeNodeData.extraParams!.dataSourceName, + databaseType: treeNodeData.extraParams!.databaseType, + databaseName: treeNodeData.extraParams?.databaseName, + schemaName: treeNodeData.extraParams?.schemaName, + }); }; // 双击节点 diff --git a/chat2db-client/src/blocks/Tree/treeStore.ts b/chat2db-client/src/blocks/Tree/treeStore.ts index 276b524a3..15c501eeb 100644 --- a/chat2db-client/src/blocks/Tree/treeStore.ts +++ b/chat2db-client/src/blocks/Tree/treeStore.ts @@ -6,10 +6,19 @@ import { devtools } from 'zustand/middleware'; export interface ITreeStore { focusId: number | string | null; + focusTreeNode: { + dataSourceId: number; + dataSourceName: string; + databaseType: string, + databaseName?: string; + schemaName?: string, + tableName?: string, + } | null; } const treeStore = { focusId: null, + focusTreeNode: null, } export const useTreeStore: UseBoundStore> = create( @@ -19,3 +28,12 @@ export const useTreeStore: UseBoundStore> = create( export const setFocusId = (focusId: ITreeStore['focusId']) => { useTreeStore.setState({ focusId }); } + +export const setFocusTreeNode = (focusTreeNode: ITreeStore['focusTreeNode']) => { + useTreeStore.setState({ focusTreeNode }); +} + +// 清除treeStore +export const clearTreeStore = () => { + useTreeStore.setState(treeStore); +} diff --git a/chat2db-client/src/components/ConnectionEdit/config/dataSource.ts b/chat2db-client/src/components/ConnectionEdit/config/dataSource.ts index 115aa9403..f14c86510 100644 --- a/chat2db-client/src/components/ConnectionEdit/config/dataSource.ts +++ b/chat2db-client/src/components/ConnectionEdit/config/dataSource.ts @@ -250,6 +250,10 @@ export const dataSourceFormConfigs: IConnectionConfig[] = [ { "key": "zeroDateTimeBehavior", "value": "convertToNull" + }, + { + "key": "useInformationSchema", + "value": "true" } ], type: DatabaseTypeCode.MYSQL, @@ -470,16 +474,16 @@ export const dataSourceFormConfigs: IConnectionConfig[] = [ labelTextAlign: 'right', selects: [ { - value: 'THIN', + value: 'thin', label: 'thin', }, { - value: 'OCI', + value: 'oci', label: 'oci', }, { - value: 'OCI8', + value: 'oci8', label: 'oci8', }, ], diff --git a/chat2db-client/src/components/Tabs/index.less b/chat2db-client/src/components/Tabs/index.less index e1caa348a..613864626 100644 --- a/chat2db-client/src/components/Tabs/index.less +++ b/chat2db-client/src/components/Tabs/index.less @@ -179,7 +179,7 @@ .input { border: 0; - width: 86px; + width: 200px; flex: 1; height: 20px; outline: none; diff --git a/chat2db-client/src/pages/demo/index.tsx b/chat2db-client/src/pages/demo/index.tsx index aceb18934..c341aac46 100644 --- a/chat2db-client/src/pages/demo/index.tsx +++ b/chat2db-client/src/pages/demo/index.tsx @@ -1,16 +1,27 @@ import React, { useEffect } from 'react'; -import OpenScreenAnimation from '@/components/OpenScreenAnimation'; +import sqlService from '@/service/sql'; function Test() { - // const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjIsImRldmljZSI6ImRlZmF1bHQtZGV2aWNlIiwiZWZmIjoxNzA2ODU0NTMwMDI3LCJyblN0ciI6Ik1RcHRPOUVBVlJlbGRQa1RFN01MZUpLeG5KTGVwRFpaIn0.knOw08E6mwWF_GpkeQ8KflQlfQuNu4jd-_Bgh7EnCj4' - // useEffect(() => { - // const socket = new WebSocket(`ws://127.0.0.1:10821/api/ws/${token}`); - // socket.onopen = () => { - // console.log('open'); - // socket.send('hello'); - // }; - // }, []); - return ; + const sql = "INSERT INTO `big_data_table` (`name1`,`name2`,`name3`,`name4`,`name5`,`name6`,`name7`,`name8`,`name9`,`name10`,`name11`,`name21`,`name31`,`name41`,`name51`,`name61`,`name71`,`name81`,`name91`,`name12`,`name22`,`name32`,`name42`,`name52`,`name62`,`name72`,`name82`,`name92`,`name13`,`name223`,`name323`,`name423`,`name523`,`name623`,`name723`,`name823`,`name923`) VALUES ('牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛','牛牛牛牛牛牛牛牛牛牛牛牛');"; + const sqls:any = []; + for (let i = 30; i < 1030; i++) { + sqls.push(sql) + } + const a = () =>{ + const executeSQLParams = { + sql: sqls.join(''), + dataSourceId:2, + databaseName: "e-commerc", + }; + // 获取当前SQL的查询结果 + return sqlService.executeSql(executeSQLParams).finally(()=>{ + a() + }); + } + useEffect(() => { + a() + },[]) + return 11111; } export default Test; diff --git a/chat2db-client/src/pages/login/index.tsx b/chat2db-client/src/pages/login/index.tsx index 8a4045262..7d5d5af32 100644 --- a/chat2db-client/src/pages/login/index.tsx +++ b/chat2db-client/src/pages/login/index.tsx @@ -38,9 +38,8 @@ const Login: React.FC = () => {
{i18n('login.text.welcome')}
+
{i18n('login.text.tips')}
} diff --git a/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx b/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx index 56cca69af..bf878431e 100644 --- a/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx +++ b/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx @@ -6,7 +6,6 @@ import { Button } from 'antd'; // ----- constants ----- import { WorkspaceTabType, workspaceTabConfig } from '@/constants'; import { IWorkspaceTab } from '@/typings'; -// import WorkspaceExtend from '../WorkspaceExtend'; // ----- components ----- import Tabs, { ITabItem } from '@/components/Tabs'; @@ -25,6 +24,7 @@ import { createConsole, } from '@/pages/main/workspace/store/console'; import { useWorkspaceStore } from '@/pages/main/workspace/store'; +import { useTreeStore } from '@/blocks/Tree/treeStore'; // ----- services ----- import historyService from '@/service/history'; @@ -83,12 +83,14 @@ const WorkspaceTabs = memo(() => { }; const createNewConsole = () => { + const { databaseName, schemaName } = useTreeStore.getState().focusTreeNode || {}; if (currentConnectionDetails) { createConsole({ dataSourceId: currentConnectionDetails.id, dataSourceName: currentConnectionDetails.alias, databaseType: currentConnectionDetails.type, - // databaseName: currentConnectionDetails.databaseName, + databaseName, + schemaName }); } }; diff --git a/chat2db-client/src/pages/main/workspace/store/console.ts b/chat2db-client/src/pages/main/workspace/store/console.ts index 82fc4b0ec..f82e3b90b 100644 --- a/chat2db-client/src/pages/main/workspace/store/console.ts +++ b/chat2db-client/src/pages/main/workspace/store/console.ts @@ -59,13 +59,13 @@ export const createConsole = (params: ICreateConsoleParams) => { const currentConnectionDetails = useWorkspaceStore.getState().currentConnectionDetails; const newConsole = { ...params, - name: params.name || 'new console', + name: params.name || `untitled-${params.databaseName || params.schemaName} (${params.dataSourceName})`, ddl: params.ddl || '', status: ConsoleStatus.DRAFT, operationType: params.operationType || WorkspaceTabType.CONSOLE, type: params.databaseType, supportDatabase: currentConnectionDetails?.supportDatabase, - supportSchema: currentConnectionDetails?.supportSchema + supportSchema: currentConnectionDetails?.supportSchema, }; return new Promise((resolve) => { diff --git a/chat2db-server/.apifox-helper.properties b/chat2db-server/.apifox-helper.properties index c8128de5b..07a16dd04 100644 --- a/chat2db-server/.apifox-helper.properties +++ b/chat2db-server/.apifox-helper.properties @@ -1,11 +1,11 @@ -# easy-yapi插件生成的配置 -# 日期转long +# Configuration generated by easy-yapi plug-in +# Convert date to long json.rule.convert[java.util.Date]=java.lang.Long json.rule.convert[java.sql.Timestamp]=java.lang.Long json.rule.convert[java.time.LocalDateTime]=java.lang.Long json.rule.convert[java.time.LocalDate]=java.lang.Long -# 使用version来 修改标签 +# Use version to modify tags api.tag=#version # ignore serialVersionUID diff --git a/chat2db-server/.easy.api.config b/chat2db-server/.easy.api.config index 85a243faa..24a508611 100644 --- a/chat2db-server/.easy.api.config +++ b/chat2db-server/.easy.api.config @@ -1,11 +1,11 @@ -# easy-yapi插件生成的配置 -# 日期转long +# Configuration generated by easy-yapi plug-in +# Convert date to long json.rule.convert[java.util.Date]=java.lang.Long json.rule.convert[java.sql.Timestamp]=java.lang.Long json.rule.convert[java.time.LocalDateTime]=java.lang.Long json.rule.convert[java.time.LocalDate]=java.lang.Long -# 使用version来 修改标签 +# Use version to modify tags api.tag=#version # ignore serialVersionUID diff --git a/chat2db-server/.gitignore b/chat2db-server/.gitignore index 7ccb39ad8..ba303e2d1 100644 --- a/chat2db-server/.gitignore +++ b/chat2db-server/.gitignore @@ -25,6 +25,6 @@ nbbuild/ dist/ nbdist/ -## 前端打包生成的代码 不用提交到github, +## The code generated by front-end packaging does not need to be submitted to github /chat2db-server-start/src/main/resources/static/front/ /chat2db-server-start/src/main/resources/thymeleaf/ diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/pom.xml b/chat2db-server/chat2db-plugins/chat2db-clickhouse/pom.xml index e3edd0f6d..f96cc9a82 100644 --- a/chat2db-server/chat2db-plugins/chat2db-clickhouse/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/pom.xml @@ -22,7 +22,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseDBManage.java b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseDBManage.java index c1478405a..75d782d2d 100644 --- a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseDBManage.java @@ -1,14 +1,59 @@ package ai.chat2db.plugin.clickhouse; -import java.sql.Connection; - import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; import ai.chat2db.spi.sql.ConnectInfo; import ai.chat2db.spi.sql.SQLExecutor; import org.apache.commons.lang3.StringUtils; +import java.sql.*; +import java.util.Objects; + public class ClickHouseDBManage extends DefaultDBManage implements DBManage { + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTablesOrViewsOrDictionaries(connection, sqlBuilder, databaseName, schemaName,containData); + exportFunctions(connection, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportFunctions(Connection connection, StringBuilder sqlBuilder) throws SQLException { + String sql ="SELECT name,create_query from system.functions where origin='SQLUserDefined'"; + try(ResultSet resultSet=connection.createStatement().executeQuery(sql)){ + while (resultSet.next()) { + sqlBuilder.append("DROP FUNCTION IF EXISTS ").append(resultSet.getString("name")).append(";") + .append("\n") + .append(resultSet.getString("create_query")).append(";").append("\n"); + } + } + } + + private void exportTablesOrViewsOrDictionaries(Connection connection, StringBuilder sqlBuilder, String databaseName, String schemaName, boolean containData) throws SQLException { + String sql =String.format("SELECT create_table_query, has_own_data,engine,name from system.`tables` WHERE `database`='%s'", databaseName); + try (Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(sql)) { + while (resultSet.next()) { + String ddl = resultSet.getString("create_table_query"); + boolean dataFlag = resultSet.getInt("has_own_data") == 1; + String tableType = resultSet.getString("engine"); + String tableOrViewName = resultSet.getString("name"); + if (Objects.equals("View", tableType)) { + sqlBuilder.append("DROP VIEW IF EXISTS ").append(databaseName).append(".").append(tableOrViewName) + .append(";").append("\n").append(ddl).append(";").append("\n"); + } else if (Objects.equals("Dictionary", tableType)) { + sqlBuilder.append("DROP DICTIONARY IF EXISTS ").append(databaseName).append(".").append(tableOrViewName) + .append(";").append("\n").append(ddl).append(";").append("\n"); + } else { + sqlBuilder.append("DROP TABLE IF EXISTS ").append(databaseName).append(".").append(tableOrViewName) + .append(";").append("\n").append(ddl).append(";").append("\n"); + if (containData && dataFlag) { + exportTableData(connection,schemaName, tableOrViewName, sqlBuilder); + } + } + } + } + } + @Override public Connection getConnection(ConnectInfo connectInfo) { @@ -29,10 +74,10 @@ private String setDatabaseInJdbcUrl(ConnectInfo connectInfo) { String[] addressSplit = url.split(connectAddress); String connectParams = addressSplit[1]; if (connectParams.startsWith("/")) { - // 删除连接参数中的 / + // Remove / from connection parameters connectParams = connectParams.substring(1); } - // 添加数据库名 + // Add database name return addressSplit[0] + connectAddress + "/" + databaseName + connectParams; } diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseMetaData.java b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseMetaData.java index 0d30804ce..45b9a157e 100644 --- a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/ClickHouseMetaData.java @@ -1,8 +1,311 @@ package ai.chat2db.plugin.clickhouse; +import ai.chat2db.plugin.clickhouse.builder.ClickHouseSqlBuilder; +import ai.chat2db.plugin.clickhouse.type.ClickHouseColumnTypeEnum; +import ai.chat2db.plugin.clickhouse.type.ClickHouseEngineTypeEnum; +import ai.chat2db.plugin.clickhouse.type.ClickHouseIndexTypeEnum; import ai.chat2db.spi.MetaData; +import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.jdbc.DefaultMetaService; +import ai.chat2db.spi.model.*; +import ai.chat2db.spi.sql.SQLExecutor; +import jakarta.validation.constraints.NotEmpty; +import org.apache.commons.lang3.StringUtils; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.stream.Collectors; + +import static ai.chat2db.spi.util.SortUtils.sortDatabase; public class ClickHouseMetaData extends DefaultMetaService implements MetaData { + + private static String ROUTINES_SQL + = + "SELECT SPECIFIC_NAME, ROUTINE_COMMENT, ROUTINE_DEFINITION FROM information_schema.routines WHERE " + + "routine_type = '%s' AND ROUTINE_SCHEMA ='%s' AND " + + "routine_name = '%s';"; + private static String TRIGGER_SQL + = "SELECT TRIGGER_NAME,EVENT_MANIPULATION, ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS where " + + "TRIGGER_SCHEMA = '%s' AND TRIGGER_NAME = '%s';"; + private static String TRIGGER_SQL_LIST + = "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS where TRIGGER_SCHEMA = '%s';"; + private static String SELECT_TABLE_COLUMNS = "select * from `system`.columns where table ='%s' and database='%s';"; + private static String VIEW_SQL + = "SELECT create_table_query from system.`tables` WHERE `database`='%s' and name='%s'"; + private List systemDatabases = Arrays.asList("information_schema", "system"); + public static final String FUNCTION_SQL = "SELECT name,create_query as ddl from system.functions where origin='SQLUserDefined'"; + + public static String format(String tableName) { + return "`" + tableName + "`"; + } + + @Override + public List functions(Connection connection, String databaseName, String schemaName) { + return SQLExecutor.getInstance().execute(connection, FUNCTION_SQL, resultSet -> { + List functions = new ArrayList<>(); + while (resultSet.next()) { + Function function = new Function(); + function.setFunctionName(resultSet.getString("name")); + functions.add(function); + } + return functions; + }); + } + + @Override + public List databases(Connection connection) { + List list = SQLExecutor.getInstance().execute(connection, "SELECT name FROM system.databases;;", resultSet -> { + List databases = new ArrayList<>(); + try { + while (resultSet.next()) { + String dbName = resultSet.getString("name"); + Database database = new Database(); + database.setName(dbName); + databases.add(database); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + return databases; + }); + return sortDatabase(list, systemDatabases, connection); + } + + @Override + public String tableDDL(Connection connection, @NotEmpty String databaseName, String schemaName, + @NotEmpty String tableName) { + String sql = "SHOW CREATE TABLE " + format(databaseName) + "." + + format(tableName); + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + if (resultSet.next()) { + return resultSet.getString("Create Table"); + } + return null; + }); + } + + @Override + public Function function(Connection connection, @NotEmpty String databaseName, String schemaName, + String functionName) { + return SQLExecutor.getInstance().execute(connection, FUNCTION_SQL, resultSet -> { + Function function = new Function(); + function.setDatabaseName(databaseName); + function.setSchemaName(schemaName); + function.setFunctionName(functionName); + if (resultSet.next()) { +/* function.setSpecificName(resultSet.getString("SPECIFIC_NAME")); + function.setRemarks(resultSet.getString("ROUTINE_COMMENT"));*/ + function.setFunctionBody(resultSet.getString("ddl")); + } + return function; + }); + + } + + @Override + public List triggers(Connection connection, String databaseName, String schemaName) { + List triggers = new ArrayList<>(); + String sql = String.format(TRIGGER_SQL_LIST, databaseName); + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + while (resultSet.next()) { + Trigger trigger = new Trigger(); + trigger.setTriggerName(resultSet.getString("TRIGGER_NAME")); + trigger.setSchemaName(schemaName); + trigger.setDatabaseName(databaseName); + triggers.add(trigger); + } + return triggers; + }); + } + + @Override + public Trigger trigger(Connection connection, @NotEmpty String databaseName, String schemaName, + String triggerName) { + + String sql = String.format(TRIGGER_SQL, databaseName, triggerName); + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + Trigger trigger = new Trigger(); + trigger.setDatabaseName(databaseName); + trigger.setSchemaName(schemaName); + trigger.setTriggerName(triggerName); + if (resultSet.next()) { + trigger.setTriggerBody(resultSet.getString("ACTION_STATEMENT")); + } + return trigger; + }); + } + + @Override + public Procedure procedure(Connection connection, @NotEmpty String databaseName, String schemaName, + String procedureName) { + String sql = String.format(ROUTINES_SQL, "PROCEDURE", databaseName, procedureName); + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + Procedure procedure = new Procedure(); + procedure.setDatabaseName(databaseName); + procedure.setSchemaName(schemaName); + procedure.setProcedureName(procedureName); + if (resultSet.next()) { + procedure.setSpecificName(resultSet.getString("SPECIFIC_NAME")); + procedure.setRemarks(resultSet.getString("ROUTINE_COMMENT")); + procedure.setProcedureBody(resultSet.getString("ROUTINE_DEFINITION")); + } + return procedure; + }); + } + + @Override + public List columns(Connection connection, String databaseName, String schemaName, String tableName) { + String sql = String.format(SELECT_TABLE_COLUMNS, tableName, databaseName); + List tableColumns = new ArrayList<>(); + + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + while (resultSet.next()) { + TableColumn column = new TableColumn(); + column.setDatabaseName(databaseName); + column.setTableName(tableName); + column.setOldName(resultSet.getString("name")); + column.setName(resultSet.getString("name")); + String dataType = resultSet.getString("type"); + if (dataType.startsWith("Nullable(")) { + dataType = dataType.substring(9, dataType.length() - 1); + column.setNullable(1); + } + column.setColumnType(dataType); + column.setDefaultValue(resultSet.getString("default_expression")); +// column.setAutoIncrement(resultSet.getString("EXTRA").contains("auto_increment")); + column.setComment(resultSet.getString("comment")); + column.setOrdinalPosition(resultSet.getInt("position")); + column.setDecimalDigits(resultSet.getInt("numeric_scale")); + /*column.setCharSetName(resultSet.getString("CHARACTER_SET_NAME")); + column.setCollationName(resultSet.getString("COLLATION_NAME"));*/ + setColumnSize(column, dataType); + tableColumns.add(column); + } + return tableColumns; + }); + } + + private void setColumnSize(TableColumn column, String columnType) { + try { + if (columnType.contains("(")) { + String size = columnType.substring(columnType.indexOf("(") + 1, columnType.indexOf(")")); + if ("SET".equalsIgnoreCase(column.getColumnType()) || "ENUM".equalsIgnoreCase(column.getColumnType())) { + column.setValue(size); + } else { + if (size.contains(",")) { + String[] sizes = size.split(","); + if (StringUtils.isNotBlank(sizes[0])) { + column.setColumnSize(Integer.parseInt(sizes[0])); + } + if (StringUtils.isNotBlank(sizes[1])) { + column.setDecimalDigits(Integer.parseInt(sizes[1])); + } + } else { + column.setColumnSize(Integer.parseInt(size)); + } + } + } + } catch (Exception e) { + } + } + + @Override + public Table view(Connection connection, String databaseName, String schemaName, String viewName) { + String sql = String.format(VIEW_SQL, databaseName, viewName); + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + Table table = new Table(); + table.setDatabaseName(databaseName); + table.setSchemaName(schemaName); + table.setName(viewName); + if (resultSet.next()) { + table.setDdl(resultSet.getString(1)); + } + return table; + }); + } + + + @Override + public List indexes(Connection connection, String databaseName, String schemaName, String tableName) { + StringBuilder queryBuf = new StringBuilder("SHOW INDEX FROM "); + queryBuf.append("`").append(tableName).append("`"); + queryBuf.append(" FROM "); + queryBuf.append("`").append(databaseName).append("`"); + return SQLExecutor.getInstance().execute(connection, queryBuf.toString(), resultSet -> { + LinkedHashMap map = new LinkedHashMap(); + while (resultSet.next()) { + String keyName = resultSet.getString("Key_name"); + + TableIndex index = new TableIndex(); + index.setDatabaseName(databaseName); + index.setSchemaName(schemaName); + index.setTableName(tableName); + index.setName(keyName); + index.setUnique(!resultSet.getBoolean("Non_unique")); + index.setType(resultSet.getString("Index_type")); +// index.setComment(resultSet.getString("Index_comment")); + List tableIndexColumns = new ArrayList<>(); + tableIndexColumns.addAll(getTableIndexColumn(resultSet)); + index.setColumnList(tableIndexColumns); + if ("PRIMARY".equalsIgnoreCase(keyName)) { + index.setType(ClickHouseIndexTypeEnum.PRIMARY.getName()); + } + map.put(keyName, index); + } + return map.values().stream().collect(Collectors.toList()); + }); + + } + + private List getTableIndexColumn(ResultSet resultSet) throws SQLException { + List tableIndexColumns = new ArrayList<>(); + String name = StringUtils.isBlank(resultSet.getString("column_name")) ? resultSet.getString("expression") : resultSet.getString("column_name"); + if (StringUtils.isNotBlank(name)) { + String[] split = name.split(","); + for (String columName : split) { + TableIndexColumn tableIndexColumn = new TableIndexColumn(); + tableIndexColumn.setColumnName(columName); + tableIndexColumn.setOrdinalPosition(resultSet.getShort("seq_in_index")); + tableIndexColumn.setCollation(resultSet.getString("collation")); + tableIndexColumn.setCardinality(resultSet.getLong("cardinality")); + tableIndexColumn.setSubPart(resultSet.getLong("sub_part")); + tableIndexColumns.add(tableIndexColumn); + } + } + return tableIndexColumns; + } + + @Override + public SqlBuilder getSqlBuilder() { + return new ClickHouseSqlBuilder(); + } + + @Override + public TableMeta getTableMeta(String databaseName, String schemaName, String tableName) { + return TableMeta.builder() + .columnTypes(ClickHouseColumnTypeEnum.getTypes()) + .engineTypes(ClickHouseEngineTypeEnum.getTypes()) + .indexTypes(ClickHouseIndexTypeEnum.getIndexTypes()) + .build(); + } + + @Override + public String getMetaDataName(String... names) { + return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "`" + name + "`").collect(Collectors.joining(".")); + } + + + @Override + public List getSystemDatabases() { + return systemDatabases; + } + + } diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/builder/ClickHouseSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/builder/ClickHouseSqlBuilder.java new file mode 100644 index 000000000..f093c198a --- /dev/null +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/builder/ClickHouseSqlBuilder.java @@ -0,0 +1,137 @@ +package ai.chat2db.plugin.clickhouse.builder; + +import ai.chat2db.plugin.clickhouse.type.ClickHouseColumnTypeEnum; +import ai.chat2db.plugin.clickhouse.type.ClickHouseIndexTypeEnum; +import ai.chat2db.spi.SqlBuilder; +import ai.chat2db.spi.jdbc.DefaultSqlBuilder; +import ai.chat2db.spi.model.Database; +import ai.chat2db.spi.model.Table; +import ai.chat2db.spi.model.TableColumn; +import ai.chat2db.spi.model.TableIndex; +import org.apache.commons.lang3.StringUtils; + + +public class ClickHouseSqlBuilder extends DefaultSqlBuilder { + @Override + public String buildCreateTableSql(Table table) { + StringBuilder script = new StringBuilder(); + script.append("CREATE TABLE "); + if (StringUtils.isNotBlank(table.getDatabaseName())) { + script.append("`").append(table.getDatabaseName()).append("`").append("."); + } + script.append("`").append(table.getName()).append("`").append(" (").append("\n"); + + // append column + for (TableColumn column : table.getColumnList()) { + if (StringUtils.isBlank(column.getName()) || StringUtils.isBlank(column.getColumnType())) { + continue; + } + ClickHouseColumnTypeEnum typeEnum = ClickHouseColumnTypeEnum.getByType(column.getColumnType()); + script.append("\t").append(typeEnum.buildCreateColumnSql(column)).append(",\n"); + } + + // append index + for (TableIndex tableIndex : table.getIndexList()) { + if (StringUtils.isBlank(tableIndex.getName()) || StringUtils.isBlank(tableIndex.getType())) { + continue; + } + ClickHouseIndexTypeEnum mysqlIndexTypeEnum = ClickHouseIndexTypeEnum.getByType(tableIndex.getType()); + if (!ClickHouseIndexTypeEnum.PRIMARY.equals(mysqlIndexTypeEnum) ) { + script.append("\t").append("").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append(",\n"); + } + } + + script = new StringBuilder(script.substring(0, script.length() - 2)); + script.append("\n)"); + + + if (StringUtils.isNotBlank(table.getEngine())) { + script.append(" ENGINE=").append(table.getEngine()).append("\n"); + } + // append primary key + for (TableIndex tableIndex : table.getIndexList()) { + if (StringUtils.isBlank(tableIndex.getName()) || StringUtils.isBlank(tableIndex.getType())) { + continue; + } + ClickHouseIndexTypeEnum mysqlIndexTypeEnum = ClickHouseIndexTypeEnum.getByType(tableIndex.getType()); + if (ClickHouseIndexTypeEnum.PRIMARY.equals(mysqlIndexTypeEnum) ) { + script.append("\t").append("").append(mysqlIndexTypeEnum.buildIndexScript(tableIndex)).append("\n"); + } + } + + if (StringUtils.isNotBlank(table.getComment())) { + script.append(" COMMENT '").append(table.getComment()).append("'"); + } + + script.append(";"); + + return script.toString(); + } + + @Override + public String buildModifyTaleSql(Table oldTable, Table newTable) { + StringBuilder script = new StringBuilder(); + script.append("ALTER TABLE "); + if (StringUtils.isNotBlank(oldTable.getDatabaseName())) { + script.append("`").append(oldTable.getDatabaseName()).append("`").append("."); + } + script.append("`").append(oldTable.getName()).append("`").append("\n"); + + if (!StringUtils.equalsIgnoreCase(oldTable.getComment(), newTable.getComment())) { + script.append("\t").append("MODIFY COMMENT").append("'").append(newTable.getComment()).append("'").append(",\n"); + } + + // append modify column + for (TableColumn tableColumn : newTable.getColumnList()) { + if (StringUtils.isNotBlank(tableColumn.getEditStatus()) && StringUtils.isNotBlank(tableColumn.getColumnType()) && StringUtils.isNotBlank(tableColumn.getName())) { + ClickHouseColumnTypeEnum typeEnum = ClickHouseColumnTypeEnum.getByType(tableColumn.getColumnType()); + script.append("\t").append(typeEnum.buildModifyColumn(tableColumn)).append(",\n"); + } + } + + // append modify index + for (TableIndex tableIndex : newTable.getIndexList()) { + if (StringUtils.isNotBlank(tableIndex.getEditStatus()) && StringUtils.isNotBlank(tableIndex.getType())) { + ClickHouseIndexTypeEnum mysqlIndexTypeEnum = ClickHouseIndexTypeEnum + .getByType(tableIndex.getType()); + script.append("\t").append(mysqlIndexTypeEnum.buildModifyIndex(tableIndex)).append(",\n"); + } + } + + if (script.length() > 2) { + script = new StringBuilder(script.substring(0, script.length() - 2)); + script.append(";"); + } + + return script.toString(); + } + + + @Override + public String pageLimit(String sql, int offset, int pageNo, int pageSize) { + StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14); + sqlBuilder.append(sql); + if (offset == 0) { + sqlBuilder.append("\n LIMIT "); + sqlBuilder.append(pageSize); + } else { + sqlBuilder.append("\n LIMIT "); + sqlBuilder.append(offset); + sqlBuilder.append(","); + sqlBuilder.append(pageSize); + } + return sqlBuilder.toString(); + } + + + @Override + public String buildCreateDatabaseSql(Database database) { + StringBuilder sqlBuilder = new StringBuilder(); + sqlBuilder.append("CREATE DATABASE `" + database.getName() + "`"); + if(StringUtils.isNotBlank(database.getComment())){ + sqlBuilder.append(";ALTER DATABASE ").append(database.getName()).append(" COMMENT '").append(database.getComment()).append("';"); + } + return sqlBuilder.toString(); + } + +} diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/clickhouse.json b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/clickhouse.json index c99541f5f..ab285fdc9 100644 --- a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/clickhouse.json +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/clickhouse.json @@ -1,14 +1,14 @@ { "dbType": "CLICKHOUSE", - "supportDatabase": false, - "supportSchema": true, + "supportDatabase": true, + "supportSchema":false, "driverConfigList": [ { "url": "jdbc:clickhouse://localhost:8123/", "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/clickhouse-jdbc-0.3.2-patch8-http.jar" + "https://cdn.chat2db-ai.com/lib/clickhouse-jdbc-0.3.2-patch8-http.jar" ], "jdbcDriver": "clickhouse-jdbc-0.3.2-patch8-http.jar", "jdbcDriverClass": "com.clickhouse.jdbc.ClickHouseDriver" diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseColumnTypeEnum.java b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseColumnTypeEnum.java new file mode 100644 index 000000000..d53c90cc7 --- /dev/null +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseColumnTypeEnum.java @@ -0,0 +1,221 @@ +package ai.chat2db.plugin.clickhouse.type; + +import ai.chat2db.spi.ColumnBuilder; +import ai.chat2db.spi.enums.EditStatus; +import ai.chat2db.spi.model.ColumnType; +import ai.chat2db.spi.model.TableColumn; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public enum ClickHouseColumnTypeEnum implements ColumnBuilder { + + String("String", false, false, true, false, false, false, true, true, false, false), + Int8("Int8", false, false, true, false, false, false, true, true, false, false), + Int16("Int16", false, false, true, false, false, false, true, true, false, false), + Int32("Int32", false, false, true, false, false, false, true, true, false, false), + Int64("Int64", false, false, true, false, false, false, true, true, false, false), + Int128("Int128", false, false, true, false, false, false, true, true, false, false), + Int256("Int256", false, false, true, false, false, false, true, true, false, false), + UInt8("UInt8", false, false, true, false, false, false, true, true, false, false), + UInt16("UInt16", false, false, true, false, false, false, true, true, false, false), + UInt32("UInt32", false, false, true, false, false, false, true, true, false, false), + UInt64("UInt64", false, false, true, false, false, false, true, true, false, false), + UInt128("UInt128", false, false, true, false, false, false, true, true, false, false), + UInt256("UInt256", false, false, true, false, false, false, true, true, false, false), + Float32("Float32", false, false, true, false, false, false, true, true, false, false), + Float64("Float64", false, false, true, false, false, false, true, true, false, false), + Decimal("Decimal", true, true, true, false, false, false, true, true, false, false), + Boolean("Boolean", false, false, true, false, false, false, true, true, false, false), + FixedString("FixedString", false, false, true, false, false, false, true, true, false, false), + UUID("UUID", false, false, true, false, false, false, true, true, false, false), + Date("Date", false, false, true, false, false, false, true, true, false, false), + DATE32("DATE32", false, false, true, false, false, false, true, true, false, false), + DateTime("DateTime", false, false, true, false, false, false, true, true, false, false), + DateTime64("DateTime64", false, false, true, false, false, false, true, true, false, false), + Enum8("Enum8", false, false, true, false, false, false, true, true, false, false), + Enum16("Enum16", false, false, true, false, false, false, true, true, false, false), + Array("Array", false, false, false, false, false, false, true, true, false, false), + JSON("JSON", false, false, true, false, false, false, true, true, false, false), + Nested("Nested", false, false, true, false, false, false, true, true, false, false), + Map("Map", true, true, true, false, false, false, true, true, false, false), + IPv4("IPv4", false, false, true, false, false, false, true, true, false, false), + IPv6("IPv6", false, false, true, false, false, false, true, true, false, false), + Point("Point", false, false, true, false, false, false, true, true, false, false), + Ring("Ring", false, false, true, false, false, false, true, true, false, false), + Polygon("Polygon", false, false, true, false, false, false, true, true, false, false), + MultiPolygon("MultiPolygon", false, false, true, false, false, false, true, true, false, false), + AggregateFunction("AggregateFunction", true, true, true, false, false, false, true, true, false, false), + SimpleAggregateFunction("SimpleAggregateFunction", true, true, true, false, false, false, true, true, false, false), + ; + private static Map COLUMN_TYPE_MAP = Maps.newHashMap(); + + static { + for (ClickHouseColumnTypeEnum value : ClickHouseColumnTypeEnum.values()) { + COLUMN_TYPE_MAP.put(value.getColumnType().getTypeName(), value); + } + } + + private ColumnType columnType; + + + ClickHouseColumnTypeEnum(String dataTypeName, boolean supportLength, boolean supportScale, boolean supportNullable, boolean supportAutoIncrement, boolean supportCharset, boolean supportCollation, boolean supportComments, boolean supportDefaultValue, boolean supportExtent, boolean supportValue) { + this.columnType = new ColumnType(dataTypeName, supportLength, supportScale, supportNullable, supportAutoIncrement, supportCharset, supportCollation, supportComments, supportDefaultValue, supportExtent, supportValue, false); + } + + public static ClickHouseColumnTypeEnum getByType(String dataType) { + return COLUMN_TYPE_MAP.get(dataType); + } + + public static List getTypes() { + return Arrays.stream(ClickHouseColumnTypeEnum.values()).map(columnTypeEnum -> + columnTypeEnum.getColumnType() + ).toList(); + } + + public ColumnType getColumnType() { + return columnType; + } + + @Override + public String buildCreateColumnSql(TableColumn column) { + ClickHouseColumnTypeEnum type = COLUMN_TYPE_MAP.get(column.getColumnType()); + if (type == null) { + return ""; + } + StringBuilder script = new StringBuilder(); + + script.append("`").append(column.getName()).append("`").append(" "); + + script.append(buildNullableAndDataType(column, type)).append(" "); + + script.append(buildDefaultValue(column, type)).append(" "); + + script.append(buildComment(column, type)).append(" "); + + return script.toString(); + } + + @Override + public String buildModifyColumn(TableColumn tableColumn) { + + if (EditStatus.DELETE.name().equals(tableColumn.getEditStatus())) { + return StringUtils.join("DROP COLUMN `", tableColumn.getName() + "`"); + } + if (EditStatus.ADD.name().equals(tableColumn.getEditStatus())) { + return StringUtils.join("ADD COLUMN ", buildCreateColumnSql(tableColumn)); + } + if (EditStatus.MODIFY.name().equals(tableColumn.getEditStatus())) { + String modifyColumn = ""; + if (!StringUtils.equalsIgnoreCase(tableColumn.getOldName(), tableColumn.getName())) { + modifyColumn = StringUtils.join("RENAME COLUMN `", tableColumn.getOldName(), "` TO `", tableColumn.getName(), + "`, ", buildCreateColumnSql(tableColumn)); + } + return StringUtils.join(modifyColumn, "MODIFY COLUMN ", buildCreateColumnSql(tableColumn)); + } + return ""; + } + + private String buildComment(TableColumn column, ClickHouseColumnTypeEnum type) { + if (!type.columnType.isSupportComments() || StringUtils.isEmpty(column.getComment())) { + return ""; + } + return StringUtils.join("COMMENT '", column.getComment(), "'"); + } + + private String buildDefaultValue(TableColumn column, ClickHouseColumnTypeEnum type) { + if (!type.getColumnType().isSupportDefaultValue() || StringUtils.isEmpty(column.getDefaultValue())) { + return ""; + } + + if ("EMPTY_STRING".equalsIgnoreCase(column.getDefaultValue().trim())) { + return StringUtils.join("DEFAULT ''"); + } + + if ("NULL".equalsIgnoreCase(column.getDefaultValue().trim())) { + return StringUtils.join("DEFAULT NULL"); + } + + if (Arrays.asList(Enum8,Enum16).contains(type)) { + return StringUtils.join("DEFAULT '", column.getDefaultValue(), "'"); + } + + if (Arrays.asList(Date).contains(type)) { + return StringUtils.join("DEFAULT '", column.getDefaultValue(), "'"); + } + + if (Arrays.asList(DateTime).contains(type)) { + if ("CURRENT_TIMESTAMP".equalsIgnoreCase(column.getDefaultValue().trim())) { + return StringUtils.join("DEFAULT ", column.getDefaultValue()); + } + return StringUtils.join("DEFAULT '", column.getDefaultValue(), "'"); + } + + return StringUtils.join("DEFAULT ", column.getDefaultValue()); + } + + private String buildNullableAndDataType(TableColumn column, ClickHouseColumnTypeEnum type) { + StringBuilder script = new StringBuilder(); + script.append(buildDataType(column, type)); + + if (!type.getColumnType().isSupportNullable()) { + return script.toString(); + } + if (column.getNullable() != null && 1 == column.getNullable()) { + return "Nullable("+script.append(")").toString(); + } else { + return script.toString(); + } + } + + private String buildDataType(TableColumn column, ClickHouseColumnTypeEnum type) { + String columnType = type.columnType.getTypeName(); + if (Arrays.asList(FixedString).contains(type)) { + return StringUtils.join(columnType, "(", column.getColumnSize(), ")"); + } + + + if (Arrays.asList(Decimal).contains(type)) { + if (column.getColumnSize() == null || column.getDecimalDigits() == null) { + return columnType; + } + if (column.getColumnSize() != null && column.getDecimalDigits() == null) { + return StringUtils.join(columnType, "(", column.getColumnSize() + ")"); + } + if (column.getColumnSize() != null && column.getDecimalDigits() != null) { + return StringUtils.join(columnType, "(", column.getColumnSize() + "," + column.getDecimalDigits() + ")"); + } + } + + return columnType; + + + } + + public String buildColumn(TableColumn column) { + ClickHouseColumnTypeEnum type = COLUMN_TYPE_MAP.get(column.getColumnType()); + if (type == null) { + return ""; + } + StringBuilder script = new StringBuilder(); + + script.append("`").append(column.getName()).append("`").append(" "); + script.append(buildDataType(column, type)).append(" "); + if (StringUtils.isNoneBlank(column.getComment())) { + script.append("COMMENT").append(" ").append("'").append(column.getComment()).append("'").append(" "); + } + return script.toString(); + } + + private String unsignedDataType(String dataTypeName, String middle) { + String[] split = dataTypeName.split(" "); + if (split.length == 2) { + return StringUtils.join(split[0], middle, split[1]); + } + return StringUtils.join(dataTypeName, middle); + } + +} diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseEngineTypeEnum.java b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseEngineTypeEnum.java new file mode 100644 index 000000000..902b2154d --- /dev/null +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseEngineTypeEnum.java @@ -0,0 +1,101 @@ +package ai.chat2db.plugin.clickhouse.type; + +import ai.chat2db.spi.model.EngineType; +import com.google.common.collect.Maps; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public enum ClickHouseEngineTypeEnum { + AzureBlobStorage("AzureBlobStorage",false,true,false,false,true,false,false,false ), + KeeperMap("KeeperMap",false,true,false,false,false,true,false,false ), + SQLite("SQLite",false,false,false,false,false,false,false,false ), + ExternalDistributed("ExternalDistributed",false,false,false,false,false,false,false,false ), + PostgreSQL("PostgreSQL",false,false,false,false,false,false,false,false ), + NATS("NATS",false,false,false,false,true,false,false,false ), + RabbitMQ("RabbitMQ",false,false,false,false,true,false,false,false ), + Kafka("Kafka",false,false,false,false,true,false,false,false ), + MongoDB("MongoDB",false,false,false,false,false,false,false,false ), + FileLog("FileLog",false,false,false,false,true,false,false,false ), + Dictionary("Dictionary",false,false,false,false,false,false,false,false ), + MySQL("MySQL",false,false,false,false,true,false,false,false ), + S3Queue("S3Queue",false,false,false,false,true,false,false,false ), + HDFS("HDFS",false,true,false,false,false,false,false,false ), + MaterializedPostgreSQL("MaterializedPostgreSQL",false,true,false,false,true,false,false,false ), + S3("S3",false,true,false,false,true,false,false,false ), + FuzzJSON("FuzzJSON",false,false,false,false,false,false,false,false ), + OSS("OSS",false,true,false,false,true,false,false,false ), + WindowView("WindowView",false,false,false,false,false,false,false,false ), + Distributed("Distributed",false,false,false,false,true,true,false,false ), + ReplicatedSummingMergeTree("ReplicatedSummingMergeTree",true,true,true,true,true,true,true,true ), + ExecutablePool("ExecutablePool",false,false,false,false,true,false,false,false ), + COSN("COSN",false,true,false,false,true,false,false,false ), + Iceberg("Iceberg",false,false,false,false,false,false,false,false ), + MaterializedView("MaterializedView",false,false,false,false,false,false,false,false ), + View("View",false,false,false,false,false,false,false,false ), + JDBC("JDBC",false,false,false,false,false,false,false,false ), + Join("Join",false,false,false,false,true,false,false,false ), + Executable("Executable",false,false,false,false,true,false,false,false ), + Set("Set",false,false,false,false,true,false,false,false ), + Redis("Redis",false,true,false,false,false,true,false,false ), + GenerateRandom("GenerateRandom",false,false,false,false,false,false,false,false ), + LiveView("LiveView",false,false,false,false,false,false,false,false ), + MergeTree("MergeTree",true,true,true,false,true,true,true,false ), + ReplicatedReplacingMergeTree("ReplicatedReplacingMergeTree",true,true,true,true,true,true,true,true ), + Memory("Memory",false,false,false,false,true,true,false,false ), + Buffer("Buffer",false,false,false,false,false,true,false,false ), + URL("URL",false,false,false,false,true,false,false,false ), + ReplicatedVersionedCollapsingMergeTree("ReplicatedVersionedCollapsingMergeTree",true,true,true,true,true,true,true,true ), + VersionedCollapsingMergeTree("VersionedCollapsingMergeTree",true,true,true,false,true,true,true,false ), + Hive("Hive",false,true,false,false,true,false,false,false ), + ReplacingMergeTree("ReplacingMergeTree",true,true,true,false,true,true,true,false ), + ReplicatedAggregatingMergeTree("ReplicatedAggregatingMergeTree",true,true,true,true,true,true,true,true ), + ReplicatedMergeTree("ReplicatedMergeTree",true,true,true,true,true,true,true,true ), + DeltaLake("DeltaLake",false,false,false,false,false,false,false,false ), + EmbeddedRocksDB("EmbeddedRocksDB",true,true,false,false,false,true,false,false ), + ReplicatedCollapsingMergeTree("ReplicatedCollapsingMergeTree",true,true,true,true,true,true,true,true ), + File("File",false,false,false,false,true,false,false,false ), + TinyLog("TinyLog",false,false,false,false,true,false,false,false ), + ReplicatedGraphiteMergeTree("ReplicatedGraphiteMergeTree",true,true,true,true,true,true,true,true ), + SummingMergeTree("SummingMergeTree",true,true,true,false,true,true,true,false ), + Hudi("Hudi",false,false,false,false,false,false,false,false ), + GraphiteMergeTree("GraphiteMergeTree",true,true,true,false,true,true,true,false ), + CollapsingMergeTree("CollapsingMergeTree",true,true,true,false,true,true,true,false ), + Merge("Merge",false,false,false,false,false,false,false,false ), + AggregatingMergeTree("AggregatingMergeTree",true,true,true,false,true,true,true,false ), + ODBC("ODBC",false,false,false,false,false,false,false,false ), + Null("Null",false,false,false,false,false,true,false,false ), + StripeLog("StripeLog",false,false,false,false,true,false,false,false ), + Log("Log",false,false,false,false,true,false,false,false ), + + ; + private static Map ENGINE_TYPE_MAP = Maps.newHashMap(); + + static { + for (ClickHouseEngineTypeEnum value : ClickHouseEngineTypeEnum.values()) { + ENGINE_TYPE_MAP.put(value.getEngineType().getName(), value); + } + } + + private EngineType engineType; + + + ClickHouseEngineTypeEnum(String name, boolean supportTTL, boolean supportSortOrder, boolean supportSkippingIndices, boolean supportDeduplication, boolean supportSettings, boolean supportParallelInsert, boolean supportProjections, boolean supportReplication) { + this.engineType = new EngineType(name, supportTTL, supportSortOrder, supportSkippingIndices, supportDeduplication, supportSettings, supportParallelInsert, supportProjections, supportReplication); + } + + public static ClickHouseEngineTypeEnum getByType(String dataType) { + return ENGINE_TYPE_MAP.get(dataType.toUpperCase()); + } + + public static List getTypes() { + return Arrays.stream(ClickHouseEngineTypeEnum.values()).map(engineTypeEnum -> + engineTypeEnum.getEngineType() + ).toList(); + } + + public EngineType getEngineType() { + return engineType; + } +} diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseIndexTypeEnum.java b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseIndexTypeEnum.java new file mode 100644 index 000000000..7321ab462 --- /dev/null +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/type/ClickHouseIndexTypeEnum.java @@ -0,0 +1,123 @@ +package ai.chat2db.plugin.clickhouse.type; + +import ai.chat2db.spi.enums.EditStatus; +import ai.chat2db.spi.model.IndexType; +import ai.chat2db.spi.model.TableIndex; +import ai.chat2db.spi.model.TableIndexColumn; +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.List; + +public enum ClickHouseIndexTypeEnum { + + PRIMARY("Primary", "PRIMARY KEY"), + MINMAX("MINMAX", "INDEX"), + SET("SET", "INDEX"), + BLOOM_FILTER("BLOOM_FILTER", "INDEX"), + TOKENBF_V1("TOKENBF_V1", "INDEX"), + NGRAMBF_V1("NGRAMBF_V1", "INDEX"), + INVERTED("INVERTED", "INDEX"), + HYPOTHESIS("HYPOTHESIS", "INDEX"), + ANNOY("ANNOY", "INDEX"), + USEARCH("USEARCH", "INDEX"), + + ; + + private String name; + private String keyword; + private IndexType indexType; + + ClickHouseIndexTypeEnum(String name, String keyword) { + this.name = name; + this.keyword = keyword; + this.indexType = new IndexType(name); + } + + public static ClickHouseIndexTypeEnum getByType(String type) { + for (ClickHouseIndexTypeEnum value : ClickHouseIndexTypeEnum.values()) { + if (value.name.equalsIgnoreCase(type)) { + return value; + } + } + return null; + } + + public static List getIndexTypes() { + return Arrays.asList(ClickHouseIndexTypeEnum.values()).stream().map(ClickHouseIndexTypeEnum::getIndexType).collect(java.util.stream.Collectors.toList()); + } + + public String getName() { + return name; + } + + public String getKeyword() { + return keyword; + } + + public IndexType getIndexType() { + return indexType; + } + + public void setIndexType(IndexType indexType) { + this.indexType = indexType; + } + + public String buildIndexScript(TableIndex tableIndex) { + StringBuilder script = new StringBuilder(); + + script.append(keyword).append(" "); + script.append(buildIndexName(tableIndex)).append(" "); + script.append(buildIndexColumn(tableIndex)).append(" "); + script.append(buildIndexType(tableIndex)).append(" "); + return script.toString(); + } + + private String buildIndexType(TableIndex tableIndex) { + if (this.equals(PRIMARY)) { + return ""; + } else { + return "TYPE " + name ; + } + } + + private String buildIndexColumn(TableIndex tableIndex) { + StringBuilder script = new StringBuilder(); + script.append("("); + for (TableIndexColumn column : tableIndex.getColumnList()) { + if (StringUtils.isNotBlank(column.getColumnName())) { + script.append("`").append(column.getColumnName()).append("`"); + script.append(","); + } + } + script.deleteCharAt(script.length() - 1); + script.append(")"); + return script.toString(); + } + + private String buildIndexName(TableIndex tableIndex) { + if (this.equals(PRIMARY)) { + return ""; + } else { + return "`" + tableIndex.getName() + "`"; + } + } + + public String buildModifyIndex(TableIndex tableIndex) { + if (this.equals(PRIMARY)) { + return ""; + } + if (EditStatus.DELETE.name().equals(tableIndex.getEditStatus())) { + return StringUtils.join("DROP INDEX `", tableIndex.getOldName(), "`"); + } + if (EditStatus.MODIFY.name().equals(tableIndex.getEditStatus())) { + return StringUtils.join("DROP INDEX `", tableIndex.getOldName(), + "`,\n ADD ", buildIndexScript(tableIndex)); + } + if (EditStatus.ADD.name().equals(tableIndex.getEditStatus())) { + return StringUtils.join("ADD ", buildIndexScript(tableIndex)); + } + return ""; + } + +} diff --git a/chat2db-server/chat2db-plugins/chat2db-db2/pom.xml b/chat2db-server/chat2db-plugins/chat2db-db2/pom.xml index 11afc7adf..9169adfc0 100644 --- a/chat2db-server/chat2db-plugins/chat2db-db2/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-db2/pom.xml @@ -22,7 +22,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2DBManage.java b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2DBManage.java index d3480aa17..0946d550c 100644 --- a/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2DBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2DBManage.java @@ -1,8 +1,6 @@ package ai.chat2db.plugin.db2; -import java.sql.Connection; -import java.sql.SQLException; - +import ai.chat2db.plugin.db2.constant.SQLConstant; import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; import ai.chat2db.spi.sql.Chat2DBContext; @@ -11,8 +9,80 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + public class DB2DBManage extends DefaultDBManage implements DBManage { + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTables(connection, schemaName, sqlBuilder, containData); + exportViews(connection, schemaName, sqlBuilder); + exportProceduresAndFunctions(connection, schemaName, sqlBuilder); + exportTriggers(connection, schemaName, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportTables(Connection connection, String schemaName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(null, schemaName, null, new String[]{"TABLE", "SYSTEM TABLE"})) { + while (resultSet.next()) { + exportTable(connection, schemaName, resultSet.getString("TABLE_NAME"), sqlBuilder, containData); + } + } + } + + + private void exportTable(Connection connection, String schemaName, String tableName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + try { + SQLExecutor.getInstance().execute(connection, SQLConstant.TABLE_DDL_FUNCTION_SQL, resultSet -> null); + } catch (Exception e) { + //log.error("Failed to create function", e); + } + String sql = String.format("select %s.GENERATE_TABLE_DDL('%s', '%s') as sql from %s;", schemaName, schemaName, tableName, tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("sql")).append("\n"); + if (containData) { + exportTableData(connection, schemaName, tableName, sqlBuilder); + } + } + } + } + + + private void exportViews(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("select TEXT from syscat.views where VIEWSCHEMA='%s';", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String ddl = resultSet.getString("TEXT"); + sqlBuilder.append(ddl).append(";").append("\n"); + } + } + } + + private void exportProceduresAndFunctions(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("select TEXT from syscat.routines where ROUTINESCHEMA='%s';", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String ddl = resultSet.getString("TEXT"); + sqlBuilder.append(ddl).append(";").append("\n"); + } + } + } + + + private void exportTriggers(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("select * from SYSCAT.TRIGGERS where TRIGSCHEMA = '%s';", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String ddl = resultSet.getString("TEXT"); + sqlBuilder.append(ddl).append(";").append("\n"); + } + } + } + @Override public void connectDatabase(Connection connection, String database) { ConnectInfo connectInfo = Chat2DBContext.getConnectInfo(); @@ -26,9 +96,10 @@ public void connectDatabase(Connection connection, String database) { e.printStackTrace(); } } + @Override public void dropTable(Connection connection, String databaseName, String schemaName, String tableName) { String sql = "DROP TABLE " + tableName; - SQLExecutor.getInstance().execute(connection,sql, resultSet -> null); + SQLExecutor.getInstance().execute(connection, sql, resultSet -> null); } } diff --git a/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2MetaData.java b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2MetaData.java index 7f1446a64..d32a63caf 100644 --- a/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2MetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/DB2MetaData.java @@ -7,16 +7,14 @@ import java.util.stream.Collectors; import ai.chat2db.plugin.db2.builder.DB2SqlBuilder; +import ai.chat2db.plugin.db2.constant.SQLConstant; import ai.chat2db.plugin.db2.type.DB2ColumnTypeEnum; import ai.chat2db.plugin.db2.type.DB2DefaultValueEnum; import ai.chat2db.plugin.db2.type.DB2IndexTypeEnum; import ai.chat2db.spi.MetaData; import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.jdbc.DefaultMetaService; -import ai.chat2db.spi.model.Schema; -import ai.chat2db.spi.model.TableIndex; -import ai.chat2db.spi.model.TableIndexColumn; -import ai.chat2db.spi.model.TableMeta; +import ai.chat2db.spi.model.*; import ai.chat2db.spi.sql.SQLExecutor; import ai.chat2db.spi.util.SortUtils; import com.google.common.collect.Lists; @@ -30,45 +28,16 @@ public List schemas(Connection connection, String databaseName) { List schemas = SQLExecutor.getInstance().schemas(connection, databaseName, null); return SortUtils.sortSchema(schemas, systemSchemas); } - private String functionSQL - = "CREATE FUNCTION tableSchema.ufn_GetCreateTableScript( @schema_name NVARCHAR(128), @table_name NVARCHAR" - + "(128)) RETURNS NVARCHAR(MAX) AS BEGIN DECLARE @CreateTableScript NVARCHAR(MAX); DECLARE @IndexScripts " - + "NVARCHAR(MAX) = ''; DECLARE @ColumnDescriptions NVARCHAR(MAX) = N''; SELECT @CreateTableScript = CONCAT( " - + "'CREATE TABLE [', s.name, '].[' , t.name, '] (', STUFF( ( SELECT ', [' + c.name + '] ' + tp.name + CASE " - + "WHEN tp.name IN ('varchar', 'nvarchar', 'char', 'nchar') THEN '(' + IIF(c.max_length = -1, 'MAX', CAST(c" - + ".max_length AS NVARCHAR(10))) + ')' WHEN tp.name IN ('decimal', 'numeric') THEN '(' + CAST(c.precision AS " - + "NVARCHAR(10)) + ', ' + CAST(c.scale AS NVARCHAR(10)) + ')' ELSE '' END + ' ' + CASE WHEN c.is_nullable = 1" - + " THEN 'NULL' ELSE 'NOT NULL' END FROM sys.columns c JOIN sys.types tp ON c.user_type_id = tp.user_type_id " - + "WHERE c.object_id = t.object_id FOR XML PATH(''), TYPE ).value('/', 'nvarchar(max)'), 1, 1, ''), ');' ) " - + "FROM sys.tables t JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE t.name = @table_name AND s.name = " - + "@schema_name; SELECT @IndexScripts = @IndexScripts + 'CREATE ' + CASE WHEN i.is_unique = 1 THEN 'UNIQUE ' " - + "ELSE '' END + i.type_desc + ' INDEX [' + i.name + '] ON [' + s.name + '].[' + t.name + '] (' + STUFF( ( " - + "SELECT ', [' + c.name + ']' + CASE WHEN ic.is_descending_key = 1 THEN ' DESC' ELSE ' ASC' END FROM sys" - + ".index_columns ic JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id WHERE ic" - + ".object_id = i.object_id AND ic.index_id = i.index_id ORDER BY ic.key_ordinal FOR XML PATH('') ), 1, 1, " - + "'') + ')' + CASE WHEN i.has_filter = 1 THEN ' WHERE ' + i.filter_definition ELSE '' END + ';' + CHAR(13) +" - + " CHAR(10) FROM sys.indexes i JOIN sys.tables t ON i.object_id = t.object_id JOIN sys.schemas s ON t" - + ".schema_id = s.schema_id WHERE i.type > 0 AND t.name = @table_name AND s.name " - + "= @schema_name; SELECT @ColumnDescriptions += 'EXEC sp_addextendedproperty @name=N''MS_Description'', " - + "@value=N''' + CAST(p.value AS NVARCHAR(MAX)) + ''', @level0type=N''SCHEMA'', @level0name=N''' + " - + "@schema_name + ''', @level1type=N''TABLE'', @level1name=N''' + @table_name + ''', @level2type=N''COLUMN''," - + " @level2name=N''' + c.name + ''';' + CHAR(13) + CHAR(10) FROM sys.extended_properties p JOIN sys.columns c" - + " ON p.major_id = c.object_id AND p.minor_id = c.column_id JOIN sys.tables t ON c.object_id = t.object_id " - + "JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE p.class = 1 AND t.name = @table_name AND s.name = " - + "@schema_name; SET @CreateTableScript = @CreateTableScript + CHAR(13) + CHAR(10) + @IndexScripts + CHAR(13)" - + " + CHAR(10)+ @ColumnDescriptions+ CHAR(10); RETURN @CreateTableScript; END"; @Override public String tableDDL(Connection connection, String databaseName, String schemaName, String tableName) { try { - SQLExecutor.getInstance().execute(connection, functionSQL.replace("tableSchema", schemaName), resultSet -> null); + SQLExecutor.getInstance().execute(connection, SQLConstant.TABLE_DDL_FUNCTION_SQL, resultSet -> null); } catch (Exception e) { - //log.error("创建函数失败", e); + //log.error("Failed to create function", e); } - - String ddlSql = "SELECT " + schemaName + ".ufn_GetCreateTableScript('" + schemaName + "', '" + tableName - + "') AS sql"; + String ddlSql = String.format("select %s.GENERATE_TABLE_DDL('%s', '%s') as sql from %s;",schemaName,schemaName,tableName,tableName); return SQLExecutor.getInstance().execute(connection, ddlSql, resultSet -> { try { if (resultSet.next()) { @@ -130,6 +99,54 @@ public List indexes(Connection connection, String databaseName, Stri } + private static String VIEW_DDL_SQL="select TEXT from syscat.views where VIEWSCHEMA='%s' and VIEWNAME='%s';"; + @Override + public Table view(Connection connection, String databaseName, String schemaName, String viewName) { + String sql = String.format(VIEW_DDL_SQL, schemaName, viewName); + Table table = new Table(); + table.setDatabaseName(databaseName); + table.setSchemaName(schemaName); + table.setName(viewName); + SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + if (resultSet.next()) { + table.setDdl(resultSet.getString("TEXT")+";"); + } + }); + return table; + } + + private static String ROUTINE_DDL_SQL="select TEXT from syscat.routines where ROUTINESCHEMA='%s' and ROUTINENAME='%s';"; + + @Override + public Function function(Connection connection, String databaseName, String schemaName, String functionName) { + Function function = new Function(); + function.setDatabaseName(databaseName); + function.setSchemaName(schemaName); + function.setFunctionName(functionName); + String sql = String.format(ROUTINE_DDL_SQL, schemaName, functionName); + SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + if (resultSet.next()) { + function.setFunctionBody(resultSet.getString("TEXT")+";"); + } + }); + return function; + } + + @Override + public Procedure procedure(Connection connection, String databaseName, String schemaName, String procedureName) { + Procedure procedure = new Procedure(); + procedure.setDatabaseName(databaseName); + procedure.setSchemaName(schemaName); + procedure.setProcedureName(procedureName); + String sql = String.format(ROUTINE_DDL_SQL, schemaName, procedureName); + SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + if (resultSet.next()) { + procedure.setProcedureBody(resultSet.getString("TEXT")+";"); + } + }); + return procedure; + } + private TableIndexColumn getTableIndexColumn(ResultSet resultSet) throws SQLException { TableIndexColumn tableIndexColumn = new TableIndexColumn(); tableIndexColumn.setColumnName(resultSet.getString("COLNAME")); @@ -161,4 +178,8 @@ public String getMetaDataName(String... names) { return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "\"" + name + "\"").collect(Collectors.joining(".")); } + @Override + public List getSystemSchemas() { + return systemSchemas; + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/constant/SQLConstant.java b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/constant/SQLConstant.java new file mode 100644 index 000000000..55543e2ef --- /dev/null +++ b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/constant/SQLConstant.java @@ -0,0 +1,98 @@ +package ai.chat2db.plugin.db2.constant; + +/** + * @author: zgq + * @date: 2024年03月16日 10:11 + */ +public class SQLConstant { + + public static final String TABLE_DDL_FUNCTION_SQL + = """ + CREATE OR REPLACE FUNCTION generate_table_ddl(schema_name VARCHAR(128), table_name VARCHAR(128)) + RETURNS CLOB + LANGUAGE SQL + BEGIN + DECLARE ddl CLOB; + + -- 获取表的注释信息 + DECLARE table_remarks CLOB; + SELECT REMARKS + INTO table_remarks + FROM SYSCAT.TABLES + WHERE TABSCHEMA = schema_name + AND TABNAME = table_name; + + -- 拼接表的创建语句 + SET ddl = 'CREATE TABLE ' || table_name || ' ('; + + -- 获取表的字段信息并拼接到DDL语句中 + FOR col_info AS + SELECT COLNAME, TYPENAME, LENGTH, SCALE, NULLS, DEFAULT as default, REMARKS + FROM SYSCAT.COLUMNS + WHERE TABSCHEMA = schema_name + AND TABNAME = table_name + ORDER BY COLNO + DO + SET ddl = ddl || col_info.COLNAME || ' '; + IF col_info.TYPENAME = 'INTEGER' THEN + SET ddl = ddl || col_info.TYPENAME; + ELSE + SET ddl = ddl || col_info.TYPENAME; + IF col_info.LENGTH IS NOT NULL THEN + SET ddl = ddl || '(' || col_info.LENGTH; + IF col_info.TYPENAME != 'VARCHAR' AND col_info.SCALE IS NOT NULL THEN + SET ddl = ddl || ',' || col_info.SCALE; + END IF; + SET ddl = ddl || ')'; + END IF; + END IF; + IF col_info.NULLS = 'N' THEN + SET ddl = ddl || ' NOT NULL'; + END IF; + IF col_info.default IS NOT NULL THEN + SET ddl = ddl || ' DEFAULT ' || col_info.default; + END IF; + SET ddl = ddl || ','; -- 添加字段定义结束符 + END FOR; + + -- 删除最后一个逗号 + SET ddl = LEFT(ddl, LENGTH(ddl) - 1); + SET ddl = ddl || ');'; + + -- 添加表的注释 + IF table_remarks IS NOT NULL THEN + SET ddl = ddl || 'comment on table ' || table_name || ' is ''' || table_remarks || ''';'; + END IF; + + for column as + SELECT COLNAME, REMARKS + FROM SYSCAT.COLUMNS + WHERE TABSCHEMA = schema_name + AND TABNAME = table_name + ORDER BY COLNO + do + if column.REMARKS is not null then + set ddl = ddl || 'comment on column ' || table_name || '.' || column.COLNAME || ' is ''' || + column.REMARKS || ''';'; + end if; + end for; + + -- 获取表的索引信息并拼接到DDL语句中 + FOR index_info AS + SELECT INDNAME, SUBSTR(COLNAMES, 2) AS COLNAMES, UNIQUERULE + FROM SYSCAT.INDEXES + WHERE TABSCHEMA = schema_name + AND TABNAME = table_name + DO + IF index_info.UNIQUERULE = 'P' THEN + SET ddl = ddl || ' ALTER TABLE ' || table_name || ' ADD PRIMARY KEY (' || + index_info.COLNAMES || ');'; + ELSEIF index_info.UNIQUERULE = 'U' THEN + SET ddl = ddl || ' CREATE UNIQUE INDEX ' || index_info.INDNAME || ' ON ' || + table_name || ' (' || index_info.COLNAMES || ');'; + END IF; + END FOR; + + RETURN ddl; + END;"""; +} diff --git a/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/db2.json b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/db2.json index b0b3d12a3..bd9ab6272 100644 --- a/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/db2.json +++ b/chat2db-server/chat2db-plugins/chat2db-db2/src/main/java/ai/chat2db/plugin/db2/db2.json @@ -8,7 +8,7 @@ "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/db2jcc4_4.26.14.jar" + "https://cdn.chat2db-ai.com/lib/db2jcc4_4.26.14.jar" ], "jdbcDriver": "db2jcc4_4.26.14.jar", "jdbcDriverClass": "com.ibm.db2.jcc.DB2Driver" diff --git a/chat2db-server/chat2db-plugins/chat2db-dm/pom.xml b/chat2db-server/chat2db-plugins/chat2db-dm/pom.xml index 4e953132f..254b60bd4 100644 --- a/chat2db-server/chat2db-plugins/chat2db-dm/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-dm/pom.xml @@ -23,7 +23,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMDBManage.java b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMDBManage.java index 16df526f6..44c35fe15 100644 --- a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMDBManage.java @@ -1,7 +1,7 @@ package ai.chat2db.plugin.dm; -import java.sql.Connection; -import java.sql.SQLException; +import java.sql.*; +import java.util.Objects; import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; @@ -12,6 +12,132 @@ import org.apache.commons.lang3.StringUtils; public class DMDBManage extends DefaultDBManage implements DBManage { + private String format(String tableName) { + return "\"" + tableName + "\""; + } + private static String ROUTINES_SQL + = "SELECT OWNER, NAME, TEXT FROM ALL_SOURCE WHERE TYPE = '%s' AND OWNER = '%s' AND NAME = '%s' ORDER BY LINE"; + private static String TRIGGER_SQL_LIST = "SELECT OWNER, TRIGGER_NAME FROM ALL_TRIGGERS WHERE OWNER = '%s'"; + + private static String TRIGGER_SQL + = "SELECT OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, TRIGGERING_TYPE, TRIGGERING_EVENT, STATUS, TRIGGER_BODY " + + "FROM ALL_TRIGGERS WHERE OWNER = '%s' AND TRIGGER_NAME = '%s'"; + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTables(connection, sqlBuilder, schemaName, containData); + exportViews(connection, schemaName, sqlBuilder); + exportProcedures(connection, schemaName, sqlBuilder); + exportTriggers(connection,schemaName, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportTables(Connection connection, StringBuilder sqlBuilder, String schemaName, boolean containData) throws SQLException { + String sql =String.format("SELECT TABLE_NAME FROM ALL_TABLES where OWNER='%s' and TABLESPACE_NAME='MAIN'", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String tableName = resultSet.getString("TABLE_NAME"); + exportTable(connection, tableName, schemaName, sqlBuilder, containData); + } + } + } + + + private void exportTable(Connection connection, String tableName, String schemaName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + String sql = """ + SELECT + (SELECT comments FROM user_tab_comments WHERE table_name = '%s') AS comments, + (SELECT dbms_metadata.get_ddl('TABLE', '%s', '%s') FROM dual) AS ddl + FROM dual; + """; + try (Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(String.format(sql, tableName, tableName, schemaName))) { + String formatSchemaName = format(schemaName); + String formatTableName = format(tableName); + if (resultSet.next()) { + sqlBuilder.append("DROP TABLE IF EXISTS ").append(formatSchemaName).append(".").append(formatTableName) + .append(";").append("\n") + .append(resultSet.getString("ddl")).append("\n"); + String comment = resultSet.getString("comments"); + if (StringUtils.isNotBlank(comment)) { + sqlBuilder.append("COMMENT ON TABLE ").append(formatSchemaName).append(".").append(formatTableName) + .append(" IS ").append("'").append(comment).append("';"); + } + exportTableColumnComment(connection, schemaName, tableName, sqlBuilder); + } + if (containData) { + exportTableData(connection, schemaName, tableName, sqlBuilder); + } + } + } + + private void exportTableColumnComment(Connection connection, String schemaName, String tableName, StringBuilder sqlBuilder) throws SQLException { + String sql =String.format("select COLNAME,COMMENT$ from SYS.SYSCOLUMNCOMMENTS\n" + + "where SCHNAME = '%s' and TVNAME = '%s'and TABLE_TYPE = 'TABLE';", schemaName,tableName); + try(ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String columnName = resultSet.getString("COLNAME"); + String comment = resultSet.getString("COMMENT$"); + sqlBuilder.append("COMMENT ON COLUMN ").append(format(schemaName)).append(".").append(format(tableName)) + .append(".").append(format(columnName)).append(" IS ").append("'").append(comment).append("';").append("\n"); + } + } + } + + + private void exportViews(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(null, schemaName, null, new String[]{"VIEW"})) { + while (resultSet.next()) { + String viewName = resultSet.getString("TABLE_NAME"); + exportView(connection, viewName, schemaName, sqlBuilder); + } + } + } + + private void exportView(Connection connection, String viewName, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT DBMS_METADATA.GET_DDL('VIEW','%s','%s') as ddl FROM DUAL;", viewName, schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("ddl")).append("\n"); + } + } + } + + private void exportProcedures(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getProcedures(null, schemaName, null)) { + while (resultSet.next()) { + String procedureName = resultSet.getString("PROCEDURE_NAME"); + exportProcedure(connection, schemaName,procedureName, sqlBuilder); + } + } + } + + private void exportProcedure(Connection connection, String schemaName, String procedureName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(ROUTINES_SQL,"PROC", schemaName,procedureName); + try (Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("TEXT")).append("\n"); + } + } + } + + private void exportTriggers(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql =String.format(TRIGGER_SQL_LIST, schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String triggerName = resultSet.getString("TRIGGER_NAME"); + exportTrigger(connection,schemaName, triggerName, sqlBuilder); + } + } + } + + private void exportTrigger(Connection connection, String schemaName, String triggerName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(TRIGGER_SQL, schemaName,triggerName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("TRIGGER_BODY")).append("\n"); + } + } + } @Override public void connectDatabase(Connection connection, String database) { diff --git a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMMetaData.java b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMMetaData.java index a2e514fad..fc2db8523 100644 --- a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/DMMetaData.java @@ -1,11 +1,5 @@ package ai.chat2db.plugin.dm; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; -import java.util.stream.Collectors; - import ai.chat2db.plugin.dm.builder.DMSqlBuilder; import ai.chat2db.plugin.dm.type.DMColumnTypeEnum; import ai.chat2db.plugin.dm.type.DMDefaultValueEnum; @@ -16,11 +10,16 @@ import ai.chat2db.spi.model.*; import ai.chat2db.spi.sql.SQLExecutor; import ai.chat2db.spi.util.SortUtils; -import ai.chat2db.spi.util.SqlUtils; import com.google.common.collect.Lists; import jakarta.validation.constraints.NotEmpty; import org.apache.commons.lang3.StringUtils; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.util.stream.Collectors; + public class DMMetaData extends DefaultMetaService implements MetaData { private List systemSchemas = Arrays.asList("CTISYS", "SYS","SYSDBA","SYSSSO","SYSAUDITOR"); @@ -30,21 +29,40 @@ public List schemas(Connection connection, String databaseName) { List schemas = SQLExecutor.getInstance().schemas(connection, databaseName, null); return SortUtils.sortSchema(schemas, systemSchemas); } + private String format(String tableName){ + return "\"" + tableName + "\""; + } + public String tableDDL(Connection connection, String databaseName, String schemaName, String tableName) { - String selectObjectDDLSQL = String.format( - "select dbms_metadata.get_ddl(%s, %s, %s) AS \"sql\" from dual", - SqlUtils.formatSQLString("TABLE"), SqlUtils.formatSQLString(tableName), - SqlUtils.formatSQLString(schemaName)); - return SQLExecutor.getInstance().execute(connection, selectObjectDDLSQL, resultSet -> { - try { - if (resultSet.next()) { - return resultSet.getString("sql"); + String sql = """ + SELECT + (SELECT comments FROM user_tab_comments WHERE table_name = '%s') AS comments, + (SELECT dbms_metadata.get_ddl('TABLE', '%s', '%s') FROM dual) AS ddl + FROM dual; + """; + StringBuilder ddlBuilder = new StringBuilder(); + String tableDDLSql = String.format(sql, tableName, tableName, schemaName); + SQLExecutor.getInstance().execute(connection, tableDDLSql, resultSet -> { + if (resultSet.next()) { + String ddl = resultSet.getString("ddl"); + String comment = resultSet.getString("comments"); + if (StringUtils.isNotBlank(comment)) { + ddlBuilder.append(ddl).append("\n").append("COMMENT ON TABLE ").append(format(schemaName)) + .append(".").append(format(tableName)).append(" IS ").append("'").append(comment).append("';"); } - } catch (SQLException e) { - throw new RuntimeException(e); } - return null; }); + String columnCommentsSql =String.format("select COLNAME,COMMENT$ from SYS.SYSCOLUMNCOMMENTS\n" + + "where SCHNAME = '%s' and TVNAME = '%s'and TABLE_TYPE = 'TABLE';", schemaName,tableName); + SQLExecutor.getInstance().execute(connection, columnCommentsSql, resultSet->{ + while (resultSet.next()) { + String columnName = resultSet.getString("COLNAME"); + String comment = resultSet.getString("COMMENT$"); + ddlBuilder.append("COMMENT ON COLUMN ").append(format(schemaName)).append(".").append(format(tableName)) + .append(".").append(format(columnName)).append(" IS ").append("'").append(comment).append("';").append("\n"); + } + }); + return ddlBuilder.toString(); } private static String ROUTINES_SQL @@ -90,7 +108,7 @@ public Procedure procedure(Connection connection, @NotEmpty String databaseName, } private static String TRIGGER_SQL - = "SELECT OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, TRIGGER_TYPE, TRIGGERING_EVENT, STATUS, TRIGGER_BODY " + = "SELECT OWNER, TRIGGER_NAME, TABLE_OWNER, TABLE_NAME, TRIGGERING_TYPE, TRIGGERING_EVENT, STATUS, TRIGGER_BODY " + "FROM ALL_TRIGGERS WHERE OWNER = '%s' AND TRIGGER_NAME = '%s'"; private static String TRIGGER_SQL_LIST = "SELECT OWNER, TRIGGER_NAME FROM ALL_TRIGGERS WHERE OWNER = '%s'"; @@ -227,4 +245,10 @@ public TableMeta getTableMeta(String databaseName, String schemaName, String tab public String getMetaDataName(String... names) { return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "\"" + name + "\"").collect(Collectors.joining(".")); } + + + @Override + public List getSystemSchemas() { + return systemSchemas; + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/builder/DMSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/builder/DMSqlBuilder.java index 5f840cf58..8ea2ef08b 100644 --- a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/builder/DMSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/builder/DMSqlBuilder.java @@ -2,6 +2,7 @@ import ai.chat2db.plugin.dm.type.DMColumnTypeEnum; import ai.chat2db.plugin.dm.type.DMIndexTypeEnum; +import ai.chat2db.spi.enums.EditStatus; import ai.chat2db.spi.jdbc.DefaultSqlBuilder; import ai.chat2db.spi.model.Schema; import ai.chat2db.spi.model.Table; @@ -9,6 +10,8 @@ import ai.chat2db.spi.model.TableIndex; import org.apache.commons.lang3.StringUtils; +import java.util.Objects; + public class DMSqlBuilder extends DefaultSqlBuilder { @@ -79,10 +82,11 @@ public String buildModifyTaleSql(Table oldTable, Table newTable) { // append modify column for (TableColumn tableColumn : newTable.getColumnList()) { - if (StringUtils.isNotBlank(tableColumn.getEditStatus())) { + String editStatus = tableColumn.getEditStatus(); + if (StringUtils.isNotBlank(editStatus)) { DMColumnTypeEnum typeEnum = DMColumnTypeEnum.getByType(tableColumn.getColumnType()); script.append("\t").append(typeEnum.buildModifyColumn(tableColumn)).append(";\n"); - if (StringUtils.isNotBlank(tableColumn.getComment())) { + if (StringUtils.isNotBlank(tableColumn.getComment())&&!Objects.equals(EditStatus.DELETE.toString(),editStatus)) { script.append("\n").append(buildComment(tableColumn)).append(";\n"); } } diff --git a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/dm.json b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/dm.json index 075966e14..2ffe4a20a 100644 --- a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/dm.json +++ b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/dm.json @@ -8,7 +8,7 @@ "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/DmJdbcDriver18-8.1.2.141.jar" + "https://cdn.chat2db-ai.com/lib/DmJdbcDriver18-8.1.2.141.jar" ], "jdbcDriver": "DmJdbcDriver18-8.1.2.141.jar", "jdbcDriverClass": "dm.jdbc.driver.DmDriver" diff --git a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/type/DMColumnTypeEnum.java b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/type/DMColumnTypeEnum.java index dd15ed232..ea9876c92 100644 --- a/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/type/DMColumnTypeEnum.java +++ b/chat2db-server/chat2db-plugins/chat2db-dm/src/main/java/ai/chat2db/plugin/dm/type/DMColumnTypeEnum.java @@ -41,13 +41,14 @@ public enum DMColumnTypeEnum implements ColumnBuilder { DATE("DATE", false, false, true, false, false, false, true, true, false, false), DECIMAL("DECIMAL", true, true, true, false, false, false, true, true, false, false), + DEC("DEC", true, true, true, false, false, false, true, true, false, false), DOUBLE("DOUBLE", false, false, true, false, false, false, true, true, false, false), FLOAT("FLOAT", true, false, true, false, false, false, true, true, false, false), - INT("INT", false, false, true, false, false, false, true, true, false, false), + INT("INT", false, false, true, true, false, false, true, true, false, false), // INTEGER("INTEGER", false, false, true, false, false, false, true, true, false, false), @@ -84,7 +85,8 @@ public enum DMColumnTypeEnum implements ColumnBuilder { LONGVARBINARY("LONGVARBINARY", false, false, true, false, false, false, true, true, false, false), - LONGVARCHAR("LONGVARCHAR", true, false, true, false, false, false, true, true, false, false), + LONGVARCHAR("LONGVARCHAR", false, false, true, false, false, false, true, true, false, false), + TEXT("TEXT", false, false, true, false, false, false, true, true, false, false), NUMBERIC("NUMBERIC", true, true, true, false, false, false, true, true, false, false), @@ -159,11 +161,26 @@ public String buildCreateColumnSql(TableColumn column) { script.append(buildDefaultValue(column, type)).append(" "); + script.append(buildAutoIncrement(column,type)).append(" "); + script.append(buildNullable(column, type)).append(" "); return script.toString(); } + private String buildAutoIncrement(TableColumn column, DMColumnTypeEnum type) { + if(!type.getColumnType().isSupportAutoIncrement()){ + return ""; + } + if (column.getAutoIncrement() != null && column.getAutoIncrement() + && column.getSeed() != null && column.getSeed() > 0 && column.getIncrement() != null && column.getIncrement() > 0) { + return "IDENTITY(" + column.getSeed() + "," + column.getIncrement() + ")"; + } + if (column.getAutoIncrement() != null && column.getAutoIncrement()) { + return "IDENTITY(1,1)"; + } + return ""; + } private String buildNullable(TableColumn column, DMColumnTypeEnum type) { if (!type.getColumnType().isSupportNullable()) { @@ -194,7 +211,7 @@ private String buildDefaultValue(TableColumn column, DMColumnTypeEnum type) { private String buildDataType(TableColumn column, DMColumnTypeEnum type) { String columnType = type.columnType.getTypeName(); - if (Arrays.asList(CHAR, VARCHAR, VARCHAR2, LONGVARCHAR).contains(type)) { + if (Arrays.asList(CHAR, VARCHAR, VARCHAR2, LONGVARCHAR,TEXT).contains(type)) { StringBuilder script = new StringBuilder(); script.append(columnType); if (column.getColumnSize() != null && StringUtils.isEmpty(column.getUnit())) { @@ -205,7 +222,7 @@ private String buildDataType(TableColumn column, DMColumnTypeEnum type) { return script.toString(); } - if (Arrays.asList(DECIMAL, FLOAT, NUMBER, TIMESTAMP, NUMBERIC).contains(type)) { + if (Arrays.asList(DECIMAL,DEC, FLOAT, NUMBER, TIMESTAMP, NUMBERIC).contains(type)) { StringBuilder script = new StringBuilder(); script.append(columnType); if (column.getColumnSize() != null && column.getDecimalDigits() == null) { diff --git a/chat2db-server/chat2db-plugins/chat2db-h2/pom.xml b/chat2db-server/chat2db-plugins/chat2db-h2/pom.xml index 4192b0e14..315204368 100644 --- a/chat2db-server/chat2db-plugins/chat2db-h2/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-h2/pom.xml @@ -22,7 +22,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2DBManage.java b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2DBManage.java index 25e48f85f..7f3bf75ec 100644 --- a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2DBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2DBManage.java @@ -1,8 +1,5 @@ package ai.chat2db.plugin.h2; -import java.sql.Connection; -import java.sql.SQLException; - import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; import ai.chat2db.spi.sql.Chat2DBContext; @@ -11,7 +8,36 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.Objects; + public class H2DBManage extends DefaultDBManage implements DBManage { + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportSchema(connection, schemaName, sqlBuilder, containData); + return sqlBuilder.toString(); + } + + private void exportSchema(Connection connection, String schemaName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + String sql = String.format("SCRIPT NODATA NOPASSWORDS NOSETTINGS DROP SCHEMA %s;", schemaName); + if (containData) { + sql = sql.replace("NODATA", ""); + } + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String script = resultSet.getString("SCRIPT"); + if (!(script.startsWith("CREATE USER")||script.startsWith("--"))) { + sqlBuilder.append(script); + sqlBuilder.append("\n"); + } + } + } + + } @Override public void connectDatabase(Connection connection, String database) { @@ -30,7 +56,7 @@ public void connectDatabase(Connection connection, String database) { @Override public void dropTable(Connection connection, String databaseName, String schemaName, String tableName) { - String sql = "DROP TABLE " +tableName; - SQLExecutor.getInstance().execute(connection,sql, resultSet -> null); + String sql = "DROP TABLE " + tableName; + SQLExecutor.getInstance().execute(connection, sql, resultSet -> null); } } diff --git a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java index f5c725614..5caffc8cf 100644 --- a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java +++ b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java @@ -34,7 +34,7 @@ public String tableDDL(Connection connection, @NotEmpty String databaseName, Str private String getDDL(Connection connection, String databaseName, String schemaName, String tableName) { try { - // 查询表结构信息 + // Query table structure information ResultSet columns = connection.getMetaData().getColumns(databaseName, schemaName, tableName, null); List columnDefinitions = new ArrayList<>(); while (columns.next()) { @@ -59,7 +59,7 @@ private String getDDL(Connection connection, String databaseName, String schemaN columnDefinitions.add(columnDefinition.toString()); } - // 查询表索引信息 + // Query table index information ResultSet indexes = connection.getMetaData().getIndexInfo(databaseName, schemaName, tableName, false, false); Map> indexMap = new HashMap<>(); @@ -77,7 +77,7 @@ private String getDDL(Connection connection, String databaseName, String schemaN createTableDDL.append(tableName).append(" (\n"); createTableDDL.append(String.join(",\n", columnDefinitions)); createTableDDL.append("\n);\n"); - // 输出索引信息 + // Output index information for (Map.Entry> entry : indexMap.entrySet()) { String indexName = entry.getKey(); List columnList = entry.getValue(); @@ -205,4 +205,9 @@ public SqlBuilder getSqlBuilder() { public String getMetaDataName(String... names) { return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "\"" + name + "\"").collect(Collectors.joining(".")); } + + @Override + public List getSystemSchemas() { + return systemSchemas; + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/builder/H2SqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/builder/H2SqlBuilder.java index ed41f653d..325456ae2 100644 --- a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/builder/H2SqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/builder/H2SqlBuilder.java @@ -5,7 +5,7 @@ import ai.chat2db.spi.model.Schema; import org.apache.commons.lang3.StringUtils; -public class H2SqlBuilder extends DefaultSqlBuilder implements SqlBuilder { +public class H2SqlBuilder extends DefaultSqlBuilder { @Override public String buildCreateSchemaSql(Schema schema) { diff --git a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/h2.json b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/h2.json index ee11410d5..cd47547e8 100644 --- a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/h2.json +++ b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/h2.json @@ -8,7 +8,7 @@ "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/h2-2.1.214.jar" + "https://cdn.chat2db-ai.com/lib/h2-2.1.214.jar" ], "jdbcDriver": "h2-2.1.214.jar", "jdbcDriverClass": "org.h2.Driver" diff --git a/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/hive.json b/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/hive.json index 967bdd80c..6aadb0ab0 100644 --- a/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/hive.json +++ b/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/hive.json @@ -8,7 +8,7 @@ "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/hive-jdbc-3.1.2-standalone.jar" + "https://cdn.chat2db-ai.com/lib/hive-jdbc-3.1.2-standalone.jar" ], "jdbcDriver": "hive-jdbc-3.1.2-standalone.jar", "jdbcDriverClass": "org.apache.hive.jdbc.HiveDriver" diff --git a/chat2db-server/chat2db-plugins/chat2db-kingbase/pom.xml b/chat2db-server/chat2db-plugins/chat2db-kingbase/pom.xml index 262e20f0c..747cd06f3 100644 --- a/chat2db-server/chat2db-plugins/chat2db-kingbase/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-kingbase/pom.xml @@ -23,7 +23,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseDBManage.java b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseDBManage.java index be2f6549d..918e5765e 100644 --- a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseDBManage.java @@ -37,20 +37,20 @@ public Connection getConnection(ConnectInfo connectInfo) { public String replaceDatabaseInJdbcUrl(String url, String newDatabase) { - // 先在"?"字符处分割字符串,处理查询参数 + // First split the string at the "?" character and process the query parameters String[] urlAndParams = url.split("\\?"); String urlWithoutParams = urlAndParams[0]; - // 在URL中的"/"字符处分割字符串 + // Split string at "/" character in URL String[] parts = urlWithoutParams.split("/"); - // 取最后一部分,即数据库名,并替换为新的数据库名 + // Take the last part, the database name, and replace it with the new database name parts[parts.length - 1] = newDatabase; - // 将修改后的部分重新组合成URL + // Reassemble the modified parts into a URL String newUrlWithoutParams = String.join("/", parts); - // 如果存在查询参数,重新添加 + // If query parameters exist, add them again String newUrl = urlAndParams.length > 1 ? newUrlWithoutParams + "?" + urlAndParams[1] : newUrlWithoutParams; return newUrl; diff --git a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseMetaData.java b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseMetaData.java index 5d85cd231..6f12f7f90 100644 --- a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseMetaData.java @@ -30,6 +30,9 @@ public class KingBaseMetaData extends DefaultMetaService implements MetaData { private List systemDatabases = Arrays.asList("SAMPLES", "SECURITY"); + + private List systemSchemas = Arrays.asList("pg_toast","pg_temp_1","pg_toast_temp_1","pg_catalog","information_schema"); + @Override public List databases(Connection connection) { List list = SQLExecutor.getInstance().execute(connection, "SELECT datname FROM sys_database", resultSet -> { @@ -203,4 +206,14 @@ public TableMeta getTableMeta(String databaseName, String schemaName, String tab public String getMetaDataName(String... names) { return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "\"" + name + "\"").collect(Collectors.joining(".")); } + + @Override + public List getSystemDatabases() { + return systemDatabases; + } + + @Override + public List getSystemSchemas() { + return systemSchemas; + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/builder/KingBaseSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/builder/KingBaseSqlBuilder.java index bccae8957..9dcbf920d 100644 --- a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/builder/KingBaseSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/builder/KingBaseSqlBuilder.java @@ -14,7 +14,7 @@ import java.util.stream.Collectors; -public class KingBaseSqlBuilder extends DefaultSqlBuilder implements SqlBuilder { +public class KingBaseSqlBuilder extends DefaultSqlBuilder { @Override public String buildCreateTableSql(Table table) { StringBuilder script = new StringBuilder(); diff --git a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/kingbase.json b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/kingbase.json index c401d4785..33f751f00 100644 --- a/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/kingbase.json +++ b/chat2db-server/chat2db-plugins/chat2db-kingbase/src/main/java/ai/chat2db/plugin/kingbase/kingbase.json @@ -8,7 +8,7 @@ "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/kingbase8-8.6.0.jar" + "https://cdn.chat2db-ai.com/lib/kingbase8-8.6.0.jar" ], "jdbcDriver": "kingbase8-8.6.0.jar", "jdbcDriverClass": "com.kingbase8.Driver" @@ -18,7 +18,7 @@ "custom": false, "defaultDriver": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/kingbase8-8.2.0.jar" + "https://cdn.chat2db-ai.com/lib/kingbase8-8.2.0.jar" ], "jdbcDriver": "kingbase8-8.2.0.jar", "jdbcDriverClass": "com.kingbase8.Driver" diff --git a/chat2db-server/chat2db-plugins/chat2db-mariadb/pom.xml b/chat2db-server/chat2db-plugins/chat2db-mariadb/pom.xml index 99508bf62..633d097aa 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mariadb/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-mariadb/pom.xml @@ -28,7 +28,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-mariadb/src/main/java/ai/chat2db/plugin/mariadb/mariadb.json b/chat2db-server/chat2db-plugins/chat2db-mariadb/src/main/java/ai/chat2db/plugin/mariadb/mariadb.json index 59caa4a1a..a65e02bd8 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mariadb/src/main/java/ai/chat2db/plugin/mariadb/mariadb.json +++ b/chat2db-server/chat2db-plugins/chat2db-mariadb/src/main/java/ai/chat2db/plugin/mariadb/mariadb.json @@ -8,7 +8,7 @@ "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/mariadb-java-client-3.0.8.jar" + "https://cdn.chat2db-ai.com/lib/mariadb-java-client-3.0.8.jar" ], "jdbcDriver": "mariadb-java-client-3.0.8.jar", "jdbcDriverClass": "org.mariadb.jdbc.Driver" diff --git a/chat2db-server/chat2db-plugins/chat2db-mongodb/pom.xml b/chat2db-server/chat2db-plugins/chat2db-mongodb/pom.xml index 8cfe62d7e..9ce3f54c3 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mongodb/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-mongodb/pom.xml @@ -23,7 +23,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbCommandExecutor.java b/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbCommandExecutor.java new file mode 100644 index 000000000..222518b37 --- /dev/null +++ b/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbCommandExecutor.java @@ -0,0 +1,17 @@ +package ai.chat2db.plugin.mongodb; + +import ai.chat2db.spi.model.Command; +import ai.chat2db.spi.model.ExecuteResult; +import ai.chat2db.spi.sql.SQLExecutor; + +import java.util.List; + +public class MongodbCommandExecutor extends SQLExecutor { + + @Override + public List executeSelectTable(Command command) { + String sql = "db." + command.getTableName() + ".find()"; + command.setScript(sql); + return execute(command); + } +} diff --git a/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbMetaData.java b/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbMetaData.java index 4716d88e7..01047a760 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/MongodbMetaData.java @@ -1,9 +1,9 @@ package ai.chat2db.plugin.mongodb; +import ai.chat2db.spi.CommandExecutor; import ai.chat2db.spi.MetaData; import ai.chat2db.spi.jdbc.DefaultMetaService; import ai.chat2db.spi.model.Database; -import ai.chat2db.spi.sql.SQLExecutor; import com.google.common.collect.Lists; import java.sql.Connection; @@ -17,4 +17,9 @@ public class MongodbMetaData extends DefaultMetaService implements MetaData { public List databases(Connection connection) { return Lists.newArrayList(); } + + @Override + public CommandExecutor getCommandExecutor() { + return new MongodbCommandExecutor(); + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/mongodb.json b/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/mongodb.json index 29d55a1c4..7388fa3dc 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/mongodb.json +++ b/chat2db-server/chat2db-plugins/chat2db-mongodb/src/main/java/ai/chat2db/plugin/mongodb/mongodb.json @@ -8,7 +8,7 @@ "defaultDriver":true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/mongo-jdbc-standalone-1.18.jar" + "https://cdn.chat2db-ai.com/lib/mongo-jdbc-standalone-1.18.jar" ], "jdbcDriver": "mongo-jdbc-standalone-1.18.jar", "jdbcDriverClass": "com.dbschema.MongoJdbcDriver" diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/pom.xml b/chat2db-server/chat2db-plugins/chat2db-mysql/pom.xml index d867bde57..cd2b57f0a 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/pom.xml @@ -23,7 +23,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java index 2322dd669..cefa6f98d 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlDBManage.java @@ -1,32 +1,160 @@ package ai.chat2db.plugin.mysql; -import java.sql.Connection; -import java.sql.SQLException; - import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; +import ai.chat2db.spi.model.Procedure; import ai.chat2db.spi.sql.SQLExecutor; import org.springframework.util.StringUtils; +import java.sql.*; +import java.util.Objects; + public class MysqlDBManage extends DefaultDBManage implements DBManage { + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTables(connection, databaseName, sqlBuilder, containData); + exportViews(connection, databaseName, sqlBuilder); + exportProcedures(connection, sqlBuilder); + exportTriggers(connection, sqlBuilder); + exportFunctions(connection, databaseName, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportFunctions(Connection connection, String databaseName, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getFunctions(databaseName, null, null)) { + while (resultSet.next()) { + exportFunction(connection, resultSet.getString("FUNCTION_NAME"), sqlBuilder); + } + + } + } + + private void exportFunction(Connection connection, String functionName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SHOW CREATE FUNCTION %s;", functionName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP FUNCTION IF EXISTS ").append(functionName).append(";").append("\n") + .append(resultSet.getString("Create Function")).append(";").append("\n"); + } + } + } + + private void exportTables(Connection connection, String databaseName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, null, null, new String[]{"TABLE", "SYSTEM TABLE"})) { + while (resultSet.next()) { + exportTable(connection, resultSet.getString("TABLE_NAME"), sqlBuilder, containData); + } + } + } + + + private void exportTable(Connection connection, String tableName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + String sql = String.format("show create table %s ", tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP TABLE IF EXISTS ").append(format(tableName)).append(";").append("\n") + .append(resultSet.getString("Create Table")).append(";").append("\n"); + if (containData) { + exportTableData(connection, null,tableName, sqlBuilder); + } + } + } + } + + + private void exportViews(Connection connection, String databaseName, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, null, null, new String[]{"VIEW"})) { + while (resultSet.next()) { + exportView(connection, resultSet.getString("TABLE_NAME"), sqlBuilder); + } + } + } + + private void exportView(Connection connection, String viewName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("show create view %s ", viewName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP VIEW IF EXISTS ").append(format(viewName)).append(";").append("\n") + .append(resultSet.getString("Create View")).append(";").append("\n"); + } + } + } + + private void exportProcedures(Connection connection, StringBuilder sqlBuilder) throws SQLException { + String sql = "SHOW PROCEDURE STATUS WHERE Db = DATABASE()"; + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + exportProcedure(connection, resultSet.getString("Name"), sqlBuilder); + } + } + } + + private void exportProcedure(Connection connection, String procedureName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("show create procedure %s ", procedureName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP PROCEDURE IF EXISTS ").append(format(procedureName)).append(";").append("\n") + .append("delimiter ;;").append("\n").append(resultSet.getString("Create Procedure")).append(";;") + .append("\n").append("delimiter ;").append("\n"); + } + } + } + + private void exportTriggers(Connection connection, StringBuilder sqlBuilder) throws SQLException { + String sql = "SHOW TRIGGERS"; + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String triggerName = resultSet.getString("Trigger"); + exportTrigger(connection, triggerName, sqlBuilder); + } + } + } + + private void exportTrigger(Connection connection, String triggerName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("show create trigger %s ", triggerName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP TRIGGER IF EXISTS ").append(format(triggerName)).append(";").append("\n") + .append("delimiter ;;").append("\n").append(resultSet.getString("SQL Original Statement")).append(";;") + .append("\n").append("delimiter ;").append("\n"); + } + } + } + + @Override + public void updateProcedure(Connection connection, String databaseName, String schemaName, Procedure procedure) throws SQLException { + try { + connection.setAutoCommit(false); + String sql = "DROP PROCEDURE " + procedure.getProcedureName(); + SQLExecutor.getInstance().execute(connection, sql, resultSet -> {}); + String procedureBody = procedure.getProcedureBody(); + SQLExecutor.getInstance().execute(connection, procedureBody, resultSet -> {}); + connection.commit(); + } catch (Exception e) { + connection.rollback(); + throw new RuntimeException(e); + } + + } + @Override public void connectDatabase(Connection connection, String database) { if (StringUtils.isEmpty(database)) { return; } try { - SQLExecutor.getInstance().execute(connection,"use `" + database + "`;"); + SQLExecutor.getInstance().execute(connection, "use `" + database + "`;"); } catch (SQLException e) { throw new RuntimeException(e); } } - @Override public void dropTable(Connection connection, String databaseName, String schemaName, String tableName) { - String sql = "DROP TABLE "+ format(tableName); - SQLExecutor.getInstance().execute(connection,sql, resultSet -> null); + String sql = "DROP TABLE " + format(tableName); + SQLExecutor.getInstance().execute(connection, sql, resultSet -> null); } public static String format(String tableName) { diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java index 40a291955..c802176e5 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlMetaData.java @@ -1,12 +1,5 @@ package ai.chat2db.plugin.mysql; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - import ai.chat2db.plugin.mysql.builder.MysqlSqlBuilder; import ai.chat2db.plugin.mysql.type.*; import ai.chat2db.spi.MetaData; @@ -17,16 +10,24 @@ import ai.chat2db.spi.sql.SQLExecutor; import jakarta.validation.constraints.NotEmpty; import org.apache.commons.lang3.StringUtils; +import org.checkerframework.checker.units.qual.A; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.util.stream.Collectors; import static ai.chat2db.spi.util.SortUtils.sortDatabase; public class MysqlMetaData extends DefaultMetaService implements MetaData { private List systemDatabases = Arrays.asList("information_schema", "performance_schema", "mysql", "sys"); + @Override public List databases(Connection connection) { List databases = SQLExecutor.getInstance().databases(connection); - return sortDatabase(databases,systemDatabases,connection); + return sortDatabase(databases, systemDatabases, connection); } @@ -57,19 +58,25 @@ public static String format(String tableName) { public Function function(Connection connection, @NotEmpty String databaseName, String schemaName, String functionName) { - String sql = String.format(ROUTINES_SQL, "FUNCTION", databaseName, functionName); - return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { - Function function = new Function(); - function.setDatabaseName(databaseName); - function.setSchemaName(schemaName); - function.setFunctionName(functionName); + String functionInfoSql = String.format(ROUTINES_SQL, "FUNCTION", databaseName, functionName); + Function function = SQLExecutor.getInstance().execute(connection, functionInfoSql, resultSet -> { + Function f = new Function(); + f.setDatabaseName(databaseName); + f.setSchemaName(schemaName); + f.setFunctionName(functionName); if (resultSet.next()) { - function.setSpecificName(resultSet.getString("SPECIFIC_NAME")); - function.setRemarks(resultSet.getString("ROUTINE_COMMENT")); - function.setFunctionBody(resultSet.getString("ROUTINE_DEFINITION")); + f.setSpecificName(resultSet.getString("SPECIFIC_NAME")); + f.setRemarks(resultSet.getString("ROUTINE_COMMENT")); } - return function; + return f; }); + String functionDDlSql =String.format("SHOW CREATE FUNCTION %s", functionName); + SQLExecutor.getInstance().execute(connection,functionDDlSql, resultSet -> { + if (resultSet.next()) { + function.setFunctionBody(resultSet.getString("Create Function")); + } + } ); + return function; } @@ -113,22 +120,42 @@ public Trigger trigger(Connection connection, @NotEmpty String databaseName, Str }); } + @Override + public List procedures(Connection connection, String databaseName, String schemaName) { + String sql = "SHOW PROCEDURE STATUS WHERE Db = DATABASE()"; + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + ArrayList procedures = new ArrayList<>(); + Procedure procedure = new Procedure(); + while (resultSet.next()){ + procedure.setProcedureName(resultSet.getString("Name")); + procedures.add(procedure); + } + return procedures; + }); + } + @Override public Procedure procedure(Connection connection, @NotEmpty String databaseName, String schemaName, String procedureName) { - String sql = String.format(ROUTINES_SQL, "PROCEDURE", databaseName, procedureName); - return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { - Procedure procedure = new Procedure(); - procedure.setDatabaseName(databaseName); - procedure.setSchemaName(schemaName); - procedure.setProcedureName(procedureName); + String routinesSql = String.format(ROUTINES_SQL, "PROCEDURE", databaseName, procedureName); + String showCreateProcedureSql = "SHOW CREATE PROCEDURE " + procedureName; + Procedure procedure = SQLExecutor.getInstance().execute(connection, routinesSql, resultSet -> { + Procedure p = new Procedure(); + p.setDatabaseName(databaseName); + p.setSchemaName(schemaName); + p.setProcedureName(procedureName); + if (resultSet.next()) { + p.setSpecificName(resultSet.getString("SPECIFIC_NAME")); + p.setRemarks(resultSet.getString("ROUTINE_COMMENT")); + } + return p; + }); + SQLExecutor.getInstance().execute(connection, showCreateProcedureSql, resultSet -> { if (resultSet.next()) { - procedure.setSpecificName(resultSet.getString("SPECIFIC_NAME")); - procedure.setRemarks(resultSet.getString("ROUTINE_COMMENT")); - procedure.setProcedureBody(resultSet.getString("ROUTINE_DEFINITION")); + procedure.setProcedureBody(resultSet.getString("Create Procedure")); } - return procedure; }); + return procedure; } private static String SELECT_TABLE_COLUMNS = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s' order by ORDINAL_POSITION"; @@ -187,21 +214,18 @@ private void setColumnSize(TableColumn column, String columnType) { } } - - private static String VIEW_SQL - = "SELECT TABLE_SCHEMA AS DatabaseName, TABLE_NAME AS ViewName, VIEW_DEFINITION AS definition, CHECK_OPTION, " - + "IS_UPDATABLE FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s';"; + private static String VIEW_DDL_SQL="show create view %s"; @Override public Table view(Connection connection, String databaseName, String schemaName, String viewName) { - String sql = String.format(VIEW_SQL, databaseName, viewName); + String sql = String.format(VIEW_DDL_SQL, viewName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { Table table = new Table(); table.setDatabaseName(databaseName); table.setSchemaName(schemaName); table.setName(viewName); if (resultSet.next()) { - table.setDdl(resultSet.getString("definition")); + table.setDdl(resultSet.getString("Create View")); } return table; }); @@ -297,4 +321,10 @@ public String getMetaDataName(String... names) { public ValueHandler getValueHandler() { return new MysqlValueHandler(); } + + @Override + public List getSystemDatabases() { + return systemDatabases; + } + } diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/builder/MysqlSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/builder/MysqlSqlBuilder.java index 1a97c843b..1b84c41bc 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/builder/MysqlSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/builder/MysqlSqlBuilder.java @@ -11,12 +11,10 @@ import cn.hutool.core.util.ArrayUtil; import org.apache.commons.lang3.StringUtils; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import java.util.*; -public class MysqlSqlBuilder extends DefaultSqlBuilder implements SqlBuilder { +public class MysqlSqlBuilder extends DefaultSqlBuilder { @Override public String buildCreateTableSql(Table table) { StringBuilder script = new StringBuilder(); @@ -163,21 +161,29 @@ public String buildGenerateReorderColumnSql(Table oldTable, Table newTable) { String[] oldColumnArray = oldTable.getColumnList().stream().map(TableColumn::getName).toArray(String[]::new); String[] newColumnArray = newTable.getColumnList().stream().map(TableColumn::getName).toArray(String[]::new); + Set oldColumnSet = new HashSet<>(Arrays.asList(oldColumnArray)); + Set newColumnSet = new HashSet<>(Arrays.asList(newColumnArray)); + if (!oldColumnSet.equals(newColumnSet)) { + return ""; + } + buildSql(oldColumnArray, newColumnArray, sql, oldTable, newTable, n); return sql.toString(); } private String[] buildSql(String[] originalArray, String[] targetArray, StringBuilder sql, Table oldTable, Table newTable, int n) { - // 先完成首位移动 + // Complete the first move first if (!originalArray[0].equals(targetArray[0])) { int a = findIndex(originalArray, targetArray[0]); TableColumn column = oldTable.getColumnList().stream().filter(col -> StringUtils.equals(col.getName(), originalArray[a])).findFirst().get(); String[] newArray = moveElement(originalArray, a, 0); - System.out.println(ArrayUtil.toString(newArray)); sql.append(" MODIFY COLUMN "); MysqlColumnTypeEnum typeEnum = MysqlColumnTypeEnum.getByType(column.getColumnType()); sql.append(typeEnum.buildColumn(column)); + if (StringUtils.isNotBlank(column.getComment())) { + sql.append(" COMMENT '").append(column.getComment()).append("'"); + } sql.append(" FIRST;\n"); n++; if (Arrays.equals(newArray, targetArray)) { @@ -189,14 +195,13 @@ private String[] buildSql(String[] originalArray, String[] targetArray, StringBu } } - // 在完成最后一位移动 + // After completing the last move int max = originalArray.length - 1; if (!originalArray[max].equals(targetArray[max])) { int a = findIndex(originalArray, targetArray[max]); //System.out.println("Move " + originalArray[a] + " after " + (a > 0 ? originalArray[max] : "start")); TableColumn column = oldTable.getColumnList().stream().filter(col -> StringUtils.equals(col.getName(), originalArray[a])).findFirst().get(); String[] newArray = moveElement(originalArray, a, max); - System.out.println(ArrayUtil.toString(newArray)); if (n > 0) { sql.append("ALTER TABLE "); if (StringUtils.isNotBlank(oldTable.getDatabaseName())) { @@ -207,7 +212,9 @@ private String[] buildSql(String[] originalArray, String[] targetArray, StringBu sql.append(" MODIFY COLUMN "); MysqlColumnTypeEnum typeEnum = MysqlColumnTypeEnum.getByType(column.getColumnType()); sql.append(typeEnum.buildColumn(column)); - sql.append(" "); + if (StringUtils.isNotBlank(column.getComment())) { + sql.append(" COMMENT '").append(column.getComment()).append("'"); + } sql.append(" AFTER "); sql.append(oldTable.getColumnList().get(max).getName()); sql.append(";\n"); @@ -225,7 +232,7 @@ private String[] buildSql(String[] originalArray, String[] targetArray, StringBu for (int i = 0; i < originalArray.length; i++) { int a = findIndex(targetArray, originalArray[i]); if (i != a && isMoveValid(originalArray, targetArray, i, a)) { - // oldTable.getColumnList中查找name为a + // Find name a in oldTable.getColumnList int finalI = i; TableColumn column = oldTable.getColumnList().stream().filter(col -> StringUtils.equals(col.getName(), originalArray[finalI])).findFirst().get(); if (n > 0) { @@ -238,7 +245,9 @@ private String[] buildSql(String[] originalArray, String[] targetArray, StringBu sql.append(" MODIFY COLUMN "); MysqlColumnTypeEnum typeEnum = MysqlColumnTypeEnum.getByType(column.getColumnType()); sql.append(typeEnum.buildColumn(column)); - sql.append(" "); + if (StringUtils.isNotBlank(column.getComment())) { + sql.append(" COMMENT '").append(column.getComment()).append("'"); + } sql.append(" AFTER "); if (i < a) { sql.append(originalArray[a]); @@ -271,7 +280,6 @@ private static int findIndex(String[] array, String element) { } private static boolean isMoveValid(String[] originalArray, String[] targetArray, int i, int a) { - System.out.println("i : " + i + " a:" + a); return (i == 0 || a == 0 || !originalArray[i - 1].equals(targetArray[a - 1])) && (i >= originalArray.length - 1 || a >= targetArray.length - 1 || !originalArray[i + 1].equals(targetArray[a + 1])); } @@ -286,7 +294,6 @@ private static String[] moveElement(String[] originalArray, int from, int to) { System.arraycopy(originalArray, to, newArray, to + 1, from - to); } newArray[to] = temp; - System.out.println(ArrayUtil.toString(newArray)); return newArray; } diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/mysql.json b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/mysql.json index 5c720fa70..93ed97ba9 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/mysql.json +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/mysql.json @@ -8,7 +8,7 @@ "defaultDriver": true, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/mysql-connector-java-8.0.30.jar" + "https://cdn.chat2db-ai.com/lib/mysql-connector-java-8.0.30.jar" ], "jdbcDriver": "mysql-connector-java-8.0.30.jar", "jdbcDriverClass": "com.mysql.cj.jdbc.Driver", @@ -25,7 +25,7 @@ "defaultDriver": false, "custom": false, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/mysql-connector-java-5.1.47.jar" + "https://cdn.chat2db-ai.com/lib/mysql-connector-java-5.1.47.jar" ], "jdbcDriver": "mysql-connector-java-5.1.47.jar", "jdbcDriverClass": "com.mysql.jdbc.Driver", diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java index c6ed4175b..a26b73b0f 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java @@ -327,6 +327,9 @@ public String buildColumn(TableColumn column) { script.append("`").append(column.getName()).append("`").append(" "); script.append(buildDataType(column, type)).append(" "); + if (StringUtils.isNoneBlank(column.getComment())) { + script.append("COMMENT").append(" ").append("'").append(column.getComment()).append("'").append(" "); + } return script.toString(); } diff --git a/chat2db-server/chat2db-plugins/chat2db-oceanbase/pom.xml b/chat2db-server/chat2db-plugins/chat2db-oceanbase/pom.xml index a528fe2ab..f27394b1a 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oceanbase/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-oceanbase/pom.xml @@ -23,7 +23,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-oceanbase/src/main/java/ai/chat2db/plugin/oceanbase/oceanbase.json b/chat2db-server/chat2db-plugins/chat2db-oceanbase/src/main/java/ai/chat2db/plugin/oceanbase/oceanbase.json index 103102d6f..cdf3cee52 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oceanbase/src/main/java/ai/chat2db/plugin/oceanbase/oceanbase.json +++ b/chat2db-server/chat2db-plugins/chat2db-oceanbase/src/main/java/ai/chat2db/plugin/oceanbase/oceanbase.json @@ -8,7 +8,7 @@ "custom": false, "defaultDriver": true, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/oceanbase-client-2.4.2.jar" + "https://cdn.chat2db-ai.com/lib/oceanbase-client-2.4.2.jar" ], "jdbcDriver": "oceanbase-client-2.4.2.jar", "jdbcDriverClass": "com.oceanbase.jdbc.Driver" diff --git a/chat2db-server/chat2db-plugins/chat2db-oracle/pom.xml b/chat2db-server/chat2db-plugins/chat2db-oracle/pom.xml index 7ddfb92b9..5136fde29 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oracle/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-oracle/pom.xml @@ -24,7 +24,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleDBManage.java b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleDBManage.java index 6d246a786..728177b1f 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleDBManage.java @@ -1,8 +1,5 @@ package ai.chat2db.plugin.oracle; -import java.sql.Connection; -import java.sql.SQLException; - import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; import ai.chat2db.spi.sql.Chat2DBContext; @@ -11,7 +8,188 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.Objects; + public class OracleDBManage extends DefaultDBManage implements DBManage { + private static String TABLE_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('TABLE', table_name) as ddl FROM all_tables WHERE owner = '%s' AND table_name = '%s'"; + private static String TABLE_COMMENT_SQL = "SELECT 'COMMENT ON TABLE ' || table_name || ' IS ''' || comments || ''';' AS table_comment_ddl FROM user_tab_comments WHERE table_name = '%s'"; + private static String TABLE_COLUMN_COMMENT_SQL = "SELECT 'COMMENT ON COLUMN ' || table_name || '.' || column_name || ' IS ''' || comments || ''';' AS column_comment_ddl " + + "FROM user_col_comments " + + "WHERE table_name = '%s' " + + "AND comments IS NOT NULL"; + private static String VIEW_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('VIEW', view_name) as ddl FROM all_views WHERE owner = '%s' AND view_name = '%s'"; + private String PROCEDURE_LIST_DDL ="SELECT object_name FROM all_procedures where OWNER = '%s' and OBJECT_TYPE='PROCEDURE'"; + private static String PROCEDURE_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('PROCEDURE', object_name) as ddl FROM all_procedures WHERE owner = '%s' AND object_name = '%s'"; + private static String TRIGGER_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('TRIGGER', trigger_name) AS ddl FROM all_triggers WHERE owner = '%s' AND trigger_name = '%s'"; + private static String FUNCTION_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('FUNCTION', object_name) as ddl FROM all_procedures WHERE owner = '%s' AND object_name = '%s'"; + + @Override + public String exportDatabaseData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTableData(connection, tableName, sqlBuilder); + return sqlBuilder.toString(); + } + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTables(connection, schemaName, sqlBuilder, containData); + exportViews(connection, sqlBuilder, schemaName); + exportProcedures(connection, schemaName, sqlBuilder); + exportTriggers(connection, schemaName, sqlBuilder); + exportFunctions(connection, schemaName, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportTables(Connection connection, String schemaName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(null, schemaName, null, new String[]{"TABLE", "SYSTEM TABLE"})) { + while (resultSet.next()) { + String tableName = resultSet.getString("TABLE_NAME"); + exportTable(connection, schemaName, tableName, sqlBuilder, containData); + } + } + } + + + private void exportTable(Connection connection, String schemaName, String tableName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + String sql = String.format(TABLE_DDL_SQL, schemaName, tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP TABLE ").append(schemaName).append(".").append(tableName).append(";") + .append(resultSet.getString("ddl")).append(";").append("\n"); + } + exportTableComments(connection, tableName, sqlBuilder); + exportTableColumnsComments(connection, tableName, sqlBuilder); + if (containData) { + exportTableData(connection, tableName, sqlBuilder); + } + } + } + + private void exportTableComments(Connection connection, String tableName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(TABLE_COMMENT_SQL, tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("table_comment_ddl")).append("\n"); + } + } + sqlBuilder.append("\n"); + } + + private void exportTableColumnsComments(Connection connection, String tableName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(TABLE_COLUMN_COMMENT_SQL, tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + sqlBuilder.append(resultSet.getString("column_comment_ddl")).append("\n"); + } + } + sqlBuilder.append("\n"); + } + + private void exportTableData(Connection connection, String tableName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT * FROM %s", tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + ResultSetMetaData metaData = resultSet.getMetaData(); + int columnCount = metaData.getColumnCount(); + while (resultSet.next()) { + sqlBuilder.append("INSERT INTO ").append(tableName).append(" VALUES ("); + for (int i = 1; i <= columnCount; i++) { + String columnValue = resultSet.getString(i); + if (Objects.isNull(columnValue)) { + sqlBuilder.append("NULL"); + } else if (metaData.getColumnTypeName(i).equalsIgnoreCase("DATE")) { + // 处理日期值格式 + columnValue = "TO_DATE('" + columnValue + "', 'YYYY-MM-DD HH24:MI:SS')"; + sqlBuilder.append(columnValue); + } else { + sqlBuilder.append("'").append(columnValue).append("'"); + } + if (i < columnCount) { + sqlBuilder.append(", "); + } + } + sqlBuilder.append(");"); + sqlBuilder.append("\n"); + } + } + } + + private void exportViews(Connection connection, StringBuilder sqlBuilder, String schemaName) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(null, schemaName, null, new String[]{"VIEW"})) { + while (resultSet.next()) { + String viewName = resultSet.getString("TABLE_NAME"); + exportView(connection, sqlBuilder, schemaName, viewName); + } + } + } + + private void exportView(Connection connection, StringBuilder sqlBuilder, String schemaName, String viewName) throws SQLException { + String sql = String.format(VIEW_DDL_SQL, schemaName, viewName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("ddl")).append(";").append("\n"); + } + } + } + + private void exportProcedures(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(PROCEDURE_LIST_DDL,schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String procedureName = resultSet.getString("object_name"); + exportProcedure(connection, schemaName, procedureName, sqlBuilder); + } + } + } + + private void exportProcedure(Connection connection, String schemaName, String procedureName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(PROCEDURE_DDL_SQL, schemaName, procedureName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("ddl")).append("\n"); + } + } + } + + private void exportTriggers(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT TRIGGER_NAME FROM all_triggers where OWNER='%s'", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String triggerName = resultSet.getString("TRIGGER_NAME"); + exportTrigger(connection, schemaName, triggerName, sqlBuilder); + } + } + } + + private void exportTrigger(Connection connection, String schemaName, String triggerName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(TRIGGER_DDL_SQL, schemaName, triggerName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("ddl")).append(";").append("\n"); + } + } + } + + private void exportFunctions(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getFunctions(null, schemaName, null)) { + while (resultSet.next()) { + String functionName = resultSet.getString("FUNCTION_NAME"); + exportFunction(connection, schemaName, functionName, sqlBuilder); + } + } + } + + private void exportFunction(Connection connection, String schemaName, String functionName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format(FUNCTION_DDL_SQL, schemaName, functionName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("ddl")).append("\n"); + } + } + } + @Override public void connectDatabase(Connection connection, String database) { diff --git a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java index f86637f91..7a7c00171 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java @@ -27,6 +27,21 @@ public class OracleMetaData extends DefaultMetaService implements MetaData { private List systemSchemas = Arrays.asList("ANONYMOUS","APEX_030200","APEX_PUBLIC_USER","APPQOSSYS","BI","CTXSYS","DBSNMP","DIP","EXFSYS","FLOWS_FILES","HR","IX","MDDATA","MDSYS","MGMT_VIEW","OE","OLAPSYS","ORACLE_OCM","ORDDATA","ORDPLUGINS","ORDSYS","OUTLN","OWBSYS","OWBSYS_AUDIT","PM","SCOTT","SH","SI_INFORMTN_SCHEMA","SPATIAL_CSW_ADMIN_USR","SPATIAL_WFS_ADMIN_USR","SYS","SYSMAN","SYSTEM","WMSYS","XDB","XS$NULL"); + private String PROCEDURE_LIST_DDL ="SELECT object_name FROM all_procedures where OWNER = '%s' and OBJECT_TYPE='PROCEDURE'"; + + @Override + public List procedures(Connection connection, String databaseName, String schemaName) { + String sql = String.format(PROCEDURE_LIST_DDL,schemaName); + ArrayList procedures = new ArrayList<>(); + SQLExecutor.getInstance().execute(connection, sql, resultSet->{ + while (resultSet.next()) { + Procedure procedure = new Procedure(); + procedure.setProcedureName(resultSet.getString("object_name")); + procedures.add(procedure); + } + }); + return procedures; + } @Override public List schemas(Connection connection, String databaseName) { @@ -103,7 +118,7 @@ public List columns(Connection connection, String databaseName, Str tableColumn.setName(resultSet.getString("COLUMN_NAME")); tableColumn.setColumnType(resultSet.getString("DATA_TYPE")); Integer dataPrecision = resultSet.getInt("DATA_PRECISION"); - if(dataPrecision!=null) { + if(resultSet.getString("DATA_PRECISION") != null) { tableColumn.setColumnSize(dataPrecision); }else { tableColumn.setColumnSize(resultSet.getInt("DATA_LENGTH")); @@ -132,27 +147,19 @@ public List columns(Connection connection, String databaseName, Str }); } - private static String ROUTINES_SQL - = "SELECT LINE, TEXT " - + "FROM ALL_SOURCE " - + "WHERE TYPE = '%s' AND NAME = '%s' " - + "ORDER BY LINE"; - + private static String FUNCTION_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('FUNCTION', object_name) as ddl FROM all_procedures WHERE owner = '%s' AND object_name = '%s'"; @Override public Function function(Connection connection, @NotEmpty String databaseName, String schemaName, String functionName) { - - String sql = String.format(ROUTINES_SQL, "FUNCTION", functionName); + String sql = String.format(FUNCTION_DDL_SQL, schemaName, functionName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { - StringBuilder sb = new StringBuilder(); - while (resultSet.next()) { - sb.append(resultSet.getString("TEXT") + "\n"); - } Function function = new Function(); function.setDatabaseName(databaseName); function.setSchemaName(schemaName); function.setFunctionName(functionName); - function.setFunctionBody(sb.toString()); + if (resultSet.next()) { + function.setFunctionBody(resultSet.getString("ddl")); + } return function; }); @@ -242,8 +249,9 @@ public List triggers(Connection connection, String databaseName, String return SQLExecutor.getInstance().execute(connection, String.format(TRIGGER_SQL_LIST, schemaName), resultSet -> { while (resultSet.next()) { + String triggerName = resultSet.getString("TRIGGER_NAME"); Trigger trigger = new Trigger(); - trigger.setTriggerName(resultSet.getString("TRIGGER_NAME")); + trigger.setTriggerName(triggerName==null?"":triggerName.trim()); trigger.setSchemaName(schemaName); trigger.setDatabaseName(databaseName); triggers.add(trigger); @@ -251,57 +259,54 @@ public List triggers(Connection connection, String databaseName, String return triggers; }); } - + private static String TRIGGER_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('TRIGGER', trigger_name) AS ddl FROM all_triggers WHERE owner = '%s' AND trigger_name = '%s'"; @Override public Trigger trigger(Connection connection, @NotEmpty String databaseName, String schemaName, String triggerName) { - String sql = String.format(ROUTINES_SQL, "TRIGGER", triggerName); + + String sql = String.format(TRIGGER_DDL_SQL, schemaName, triggerName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { - StringBuilder sb = new StringBuilder(); - while (resultSet.next()) { - sb.append(resultSet.getString("TEXT") + "\n"); - } Trigger trigger = new Trigger(); trigger.setDatabaseName(databaseName); trigger.setSchemaName(schemaName); trigger.setTriggerName(triggerName); - trigger.setTriggerBody(resultSet.getString(sb.toString())); + if (resultSet.next()) { + trigger.setTriggerBody(resultSet.getString("ddl")); + } return trigger; }); } - + private static String PROCEDURE_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('PROCEDURE', object_name) as ddl FROM all_procedures WHERE owner = '%s' AND object_name = '%s'"; @Override public Procedure procedure(Connection connection, @NotEmpty String databaseName, String schemaName, String procedureName) { - String sql = String.format(ROUTINES_SQL, "PROCEDURE", procedureName); + String sql = String.format(PROCEDURE_DDL_SQL, schemaName, procedureName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { - StringBuilder sb = new StringBuilder(); - while (resultSet.next()) { - sb.append(resultSet.getString("TEXT") + "\n"); - } Procedure procedure = new Procedure(); - procedure.setDatabaseName(databaseName); - procedure.setSchemaName(schemaName); - procedure.setProcedureName(procedureName); - procedure.setProcedureBody(sb.toString()); + if (resultSet.next()) { + procedure.setDatabaseName(databaseName); + procedure.setSchemaName(schemaName); + procedure.setProcedureName(procedureName); + procedure.setProcedureBody(resultSet.getString("ddl")); + } return procedure; }); } - private static String VIEW_SQL - = "SELECT VIEW_NAME, TEXT FROM ALL_VIEWS WHERE OWNER = '%s' AND VIEW_NAME = '%s'"; + + private static String VIEW_DDL_SQL = "SELECT DBMS_METADATA.GET_DDL('VIEW', view_name) as ddl FROM all_views WHERE owner = '%s' AND view_name = '%s'"; @Override public Table view(Connection connection, String databaseName, String schemaName, String viewName) { - String sql = String.format(VIEW_SQL, schemaName, viewName); + String sql = String.format(VIEW_DDL_SQL, schemaName, viewName); return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { Table table = new Table(); table.setDatabaseName(databaseName); table.setSchemaName(schemaName); table.setName(viewName); if (resultSet.next()) { - table.setDdl(resultSet.getString("TEXT")); + table.setDdl(resultSet.getString("ddl")); } return table; }); @@ -327,4 +332,10 @@ public TableMeta getTableMeta(String databaseName, String schemaName, String tab public String getMetaDataName(String... names) { return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "\"" + name + "\"").collect(Collectors.joining(".")); } + + + @Override + public List getSystemSchemas() { + return systemSchemas; + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/builder/OracleSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/builder/OracleSqlBuilder.java index 468ac2027..57d9b4a3f 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/builder/OracleSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/builder/OracleSqlBuilder.java @@ -2,14 +2,13 @@ import ai.chat2db.plugin.oracle.type.OracleColumnTypeEnum; import ai.chat2db.plugin.oracle.type.OracleIndexTypeEnum; -import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.jdbc.DefaultSqlBuilder; import ai.chat2db.spi.model.Table; import ai.chat2db.spi.model.TableColumn; import ai.chat2db.spi.model.TableIndex; import org.apache.commons.lang3.StringUtils; -public class OracleSqlBuilder extends DefaultSqlBuilder implements SqlBuilder { +public class OracleSqlBuilder extends DefaultSqlBuilder { @Override public String buildCreateTableSql(Table table) { StringBuilder script = new StringBuilder(); diff --git a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/oracle.json b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/oracle.json index e2ae89fb6..adb455ed2 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/oracle.json +++ b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/oracle.json @@ -8,8 +8,8 @@ "custom": false, "defaultDriver": true, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/ojdbc8-19.3.0.0.jar", - "https://oss.sqlgpt.cn/lib/orai18n-19.3.0.0.jar" + "https://cdn.chat2db-ai.com/lib/ojdbc8-19.3.0.0.jar", + "https://cdn.chat2db-ai.com/lib/orai18n-19.3.0.0.jar" ], "jdbcDriver": "ojdbc8-19.3.0.0.jar,orai18n-19.3.0.0.jar", "jdbcDriverClass": "oracle.jdbc.driver.OracleDriver" diff --git a/chat2db-server/chat2db-plugins/chat2db-postgresql/pom.xml b/chat2db-server/chat2db-plugins/chat2db-postgresql/pom.xml index 1006e9896..d5383408c 100644 --- a/chat2db-server/chat2db-plugins/chat2db-postgresql/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-postgresql/pom.xml @@ -24,7 +24,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLDBManage.java b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLDBManage.java index 43d9a2714..123e7128f 100644 --- a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLDBManage.java @@ -1,7 +1,5 @@ package ai.chat2db.plugin.postgresql; -import java.sql.Connection; - import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; import ai.chat2db.spi.sql.Chat2DBContext; @@ -9,7 +7,96 @@ import ai.chat2db.spi.sql.SQLExecutor; import org.apache.commons.lang3.StringUtils; +import java.sql.*; +import java.util.ArrayList; +import java.util.Objects; + +import static ai.chat2db.plugin.postgresql.consts.SQLConst.*; + public class PostgreSQLDBManage extends DefaultDBManage implements DBManage { + + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTypes(connection, sqlBuilder); + exportTables(connection, databaseName, schemaName, sqlBuilder, containData); + exportViews(connection, schemaName, sqlBuilder); + exportFunctions(connection, schemaName, sqlBuilder); + exportTriggers(connection, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportTypes(Connection connection, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.createStatement().executeQuery(ENUM_TYPE_DDL_SQL)) { + while (resultSet.next()) { + sqlBuilder.append(resultSet.getString("ddl")).append("\n"); + } + } + } + private void exportTables(Connection connection, String databaseName, String schemaName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, schemaName, null, + new String[]{"TABLE", "SYSTEM TABLE","PARTITIONED TABLE"})) { + ArrayList tableNames = new ArrayList<>(); + while (resultSet.next()) { + String tableName = resultSet.getString("TABLE_NAME"); + tableNames.add(tableName); + } + for (String tableName : tableNames) { + exportTable(connection, schemaName, tableName, sqlBuilder); + } + if (containData) { + for (String tableName : tableNames) { + exportTableData(connection, schemaName, tableName, sqlBuilder); + } + } + } + } + + private void exportTable(Connection connection, String schemaName, String tableName, StringBuilder sqlBuilder) throws SQLException { + String sql =String.format( "select pg_get_tabledef('%s','%s',true,'COMMENTS') as ddl;", schemaName,tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("\n").append("DROP TABLE IF EXISTS ").append(tableName).append(";").append("\n") + .append(resultSet.getString("ddl")).append("\n"); + } + } + } + + + + private void exportViews(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + + String sql = String.format("SELECT table_name, view_definition FROM information_schema.views WHERE table_schema = '%s'",schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String viewName = resultSet.getString("table_name"); + String viewDefinition = resultSet.getString("view_definition"); + sqlBuilder.append("CREATE OR REPLACE VIEW ").append(viewName).append(" AS ").append(viewDefinition).append("\n"); + } + } + } + + private void exportFunctions(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT proname, pg_get_functiondef(oid) AS function_definition FROM pg_proc " + + "WHERE pronamespace = (SELECT oid FROM pg_namespace WHERE nspname = '%s')", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String functionName = resultSet.getString("proname"); + String functionDefinition = resultSet.getString("function_definition"); + sqlBuilder.append("DROP FUNCTION IF EXISTS ").append(schemaName).append(".").append(functionName).append(";\n"); + sqlBuilder.append(functionDefinition).append(";\n\n"); + } + } + } + + private void exportTriggers(Connection connection, StringBuilder sqlBuilder) throws SQLException { + String sql = "SELECT pg_get_triggerdef(oid) AS trigger_definition FROM pg_trigger"; + try (Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(sql)) { + while (resultSet.next()) { + sqlBuilder.append(resultSet.getString("trigger_definition")).append(";").append("\n"); + } + } + } + @Override public void connectDatabase(Connection connection, String database) { try { @@ -36,20 +123,20 @@ public Connection getConnection(ConnectInfo connectInfo) { public String replaceDatabaseInJdbcUrl(String url, String newDatabase) { - // 先在"?"字符处分割字符串,处理查询参数 + // First split the string at the "?" character and process the query parameters String[] urlAndParams = url.split("\\?"); String urlWithoutParams = urlAndParams[0]; - // 在URL中的"/"字符处分割字符串 + // Split string at "/" character in URL String[] parts = urlWithoutParams.split("/"); - // 取最后一部分,即数据库名,并替换为新的数据库名 + // Take the last part, the database name, and replace it with the new database name parts[parts.length - 1] = newDatabase; - // 将修改后的部分重新组合成URL + // Reassemble the modified parts into a URL String newUrlWithoutParams = String.join("/", parts); - // 如果存在查询参数,重新添加 + // If query parameters exist, add them again String newUrl = urlAndParams.length > 1 ? newUrlWithoutParams + "?" + urlAndParams[1] : newUrlWithoutParams; return newUrl; diff --git a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLMetaData.java b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLMetaData.java index 0e7729571..5e9d68978 100644 --- a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/PostgreSQLMetaData.java @@ -102,13 +102,12 @@ public List triggers(Connection connection, String databaseName, String @Override public String tableDDL(Connection connection, String databaseName, String schemaName, String tableName) { - SQLExecutor.getInstance().execute(connection, FUNCTION_SQL.replaceFirst("tableSchema", schemaName), - resultSet -> null); - String ddlSql = "select showcreatetable('" + schemaName + "','" + tableName + "') as sql"; + SQLExecutor.getInstance().execute(connection, FUNCTION_SQL, resultSet -> null); + String ddlSql = "select pg_get_tabledef" + "(" + "'" + schemaName + "'" + "," + "'" + tableName + "'" + "," + "false" + "," + "'" + "COMMENTS" + "'" + ")" + ";"; return SQLExecutor.getInstance().execute(connection, ddlSql, resultSet -> { try { if (resultSet.next()) { - return resultSet.getString("sql"); + return resultSet.getString(1); } } catch (SQLException e) { throw new RuntimeException(e); @@ -306,4 +305,14 @@ public TableMeta getTableMeta(String databaseName, String schemaName, String tab public String getMetaDataName(String... names) { return Arrays.stream(names).filter(name -> StringUtils.isNotBlank(name)).map(name -> "\"" + name + "\"").collect(Collectors.joining(".")); } + + @Override + public List getSystemDatabases() { + return systemDatabases; + } + + @Override + public List getSystemSchemas() { + return systemSchemas; + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/builder/PostgreSQLSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/builder/PostgreSQLSqlBuilder.java index e0d90a517..34a856cb7 100644 --- a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/builder/PostgreSQLSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/builder/PostgreSQLSqlBuilder.java @@ -2,7 +2,6 @@ import ai.chat2db.plugin.postgresql.type.PostgreSQLColumnTypeEnum; import ai.chat2db.plugin.postgresql.type.PostgreSQLIndexTypeEnum; -import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.jdbc.DefaultSqlBuilder; import ai.chat2db.spi.model.*; import org.apache.commons.collections4.CollectionUtils; @@ -14,7 +13,7 @@ import java.util.stream.Collectors; -public class PostgreSQLSqlBuilder extends DefaultSqlBuilder implements SqlBuilder { +public class PostgreSQLSqlBuilder extends DefaultSqlBuilder { @Override public String buildCreateTableSql(Table table) { StringBuilder script = new StringBuilder(); diff --git a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/consts/SQLConst.java b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/consts/SQLConst.java index 9d73d2cb9..276f59614 100644 --- a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/consts/SQLConst.java +++ b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/consts/SQLConst.java @@ -2,152 +2,689 @@ public class SQLConst { public static String FUNCTION_SQL = - " CREATE OR REPLACE FUNCTION showcreatetable(namespace character varying, tablename character " - + "varying)\n" - + " RETURNS character varying AS\n" - + "\n" - + " $BODY$\n" - + " declare\n" - + " tableScript character varying default '';\n" - + "\n" - + " begin\n" - + " -- columns\n" - + " tableScript:=tableScript || ' CREATE TABLE '|| tablename|| ' ( '|| chr(13)||chr(10) || " - + "array_to_string" - + "(\n" - + " array(\n" - + " select ' ' || concat_ws(' ',fieldName, fieldType, defaultValue, isNullStr" - + " ) as " - + "column_line\n" - + " from (\n" - + " select a.attname as fieldName,format_type(a.atttypid,a.atttypmod) as fieldType," - + " CASE WHEN \n" - + " (SELECT substring(pg_catalog.pg_get_expr(B.adbin, B.adrelid) for 128)\n" - + " FROM pg_catalog.pg_attrdef B WHERE B.adrelid = A.attrelid AND B.adnum = A.attnum AND A.atthasdef) IS NOT NULL THEN\n" - + " 'DEFAULT '|| (SELECT substring(pg_catalog.pg_get_expr(B.adbin, B.adrelid) for 128)\n" - + " FROM pg_catalog.pg_attrdef B WHERE B.adrelid = A.attrelid AND B.adnum = A.attnum AND A.atthasdef)\n" - + " ELSE\n" - + " ''\n" - + " END as defaultValue," - + " (case when a.attnotnull=true then 'not null' else 'null' end) as isNullStr\n" - + " from pg_attribute a where attstattarget=-1 and attrelid = (select c.oid from pg_class c," - + "pg_namespace n" - + " where\n" - + " c.relnamespace=n.oid and n.nspname =namespace and relname =tablename)\n" - + "\n" - + " ) as string_columns\n" - + " ),','||chr(13)||chr(10)) || ',';\n" - + "\n" - + "\n" - + " -- 约束\n" - + " tableScript:= tableScript || chr(13)||chr(10) || array_to_string(\n" - + " array(\n" - + " select concat(' CONSTRAINT ',conname ,c ,u,p,f) from (\n" - + " select conname,\n" - + " case when contype='c' then ' CHECK('|| ( select findattname(namespace,tablename,'c') ) ||')' " - + "end " - + "as c " - + ",\n" - + " case when contype='u' then ' UNIQUE('|| ( select findattname(namespace,tablename,'u') ) ||')' " - + "end " - + "as u" - + " ,\n" - + " case when contype='p' then ' PRIMARY KEY ('|| ( select findattname(namespace,tablename,'p') ) " - + "||')' " - + "end as p ,\n" - + " case when contype='f' then ' FOREIGN KEY('|| ( select findattname(namespace,tablename,'u') ) " - + "||') " - + "REFERENCES '||\n" - + " (select p.relname from pg_class p where p.oid=c.confrelid ) || '('|| ( select\n" - + " findattname(namespace,tablename,'u') ) ||')' end as f\n" - + " from pg_constraint c\n" - + " where contype in('u','c','f','p') and conrelid=(\n" - + " select oid from pg_class where relname=tablename and relnamespace =(\n" - + " select oid from pg_namespace where nspname = namespace\n" - + " )\n" - + " )\n" - + " ) as t\n" - + " ) ,',' || chr(13)||chr(10) ) || chr(13)||chr(10) ||' ); ';\n" - + "\n" - + " -- indexs\n" - + " -- CREATE UNIQUE INDEX pg_language_oid_index ON pg_language USING btree (oid); -- table " - + "pg_language\n" - + "\n" - + "\n" - + " --\n" - + " /** **/\n" - + " --- 获取非约束索引 column\n" - + " -- CREATE UNIQUE INDEX pg_language_oid_index ON pg_language USING btree (oid); -- table " - + "pg_language\n" - + " tableScript:= tableScript || chr(13)||chr(10) || chr(13)||chr(10) || array_to_string(\n" - + " array(\n" - + " select 'CREATE INDEX ' || indexrelname || ' ON ' || tablename || ' USING btree '|| '(' || " - + "attname " - + "|| " - + "');' from (\n" - + " SELECT\n" - + " i.relname AS indexrelname , x.indkey,\n" - + "\n" - + " ( select array_to_string (\n" - + " array(\n" - + " select a.attname from pg_attribute a where attrelid=c.oid and a.attnum in ( select unnest(x" - + ".indkey) )\n" - + "\n" - + " )\n" - + " ,',' ) )as attname\n" - + "\n" - + " FROM pg_class c\n" - + " JOIN pg_index x ON c.oid = x.indrelid\n" - + " JOIN pg_class i ON i.oid = x.indexrelid\n" - + " LEFT JOIN pg_namespace n ON n.oid = c.relnamespace\n" - + " WHERE c.relname=tablename and i.relname not in\n" - + " ( select constraint_name from information_schema.key_column_usage where table_name=tablename )\n" - + " )as t\n" - + " ) ,','|| chr(13)||chr(10));\n" - + "\n" - + "\n" - + " -- COMMENT COMMENT ON COLUMN sys_activity.id IS '主键';\n" - + " tableScript:= tableScript || chr(13)||chr(10) || chr(13)||chr(10) || array_to_string(\n" - + " array(\n" - + " SELECT 'COMMENT ON COLUMN ' || 'namespace.tablename' || '.' || a.attname ||' IS '|| ''''|| d.description " - + "||''''\n" - + " FROM pg_class c\n" - + " JOIN pg_description d ON c.oid=d.objoid\n" - + " JOIN pg_attribute a ON c.oid = a.attrelid\n" - + " WHERE c.relname=tablename\n" - + " AND a.attnum = d.objsubid),';'|| chr(13)||chr(10)) ;\n" - + "\n" - + " return tableScript;\n" - + "\n" - + " end\n" - + " $BODY$ LANGUAGE plpgsql;\n" - + "\n" - + " CREATE OR REPLACE FUNCTION findattname(namespace character varying, tablename character " - + "varying, " - + "ctype" - + " character\n" - + " varying)\n" - + " RETURNS character varying as $BODY$\n" - + "\n" - + " declare\n" - + " tt oid ;\n" - + " aname character varying default '';\n" - + "\n" - + " begin\n" - + " tt := oid from pg_class where relname= tablename and relnamespace =(select oid from " - + "pg_namespace " - + "where\n" - + " nspname=namespace) ;\n" - + " aname:= array_to_string(\n" - + " array(\n" - + " select a.attname from pg_attribute a\n" - + " where a.attrelid=tt and a.attnum in (\n" - + " select unnest(conkey) from pg_constraint c where contype=ctype\n" - + " and conrelid=tt and array_to_string(conkey,',') is not null\n" - + " )\n" - + " ),',');\n" - + "\n" - + " return aname;\n" - + " end\n" - + " $BODY$ LANGUAGE plpgsql"; + """ + DROP TYPE IF EXISTS public.tabledefs CASCADE; + CREATE TYPE public.tabledefs AS ENUM ('PKEY_INTERNAL','PKEY_EXTERNAL','FKEYS_INTERNAL', 'FKEYS_EXTERNAL', 'COMMENTS', 'FKEYS_NONE', 'INCLUDE_TRIGGERS', 'NO_TRIGGERS'); + + -- SELECT * FROM public.pg_get_coldef('sample','orders','id'); + -- DROP FUNCTION public.pg_get_coldef(text,text,text,boolean); + CREATE OR REPLACE FUNCTION public.pg_get_coldef( + in_schema text, + in_table text, + in_column text, + oldway boolean default False + ) + RETURNS text + LANGUAGE plpgsql VOLATILE + AS + $$ + DECLARE + v_coldef text; + v_dt1 text; + v_dt2 text; + v_dt3 text; + v_nullable boolean; + v_position int; + v_identity text; + v_generated text; + v_hasdflt boolean; + v_dfltexpr text; + + BEGIN + IF oldway THEN + SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) INTO v_coldef FROM pg_namespace n, pg_class c, pg_attribute a, pg_type t + WHERE n.nspname = in_schema AND n.oid = c.relnamespace AND c.relname = in_table AND a.attname = in_column and a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid ORDER BY a.attnum; + -- RAISE NOTICE 'DEBUG: oldway=%',v_coldef; + ELSE + -- a.attrelid::regclass::text, a.attname + SELECT CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (SELECT FROM pg_attrdef ad WHERE ad.adrelid = a.attrelid AND ad.adnum = a.attnum AND + pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || (pg_get_serial_sequence (a.attrelid::regclass::text, a.attname))::regclass || '''::regclass)') THEN CASE a.atttypid + WHEN 'int'::regtype THEN 'serial' WHEN 'int8'::regtype THEN 'bigserial' WHEN 'int2'::regtype THEN 'smallserial' END ELSE format_type(a.atttypid, a.atttypmod) END AS data_type + INTO v_coldef FROM pg_namespace n, pg_class c, pg_attribute a, pg_type t + WHERE n.nspname = in_schema AND n.oid = c.relnamespace AND c.relname = in_table AND a.attname = in_column and a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid ORDER BY a.attnum; + -- RAISE NOTICE 'DEBUG: newway=%',v_coldef; + + -- Issue#24: not implemented yet + -- might replace with this below to do more detailed parsing... + -- SELECT a.atttypid::regtype AS dt1, format_type(a.atttypid, a.atttypmod) as dt2, t.typname as dt3, CASE WHEN not(a.attnotnull) THEN True ELSE False END AS nullable, + -- a.attnum, a.attidentity, a.attgenerated, a.atthasdef, pg_get_expr(ad.adbin, ad.adrelid) dfltexpr + -- INTO v_dt1, v_dt2, v_dt3, v_nullable, v_position, v_identity, v_generated, v_hasdflt, v_dfltexpr + -- FROM pg_attribute a JOIN pg_class c ON (a.attrelid = c.oid) JOIN pg_type t ON (a.atttypid = t.oid) LEFT JOIN pg_attrdef ad ON (a.attrelid = ad.adrelid AND a.attnum = ad.adnum) + -- WHERE c.relkind in ('r','p') AND a.attnum > 0 AND NOT a.attisdropped AND c.relnamespace::regnamespace::text = in_schema AND c.relname = in_table AND a.attname = in_column; + -- RAISE NOTICE 'schema=% table=% column=% dt1=% dt2=% dt3=% nullable=% pos=% identity=% generated=% HasDefault=% DeftExpr=%', in_schema, in_table, in_column, v_dt1,v_dt2,v_dt3,v_nullable,v_position,v_identity,v_generated,v_hasdflt,v_dfltexpr; + END IF; + RETURN v_coldef; + END; + $$; + + -- SELECT * FROM public.pg_get_tabledef('sample', 'address', false); + DROP FUNCTION IF EXISTS public.pg_get_tabledef(character varying,character varying,boolean,tabledefs[]); + CREATE OR REPLACE FUNCTION public.pg_get_tabledef( + in_schema varchar, + in_table varchar, + _verbose boolean, + VARIADIC arr public.tabledefs[] DEFAULT '{}':: public.tabledefs[] + ) + RETURNS text + LANGUAGE plpgsql VOLATILE + AS + $$ + DECLARE + v_qualified text := ''; + v_table_ddl text; + v_table_oid int; + v_colrec record; + v_constraintrec record; + v_trigrec record; + v_indexrec record; + v_rec record; + v_constraint_name text; + v_constraint_def text; + v_pkey_def text := ''; + v_fkey_def text := ''; + v_fkey_defs text := ''; + v_trigger text := ''; + v_partition_key text := ''; + v_partbound text; + v_parent text; + v_parent_schema text; + v_persist text; + v_temp text := ''; + v_relopts text; + v_tablespace text; + v_pgversion int; + bSerial boolean; + bPartition boolean; + bInheritance boolean; + bRelispartition boolean; + constraintarr text[] := '{}'; + constraintelement text; + bSkip boolean; + bVerbose boolean := False; + v_cnt1 integer; + v_cnt2 integer; + v_src_path_old text := ''; + v_src_path_new text := ''; + + -- assume defaults for ENUMs at the getgo + pkcnt int := 0; + fkcnt int := 0; + trigcnt int := 0; + cmtcnt int := 0; + pktype public.tabledefs := 'PKEY_INTERNAL'; + fktype public.tabledefs := 'FKEYS_INTERNAL'; + trigtype public.tabledefs := 'NO_TRIGGERS'; + arglen integer; + vargs text; + avarg public.tabledefs; + + -- exception variables + v_ret text; + v_diag1 text; + v_diag2 text; + v_diag3 text; + v_diag4 text; + v_diag5 text; + v_diag6 text; + + BEGIN + SET client_min_messages = 'notice'; + IF _verbose THEN bVerbose = True; END IF; + + -- v17 fix: handle case-sensitive + -- v_qualified = in_schema || '.' || in_table; + + arglen := array_length($4, 1); + IF arglen IS NULL THEN + -- nothing to do, so assume defaults + NULL; + ELSE + -- loop thru args + -- IF 'NO_TRIGGERS' = ANY ($4) + -- select array_to_string($4, ',', '***') INTO vargs; + IF bVerbose THEN RAISE NOTICE 'arguments=%', $4; END IF; + FOREACH avarg IN ARRAY $4 LOOP + IF bVerbose THEN RAISE INFO 'arg=%', avarg; END IF; + IF avarg = 'FKEYS_INTERNAL' OR avarg = 'FKEYS_EXTERNAL' OR avarg = 'FKEYS_NONE' THEN + fkcnt = fkcnt + 1; + fktype = avarg; + ELSEIF avarg = 'INCLUDE_TRIGGERS' OR avarg = 'NO_TRIGGERS' THEN + trigcnt = trigcnt + 1; + trigtype = avarg; + ELSEIF avarg = 'PKEY_EXTERNAL' THEN + pkcnt = pkcnt + 1; + pktype = avarg; + ELSEIF avarg = 'COMMENTS' THEN + cmtcnt = cmtcnt + 1; + + END IF; + END LOOP; + IF fkcnt > 1 THEN + RAISE WARNING 'Only one foreign key option can be provided. You provided %', fkcnt; + RETURN ''; + ELSEIF trigcnt > 1 THEN + RAISE WARNING 'Only one trigger option can be provided. You provided %', trigcnt; + RETURN ''; + ELSEIF pkcnt > 1 THEN + RAISE WARNING 'Only one pkey option can be provided. You provided %', pkcnt; + RETURN ''; + ELSEIF cmtcnt > 1 THEN + RAISE WARNING 'Only one comments option can be provided. You provided %', cmtcnt; + RETURN ''; + + END IF; + END IF; + + SELECT c.oid, (select setting from pg_settings where name = 'server_version_num') INTO v_table_oid, v_pgversion FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace + WHERE c.relkind in ('r','p') AND c.relname = in_table AND n.nspname = in_schema; + + -- set search_path = public before we do anything to force explicit schema qualification but dont forget to set it back before exiting... + SELECT setting INTO v_src_path_old FROM pg_settings WHERE name = 'search_path'; + + SELECT REPLACE(REPLACE(setting, '"$user"', '$user'), '$user', '"$user"') INTO v_src_path_old + FROM pg_settings + WHERE name = 'search_path'; + -- RAISE INFO 'DEBUG tableddl: saving old search_path: ***%***', v_src_path_old; + EXECUTE 'SET search_path = "public"'; + SELECT setting INTO v_src_path_new FROM pg_settings WHERE name = 'search_path'; + -- RAISE INFO 'DEBUG tableddl: using new search path=***%***', v_src_path_new; + + -- throw an error if table was not found + IF (v_table_oid IS NULL) THEN + RAISE EXCEPTION 'table does not exist'; + END IF; + + -- get user-defined tablespaces if applicable + SELECT tablespace INTO v_temp FROM pg_tables WHERE schemaname = in_schema and tablename = in_table and tablespace IS NOT NULL; + IF v_temp IS NULL THEN + v_tablespace := 'TABLESPACE pg_default'; + ELSE + v_tablespace := 'TABLESPACE ' || v_temp; + END IF; + + -- also see if there are any SET commands for this table, ie, autovacuum_enabled=off, fillfactor=70 + WITH relopts AS (SELECT unnest(c.reloptions) relopts FROM pg_class c, pg_namespace n WHERE n.nspname = in_schema and n.oid = c.relnamespace and c.relname = in_table) + SELECT string_agg(r.relopts, ', ') as relopts INTO v_temp from relopts r; + IF v_temp IS NULL THEN + v_relopts := ''; + ELSE + v_relopts := ' WITH (' || v_temp || ')'; + END IF; + + -- ----------------------------------------------------------------------------------- + -- Create table defs for partitions/children using inheritance or declarative methods. + -- inheritance: pg_class.relkind = 'r' pg_class.relispartition=false pg_class.relpartbound is NULL + -- declarative: pg_class.relkind = 'r' pg_class.relispartition=true pg_class.relpartbound is NOT NULL + -- ----------------------------------------------------------------------------------- + v_partbound := ''; + bPartition := False; + bInheritance := False; + IF v_pgversion < 100000 THEN + -- Issue#11: handle parent schema + SELECT c2.relname parent, c2.relnamespace::regnamespace INTO v_parent, v_parent_schema from pg_class c1, pg_namespace n, pg_inherits i, pg_class c2 + WHERE n.nspname = in_schema and n.oid = c1.relnamespace and c1.relname = in_table and c1.oid = i.inhrelid and i.inhparent = c2.oid and c1.relkind = 'r'; + IF (v_parent IS NOT NULL) THEN + bPartition := True; + bInheritance := True; + END IF; + ELSE + -- Issue#11: handle parent schema + SELECT c2.relname parent, c1.relispartition, pg_get_expr(c1.relpartbound, c1.oid, true), c2.relnamespace::regnamespace INTO v_parent, bRelispartition, v_partbound, v_parent_schema from pg_class c1, pg_namespace n, pg_inherits i, pg_class c2 + WHERE n.nspname = in_schema and n.oid = c1.relnamespace and c1.relname = in_table and c1.oid = i.inhrelid and i.inhparent = c2.oid and c1.relkind = 'r'; + IF (v_parent IS NOT NULL) THEN + bPartition := True; + IF bRelispartition THEN + bInheritance := False; + ELSE + bInheritance := True; + END IF; + END IF; + END IF; + IF bPartition THEN + --Issue#17 fix for case-sensitive tables + -- SELECT count(*) INTO v_cnt1 FROM information_schema.tables t WHERE EXISTS (SELECT REGEXP_MATCHES(s.table_name, '([A-Z]+)','g') FROM information_schema.tables s + -- WHERE t.table_schema=s.table_schema AND t.table_name=s.table_name AND t.table_schema = quote_ident(in_schema) AND t.table_name = quote_ident(in_table) AND t.table_type = 'BASE TABLE'); + SELECT count(*) INTO v_cnt1 FROM information_schema.tables t WHERE EXISTS (SELECT REGEXP_MATCHES(s.table_name, '([A-Z]+)','g') FROM information_schema.tables s + WHERE t.table_schema=s.table_schema AND t.table_name=s.table_name AND t.table_schema = in_schema AND t.table_name = in_table AND t.table_type = 'BASE TABLE'); + + --Issue#19 put double-quotes around SQL keyword column names + -- Issue#121: fix keyword lookup for table name not column name that does not apply here + -- SELECT COUNT(*) INTO v_cnt2 FROM pg_get_keywords() WHERE word = v_colrec.column_name AND catcode = 'R'; + SELECT COUNT(*) INTO v_cnt2 FROM pg_get_keywords() WHERE word = in_table AND catcode = 'R'; + + IF bInheritance THEN + -- inheritance-based + IF v_cnt1 > 0 OR v_cnt2 > 0 THEN + v_table_ddl := 'CREATE TABLE ' || in_schema || '."' || in_table || '"( '|| E'\\n'; + ELSE + v_table_ddl := 'CREATE TABLE ' || in_schema || '.' || in_table || '( '|| E'\\n'; + END IF; + + -- Jump to constraints section to add the check constraints + ELSE + -- declarative-based + IF v_relopts <> '' THEN + IF v_cnt1 > 0 OR v_cnt2 > 0 THEN + v_table_ddl := 'CREATE TABLE ' || in_schema || '."' || in_table || '" PARTITION OF ' || in_schema || '.' || v_parent || ' ' || v_partbound || v_relopts || ' ' || v_tablespace || '; ' || E'\\n'; + ELSE + v_table_ddl := 'CREATE TABLE ' || in_schema || '.' || in_table || ' PARTITION OF ' || in_schema || '.' || v_parent || ' ' || v_partbound || v_relopts || ' ' || v_tablespace || '; ' || E'\\n'; + END IF; + ELSE + IF v_cnt1 > 0 OR v_cnt2 > 0 THEN + v_table_ddl := 'CREATE TABLE ' || in_schema || '."' || in_table || '" PARTITION OF ' || in_schema || '.' || v_parent || ' ' || v_partbound || ' ' || v_tablespace || '; ' || E'\\n'; + ELSE + v_table_ddl := 'CREATE TABLE ' || in_schema || '.' || in_table || ' PARTITION OF ' || in_schema || '.' || v_parent || ' ' || v_partbound || ' ' || v_tablespace || '; ' || E'\\n'; + END IF; + END IF; + -- Jump to constraints and index section to add the check constraints and indexes and perhaps FKeys + END IF; + END IF; + IF bVerbose THEN RAISE INFO '(1)tabledef so far: %', v_table_ddl; END IF; + + IF NOT bPartition THEN + -- see if this is unlogged or temporary table + select c.relpersistence into v_persist from pg_class c, pg_namespace n where n.nspname = in_schema and n.oid = c.relnamespace and c.relname = in_table and c.relkind = 'r'; + IF v_persist = 'u' THEN + v_temp := 'UNLOGGED'; + ELSIF v_persist = 't' THEN + v_temp := 'TEMPORARY'; + ELSE + v_temp := ''; + END IF; + END IF; + + -- start the create definition for regular tables unless we are in progress creating an inheritance-based child table + IF NOT bPartition THEN + --Issue#17 fix for case-sensitive tables + -- SELECT count(*) INTO v_cnt1 FROM information_schema.tables t WHERE EXISTS (SELECT REGEXP_MATCHES(s.table_name, '([A-Z]+)','g') FROM information_schema.tables s + -- WHERE t.table_schema=s.table_schema AND t.table_name=s.table_name AND t.table_schema = quote_ident(in_schema) AND t.table_name = quote_ident(in_table) AND t.table_type = 'BASE TABLE'); + SELECT count(*) INTO v_cnt1 FROM information_schema.tables t WHERE EXISTS (SELECT REGEXP_MATCHES(s.table_name, '([A-Z]+)','g') FROM information_schema.tables s + WHERE t.table_schema=s.table_schema AND t.table_name=s.table_name AND t.table_schema = in_schema AND t.table_name = in_table AND t.table_type = 'BASE TABLE'); + IF v_cnt1 > 0 THEN + v_table_ddl := 'CREATE ' || v_temp || ' TABLE ' || in_schema || '."' || in_table || '" (' || E'\\n'; + ELSE + v_table_ddl := 'CREATE ' || v_temp || ' TABLE ' || in_schema || '.' || in_table || ' (' || E'\\n'; + END IF; + END IF; + -- RAISE INFO 'DEBUG2: tabledef so far: %', v_table_ddl; + -- define all of the columns in the table unless we are in progress creating an inheritance-based child table + IF NOT bPartition THEN + FOR v_colrec IN + SELECT c.column_name, c.data_type, c.udt_name, c.udt_schema, c.character_maximum_length, c.is_nullable, c.column_default, c.numeric_precision, c.numeric_scale, c.is_identity, c.identity_generation, c.is_generated, c.generation_expression + FROM information_schema.columns c WHERE (table_schema, table_name) = (in_schema, in_table) ORDER BY ordinal_position + LOOP + IF bVerbose THEN RAISE INFO '(col loop) name=% type=% udt_name=% default=% is_generated=% gen_expr=%', v_colrec.column_name, v_colrec.data_type, v_colrec.udt_name, v_colrec.column_default, v_colrec.is_generated, v_colrec.generation_expression; END IF; + + -- v17 fix: handle case-sensitive for pg_get_serial_sequence that requires SQL Identifier handling + -- SELECT CASE WHEN pg_get_serial_sequence(v_qualified, v_colrec.column_name) IS NOT NULL THEN True ELSE False END into bSerial; + SELECT CASE WHEN pg_get_serial_sequence(quote_ident(in_schema) || '.' || quote_ident(in_table), v_colrec.column_name) IS NOT NULL THEN True ELSE False END into bSerial; + IF bVerbose THEN + -- v17 fix: handle case-sensitive for pg_get_serial_sequence that requires SQL Identifier handling + -- SELECT pg_get_serial_sequence(v_qualified, v_colrec.column_name) into v_temp; + SELECT pg_get_serial_sequence(quote_ident(in_schema) || '.' || quote_ident(in_table), v_colrec.column_name) into v_temp; + IF v_temp IS NULL THEN v_temp = 'NA'; END IF; + SELECT public.pg_get_coldef(in_schema, in_table,v_colrec.column_name) INTO v_diag1; + RAISE NOTICE 'DEBUG table: % Column: % datatype: % Serial=% serialval=% coldef=%', v_qualified, v_colrec.column_name, v_colrec.data_type, bSerial, v_temp, v_diag1; + RAISE NOTICE 'DEBUG tabledef: %', v_table_ddl; + END IF; + + --Issue#17 put double-quotes around case-sensitive column names + SELECT COUNT(*) INTO v_cnt1 FROM information_schema.columns t WHERE EXISTS (SELECT REGEXP_MATCHES(s.column_name, '([A-Z]+)','g') FROM information_schema.columns s + WHERE t.table_schema=s.table_schema and t.table_name=s.table_name and t.column_name=s.column_name AND t.table_schema = quote_ident(in_schema) AND column_name = v_colrec.column_name); + + --Issue#19 put double-quotes around SQL keyword column names + SELECT COUNT(*) INTO v_cnt2 FROM pg_get_keywords() WHERE word = v_colrec.column_name AND catcode = 'R'; + + IF v_cnt1 > 0 OR v_cnt2 > 0 THEN + v_table_ddl := v_table_ddl || ' "' || v_colrec.column_name || '" '; + ELSE + v_table_ddl := v_table_ddl || ' ' || v_colrec.column_name || ' '; + END IF; + + -- Issue#23: Handle autogenerated columns and rewrite as a simpler IF THEN ELSE branch instead of a much more complex embedded CASE STATEMENT + IF v_colrec.is_generated = 'ALWAYS' and v_colrec.generation_expression IS NOT NULL THEN + -- searchable tsvector GENERATED ALWAYS AS (to_tsvector('simple'::regconfig, COALESCE(translate(email, '@.-'::citext, ' '::text), ''::text)) ) STORED + v_temp = v_colrec.data_type || ' GENERATED ALWAYS AS (' || v_colrec.generation_expression || ') STORED '; + ELSEIF v_colrec.udt_name in ('geometry', 'box2d', 'box2df', 'box3d', 'geography', 'geometry_dump', 'gidx', 'spheroid', 'valid_detail') THEN + v_temp = v_colrec.udt_name; + ELSEIF v_colrec.data_type = 'USER-DEFINED' THEN + v_temp = v_colrec.udt_schema || '.' || v_colrec.udt_name; + ELSEIF v_colrec.data_type = 'ARRAY' THEN + -- Issue#6 fix: handle arrays + v_temp = public.pg_get_coldef(in_schema, in_table,v_colrec.column_name); + -- v17 fix: handle case-sensitive for pg_get_serial_sequence that requires SQL Identifier handling + -- WHEN pg_get_serial_sequence(v_qualified, v_colrec.column_name) IS NOT NULL + ELSEIF pg_get_serial_sequence(quote_ident(in_schema) || '.' || quote_ident(in_table), v_colrec.column_name) IS NOT NULL THEN + -- Issue#8 fix: handle serial. Note: NOT NULL is implied so no need to declare it explicitly + v_temp = public.pg_get_coldef(in_schema, in_table,v_colrec.column_name); + ELSE + v_temp = v_colrec.data_type; + END IF; + -- RAISE NOTICE 'column def1=%', v_temp; + + -- handle IDENTITY columns + IF v_colrec.is_identity = 'YES' THEN + IF v_colrec.identity_generation = 'ALWAYS' THEN + v_temp = v_temp || ' GENERATED ALWAYS AS IDENTITY NOT NULL'; + ELSE + v_temp = v_temp || ' GENERATED BY DEFAULT AS IDENTITY NOT NULL'; + END IF; + ELSEIF v_colrec.character_maximum_length IS NOT NULL THEN + v_temp = v_temp || ('(' || v_colrec.character_maximum_length || ')'); + ELSEIF v_colrec.numeric_precision > 0 AND v_colrec.numeric_scale > 0 THEN + v_temp = v_temp || '(' || v_colrec.numeric_precision || ',' || v_colrec.numeric_scale || ')'; + END IF; + + -- Handle NULL/NOT NULL + IF bSerial THEN + v_temp = v_temp || ' NOT NULL'; + ELSEIF v_colrec.is_nullable = 'NO' THEN + v_temp = v_temp || ' NOT NULL'; + ELSEIF v_colrec.is_nullable = 'YES' THEN + v_temp = v_temp || ' NULL'; + END IF; + + -- Handle defaults + IF v_colrec.column_default IS NOT null AND NOT bSerial THEN + -- RAISE INFO 'Setting default for column, %', v_colrec.column_name; + v_temp = v_temp || (' DEFAULT ' || v_colrec.column_default); + END IF; + v_temp = v_temp || ',' || E'\\n'; + -- RAISE NOTICE 'column def2=%', v_temp; + v_table_ddl := v_table_ddl || v_temp; + -- RAISE NOTICE 'tabledef=%', v_table_ddl; + + END LOOP; + END IF; + IF bVerbose THEN RAISE INFO '(2)tabledef so far: %', v_table_ddl; END IF; + + -- define all the constraints: conparentid does not exist pre PGv11 + IF v_pgversion < 110000 THEN + FOR v_constraintrec IN + SELECT con.conname as constraint_name, con.contype as constraint_type, + CASE + WHEN con.contype = 'p' THEN 1 -- primary key constraint + WHEN con.contype = 'u' THEN 2 -- unique constraint + WHEN con.contype = 'f' THEN 3 -- foreign key constraint + WHEN con.contype = 'c' THEN 4 + ELSE 5 + END as type_rank, + pg_get_constraintdef(con.oid) as constraint_definition + FROM pg_catalog.pg_constraint con JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace + WHERE nsp.nspname = in_schema AND rel.relname = in_table ORDER BY type_rank + LOOP + v_constraint_name := v_constraintrec.constraint_name; + v_constraint_def := v_constraintrec.constraint_definition; + IF v_constraintrec.type_rank = 1 THEN + IF pkcnt = 0 OR pktype = 'PKEY_INTERNAL' THEN + -- internal def + v_constraint_name := v_constraintrec.constraint_name; + v_constraint_def := v_constraintrec.constraint_definition; + v_table_ddl := v_table_ddl || ' ' -- note: two char spacer to start, to indent the column + || 'CONSTRAINT' || ' ' + || v_constraint_name || ' ' + || v_constraint_def + || ',' || E'\\n'; + ELSE + -- Issue#16 handle external PG def + SELECT 'ALTER TABLE ONLY ' || in_schema || '.' || c.relname || ' ADD CONSTRAINT ' || r.conname || ' ' || pg_catalog.pg_get_constraintdef(r.oid, true) || ';' INTO v_pkey_def + FROM pg_catalog.pg_constraint r, pg_class c, pg_namespace n where r.conrelid = c.oid and r.contype = 'p' and n.oid = r.connamespace and n.nspname = in_schema AND c.relname = in_table and r.conname = v_constraint_name; + END IF; + IF bPartition THEN + continue; + END IF; + ELSIF v_constraintrec.type_rank = 3 THEN + -- handle foreign key constraints + --Issue#22 fix: added FKEY_NONE check + IF fktype = 'FKEYS_NONE' THEN + -- skip + continue; + ELSIF fkcnt = 0 OR fktype = 'FKEYS_INTERNAL' THEN + -- internal def + v_table_ddl := v_table_ddl || ' ' -- note: two char spacer to start, to indent the column + || 'CONSTRAINT' || ' ' + || v_constraint_name || ' ' + || v_constraint_def + || ',' || E'\\n'; + ELSE + -- external def + SELECT 'ALTER TABLE ONLY ' || n.nspname || '.' || c2.relname || ' ADD CONSTRAINT ' || r.conname || ' ' || pg_catalog.pg_get_constraintdef(r.oid, true) || ';' INTO v_fkey_def + FROM pg_constraint r, pg_class c1, pg_namespace n, pg_class c2 where r.conrelid = c1.oid and r.contype = 'f' and n.nspname = in_schema and n.oid = r.connamespace and r.conrelid = c2.oid and c2.relname = in_table; + v_fkey_defs = v_fkey_defs || v_fkey_def || E'\\n'; + END IF; + ELSE + -- handle all other constraints besides PKEY and FKEYS as internal defs by default + v_table_ddl := v_table_ddl || ' ' -- note: two char spacer to start, to indent the column + || 'CONSTRAINT' || ' ' + || v_constraint_name || ' ' + || v_constraint_def + || ',' || E'\\n'; + END IF; + if bVerbose THEN RAISE INFO 'DEBUG4: constraint name=% constraint_def=%', v_constraint_name,v_constraint_def; END IF; + constraintarr := constraintarr || v_constraintrec.constraint_name:: text; + + END LOOP; + ELSE + -- handle PG versions 11 and up + -- Issue#20: Fix logic for external PKEY and FKEYS + FOR v_constraintrec IN + SELECT con.conname as constraint_name, con.contype as constraint_type, + CASE + WHEN con.contype = 'p' THEN 1 -- primary key constraint + WHEN con.contype = 'u' THEN 2 -- unique constraint + WHEN con.contype = 'f' THEN 3 -- foreign key constraint + WHEN con.contype = 'c' THEN 4 + ELSE 5 + END as type_rank, + pg_get_constraintdef(con.oid) as constraint_definition + FROM pg_catalog.pg_constraint con JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace + WHERE nsp.nspname = in_schema AND rel.relname = in_table + --Issue#13 added this condition: + AND con.conparentid = 0 + ORDER BY type_rank + LOOP + v_constraint_name := v_constraintrec.constraint_name; + v_constraint_def := v_constraintrec.constraint_definition; + IF v_constraintrec.type_rank = 1 THEN + IF pkcnt = 0 OR pktype = 'PKEY_INTERNAL' THEN + -- internal def + v_constraint_name := v_constraintrec.constraint_name; + v_constraint_def := v_constraintrec.constraint_definition; + v_table_ddl := v_table_ddl || ' ' -- note: two char spacer to start, to indent the column + || 'CONSTRAINT' || ' ' + || v_constraint_name || ' ' + || v_constraint_def + || ',' || E'\\n'; + ELSE + -- Issue#16 handle external PG def + SELECT 'ALTER TABLE ONLY ' || in_schema || '.' || c.relname || ' ADD CONSTRAINT ' || r.conname || ' ' || pg_catalog.pg_get_constraintdef(r.oid, true) || ';' INTO v_pkey_def + FROM pg_catalog.pg_constraint r, pg_class c, pg_namespace n where r.conrelid = c.oid and r.contype = 'p' and n.oid = r.connamespace and n.nspname = in_schema AND c.relname = in_table; + END IF; + IF bPartition THEN + continue; + END IF; + ELSIF v_constraintrec.type_rank = 3 THEN + -- handle foreign key constraints + --Issue#22 fix: added FKEY_NONE check + IF fktype = 'FKEYS_NONE' THEN + -- skip + continue; + ELSIF fkcnt = 0 OR fktype = 'FKEYS_INTERNAL' THEN + -- internal def + v_table_ddl := v_table_ddl || ' ' -- note: two char spacer to start, to indent the column + || 'CONSTRAINT' || ' ' + || v_constraint_name || ' ' + || v_constraint_def + || ',' || E'\\n'; + ELSE + -- external def + SELECT 'ALTER TABLE ONLY ' || n.nspname || '.' || c2.relname || ' ADD CONSTRAINT ' || r.conname || ' ' || pg_catalog.pg_get_constraintdef(r.oid, true) || ';' INTO v_fkey_def + FROM pg_constraint r, pg_class c1, pg_namespace n, pg_class c2 where r.conrelid = c1.oid and r.contype = 'f' and n.nspname = in_schema and n.oid = r.connamespace and r.conrelid = c2.oid and c2.relname = in_table and + r.conname = v_constraint_name and r.conparentid = 0; + v_fkey_defs = v_fkey_defs || v_fkey_def || E'\\n'; + END IF; + ELSE + -- handle all other constraints besides PKEY and FKEYS as internal defs by default + v_table_ddl := v_table_ddl || ' ' -- note: two char spacer to start, to indent the column + || 'CONSTRAINT' || ' ' + || v_constraint_name || ' ' + || v_constraint_def + || ',' || E'\\n'; + END IF; + if bVerbose THEN RAISE INFO 'DEBUG4: constraint name=% constraint_def=%', v_constraint_name,v_constraint_def; END IF; + constraintarr := constraintarr || v_constraintrec.constraint_name:: text; + + END LOOP; + END IF; + IF bVerbose THEN RAISE INFO '(3)tabledef so far: %', v_table_ddl; END IF; + + -- drop the last comma before ending the create statement + v_table_ddl = substr(v_table_ddl, 0, length(v_table_ddl) - 1) || E'\\n'; + + -- --------------------------------------------------------------------------- + -- at this point we have everything up to the last table-enclosing parenthesis + -- --------------------------------------------------------------------------- + IF bVerbose THEN RAISE INFO '(4)tabledef so far: %', v_table_ddl; END IF; + + -- See if this is an inheritance-based child table and finish up the table create. + IF bPartition and bInheritance THEN + -- Issue#11: handle parent schema + -- v_table_ddl := v_table_ddl || ') INHERITS (' || in_schema || '.' || v_parent || ') ' || E'\\n' || v_relopts || ' ' || v_tablespace || ';' || E'\\n'; + IF v_parent_schema = '' OR v_parent_schema IS NULL THEN v_parent_schema = in_schema; END IF; + v_table_ddl := v_table_ddl || ') INHERITS (' || v_parent_schema || '.' || v_parent || ') ' || E'\\n' || v_relopts || ' ' || v_tablespace || ';' || E'\\n'; + END IF; + + IF v_pgversion >= 100000 AND NOT bPartition and NOT bInheritance THEN + -- See if this is a partitioned table (pg_class.relkind = 'p') and add the partitioned key + SELECT pg_get_partkeydef(c1.oid) as partition_key INTO v_partition_key FROM pg_class c1 JOIN pg_namespace n ON (n.oid = c1.relnamespace) LEFT JOIN pg_partitioned_table p ON (c1.oid = p.partrelid) + WHERE n.nspname = in_schema and n.oid = c1.relnamespace and c1.relname = in_table and c1.relkind = 'p'; + + IF v_partition_key IS NOT NULL AND v_partition_key <> '' THEN + -- add partition clause + -- NOTE: cannot specify default tablespace for partitioned relations + -- v_table_ddl := v_table_ddl || ') PARTITION BY ' || v_partition_key || ' ' || v_tablespace || ';' || E'\\n'; + v_table_ddl := v_table_ddl || ') PARTITION BY ' || v_partition_key || ';' || E'\\n'; + ELSEIF v_relopts <> '' THEN + v_table_ddl := v_table_ddl || ') ' || v_relopts || ' ' || v_tablespace || ';' || E'\\n'; + ELSE + -- end the create definition + v_table_ddl := v_table_ddl || ') ' || v_tablespace || ';' || E'\\n'; + END IF; + END IF; + + IF bVerbose THEN RAISE INFO '(5)tabledef so far: %', v_table_ddl; END IF; + + -- Add closing paren for regular tables + -- IF NOT bPartition THEN + -- v_table_ddl := v_table_ddl || ') ' || v_relopts || ' ' || v_tablespace || E';\\n'; + -- END IF; + -- RAISE NOTICE 'ddlsofar3: %', v_table_ddl; + + -- Issue#16 create the external PKEY def if indicated + IF v_pkey_def <> '' THEN + v_table_ddl := v_table_ddl || v_pkey_def || E'\\n'; + END IF; + + -- Issue#20 + IF v_fkey_defs <> '' THEN + v_table_ddl := v_table_ddl || v_fkey_defs || E'\\n'; + END IF; + + IF bVerbose THEN RAISE INFO '(6)tabledef so far: %', v_table_ddl; END IF; + + -- create indexes + FOR v_indexrec IN + SELECT indexdef, COALESCE(tablespace, 'pg_default') as tablespace, indexname FROM pg_indexes WHERE (schemaname, tablename) = (in_schema, in_table) + LOOP + -- RAISE INFO 'DEBUG6: indexname=%', v_indexrec.indexname; + -- loop through constraints and skip ones already defined + bSkip = False; + FOREACH constraintelement IN ARRAY constraintarr + LOOP + IF constraintelement = v_indexrec.indexname THEN + -- RAISE INFO 'DEBUG7: skipping index, %', v_indexrec.indexname; + bSkip = True; + EXIT; + END IF; + END LOOP; + if bSkip THEN CONTINUE; END IF; + + -- Add IF NOT EXISTS clause so partition index additions will not be created if declarative partition in effect and index already created on parent + v_indexrec.indexdef := REPLACE(v_indexrec.indexdef, 'CREATE UNIQUE INDEX', 'CREATE UNIQUE INDEX IF NOT EXISTS'); + v_indexrec.indexdef := REPLACE(v_indexrec.indexdef, 'CREATE INDEX', 'CREATE INDEX IF NOT EXISTS'); + -- RAISE INFO 'DEBUG8: adding index, %', v_indexrec.indexname; + + -- NOTE: cannot specify default tablespace for partitioned relations + IF v_partition_key IS NOT NULL AND v_partition_key <> '' THEN + v_table_ddl := v_table_ddl || v_indexrec.indexdef || ';' || E'\\n'; + ELSE + v_table_ddl := v_table_ddl || v_indexrec.indexdef || ' TABLESPACE ' || v_indexrec.tablespace || ';' || E'\\n'; + END IF; + + END LOOP; + IF bVerbose THEN RAISE INFO '(7)tabledef so far: %', v_table_ddl; END IF; + + -- Issue#20: added logic for table and column comments + IF cmtcnt > 0 THEN + FOR v_rec IN + SELECT c.relname, 'COMMENT ON ' || CASE WHEN c.relkind in ('r','p') AND a.attname IS NULL THEN 'TABLE ' WHEN c.relkind in ('r','p') AND a.attname IS NOT NULL THEN 'COLUMN ' WHEN c.relkind = 'f' THEN 'FOREIGN TABLE ' + WHEN c.relkind = 'm' THEN 'MATERIALIZED VIEW ' WHEN c.relkind = 'v' THEN 'VIEW ' WHEN c.relkind = 'i' THEN 'INDEX ' WHEN c.relkind = 'S' THEN 'SEQUENCE ' ELSE 'XX' END || n.nspname || '.' || + CASE WHEN c.relkind in ('r','p') AND a.attname IS NOT NULL THEN quote_ident(c.relname) || '.' || a.attname ELSE quote_ident(c.relname) END || ' IS ' || quote_literal(d.description) || ';' as ddl + FROM pg_class c JOIN pg_namespace n ON (n.oid = c.relnamespace) LEFT JOIN pg_description d ON (c.oid = d.objoid) LEFT JOIN pg_attribute a ON (c.oid = a.attrelid AND a.attnum > 0 and a.attnum = d.objsubid) + WHERE d.description IS NOT NULL AND n.nspname = in_schema AND c.relname = in_table ORDER BY 2 desc, ddl + LOOP + --RAISE INFO 'comments:%', v_rec.ddl; + v_table_ddl = v_table_ddl || v_rec.ddl || E'\\n'; + END LOOP; + END IF; + IF bVerbose THEN RAISE INFO '(8)tabledef so far: %', v_table_ddl; END IF; + + IF trigtype = 'INCLUDE_TRIGGERS' THEN + -- Issue#14: handle multiple triggers for a table + FOR v_trigrec IN + select pg_get_triggerdef(t.oid, True) || ';' as triggerdef FROM pg_trigger t, pg_class c, pg_namespace n + WHERE n.nspname = in_schema and n.oid = c.relnamespace and c.relname = in_table and c.relkind = 'r' and t.tgrelid = c.oid and NOT t.tgisinternal + LOOP + v_table_ddl := v_table_ddl || v_trigrec.triggerdef; + v_table_ddl := v_table_ddl || E'\\n'; + IF bVerbose THEN RAISE INFO 'triggerdef = %', v_trigrec.triggerdef; END IF; + END LOOP; + END IF; + + IF bVerbose THEN RAISE INFO '(9)tabledef so far: %', v_table_ddl; END IF; + -- add empty line + v_table_ddl := v_table_ddl || E'\\n'; + IF bVerbose THEN RAISE INFO '(10)tabledef so far: %', v_table_ddl; END IF; + + -- reset search_path back to what it was + IF v_src_path_old = '' THEN + SELECT set_config('search_path', '', false) into v_temp; + ELSE + EXECUTE 'SET search_path = ' || v_src_path_old; + END IF; + + RETURN v_table_ddl; + + EXCEPTION + WHEN others THEN + BEGIN + GET STACKED DIAGNOSTICS v_diag1 = MESSAGE_TEXT, v_diag2 = PG_EXCEPTION_DETAIL, v_diag3 = PG_EXCEPTION_HINT, v_diag4 = RETURNED_SQLSTATE, v_diag5 = PG_CONTEXT, v_diag6 = PG_EXCEPTION_CONTEXT; + -- v_ret := 'line=' || v_diag6 || '. '|| v_diag4 || '. ' || v_diag1 || ' .' || v_diag2 || ' .' || v_diag3; + v_ret := 'line=' || v_diag6 || '. '|| v_diag4 || '. ' || v_diag1; + RAISE EXCEPTION '%', v_ret; + -- put additional coding here if necessarY + RETURN ''; + END; + + END; + $$;""".indent(1); + + public static final String ENUM_TYPE_DDL_SQL = """ + SELECT 'CREATE TYPE "' || n.nspname || '"."' || t.typname || '" AS ENUM (' || + string_agg(quote_literal(e.enumlabel), ', ') || ');' AS ddl + FROM pg_type t + JOIN pg_enum e ON t.oid = e.enumtypid + JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace + WHERE t.typtype = 'e' + GROUP BY n.nspname, t.typname;"""; } diff --git a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/pg.json b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/pg.json index 040611bbe..71dd6f6c3 100644 --- a/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/pg.json +++ b/chat2db-server/chat2db-plugins/chat2db-postgresql/src/main/java/ai/chat2db/plugin/postgresql/pg.json @@ -8,7 +8,7 @@ "custom": false, "defaultDriver": true, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/postgresql-42.5.1.jar" + "https://cdn.chat2db-ai.com/lib/postgresql-42.5.1.jar" ], "jdbcDriver": "postgresql-42.5.1.jar", "jdbcDriverClass": "org.postgresql.Driver" diff --git a/chat2db-server/chat2db-plugins/chat2db-presto/pom.xml b/chat2db-server/chat2db-plugins/chat2db-presto/pom.xml index 960fe6dfb..48600790e 100644 --- a/chat2db-server/chat2db-plugins/chat2db-presto/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-presto/pom.xml @@ -22,7 +22,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-presto/src/main/java/ai/chat2db/plugin/presto/presto.json b/chat2db-server/chat2db-plugins/chat2db-presto/src/main/java/ai/chat2db/plugin/presto/presto.json index df469d82f..b20f0f9a4 100644 --- a/chat2db-server/chat2db-plugins/chat2db-presto/src/main/java/ai/chat2db/plugin/presto/presto.json +++ b/chat2db-server/chat2db-plugins/chat2db-presto/src/main/java/ai/chat2db/plugin/presto/presto.json @@ -8,7 +8,7 @@ "custom": false, "defaultDriver": true, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/presto-jdbc-0.245.1.jar" + "https://cdn.chat2db-ai.com/lib/presto-jdbc-0.245.1.jar" ], "jdbcDriver": "presto-jdbc-0.245.1.jar", "jdbcDriverClass": "com.facebook.presto.jdbc.PrestoDriver" diff --git a/chat2db-server/chat2db-plugins/chat2db-redis/pom.xml b/chat2db-server/chat2db-plugins/chat2db-redis/pom.xml deleted file mode 100644 index 598defa20..000000000 --- a/chat2db-server/chat2db-plugins/chat2db-redis/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - 4.0.0 - - ai.chat2db - chat2db-plugins - ${revision} - ../pom.xml - - - - ai.chat2db - chat2db-spi - - - - chat2db-redis - - - - src/main/java - - - **/*.json - - - - src/main/resources - - - - \ No newline at end of file diff --git a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisDBManage.java b/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisDBManage.java deleted file mode 100644 index b9761c5d4..000000000 --- a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisDBManage.java +++ /dev/null @@ -1,8 +0,0 @@ -package ai.chat2db.plugin.redis; - -import ai.chat2db.spi.DBManage; -import ai.chat2db.spi.jdbc.DefaultDBManage; - -public class RedisDBManage extends DefaultDBManage implements DBManage { - -} diff --git a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisMetaData.java b/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisMetaData.java deleted file mode 100644 index ac85570d2..000000000 --- a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisMetaData.java +++ /dev/null @@ -1,57 +0,0 @@ -package ai.chat2db.plugin.redis; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import ai.chat2db.spi.MetaData; -import ai.chat2db.spi.jdbc.DefaultMetaService; -import ai.chat2db.spi.model.Database; -import ai.chat2db.spi.model.Table; -import ai.chat2db.spi.sql.SQLExecutor; -import org.apache.commons.lang3.StringUtils; - -public class RedisMetaData extends DefaultMetaService implements MetaData { - - @Override - public List databases(Connection connection) { - List databases = new ArrayList<>(); - return SQLExecutor.getInstance().execute(connection,"config get databases", resultSet -> { - try { - if (resultSet.next()) { - Object count = resultSet.getObject(2); - if(StringUtils.isNotBlank(count.toString())) { - for (int i = 0; i < Integer.parseInt(count.toString()); i++) { - Database database = Database.builder().name(String.valueOf(i)).build(); - databases.add(database); - } - } - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return databases; - }); - } - - @Override - public List tables(Connection connection, String databaseName, String schemaName, String tableName) { - return SQLExecutor.getInstance().execute(connection,"scan 0 MATCH * COUNT 1000", resultSet -> { - List
tables = new ArrayList<>(); - try { - while (resultSet.next()) { - ArrayList list = (ArrayList)resultSet.getObject(2); - for (Object object : list) { - Table table = new Table(); - table.setName(object.toString()); - tables.add(table); - } - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - return tables; - }); - } -} diff --git a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisPlugin.java b/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisPlugin.java deleted file mode 100644 index 53c988db4..000000000 --- a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/RedisPlugin.java +++ /dev/null @@ -1,27 +0,0 @@ -package ai.chat2db.plugin.redis; - - -import ai.chat2db.spi.DBManage; -import ai.chat2db.spi.MetaData; -import ai.chat2db.spi.Plugin; -import ai.chat2db.spi.config.DBConfig; -import ai.chat2db.spi.util.FileUtils; - -public class RedisPlugin implements Plugin { - - @Override - public DBConfig getDBConfig() { - return FileUtils.readJsonValue(this.getClass(),"redis.json", DBConfig.class); - - } - - @Override - public MetaData getMetaData() { - return new RedisMetaData(); - } - - @Override - public DBManage getDBManage() { - return new RedisDBManage(); - } -} diff --git a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/redis.json b/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/redis.json deleted file mode 100644 index a10b33ae5..000000000 --- a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/java/ai/chat2db/plugin/redis/redis.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "dbType": "REDIS", - "supportDatabase": false, - "supportSchema": false, - "driverConfigList": [ - { - "url": "jdbc:redis://127.0.0.1:6379/0", - "custom": false, - "defaultDriver": true, - "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/redis-jdbc-driver-1.3.jar" - ], - "jdbcDriver": "redis-jdbc-driver-1.3.jar", - "jdbcDriverClass": "jdbc.RedisDriver" - } - ], - "name": "Redis" -} diff --git a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/resources/META-INF/services/ai.chat2db.spi.Plugin b/chat2db-server/chat2db-plugins/chat2db-redis/src/main/resources/META-INF/services/ai.chat2db.spi.Plugin deleted file mode 100644 index 3ccb61291..000000000 --- a/chat2db-server/chat2db-plugins/chat2db-redis/src/main/resources/META-INF/services/ai.chat2db.spi.Plugin +++ /dev/null @@ -1 +0,0 @@ -ai.chat2db.plugin.redis.RedisPlugin \ No newline at end of file diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlite/pom.xml b/chat2db-server/chat2db-plugins/chat2db-sqlite/pom.xml index 84a93aa47..e41cc4e2b 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlite/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-sqlite/pom.xml @@ -21,7 +21,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteDBManage.java b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteDBManage.java index 6130d7a65..da9659266 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteDBManage.java @@ -3,5 +3,81 @@ import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + public class SqliteDBManage extends DefaultDBManage implements DBManage { + + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTables(connection, databaseName, schemaName,sqlBuilder, containData); + exportViews(connection, databaseName, sqlBuilder); + exportTriggers(connection, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportTables(Connection connection, String databaseName, String schemaName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, null, null, new String[]{"TABLE", "SYSTEM TABLE"})) { + while (resultSet.next()) { + exportTable(connection,schemaName, resultSet.getString("TABLE_NAME"), sqlBuilder, containData); + } + } + } + + + private void exportTable(Connection connection, String schemaName, String tableName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + String sql = String.format("SELECT sql FROM sqlite_master WHERE type='table' AND name='%s'", tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP TABLE IF EXISTS ").append(format(tableName)).append(";").append("\n") + .append(resultSet.getString("sql")).append(";").append("\n"); + if (containData) { + exportTableData(connection,schemaName, tableName, sqlBuilder); + } + } + } + } + + private String format(String tableName) { + return "\""+tableName+"\""; + } + + private void exportViews(Connection connection, String databaseName, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, null, null, new String[]{"VIEW"})) { + while (resultSet.next()) { + exportView(connection, resultSet.getString("TABLE_NAME"), sqlBuilder); + } + } + } + + private void exportView(Connection connection, String viewName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT * FROM sqlite_master WHERE type = 'view' and name='%s';", viewName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP VIEW IF EXISTS ").append(format(viewName)).append(";").append("\n") + .append(resultSet.getString("sql")).append(";").append("\n"); + } + } + } + + private void exportTriggers(Connection connection, StringBuilder sqlBuilder) throws SQLException { + String sql = "SELECT * FROM sqlite_master WHERE type = 'trigger';"; + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String triggerName = resultSet.getString("name"); + exportTrigger(connection, triggerName, sqlBuilder); + } + } + } + + private void exportTrigger(Connection connection, String triggerName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT * FROM sqlite_master WHERE type = 'trigger' and name='%s';", triggerName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("sql")).append("\n"); + } + } + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteMetaData.java b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteMetaData.java index 4fb72270a..8450a4236 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/SqliteMetaData.java @@ -1,11 +1,5 @@ package ai.chat2db.plugin.sqlite; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - import ai.chat2db.plugin.sqlite.builder.SqliteBuilder; import ai.chat2db.plugin.sqlite.type.SqliteCollationEnum; import ai.chat2db.plugin.sqlite.type.SqliteColumnTypeEnum; @@ -14,18 +8,69 @@ import ai.chat2db.spi.MetaData; import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.jdbc.DefaultMetaService; -import ai.chat2db.spi.model.Database; -import ai.chat2db.spi.model.Schema; -import ai.chat2db.spi.model.TableMeta; +import ai.chat2db.spi.model.*; import ai.chat2db.spi.sql.SQLExecutor; import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + public class SqliteMetaData extends DefaultMetaService implements MetaData { + private static String VIEW_DDL_SQL="SELECT * FROM sqlite_master WHERE type = 'view' and name='%s';"; + @Override + public Table view(Connection connection, String databaseName, String schemaName, String viewName) { + Table view = new Table(); + String sql = String.format(VIEW_DDL_SQL,viewName); + SQLExecutor.getInstance().execute(connection, sql, resultSet->{ + if (resultSet.next()) { + view.setDatabaseName(databaseName); + view.setDdl(resultSet.getString("sql")); + } + }); + return view; + } + + private static final String TRIGGER_LIST_SQL = "SELECT * FROM sqlite_master WHERE type = 'trigger';"; + private static String TRIGGER_DDL_SQL = "SELECT * FROM sqlite_master WHERE type = 'trigger' and name='%s';"; + + @Override + public List triggers(Connection connection, String databaseName, String schemaName) { + List triggers = new ArrayList<>(); + return SQLExecutor.getInstance().execute(connection, TRIGGER_LIST_SQL, resultSet -> { + while (resultSet.next()) { + Trigger trigger = new Trigger(); + String triggerName = resultSet.getString("name"); + trigger.setTriggerName(triggerName); + trigger.setDatabaseName(databaseName); + triggers.add(trigger); + } + return triggers; + }); + } + + @Override + public Trigger trigger(Connection connection, String databaseName, String schemaName, String triggerName) { + Trigger trigger = new Trigger(); + String sql = String.format(TRIGGER_DDL_SQL, triggerName); + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { + while (resultSet.next()) { + trigger.setTriggerName(triggerName); + trigger.setDatabaseName(databaseName); + trigger.setTriggerBody(resultSet.getString("sql")); + } + return trigger; + }); + } + @Override public String tableDDL(Connection connection, String databaseName, String schemaName, String tableName) { String sql = "SELECT sql FROM sqlite_master WHERE type='table' AND name='" + tableName + "'"; - return SQLExecutor.getInstance().execute(connection,sql, resultSet -> { + return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { try { if (resultSet.next()) { return resultSet.getString("sql"); @@ -36,13 +81,14 @@ public String tableDDL(Connection connection, String databaseName, String schema return null; }); } + @Override public List databases(Connection connection) { return Lists.newArrayList(Database.builder().name("main").build()); } @Override - public List schemas(Connection connection,String databaseName) { + public List schemas(Connection connection, String databaseName) { return Lists.newArrayList(); } @@ -50,6 +96,7 @@ public List schemas(Connection connection,String databaseName) { public SqlBuilder getSqlBuilder() { return new SqliteBuilder(); } + @Override public TableMeta getTableMeta(String databaseName, String schemaName, String tableName) { return TableMeta.builder() diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/builder/SqliteBuilder.java b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/builder/SqliteBuilder.java index 8c28e9e60..5878d6675 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/builder/SqliteBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/builder/SqliteBuilder.java @@ -10,7 +10,7 @@ import org.apache.commons.lang3.StringUtils; -public class SqliteBuilder extends DefaultSqlBuilder implements SqlBuilder { +public class SqliteBuilder extends DefaultSqlBuilder { @Override public String buildCreateTableSql(Table table) { StringBuilder script = new StringBuilder(); diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/sqlite.json b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/sqlite.json index 408af9170..373e89899 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/sqlite.json +++ b/chat2db-server/chat2db-plugins/chat2db-sqlite/src/main/java/ai/chat2db/plugin/sqlite/sqlite.json @@ -8,7 +8,7 @@ "custom": false, "defaultDriver": true, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/sqlite-jdbc-3.39.3.0.jar" + "https://cdn.chat2db-ai.com/lib/sqlite-jdbc-3.39.3.0.jar" ], "jdbcDriver": "sqlite-jdbc-3.39.3.0.jar", "jdbcDriverClass": "org.sqlite.JDBC" diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlserver/pom.xml b/chat2db-server/chat2db-plugins/chat2db-sqlserver/pom.xml index 5485f539d..4524ce15d 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlserver/pom.xml +++ b/chat2db-server/chat2db-plugins/chat2db-sqlserver/pom.xml @@ -29,7 +29,7 @@ src/main/java - + **/*.json diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerDBManage.java b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerDBManage.java index ded0abf11..8e9bff5d6 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerDBManage.java +++ b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerDBManage.java @@ -1,13 +1,186 @@ package ai.chat2db.plugin.sqlserver; -import java.sql.Connection; -import java.sql.SQLException; - import ai.chat2db.spi.DBManage; import ai.chat2db.spi.jdbc.DefaultDBManage; import ai.chat2db.spi.sql.SQLExecutor; +import java.sql.*; +import java.util.Objects; + public class SqlServerDBManage extends DefaultDBManage implements DBManage { + private String tableDDLFunction + = "CREATE FUNCTION tableSchema.ufn_GetCreateTableScript( @schema_name NVARCHAR(128), @table_name NVARCHAR" + + "(128)) RETURNS NVARCHAR(MAX) AS BEGIN DECLARE @CreateTableScript NVARCHAR(MAX); DECLARE @IndexScripts " + + "NVARCHAR(MAX) = ''; DECLARE @ColumnDescriptions NVARCHAR(MAX) = N''; SELECT @CreateTableScript = CONCAT( " + + "'CREATE TABLE [', s.name, '].[' , t.name, '] (', STUFF( ( SELECT ', [' + c.name + '] ' + tp.name + CASE " + + "WHEN tp.name IN ('varchar', 'nvarchar', 'char', 'nchar') THEN '(' + IIF(c.max_length = -1, 'MAX', CAST(c" + + ".max_length AS NVARCHAR(10))) + ')' WHEN tp.name IN ('decimal', 'numeric') THEN '(' + CAST(c.precision AS " + + "NVARCHAR(10)) + ', ' + CAST(c.scale AS NVARCHAR(10)) + ')' ELSE '' END + ' ' + CASE WHEN c.is_nullable = 1" + + " THEN 'NULL' ELSE 'NOT NULL' END FROM sys.columns c JOIN sys.types tp ON c.user_type_id = tp.user_type_id " + + "WHERE c.object_id = t.object_id FOR XML PATH(''), TYPE ).value('/', 'nvarchar(max)'), 1, 1, ''), ');' ) " + + "FROM sys.tables t JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE t.name = @table_name AND s.name = " + + "@schema_name; SELECT @IndexScripts = @IndexScripts + 'CREATE ' + CASE WHEN i.is_unique = 1 THEN 'UNIQUE ' " + + "ELSE '' END + i.type_desc + ' INDEX [' + i.name + '] ON [' + s.name + '].[' + t.name + '] (' + STUFF( ( " + + "SELECT ', [' + c.name + ']' + CASE WHEN ic.is_descending_key = 1 THEN ' DESC' ELSE ' ASC' END FROM sys" + + ".index_columns ic JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id WHERE ic" + + ".object_id = i.object_id AND ic.index_id = i.index_id ORDER BY ic.key_ordinal FOR XML PATH('') ), 1, 1, " + + "'') + ')' + CASE WHEN i.has_filter = 1 THEN ' WHERE ' + i.filter_definition ELSE '' END + ';' + CHAR(13) +" + + " CHAR(10) FROM sys.indexes i JOIN sys.tables t ON i.object_id = t.object_id JOIN sys.schemas s ON t" + + ".schema_id = s.schema_id WHERE i.type > 0 AND t.name = @table_name AND s.name " + + "= @schema_name; SELECT @ColumnDescriptions += 'EXEC sp_addextendedproperty @name=N''MS_Description'', " + + "@value=N''' + CAST(p.value AS NVARCHAR(MAX)) + ''', @level0type=N''SCHEMA'', @level0name=N''' + " + + "@schema_name + ''', @level1type=N''TABLE'', @level1name=N''' + @table_name + ''', @level2type=N''COLUMN''," + + " @level2name=N''' + c.name + ''';' + CHAR(13) + CHAR(10) FROM sys.extended_properties p JOIN sys.columns c" + + " ON p.major_id = c.object_id AND p.minor_id = c.column_id JOIN sys.tables t ON c.object_id = t.object_id " + + "JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE p.class = 1 AND t.name = @table_name AND s.name = " + + "@schema_name; SET @CreateTableScript = @CreateTableScript + CHAR(13) + CHAR(10) + @IndexScripts + CHAR(13)" + + " + CHAR(10)+ @ColumnDescriptions+ CHAR(10); RETURN @CreateTableScript; END"; + + private static String TRIGGER_SQL_LIST + = "SELECT OBJECT_NAME(parent_obj) AS TableName, name AS triggerName, OBJECT_DEFINITION(id) AS " + + "triggerDefinition, CASE WHEN status & 1 = 1 THEN 'Enabled' ELSE 'Disabled' END AS Status FROM sysobjects " + + "WHERE xtype = 'TR' "; + + @Override + public String exportDatabaseData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTableData(connection, tableName, sqlBuilder); + return sqlBuilder.toString(); + } + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTables(connection, sqlBuilder, schemaName, containData); + exportViews(connection, databaseName, schemaName, sqlBuilder); + exportFunctions(connection, schemaName, sqlBuilder); + exportProcedures(connection, schemaName, sqlBuilder); + exportTriggers(connection, sqlBuilder); + return sqlBuilder.toString(); + } + + private void exportTables(Connection connection, StringBuilder sqlBuilder, String schemaName, boolean containData) throws SQLException { + String sql ="SELECT name FROM SysObjects Where XType='U'"; + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String tableName = resultSet.getString("name"); + exportTable(connection, tableName, schemaName, sqlBuilder, containData); + } + } + } + + + private void exportTable(Connection connection, String tableName, String schemaName, StringBuilder sqlBuilder, boolean containData) throws SQLException { + try { + SQLExecutor.getInstance().execute(connection, tableDDLFunction.replace("tableSchema", schemaName), + resultSet -> null); + } catch (Exception e) { + //log.error("Failed to create function", e); + } + String sql = String.format("SELECT %s.ufn_GetCreateTableScript('%s', '%s') as ddl",schemaName,schemaName,tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append("DROP TABLE IF EXISTS ").append(tableName).append(";").append("\n") + .append(resultSet.getString("ddl")).append("\n"); + if (containData) { + exportTableData(connection, tableName, sqlBuilder); + } else { + sqlBuilder.append("go").append("\n"); + } + } + } + } + + + private void exportTableData(Connection connection, String tableName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("select * from %s", tableName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + ResultSetMetaData metaData = resultSet.getMetaData(); + while (resultSet.next()) { + sqlBuilder.append("INSERT INTO ").append(tableName).append(" VALUES ("); + for (int i = 1; i <= metaData.getColumnCount(); i++) { + String value = resultSet.getString(i); + if (Objects.isNull(value)) { + sqlBuilder.append("NULL"); + } else { + sqlBuilder.append("'").append(value).append("'"); + } + if (i < metaData.getColumnCount()) { + sqlBuilder.append(", "); + } + } + sqlBuilder.append(");\n"); + } + sqlBuilder.append("\n"); + } + sqlBuilder.append("go").append("\n"); + } + + private void exportViews(Connection connection, String databaseName, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT TABLE_NAME, VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS " + + "WHERE TABLE_SCHEMA = '%s' AND TABLE_CATALOG = '%s'; ", schemaName, databaseName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + sqlBuilder.append("DROP VIEW IF EXISTS ").append(resultSet.getString("TABLE_NAME")).append(";\n").append("go").append("\n") + .append(resultSet.getString("VIEW_DEFINITION")).append(";").append("\n") + .append("go").append("\n"); + } + + } + } + + private void exportFunctions(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT name FROM sys.objects WHERE type = 'FN' and SCHEMA_ID = SCHEMA_ID('%s')", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String functionName = resultSet.getString("name"); + exportFunction(connection, functionName, schemaName, sqlBuilder); + } + } + } + + private void exportFunction(Connection connection, String functionName, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT OBJECT_DEFINITION(OBJECT_ID('%s.%s')) as ddl", schemaName, functionName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("ddl") + .replace("CREATE FUNCTION", "CREATE OR ALTER FUNCTION")) + .append("\n").append("go").append("\n"); + + } + } + } + + private void exportProcedures(Connection connection, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT name FROM sys.procedures WHERE SCHEMA_ID = SCHEMA_ID('%s')", schemaName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + while (resultSet.next()) { + String procedureName = resultSet.getString("name"); + exportProcedure(connection, procedureName, schemaName, sqlBuilder); + } + } + } + + private void exportProcedure(Connection connection, String procedureName, String schemaName, StringBuilder sqlBuilder) throws SQLException { + String sql = String.format("SELECT definition FROM sys.sql_modules WHERE object_id = (OBJECT_ID('%s.%s'));", schemaName, procedureName); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + if (resultSet.next()) { + sqlBuilder.append(resultSet.getString("definition") + .replace("CREATE PROCEDURE", "CREATE OR ALTER PROCEDURE")) + .append("\n").append("go").append("\n"); + + } + } + } + + private void exportTriggers(Connection connection, StringBuilder sqlBuilder) throws SQLException { + try (ResultSet resultSet = connection.createStatement().executeQuery(TRIGGER_SQL_LIST)) { + while (resultSet.next()) { + sqlBuilder.append(resultSet.getString("triggerDefinition") + .replace("CREATE TRIGGER", "CREATE OR ALTER TRIGGER")) + .append("\n").append("go").append("\n"); + } + } + } @Override public void connectDatabase(Connection connection, String database) { try { diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerMetaData.java b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerMetaData.java index 88498eafc..c68bdf8cc 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/SqlServerMetaData.java @@ -17,6 +17,7 @@ import ai.chat2db.spi.model.*; import ai.chat2db.spi.sql.SQLExecutor; import ai.chat2db.spi.util.SortUtils; +import com.google.common.collect.Lists; import jakarta.validation.constraints.NotEmpty; import org.apache.commons.lang3.StringUtils; @@ -77,7 +78,7 @@ public String tableDDL(Connection connection, String databaseName, String schema SQLExecutor.getInstance().execute(connection, functionSQL.replace("tableSchema", schemaName), resultSet -> null); } catch (Exception e) { - //log.error("创建函数失败", e); + //log.error("Failed to create function", e); } String ddlSql = "SELECT " + schemaName + ".ufn_GetCreateTableScript('" + schemaName + "', '" + tableName @@ -398,4 +399,14 @@ public String getMetaDataName(String... names) { public CommandExecutor getCommandExecutor() { return new SqlServerCommandExecutor(); } + + @Override + public List getSystemDatabases() { + return systemDatabases; + } + + @Override + public List getSystemSchemas() { + return systemSchemas; + } } diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/builder/SqlServerSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/builder/SqlServerSqlBuilder.java index 77e8d524f..85a0baee8 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/builder/SqlServerSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/builder/SqlServerSqlBuilder.java @@ -8,7 +8,7 @@ import ai.chat2db.spi.sql.Chat2DBContext; import org.apache.commons.lang3.StringUtils; -public class SqlServerSqlBuilder extends DefaultSqlBuilder implements SqlBuilder { +public class SqlServerSqlBuilder extends DefaultSqlBuilder { @Override public String buildCreateTableSql(Table table) { StringBuilder script = new StringBuilder(); diff --git a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/sqlserver.json b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/sqlserver.json index 1c54832ca..157621830 100644 --- a/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/sqlserver.json +++ b/chat2db-server/chat2db-plugins/chat2db-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/sqlserver.json @@ -8,7 +8,7 @@ "custom": false, "defaultDriver": true, "downloadJdbcDriverUrls": [ - "https://oss.sqlgpt.cn/lib/mssql-jdbc-11.2.1.jre17.jar" + "https://cdn.chat2db-ai.com/lib/mssql-jdbc-11.2.1.jre17.jar" ], "jdbcDriver": "mssql-jdbc-11.2.1.jre17.jar", "jdbcDriverClass": "com.microsoft.sqlserver.jdbc.SQLServerDriver", diff --git a/chat2db-server/chat2db-plugins/pom.xml b/chat2db-server/chat2db-plugins/pom.xml index d058b04e7..17be8e0e8 100644 --- a/chat2db-server/chat2db-plugins/pom.xml +++ b/chat2db-server/chat2db-plugins/pom.xml @@ -28,7 +28,6 @@ chat2db-mongodb chat2db-presto chat2db-hive - chat2db-redis chat2db-kingbase diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartCreateParam.java index 8bc453d32..63df696ce 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartCreateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartCreateParam.java @@ -6,64 +6,64 @@ /** * @author moji - * @version ChartCreateParam.java, v 0.1 2023年06月09日 15:38 moji Exp $ + * @version ChartCreateParam.java, v 0.1 June 9, 2023 15:38 moji Exp $ * @date 2023/06/09 */ @Data public class ChartCreateParam { /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 图表名称 + * chart name */ private String name; /** - * 图表信息 + * chart information */ private String schema; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据库类型 + * Database type */ private String type; /** - * db名称 + * DB name */ private String databaseName; /** - * + * schemaName */ private String schemaName; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否被删除,y表示删除,n表示未删除 + * Whether it has been deleted, y means deleted, n means not deleted */ private String deleted; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartListQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartListQueryParam.java index 3c40a31b4..a141c3f78 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartListQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartListQueryParam.java @@ -16,13 +16,13 @@ public class ChartListQueryParam { /** - * 主键 + * primary key */ @NonNull private List idList; /** - * 用户id + * user id */ @NonNull private Long userId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartPageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartPageQueryParam.java index 589efab29..afc2f2219 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartPageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartPageQueryParam.java @@ -6,19 +6,19 @@ /** * @author moji - * @version UserSavedDdlPageQueryParam.java, v 0.1 2022年09月25日 14:05 moji Exp $ + * @version UserSavedDdlPageQueryParam.java, v 0.1 September 25, 2022 14:05 moji Exp $ * @date 2022/09/25 */ @Data public class ChartPageQueryParam extends PageQueryParam { /** - * 报表ID + * Report ID */ private Long dashboardId; /** - * 搜索关键词 + * search keyword */ private String searchKey; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartQueryParam.java index 6de1cfb54..ad967c916 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartQueryParam.java @@ -14,13 +14,13 @@ public class ChartQueryParam { /** - * 主键 + * primary key */ @NonNull private Long id; /** - * 用户id + * user id */ @NonNull private Long userId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartUpdateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartUpdateParam.java index 63b5bb538..1e0eb3587 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartUpdateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/chart/ChartUpdateParam.java @@ -6,63 +6,63 @@ /** * @author moji - * @version ChartUpdateParam.java, v 0.1 2023年06月09日 15:39 moji Exp $ + * @version ChartUpdateParam.java, v 0.1 June 9, 2023 15:39 moji Exp $ * @date 2023/06/09 */ @Data public class ChartUpdateParam { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 图表名称 + * chart name */ private String name; /** - * 图表信息 + * chart information */ private String schema; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据库类型 + * Database type */ private String type; /** - * db名称 + * DB name */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/AiSqlSourceEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/AiSqlSourceEnum.java index c44052d50..05eb2050a 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/AiSqlSourceEnum.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/AiSqlSourceEnum.java @@ -6,7 +6,7 @@ import lombok.Getter; /** - * AI SQL选择的AI模型类型 + * AI model type selected by AI SQL * * @author moji */ @@ -72,7 +72,7 @@ public enum AiSqlSourceEnum implements BaseEnum { } /** - * 通过名称获取枚举 + * Get enum by name * * @param name * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/DeletedTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/DeletedTypeEnum.java new file mode 100644 index 000000000..aac6872b7 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/DeletedTypeEnum.java @@ -0,0 +1,6 @@ +package ai.chat2db.server.domain.api.enums; + +public enum DeletedTypeEnum { + + Y,N +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportFileSuffix.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportFileSuffix.java index 9f98f0cdb..9b5d854ee 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportFileSuffix.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportFileSuffix.java @@ -19,7 +19,15 @@ public enum ExportFileSuffix { //html HTML(".html"), //pdf - PDF(".pdf"); + PDF(".pdf"), + + SQL(".sql"), + + JSON(".json"), + + CSV(".csv"), + + ZIP(".zip"); private String suffix; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportTypeEnum.java index c00ac9bbf..89daeae14 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportTypeEnum.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/ExportTypeEnum.java @@ -45,7 +45,11 @@ public enum ExportTypeEnum implements BaseEnum { /** * PDF */ - PDF("PDF"); + PDF("PDF"), + + JSON("JSON"), + + SQL("SQL"); final String description; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/OperationStatusEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/OperationStatusEnum.java index 8d9d79004..91f533fa7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/OperationStatusEnum.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/OperationStatusEnum.java @@ -5,19 +5,19 @@ import lombok.Getter; /** - * 状态 + * state * - * @author 是仪 + * @author Shi Yi */ @Getter public enum OperationStatusEnum implements BaseEnum { /** - * 草稿 + * draft */ DRAFT("草稿"), /** - * 已发布 + * Published */ RELEASE("已发布"), diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TableVectorEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TableVectorEnum.java index 6565c6095..2737a2fe4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TableVectorEnum.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TableVectorEnum.java @@ -27,7 +27,7 @@ public enum TableVectorEnum implements BaseEnum { } /** - * 通过名称获取枚举 + * Get enum by name * * @param name * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskStatusEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskStatusEnum.java new file mode 100644 index 000000000..821ac74b4 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskStatusEnum.java @@ -0,0 +1,6 @@ +package ai.chat2db.server.domain.api.enums; + +public enum TaskStatusEnum { + + INIT, PROCESSING, FINISH, ERROR +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskTypeEnum.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskTypeEnum.java new file mode 100644 index 000000000..7d3b93419 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskTypeEnum.java @@ -0,0 +1,24 @@ +package ai.chat2db.server.domain.api.enums; + +public enum TaskTypeEnum { + + /** + * download table data + */ + DOWNLOAD_TABLE_DATA, + + /** + * upload table data + */ + UPLOAD_TABLE_DATA, + + /** + * download table structure + */ + DOWNLOAD_TABLE_STRUCTURE, + + /** + * upload table structure + */ + UPLOAD_TABLE_STRUCTURE, +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/AIConfig.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/AIConfig.java index 48bf0d612..de1c88329 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/AIConfig.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/AIConfig.java @@ -45,7 +45,7 @@ public class AIConfig { /** * return data stream - * 非必填,默认值为TRUE + * Optional, default value is TRUE */ private Boolean stream = Boolean.TRUE; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Chart.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Chart.java index e2705a969..d7a80d4ce 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Chart.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Chart.java @@ -6,79 +6,79 @@ /** * @author moji - * @version Chart.java, v 0.1 2023年06月09日 15:37 moji Exp $ + * @version Chart.java, v 0.1 June 9, 2023 15:37 moji Exp $ * @date 2023/06/09 */ @Data public class Chart { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 图表名称 + * Chart name */ private String name; /** - * 图表描述 + * Chart description */ private String description; /** - * 图表信息 + * schema */ private String schema; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据源名称 + * Data source name */ private String dataSourceName; /** - * schema名称 + * schema name */ private String schemaName; /** - * 数据库类型 + * Database type */ private String type; /** - * db名称 + * DB name */ private String databaseName; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否被删除,y表示删除,n表示未删除 + * Whether it has been deleted, y means deleted, n means not deleted */ private String deleted; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/ChatGptConfig.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/ChatGptConfig.java index 711809606..553dcb016 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/ChatGptConfig.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/ChatGptConfig.java @@ -5,7 +5,7 @@ /** * @author moji - * @version ChatGptConfig.java, v 0.1 2023年05月09日 13:47 moji Exp $ + * @version ChatGptConfig.java, v 0.1 May 9, 2023 13:47 moji Exp $ * @date 2023/05/09 */ @Data @@ -31,29 +31,29 @@ public class ChatGptConfig { private String apiHost; /** - * http代理Host + * HTTP proxy host */ private String httpProxyHost; /** - * http代理Port + * HTTP proxy Port */ private String httpProxyPort; /** - * AI类型 + * AI type * @see AiSqlSourceEnum */ private String aiSqlSource; /** - * 自定义AI接口 + * Custom AI interface */ private String restAiUrl; /** - * Rest接口是否流式输出 - * 非必填,默认值为TRUE + * Whether the Rest interface streams output + * Optional, default value is TRUE */ private Boolean restAiStream = Boolean.TRUE; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Config.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Config.java index 8af6543a5..f5562d7fc 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Config.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Config.java @@ -19,28 +19,28 @@ public class Config implements Serializable { private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 配置项code + * Configuration item code */ private String code; /** - * 配置项内容 + * Configuration item content */ private String content; /** - * 配置摘要 + * Configuration summary */ private String summary; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Dashboard.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Dashboard.java index 13ceff6a3..18fcf0279 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Dashboard.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Dashboard.java @@ -7,54 +7,54 @@ /** * @author moji - * @version Dashboard.java, v 0.1 2023年06月09日 15:32 moji Exp $ + * @version Dashboard.java, v 0.1 June 9, 2023 15:32 moji Exp $ * @date 2023/06/09 */ @Data public class Dashboard { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 报表名称 + * Dashboard name */ private String name; /** - * 报表描述 + * Dashboard description */ private String description; /** - * 报表布局信息 + * Dashboard layout information */ private String schema; /** - * 是否被删除,y表示删除,n表示未删除 + * Whether it has been deleted, y means deleted, n means not deleted */ private String deleted; /** - * 用户id + * user id */ private Long userId; /** - * 图表ID列表 + * Chart ID list */ private List chartIds; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSource.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSource.java index 1abce5fa0..70287511a 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSource.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSource.java @@ -13,54 +13,54 @@ /** * @author moji - * @version DataSourceDTO.java, v 0.1 2022年09月23日 15:39 moji Exp $ + * @version DataSourceDTO.java, v 0.1 September 23, 2022 15:39 moji Exp $ * @date 2022/09/23 */ @Data public class DataSource { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 别名 + * Alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 用户名 + * user name */ private String userName; /** - * 密码 + * password */ private String password; /** - * 数据库类型 + * Database type */ private String type; /** - * 环境类型 + * environment type */ private String envType; @@ -95,38 +95,38 @@ public class DataSource { private String driver; /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 环境id + * environment id */ private Long environmentId; /** - * 环境 + * environment */ private Environment environment; /** - * 用户id + * user id */ private Long userId; /** - * 连接类型 + * Connection Type * * @see ai.chat2db.server.domain.api.enums.DataSourceKindEnum */ @@ -134,12 +134,12 @@ public class DataSource { /** - * 服务名称 + * Service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccess.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccess.java index 91c094be5..48949064a 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccess.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccess.java @@ -28,47 +28,47 @@ public class DataSourceAccess implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 创建时间 + * creation time */ @NotNull private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ @NotNull private LocalDateTime gmtModified; /** - * 创建人用户id + * Creator user id */ private Long createUserId; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * 数据源 + * data source */ @NotNull private DataSource dataSource; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ @@ -76,13 +76,13 @@ public class DataSourceAccess implements Serializable { private String accessObjectType; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ @NotNull private Long accessObjectId; /** - * 授权对象 + * Authorization object * @see DataSourceAccessSelector#setAccessObject(Boolean) */ @NotNull diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccessObject.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccessObject.java index cf5648936..19c0a7c17 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccessObject.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/DataSourceAccessObject.java @@ -26,12 +26,12 @@ public class DataSourceAccessObject implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ private Long id; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Environment.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Environment.java index a7732bc20..9c04f6e4f 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Environment.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Environment.java @@ -24,22 +24,22 @@ public class Environment implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 主键 + * primary key */ private Long id; /** - * 环境名称 + * environment name */ private String name; /** - * 环境缩写 + * environment abbreviation */ private String shortName; /** - * 颜色 + * color */ private String color; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/IndexInfo.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/IndexInfo.java index 111762682..d629451ac 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/IndexInfo.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/IndexInfo.java @@ -4,7 +4,7 @@ import lombok.experimental.Accessors; /** - * 索引导出信息 + * Index export information * * @author lzy */ @@ -12,23 +12,23 @@ @Accessors(chain = true) public class IndexInfo { /** - * 索引名称 + * Index name */ private String name; /** - * 字段 + * Field */ private String columnName; /** - * 索引类型 + * Index type */ private String indexType; /** - * 索引方法 + * Index method */ private String indexMethod; /** - * 注释 + * Comment */ private String comment; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Operation.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Operation.java index 9ce73efde..76fa0d7c5 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Operation.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Operation.java @@ -6,7 +6,7 @@ /** *

- * 我的保存表 + * My save list *

* * @author ali-dbhub @@ -16,62 +16,62 @@ public class Operation { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据源名称 + * Data source name */ private String dataSourceName; /** - * db名称 + * DB name */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; /** - * 保存名称 + * save name */ private String name; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl语句状态:DRAFT/RELEASE + * ddl statement status: DRAFT/RELEASE */ private String status; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; @@ -81,7 +81,7 @@ public class Operation { private String operationType; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/OperationLog.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/OperationLog.java index 9634f5ff2..007aa06e7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/OperationLog.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/OperationLog.java @@ -6,7 +6,7 @@ /** *

- * 我的执行记录 + * My execution record *

* * @author ali-dbhub @@ -16,69 +16,67 @@ public class OperationLog { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据源 + * data source */ private String dataSourceName; /** - * db名称 + * DB name */ private String databaseName; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl内容 + * ddl content */ private String ddl; - - /** - * 状态 + * status */ private String status; /** - * 操作行数 + * Number of operation lines */ private Long operationRows; /** - * 使用时长 + * Length of use */ private Long useTime; /** - * 扩展信息 + * Extended Information */ private String extendInfo; /** - * schema名称 + * schema name */ private String schemaName; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TableParameter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TableParameter.java index 835c4a009..828923332 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TableParameter.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TableParameter.java @@ -12,35 +12,35 @@ @Accessors(chain = true) public class TableParameter { /** - * 序号 + * serial number **/ private String no; /** - * 字段名 + * Field name **/ private String fieldName; /** - * 数据类型 + * type of data **/ private String columnType; /** - * 长度 + * length **/ private String length; /** - * 不是null + * not null **/ private String isNullAble; /** - * 默认值 + * default value **/ private String columnDefault; /** - * 小数位 + * Decimal places **/ private String decimalPlaces; /** - * 备注 + * Remark **/ private String columnComment; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Task.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Task.java new file mode 100644 index 000000000..8eb5dc18e --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Task.java @@ -0,0 +1,84 @@ +package ai.chat2db.server.domain.api.model; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +@Data +public class Task implements Serializable { + /** + * primary key + */ + private Long id; + + /** + * creation time + */ + private Date gmtCreate; + + /** + * modified time + */ + private Date gmtModified; + + /** + * Data source connection ID + */ + private Long dataSourceId; + + /** + * DB name + */ + private String databaseName; + + /** + * schema name + */ + private String schemaName; + + /** + * table_name + */ + private String tableName; + + /** + * Whether it has been deleted, y means deleted, n means not deleted + */ + private String deleted; + + /** + * user id + */ + private Long userId; + + /** + * task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE, + */ + private String taskType; + + /** + * task status + */ + private String taskStatus; + + /** + * task progress + */ + private String taskProgress; + + /** + * task name + */ + private String taskName; + + /** + * download url + */ + private String downloadUrl; + + /** + * task content + */ + private byte[] content; +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Team.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Team.java index c951b0e39..412bf6ada 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Team.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Team.java @@ -26,25 +26,25 @@ public class Team implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 团队编码 + * team coding */ @NotNull private String code; /** - * 团队名称 + * Team Name */ @NotNull private String name; /** - * 团队状态 + * Team status * * @see ai.chat2db.server.domain.api.enums.ValidStatusEnum */ @@ -52,22 +52,22 @@ public class Team implements Serializable { private String status; /** - * 团队描述 + * Team description */ private String description; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 修改人用户 + * Modifier user */ private User modifiedUser; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TeamUser.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TeamUser.java index 107f0f122..cc996e7e1 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TeamUser.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/TeamUser.java @@ -25,31 +25,31 @@ public class TeamUser implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 团队id + * team id */ @NotNull private Long teamId; /** - * 团队 + * team */ @NotNull private Team team; /** - * 用户id + * user id */ @NotNull private Long userId; /** - * 用户 + * user */ @NotNull private User user; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/User.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/User.java index 2662063ad..1439bd6a9 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/User.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/User.java @@ -11,7 +11,7 @@ import lombok.experimental.SuperBuilder; /** - * 用户信息 + * User Info * * @author Jiaju Zhuang */ @@ -21,44 +21,44 @@ @AllArgsConstructor public class User { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 用户名 + * username */ @NotNull private String userName; /** - * 密码 + * password */ @NotNull private String password; /** - * 昵称 + * Nick name */ @NotNull private String nickName; /** - * 邮箱 + * email */ @NotNull private String email; /** - * 角色编码 + * role coding * * @see RoleCodeEnum */ private String roleCode; /** - * 用户状态 + * user status * * @see ValidStatusEnum */ @@ -66,17 +66,17 @@ public class User { private String status; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 修改人用户 + * Modifier user */ private User modifiedUser; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCloseParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCloseParam.java index 9a62206da..75cab0b17 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCloseParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCloseParam.java @@ -7,7 +7,7 @@ import lombok.experimental.SuperBuilder; /** - * 控制台关闭参数 + * Console shutdown parameters * * @author Jiaju Zhuang */ @@ -18,13 +18,13 @@ public class ConsoleCloseParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; /** - * 控制台的id ,确保全局唯一 + * The id of the console, ensuring global uniqueness */ @NotNull private Long consoleId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleConnectParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleConnectParam.java index a1e944c12..e782d05a9 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleConnectParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleConnectParam.java @@ -4,24 +4,24 @@ /** * @author moji - * @version ConsoleConnectParam.java, v 0.1 2022年10月30日 15:53 moji Exp $ + * @version ConsoleConnectParam.java, v 0.1 October 30, 2022 15:53 moji Exp $ * @date 2022/10/30 */ @Data public class ConsoleConnectParam { /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * 数据库db名称 + * databaseName */ private String databaseName; /** - * 控制台id + * console id */ private Long consoleId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCreateParam.java index ff2a13d40..4bf63c744 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCreateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ConsoleCreateParam.java @@ -8,7 +8,7 @@ import lombok.experimental.SuperBuilder; /** - * 控制台创建参数 + * Console creation parameters * * @author Jiaju Zhuang */ @@ -18,21 +18,21 @@ @AllArgsConstructor public class ConsoleCreateParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; /** - * 控制台的id ,确保全局唯一 - * 确保不要重复,重复的情况下会弃用以前的连接,并重新创建 + * The id of the console, ensuring global uniqueness + * Make sure not to duplicate it, in which case the previous connection will be discarded and recreated */ @NotNull private Long consoleId; /** - * 对应的连接数据库名称 - * 支持多个database的数据库会调用use xx;来切换来数据库 + * Corresponding connection database name + * Databases that support multiple databases will call use xx; to switch to the database. */ @NotNull private String databaseName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlCountParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlCountParam.java index f956fa7d1..b610614f1 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlCountParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlCountParam.java @@ -5,33 +5,33 @@ import lombok.Data; /** - * 统计数量 + * total number * - * @author 是仪 + * @author Shi Yi */ @Data public class DlCountParam { /** - * sql语句 + * sql statement */ @NotNull private String sql; /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * databaseName */ @NotNull private String databaseName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlExecuteParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlExecuteParam.java index cae98b5ce..63b12a260 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlExecuteParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DlExecuteParam.java @@ -6,57 +6,60 @@ /** * @author moji - * @version DataSourceExecuteParam.java, v 0.1 2022年10月14日 13:53 moji Exp $ + * @version DataSourceExecuteParam.java, v 0.1 October 14, 2022 13:53 moji Exp $ * @date 2022/10/14 */ @Data public class DlExecuteParam { /** - * sql语句 + * sql statement */ @NotNull private String sql; /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * databaseName */ @NotNull private String databaseName; + private String tableName; + + /** - * schema名称 + * schema name */ private String schemaName; /** - * 分页编码 - * 只有select语句才有 + * Page coding + * Only the select statement has */ private Integer pageNo; /** - * 分页大小 - * 只有select语句才有 + * Paging Size + * Only the select statement has */ private Integer pageSize; /** - * 返回全部数据 - * 只有select语句才有 + * Return all data + * Only the select statement has */ private Boolean pageSizeAll; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DmlSqlCopyParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DmlSqlCopyParam.java new file mode 100644 index 000000000..4f372aa3e --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DmlSqlCopyParam.java @@ -0,0 +1,15 @@ +package ai.chat2db.server.domain.api.param; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class DmlSqlCopyParam extends TableQueryParam{ + + private String type; +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DropParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DropParam.java index 74fe89675..ba60b57b9 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DropParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/DropParam.java @@ -8,7 +8,7 @@ import lombok.experimental.SuperBuilder; /** - * 删除表结构 + * Delete table structure * * @author Jiaju Zhuang */ @@ -18,24 +18,24 @@ @AllArgsConstructor public class DropParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; /** - * 对应的连接数据库名称 + * Corresponding connection database name */ @NotNull private String databaseName; /** - * 表名 + * Table Name */ private String tableName; /** - * + * schema */ private String tableSchema; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/EnvironmentPageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/EnvironmentPageQueryParam.java index 38d0c2bcf..e22c8e839 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/EnvironmentPageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/EnvironmentPageQueryParam.java @@ -12,7 +12,7 @@ public class EnvironmentPageQueryParam extends PageQueryParam { /** - * 搜索关键词 + * search keyword */ private String searchKey; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/OrderByParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/OrderByParam.java index 8110677b3..ba58f048b 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/OrderByParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/OrderByParam.java @@ -11,25 +11,25 @@ public class OrderByParam { /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * databaseName */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; @@ -41,7 +41,7 @@ public class OrderByParam { /** - * 排序字段 + * sort field */ private List orderByList; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/PinTableParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/PinTableParam.java index bbda4bfef..b6300c0c7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/PinTableParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/PinTableParam.java @@ -10,12 +10,12 @@ public class PinTableParam { private Long dataSourceId; /** - * DB名称 + * databaseName */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ShowCreateTableParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ShowCreateTableParam.java index ef24e14b6..5967a93b8 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ShowCreateTableParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/ShowCreateTableParam.java @@ -8,7 +8,7 @@ import lombok.experimental.SuperBuilder; /** - * 查询建表语句 + * Query table creation statement * * @author Jiaju Zhuang */ @@ -18,24 +18,24 @@ @AllArgsConstructor public class ShowCreateTableParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; /** - * 对应的连接数据库名称 + * Corresponding connection database name */ @NotNull private String databaseName; /** - * 表名 + * Table Name */ private String tableName; /** - * 表所属schema + * The schema to which the table belongs */ private String schemaName; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SqlAnalyseParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SqlAnalyseParam.java index ad47deeb0..ee1075286 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SqlAnalyseParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SqlAnalyseParam.java @@ -8,7 +8,7 @@ import lombok.experimental.SuperBuilder; /** - * Sql解析参数 + * Sql parsing parameters * * @author Jiaju Zhuang */ @@ -19,13 +19,13 @@ public class SqlAnalyseParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; /** - * 需要解析的sql 可能是一个复杂的sql + * The SQL that needs to be parsed may be a complex SQL */ private String sql; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SystemConfigParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SystemConfigParam.java index 6a18bb948..d7c172fc2 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SystemConfigParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/SystemConfigParam.java @@ -22,17 +22,17 @@ public class SystemConfigParam implements Serializable { private static final long serialVersionUID = 7969235263543844658L; /** - * 配置项code + * Configuration item code */ private String code; /** - * 配置项内容 + * Configuration item content */ private String content; /** - * 配置摘要 + * Configuration summary */ private String summary; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TablePageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TablePageQueryParam.java index d93c9beff..288badd82 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TablePageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TablePageQueryParam.java @@ -8,7 +8,7 @@ import lombok.experimental.SuperBuilder; /** - * 分页查询表信息 + * Pagination query table information * * @author Jiaju Zhuang */ @@ -19,25 +19,25 @@ public class TablePageQueryParam extends PageQueryParam { private static final long serialVersionUID = 8054519332890887747L; /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; /** - * 对应的连接数据库名称 + * Corresponding connection database name */ @NotNull private String databaseName; /** - * 表名 + * Table Name */ private String tableName; /** - * + * schema */ private String schemaName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableQueryParam.java index 4f6e3b4cd..ec300af63 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableQueryParam.java @@ -12,7 +12,7 @@ import lombok.experimental.SuperBuilder; /** - * 查询表信息 + * Query table information * * @author Jiaju Zhuang */ @@ -24,24 +24,24 @@ public class TableQueryParam extends QueryParam { @Serial private static final long serialVersionUID = -8918610899872508804L; /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; /** - * 对应的连接数据库名称 + * Corresponding connection database name */ @NotNull private String databaseName; /** - * 表名 + * Table Name */ private String tableName; /** - * 空间名 + * Space name */ private String schemaName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableSelector.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableSelector.java index d91f5ff56..e9bb97122 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableSelector.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableSelector.java @@ -6,7 +6,7 @@ import lombok.experimental.SuperBuilder; /** - * 表结构选择器 + * table structure selector * * @author Jiaju Zhuang */ @@ -16,12 +16,12 @@ @AllArgsConstructor public class TableSelector { /** - * 列列表 + * column list */ private Boolean columnList; /** - * 索引列表 + * index list */ private Boolean indexList; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableVectorParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableVectorParam.java index 1aaeae810..cc8e3d987 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableVectorParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TableVectorParam.java @@ -20,22 +20,22 @@ public class TableVectorParam { private String apiKey; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据库名称 + * database name */ private String database; /** - * schema名称 + * schema name */ private String schema; /** - * 向量保存状态 + * Vector saved state */ private String status; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskCreateParam.java new file mode 100644 index 000000000..89504e133 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskCreateParam.java @@ -0,0 +1,53 @@ +package ai.chat2db.server.domain.api.param; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class TaskCreateParam implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Data source connection ID + */ + private Long dataSourceId; + + /** + * databaseName + */ + private String databaseName; + + /** + * schema name + */ + private String schemaName; + + /** + * table_name + */ + private String tableName; + + /** + * user id + */ + private Long userId; + + /** + * task progress + */ + private String taskProgress; + + /** + * task name + */ + private String taskName; + + /** + * task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE, + */ + private String taskType; + + +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskPageParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskPageParam.java new file mode 100644 index 000000000..ecf207558 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskPageParam.java @@ -0,0 +1,19 @@ +package ai.chat2db.server.domain.api.param; + +import ai.chat2db.server.tools.base.wrapper.param.PageQueryParam; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class TaskPageParam extends PageQueryParam implements Serializable { + + + private Long userId; + + private List taskType; + + private String taskStatus; + +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskUpdateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskUpdateParam.java new file mode 100644 index 000000000..6b3c3ea45 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskUpdateParam.java @@ -0,0 +1,47 @@ +package ai.chat2db.server.domain.api.param; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class TaskUpdateParam implements Serializable { + + + private static final long serialVersionUID = 1L; + + /** + * task id + */ + private Long id; + + /** + * user id + */ + private Long userId; + + /** + * task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE, + */ + private String taskStatus; + + /** + * task progress + */ + private String taskProgress; + + /** + * task name + */ + private String taskName; + + /** + * task description + */ + private String downloadUrl; + + /** + * task content + */ + private byte[] content; +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TypeQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TypeQueryParam.java index 2d430ed3d..a89b172c8 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TypeQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TypeQueryParam.java @@ -14,7 +14,7 @@ public class TypeQueryParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/UpdateSelectResultParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/UpdateSelectResultParam.java index 0880e7a99..d890976be 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/UpdateSelectResultParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/UpdateSelectResultParam.java @@ -11,45 +11,45 @@ @Data public class UpdateSelectResultParam { /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * databaseName */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; /** - * 展示头的列表 + * List of display headers */ @NotEmpty private List
headerList; /** - * 修改后数据的列表 + * List of modified data */ @NotEmpty private List operations; /** - * 表名 + * Table Name */ @NotEmpty private String tableName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardCreateParam.java index 6e4acd505..c08d19adb 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardCreateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardCreateParam.java @@ -7,49 +7,49 @@ /** * @author moji - * @version DashboardSaveParam.java, v 0.1 2023年06月09日 15:29 moji Exp $ + * @version DashboardSaveParam.java, v 0.1 June 9, 2023 15:29 moji Exp $ * @date 2023/06/09 */ @Data public class DashboardCreateParam { /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 报表名称 + * Report name */ private String name; /** - * 描述 + * description */ private String description; /** - * 报表布局信息 + * Report layout information */ private String schema; /** - * 是否被删除,y表示删除,n表示未删除 + * Whether it has been deleted, y means deleted, n means not deleted */ private String deleted; /** - * 用户id + * user id */ private Long userId; /** - * 图表ID列表 + * Chart ID list */ private List chartIds; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardPageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardPageQueryParam.java index 8e6288959..4a74f3186 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardPageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardPageQueryParam.java @@ -6,19 +6,19 @@ /** * @author moji - * @version UserSavedDdlPageQueryParam.java, v 0.1 2022年09月25日 14:05 moji Exp $ + * @version UserSavedDdlPageQueryParam.java, v 0.1 September 25, 2022 14:05 moji Exp $ * @date 2022/09/25 */ @Data public class DashboardPageQueryParam extends PageQueryParam { /** - * 搜索关键词 + * search keyword */ private String searchKey; /** - * 用户id + * user id */ private Long userId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardQueryParam.java index 236b3be8a..2a07dd6dd 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardQueryParam.java @@ -14,13 +14,13 @@ public class DashboardQueryParam { /** - * 主键 + * primary key */ @NonNull private Long id; /** - * 用户id + * user id */ @NonNull private Long userId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardSelector.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardSelector.java index f5e072f74..66dfa118d 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardSelector.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardSelector.java @@ -17,7 +17,7 @@ public class DashboardSelector { /** - * 图表ID列表 + * Chart ID list */ private Boolean chartIds; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardUpdateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardUpdateParam.java index 51c187bb6..36c47ef5f 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardUpdateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/dashboard/DashboardUpdateParam.java @@ -7,54 +7,54 @@ /** * @author moji - * @version DashboardSaveParam.java, v 0.1 2023年06月09日 15:29 moji Exp $ + * @version DashboardSaveParam.java, v 0.1 June 9, 2023 15:29 moji Exp $ * @date 2023/06/09 */ @Data public class DashboardUpdateParam { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 报表名称 + * Report name */ private String name; /** - * 描述 + * description */ private String description; /** - * 报表布局信息 + * Report layout information */ private String schema; /** - * 是否被删除,y表示删除,n表示未删除 + * Whether it has been deleted, y means deleted, n means not deleted */ private String deleted; /** - * 用户id + * user id */ private Long userId; /** - * 图表ID列表 + * Chart ID list */ private List chartIds; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCloseParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCloseParam.java index d5a8904c6..93e316ac3 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCloseParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCloseParam.java @@ -8,7 +8,7 @@ import lombok.experimental.SuperBuilder; /** - * 数据源关闭 + * data source closed * * @author Jiaju Zhuang */ @@ -18,7 +18,7 @@ @AllArgsConstructor public class DataSourceCloseParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCreateParam.java index 373f25ebb..4b5c4cafe 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCreateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceCreateParam.java @@ -12,39 +12,39 @@ /** * @author moji - * @version DataSourceCreateParam.java, v 0.1 2022年09月23日 15:23 moji Exp $ + * @version DataSourceCreateParam.java, v 0.1 September 23, 2022 15:23 moji Exp $ * @date 2022/09/23 */ @Data public class DataSourceCreateParam { /** - * 别名 + * Alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 用户名 + * userName */ private String userName; /** - * 密码 + * password */ private String password; /** - * 数据库类型 + * Database type */ private String type; /** - * 环境类型 + * environment type */ private String envType; @@ -81,42 +81,41 @@ public class DataSourceCreateParam { /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 连接类型 + * Connection Type * * @see ai.chat2db.server.domain.api.enums.DataSourceKindEnum */ private String kind; /** - * 环境id + * environment id */ @NotNull private Long environmentId; - /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePageQueryParam.java index b2f960757..4735ec1fa 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePageQueryParam.java @@ -7,19 +7,19 @@ /** * @author moji - * @version DataSourcePageQueryParam.java, v 0.1 2022年09月23日 15:27 moji Exp $ + * @version DataSourcePageQueryParam.java, v 0.1 September 23, 2022 15:27 moji Exp $ * @date 2022/09/23 */ @Data public class DataSourcePageQueryParam extends PageQueryParam { /** - * 搜索关键词 + * search keyword */ private String searchKey; /** - * 连接类型 + * Connection Type * * @see ai.chat2db.server.domain.api.enums.DataSourceKindEnum */ diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePreConnectParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePreConnectParam.java index ee4db569e..462575731 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePreConnectParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourcePreConnectParam.java @@ -11,36 +11,36 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourcePreConnectParam { /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ @NotNull private String url; /** - * 连接用户 + * Connect users */ private String user; /** - * 密码 + * password */ @NotNull private String password; /** - * 连接类型 + * Connection Type */ @NotNull private String type; @@ -78,17 +78,17 @@ public class DataSourcePreConnectParam { /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceSelector.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceSelector.java index 00f411f6a..1cf14a211 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceSelector.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceSelector.java @@ -7,7 +7,7 @@ /** * @author moji - * @version DataSourceSelector.java, v 0.1 2022年09月23日 15:28 moji Exp $ + * @version DataSourceSelector.java, v 0.1 September 23, 2022 15:28 moji Exp $ * @date 2022/09/23 */ @Data @@ -17,7 +17,7 @@ public class DataSourceSelector { /** - * 环境id + * environment id */ private Boolean environment; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceTestParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceTestParam.java index 58bd235cb..b873d89ea 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceTestParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceTestParam.java @@ -13,7 +13,7 @@ import lombok.experimental.SuperBuilder; /** - * 数据源测试参数 + * Data source test parameters * * @author Jiaju Zhuang */ @@ -24,7 +24,7 @@ public class DataSourceTestParam { /** - * 数据库类型 + * Database type * * @see DbTypeEnum */ @@ -32,18 +32,18 @@ public class DataSourceTestParam { private String dbType; /** - * 请求连接 + * Request connection */ @NotNull private String url; /** - * 用户名 + * userName */ private String username; /** - * 密码 + * password */ private String password; @@ -79,18 +79,18 @@ public class DataSourceTestParam { /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceUpdateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceUpdateParam.java index 2aa39e3b8..9111b641f 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceUpdateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DataSourceUpdateParam.java @@ -11,50 +11,50 @@ /** * @author moji - * @version DataSourceCreateParam.java, v 0.1 2022年09月23日 15:23 moji Exp $ + * @version DataSourceCreateParam.java, v 0.1 September 23, 2022 15:23 moji Exp $ * @date 2022/09/23 */ @Data public class DataSourceUpdateParam { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 别名 + * Alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 用户名 + * userName */ private String userName; /** - * 密码 + * password */ private String password; /** - * 数据库类型 + * Database type */ private String type; /** - * 环境类型 + * environment type */ private String envType; /** - * 环境id + * environment id */ private Integer environmentId; @@ -90,27 +90,27 @@ public class DataSourceUpdateParam { /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseExportDataParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseExportDataParam.java new file mode 100644 index 000000000..4e562cedf --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseExportDataParam.java @@ -0,0 +1,18 @@ +package ai.chat2db.server.domain.api.param.datasource; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: zgq + * @date: 2024年03月24日 13:17 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class DatabaseExportDataParam { + private String databaseName; + private String schemaName; + private String exportType; +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseExportParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseExportParam.java new file mode 100644 index 000000000..94dedbf09 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseExportParam.java @@ -0,0 +1,26 @@ +package ai.chat2db.server.domain.api.param.datasource; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: zgq + * @date: 2024年02月27日 22:08 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class DatabaseExportParam { + /** + * DB name + */ + private String databaseName; + + private String schemaName; + + private Boolean containData; + +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseQueryAllParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseQueryAllParam.java index 2e2b27595..b37ba7943 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseQueryAllParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/DatabaseQueryAllParam.java @@ -9,7 +9,7 @@ import lombok.experimental.SuperBuilder; /** - * 展示数据库信息 + * Display database information * * @author Jiaju Zhuang */ @@ -19,7 +19,7 @@ @AllArgsConstructor public class DatabaseQueryAllParam { /** - * 对应数据库存储的来源id + * Corresponding source id stored in the database */ @NotNull private Long dataSourceId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessBatchCreatParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessBatchCreatParam.java index 7529557e2..156aed535 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessBatchCreatParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessBatchCreatParam.java @@ -15,7 +15,7 @@ @Data public class DataSourceAccessBatchCreatParam extends PageQueryParam { /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessComprehensivePageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessComprehensivePageQueryParam.java index b3c94cae4..7955393b4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessComprehensivePageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessComprehensivePageQueryParam.java @@ -12,19 +12,19 @@ @Data public class DataSourceAccessComprehensivePageQueryParam extends PageQueryParam { /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ private String accessObjectType; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ private Long accessObjectId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessCreatParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessCreatParam.java index 133989782..807878a89 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessCreatParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessCreatParam.java @@ -18,13 +18,13 @@ @AllArgsConstructor public class DataSourceAccessCreatParam { /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ @@ -32,7 +32,7 @@ public class DataSourceAccessCreatParam { private String accessObjectType; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ @NotNull private Long accessObjectId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessObjectParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessObjectParam.java index 20896eb47..6c76bfecd 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessObjectParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessObjectParam.java @@ -27,12 +27,12 @@ public class DataSourceAccessObjectParam implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ private Long id; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessPageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessPageQueryParam.java index d12310ae7..3fe1f6b38 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessPageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessPageQueryParam.java @@ -13,13 +13,13 @@ @Data public class DataSourceAccessPageQueryParam extends PageQueryParam { /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ @@ -27,7 +27,7 @@ public class DataSourceAccessPageQueryParam extends PageQueryParam { private String accessObjectType; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ @NotNull private Long accessObjectId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessSelector.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessSelector.java index 65c50c2ba..2908e900c 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessSelector.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/datasource/access/DataSourceAccessSelector.java @@ -18,17 +18,17 @@ public class DataSourceAccessSelector { /** - * 授权对象 + * Authorization object */ private Boolean accessObject; /** - * 数据源 + * data source */ private Boolean dataSource; /** - * 数据源 + * data source */ private DataSourceSelector dataSourceSelector; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogCreateParam.java index 77c60a58d..b9c685044 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogCreateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogCreateParam.java @@ -4,60 +4,60 @@ /** * @author moji - * @version UserExecutedDdlCreateParam.java, v 0.1 2022年09月25日 11:08 moji Exp $ + * @version UserExecutedDdlCreateParam.java, v 0.1 September 25, 2022 11:08 moji Exp $ * @date 2022/09/25 */ @Data public class OperationLogCreateParam { /** - * 主键 + * primary key */ private Long id; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * databaseName */ private String databaseName; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 状态 + * state */ private String status; /** - * 操作行数 + * Number of operation lines */ private Long operationRows; /** - * 使用时长 + * Length of use */ private Long useTime; /** - * 扩展信息 + * Extended Information */ private String extendInfo; /** - * schema名称 + * schema name */ private String schemaName; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogPageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogPageQueryParam.java index ee6b099f3..826e06ea6 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogPageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationLogPageQueryParam.java @@ -6,34 +6,34 @@ /** * @author moji - * @version UserExecutedDdlPageQueryParam.java, v 0.1 2022年09月25日 14:05 moji Exp $ + * @version UserExecutedDdlPageQueryParam.java, v 0.1 September 25, 2022 14:05 moji Exp $ * @date 2022/09/25 */ @Data public class OperationLogPageQueryParam extends PageQueryParam { /** - * 用户id + * user id */ private Long userId; /** - * 搜索关键词 + * search keyword */ private String searchKey; /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * 数据库名称 + * database name */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationPageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationPageQueryParam.java index d0232b300..38f2f5f2b 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationPageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationPageQueryParam.java @@ -6,34 +6,34 @@ /** * @author moji - * @version UserSavedDdlPageQueryParam.java, v 0.1 2022年09月25日 14:05 moji Exp $ + * @version UserSavedDdlPageQueryParam.java, v 0.1 September 25, 2022 14:05 moji Exp $ * @date 2022/09/25 */ @Data public class OperationPageQueryParam extends PageQueryParam { /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * databaseName */ private String databaseName; /** - * ddl语句状态:DRAFT/RELEASE + * ddl statement status: DRAFT/RELEASE */ private String status; /** - * 搜索关键词 + * search keyword */ private String searchKey; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; @@ -53,7 +53,7 @@ public class OperationPageQueryParam extends PageQueryParam { private String operationType; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationQueryParam.java index fbcee3508..598b76130 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationQueryParam.java @@ -14,13 +14,13 @@ public class OperationQueryParam { /** - * 主键 + * primary key */ @NonNull private Long id; /** - * 用户id + * user id */ @NonNull private Long userId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationSavedParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationSavedParam.java index 907c9ceb9..24c040cd3 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationSavedParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationSavedParam.java @@ -4,49 +4,49 @@ /** * @author moji - * @version UserSavedDdlCreateParam.java, v 0.1 2022年09月25日 15:40 moji Exp $ + * @version UserSavedDdlCreateParam.java, v 0.1 September 25, 2022 15:40 moji Exp $ * @date 2022/09/25 */ @Data public class OperationSavedParam { /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * databaseName */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; /** - * 保存名称 + * save name */ private String name; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl语句状态:DRAFT/RELEASE + * ddl statement status: DRAFT/RELEASE */ private String status; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationUpdateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationUpdateParam.java index 6f06cc5d3..bcd19b5ac 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationUpdateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/operation/OperationUpdateParam.java @@ -6,55 +6,55 @@ /** * @author moji - * @version UserSavedDdlCreateParam.java, v 0.1 2022年09月25日 15:40 moji Exp $ + * @version UserSavedDdlCreateParam.java, v 0.1 September 25, 2022 15:40 moji Exp $ * @date 2022/09/25 */ @Data public class OperationUpdateParam { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * databaseName */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; /** - * 保存名称 + * save name */ private String name; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl语句状态:DRAFT/RELEASE + * ddl statement status: DRAFT/RELEASE */ private String status; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamCreateParam.java index f8a3f39e5..b85679eff 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamCreateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamCreateParam.java @@ -11,19 +11,19 @@ @Data public class TeamCreateParam { /** - * 团队编码 + * team coding */ @NotNull private String code; /** - * 团队名称 + * Team Name */ @NotNull private String name; /** - * 团队状态 + * Team status * * @see ai.chat2db.server.domain.api.enums.ValidStatusEnum */ @@ -32,7 +32,7 @@ public class TeamCreateParam { /** - * 角色编码 + * role coding * * @see ai.chat2db.server.domain.api.enums.RoleCodeEnum */ @@ -40,7 +40,7 @@ public class TeamCreateParam { private String roleCode; /** - * 团队描述 + * Team description */ private String description; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamSelector.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamSelector.java index 5be026ec1..33ed2ef9d 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamSelector.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamSelector.java @@ -16,7 +16,7 @@ @AllArgsConstructor public class TeamSelector { /** - * 修改人用户 + * Modifier user */ private Boolean modifiedUser; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamUpdateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamUpdateParam.java index 047c05a27..30cb66d17 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamUpdateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/TeamUpdateParam.java @@ -11,32 +11,32 @@ @Data public class TeamUpdateParam { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 团队名称 + * Team Name */ private String name; /** - * 团队状态 + * Team status * * @see ai.chat2db.server.domain.api.enums.ValidStatusEnum */ private String status; /** - * 角色编码 + * role coding * * @see ai.chat2db.server.domain.api.enums.RoleCodeEnum */ private String roleCode; /** - * 团队描述 + * Team description */ private String description; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserComprehensivePageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserComprehensivePageQueryParam.java index 747ce57ca..8699f35d4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserComprehensivePageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserComprehensivePageQueryParam.java @@ -12,12 +12,12 @@ public class TeamUserComprehensivePageQueryParam extends PageQueryParam { /** - * 团队id + * team id */ private Long teamId; /** - * 用户id + * user id */ private Long userId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserPageQueryParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserPageQueryParam.java index 80cc51160..98a4adcf6 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserPageQueryParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserPageQueryParam.java @@ -13,13 +13,13 @@ public class TeamUserPageQueryParam extends PageQueryParam { /** - * 团队id + * team id */ @NotNull private Long teamId; /** - * 用户id + * user id */ @NotNull private Long userId; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserSelector.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserSelector.java index a14e74efb..936a5483e 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserSelector.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/team/user/TeamUserSelector.java @@ -16,12 +16,12 @@ @AllArgsConstructor public class TeamUserSelector { /** - * 团队 + * Team */ private Boolean team; /** - * 用户 + * User */ private Boolean user; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserCreateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserCreateParam.java index eb75caea7..3c2ccd6d6 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserCreateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserCreateParam.java @@ -13,31 +13,31 @@ @Data public class UserCreateParam { /** - * 用户名 + * userName */ @NotNull private String userName; /** - * 密码 + * password */ @NotNull private String password; /** - * 昵称 + * Nick name */ @NotNull private String nickName; /** - * 邮箱 + * Mail */ @NotNull private String email; /** - * 角色编码 + * role coding * * @see RoleCodeEnum */ @@ -45,7 +45,7 @@ public class UserCreateParam { private String roleCode; /** - * 用户状态 + * user status * * @see ValidStatusEnum */ diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserSelector.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserSelector.java index 0f25ce938..2dbc799d0 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserSelector.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserSelector.java @@ -16,7 +16,7 @@ @AllArgsConstructor public class UserSelector { /** - * 修改人用户 + * Modifier user */ private Boolean modifiedUser; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserUpdateParam.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserUpdateParam.java index 1b6358cbe..e6ed3836a 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserUpdateParam.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/user/UserUpdateParam.java @@ -13,39 +13,39 @@ @Data public class UserUpdateParam { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 密码 + * password */ @NotNull private String password; /** - * 昵称 + * Nick name */ @NotNull private String nickName; /** - * 邮箱 + * Mail */ @NotNull private String email; /** - * 角色编码 + * role coding * * @see RoleCodeEnum */ private String roleCode; /** - * 用户状态 + * user status * * @see ValidStatusEnum */ diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ChartService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ChartService.java index c831cbc5a..dd579e0c7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ChartService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ChartService.java @@ -15,12 +15,12 @@ /** * @author moji - * @version ChartService.java, v 0.1 2023年06月09日 15:28 moji Exp $ + * @version ChartService.java, v 0.1 June 9, 2023 15:28 moji Exp $ * @date 2023/06/09 */ public interface ChartService { /** - * 保存报表 + * Save report * * @param param * @return @@ -28,7 +28,7 @@ public interface ChartService { DataResult createWithPermission(ChartCreateParam param); /** - * 更新报表 + * Update report * * @param param * @return @@ -36,7 +36,7 @@ public interface ChartService { ActionResult updateWithPermission(ChartUpdateParam param); /** - * 根据id查询 + * Query based on id * * @param id * @return @@ -44,7 +44,7 @@ public interface ChartService { DataResult find(@NotNull Long id); /** - * 查询一条数据 + * Query a piece of data * * @param param * @return @@ -52,7 +52,7 @@ public interface ChartService { DataResult queryExistent(@NotNull ChartQueryParam param); /** - * 查询一条数据 + * Query a piece of data * * @param id * @return @@ -60,7 +60,7 @@ public interface ChartService { DataResult queryExistent(@NotNull Long id); /** - * 查询多条数据 + * Query multiple pieces of data * * @param param * @return @@ -68,7 +68,7 @@ public interface ChartService { ListResult listQuery(@NotNull ChartListQueryParam param); /** - * 通过ID查询图表列表 + * Query chart list by ID * * @param ids * @return @@ -76,7 +76,7 @@ public interface ChartService { ListResult queryByIds(@NotEmpty List ids); /** - * 删除 + * delete * * @param id * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConfigService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConfigService.java index acab8df0c..43cc750e4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConfigService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConfigService.java @@ -15,7 +15,7 @@ public interface ConfigService { /** - * 创建配置 + * Create configuration * * @param param * @return @@ -23,7 +23,7 @@ public interface ConfigService { ActionResult create(SystemConfigParam param); /** - * 修改配置 + * Change setting * * @param param * @return @@ -31,14 +31,14 @@ public interface ConfigService { ActionResult update(SystemConfigParam param); /** - * 插入或者更新 + * insert or update * @param param * @return */ ActionResult createOrUpdate(SystemConfigParam param); /** - * 根据code查询 + * Query based on code * * @param code * @return @@ -46,7 +46,7 @@ public interface ConfigService { DataResult find(@NotNull String code); /** - * 删除 + * delete * * @param code * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConsoleService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConsoleService.java index e500841e6..59b4e9688 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConsoleService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ConsoleService.java @@ -5,16 +5,16 @@ import ai.chat2db.server.tools.base.wrapper.result.ActionResult; /** - * 数据源管理服务 + * Data source management services * * @author moji - * @version DataSourceCoreService.java, v 0.1 2022年09月23日 15:22 moji Exp $ + * @version DataSourceCoreService.java, v 0.1 September 23, 2022 15:22 moji Exp $ * @date 2022/09/23 */ public interface ConsoleService { /** - * 创建console链接 + * Create console link * * @param param * @return @@ -22,7 +22,7 @@ public interface ConsoleService { ActionResult createConsole(ConsoleConnectParam param); /** - * 关闭连接 + * close connection * * @param param * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DashboardService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DashboardService.java index 645f9df60..6189293d7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DashboardService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DashboardService.java @@ -12,13 +12,13 @@ /** * @author moji - * @version DashboardService.java, v 0.1 2023年06月09日 15:28 moji Exp $ + * @version DashboardService.java, v 0.1 June 9, 2023 15:28 moji Exp $ * @date 2023/06/09 */ public interface DashboardService { /** - * 保存报表 + * Save report * * @param param * @return @@ -26,7 +26,7 @@ public interface DashboardService { DataResult createWithPermission(DashboardCreateParam param); /** - * 更新报表 + * Update report * * @param param * @return @@ -34,7 +34,7 @@ public interface DashboardService { ActionResult updateWithPermission(DashboardUpdateParam param); /** - * 根据id查询 + * Query based on id * * @param id * @return @@ -42,7 +42,7 @@ public interface DashboardService { DataResult find(@NotNull Long id); /** - * 查询一条数据 + * Query a piece of data * * @param param * @param selector @@ -51,7 +51,7 @@ public interface DashboardService { DataResult queryExistent(@NotNull DashboardQueryParam param); /** - * 查询一条数据 + * Query a piece of data * * @param id * @return @@ -59,7 +59,7 @@ public interface DashboardService { DataResult queryExistent(@NotNull Long id); /** - * 删除 + * delete * * @param id * @return @@ -67,7 +67,7 @@ public interface DashboardService { ActionResult deleteWithPermission(@NotNull Long id); /** - * 查询报表列表 + * Query report list * * @param param * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DataSourceService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DataSourceService.java index e9f706315..7173e8a51 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DataSourceService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DataSourceService.java @@ -17,16 +17,16 @@ import jakarta.validation.constraints.NotNull; /** - * 数据源管理服务 + * Data source management services * * @author moji - * @version DataSourceCoreService.java, v 0.1 2022年09月23日 15:22 moji Exp $ + * @version DataSourceCoreService.java, v 0.1 September 23, 2022 15:22 moji Exp $ * @date 2022/09/23 */ public interface DataSourceService { /** - * 创建数据源连接 + * Create data source connection * * @param param * @return @@ -34,7 +34,7 @@ public interface DataSourceService { DataResult createWithPermission(DataSourceCreateParam param); /** - * 更新数据源连接 + * Update data source connection * * @param param * @return @@ -42,7 +42,7 @@ public interface DataSourceService { DataResult updateWithPermission(DataSourceUpdateParam param); /** - * 删除数据源连接 + * Delete data source connection * * @param id * @return @@ -50,7 +50,7 @@ public interface DataSourceService { ActionResult deleteWithPermission(@NotNull Long id); /** - * 根据id查询数据源连接详情 + * Query data source connection details based on id * * @param id * @return @@ -58,7 +58,7 @@ public interface DataSourceService { DataResult queryById(@NotNull Long id); /** - * 根据id查询数据源连接详情 + * Query data source connection details based on id * * @param id * @return @@ -67,7 +67,7 @@ public interface DataSourceService { DataResult queryExistent(@NotNull Long id, DataSourceSelector selector); /** - * 克隆连接 + * clone connection * * @param id * @return @@ -75,7 +75,7 @@ public interface DataSourceService { DataResult copyByIdWithPermission(@NotNull Long id); /** - * 分页查询数据源列表 + * Paginated query data source list * * @param param * @param selector @@ -84,7 +84,7 @@ public interface DataSourceService { PageResult queryPage(DataSourcePageQueryParam param, DataSourceSelector selector); /** - * 分页查询数据源列表 + * Paginated query data source list * Need to determine permissions * * @param param @@ -95,7 +95,7 @@ public interface DataSourceService { PageResult queryPageWithPermission(DataSourcePageQueryParam param, DataSourceSelector selector); /** - * 通过ID列表查询数据源 + * Query data source by ID list * * @param ids * @return @@ -104,7 +104,7 @@ public interface DataSourceService { ListResult queryByIds(List ids); /** - * 通过ID列表查询数据源 + * Query data source by ID list * * @param idList * @return @@ -112,7 +112,7 @@ public interface DataSourceService { ListResult listQuery(List idList, DataSourceSelector selector); /** - * 数据源连接测试 + * Data source connection test * * @param param * @return @@ -120,7 +120,7 @@ public interface DataSourceService { ActionResult preConnect(DataSourcePreConnectParam param); /** - * 连接数据源 + * Connect to data source * * @param id * @return @@ -128,7 +128,7 @@ public interface DataSourceService { ListResult connect(Long id); /** - * 关闭数据源连接 + * Close data source connection * * @param id * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DatabaseService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DatabaseService.java index 81957a0ac..c990eec48 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DatabaseService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DatabaseService.java @@ -2,23 +2,26 @@ import ai.chat2db.server.domain.api.param.*; import ai.chat2db.server.domain.api.param.datasource.DatabaseCreateParam; +import ai.chat2db.server.domain.api.param.datasource.DatabaseExportParam; import ai.chat2db.server.domain.api.param.datasource.DatabaseQueryAllParam; import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.spi.model.*; import ai.chat2db.server.tools.base.wrapper.result.ActionResult; import ai.chat2db.server.tools.base.wrapper.result.ListResult; +import java.sql.SQLException; + /** - * 数据源管理服务 + * Data source management services * * @author moji - * @version DataSourceCoreService.java, v 0.1 2022年09月23日 15:22 moji Exp $ + * @version DataSourceCoreService.java, v 0.1 September 23, 2022 15:22 moji Exp $ * @date 2022/09/23 */ public interface DatabaseService { /** - * 查询数据源下的所有database + * Query all databases under the data source * * @param param * @return @@ -26,7 +29,7 @@ public interface DatabaseService { ListResult queryAll(DatabaseQueryAllParam param); /** - * 查询某个database下的schema + * Query the schema under a database * @param param * @return */ @@ -42,7 +45,7 @@ public interface DatabaseService { /** - * 删除数据库 + * Delete database * * @param param * @return @@ -50,7 +53,7 @@ public interface DatabaseService { ActionResult deleteDatabase(DatabaseCreateParam param); /** - * 创建database + * create database * * @param param * @return @@ -58,14 +61,14 @@ public interface DatabaseService { DataResult createDatabase(Database param); /** - * 修改database + * Modify database * * @return */ ActionResult modifyDatabase( DatabaseCreateParam param) ; /** - * 删除schema + * Delete schema * * @param param * @return @@ -73,7 +76,7 @@ public interface DatabaseService { ActionResult deleteSchema(SchemaOperationParam param) ; /** - * 创建schema + * Create schema * * @param schema * @return @@ -81,10 +84,12 @@ public interface DatabaseService { DataResult createSchema(Schema schema); /** - * 修改schema + * Modify schema * * @param request * @return */ ActionResult modifySchema( SchemaOperationParam request); + + String exportDatabase(DatabaseExportParam param) throws SQLException; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DlTemplateService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DlTemplateService.java index cfee4cd12..b4a745c80 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DlTemplateService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/DlTemplateService.java @@ -10,16 +10,16 @@ import ai.chat2db.server.tools.base.wrapper.result.ListResult; /** - * 数据源管理服务 + * Data source management services * * @author moji - * @version DataSourceCoreService.java, v 0.1 2022年09月23日 15:22 moji Exp $ + * @version DataSourceCoreService.java, v 0.1 September 23, 2022 15:22 moji Exp $ * @date 2022/09/23 */ public interface DlTemplateService { /** - * 数据源执行dl + * data source execution dl * * @param param * @return @@ -28,7 +28,15 @@ public interface DlTemplateService { /** - * 数据源执行update + * + * @param param + * @return + */ + ListResult executeSelectTable(DlExecuteParam param); + + + /** + * Data source execution update * * @param param * @return @@ -36,22 +44,20 @@ public interface DlTemplateService { DataResult executeUpdate(DlExecuteParam param); /** - * 执行统计sql + * Execute statistics sql * * @param param * @return */ DataResult count(DlCountParam param); - /** - * 更新查询结果 + * Update query results * @param param * @return */ DataResult updateSelectResult(UpdateSelectResultParam param); - /** * * @param param diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationLogService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationLogService.java index 4872413b9..f151440ac 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationLogService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationLogService.java @@ -7,16 +7,16 @@ import ai.chat2db.server.tools.base.wrapper.result.PageResult; /** - * 用户执行ddl + * User executes ddl * * @author moji - * @version UserExecutedDdlCoreService.java, v 0.1 2022年09月23日 17:35 moji Exp $ + * @version UserExecutedDdlCoreService.java, v 0.1 September 23, 2022 17:35 moji Exp $ * @date 2022/09/23 */ public interface OperationLogService { /** - * 创建用户执行的ddl记录 + * Create ddl record executed by user * * @param param * @return @@ -24,7 +24,7 @@ public interface OperationLogService { DataResult create(OperationLogCreateParam param); /** - * 查询用户执行的ddl记录 + * Query the ddl records executed by the user * * @param param * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationService.java index 4715ec3f2..48ed2d480 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/OperationService.java @@ -11,16 +11,16 @@ import jakarta.validation.constraints.NotNull; /** - * 用户保存ddl + * user save ddl * * @author moji - * @version UserSavedDdlCoreService.java, v 0.1 2022年09月23日 17:35 moji Exp $ + * @version UserSavedDdlCoreService.java, v 0.1 September 23, 2022 17:35 moji Exp $ * @date 2022/09/23 */ public interface OperationService { /** - * 保存用户的ddl + * Save user's ddl * * @param param * @return @@ -28,7 +28,7 @@ public interface OperationService { DataResult createWithPermission(OperationSavedParam param); /** - * 更新用户的ddl + * Update user's ddl * * @param param * @return @@ -36,7 +36,7 @@ public interface OperationService { ActionResult updateWithPermission(OperationUpdateParam param); /** - * 根据id查询 + * Query based on id * * @param id * @return @@ -44,21 +44,21 @@ public interface OperationService { DataResult find(@NotNull Long id); /** - * 根据id查询 + * Query based on id * * @param id * @return */ DataResult queryExistent(@NotNull Long id); /** - * 查询一条数据 + * Query a piece of data * * @param param * @return */ DataResult queryExistent(@NotNull OperationQueryParam param); /** - * 删除 + * delete * * @param id * @return @@ -66,7 +66,7 @@ public interface OperationService { ActionResult deleteWithPermission(@NotNull Long id); /** - * 查询用户执行的ddl记录 + * Query the ddl records executed by the user * * @param param * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ProcedureService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ProcedureService.java index 3df6301bf..d4f8053c7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ProcedureService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/ProcedureService.java @@ -1,10 +1,13 @@ package ai.chat2db.server.domain.api.service; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.server.tools.base.wrapper.result.ListResult; import ai.chat2db.spi.model.Procedure; import jakarta.validation.constraints.NotEmpty; +import java.sql.SQLException; + public interface ProcedureService { /** @@ -23,4 +26,12 @@ public interface ProcedureService { * @return */ DataResult detail(String databaseName, String schemaName, String procedureName); + + /** + * @param databaseName + * @param schemaName + * @param procedure + * @return + */ + ActionResult update(String databaseName, String schemaName, Procedure procedure) throws SQLException; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java index 93f245af2..b962c3ba5 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TableService.java @@ -10,16 +10,16 @@ import ai.chat2db.server.tools.base.wrapper.result.PageResult; /** - * 数据源管理服务 + * Data source management services * * @author moji - * @version DataSourceCoreService.java, v 0.1 2022年09月23日 15:22 moji Exp $ + * @version DataSourceCoreService.java, v 0.1 September 23, 2022 15:22 moji Exp $ * @date 2022/09/23 */ public interface TableService { /** - * 查询表信息 + * Query table information * * @param param * @return @@ -27,7 +27,7 @@ public interface TableService { DataResult showCreateTable(ShowCreateTableParam param); /** - * 删除表 + * Delete table * * @param param * @return @@ -35,7 +35,7 @@ public interface TableService { ActionResult drop(DropParam param); /** - * 创建表结构的样例 + * Example of creating a table structure * * @param dbType * @return @@ -43,7 +43,7 @@ public interface TableService { DataResult createTableExample(String dbType); /** - * 修改表结构的样例 + * Example of modifying table structure * * @param dbType * @return @@ -51,7 +51,7 @@ public interface TableService { DataResult alterTableExample(String dbType); /** - * 查询表信息 + * Query table information * * @param param * @return @@ -59,7 +59,7 @@ public interface TableService { DataResult
query(TableQueryParam param, TableSelector selector); /** - * 构建sql + * build sql * * @param oldTable * @param newTable @@ -68,7 +68,7 @@ public interface TableService { ListResult buildSql(Table oldTable, Table newTable); /** - * 分页查询表信息 + * Pagination query table information * * @param param * @return @@ -77,14 +77,14 @@ public interface TableService { /** - * 查询表信息 + * Query table information * @param param * @return */ ListResult queryTables(TablePageQueryParam param); /** - * 查询表包含的字段 + * Fields included in the query table * * @param param * @return @@ -92,7 +92,7 @@ public interface TableService { List queryColumns(TableQueryParam param); /** - * 查询表索引 + * Query table index * * @param param * @return @@ -129,4 +129,12 @@ public interface TableService { * @return */ DataResult checkTableVector(TableVectorParam param); + + + /** + * Get dml template sql + * @param param table query param + * @return sql + */ + DataResult copyDmlSql(DmlSqlCopyParam param); } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TaskService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TaskService.java new file mode 100644 index 000000000..e8d44bd8e --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TaskService.java @@ -0,0 +1,45 @@ +package ai.chat2db.server.domain.api.service; + +import ai.chat2db.server.domain.api.model.Task; +import ai.chat2db.server.domain.api.param.TaskCreateParam; +import ai.chat2db.server.domain.api.param.TaskPageParam; +import ai.chat2db.server.domain.api.param.TaskUpdateParam; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.tools.base.wrapper.result.PageResult; + +public interface TaskService { + + /** + * create task + * + * @param param task param + * @return task id + */ + DataResult create(TaskCreateParam param); + + /** + * update task status + * + * @param param task param + * @return action result + */ + ActionResult updateStatus(TaskUpdateParam param); + + + /** + * get task list + * + * @param param task id + * @return task + */ + PageResult page(TaskPageParam param); + + /** + * get task + * + * @param id task id + * @return task + */ + DataResult get(Long id); +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/UserService.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/UserService.java index 1c98ca4f2..5e50ef20d 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/UserService.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/UserService.java @@ -13,14 +13,14 @@ import ai.chat2db.server.tools.base.wrapper.result.PageResult; /** - * 用户服务 + * User service * * @author Jiaju Zhuang */ public interface UserService { /** - * 查询用户信息 + * Query user information * * @param id * @return @@ -43,7 +43,7 @@ public interface UserService { ListResult listQuery(List idList); /** - * 查询用户信息 + * Query user information * * @param param * @return @@ -51,21 +51,21 @@ public interface UserService { PageResult pageQuery(UserPageQueryParam param, UserSelector selector); /** - * 更新用户信息 + * Update user information * @param user * @return */ DataResult update(UserUpdateParam user); /** - * 删除用户 + * delete users * @param id * @return */ ActionResult delete(Long id); /** - * 创建一个用户 + * Create a user * @param user * @return */ diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/pom.xml b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/pom.xml index ce19bc340..47a86c68a 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/pom.xml +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/pom.xml @@ -111,11 +111,6 @@ chat2db-presto ${revision} - - ai.chat2db - chat2db-redis - ${revision} - ai.chat2db chat2db-sqlite diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/cache/CacheManage.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/cache/CacheManage.java index 778706d20..db055fbd7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/cache/CacheManage.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/cache/CacheManage.java @@ -25,11 +25,11 @@ public class CacheManage { static { cacheManager = CacheManagerBuilder.newCacheManagerBuilder() - .with(CacheManagerBuilder.persistence(PATH)) // 确保这个路径是存在且有写权限的 + .with(CacheManagerBuilder.persistence(PATH)) // Make sure this path exists and has write permissions .withCache(CACHE, CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .heap(1000, EntryUnit.ENTRIES) - .disk(20, MemoryUnit.GB, true))) // 磁盘持久化设置为true + .disk(20, MemoryUnit.GB, true))) // Disk persistence is set to true .build(true); } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/ChartConverter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/ChartConverter.java index 8db1b6c19..93de7e021 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/ChartConverter.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/ChartConverter.java @@ -11,14 +11,14 @@ /** * @author moji - * @version ChartConverter.java, v 0.1 2023年06月09日 17:13 moji Exp $ + * @version ChartConverter.java, v 0.1 June 9, 2023 17:13 moji Exp $ * @date 2023/06/09 */ @Mapper(componentModel = "spring") public abstract class ChartConverter { /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -26,7 +26,7 @@ public abstract class ChartConverter { public abstract ChartDO param2do(ChartCreateParam param); /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -34,7 +34,7 @@ public abstract class ChartConverter { public abstract ChartDO updateParam2do(ChartUpdateParam param); /** - * 模型转换 + * Model conversion * * @param chartDO * @return @@ -42,7 +42,7 @@ public abstract class ChartConverter { public abstract Chart do2model(ChartDO chartDO); /** - * 模型转换 + * Model conversion * * @param chartDOS * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DashboardConverter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DashboardConverter.java index e82f35634..5fbd647bd 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DashboardConverter.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DashboardConverter.java @@ -11,14 +11,14 @@ /** * @author moji - * @version ChartConverter.java, v 0.1 2023年06月09日 17:13 moji Exp $ + * @version ChartConverter.java, v 0.1 June 9, 2023 17:13 moji Exp $ * @date 2023/06/09 */ @Mapper(componentModel = "spring") public abstract class DashboardConverter { /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -26,7 +26,7 @@ public abstract class DashboardConverter { public abstract DashboardDO param2do(DashboardCreateParam param); /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -34,7 +34,7 @@ public abstract class DashboardConverter { public abstract DashboardDO updateParam2do(DashboardUpdateParam param); /** - * 模型转换 + * Model conversion * * @param chartDO * @return @@ -42,7 +42,7 @@ public abstract class DashboardConverter { public abstract Dashboard do2model(DashboardDO chartDO); /** - * 模型转换 + * Model conversion * * @param chartDOS * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DataSourceConverter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DataSourceConverter.java index ea308a390..eb207de8d 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DataSourceConverter.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/DataSourceConverter.java @@ -27,7 +27,7 @@ /** * @author moji - * @version DataSourceCoreConverter.java, v 0.1 2022年09月23日 15:53 moji Exp $ + * @version DataSourceCoreConverter.java, v 0.1 September 23, 2022 15:53 moji Exp $ * @date 2022/09/23 */ @Slf4j @@ -39,7 +39,7 @@ public abstract class DataSourceConverter { private DataSourceService dataSourceService; /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -115,7 +115,7 @@ protected String decryptString(DataSourceDO param) { } /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -136,7 +136,7 @@ protected String decryptString(DataSourceDO param) { public abstract DataSourceDO param2do(DataSourceUpdateParam param); /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -144,7 +144,7 @@ protected String decryptString(DataSourceDO param) { public abstract ConsoleCreateParam param2consoleParam(ConsoleConnectParam param); /** - * 参数转换 + * Parameter conversion * * @param dataSourcePreConnectParam * @return @@ -157,7 +157,7 @@ public abstract DataSourceTestParam param2param( DataSourcePreConnectParam dataSourcePreConnectParam); /** - * 模型转换 + * Model conversion * * @param dataSourceDO * @return @@ -184,7 +184,7 @@ public abstract DataSourceTestParam param2param( public abstract DataSource do2dto(DataSourceDO dataSourceDO); /** - * 模型转换 + * Model conversion * * @param dataSourceDOList * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationConverter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationConverter.java index c439b707d..9db1d145d 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationConverter.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationConverter.java @@ -13,14 +13,14 @@ /** * @author moji - * @version UserSavedDdlCoreConverter.java, v 0.1 2022年09月25日 15:50 moji Exp $ + * @version UserSavedDdlCoreConverter.java, v 0.1 September 25, 2022 15:50 moji Exp $ * @date 2022/09/25 */ @Mapper(componentModel = "spring") public abstract class OperationConverter { /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -31,7 +31,7 @@ public abstract class OperationConverter { public abstract OperationSavedDO param2do(OperationSavedParam param); /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -42,7 +42,7 @@ public abstract class OperationConverter { public abstract OperationSavedDO param2do(OperationUpdateParam param); /** - * 模型转换 + * Model conversion * * @param userSavedDdlDO * @return @@ -53,7 +53,7 @@ public abstract class OperationConverter { public abstract Operation do2dto(OperationSavedDO userSavedDdlDO); /** - * 模型转换 + * Model conversion * * @param userSavedDdlDOS * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationLogConverter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationLogConverter.java index 9a0de55ba..5e3ce3bad 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationLogConverter.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/OperationLogConverter.java @@ -10,14 +10,14 @@ /** * @author moji - * @version UserExecutedDdlCoreConverter.java, v 0.1 2022年09月25日 14:08 moji Exp $ + * @version UserExecutedDdlCoreConverter.java, v 0.1 September 25, 2022 14:08 moji Exp $ * @date 2022/09/25 */ @Mapper(componentModel = "spring") public abstract class OperationLogConverter { /** - * 参数转换 + * Parameter conversion * * @param param * @return @@ -25,7 +25,7 @@ public abstract class OperationLogConverter { public abstract OperationLogDO param2do(OperationLogCreateParam param); /** - * 模型转换 + * Model conversion * * @param userExecutedDdlDO * @return @@ -33,7 +33,7 @@ public abstract class OperationLogConverter { public abstract OperationLog do2dto(OperationLogDO userExecutedDdlDO); /** - * 模型转换 + * Model conversion * * @param userExecutedDdlDOS * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/TaskConverter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/TaskConverter.java new file mode 100644 index 000000000..e1f66aa81 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/TaskConverter.java @@ -0,0 +1,21 @@ +package ai.chat2db.server.domain.core.converter; + +import ai.chat2db.server.domain.api.model.Task; +import ai.chat2db.server.domain.api.param.TaskCreateParam; +import ai.chat2db.server.domain.repository.entity.TaskDO; +import lombok.extern.slf4j.Slf4j; +import org.mapstruct.Mapper; + +import java.util.List; +@Slf4j +@Mapper(componentModel = "spring") +public abstract class TaskConverter { + + public abstract TaskDO todo(TaskCreateParam param); + + + public abstract Task toModel(TaskDO param); + + + public abstract List toModel(List param); +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/UserConverter.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/UserConverter.java index 3ca22755b..e43df2943 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/UserConverter.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/UserConverter.java @@ -18,7 +18,7 @@ import org.springframework.context.annotation.Lazy; /** - * 转换器 + * converter * * @author Jiaju Zhuang */ @@ -30,7 +30,7 @@ public abstract class UserConverter { private UserService userService; /** - * 转换 + * Convert * * @param data * @return @@ -41,7 +41,7 @@ public abstract class UserConverter { public abstract User do2dto(DbhubUserDO data); /** - * 转换 + * Convert * * @param datas * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ChartServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ChartServiceImpl.java index 4225a8fe8..db41c7aa3 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ChartServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ChartServiceImpl.java @@ -38,7 +38,7 @@ /** * @author moji - * @version ChartServiceImpl.java, v 0.1 2023年06月09日 16:06 moji Exp $ + * @version ChartServiceImpl.java, v 0.1 June 9, 2023 16:06 moji Exp $ * @date 2023/06/09 */ @Service @@ -159,7 +159,7 @@ public ListResult queryByIds(List ids) { } /** - * 回填数据源信息 + * Backfill data source information * * @param result */ diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConsoleServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConsoleServiceImpl.java index 00904a674..b29c1c178 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConsoleServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ConsoleServiceImpl.java @@ -11,7 +11,7 @@ /** * @author moji - * @version DataSourceCoreServiceImpl.java, v 0.1 2022年09月23日 15:51 moji Exp $ + * @version DataSourceCoreServiceImpl.java, v 0.1 September 23, 2022 15:51 moji Exp $ * @date 2022/09/23 */ @Service diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DashboardServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DashboardServiceImpl.java index b3e15d705..038731adf 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DashboardServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DashboardServiceImpl.java @@ -34,7 +34,7 @@ /** * @author moji - * @version DashboardServiceImpl.java, v 0.1 2023年06月09日 16:06 moji Exp $ + * @version DashboardServiceImpl.java, v 0.1 June 9, 2023 16:06 moji Exp $ * @date 2023/06/09 */ @Service diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DataSourceServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DataSourceServiceImpl.java index 79313e7bf..db7fa7bd1 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DataSourceServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DataSourceServiceImpl.java @@ -60,7 +60,7 @@ /** * @author moji - * @version DataSourceCoreServiceImpl.java, v 0.1 2022年09月23日 15:51 moji Exp $ + * @version DataSourceCoreServiceImpl.java, v 0.1 September 23, 2022 15:51 moji Exp $ * @date 2022/09/23 */ @Slf4j diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DatabaseServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DatabaseServiceImpl.java index 1c3677b64..c819924c7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DatabaseServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DatabaseServiceImpl.java @@ -7,6 +7,7 @@ import java.util.concurrent.CountDownLatch; import ai.chat2db.server.domain.api.param.datasource.DatabaseCreateParam; +import ai.chat2db.server.domain.api.param.datasource.DatabaseExportParam; import ai.chat2db.server.domain.api.param.datasource.DatabaseQueryAllParam; import ai.chat2db.server.domain.api.param.MetaDataQueryParam; import ai.chat2db.server.domain.api.param.SchemaOperationParam; @@ -17,7 +18,6 @@ import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.server.tools.base.wrapper.result.ListResult; import ai.chat2db.spi.MetaData; -import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.model.Database; import ai.chat2db.spi.model.MetaSchema; import ai.chat2db.spi.model.Schema; @@ -35,7 +35,7 @@ /** * @author moji - * @version DataSourceCoreServiceImpl.java, v 0.1 2022年09月23日 15:51 moji Exp $ + * @version DataSourceCoreServiceImpl.java, v 0.1 September 23, 2022 15:51 moji Exp $ * @date 2022/09/23 */ @Slf4j @@ -177,4 +177,12 @@ public ActionResult modifySchema(SchemaOperationParam param) { return ActionResult.isSuccess(); } + @Override + public String exportDatabase(DatabaseExportParam param) throws SQLException { + return Chat2DBContext.getDBManage().exportDatabase(Chat2DBContext.getConnection(), + param.getDatabaseName(), + param.getSchemaName(), + param.getContainData()); + } + } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DlTemplateServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DlTemplateServiceImpl.java index fb37dc4bd..56dc646ac 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DlTemplateServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/DlTemplateServiceImpl.java @@ -17,7 +17,6 @@ import ai.chat2db.spi.model.*; import ai.chat2db.spi.sql.Chat2DBContext; import ai.chat2db.spi.sql.ConnectInfo; -import ai.chat2db.spi.sql.SQLExecutor; import ai.chat2db.spi.util.JdbcUtils; import ai.chat2db.spi.util.SqlUtils; import com.alibaba.druid.DbType; @@ -28,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -40,7 +40,7 @@ /** * @author moji - * @version DataSourceCoreServiceImpl.java, v 0.1 2022年09月23日 15:51 moji Exp $ + * @version DataSourceCoreServiceImpl.java, v 0.1 September 23, 2022 15:51 moji Exp $ * @date 2022/09/23 */ @Slf4j @@ -61,12 +61,15 @@ public ListResult execute(DlExecuteParam param) { CommandExecutor executor = Chat2DBContext.getMetaData().getCommandExecutor(); Command command = commandConverter.param2model(param); List results = executor.execute(command); + return reBuildHeader(results,param.getSchemaName(),param.getDatabaseName()); + } + + private ListResult reBuildHeader(List results,String schemaName,String databaseName){ ListResult listResult = ListResult.of(results); for (ExecuteResult executeResult : results) { List
headers = executeResult.getHeaderList(); if (executeResult.getSuccess() && executeResult.isCanEdit() && CollectionUtils.isNotEmpty(headers)) { - headers = setColumnInfo(headers, executeResult.getTableName(), param.getSchemaName(), - param.getDatabaseName()); + headers = setColumnInfo(headers, executeResult.getTableName(), schemaName, databaseName); executeResult.setHeaderList(headers); } if (!executeResult.getSuccess()) { @@ -77,12 +80,13 @@ public ListResult execute(DlExecuteParam param) { addOperationLog(executeResult); } return listResult; + } -// if ("SQLSERVER".equalsIgnoreCase(type)) { -// RemoveSpecialGO(param); -// } - - + @Override + public ListResult executeSelectTable(DlExecuteParam param) { + Command command = commandConverter.param2model(param); + List results = Chat2DBContext.getMetaData().getCommandExecutor().executeSelectTable(command); + return reBuildHeader(results,param.getSchemaName(),param.getDatabaseName()); } @Override @@ -123,7 +127,7 @@ public DataResult count(DlCountParam param) { DbType dbType = JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType()); String sql = param.getSql(); - // 解析sql分页 + // Parse sql pagination SQLStatement sqlStatement = SQLUtils.parseSingleStatement(sql, dbType); if (!(sqlStatement instanceof SQLSelectStatement)) { throw new BusinessException("dataSource.sqlAnalysisError"); @@ -135,7 +139,7 @@ public DataResult count(DlCountParam param) { executeResult = Chat2DBContext.getMetaData().getCommandExecutor().execute(sql, Chat2DBContext.getConnection(), true, null, null, valueHandler); } catch (SQLException e) { - log.warn("执行sql:{}异常", sql, e); + log.warn("Execute sql: {} exception", sql, e); executeResult = ExecuteResult.builder() .sql(sql) .success(Boolean.FALSE) @@ -159,8 +163,9 @@ public DataResult count(DlCountParam param) { @Override public DataResult updateSelectResult(UpdateSelectResultParam param) { SqlBuilder sqlBuilder = Chat2DBContext.getSqlBuilder(); - String sql = sqlBuilder.generateSqlBasedOnResults(param.getTableName(), param.getHeaderList(), - param.getOperations()); + QueryResult queryResult = new QueryResult(); + BeanUtils.copyProperties(param, queryResult); + String sql = sqlBuilder.buildSqlByQuery(queryResult); return DataResult.of(sql); } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/JdbcDriverServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/JdbcDriverServiceImpl.java index cf95d0398..849264147 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/JdbcDriverServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/JdbcDriverServiceImpl.java @@ -63,7 +63,7 @@ public DataResult getDrivers(String dbType) { boolean flag = driverExists(driverConfig); if (flag && driverConfigMap.get(driverConfig.getJdbcDriver()) == null) { driverConfigMap.put(driverConfig.getJdbcDriver(), driverConfig); - //TODO :临时解决方案,后续需要优化 + //TODO :Temporary solution, need to be optimized later //setDriverDefaultProperty(driverConfig); } else { log.warn("Driver file not found: {}", driverConfig.getJdbcDriver()); diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationLogServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationLogServiceImpl.java index acf8d1e98..63628adb0 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationLogServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationLogServiceImpl.java @@ -32,7 +32,7 @@ /** * @author moji - * @version UserExecutedDdlCoreServiceImpl.java, v 0.1 2022年09月25日 14:07 moji Exp $ + * @version UserExecutedDdlCoreServiceImpl.java, v 0.1 September 25, 2022 14:07 moji Exp $ * @date 2022/09/25 */ @Service diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationServiceImpl.java index 5b68ec98a..d7e9fbed1 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/OperationServiceImpl.java @@ -40,7 +40,7 @@ /** * @author moji - * @version UserSavedDdlCoreServiceImpl.java, v 0.1 2022年09月25日 15:50 moji Exp $ + * @version UserSavedDdlCoreServiceImpl.java, v 0.1 September 25, 2022 15:50 moji Exp $ * @date 2022/09/25 */ @Service @@ -167,7 +167,7 @@ public PageResult queryPage(OperationPageQueryParam param) { } /** - * 查询数据源信息 + * Query data source information * * @param dataSourceIds * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ProcedureServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ProcedureServiceImpl.java index c6bafe71e..b8dec55c0 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ProcedureServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/ProcedureServiceImpl.java @@ -1,12 +1,15 @@ package ai.chat2db.server.domain.core.impl; import ai.chat2db.server.domain.api.service.ProcedureService; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.server.tools.base.wrapper.result.ListResult; import ai.chat2db.spi.model.Procedure; import ai.chat2db.spi.sql.Chat2DBContext; import org.springframework.stereotype.Service; +import java.sql.SQLException; + @Service public class ProcedureServiceImpl implements ProcedureService { @@ -19,4 +22,9 @@ public ListResult procedures(String databaseName, String schemaName) public DataResult detail(String databaseName, String schemaName, String procedureName) { return DataResult.of(Chat2DBContext.getMetaData().procedure(Chat2DBContext.getConnection(), databaseName, schemaName, procedureName)); } + @Override + public ActionResult update(String databaseName, String schemaName, Procedure procedure) throws SQLException { + Chat2DBContext.getDBManage().updateProcedure(Chat2DBContext.getConnection(), databaseName, schemaName, procedure); + return ActionResult.isSuccess(); + } } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java index 1454772d8..5e0282efc 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TableServiceImpl.java @@ -1,12 +1,5 @@ package ai.chat2db.server.domain.core.impl; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - import ai.chat2db.server.domain.api.enums.TableVectorEnum; import ai.chat2db.server.domain.api.param.*; import ai.chat2db.server.domain.api.service.PinService; @@ -15,7 +8,9 @@ import ai.chat2db.server.domain.core.converter.PinTableConverter; import ai.chat2db.server.domain.core.converter.TableConverter; import ai.chat2db.server.domain.repository.Dbutils; -import ai.chat2db.server.domain.repository.entity.*; +import ai.chat2db.server.domain.repository.entity.TableCacheDO; +import ai.chat2db.server.domain.repository.entity.TableCacheVersionDO; +import ai.chat2db.server.domain.repository.entity.TableVectorMappingDO; import ai.chat2db.server.domain.repository.mapper.TableCacheMapper; import ai.chat2db.server.domain.repository.mapper.TableCacheVersionMapper; import ai.chat2db.server.domain.repository.mapper.TableVectorMappingMapper; @@ -40,12 +35,19 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + import static ai.chat2db.server.domain.core.cache.CacheKey.getColumnKey; import static ai.chat2db.server.domain.core.cache.CacheKey.getTableKey; /** * @author moji - * @version DataSourceCoreServiceImpl.java, v 0.1 2022年09月23日 15:51 moji Exp $ + * @version DataSourceCoreServiceImpl.java, v 0.1 September 23, 2022 15:51 moji Exp $ * @date 2022/09/23 */ @Service @@ -67,7 +69,6 @@ private TableCacheMapper getTableCacheMapper() { private TableConverter tableConverter; - private TableCacheVersionMapper getVersionMapper() { return Dbutils.getMapper(TableCacheVersionMapper.class); } @@ -249,7 +250,7 @@ private void addPrimaryKey(Table newTable, TableColumn column, String status) { keyIndex.setSchemaName(newTable.getSchemaName()); keyIndex.setDatabaseName(newTable.getDatabaseName()); keyIndex.setEditStatus(status); - if(!EditStatus.ADD.name().equals(status)){ + if (!EditStatus.ADD.name().equals(status)) { keyIndex.setOldName(keyIndex.getName()); } indexes.add(keyIndex); @@ -319,7 +320,7 @@ public PageResult
pageQuery(TablePageQueryParam param, TableSelector sele long total = 0; long version = 0L; if (param.isRefresh() || versionDO == null) { - total = addCache(param,versionDO); + total = addCache(param, versionDO); } else { if ("2".equals(versionDO.getStatus())) { version = versionDO.getVersion() - 1; @@ -348,7 +349,7 @@ public PageResult
pageQuery(TablePageQueryParam param, TableSelector sele return PageResult.of(tables, total, param); } - private long addCache(TablePageQueryParam param,TableCacheVersionDO versionDO){ + private long addCache(TablePageQueryParam param, TableCacheVersionDO versionDO) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); String key = getTableKey(param.getDataSourceId(), param.getDatabaseName(), param.getSchemaName()); queryWrapper.eq(TableCacheVersionDO::getKey, key); @@ -386,7 +387,7 @@ public ListResult queryTables(TablePageQueryParam param) { queryWrapper.eq(TableCacheVersionDO::getKey, key); TableCacheVersionDO versionDO = getVersionMapper().selectOne(queryWrapper); if (versionDO == null) { - addCache(param,versionDO); + addCache(param, versionDO); versionDO = getVersionMapper().selectOne(queryWrapper); } long version = "2".equals(versionDO.getStatus()) ? versionDO.getVersion() - 1 : versionDO.getVersion(); @@ -564,7 +565,7 @@ public TableMeta queryTableMeta(TypeQueryParam param) { //filter primary key List indexTypes = tableMeta.getIndexTypes(); if (CollectionUtils.isNotEmpty(indexTypes)) { - List types = indexTypes.stream().filter(indexType -> !"Primary".equals(indexType.getTypeName())).collect(Collectors.toList()); + List types = indexTypes.stream().filter(indexType -> !"Primary".equalsIgnoreCase(indexType.getTypeName())).collect(Collectors.toList()); tableMeta.setIndexTypes(types); } } @@ -596,4 +597,13 @@ public DataResult checkTableVector(TableVectorParam param) { } return DataResult.of(false); } + + @Override + public DataResult copyDmlSql(DmlSqlCopyParam param) { + List columns = queryColumns(param); + SqlBuilder sqlBuilder = Chat2DBContext.getSqlBuilder(); + Table table = Table.builder().name(param.getTableName()).columnList(columns).build(); + String sql = sqlBuilder.getTableDmlSql(table, param.getType()); + return DataResult.of(sql); + } } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TaskServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TaskServiceImpl.java new file mode 100644 index 000000000..25ba9a9fe --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TaskServiceImpl.java @@ -0,0 +1,69 @@ +package ai.chat2db.server.domain.core.impl; + +import ai.chat2db.server.domain.api.enums.DeletedTypeEnum; +import ai.chat2db.server.domain.api.enums.TaskStatusEnum; +import ai.chat2db.server.domain.api.model.Task; +import ai.chat2db.server.domain.api.param.TaskCreateParam; +import ai.chat2db.server.domain.api.param.TaskPageParam; +import ai.chat2db.server.domain.api.param.TaskUpdateParam; +import ai.chat2db.server.domain.api.service.TaskService; +import ai.chat2db.server.domain.core.converter.TaskConverter; +import ai.chat2db.server.domain.repository.MapperUtils; +import ai.chat2db.server.domain.repository.entity.TaskDO; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.tools.base.wrapper.result.PageResult; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.collect.Lists; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class TaskServiceImpl implements TaskService { + + /** + * task converter + */ + @Autowired + private TaskConverter taskConverter; + + @Override + public DataResult create(TaskCreateParam param) { + TaskDO taskDO = taskConverter.todo(param); + taskDO.setDeleted(DeletedTypeEnum.N.name()); + taskDO.setTaskStatus(TaskStatusEnum.INIT.name()); + MapperUtils.getTaskMapper().insert(taskDO); + return DataResult.of(taskDO.getId()); + } + + @Override + public ActionResult updateStatus(TaskUpdateParam param) { + TaskDO taskDO = new TaskDO(); + taskDO.setId(param.getId()); + taskDO.setTaskStatus(param.getTaskStatus()); + taskDO.setContent(param.getContent()); + MapperUtils.getTaskMapper().updateById(taskDO); + return ActionResult.isSuccess(); + } + + @Override + public PageResult page(TaskPageParam param) { + Page page = new Page<>(); + page.setCurrent(param.getPageNo()); + page.setSize(param.getPageSize()); + page.setOrders(Lists.newArrayList(OrderItem.desc("gmt_create"))); + IPage iPage = MapperUtils.getTaskMapper().pageQuery(page, param.getUserId(), DeletedTypeEnum.N.name()); + if (iPage != null) { + return PageResult.of(taskConverter.toModel(iPage.getRecords()), param); + } + return PageResult.empty(param.getPageNo(), param.getPageSize()); + } + + @Override + public DataResult get(Long id) { + TaskDO task = MapperUtils.getTaskMapper().selectById(id); + return DataResult.of(taskConverter.toModel(task)); + } +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/UserServiceImpl.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/UserServiceImpl.java index 7a3947bba..fc09fc820 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/UserServiceImpl.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/UserServiceImpl.java @@ -41,9 +41,9 @@ import org.springframework.stereotype.Service; /** - * 用户服务 + * User service * - * @author 是仪 + * @author Shi Yi */ @Service public class UserServiceImpl implements UserService { diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/DesUtil.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/DesUtil.java index a5eaf3ab5..1da6ef14a 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/DesUtil.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/DesUtil.java @@ -22,7 +22,7 @@ /** * @author moji - * @version DESUtil.java, v 0.1 2022年12月26日 19:54 moji Exp $ + * @version DESUtil.java, v 0.1 December 26, 2022 19:54 moji Exp $ * @date 2022/12/26 */ public class DesUtil { @@ -43,7 +43,7 @@ public class DesUtil { public static final String CBC = "CBC"; /** - * iv向量 + * iv vector */ private static final byte[] DESIV = { (byte) 0xCE, (byte) 0x35, (byte) 0x5, (byte) 0xD, (byte) 0x98, (byte) 0x91, (byte) 0x8, (byte) 0xA }; @@ -59,27 +59,27 @@ public class DesUtil { private static final String SHA1PRNG = "SHA1PRNG"; /** - * DES默认模式 + * DES default mode */ private static final String DES = "DES"; /** - * CBC加密模式 + * CBC encryption mode */ private static final String DES_CBC_PKCS5PADDING = "DES/CBC/PKCS5Padding"; /** - * OFB加密模式 + * OFB encryption mode */ private static final String DES_OFB_PKCS5PADDING = "DES/OFB/PKCS5Padding"; /** - * CFB加密模式 + * CFB encryption mode */ private static final String DES_CFB_PKCS5_PADDING = "DES/CFB/PKCS5Padding"; /** - * 加密模式 + * encryption mode */ private static final int ENCRYPT_MODE = 1; @@ -89,12 +89,12 @@ public class DesUtil { public static final String DES_KEY = "dbhub"; /** - * 解密模式 + * Decryption mode */ private static final int DECRYPT_MODE = 2; /** - * 密钥 + * private key */ private Key key; @@ -111,8 +111,8 @@ public void setKey(Key key) { } /** - * 通过密钥获得key - * @param secretKey 密钥 + * Get key through private key + * @param secretKey private key * @author sucb * @date 2017年2月28日下午1:17:58 */ @@ -138,13 +138,13 @@ public void getKey(String secretKey) { } /** - * 字符串des加密 - * @param data 需要加密的字符串 - * @param encryptType 加密模式 (ECB/CBC/OFB/CFB) - * @return 加密结果 - * @throws Exception 异常 + * String des encryption + * @param data String that needs to be encrypted + * @param encryptType encryption mode (ECB/CBC/OFB/CFB) + * @return Encryption result + * @throws Exception exception * @author sucb - * @date 2017年3月2日下午7:47:37 + * @date March 2, 2017 7:47:37 pm */ public String encrypt(String data, String encryptType) throws Exception { Cipher cipher = getPattern(encryptType, ENCRYPT_MODE); @@ -153,13 +153,13 @@ public String encrypt(String data, String encryptType) throws Exception { } /** - * 字符串des解密 - * @param data 需要解密的字符串 - * @param decryptType 解密模式 (ECB/CBC/OFB/CFB) - * @return 解密结果 - * @throws Exception 异常 + * String decryption + * @param data The string that needs to be decrypted + * @param decryptType Decryption mode (ECB/CBC/OFB/CFB) + * @return Decryption result + * @throws Exception exception * @author sucb - * @date 2017年3月2日下午7:48:21 + * @date March 2, 2017 7:48:21 pm */ public String decrypt(String data, String decryptType) throws Exception { if (StringUtils.isBlank(data)) { @@ -171,13 +171,13 @@ public String decrypt(String data, String decryptType) throws Exception { } /** - * 初始化cipher - * @param type 加密/解密模式 (ECB/CBC/OFB/CFB) - * @param cipherMode cipher工作模式 1:加密; 2:解密 + * Initialize cipher + * @param type Encryption/decryption mode (ECB/CBC/OFB/CFB) + * @param cipherMode cipher working mode 1: encryption; 2: decryption * @return cipher - * @throws Exception 异常 + * @throws Exception exception * @author sucb - * @date 2017年3月2日下午7:49:16 + * @date March 2, 2017 7:49:16 pm */ private Cipher getPattern(String type, int cipherMode) throws Exception { Cipher cipher; @@ -203,13 +203,13 @@ private Cipher getPattern(String type, int cipherMode) throws Exception { } /** - * 文件 file 进行加密并保存目标文件 destFile 中 - * @param file 要加密的文件 如 c:/test/file.txt - * @param destFile 加密后存放的文件名 如 c:/ 加密后文件 .txt - * @param encryptType 加密模式 (ECB/CBC/OFB/CFB) - * @return 加密结果 0:异常 1:加密成功; 5:未找到需要加密的文件 + * The file file is encrypted and saved in the target file destFile. + * @param file The file to be encrypted such as c:/test/file.txt + * @param destFile The name of the file stored after encryption, such as c:/ encrypted file .txt + * @param encryptType encryption mode (ECB/CBC/OFB/CFB) + * @return Encryption result 0: Abnormal 1: Encryption successful; 5: File to be encrypted not found * @author sucb - * @date 2017年3月2日下午7:56:08 + * @date March 2, 2017 7:56:08 pm */ public int encryptFile(String file, String destFile, String encryptType) { int result = 0; @@ -236,13 +236,13 @@ public int encryptFile(String file, String destFile, String encryptType) { } /** - * 文件 file 进行解密并保存目标文件 destFile 中 - * @param file 要解密的文件 如 c:/test/file.txt - * @param destFile 解密后存放的文件名 如 c:/ 解密后文件 .txt - * @param decryptType 解密模式 (ECB/CBC/OFB/CFB) - * @return 解密结果 0:解密异常;1:解密正常;5:未找到需要解密的文件 + * The file file is decrypted and saved in the target file destFile. + * @param file The file to be decrypted such as c:/test/file.txt + * @param destFile The name of the file stored after decryption, such as c:/ decrypted file .txt + * @param decryptType Decryption mode (ECB/CBC/OFB/CFB) + * @return Decryption result 0: decryption abnormal; 1: decryption normal; 5: file to be decrypted not found * @author sucb - * @date 2017年3月2日下午7:58:56 + * @date March 2, 2017 7:58:56 pm */ public int decryptFile(String file, String destFile, String decryptType) { int result = 0; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/PermissionUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/PermissionUtils.java index 05bb2f33d..cdef5918f 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/PermissionUtils.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-core/src/main/java/ai/chat2db/server/domain/core/util/PermissionUtils.java @@ -38,7 +38,7 @@ public static void checkOperationPermission(Long createUserId) { } /** - * 校验是否有查询权限 + * Verify whether you have query permission * * @param createUserId * @return diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java index ce829f212..d5d5f31f4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/Dbutils.java @@ -69,34 +69,34 @@ public static void removeSession() { private static void before() throws IOException { SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); - //这是mybatis-plus的配置对象,对mybatis的Configuration进行增强 + //This is the configuration object of mybatis-plus, which enhances the configuration of mybatis. MybatisConfiguration configuration = new MybatisConfiguration(); - //这是初始化配置,后面会添加这部分代码 + //This is the initial configuration, this part of the code will be added later initConfiguration(configuration); - //这是初始化连接器,如mybatis-plus的分页插件 + //This is the initialization connector, such as the paging plug-in of mybatis-plus configuration.addInterceptor(initInterceptor()); - //配置日志实现 + //Configuration log implementation configuration.setLogImpl(Slf4jImpl.class); - //扫描mapper接口所在包 + //Scan the package where the mapper interface is located configuration.addMappers("ai.chat2db.server.domain.repository.mapper"); - //构建mybatis-plus需要的globalconfig + //Globalconfig required to build mybatis-plus GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration); - //此参数会自动生成实现baseMapper的基础方法映射 + //This parameter will automatically generate the basic method mapping that implements baseMapper. globalConfig.setSqlInjector(new DefaultSqlInjector()); - //设置id生成器 + //Set up id generator globalConfig.setIdentifierGenerator(new DefaultIdentifierGenerator()); - //设置超类mapper + //Set super class mapper globalConfig.setSuperMapperClass(BaseMapper.class); DataSource dataSource = initDataSource(); Environment environment = new Environment("1", new JdbcTransactionFactory(), dataSource); configuration.setEnvironment(environment); - //设置数据源 + //Set data source registryMapperXml(configuration, "mapper"); - //构建sqlSessionFactory + //Build sqlSessionFactory sqlSessionFactory = builder.build(configuration); initFlyway(dataSource); - //创建session + //create session } @@ -121,19 +121,19 @@ private static void initFlyway(DataSource dataSource) { } /** - * 初始化配置 + * Initial configuration * * @param configuration */ private static void initConfiguration(MybatisConfiguration configuration) { - //开启驼峰大小写转换 + //Turn on camel case conversion configuration.setMapUnderscoreToCamelCase(true); - //配置添加数据自动返回数据主键 + //Configure adding data to automatically return the data primary key configuration.setUseGeneratedKeys(true); } /** - * 初始化数据源 + * Initialize data source * * @return */ @@ -159,14 +159,14 @@ private static DataSource initDataSource() { } /** - * 初始化拦截器 + * Initialize interceptor * * @return */ private static Interceptor initInterceptor() { - //创建mybatis-plus插件对象 + //Create mybatis-plus plug-in object MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - //构建分页插件 + //Build a pagination plugin PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); paginationInnerInterceptor.setDbType(DbType.H2); paginationInnerInterceptor.setOverflow(true); @@ -176,7 +176,7 @@ private static Interceptor initInterceptor() { } /** - * 解析mapper.xml文件 + * Parse mapper.xml file * * @param configuration * @param classPath diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/MapperUtils.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/MapperUtils.java new file mode 100644 index 000000000..5f19d25f6 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/MapperUtils.java @@ -0,0 +1,10 @@ +package ai.chat2db.server.domain.repository; + +import ai.chat2db.server.domain.repository.mapper.TaskMapper; + +public class MapperUtils { + + public static TaskMapper getTaskMapper() { + return Dbutils.getMapper(TaskMapper.class); + } +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/ChartDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/ChartDO.java index e1b28625a..10cf78ef7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/ChartDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/ChartDO.java @@ -10,7 +10,7 @@ /** *

- * 自定义报表表 + * Custom dashboard *

* * @author chat2db @@ -24,48 +24,48 @@ public class ChartDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 图表名称 + * Chart name */ private String name; /** - * 图表描述 + * Chart description */ private String description; /** - * 图表信息 + * chart information */ private String schema; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据库类型 + * Database type */ private String type; /** - * db名称 + * DB name */ private String databaseName; @@ -73,17 +73,17 @@ public class ChartDO implements Serializable { private String schemaName; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否被删除,y表示删除,n表示未删除 + * Whether it has been deleted, y means deleted, n means not deleted */ private String deleted; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardChartRelationDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardChartRelationDO.java index 802a2e940..edd0b2b4e 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardChartRelationDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardChartRelationDO.java @@ -10,7 +10,7 @@ /** *

- * 自定义报表表 + * Custom dashboard *

* * @author ali-dbhub @@ -24,28 +24,28 @@ public class DashboardChartRelationDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 报表id + * report id */ private Long dashboardId; /** - * 图表id + * chart id */ private Long chartId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardDO.java index 5d4cd4df0..62c72d128 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DashboardDO.java @@ -10,7 +10,7 @@ /** *

- * 自定义报表表 + * Custom dashboard *

* * @author chat2db @@ -24,43 +24,43 @@ public class DashboardDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 报表名称 + * Dashboard name */ private String name; /** - * 报表描述 + * Dashboard description */ private String description; /** - * 报表布局信息 + * Dashboard layout information */ private String schema; /** - * 是否被删除,y表示删除,n表示未删除 + * Whether it has been deleted, y means deleted, n means not deleted */ private String deleted; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceAccessDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceAccessDO.java index 121b12abf..aad21a1ab 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceAccessDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceAccessDO.java @@ -10,7 +10,7 @@ /** *

- * 数据源授权 + * Data source authorization *

* * @author chat2db @@ -24,43 +24,43 @@ public class DataSourceAccessDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 创建人用户id + * Creator user id */ private Long createUserId; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * 授权类型 + * Authorization type */ private String accessObjectType; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ private Long accessObjectId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceDO.java index 88c4e10f5..4f3961e22 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DataSourceDO.java @@ -10,7 +10,7 @@ /** *

- * 数据源连接表 + * Data source connection table *

* * @author chat2db @@ -24,73 +24,73 @@ public class DataSourceDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 别名 + * Alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 用户名 + * userName */ private String userName; /** - * 密码 + * password */ private String password; /** - * 数据库类型 + * Database type */ private String type; /** - * 环境类型 + * environment type */ private String envType; /** - * 用户id + * user id */ private Long userId; /** - * host地址 + * host address */ private String host; /** - * 端口 + * port */ private String port; /** - * ssh配置信息json + * ssh configuration information json */ private String ssh; /** - * ssl配置信息json + * ssl configuration information json */ private String ssl; @@ -100,42 +100,42 @@ public class DataSourceDO implements Serializable { private String sid; /** - * 驱动信息 + * driver information */ private String driver; /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 自定义扩展字段json + * Custom extension field json */ private String extendInfo; /** - * driver_config配置 + * driver_config configuration */ private String driverConfig; /** - * 环境id + * environment id */ private Long environmentId; /** - * 连接类型 + * Connection Type */ private String kind; /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DbhubUserDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DbhubUserDO.java index 3e0504dc2..ca27af3fd 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DbhubUserDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/DbhubUserDO.java @@ -10,7 +10,7 @@ /** *

- * 数据源连接表 + * Data source connection table *

* * @author chat2db @@ -24,58 +24,58 @@ public class DbhubUserDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 用户名 + * userName */ private String userName; /** - * 密码 + * password */ private String password; /** - * 昵称 + * Nick name */ private String nickName; /** - * 邮箱 + * email */ private String email; /** - * 角色编码 + * role coding */ private String roleCode; /** - * 用户状态 + * user status */ private String status; /** - * 创建人用户id + * Creator user id */ private Long createUserId; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/EnvironmentDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/EnvironmentDO.java index a921bc834..ce930a9e0 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/EnvironmentDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/EnvironmentDO.java @@ -10,7 +10,7 @@ /** *

- * 数据库连接环境 + * Database connection environment *

* * @author chat2db @@ -24,43 +24,43 @@ public class EnvironmentDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 创建人用户id + * Creator user id */ private Long createUserId; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 环境名称 + * environment name */ private String name; /** - * 环境缩写 + * environment abbreviation */ private String shortName; /** - * 颜色 + * color */ private String color; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/JdbcDriverDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/JdbcDriverDO.java index 83543da07..ca2706836 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/JdbcDriverDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/JdbcDriverDO.java @@ -17,18 +17,18 @@ public class JdbcDriverDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationLogDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationLogDO.java index 719593b91..ca2882a5f 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationLogDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationLogDO.java @@ -11,7 +11,7 @@ /** *

- * 我的执行记录表 + * My execution record table *

* * @author chat2db @@ -25,68 +25,68 @@ public class OperationLogDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * DB name */ private String databaseName; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 用户id + * user id */ private Long userId; /** - * 状态 + * status */ private String status; /** - * 操作行数 + * Number of operation lines */ private Long operationRows; /** - * 使用时长 + * Length of use */ private Long useTime; /** - * 扩展信息 + * Extended Information */ private String extendInfo; /** - * schema名称 + * schema name */ private String schemaName; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationSavedDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationSavedDO.java index 902a13f76..80a392d8f 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationSavedDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/OperationSavedDO.java @@ -10,7 +10,7 @@ /** *

- * 我的保存表 + * My save list *

* * @author ali-dbhub @@ -24,63 +24,63 @@ public class OperationSavedDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * DB name */ private String databaseName; /** - * 保存名称 + * save name */ private String name; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl语句状态:DRAFT/RELEASE + * ddl statement status: DRAFT/RELEASE */ private String status; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; /** - * 用户id + * user id */ private Long userId; /** - * schema名称 + * schema name */ private String dbSchemaName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/PinTableDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/PinTableDO.java index 9d764d2fa..f78ea1603 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/PinTableDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/PinTableDO.java @@ -17,34 +17,33 @@ public class PinTableDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * DB name */ private String databaseName; - /** - * 保存名称 + * save name */ private String schemaName; diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/SystemConfigDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/SystemConfigDO.java index f861419a9..acc4ec24e 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/SystemConfigDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/SystemConfigDO.java @@ -22,34 +22,34 @@ public class SystemConfigDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 配置项code + * Configuration item code */ private String code; /** - * 配置项内容 + * Configuration item content */ private String content; /** - * 配置摘要 + * Configuration summary */ private String summary; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheDO.java index 5eace2195..a9692e797 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheDO.java @@ -25,59 +25,59 @@ public class TableCacheDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * DB name */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; /** - * table名称 + * table name */ private String tableName; /** - * 唯一索引 + * unique index */ @TableField(value = "`key`") private String key; /** - * 版本 + * version */ private Long version; /** - * 表字段 + * table fields */ private String columns; /** - * 自定义扩展字段json + * Custom extension field json */ private String extendInfo; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheVersionDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheVersionDO.java index 9c3d4e0f7..623241817 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheVersionDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableCacheVersionDO.java @@ -25,54 +25,54 @@ public class TableCacheVersionDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * DB name */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; /** - * 唯一索引 + * unique index */ @TableField(value = "`key`") private String key; /** - * 版本 + * version */ private Long version; /** - * 表数量 + * Number of tables */ private Long tableCount; /** - * 状态 + * status */ private String status; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableVectorMappingDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableVectorMappingDO.java index fb020c14f..e17ffa45e 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableVectorMappingDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TableVectorMappingDO.java @@ -9,7 +9,7 @@ /** *

- * milvus映射表保存记录 + * Milvus mapping table saves records *

* * @author chat2db @@ -23,7 +23,7 @@ public class TableVectorMappingDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; @@ -34,22 +34,22 @@ public class TableVectorMappingDO implements Serializable { private String apiKey; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据库名称 + * Name database */ private String database; /** - * schema名称 + * schema name */ private String schema; /** - * 向量保存状态 + * Vector saved state */ private String status; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TaskDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TaskDO.java new file mode 100644 index 000000000..73e303bc5 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TaskDO.java @@ -0,0 +1,101 @@ +package ai.chat2db.server.domain.repository.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.util.Date; +import lombok.Getter; +import lombok.Setter; + +/** + *

+ * TASK TABLE + *

+ * + * @author chat2db + * @since 2024-01-25 + */ +@Getter +@Setter +@TableName("TASK") +public class TaskDO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * primary key + */ + @TableId(value = "ID", type = IdType.AUTO) + private Long id; + + /** + * creation time + */ + private Date gmtCreate; + + /** + * modified time + */ + private Date gmtModified; + + /** + * Data source connection ID + */ + private Long dataSourceId; + + /** + * DB name + */ + private String databaseName; + + /** + * schema name + */ + private String schemaName; + + /** + * table_name + */ + private String tableName; + + /** + * Whether it has been deleted, y means deleted, n means not deleted + */ + private String deleted; + + /** + * user id + */ + private Long userId; + + /** + * task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE, + */ + private String taskType; + + /** + * task status + */ + private String taskStatus; + + /** + * task progress + */ + private String taskProgress; + + /** + * task name + */ + private String taskName; + + /** + * download url + */ + private String downloadUrl; + + /** + * task content + */ + private byte[] content; +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamDO.java index 15e04221d..f4cb616ce 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamDO.java @@ -10,7 +10,7 @@ /** *

- * 团队 + * Team *

* * @author chat2db @@ -24,48 +24,48 @@ public class TeamDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 创建人用户id + * Creator user id */ private Long createUserId; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 团队编码 + * Team Coding */ private String code; /** - * 团队名称 + * Team Name */ private String name; /** - * 团队状态 + * Team Status */ private String status; /** - * 团队描述 + * Team Description */ private String description; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamUserDO.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamUserDO.java index f9f3fbbf8..09e60c6f6 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamUserDO.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/entity/TeamUserDO.java @@ -11,7 +11,7 @@ /** *

- * 用户团队表 + * User team table *

* * @author chat2db @@ -25,38 +25,38 @@ public class TeamUserDO implements Serializable { private static final long serialVersionUID = 1L; /** - * 主键 + * primary key */ @TableId(value = "ID", type = IdType.AUTO) private Long id; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** - * 创建人用户id + * Creator user id */ private Long createUserId; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 团队id + * team id */ private Long teamId; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/ChartMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/ChartMapper.java index b390aabd1..850d959e4 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/ChartMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/ChartMapper.java @@ -5,7 +5,7 @@ /** *

- * 自定义报表表 Mapper 接口 + * Custom dashboard Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardChartRelationMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardChartRelationMapper.java index eacc818ac..4fa3f60d7 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardChartRelationMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardChartRelationMapper.java @@ -5,7 +5,7 @@ /** *

- * 自定义报表表 Mapper 接口 + * Custom dashboard Mapper interface *

* * @author ali-dbhub diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardMapper.java index e53cf1abe..86f4c588e 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DashboardMapper.java @@ -5,7 +5,7 @@ /** *

- * 自定义报表表 Mapper 接口 + * Custom dashboard Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceAccessMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceAccessMapper.java index 27a80eeb9..d28d16fca 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceAccessMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceAccessMapper.java @@ -5,7 +5,7 @@ /** *

- * 数据源授权 Mapper 接口 + * Data source authorization Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceMapper.java index 2f4f8be93..cfe13ad7e 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DataSourceMapper.java @@ -5,7 +5,7 @@ /** *

- * 数据源连接表 Mapper 接口 + * Data source connection table Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DbhubUserMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DbhubUserMapper.java index 4ff5dce70..60b35f6f5 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DbhubUserMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/DbhubUserMapper.java @@ -5,7 +5,7 @@ /** *

- * 数据源连接表 Mapper 接口 + * Data source connection table Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/EnvironmentMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/EnvironmentMapper.java index 75469d31b..9677af3cb 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/EnvironmentMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/EnvironmentMapper.java @@ -5,7 +5,7 @@ /** *

- * 数据库连接环境 Mapper 接口 + * Database connection environment Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationLogMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationLogMapper.java index 94e2e6253..47abd66d2 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationLogMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationLogMapper.java @@ -5,7 +5,7 @@ /** *

- * 我的执行记录表 Mapper 接口 + * My execution record table Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationSavedMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationSavedMapper.java index 3ee6b0fc7..0677477d6 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationSavedMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/OperationSavedMapper.java @@ -5,7 +5,7 @@ /** *

- * 我的保存表 Mapper 接口 + * My save table Mapper interface *

* * @author ali-dbhub diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheMapper.java index 7c26d0cd1..2efd171f2 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheMapper.java @@ -10,7 +10,7 @@ /** *

- * table cache Mapper 接口 + * table cache Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheVersionMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheVersionMapper.java index 5ac07037f..dd634aadd 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheVersionMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableCacheVersionMapper.java @@ -5,7 +5,7 @@ /** *

- * table cache version Mapper 接口 + * table cache version Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableVectorMappingMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableVectorMappingMapper.java index 40749c54e..e95247521 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableVectorMappingMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TableVectorMappingMapper.java @@ -5,7 +5,7 @@ /** *

- * milvus映射表保存记录 Mapper 接口 + * Milvus mapping table saves records Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TaskMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TaskMapper.java new file mode 100644 index 000000000..77658db07 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TaskMapper.java @@ -0,0 +1,19 @@ +package ai.chat2db.server.domain.repository.mapper; + +import ai.chat2db.server.domain.repository.entity.TaskDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.apache.ibatis.annotations.Param; + +/** + *

+ * TASK TABLE Mapper interface + *

+ * + * @author chat2db + * @since 2024-01-25 + */ +public interface TaskMapper extends BaseMapper { + + IPage pageQuery(IPage page, @Param("userId") Long userId,@Param("deleted") String deleted); +} diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamMapper.java index 07cfc32d1..4c45044d0 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamMapper.java @@ -5,7 +5,7 @@ /** *

- * 团队 Mapper 接口 + * Team Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamUserMapper.java b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamUserMapper.java index 43998295d..c68225331 100644 --- a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamUserMapper.java +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/java/ai/chat2db/server/domain/repository/mapper/TeamUserMapper.java @@ -5,7 +5,7 @@ /** *

- * 用户团队表 Mapper 接口 + * User team table Mapper interface *

* * @author chat2db diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/db/migration/V2_1_9__task.sql b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/db/migration/V2_1_9__task.sql new file mode 100644 index 000000000..326972a20 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/db/migration/V2_1_9__task.sql @@ -0,0 +1,20 @@ +CREATE TABLE IF NOT EXISTS `task` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', + `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', + `data_source_id` bigint(20) unsigned NULL COMMENT '数据源连接ID', + `database_name` varchar(128) DEFAULT NULL COMMENT 'db名称', + `schema_name` varchar(128) DEFAULT NULL COMMENT 'schema名称', + `table_name` varchar(128) DEFAULT NULL COMMENT 'table_name', + `deleted` varchar(10) DEFAULT NULL COMMENT '是否被删除,y表示删除,n表示未删除', + `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户id', + `task_type` varchar(128) DEFAULT NULL COMMENT 'task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE,', + `task_status` varchar(128) DEFAULT NULL COMMENT 'task status', + `task_progress` varchar(128) DEFAULT NULL COMMENT 'task progress', + `task_name` varchar(128) DEFAULT NULL COMMENT 'task name', + `content` blob DEFAULT NULL COMMENT 'task content', + `download_url` varchar(512) DEFAULT NULL COMMENT 'down load url', + PRIMARY KEY (`id`) + ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='TASK TABLE' +; +create INDEX idx_task_user_id on task(user_id) ; \ No newline at end of file diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/mapper/TaskMapper.xml b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/mapper/TaskMapper.xml new file mode 100644 index 000000000..498d1b6d3 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/mapper/TaskMapper.xml @@ -0,0 +1,36 @@ + + + + + + diff --git a/chat2db-server/chat2db-server-start/pom.xml b/chat2db-server/chat2db-server-start/pom.xml index 1c1cbef8e..a2f475ee8 100644 --- a/chat2db-server/chat2db-server-start/pom.xml +++ b/chat2db-server/chat2db-server-start/pom.xml @@ -28,13 +28,13 @@ ai.chat2db chat2db-server-web-api - + ai.chat2db chat2db-server-domain-core - + org.slf4j jcl-over-slf4j @@ -48,13 +48,13 @@ logback-classic - + com.h2database h2 - + org.flywaydb flyway-core @@ -65,7 +65,7 @@ - + org.springframework.boot spring-boot-starter-thymeleaf @@ -114,7 +114,7 @@ - + @@ -127,7 +127,7 @@ - + @@ -139,7 +139,7 @@ - + diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/Application.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/Application.java index 573a6105f..0952b634f 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/Application.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/Application.java @@ -11,10 +11,9 @@ import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.stereotype.Indexed; -import java.util.concurrent.CompletableFuture; /** - * 启动类 + * Startup class * * @author Jiaju Zhuang */ diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/StdinReader.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/StdinReader.java deleted file mode 100644 index 3505849c5..000000000 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/StdinReader.java +++ /dev/null @@ -1,30 +0,0 @@ -//package ai.chat2db.server.start.config; -// -//import jakarta.annotation.PostConstruct; -//import org.springframework.boot.context.event.ApplicationReadyEvent; -//import org.springframework.context.ApplicationListener; -//import org.springframework.stereotype.Component; -// -//import java.util.Scanner; -// -//@Component -//public class StdinReader implements ApplicationListener { -// -// -// @Override -// public void onApplicationEvent(ApplicationReadyEvent event) { -// // 启动读取 stdin 的线程 -// new Thread(() -> readStdin()).start(); -// } -// -// private void readStdin() { -// Scanner scanner = new Scanner(System.in); -// while (scanner.hasNextLine()) { -// String line = scanner.nextLine(); -// // 处理接收到的数据 -// System.out.println("接收到数据: " + line); -// // 在这里调用其他服务或逻辑 -// } -// } -// -//} diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/config/Chat2dbWebMvcConfigurer.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/config/Chat2dbWebMvcConfigurer.java index 2c178c95d..c43d2aa7c 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/config/Chat2dbWebMvcConfigurer.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/config/Chat2dbWebMvcConfigurer.java @@ -37,21 +37,21 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** - * web项目配置 + * web project configuration * - * @author 是仪 + * @author Shi Yi */ @Configuration @Slf4j public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer { /** - * api前缀 + * api prefix */ private static final String API_PREFIX = "/api/"; /** - * 全局放行的url + * Globally released url */ private static final String[] FRONT_PERMIT_ALL = new String[] {"/favicon.ico", "/error", "/static/**", "/api/system", "/login"}; @@ -62,7 +62,7 @@ public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - // 所有请求尝试加入用户信息 + // All requests try to add user information registry.addInterceptor(new AsyncHandlerInterceptor() { @Override public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @@ -86,7 +86,7 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl }); if (loginUser == null) { - // 代表用户可能被删除了 + // Indicates that the user may have been deleted return true; } loginUser.setToken(userId.toString()); @@ -100,7 +100,7 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - // 移除登录信息 + // Remove login information ContextUtils.removeContext(); Dbutils.removeSession(); } @@ -109,7 +109,7 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp .addPathPatterns("/**") .excludePathPatterns(FRONT_PERMIT_ALL); - // 校验登录信息 + // Verify login information } diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/interceptor/CorsFilter.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/interceptor/CorsFilter.java index 1b339739a..a0255828e 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/interceptor/CorsFilter.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/interceptor/CorsFilter.java @@ -13,12 +13,12 @@ import org.springframework.stereotype.Component; /** - * Cors跨域的拦截器,任何情况都允许跨域 + * Cors cross-domain interceptor, allowing cross-domain under any circumstances * - * 通过CorsRegistry策略的跨域 在登录的情况下会有有问题,但是本地没有复现,可能原因是:bean 的加载顺序的问题。 - * 临时通过CorsFilter解决,后续可以研究下:CorsRegistry + * There will be problems when logging in across domains through the CorsRegistry policy, but it does not occur locally. The possible reason is: the loading order of the beans. + * Temporarily solved through CorsFilter, you can study it later: CorsRegistry * - * @author 是仪 + * @author Shi Yi */ @Component public class CorsFilter implements Filter { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/DbhubTomcatConnectorCustomizer.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/DbhubTomcatConnectorCustomizer.java index 9a12cb7e4..d2177870d 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/DbhubTomcatConnectorCustomizer.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/DbhubTomcatConnectorCustomizer.java @@ -8,7 +8,7 @@ //import org.springframework.stereotype.Component; // ///** -// * 自定义tomcat参数 +// * Custom tomcat parameters // * // * @author Jiaju Zhuang // */ @@ -18,7 +18,7 @@ // @Override // public void customize(Connector connector) { // connector.addLifecycleListener(event -> { -// // 接受到关闭事件 直接退出系统,因为有时候不会退出系统 +// // Exit the system directly after receiving the shutdown event, because sometimes the system will not exit. // if (LifecycleState.STOPPING == event.getLifecycle().getState()) { // SystemUtils.stop(); // } diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/FailedEventApplicationListener.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/FailedEventApplicationListener.java index 4185ae7fe..0220396c9 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/FailedEventApplicationListener.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/FailedEventApplicationListener.java @@ -6,8 +6,8 @@ import org.springframework.context.ApplicationListener; /** - * 应用启动失败的监听器 - * 应用启动失败了只是停止了tomcat 并没有停止应用 这里停止xia + * Listener that failed to start application + * The application failed to start. It just stopped tomcat and did not stop the application. Stop xia here. * * @author Jiaju Zhuang */ @@ -16,7 +16,7 @@ public class FailedEventApplicationListener implements ApplicationListener dataResult; // try { // String body = HttpUtil.get("http://127.0.0.1:" + serverPort + "/api/system/get-version-a", 10); // dataResult = JSON.parseObject(body, new TypeReference<>() {}); // } catch (Exception e) { -// // 抛出异常 代表没有旧的启动 或者旧的不靠谱 -// log.info("尝试访问旧的应用失败。本异常不重要,正常启动启动都会输出,请忽略。" + e.getMessage()); +// // Throwing an exception means that there is no old startup or the old one is unreliable. +// log.info("Attempts to access old applications failed. This exception is not important. It will be output during normal startup, so please ignore it." + e.getMessage()); // -// // 尝试杀死旧的进程 +// // Try killing the old process // killOldIfNecessary(environment); // return; // } // // if (dataResult == null || BooleanUtils.isNotTrue(dataResult.getSuccess())) { -// // 尝试杀死旧的进程 +// // Try killing the old process // killOldIfNecessary(environment); // return; // } // -// // 代表旧的进程是可以用的 -// log.info("当前接口已经存在启动的应用了,本应用不在启动"); +// // Indicates that the old process is available +// log.info("There is already a started application on the current interface, and this application is no longer started."); // System.exit(0); // } // @@ -59,7 +59,7 @@ // try { // ProcessHandle.allProcesses().forEach(process -> { // String command = process.info().command().orElse(null); -// // 不是java应用 +// // Not a java application // boolean isJava = StringUtils.endsWithIgnoreCase(command, "java") || StringUtils.endsWithIgnoreCase( // command, // "java.exe"); @@ -67,11 +67,11 @@ // return; // } // String[] arguments = process.info().arguments().orElse(null); -// // 没有参数 +// // no parameters // if (arguments == null) { // return; // } -// // 是否是dbhub +// // Is it dbhub? // boolean isDbhub = false; // String environmentArgument = null; // for (String argument : arguments) { @@ -82,47 +82,47 @@ // environmentArgument = StringUtils.substringAfter(argument, "-Dspring.profiles.active="); // } // } -// // 不是dbhub +// // Not dbhub // if (!isDbhub) { // return; // } -// // 判断是否是正式环境 +// // Determine whether it is a formal environment // if (StringUtils.equals(SystemEnvironmentEnum.RELEASE.getCode(), environment) && StringUtils.equals( // SystemEnvironmentEnum.RELEASE.getCode(), environmentArgument)) { -// log.info("正式环境需要关闭进程"); +// log.info("The formal environment requires closing the process"); // destroyProcess(process, command, arguments); // return; // } // -// // 判断是否是测试环境 +// // Determine whether it is a test environment // if (StringUtils.equals(SystemEnvironmentEnum.TEST.getCode(), environment) && StringUtils.equals( // SystemEnvironmentEnum.TEST.getCode(), environmentArgument)) { -// log.info("测试环境需要关闭进程"); +// log.info("The test environment needs to shut down the process"); // destroyProcess(process, command, arguments); // return; // } // -// // 判断是否是本地环境 +// // Determine whether it is a local environment // boolean devDestroy = StringUtils.equals(SystemEnvironmentEnum.DEV.getCode(), environment) && ( // environmentArgument == null // || StringUtils.equals(SystemEnvironmentEnum.DEV.getCode(), environmentArgument)); // if (devDestroy) { -// log.info("本地环境需要关闭进程"); +// log.info("The local environment needs to close the process"); // destroyProcess(process, command, arguments); // } // }); // } catch (Throwable t) { -// log.warn("尝试关闭多余的进程失败,不影响正常启动", t); +// log.warn("Attempts to close redundant processes failed and did not affect normal startup.", t); // } // // } // // private void destroyProcess(ProcessHandle process, String command, String[] arguments) { -// log.info("检查到存在需要关闭的进程:{},{}", JSON.toJSONString(command), JSON.toJSONString(arguments)); +// log.info("Checked that there are processes that need to be shut down:{},{}", JSON.toJSONString(command), JSON.toJSONString(arguments)); // try { // process.destroy(); // } catch (Exception e) { -// log.error("结束进程失败", e); +// log.error("Failed to end process", e); // } // } //} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/ManageMessage.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/ManageMessage.java index 1645efddb..cc5b01db7 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/ManageMessage.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/ManageMessage.java @@ -10,7 +10,7 @@ import java.io.Serializable; /** - * 管理的消息 + * Administrative messages * * @author Jiaju Zhuang */ @@ -23,7 +23,7 @@ public class ManageMessage implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 消息类型 + * Message type * * @see MessageTypeEnum */ diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/MessageTypeEnum.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/MessageTypeEnum.java index 32ae3c587..e130d779f 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/MessageTypeEnum.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/listener/manage/MessageTypeEnum.java @@ -4,14 +4,14 @@ import lombok.Getter; /** - * 消息类型枚举 + * Message type enum * * @author Jiaju Zhuang */ @Getter public enum MessageTypeEnum implements BaseEnum { /** - * 检查是否正常运行 + * Check if it works properly */ HEARTBEAT, diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/mybatis/MyBatisPlusConfig.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/mybatis/MyBatisPlusConfig.java index 14f03d2db..ad688f01e 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/mybatis/MyBatisPlusConfig.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/mybatis/MyBatisPlusConfig.java @@ -8,14 +8,14 @@ /** * @author moji - * @version MyBatisPlusConfig.java, v 0.1 2022年09月29日 17:38 moji Exp $ + * @version MyBatisPlusConfig.java, v 0.1 September 29, 2022 17:38 moji Exp $ * @date 2022/09/29 */ @Configuration public class MyBatisPlusConfig { /** - * myBatisPlus 分页插件 + * myBatisPlus paging plug-in */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/oauth/SaLogForSlf4j.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/oauth/SaLogForSlf4j.java deleted file mode 100644 index f45df2fe8..000000000 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/oauth/SaLogForSlf4j.java +++ /dev/null @@ -1,44 +0,0 @@ -//package ai.chat2db.server.start.config.oauth; -// -//import cn.dev33.satoken.log.SaLog; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.stereotype.Component; -// -///** -// * satoken 日志打印 -// * -// * @author 是仪 -// */ -//@Slf4j -//@Component -//public class SaLogForSlf4j implements SaLog { -// @Override -// public void trace(String str, Object... args) { -// log.trace(str, args); -// } -// -// @Override -// public void debug(String str, Object... args) { -// log.debug(str, args); -// } -// -// @Override -// public void info(String str, Object... args) { -// log.info(str, args); -// } -// -// @Override -// public void warn(String str, Object... args) { -// log.trace(str, args); -// } -// -// @Override -// public void error(String str, Object... args) { -// log.error(str, args); -// } -// -// @Override -// public void fatal(String str, Object... args) { -// log.error(str, args); -// } -//} diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/oauth/SaTokenConfigure.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/oauth/SaTokenConfigure.java deleted file mode 100644 index 66663a8ff..000000000 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/config/oauth/SaTokenConfigure.java +++ /dev/null @@ -1,21 +0,0 @@ -//package ai.chat2db.server.start.config.oauth; -// -//import cn.dev33.satoken.jwt.StpLogicJwtForStateless; -//import cn.dev33.satoken.stp.StpLogic; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -// -///** -// * satoken配置 -// * -// * @author 是仪 -// */ -//@Configuration -//public class SaTokenConfigure { -// @Bean -// public StpLogic ttpLogic() { -// // 登录展示用 无状态的 这样不用依赖于与redis之类的 -// // 后续可以改成ehcahe 存储磁盘? -// return new StpLogicJwtForStateless(); -// } -//} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/OauthController.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/OauthController.java index 8d5514db9..9ecfbeab0 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/OauthController.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/OauthController.java @@ -26,7 +26,7 @@ import java.util.Objects; /** - * 登录授权服务 + * Login authorization service * * @author Jiaju Zhuang */ @@ -39,14 +39,14 @@ public class OauthController { private UserService userService; /** - * 用户名密码登录 + * Login with username and password * * @param request * @return */ @PostMapping("login_a") public DataResult login(@Validated @RequestBody LoginRequest request) { - // 查询用户 + // Query user return DataResult.of(null); } diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/request/LoginRequest.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/request/LoginRequest.java index 5207c8fee..94e67684c 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/request/LoginRequest.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/oauth/request/LoginRequest.java @@ -8,7 +8,7 @@ import lombok.experimental.SuperBuilder; /** - * 登录 + * Log in * * @author Jiaju Zhuang */ @@ -18,13 +18,13 @@ @AllArgsConstructor public class LoginRequest { /** - * 用户名 + * userName */ @NotNull(message = "用户名不能为空") private String userName; /** - * 密码 + * password */ @NotNull(message = "密码不能为空") private String password; diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/thymeleaf/ThymeleafController.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/thymeleaf/ThymeleafController.java index fa01f4ac8..b771de340 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/thymeleaf/ThymeleafController.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/controller/thymeleaf/ThymeleafController.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestMethod; /** - * 模板引擎 配置 + * Template engine configuration * * @author Jiaju Zhuang */ @@ -18,7 +18,7 @@ public class ThymeleafController { /** - * 前端的模板设置 + * Front-end template settings * * @return */ diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/EasyControllerExceptionHandler.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/EasyControllerExceptionHandler.java index ab42935ee..c531c4552 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/EasyControllerExceptionHandler.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/EasyControllerExceptionHandler.java @@ -41,9 +41,9 @@ import org.springframework.web.servlet.ModelAndView; /** - * 拦截Controller异常 + * Intercepting Controller exceptions * - * @author 是仪 + * @author Shi Yi */ @ControllerAdvice @Slf4j @@ -51,7 +51,7 @@ public class EasyControllerExceptionHandler { /** - * 所有的异常处理转换器 + * All exception handling converters */ public static final Map, ExceptionConvertor> EXCEPTION_CONVERTOR_MAP = Maps.newHashMap(); @@ -70,12 +70,12 @@ public class EasyControllerExceptionHandler { } /** - * 默认转换器 + * Default converter */ public static ExceptionConvertor DEFAULT_EXCEPTION_CONVERTOR = new DefaultExceptionConvertor(); /** - * 业务异常 + * Business abnormality * * @param request request * @param exception exception @@ -91,12 +91,12 @@ public class EasyControllerExceptionHandler { @ResponseBody public ActionResult handleBusinessException(HttpServletRequest request, Exception exception) { ActionResult result = convert(exception); - log.info("发生业务异常{}:{}", request.getRequestURI(), result, exception); + log.info("Business exception occurred{}:{}", request.getRequestURI(), result, exception); return result; } /** - * 业务异常 + * Business abnormality * * @param request request * @param exception exception @@ -105,35 +105,35 @@ public ActionResult handleBusinessException(HttpServletRequest request, Exceptio @ExceptionHandler({RedirectBusinessException.class}) public ModelAndView handleModelAndViewBizException(HttpServletRequest request, Exception exception) { ModelAndView result = translateModelAndView(exception); - log.info("发生ModelAndView业务异常{}:{}", request.getRequestURI(), result, exception); + log.info("ModelAndView business exception occurred{}:{}", request.getRequestURI(), result, exception); return result; } public ModelAndView translateModelAndView(Throwable exception) { - // 参数异常 + // Parameter exception if (exception instanceof RedirectBusinessException) { RedirectBusinessException e = (RedirectBusinessException)exception; return dealResponseModelAndView(null, e.getMessage(), e.getRedirect(), null, null); } - // 默认跳首页 + // Jump to homepage by default return new ModelAndView("redirect:/"); } private ModelAndView dealResponseModelAndView(String title, String errorMessage, String redirect, String href, String buttonText) { - // 如果有车重定向信息 则跳转 + // If there is redirection information, jump if (StringUtils.isNotBlank(redirect)) { return new ModelAndView("redirect:" + redirect); } - // 默认跳首页 + // Jump to homepage by default return new ModelAndView("redirect:/"); - // 同步请求 + // synchronous request //return ModelAndViewUtils.error(title, errorMessage,href,buttonText); } /** - * 系统异常 + * System exception * * @param request request * @param exception exception @@ -144,12 +144,12 @@ private ModelAndView dealResponseModelAndView(String title, String errorMessage, @ResponseBody public ActionResult handleSystemException(HttpServletRequest request, Exception exception) { ActionResult result = convert(exception); - log.error("发生业务异常{}:{}", request.getRequestURI(), result, exception); + log.error("Business exception occurred{}:{}", request.getRequestURI(), result, exception); return result; } /** - * 未知异常 需要人工介入查看日志 + * Unknown exception requires manual intervention to view logs * * @param request request * @param exception exception @@ -160,7 +160,7 @@ public ActionResult handleSystemException(HttpServletRequest request, Exception @ResponseBody public ActionResult handledException(HttpServletRequest request, Exception exception) { ActionResult result = convert(exception); - log.error("发生未知异常{}:{},请求参数:{}", request.getRequestURI(), result, + log.error("An unknown exception occurred {}:{}, request parameters:{}", request.getRequestURI(), result, JSON.toJSONString(request.getParameterMap()), exception); return result; diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BindExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BindExceptionConvertor.java index 7472f8dfa..555a0a55f 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BindExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BindExceptionConvertor.java @@ -7,7 +7,7 @@ /** * BindException * - * @author 是仪 + * @author Shi Yi */ public class BindExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BusinessExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BusinessExceptionConvertor.java index 6ab373b79..b65f0aa17 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BusinessExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/BusinessExceptionConvertor.java @@ -8,7 +8,7 @@ /** * BusinessException * - * @author 是仪 + * @author Shi Yi */ public class BusinessExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/DefaultExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/DefaultExceptionConvertor.java index b1cafab06..3897e00a7 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/DefaultExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/DefaultExceptionConvertor.java @@ -5,10 +5,10 @@ import ai.chat2db.spi.util.ExceptionUtils; /** - * 默认的异常处理 - * 直接抛出系统异常 + * Default exception handling + * Throw system exception directly * - * @author 是仪 + * @author Shi Yi */ public class DefaultExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertor.java index ffc971e6c..323ccbc9f 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertor.java @@ -3,14 +3,14 @@ import ai.chat2db.server.tools.base.wrapper.result.ActionResult; /** - * 异常转换器 + * exception converter * - * @author 是仪 + * @author Shi Yi */ public interface ExceptionConvertor { /** - * 转换异常 + * Conversion exception * * @param exception * @return diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertorUtils.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertorUtils.java index a66c5a504..74d41b0ea 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertorUtils.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ExceptionConvertorUtils.java @@ -10,14 +10,14 @@ import org.springframework.validation.ObjectError; /** - * 转换工具类 + * Conversion tool class * - * @author 是仪 + * @author Shi Yi */ public class ExceptionConvertorUtils { /** - * 提取BindingResult中的错误消息 + * Extract error message from BindingResult * * @param result * @return @@ -33,7 +33,7 @@ public static String buildMessage(BindingResult result) { msg.append(I18nUtils.getMessage("common.paramCheckError")); for (ObjectError e : errors) { msg.append(index++); - // 得到错误消息 + // got error message msg.append(SymbolConstant.DOT); if (e instanceof FieldError fieldError) { msg.append(fieldError.getField()); diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java index b7b160a88..8c2fd9246 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java @@ -9,7 +9,7 @@ /** * MaxUploadSizeExceededException * - * @author 是仪 + * @author Shi Yi */ public class MaxUploadSizeExceededExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java index 8576ec751..5f01f080d 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java @@ -8,7 +8,7 @@ /** * MethodArgumentNotValidException * - * @author 是仪 + * @author Shi Yi */ public class MethodArgumentNotValidExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java index 31be931fb..398129c3e 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java @@ -9,7 +9,7 @@ /** * MethodArgumentTypeMismatchException * - * @author 是仪 + * @author Shi Yi */ public class MethodArgumentTypeMismatchExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ParamExceptionConvertor.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ParamExceptionConvertor.java index 28f0e8e85..650db6794 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ParamExceptionConvertor.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/exception/convertor/ParamExceptionConvertor.java @@ -4,12 +4,12 @@ import ai.chat2db.spi.util.ExceptionUtils; /** - * 参数异常 目前包括 + * Parameter exceptions currently include: * ConstraintViolationException * MissingServletRequestParameterException * IllegalArgumentException * - * @author 是仪 + * @author Shi Yi */ public class ParamExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/EasyLogSink.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/EasyLogSink.java index f3f9857bd..2b8b23c60 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/EasyLogSink.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/EasyLogSink.java @@ -34,17 +34,17 @@ public void write(final Correlation correlation, final HttpRequest request, fina try { printLog(correlation, request, response); } catch (Exception e) { - log.error("记录日志异常", e); + log.error("Log exceptions", e); } } public void printLog(final Correlation correlation, final HttpRequest request, final HttpResponse response) throws IOException { - // 封装log 对象 + // Encapsulate log object WebLog webLog = new WebLog(); String method = request.getMethod(); - // 路径 + // Path String path = request.getPath(); webLog.setMethod(method); @@ -62,7 +62,7 @@ public void printLog(final Correlation correlation, final HttpRequest request, f webLog.setResponse(response.getContentType() + ":[" + response.getBody().length + "]"); } } catch (IOException e) { - log.warn("获取日志的请求&返回异常,大概率是用户关闭了流。", e); + log.warn("The request to obtain the log & returns an exception. Most likely, the user has closed the stream.", e); } webLog.setIp(LogUtils.getClientIp(request)); diff --git a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/WebLog.java b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/WebLog.java index 79d9400d2..57514d8db 100644 --- a/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/WebLog.java +++ b/chat2db-server/chat2db-server-start/src/main/java/ai/chat2db/server/start/log/WebLog.java @@ -8,9 +8,9 @@ import lombok.experimental.SuperBuilder; /** - * log 对象 + * log object * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -18,47 +18,47 @@ @AllArgsConstructor public class WebLog { /** - * 调用方法 + * call method */ private String method; /** - * 路径 + * Path */ private String path; /** - * 查询条件 + * Query conditions */ private String query; /** - * 耗时 ms + * Time consuming (ms) */ private Long duration; /** - * 耗时 ms + * Time consuming (ms) */ private LocalDateTime startTime; /** - * 耗时 ms + * Time consuming (ms) */ private LocalDateTime endTime; /** - * 请求 + * request */ private String request; /** - * 返回 + * response */ private String response; /** - * ip地址 + * IP address */ private String ip; } diff --git a/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml b/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml index 20fc689e5..40842febc 100644 --- a/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml +++ b/chat2db-server/chat2db-server-start/src/main/resources/application-dev.yml @@ -1,4 +1,4 @@ -# 端口号 +# port server: port: 10821 diff --git a/chat2db-server/chat2db-server-start/src/main/resources/application-release.yml b/chat2db-server/chat2db-server-start/src/main/resources/application-release.yml index 7f14992cc..4927c6143 100644 --- a/chat2db-server/chat2db-server-start/src/main/resources/application-release.yml +++ b/chat2db-server/chat2db-server-start/src/main/resources/application-release.yml @@ -1,9 +1,9 @@ #spring: # datasource: -# # 配置自带数据库的相对路径 +# # Configure the relative path of the built-in database # url: jdbc:h2:~/.chat2db/db/chat2db;MODE=MYSQL;FILE_LOCK=NO # driver-class-name: org.h2.Driver -# 端口号 +# port server: port: 10824 diff --git a/chat2db-server/chat2db-server-start/src/main/resources/application-test.yml b/chat2db-server/chat2db-server-start/src/main/resources/application-test.yml index 344076cd4..ee8972636 100644 --- a/chat2db-server/chat2db-server-start/src/main/resources/application-test.yml +++ b/chat2db-server/chat2db-server-start/src/main/resources/application-test.yml @@ -1,4 +1,4 @@ -# 端口号 +# port server: port: 10822 diff --git a/chat2db-server/chat2db-server-start/src/main/resources/application.yml b/chat2db-server/chat2db-server-start/src/main/resources/application.yml index dac984258..037591931 100644 --- a/chat2db-server/chat2db-server-start/src/main/resources/application.yml +++ b/chat2db-server/chat2db-server-start/src/main/resources/application.yml @@ -1,5 +1,5 @@ spring: - # 默认开发环境 + # Default development environment profiles: active: dev main: @@ -19,13 +19,13 @@ spring: servlet: content-type: text/html mode: HTML5 - # 静态文件 + # static files mvc: static-path-pattern: /static/** web: resources: static-locations[0]: classpath:/static/ - # 用于数据库表结构版本管理 + # Used for database table structure version management servlet: multipart: max-file-size: -1 @@ -37,7 +37,7 @@ spring: chat2db: version: 1.0.0 -# flywaydb 输出执行sql的日志 +# flywaydb outputs the log of executing sql logging: ai: chat2db: @@ -49,7 +49,7 @@ logging: chatgpt: apiKey: sk-xxxx apiHost: https://api.openai.com/ - # 可以选择GPT3或GPT35 + # You can choose GPT3 or GPT35 version: GPT35 context: length: 1 diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/TestApplication.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/TestApplication.java index 8a74a8b12..9ed8495f0 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/TestApplication.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/TestApplication.java @@ -8,10 +8,10 @@ import org.springframework.stereotype.Indexed; /** - * 本地环境的启动。 - * 主要为了读取本地的一些配置 比如日志输出就和其他环境不一样 + * Startup of the local environment. + * Mainly to read some local configurations. For example, log output is different from other environments. * - * @author 是仪 + * @author Shi Yi */ @SpringBootTest(classes = {Application.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Slf4j diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/common/BaseTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/common/BaseTest.java index 9317d8823..fa1fcad4a 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/common/BaseTest.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/common/BaseTest.java @@ -6,7 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest; /** - * 基础测试类 + * Basic test class * * @author Jiaju Zhuang **/ diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest.java index 943c1863a..9a3e12c99 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest.java @@ -24,43 +24,43 @@ public class SqlUtilsTest { @Test public void test() { List sqlStatements = SQLUtils.parseStatements("select 1 from test;", DbType.mysql); - log.info("解析sql:{}", sqlStatements); + log.info("Parse sql:{}", sqlStatements); sqlStatements = SQLUtils.parseStatements("use xxx;select 1 from test;explain select 1 from test", DbType.mysql); - log.info("解析sql:{}", sqlStatements); + log.info("Parse sql:{}", sqlStatements); sqlStatements = SQLUtils.parseStatements("select 1 from1 test", DbType.mysql); - log.info("解析sql:{}", sqlStatements); + log.info("Parse sql:{}", sqlStatements); } @Test public void test55() { List sqlStatements = SQLUtils.parseStatements("create table test(id int) comment 'xx';", DbType.mysql); - log.info("解析sql:{}", sqlStatements); + log.info("Parse sql:{}", sqlStatements); } @Test public void test2() { String sql = "select * from test"; - log.info("分页:{} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), + log.info("Pagination: {} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), PagerUtils.limit(sql, DbType.mysql, 1000, 999), PagerUtils.limit(sql, DbType.mysql, 1000, 999, true)); sql = "select * from test where id=1 limit 100;"; - log.info("分页:{} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), + log.info("Pagination: {} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), PagerUtils.limit(sql, DbType.mysql, 1000, 999), PagerUtils.limit(sql, DbType.mysql, 1000, 999, true)); sql = "select * from test where id=1 limit 100,10;"; - log.info("分页:{} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), + log.info("Pagination: {} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), PagerUtils.limit(sql, DbType.mysql, 1000, 999), PagerUtils.limit(sql, DbType.mysql, 1000, 999, true)); sql = "select * from test where id=1 limit 100,10;"; - log.info("分页:{} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), + log.info("Pagination: {} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), PagerUtils.limit(sql, DbType.mysql, 2, 2), PagerUtils.limit(sql, DbType.mysql, 2, 2, true)); sql = "select * from test union select * from test2"; - log.info("分页:{} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), + log.info("Pagination: {} ----- {} --- {}", PagerUtils.count(sql, DbType.mysql), PagerUtils.limit(sql, DbType.mysql, 2, 2), PagerUtils.limit(sql, DbType.mysql, 2, 2, true)); @@ -77,7 +77,7 @@ public void test56() { + "index ds(id) ,primary key (id,nu)) " + "comment 'xx';", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -103,7 +103,7 @@ public void testreaname() { SQLStatement sqlStatement = SQLUtils.parseSingleStatement( "rename table data_ops_table_test_1667268894825 to data_ops_table_test_166726889482511;", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -111,9 +111,9 @@ public void testcomment() { SQLStatement sqlStatement = SQLUtils.parseSingleStatement( "\n" + "alter table data_ops_table_test_166726889482511\n" - + " comment '测试表33';", + + " comment 'Test table 33';", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -121,7 +121,7 @@ public void dropindex() { SQLStatement sqlStatement = SQLUtils.parseSingleStatement( "drop index data_ops_table_test_1667268894825_idx_date on data_ops_table_test_1667268894825;", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -130,9 +130,9 @@ public void createindex() { "\n" + "create index data_ops_table_test_1667268894825_idx_date\n" + " on data_ops_table_test_1667268894825 (date desc, id asc)\n" - + " comment '日期索引';", + + " comment 'date index';", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -141,25 +141,25 @@ public void addColumn() { "alter table data_ops_table_test_1667268894825\n" + " add column_5 int default de null;", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test public void change() { SQLStatement sqlStatement = SQLUtils.parseSingleStatement( "alter table data_ops_table_test_1667268894825\n" - + " change number number1 bigint null comment '长整型';", + + " change number number1 bigint null comment 'long integer';", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test public void modify() { SQLStatement sqlStatement = SQLUtils.parseSingleStatement( "alter table data_ops_table_test_1667268894825\n" - + " modify number1 bigint null comment '长整型';", + + " modify number1 bigint null comment 'long integer';", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -168,7 +168,7 @@ public void dropColumn() { "alter table data_ops_table_test_1667268894825\n" + " drop column string;", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -178,7 +178,7 @@ public void dropPrimaryKey() { + "DROP PRIMARY KEY,\n" + "ADD PRIMARY KEY (`date`) USING BTREE;", DbType.mysql); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -186,9 +186,9 @@ public void coment() { try { SQLStatement sqlStatement = SQLUtils.parseSingleStatement( - "comment on index DATA_OPS_TEMPLATE_TEST_1672663574919_idx_date is '日期索引xx';\n", + "comment on index DATA_OPS_TEMPLATE_TEST_1672663574919_idx_date is 'Date index xx';\n", DbType.h2, SQLParserFeature.PrintSQLWhileParsingFailed); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } catch (Exception e) { e.printStackTrace(); } @@ -198,9 +198,9 @@ public void coment() { public void errro() { List sqlStatementList = SQLUtils.parseStatements( "alter table data_ops_table_test_1667268894825 drop column string;comment on index " - + "DATA_OPS_TEMPLATE_TEST_1672663574919_idx_date is '日期索引xx';\n", + + "DATA_OPS_TEMPLATE_TEST_1672663574919_idx_date is 'Date index xx';\n", DbType.h2, SQLParserFeature.PrintSQLWhileParsingFailed); - log.info("解析sql:{}", sqlStatementList); + log.info("Parse sql:{}", sqlStatementList); } @@ -210,24 +210,24 @@ public void creattable() { List sqlStatementList = SQLUtils.parseStatements( "CREATE TABLE `data_ops_table_test_1673096155228`\n" + "\t(\n" - + "\t `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n" - + "\t `date` datetime(3) not null COMMENT '日期',\n" - + "\t `number` bigint COMMENT '长整型',\n" - + "\t `string` VARCHAR(100) default 'DATA' COMMENT '名字',\n" - + "\t index data_ops_table_test_1673096155228_idx_date (date desc) comment '日期索引',\n" - + "\t unique data_ops_table_test_1673096155228_uk_number (number) comment '唯一索引',\n" - + "\t index data_ops_table_test_1673096155228_idx_number_string (number, date) comment '联合索引'\n" - + "\t) COMMENT ='测试表';", DbType.mysql); - log.info("解析sql:{}", sqlStatementList); + + "\t `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n" + + "\t `date` datetime(3) not null COMMENT 'date',\n" + + "\t `number` bigint COMMENT 'long integer',\n" + + "\t `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n" + + "\t index data_ops_table_test_1673096155228_idx_date (date desc) comment 'date index',\n" + + "\t unique data_ops_table_test_1673096155228_uk_number (number) comment 'unique index',\n" + + "\t index data_ops_table_test_1673096155228_idx_number_string (number, date) comment 'Union index'\n" + + "\t) COMMENT ='Test table';", DbType.mysql); + log.info("Parse sql:{}", sqlStatementList); } @Test public void testlimit2() { SQLLimit sqlLimit= SQLUtils.getLimit("select * from t_orderdetail limit 0,1",DbType.mysql); - log.info("解析sql:{}", sqlLimit); + log.info("Parse sql:{}", sqlLimit); sqlLimit= SQLUtils.getLimit("select * from t_orderdetail",DbType.mysql); - log.info("解析sql:{}", sqlLimit); + log.info("Parse sql:{}", sqlLimit); } diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest2.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest2.java index 7ef4e6c95..dfe939984 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest2.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/druid/SqlUtilsTest2.java @@ -18,9 +18,9 @@ public class SqlUtilsTest2 { @Test public void coment() { SQLStatement sqlStatement = SQLUtils.parseSingleStatement( - "comment on index myindex is '日期xxx';\n", + "comment on index myindex is 'datexxx';\n", DbType.h2); - log.info("解析sql:{}", sqlStatement); + log.info("Parse sql:{}", sqlStatement); } @Test @@ -50,7 +50,7 @@ public void select2() { public void insert() { SQLStatement sqlStatement = SQLUtils.parseSingleStatement("INSERT INTO chat2db.`order` (id, user_id, total_price, created_at, updated_at) VALUES (8, 345, 5601.16, '2022-09-18 11:21:12', '2023-04-30 11:21:12');", DbType.mysql); - log.info("解析sql1:{}", sqlStatement); + log.info("Parse sql1:{}", sqlStatement); } diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/mybatis/MybatisGeneratorTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/mybatis/MybatisGeneratorTest.java index e07c3c103..b502e1dc1 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/mybatis/MybatisGeneratorTest.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/mybatis/MybatisGeneratorTest.java @@ -14,12 +14,14 @@ import com.baomidou.mybatisplus.generator.config.rules.DateType; import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; import com.google.common.collect.Lists; +import com.zaxxer.hikari.HikariDataSource; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; /** - * 生成mybatis 的mapper + * Generate mapper of mybatis * * @author Jiaju Zhuang */ @@ -30,17 +32,35 @@ public class MybatisGeneratorTest extends BaseTest { @Test public void coreGenerator() { + + HikariDataSource dataSource = new HikariDataSource(); + String environment = StringUtils.defaultString(System.getProperty("spring.profiles.active"), "dev"); + if ("dev".equalsIgnoreCase(environment)) { + dataSource.setJdbcUrl("jdbc:h2:file:~/.chat2db/db/chat2db_dev;MODE=MYSQL"); + }else if ("test".equalsIgnoreCase(environment)) { + dataSource.setJdbcUrl("jdbc:h2:file:~/.chat2db/db/chat2db_test;MODE=MYSQL"); + }else { + dataSource.setJdbcUrl("jdbc:h2:~/.chat2db/db/chat2db;MODE=MYSQL;FILE_LOCK=NO"); + } + dataSource.setDriverClassName("org.h2.Driver"); + dataSource.setIdleTimeout(60000); + dataSource.setAutoCommit(true); + dataSource.setMaximumPoolSize(500); + dataSource.setMinimumIdle(1); + dataSource.setMaxLifetime(60000 * 10); + dataSource.setConnectionTestQuery("SELECT 1"); + this.dataSource = dataSource; //doGenerator(Lists.newArrayList("data_source")); //doGenerator(Lists.newArrayList("operation_log")); //doGenerator(Lists.newArrayList("operation_saved")); //doGenerator(Lists.newArrayList("environment","data_source","team","team_dbhub_user","data_source_access", // "dbhub_user")); - doGenerator(Lists.newArrayList("operation_log")); + doGenerator(Lists.newArrayList("TASK")); } private void doGenerator(List tableList) { - // 当前项目地址 拿到的是chat2db-server-start地址 + // The current project address is the chat2db-server-start address. String outputDir = System.getProperty("user.dir") + "/../chat2db-server-domain/chat2db-server-domain-repository/src/main" + "/java"; @@ -48,7 +68,7 @@ private void doGenerator(List tableList) { + "/../chat2db-server-domain/chat2db-server-domain-repository/src/main" + "/resources/mapper"; - // 不要生成service controller + // Do not generate service controller Map pathInfo = new HashMap<>(); pathInfo.put(OutputFile.service, null); pathInfo.put(OutputFile.serviceImpl, null); @@ -58,48 +78,48 @@ private void doGenerator(List tableList) { FastAutoGenerator .create(new DataSourceConfig.Builder(dataSource) .typeConvert(new MySqlTypeConvert())) - //全局配置 + //Global configuration .globalConfig(builder -> { - // 设置作者 + // Set author builder.author("chat2db") - //执行完毕不打开文件夹 + //Do not open the folder after execution .disableOpenDir() - // 还是使用date + // Or use date .dateType(DateType.ONLY_DATE) - // 指定输出目录 + // Specify output directory .outputDir(outputDir); }) - //包配置 + //Package configuration .packageConfig(builder -> { - // 设置父包名 + // Set parent package name builder.parent("ai.chat2db.server.domain.repository") - //生成实体层 + //Generate solid layer .entity("entity") .pathInfo(pathInfo) - //生成mapper层 + //Generate mapper layer .mapper("mapper"); }) - //策略配置 + //Policy configuration .strategyConfig(builder -> { - // 设置需要生成的表名 + // Set the table name to be generated builder.addInclude(tableList) - //开启实体类配置 + //Enable entity class configuration .entityBuilder() .formatFileName("%sDO") .enableFileOverride() - //.addTableFills(new Column("gmt_create", FieldFill.INSERT)) // 表字段填充 - //.addTableFills(new Column("update_time", FieldFill.INSERT_UPDATE)) // 表字段填充 - //开启lombok + //.addTableFills(new Column("gmt_create", FieldFill.INSERT)) // Table field filling + //.addTableFills(new Column("update_time", FieldFill.INSERT_UPDATE)) // Table field filling + //Turn on lombok .enableLombok() .mapperBuilder() - //// 覆盖文件 + //// overwrite file .enableFileOverride() ; }) - //模板配置 + //Template configuration .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板 - //执行 + //execute .execute(); } diff --git a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/sql/DbhubJdbcTemplateTest.java b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/sql/DbhubJdbcTemplateTest.java index 20f9cd51b..37ef1c829 100644 --- a/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/sql/DbhubJdbcTemplateTest.java +++ b/chat2db-server/chat2db-server-start/src/test/java/ai/chat2db/server/start/test/sql/DbhubJdbcTemplateTest.java @@ -10,7 +10,7 @@ import org.springframework.jdbc.core.JdbcTemplate; /** - * 模板 + * template * * @author Jiaju Zhuang */ @@ -21,7 +21,7 @@ public class DbhubJdbcTemplateTest { @BeforeAll public static void prepare() throws Exception { - log.info("连接mysql"); + log.info("connect mysql"); } @Test diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/common/BaseTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/common/BaseTest.java index be4900657..fcc8c4145 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/common/BaseTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/common/BaseTest.java @@ -10,7 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; /** - * 基础测试类 + * Basic test class * * @author Jiaju Zhuang **/ diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ConsoleOperationsTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ConsoleOperationsTest.java index cab72a50b..b1cb6c5ad 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ConsoleOperationsTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ConsoleOperationsTest.java @@ -19,7 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; /** - * 数据源测试 + * Data source testing * * @author Jiaju Zhuang */ @@ -48,14 +48,14 @@ public void createAndClose() { dataSourceCreateParam.setPassword(dialectProperties.getPassword()); dataSourceService.preConnect(dataSourceCreateParam); - // 创建 + // creat ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); consoleCreateParam.setDataSourceId(dataSourceId); consoleCreateParam.setConsoleId(consoleId); consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName()); consoleService.createConsole(consoleCreateParam); - // 关闭 + // close ConsoleCloseParam consoleCloseParam = new ConsoleCloseParam(); consoleCloseParam.setDataSourceId(dataSourceId); consoleCloseParam.setConsoleId(consoleId); @@ -102,7 +102,7 @@ public void closeDataSourceAfterCreateConsole() { dataSourceCreateParam.setPassword(dialectProperties.getPassword()); dataSourceService.preConnect(dataSourceCreateParam); - // 创建控制台 + // Create a console ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); consoleCreateParam.setDataSourceId(dataSourceId); consoleCreateParam.setConsoleId(consoleId); diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/DatabaseOperationsTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/DatabaseOperationsTest.java index 5ba0a44e7..eb6622275 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/DatabaseOperationsTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/DatabaseOperationsTest.java @@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; /** - * 数据库测试 + * Database testing * * @author Jiaju Zhuang */ @@ -42,7 +42,7 @@ public void queryAll() { String dbTypeEnum = dialectProperties.getDbType(); Long dataSourceId = TestUtils.nextLong(); - // 准备上下文 + // Prepare context putConnect(dialectProperties.getUrl(), dialectProperties.getUsername(), dialectProperties.getPassword(), dialectProperties.getDbType(), dialectProperties.getDatabaseName(), dataSourceId, null); @@ -57,13 +57,13 @@ public void queryAll() { DatabaseQueryAllParam databaseQueryAllParam = new DatabaseQueryAllParam(); databaseQueryAllParam.setDataSourceId(dataSourceId); ListResult databaseList = databaseService.queryAll(databaseQueryAllParam); - log.info("查询数据库返回:{}", JSON.toJSONString(databaseList)); + log.info("Querying the database returns: {}", JSON.toJSONString(databaseList)); Database Database = databaseList.getData().stream() .filter(database -> dialectProperties.getDatabaseName().equals(database.getName())) .findFirst() .orElse(null); - Assertions.assertNotNull(Database, "查询数据库失败"); + Assertions.assertNotNull(Database, "Query database failed"); removeConnect(); } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ExampleOperationsTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ExampleOperationsTest.java index c128f1ec7..f2edde37a 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ExampleOperationsTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/ExampleOperationsTest.java @@ -16,7 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; /** - * 样例 + * Sample * * @author Jiaju Zhuang */ @@ -33,11 +33,11 @@ public class ExampleOperationsTest extends BaseTest { public void example() { for (DialectProperties dialectProperties : dialectPropertiesList) { DataResult createTable = tableService.createTableExample(dialectProperties.getDbType()); - log.info("返回建表语句:{}", createTable); - Assertions.assertNotNull(createTable, "查询样例失败"); + log.info("Return table creation statement: {}", createTable); + Assertions.assertNotNull(createTable, "Query sample failed"); DataResult alterTable = tableService.alterTableExample(dialectProperties.getDbType()); - log.info("返回建修改表语句:{}", alterTable); - Assertions.assertNotNull(alterTable, "查询样例失败"); + log.info("Return the statement to create and modify the table: {}", alterTable); + Assertions.assertNotNull(alterTable, "Query sample failed"); } } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/JdbcOperationsTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/JdbcOperationsTest.java index e4a8d3a3e..91dab51f7 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/JdbcOperationsTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/JdbcOperationsTest.java @@ -28,14 +28,14 @@ import org.springframework.beans.factory.annotation.Autowired; /** - * 查询测试 + * query test * * @author Jiaju Zhuang */ @Slf4j public class JdbcOperationsTest extends BaseTest { /** - * 表名 + * Table Name */ public static final String TABLE_NAME = "DATA_OPS_TEMPLATE_TEST_" + System.currentTimeMillis(); private final static String STRING = "STR"; @@ -61,7 +61,7 @@ public void execute() { Long dataSourceId = TestUtils.nextLong(); Long consoleId = TestUtils.nextLong(); - // 准备上下文 + // Prepare context putConnect(dialectProperties.getUrl(), dialectProperties.getUsername(), dialectProperties.getPassword(), dialectProperties.getDbType(), dialectProperties.getDatabaseName(), dataSourceId, consoleId); @@ -72,7 +72,7 @@ public void execute() { dataSourceCreateParam.setPassword(dialectProperties.getPassword()); dataSourceService.preConnect(dataSourceCreateParam); - // 创建控制台 + // Create a console ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); consoleCreateParam.setDataSourceId(dataSourceId); consoleCreateParam.setConsoleId(consoleId); @@ -85,46 +85,46 @@ public void execute() { templateQueryParam.setSql(dialectProperties.getCrateTableSql(TABLE_NAME)); dlTemplateService.execute(templateQueryParam); - // 插入 + // insert templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(consoleId); templateQueryParam.setDataSourceId(dataSourceId); templateQueryParam.setSql(dialectProperties.getInsertSql(TABLE_NAME, DATE, NUMBER, STRING)); ListResult executeResult = dlTemplateService.execute(templateQueryParam); - Assertions.assertTrue(executeResult.getSuccess(), "查询数据失败"); - // Assertions.assertEquals(1, listResult.getUpdateCount(), "查询数据失败"); + Assertions.assertTrue(executeResult.getSuccess(), "Query data failed"); + // Assertions.assertEquals(1, listResult.getUpdateCount(), "Query data failed"); - // 查询 + // query templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(consoleId); templateQueryParam.setDataSourceId(dataSourceId); templateQueryParam.setSql(dialectProperties.getSelectSqlById(TABLE_NAME, 1L)); executeResult = dlTemplateService.execute(templateQueryParam); - log.info("返回数据:{}", JSON.toJSONString(executeResult)); - Assertions.assertTrue(executeResult.getSuccess(), "查询数据失败"); + log.info("Return data:{}", JSON.toJSONString(executeResult)); + Assertions.assertTrue(executeResult.getSuccess(), "Query data failed"); List
headerList = executeResult.getData().get(0).getHeaderList(); - Assertions.assertEquals(4L, headerList.size(), "查询数据失败"); - Assertions.assertEquals(dialectProperties.toCase("ID"), headerList.get(0).getName(), "查询数据失败"); + Assertions.assertEquals(4L, headerList.size(), "Query data failed"); + Assertions.assertEquals(dialectProperties.toCase("ID"), headerList.get(0).getName(), "Query data failed"); List> dataList = executeResult.getData().get(0).getDataList(); - Assertions.assertEquals(1L, dataList.size(), "查询数据失败"); + Assertions.assertEquals(1L, dataList.size(), "Query data failed"); List data1 = dataList.get(0); - Assertions.assertEquals(Long.toString(NUMBER), data1.get(0), "查询数据失败"); + Assertions.assertEquals(Long.toString(NUMBER), data1.get(0), "Query data failed"); log.info("date:{},{}", DATE, data1.get(1)); Assertions.assertEquals(DateUtil.format(DATE, DatePattern.NORM_DATETIME_FORMAT), data1.get(1), - "查询数据失败"); - Assertions.assertEquals(Long.toString(NUMBER), data1.get(2), "查询数据失败"); - Assertions.assertEquals(STRING, data1.get(3), "查询数据失败"); + "Query data failed"); + Assertions.assertEquals(Long.toString(NUMBER), data1.get(2), "Query data failed"); + Assertions.assertEquals(STRING, data1.get(3), "Query data failed"); - // 异常sql + // Exception sql templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(consoleId); templateQueryParam.setDataSourceId(dataSourceId); templateQueryParam.setSql(dialectProperties.getTableNotFoundSqlById(TABLE_NAME)); executeResult = dlTemplateService.execute(templateQueryParam); - log.info("异常sql执行结果:{}", JSON.toJSONString(executeResult)); - Assertions.assertFalse(executeResult.getSuccess(), "异常sql错误"); - Assertions.assertNotNull(executeResult.getErrorMessage(), "异常sql错误"); + log.info("Abnormal sql execution result: {}", JSON.toJSONString(executeResult)); + Assertions.assertFalse(executeResult.getSuccess(), "Exception sql error"); + Assertions.assertNotNull(executeResult.getErrorMessage(), "Exception sql error"); removeConnect(); } @@ -146,21 +146,21 @@ public void dropTable() { dataSourceCreateParam.setPassword(dialectProperties.getPassword()); dataSourceService.preConnect(dataSourceCreateParam); - // 创建控制台 + // Create a console ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); consoleCreateParam.setDataSourceId(dataSourceId); consoleCreateParam.setConsoleId(consoleId); consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName()); consoleService.createConsole(consoleCreateParam); - // 创建表结构 + // Create table structure DlExecuteParam templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(consoleId); templateQueryParam.setDataSourceId(dataSourceId); templateQueryParam.setSql(dialectProperties.getDropTableSql(TABLE_NAME)); dlTemplateService.execute(templateQueryParam); } catch (Exception e) { - log.warn("删除表结构失败.", e); + log.warn("Failed to delete table structure.", e); } } } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/SQLExecutorOperationsTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/SQLExecutorOperationsTest.java index 7fbe3ebae..54275ec2d 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/SQLExecutorOperationsTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/SQLExecutorOperationsTest.java @@ -19,7 +19,7 @@ import java.util.List; /** - * 数据源测试 + * Data source testing * * @author Jiaju Zhuang */ @@ -37,7 +37,7 @@ public void createAndClose() { String dbTypeEnum = dialectProperties.getDbType(); Long dataSourceId = TestUtils.nextLong(); TestUtils.buildContext(dialectProperties, dataSourceId, null); - // 创建 + // creat DataSourcePreConnectParam dataSourceCreateParam = new DataSourcePreConnectParam(); dataSourceCreateParam.setType(dbTypeEnum); @@ -45,10 +45,10 @@ public void createAndClose() { dataSourceCreateParam.setUser(dialectProperties.getUsername()); dataSourceCreateParam.setPassword(dialectProperties.getPassword()); ActionResult dataSourceConnect = dataSourceService.preConnect(dataSourceCreateParam); - Assertions.assertTrue(dataSourceConnect.getSuccess(), "创建数据库连接池失败"); - // Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "创建数据库连接池失败"); + Assertions.assertTrue(dataSourceConnect.getSuccess(), "Failed to create database connection pool"); + // Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "Failed to create database connection pool"); - // 关闭 + // cloes dataSourceService.close(dataSourceId); TestUtils.remove(); } @@ -60,7 +60,7 @@ public void test() { for (DialectProperties dialectProperties : dialectPropertiesList) { String dbTypeEnum = dialectProperties.getDbType(); - // 创建 + // creat DataSourcePreConnectParam dataSourceCreateParam = new DataSourcePreConnectParam(); dataSourceCreateParam.setType(dbTypeEnum); @@ -68,8 +68,8 @@ public void test() { dataSourceCreateParam.setUser(dialectProperties.getUsername()); dataSourceCreateParam.setPassword(dialectProperties.getPassword()); ActionResult dataSourceConnect = dataSourceService.preConnect(dataSourceCreateParam); - log.info("创建数据库返回:{}", JSON.toJSONString(dataSourceConnect)); - Assertions.assertFalse(dataSourceConnect.getSuccess(), "创建数据库失败错误"); + log.info("Create database returns: {}", JSON.toJSONString(dataSourceConnect)); + Assertions.assertFalse(dataSourceConnect.getSuccess(), "Database creation failed error"); } } @Test @@ -82,7 +82,7 @@ public void createDataSource(){ String dbTypeEnum = dialectProperties.getDbType(); Long dataSourceId = TestUtils.nextLong(); TestUtils.buildContext(dialectProperties, dataSourceId, null); - // 创建 + // creat DataSourceCreateParam dataSourceCreateParam = new DataSourceCreateParam(); dataSourceCreateParam.setAlias(dialectProperties.getDbType()+"_unittest_"+dialectProperties.getDbType()); dataSourceCreateParam.setType(dbTypeEnum); @@ -90,8 +90,8 @@ public void createDataSource(){ dataSourceCreateParam.setUserName(dialectProperties.getUsername()); dataSourceCreateParam.setPassword(dialectProperties.getPassword()); DataResult dataSourceConnect = dataSourceService.createWithPermission(dataSourceCreateParam); - Assertions.assertTrue(dataSourceConnect.getSuccess(), "创建数据库连接池失败"); - // Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "创建数据库连接池失败"); + Assertions.assertTrue(dataSourceConnect.getSuccess(), "Failed to create database connection pool"); + // Assertions.assertTrue(DataCenterUtils.JDBC_ACCESSOR_MAP.containsKey(dataSourceId), "Failed to create database connection pool"); } } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/TableOperationsTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/TableOperationsTest.java index 84dfc5ae5..c4d27adda 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/TableOperationsTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/TableOperationsTest.java @@ -39,14 +39,14 @@ import org.springframework.beans.factory.annotation.Autowired; /** - * 数据源测试 + * Data source testing * * @author Jiaju Zhuang */ @Slf4j public class TableOperationsTest extends BaseTest { /** - * 表名 + * Table Name */ public static final String TABLE_NAME = "data_ops_table_test_" + System.currentTimeMillis(); @@ -72,7 +72,7 @@ public void table() { Long dataSourceId = TestUtils.nextLong(); Long consoleId = TestUtils.nextLong(); - // 准备上下文 + // Prepare context putConnect(dialectProperties.getUrl(), dialectProperties.getUsername(), dialectProperties.getPassword(), dialectProperties.getDbType(), dialectProperties.getDatabaseName(), dataSourceId, consoleId); @@ -84,21 +84,21 @@ public void table() { dataSourceCreateParam.setPassword(dialectProperties.getPassword()); dataSourceService.preConnect(dataSourceCreateParam); - // 创建控制台 + // Create a console ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); consoleCreateParam.setDataSourceId(dataSourceId); consoleCreateParam.setConsoleId(consoleId); consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName()); consoleService.createConsole(consoleCreateParam); - // 创建表结构 + // Create table structure DlExecuteParam templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(consoleId); templateQueryParam.setDataSourceId(dataSourceId); templateQueryParam.setSql(dialectProperties.getCrateTableSql(TABLE_NAME)); dlTemplateService.execute(templateQueryParam); - // 查询建表语句 + // Query table creation statement ShowCreateTableParam showCreateTableParam = ShowCreateTableParam.builder() .dataSourceId(dataSourceId) .databaseName(dialectProperties.getDatabaseName()) @@ -109,13 +109,13 @@ public void table() { } DataResult createTable = tableService.showCreateTable(showCreateTableParam); - log.info("建表语句:{}", createTable.getData()); + log.info("Table creation statement: {}", createTable.getData()); if (dialectProperties.getDbType() != "H2") { Assertions.assertTrue(createTable.getData().contains(dialectProperties.toCase(TABLE_NAME)), - "查询表结构失败"); + "Query table structure failed"); } - // 查询表结构 + // Query table structure TablePageQueryParam tablePageQueryParam = new TablePageQueryParam(); tablePageQueryParam.setDataSourceId(dataSourceId); tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName()); @@ -127,12 +127,12 @@ public void table() { .columnList(Boolean.TRUE) .indexList(Boolean.TRUE) .build()).getData(); - log.info("分析数据返回{}", JSON.toJSONString(tableList)); - Assertions.assertNotEquals(0L, tableList.size(), "查询表结构失败"); + log.info("Analyzing data returns {}", JSON.toJSONString(tableList)); + Assertions.assertNotEquals(0L, tableList.size(), "Query table structure failed"); Table table = tableList.get(0); - // Assertions.assertEquals(dialectProperties.toCase(TABLE_NAME), table.getName(), "查询表结构失败"); + // Assertions.assertEquals(dialectProperties.toCase(TABLE_NAME), table.getName(), "Query table structure failed"); if (dialectProperties.getDbType() != "POSTGRESQL") { - Assertions.assertEquals("测试表", table.getComment(), "查询表结构失败"); + Assertions.assertEquals("Test table", table.getComment(), "Query table structure failed"); } TableQueryParam tableQueryParam = new TableQueryParam(); tableQueryParam.setTableName(table.getName()); @@ -142,50 +142,50 @@ public void table() { tableQueryParam.setSchemaName("public"); } List columnList = tableService.queryColumns(tableQueryParam); - Assertions.assertEquals(4L, columnList.size(), "查询表结构失败"); + Assertions.assertEquals(4L, columnList.size(), "Query table structure failed"); TableColumn id = columnList.get(0); - Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "查询表结构失败"); - Assertions.assertEquals("主键自增", id.getComment(), "查询表结构失败"); - Assertions.assertTrue(id.getAutoIncrement(), "查询表结构失败"); - //Assertions.assertFalse(id.getNullable(), "查询表结构失败"); + Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "Query table structure failed"); + Assertions.assertEquals("Primary key auto-increment", id.getComment(), "Query table structure failed"); + Assertions.assertTrue(id.getAutoIncrement(), "Query table structure failed"); + //Assertions.assertFalse(id.getNullable(), "Query table structure failed"); TableColumn string = columnList.get(3); - Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "查询表结构失败"); - //Assertions.assertTrue(string.getNullable(), "查询表结构失败"); + Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "Query table structure failed"); + //Assertions.assertTrue(string.getNullable(), "Query table structure failed"); Assertions.assertEquals("DATA", TestUtils.unWrapperDefaultValue(string.getDefaultValue()), - "查询表结构失败"); + "Query table structure failed"); if (dialectProperties.getDbType() == "POSTGRESQL") { tablePageQueryParam.setSchemaName("public"); } List tableIndexList = tableService.queryIndexes(tableQueryParam); - log.info("分析数据返回{}", JSON.toJSONString(tableIndexList)); - Assertions.assertEquals(4L, tableIndexList.size(), "查询表结构失败"); + log.info("Analyzing data returns {}", JSON.toJSONString(tableIndexList)); + Assertions.assertEquals(4L, tableIndexList.size(), "Query table structure failed"); Map tableIndexMap = EasyCollectionUtils.toIdentityMap(tableIndexList, TableIndex::getName); TableIndex idxDate = tableIndexMap.get(dialectProperties.toCase(TABLE_NAME + "_idx_date")); - Assertions.assertEquals("日期索引", idxDate.getComment(), "查询表结构失败"); - Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "查询表结构失败"); - Assertions.assertEquals(1L, idxDate.getColumnList().size(), "查询表结构失败"); + Assertions.assertEquals("date index", idxDate.getComment(), "Query table structure failed"); + Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "Query table structure failed"); + Assertions.assertEquals(1L, idxDate.getColumnList().size(), "Query table structure failed"); Assertions.assertEquals(dialectProperties.toCase("date"), idxDate.getColumnList().get(0).getColumnName(), - "查询表结构失败"); + "Query table structure failed"); Assertions.assertEquals(CollationEnum.DESC.getCode(), idxDate.getColumnList().get(0).getCollation(), - "查询表结构失败"); + "Query table structure failed"); TableIndex ukNumber = tableIndexMap.get(dialectProperties.toCase(TABLE_NAME + "_uk_number")); - Assertions.assertEquals("唯一索引", ukNumber.getComment(), "查询表结构失败"); - Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "查询表结构失败"); + Assertions.assertEquals("unique index", ukNumber.getComment(), "Query table structure failed"); + Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "Query table structure failed"); TableIndex idxNumberString = tableIndexMap.get(dialectProperties.toCase(TABLE_NAME + "_idx_number_string")); - Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "查询表结构失败"); + Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "Query table structure failed"); - // 删除表结构 + // Delete table structure DropParam dropParam = DropParam.builder() .dataSourceId(dataSourceId) .databaseName(dialectProperties.getDatabaseName()) .tableName(dialectProperties.toCase(TABLE_NAME)) .build(); tableService.drop(dropParam); - // 查询表结构 + // Query table structure tablePageQueryParam = new TablePageQueryParam(); tablePageQueryParam.setDataSourceId(dataSourceId); tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName()); @@ -194,10 +194,10 @@ public void table() { .columnList(Boolean.TRUE) .indexList(Boolean.TRUE) .build()).getData(); - log.info("删除表后数据返回{}", JSON.toJSONString(tableList)); - Assertions.assertEquals(0L, tableList.size(), "查询表结构失败"); + log.info("After deleting the table, the data returns {}", JSON.toJSONString(tableList)); + Assertions.assertEquals(0L, tableList.size(), "Query table structure failed"); - // 测试建表语句 + // Test the table creation statement testBuildSql(dialectProperties, dataSourceId, consoleId); removeConnect(); @@ -207,36 +207,36 @@ public void table() { private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId, Long consoleId) { if (dialectProperties.getDbType() != "MYSQL") { - log.error("目前测试案例只支持mysql"); + log.error("Currently the test case only supports mysql"); return; } - // 新建表 + // Create new table // CREATE TABLE `DATA_OPS_TEMPLATE_TEST_1673093980449` // ( - // `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增', - // `date` datetime(3) not null COMMENT '日期', - // `number` bigint COMMENT '长整型', - // `string` VARCHAR(100) default 'DATA' COMMENT '名字', - // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment '日期索引', - // unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment '唯一索引', - // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment '联合索引' - //) COMMENT ='测试表'; - // * 大小写看具体的数据库决定: - //* 创建表表结构 : 测试表 - // * 字段: - //* id 主键自增 - //* date 日期 非空 - // * number 长整型 - // * string 字符串 长度100 默认值 "DATA" + // `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment', + // `date` datetime(3) not null COMMENT 'date', + // `number` bigint COMMENT 'long integer', + // `string` VARCHAR(100) default 'DATA' COMMENT 'name', + // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment 'date index', + // unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment 'unique index', + // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment 'Union index' + //) COMMENT ='Test table'; + // * The case depends on the specific database: + //* Create table structure: Test table + // * Fields: + //* id Primary key auto-increment + //* date date is not null + // * number long integer + // * string String length 100 default value "DATA" // * - //* 索引(加上$tableName_ 原因是 有些数据库索引是全局唯一的): - //* $tableName_idx_date 日期索引 倒序 - // * $tableName_uk_number 唯一索引 - // * $tableName_idx_number_string 联合索引 + //* Index (plus $tableName_ because some database indexes are globally unique): + //* $tableName_idx_date date index reverse order + // * $tableName_uk_number unique index + // * $tableName_idx_number_string Union index String tableName = dialectProperties.toCase("data_ops_table_test_" + System.currentTimeMillis()); Table newTable = new Table(); newTable.setName(tableName); - newTable.setComment("测试表"); + newTable.setComment("Test table"); List tableColumnList = new ArrayList<>(); newTable.setColumnList(tableColumnList); //id @@ -245,7 +245,7 @@ private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId idTableColumn.setAutoIncrement(Boolean.TRUE); idTableColumn.setPrimaryKey(Boolean.TRUE); //idTableColumn.setNullable(Boolean.FALSE); - idTableColumn.setComment("主键自增"); + idTableColumn.setComment("Primary key auto-increment"); idTableColumn.setColumnType("bigint"); tableColumnList.add(idTableColumn); @@ -253,54 +253,54 @@ private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId TableColumn dateTableColumn = new TableColumn(); dateTableColumn.setName("date"); //dateTableColumn.setNullable(Boolean.FALSE); - dateTableColumn.setComment("日期"); + dateTableColumn.setComment("date"); dateTableColumn.setColumnType("datetime(3)"); tableColumnList.add(dateTableColumn); // number TableColumn numberTableColumn = new TableColumn(); numberTableColumn.setName("number"); - numberTableColumn.setComment("长整型"); + numberTableColumn.setComment("long integer"); numberTableColumn.setColumnType("bigint"); tableColumnList.add(numberTableColumn); // string TableColumn stringTableColumn = new TableColumn(); stringTableColumn.setName("string"); - stringTableColumn.setComment("名字"); + stringTableColumn.setComment("name"); stringTableColumn.setColumnType("varchar(100)"); stringTableColumn.setDefaultValue("DATA"); tableColumnList.add(stringTableColumn); - // 索引 + // index List tableIndexList = new ArrayList<>(); newTable.setIndexList(tableIndexList); - // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment '日期索引', + // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_date (date desc) comment 'date index', tableIndexList.add(TableIndex.builder() .name(tableName + "_idx_date") .type(IndexTypeEnum.NORMAL.getCode()) - .comment("日期索引") + .comment("date index") .columnList(Lists.newArrayList(TableIndexColumn.builder() .columnName("date") .collation(CollationEnum.DESC.getCode()) .build())) .build()); - // unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment '唯一索引', + // unique DATA_OPS_TEMPLATE_TEST_1673093980449_uk_number (number) comment 'unique index', tableIndexList.add(TableIndex.builder() .name(tableName + "_uk_number") .type(IndexTypeEnum.UNIQUE.getCode()) - .comment("唯一索引") + .comment("unique index") .columnList(Lists.newArrayList(TableIndexColumn.builder() .columnName("number") .build())) .build()); - // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment '联合索引' + // index DATA_OPS_TEMPLATE_TEST_1673093980449_idx_number_string (number, date) comment 'Union index' tableIndexList.add(TableIndex.builder() .name(tableName + "_idx_number_string") .type(IndexTypeEnum.NORMAL.getCode()) - .comment("联合索引") + .comment("Union index") .columnList(Lists.newArrayList(TableIndexColumn.builder() .columnName("number") .build(), @@ -308,9 +308,9 @@ private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId .columnName("date") .build())) .build()); - // 构建sql + // build sql List buildTableSqlList = tableService.buildSql(null, newTable).getData(); - log.info("创建表的结构语句是:{}", JSON.toJSONString(buildTableSqlList)); + log.info("The structural statement to create a table is:{}", JSON.toJSONString(buildTableSqlList)); for (Sql sql : buildTableSqlList) { DlExecuteParam templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(consoleId); @@ -319,10 +319,10 @@ private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId dlTemplateService.execute(templateQueryParam); } - // 校验表结构 + // Check table structure checkTable(tableName, dialectProperties, dataSourceId); - // 去数据库查询表结构 + // Go to the database to query the table structure TableQueryParam tablePageQueryParam = new TableQueryParam(); tablePageQueryParam.setDataSourceId(dataSourceId); tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName()); @@ -331,20 +331,20 @@ private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId .columnList(Boolean.TRUE) .indexList(Boolean.TRUE) .build()).getData(); - log.info("分析数据返回{}", JSON.toJSONString(table)); - Assertions.assertNotNull(table, "查询表结构失败"); + log.info("Analyzing data returns {}", JSON.toJSONString(table)); + Assertions.assertNotNull(table, "Query table structure failed"); Table oldTable = table; - Assertions.assertEquals(dialectProperties.toCase(tableName), oldTable.getName(), "查询表结构失败"); - Assertions.assertEquals("测试表", oldTable.getComment(), "查询表结构失败"); + Assertions.assertEquals(dialectProperties.toCase(tableName), oldTable.getName(), "Query table structure failed"); + Assertions.assertEquals("Test table", oldTable.getComment(), "Query table structure failed"); - // 修改表结构 - // 构建sql + // Modify table structure + // build sql log.info("oldTable:{}", JSON.toJSONString(oldTable)); log.info("newTable:{}", JSON.toJSONString(newTable)); buildTableSqlList = tableService.buildSql(oldTable, newTable).getData(); - log.info("修改表结构是:{}", JSON.toJSONString(buildTableSqlList)); + log.info("Modify the table structure: {}", JSON.toJSONString(buildTableSqlList)); Assertions.assertTrue(!buildTableSqlList.isEmpty(), "构建sql失败"); - // 重新去查询下 这样有2个对象 + // Let’s query again. There will be 2 objects. tablePageQueryParam = new TableQueryParam(); tablePageQueryParam.setDataSourceId(dataSourceId); tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName()); @@ -354,45 +354,45 @@ private void testBuildSql(DialectProperties dialectProperties, Long dataSourceId .indexList(Boolean.TRUE) .build()).getData(); - // 修改字段 + // Modify fields - // 新增一个字段 + // Add a new field newTable.getColumnList().add(TableColumn.builder() .name("add_string") .columnType("varchar(20)") - .comment("新增的字符串") + .comment("New string") .build()); - // 新增一个索引 + // Add a new index newTable.getIndexList().add(TableIndex.builder() .name(tableName + "_idx_string_new") .type(IndexTypeEnum.NORMAL.getCode()) - .comment("新的字符串索引") + .comment("new string index") .columnList(Lists.newArrayList(TableIndexColumn.builder() .columnName("add_string") .collation(CollationEnum.DESC.getCode()) .build())) .build()); - // 查询表结构变更 + // Query table structure changes log.info("oldTable:{}", JSON.toJSONString(oldTable)); log.info("newTable:{}", JSON.toJSONString(newTable)); buildTableSqlList = tableService.buildSql(oldTable, newTable).getData(); - log.info("修改表结构是:{}", JSON.toJSONString(buildTableSqlList)); + log.info("Modify the table structure: {}", JSON.toJSONString(buildTableSqlList)); - // 删除表结构 + // Delete table structure dropTable(tableName, dialectProperties, dataSourceId); } private void dropTable(String tableName, DialectProperties dialectProperties, Long dataSourceId) { - // 删除表结构 + // Delete table structure DropParam dropParam = DropParam.builder() .dataSourceId(dataSourceId) .databaseName(dialectProperties.getDatabaseName()) .tableName(dialectProperties.toCase(tableName)) .build(); tableService.drop(dropParam); - // 查询表结构 + // Query table structure TablePageQueryParam tablePageQueryParam = new TablePageQueryParam(); tablePageQueryParam.setDataSourceId(dataSourceId); tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName()); @@ -401,12 +401,12 @@ private void dropTable(String tableName, DialectProperties dialectProperties, Lo .columnList(Boolean.TRUE) .indexList(Boolean.TRUE) .build()).getData(); - log.info("删除表后数据返回{}", JSON.toJSONString(tableList)); - Assertions.assertEquals(0L, tableList.size(), "查询表结构失败"); + log.info("After deleting the table, the data returns {}", JSON.toJSONString(tableList)); + Assertions.assertEquals(0L, tableList.size(), "Query table structure failed"); } private void checkTable(String tableName, DialectProperties dialectProperties, Long dataSourceId) { - // 查询表结构 + // Query table structure TablePageQueryParam tablePageQueryParam = new TablePageQueryParam(); tablePageQueryParam.setDataSourceId(dataSourceId); tablePageQueryParam.setDatabaseName(dialectProperties.getDatabaseName()); @@ -416,50 +416,50 @@ private void checkTable(String tableName, DialectProperties dialectProperties, L .indexList(Boolean.TRUE) .build()).getData(); - log.info("分析数据返回{}", JSON.toJSONString(tableList)); - Assertions.assertEquals(1L, tableList.size(), "查询表结构失败"); + log.info("Analyzing data returns {}", JSON.toJSONString(tableList)); + Assertions.assertEquals(1L, tableList.size(), "Query table structure failed"); Table table = tableList.get(0); - Assertions.assertEquals(dialectProperties.toCase(tableName), table.getName(), "查询表结构失败"); - Assertions.assertEquals("测试表", table.getComment(), "查询表结构失败"); + Assertions.assertEquals(dialectProperties.toCase(tableName), table.getName(), "Query table structure failed"); + Assertions.assertEquals("Test table", table.getComment(), "Query table structure failed"); TableQueryParam tableQueryParam = new TableQueryParam(); tableQueryParam.setTableName(table.getName()); tableQueryParam.setDataSourceId(dataSourceId); tableQueryParam.setDatabaseName(dialectProperties.getDatabaseName()); List columnList = tableService.queryColumns(tableQueryParam); - Assertions.assertEquals(4L, columnList.size(), "查询表结构失败"); + Assertions.assertEquals(4L, columnList.size(), "Query table structure failed"); TableColumn id = columnList.get(0); - Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "查询表结构失败"); - Assertions.assertEquals("主键自增", id.getComment(), "查询表结构失败"); - Assertions.assertTrue(id.getAutoIncrement(), "查询表结构失败"); - //Assertions.assertFalse(id.getNullable(), "查询表结构失败"); - Assertions.assertTrue(id.getPrimaryKey(), "查询表结构失败"); + Assertions.assertEquals(dialectProperties.toCase("id"), id.getName(), "Query table structure failed"); + Assertions.assertEquals("Primary key auto-increment", id.getComment(), "Query table structure failed"); + Assertions.assertTrue(id.getAutoIncrement(), "Query table structure failed"); + //Assertions.assertFalse(id.getNullable(), "Query table structure failed"); + Assertions.assertTrue(id.getPrimaryKey(), "Query table structure failed"); TableColumn string = columnList.get(3); - Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "查询表结构失败"); - //Assertions.assertTrue(string.getNullable(), "查询表结构失败"); + Assertions.assertEquals(dialectProperties.toCase("string"), string.getName(), "Query table structure failed"); + //Assertions.assertTrue(string.getNullable(), "Query table structure failed"); Assertions.assertEquals("DATA", TestUtils.unWrapperDefaultValue(string.getDefaultValue()), - "查询表结构失败"); + "Query table structure failed"); List tableIndexList = tableService.queryIndexes(tableQueryParam); - Assertions.assertEquals(4L, tableIndexList.size(), "查询表结构失败"); + Assertions.assertEquals(4L, tableIndexList.size(), "Query table structure failed"); Map tableIndexMap = EasyCollectionUtils.toIdentityMap(tableIndexList, TableIndex::getName); TableIndex idxDate = tableIndexMap.get(dialectProperties.toCase(tableName + "_idx_date")); - Assertions.assertEquals("日期索引", idxDate.getComment(), "查询表结构失败"); - Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "查询表结构失败"); - Assertions.assertEquals(1L, idxDate.getColumnList().size(), "查询表结构失败"); + Assertions.assertEquals("date index", idxDate.getComment(), "Query table structure failed"); + Assertions.assertEquals(IndexTypeEnum.NORMAL.getCode(), idxDate.getType(), "Query table structure failed"); + Assertions.assertEquals(1L, idxDate.getColumnList().size(), "Query table structure failed"); Assertions.assertEquals(dialectProperties.toCase("date"), idxDate.getColumnList().get(0).getColumnName(), - "查询表结构失败"); + "Query table structure failed"); Assertions.assertEquals(CollationEnum.DESC.getCode(), idxDate.getColumnList().get(0).getCollation(), - "查询表结构失败"); + "Query table structure failed"); TableIndex ukNumber = tableIndexMap.get(dialectProperties.toCase(tableName + "_uk_number")); - Assertions.assertEquals("唯一索引", ukNumber.getComment(), "查询表结构失败"); - Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "查询表结构失败"); + Assertions.assertEquals("unique index", ukNumber.getComment(), "Query table structure failed"); + Assertions.assertEquals(IndexTypeEnum.UNIQUE.getCode(), ukNumber.getType(), "Query table structure failed"); TableIndex idxNumberString = tableIndexMap.get(dialectProperties.toCase(tableName + "_idx_number_string")); - Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "查询表结构失败"); + Assertions.assertEquals(2, idxNumberString.getColumnList().size(), "Query table structure failed"); } @Test @@ -478,21 +478,21 @@ public void dropTable() { dataSourceCreateParam.setPassword(dialectProperties.getPassword()); dataSourceService.preConnect(dataSourceCreateParam); - // 创建控制台 + // Create a console ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); consoleCreateParam.setDataSourceId(dataSourceId); consoleCreateParam.setConsoleId(consoleId); consoleCreateParam.setDatabaseName(dialectProperties.getDatabaseName()); consoleService.createConsole(consoleCreateParam); - // 创建表结构 + // Create table structure DlExecuteParam templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(consoleId); templateQueryParam.setDataSourceId(dataSourceId); templateQueryParam.setSql(dialectProperties.getDropTableSql(TABLE_NAME)); dlTemplateService.execute(templateQueryParam); } catch (Exception e) { - log.warn("删除表结构失败.", e); + log.warn("Failed to delete table structure.", e); } } } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/ClickHouseDialectProperties.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/ClickHouseDialectProperties.java index 6df6320b9..718d2aa4a 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/ClickHouseDialectProperties.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/ClickHouseDialectProperties.java @@ -49,17 +49,17 @@ public String getCrateTableSql(String tableName) { + " number int,\n" + " string varchar(100) default 'DATA'\n" + ");\n"; - sql += "comment on table " + tableName + " is '测试表';\n"; - sql += "comment on column " + tableName + ".id is '主键自增';\n"; - sql += "comment on column " + tableName + ".date is '日期';\n"; - sql += "comment on column " + tableName + ".number is '长整型';\n"; - sql += "comment on column " + tableName + ".string is '名字';\n"; + sql += "comment on table " + tableName + " is 'Test table';\n"; + sql += "comment on column " + tableName + ".id is 'Primary key auto-increment';\n"; + sql += "comment on column " + tableName + ".date is 'date';\n"; + sql += "comment on column " + tableName + ".number is 'long integer';\n"; + sql += "comment on column " + tableName + ".string is 'name';\n"; sql += "create index " + tableName + "idx_date on " + tableName + " (date desc);"; sql += "create unique index " + tableName + "_uk_number on " + tableName + " (number);"; sql += "create index " + tableName + "_idx_number_string on " + tableName + " (number, date);"; - sql += "comment on index " + tableName + "_uk_number is '日期索引';"; - sql += "comment on index " + tableName + "_uk_number is '唯一索引';"; - sql += "comment on index " + tableName + "_idx_number_string is '联合索引';"; + sql += "comment on index " + tableName + "_uk_number is 'date index';"; + sql += "comment on index " + tableName + "_uk_number is 'unique index';"; + sql += "comment on index " + tableName + "_idx_number_string is 'Union index';"; return sql; } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/DialectProperties.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/DialectProperties.java index 5132932a0..3486b7d86 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/DialectProperties.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/DialectProperties.java @@ -5,35 +5,35 @@ /** - * 方言配置 + * Dialect configuration * * @author Jiaju Zhuang */ public interface DialectProperties { /** - * 支持的数据库类型 + * Supported database types * * @return */ String getDbType(); /** - * 连接 + * connection * * @return */ String getUrl(); /** - * 异常连接 + * Abnormal connection * * @return */ String getErrorUrl(); /** - * 用户名 + * userName * * @return */ @@ -41,69 +41,69 @@ public interface DialectProperties { String getUsername(); /** - * 密码 + * password * * @return */ String getPassword(); /** - * 数据库名称 + * Name database * * @return */ String getDatabaseName(); /** - * 大小写看具体的数据库决定: - * 创建表表结构 : 测试表 - * 字段: - * id 主键自增 - * date 日期 非空 - * number 长整型 - * string 字符串 长度100 默认值 "DATA" + * The case depends on the specific database: + * Create table structure: test table + * Field: + * id primary key auto-increment + * date date is not empty + * number long integer type + * string string length 100 default value "DATA" * - * 索引(加上$tableName_ 原因是 有些数据库索引是全局唯一的): - * $tableName_idx_date 日期索引 倒序 - * $tableName_uk_number 唯一索引 - * $tableName_idx_number_string 联合索引 + * Index (plus $tableName_ because some database indexes are globally unique): + * $tableName_idx_date date index reverse order + * $tableName_uk_number unique index + * $tableName_idx_number_string joint index * * @return */ String getCrateTableSql(String tableName); /** - * 创建表表结构 + * Create table structure * * @return */ String getDropTableSql(String tableName); /** - * 创建一条数据 + * Create a piece of data * * @return */ String getInsertSql(String tableName, Date date, Long number, String string); /** - * 查询一条查询sql + * Query a query sql * * @return */ String getSelectSqlById(String tableName, Long id); /** - * 获取一条表结构不存在的sql + * Get a sql whose table structure does not exist * * @return */ String getTableNotFoundSqlById(String tableName); /** - * 转换大小写 - * 有些数据库表结构默认存储大写 - * 有些数据库默认存储小写 + * Convert case + * Some database table structures store uppercase letters by default + * Some databases store lowercase by default * * @param string * @return diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/H2DialectProperties.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/H2DialectProperties.java index 1890a2d05..5a8784b6b 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/H2DialectProperties.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/H2DialectProperties.java @@ -48,21 +48,21 @@ public String getDatabaseName() { @Override public String getCrateTableSql(String tableName) { - // TODO druid有sql解析的bug + // TODO druid has sql parsing bug String sql = "CREATE TABLE `" + tableName + "`\n\t" + "(\n\t" - + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t" - + " `date` datetime not null COMMENT '日期',\n\t" - + " `number` bigint COMMENT '长整型',\n\t" - + " `string` VARCHAR(100) default 'DATA' COMMENT '名字'\n\t" + + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t" + + " `date` datetime not null COMMENT 'date',\n\t" + + " `number` bigint COMMENT 'long integer',\n\t" + + " `string` VARCHAR(100) default 'DATA' COMMENT 'name'\n\t" + ");\n\t"; - sql += "comment on table " + tableName + " is '测试表';\n\t"; + sql += "comment on table " + tableName + " is 'Test table';\n\t"; sql += "create index " + tableName + "_idx_date on " + tableName + "(DATE desc);\n\t"; - sql += "comment on index " + tableName + "_idx_date is '日期索引';\n\t"; + sql += "comment on index " + tableName + "_idx_date is 'date index';\n\t"; sql += "create unique index " + tableName + "_uk_number on " + tableName + "(NUMBER);\n\t"; - sql += "comment on index " + tableName + "_uk_number is '唯一索引';\n\t"; + sql += "comment on index " + tableName + "_uk_number is 'unique index';\n\t"; sql += "create index " + tableName + "_idx_number_string on " + tableName + "(NUMBER, DATE);\n\t"; - sql += "comment on index " + tableName + "_idx_number_string is '联合索引';\n\t"; + sql += "comment on index " + tableName + "_idx_number_string is 'Union index';\n\t"; return sql; } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/MysqlDialectProperties.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/MysqlDialectProperties.java index 6100410af..b72af4da4 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/MysqlDialectProperties.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/MysqlDialectProperties.java @@ -50,14 +50,14 @@ public String getDatabaseName() { public String getCrateTableSql(String tableName) { return "CREATE TABLE `" + tableName + "`\n\t" + "(\n\t" - + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t" - + " `date` datetime(3) not null COMMENT '日期',\n\t" - + " `number` bigint COMMENT '长整型',\n\t" - + " `string` VARCHAR(100) default 'DATA' COMMENT '名字',\n\t" - + " index " + tableName + "_idx_date (date desc) comment '日期索引',\n\t" - + " unique " + tableName + "_uk_number (number) comment '唯一索引',\n\t" - + " index " + tableName + "_idx_number_string (number, date) comment '联合索引'\n\t" - + ") COMMENT ='测试表';"; + + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t" + + " `date` datetime(3) not null COMMENT 'date',\n\t" + + " `number` bigint COMMENT 'long integer',\n\t" + + " `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n\t" + + " index " + tableName + "_idx_date (date desc) comment 'date index',\n\t" + + " unique " + tableName + "_uk_number (number) comment 'unique index',\n\t" + + " index " + tableName + "_idx_number_string (number, date) comment 'Union index'\n\t" + + ") COMMENT ='Test table';"; } @Override diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/OracleDialectProperties.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/OracleDialectProperties.java index aa43cc3f6..873fc149c 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/OracleDialectProperties.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/OracleDialectProperties.java @@ -43,14 +43,14 @@ public String getDatabaseName() { public String getCrateTableSql(String tableName) { return "CREATE TABLE `" + tableName + "`\n\t" + "(\n\t" - + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t" - + " `date` datetime(3) not null COMMENT '日期',\n\t" - + " `number` bigint COMMENT '长整型',\n\t" - + " `string` VARCHAR(100) default 'DATA' COMMENT '名字',\n\t" - + " index " + tableName + "_idx_date (date desc) comment '日期索引',\n\t" - + " unique " + tableName + "_uk_number (number) comment '唯一索引',\n\t" - + " index " + tableName + "_idx_number_string (number, date) comment '联合索引'\n\t" - + ") COMMENT ='测试表';"; + + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t" + + " `date` datetime(3) not null COMMENT 'date',\n\t" + + " `number` bigint COMMENT 'long integer',\n\t" + + " `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n\t" + + " index " + tableName + "_idx_date (date desc) comment 'date index',\n\t" + + " unique " + tableName + "_uk_number (number) comment 'unique index',\n\t" + + " index " + tableName + "_idx_number_string (number, date) comment 'Union index'\n\t" + + ") COMMENT ='Test table';"; } @Override diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/PostgresqlDialectProperties.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/PostgresqlDialectProperties.java index d03653b7c..95fdd17b1 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/PostgresqlDialectProperties.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/PostgresqlDialectProperties.java @@ -14,7 +14,7 @@ /** * @author jipengfei - * @version : PgDialectProperties.java, v 0.1 2022年12月13日 21:48 jipengfei Exp $ + * @version : PgDialectProperties.java, v 0.1 December 13, 2022 21:48 jipengfei Exp $ */ @Component public class PostgresqlDialectProperties implements DialectProperties { @@ -59,17 +59,17 @@ public String getCrateTableSql(String tableName) { + " number int,\n" + " string varchar(100) default 'DATA'\n" + ");\n"; - sql += "comment on table " + tableName + " is '测试表';\n"; - sql += "comment on column " + tableName + ".id is '主键自增';\n"; - sql += "comment on column " + tableName + ".date is '日期';\n"; - sql += "comment on column " + tableName + ".number is '长整型';\n"; - sql += "comment on column " + tableName + ".string is '名字';\n"; + sql += "comment on table " + tableName + " is 'Test table';\n"; + sql += "comment on column " + tableName + ".id is 'Primary key auto-increment';\n"; + sql += "comment on column " + tableName + ".date is 'date';\n"; + sql += "comment on column " + tableName + ".number is 'long integer';\n"; + sql += "comment on column " + tableName + ".string is 'name';\n"; sql += "create index " + tableName + "idx_date on " + tableName + " (date desc);"; sql += "create unique index " + tableName + "_uk_number on " + tableName + " (number);"; sql += "create index " + tableName + "_idx_number_string on " + tableName + " (number, date);"; - sql += "comment on index " + tableName + "_uk_number is '日期索引';"; - sql += "comment on index " + tableName + "_uk_number is '唯一索引';"; - sql += "comment on index " + tableName + "_idx_number_string is '联合索引';"; + sql += "comment on index " + tableName + "_uk_number is 'date index';"; + sql += "comment on index " + tableName + "_uk_number is 'unique index';"; + sql += "comment on index " + tableName + "_idx_number_string is 'Union index';"; return sql; } diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/SQLITEDialectProperties.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/SQLITEDialectProperties.java index 56abb6c8b..f72d2fb64 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/SQLITEDialectProperties.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/service/dialect/SQLITEDialectProperties.java @@ -48,14 +48,14 @@ public String getDatabaseName() { public String getCrateTableSql(String tableName) { return "CREATE TABLE `" + tableName + "`\n\t" + "(\n\t" - + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '主键自增',\n\t" - + " `date` datetime(3) not null COMMENT '日期',\n\t" - + " `number` bigint COMMENT '长整型',\n\t" - + " `string` VARCHAR(100) default 'DATA' COMMENT '名字',\n\t" - + " index " + tableName + "_idx_date (date desc) comment '日期索引',\n\t" - + " unique " + tableName + "_uk_number (number) comment '唯一索引',\n\t" - + " index " + tableName + "_idx_number_string (number, date) comment '联合索引'\n\t" - + ") COMMENT ='测试表';"; + + " `id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'Primary key auto-increment',\n\t" + + " `date` datetime(3) not null COMMENT 'date',\n\t" + + " `number` bigint COMMENT 'long integer',\n\t" + + " `string` VARCHAR(100) default 'DATA' COMMENT 'name',\n\t" + + " index " + tableName + "_idx_date (date desc) comment 'date index',\n\t" + + " unique " + tableName + "_uk_number (number) comment 'unique index',\n\t" + + " index " + tableName + "_idx_number_string (number, date) comment 'Union index'\n\t" + + ") COMMENT ='Test table';"; } @Override diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/utils/TestUtils.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/utils/TestUtils.java index c8ef23a08..1029d3e97 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/utils/TestUtils.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/domain/data/utils/TestUtils.java @@ -7,7 +7,7 @@ import ai.chat2db.spi.sql.ConnectInfo; /** - * 测试工具类 + * Test tool class * * @author Jiaju Zhuang */ @@ -16,7 +16,7 @@ public class TestUtils { public static final AtomicLong ATOMIC_LONG = new AtomicLong(); /** - * 一个全局唯一的long + * a globally unique long * * @return */ @@ -25,8 +25,8 @@ public static long nextLong() { } /** - * 如果默认值类似于 'DATA' - * 则需要把'' 去掉 + * If the default value is something like 'DATA' + * then you need to remove '' * * @param defaultValue * @return diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SQLParseTest.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SQLParseTest.java index 590fcdc80..15c299d32 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SQLParseTest.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SQLParseTest.java @@ -22,12 +22,12 @@ public static void main(String[] args) throws JSQLParserException { Statements statements = CCJSqlParserUtil.parseStatements(sql); - // 如果是多条语句,解析后的实际类型是StatementList + // If there are multiple statements, the actual type after parsing is StatementList - // 遍历每个语句 + // Iterate through each statement for (Statement stmt : statements.getStatements()) { - // 如果是单条语句,实际类型是Statement + // If it is a single statement, the actual type is Statement System.out.println(stmt.toString()); System.out.println(" dddd:"+SqlFormatter.format(stmt.toString())); diff --git a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SqlTeset.java b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SqlTeset.java index 86c5292eb..a58479481 100644 --- a/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SqlTeset.java +++ b/chat2db-server/chat2db-server-test/src/test/java/ai/chat2db/server/test/temp/SqlTeset.java @@ -41,7 +41,7 @@ public class SqlTeset extends BaseTest { @Test public void test() { - // 创建 + // creat DataSourcePreConnectParam dataSourceCreateParam = new DataSourcePreConnectParam(); dataSourceCreateParam.setType("MYSQL"); @@ -58,14 +58,14 @@ public void test() { List sqlList = new ArrayList<>(); sqlList.add(Sql.builder().sql(createTable.getData()).build()); - // 创建控制台 + // Create a console ConsoleConnectParam consoleCreateParam = new ConsoleConnectParam(); consoleCreateParam.setDataSourceId(1L); consoleCreateParam.setConsoleId(1L); consoleCreateParam.setDatabaseName(mysqlDialectProperties.getDatabaseName()); consoleService.createConsole(consoleCreateParam); - // 删除 + // delete DlExecuteParam templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(1L); templateQueryParam.setDataSourceId(1L); @@ -73,7 +73,7 @@ public void test() { ListResult executeResult = dlTemplateService.execute(templateQueryParam); log.info("result:{}", JSON.toJSONString(executeResult)); - // 创建表结构 + // Create table structure templateQueryParam = new DlExecuteParam(); templateQueryParam.setConsoleId(1L); templateQueryParam.setDataSourceId(1L); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/EasyToolsConstant.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/EasyToolsConstant.java index 4b0dece41..5e822eb47 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/EasyToolsConstant.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/EasyToolsConstant.java @@ -1,29 +1,29 @@ package ai.chat2db.server.tools.base.constant; /** - * 常量 + * constant * - * @author 是仪 + * @author Shi Yi */ public interface EasyToolsConstant { /** - * 日志的追踪id + * Log tracking id */ String LOG_TRACE_ID = "EAGLEEYE_TRACE_ID"; /** - * 最大分页大小 + * Maximum paging size */ int MAX_PAGE_SIZE = 1000; /** - * 序列化id + * serializedid */ long SERIAL_VERSION_UID = 1L; /** - * 最大循环次数 防止很多循环进入死循环 + * Maximum number of loops to prevent many loops from entering an infinite loop */ int MAXIMUM_ITERATIONS = 10 * 1000; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/SymbolConstant.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/SymbolConstant.java index 480567fc1..eb03bed26 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/SymbolConstant.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/constant/SymbolConstant.java @@ -1,9 +1,9 @@ package ai.chat2db.server.tools.base.constant; /** - * 常见符号的常量枚举 + * Constant enumeration of common symbols * - * @author 是仪 + * @author Shi Yi **/ public class SymbolConstant { /** @@ -23,35 +23,35 @@ public class SymbolConstant { */ public static final String SLASH = "/"; /** - * 单引号"'" + * apostrophe"'" */ public static final String SQUOT = "'"; /** - * 空串 "" + * empty string "" */ public static final String EMPTY = ""; /** - * 分隔符 "-" + * delimiter "-" */ public static final String SEPARATOR = "-"; /** - * 等号 "=" + * equal sign "=" */ public static final String EQ = "="; /** - * 分号 ";" + * semicolon ";" */ public static final String SEMICOLON = ";"; /** - * 逗号 "," + * comma "," */ public static final String COMMA = ","; /** - * 点 "." + * point "." */ public static final String DOT = "."; /** - * 冒号 ":" + * colon ":" */ public static final String COLON = ":"; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/BaseEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/BaseEnum.java index 6395c2e20..a85ca1dd1 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/BaseEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/BaseEnum.java @@ -1,23 +1,26 @@ package ai.chat2db.server.tools.base.enums; /** - * 基础的枚举 + * Basic enumeration * - * 由于java枚举继承的限制,枚举基类只能设计为接口,请自行保证子类一定是枚举类型。 + * Due to the limitations of Java enumeration inheritance, the enumeration base class can only be designed as an interface. + * Please ensure that the subclass must be an enumeration type. * * @author Jiaju Zhuang **/ public interface BaseEnum { /** - * 返回枚举的code。一般建议直接返回枚举的name + * Returns the enumeration code. + * It is generally recommended to directly return the name of the enumeration * * @return code */ T getCode(); /** - * 返回枚举的描述。返回枚举的中文 方便前端下拉 + * Returns the description of the enumeration. + * Return the enumerated Chinese to facilitate front-end drop-down * * @return description */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DataSourceTypeEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DataSourceTypeEnum.java index 7a9cbcc64..9bfb5af29 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DataSourceTypeEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DataSourceTypeEnum.java @@ -4,27 +4,31 @@ /** * @author moji - * @version ConnectionTypeEnum.java, v 0.1 2022年09月16日 14:59 moji Exp $ + * @version ConnectionTypeEnum.java, v 0.1 September 16, 2022 14:59 moji Exp $ * @date 2022/09/16 */ @Getter public enum DataSourceTypeEnum implements BaseEnum { /** - * mysql数据库连接 + * mysql database connection */ - MYSQL("mysql数据库连接"), + MYSQL("mysql database connection"), /** - * redis数据库连接 + * redis database connection */ - REDIS("redis数据库连接"), + REDIS("redis database connection"), + /** + * sqlserver database connection + */ + SQLSERVER("sqlserver database connection"), /** - * mongo数据库连接 + * mongo database connection */ - MONGODB("mongo数据库连接"), + MONGODB("mongo database connection"), ; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DeletedIdEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DeletedIdEnum.java index fc181e07d..cc5febeda 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DeletedIdEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/DeletedIdEnum.java @@ -3,20 +3,23 @@ import lombok.Getter; /** - * 删除标记枚举 + * Delete mark enumeration *

- * 为了兼容唯一主键+逻辑删除。使用DeletedId来标记当前数据是否删除。如果是0 则代表未删除。其他任何情况都代表已经删除。 - * 删除的时候 执行语句:update set deleted_id = di where 条件=条件; + * In order to be compatible with unique primary key + tombstone. + * Use DeletedId to mark whether the current data is deleted. + * If it is 0, it means it has not been deleted. + * Anything else means it has been deleted. + * When deleting, execute the statement: update set deleted_id = di where condition = condition; * - * @author 是仪 + * @author Shi Yi */ @Getter public enum DeletedIdEnum implements BaseEnum { /** - * 未删除 + * Not deleted */ - NOT_DELETED(0L, "未删除"), + NOT_DELETED(0L, "Not deleted"), ; @@ -29,10 +32,10 @@ public enum DeletedIdEnum implements BaseEnum { } /** - * 判断 当前数据是否已经逻辑删除 + * Determine whether the current data has been logically deleted * - * @param deletedId 表中的deleted_id - * @return 是否已经删除 + * @param deletedId deleted_id in table + * @return Has it been deleted? */ public static boolean isDeleted(Long deletedId) { return !NOT_DELETED.getCode().equals(deletedId); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OperationEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OperationEnum.java index 48d403f87..0ea0586bb 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OperationEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OperationEnum.java @@ -3,26 +3,26 @@ import lombok.Getter; /** - * 操作枚举 + * Operation enumeration * - * @author 是仪 + * @author Shi Yi */ @Getter public enum OperationEnum implements BaseEnum { /** - * 新增 + * creat */ - CREATE("新增"), + CREATE("creat"), /** - * 修改 + * update */ - UPDATE("修改"), + UPDATE("update"), /** - * 删除 + * delete */ - DELETE("删除"), + DELETE("delete"), ; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OrderByDirectionEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OrderByDirectionEnum.java index 216f893ee..da90e3755 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OrderByDirectionEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/OrderByDirectionEnum.java @@ -1,18 +1,18 @@ package ai.chat2db.server.tools.base.enums; /** - * 排序方向的枚举 + * Enumeration of sorting directions * - * @author 是仪 + * @author Shi Yi */ public enum OrderByDirectionEnum implements BaseEnum { /** - * 升序 + * asc */ ASC, /** - * 降序 + * desc */ DESC; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/StatusEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/StatusEnum.java index 6d37aedb3..ae73be5a2 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/StatusEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/StatusEnum.java @@ -4,21 +4,21 @@ /** * @author moji - * @version StatusEnum.java, v 0.1 2022年09月25日 16:57 moji Exp $ + * @version StatusEnum.java, v 0.1 September 25, 2022 16:57 moji Exp $ * @date 2022/09/25 */ @Getter public enum StatusEnum implements BaseEnum { /** - * 草稿 + * draft */ - DRAFT("草稿"), + DRAFT("draft"), /** - * 发布 + * release */ - RELEASE("发布"), + RELEASE("release"), ; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/SystemEnvironmentEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/SystemEnvironmentEnum.java index 8fd4adb78..9dbae2f0d 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/SystemEnvironmentEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/SystemEnvironmentEnum.java @@ -3,7 +3,7 @@ import lombok.Getter; /** - * 系统环境 + * System environment * * @author Jiaju Zhuang */ @@ -11,17 +11,17 @@ public enum SystemEnvironmentEnum implements BaseEnum { /** - * 本地 + * dev */ DEV("dev", "本地"), /** - * 测试 + * test */ TEST("test", "测试"), /** - * 正式 + * release */ RELEASE("release", "正式"), diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/WhiteListTypeEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/WhiteListTypeEnum.java index 4290040a2..fdfdb41f4 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/WhiteListTypeEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/WhiteListTypeEnum.java @@ -4,14 +4,14 @@ /** * @author moji - * @version WhiteListTypeEnum.java, v 0.1 2022年09月25日 16:57 moji Exp $ + * @version WhiteListTypeEnum.java, v 0.1 September 25, 2022 16:57 moji Exp $ * @date 2022/09/25 */ @Getter public enum WhiteListTypeEnum implements BaseEnum { /** - * 向量接口 + * vector interface */ VECTOR("VECTOR"), diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/YesOrNoEnum.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/YesOrNoEnum.java index 22b37f474..1a82a81ba 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/YesOrNoEnum.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/enums/YesOrNoEnum.java @@ -3,19 +3,19 @@ import lombok.Getter; /** - * 是否枚举 + * Whether to enumerate * - * @author 是仪 + * @author Shi Yi */ @Getter public enum YesOrNoEnum implements BaseEnum { /** - * 是 + * yes */ YES("Y", "是", true), /** - * 未读 + * no */ NO("N", "否", false), @@ -37,9 +37,9 @@ public String getCode() { } /** - * 根据布尔值转换 + * Convert based on boolean value * - * @param booleanValue 布尔值 + * @param booleanValue Boolean value * @return */ public static YesOrNoEnum valueOf(Boolean booleanValue) { diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/BusinessException.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/BusinessException.java index a98cda118..13b834c55 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/BusinessException.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/BusinessException.java @@ -3,7 +3,8 @@ import lombok.Data; /** - * 业务异常。不需要人工介入的叫做业务异常。 + * Business abnormality. + * Those that do not require manual intervention are called business exceptions. * * @author zhuangjiaju * @date 2021/06/26 diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/SystemException.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/SystemException.java index 0faf46553..22195b88d 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/SystemException.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/excption/SystemException.java @@ -3,7 +3,8 @@ import lombok.Data; /** - * 业务异常。简单的说就是需要人工介入的异常叫做系统异常。 + * Business abnormality. + * Simply put, exceptions that require manual intervention are called system exceptions. * * @author zhuangjiaju * @date 2021/06/26 diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/handler/EasyCallBackHandler.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/handler/EasyCallBackHandler.java index 6eedcec6d..d2383de5f 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/handler/EasyCallBackHandler.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/handler/EasyCallBackHandler.java @@ -1,28 +1,28 @@ package ai.chat2db.server.tools.base.handler; /** - * 回调的处理器 - * 比如meatq回调的时候 会执行这个方法 + * Callback handler + * For example, this method will be executed when meatq calls back. * - * @author 是仪 + * @author Shi Yi */ public interface EasyCallBackHandler { /** - * 在处理回调前调用 + * Called before handling the callback */ default void preHandle() { } /** - * 在处理回调后调用 - * 抛出异常了不会处理 + * Called after handling the callback + * If an exception is thrown, it will not be handled. */ default void postHandle() { } /** - * 在处理回调后调用 - * 无论是否异常 都会调用 + * Called after handling the callback + * Will be called regardless of whether there is an exception or not */ default void afterCompletion() { } diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Result.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Result.java index e63227020..29f255868 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Result.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Result.java @@ -6,7 +6,7 @@ */ public interface Result extends Traceable{ /** - * 是否成功 + * whether succeed * * @return * @mock true @@ -14,14 +14,14 @@ public interface Result extends Traceable{ boolean success(); /** - * 设置是否成功 + * Is the setting successful? * * @return */ void success(boolean success); /** - * 错误编码 + * error coding * * @return * @mock 000000 @@ -29,14 +29,14 @@ public interface Result extends Traceable{ String errorCode(); /** - * 设置错误编码 + * Set error encoding * * @param errorCode */ void errorCode(String errorCode); /** - * 错误信息 + * error message * * @return */ @@ -44,7 +44,7 @@ public interface Result extends Traceable{ /** - * 设置错误信息 + * Set error message * * @param errorMessage */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Traceable.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Traceable.java index cb7b97694..d52f97e7d 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Traceable.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/Traceable.java @@ -1,20 +1,20 @@ package ai.chat2db.server.tools.base.wrapper; /** - * 是否可以跟踪 + * Is it possible to track * - * @author 是仪 + * @author Shi Yi */ public interface Traceable { /** - * 获取 traceId + * Get traceId * * @return traceId */ String getTraceId(); /** - * 设置traceId + * Set traceId * * @param traceId */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderBy.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderBy.java index ebfe07d9e..039984196 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderBy.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderBy.java @@ -10,9 +10,9 @@ import lombok.NoArgsConstructor; /** - * 排序的对象 + * sorted objects * - * @author 是仪 + * @author Shi Yi */ @Data @Builder @@ -20,11 +20,11 @@ @AllArgsConstructor public class OrderBy implements Serializable { /** - * 排序字段 + * sort field */ private String orderConditionName; /** - * 排序方向 + * Sorting direction */ private OrderByDirectionEnum direction; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderCondition.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderCondition.java index 78c9e7230..28be121bf 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderCondition.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/OrderCondition.java @@ -1,14 +1,14 @@ package ai.chat2db.server.tools.base.wrapper.param; /** - * 排序条件 + * Sorting conditions * - * @author 是仪 + * @author Shi Yi */ public interface OrderCondition { /** - * 返回列的名字 + * Return column name * * @return */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/PageQueryParam.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/PageQueryParam.java index 762af5e97..dd2a4ec47 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/PageQueryParam.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/PageQueryParam.java @@ -16,7 +16,7 @@ import org.hibernate.validator.constraints.Range; /** - * 分页查询的参数 + * Parameters of paging query * * @author zhuangjiaju * @date 2021/06/26 @@ -29,27 +29,27 @@ public class PageQueryParam implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 页码 + * page number */ - @NotNull(message = "分页页码不能为空") - @Min(value = 1, message = "分页页码必须大于0") + @NotNull(message = "Pagination page number cannot be empty") + @Min(value = 1, message = "Pagination page number must be greater than 0") private Integer pageNo; /** - * 分页大小 + * Paging Size */ - @NotNull(message = "分页大小不能为空") + @NotNull(message = "Paging size cannot be empty") @Range(min = 1, max = EasyToolsConstant.MAX_PAGE_SIZE, - message = "分页大小必须在1-" + EasyToolsConstant.MAX_PAGE_SIZE + "之间") + message = "Paging size must be between 1-" + EasyToolsConstant.MAX_PAGE_SIZE) private Integer pageSize; /** - * 是否返回总条数 - * 默认不返回 提高性能 + * Whether to return the total number of items + * Not returned by default to improve performance */ private Boolean enableReturnCount; /** - * 排序 + * sort */ private List orderByList; @@ -60,7 +60,7 @@ public PageQueryParam() { } /** - * 查询全部数据 + * Query all data */ public void queryAll() { this.pageNo = 1; @@ -68,7 +68,7 @@ public void queryAll() { } /** - * 查询1条加速 + * Query 1 piece of data */ public void queryOne() { this.pageNo = 1; @@ -76,10 +76,10 @@ public void queryOne() { } /** - * 新增一个排序 并替换原有排序 + * Add a new sort and replace the original sort * - * @param orderBy 排序 - * @return 排序参数 + * @param orderBy sort + * @return Sorting parameters */ public PageQueryParam orderBy(OrderBy orderBy) { orderByList = new ArrayList<>(); @@ -88,31 +88,31 @@ public PageQueryParam orderBy(OrderBy orderBy) { } /** - * 新增一个排序 并替换原有排序 + * Add a new sort and replace the original sort * - * @param orderConditionName 排序字段 - * @param direction 排序方向 - * @return 排序参数 + * @param orderConditionName sort field + * @param direction Sorting direction + * @return Sorting parameters */ public PageQueryParam orderBy(String orderConditionName, OrderByDirectionEnum direction) { return orderBy(new OrderBy(orderConditionName, direction)); } /** - * 新增一个排序 并替换原有排序 + * Add a new sort and replace the original sort * - * @param orderCondition 排序条件 - * @return 排序参数 + * @param orderCondition Sorting conditions + * @return Sorting parameters */ public PageQueryParam orderBy(OrderCondition orderCondition) { return orderBy(orderCondition.getOrderBy()); } /** - * 新增一个排序 + * Add a new sort * - * @param orderBy 排序 - * @return 排序参数 + * @param orderBy sort + * @return Sorting parameters */ public PageQueryParam andOrderBy(OrderBy orderBy) { orderByList.add(orderBy); @@ -120,21 +120,21 @@ public PageQueryParam andOrderBy(OrderBy orderBy) { } /** - * 新增一个排序 + * Add a new sort * - * @param orderConditionName 排序字段 - * @param direction 排序方向 - * @return 排序参数 + * @param orderConditionName sort field + * @param direction Sorting direction + * @return Sorting parameters */ public PageQueryParam andOrderBy(String orderConditionName, OrderByDirectionEnum direction) { return andOrderBy(new OrderBy(orderConditionName, direction)); } /** - * 新增一个排序 + * Add a new sort * - * @param orderCondition 排序条件 - * @return 排序参数 + * @param orderCondition Sorting conditions + * @return Sorting parameters */ public PageQueryParam andOrderBy(OrderCondition orderCondition) { return andOrderBy(orderCondition.getOrderBy()); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/QueryParam.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/QueryParam.java index bffb6edb2..d66dc8eb3 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/QueryParam.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/param/QueryParam.java @@ -14,7 +14,7 @@ import lombok.experimental.SuperBuilder; /** - * 查询的参数 + * query parameters * * @author zhuangjiaju * @date 2021/06/26 @@ -28,15 +28,15 @@ public class QueryParam implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 排序 + * sort */ private List orderByList; /** - * 新增一个排序 并替换原有排序 + * Add a new sort and replace the original sort * - * @param orderBy 排序 - * @return 排序参数 + * @param orderBy sort + * @return Sorting parameters */ public QueryParam orderBy(OrderBy orderBy) { orderByList = new ArrayList<>(); @@ -45,31 +45,31 @@ public QueryParam orderBy(OrderBy orderBy) { } /** - * 新增一个排序 并替换原有排序 + * Add a new sort and replace the original sort * - * @param orderConditionName 排序字段 - * @param direction 排序方向 - * @return 排序参数 + * @param orderConditionName sort field + * @param direction Sorting direction + * @return Sorting parameters */ public QueryParam orderBy(String orderConditionName, OrderByDirectionEnum direction) { return orderBy(new OrderBy(orderConditionName, direction)); } /** - * 新增一个排序 并替换原有排序 + * Add a new sort and replace the original sort * - * @param orderCondition 排序条件 - * @return 排序参数 + * @param orderCondition Sorting conditions + * @return Sorting parameters */ public QueryParam orderBy(OrderCondition orderCondition) { return orderBy(orderCondition.getOrderBy()); } /** - * 新增一个排序 + * Add a new sort * - * @param orderBy 排序 - * @return 排序参数 + * @param orderBy sort + * @return Sorting parameters */ public QueryParam andOrderBy(OrderBy orderBy) { orderByList.add(orderBy); @@ -77,21 +77,21 @@ public QueryParam andOrderBy(OrderBy orderBy) { } /** - * 新增一个排序 + * Add a new sort * - * @param orderConditionName 排序字段 - * @param direction 排序方向 - * @return 排序参数 + * @param orderConditionName sort field + * @param direction Sorting direction + * @return Sorting parameters */ public QueryParam andOrderBy(String orderConditionName, OrderByDirectionEnum direction) { return andOrderBy(new OrderBy(orderConditionName, direction)); } /** - * 新增一个排序 + * Add a new sort * - * @param orderCondition 排序条件 - * @return 排序参数 + * @param orderCondition Sorting conditions + * @return Sorting parameters */ public QueryParam andOrderBy(OrderCondition orderCondition) { return andOrderBy(orderCondition.getOrderBy()); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/request/PageQueryRequest.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/request/PageQueryRequest.java index 7bf1ccbfb..37af7b428 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/request/PageQueryRequest.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/request/PageQueryRequest.java @@ -12,7 +12,7 @@ import org.hibernate.validator.constraints.Range; /** - * 分页查询的参数 + * Parameters of paging query * * @author zhuangjiaju * @date 2021/06/26 @@ -24,20 +24,20 @@ public class PageQueryRequest implements Serializable { @Serial private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 页码 + * page number * * @mock 1 */ - @NotNull(message = "分页页码不能为空") + @NotNull(message = "Pagination page number cannot be empty") private Integer pageNo; /** - * 分页条数 + * Number of pagination items * * @demo 10 */ - @NotNull(message = "分页大小不能为空") + @NotNull(message = "Paging size cannot be empty") @Range(min = 1, max = EasyToolsConstant.MAX_PAGE_SIZE, - message = "分页大小必须在1-" + EasyToolsConstant.MAX_PAGE_SIZE + "之间") + message = "Paging size must be between 1-" + EasyToolsConstant.MAX_PAGE_SIZE) private Integer pageSize; public PageQueryRequest() { diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ActionResult.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ActionResult.java index 1dae8adc0..838ec6873 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ActionResult.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ActionResult.java @@ -10,9 +10,9 @@ import lombok.experimental.SuperBuilder; /** - * action的返回对象 + * action return object * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -21,20 +21,20 @@ public class ActionResult implements Serializable, Result { @Serial private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 是否成功 + * whether succeed * * @mock true */ private Boolean success; /** - * 错误编码 + * error coding * * @see CommonErrorEnum */ private String errorCode; /** - * 错误信息 + * error message */ private String errorMessage; @@ -58,9 +58,9 @@ public ActionResult() { } /** - * 返回成功 + * Return success * - * @return 运行结果 + * @return operation result */ public static ActionResult isSuccess() { return new ActionResult(); @@ -117,12 +117,12 @@ public String solutionLink() { } /** - * 返回失败 + * Return failure * * @param errorCode error code * @param errorMessage error message * @param errorDetail error detail - * @return 运行结果 + * @return operation result */ public static ActionResult fail(String errorCode, String errorMessage, String errorDetail) { ActionResult result = new ActionResult(); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/DataResult.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/DataResult.java index 12def153b..0e65c59ef 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/DataResult.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/DataResult.java @@ -10,9 +10,9 @@ import lombok.experimental.SuperBuilder; /** - * data的返回对象 + * data return object * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -20,21 +20,21 @@ public class DataResult implements Serializable, Result { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 是否成功 + * whether succeed * * @mock true */ private Boolean success; /** - * 错误编码 + * error coding * * @see CommonErrorEnum */ private String errorCode; /** - * 错误信息 + * error message */ private String errorMessage; @@ -49,7 +49,7 @@ public class DataResult implements Serializable, Result { private String solutionLink; /** - * 数据信息 + * Data information */ private T data; @@ -68,33 +68,33 @@ private DataResult(T data) { } /** - * 构建返回对象 + * Construct the return object * - * @param data 需要构建的对象 - * @param 需要构建的对象类型 - * @return 返回的结果 + * @param data object to be constructed + * @param The object type to be constructed + * @return the returned result */ public static DataResult of(T data) { return new DataResult<>(data); } /** - * 构建空的返回对象 + * Construct an empty return object * - * @param 需要构建的对象类型 - * @return 返回的结果 + * @param The object type to be constructed + * @return the returned result */ public static DataResult empty() { return new DataResult<>(); } /** - * 构建异常返回 + * Build exception return * - * @param errorCode 错误编码 - * @param errorMessage 错误信息 - * @param 需要构建的对象类型 - * @return 返回的结果 + * @param errorCode error coding + * @param errorMessage error message + * @param The object type to be constructed + * @return the returned result */ public static DataResult error(String errorCode, String errorMessage) { DataResult result = new DataResult<>(); @@ -106,21 +106,21 @@ public static DataResult error(String errorCode, String errorMessage) { /** - * 判断是否存在数据 + * Determine whether data exists * * @param dataResult - * @return 是否存在数据 + * @return whether data exists */ public static boolean hasData(DataResult dataResult) { return dataResult != null && dataResult.getSuccess() && dataResult.getData() != null; } /** - * 将当前的类型转换成另外一个类型 + * Convert the current type to another type * - * @param mapper 转换的方法 - * @param 返回的类型 - * @return 返回的结果 + * @param mapper conversion method + * @param Return type + * @return the returned result */ public DataResult map(Function mapper) { R returnData = hasData(this) ? mapper.apply(getData()) : null; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ListResult.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ListResult.java index ae8ca36a7..bd3c5db75 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ListResult.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/ListResult.java @@ -16,9 +16,9 @@ import lombok.experimental.SuperBuilder; /** - * data的返回对象 + * data return object * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -27,22 +27,22 @@ public class ListResult implements Serializable, Result { @Serial private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 是否成功 + * whether succeed * * @mock true */ private Boolean success; /** - * 错误编码 + * error coding */ private String errorCode; /** - * 异常信息 + * Exception information */ private String errorMessage; /** - * 数据信息 + * Data information */ private List data; /** @@ -70,33 +70,33 @@ private ListResult(List data) { } /** - * 构建列表返回对象 + * Build the list and return the object * - * @param data 需要构建的对象 - * @param 需要构建的对象类型 - * @return 返回的列表 + * @param data object to be constructed + * @param The object type to be constructed + * @return the returned list */ public static ListResult of(List data) { return new ListResult<>(data); } /** - * 构建空的列表返回对象 + * Build an empty list and return the object * - * @param 需要构建的对象类型 - * @return 返回的列表 + * @param The type of object to be constructed + * @return the returned list */ public static ListResult empty() { return of(Collections.emptyList()); } /** - * 构建异常返回列表 + * Build exception return list * - * @param errorCode 错误编码 - * @param errorMessage 错误信息 - * @param 需要构建的对象类型 - * @return 返回的列表 + * @param errorCode error coding + * @param errorMessage error message + * @param The object type to be constructed + * @return the returned list */ public static ListResult error(String errorCode, String errorMessage) { ListResult result = new ListResult<>(); @@ -107,10 +107,10 @@ public static ListResult error(String errorCode, String errorMessage) { } /** - * 判断是否存在数据 + * Determine whether data exists * * @param listResult - * @return 是否存在数据 + * @return whether data exists */ public static boolean hasData(ListResult listResult) { return listResult != null && listResult.getSuccess() && listResult.getData() != null && !listResult.getData() @@ -118,11 +118,11 @@ public static boolean hasData(ListResult listResult) { } /** - * 将当前的类型转换成另外一个类型 + * Convert the current type to another type * - * @param mapper 转换的方法 - * @param 返回的类型 - * @return 分页返回对象 + * @param mapper conversion method + * @param Return type + * @return paging return object */ public ListResult map(Function mapper) { List returnData = hasData(this) ? getData().stream().map(mapper).collect(Collectors.toList()) diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/PageResult.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/PageResult.java index 1e377cb33..f7c201e91 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/PageResult.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/PageResult.java @@ -16,9 +16,9 @@ import lombok.experimental.SuperBuilder; /** - * data的返回对象 + * data return object * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -26,34 +26,34 @@ public class PageResult implements Serializable, Result> { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 是否成功 + * whether succeed * * @mock true */ private Boolean success; /** - * 错误编码 + * error coding */ private String errorCode; /** - * 异常信息 + * Exception information */ private String errorMessage; /** - * 数据信息 + * Data information */ private List data; /** - * 分页编码 + * Page coding */ private Integer pageNo; /** - * 分页大小 + * Paging Size */ private Integer pageSize; /** - * 总的大小 + * Total */ private Long total; /** @@ -61,7 +61,7 @@ public class PageResult implements Serializable, Result> { */ private String traceId; /** - * 是否存在下一页 + * Is there a next page? */ private Boolean hasNextPage; @@ -107,108 +107,108 @@ private PageResult(List data, Long total, Integer pageNo, Integer pageSize) { } /** - * 构建分页返回对象 + * Construct paging return object * - * @param data 返回的对象 - * @param total 总的条数 - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param data object returned + * @param total total number of items + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static PageResult of(List data, Long total, Long pageNo, Long pageSize) { return new PageResult<>(data, total, pageNo, pageSize); } /** - * 构建分页返回对象 + * Construct paging return object * - * @param data 返回的对象 - * @param total 总的条数 - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param data object returned + * @param total total number of items + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static PageResult of(List data, Long total, Integer pageNo, Integer pageSize) { return new PageResult<>(data, total, pageNo, pageSize); } /** - * 构建分页返回对象 + * Construct paging return object * - * @param data 返回的对象 - * @param total 总的条数 - * @param param 分页参数 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param data object returned + * @param total total number of items + * @param param paging parameters + * @param The returned object type + * @return paging return object */ public static PageResult of(List data, Long total, PageQueryParam param) { return new PageResult<>(data, total, param.getPageNo(), param.getPageSize()); } /** - * 构建分页返回对象 - * 总条数返回 + * Construct paging return object + * Total number of items returned * - * @param data 返回的对象 - * @param param 分页参数 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param data object returned + * @param param paging parameters + * @param The returned object type + * @return paging return object */ public static PageResult of(List data, PageQueryParam param) { return new PageResult<>(data, 0L, param.getPageNo(), param.getPageSize()); } /** - * 构建空的返回对象 + * Construct an empty return object * - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static PageResult empty(Long pageNo, Long pageSize) { return of(Collections.emptyList(), 0L, pageNo, pageSize); } /** - * 构建空的返回对象 + * Construct an empty return object * - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static PageResult empty(Integer pageNo, Integer pageSize) { return of(Collections.emptyList(), 0L, pageNo, pageSize); } /** - * 判断是否还有下一页 - * 根据分页大小来计算 防止total为空 + * Determine whether there is a next page + * Calculated based on paging size to prevent total from being empty * - * @return 是否还有下一页 + * @return Is there a next page? */ public Boolean calculateHasNextPage() { - // 存在分页大小 根据分页来计算 + // There is a paging size calculated based on the paging if (total > 0) { return (long)pageSize * pageNo <= total; } - // 没有数据 肯定没有下一页 + // No data, definitely no next page if (data == null || data.isEmpty()) { return false; } - // 当前数量小于分页数量 + // The current number is less than the number of pages return data.size() >= pageSize; } /** - * 判断是否还有下一页 - * 根据分页大小来计算 防止total为空 + * Determine whether there is a next page + * Calculated based on paging size to prevent total from being empty * - * @return 是否还有下一页 - * @deprecated 使用 {@link #getHasNextPage()} ()} + * @return Is there a next page? + * @deprecated using {@link #getHasNextPage()} ()} */ @Deprecated public boolean hasNextPage() { @@ -223,21 +223,21 @@ public Boolean getHasNextPage() { } /** - * 判断是否存在数据 + * Determine whether data exists * - * @return 是否存在数据 + * @return whether data exists */ public boolean hasData() { return hasData(this); } /** - * 返回查询异常信息 + * Return query exception information * - * @param errorCode 错误编码 - * @param errorMessage 错误信息 - * @param 返回的对象 - * @return 分页返回对象 + * @param errorCode error coding + * @param errorMessage error message + * @param The returned object + * @return paging return object */ public static PageResult error(String errorCode, String errorMessage) { PageResult result = new PageResult<>(); @@ -248,10 +248,10 @@ public static PageResult error(String errorCode, String errorMessage) { } /** - * 判断是否存在数据 + * Determine whether data exists * * @param pageResult - * @return 是否存在数据 + * @return whether data exists */ public static boolean hasData(PageResult pageResult) { return pageResult != null && pageResult.getSuccess() && pageResult.getData() != null && !pageResult.getData() @@ -259,11 +259,11 @@ public static boolean hasData(PageResult pageResult) { } /** - * 将当前的类型转换成另外一个类型 + * Convert the current type to another type * - * @param mapper 转换的方法 - * @param 返回的类型 - * @return 分页返回对象 + * @param mapper conversion method + * @param Return type + * @return paging return object */ public PageResult map(Function mapper) { List returnData = hasData(this) ? getData().stream().map(mapper).collect(Collectors.toList()) @@ -281,11 +281,11 @@ public PageResult map(Function mapper) { } /** - * 将当前的类型转换成另外一个类型 + * Convert the current type to another type * - * @param mapper 转换的方法 - * @param 返回的类型 - * @return 分页返回对象 + * @param mapper conversion method + * @param Return type + * @return paging return object */ public ListResult mapToList(Function mapper) { List returnData = hasData(this) ? getData().stream().map(mapper).collect(Collectors.toList()) @@ -300,13 +300,13 @@ public ListResult mapToList(Function mapper) { } /** - * 将当前的类型转换成另外一个类型 - * 并且转换成web的类型 - * 这里注意如果当前项目在web层用的也是 PageResult 则直接使用 map方法接口即可 + * Convert the current type to another type + * and converted to web type + * Note here that if the current project also uses PageResult in the web layer, you can directly use the map method interface. * - * @param mapper 转换的方法 - * @param 返回的类型 - * @return 分页返回对象 + * @param mapper conversion method + * @param Return type + * @return paging return object */ public WebPageResult mapToWeb(Function mapper) { List returnData = hasData(this) ? getData().stream().map(mapper).collect(Collectors.toList()) @@ -316,7 +316,7 @@ public WebPageResult mapToWeb(Function mapper) { pageResult.setErrorCode(getErrorCode()); pageResult.setErrorMessage(getErrorMessage()); pageResult.setTraceId(getTraceId()); - // 重新设置一个分页信息 + // Reset a paging information Page page = new Page<>(); pageResult.setData(page); page.setData(returnData); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/web/WebPageResult.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/web/WebPageResult.java index eef879b9f..95a0ea85b 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/web/WebPageResult.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-base/src/main/java/ai/chat2db/server/tools/base/wrapper/result/web/WebPageResult.java @@ -17,10 +17,11 @@ import lombok.experimental.SuperBuilder; /** - * data的返回对象 - * 和 PageResult 比较一致 也可以直接用 PageResult。 这个是部分项目前端需要将 data+pageNo 封装到一起 所以额外创建的类 + *The return object of data + * Consistent with PageResult, you can also use PageResult directly. + * This is an additional class created because the front end of some projects needs to encapsulate data+pageNo together. * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -28,21 +29,21 @@ public class WebPageResult implements Serializable, Result> { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 是否成功 + * whether succeed * * @mock true */ private Boolean success; /** - * 异常编码 + * Exception coding */ private String errorCode; /** - * 异常信息 + * Exception information */ private String errorMessage; /** - * 数据信息 + * Data information */ private Page data; /** @@ -76,76 +77,76 @@ private WebPageResult(List data, Long total, Integer pageNo, Integer pageSize } /** - * 构建分页返回对象 + * Build pagination return object * - * @param data 返回的对象 - * @param total 总的条数 - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param data object returned + * @param total total number of items + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static WebPageResult of(List data, Long total, Long pageNo, Long pageSize) { return new WebPageResult<>(data, total, pageNo, pageSize); } /** - * 构建分页返回对象 + * Construct paging return object * - * @param data 返回的对象 - * @param total 总的条数 - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param data object returned + * @param total total number of items + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static WebPageResult of(List data, Long total, Integer pageNo, Integer pageSize) { return new WebPageResult<>(data, total, pageNo, pageSize); } /** - * 构建分页返回对象 + * Construct paging return object * - * @param data 返回的对象 - * @param total 总的条数 - * @param param 分页参数 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param data object returned + * @param total total number of items + * @param param paging parameters + * @param The returned object type + * @return paging return object */ public static WebPageResult of(List data, Long total, PageQueryParam param) { return new WebPageResult<>(data, total, param.getPageNo(), param.getPageSize()); } /** - * 构建空的返回对象 + * Construct an empty return object * - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static WebPageResult empty(Long pageNo, Long pageSize) { return of(Collections.emptyList(), 0L, pageNo, pageSize); } /** - * 构建空的返回对象 + * Construct an empty return object * - * @param pageNo 页码 - * @param pageSize 分页大小 - * @param 返回的对象类型 - * @return 分页返回对象 + * @param pageNo page number + * @param pageSize paging size + * @param The returned object type + * @return paging return object */ public static WebPageResult empty(Integer pageNo, Integer pageSize) { return of(Collections.emptyList(), 0L, pageNo, pageSize); } /** - * 判断是否还有下一页 - * 根据分页大小来计算 防止total为空 + * Determine whether there is a next page + * Calculated based on paging size to prevent total from being empty * - * @return 是否还有下一页 - * @deprecated 使用 {@link #getHasNextPage()} ()} + * @return Is there a next page? + * @deprecated using {@link #getHasNextPage()} ()} */ @Deprecated public boolean hasNextPage() { @@ -160,12 +161,12 @@ public Boolean getHasNextPage() { } /** - * 返回查询异常信息 + * Return query exception information * - * @param errorCode 错误编码 - * @param errorMessage 错误信息 - * @param 返回的对象 - * @return 分页返回对象 + * @param errorCode error code + * @param errorMessage error message + * @param The returned object + * @return paging return object */ public static WebPageResult error(String errorCode, String errorMessage) { WebPageResult result = new WebPageResult<>(); @@ -176,10 +177,10 @@ public static WebPageResult error(String errorCode, String errorMessage) } /** - * 判断是否存在数据 + * Determine whether data exists * * @param pageResult - * @return 是否存在数据 + * @return whether data exists */ public static boolean hasData(WebPageResult pageResult) { return pageResult != null && pageResult.getSuccess() && pageResult.getData() != null @@ -187,11 +188,11 @@ public static boolean hasData(WebPageResult pageResult) { } /** - * 将当前的类型转换成另外一个类型 + * Convert the current type to another type * - * @param mapper 转换的方法 - * @param 返回的类型 - * @return 分页返回对象 + * @param mapper conversion method + * @param Return type + * @return paging return object */ public WebPageResult map(Function mapper) { List returnData = hasData(this) ? getData().getData().stream().map(mapper).collect(Collectors.toList()) @@ -201,7 +202,7 @@ public WebPageResult map(Function mapper) { pageResult.setErrorCode(getErrorCode()); pageResult.setErrorMessage(getErrorMessage()); pageResult.setTraceId(getTraceId()); - // 重新设置一个分页信息 + // Reset a paging information Page page = new Page<>(); pageResult.setData(page); page.setData(returnData); @@ -262,30 +263,30 @@ public String solutionLink() { } /** - * 分页信息 + * Pagination information * * @param */ @Data public static class Page { /** - * 数据信息 + * Data information */ private List data; /** - * 分页编码 + * Page coding */ private Integer pageNo; /** - * 分页大小 + * Paging Size */ private Integer pageSize; /** - * 总的大小 + * Total */ private Long total; /** - * 是否存在下一页 + * Is there a next page? */ private Boolean hasNextPage; @@ -327,21 +328,21 @@ public Boolean getHasNextPage() { } /** - * 判断是否还有下一页 - * 根据分页大小来计算 防止total为空 + * Determine whether there is a next page + * Calculated based on paging size to prevent total from being empty * - * @return 是否还有下一页 + * @return Is there a next page? */ public Boolean calculateHasNextPage() { - // 存在分页大小 根据分页来计算 + // There is a paging size calculated based on the paging if (total > 0) { return (long)pageSize * pageNo <= total; } - // 没有数据 肯定没有下一页 + // No data, definitely no next page if (data == null || data.isEmpty()) { return false; } - // 当前数量小于分页数量 + // The current number is less than the number of pages return data.size() >= pageSize; } } diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/Chat2dbProperties.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/Chat2dbProperties.java index de7395182..edf4c3eb5 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/Chat2dbProperties.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/Chat2dbProperties.java @@ -7,7 +7,7 @@ /** * @author moji - * @version SystemProperties.java, v 0.1 2022年11月13日 14:28 moji Exp $ + * @version SystemProperties.java, v 0.1 November 13, 2022 14:28 moji Exp $ * @date 2022/11/13 */ @Configuration @@ -16,7 +16,7 @@ public class Chat2dbProperties { /** - * 版本 + * version */ private String version; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/GlobalDict.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/GlobalDict.java index 45ae392e8..c80c9cd97 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/GlobalDict.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/config/GlobalDict.java @@ -7,17 +7,17 @@ import java.util.List; /** - * 全局字典 + * global dictionary * * @author lzy */ public interface GlobalDict { /** - * 模板文件 + * template file **/ List TEMPLATE_FILE = Arrays.asList("template.html", "template_diy.docx", "sub_template_diy.docx"); /** - * 模板存放目录 + * Template storage directory **/ String templateDir = ConfigUtils.CONFIG_BASE_PATH + File.separator + "template" + File.separator; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/NeedLoggedInBusinessException.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/NeedLoggedInBusinessException.java index 8a48ea06f..6c50d60e3 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/NeedLoggedInBusinessException.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/NeedLoggedInBusinessException.java @@ -7,7 +7,7 @@ import lombok.Getter; /** - * 用户登录异常 + * User login exception * * @author Jiaju Zhuang */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/RedirectBusinessException.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/RedirectBusinessException.java index fe821f893..3902e2adc 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/RedirectBusinessException.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/exception/RedirectBusinessException.java @@ -7,7 +7,7 @@ import lombok.Getter; /** - * 需要重定向的业务异常 + * Business exceptions that require redirection * * @author Jiaju Zhuang */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/Context.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/Context.java index 872134844..c73c4a922 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/Context.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/Context.java @@ -11,7 +11,7 @@ import lombok.experimental.SuperBuilder; /** - * 上下文信息 + * contextual information * * @author Jiaju Zhuang */ @@ -24,7 +24,7 @@ public class Context implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /*** - * 用户信息 + * User Info */ private LoginUser loginUser; } diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/EasyLambdaQueryWrapper.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/EasyLambdaQueryWrapper.java index 70e547260..3fbc45bb0 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/EasyLambdaQueryWrapper.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/EasyLambdaQueryWrapper.java @@ -63,7 +63,7 @@ public EasyLambdaQueryWrapper inWhenPresent(SFunction column, Collectio // The following are the methods that come with the system /** - * 查询字段 + * Query field */ private SharedString sqlSelect = new SharedString(); @@ -97,9 +97,9 @@ public EasyLambdaQueryWrapper(Class entityClass) { } /** - * SELECT 部分 SQL 设置 + * SELECT some SQL settings * - * @param columns 查询字段 + * @param columns query fields */ @SafeVarargs @Override @@ -115,14 +115,14 @@ public EasyLambdaQueryWrapper select(List> columns) { } /** - * 过滤查询的字段信息(主键除外!) - *

例1: 只要 java 字段名以 "test" 开头的 -> select(i -> i.getProperty().startsWith("test"))

- *

例2: 只要 java 字段属性是 CharSequence 类型的 -> select(TableFieldInfo::isCharSequence)

- *

例3: 只要 java 字段没有填充策略的 -> select(i -> i.getFieldFill() == FieldFill.DEFAULT)

- *

例4: 要全部字段 -> select(i -> true)

- *

例5: 只要主键字段 -> select(i -> false)

+ * Filter the field information of the query (except primary key!) + *

Example 1: As long as the java field name starts with "test" -> select(i -> i.getProperty().startsWith("test"))

+ *

Example 2: As long as the java field attribute is of type CharSequence -> select(TableFieldInfo::isCharSequence)

+ *

Example 3: As long as the java field does not have a filling strategy -> select(i -> i.getFieldFill() == FieldFill.DEFAULT)

+ *

Example 4: Want all fields -> select(i -> true)

+ *

Example 5: As long as the primary key field -> select(i -> false)

* - * @param predicate 过滤方式 + * @param predicate filtering method * @return this */ @Override @@ -143,8 +143,8 @@ public String getSqlSelect() { } /** - * 用于生成嵌套 sql - *

故 sqlSelect 不向下传递

+ * Used to generate nested sql + *

Therefore sqlSelect does not pass down

*/ @Override protected EasyLambdaQueryWrapper instance() { diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/IntegerWrapper.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/IntegerWrapper.java index 28eb89ebc..5d8ec61d5 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/IntegerWrapper.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/IntegerWrapper.java @@ -3,9 +3,9 @@ import java.io.Serializable; /** - * 整形的封装类 + * Plastic encapsulation class * - * @author 是仪 + * @author Shi Yi */ public class IntegerWrapper extends Number implements Serializable { private static final long serialVersionUID = 1L; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/LoginUser.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/LoginUser.java index be064187d..518655838 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/LoginUser.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/model/LoginUser.java @@ -11,7 +11,7 @@ import lombok.experimental.SuperBuilder; /** - * 登录的用户信息 + * Login user information * * @author Jiaju Zhuang */ @@ -24,12 +24,12 @@ public class LoginUser implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 用户id + * user id */ private Long id; /** - * 昵称 + * nick name */ private String nickName; @@ -39,7 +39,7 @@ public class LoginUser implements Serializable { private Boolean admin; /** - * 角色编码 + * role coding * * @see RoleCodeEnum */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/ContextUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/ContextUtils.java index a3bf4d69f..c5d905c0f 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/ContextUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/ContextUtils.java @@ -7,7 +7,7 @@ import lombok.extern.slf4j.Slf4j; /** - * 上下文工具类 + * Context tool class * * @author Jiaju Zhuang */ @@ -15,12 +15,12 @@ public class ContextUtils { /** - * 存储context + * Store context */ private static final ThreadLocal CONTEXT_THREAD_LOCAL = new ThreadLocal<>(); /** - * 获取用户id + * Get user id * * @return */ @@ -29,12 +29,12 @@ public static Long getUserId() { } /** - * 获取用户信息 + * Get user information * - * @return 可能返回为空 + * @return may return empty */ public static LoginUser queryLoginUser() { - // 去登录信息获取 + // Go to get login information Context context = queryContext(); if (context == null) { return null; @@ -46,31 +46,31 @@ public static LoginUser queryLoginUser() { } /** - * 获取用户信息 + * Get user information * - * @return 拿不到会抛出重新登陆异常 + * @return If it cannot be obtained, a re-login exception will be thrown. */ public static LoginUser getLoginUser() { - // 去登录信息获取 + // Go to get login information Context context = queryContext(); if (context != null && context.getLoginUser() != null) { return context.getLoginUser(); } - // 判断用户必须登录 + // Determine that the user must log in throw new NeedLoggedInBusinessException(); } /** - * 查询上下文 + * query context * - * @return SaTokenWebMvcConfigurer的拦截器,其他地方调用至少 会返回一个Context ,且里面至少有tokenValue + * @return The interceptor of SaTokenWebMvcConfigurer, when called elsewhere, at least a Context will be returned, and there will be at least tokenValue in it. */ public static Context queryContext() { return CONTEXT_THREAD_LOCAL.get(); } /** - * 设置上下文 设置上下文 + * Set context * * @param context * @return @@ -80,7 +80,7 @@ public static void setContext(Context context) { } /** - * 移除上下文 + * remove context */ public static void removeContext() { CONTEXT_THREAD_LOCAL.remove(); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyBooleanUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyBooleanUtils.java index 18d997d2b..d9c29a176 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyBooleanUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyBooleanUtils.java @@ -1,18 +1,18 @@ package ai.chat2db.server.tools.common.util; /** - * Boolean工具类 + * Boolean tool class * * @author Jiaju Zhuang */ public class EasyBooleanUtils { /** - * 判断2个布尔值是否相同 + * Determine whether two Boolean values are the same * * @param b1 * @param b2 - * @param defaultValue 默认值 ,假设b1 b2为空的情况下 取哪个默认值 + * @param defaultValue Default value, assuming that b1 and b2 are empty, which default value should be taken? * @return */ public static boolean equals(Boolean b1, Boolean b2, Boolean defaultValue) { diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyCollectionUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyCollectionUtils.java index 9f1ad43ac..ad1ab587e 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyCollectionUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyCollectionUtils.java @@ -12,29 +12,29 @@ import org.springframework.boot.autoconfigure.security.SecurityProperties; /** - * 集合工具类 + * Collection tool class * * @author Jiaju Zhuang */ public class EasyCollectionUtils { /** - * 集合stream + * Collection stream * - * @param collection 集合 - * @param 返回的类型 - * @return 集合的stream + * @param collection collection + * @param Return type + * @return the stream of the collection */ public static Stream stream(Collection collection) { return collection != null ? collection.stream() : Stream.empty(); } /** - * 将第一个元素返回 如果没有 则返回空 + * Return the first element. If there is none, return empty. * - * @param collection 集合 - * @param 数据类型 - * @return 返回第一个元素 可能为空 + * @param collection collection + * @param data type + * @return Returns the first element, which may be empty */ public static T findFirst(Collection collection) { return stream(collection) @@ -43,15 +43,15 @@ public static T findFirst(Collection collection) { } /** - * 将一个集合 转换成一个list + * Convert a collection into a list *

- * 会过滤集合中转换前后的空数据,所以会入参出参数量不一致 + * Will filter the empty data before and after conversion in the collection, so the input and output parameters will be inconsistent. * - * @param collection 集合 - * @param function 转换function - * @param 转换前的数据类型 - * @param 转换后数据类型 - * @return list 如果入参为空 会返回一个空数组,且无法修改 + * @param collection collection + * @param function conversion function + * @param Data type before conversion + * @param Data type after conversion + * @return list If the input parameter is empty, an empty array will be returned and cannot be modified. */ public static List toList(Collection collection, Function function) { return stream(collection) @@ -62,15 +62,15 @@ public static List toList(Collection collection, Function fun } /** - * 将一个集合 转换成一个set + * Convert a collection into a set *

- * 会过滤集合中转换前后的空数据 + * Will filter out empty data before and after conversion in the collection * - * @param collection 集合 - * @param function 转换function - * @param 转换前的数据类型 - * @param 转换后数据类型 - * @return list 如果入参为空 会返回一个空数组,且无法修改 + * @param collection collection + * @param function conversion function + * @param Data type before conversion + * @param Data type after conversion + * @return list If the input parameter is empty, an empty array will be returned and cannot be modified. */ public static Set toSet(Collection collection, Function function) { return stream(collection) @@ -81,15 +81,15 @@ public static Set toSet(Collection collection, Function funct } /** - * 将一个集合转成map,遇到key冲突以第二个为准 + * Convert a set into a map. If there is a key conflict, the second one will prevail. * - * @param collection 集合 - * @param keyFunction keyFunction + * @param collection collection + * @param keyFunction keyFunction * @param valueFunction valueFunction - * @param key数据类型 - * @param value数据类型 - * @param 转换前的数据类型 - * @return 转成以后的map + * @param key data type + * @param value data type + * @param Data type before conversion + * @return Convert to future map */ public static Map toMap(Collection collection, Function keyFunction, Function valueFunction) { @@ -99,25 +99,25 @@ public static Map toMap(Collection collection, Function key数据类型 - * @param 转换前的数据类型 - * @return 转成以后的map + * @param key data type + * @param Data type before conversion + * @return Convert to future map */ public static Map toIdentityMap(Collection collection, Function keyFunction) { return toMap(collection, keyFunction, Function.identity()); } /** - * 往一个集合里面加入另一个一个集合 + * Add another set to a set * - * @param collection 原始的集合 - * @param collectionAdd 需要被加入的集合 + * @param collection original collection + * @param collectionAdd The collection to be added * @param - * @return 是否加入了数据 + * @return whether data has been added */ public static boolean addAll(final Collection collection, final Collection collectionAdd) { if (collectionAdd == null) { @@ -127,9 +127,9 @@ public static boolean addAll(final Collection collection, final Collectio } /** - * 判断一个集合的长度为0 但是不为null + * Determine if the length of a set is 0 but not null * - * @param collection 集合 + * @param collection collection * @return */ public static boolean isEmptyButNotNull(final Collection collection) { @@ -137,9 +137,9 @@ public static boolean isEmptyButNotNull(final Collection collection) { } /** - * 判断 一堆集合 是否存在一个 长度为0 但是不为null的数组 + * Determine whether there is an array with a length of 0 but not null in a bunch of collections * - * @param collections 为空则返回false + * @param collections returns false if it is empty * @return */ public static boolean isAnyEmptyButNotNull(final Collection... collections) { @@ -155,9 +155,9 @@ public static boolean isAnyEmptyButNotNull(final Collection... collections) { } /** - * 将一个对象加入集合 - * @param collection 原始集合 - * @param objectAdd 需要加入的对象 + * Add an object to the collection + * @param collection original collection + * @param objectAdd the object to be added * @param */ public static void add(Collection collection, T objectAdd) { @@ -168,12 +168,12 @@ public static void add(Collection collection, T objectAdd) { } /** - * 根据指定字段 集合去重 - * @param collection 原始的集合 + * Deduplication based on specified field collection + * @param collection original collection * @param keyFunction keyFunction * @param * @param - * @return 去重后的集合 + * @return the collection after deduplication */ public static List distinctByKey(Collection collection, Function keyFunction){ return stream(collection).filter(distinctByKey(keyFunction)).collect(Collectors.toList()); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyEnumUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyEnumUtils.java index f78afcf87..d8b5815b0 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyEnumUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyEnumUtils.java @@ -9,25 +9,27 @@ import ai.chat2db.server.tools.base.enums.BaseEnum; /** - * enum工具类 + * enum tool class *

- * 主要为了解决每个枚举都需要写一个根据code 获取value 的函数,看起来不太友好 + * Mainly to solve the problem of each enumeration, + * you need to write a function to get the value according to the code, + * which does not seem very friendly. * * @author Jiaju Zhuang */ public class EasyEnumUtils { /** - * 枚举缓存 不用每次都去循环读取枚举 + * Enumeration cache does not need to loop to read the enumeration every time */ private static final Map>> ENUM_CACHE = new ConcurrentHashMap<>(); /** - * 根据一个枚举类型获取 枚举的描述 + * Get the description of the enumeration based on an enumeration type * - * @param clazz 枚举的class - * @param code 枚举的编码 - * @param 枚举的类型 - * @return 找不到code 则返回为空 + * @param clazz enumeration class + * @param code Enumeration encoding + * @param The type of enumeration + * @return If the code cannot be found, the return value is empty. */ public static > String getDescription(final Class clazz, final String code) { BaseEnum baseEnum = getEnum(clazz, code); @@ -38,37 +40,37 @@ public static > String getDescription(final Class clazz } /** - * 根据一个枚举类型获取 枚举的描述 + * Get the description of the enumeration based on an enumeration type * - * @param clazz 枚举的class - * @param code 枚举的编码 - * @param 枚举的类型 - * @return 找不到code 则返回为空 + * @param clazz enumeration class + * @param code Enumeration encoding + * @param The type of enumeration + * @return If the code cannot be found, the return value is empty. */ public static > T getEnum(final Class clazz, final String code) { return getEnumMap(clazz).get(code); } /** - * 校验是否是一个有效的枚举 + * Verify whether it is a valid enumeration * - * @param clazz 枚举的class - * @param code 枚举的编码 , null 也认为是一个有效的枚举 - * @param 枚举的类型 - * @return 是否有效 + * @param clazz enumeration class + * @param code the encoding of the enumeration, null is also considered a valid enumeration + * @param The type of enumeration + * @return Is it valid? */ public static > boolean isValidEnum(final Class clazz, final String code) { return isValidEnum(clazz, code, true); } /** - * 校验是否是一个有效的枚举 + * Verify whether it is a valid enumeration * - * @param clazz 枚举的class - * @param code 枚举的编码,为空认为是一个无效的枚举 - * @param ignoreNull 是否忽略空的code - * @param 枚举的类型 - * @return 是否有效 + * @param clazz enumeration class + * @param code The encoding of the enumeration. If it is empty, it is considered an invalid enumeration. + * @param ignoreNull whether to ignore empty codes + * @param The type of enumeration + * @return Is it valid? */ public static > boolean isValidEnum(final Class clazz, final String code, final boolean ignoreNull) { @@ -79,10 +81,10 @@ public static > boolean isValidEnum(final Class clazz, } /** - * 获取一个枚举的code Enum的map + * Get the map of an enumerated code Enum * - * @param clazz 枚举的class - * @param 枚举的类型 + * @param clazz enumeration class + * @param The type of enumeration * @return Map */ public static > Map getEnumMap(final Class clazz) { diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyIntegerUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyIntegerUtils.java index 1e64099df..fc9ba1ffa 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyIntegerUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyIntegerUtils.java @@ -3,11 +3,13 @@ public class EasyIntegerUtils { /** - * 判断2个布尔值是否相同 + * Determine whether two Boolean values are the same * * @param b1 * @param b2 - * @param defaultValue 默认值 ,假设b1 b2为空的情况下 取哪个默认值 + * @param defaultValue default value, + * assuming that b1 b2 is empty, + * which default value should be taken? * @return */ public static boolean equals(Integer b1, Integer b2, Integer defaultValue) { diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyOptionalUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyOptionalUtils.java index 40105b5de..4e2e63e39 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyOptionalUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyOptionalUtils.java @@ -4,34 +4,34 @@ import java.util.function.Function; /** - * Optional的工具类 + * Optional tool class * * @author Jiaju Zhuang */ public class EasyOptionalUtils { /** - * 将一个可能未null 的对象 获取其值 + * Get the value of an object that may not be null * - * @param source 原始对象 - * @param function 转换方法 + * @param source original object + * @param function conversion method * @param * @param - * @return 返回值 为空则返回nulll + * @return Return value If empty, return null */ public static R mapTo(T source, Function function) { return mapTo(source, function, null); } /** - * 将一个可能未null 的对象 获取其值 + * Get the value of an object that may not be null * - * @param source 原始对象 - * @param function 转换方法 - * @param defaultValue 默认值 + * @param source original object + * @param function conversion method + * @param defaultValue default value * @param * @param - * @return 返回值 + * @return return value */ public static R mapTo(T source, Function function, R defaultValue) { return Optional.ofNullable(source).map(function).orElse(defaultValue); diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasySqlUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasySqlUtils.java index d73f3543e..6cf090eb5 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasySqlUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasySqlUtils.java @@ -35,7 +35,7 @@ public static String orderBy(List orderByList) { } /** - * 获取 columnName + * get columnName */ public static ColumnSegment columnToSqlSegment(String column) { return () -> column; diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyStringUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyStringUtils.java index b0a1e0b80..5f2987bb9 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyStringUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/EasyStringUtils.java @@ -9,21 +9,21 @@ import org.apache.commons.lang3.StringUtils; /** - * String工具类 + * String utility class * * @author Jiaju Zhuang */ public class EasyStringUtils { /** - * 0的字符 + * 0 characters */ private static final char ZERO_CHAR = '0'; /** - * 去掉工号前面的0 + * Remove the 0 in front of the job number * - * @param userId 工号 - * @return 修改后的工号 + * @param userId employee ID + * @return modified job number */ public static String cutUserId(String userId) { if (!org.apache.commons.lang3.StringUtils.isNumeric(userId)) { @@ -32,14 +32,14 @@ public static String cutUserId(String userId) { int startIndex = 0; for (int i = 0; i < userId.length(); i++) { char c = userId.charAt(i); - // 查询第一个不是0的位置 + // Query the first position that is not 0 if (ZERO_CHAR == c) { startIndex = i + 1; } else { break; } } - // 可能整个账号都是0 + // Maybe the entire account is 0 if (startIndex == userId.length()) { return "0"; } @@ -47,21 +47,21 @@ public static String cutUserId(String userId) { } /** - * 去除花名后面的工号 + * Remove the job number after the flower name * - * @param name 姓名或者花名 - * @return 去除工号后的姓名或者花名 + * @param name name or nickname + * @return the name or nickname after removing the work number */ public static String cutName(String name, String workNo) { if (StringUtils.isBlank(workNo) || StringUtils.isBlank(name)) { return name; } - // 这里可能会出现 0结的情况 + // There may be 0 knots here String cutName = RegExUtils.removeFirst(name, workNo); int lastIndex = cutName.length(); for (int i = cutName.length() - 1; i >= 0; i--) { char c = cutName.charAt(i); - // 查询第最后一个不是0的位置 + // Query the last position that is not 0 if (ZERO_CHAR == c) { lastIndex = i; } else { @@ -72,10 +72,10 @@ public static String cutName(String name, String workNo) { } /** - * 增加工号前面的0 + * Add 0 in front of the job number * - * @param userId 工号 - * @return 修改后的工号 + * @param userId employee ID + * @return modified job number */ public static String padUserId(String userId) { if (!StringUtils.isNumeric(userId)) { @@ -85,11 +85,11 @@ public static String padUserId(String userId) { } /** - * 构建展示的名称 + * Build the name of the display * - * @param name 姓名 - * @param nickName 花名 - * @return 展示名称 姓名(花名) + * @param name name + * @param nickName flower name + * @return display name name (flower name) */ public static String buildShowName(String name, String nickName) { StringBuilder showName = new StringBuilder(); @@ -105,10 +105,10 @@ public static String buildShowName(String name, String nickName) { } /** - * 将多个字符串 拼接在一起 + * Splice multiple strings together * - * @param delimiter 分隔符 不能为空 - * @param elements 字符串 可以为空 会忽略空的字符串 + * @param delimiter delimiter cannot be empty + * @param elements string can be empty and empty strings will be ignored * @return */ public static String join(CharSequence delimiter, CharSequence... elements) { @@ -124,10 +124,10 @@ public static String join(CharSequence delimiter, CharSequence... elements) { } /** - * 限制一个string字符串的长度 ,超过长度 会用... 替换 + * Limit the length of a string string. If it exceeds the length, it will be replaced with... * - * @param str 字符串 - * @param length 限制长度 + * @param str string + * @param length limit length * @return */ public static String limitString(String str, int length) { diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/I18nUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/I18nUtils.java index 91dc2dde8..0c2a24147 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/I18nUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/I18nUtils.java @@ -40,7 +40,7 @@ public static String getMessage(String messageCode, @Nullable Object[] args) { } /** - * 是否是英文 + * Is it in English? * * @return */ diff --git a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/LogUtils.java b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/LogUtils.java index 73dbd5c2f..d6cb2e330 100644 --- a/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/LogUtils.java +++ b/chat2db-server/chat2db-server-tools/chat2db-server-tools-common/src/main/java/ai/chat2db/server/tools/common/util/LogUtils.java @@ -33,7 +33,7 @@ public class LogUtils { public static final String TRACE_ID_HEADER = "X-Chat2DB-Trace-Id"; /** - * 换行符 + * newline character */ private static final Pattern LINE_FEED_PATTERN = Pattern.compile("\r|\n"); @@ -56,7 +56,7 @@ public static String maskString(String input) { } /** - * 去除换行符 + * Remove newlines * * @param log * @return @@ -69,7 +69,7 @@ public static String removeCrlf(String log) { } /** - * 裁切日志 + * cut log * * @param log * @return @@ -82,7 +82,7 @@ public static String cutLog(Object log) { } /** - * 返回traceId + * Return traceId * * @return */ diff --git a/chat2db-server/chat2db-server-web-start/pom.xml b/chat2db-server/chat2db-server-web-start/pom.xml index f3bd4c7d8..5012d6e05 100644 --- a/chat2db-server/chat2db-server-web-start/pom.xml +++ b/chat2db-server/chat2db-server-web-start/pom.xml @@ -32,13 +32,13 @@ ai.chat2db chat2db-server-admin-api - + ai.chat2db chat2db-server-domain-core - + org.slf4j jcl-over-slf4j @@ -52,13 +52,13 @@ logback-classic - + com.h2database h2 - + org.flywaydb flyway-core @@ -68,18 +68,18 @@ flyway-mysql - + cn.dev33 sa-token-spring-boot3-starter - + cn.dev33 sa-token-jwt - + org.springframework.boot spring-boot-starter-thymeleaf @@ -128,7 +128,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -153,7 +153,7 @@ - + diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/Application.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/Application.java index 3d165e0c0..b121c56ab 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/Application.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/Application.java @@ -18,7 +18,7 @@ import org.springframework.stereotype.Indexed; /** - * 启动类 + * Startup class * * @author Jiaju Zhuang */ diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/StdinReader.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/StdinReader.java index 71463bbb7..0fd75a6f8 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/StdinReader.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/StdinReader.java @@ -13,7 +13,7 @@ // // @Override // public void onApplicationEvent(ApplicationReadyEvent event) { -// // 启动读取 stdin 的线程 +// // Start a thread that reads stdin // new Thread(() -> readStdin()).start(); // } // @@ -21,9 +21,9 @@ // Scanner scanner = new Scanner(System.in); // while (scanner.hasNextLine()) { // String line = scanner.nextLine(); -// // 处理接收到的数据 -// System.out.println("接收到数据: " + line); -// // 在这里调用其他服务或逻辑 +// // Process the received data +// System.out.println("data received: " + line); +// // Call other services or logic here // } // } // diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/config/Chat2dbWebMvcConfigurer.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/config/Chat2dbWebMvcConfigurer.java index 519fa42fd..baf260fc1 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/config/Chat2dbWebMvcConfigurer.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/config/Chat2dbWebMvcConfigurer.java @@ -39,21 +39,21 @@ import java.util.Enumeration; /** - * web项目配置 + * web project configuration * - * @author 是仪 + * @author Shi Yi */ @Configuration @Slf4j public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer { /** - * api前缀 + * api prefix */ private static final String API_PREFIX = "/api/"; /** - * 全局放行的url + * Globally released url */ private static final String[] FRONT_PERMIT_ALL = new String[] {"/favicon.ico", "/error", "/static/**", "/api/system", "/login", "/api/system/get_latest_version"}; @@ -68,7 +68,7 @@ public class Chat2dbWebMvcConfigurer implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - // 所有请求尝试加入用户信息 + // All requests try to add user information registry.addInterceptor(new AsyncHandlerInterceptor() { @Override public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @@ -76,7 +76,7 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl Dbutils.setSession(); String userIdString = (String)StpUtil.getLoginIdDefaultNull(); Long userId; - // 未登录 + // Not logged in if (!StringUtils.isNumeric(userIdString)) { if (chat2dbProperties.getMode() == ModeEnum.DESKTOP) { userId = RoleCodeEnum.DESKTOP.getDefaultUserId(); @@ -107,7 +107,7 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl }); if (loginUser == null) { - // 代表用户可能被删除了 + // Indicates that the user may have been deleted return true; } @@ -121,7 +121,7 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - // 移除登录信息 + // Remove login information ContextUtils.removeContext(); Dbutils.removeSession(); } @@ -130,15 +130,15 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp .addPathPatterns("/**") .excludePathPatterns(FRONT_PERMIT_ALL); - // 校验登录信息 + // Verify login information registry.addInterceptor(new AsyncHandlerInterceptor() { @Override public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws IOException { Context context = ContextUtils.queryContext(); - // 校验登录信息 + // Verify login information if (context == null) { - log.info("访问{},{}需要登录", buildHeaderString(request), SaHolder.getRequest().getUrl()); + log.info("Login is required to access {},{}", buildHeaderString(request), SaHolder.getRequest().getUrl()); String path = SaHolder.getRequest().getRequestPath(); // if(path.startsWith("/login")){ @@ -160,14 +160,14 @@ public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServl }) .order(2) .addPathPatterns("/**") - // 前端需要放行的链接 + // Links that need to be released on the front end .excludePathPatterns(FRONT_PERMIT_ALL) - // -a结尾的统一放行 + // Uniform release ending in -a .excludePathPatterns("/**/*-a") - // _a结尾的统一放行 + // Uniform release of endings in _a .excludePathPatterns("/**/*_a"); - // 校验权限 + // Verify permissions registry.addInterceptor(new AsyncHandlerInterceptor() { @Override public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/interceptor/CorsFilter.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/interceptor/CorsFilter.java index 1c4310a23..e1520c435 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/interceptor/CorsFilter.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/interceptor/CorsFilter.java @@ -9,12 +9,12 @@ import java.io.IOException; /** - * Cors跨域的拦截器,任何情况都允许跨域 + * Cors cross-domain interceptor, allowing cross-domain under any circumstances * - * 通过CorsRegistry策略的跨域 在登录的情况下会有有问题,但是本地没有复现,可能原因是:bean 的加载顺序的问题。 - * 临时通过CorsFilter解决,后续可以研究下:CorsRegistry + * There will be a problem when logging in across domains through the CorsRegistry policy, but it does not happen locally. The possible reason is: the loading order of the beans. + * Temporarily solved through CorsFilter, you can study it later: CorsRegistry * - * @author 是仪 + * @author Shi Yi */ @Component public class CorsFilter implements Filter { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/DbhubTomcatConnectorCustomizer.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/DbhubTomcatConnectorCustomizer.java index 84f9e5423..1787cd07a 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/DbhubTomcatConnectorCustomizer.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/DbhubTomcatConnectorCustomizer.java @@ -8,7 +8,7 @@ //import org.springframework.stereotype.Component; // ///** -// * 自定义tomcat参数 +// * Custom tomcat parameters // * // * @author Jiaju Zhuang // */ @@ -18,7 +18,7 @@ // @Override // public void customize(Connector connector) { // connector.addLifecycleListener(event -> { -// // 接受到关闭事件 直接退出系统,因为有时候不会退出系统 +// // Exit the system directly after receiving the shutdown event, because sometimes the system will not exit. // if (LifecycleState.STOPPING == event.getLifecycle().getState()) { // SystemUtils.stop(); // } diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/FailedEventApplicationListener.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/FailedEventApplicationListener.java index b91a97a45..126c5f307 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/FailedEventApplicationListener.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/FailedEventApplicationListener.java @@ -6,8 +6,8 @@ import org.springframework.context.ApplicationListener; /** - * 应用启动失败的监听器 - * 应用启动失败了只是停止了tomcat 并没有停止应用 这里停止xia + * Listener for application startup failure + * The application failed to start. It just stopped tomcat and did not stop the application. Stop xia here. * * @author Jiaju Zhuang */ @@ -16,7 +16,7 @@ public class FailedEventApplicationListener implements ApplicationListener dataResult; // try { // String body = HttpUtil.get("http://127.0.0.1:" + serverPort + "/api/system/get-version-a", 10); // dataResult = JSON.parseObject(body, new TypeReference<>() {}); // } catch (Exception e) { -// // 抛出异常 代表没有旧的启动 或者旧的不靠谱 -// log.info("尝试访问旧的应用失败。本异常不重要,正常启动启动都会输出,请忽略。" + e.getMessage()); +// // Throwing an exception means that there is no old startup or the old one is unreliable. +// log.info("Attempts to access old applications failed. This exception is not important. It will be output during normal startup, so please ignore it." + e.getMessage()); // -// // 尝试杀死旧的进程 +// // Try killing the old process // killOldIfNecessary(environment); // return; // } // // if (dataResult == null || BooleanUtils.isNotTrue(dataResult.getSuccess())) { -// // 尝试杀死旧的进程 +// // Try killing the old process // killOldIfNecessary(environment); // return; // } // -// // 代表旧的进程是可以用的 -// log.info("当前接口已经存在启动的应用了,本应用不在启动"); +// // Indicates that the old process is available +// log.info("There is already a started application on the current interface, and this application is no longer started."); // System.exit(0); // } // @@ -59,7 +59,7 @@ // try { // ProcessHandle.allProcesses().forEach(process -> { // String command = process.info().command().orElse(null); -// // 不是java应用 +// // Not a java application // boolean isJava = StringUtils.endsWithIgnoreCase(command, "java") || StringUtils.endsWithIgnoreCase( // command, // "java.exe"); @@ -67,11 +67,11 @@ // return; // } // String[] arguments = process.info().arguments().orElse(null); -// // 没有参数 +// // no parameters // if (arguments == null) { // return; // } -// // 是否是dbhub +// // Is it dbhub? // boolean isDbhub = false; // String environmentArgument = null; // for (String argument : arguments) { @@ -82,47 +82,47 @@ // environmentArgument = StringUtils.substringAfter(argument, "-Dspring.profiles.active="); // } // } -// // 不是dbhub +// // Not dbhub // if (!isDbhub) { // return; // } -// // 判断是否是正式环境 +// // Determine whether it is a formal environment // if (StringUtils.equals(SystemEnvironmentEnum.RELEASE.getCode(), environment) && StringUtils.equals( // SystemEnvironmentEnum.RELEASE.getCode(), environmentArgument)) { -// log.info("正式环境需要关闭进程"); +// log.info("The formal environment requires closing the process"); // destroyProcess(process, command, arguments); // return; // } // -// // 判断是否是测试环境 +// // Determine whether it is a test environment // if (StringUtils.equals(SystemEnvironmentEnum.TEST.getCode(), environment) && StringUtils.equals( // SystemEnvironmentEnum.TEST.getCode(), environmentArgument)) { -// log.info("测试环境需要关闭进程"); +// log.info("The test environment needs to shut down the process"); // destroyProcess(process, command, arguments); // return; // } // -// // 判断是否是本地环境 +// // Determine whether it is a local environment // boolean devDestroy = StringUtils.equals(SystemEnvironmentEnum.DEV.getCode(), environment) && ( // environmentArgument == null // || StringUtils.equals(SystemEnvironmentEnum.DEV.getCode(), environmentArgument)); // if (devDestroy) { -// log.info("本地环境需要关闭进程"); +// log.info("The local environment needs to close the process"); // destroyProcess(process, command, arguments); // } // }); // } catch (Throwable t) { -// log.warn("尝试关闭多余的进程失败,不影响正常启动", t); +// log.warn("Attempts to close redundant processes failed and did not affect normal startup.", t); // } // // } // // private void destroyProcess(ProcessHandle process, String command, String[] arguments) { -// log.info("检查到存在需要关闭的进程:{},{}", JSON.toJSONString(command), JSON.toJSONString(arguments)); +// log.info("Checked that there are processes that need to be shut down:{},{}", JSON.toJSONString(command), JSON.toJSONString(arguments)); // try { // process.destroy(); // } catch (Exception e) { -// log.error("结束进程失败", e); +// log.error("Failed to end process", e); // } // } //} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/ManageMessage.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/ManageMessage.java index 1789c5edd..b5dad69e1 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/ManageMessage.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/ManageMessage.java @@ -10,7 +10,7 @@ import java.io.Serializable; /** - * 管理的消息 + * Administrative messages * * @author Jiaju Zhuang */ @@ -23,7 +23,7 @@ public class ManageMessage implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 消息类型 + * Message type * * @see MessageTypeEnum */ diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/MessageTypeEnum.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/MessageTypeEnum.java index d8838c2fa..614b32abc 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/MessageTypeEnum.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/listener/manage/MessageTypeEnum.java @@ -4,14 +4,14 @@ import lombok.Getter; /** - * 消息类型枚举 + * Message type enum * * @author Jiaju Zhuang */ @Getter public enum MessageTypeEnum implements BaseEnum { /** - * 检查是否正常运行 + * Check if it works properly */ HEARTBEAT, diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/mybatis/MyBatisPlusConfig.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/mybatis/MyBatisPlusConfig.java index a4fc2e857..4a3601f57 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/mybatis/MyBatisPlusConfig.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/mybatis/MyBatisPlusConfig.java @@ -8,14 +8,14 @@ /** * @author moji - * @version MyBatisPlusConfig.java, v 0.1 2022年09月29日 17:38 moji Exp $ + * @version MyBatisPlusConfig.java, v 0.1 September 29, 2022 17:38 moji Exp $ * @date 2022/09/29 */ @Configuration public class MyBatisPlusConfig { /** - * myBatisPlus 分页插件 + * myBatisPlus Pagination plugin */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaLogForSlf4j.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaLogForSlf4j.java index eedd308d2..a2f00bf52 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaLogForSlf4j.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaLogForSlf4j.java @@ -5,9 +5,9 @@ import org.springframework.stereotype.Component; /** - * satoken 日志打印 + * satoken Log printing * - * @author 是仪 + * @author Shi Yi */ @Slf4j @Component diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaTokenConfigure.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaTokenConfigure.java index 6f4d9a909..cd27fa010 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaTokenConfigure.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/config/oauth/SaTokenConfigure.java @@ -6,16 +6,16 @@ import org.springframework.context.annotation.Configuration; /** - * satoken配置 + * satoken placement * - * @author 是仪 + * @author Shi Yi */ @Configuration public class SaTokenConfigure { @Bean public StpLogic ttpLogic() { - // 登录展示用 无状态的 这样不用依赖于与redis之类的 - // 后续可以改成ehcahe 存储磁盘? + // Login display is stateless, so there is no need to rely on redis or the like. + // Can it be changed to ehcahe storage disk later? return new StpLogicJwtForStateless(); } } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/OauthController.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/OauthController.java index 6e0af757a..63cd57e35 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/OauthController.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/OauthController.java @@ -23,7 +23,7 @@ import java.util.Objects; /** - * 登录授权服务 + * Login authorization service * * @author Jiaju Zhuang */ @@ -36,14 +36,14 @@ public class OauthController { private UserService userService; /** - * 用户名密码登录 + * Login with username and password * * @param request * @return */ @PostMapping("login_a") public DataResult login(@Validated @RequestBody LoginRequest request) { - // 查询用户 + // Query user User user = userService.query(request.getUserName()).getData(); this.validateUser(user); @@ -82,7 +82,7 @@ private Object doLogin(User user) { } /** - * 登出 + * Sign out * * @return */ diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/request/LoginRequest.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/request/LoginRequest.java index 690861eca..79c37be4a 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/request/LoginRequest.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/oauth/request/LoginRequest.java @@ -7,7 +7,7 @@ import lombok.experimental.SuperBuilder; /** - * 登录 + * Log in * * @author Jiaju Zhuang */ @@ -17,14 +17,14 @@ @AllArgsConstructor public class LoginRequest { /** - * 用户名 + * userName */ - @NotNull(message = "用户名不能为空") + @NotNull(message = "Username can not be empty") private String userName; /** - * 密码 + * password */ - @NotNull(message = "密码不能为空") + @NotNull(message = "password can not be blank") private String password; } diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/thymeleaf/ThymeleafController.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/thymeleaf/ThymeleafController.java index 2da27b52d..89b8ff4ff 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/thymeleaf/ThymeleafController.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/controller/thymeleaf/ThymeleafController.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestMethod; /** - * 模板引擎 配置 + * Template engine configuration * * @author Jiaju Zhuang */ @@ -18,7 +18,7 @@ public class ThymeleafController { /** - * 前端的模板设置 + * Front-end template settings * * @return */ diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/EasyControllerExceptionHandler.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/EasyControllerExceptionHandler.java index 859bc930a..00a042410 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/EasyControllerExceptionHandler.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/EasyControllerExceptionHandler.java @@ -33,9 +33,9 @@ import java.util.Map; /** - * 拦截Controller异常 + * Intercepting Controller exceptions * - * @author 是仪 + * @author Shi Yi */ @ControllerAdvice @Slf4j @@ -43,7 +43,7 @@ public class EasyControllerExceptionHandler { /** - * 所有的异常处理转换器 + * All exception handling converters */ public static final Map, ExceptionConvertor> EXCEPTION_CONVERTOR_MAP = Maps.newHashMap(); @@ -62,12 +62,12 @@ public class EasyControllerExceptionHandler { } /** - * 默认转换器 + * Default converter */ public static ExceptionConvertor DEFAULT_EXCEPTION_CONVERTOR = new DefaultExceptionConvertor(); /** - * 业务异常 + * Business abnormality * * @param request request * @param exception exception @@ -83,12 +83,12 @@ public class EasyControllerExceptionHandler { @ResponseBody public ActionResult handleBusinessException(HttpServletRequest request, Exception exception) { ActionResult result = convert(exception); - log.info("发生业务异常{}:{}", request.getRequestURI(), result, exception); + log.info("Business exception occurred{}:{}", request.getRequestURI(), result, exception); return result; } /** - * 业务异常 + * Business abnormality * * @param request request * @param exception exception @@ -97,35 +97,35 @@ public ActionResult handleBusinessException(HttpServletRequest request, Exceptio @ExceptionHandler({RedirectBusinessException.class}) public ModelAndView handleModelAndViewBizException(HttpServletRequest request, Exception exception) { ModelAndView result = translateModelAndView(exception); - log.info("发生ModelAndView业务异常{}:{}", request.getRequestURI(), result, exception); + log.info("ModelAndView business exception occurred{}:{}", request.getRequestURI(), result, exception); return result; } public ModelAndView translateModelAndView(Throwable exception) { - // 参数异常 + // Parameter exception if (exception instanceof RedirectBusinessException) { RedirectBusinessException e = (RedirectBusinessException)exception; return dealResponseModelAndView(null, e.getMessage(), e.getRedirect(), null, null); } - // 默认跳首页 + // Jump to homepage by default return new ModelAndView("redirect:/"); } private ModelAndView dealResponseModelAndView(String title, String errorMessage, String redirect, String href, String buttonText) { - // 如果有车重定向信息 则跳转 + // If there is redirection information, jump if (StringUtils.isNotBlank(redirect)) { return new ModelAndView("redirect:" + redirect); } - // 默认跳首页 + // Jump to homepage by default return new ModelAndView("redirect:/"); - // 同步请求 + // synchronous request //return ModelAndViewUtils.error(title, errorMessage,href,buttonText); } /** - * 系统异常 + * System exception * * @param request request * @param exception exception @@ -136,12 +136,12 @@ private ModelAndView dealResponseModelAndView(String title, String errorMessage, @ResponseBody public ActionResult handleSystemException(HttpServletRequest request, Exception exception) { ActionResult result = convert(exception); - log.error("发生业务异常{}:{}", request.getRequestURI(), result, exception); + log.error("Business exception occurred{}:{}", request.getRequestURI(), result, exception); return result; } /** - * 未知异常 需要人工介入查看日志 + * Unknown exception requires manual intervention to view logs * * @param request request * @param exception exception @@ -152,7 +152,7 @@ public ActionResult handleSystemException(HttpServletRequest request, Exception @ResponseBody public ActionResult handledException(HttpServletRequest request, Exception exception) { ActionResult result = convert(exception); - log.error("发生未知异常{}:{},请求参数:{}", request.getRequestURI(), result, + log.error("An unknown exception occurred {}:{}, request parameters:{}", request.getRequestURI(), result, JSON.toJSONString(request.getParameterMap()), exception); return result; diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BindExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BindExceptionConvertor.java index 684ec1ba1..61a9960bf 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BindExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BindExceptionConvertor.java @@ -7,7 +7,7 @@ /** * BindException * - * @author 是仪 + * @author Shi Yi */ public class BindExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BusinessExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BusinessExceptionConvertor.java index 229abed88..c40a616d2 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BusinessExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/BusinessExceptionConvertor.java @@ -8,7 +8,7 @@ /** * BusinessException * - * @author 是仪 + * @author Shi Yi */ public class BusinessExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/DefaultExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/DefaultExceptionConvertor.java index d71090407..c34fa13b7 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/DefaultExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/DefaultExceptionConvertor.java @@ -5,10 +5,10 @@ import ai.chat2db.spi.util.ExceptionUtils; /** - * 默认的异常处理 - * 直接抛出系统异常 + * Default exception handling + * Throw system exception directly * - * @author 是仪 + * @author Shi Yi */ public class DefaultExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertor.java index 5befeb70b..6f0fe91b4 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertor.java @@ -3,14 +3,14 @@ import ai.chat2db.server.tools.base.wrapper.result.ActionResult; /** - * 异常转换器 + * exception converter * - * @author 是仪 + * @author Shi Yi */ public interface ExceptionConvertor { /** - * 转换异常 + * Conversion exception * * @param exception * @return diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertorUtils.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertorUtils.java index ce386e333..993ef8d83 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertorUtils.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ExceptionConvertorUtils.java @@ -10,14 +10,14 @@ import java.util.List; /** - * 转换工具类 + * Conversion tool class * - * @author 是仪 + * @author Shi Yi */ public class ExceptionConvertorUtils { /** - * 提取BindingResult中的错误消息 + * Extract error message from BindingResult * * @param result * @return @@ -33,7 +33,7 @@ public static String buildMessage(BindingResult result) { msg.append(I18nUtils.getMessage("common.paramCheckError")); for (ObjectError e : errors) { msg.append(index++); - // 得到错误消息 + // got error message msg.append(SymbolConstant.DOT); if (e instanceof FieldError fieldError) { msg.append(fieldError.getField()); diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java index 027021c98..69f9f0a34 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MaxUploadSizeExceededExceptionConvertor.java @@ -8,7 +8,7 @@ /** * MaxUploadSizeExceededException * - * @author 是仪 + * @author Shi Yi */ public class MaxUploadSizeExceededExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java index 5f81c2a22..ca08816ea 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentNotValidExceptionConvertor.java @@ -7,7 +7,7 @@ /** * MethodArgumentNotValidException * - * @author 是仪 + * @author Shi Yi */ public class MethodArgumentNotValidExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java index fe71e877f..616ff7c7f 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/MethodArgumentTypeMismatchExceptionConvertor.java @@ -8,7 +8,7 @@ /** * MethodArgumentTypeMismatchException * - * @author 是仪 + * @author Shi Yi */ public class MethodArgumentTypeMismatchExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ParamExceptionConvertor.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ParamExceptionConvertor.java index 962162421..5782fc5e5 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ParamExceptionConvertor.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/exception/convertor/ParamExceptionConvertor.java @@ -4,12 +4,12 @@ import ai.chat2db.spi.util.ExceptionUtils; /** - * 参数异常 目前包括 + * Parameter exceptions currently include: * ConstraintViolationException * MissingServletRequestParameterException * IllegalArgumentException * - * @author 是仪 + * @author Shi Yi */ public class ParamExceptionConvertor implements ExceptionConvertor { diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/EasyLogSink.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/EasyLogSink.java index a65c0ad5a..21f032ed1 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/EasyLogSink.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/EasyLogSink.java @@ -30,17 +30,17 @@ public void write(final Correlation correlation, final HttpRequest request, fina try { printLog(correlation, request, response); } catch (Exception e) { - log.error("记录日志异常", e); + log.error("Log exceptions", e); } } public void printLog(final Correlation correlation, final HttpRequest request, final HttpResponse response) throws IOException { - // 封装log 对象 + // Encapsulate log object WebLog webLog = new WebLog(); String method = request.getMethod(); - // 路径 + // path String path = request.getPath(); webLog.setMethod(method); @@ -58,7 +58,7 @@ public void printLog(final Correlation correlation, final HttpRequest request, f webLog.setResponse(response.getContentType() + ":[" + response.getBody().length + "]"); } } catch (IOException e) { - log.warn("获取日志的请求&返回异常,大概率是用户关闭了流。", e); + log.warn("The request to obtain the log & returns an exception. Most likely, the user has closed the stream.", e); } webLog.setIp(LogUtils.getClientIp(request)); diff --git a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/WebLog.java b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/WebLog.java index cab943e1a..b77634417 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/WebLog.java +++ b/chat2db-server/chat2db-server-web-start/src/main/java/ai/chat2db/server/web/start/log/WebLog.java @@ -8,9 +8,9 @@ import java.time.LocalDateTime; /** - * log 对象 + * log object * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -18,47 +18,47 @@ @AllArgsConstructor public class WebLog { /** - * 调用方法 + * call method */ private String method; /** - * 路径 + * path */ private String path; /** - * 查询条件 + * Query conditions */ private String query; /** - * 耗时 ms + * Time consuming ms */ private Long duration; /** - * 耗时 ms + * Time consuming ms */ private LocalDateTime startTime; /** - * 耗时 ms + * Time consuming ms */ private LocalDateTime endTime; /** - * 请求 + * request */ private String request; /** - * 返回 + * response */ private String response; /** - * ip地址 + * IP address */ private String ip; } diff --git a/chat2db-server/chat2db-server-web-start/src/main/resources/application-dev.yml b/chat2db-server/chat2db-server-web-start/src/main/resources/application-dev.yml index 6a8058893..a91ded0a1 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/resources/application-dev.yml +++ b/chat2db-server/chat2db-server-web-start/src/main/resources/application-dev.yml @@ -1,9 +1,9 @@ #spring: # datasource: -# # 配置自带数据库的相对路径 +# # Configure the relative path of the built-in database # url: jdbc:h2:~/.chat2db/db/chat2db_dev;FILE_LOCK=NO;MODE=MYSQL # driver-class-name: org.h2.Driver -# 端口号 +# The port number server: port: 10821 diff --git a/chat2db-server/chat2db-server-web-start/src/main/resources/application-release.yml b/chat2db-server/chat2db-server-web-start/src/main/resources/application-release.yml index 7f14992cc..49054bbd6 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/resources/application-release.yml +++ b/chat2db-server/chat2db-server-web-start/src/main/resources/application-release.yml @@ -1,9 +1,9 @@ #spring: # datasource: -# # 配置自带数据库的相对路径 +# # Configure the relative path of the built-in database # url: jdbc:h2:~/.chat2db/db/chat2db;MODE=MYSQL;FILE_LOCK=NO # driver-class-name: org.h2.Driver -# 端口号 +# The port number server: port: 10824 diff --git a/chat2db-server/chat2db-server-web-start/src/main/resources/application-test.yml b/chat2db-server/chat2db-server-web-start/src/main/resources/application-test.yml index ff183746c..bd20de4ec 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/resources/application-test.yml +++ b/chat2db-server/chat2db-server-web-start/src/main/resources/application-test.yml @@ -1,5 +1,5 @@ -# 端口号 +# port server: port: 10822 diff --git a/chat2db-server/chat2db-server-web-start/src/main/resources/application.yml b/chat2db-server/chat2db-server-web-start/src/main/resources/application.yml index e90d6af38..61798388b 100644 --- a/chat2db-server/chat2db-server-web-start/src/main/resources/application.yml +++ b/chat2db-server/chat2db-server-web-start/src/main/resources/application.yml @@ -1,5 +1,5 @@ spring: - # 默认开发环境 + # Default development environment profiles: active: dev main: @@ -18,13 +18,13 @@ spring: servlet: content-type: text/html mode: HTML5 - # 静态文件 + # static files mvc: static-path-pattern: /static/** web: resources: static-locations[0]: classpath:/static/ - # 用于数据库表结构版本管理 + # Used for database table structure version management flyway: enabled: false servlet: @@ -38,7 +38,7 @@ spring: chat2db: version: 1.0.0 -# flywaydb 输出执行sql的日志 +# flywaydb outputs the log of executing sql logging: level: org: @@ -49,25 +49,25 @@ logging: domain: repository: mapper: debug -# 登录功能 +# Login function sa-token: - # token名称 (同时也是cookie名称) + # token name (also cookie name) token-name: CHAT2DB timeout: 2592000 - # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) + # Whether to allow concurrent logins with the same account (when true, simultaneous logins are allowed, when false, new logins crowd out old logins) is-concurrent: true - # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) + # When multiple people log in to the same account, whether to share a token (when true, all logins share a token, when false, a new token is created for each login) is-share: true - # token风格 + # token style token-style: uuid - # 是否输出操作日志 + # Whether to output operation logs is-log: true is-write-header: true chatgpt: apiKey: sk-xxxx apiHost: https://api.openai.com/ - # 可以选择GPT3或GPT35 + # You can choose GPT3 or GPT35 version: GPT35 context: length: 1 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/request/TeamUserPageQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/request/TeamUserPageQueryRequest.java index 53a5c01af..0bd5ca159 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/request/TeamUserPageQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/request/TeamUserPageQueryRequest.java @@ -14,7 +14,7 @@ public class TeamUserPageQueryRequest extends PageQueryRequest { /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/vo/TeamUserListVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/vo/TeamUserListVO.java index 7b2b55f25..d18d2ea25 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/vo/TeamUserListVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/common/vo/TeamUserListVO.java @@ -27,12 +27,12 @@ public class TeamUserListVO implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ private Long id; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/converter/DataSourceAdminConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/converter/DataSourceAdminConverter.java index 3b91cd068..06d1fc888 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/converter/DataSourceAdminConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/converter/DataSourceAdminConverter.java @@ -53,7 +53,7 @@ public abstract class DataSourceAdminConverter { public abstract DataSourcePageQueryVO dto2vo(DataSource dto); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -65,7 +65,7 @@ public abstract class DataSourceAdminConverter { public abstract DataSourceCreateParam createReq2param(DataSourceCreateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessBatchCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessBatchCreateRequest.java index 14d179409..3a3c6fdf3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessBatchCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessBatchCreateRequest.java @@ -20,7 +20,7 @@ public class DataSourceAccessBatchCreateRequest { /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessObjectRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessObjectRequest.java index e0bdf202e..51972bdfc 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessObjectRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessObjectRequest.java @@ -27,12 +27,12 @@ public class DataSourceAccessObjectRequest implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ private Long id; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessPageQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessPageQueryRequest.java index f833609b6..ddaa389b7 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessPageQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceAccessPageQueryRequest.java @@ -14,7 +14,7 @@ public class DataSourceAccessPageQueryRequest extends PageQueryRequest { /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCloneRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCloneRequest.java index 54386e61b..cf954809a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCloneRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCloneRequest.java @@ -5,14 +5,14 @@ /** * @author moji - * @version ConnectionCloneRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCloneRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceCloneRequest { /** - * 主键id + * primary key id */ private Long id; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCreateRequest.java index bd6557282..c6b9a98a7 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceCreateRequest.java @@ -11,41 +11,41 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceCreateRequest { /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ @NotNull private String url; /** - * 连接用户名 + * Connect username */ private String user; /** - * 密码 + * password */ @NotNull private String password; /** - * 认证类型 + * Certification type */ private String authenticationType; /** - * 连接类型 + * Connection Type */ @NotNull private String type; @@ -82,33 +82,33 @@ public class DataSourceCreateRequest { /** - * jdbc版本 + * jdbc version */ private String jdbc; + /** - * 扩展信息 + * Extended Information */ private List extendInfo; - /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 环境id + * environment id */ @NotNull private Long environmentId; /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceUpdateRequest.java index dd754dedf..2f3909d96 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/request/DataSourceUpdateRequest.java @@ -11,45 +11,45 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceUpdateRequest { /** - * 主键id + * primary key id */ @NotNull private Long id; /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 连接用户 + * Connect users */ private String user; /** - * 密码 + * password */ private String password; /** - * 连接类型 + * Connection Type */ private String type; /** - * 环境类型 + * environment type * * @see EnvTypeEnum */ @@ -86,33 +86,33 @@ public class DataSourceUpdateRequest { private String driver; /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 环境id + * environment id */ @NotNull private Long environmentId; /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessObjectVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessObjectVO.java index 4d1ccb914..55e1aa438 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessObjectVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessObjectVO.java @@ -27,12 +27,12 @@ public class DataSourceAccessObjectVO implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ private Long id; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessPageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessPageQueryVO.java index 6d2220dc6..9448fcd56 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessPageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourceAccessPageQueryVO.java @@ -14,12 +14,12 @@ public class DataSourceAccessPageQueryVO { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 授权类型 + * Authorization type * * @see AccessObjectTypeEnum */ @@ -27,13 +27,13 @@ public class DataSourceAccessPageQueryVO { private String accessObjectType; /** - * 授权id,根据类型区分是用户还是团队 + * Authorization ID, distinguish whether it is a user or a team according to the type */ @NotNull private Long accessObjectId; /** - * 授权对象 + * Authorization object */ @NotNull private DataSourceAccessObjectVO accessObject; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourcePageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourcePageQueryVO.java index b77956d66..1a00c98e5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourcePageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/DataSourcePageQueryVO.java @@ -13,27 +13,27 @@ public class DataSourcePageQueryVO { /** - * 主键id + * primary key id */ private Long id; /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 环境id + * environment id */ private Long environmentId; /** - * 环境 + * environment */ private SimpleEnvironmentVO environment; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/SimpleDataSourceVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/SimpleDataSourceVO.java index 8ae1f9820..07c7e2c11 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/SimpleDataSourceVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/datasource/vo/SimpleDataSourceVO.java @@ -13,27 +13,27 @@ public class SimpleDataSourceVO { /** - * 主键id + * primary key id */ private Long id; /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 环境id + * environment id */ private Long environmentId; /** - * 环境 + * environment */ private SimpleEnvironmentVO environment; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamCreateRequest.java index 1b3bcf9a2..c0a8a5346 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamCreateRequest.java @@ -12,19 +12,19 @@ public class TeamCreateRequest { /** - * 团队编码 + * team coding */ @NotNull private String code; /** - * 团队名称 + * Team Name */ @NotNull private String name; /** - * 团队状态 + * Team status * * @see ai.chat2db.server.domain.api.enums.ValidStatusEnum */ @@ -32,7 +32,7 @@ public class TeamCreateRequest { private String status; /** - * 团队描述 + * Team description */ private String description; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamUpdateRequest.java index 623b517d6..dbd6ef2dd 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/request/TeamUpdateRequest.java @@ -11,19 +11,19 @@ @Data public class TeamUpdateRequest { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 团队名称 + * Team Name */ @NotNull private String name; /** - * 团队状态 + * Team status * * @see ai.chat2db.server.domain.api.enums.ValidStatusEnum */ @@ -31,7 +31,7 @@ public class TeamUpdateRequest { private String status; /** - * 角色编码 + * role coding * * @see ai.chat2db.server.domain.api.enums.RoleCodeEnum */ @@ -39,7 +39,7 @@ public class TeamUpdateRequest { private String roleCode; /** - * 团队描述 + * Team description */ private String description; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/SimpleTeamVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/SimpleTeamVO.java index f6b0bf5f2..923cfd1e8 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/SimpleTeamVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/SimpleTeamVO.java @@ -12,23 +12,23 @@ public class SimpleTeamVO { /** - * 主键 + * primary key */ private Long id; /** - * 团队编码 + * team coding */ private String code; /** - * 团队名称 + * Team Name */ private String name; /** - * 团队状态 + * Team status * * @see ai.chat2db.server.domain.api.enums.ValidStatusEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamDataSourcePageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamDataSourcePageQueryVO.java index 7caa47de1..b32807ef5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamDataSourcePageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamDataSourcePageQueryVO.java @@ -14,7 +14,7 @@ public class TeamDataSourcePageQueryVO { /** - * 主键 + * primary key */ @NotNull private Long id; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamPageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamPageQueryVO.java index 75e2b9a51..be19b0f5c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamPageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamPageQueryVO.java @@ -14,44 +14,44 @@ @Data public class TeamPageQueryVO { /** - * 主键 + * primary key */ private Long id; /** - * 团队编码 + * team coding */ private String code; /** - * 团队名称 + * Team Name */ private String name; /** - * 团队状态 + * Team status * * @see ai.chat2db.server.domain.api.enums.ValidStatusEnum */ private String status; /** - * 团队描述 + * Team description */ private String description; /** - * 修改时间 + * Change the time */ private Date gmtModified; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 修改人用户 + * Modifier user */ private SimpleUserVO modifiedUser; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamUserPageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamUserPageQueryVO.java index a5520a23e..6e7dc39b1 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamUserPageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/team/vo/TeamUserPageQueryVO.java @@ -12,7 +12,7 @@ @Data public class TeamUserPageQueryVO { /** - * 主键 + * primary key */ private Long id; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserAdminController.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserAdminController.java index 5f45bd79d..d0f74f546 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserAdminController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserAdminController.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.admin.api.controller.user; import ai.chat2db.server.admin.api.controller.user.converter.UserAdminConverter; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserDataSourceAdminController.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserDataSourceAdminController.java index c30cc4409..f8d1b3549 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserDataSourceAdminController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserDataSourceAdminController.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.admin.api.controller.user; import ai.chat2db.server.admin.api.controller.user.converter.UserDataSourcesAdminConverter; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserTeamAdminController.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserTeamAdminController.java index 06d1d3b8e..bfa0b71d4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserTeamAdminController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/UserTeamAdminController.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.admin.api.controller.user; import ai.chat2db.server.admin.api.controller.user.converter.UserTeamAdminConverter; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserCreateRequest.java index 4e2d1cd78..1bc1035a4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserCreateRequest.java @@ -12,32 +12,31 @@ @Data public class UserCreateRequest { /** - * 用户名 + * userName */ @NotNull private String userName; /** - * 密码 + * password */ @NotNull private String password; /** - * 昵称 + * Nick name */ @NotNull private String nickName; /** - * 邮箱 + * email */ @NotNull private String email; - /** - * 角色编码 + * role coding * * @see RoleCodeEnum */ @@ -45,7 +44,7 @@ public class UserCreateRequest { private String roleCode; /** - * 用户状态 + * user status * * @see ValidStatusEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserUpdateRequest.java index 382826b0b..c1c4871be 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/request/UserUpdateRequest.java @@ -12,38 +12,38 @@ @Data public class UserUpdateRequest { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 密码 + * password */ private String password; /** - * 昵称 + * Nick name */ @NotNull private String nickName; /** - * 邮箱 + * email */ @NotNull private String email; /** - * 角色编码 + * role coding * * @see RoleCodeEnum */ private String roleCode; /** - * 用户状态 + * user status * * @see ValidStatusEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/SimpleUserVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/SimpleUserVO.java index 8b8f88071..a4fe65f2d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/SimpleUserVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/SimpleUserVO.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.admin.api.controller.user.vo; import ai.chat2db.server.domain.api.enums.ValidStatusEnum; @@ -13,25 +12,25 @@ @Data public class SimpleUserVO { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 用户名 + * userName */ @NotNull private String userName; /** - * 昵称 + * Nick name */ @NotNull private String nickName; /** - * 用户状态 + * user status * * @see ValidStatusEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserDataSourcePageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserDataSourcePageQueryVO.java index 0281b318e..0c2ce07fb 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserDataSourcePageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserDataSourcePageQueryVO.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.admin.api.controller.user.vo; import ai.chat2db.server.admin.api.controller.datasource.vo.SimpleDataSourceVO; @@ -14,7 +13,7 @@ public class UserDataSourcePageQueryVO { /** - * 主键 + * primary key */ @NotNull private Long id; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserPageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserPageQueryVO.java index 5ff1abaf7..f0bd9ef37 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserPageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserPageQueryVO.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.admin.api.controller.user.vo; import java.util.Date; @@ -17,56 +16,55 @@ @Data public class UserPageQueryVO { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 用户名 + * userName */ @NotNull private String userName; /** - * 昵称 + * Nick name */ @NotNull private String nickName; /** - * 用户状态 + * user status * * @see ValidStatusEnum */ private String status; /** - * 邮箱 + * email */ @NotNull private String email; /** - * 角色编码 + * role coding * * @see RoleCodeEnum */ private String roleCode; - /** - * 修改时间 + * Change the time */ private Date gmtModified; /** - * 修改人用户id + * Modifier user id */ private Long modifiedUserId; /** - * 修改人用户 + * Modifier user */ private SimpleUserVO modifiedUser; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserTeamPageQueryVO.java b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserTeamPageQueryVO.java index 56424c24b..ec7c74a87 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserTeamPageQueryVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-admin-api/src/main/java/ai/chat2db/server/admin/api/controller/user/vo/UserTeamPageQueryVO.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.admin.api.controller.user.vo; import ai.chat2db.server.admin.api.controller.team.vo.SimpleTeamVO; @@ -12,7 +11,7 @@ @Data public class UserTeamPageQueryVO { /** - * 主键 + * primary key */ private Long id; @@ -22,7 +21,7 @@ public class UserTeamPageQueryVO { private Long userId; /** - * 团队 + * team */ private SimpleTeamVO team; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/CommonCommonController.java b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/CommonCommonController.java index 327a2aab6..d2b6d82ec 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/CommonCommonController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/CommonCommonController.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.common.api.controller; import ai.chat2db.server.common.api.controller.converter.EnvironmentCommonConverter; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonPageQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonPageQueryRequest.java index 87c58b294..ad080e559 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonPageQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonPageQueryRequest.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.common.api.controller.request; import ai.chat2db.server.tools.base.wrapper.request.PageQueryRequest; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonQueryRequest.java index 048b6c23e..d987fe1ef 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/request/CommonQueryRequest.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.common.api.controller.request; import lombok.Data; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleEnvironmentVO.java b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleEnvironmentVO.java index 6ee9e7334..d9e7b9e51 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleEnvironmentVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleEnvironmentVO.java @@ -24,22 +24,22 @@ public class SimpleEnvironmentVO implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 主键 + * primary key */ private Long id; /** - * 环境名称 + * environment name */ private String name; /** - * 环境缩写 + * environment abbreviation */ private String shortName; /** - * 颜色 + * color */ private String color; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleUserVO.java b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleUserVO.java index d9c67b84d..e7d09e1b6 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleUserVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-common-api/src/main/java/ai/chat2db/server/common/api/controller/vo/SimpleUserVO.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.common.api.controller.vo; import java.io.Serial; @@ -25,17 +24,17 @@ private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 主键 + * primary key */ private Long id; /** - * 用户名 + * username */ private String userName; /** - * 昵称 + * Nick name */ private String nickName; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoAspect.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoAspect.java index cb1668c0f..9c1472eb6 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoAspect.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoAspect.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.web.api.aspect; import java.lang.annotation.Documented; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoHandler.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoHandler.java index c8958d783..ff1fe624a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoHandler.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/aspect/ConnectionInfoHandler.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.web.api.aspect; import ai.chat2db.server.domain.api.model.DataSource; @@ -6,6 +5,7 @@ import ai.chat2db.server.domain.api.service.DataSourceService; import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.server.tools.common.exception.ParamBusinessException; +import ai.chat2db.server.tools.common.util.ContextUtils; import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequest; import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequestInfo; import ai.chat2db.server.web.api.controller.data.source.request.DataSourceConsoleRequestInfo; @@ -43,18 +43,18 @@ public Object connectionInfoHandler(ProceedingJoinPoint proceedingJoinPoint) thr for (int i = 0; i < params.length; i++) { Object param = params[i]; if (param instanceof DataSourceBaseRequest) { - Long dataSourceId = ((DataSourceBaseRequest)param).getDataSourceId(); - String schemaName = ((DataSourceBaseRequest)param).getSchemaName(); - String database = ((DataSourceBaseRequest)param).getDatabaseName(); + Long dataSourceId = ((DataSourceBaseRequest) param).getDataSourceId(); + String schemaName = ((DataSourceBaseRequest) param).getSchemaName(); + String database = ((DataSourceBaseRequest) param).getDatabaseName(); Chat2DBContext.putContext(toInfo(dataSourceId, database, null, schemaName)); } else if (param instanceof DataSourceConsoleRequestInfo) { - Long dataSourceId = ((DataSourceConsoleRequestInfo)param).getDataSourceId(); - Long consoleId = ((DataSourceConsoleRequestInfo)param).getConsoleId(); - String database = ((DataSourceConsoleRequestInfo)param).getDatabaseName(); + Long dataSourceId = ((DataSourceConsoleRequestInfo) param).getDataSourceId(); + Long consoleId = ((DataSourceConsoleRequestInfo) param).getConsoleId(); + String database = ((DataSourceConsoleRequestInfo) param).getDatabaseName(); Chat2DBContext.putContext(toInfo(dataSourceId, database, consoleId, null)); } else if (param instanceof DataSourceBaseRequestInfo) { - Long dataSourceId = ((DataSourceBaseRequestInfo)param).getDataSourceId(); - String database = ((DataSourceBaseRequestInfo)param).getDatabaseName(); + Long dataSourceId = ((DataSourceBaseRequestInfo) param).getDataSourceId(); + String database = ((DataSourceBaseRequestInfo) param).getDatabaseName(); Chat2DBContext.putContext(toInfo(dataSourceId, database)); } } @@ -94,6 +94,7 @@ public ConnectInfo toInfo(Long dataSourceId, String database, Long consoleId, St connectInfo.setUrl(dataSource.getUrl()); connectInfo.setPort(StringUtils.isNotBlank(dataSource.getPort()) ? Integer.parseInt(dataSource.getPort()) : null); connectInfo.setHost(dataSource.getHost()); + connectInfo.setLoginUser(ContextUtils.getLoginUser().getId() + ""); DriverConfig driverConfig = dataSource.getDriverConfig(); if (driverConfig != null && driverConfig.notEmpty()) { connectInfo.setDriverConfig(driverConfig); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java index c9e77806f..1b1e519ca 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java @@ -79,7 +79,7 @@ import java.util.stream.Collectors; /** - * 描述: + * description: * * @author https:www.unfbx.com * @date 2023-03-01 @@ -109,30 +109,30 @@ public class ChatController { private GatewayClientService gatewayClientService; /** - * chat的超时时间 + * chat timeout */ private static final Long CHAT_TIMEOUT = Duration.ofMinutes(50).toMillis(); /** - * 提示语最大token数 + * Maximum number of tokens for prompts */ private Integer MAX_PROMPT_LENGTH = 3850; /** - * token转换字符串长度 + * token conversion string length */ private Integer TOKEN_CONVERT_CHAR_LENGTH = 4; /** - * 返回token大小 + * Return token size */ private Integer RETURN_TOKEN_LENGTH = 150; /** - * 自定义模型流式输出接口DEMO + * Custom model streaming output interface DEMO *

- * Note:使用自己本地的流式输出的自定义AI,接口输入和输出需与该样例保持一致 + * Note: For custom AI that uses its own local streaming output, the interface input and output must be consistent with this sample. *

* * @param queryRequest @@ -144,14 +144,14 @@ public class ChatController { public SseEmitter customChat(@RequestBody ChatRequest queryRequest) throws IOException { SseEmitter emitter = new SseEmitter(CHAT_TIMEOUT); - // 设置 SSEEmitter 的事件处理程序 + // Set event handler for SSEEmitter emitter.onCompletion(() -> log.info(LocalDateTime.now() + ", on completion")); emitter.onTimeout(() -> { log.info(LocalDateTime.now() + ", uid# on timeout"); emitter.complete(); }); - // 启动一个新的线程来生成 SSE 事件 + // Start a new thread to generate SSE events new Thread(() -> { try { for (int i = 0; i < 10; i++) { @@ -169,9 +169,9 @@ public SseEmitter customChat(@RequestBody ChatRequest queryRequest) throws IOExc } /** - * 自定义模型非流式输出接口DEMO + * Custom model non-streaming output interface DEMO *

- * Note:使用自己本地的飞流式输出自定义AI,接口输入和输出需与该样例保持一致 + * Note: Use your own local flying flow output to customize the AI. The interface input and output must be consistent with this sample. *

* * @param queryRequest @@ -181,12 +181,12 @@ public SseEmitter customChat(@RequestBody ChatRequest queryRequest) throws IOExc @PostMapping("/custom/non/stream/chat") @CrossOrigin public String customNonStreamChat(@RequestBody ChatRequest queryRequest) throws IOException { - String data = "自定义AI样例接口连接成功!!!!"; + String data = "The custom AI sample interface is connected successfully! ! ! !"; return data; } /** - * SQL转换模型 + * SQL conversion model * * @param queryRequest * @param headers @@ -197,14 +197,14 @@ public String customNonStreamChat(@RequestBody ChatRequest queryRequest) throws @CrossOrigin public SseEmitter completions(ChatQueryRequest queryRequest, @RequestHeader Map headers) throws IOException { - //默认30秒超时,设置为0L则永不超时 + //The default timeout is 30 seconds. If set to 0L, it will never timeout. SseEmitter sseEmitter = new SseEmitter(CHAT_TIMEOUT); String uid = headers.get("uid"); if (StrUtil.isBlank(uid)) { throw new ParamBusinessException("uid"); } - //提示消息不得为空 + //Prompt message cannot be empty if (StringUtils.isBlank(queryRequest.getMessage())) { throw new ParamBusinessException("message"); } @@ -254,7 +254,7 @@ public SseEmitter distributeAISql(ChatQueryRequest queryRequest, SseEmitter sseE } /** - * 使用自定义AI接口进行聊天 + * Chat using a custom AI interface * * @param prompt * @param sseEmitter @@ -267,7 +267,7 @@ private SseEmitter chatWithRestAi(ChatQueryRequest prompt, SseEmitter sseEmitter } /** - * 使用OPENAI SQL接口 + * Using the OPENAI SQL interface * * @param queryRequest * @param sseEmitter @@ -279,7 +279,7 @@ private SseEmitter chatWithOpenAi(ChatQueryRequest queryRequest, SseEmitter sseE throws IOException { String prompt = buildPrompt(queryRequest); if (prompt.length() / TOKEN_CONVERT_CHAR_LENGTH > MAX_PROMPT_LENGTH) { - log.error("提示语超出最大长度:{},输入长度:{}, 请重新输入", MAX_PROMPT_LENGTH, + log.error("The prompt exceeds the maximum length: {}, input length: {}, please re-enter", MAX_PROMPT_LENGTH, prompt.length() / TOKEN_CONVERT_CHAR_LENGTH); throw new ParamBusinessException(); } @@ -298,7 +298,7 @@ private SseEmitter chatWithOpenAi(ChatQueryRequest queryRequest, SseEmitter sseE } /** - * 使用OPENAI SQL接口 + * Using the OPENAI SQL interface * * @param queryRequest * @param sseEmitter @@ -340,7 +340,7 @@ private SseEmitter chatWithChat2dbAi(ChatQueryRequest queryRequest, SseEmitter s private SseEmitter chatWithAzureAi(ChatQueryRequest queryRequest, SseEmitter sseEmitter, String uid) throws IOException { String prompt = buildPrompt(queryRequest); if (prompt.length() / TOKEN_CONVERT_CHAR_LENGTH > MAX_PROMPT_LENGTH) { - log.error("提示语超出最大长度:{},输入长度:{}, 请重新输入", MAX_PROMPT_LENGTH, + log.error("The prompt exceeds the maximum length: {}, input length: {}, please re-enter", MAX_PROMPT_LENGTH, prompt.length() / TOKEN_CONVERT_CHAR_LENGTH); throw new ParamBusinessException(); } @@ -536,7 +536,7 @@ private SseEmitter buildSseEmitter(SseEmitter sseEmitter, String uid) throws IOE throwable -> { try { log.info(LocalDateTime.now() + ", uid#" + "765431" + ", on error#" + throwable.toString()); - sseEmitter.send(SseEmitter.event().id("765431").name("发生异常!").data(throwable.getMessage()) + sseEmitter.send(SseEmitter.event().id("765431").name("An exception occurs!").data(throwable.getMessage()) .reconnectTime(3000)); } catch (IOException e) { e.printStackTrace(); @@ -547,7 +547,7 @@ private SseEmitter buildSseEmitter(SseEmitter sseEmitter, String uid) throws IOE } /** - * 构建schema参数 + * Build schema parameters * * @param tableQueryParam * @param tableNames @@ -589,7 +589,7 @@ private String queryTableDdl(String tableName, TableQueryParam request) { } /** - * 构建prompt + * build prompt * * @param queryRequest * @return @@ -599,7 +599,7 @@ private String buildPrompt(ChatQueryRequest queryRequest) { return queryRequest.getMessage(); } - // 查询schema信息 + // Query schema information String dataSourceType = queryDatabaseType(queryRequest); String properties = ""; if (CollectionUtils.isNotEmpty(queryRequest.getTableNames())) { @@ -614,15 +614,15 @@ private String buildPrompt(ChatQueryRequest queryRequest) { PromptType pType = EasyEnumUtils.getEnum(PromptType.class, promptType); String ext = StringUtils.isNotBlank(queryRequest.getExt()) ? queryRequest.getExt() : ""; String schemaProperty = StringUtils.isNotEmpty(properties) ? String.format( - "### 请根据以下table properties和SQL input%s. %s\n#\n### %s SQL tables, with their properties:\n#\n# " + "### Please follow the below table properties and SQL input%s. %s\n#\n### %s SQL tables, with their properties:\n#\n# " + "%s\n#\n#\n### SQL input: %s", pType.getDescription(), ext, dataSourceType, - properties, prompt) : String.format("### 请根据以下SQL input%s. %s\n#\n### SQL input: %s", + properties, prompt) : String.format("### Please follow the below SQL input%s. %s\n#\n### SQL input: %s", pType.getDescription(), ext, prompt); switch (pType) { case SQL_2_SQL: schemaProperty = StringUtils.isNotBlank(queryRequest.getDestSqlType()) ? String.format( - "%s\n#\n### 目标SQL类型: %s", schemaProperty, queryRequest.getDestSqlType()) : String.format( - "%s\n#\n### 目标SQL类型: %s", schemaProperty, dataSourceType); + "%s\n#\n### Target SQL type: %s", schemaProperty, queryRequest.getDestSqlType()) : String.format( + "%s\n#\n### Target SQL type: %s", schemaProperty, dataSourceType); default: break; } @@ -657,7 +657,7 @@ public String getApiKey() { * @return */ public String queryDatabaseType(ChatQueryRequest queryRequest) { - // 查询schema信息 + // Query schema information DataResult dataResult = dataSourceService.queryById(queryRequest.getDataSourceId()); String dataSourceType = dataResult.getData().getType(); if (StringUtils.isBlank(dataSourceType)) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/AbstractParser.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/AbstractParser.java index 5dbf1007a..2bc2dcc29 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/AbstractParser.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/AbstractParser.java @@ -5,7 +5,7 @@ /** * @author CYY - * @date 2023年03月20日 上午8:13 + * @date March 20, 2023 8:13 am * @description */ public abstract class AbstractParser { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/PdfParse.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/PdfParse.java index ae79abb46..0ade6c066 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/PdfParse.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/DocParser/PdfParse.java @@ -10,7 +10,7 @@ /** * @author CYY - * @date 2023年03月11日 下午3:23 + * @date March 11, 2023 3:23 pm * @description */ public class PdfParse extends AbstractParser { @@ -18,13 +18,13 @@ public class PdfParse extends AbstractParser { @Override public List parse(InputStream inputStream) throws IOException { - // 打开 PDF 文件 + // Open PDF file PDDocument document = PDDocument.load(inputStream); - // 创建 PDFTextStripper 对象 + // Create a PDFTextStripper object PDFTextStripper stripper = new PDFTextStripper(); - // 获取文本内容 + // Get text content String text = stripper.getText(document); - //过滤字符 + // Filter characters text = text.replaceAll("\\s", " ").replaceAll("(\\r\\n|\\r|\\n|\\n\\r)"," "); String[] sentence = text.split("。"); List ans = new ArrayList<>(); @@ -39,7 +39,7 @@ public List parse(InputStream inputStream) throws IOException { ans.add(s); } } - // 关闭文档 + // Close document document.close(); return ans; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/KnowledgeController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/KnowledgeController.java index 6ff16ee09..9119277d4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/KnowledgeController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/KnowledgeController.java @@ -42,7 +42,7 @@ public class KnowledgeController extends ChatController { /** - * chat的超时时间 + * chat timeout */ private static final Long CHAT_TIMEOUT = Duration.ofMinutes(50).toMillis(); @@ -113,7 +113,7 @@ public SseEmitter search(ChatQueryRequest queryRequest, @RequestHeader Map chatMessages, EventSourceLi .url(url) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); log.info("finish invoking azure ai"); } catch (Exception e) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/interceptor/AzureHeaderAuthorizationInterceptor.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/interceptor/AzureHeaderAuthorizationInterceptor.java index 0a07325e0..26a0b9e1a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/interceptor/AzureHeaderAuthorizationInterceptor.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/interceptor/AzureHeaderAuthorizationInterceptor.java @@ -15,7 +15,7 @@ import okhttp3.Response; /** - * 描述:请求增加header apikey + * Description: Request to add header apikey * * @author grt * @since 2023-03-23 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/listener/AzureOpenAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/listener/AzureOpenAIEventSourceListener.java index 4488bd6b8..ac96dd6b3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/listener/AzureOpenAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/azure/listener/AzureOpenAIEventSourceListener.java @@ -20,7 +20,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; /** - * 描述:OpenAIEventSourceListener + * description:OpenAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 @@ -50,9 +50,9 @@ public void onOpen(EventSource eventSource, Response response) { @SneakyThrows @Override public void onEvent(EventSource eventSource, String id, String type, String data) { - log.info("AzureOpenAI返回数据:{}", data); + log.info("AzureOpenAI returns data: {}", data); if (data.equals("[DONE]")) { - log.info("AzureOpenAI返回数据结束了"); + log.info("AzureOpenAI returns data ended"); sseEmitter.send(SseEmitter.event() .id("[DONE]") .data("[DONE]") @@ -142,7 +142,7 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { .data("[DONE]")); sseEmitter.complete(); } catch (Exception exception) { - log.error("Azure OpenAI发送数据异常:", exception); + log.error("Azure OpenAI sends data abnormally:", exception); } } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/client/BaichuanAIStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/client/BaichuanAIStreamClient.java index 57aa33bc4..e4699c9c4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/client/BaichuanAIStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/client/BaichuanAIStreamClient.java @@ -95,7 +95,7 @@ private OkHttpClient okHttpClient() { } /** - * 构造 + * structure * * @return */ @@ -170,7 +170,7 @@ public BaichuanAIStreamClient build() { } /** - * 问答接口 stream 形式 + * Q&A interface stream form * * @param chatMessages * @param eventSourceListener @@ -198,14 +198,14 @@ public void streamCompletions(List chatMessages, EventSourceLis .url(apiHost) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 - // 发送请求并处理响应 + //Create event + //Send the request and process the response try (Response response = this.okHttpClient.newCall(request).execute()) { if (!response.isSuccessful()) { throw new IOException("Unexpected code " + response); } - // 读取并输出响应数据 + //Read and output response data BufferedSource source = response.body().source(); while (!source.exhausted()) { String content = source.readUtf8Line(); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/interceptor/BaichuanHeaderAuthorizationInterceptor.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/interceptor/BaichuanHeaderAuthorizationInterceptor.java index 3eb47f6eb..e6d7709e3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/interceptor/BaichuanHeaderAuthorizationInterceptor.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/interceptor/BaichuanHeaderAuthorizationInterceptor.java @@ -37,10 +37,10 @@ public BaichuanHeaderAuthorizationInterceptor(String apiKey, String secretKey) { public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); - // 获取当前的时间戳(UTC标准时间戳) + // Get the current timestamp (UTC standard timestamp) long timestamp = System.currentTimeMillis() / 1000; - // 获取原始的HTTP-Body + // Get the original HTTP-Body RequestBody originalRequestBody = originalRequest.body(); Buffer buffer = new Buffer(); if (originalRequestBody != null) { @@ -48,10 +48,10 @@ public Response intercept(Chain chain) throws IOException { } String httpBody = buffer.readUtf8(); - // 计算 X-BC-Signature + // Calculate X-BC-Signature String signature = calculateSignature(secretKey, httpBody, timestamp); - // 创建新的请求,并添加自定义请求头 + //Create a new request and add custom request headers Request newRequest = originalRequest.newBuilder() .addHeader("Authorization", "Bearer " + apiKey) .addHeader("Content-Type", "application/json") @@ -89,11 +89,11 @@ private String calculateSignature(String secretKey, RequestBody body, long times String requestBody = bodyToString(body); String rawSignature = secretKey + requestBody + timestamp; - // 使用 MD5 计算签名 + // Use MD5 to calculate signature MessageDigest md = MessageDigest.getInstance("MD5"); byte[] mdBytes = md.digest(rawSignature.getBytes(StandardCharsets.UTF_8)); - // 将 MD5 字节数组转换为 Base64 编码的字符串 + // Convert MD5 byte array to Base64 encoded string return Base64.getEncoder().encodeToString(mdBytes); } catch (IOException | NoSuchAlgorithmException e) { log.error("baichuan secret key md5 error", e); @@ -102,7 +102,7 @@ private String calculateSignature(String secretKey, RequestBody body, long times } private String bodyToString(RequestBody body) throws IOException { - // 将 RequestBody 转换为字符串 + //Convert RequestBody to string return body == null ? "" : body.toString(); } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/listener/BaichuanChatAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/listener/BaichuanChatAIEventSourceListener.java index c84f05b5f..e0219d251 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/listener/BaichuanChatAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/baichuan/listener/BaichuanChatAIEventSourceListener.java @@ -18,7 +18,7 @@ import java.util.Objects; /** - * 描述:OpenAIEventSourceListener + * description:OpenAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2DBAIStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2DBAIStreamClient.java index 0f0b6d84f..9641f25f4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2DBAIStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2DBAIStreamClient.java @@ -76,7 +76,6 @@ public class Chat2DBAIStreamClient { @Getter private FastChatOpenAiApi fastChatOpenAiApi; - /** * @param builder */ @@ -115,7 +114,7 @@ private OkHttpClient okHttpClient() { } /** - * 构造 + * structure * * @return */ @@ -183,7 +182,7 @@ public Chat2DBAIStreamClient build() { } /** - * 问答接口 stream 形式 + * Q&A interface stream form * * @param chatMessages * @param eventSourceListener @@ -211,7 +210,7 @@ public void streamCompletions(List chatMessages, EventSourceListener ev .url(this.apiHost + "v1/chat/completions") .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); log.info("finish invoking chat ai"); } catch (Exception e) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2dbAIClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2dbAIClient.java index a687d4596..0ff5afbee 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2dbAIClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/client/Chat2dbAIClient.java @@ -20,12 +20,12 @@ public class Chat2dbAIClient { public static final String CHAT2DB_OPENAI_KEY = "chat2db.apiKey"; /** - * OPENAI接口域名 + * OPENAI interface domain name */ public static final String CHAT2DB_OPENAI_HOST = "chat2db.apiHost"; /** - * OPENAI模型 + * OPENAI model */ public static final String CHAT2DB_OPENAI_MODEL = "chat2db.model"; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/interceptor/Chat2dbHeaderAuthorizationInterceptor.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/interceptor/Chat2dbHeaderAuthorizationInterceptor.java index 446a84a11..48e8e346e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/interceptor/Chat2dbHeaderAuthorizationInterceptor.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/interceptor/Chat2dbHeaderAuthorizationInterceptor.java @@ -12,7 +12,7 @@ import java.io.IOException; /** - * 描述:请求增加header apikey + * Description: Request to add header apikey * * @author grt * @since 2023-03-23 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/listener/Chat2dbAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/listener/Chat2dbAIEventSourceListener.java index 24b0847a6..b0daccf12 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/listener/Chat2dbAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/chat2db/listener/Chat2dbAIEventSourceListener.java @@ -26,7 +26,7 @@ import java.util.Objects; /** - * 描述:Chat2dbAIEventSourceListener + * Description: Chat2dbAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 @@ -54,9 +54,9 @@ public void onOpen(EventSource eventSource, Response response) { @SneakyThrows @Override public void onEvent(EventSource eventSource, String id, String type, String data) { - log.info("Chat2db AI 返回数据:{}", data); + log.info("Chat2db AI returns data: {}", data); if (data.equals("[DONE]")) { - log.info("Chat2db AI 返回数据结束了"); + log.info("Chat2db AI return data is over"); sseEmitter.send(SseEmitter.event() .id("[DONE]") .data("[DONE]") @@ -85,7 +85,7 @@ public void onEvent(EventSource eventSource, String id, String type, String data @Override public void onClosed(EventSource eventSource) { sseEmitter.complete(); - log.info("Chat2db AI 关闭sse连接..."); + log.info("Chat2db AI closes sse connection..."); } @Override @@ -108,9 +108,9 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { String bodyString = null; if (Objects.nonNull(body)) { bodyString = body.string(); - log.error("Chat2db AI sse连接异常data:{}", bodyString, t); + log.error("Chat2db AI sse connection exception data: {}", bodyString, t); } else { - log.error("Chat2db AI sse连接异常data:{}", response, t); + log.error("Chat2db AI sse connection exception data: {}", response, t); } eventSource.cancel(); Message message = new Message(); @@ -123,7 +123,7 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { .data("[DONE]")); sseEmitter.complete(); } catch (Exception exception) { - log.error("发送数据异常:", exception); + log.error("Exception in sending data:", exception); } } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/client/ClaudeAiStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/client/ClaudeAiStreamClient.java index 692a32a72..17b1f8053 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/client/ClaudeAiStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/client/ClaudeAiStreamClient.java @@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit; /** - * 自定义AI接口client + * Custom AI interface client * * @author moji */ @@ -87,7 +87,7 @@ private OkHttpClient okHttpClient() { } /** - * 构造 + * structure * * @return */ @@ -105,7 +105,7 @@ public static final class Builder { private String userId; /** - * 自定义OkhttpClient + * Customize OkhttpClient */ private OkHttpClient okHttpClient; @@ -175,7 +175,7 @@ public void streamCompletions(ClaudeChatMessage claudeChatMessage, EventSourceLi .url(this.apiHost) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); log.info("finish invoking claude ai"); } catch (Exception e) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/interceptor/ClaudeHeaderAuthorizationInterceptor.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/interceptor/ClaudeHeaderAuthorizationInterceptor.java index 351bb6c54..0d053b131 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/interceptor/ClaudeHeaderAuthorizationInterceptor.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/interceptor/ClaudeHeaderAuthorizationInterceptor.java @@ -10,7 +10,7 @@ import java.io.IOException; /** - * 描述:请求增加header apikey + * Description: Request to add header apikey * * @author grt * @since 2023-03-23 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/listener/ClaudeAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/listener/ClaudeAIEventSourceListener.java index f3570fa6c..e16e8192a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/listener/ClaudeAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/listener/ClaudeAIEventSourceListener.java @@ -52,7 +52,7 @@ public void onEvent(EventSource eventSource, String id, String type, String data sseEmitter.complete(); return; } - // 读取Json + // Read JSON ClaudeCompletionResponse completionResponse = mapper.readValue(data, ClaudeCompletionResponse.class); String text = completionResponse.getCompletion(); Message message = new Message(); @@ -106,7 +106,7 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { .data("[DONE]")); sseEmitter.complete(); } catch (Exception exception) { - log.error("发送数据异常:", exception); + log.error("Exception in sending data:", exception); } } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/model/ClaudeCompletionResponse.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/model/ClaudeCompletionResponse.java index 627078c9b..254900ce9 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/model/ClaudeCompletionResponse.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/claude/model/ClaudeCompletionResponse.java @@ -1,4 +1,3 @@ - package ai.chat2db.server.web.api.controller.ai.claude.model; import com.unfbx.chatgpt.entity.common.Usage; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/config/LocalCache.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/config/LocalCache.java index 37d3ff3d3..c321005d4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/config/LocalCache.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/config/LocalCache.java @@ -5,27 +5,27 @@ import cn.hutool.core.date.DateUnit; /** - * 描述: + * description: * * @author https:www.unfbx.com * @date 2023-03-10 */ public class LocalCache { /** - * 缓存时长 + * Cache duration */ public static final long TIMEOUT = 5 * DateUnit.MINUTE.getMillis(); /** - * 清理间隔 + * Cleanup interval */ private static final long CLEAN_TIMEOUT = 5 * DateUnit.MINUTE.getMillis(); /** - * 缓存对象 + * Cache object */ public static final TimedCache CACHE = CacheUtil.newTimedCache(TIMEOUT); static { - //启动定时任务 + //Start a scheduled task CACHE.schedulePrune(CLEAN_TIMEOUT); } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/converter/ChatConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/converter/ChatConverter.java index 1124b1a58..a3226fc18 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/converter/ChatConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/converter/ChatConverter.java @@ -13,14 +13,14 @@ /** * @author moji - * @version ChatConverter.java, v 0.1 2023年04月02日 13:31 moji Exp $ + * @version ChatConverter.java, v 0.1 April 2, 2023 13:31 moji Exp $ * @date 2023/04/02 */ @Mapper(componentModel = "spring") public abstract class ChatConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/GptVersionType.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/GptVersionType.java index 21deba04b..ea1f94479 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/GptVersionType.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/GptVersionType.java @@ -6,7 +6,7 @@ /** * @author moji - * @version GptModelType.java, v 0.1 2023年04月09日 19:05 moji Exp $ + * @version GptModelType.java, v 0.1 April 9, 2023 19:05 moji Exp $ * @date 2023/04/09 */ @Getter diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/PromptType.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/PromptType.java index 9e9745c75..69d423f65 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/PromptType.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/enums/PromptType.java @@ -5,39 +5,39 @@ import lombok.Getter; /** - * 提示类型 + * prompt type * * @author moji - * @version PromptType.java, v 0.1 2023年04月09日 15:36 moji Exp $ + * @version PromptType.java, v 0.1 April 9, 2023 15:36 moji Exp $ * @date 2023/04/09 */ @Getter public enum PromptType implements BaseEnum { /** - * 自然语言转换成SQL + * Convert natural language to SQL */ - NL_2_SQL("将自然语言转换成SQL查询"), + NL_2_SQL("Convert natural language into SQL queries"), /** - * 解释SQL + * Interpret SQL */ - SQL_EXPLAIN("解释SQL"), + SQL_EXPLAIN("Interpret SQL"), /** - * SQL优化 + * SQL optimization */ - SQL_OPTIMIZER("提供优化建议"), + SQL_OPTIMIZER("Provide optimization suggestions"), /** - * SQL转换 + * SQL conversion */ - SQL_2_SQL("进行SQL转换"), + SQL_2_SQL("Perform SQL conversion"), /** * text generation */ - TEXT_GENERATION("文本生成"), + TEXT_GENERATION("text generation"), ; final String description; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatAIStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatAIStreamClient.java index d3dcaadf2..2772cccd5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatAIStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatAIStreamClient.java @@ -109,7 +109,7 @@ private OkHttpClient okHttpClient() { } /** - * 构造 + * structure * * @return */ @@ -177,7 +177,7 @@ public FastChatAIStreamClient build() { } /** - * 问答接口 stream 形式 + * Q&A interface stream form * * @param chatMessages * @param eventSourceListener @@ -206,7 +206,7 @@ public void streamCompletions(List chatMessages, EventSourceLis .url(apiHost) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); log.info("finish invoking fast chat ai"); } catch (Exception e) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatOpenAiApi.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatOpenAiApi.java index ed12c5f54..d4b85b920 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatOpenAiApi.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/client/FastChatOpenAiApi.java @@ -35,7 +35,7 @@ import java.util.Map; /** - * 描述: open ai官方api接口 + * Description: open ai official api interface * * @author https:www.unfbx.com * 2023-02-15 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbedding.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbedding.java index 54d147196..653b76297 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbedding.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbedding.java @@ -10,7 +10,7 @@ import java.util.Objects; /** - * 描述: + * description: * * @author https:www.unfbx.com * 2023-02-15 @@ -26,7 +26,7 @@ public class FastChatEmbedding implements Serializable { @Builder.Default private String model = Model.TEXT_EMBEDDING_ADA_002.getName(); /** - * 必选项:长度不能超过:8192 + * Required: Length cannot exceed: 8192 */ @NonNull private String input; @@ -49,11 +49,11 @@ public void setModel(String model) { public void setInput(String input) { if (input == null || "".equals(input)) { - log.error("input不能为空"); + log.error("input cannot be empty"); throw new BaseException(CommonError.PARAM_ERROR); } if (input.length() > 8192) { - log.error("input超长"); + log.error("input is too long"); throw new BaseException(CommonError.PARAM_ERROR); } this.input = input; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbeddingResponse.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbeddingResponse.java index a364ffc23..00874a2f2 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbeddingResponse.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/embeddings/FastChatEmbeddingResponse.java @@ -7,7 +7,7 @@ import java.util.List; /** - * 描述: + * description: * * @author https:www.unfbx.com * 2023-02-15 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/listener/FastChatAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/listener/FastChatAIEventSourceListener.java index 7ad62178f..1e02f635e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/listener/FastChatAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/listener/FastChatAIEventSourceListener.java @@ -20,7 +20,7 @@ import java.util.Objects; /** - * 描述:OpenAIEventSourceListener + * description:OpenAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 @@ -66,7 +66,7 @@ public void onEvent(EventSource eventSource, String id, String type, String data log.info("Model={} is created at {}.", chatCompletions.getId(), chatCompletions.getCreated()); for (FastChatChoice choice : chatCompletions.getChoices()) { - FastChatMessage message = choice.getMessage(); + FastChatMessage message = choice.getDelta(); if (message != null) { log.info("Index: {}, Chat Role: {}", choice.getIndex(), message.getRole()); if (message.getContent() != null) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatChoice.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatChoice.java index 5ac0c364f..751f777b6 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatChoice.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatChoice.java @@ -30,8 +30,8 @@ public final class FastChatChoice { /* * The log probabilities model for tokens associated with this completions choice. */ - @JsonProperty(value = "message") - private FastChatMessage message; + @JsonProperty(value = "delta") + private FastChatMessage delta; /* * Reason for finishing @@ -44,18 +44,18 @@ public final class FastChatChoice { * * @param text the text value to set. * @param index the index value to set. - * @param message the message value to set + * @param delta the message value to set * @param finishReason the finishReason value to set. */ @JsonCreator private FastChatChoice( @JsonProperty(value = "text") String text, @JsonProperty(value = "index") int index, - @JsonProperty(value = "message") FastChatMessage message, + @JsonProperty(value = "delta") FastChatMessage delta, @JsonProperty(value = "finish_reason") FastChatCompletionsFinishReason finishReason) { this.text = text; this.index = index; - this.message = message; + this.delta = delta; this.finishReason = finishReason; } @@ -82,8 +82,8 @@ public int getIndex() { * * @return the logprobs value. */ - public FastChatMessage getMessage() { - return this.message; + public FastChatMessage getDelta() { + return this.delta; } /** diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatMessage.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatMessage.java index d74d3c1be..d40d1d8ec 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatMessage.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/fastchat/model/FastChatMessage.java @@ -7,7 +7,6 @@ @Data public class FastChatMessage { - /* * The role associated with this message payload. */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/client/OpenAIClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/client/OpenAIClient.java index 9ebf711c2..f4a679125 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/client/OpenAIClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/client/OpenAIClient.java @@ -26,17 +26,17 @@ public class OpenAIClient { public static final String OPENAI_KEY = "chatgpt.apiKey"; /** - * OPENAI接口域名 + * OPENAI interface domain name */ public static final String OPENAI_HOST = "chatgpt.apiHost"; /** - * 代理IP + * Proxy IP */ public static final String PROXY_HOST = "chatgpt.proxy.host"; /** - * 代理端口 + * proxy port */ public static final String PROXY_PORT = "chatgpt.proxy.port"; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/listener/OpenAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/listener/OpenAIEventSourceListener.java index ccadf6d68..0a026b223 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/listener/OpenAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/openai/listener/OpenAIEventSourceListener.java @@ -16,7 +16,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; /** - * 描述:OpenAIEventSourceListener + * description:OpenAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 @@ -44,9 +44,9 @@ public void onOpen(EventSource eventSource, Response response) { @SneakyThrows @Override public void onEvent(EventSource eventSource, String id, String type, String data) { - log.info("OpenAI返回数据:{}", data); + log.info("OpenAI returns data: {}", data); if (data.equals("[DONE]")) { - log.info("OpenAI返回数据结束了"); + log.info("OpenAI returns data ended"); sseEmitter.send(SseEmitter.event() .id("[DONE]") .data("[DONE]") @@ -56,7 +56,7 @@ public void onEvent(EventSource eventSource, String id, String type, String data } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - // 读取Json + // Read JSON ChatCompletionResponse completionResponse = mapper.readValue(data, ChatCompletionResponse.class); String text = completionResponse.getChoices().get(0).getDelta() == null ? completionResponse.getChoices().get(0).getText() @@ -74,7 +74,7 @@ public void onEvent(EventSource eventSource, String id, String type, String data @Override public void onClosed(EventSource eventSource) { sseEmitter.complete(); - log.info("OpenAI关闭sse连接..."); + log.info("OpenAI closes sse connection..."); } @Override @@ -83,7 +83,7 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { if (Objects.isNull(response)) { String message = t.getMessage(); if ("No route to host".equals(message)) { - message = "网络连接超时,请百度自行解决网络问题"; + message = "The network connection timed out. Please Baidu solve the network problem by yourself."; } Message sseMessage = new Message(); sseMessage.setContent(message); @@ -100,13 +100,13 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { String bodyString = null; if (Objects.nonNull(body)) { bodyString = body.string(); - log.error("OpenAI sse连接异常data:{}", bodyString, t); + log.error("OpenAI sse connection exception data: {}", bodyString, t); } else { - log.error("OpenAI sse连接异常data:{}", response, t); + log.error("OpenAI sse connection exception data: {}", response, t); } eventSource.cancel(); Message message = new Message(); - message.setContent("出现异常,请在帮助中查看详细日志:" + bodyString); + message.setContent("An exception occurred, please view the detailed log in the help:" + bodyString); sseEmitter.send(SseEmitter.event() .id("[ERROR]") .data(message)); @@ -115,7 +115,7 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { .data("[DONE]")); sseEmitter.complete(); } catch (Exception exception) { - log.error("发送数据异常:", exception); + log.error("Exception in sending data:", exception); } } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatQueryRequest.java index 70a631e8c..7bafb185a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatQueryRequest.java @@ -8,39 +8,39 @@ import lombok.Data; /** - * chat查询入参 + * Chat query input parameters * * @author moji - * @version ChatQueryRequest.java, v 0.1 2023年04月02日 13:28 moji Exp $ + * @version ChatQueryRequest.java, v 0.1 April 2, 2023 13:28 moji Exp $ * @date 2023/04/02 */ @Data public class ChatQueryRequest extends DataSourceBaseRequest { /** - * 输入消息 + * Enter message */ private String message; /** - * SQL功能类型 + * SQL function type * @see PromptType */ private String promptType; /** - * 表名列表 + * table name list */ private List tableNames; /** - * 目标SQL数据类型 + * Target SQL data type * @see ai.chat2db.server.domain.support.enums.DbTypeEnum */ private String destSqlType; /** - * 更多备注信息:如要求或限制条件等 + * More remarks: such as requirements or restrictions, etc. */ private String ext; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatRequest.java index 6b0e9b93b..fc6722bea 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/request/ChatRequest.java @@ -7,10 +7,10 @@ import lombok.Data; /** - * chat查询入参 + * Chat query input parameters * * @author moji - * @version ChatQueryRequest.java, v 0.1 2023年04月02日 13:28 moji Exp $ + * @version ChatQueryRequest.java, v 0.1 April 2, 2023 13:28 moji Exp $ * @date 2023/04/02 */ @Data diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/response/ChatChoice.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/response/ChatChoice.java index ec4b16b4d..871154a28 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/response/ChatChoice.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/response/ChatChoice.java @@ -21,28 +21,28 @@ public class ChatChoice implements Serializable { private long index; /** - * 请求参数stream为true返回是delta + * If the request parameter stream is true, the return value is delta. */ @JsonProperty("delta") private Message delta; /** - * 请求参数stream为false返回是message + * If the request parameter stream is false, the return value is message. */ @JsonProperty("message") private Message message; /** - * 请求参数stream为false返回是message + * If the request parameter stream is false, the return value is message. */ @JsonProperty("finish_reason") private String finishReason; /** - * 请求参数stream为true返回是text + * If the request parameter stream is true, the return value is text. */ private String text; /** - * 请求参数stream为true返回是logprobs + * If the request parameter stream is true, the return value is logprobs. */ private String logprobs; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java index 8140be3ea..b95c09348 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java @@ -15,17 +15,17 @@ public class RestAIClient { /** - * AI SQL选择的接口来源 + * Interface source selected by AI SQL */ public static final String AI_SQL_SOURCE = "ai.sql.source"; /** - * 自定义AI接口地址 + * Customized AI interface address */ public static final String REST_AI_URL = "rest.ai.url"; /** - * 自定义AI接口请求方法 + * Custom AI interface request method */ public static final String REST_AI_STREAM_OUT = "rest.ai.stream"; @@ -51,7 +51,7 @@ private static RestAiStreamClient singleton() { } /** - * 刷新客户端 + * Refresh client */ public static void refresh() { String apiUrl = ""; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAiStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAiStreamClient.java index fba46a4e6..7d5164e5b 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAiStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAiStreamClient.java @@ -26,7 +26,7 @@ import org.apache.commons.lang3.StringUtils; /** - * 自定义AI接口client + * Custom AI interface client * @author moji */ @Slf4j @@ -38,7 +38,7 @@ public class RestAiStreamClient { private String apiUrl; /** - * 是否流式接口 + * Whether to stream interface */ @Getter private Boolean stream; @@ -49,7 +49,7 @@ public class RestAiStreamClient { private OkHttpClient okHttpClient; /** - * 构造实例对象 + * Construct instance object * * @param url */ @@ -65,39 +65,39 @@ public RestAiStreamClient(String url, Boolean stream) { } /** - * 请求RESTAI接口 + * Request RESTAI interface * * @param prompt * @param eventSourceListener */ public void restCompletions(String prompt, EventSourceListener eventSourceListener) { - log.info("开始调用自定义AI, prompt:{}", prompt); + log.info("Start calling the custom AI, prompt:{}", prompt); RestAiCompletion completion = new RestAiCompletion(); completion.setPrompt(prompt); if (Objects.isNull(stream) || stream) { streamCompletions(completion, eventSourceListener); - log.info("结束调用流式输出自定义AI"); + log.info("End calling streaming output custom AI"); return; } nonStreamCompletions(completion, eventSourceListener); - log.info("结束调用非流式输出自定义AI"); + log.info("End calling non-streaming output custom AI"); } /** - * 问答接口 stream 形式 + * Q&A interface stream form * - * @param completion open ai 参数 - * @param eventSourceListener sse监听器 + * @param completion open ai parameter + * @param eventSourceListener sse listener * @see ConsoleEventSourceListener */ public void streamCompletions(RestAiCompletion completion, EventSourceListener eventSourceListener) { if (Objects.isNull(eventSourceListener)) { - log.error("参数异常:EventSourceListener不能为空"); + log.error("Parameter exception: EventSourceListener cannot be empty"); throw new ParamBusinessException(); } if (StringUtils.isBlank(completion.getPrompt())) { - log.error("参数异常:Prompt不能为空"); + log.error("Parameter exception: Prompt cannot be empty"); throw new ParamBusinessException(); } try { @@ -109,23 +109,23 @@ public void streamCompletions(RestAiCompletion completion, EventSourceListener e .url(this.apiUrl) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); } catch (Exception e) { - log.error("请求参数解析异常", e); + log.error("Request parameter parsing exception", e); throw new ParamBusinessException(); } } /** - * 请求非流式输出接口 + * Request non-streaming output interface * * @param completion * @param eventSourceListener */ public void nonStreamCompletions(RestAiCompletion completion, EventSourceListener eventSourceListener) { if (StringUtils.isBlank(completion.getPrompt())) { - log.error("参数异常:Prompt不能为空"); + log.error("Parameter exception: Prompt cannot be empty"); throw new ParamBusinessException(); } try { @@ -158,7 +158,7 @@ public void onResponse(Call call, Response response) throws IOException { }); } catch (Exception e) { - log.error("请求参数解析异常", e); + log.error("Request parameter parsing exception", e); throw new ParamBusinessException(); } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java index bb0e12caf..bb5524783 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java @@ -13,7 +13,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; /** - * 描述:RESTAIEventSourceListener + * description:RESTAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 @@ -41,10 +41,10 @@ public void onOpen(EventSource eventSource, Response response) { @SneakyThrows @Override public void onEvent(EventSource eventSource, String id, String type, String data) { - log.info("REST AI返回数据:{}", data); + log.info("REST AI return data:{}", data); String end = "[DONE]"; if (data.equals(end)) { - log.info("REST AI返回数据结束了"); + log.info("REST AI returns data finished"); sseEmitter.send(SseEmitter.event() .id(end) .data(end) @@ -67,7 +67,7 @@ public void onEvent(EventSource eventSource, String id, String type, String data @SneakyThrows @Override public void onClosed(EventSource eventSource) { - log.info("REST AI关闭sse连接..."); + log.info("REST AI close sse connection..."); sseEmitter.send(SseEmitter.event() .id("[DONE]") .data("[DONE]") @@ -112,7 +112,7 @@ public void onFailure(EventSource eventSource, Throwable t, Response response) { .data("[DONE]")); sseEmitter.complete(); } catch (Exception exception) { - log.error("发送数据异常:", exception); + log.error("Exception in sending data:", exception); } } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/model/RestAiCompletion.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/model/RestAiCompletion.java index 1af3c3cf7..06d09bf9c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/model/RestAiCompletion.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/model/RestAiCompletion.java @@ -9,7 +9,7 @@ /** * @author moji - * @version RestAiCompletion.java, v 0.1 2023年05月27日 14:00 moji Exp $ + * @version RestAiCompletion.java, v 0.1 May 27, 2023 14:00 moji Exp $ * @date 2023/05/27 */ @Data @@ -19,7 +19,7 @@ public class RestAiCompletion implements Serializable { /** - * 提示语 + * hint */ private String prompt; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/client/TongyiChatAIStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/client/TongyiChatAIStreamClient.java index 36e71614d..91635b353 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/client/TongyiChatAIStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/client/TongyiChatAIStreamClient.java @@ -96,7 +96,7 @@ private OkHttpClient okHttpClient() { } /** - * 构造 + * structure * * @return */ @@ -164,7 +164,7 @@ public TongyiChatAIStreamClient build() { } /** - * 问答接口 stream 形式 + * Q&A interface stream form * * @param chatMessages * @param eventSourceListener @@ -199,7 +199,7 @@ public void streamCompletions(List chatMessages, EventSourceLis .url(apiHost) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); log.info("finish invoking tongyi chat ai"); } catch (Exception e) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/listener/TongyiChatAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/listener/TongyiChatAIEventSourceListener.java index 361c427ea..388649a9e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/listener/TongyiChatAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/tongyi/listener/TongyiChatAIEventSourceListener.java @@ -21,7 +21,7 @@ import java.util.Objects; /** - * 描述:OpenAIEventSourceListener + * description:OpenAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/client/WenxinAIStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/client/WenxinAIStreamClient.java index b89744d60..19055b362 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/client/WenxinAIStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/client/WenxinAIStreamClient.java @@ -90,7 +90,7 @@ private OkHttpClient okHttpClient() { } /** - * 构造 + * structure * * @return */ @@ -158,7 +158,7 @@ public WenxinAIStreamClient build() { } /** - * 问答接口 stream 形式 + * Q&A interface stream form * * @param chatMessages * @param eventSourceListener @@ -186,7 +186,7 @@ public void streamCompletions(List chatMessages, EventSourceLis .url(apiHost) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); log.info("finish invoking fast chat ai"); } catch (Exception e) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/interceptor/AccessTokenInterceptor.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/interceptor/AccessTokenInterceptor.java index 5cca185f2..3b5212d68 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/interceptor/AccessTokenInterceptor.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/interceptor/AccessTokenInterceptor.java @@ -19,12 +19,12 @@ public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); HttpUrl originalHttpUrl = originalRequest.url(); - // 使用 HttpUrl.Builder 来添加查询参数 access_token + // Use HttpUrl.Builder to add query parameter access_token HttpUrl urlWithAccessToken = originalHttpUrl.newBuilder() .addQueryParameter("access_token", accessToken) .build(); - // 创建新的请求,将新的 URL 应用到它上面 + // Create a new request and apply the new URL to it Request newRequest = originalRequest.newBuilder() .url(urlWithAccessToken) .build(); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/listener/WenxinAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/listener/WenxinAIEventSourceListener.java index cee3504b3..8c8b461bb 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/listener/WenxinAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/wenxin/listener/WenxinAIEventSourceListener.java @@ -17,7 +17,7 @@ import java.util.Objects; /** - * 描述:OpenAIEventSourceListener + * description:OpenAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/client/ZhipuChatAIStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/client/ZhipuChatAIStreamClient.java index 550c929eb..04bdb4b9d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/client/ZhipuChatAIStreamClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/client/ZhipuChatAIStreamClient.java @@ -101,7 +101,7 @@ private OkHttpClient okHttpClient() { } /** - * 构造 + * structure * * @return */ @@ -179,7 +179,7 @@ public ZhipuChatAIStreamClient build() { } /** - * 问答接口 stream 形式 + * Q&A interface stream form * * @param chatMessages * @param eventSourceListener @@ -195,7 +195,7 @@ public void streamCompletions(List chatMessages, EventSourceLis } log.info("Zhipu Chat AI, prompt:{}", chatMessages.get(chatMessages.size() - 1).getContent()); try { - // 建议直接查看demo包代码,这里更新可能不及时 + // It is recommended to check the demo package code directly. The update here may not be timely. ZhipuChatCompletionsOptions completionsOptions = new ZhipuChatCompletionsOptions(); completionsOptions.setPrompt(chatMessages); completionsOptions.setModel(this.model); @@ -211,7 +211,7 @@ public void streamCompletions(List chatMessages, EventSourceLis .url(url) .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) .build(); - //创建事件 + //Create event EventSource eventSource = factory.newEventSource(request, eventSourceListener); log.info("finish invoking zhipu chat ai"); } catch (Exception e) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/listener/ZhipuChatAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/listener/ZhipuChatAIEventSourceListener.java index a8b1ae016..91ce3c788 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/listener/ZhipuChatAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/zhipu/listener/ZhipuChatAIEventSourceListener.java @@ -18,7 +18,7 @@ import java.util.Objects; /** - * 描述:OpenAIEventSourceListener + * description:OpenAIEventSourceListener * * @author https:www.unfbx.com * @date 2023-02-22 diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java index fd07c3ec3..0d8625cd9 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java @@ -56,7 +56,7 @@ public ActionResult systemConfig(@RequestBody SystemConfigRequest request) { } /** - * 保存ChatGPT相关配置 + * Save ChatGPT related configurations * * @param request * @return @@ -83,7 +83,7 @@ public ActionResult addChatGptSystemConfig(@RequestBody AIConfigCreateRequest re saveChat2dbAIConfig(request); break; case RESTAI: - saveRestAIConfig(request); + saveFastChatAIConfig(request); break; case AZUREAI: saveAzureAIConfig(request); @@ -330,12 +330,6 @@ public DataResult getChatAiSystemConfig(String aiSqlSource) { config.setModel(Objects.nonNull(azureDeployId.getData()) ? azureDeployId.getData().getContent() : ""); break; case RESTAI: - DataResult restAiUrl = configService.find(RestAIClient.REST_AI_URL); - DataResult restAiHttpMethod = configService.find(RestAIClient.REST_AI_STREAM_OUT); - config.setApiHost(Objects.nonNull(restAiUrl.getData()) ? restAiUrl.getData().getContent() : ""); - config.setStream(Objects.nonNull(restAiHttpMethod.getData()) ? Boolean.valueOf( - restAiHttpMethod.getData().getContent()) : Boolean.TRUE); - break; case FASTCHATAI: DataResult fastChatApiKey = configService.find(FastChatAIClient.FASTCHAT_API_KEY); DataResult fastChatApiHost = configService.find(FastChatAIClient.FASTCHAT_HOST); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AIConfigCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AIConfigCreateRequest.java index 188a9b434..378cf46e1 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AIConfigCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AIConfigCreateRequest.java @@ -45,7 +45,7 @@ public class AIConfigCreateRequest { /** * return data stream - * 非必填,默认值为TRUE + * Optional, default value is TRUE */ private Boolean stream = Boolean.TRUE; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AISystemConfigRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AISystemConfigRequest.java index bbf9b93e6..84a4d6b6c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AISystemConfigRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/request/AISystemConfigRequest.java @@ -24,43 +24,43 @@ public class AISystemConfigRequest { /** * OpenAi APIKEY - * 使用OpenAi接口时必填,可前往OpenAI官网查看APIKEY + * Required when using the OpenAi interface, you can go to the OpenAI official website to view APIKEY */ private String apiKey; /** * OpenAi APIHOST - * 非必填,默认值为 https://api.openai.com/ + * Optional, the default value is https://api.openai.com/ */ private String apiHost; /** - * http代理Host - * 非必填,用于设置请求OPENAI接口时的HTTP代理host + * http proxy Host + * Optional, used to set the HTTP proxy host when requesting the OPENAI interface */ private String httpProxyHost; /** - * http代理Port - * 非必填,用于设置请求OPENAI接口时的HTTP代理port + * http proxy Port + * Optional, used to set the HTTP proxy port when requesting the OPENAI interface */ private String httpProxyPort; /** - * AI来源 + * AI source * @see AiSqlSourceEnum */ private String aiSqlSource; /** - * 自定义AI接口 - * 选择自定义AI时必填,用于设置自定义AI的REST接口URL + * Customized AI interface + * Required when selecting custom AI, used to set the REST interface URL of the custom AI */ private String restAiUrl; /** - * Rest接口是否流式输出 - * 非必填,默认值为TRUE + * Whether the Rest interface has streaming output + * Optional, default value is TRUE */ private Boolean restAiStream = Boolean.TRUE; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/ChartController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/ChartController.java index 1660b8139..85e9b0e3d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/ChartController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/ChartController.java @@ -26,10 +26,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * 保存图表类 + * Save chart class * * @author moji - * @version ChartController.java, v 0.1 2022年09月18日 10:55 moji Exp $ + * @version ChartController.java, v 0.1 September 18, 2022 10:55 moji Exp $ * @date 2022/09/18 */ @RequestMapping("/api/chart") @@ -43,7 +43,7 @@ public class ChartController { private ChartWebConverter chartWebConverter; /** - * 根据id查询图表详情 + * Query chart details based on id * * @param id * @return @@ -58,7 +58,7 @@ public DataResult get(@PathVariable("id") Long id) { } /** - * 根据ID列表查询报表列表 + * Query report list based on ID list * * @param request * @return @@ -73,7 +73,7 @@ public ListResult list(ChartQueryRequest request) { } /** - * 保存图表 + * Save chart * * @param request * @return @@ -85,7 +85,7 @@ public DataResult create(@Valid @RequestBody ChartCreateRequest request) { } /** - * 更新图表 + * Update chart * * @param request * @return @@ -97,7 +97,7 @@ public ActionResult update(@RequestBody ChartUpdateRequest request) { } /** - * 删除图表 + * Delete chart * * @param id * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/DashboardController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/DashboardController.java index ecf48b9ac..61be4845c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/DashboardController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/DashboardController.java @@ -29,10 +29,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * 保存报表类 + * Save dashboard class * * @author moji - * @version DashboardController.java, v 0.1 2022年09月18日 10:55 moji Exp $ + * @version DashboardController.java, v 0.1 September 18, 2022 10:55 moji Exp $ * @date 2022/09/18 */ @RequestMapping("/api/dashboard") @@ -46,7 +46,7 @@ public class DashboardController { private DashboardWebConverter dashboardWebConverter; /** - * 查询报表列表 + * Query dashboard list * * @param request * @return @@ -60,7 +60,7 @@ public WebPageResult list(DashboardPageQueryParam request) { } /** - * 根据id查询报表详情 + * Query dashboard details based on id * * @param id * @return @@ -75,7 +75,7 @@ public DataResult get(@PathVariable("id") Long id) { } /** - * 保存报表 + * Save dashboard * * @param request * @return @@ -87,7 +87,7 @@ public DataResult create(@RequestBody DashboardCreateRequest request) { } /** - * 更新报表 + * Update dashboard * * @param request * @return @@ -99,7 +99,7 @@ public ActionResult update(@RequestBody DashboardUpdateRequest request) { } /** - * 删除报表 + * Delete dashboard * * @param id * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/ChartWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/ChartWebConverter.java index 6cca23e61..8603ec387 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/ChartWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/ChartWebConverter.java @@ -15,14 +15,14 @@ /** * @author moji - * @version ChartWebConverter.java, v 0.1 2023年06月09日 15:46 moji Exp $ + * @version ChartWebConverter.java, v 0.1 June 9, 2023 15:46 moji Exp $ * @date 2023/06/09 */ @Mapper(componentModel = "spring") public abstract class ChartWebConverter { /** - * 模型转换 + * Model conversion * * @param chart * @return @@ -33,7 +33,7 @@ public abstract class ChartWebConverter { public abstract ChartVO model2vo(Chart chart); /** - * 模型转换 + * Model conversion * * @param charts * @return @@ -41,7 +41,7 @@ public abstract class ChartWebConverter { public abstract List model2vo(List charts); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -49,7 +49,7 @@ public abstract class ChartWebConverter { public abstract ChartCreateParam req2param(ChartCreateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/DashboardWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/DashboardWebConverter.java index fed7ae7b1..27534a1a0 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/DashboardWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/converter/DashboardWebConverter.java @@ -13,14 +13,14 @@ /** * @author moji - * @version DashboardWebConverter.java, v 0.1 2023年06月09日 15:45 moji Exp $ + * @version DashboardWebConverter.java, v 0.1 June 9, 2023 15:45 moji Exp $ * @date 2023/06/09 */ @Mapper(componentModel = "spring") public abstract class DashboardWebConverter { /** - * 模型转换 + * Model conversion * * @param dashboard * @return @@ -28,7 +28,7 @@ public abstract class DashboardWebConverter { public abstract DashboardVO model2vo(Dashboard dashboard); /** - * 模型转换 + * Model conversion * * @param dashboards * @return @@ -36,7 +36,7 @@ public abstract class DashboardWebConverter { public abstract List model2vo(List dashboards); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -44,7 +44,7 @@ public abstract class DashboardWebConverter { public abstract DashboardCreateParam req2param(DashboardCreateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartCreateRequest.java index dc5620611..f59018ca5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartCreateRequest.java @@ -4,7 +4,7 @@ /** * @author moji - * @version ChartCreateParam.java, v 0.1 2023年06月09日 15:38 moji Exp $ + * @version ChartCreateParam.java, v 0.1 June 9, 2023 15:38 moji Exp $ * @date 2023/06/09 */ @Data @@ -12,41 +12,41 @@ public class ChartCreateRequest { /** - * 图表名称 + * Chart name */ private String name; /** - * 描述 + * description */ private String description; /** - * 图表信息 + * chart information */ private String schema; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据库类型 + * Database type */ private String type; /** - * db名称 + * DB name */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; /** - * ddl内容 + * ddl content */ private String ddl; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartQueryRequest.java index dedce0efd..373aa8f55 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartQueryRequest.java @@ -6,14 +6,14 @@ /** * @author moji - * @version ChartQueryRequest.java, v 0.1 2023年06月09日 17:46 moji Exp $ + * @version ChartQueryRequest.java, v 0.1 June 9, 2023 17:46 moji Exp $ * @date 2023/06/09 */ @Data public class ChartQueryRequest { /** - * 图表ID列表 + * Chart ID list */ private List ids; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartUpdateRequest.java index 05ecc3f5b..dc1f99f0d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/ChartUpdateRequest.java @@ -6,49 +6,49 @@ /** * @author moji - * @version ChartUpdateParam.java, v 0.1 2023年06月09日 15:39 moji Exp $ + * @version ChartUpdateParam.java, v 0.1 June 9, 2023 15:39 moji Exp $ * @date 2023/06/09 */ @Data public class ChartUpdateRequest { /** - * 主键 + * primary key */ private Long id; /** - * 图表名称 + * Chart name */ private String name; /** - * 图表信息 + * chart information */ private String schema; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据库类型 + * Database type */ private String type; /** - * db名称 + * DB name */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; /** - * ddl内容 + * ddl content */ private String ddl; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardCreateRequest.java index 85673e620..67c901aab 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardCreateRequest.java @@ -7,24 +7,24 @@ /** * @author moji - * @version DashboardSaveParam.java, v 0.1 2023年06月09日 15:29 moji Exp $ + * @version DashboardSaveParam.java, v 0.1 June 9, 2023 15:29 moji Exp $ * @date 2023/06/09 */ @Data public class DashboardCreateRequest { /** - * 报表名称 + * Dashboard name */ private String name; /** - * 报表布局信息 + * Dashboard layout information */ private String schema; /** - * 图表ID列表 + * Chart ID list */ private List chartIds; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardUpdateRequest.java index e9e46ef94..142bc0109 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/request/DashboardUpdateRequest.java @@ -6,30 +6,30 @@ /** * @author moji - * @version DashboardSaveParam.java, v 0.1 2023年06月09日 15:29 moji Exp $ + * @version DashboardSaveParam.java, v 0.1 June 9, 2023 15:29 moji Exp $ * @date 2023/06/09 */ @Data public class DashboardUpdateRequest { /** - * 主键 + * primary key */ private Long id; /** - * 报表名称 + * Dashboard name */ private String name; /** - * 报表布局信息 + * Dashboard layout information */ private String schema; /** - * 图表ID列表 + * Chart ID list */ private List chartIds; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/ChartVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/ChartVO.java index 85beee800..739a01d62 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/ChartVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/ChartVO.java @@ -6,75 +6,75 @@ /** * @author moji - * @version Chart.java, v 0.1 2023年06月09日 15:37 moji Exp $ + * @version Chart.java, v 0.1 June 9, 2023 15:37 moji Exp $ * @date 2023/06/09 */ @Data public class ChartVO { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 图表名称 + * Chart name */ private String name; /** - * 图表描述 + * Chart description */ private String description; /** - * 图表信息 + * chart information */ private String schema; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * 数据源名称 + * Data source name */ private String dataSourceName; /** - * 数据库类型 + * Database type */ private String type; /** - * db名称 + * DB name */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 是否可连接,false表示不可连接,表示数据源已被删除或不存在 + * Whether it can be connected, false means it cannot be connected, which means the data source has been deleted or does not exist. */ private Boolean connectable; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/DashboardVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/DashboardVO.java index 49185ce1f..230efac55 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/DashboardVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/dashboard/vo/DashboardVO.java @@ -7,44 +7,44 @@ /** * @author moji - * @version Dashboard.java, v 0.1 2023年06月09日 15:32 moji Exp $ + * @version Dashboard.java, v 0.1 June 9, 2023 15:32 moji Exp $ * @date 2023/06/09 */ @Data public class DashboardVO { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ private Date gmtCreate; /** - * 修改时间 + * modified time */ private Date gmtModified; /** - * 报表名称 + * Dashboard name */ private String name; /** - * 报表描述 + * Dashboard description */ private String description; /** - * 报表布局信息 + * Dashboard layout information */ private String schema; /** - * 图表ID列表 + * Chart ID list */ private List chartIds; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/DataSourceController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/DataSourceController.java index 37c8e4c9d..9e820eb36 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/DataSourceController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/DataSourceController.java @@ -51,10 +51,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * 数据库连接类 + * Database connection class * * @author moji - * @version ConnectionController.java, v 0.1 2022年09月16日 14:07 moji Exp $ + * @version ConnectionController.java, v 0.1 September 16, 2022 14:07 moji Exp $ * @date 2022/09/16 */ @ConnectionInfoAspect @@ -80,7 +80,7 @@ public class DataSourceController { private SSHWebConverter sshWebConverter; /** - * 数据库连接测试 + * Database connection test * * @param request * @return @@ -92,7 +92,7 @@ public ActionResult preConnect(@RequestBody DataSourceTestRequest request) { } /** - * 数据库连接测试 + * Database connection test * * @param request * @return @@ -114,7 +114,7 @@ public ActionResult sshConnect(@RequestBody SSHTestRequest request) { } /** - * 数据库连接 + * Database connection * * @param request * @return @@ -127,7 +127,7 @@ public ListResult attach(@Valid @NotNull DataSourceAttachRequest req } /** - * 关闭数据库连接 + * Close database connection * * @param request * @return @@ -138,7 +138,7 @@ public ActionResult close(@Valid @NotNull DataSourceCloseRequest request) { } /** - * Console连接 + * Console connection * * @param request * @return @@ -150,7 +150,7 @@ public ActionResult connect(@Valid @NotNull ConsoleConnectRequest request) { } /** - * 关闭Console连接 + * Close the Console connection * * @param request * @return @@ -162,7 +162,7 @@ public ActionResult closeConsole(@Valid @NotNull ConsoleCloseRequest request) { } /** - * 查询我建立的数据库连接 + * Query the database connection I established * * @param request * @return @@ -177,7 +177,7 @@ public WebPageResult list(DataSourceQueryRequest request) { } /** - * 获取连接内容 + * Get connection content * * @param id * @return @@ -195,7 +195,7 @@ public DataResult queryById(@PathVariable("id") Long id) { } /** - * 保存连接 + * save connection * * @param request * @return @@ -207,7 +207,7 @@ public DataResult create(@RequestBody DataSourceCreateRequest request) { } /** - * 更新连接 + * Update connection * * @param request * @return @@ -219,7 +219,7 @@ public DataResult update(@RequestBody DataSourceUpdateRequest request) { } /** - * 克隆连接 + * clone connection * * @param request * @return @@ -230,7 +230,7 @@ public DataResult copy(@RequestBody DataSourceCloneRequest request) { } /** - * 删除连接 + * Delete connection * * @param id * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/DataSourceWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/DataSourceWebConverter.java index 26802232e..5245bdbaf 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/DataSourceWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/DataSourceWebConverter.java @@ -25,14 +25,14 @@ /** * @author moji - * @version DataSourceWebConverter.java, v 0.1 2022年09月23日 16:45 moji Exp $ + * @version DataSourceWebConverter.java, v 0.1 September 23, 2022 16:45 moji Exp $ * @date 2022/09/23 */ @Mapper(componentModel = "spring", imports = {DataSourceKindEnum.class}) public abstract class DataSourceWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -44,7 +44,7 @@ public abstract class DataSourceWebConverter { public abstract DataSourceCreateParam createReq2param(DataSourceCreateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -55,7 +55,7 @@ public abstract class DataSourceWebConverter { public abstract DataSourceUpdateParam updateReq2param(DataSourceUpdateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -63,7 +63,7 @@ public abstract class DataSourceWebConverter { public abstract DataSourcePageQueryParam queryReq2param(DataSourceQueryRequest request); /** - * 模型转换 + * Model conversion * * @param dataSource * @return @@ -74,7 +74,7 @@ public abstract class DataSourceWebConverter { public abstract DataSourceVO dto2vo(DataSource dataSource); /** - * 模型转换 + * Model conversion * * @param dataSources * @return @@ -82,7 +82,7 @@ public abstract class DataSourceWebConverter { public abstract List dto2vo(List dataSources); /** - * 模型转换 + * Model conversion * * @param databaseDTO * @return @@ -90,7 +90,7 @@ public abstract class DataSourceWebConverter { public abstract DatabaseVO databaseDto2vo(Database databaseDTO); /** - * 模型转换 + * Model conversion * * @param databaseDTOS * @return @@ -98,7 +98,7 @@ public abstract class DataSourceWebConverter { public abstract List databaseDto2vo(List databaseDTOS); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -106,7 +106,7 @@ public abstract class DataSourceWebConverter { public abstract DataSourcePreConnectParam testRequest2param(DataSourceTestRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -114,7 +114,7 @@ public abstract class DataSourceWebConverter { public abstract ConsoleConnectParam request2connectParam(ConsoleConnectRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/SSHWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/SSHWebConverter.java index 6d6046818..81147ce78 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/SSHWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/converter/SSHWebConverter.java @@ -14,7 +14,7 @@ public abstract class SSHWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleCloseRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleCloseRequest.java index 83ee9b48f..25fb77e06 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleCloseRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleCloseRequest.java @@ -4,14 +4,14 @@ /** * @author moji - * @version ConsoleContentRequest.java, v 0.1 2022年10月30日 15:52 moji Exp $ + * @version ConsoleContentRequest.java, v 0.1 October 30, 2022 15:52 moji Exp $ * @date 2022/10/30 */ @Data public class ConsoleCloseRequest extends DataSourceBaseRequest implements DataSourceConsoleRequestInfo{ /** - * 控制台id + * console id */ private Long consoleId; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleConnectRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleConnectRequest.java index 1f09f8824..7eb7dba2e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleConnectRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/ConsoleConnectRequest.java @@ -4,14 +4,14 @@ /** * @author moji - * @version ConsoleContentRequest.java, v 0.1 2022年10月30日 15:52 moji Exp $ + * @version ConsoleContentRequest.java, v 0.1 October 30, 2022 15:52 moji Exp $ * @date 2022/10/30 */ @Data public class ConsoleConnectRequest extends DataSourceBaseRequest implements DataSourceConsoleRequestInfo { /** - * 控制台id + * console id */ private Long consoleId; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceAttachRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceAttachRequest.java index fa105b81b..4035c3389 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceAttachRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceAttachRequest.java @@ -7,14 +7,14 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceAttachRequest implements DataSourceBaseRequestInfo{ /** - * 主键id + * primary key id */ @NotNull private Long id; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequest.java index b178ebf18..8cdc83e8e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequest.java @@ -6,25 +6,25 @@ /** * @author moji - * @version MysqlBaseRequest.java, v 0.1 2022年09月18日 11:51 moji Exp $ + * @version MysqlBaseRequest.java, v 0.1 September 18, 2022 11:51 moji Exp $ * @date 2022/09/18 */ @Data public class DataSourceBaseRequest implements DataSourceBaseRequestInfo{ /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequestInfo.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequestInfo.java index 25b68ca85..8dfe798da 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequestInfo.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceBaseRequestInfo.java @@ -8,13 +8,13 @@ public interface DataSourceBaseRequestInfo { /** - * 获取datasoure id + * Get datasoure id * @return */ Long getDataSourceId(); /** - * 获取datasoure name + * get datasoure name * @return */ String getDatabaseName(); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloneRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloneRequest.java index 67864a095..d6b640d69 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloneRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloneRequest.java @@ -5,14 +5,14 @@ /** * @author moji - * @version ConnectionCloneRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCloneRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceCloneRequest { /** - * 主键id + * primary key id */ private Long id; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloseRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloseRequest.java index 543b5a417..f80e84eb5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloseRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCloseRequest.java @@ -7,14 +7,14 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceCloseRequest { /** - * 主键id + * primary key id */ @NotNull private Long id; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCreateRequest.java index 4a8ee6f52..e1fb0c757 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceCreateRequest.java @@ -13,41 +13,41 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceCreateRequest { /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ @NotNull private String url; /** - * 连接用户名 + * Connect username */ private String user; /** - * 密码 + * password */ @NotNull private String password; /** - * 认证类型 + * Certification type */ private String authenticationType; /** - * 连接类型 + * Connection Type */ @NotNull private String type; @@ -84,36 +84,34 @@ public class DataSourceCreateRequest { /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 环境id + * environment id */ @NotNull private Long environmentId; - - /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceQueryRequest.java index c4448b677..bc88a01f3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceQueryRequest.java @@ -5,18 +5,18 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceQueryRequest extends PageQueryRequest { /** - * 别名模糊搜索词 + * Alias fuzzy search terms */ private String searchKey; /** - * 连接类型 + * Connection Type * * @see ai.chat2db.server.domain.api.enums.DataSourceKindEnum */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceTestRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceTestRequest.java index 30b3966a5..0eee8614c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceTestRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceTestRequest.java @@ -13,42 +13,42 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceTestRequest { /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ @NotNull private String url; /** - * 连接用户 + * Connect users */ private String user; /** - * 密码 + * password */ @NotNull private String password; /** - * 数据库连接类型 + * Database connection type */ @NotNull private String type; /** - * 认证类型 + * Certification type */ private String authenticationType; @@ -84,17 +84,17 @@ public class DataSourceTestRequest { /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceUpdateRequest.java index c10fa18a3..23a260713 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/request/DataSourceUpdateRequest.java @@ -13,51 +13,51 @@ /** * @author moji - * @version ConnectionCreateRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionCreateRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceUpdateRequest { /** - * 主键id + * primary key id */ @NotNull private Long id; /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 连接用户 + * Connect users */ private String user; /** - * 密码 + * password */ private String password; /** - * 连接类型 + * Connection Type */ private String type; /** - * 环境类型 + * environment type * @see EnvTypeEnum */ private String envType; /** - * 环境id + * environment id */ private Integer environmentId; @@ -93,27 +93,27 @@ public class DataSourceUpdateRequest { /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DataSourceVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DataSourceVO.java index f0a3c2017..7d34178d4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DataSourceVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DataSourceVO.java @@ -10,29 +10,29 @@ /** * @author moji - * @version ConnectionVO.java, v 0.1 2022年09月16日 14:15 moji Exp $ + * @version ConnectionVO.java, v 0.1 September 16, 2022 14:15 moji Exp $ * @date 2022/09/16 */ @Data public class DataSourceVO { /** - * 主键id + * primary key id */ private Long id; /** - * 连接别名 + * Connection alias */ private String alias; /** - * 连接地址 + * connection address */ private String url; /** - * 连接用户 + * Connect users */ private String user; @@ -42,16 +42,16 @@ public class DataSourceVO { private String password; /** - * 认证类型 + * Certification type */ private String authenticationType; /** - * 连接类型 + * Connection Type */ private String type; /** - * 环境类型 + * environment type */ private String envType; @@ -86,56 +86,55 @@ public class DataSourceVO { private String driver; /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; /** - * 驱动配置 + * Driver configuration */ private DriverConfig driverConfig; /** - * 环境id + * environment id */ private Long environmentId; /** - * 环境 + * environment */ private SimpleEnvironmentVO environment; /** - * 连接类型 + * Connection Type * * @see ai.chat2db.server.domain.api.enums.DataSourceKindEnum */ private String kind; - /** - * 服务名称 + * service name */ private String serviceName; /** - * 服务类型 + * Service type */ private String serviceType; /** - * 是否支持数据库 + * Whether to support database */ private boolean supportDatabase; /** - * 是否支持schema + * Whether to support schema */ private boolean supportSchema; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DatabaseVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DatabaseVO.java index 162be4076..8689c14d0 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DatabaseVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/DatabaseVO.java @@ -4,24 +4,24 @@ /** * @author moji - * @version DatabaseVO.java, v 0.1 2022年09月16日 17:24 moji Exp $ + * @version DatabaseVO.java, v 0.1 September 16, 2022 17:24 moji Exp $ * @date 2022/09/16 */ @Data public class DatabaseVO { /** - * DB名称 + * DB name */ private String name; /** - * DB描述 + * DB description */ private String description; /** - * DB下表数量或key数量 + * The number of tables or keys under DB */ private Integer count; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/EnvVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/EnvVO.java index ca4304250..5f27f2dc9 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/EnvVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/data/source/vo/EnvVO.java @@ -4,19 +4,19 @@ /** * @author moji - * @version EnvVO.java, v 0.1 2022年09月18日 14:06 moji Exp $ + * @version EnvVO.java, v 0.1 September 18, 2022 14:06 moji Exp $ * @date 2022/09/18 */ @Data public class EnvVO { /** - * 环境code + * environment code */ private String code; /** - * 环境名称 + * environment name */ private String name; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/driver/JdbcDriverController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/driver/JdbcDriverController.java index 523dafcf8..f31788c23 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/driver/JdbcDriverController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/driver/JdbcDriverController.java @@ -26,7 +26,7 @@ * JDBC driver management * * @author moji - * @version JdbcDriverController.java, v 0.1 2022年09月16日 17:41 moji Exp $ + * @version JdbcDriverController.java, v 0.1 September 16, 2022 17:41 moji Exp $ * @date 2022/09/16 */ @RequestMapping("/api/jdbc/driver") @@ -37,7 +37,7 @@ public class JdbcDriverController { private JdbcDriverService jdbcDriverService; /** - * 查询当前DB驱动信息 + * Query current DB driver information * * @param dbType * @return @@ -48,7 +48,7 @@ public DataResult list(@RequestParam String dbType) { } /** - * 下载驱动 + * Download driver * * @param dbType * @return @@ -60,7 +60,7 @@ public ActionResult download(@RequestParam String dbType) { } /** - * 上传驱动 + * Upload driver * * @param multipartFiles * @return @@ -97,7 +97,7 @@ public ActionResult save(@RequestBody JdbcDriverRequest request) { } ///** - // * 删除驱动 + // * Delete driver // * // * @param request // * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/ConverterController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/ConverterController.java index 08348a48c..7d5beee7a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/ConverterController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/ConverterController.java @@ -32,7 +32,7 @@ public class ConverterController { private ConverterService converterService; /** - * 导出教程 + * Export tutorial * * @param file file * @return DataResult @@ -41,11 +41,11 @@ public class ConverterController { @SneakyThrows @PostMapping("/ncx/upload") public DataResult ncxUploadFile(@RequestParam("file") MultipartFile file) { - log.info("开始上传ncx"); - // 验证文件后缀 + log.info("Start uploading ncx"); + // Verify file suffix String fileExtension = FileUtils.getFileExtension(Objects.requireNonNull(file.getOriginalFilename())); if (!fileExtension.equalsIgnoreCase(FileUtils.ConfigFile.NCX.name())) { - return DataResult.error("1", "上传的文件必须是ncx文件!"); + return DataResult.error("1", "The uploaded file must be an ncx file!"); } File temp = new File(ConfigUtils.CONFIG_BASE_PATH + File.separator + UUID.randomUUID() + ".tmp"); file.transferTo(temp); @@ -55,10 +55,10 @@ public DataResult ncxUploadFile(@RequestParam("file") MultipartFile fi @SneakyThrows @PostMapping("/dbp/upload") public DataResult edbpUploadFile(@RequestParam("file") MultipartFile file) { - // 验证文件后缀 + // Verify file suffix String fileExtension = FileUtils.getFileExtension(Objects.requireNonNull(file.getOriginalFilename())); if (!fileExtension.equalsIgnoreCase(FileUtils.ConfigFile.DBP.name())) { - return DataResult.error("1", "上传的文件必须是dbp文件!"); + return DataResult.error("1", "The uploaded file must be a dbp file!"); } File temp = new File(ConfigUtils.CONFIG_BASE_PATH + File.separator + UUID.randomUUID() + ".tmp"); file.transferTo(temp); @@ -67,8 +67,8 @@ public DataResult edbpUploadFile(@RequestParam("file") MultipartFile f /** - * 导入datagrip的连接信息,通过 ctrl/cmd + c(shift多选)复制连接,再导入进来 - * 目前复制的连接信息里面是没有密码的、ssh连接信息也没有 + * Import the connection information of datagrip, copy the connection through ctrl/cmd + c (shift multiple selection), and then import it. + * There is no password in the currently copied connection information, and there is no ssh connection information either. * * @param text text * @return DataResult diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/CommonCipher.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/CommonCipher.java index 55fe1f86a..a57f91264 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/CommonCipher.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/CommonCipher.java @@ -3,7 +3,7 @@ import java.util.Formatter; /** - * CommonCipher 公共加/解密 + * CommonCipher Public encryption/decryption * * @author lzy */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat11Cipher.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat11Cipher.java index dc3c053c2..7a80ac05f 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat11Cipher.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat11Cipher.java @@ -9,7 +9,7 @@ import java.util.Arrays; /** - * Navicat11及以下密码加密解密 + * Navicat11 and below password encryption and decryption * * @author lzy */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat12Cipher.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat12Cipher.java index 45fdd48b0..a0db4aee2 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat12Cipher.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/cipher/Navicat12Cipher.java @@ -8,7 +8,7 @@ import java.nio.charset.StandardCharsets; /** - * Navicat12及以上密码加密解密 + * Navicat12 and above password encryption and decryption * * @author lzy */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/dbeaver/DefaultValueEncryptor.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/dbeaver/DefaultValueEncryptor.java index 28ed1ef07..ba6026fc7 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/dbeaver/DefaultValueEncryptor.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/dbeaver/DefaultValueEncryptor.java @@ -55,7 +55,7 @@ public DefaultValueEncryptor(SecretKey secretKey) { } /** - * 通过 DBeaver 源码查看到默认的 SecretKey + * View the default SecretKey through DBeaver source code **/ public static SecretKey getLocalSecretKey() { return new SecretKeySpec(LOCAL_KEY_CACHE, DefaultValueEncryptor.KEY_ALGORITHM); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/enums/VersionEnum.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/enums/VersionEnum.java index 18b34e71e..3b5103186 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/enums/VersionEnum.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/enums/VersionEnum.java @@ -1,7 +1,7 @@ package ai.chat2db.server.web.api.controller.ncx.enums; /** - * navicat版本枚举(版本区分navicat加密算法) + * navicat version enumeration (version distinguishes navicat encryption algorithm) * * @author lzy */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/factory/CipherFactory.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/factory/CipherFactory.java index 53253d966..25f107fa3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/factory/CipherFactory.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/factory/CipherFactory.java @@ -18,7 +18,7 @@ @Service public class CipherFactory { /** - * NavicatCipher缓存池 + * NavicatCipher cache pool */ private static final Map REPORT_POOL = new ConcurrentHashMap<>(0); @@ -28,9 +28,9 @@ public class CipherFactory { } /** - * 获取对应加/解密方法 + * Get the corresponding encryption/decryption method * - * @param type 类型 + * @param type type * @return ITokenGranter */ @SneakyThrows diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/service/impl/ConverterServiceImpl.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/service/impl/ConverterServiceImpl.java index e372baf30..5d6aa03c2 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/service/impl/ConverterServiceImpl.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ncx/service/impl/ConverterServiceImpl.java @@ -68,16 +68,16 @@ public class ConverterServiceImpl implements ConverterService { private static CommonCipher cipher; /** - * 连接信息头部 + * Connection information header **/ private static final String DATASOURCE_SETTINGS = "#DataSourceSettings#"; private static final String XML_HEADER = ""; /** - * xml连接信息开始标志位 + * xml connection information start flag **/ private static final String BEGIN = "#BEGIN#"; /** - * 密码json的key + * Password json key **/ private static final String connection = "#connection"; @@ -86,11 +86,11 @@ private DataSourceMapper getDataSourceMapper(){ return Dbutils.getMapper(DataSourceMapper.class); } /** - * jdbc通用匹配ip和端口 + * jdbc universal matching ip and port */ public static final Pattern IP_PORT = Pattern.compile("jdbc:(?[a-z]+)://(?[a-zA-Z0-9-//.]+):(?[0-9]+)"); /** - * oracle匹配ip和端口 + * oracle matching ip and port */ public static final Pattern ORACLE_IP_PORT = Pattern.compile("jdbc:(?[a-z]+):(?[a-z]+):@(?[a-zA-Z0-9-//.]+):(?[0-9]+)"); @@ -98,20 +98,20 @@ private DataSourceMapper getDataSourceMapper(){ public UploadVO uploadFile(File file) { UploadVO vo = new UploadVO(); try { - // List>> 要导入的连接 + // List>> The connection to be imported List>> configMap = new ArrayList<>(); - //1、创建一个DocumentBuilderFactory的对象 + //1、Create a DocumentBuilderFactory object DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - //2、创建一个DocumentBuilder的对象 - //创建DocumentBuilder对象 + //2、Create a DocumentBuilder object + //Create DocumentBuilder object DocumentBuilder db = dbf.newDocumentBuilder(); - //3、通过DocumentBuilder对象的parser方法加载xml文件到当前项目下 + //3、Load the xml file into the current project through the parser method of the DocumentBuilder object Document document = db.parse(file); - //获取所有Connections节点的集合 + //Get the collection of all Connections nodes NodeList connectList = document.getElementsByTagName("Connection"); NodeList nodeList = document.getElementsByTagName("Connections"); - //选中第一个节点 + //Select the first node NamedNodeMap verMap = nodeList.item(0).getAttributes(); double version = Double.parseDouble((verMap.getNamedItem("Ver").getNodeValue())); if (version <= NAVICAT11) { @@ -119,18 +119,18 @@ public UploadVO uploadFile(File file) { } else { cipher = CipherFactory.get(VersionEnum.navicat12more.name()); } - //配置map + //Configure map Map> connectionMap = new HashMap<>(); - //遍历每一个Connections节点 + //Traverse each Connections node for (int i = 0; i < connectList.getLength(); i++) { - //通过 item(i)方法 获取一个Connection节点,nodeList的索引值从0开始 + //Get a Connection node through the item(i) method, the index value of nodeList starts from 0 Node connect = connectList.item(i); - //获取Connection节点的所有属性集合 + //Get the collection of all properties of the Connection node NamedNodeMap attrs = connect.getAttributes(); - //遍历Connection的属性 + //Traverse the properties of Connection Map map = new HashMap<>(0); for (int j = 0; j < attrs.getLength(); j++) { - //通过item(index)方法获取connect节点的某一个属性 + //Obtain a certain attribute of the connect node through the item(index) method Node attr = attrs.item(j); map.put(attr.getNodeName(), attr.getNodeValue()); } @@ -138,10 +138,10 @@ public UploadVO uploadFile(File file) { } configMap.add(connectionMap); log.info("insert to db, param:{}", JSON.toJSONString(configMap)); - // 将获取到navicat导入的链接,写入chat2db的h2数据库 + // Get the link imported from navicat and write it into the h2 database of chat2db insertDBConfig(configMap); log.info("insert to h2 success"); - //删除临时文件 + //Delete temporary files FileUtils.delete(file); } catch (Exception e) { throw new RuntimeException(e); @@ -154,7 +154,7 @@ public UploadVO uploadFile(File file) { public UploadVO dbpUploadFile(File file) { UploadVO vo = new UploadVO(); Document metaTree; - //等待删除的projects + //Projects waiting to be deleted List projects = new ArrayList<>(); try (ZipFile zipFile = new ZipFile(file, ZipFile.OPEN_READ)) { ZipEntry metaEntry = zipFile.getEntry(ExportConstants.META_FILENAME); @@ -170,18 +170,18 @@ public UploadVO dbpUploadFile(File file) { if (projectsElement != null) { final Collection projectList = XMLUtils.getChildElementList(projectsElement, ExportConstants.TAG_PROJECT); for (Element projectElement : projectList) { - //获取项目名称 + //Get project name String projectName = projectElement.getAttribute(ExportConstants.ATTR_NAME); - //导入匹配文件目录 + //Import matching file directory String config = ConfigUtils.CONFIG_BASE_PATH + File.separator + projectName + File.separator + ExportConstants.CONFIG_FILE; importDbeaverConfig(new File(config), projectElement, - //不可替换成File.separator + //Cannot be replaced by File.separator ExportConstants.DIR_PROJECTS + "/" + projectName + "/", zipFile); - //加入删除名单 + //Add to delete list projects.add(projectName); - //配置的json文件 + //Configured json file File json = new File(config + File.separator + ExportConstants.CONFIG_DATASOURCE_FILE); JSONObject jsonObject = JSON.parseObject(new FileInputStream(json)); JSONObject connections = jsonObject.getJSONObject(ExportConstants.DIR_CONNECTIONS); @@ -189,29 +189,29 @@ public UploadVO dbpUploadFile(File file) { for (String key : keys) { JSONObject configurations = connections.getJSONObject(key); JSONObject configuration = configurations.getJSONObject(ExportConstants.DIR_CONFIGURATION); - //匹配数据库类型 + //Match database type String provider = configurations.getString("provider"); if (provider.equals(ExportConstants.GENERIC)) { - //自定义驱动 + //Custom driverCustom driver JSONObject drivers = jsonObject.getJSONObject(ExportConstants.DIR_DRIVERS); - //获得驱动id + //Get driver id String driverId = configurations.getString("driver"); - //获得所有generic + //Get all generic JSONObject generics = drivers.getJSONObject(provider); - //获得自己的驱动 + //Get your own driver JSONObject generic = generics.getJSONObject(driverId); - //如果不存在,则不导入 + //If it does not exist, it will not be imported. if (null == generic) { continue; } - //赋值驱动名称,用来确定数据库的类型 + //Assign driver name to determine the type of database provider = generic.getString("name"); } DataBaseType dataBaseType = DataBaseType.matchType(provider.toUpperCase()); DataSourceDO dataSourceDO; - //未匹配到数据库类型,如:dbeaver支持自定义驱动等,但chat2DB暂不支持 + //The database type is not matched. For example: dbeaver supports custom drivers, etc., but chat2DB does not support it yet. if (null != dataBaseType) { - //密码信息 + //Password information File credentials = new File(config + File.separator + ExportConstants.CONFIG_CREDENTIALS_FILE); DefaultValueEncryptor defaultValueEncryptor = new DefaultValueEncryptor(DefaultValueEncryptor.getLocalSecretKey()); JSONObject credentialsJson = JSON.parseObject(defaultValueEncryptor.decryptValue(Files.readAllBytes(credentials.toPath()))); @@ -219,13 +219,13 @@ public UploadVO dbpUploadFile(File file) { Date dateTime = new Date(); dataSourceDO.setGmtCreate(dateTime); dataSourceDO.setGmtModified(dateTime); - //插入用户id + //Insert user id dataSourceDO.setUserId(ContextUtils.getUserId()); dataSourceDO.setAlias(configurations.getString("name")); dataSourceDO.setHost(configuration.getString("host")); dataSourceDO.setPort(configuration.getString("port")); dataSourceDO.setUrl(configuration.getString("url")); - //ssh设置为false + //ssh is set to false SSHInfo sshInfo = new SSHInfo(); sshInfo.setUse(false); dataSourceDO.setSsh(JSON.toJSONString(sshInfo)); @@ -245,9 +245,9 @@ public UploadVO dbpUploadFile(File file) { } } } - //删除临时文件 + //Delete temporary files FileUtils.delete(file); - //删除导入dbeaver时,dbp产生的临时配置文件 + //Delete the temporary configuration file generated by dbp when importing dbeaver projects.forEach(v -> FileUtils.delete(new File(ConfigUtils.CONFIG_BASE_PATH + File.separator + v))); return vo; } @@ -290,28 +290,28 @@ public UploadVO datagripUploadFile(String text) { } } for (String config : configs) { - //1、创建一个DocumentBuilderFactory的对象 + //1、Create a DocumentBuilderFactory object DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - //2、创建一个DocumentBuilder的对象 - //创建DocumentBuilder对象 + //2、Create a DocumentBuilder object + //Create DocumentBuilder object DocumentBuilder db = dbf.newDocumentBuilder(); - //3、通过DocumentBuilder对象的parser方法加载xml文件到当前项目下 + //3、Load the xml file into the current project through the parser method of the DocumentBuilder object try (InputStream inputStream = new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8))) { Document document = db.parse(inputStream); - // 获取根元素 + // Get the root element Element rootElement = document.getDocumentElement(); - //创建datasource + //Create datasource DataSourceDO dataSourceDO = new DataSourceDO(); Date dateTime = new Date(); dataSourceDO.setGmtCreate(dateTime); dataSourceDO.setGmtModified(dateTime); dataSourceDO.setAlias(rootElement.getAttribute("name")); - //插入用户id + //Insert user id dataSourceDO.setUserId(ContextUtils.getUserId()); - // 获取子元素 database-info + // Get child elements database-info Element databaseInfoElement = (Element) rootElement.getElementsByTagName("database-info").item(0); - // 获取连接相关信息 + // Get connection related information String type = databaseInfoElement.getAttribute("dbms"); String jdbcUrl = rootElement.getElementsByTagName("jdbc-url").item(0).getTextContent(); String username = rootElement.getElementsByTagName("user-name").item(0).getTextContent(); @@ -319,24 +319,24 @@ public UploadVO datagripUploadFile(String text) { String host = ""; String port = ""; if (type.equals(DataBaseType.ORACLE.name())) { - // 创建 Matcher 对象 + // Create Matcher object Matcher matcher = ORACLE_IP_PORT.matcher(jdbcUrl); - // 查找匹配的 IP 地址和端口号 + // Find matching IP address and port number if (matcher.find()) { host = matcher.group("host"); port = matcher.group("port"); } } else { - // 创建 Matcher 对象 + // Create Matcher object Matcher matcher = IP_PORT.matcher(jdbcUrl); - // 查找匹配的 IP 地址和端口号 + // Find matching IP address and port number if (matcher.find()) { host = matcher.group("host"); port = matcher.group("port"); } } - //ssh设置为false + //ssh is set to false SSHInfo sshInfo = new SSHInfo(); sshInfo.setUse(false); dataSourceDO.setSsh(JSON.toJSONString(sshInfo)); @@ -353,20 +353,20 @@ public UploadVO datagripUploadFile(String text) { } /** - * 写入到数据库 + * Write to database * - * @param list 读取ncx文件的数据 + * @param list Read data from ncx file */ @SneakyThrows public void insertDBConfig(List>> list) { for (Map> map : list) { for (Map.Entry> valueMap : map.entrySet()) { Map resultMap = valueMap.getValue(); - // mysql的版本还无法区分 + // The version of mysql cannot be distinguished yet DataBaseType dataBaseType = DataBaseType.matchType(resultMap.get("ConnType")); DataSourceDO dataSourceDO; if (null == dataBaseType) { - //未匹配到数据库类型,如:navicat支持MongoDB等,但chat2DB暂不支持 + //The database type is not matched. For example: navicat supports MongoDB, etc., but chat2DB does not support it yet. continue; } else { dataSourceDO = new DataSourceDO(); @@ -374,7 +374,7 @@ public void insertDBConfig(List>> list) { dataSourceDO.setPort(resultMap.get("Port")); dataSourceDO.setUrl(String.format(dataBaseType.getUrlString(), dataSourceDO.getHost(), dataSourceDO.getPort())); } - // 解密密码 + // Decrypt password String password = cipher.decryptString(resultMap.getOrDefault("Password", "")); Date dateTime =new Date(); dataSourceDO.setGmtCreate(dateTime); @@ -382,9 +382,9 @@ public void insertDBConfig(List>> list) { dataSourceDO.setAlias(resultMap.get("ConnectionName")); dataSourceDO.setUserName(resultMap.get("UserName")); dataSourceDO.setType(resultMap.get("ConnType")); - //插入用户id + //Insert user id dataSourceDO.setUserId(ContextUtils.getUserId()); - //password 为解密出来的密文,再使用chat2db的加密 + //Password is the decrypted ciphertext, and then uses chat2db for encryption. DesUtil desUtil = new DesUtil(DesUtil.DES_KEY); String encryptStr = desUtil.encrypt(password, "CBC"); dataSourceDO.setPassword(encryptStr); @@ -396,11 +396,11 @@ public void insertDBConfig(List>> list) { sshInfo.setHostName(resultMap.get("SSH_Host")); sshInfo.setPort(resultMap.get("SSH_Port")); sshInfo.setUserName(resultMap.get("SSH_UserName")); - // 目前chat2DB只支持 password 和 Private key + // Currently chat2DB only supports password and Private key boolean passwordType = "password".equalsIgnoreCase(resultMap.get("SSH_AuthenMethod")); sshInfo.setAuthenticationType(passwordType ? "password" : "Private key"); if (passwordType) { - // 解密密码 + // Decrypt password String ssh_password = cipher.decryptString(resultMap.getOrDefault("SSH_Password", "")); sshInfo.setPassword(ssh_password); } else { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/OperationLogController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/OperationLogController.java index 3ec810b08..c6b499830 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/OperationLogController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/OperationLogController.java @@ -23,10 +23,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * 历史记录服务类 + * History service class * * @author moji - * @version HistoryManageController.java, v 0.1 2022年09月18日 10:55 moji Exp $ + * @version HistoryManageController.java, v 0.1 September 18, 2022 10:55 moji Exp $ * @date 2022/09/18 */ @RequestMapping("/api/operation/log") @@ -40,7 +40,7 @@ public class OperationLogController { private OperationLogWebConverter operationLogWebConverter; /** - * 查询执行记录 + * Query execution records * * @param request * @return @@ -55,7 +55,7 @@ public WebPageResult list(OperationLogQueryRequest request) { } /** - * 新增历史记录 + * Add history * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/converter/OperationLogWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/converter/OperationLogWebConverter.java index c8ebcda96..aa6ff3f4d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/converter/OperationLogWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/converter/OperationLogWebConverter.java @@ -15,14 +15,14 @@ /** * @author moji - * @version HistoryWebConverter.java, v 0.1 2022年09月25日 16:53 moji Exp $ + * @version HistoryWebConverter.java, v 0.1 September 25, 2022 16:53 moji Exp $ * @date 2022/09/25 */ @Mapper(componentModel = "spring") public abstract class OperationLogWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -30,7 +30,7 @@ public abstract class OperationLogWebConverter { public abstract OperationLogCreateParam createReq2param(OperationLogCreateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -38,7 +38,7 @@ public abstract class OperationLogWebConverter { public abstract OperationLogPageQueryParam req2param(OperationLogQueryRequest request); /** - * 模型转换 + * Model conversion * * @param ddlDTO * @return @@ -50,7 +50,7 @@ public abstract class OperationLogWebConverter { public abstract OperationLogVO dto2vo(OperationLog ddlDTO); /** - * 模型转换 + * Model conversion * * @param ddlDTOS * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogCreateRequest.java index b8748c3cb..4fcbe96e3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogCreateRequest.java @@ -8,25 +8,25 @@ /** * @author moji - * @version DdlCreateRequest.java, v 0.1 2022年09月18日 11:13 moji Exp $ + * @version DdlCreateRequest.java, v 0.1 September 18, 2022 11:13 moji Exp $ * @date 2022/09/18 */ @Data public class OperationLogCreateRequest extends DataSourceBaseRequest { /** - * 文件别名 + * file alias */ private String name; /** - * ddl类型 + * ddl type */ @NotNull private String type; /** - * ddl内容 + * ddl content */ @NotNull private String ddl; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogQueryRequest.java index 689a76d21..7297c9a2c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/request/OperationLogQueryRequest.java @@ -6,29 +6,29 @@ /** * @author moji - * @version DdlCreateRequest.java, v 0.1 2022年09月18日 11:13 moji Exp $ + * @version DdlCreateRequest.java, v 0.1 September 18, 2022 11:13 moji Exp $ * @date 2022/09/18 */ @Data public class OperationLogQueryRequest extends PageQueryRequest { /** - * 模糊词搜索 + * Fuzzy word search */ private String searchKey; /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * 数据库名称 + * Name database */ private String databaseName; /** - * schema名称 + * schema name */ private String schemaName; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/vo/OperationLogVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/vo/OperationLogVO.java index 69da90720..8512376c3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/vo/OperationLogVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/log/vo/OperationLogVO.java @@ -8,86 +8,86 @@ /** * @author moji - * @version DdlVO.java, v 0.1 2022年09月18日 11:06 moji Exp $ + * @version DdlVO.java, v 0.1 September 18, 2022 11:06 moji Exp $ * @date 2022/09/18 */ @Data public class OperationLogVO { /** - * 主键 + * primary key */ private Long id; /** - * 创建时间 + * creation time */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime gmtModified; /** - * 文件别名 + * file alias */ private String name; /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * 数据源名称 + * Data source name */ private String dataSourceName; /** - * 是否可连接 + * Is it connectable? */ private Boolean connectable; /** - * DB名称 + * DB name */ private String databaseName; /** - * ddl语言类型 + * ddl language type */ private String type; /** - * ddl内容 + * ddl content */ private String ddl; /** - * 状态 + * state */ private String status; /** - * 操作行数 + * Number of operation lines */ private Long operationRows; /** - * 使用时长 + * Length of use */ private Long useTime; /** - * 扩展信息 + * Extended Information */ private String extendInfo; /** - * schema名称 + * schema name */ private String schemaName; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/OperationSavedController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/OperationSavedController.java index 42b2adc7d..2c0ace543 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/OperationSavedController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/OperationSavedController.java @@ -31,10 +31,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * 我的保存服务类 + * My save service class * * @author moji - * @version DdlManageController.java, v 0.1 2022年09月16日 19:59 moji Exp $ + * @version DdlManageController.java, v 0.1 September 16, 2022 19:59 moji Exp $ * @date 2022/09/16 */ @RequestMapping("/api/operation/saved") @@ -48,7 +48,7 @@ public class OperationSavedController { private OperationWebConverter operationWebConverter; /** - * 查询我的保存 + * Check my saves * * @param request * @return @@ -63,7 +63,7 @@ public WebPageResult list(OperationQueryRequest request) { } /** - * 根据id查询console + * Query console based on id * * @param id * @return @@ -77,7 +77,7 @@ public DataResult get(@PathVariable("id") Long id) { } /** - * 新增我的保存 + * Add my save * * @param request * @return @@ -90,7 +90,7 @@ public DataResult create(@RequestBody OperationCreateRequest request) { } /** - * 更新我的保存 + * Update my save * * @param request * @return @@ -102,7 +102,7 @@ public ActionResult update(@RequestBody OperationUpdateRequest request) { } /** - * 批量关闭标签 + * Close tags in batches * * @param request * @return @@ -122,7 +122,7 @@ public ActionResult batchTabClose(@RequestBody BatchTabCloseRequest request) { } /** - * 删除我的保存 + * delete my save * * @param id * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/converter/OperationWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/converter/OperationWebConverter.java index a3e1f03c6..eac063684 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/converter/OperationWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/converter/OperationWebConverter.java @@ -17,14 +17,14 @@ /** * @author moji - * @version DdlManageWebConverter.java, v 0.1 2022年09月26日 10:08 moji Exp $ + * @version DdlManageWebConverter.java, v 0.1 September 26, 2022 10:08 moji Exp $ * @date 2022/09/26 */ @Mapper(componentModel = "spring") public abstract class OperationWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -32,7 +32,7 @@ public abstract class OperationWebConverter { public abstract OperationSavedParam req2param(OperationCreateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -40,7 +40,7 @@ public abstract class OperationWebConverter { public abstract OperationUpdateParam updateReq2param(OperationUpdateRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -48,7 +48,7 @@ public abstract class OperationWebConverter { public abstract OperationPageQueryParam queryReq2param(OperationQueryRequest request, Long userId); /** - * 模型转换 + * Model conversion * * @param ddlDTO * @return @@ -59,7 +59,7 @@ public abstract class OperationWebConverter { public abstract OperationVO dto2vo(Operation ddlDTO); /** - * 模型转换 + * Model conversion * * @param ddlDTOS * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/BatchTabCloseRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/BatchTabCloseRequest.java index 20969e96d..788194b99 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/BatchTabCloseRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/BatchTabCloseRequest.java @@ -13,7 +13,7 @@ public class BatchTabCloseRequest { /** - * 主键 + * primary key */ @NotNull private List idList; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationCreateRequest.java index 187f093f1..9c2939e14 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationCreateRequest.java @@ -9,19 +9,19 @@ /** * @author moji - * @version DdlCreateRequest.java, v 0.1 2022年09月18日 11:13 moji Exp $ + * @version DdlCreateRequest.java, v 0.1 September 18, 2022 11:13 moji Exp $ * @date 2022/09/18 */ @Data public class OperationCreateRequest extends DataSourceBaseRequest { /** - * 文件别名 + * file alias */ private String name; /** - * 保存状态 + * Save state * @see StatusEnum */ @NotNull @@ -34,13 +34,13 @@ public class OperationCreateRequest extends DataSourceBaseRequest { private String type; /** - * ddl内容 + * ddl content */ @NotNull private String ddl; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationQueryRequest.java index 0723d47aa..8363838b2 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationQueryRequest.java @@ -6,34 +6,34 @@ /** * @author moji - * @version DdlCreateRequest.java, v 0.1 2022年09月18日 11:13 moji Exp $ + * @version DdlCreateRequest.java, v 0.1 September 18, 2022 11:13 moji Exp $ * @date 2022/09/18 */ @Data public class OperationQueryRequest extends PageQueryRequest { /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 模糊搜索词 + * Fuzzy search terms */ private String searchKey; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; /** - * ddl语句状态:DRAFT/RELEASE + * ddl statement status: DRAFT/RELEASE */ private String status; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationUpdateRequest.java index 5b0b9fe21..30112371f 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/request/OperationUpdateRequest.java @@ -6,56 +6,56 @@ /** * @author moji - * @version DdlCreateRequest.java, v 0.1 2022年09月18日 11:13 moji Exp $ + * @version DdlCreateRequest.java, v 0.1 September 18, 2022 11:13 moji Exp $ * @date 2022/09/18 */ @Data public class OperationUpdateRequest { /** - * 主键 + * primary key */ @NotNull private Long id; /** - * 文件别名 + * file alias */ private String name; /** - * 数据源连接ID + * Data source connection ID */ private Long dataSourceId; /** - * db名称 + * DB name */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; /** - * 数据库类型 + * Database type */ private String type; /** - * ddl内容 + * ddl content */ @NotNull private String ddl; /** - * 更新状态 DRAFT/RELEASE + * Update status DRAFT/RELEASE */ private String status; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; @@ -65,7 +65,7 @@ public class OperationUpdateRequest { private String operationType; /** - * 用户id + * user id */ private Long userId; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/vo/OperationVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/vo/OperationVO.java index d6f002fda..14cfac6cf 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/vo/OperationVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/operation/saved/vo/OperationVO.java @@ -5,64 +5,64 @@ /** * @author moji - * @version DdlVO.java, v 0.1 2022年09月18日 11:06 moji Exp $ + * @version DdlVO.java, v 0.1 September 18, 2022 11:06 moji Exp $ * @date 2022/09/18 */ @Data public class OperationVO { /** - * 主键 + * primary key */ private Long id; /** - * 文件别名 + * file alias */ private String name; /** - * 数据源id + * Data source id */ private Long dataSourceId; /** - * 数据源名称 + * Data source name */ private String dataSourceName; /** - * 是否可连接 + * Is it connectable? */ private Boolean connectable; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; /** - * ddl语言类型 + * ddl language type */ private String type; /** - * ddl内容 + * ddl content */ private String ddl; /** - * ddl语句状态:DRAFT/RELEASE + * ddl statement status: DRAFT/RELEASE */ private String status; /** - * 是否在tab中被打开,y表示打开,n表示未打开 + * Whether it is opened in the tab, y means open, n means not opened */ private String tabOpened; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/pin/request/PinTableRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/pin/request/PinTableRequest.java index ab4a26d31..1150948c4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/pin/request/PinTableRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/pin/request/PinTableRequest.java @@ -14,18 +14,18 @@ public class PinTableRequest { /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间 + * The space where the table is located */ private String schemaName; /** diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/DatabaseController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/DatabaseController.java index 848ae1722..6348db871 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/DatabaseController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/DatabaseController.java @@ -1,8 +1,10 @@ package ai.chat2db.server.web.api.controller.rdb; +import ai.chat2db.server.domain.api.param.MetaDataQueryParam; import ai.chat2db.server.domain.api.param.datasource.DatabaseCreateParam; +import ai.chat2db.server.domain.api.param.datasource.DatabaseExportDataParam; +import ai.chat2db.server.domain.api.param.datasource.DatabaseExportParam; import ai.chat2db.server.domain.api.param.datasource.DatabaseQueryAllParam; -import ai.chat2db.server.domain.api.param.MetaDataQueryParam; import ai.chat2db.server.domain.api.service.DatabaseService; import ai.chat2db.server.tools.base.wrapper.result.ActionResult; import ai.chat2db.server.tools.base.wrapper.result.DataResult; @@ -12,21 +14,25 @@ import ai.chat2db.server.web.api.controller.data.source.vo.DatabaseVO; import ai.chat2db.server.web.api.controller.rdb.converter.DatabaseConverter; import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter; +import ai.chat2db.server.web.api.controller.rdb.data.export.strategy.ExportDBDataStrategy; +import ai.chat2db.server.web.api.controller.rdb.factory.ExportDBDataStrategyFactory; import ai.chat2db.server.web.api.controller.rdb.request.DatabaseCreateRequest; +import ai.chat2db.server.web.api.controller.rdb.request.DatabaseExportDataRequest; +import ai.chat2db.server.web.api.controller.rdb.request.DatabaseExportRequest; import ai.chat2db.server.web.api.controller.rdb.request.UpdateDatabaseRequest; import ai.chat2db.server.web.api.controller.rdb.vo.MetaSchemaVO; import ai.chat2db.spi.model.Database; import ai.chat2db.spi.model.MetaSchema; import ai.chat2db.spi.model.Sql; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import org.apache.commons.lang3.StringUtils; -import org.apache.poi.util.StringUtil; import org.springframework.beans.factory.annotation.Autowired; -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.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.io.PrintWriter; +import java.lang.reflect.Constructor; +import java.util.Objects; /** * database controller @@ -45,7 +51,7 @@ public class DatabaseController { public DatabaseConverter databaseConverter; /** - * 查询数据库里包含的database_schema_list + * Query the database_schema_list contained in the database * * @param request * @return @@ -70,7 +76,7 @@ public ListResult databaseList(@Valid DataSourceBaseRequest request) } /** - * 删除数据库 + * Delete database * * @param request * @return @@ -82,7 +88,7 @@ public ActionResult deleteDatabase(@Valid @RequestBody DataSourceBaseRequest req } /** - * 创建database + * create database * * @param request * @return @@ -97,7 +103,7 @@ public DataResult createDatabase(@Valid @RequestBody DatabaseCreateRequest } /** - * 修改database + * Modify database * * @param request * @return @@ -108,4 +114,33 @@ public ActionResult modifyDatabase(@Valid @RequestBody UpdateDatabaseRequest req .name(request.getNewDatabaseName()).build(); return databaseService.modifyDatabase(param); } + @PostMapping("/export") + public void exportDatabase(@Valid @RequestBody DatabaseExportRequest request, HttpServletResponse response){ + String fileName = Objects.isNull(request.getSchemaName())?request.getDatabaseName() : request.getSchemaName(); + response.setContentType("text/sql"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".sql"); + response.setCharacterEncoding("utf-8"); + DatabaseExportParam param = databaseConverter.request2param(request); + try (PrintWriter printWriter = response.getWriter()) { + String sql = databaseService.exportDatabase(param); + printWriter.println(sql); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @PostMapping("/export_data") + public void exportData(@Valid @RequestBody DatabaseExportDataRequest request, HttpServletResponse response) { + Class targetClass = ExportDBDataStrategyFactory.get(request.getExportType()); + response.setCharacterEncoding("utf-8"); + DatabaseExportDataParam param = databaseConverter.request2param(request); + try { + Constructor constructor = targetClass.getDeclaredConstructor(); + ExportDBDataStrategy service = (ExportDBDataStrategy) constructor.newInstance(); + service.doExport(param, response); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/ProcedureController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/ProcedureController.java index fc6b86827..be7980ec6 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/ProcedureController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/ProcedureController.java @@ -1,18 +1,21 @@ package ai.chat2db.server.web.api.controller.rdb; import ai.chat2db.server.domain.api.service.ProcedureService; +import ai.chat2db.server.tools.base.wrapper.result.ActionResult; import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.server.tools.base.wrapper.result.ListResult; import ai.chat2db.server.tools.base.wrapper.result.web.WebPageResult; import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect; +import ai.chat2db.server.web.api.controller.rdb.converter.ProcedureConverter; import ai.chat2db.server.web.api.controller.rdb.request.ProcedureDetailRequest; import ai.chat2db.server.web.api.controller.rdb.request.ProcedurePageRequest; +import ai.chat2db.server.web.api.controller.rdb.request.ProcedureUpdateRequest; import ai.chat2db.spi.model.Procedure; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.sql.SQLException; @ConnectionInfoAspect @RequestMapping("/api/rdb/procedure") @@ -22,6 +25,8 @@ public class ProcedureController { @Autowired private ProcedureService procedureService; + @Autowired + private ProcedureConverter procedureConverter; @GetMapping("/list") public WebPageResult list(@Valid ProcedurePageRequest request) { ListResult procedureListResult = procedureService.procedures(request.getDatabaseName(), @@ -34,4 +39,10 @@ public WebPageResult list(@Valid ProcedurePageRequest request) { public DataResult detail(@Valid ProcedureDetailRequest request) { return procedureService.detail(request.getDatabaseName(), request.getSchemaName(), request.getProcedureName()); } + + @PostMapping("/update") + public ActionResult update(@Valid @RequestBody ProcedureUpdateRequest request) throws SQLException { + Procedure procedure = procedureConverter.request2param(request); + return procedureService.update(request.getDatabaseName(), request.getSchemaName(), procedure); + } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java index feb7f3f7b..71c5760bf 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDdlController.java @@ -30,10 +30,10 @@ import java.util.concurrent.Executors; /** - * mysql表运维类 + * mysql table operation and maintenance class * * @author moji - * @version MysqlTableManageController.java, v 0.1 2022年09月16日 17:41 moji Exp $ + * @version MysqlTableManageController.java, v 0.1 September 16, 2022 17:41 moji Exp $ * @date 2022/09/16 */ @ConnectionInfoAspect @@ -58,7 +58,7 @@ public class RdbDdlController extends EmbeddingController { public static ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); /** - * 查询当前DB下的表列表 + * Query the table list under the current DB * * @param request * @return @@ -91,7 +91,7 @@ public WebPageResult list(@Valid TableBriefQueryRequest request) { } /** - * 查询数据库里包含的schema_list + * Query the schema_list contained in the database * * @param request * @return @@ -105,7 +105,7 @@ public ListResult schemaList(@Valid DataSourceBaseRequest request) { } /** - * 查询数据库里包含的database_schema_list + * Query the database_schema_list contained in the database * * @param request * @return @@ -121,8 +121,7 @@ public DataResult databaseSchemaList(@Valid DataSourceBaseRequest /** - * 查询当前DB下的表columns - * d + * Query the table columns under the current DB * * @param request * @return @@ -136,7 +135,7 @@ public ListResult columnList(@Valid TableDetailQueryRequest request) { } /** - * 查询当前DB下的表index + * Query the table index under the current DB * * @param request * @return @@ -150,19 +149,19 @@ public ListResult indexList(@Valid TableDetailQueryRequest request) { } /** - * 查询当前DB下的表key + * Query the table key under the current DB * * @param request * @return */ @GetMapping("/key_list") public ListResult keyList(@Valid TableDetailQueryRequest request) { - // TODO 增加查询key实现 + // TODO Add query key implementation return ListResult.of(Lists.newArrayList()); } /** - * 导出建表语句 + * Export table creation statement * * @param request * @return @@ -174,7 +173,7 @@ public DataResult export(@Valid DdlExportRequest request) { } /** - * 建表语句样例 + * Table creation statement example * * @param request * @return @@ -185,7 +184,7 @@ public DataResult createExample(@Valid TableCreateDdlQueryRequest reques } /** - * 更新表语句样例 + * Update table statement example * * @param request * @return @@ -196,7 +195,7 @@ public DataResult updateExample(@Valid TableUpdateDdlQueryRequest reques } /** - * 获取表下列和索引等信息 + * Get information such as table columns and indexes * * @param request * @return @@ -213,7 +212,7 @@ public DataResult query(@Valid TableDetailQueryRequest request) { } /** - * 获取修改表的sql语句 + * Get the sql statement that modifies the table * * @param request * @return @@ -227,7 +226,7 @@ public ListResult modifySql(@Valid TableModifySqlRequest request) { } /** - * 删除表 + * Delete table * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDmlController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDmlController.java index 2197d84e1..1abc17144 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDmlController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDmlController.java @@ -37,10 +37,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * mysql数据运维类 + * mysql data operation and maintenance class * * @author moji - * @version MysqlDataManageController.java, v 0.1 2022年09月16日 17:37 moji Exp $ + * @version MysqlDataManageController.java, v 0.1 September 16, 2022 17:37 moji Exp $ * @date 2022/09/16 */ @ConnectionInfoAspect @@ -60,7 +60,7 @@ public class RdbDmlController { public static ExecutorService executorService = Executors.newFixedThreadPool(10); /** - * 增删改查等数据运维 + * Data operation and maintenance such as addition, deletion, modification and query * * @param request * @return @@ -70,33 +70,9 @@ public ListResult manage(@RequestBody DmlRequest request) { DlExecuteParam param = rdbWebConverter.request2param(request); ListResult resultDTOListResult = dlTemplateService.execute(param); List resultVOS = rdbWebConverter.dto2vo(resultDTOListResult.getData()); - String type = Chat2DBContext.getConnectInfo().getDbType(); - String clientId = getClientId(); - String sqlContent = request.getSql(); - executorService.submit(() -> { - try { - addOperationLog(clientId, type, sqlContent, resultDTOListResult.getErrorMessage(), resultDTOListResult.getSuccess(), resultVOS); - } catch (Exception e) { - // do nothing - } - }); return ListResult.of(resultVOS); } - private void addOperationLog(String clientId, String sqlType, String sqlContent, String errorMessage, Boolean isSuccess, List executeResultVOS) { - SqlExecuteHistoryCreateRequest createRequest = new SqlExecuteHistoryCreateRequest(); - createRequest.setClientId(clientId); - createRequest.setErrorMessage(errorMessage); - createRequest.setDatabaseType(sqlType); - createRequest.setSqlContent(sqlContent); - createRequest.setExecuteStatus(isSuccess ? "success" : "fail"); - executeResultVOS.forEach(executeResultVO -> { - createRequest.setSqlType(executeResultVO.getSqlType()); - createRequest.setDuration(executeResultVO.getDuration()); - createRequest.setTableName(executeResultVO.getTableName()); - gatewayClientService.addOperationLog(createRequest); - }); - } /** * query chat2db apikey @@ -113,7 +89,7 @@ private String getClientId() { } /** - * 查询表结构信息 + * Query table structure information * * @param request * @return @@ -121,21 +97,12 @@ private String getClientId() { @RequestMapping(value = "/execute_table", method = {RequestMethod.POST, RequestMethod.PUT}) public ListResult executeTable(@RequestBody DmlTableRequest request) { DlExecuteParam param = rdbWebConverter.request2param(request); - // 解析sql - String type = Chat2DBContext.getConnectInfo().getDbType(); - if (DataSourceTypeEnum.MONGODB.getCode().equals(type)) { - param.setSql("db." + request.getTableName() + ".find()"); - } else { - MetaData metaData = Chat2DBContext.getMetaData(); - // 拼接`tableName`,避免关键字被占用问题 - param.setSql("select * from " + metaData.getMetaDataName(request.getTableName())); - } - return dlTemplateService.execute(param) + return dlTemplateService.executeSelectTable(param) .map(rdbWebConverter::dto2vo); } /** - * update 查询结果 + * update search result * * @param request * @return @@ -148,16 +115,6 @@ public DataResult executeSelectResultUpdate(@RequestBody DmlReq return DataResult.error(result.getErrorCode(), result.getErrorMessage()); } ExecuteResultVO executeResultVO = rdbWebConverter.dto2vo(result.getData()); - String type = Chat2DBContext.getConnectInfo().getDbType(); - String sqlContent = request.getSql(); - String clientId = getClientId(); - executorService.submit(() -> { - try { - addOperationLog(clientId, type, sqlContent, result.getErrorMessage(), result.getSuccess(), Lists.newArrayList(executeResultVO)); - } catch (Exception e) { - // do nothing - } - }); return DataResult.of(executeResultVO); } @@ -178,7 +135,7 @@ public DataResult getOrderBySql(@RequestBody OrderByRequest request) { } /** - * 增删改查等数据运维 + * Data operation and maintenance such as addition, deletion, modification and query * * @param request * @return @@ -221,7 +178,7 @@ public DataResult executeDDL(@RequestBody DmlRequest request) { } /** - * 统计行的数量 + * Number of statistics rows * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDocController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDocController.java index 0ea76219b..97266ed3d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDocController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/RdbDocController.java @@ -58,7 +58,7 @@ public class RdbDocController { */ @PostMapping("/export") public void export(@Valid @RequestBody DataExportRequest request, HttpServletResponse response) throws Exception { - //复制模板 + //Copy template ExportTypeEnum exportType = EasyEnumUtils.getEnum(ExportTypeEnum.class, request.getExportType()); response.setCharacterEncoding("utf-8"); String fileName = URLEncoder.encode( @@ -84,7 +84,7 @@ public void export(@Valid @RequestBody DataExportRequest request, HttpServletRes DatabaseExportService databaseExportService = (DatabaseExportService) constructor.newInstance(); response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + databaseExportService.getSuffix()); response.setContentType(databaseExportService.getContentType()); - // 设置数据集合 + // Set up data collection databaseExportService.setExportList(tableVOS); databaseExportService.generate(request.getDatabaseName(), response.getOutputStream(), new ExportOptions()); } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/SchemaController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/SchemaController.java index 156fdb96a..8b4b49674 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/SchemaController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/SchemaController.java @@ -47,7 +47,7 @@ public class SchemaController { private DatabaseService databaseService; /** - * 查询数据库里包含的schema_list + * Query the schema_list contained in the database * * @param request * @return @@ -62,7 +62,7 @@ public ListResult list(@Valid DataSourceBaseRequest request) { } /** - * 删除schema + * Delete schema * * @param request * @return @@ -75,7 +75,7 @@ public ActionResult deleteSchema(@Valid @RequestBody DataSourceBaseRequest reque } /** - * 创建schema + * Create schema * * @param request * @return @@ -91,7 +91,7 @@ public DataResult createSchema(@Valid @RequestBody SchemaCreateRequest requ } /** - * 创建database + * Modify schema * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java index 131a6bf6c..23a9f32ec 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/TableController.java @@ -51,7 +51,7 @@ public class TableController extends EmbeddingController { public static ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); /** - * 查询当前DB下的表列表 + * Query the table list under the current DB * * @param request * @return @@ -82,7 +82,7 @@ public WebPageResult list(@Valid TableBriefQueryRequest request) { } /** - * 查询当前DB下的表列表 + * Query the table list under the current DB * * @param request * @return @@ -99,8 +99,7 @@ public ListResult tableList(@Valid TableBriefQueryRequest request) /** - * 查询当前DB下的表columns - * d + * Query the table columns under the current DB * * @param request * @return @@ -113,8 +112,14 @@ public ListResult columnList(@Valid TableDetailQueryRequest request) { return ListResult.of(tableVOS); } + @GetMapping("/copy_dml_sql") + public DataResult copyDmlSql(@Valid DmlSqlCopyRequest request) { + DmlSqlCopyParam queryParam = rdbWebConverter.dmlRequest2param(request); + return tableService.copyDmlSql(queryParam); + } + /** - * 查询当前DB下的表index + * Query the table index under the current DB * * @param request * @return @@ -128,19 +133,19 @@ public ListResult indexList(@Valid TableDetailQueryRequest request) { } /** - * 查询当前DB下的表key + * Query the table key under the current DB * * @param request * @return */ @GetMapping("/key_list") public ListResult keyList(@Valid TableDetailQueryRequest request) { - // TODO 增加查询key实现 + // TODO Add query key implementation return ListResult.of(Lists.newArrayList()); } /** - * 导出建表语句 + * Export table creation statement * * @param request * @return @@ -152,7 +157,7 @@ public DataResult export(@Valid DdlExportRequest request) { } /** - * 建表语句样例 + * Table creation statement example * * @param request * @return @@ -163,7 +168,7 @@ public DataResult createExample(@Valid TableCreateDdlQueryRequest reques } /** - * 更新表语句样例 + * Update table statement example * * @param request * @return @@ -174,7 +179,7 @@ public DataResult updateExample(@Valid TableUpdateDdlQueryRequest reques } /** - * 获取表下列和索引等信息 + * Get information such as table columns and indexes * * @param request * @return @@ -191,7 +196,7 @@ public DataResult
query(@Valid TableDetailQueryRequest request) { } /** - * 获取修改表的sql语句 + * Get the sql statement that modifies the table * * @param request * @return @@ -219,7 +224,7 @@ public ListResult modifySql(@Valid @RequestBody TableModifySqlRequest req /** - * 数据库支持的数据类型 + * Data types supported by the database * * @param request * @return @@ -240,7 +245,7 @@ public DataResult tableMeta(@Valid TypeQueryRequest request) { } /** - * 删除表 + * Delete table * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/DatabaseConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/DatabaseConverter.java index b14e7c257..bb9bc4a9a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/DatabaseConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/DatabaseConverter.java @@ -1,6 +1,10 @@ package ai.chat2db.server.web.api.controller.rdb.converter; +import ai.chat2db.server.domain.api.param.datasource.DatabaseExportDataParam; +import ai.chat2db.server.domain.api.param.datasource.DatabaseExportParam; import ai.chat2db.server.web.api.controller.rdb.request.DatabaseCreateRequest; +import ai.chat2db.server.web.api.controller.rdb.request.DatabaseExportDataRequest; +import ai.chat2db.server.web.api.controller.rdb.request.DatabaseExportRequest; import ai.chat2db.spi.model.Database; import org.mapstruct.Mapper; @@ -8,4 +12,8 @@ public abstract class DatabaseConverter { public abstract Database request2param(DatabaseCreateRequest request); + + public abstract DatabaseExportParam request2param(DatabaseExportRequest request); + + public abstract DatabaseExportDataParam request2param(DatabaseExportDataRequest request); } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/ProcedureConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/ProcedureConverter.java new file mode 100644 index 000000000..40326560e --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/ProcedureConverter.java @@ -0,0 +1,15 @@ +package ai.chat2db.server.web.api.controller.rdb.converter; + +import ai.chat2db.server.web.api.controller.rdb.request.ProcedureUpdateRequest; +import ai.chat2db.spi.model.Procedure; +import org.mapstruct.Mapper; + +/** + * @author: zgq + * @date: February 24, 2024 13:39 + */ +@Mapper(componentModel = "spring") +public abstract class ProcedureConverter { + + public abstract Procedure request2param(ProcedureUpdateRequest request); +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java index b04663dc9..f9c529a5b 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java @@ -27,14 +27,14 @@ /** * @author moji - * @version MysqlDataConverter.java, v 0.1 2022年10月14日 14:04 moji Exp $ + * @version MysqlDataConverter.java, v 0.1 October 14, 2022 14:04 moji Exp $ * @date 2022/10/14 */ @Mapper(componentModel = "spring") public abstract class RdbWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -43,7 +43,7 @@ public abstract class RdbWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -51,7 +51,7 @@ public abstract class RdbWebConverter { public abstract OrderByParam request2param(OrderByRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -59,7 +59,7 @@ public abstract class RdbWebConverter { public abstract DlExecuteParam request2param(DmlTableRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -68,7 +68,7 @@ public abstract class RdbWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -76,7 +76,7 @@ public abstract class RdbWebConverter { public abstract DlCountParam request2param(DdlCountRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -85,7 +85,7 @@ public abstract class RdbWebConverter { /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -93,28 +93,28 @@ public abstract class RdbWebConverter { public abstract Table tableRequest2param(TableRequest request); /** - * 参数转换 + * Parameter conversion * * @param dto * @return */ public abstract SqlVO dto2vo(Sql dto); /** - * 参数转换 + * Parameter conversion * * @param request * @return */ public abstract TablePageQueryParam tablePageRequest2param(TableBriefQueryRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return */ public abstract TablePageQueryParam tablePageRequest2param(DataExportRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -122,7 +122,7 @@ public abstract class RdbWebConverter { public abstract TableQueryParam tableRequest2param(DataExportRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -130,7 +130,7 @@ public abstract class RdbWebConverter { public abstract ShowCreateTableParam ddlExport2showCreate(DdlExportRequest request); /** - * 参数转换 + * Parameter conversion * * @param request * @return @@ -139,7 +139,7 @@ public abstract class RdbWebConverter { /** - * 模型转换 + * Model conversion * * @param dto * @return @@ -147,7 +147,7 @@ public abstract class RdbWebConverter { public abstract ExecuteResultVO dto2vo(ExecuteResult dto); /** - * 模型转换 + * Model conversion * * @param dtos * @return @@ -155,7 +155,7 @@ public abstract class RdbWebConverter { public abstract List dto2vo(List dtos); /** - * 模型转换 + * Model conversion * * @param dto * @return @@ -163,7 +163,7 @@ public abstract class RdbWebConverter { public abstract ColumnVO columnDto2vo(TableColumn dto); /** - * 模型转换 + * Model conversion * * @param dtos * @return @@ -171,7 +171,7 @@ public abstract class RdbWebConverter { public abstract List columnDto2vo(List dtos); /** - * 模型转换 + * Model conversion * * @param dto * @return @@ -182,7 +182,7 @@ public abstract class RdbWebConverter { public abstract IndexVO indexDto2vo(TableIndex dto); /** - * 模型转换 + * Model conversion * * @param dtos * @return @@ -190,7 +190,7 @@ public abstract class RdbWebConverter { public abstract List indexDto2vo(List dtos); /** - * 模型转换 + * Model conversion * * @param dto * @return @@ -202,7 +202,7 @@ public abstract class RdbWebConverter { public abstract TableVO tableDto2vo(Table dto); /** - * 模型转换 + * Model conversion * * @param dtos * @return @@ -210,21 +210,21 @@ public abstract class RdbWebConverter { public abstract List tableDto2vo(List
dtos); /** - * 模型转换 + * Model conversion * @param tableColumns * @return */ public abstract List schemaDto2vo(List tableColumns); /** - * 模型转换 + * Model conversion * @param dto * @return */ public abstract SchemaVO schemaDto2vo(Schema dto); /** - * 模型转换 + * Model conversion * @param dto * @return */ @@ -232,7 +232,7 @@ public abstract class RdbWebConverter { /** - * 模型转换 + * Model conversion * @param dto * @return */ @@ -254,4 +254,6 @@ public abstract class RdbWebConverter { public abstract EsTableSchemaRequest req2req(TableBriefQueryRequest request); public abstract TablePageQueryParam schemaReq2page(EsTableSchemaRequest request); + + public abstract DmlSqlCopyParam dmlRequest2param(DmlSqlCopyRequest request) ; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2CsvStrategy.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2CsvStrategy.java new file mode 100644 index 000000000..d091bf0ca --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2CsvStrategy.java @@ -0,0 +1,54 @@ +package ai.chat2db.server.web.api.controller.rdb.data.export.strategy; + +import ai.chat2db.server.domain.api.enums.ExportFileSuffix; +import ai.chat2db.spi.util.ResultSetUtils; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.support.ExcelTypeEnum; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class ExportDBData2CsvStrategy extends ExportDBDataStrategy { + + public ExportDBData2CsvStrategy() { + suffix = ExportFileSuffix.CSV.getSuffix(); + contentType = "application/zip"; + } + + @Override + protected ByteArrayOutputStream exportData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException { + String sql; + if (Objects.isNull(schemaName)) { + sql = String.format("select * from %s", tableName); + } else { + sql = String.format("select * from %s.%s", schemaName, tableName); + } + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + ResultSetMetaData metaData = resultSet.getMetaData(); + List> headList = ResultSetUtils.getRsHeader(resultSet) + .stream() + .map(Collections::singletonList) + .collect(Collectors.toList()); + int columnCount = metaData.getColumnCount(); + List> dataList = new ArrayList<>(); + while (resultSet.next()) { + List row = new ArrayList<>(); + for (int i = 1; i <= columnCount; i++) { + row.add(resultSet.getString(i)); + } + dataList.add(row); + } + EasyExcel.write(byteOut).excelType(ExcelTypeEnum.CSV).sheet(tableName).head(headList).doWrite(dataList); + } + return byteOut; + } +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2ExcelStrategy.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2ExcelStrategy.java new file mode 100644 index 000000000..b8fc38ee8 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2ExcelStrategy.java @@ -0,0 +1,53 @@ +package ai.chat2db.server.web.api.controller.rdb.data.export.strategy; + +import ai.chat2db.server.domain.api.enums.ExportFileSuffix; +import ai.chat2db.spi.util.ResultSetUtils; +import com.alibaba.excel.EasyExcel; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class ExportDBData2ExcelStrategy extends ExportDBDataStrategy { + + public ExportDBData2ExcelStrategy() { + suffix = ExportFileSuffix.EXCEL.getSuffix(); + contentType = "application/zip"; + } + + @Override + protected ByteArrayOutputStream exportData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException { + String sql; + if (Objects.isNull(schemaName)) { + sql = String.format("select * from %s", tableName); + } else { + sql = String.format("select * from %s.%s", schemaName, tableName); + } + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + ResultSetMetaData metaData = resultSet.getMetaData(); + int columnCount = metaData.getColumnCount(); + List> headList = ResultSetUtils.getRsHeader(resultSet) + .stream() + .map(Collections::singletonList) + .collect(Collectors.toList()); + List> dataList = new ArrayList<>(); + while (resultSet.next()) { + List row = new ArrayList<>(); + for (int i = 1; i <= columnCount; i++) { + row.add(resultSet.getString(i)); + } + dataList.add(row); + } + EasyExcel.write(byteOut).sheet(tableName).head(headList).doWrite(dataList); + } + return byteOut; + } +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2JsonStrategy.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2JsonStrategy.java new file mode 100644 index 000000000..47c8a59d8 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2JsonStrategy.java @@ -0,0 +1,61 @@ +package ai.chat2db.server.web.api.controller.rdb.data.export.strategy; + +import ai.chat2db.server.domain.api.enums.ExportFileSuffix; +import ai.chat2db.server.tools.base.excption.BusinessException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.*; + +public class ExportDBData2JsonStrategy extends ExportDBDataStrategy { + + public ExportDBData2JsonStrategy() { + suffix = ExportFileSuffix.JSON.getSuffix(); + contentType = "application/zip"; + } + + @Override + protected ByteArrayOutputStream exportData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(byteOut, StandardCharsets.UTF_8))) { + String sql; + if (Objects.isNull(schemaName)) { + sql = String.format("SELECT * FROM %s", tableName); + } else { + sql = String.format("SELECT * FROM %s.%s", schemaName, tableName); + } + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + ResultSetMetaData metaData = resultSet.getMetaData(); + int columnCount = metaData.getColumnCount(); + List> data = new ArrayList<>(); + + while (resultSet.next()) { + Map row = new LinkedHashMap<>(); + for (int i = 1; i <= columnCount; i++) { + row.put(metaData.getColumnName(i), resultSet.getObject(i)); + } + data.add(row); + } + + ObjectMapper objectMapper = new ObjectMapper(); + try { + String jsonString = objectMapper.writeValueAsString(data); + writer.println(jsonString); + } catch (IOException e) { + throw new BusinessException("data.export2Json.error",data.toArray(),e); + } + } + } + return byteOut; + } + + +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2SqlStrategy.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2SqlStrategy.java new file mode 100644 index 000000000..1e0577474 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBData2SqlStrategy.java @@ -0,0 +1,33 @@ +package ai.chat2db.server.web.api.controller.rdb.data.export.strategy; + +import ai.chat2db.server.domain.api.enums.ExportFileSuffix; +import ai.chat2db.spi.sql.Chat2DBContext; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.SQLException; + +/** + * @author: zgq + * @date: 2024年03月24日 12:50 + */ +public class ExportDBData2SqlStrategy extends ExportDBDataStrategy { + + public ExportDBData2SqlStrategy() { + suffix = ExportFileSuffix.SQL.getSuffix(); + contentType = "application/zip"; + } + + @Override + protected ByteArrayOutputStream exportData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(byteOut, StandardCharsets.UTF_8))) { + String sql = Chat2DBContext.getDBManage().exportDatabaseData(connection, databaseName, schemaName, tableName); + writer.println(sql); + } + return byteOut; + } +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBDataStrategy.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBDataStrategy.java new file mode 100644 index 000000000..cb4a18209 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/data/export/strategy/ExportDBDataStrategy.java @@ -0,0 +1,65 @@ +package ai.chat2db.server.web.api.controller.rdb.data.export.strategy; + +import ai.chat2db.server.domain.api.enums.ExportFileSuffix; +import ai.chat2db.server.domain.api.param.datasource.DatabaseExportDataParam; +import ai.chat2db.spi.sql.Chat2DBContext; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.HttpServletResponse; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.io.ByteArrayOutputStream; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; +import java.util.Objects; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * @author: zgq + * @date: 2024年03月24日 12:46 + */ +@Getter +@AllArgsConstructor +@NoArgsConstructor +public abstract class ExportDBDataStrategy { + + public String suffix; + public String contentType; + + public void doExport(DatabaseExportDataParam param, HttpServletResponse response) { + String databaseName = param.getDatabaseName(); + String schemaName = param.getSchemaName(); + setResponseHeaders(param, response); + try (ServletOutputStream outputStream = response.getOutputStream(); + ZipOutputStream zipOut = new ZipOutputStream(outputStream); + Connection connection = Chat2DBContext.getConnection();) { + List tableNames = Chat2DBContext.getMetaData().tableNames(connection, databaseName, schemaName, null); + tableNames.addAll(Chat2DBContext.getMetaData().viewNames(connection, databaseName, schemaName)); + for (String tableName : tableNames) { + String fileName = tableName + getSuffix(); + zipOut.putNextEntry(new ZipEntry(fileName)); + ByteArrayOutputStream byteOut = exportData(connection, databaseName, schemaName, tableName); + byteOut.writeTo(zipOut); + zipOut.closeEntry(); + byteOut.close(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void setResponseHeaders(DatabaseExportDataParam param, HttpServletResponse response) { + response.setContentType(contentType); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + getFileName(param) + ExportFileSuffix.ZIP.getSuffix()); + } + + protected String getFileName(DatabaseExportDataParam param) { + return Objects.isNull(param.getSchemaName()) ? param.getDatabaseName() : param.getSchemaName(); + } + + protected abstract ByteArrayOutputStream exportData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException; + +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/DatabaseExportService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/DatabaseExportService.java index 4e5bc4094..29811cef0 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/DatabaseExportService.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/DatabaseExportService.java @@ -42,21 +42,21 @@ public class DatabaseExportService { @Getter public String contentType; /** - * 导出excel 集合 + * Export excel collection **/ @Setter @Getter public List exportList; /** - * 导出word、excel 表信息 集合 + * Export word and excel table information collection **/ public static Map> listMap = new LinkedHashMap<>(); /** - * 导出word 索引 集合 + * Export word index collection **/ public static Map> indexMap = new HashMap<>(0); /** - * 连接符 + * Joiner **/ public final static String JOINER = "---"; @@ -74,7 +74,7 @@ private void init() { I18nUtils.getMessage("main.fieldDefault"), I18nUtils.getMessage("main.fieldDecimalPlaces"), I18nUtils.getMessage("main.fieldNote")}; - // index表头 + // index header StringBuilder mdIndex = new StringBuilder(PatternConstant.MD_SPLIT); StringBuilder htmlIndex = new StringBuilder(""); - // column 表头 + // column header StringBuilder mdColumn = new StringBuilder(PatternConstant.MD_SPLIT); StringBuilder htmlColumn = new StringBuilder("
"); for (int i = 0; i < CommonConstant.INDEX_HEAD_NAMES.length; i++) { @@ -83,7 +83,7 @@ private void init() { } mdIndex.append(PatternConstant.MD_SPLIT); htmlIndex.append("
"); for (int i = 0; i < CommonConstant.COLUMN_HEAD_NAMES.length; i++) { @@ -108,15 +108,15 @@ public void generate(String databaseName, OutputStream outputStream, ExportOptio try { export(outputStream, exportOptions); } catch (Exception e) { - throw new RuntimeException("导出失败!请联系开发者" + e); + throw new RuntimeException("Export failed! Please contact the developer" + e); } init(); } /** - * 数据处理 + * data processing * - * @param exportOptions 配置信息 + * @param exportOptions Configuration information **/ public void dataAssemble(String databaseName, ExportOptions exportOptions, TableVO item) { boolean isExportIndex = Optional.ofNullable(exportOptions.getIsExportIndex()).orElse(false); @@ -139,9 +139,9 @@ public void dataAssemble(String databaseName, ExportOptions exportOptions, Table String str = key.substring(0, index); indexMap.put(str, vo2Info(item.getIndexList())); } - //赋值序号 + //Assignment serial number for (Map.Entry> map : listMap.entrySet()) { - //赋值序号 + //Assignment serial number List list = map.getValue(); IntStream.range(0, list.size()).forEach(x -> { list.get(x).setNo(String.valueOf(x + 1)); @@ -162,18 +162,18 @@ private List vo2Info(List indexList) { } /** - * 导出 + * Export * - * @param outputStream 文件流 + * @param outputStream file stream **/ public void export(OutputStream outputStream, ExportOptions exportOptions) { } /** - * 处理空串或null字符 + * Handle empty string or null character * - * @param source 源字符 + * @param source source character * @return java.lang.String **/ public String dealWith(String source) { @@ -204,6 +204,4 @@ public Object[] getColumnValues(TableParameter tableParameter) { values[7] = StringUtils.isNull(tableParameter.getColumnComment()); return values; } - - } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteHeightConfig.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteHeightConfig.java index 66044df5e..42c96fa1d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteHeightConfig.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteHeightConfig.java @@ -14,7 +14,7 @@ **/ public class CustomCellWriteHeightConfig extends AbstractRowHeightStyleStrategy { /** - * 默认高度 + * Default height */ private static final Integer DEFAULT_HEIGHT = 300; @@ -29,7 +29,7 @@ protected void setContentColumnHeight(Row row, int relativeRowIndex) { return; } - // 默认为 1行高度 + // Default is 1 row height int maxHeight = 1; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteWidthConfig.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteWidthConfig.java index a2059e1c3..c184fb552 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteWidthConfig.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/adaptive/CustomCellWriteWidthConfig.java @@ -45,10 +45,10 @@ protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List> cellDataList, Cell cell, Boolean isHead) { @@ -62,7 +62,7 @@ private Integer dataLength(List> cellDataList, Cell cell, Boole } else { switch (type) { case STRING: - // 换行符(数据需要提前解析好) + // Newline character (data needs to be parsed in advance) int index = cellData.getStringValue().indexOf("\n"); return index != -1 ? cellData.getStringValue().substring(0, index).getBytes().length + 1 : cellData.getStringValue().getBytes().length + 1; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/conf/ExportOptions.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/conf/ExportOptions.java index 7f4151a96..a0d4975ec 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/conf/ExportOptions.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/conf/ExportOptions.java @@ -3,23 +3,23 @@ import lombok.Data; /** - * 生成选项 + * Build options * * @author lzy */ @Data public class ExportOptions { /** - * 是否导出多sheet + * Whether to export multiple sheets */ private Boolean isExportMoreSheet = Boolean.FALSE; /** - * 是否导出索引 + * Whether to export the index */ private Boolean isExportIndex = Boolean.FALSE; /** - * 导出文件后缀 + * Export file suffix **/ private String fileSuffix; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/CommonConstant.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/CommonConstant.java index 8f9665c06..d5b9a7878 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/CommonConstant.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/CommonConstant.java @@ -7,7 +7,7 @@ **/ public final class CommonConstant { /** - * 表head + * Table head **/ public static String[] INDEX_HEAD_NAMES = {}; public static String[] COLUMN_HEAD_NAMES = {}; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/PatternConstant.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/PatternConstant.java index 38521e54d..ab231d57a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/PatternConstant.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/constant/PatternConstant.java @@ -9,7 +9,7 @@ public final class PatternConstant { /** - * 公共 + * public */ public static final String MD_SPLIT = "|"; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportHtmlService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportHtmlService.java index f470b1827..5c8ff8a52 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportHtmlService.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportHtmlService.java @@ -45,20 +45,20 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { StringBuilder catalogue = new StringBuilder(); try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) { for (Map.Entry>>> myMap : allMap.entrySet()) { - //数据库名 + //Database name String database = myMap.getKey(); String title = MessageFormat.format(PatternConstant.HTML_TITLE, I18nUtils.getMessage("main.databaseText") + database); - //数据库名-目录 + //Database name-directory catalogue.append("
  • ").append(MessageFormat.format(PatternConstant.HTML_INDEX_ITEM, I18nUtils.getMessage("main.databaseText") + database, I18nUtils.getMessage("main.databaseText") + database)).append("
      "); htmlText.append(title).append("\n"); for (Map.Entry> parameterMap : myMap.getValue()) { - //表名 + //Table Name String tableName = parameterMap.getKey().split("---")[1]; - //表名-目录 + //Table name-directory catalogue.append("
    1. ").append(MessageFormat.format(PatternConstant.HTML_INDEX_ITEM, database + tableName, tableName)); htmlText.append(MessageFormat.format(PatternConstant.HTML_CATALOG, database + tableName, tableName)).append("\n

      "); - //索引Table + //IndexTable if (!indexMap.isEmpty()) { htmlText.append("\n"); htmlText.append(PatternConstant.HTML_INDEX_TABLE_HEADER); @@ -72,7 +72,7 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { } else { htmlText.append(String.format(PatternConstant.HTML_INDEX_TABLE_BODY, getIndexValues(new IndexInfo()))); } - //字段Table + //FieldTable htmlText.append("
      \n"); htmlText.append(PatternConstant.HTML_TABLE_HEADER); List exportList = parameterMap.getValue(); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportMarkdownService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportMarkdownService.java index 7c6de40de..8ccafc93a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportMarkdownService.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportMarkdownService.java @@ -40,17 +40,17 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { .stream().collect(Collectors.groupingBy(v -> v.getKey().split("---")[0])); try (BufferedWriter fileWriter = new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) { for (Map.Entry>>> myMap : allMap.entrySet()) { - //数据库名 + //Database name String database = myMap.getKey(); String title = String.format(PatternConstant.TITLE, I18nUtils.getMessage("main.databaseText") + database); fileWriter.write(title); writeLineSeparator(fileWriter, 2); for (Map.Entry> parameterMap : myMap.getValue()) { - //表名 + //Table Name String tableName = parameterMap.getKey().split("---")[1]; fileWriter.write(String.format(PatternConstant.CATALOG, tableName)); writeLineSeparator(fileWriter, 1); - //索引Table + //IndexTable if (!indexMap.isEmpty()) { fileWriter.write(PatternConstant.ALL_INDEX_TABLE_HEADER); writeLineSeparator(fileWriter, 1); @@ -69,7 +69,7 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { writeLineSeparator(fileWriter, 1); fileWriter.write(PatternConstant.TABLE_SEPARATOR); writeLineSeparator(fileWriter, 1); - //字段Table + //FieldTable List exportList = parameterMap.getValue(); for (TableParameter tableParameter : exportList) { fileWriter.write(String.format(PatternConstant.TABLE_BODY, getColumnValues(tableParameter))); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportPdfService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportPdfService.java index 01a7a7c8a..361402839 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportPdfService.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportPdfService.java @@ -45,26 +45,26 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { Document document = new Document(); PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setStrictImageSequence(true); - // 字体设置 + // Font settings BaseFont baseFont =BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); - // 创建字体对象 + // Create font object Font font = new Font(baseFont, 10, Font.NORMAL); Font headFont = new Font(baseFont, 12, Font.NORMAL); Font titleFont = new Font(baseFont, 14, Font.BOLD); document.open(); - //遍历数据 + //Iterate over data for (Map.Entry>>> myMap : allMap.entrySet()) { - //数据库名 + //Database name String database = myMap.getKey(); String title = I18nUtils.getMessage("main.databaseText") + database; Paragraph p = new Paragraph(title, titleFont); document.add(p); for (Map.Entry> parameterMap : myMap.getValue()) { - //表名 + //Table Name String tableName = parameterMap.getKey().split("---")[1]; Paragraph tableParagraph = new Paragraph(tableName, font); document.add(tableParagraph); - //索引Table + //IndexTable if (isExportIndex && !indexMap.isEmpty()) { PdfPTable table = new PdfPTable(CommonConstant.INDEX_HEAD_NAMES.length); process(table, CommonConstant.INDEX_HEAD_NAMES, font); @@ -77,28 +77,28 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { document.add(table); } document.add(new Paragraph()); - //字段Table + //FieldTable List exportList = parameterMap.getValue(); PdfPTable table = new PdfPTable(CommonConstant.COLUMN_HEAD_NAMES.length); - //标题、内容 + //title content process(table, CommonConstant.COLUMN_HEAD_NAMES, headFont); for (TableParameter tableParameter : exportList) { process(table, getColumnValues(tableParameter), font); } - // 设置表格上方的空白间距,即向下移动的效果 + // Set the blank space above the table, that is, the effect of moving downwards table.setSpacingBefore(10f); table.setSpacingAfter(20f); - //居左对齐 + //Align left table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); document.add(table); - //分页 + //Pagination //document.newPage(); } } document.close(); } - //设置表格内容 + //Set table content public static void process(PdfPTable table, T[] line, Font font) { for (T s : line) { if (Objects.isNull(s)) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportWordSuperService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportWordSuperService.java index ab3dc33de..224f49988 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportWordSuperService.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/export/ExportWordSuperService.java @@ -39,7 +39,7 @@ public ExportWordSuperService() { } /** - * Word导出 + * Word export **/ @SneakyThrows @Override @@ -51,18 +51,18 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { .stream().collect(Collectors.groupingBy(v -> v.getKey().split("---")[0])); List> list = new ArrayList<>(); Map myDataMap = new HashMap<>(2); - //索引表头 + //Index header RowRenderData indexHeaderRow = Rows.of(CommonConstant.INDEX_HEAD_NAMES).center().textBold().textColor("000000").bgColor("bfbfbf").create(); - //字段表头 + //Field header RowRenderData tableHeaderRow = Rows.of(CommonConstant.COLUMN_HEAD_NAMES).center().textBold().textColor("000000").bgColor("bfbfbf").create(); for (Map.Entry>>> myMap : allMap.entrySet()) { - //数据库名 + //Database name String database = myMap.getKey(); int i = 1; for (Map.Entry> parameterMap : myMap.getValue()) { - //初始化容量 3/0.75 + 1 + //Initial capacity 3/0.75 + 1 Map tableData = new HashMap<>(8); - //索引Table + //IndexTable if (isExportIndex) { String name = parameterMap.getKey().split("\\[")[0]; List indexInfoVOList = indexMap.get(name); @@ -74,7 +74,7 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { map.put("dataBase", database); tableData.put("ifDatabase", map); } - //表名 + //Table Name String tableName = parameterMap.getKey().split("---")[1]; tableData.put("number", i); tableData.put("name", tableName); @@ -86,7 +86,7 @@ public void export(OutputStream outputStream, ExportOptions exportOptions) { } } myDataMap.put("mydata", Includes.ofStream(subFile).setRenderModel(list).create()); - /*根据模板生成文档*/ + /*Generate documents based on template*/ XWPFTemplate template = XWPFTemplate.compile(filePath).render(myDataMap); AddToTopic.generateTOC(template.getXWPFDocument(), outputStream); } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/merge/MyMergeExcel.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/merge/MyMergeExcel.java index 7546842be..0940dcb3a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/merge/MyMergeExcel.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/merge/MyMergeExcel.java @@ -22,24 +22,24 @@ protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex Row row = sheet.getRow(cell.getRowIndex()); cell = row.getCell(0); Workbook workbook = sheet.getWorkbook(); - // 生成一个样式 + // generate a style CellStyle style = workbook.createCellStyle(); - // 设置这些样式 + // Set these styles style.setBorderBottom(BorderStyle.THIN); style.setBorderLeft(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); - //设置填充方案 + //Set up filling scheme style.setFillPattern(FillPatternType.SOLID_FOREGROUND); - //设置自定义填充颜色 + //Set custom fill color style.setFillForegroundColor(IndexedColors.GREEN.getIndex()); - // 生成一个字体 + // generate a font Font font = workbook.createFont(); font.setBold(true); font.setFontHeightInPoints((short) 14); - // 把字体应用到当前的样式 + // Apply font to current style style.setFont(font); cell.setCellStyle(style); } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/style/CustomExcelStyle.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/style/CustomExcelStyle.java index 803d7b0ea..09b3c79ed 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/style/CustomExcelStyle.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/doc/style/CustomExcelStyle.java @@ -14,9 +14,9 @@ **/ public class CustomExcelStyle { public static WriteCellStyle getContentWriteCellStyle() { - //内容样式策略 + //Content style strategy WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); - //垂直居中,水平居中 + //Center vertically, center horizontally contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); @@ -24,11 +24,11 @@ public static WriteCellStyle getContentWriteCellStyle() { contentWriteCellStyle.setBorderTop(BorderStyle.THIN); contentWriteCellStyle.setBorderRight(BorderStyle.THIN); contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); - //设置 自动换行 + //Set automatic line wrapping contentWriteCellStyle.setWrapped(true); - // 字体策略 + // Font strategy WriteFont contentWriteFont = new WriteFont(); - // 字体大小 + // font size contentWriteFont.setFontHeightInPoints((short) 11); contentWriteFont.setFontName("宋体"); contentWriteFont.setColor(IndexedColors.BLACK.getIndex()); @@ -37,7 +37,7 @@ public static WriteCellStyle getContentWriteCellStyle() { } public static WriteCellStyle getHeadStyle() { - //头策略使用默认 设置字体大小 + //Header policy uses default settings for font size WriteCellStyle headWriteCellStyle = new WriteCellStyle(); headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/factory/ExportDBDataStrategyFactory.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/factory/ExportDBDataStrategyFactory.java new file mode 100644 index 000000000..638557b17 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/factory/ExportDBDataStrategyFactory.java @@ -0,0 +1,31 @@ +package ai.chat2db.server.web.api.controller.rdb.factory; + +import ai.chat2db.server.domain.api.enums.ExportTypeEnum; +import ai.chat2db.server.web.api.controller.rdb.data.export.strategy.*; +import lombok.SneakyThrows; + +import java.util.Map; + +/** + * @author: zgq + * @date: 2024年03月24日 12:53 + */ +public class ExportDBDataStrategyFactory { + + public static final Map> SERVICE_MAP = Map.of( + ExportTypeEnum.SQL.getCode(), ExportDBData2SqlStrategy.class, + ExportTypeEnum.CSV.getCode(), ExportDBData2CsvStrategy.class, + ExportTypeEnum.EXCEL.getCode(), ExportDBData2ExcelStrategy.class, + ExportTypeEnum.JSON.getCode(), ExportDBData2JsonStrategy.class + ); + + @SneakyThrows + public static Class get(String type) { + Class dataResult = SERVICE_MAP.get(type); + if (dataResult == null) { + throw new ClassNotFoundException("no ExportUI was found"); + } else { + return dataResult; + } + } +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/factory/ExportServiceFactory.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/factory/ExportServiceFactory.java index ff968f730..7ca9c99bd 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/factory/ExportServiceFactory.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/factory/ExportServiceFactory.java @@ -15,13 +15,11 @@ public class ExportServiceFactory { /** - * Export实现类缓存池 + * Export implementation class cache pool */ private static final Map> REPORT_POOL = new ConcurrentHashMap<>(8); - - static { REPORT_POOL.put(ExportTypeEnum.EXCEL.name(), ExportExcelService.class); REPORT_POOL.put(ExportTypeEnum.WORD.name(), ExportWordSuperService.class); @@ -31,9 +29,9 @@ public class ExportServiceFactory { } /** - * 获取对应接口 + * Get the corresponding interface * - * @param type 报表类型 + * @param type dashboard type * @return Class */ @SneakyThrows diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ColumnRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ColumnRequest.java index 308faf17e..85fab0ef1 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ColumnRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ColumnRequest.java @@ -6,9 +6,9 @@ import lombok.experimental.SuperBuilder; /** - * 列 + * Column * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -17,43 +17,43 @@ public class ColumnRequest { /** - * 旧的列名,在修改列的时候需要这个参数 - * 不修改也可以传 + * The old column name, this parameter is needed when modifying the column + * You can send it without modification */ private String oldName; /** - * 名称 + * name */ private String name; /** - * 列的类型 - * 比如 varchar(100) ,double(10,6) + * Column type + * For example, varchar(100), double(10,6) */ private String columnType; /** - * 是否为空 + * Is it empty */ private Integer nullable; /** - * 是否主键 + * Is it a primary key? */ private Boolean primaryKey; /** - * 默认值 + * default value */ private String defaultValue; /** - * 是否自增 + * Whether to increment automatically */ private Boolean autoIncrement; /** - * 注释 + * comment */ private String comment; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DataExportRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DataExportRequest.java index e062c37d8..c4f02e7d1 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DataExportRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DataExportRequest.java @@ -8,7 +8,7 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DatabaseExportDataRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DatabaseExportDataRequest.java new file mode 100644 index 000000000..41686b503 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DatabaseExportDataRequest.java @@ -0,0 +1,19 @@ +package ai.chat2db.server.web.api.controller.rdb.request; + +import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequest; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: zgq + * @date: 2024年03月24日 12:36 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class DatabaseExportDataRequest extends DataSourceBaseRequest { + @NotNull + private String exportType; +} \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DatabaseExportRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DatabaseExportRequest.java new file mode 100644 index 000000000..291f00d00 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DatabaseExportRequest.java @@ -0,0 +1,17 @@ +package ai.chat2db.server.web.api.controller.rdb.request; + +import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequest; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: zgq + * @date: February 27, 2024 22:03 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class DatabaseExportRequest extends DataSourceBaseRequest { + private Boolean containData; +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlCountRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlCountRequest.java index 79d58aaa1..244f63286 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlCountRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlCountRequest.java @@ -8,7 +8,7 @@ import lombok.Data; /** - * 统计数量 + * total number * * @author Jiaju Zhuang */ @@ -16,13 +16,13 @@ public class DdlCountRequest extends DataSourceBaseRequest implements DataSourceConsoleRequestInfo { /** - * sql语句 + * sql statement */ @NotNull private String sql; /** - * 控制台id + * console id */ @NotNull private Long consoleId; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlExportRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlExportRequest.java index 4a883ebdf..3212f3834 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlExportRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlExportRequest.java @@ -8,14 +8,14 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class DdlExportRequest extends DataSourceBaseRequest { /** - * 表名称 + * Table Name */ @NotNull private String tableName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlRequest.java index 8e73b73ef..2b69e1b06 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DdlRequest.java @@ -9,39 +9,39 @@ /** * @author moji - * @version TableManageRequest.java, v 0.1 2022年09月16日 17:55 moji Exp $ + * @version TableManageRequest.java, v 0.1 September 16, 2022 17:55 moji Exp $ * @date 2022/09/16 */ @Data public class DdlRequest extends DataSourceBaseRequest implements DataSourceConsoleRequestInfo { /** - * sql语句 + * sql statement */ @NotNull private String sql; /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 分页编码 - * 只有select语句才有 + * Page coding + * Only available for select statements */ private Integer pageNo; /** - * 分页大小 - * 只有select语句才有 + * Paging Size + * Only available for select statements */ private Integer pageSize; /** - * 返回全部数据 - * 只有select语句才有 + * Return all data + * Only available for select statements */ private Boolean pageSizeAll; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlRequest.java index 593426a15..d6289ce2f 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlRequest.java @@ -9,39 +9,39 @@ /** * @author moji - * @version TableManageRequest.java, v 0.1 2022年09月16日 17:55 moji Exp $ + * @version TableManageRequest.java, v 0.1 September 16, 2022 17:55 moji Exp $ * @date 2022/09/16 */ @Data public class DmlRequest extends DataSourceBaseRequest implements DataSourceConsoleRequestInfo { /** - * sql语句 + * sql statement */ @NotNull private String sql; /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 分页编码 - * 只有select语句才有 + *Page coding + * Only available for select statements */ private Integer pageNo; /** - * 分页大小 - * 只有select语句才有 + * Paging Size + * Only available for select statements */ private Integer pageSize; /** - * 返回全部数据 - * 只有select语句才有 + * Return all data + * Only available for select statements */ private Boolean pageSizeAll; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlSqlCopyRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlSqlCopyRequest.java new file mode 100644 index 000000000..6a3609f65 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlSqlCopyRequest.java @@ -0,0 +1,14 @@ +package ai.chat2db.server.web.api.controller.rdb.request; + +import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequest; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class DmlSqlCopyRequest extends DataSourceBaseRequest { + + @NotNull + private String tableName; + + private String type; +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlTableRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlTableRequest.java index 21efc6839..5e1573f5b 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlTableRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/DmlTableRequest.java @@ -7,39 +7,39 @@ /** * @author moji - * @version TableManageRequest.java, v 0.1 2022年09月16日 17:55 moji Exp $ + * @version TableManageRequest.java, v 0.1 September 16, 2022 17:55 moji Exp $ * @date 2022/09/16 */ @Data public class DmlTableRequest extends DataSourceBaseRequest implements DataSourceConsoleRequestInfo { /** - * 表的名词 + * table noun */ @NotNull private String tableName; /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 分页编码 - * 只有select语句才有 + *Page coding + * Only available for select statements */ private Integer pageNo; /** - * 分页大小 - * 只有select语句才有 + * Paging Size + * Only available for select statements */ private Integer pageSize; /** - * 返回全部数据 - * 只有select语句才有 + * Return all data + * Only available for select statements */ private Boolean pageSizeAll; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionDetailRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionDetailRequest.java index 344b093f2..494e2a7b5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionDetailRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionDetailRequest.java @@ -8,17 +8,17 @@ public class FunctionDetailRequest implements DataSourceBaseRequestInfo { /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间,pg,oracle需要,mysql不需要 + * The space where the table is located is required by pg and oracle, but not by mysql. */ private String schemaName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionPageRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionPageRequest.java index 8f625c5b2..107176fbf 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionPageRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/FunctionPageRequest.java @@ -13,22 +13,22 @@ public class FunctionPageRequest extends PageQueryRequest implements DataSourceB @Serial private static final long serialVersionUID = -364547173428396332L; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间,pg,oracle需要,mysql不需要 + * The space where the table is located is required by pg and oracle, but not by mysql. */ private String schemaName; /** - * 模糊搜索词 + * Fuzzy search terms */ private String searchKey; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/IndexRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/IndexRequest.java index ae798888d..25eef7162 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/IndexRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/IndexRequest.java @@ -11,9 +11,9 @@ import lombok.experimental.SuperBuilder; /** - * 索引 + * index * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -22,24 +22,24 @@ public class IndexRequest { /** - * 索引名称 + * Index name */ private String name; /** - * 所以类型 + * all types * * @see IndexTypeEnum */ private String type; /** - * 注释 + * Comment */ private String comment; /** - * 索引包含的列 + * Columns included in the index */ private List columnList; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/NewTableSqlRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/NewTableSqlRequest.java index a2aeb6fcd..eb7997c0a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/NewTableSqlRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/NewTableSqlRequest.java @@ -8,7 +8,7 @@ public class NewTableSqlRequest extends DataSourceBaseRequest { /** - * 新的表结构 + * new table structure */ @NotNull private TableRequest newTable; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/OrderByRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/OrderByRequest.java index e48b5a0bd..509e5d24a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/OrderByRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/OrderByRequest.java @@ -16,7 +16,7 @@ public class OrderByRequest extends DataSourceBaseRequest implements DataSourceB private String originSql; /** - * 排序字段 + * sort field */ private List orderByList; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedureDetailRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedureDetailRequest.java index 4e080230a..16debd631 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedureDetailRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedureDetailRequest.java @@ -12,17 +12,17 @@ public class ProcedureDetailRequest implements DataSourceBaseRequestInfo { @Serial private static final long serialVersionUID = -364547173428396332L; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间,pg,oracle需要,mysql不需要 + * The space where the table is located is required by pg and oracle, but not by mysql. */ private String schemaName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedurePageRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedurePageRequest.java index f0116c1e3..582c92e1e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedurePageRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedurePageRequest.java @@ -13,22 +13,22 @@ public class ProcedurePageRequest extends PageQueryRequest implements DataSource @Serial private static final long serialVersionUID = -364547173428396332L; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间,pg,oracle需要,mysql不需要 + * The space where the table is located is required by pg and oracle, but not by mysql. */ private String schemaName; /** - * 模糊搜索词 + * Fuzzy search terms */ private String searchKey; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedureUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedureUpdateRequest.java new file mode 100644 index 000000000..6f2a767cd --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/ProcedureUpdateRequest.java @@ -0,0 +1,20 @@ +package ai.chat2db.server.web.api.controller.rdb.request; + +import ai.chat2db.server.web.api.controller.data.source.request.DataSourceBaseRequest; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: zgq + * @date: February 24, 2024 13:21 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProcedureUpdateRequest extends DataSourceBaseRequest { + + private String procedureName; + private String procedureBody; + +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SchemaCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SchemaCreateRequest.java index 9ee25784d..67919a43b 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SchemaCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SchemaCreateRequest.java @@ -8,7 +8,7 @@ public class SchemaCreateRequest extends DataSourceBaseRequest { /** - * 数据名字 + * Data name */ @JsonAlias({"TABLE_SCHEM"}) private String name; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SelectResultUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SelectResultUpdateRequest.java index b87b173e0..48e087218 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SelectResultUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/SelectResultUpdateRequest.java @@ -14,23 +14,23 @@ public class SelectResultUpdateRequest extends DataSourceBaseRequest implements DataSourceConsoleRequestInfo { /** - * 展示头的列表 + * List of display headers */ private List
      headerList; /** - * 修改后数据的列表 + * List of modified data */ @NotEmpty private List operations; /** - * 表名 + * Table Name */ private String tableName; /** - * 控制台id + * console id */ @NotNull private Long consoleId; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableBriefQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableBriefQueryRequest.java index ed3395630..74ea379ef 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableBriefQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableBriefQueryRequest.java @@ -11,7 +11,7 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data @@ -20,22 +20,22 @@ public class TableBriefQueryRequest extends PageQueryRequest implements DataSour @Serial private static final long serialVersionUID = -364547173428396332L; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间,pg,oracle需要,mysql不需要 + * The space where the table is located is required by pg and oracle, but not by mysql. */ private String schemaName; /** - * 模糊搜索词 + * Fuzzy search terms */ private String searchKey; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableCreateDdlQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableCreateDdlQueryRequest.java index 2f4a5c1b0..97973f4ab 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableCreateDdlQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableCreateDdlQueryRequest.java @@ -6,14 +6,14 @@ /** * @author moji - * @version TableCreateDdlQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version TableCreateDdlQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class TableCreateDdlQueryRequest { /** - * DB类型 + * DB type * @see ai.chat2db.server.domain.support.enums.DbTypeEnum */ @NotNull diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDeleteRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDeleteRequest.java index e1828b929..efaf22b32 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDeleteRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDeleteRequest.java @@ -9,14 +9,14 @@ /** * @author moji - * @version TableManageRequest.java, v 0.1 2022年09月16日 17:55 moji Exp $ + * @version TableManageRequest.java, v 0.1 September 16, 2022 17:55 moji Exp $ * @date 2022/09/16 */ @Data public class TableDeleteRequest extends DataSourceBaseRequest { /** - * 表名称 + * Table Name */ @NotNull private String tableName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDetailQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDetailQueryRequest.java index 073407242..7e0f9e793 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDetailQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableDetailQueryRequest.java @@ -6,14 +6,14 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class TableDetailQueryRequest extends DataSourceBaseRequest { /** - * 表名称 + * Table Name */ @NotNull private String tableName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableModifySqlRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableModifySqlRequest.java index ce327a83b..dcad7d54a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableModifySqlRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableModifySqlRequest.java @@ -7,21 +7,21 @@ import lombok.Data; /** - * 修改表sql请求 + * Modify table sql request * - * @author 是仪 + * @author Shi Yi */ @Data public class TableModifySqlRequest extends DataSourceBaseRequest { /** - * 旧的表结构 - * 为空代表新建表 + * Old table structure + * Empty means creating a new table */ private TableRequest oldTable; /** - * 新的表结构 + * new table structure */ @NotNull private TableRequest newTable; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableQueryRequest.java index 2a1ddf038..fde071490 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableQueryRequest.java @@ -22,19 +22,19 @@ public class TableQueryRequest extends PageQueryRequest implements DataSourceBas private static final long serialVersionUID = 5794716286491282784L; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ @NotNull private String databaseName; /** - * 表名 + * Table Name */ private String tableName; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableRequest.java index 3d38ab415..1d484c00a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableRequest.java @@ -13,7 +13,7 @@ /** * 修改表sql请求 * - * @author 是仪 + * @author Shi Yi */ @Data @SuperBuilder @@ -21,33 +21,33 @@ @AllArgsConstructor public class TableRequest { /** - * 表名称 + * Table Name */ private String name; /** - * 表描述 + * Table description */ private String comment; /** - * 列 + * Column */ private List columnList; /** - * 索引 + * index */ private List indexList; /** - * 空间名 + * Space name */ private String schemaName; /** - * 数据库名 + * Database name */ private String databaseName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableUpdateDdlQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableUpdateDdlQueryRequest.java index 82e59c6de..3969b36d2 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableUpdateDdlQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TableUpdateDdlQueryRequest.java @@ -6,14 +6,14 @@ /** * @author moji - * @version TableUpdateDdlQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version TableUpdateDdlQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class TableUpdateDdlQueryRequest { /** - * DB类型 + * DB type * @see ai.chat2db.server.domain.support.enums.DbTypeEnum */ @NotNull diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerDetailRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerDetailRequest.java index 7dbe71ec8..83fb5bf1d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerDetailRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerDetailRequest.java @@ -11,17 +11,17 @@ public class TriggerDetailRequest implements DataSourceBaseRequestInfo { @Serial private static final long serialVersionUID = -364547173428396332L; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间,pg,oracle需要,mysql不需要 + * The space where the table is located is required by pg and oracle, but not by mysql. */ private String schemaName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerPageRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerPageRequest.java index 9b4b103a3..ab34b67ab 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerPageRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TriggerPageRequest.java @@ -12,22 +12,22 @@ public class TriggerPageRequest extends PageQueryRequest implements DataSourceBa @Serial private static final long serialVersionUID = -364547173428396332L; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; /** - * 表所在空间,pg,oracle需要,mysql不需要 + * The space where the table is located is required by pg and oracle, but not by mysql. */ private String schemaName; /** - * 模糊搜索词 + * Fuzzy search terms */ private String searchKey; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TypeQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TypeQueryRequest.java index a7f1c6d54..7981a626f 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TypeQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/request/TypeQueryRequest.java @@ -10,7 +10,7 @@ public class TypeQueryRequest implements DataSourceBaseRequestInfo { @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ private String databaseName; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ColumnVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ColumnVO.java index 241a1345c..5aa10bd26 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ColumnVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ColumnVO.java @@ -7,7 +7,7 @@ /** * @author moji - * @version TableVO.java, v 0.1 2022年09月16日 17:16 moji Exp $ + * @version TableVO.java, v 0.1 September 16, 2022 17:16 moji Exp $ * @date 2022/09/16 */ @Data @@ -16,65 +16,65 @@ @AllArgsConstructor public class ColumnVO { /** - * 旧的列名,在修改列的时候需要这个参数 - * 在返回的时候oldName=name + * The old column name, this parameter is needed when modifying the column + * oldName=name when returning */ private String oldName; /** - * 列名 + * Column name */ private String name; /** - * 表名 + * Table Name */ private String tableName; /** - * 列的类型 - * 比如 varchar(100) ,double(10,6) + * Column type + * For example, varchar(100), double(10,6) */ private String columnType; /** - * 列的数据类型 - * 比如 varchar ,double + * Column data type + * For example, varchar, double */ private Integer dataType; /** - * 默认值 + * default value */ private String defaultValue; /** - * 是否自增 - * 为空 代表没有值 数据库的实际语义是 false + * Whether to increase automatically + * Empty means there is no value. The actual semantics of the database are false. */ private Boolean autoIncrement; /** - * 注释 + * Comment */ private String comment; /** - * 是否主键 + * Is it a primary key? */ private Boolean primaryKey; /** - * 空间名 + * Space name */ private String schemaName; /** - * 数据库名 + * Database name */ private String databaseName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ExecuteResultVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ExecuteResultVO.java index 69147adeb..71f769e1e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ExecuteResultVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ExecuteResultVO.java @@ -8,14 +8,14 @@ /** * @author moji - * @version ExecuteResultVO.java, v 0.1 2022年10月23日 11:20 moji Exp $ + * @version ExecuteResultVO.java, v 0.1 October 23, 2022 11:20 moji Exp $ * @date 2022/10/23 */ @Data public class ExecuteResultVO { /** - * 执行的sql + * executed sql */ private String sql; @@ -25,56 +25,56 @@ public class ExecuteResultVO { private String originalSql; /** - * 描述 + * description */ private String description; /** - * 失败消息提示 + * Failure message prompt */ private String message; /** - * 是否成功标志位 + * success flag */ private Boolean success; /** - * 修改行数 查询sql不会返回 + * Modify the number of rows and query sql will not return */ private Integer updateCount; /** - * 展示头的列表 + * List of display headers */ private List
      headerList; /** - * 数据的列表 + * list of data */ private List> dataList; /** - * sql 类型 + * sql type * */ private String sqlType; /** - * 是否存在下一页 - * 只有select语句才有 + * Whether there is a next page + * Only available for select statements */ private Boolean hasNextPage; /** - * 分页编码 - * 只有select语句才有 + * Page coding + * Only available for select statements */ private Integer pageNo; /** - * 分页大小 - * 只有select语句才有 + * Paging Size + * Only available for select statements */ private Integer pageSize; @@ -85,17 +85,17 @@ public class ExecuteResultVO { private String fuzzyTotal; /** - * 执行持续时间 + * execution duration */ private Long duration; /** - * 返回结果是否可以编辑 + * Whether the returned result can be edited */ private boolean canEdit; /** - * 表名 + * Table Name */ private String tableName; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexColumnVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexColumnVO.java index 1f4be4c57..3f00ea1d5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexColumnVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexColumnVO.java @@ -7,7 +7,7 @@ import lombok.experimental.SuperBuilder; /** - * 列信息 + * Column information * * @author Jiaju Zhuang */ @@ -18,56 +18,56 @@ public class IndexColumnVO { /** - * 索引名称 + * Index name */ private String indexName; /** - * 表名 + * Table Name */ private String tableName; /** - * 索引类型 + * index type * * @see */ private String type; /** - * 注释 + * Comment */ private String comment; /** - * 列名 + * Column name */ private String columnName; /** - * 顺序 + * order */ private Short ordinalPosition; /** - * 排序 + * sort * */ private String collation; /** - * 索引所属schema + * The schema to which the index belongs */ private String schemaName; /** - * 数据库名 + * Database name */ private String databaseName; /** - * 是否唯一 + * Is it unique? */ private Boolean nonUnique; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexVO.java index 5282df01d..50e5a9abe 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/IndexVO.java @@ -8,36 +8,36 @@ /** * @author moji - * @version IndexVO.java, v 0.1 2022年09月16日 17:47 moji Exp $ + * @version IndexVO.java, v 0.1 September 16, 2022 17:47 moji Exp $ * @date 2022/09/16 */ @Data public class IndexVO { /** - * 包含列 + * Contains columns */ private String columns; /** - * 索引名称 + * Index name */ private String name; /** - * 所以类型 + * all types * * @see IndexTypeEnum */ private String type; /** - * 注释 + * Comment */ private String comment; /** - * 索引包含的列 + * Columns included in the index */ private List columnList; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/KeyVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/KeyVO.java index fb772c801..071f1f5b5 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/KeyVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/KeyVO.java @@ -6,29 +6,29 @@ /** * @author moji - * @version IndexVO.java, v 0.1 2022年09月16日 17:47 moji Exp $ + * @version IndexVO.java, v 0.1 September 16, 2022 17:47 moji Exp $ * @date 2022/09/16 */ @Data public class KeyVO { /** - * 包含列 + * Contains columns */ private String columns; /** - * 索引名称 + * Index name */ private String name; /** - * 注释 + * Comment */ private String comment; /** - * 索引包含的列 + * Columns included in the index */ private List columnList; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SchemaVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SchemaVO.java index 841363514..817e11799 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SchemaVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SchemaVO.java @@ -10,7 +10,7 @@ @Data public class SchemaVO { /** - * 数据名字 + * Data name */ private String name; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SqlVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SqlVO.java index abb47b8ba..d691aa4b3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SqlVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/SqlVO.java @@ -6,7 +6,7 @@ import lombok.experimental.SuperBuilder; /** - * sql对象 + * sql object * * @author Jiaju Zhuang */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/TableVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/TableVO.java index fd18e242f..59ed67c54 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/TableVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/TableVO.java @@ -8,34 +8,34 @@ /** * @author moji - * @version TableVO.java, v 0.1 2022年09月16日 17:16 moji Exp $ + * @version TableVO.java, v 0.1 September 16, 2022 17:16 moji Exp $ * @date 2022/09/16 */ @Data public class TableVO { /** - * 表名称 + * Table Name */ private String name; /** - * 表描述 + * Table description */ private String comment; /** - * 列 + * Column */ private List columnList; /** - * 索引 + * index */ private List indexList; /** - * 是否已经被固定 + * Has it been fixed? */ private boolean pinned; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ViewVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ViewVO.java index 42094ead3..77a32de7d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ViewVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/vo/ViewVO.java @@ -3,7 +3,7 @@ //public class ViewVO extends TableVO{ // // /** -// * 视图脚本 +// * view script // */ // private String script; //} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyManageController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyManageController.java index e2ab8a72f..e378462f9 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyManageController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyManageController.java @@ -17,10 +17,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * redis key运维类 + * redis key operation and maintenance class * * @author moji - * @version MysqlTableManageController.java, v 0.1 2022年09月16日 17:41 moji Exp $ + * @version MysqlTableManageController.java, v 0.1 September 16, 2022 17:41 moji Exp $ * @date 2022/09/16 */ @RequestMapping("/api/redis/key") @@ -28,7 +28,7 @@ public class RedisKeyManageController { /** - * 查询当前DB下的key列表 + * Query the key list under the current DB * * @param request * @return @@ -39,7 +39,7 @@ public ListResult list(KeyQueryRequest request) { } /** - * 新增Key + * Add Key * * @param request * @return @@ -50,7 +50,7 @@ public ActionResult create(@RequestBody KeyCreateRequest request) { } /** - * 修改key信息 + * Modify key information * * @param request * @return @@ -62,7 +62,7 @@ public ActionResult update(@RequestBody KeyUpdateRequest request) { /** - * 删除key + * Delete key * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyValueManageController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyValueManageController.java index 742550963..180c4aba8 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyValueManageController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/RedisKeyValueManageController.java @@ -14,10 +14,10 @@ import org.springframework.web.bind.annotation.RestController; /** - * redis数据运维类 + * redis data operation and maintenance class * * @author moji - * @version MysqlDataManageController.java, v 0.1 2022年09月16日 17:37 moji Exp $ + * @version MysqlDataManageController.java, v 0.1 September 16, 2022 17:37 moji Exp $ * @date 2022/09/16 */ @RequestMapping("/api/redis/kv") @@ -25,7 +25,7 @@ public class RedisKeyValueManageController { /** - * redis ddl命令执行 + * redis ddl command execution * * @param request * @return @@ -36,7 +36,7 @@ public DataResult manage(@RequestBody KeyValueManageRequest request) { } /** - * 获取缓存key详情 + * Get cache key details * * @param request * @return @@ -47,7 +47,7 @@ public DataResult query(KeyQueryRequest request) { } /** - * 更新key值 + * Update key value * * @param request * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyCreateRequest.java index 3316aa488..4db3ddda4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyCreateRequest.java @@ -9,25 +9,25 @@ /** * @author moji - * @version TableVO.java, v 0.1 2022年09月16日 17:16 moji Exp $ + * @version TableVO.java, v 0.1 September 16, 2022 17:16 moji Exp $ * @date 2022/09/16 */ @Data public class KeyCreateRequest extends DataSourceBaseRequest { /** - * key名称 + * key name */ @NotNull private String name; /** - * key值 + * key value */ private Object value; /** - * 过期时间 + * Expiration */ private Long ttl; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyDeleteRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyDeleteRequest.java index ba22a0cb1..0570ad080 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyDeleteRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyDeleteRequest.java @@ -7,14 +7,14 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class KeyDeleteRequest extends DataSourceBaseRequest { /** - * key名称 + * key name */ private String keyName; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyQueryRequest.java index 3f44ea925..0fe42693d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyQueryRequest.java @@ -7,19 +7,19 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class KeyQueryRequest extends DataSourceBaseRequest { /** - * 缓存key名称 + * Cache key name */ private String keyName; /** - * 搜索关键词 + * search keyword */ private String searchKey; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyUpdateRequest.java index e37a290ad..30633959d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyUpdateRequest.java @@ -9,30 +9,30 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class KeyUpdateRequest extends DataSourceBaseRequest { /** - * key名称 + * key name */ @NotNull private String originalKey; /** - * 更新后key名称 + * Key name after update */ private String updateKey; /** - * 原始ttl值 + * Original ttl value */ private Long originalTtl; /** - * 更新后ttl值 + * ttl value after update */ private Object updateTtl; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyValueManageRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyValueManageRequest.java index 3fd41b171..8cf805ef1 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyValueManageRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/KeyValueManageRequest.java @@ -9,14 +9,14 @@ /** * @author moji - * @version TableManageRequest.java, v 0.1 2022年09月16日 17:55 moji Exp $ + * @version TableManageRequest.java, v 0.1 September 16, 2022 17:55 moji Exp $ * @date 2022/09/16 */ @Data public class KeyValueManageRequest extends DataSourceBaseRequest { /** - * redis ddl语句 + * redis ddl statement */ @NotNull private String ddl; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/ValueUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/ValueUpdateRequest.java index 755afd231..87fb3f996 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/ValueUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/request/ValueUpdateRequest.java @@ -9,26 +9,26 @@ /** * @author moji - * @version ConnectionQueryRequest.java, v 0.1 2022年09月16日 14:23 moji Exp $ + * @version ConnectionQueryRequest.java, v 0.1 September 16, 2022 14:23 moji Exp $ * @date 2022/09/16 */ @Data public class ValueUpdateRequest extends DataSourceBaseRequest { /** - * key名称 + * key name */ @NotNull private String key; /** - * 原始key值 + * Original key value */ @NotNull private Object originalValue; /** - * 更新后key值 + * Key value after update */ @NotNull private Object updateValue; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/vo/KeyVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/vo/KeyVO.java index 318cbf96b..d215c782c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/vo/KeyVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/redis/vo/KeyVO.java @@ -4,29 +4,29 @@ /** * @author moji - * @version Table.java, v 0.1 2022年09月16日 17:16 moji Exp $ + * @version Table.java, v 0.1 September 16, 2022 17:16 moji Exp $ * @date 2022/09/16 */ @Data public class KeyVO { /** - * key名称 + * key name */ private String name; /** - * key值 + * key value */ private Object value; /** - * key类型 + * key type */ private String type; /** - * 过期时间 + * Expiration */ private Long ttl; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/SystemController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/SystemController.java index 6d0db0a45..146038da2 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/SystemController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/SystemController.java @@ -30,7 +30,7 @@ /** * @author jipengfei - * @version : HomeController.java, v 0.1 2022年09月18日 14:52 jipengfei Exp $ + * @version : HomeController.java, v 0.1 September 18, 2022 14:52 jipengfei Exp $ */ @RestController @RequestMapping("/api/system") @@ -47,7 +47,7 @@ public class SystemController { private ConfigService configService; /** - * 检测是否成功 + * Check if the test is successful * * @return */ @@ -124,7 +124,7 @@ public ActionResult setUpdateType(@RequestBody String updateType) { } /** - * 获取当前版本号 + * Get the current version number * * @return */ @@ -134,11 +134,11 @@ public DataResult getVersion() { } /** - * 退出服务 + * Exit service */ @RequestMapping("/stop") public DataResult stop(boolean forceQuit) { - log.info("退出应用"); + log.info("Exit application"); if (forceQuit) { stop(); } else { @@ -154,21 +154,21 @@ public DataResult stop(boolean forceQuit) { private void stop() { new Thread(() -> { - // 会在100ms以后 退出后台 + // Will exit the background after 100ms try { Thread.sleep(200L); } catch (InterruptedException e) { throw new RuntimeException(e); } - log.info("开始退出Spring应用"); + log.info("Start exiting Spring application"); SSHManager.close(); try { SpringApplication.exit(applicationContext); } catch (Exception ignore) { } - // 有可能SpringApplication.exit 会退出失败 - // 直接系统退出 - log.info("开始退出系统应用"); + // It is possible that SpringApplication.exit will fail to exit + // Direct system exit + log.info("Start exiting system applications"); CacheManage.close(); try { System.exit(0); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/util/SystemUtils.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/util/SystemUtils.java index 4bc0f3fec..33b49f8be 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/util/SystemUtils.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/util/SystemUtils.java @@ -18,7 +18,7 @@ import java.time.Duration; /** - * 系统工具包 + * System Toolkit * * @author Jiaju Zhuang */ @@ -26,19 +26,19 @@ public class SystemUtils { /** - * 停止当前应用 + * Stop current application */ public static void stop() { new Thread(() -> { - log.info("1秒以后退出应用"); - // 1秒以后自动退出应用 + log.info("Exit the application after 1 second"); + // Automatically exit the application after 1 second try { Thread.sleep(1000L); } catch (InterruptedException e) { throw new RuntimeException(e); } - // 直接系统退出 - log.info("开始退出系统应用"); + // Direct system exit + log.info("Start exiting system applications"); SSHManager.close(); try { System.exit(0); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/vo/AppVersionVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/vo/AppVersionVO.java index 9bc6c507e..6f6a67af9 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/vo/AppVersionVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/system/vo/AppVersionVO.java @@ -7,52 +7,52 @@ @Data public class AppVersionVO { /** - * 主键 + * primary key */ private Long id; /** - * 新版本 + * new version */ private String version; // /** -// * 哪些版本可以升级到该版本 +// * Which versions can be upgraded to this version // */ // private String versionUse; // /** -// * 状态 +// * state // */ // private String status; /** - * 下载地址 + * downloadLink */ private String downloadLink; /** - * 手工更新,自动强制更新 + * Manual update, automatic forced update */ private String type; // /** -// * 白名单,用于测试 +// * Whitelist, for testing // */ // private String whiteList; /** - * 热更新包地址 + * Hot update package address */ private String hotUpgradeUrl; /** - * 更新日志 + * updateLog */ private String updateLog; /** - * 桌面 + * desktop */ private boolean desktop; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/ExportController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/ExportController.java new file mode 100644 index 000000000..2c0d01e73 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/ExportController.java @@ -0,0 +1,42 @@ +package ai.chat2db.server.web.api.controller.task; + +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect; +import ai.chat2db.server.web.api.controller.rdb.request.DataExportRequest; +import ai.chat2db.server.web.api.controller.task.biz.TaskBizService; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; + +@ConnectionInfoAspect +@RequestMapping("/api/export") +@Controller +@Slf4j +public class ExportController { + + @Autowired + private TaskBizService taskBizService; + + + /** + * export data + * + * @param request + * @return + */ + @PostMapping("/export_data") + public DataResult export(@Valid @RequestBody DataExportRequest request) { + return taskBizService.exportResultData(request); + } + + @PostMapping("/export_doc") + public DataResult exportDoc(@Valid @RequestBody DataExportRequest request) { + return taskBizService.exportSchemaDoc(request); + } + + +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/TaskController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/TaskController.java new file mode 100644 index 000000000..b6c784117 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/TaskController.java @@ -0,0 +1,77 @@ +package ai.chat2db.server.web.api.controller.task; + +import ai.chat2db.server.domain.api.model.Task; +import ai.chat2db.server.domain.api.param.TaskPageParam; +import ai.chat2db.server.domain.api.service.TaskService; +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.tools.base.wrapper.result.PageResult; +import ai.chat2db.server.tools.base.wrapper.result.web.WebPageResult; +import ai.chat2db.server.tools.common.util.ContextUtils; +import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.net.MalformedURLException; + +@ConnectionInfoAspect +@RequestMapping("/api/task") +@Controller +@Slf4j +public class TaskController { + + @Autowired + private TaskService taskService; + + + @GetMapping("/list") + public WebPageResult list() { + TaskPageParam taskPageParam = new TaskPageParam(); + taskPageParam.setPageNo(1); + taskPageParam.setPageSize(10); + taskPageParam.setUserId(ContextUtils.getUserId()); + PageResult task = taskService.page(taskPageParam); + return WebPageResult.of(task.getData(), 100L, 1, 10); + } + + @GetMapping("/download/{id}") + public ResponseEntity download(@PathVariable Long id) { + DataResult task = taskService.get(id); + if(task.getData() == null){ + log.error("task is null"); + throw new RuntimeException("task is null"); + } + if(ContextUtils.getUserId() != task.getData().getUserId()){ + log.error("task is not belong to user"); + throw new RuntimeException("task is not belong to user"); + } + + Resource resource = null; + try { + resource = new UrlResource("file://"+task.getData().getDownloadUrl()); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + + if (resource.exists() || resource.isReadable()) { + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"") + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .body(resource); + } else { + throw new RuntimeException("Could not read the file!"); + } + + } + + + +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/biz/TaskBizService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/biz/TaskBizService.java new file mode 100644 index 000000000..2623c580e --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/task/biz/TaskBizService.java @@ -0,0 +1,312 @@ +package ai.chat2db.server.web.api.controller.task.biz; + +import ai.chat2db.server.domain.api.enums.*; +import ai.chat2db.server.domain.api.param.*; +import ai.chat2db.server.domain.api.service.TableService; +import ai.chat2db.server.domain.api.service.TaskService; +import ai.chat2db.server.domain.repository.Dbutils; +import ai.chat2db.server.tools.base.excption.BusinessException; +import ai.chat2db.server.tools.base.wrapper.result.DataResult; +import ai.chat2db.server.tools.base.wrapper.result.PageResult; +import ai.chat2db.server.tools.common.model.Context; +import ai.chat2db.server.tools.common.model.LoginUser; +import ai.chat2db.server.tools.common.util.ContextUtils; +import ai.chat2db.server.tools.common.util.EasyCollectionUtils; +import ai.chat2db.server.web.api.controller.rdb.RdbDmlExportController; +import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter; +import ai.chat2db.server.web.api.controller.rdb.doc.DatabaseExportService; +import ai.chat2db.server.web.api.controller.rdb.doc.conf.ExportOptions; +import ai.chat2db.server.web.api.controller.rdb.factory.ExportServiceFactory; +import ai.chat2db.server.web.api.controller.rdb.request.DataExportRequest; +import ai.chat2db.server.web.api.controller.rdb.vo.TableVO; +import ai.chat2db.spi.jdbc.DefaultValueHandler; +import ai.chat2db.spi.model.Table; +import ai.chat2db.spi.sql.Chat2DBContext; +import ai.chat2db.spi.sql.ConnectInfo; +import ai.chat2db.spi.sql.SQLExecutor; +import ai.chat2db.spi.util.JdbcUtils; +import ai.chat2db.spi.util.SqlUtils; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.lang.Assert; +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; +import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; +import com.alibaba.druid.sql.ast.statement.SQLInsertStatement; +import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; +import com.alibaba.druid.sql.visitor.VisitorFeature; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.support.ExcelTypeEnum; +import com.alibaba.excel.write.builder.ExcelWriterBuilder; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.google.common.collect.Lists; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Constructor; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@Slf4j +@Component +public class TaskBizService { + + /** + * Format insert statement + */ + private static final SQLUtils.FormatOption INSERT_FORMAT_OPTION = new SQLUtils.FormatOption(true, false); + + static { + INSERT_FORMAT_OPTION.config(VisitorFeature.OutputNameQuote, true); + } + + + @Autowired + private TaskService taskService; + + + @Autowired + private TableService tableService; + + @Autowired + private RdbWebConverter rdbWebConverter; + + public DataResult exportResultData(DataExportRequest request) { + String sql = ExportSizeEnum.CURRENT_PAGE.getCode().equals(request.getExportSize()) ? request.getSql() : request.getOriginalSql(); + Assert.notBlank(sql, "dataSource.sqlEmpty"); + DbType dbType = JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType()); + String tableName = getTableName(request, sql, dbType); + File file = createTempFile(tableName, request.getExportType()); + DataResult dataResult = createTask(tableName, request.getDatabaseName(), request.getSchemaName(), request.getDataSourceId(), tableName); + + LoginUser loginUser = ContextUtils.getLoginUser(); + ConnectInfo connectInfo = Chat2DBContext.getConnectInfo().copy(); + CompletableFuture.runAsync(() -> { + buildContext(loginUser, connectInfo); + doExport(sql, file, dbType, tableName, request.getExportType()); + }).whenComplete((aVoid, throwable) -> { + updateStatus(dataResult.getData(), file, throwable); + removeContext(); + }); + return dataResult; + } + + public DataResult exportSchemaDoc(DataExportRequest request) { + File file = createTempFile(request.getDatabaseName(), request.getExportType()); + DataResult dataResult = createTask(null, request.getDatabaseName(), request.getSchemaName(), request.getDataSourceId(), "schema_doc"); + LoginUser loginUser = ContextUtils.getLoginUser(); + ConnectInfo connectInfo = Chat2DBContext.getConnectInfo().copy(); + CompletableFuture.runAsync(() -> { + buildContext(loginUser, connectInfo); + doExportDoc(request, file); + }).whenComplete((aVoid, throwable) -> { + updateStatus(dataResult.getData(), file, throwable); + removeContext(); + }); + return dataResult; + } + + private void doExportDoc(DataExportRequest request, File file) { + try { + TablePageQueryParam queryParam = rdbWebConverter.tablePageRequest2param(request); + queryParam.setPageNo(1); + queryParam.setPageSize(Integer.MAX_VALUE); + TableSelector tableSelector = new TableSelector(); + tableSelector.setColumnList(true); + tableSelector.setIndexList(true); + PageResult
      tableDTOPageResult = tableService.pageQuery(queryParam, tableSelector); + List tableVOS = rdbWebConverter.tableDto2vo(tableDTOPageResult.getData()); + TableQueryParam param = rdbWebConverter.tableRequest2param(request); + for (TableVO tableVO : tableVOS) { + param.setTableName(tableVO.getName()); + tableVO.setColumnList(tableService.queryColumns(param)); + tableVO.setIndexList(tableService.queryIndexes(param)); + } + Class targetClass = ExportServiceFactory.get(request.getExportType()); + Constructor constructor = targetClass.getDeclaredConstructor(); + DatabaseExportService databaseExportService = (DatabaseExportService) constructor.newInstance(); + // Set up data collection + databaseExportService.setExportList(tableVOS); + databaseExportService.generate(request.getDatabaseName(), new FileOutputStream(file), new ExportOptions()); + } catch (Exception e) { + log.error("export error", e); + throw new BusinessException("dataSource.exportError"); + } + } + + + private void removeContext() { + Dbutils.removeSession(); + ContextUtils.removeContext(); + Chat2DBContext.removeContext(); + } + + private void buildContext(LoginUser loginUser, ConnectInfo connectInfo) { + ContextUtils.setContext(Context.builder() + .loginUser(loginUser) + .build()); + Dbutils.setSession(); + Chat2DBContext.putContext(connectInfo); + } + + private DataResult createTask(String tableName, String databaseName, String schemaName, Long datasourceId, String taskName) { + TaskCreateParam param = new TaskCreateParam(); + param.setTaskName("export_" + taskName); + param.setTaskType(TaskTypeEnum.DOWNLOAD_TABLE_DATA.name()); + param.setDatabaseName(databaseName); + param.setSchemaName(schemaName); + param.setTableName(tableName); + param.setDataSourceId(datasourceId); + param.setUserId(ContextUtils.getUserId()); + param.setTaskProgress("0.1"); + return taskService.create(param); + } + + private void updateStatus(Long id, File file, Throwable throwable) { + TaskUpdateParam updateParam = new TaskUpdateParam(); + updateParam.setId(id); + updateParam.setTaskProgress("1"); + updateParam.setDownloadUrl(file.getAbsolutePath()); + if (throwable != null) { + log.error("export error", throwable); + updateParam.setTaskStatus(TaskStatusEnum.ERROR.name()); + } else { + updateParam.setTaskStatus(TaskStatusEnum.FINISH.name()); + } + taskService.updateStatus(updateParam); + } + + private void doExport(String sql, File file, DbType dbType, String tableName, String exportType) { + try { + if (ExportTypeEnum.CSV.getCode().equals(exportType)) { + doExportCsv(sql, file); + } else { + doExportInsert(sql, file, dbType, tableName); + } + } catch (Exception e) { + log.error("export error", e); + throw new BusinessException("dataSource.exportError"); + } + } + + + private File createTempFile(String tableName, String exportType) { + String fileName = URLEncoder.encode( + tableName + "_" + LocalDateTime.now().format(DatePattern.PURE_DATETIME_FORMATTER), + StandardCharsets.UTF_8) + .replaceAll("\\+", "%20"); + + if (ExportTypeEnum.CSV.getCode().equals(exportType)) { + return FileUtil.createTempFile(fileName, ".csv", true); + } else if (ExportTypeEnum.INSERT.getCode().equals(exportType)) { + return FileUtil.createTempFile(fileName, ".sql", true); + } else if (ExportTypeEnum.EXCEL.getCode().equals(exportType)) { + return FileUtil.createTempFile(fileName, ExportFileSuffix.EXCEL.getSuffix(), true); + } else if (ExportTypeEnum.MARKDOWN.getCode().equals(exportType)) { + return FileUtil.createTempFile(fileName, ExportFileSuffix.MARKDOWN.getSuffix(), true); + } else if (ExportTypeEnum.WORD.getCode().equals(exportType)) { + return FileUtil.createTempFile(fileName, ExportFileSuffix.WORD.getSuffix(), true); + } else if (ExportTypeEnum.PDF.getCode().equals(exportType)) { + return FileUtil.createTempFile(fileName, ExportFileSuffix.PDF.getSuffix(), true); + } else if (ExportTypeEnum.HTML.getCode().equals(exportType)) { + return FileUtil.createTempFile(fileName, ExportFileSuffix.HTML.getSuffix(), true); + } + return FileUtil.createTempFile(fileName, ".txt", true); + } + + private String getTableName(DataExportRequest request, String sql, DbType dbType) { + String tableName = null; + if (dbType != null) { + SQLStatement sqlStatement = SQLUtils.parseSingleStatement(sql, dbType); + if (!(sqlStatement instanceof SQLSelectStatement)) { + throw new BusinessException("dataSource.sqlAnalysisError"); + } + tableName = SqlUtils.getTableName(sql, dbType); + } else { + tableName = StringUtils.join(Lists.newArrayList(request.getDatabaseName(), request.getSchemaName()), "_"); + } + return tableName; + } + + private void doExportCsv(String sql, File file) { + RdbDmlExportController.ExcelWrapper excelWrapper = new RdbDmlExportController.ExcelWrapper(); + try { + ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(file) + .charset(StandardCharsets.UTF_8) + .excelType(ExcelTypeEnum.CSV); + excelWrapper.setExcelWriterBuilder(excelWriterBuilder); + SQLExecutor.getInstance().execute(Chat2DBContext.getConnection(), sql, headerList -> { + excelWriterBuilder.head( + EasyCollectionUtils.toList(headerList, header -> Lists.newArrayList(header.getName()))); + excelWrapper.setExcelWriter(excelWriterBuilder.build()); + excelWrapper.setWriteSheet(EasyExcel.writerSheet(0).build()); + }, dataList -> { + List> writeDataList = Lists.newArrayList(); + writeDataList.add(dataList); + excelWrapper.getExcelWriter().write(writeDataList, excelWrapper.getWriteSheet()); + }, false, new DefaultValueHandler()); + } finally { + if (excelWrapper.getExcelWriter() != null) { + excelWrapper.getExcelWriter().finish(); + } + } + } + + private void doExportInsert(String sql, File file, DbType dbType, + String tableName) + throws IOException { + try (PrintWriter printWriter = new PrintWriter(file, StandardCharsets.UTF_8.name())) { + RdbDmlExportController.InsertWrapper insertWrapper = new RdbDmlExportController.InsertWrapper(); + SQLExecutor.getInstance().execute(Chat2DBContext.getConnection(), sql, + headerList -> insertWrapper.setHeaderList( + EasyCollectionUtils.toList(headerList, header -> new SQLIdentifierExpr(header.getName()))) + , dataList -> { + SQLInsertStatement sqlInsertStatement = new SQLInsertStatement(); + sqlInsertStatement.setDbType(dbType); + sqlInsertStatement.setTableSource(new SQLExprTableSource(tableName)); + sqlInsertStatement.getColumns().addAll(insertWrapper.getHeaderList()); + SQLInsertStatement.ValuesClause valuesClause = new SQLInsertStatement.ValuesClause(); + for (String s : dataList) { + valuesClause.addValue(s); + } + sqlInsertStatement.setValues(valuesClause); + + printWriter.println(SQLUtils.toSQLString(sqlInsertStatement, dbType, INSERT_FORMAT_OPTION) + ";"); + }, false, new DefaultValueHandler()); + } + } + + @Data + @SuperBuilder + @NoArgsConstructor + @AllArgsConstructor + public static class InsertWrapper { + private List headerList; + } + + @Data + @SuperBuilder + @NoArgsConstructor + @AllArgsConstructor + public static class ExcelWrapper { + private ExcelWriterBuilder excelWriterBuilder; + private ExcelWriter excelWriter; + private WriteSheet writeSheet; + } +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/UserController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/UserController.java index adfcd5885..72dd7ee6f 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/UserController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/UserController.java @@ -34,7 +34,7 @@ public class UserController { //} // ///** - // * 新增Key + // * Add Key // * // * @param request // * @return @@ -45,7 +45,7 @@ public class UserController { //} // ///** - // * 更新我的保存 + // * Update my save // * // * @param request // * @return @@ -57,7 +57,7 @@ public class UserController { //} // ///** - // * 删除我的保存 + // * delete my save // * // * @param id // * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/converter/UserWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/converter/UserWebConverter.java index 5d3c5b07e..b7aef53c3 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/converter/UserWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/converter/UserWebConverter.java @@ -17,7 +17,7 @@ @Mapper(componentModel = "spring") public abstract class UserWebConverter { /** - * 转换 + * Convert * * @param user * @return diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserCreateRequest.java index 3f4fc9492..d8ea032f6 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserCreateRequest.java @@ -22,23 +22,23 @@ public class UserCreateRequest implements Serializable { @Serial private static final long serialVersionUID = 353710386092262213L; /** - * 用户名 + * userName */ private String userName; /** - * 密码 + * password */ private String password; /** - * 昵称 + * nickName */ private String nickName; /** - * 邮箱 + * email */ private String email; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserQueryRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserQueryRequest.java index f27bb8036..40e5c5e2d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserQueryRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserQueryRequest.java @@ -23,7 +23,7 @@ public class UserQueryRequest extends PageQueryParam { @Serial private static final long serialVersionUID = 5663790872812326134L; /** - * 用户名魔化搜索 + * Username magic search */ private String keyWord; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserUpdateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserUpdateRequest.java index 2f779ea92..0bc746396 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserUpdateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/request/UserUpdateRequest.java @@ -17,28 +17,28 @@ public class UserUpdateRequest { /** - * 主键 + * primary key */ private Long id; /** - * 用户名 + * userName */ private String userName; /** - * 密码 + * password */ private String password; /** - * 昵称 + * nickName */ private String nickName; /** - * 邮箱 + * email */ private String email; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/vo/UserVO.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/vo/UserVO.java index 5950f1cf9..eb8c790e4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/vo/UserVO.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/user/vo/UserVO.java @@ -20,28 +20,28 @@ public class UserVO implements Serializable { private static final long serialVersionUID = 502943167829222727L; /** - * 主键 + * primary key */ private Long id; /** - * 用户名 + * userName */ private String userName; /** - * 密码 + * password */ private String password; /** - * 昵称 + * nickName */ private String nickName; /** - * 邮箱 + * email */ private String email; } \ No newline at end of file diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/GatewayClientService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/GatewayClientService.java index 78b72e963..05cb3679d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/GatewayClientService.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/GatewayClientService.java @@ -14,7 +14,7 @@ /** - * Gateway 的http 服务 + * Gateway http service * * @author Jiaju Zhuang */ @@ -28,7 +28,7 @@ public class GatewayClientService { private Chat2dbProperties chat2dbProperties; /** - * 获取公众号的二维码 + * Get the QR code of the official account * * @return */ @@ -59,7 +59,7 @@ public DataResult getLoginStatus(String token) { } /** - * 返回剩余次数 + * Return the remaining times * * @param key * @return @@ -204,7 +204,7 @@ public DataResult schemaEsSearch(EsTableSchemaRequest req * @return */ public DataResult checkInWhite(WhiteListRequest whiteListRequest) { - // 去掉白名单 + // Remove whitelist return DataResult.of(false); // DataResult result = Forest.get(chat2dbProperties.getGateway().getBaseUrl() + "/api/client/whitelist/check") // .connectTimeout(Duration.ofMillis(5000)) @@ -215,14 +215,5 @@ public DataResult checkInWhite(WhiteListRequest whiteListRequest) { // return result; } - public ActionResult addOperationLog(SqlExecuteHistoryCreateRequest request) { - ActionResult result = Forest.post(chat2dbProperties.getGateway().getBaseUrl() + "/api/client/sql/execute/history") - .connectTimeout(Duration.ofMillis(5000)) - .readTimeout(Duration.ofMillis(10000)) - .contentType("application/json") - .addBody(request) - .execute(new TypeReference<>() { - }); - return result; - } + } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/SqlExecuteHistoryCreateRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/SqlExecuteHistoryCreateRequest.java index 777bd70f2..49b50a1a8 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/SqlExecuteHistoryCreateRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/SqlExecuteHistoryCreateRequest.java @@ -9,7 +9,7 @@ /** *

      - * sql执行历史 + * sql execution history *

      * * @author chat2db @@ -25,42 +25,42 @@ public class SqlExecuteHistoryCreateRequest implements Serializable { /** - * 数据库类型 + * Database type */ private String databaseType; /** - * 执行SQL + * Execute SQL */ private String sqlContent; /** - * 客户端ID + * Client ID */ private String clientId; /** - * 状态 + * state */ private String executeStatus; /** - * 错误消息 + * wrong information */ private String errorMessage; /** - * sql 类型 + * sql type */ private String sqlType; /** - * 执行持续时间 + * execution duration */ private Long duration; /** - * 表名 + * Table Name */ private String tableName; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/WhiteListRequest.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/WhiteListRequest.java index 93d419b0e..640e5de6d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/WhiteListRequest.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/request/WhiteListRequest.java @@ -18,7 +18,7 @@ public class WhiteListRequest { private String apiKey; /** - * 白名单类型,如向量 + * Whitelist type, such as vector * @see ai.chat2db.server.tools.base.enums.WhiteListTypeEnum */ private String whiteType; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/response/ApiKeyResponse.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/response/ApiKeyResponse.java index ea4598fa7..b8924e41e 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/response/ApiKeyResponse.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/http/response/ApiKeyResponse.java @@ -21,17 +21,17 @@ public class ApiKeyResponse { private String key; /** - * 过期时间 + * Expiration */ private Long expiry; /** - * 返回 + * return */ private Long remainingUses; /** - * 微信公众号url + * WeChat public account url */ private String wechatMpUrl; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/AddToTopic.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/AddToTopic.java index ed067d152..a862a1053 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/AddToTopic.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/AddToTopic.java @@ -17,7 +17,7 @@ public class AddToTopic { public static void generateTOC(XWPFDocument document, OutputStream out) throws IOException { - String findText = "目录哈哈"; + String findText = "directory"; String replaceText = ""; for (XWPFParagraph p : document.getParagraphs()) { for (XWPFRun r : p.getRuns()) { diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/ApplicationContextUtil.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/ApplicationContextUtil.java index 51c3f59aa..53bc2ea5c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/ApplicationContextUtil.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/ApplicationContextUtil.java @@ -16,7 +16,7 @@ public class ApplicationContextUtil implements ApplicationContextAware { /** - * 上下文对象实例 + * context object instance */ private static ApplicationContext applicationContext; @@ -26,7 +26,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws } /** - * 获取applicationContext + * Get applicationContext * * @return */ @@ -35,7 +35,7 @@ public static ApplicationContext getApplicationContext() { } /** - * 通过name获取 Bean. + * Get bean by name * * @param name * @return @@ -45,7 +45,7 @@ public static Object getBean(String name) { } /** - * 通过class获取Bean. + * Get Bean through class. * * @param clazz * @param @@ -56,7 +56,7 @@ public static T getBean(Class clazz) { } /** - * 通过name,以及Clazz返回指定的Bean + * Return the specified Bean through name and Clazz * * @param name * @param clazz @@ -68,7 +68,7 @@ public static T getBean(String name, Class clazz) { } /** - * 获取配置文件中的值 + * Get the value in the configuration file * @param key * @return */ diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/FileUtils.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/FileUtils.java index b1fdd2f54..b8b5c0f0c 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/FileUtils.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/FileUtils.java @@ -8,9 +8,9 @@ public class FileUtils { public enum ConfigFile { - // navicat连接信息文件 + // navicat connection information file NCX, - // dbeaver连接信息文件 + //dbeaver connection information file DBP } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/StringUtils.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/StringUtils.java index c2a1d4063..671eb753a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/StringUtils.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/util/StringUtils.java @@ -4,7 +4,7 @@ import java.util.function.Function; /** - * 添加字符串工具类,为了兼容JB的各种产品,尽量不要用第三方工具包 + * Add string tool class. In order to be compatible with various JB products, try not to use third-party toolkits. * * @author lzy */ @@ -14,7 +14,7 @@ public class StringUtils { private static final String EMPTY_STR = "null"; /** - * 首字母处理方法 + * How to deal with initial letters */ private static final BiFunction, String> FIRST_CHAR_HANDLER_FUN = (str, firstCharFun) -> { int strLen; @@ -65,30 +65,30 @@ public static String isNullForHtml(String str) { } /** - * 判断是空字符串 + * Determine if it is an empty string * - * @param cs 字符串 - * @return 是否为空 + * @param cs string + * @return whether it is empty */ public static boolean isEmpty(final CharSequence cs) { return cs == null || cs.length() == 0; } /** - * 首字母大写方法 + * Capitalize the first letter * - * @param str 字符串 - * @return 首字母大写结果 + * @param str string + * @return capitalize the first letter of the result */ public static String capitalize(final String str) { return FIRST_CHAR_HANDLER_FUN.apply(str, Character::toTitleCase); } /** - * 首字母小写方法 + * Lowercase first letter * - * @param str 字符串 - * @return 首字母小写结果 + * @param str string + * @return the first letter of the result is lowercase */ public static String uncapitalize(final String str) { return FIRST_CHAR_HANDLER_FUN.apply(str, Character::toLowerCase); diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsServer.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsServer.java index 1d1925269..26f91786d 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsServer.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsServer.java @@ -39,7 +39,7 @@ public class WsServer { private static final AtomicInteger OnlineCount = new AtomicInteger(0); - // concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。 + // The thread-safe Set of the concurrent package is used to store the Session object corresponding to each client. private static CopyOnWriteArraySet SessionSet = new CopyOnWriteArraySet(); private static int num = 0; @@ -55,14 +55,14 @@ public class WsServer { private WsService wsService; /** - * 连接建立成功调用的方法 + * Method called when connection is established successfully */ @OnOpen public void onOpen(Session session, @PathParam("token") String token) throws IOException { SessionSet.add(session); this.session = session; - int cnt = OnlineCount.incrementAndGet(); // 在线数加1 - log.info("有连接加入,当前连接数为:{}", cnt); + int cnt = OnlineCount.incrementAndGet(); // Add 1 to the online number + log.info("There are connections added, and the current number of connections is: {}", cnt); heartBeat(session); this.wsService = ApplicationContextUtil.getBean(WsService.class); @@ -92,7 +92,7 @@ public void onOpen(Session session, @PathParam("token") String token) throws IOE /** - * 连接关闭调用的方法 + * Method called on connection close */ @OnClose public void onClose() throws IOException { @@ -122,21 +122,21 @@ public void onClose() throws IOException { } } int cnt = OnlineCount.decrementAndGet(); - log.info("有连接关闭,session:{},{}", session, this); - log.info("有连接关闭,当前连接数为:{}", cnt); + log.info("A connection was closed, session:{},{}", session, this); + log.info("A connection is closed, the current number of connections is: {}", cnt); } } /** - * 收到客户端消息后调用的方法 + * Method called after receiving client message * - * @param message 客户端发送过来的消息 + * @param message message sent by the client */ @OnMessage(maxMessageSize = 1024000) public void onMessage(String message, Session session) { CompletableFuture.runAsync(() -> { WsMessage wsMessage = JSONObject.parseObject(message, WsMessage.class); - // 在这里处理你的消息 + // Process your messages here try { String actionType = wsMessage.getActionType(); if (WsMessage.ActionType.PING.equalsIgnoreCase(actionType)) { @@ -186,7 +186,7 @@ public void onMessage(String message, Session session) { wsResult.setMessage(actionResult); SendMessage(session, wsResult); } finally { - Chat2DBContext.remove(); + Chat2DBContext.removeContext(); ContextUtils.removeContext(); Dbutils.removeSession(); } @@ -201,19 +201,19 @@ private String connectInfoKey(Long dataSourceId, String databaseName, String sch /** - * 出现错误 + * An error occurred * * @param session * @param error */ @OnError public void onError(Session session, Throwable error) { - log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId(), error); + log.error("An error occurred:{},Session ID: {}", error.getMessage(), session.getId(), error); error.printStackTrace(); } /** - * 心跳 + * heartbeat * * @param session */ @@ -225,14 +225,14 @@ public void run() { try { onClose(); } catch (IOException e) { - log.error("发送消息出错:{}", e.getMessage(), e); + log.error("Error sending message:{}", e.getMessage(), e); } } }, 600000); } /** - * 发送消息,实践表明,每次浏览器刷新,session会发生变化。 + * Sending a message, practice shows that every time the browser refreshes, the session will change. * * @param session * @param wsResult @@ -243,7 +243,7 @@ public static void SendMessage(Session session, WsResult wsResult) { session.getBasicRemote().sendText(JSONObject.toJSONString(wsResult)); } } catch (IOException e) { - log.error("发送消息出错:{}", e.getMessage()); + log.error("Error sending message:{}", e.getMessage()); e.printStackTrace(); } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsService.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsService.java index e2f575ab1..a9c9b4eb8 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsService.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/ws/WsService.java @@ -16,17 +16,13 @@ import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter; import ai.chat2db.server.web.api.controller.rdb.request.DmlRequest; import ai.chat2db.server.web.api.controller.rdb.vo.ExecuteResultVO; -import ai.chat2db.server.web.api.http.GatewayClientService; -import ai.chat2db.server.web.api.http.request.SqlExecuteHistoryCreateRequest; import ai.chat2db.server.web.api.util.ApplicationContextUtil; import ai.chat2db.spi.config.DriverConfig; import ai.chat2db.spi.model.ExecuteResult; -import ai.chat2db.spi.sql.Chat2DBContext; import ai.chat2db.spi.sql.ConnectInfo; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.RequestBody; import java.util.List; import java.util.Objects; @@ -53,26 +49,12 @@ public class WsService { @Autowired private DlTemplateService dlTemplateService; - @Autowired - private GatewayClientService gatewayClientService; - - public static ExecutorService executorService = Executors.newFixedThreadPool(10); public ListResult execute(DmlRequest request) { DlExecuteParam param = rdbWebConverter.request2param(request); ListResult resultDTOListResult = dlTemplateService.execute(param); List resultVOS = rdbWebConverter.dto2vo(resultDTOListResult.getData()); - String type = Chat2DBContext.getConnectInfo().getDbType(); - String clientId = getApiKey(); - String sqlContent = request.getSql(); - executorService.submit(() -> { - try { - addOperationLog(clientId, type, sqlContent, resultDTOListResult.getErrorMessage(), resultDTOListResult.getSuccess(), resultVOS); - } catch (Exception e) { - // do nothing - } - }); return ListResult.of(resultVOS); } @@ -143,20 +125,5 @@ private String getApiKey() { return keyConfig.getContent(); } - private void addOperationLog(String clientId, String sqlType, String sqlContent, String errorMessage, Boolean isSuccess, List executeResultVOS) { - SqlExecuteHistoryCreateRequest createRequest = new SqlExecuteHistoryCreateRequest(); - createRequest.setClientId(clientId); - createRequest.setErrorMessage(errorMessage); - createRequest.setDatabaseType(sqlType); - createRequest.setSqlContent(sqlContent); - createRequest.setExecuteStatus(isSuccess ? "success" : "fail"); - executeResultVOS.forEach(executeResultVO -> { - createRequest.setSqlType(executeResultVO.getSqlType()); - createRequest.setDuration(executeResultVO.getDuration()); - createRequest.setTableName(executeResultVO.getTableName()); - gatewayClientService.addOperationLog(createRequest); - }); - } - } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/resources/template/template.html b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/resources/template/template.html index f3174d826..091063c67 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/resources/template/template.html +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/resources/template/template.html @@ -4,13 +4,13 @@ diff --git a/chat2db-server/chat2db-spi/pom.xml b/chat2db-server/chat2db-spi/pom.xml index 2794cc97a..de441bc9f 100644 --- a/chat2db-server/chat2db-spi/pom.xml +++ b/chat2db-server/chat2db-spi/pom.xml @@ -22,7 +22,7 @@ druid - + com.h2database h2 @@ -77,7 +77,7 @@ org.locationtech.jts jts-core - 1.19.0 + 1.19.0 @@ -86,4 +86,21 @@ bson + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar + + + + + + \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/CommandExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/CommandExecutor.java index ee5a9c942..35b878956 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/CommandExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/CommandExecutor.java @@ -27,6 +27,12 @@ public interface CommandExecutor { ExecuteResult executeUpdate(String sql, Connection connection, int n)throws SQLException; + /** + * Execute command + */ + List executeSelectTable(Command command); + + /** * * diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java index 40a7d0077..eae7e20af 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/DBManage.java @@ -1,9 +1,12 @@ package ai.chat2db.spi; -import java.sql.Connection; - +import ai.chat2db.spi.model.Procedure; import ai.chat2db.spi.sql.ConnectInfo; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; + +import java.sql.Connection; +import java.sql.SQLException; /** * @author jipengfei @@ -24,7 +27,7 @@ public interface DBManage { void connectDatabase(Connection connection, String database); /** - * 修改数据库名称 + * Modify database name * * @param databaseName * @param newDatabaseName @@ -32,21 +35,21 @@ public interface DBManage { void modifyDatabase(Connection connection, String databaseName, String newDatabaseName); /** - * 创建数据库 + * Create database * * @param databaseName */ void createDatabase(Connection connection, String databaseName); /** - * 删除数据库 + * Delete database * * @param databaseName */ void dropDatabase(Connection connection, String databaseName); /** - * 创建schema + * Create schema * * @param databaseName * @param schemaName @@ -54,7 +57,7 @@ public interface DBManage { void createSchema(Connection connection, String databaseName, String schemaName); /** - * 删除schema + * Delete schema * * @param databaseName * @param schemaName @@ -62,7 +65,7 @@ public interface DBManage { void dropSchema(Connection connection, String databaseName, String schemaName); /** - * 修改schema + * Modify schema * * @param databaseName * @param schemaName @@ -71,41 +74,54 @@ public interface DBManage { void modifySchema(Connection connection, String databaseName, String schemaName, String newSchemaName); /** - * 删除表结构 + * Delete table structure * * @param databaseName * @param tableName * @return */ - void dropTable(Connection connection,@NotEmpty String databaseName, String schemaName, @NotEmpty String tableName); + void dropTable(Connection connection, @NotEmpty String databaseName, String schemaName, @NotEmpty String tableName); /** - * 删除函数 + * delete function * * @param databaseName * @param functionName * @return */ void dropFunction(Connection connection, @NotEmpty String databaseName, String schemaName, - @NotEmpty String functionName); + @NotEmpty String functionName); /** - * 删除触发器 + * delete trigger * * @param databaseName * @param triggerName * @return */ void dropTrigger(Connection connection, @NotEmpty String databaseName, String schemaName, - @NotEmpty String triggerName); + @NotEmpty String triggerName); /** - * 删除存储过程 + * Delete stored procedure * * @param databaseName * @param triggerName * @return */ void dropProcedure(Connection connection, @NotEmpty String databaseName, String schemaName, - @NotEmpty String triggerName); + @NotEmpty String triggerName); + + /** + * Update stored procedure + * @param connection + * @param databaseName + * @param schemaName + * @param procedure + */ + void updateProcedure(Connection connection, @NotEmpty String databaseName, String schemaName, @NotNull Procedure procedure) throws SQLException; + + String exportDatabase(Connection connection, String databaseName, String schemaName,boolean containData) throws SQLException; + + String exportDatabaseData(Connection connection, String databaseName, String schemaName,String tableName) throws SQLException; } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java index f7e377002..e6dc2bde6 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/MetaData.java @@ -3,7 +3,9 @@ import java.sql.Connection; import java.util.List; +import ai.chat2db.server.tools.base.wrapper.result.PageResult; import ai.chat2db.spi.model.*; +import cn.hutool.db.Page; import jakarta.validation.constraints.NotEmpty; /** @@ -52,6 +54,29 @@ String tableDDL(Connection connection, @NotEmpty String databaseName, String sch */ List
      tables(Connection connection, @NotEmpty String databaseName, String schemaName, String tableName); + /** + * Querying all table name under a schema. + * @param connection + * @param databaseName + * @param schemaName + * @param tableName + * @return + */ + List tableNames(Connection connection, @NotEmpty String databaseName, String schemaName, String tableName); + + + /** + * Querying all table under a schema. + * + * @param connection + * @param databaseName + * @param schemaName + * @param tableNamePattern + * @param pageNo + * @param pageSize + * @return + */ + PageResult
      tables(Connection connection, String databaseName, String schemaName, String tableNamePattern, int pageNo, int pageSize); /** * Querying view information. * @@ -64,6 +89,14 @@ String tableDDL(Connection connection, @NotEmpty String databaseName, String sch Table view(Connection connection, @NotEmpty String databaseName, String schemaName, String viewName); + /** query view names + * @param connection + * @param databaseName + * @param schemaName + * @return + */ + List viewNames(Connection connection, @NotEmpty String databaseName, String schemaName); + /** * Querying all views under a schema. * @@ -216,4 +249,17 @@ List indexes(Connection connection, @NotEmpty String databaseName, S * Get command executor. */ CommandExecutor getCommandExecutor(); + + /** + * Get system databases. + * @return + */ + List getSystemDatabases(); + + /** + * Get system schemas. + * @return + */ + List getSystemSchemas(); + } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/SqlBuilder.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/SqlBuilder.java index 237b4de45..9089634cb 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/SqlBuilder.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/SqlBuilder.java @@ -4,7 +4,7 @@ import java.util.List; -public interface SqlBuilder { +public interface SqlBuilder { /** * Generate create table sql @@ -12,7 +12,7 @@ public interface SqlBuilder { * @param table * @return */ - String buildCreateTableSql(Table table); + String buildCreateTableSql(T table); /** @@ -22,7 +22,7 @@ public interface SqlBuilder { * @param oldTable * @return */ - String buildModifyTaleSql(Table oldTable, Table newTable); + String buildModifyTaleSql(T oldTable, T newTable); /** @@ -79,6 +79,13 @@ public interface SqlBuilder { /** * generate sql based on results */ - String generateSqlBasedOnResults(String tableName, List
      headerList, List operations); + String buildSqlByQuery(QueryResult queryResult); + /** + * DML SQL + * @param table + * @param type + * @return + */ + String getTableDmlSql(T table,String type); } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/ValueHandler.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/ValueHandler.java index ee3ad80cc..80fdc342d 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/ValueHandler.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/ValueHandler.java @@ -6,7 +6,7 @@ public interface ValueHandler { /** - * 处理结果集中的列值 + * Process column values in the result set * @param rs * @param index * @param limitSize diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DBConfig.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DBConfig.java index 979ef078f..960498638 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DBConfig.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DBConfig.java @@ -32,12 +32,12 @@ public class DBConfig { private List driverConfigList; /** - * 建表语句 + * Create table statement */ private String simpleCreateTable; /** - * 修改表结构 + * Modify table structure */ private String simpleAlterTable; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DriverConfig.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DriverConfig.java index 3dc2c4802..8dac1ec72 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DriverConfig.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/config/DriverConfig.java @@ -1,6 +1,7 @@ package ai.chat2db.spi.config; +import java.io.Serializable; import java.util.List; import ai.chat2db.spi.model.KeyValue; @@ -12,7 +13,8 @@ * @version : DriverConfig.java */ @Data -public class DriverConfig { +public class DriverConfig implements Serializable { + private static final long serialVersionUID = 1L; /** * url @@ -39,7 +41,7 @@ public class DriverConfig { private String dbType; /** - * 自定义 + * customize */ private boolean custom; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CellTypeEnum.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CellTypeEnum.java index 2f4c315a2..ea74304d9 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CellTypeEnum.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CellTypeEnum.java @@ -4,36 +4,36 @@ import lombok.Getter; /** - * 驱动类枚举 + * Driver class enumeration * * @author Jiaju Zhuang */ @Getter public enum CellTypeEnum implements BaseEnum { /** - * 字符串 + * string */ - STRING("字符串"), + STRING("string"), /** - * 数字 + * number */ - BIG_DECIMAL("数字"), + BIG_DECIMAL("number"), /** - * 日期 + * date */ - DATE("日期"), + DATE("date"), /** - * 二进制流 + * binary stream */ - BYTE("二进制流"), + BYTE("binary stream"), /** - * 空数据 + * empty data */ - EMPTY("空数据"), + EMPTY("empty data"), ; final String description; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CollationEnum.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CollationEnum.java index 43f0f5a7d..88de2b6f5 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CollationEnum.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/CollationEnum.java @@ -6,7 +6,7 @@ import lombok.Getter; /** - * 排序枚举 + * Sorted enumeration * * @author Jiaju Zhuang */ @@ -44,11 +44,11 @@ public static boolean equals(String collation1, String collation2) { } public static boolean equals(CollationEnum collation1, CollationEnum collation2) { - // 想同直接返回 + // The same returns directly if (collation1 == collation2) { return true; } - // 有一个是倒序 就是不相同 ,其他都是相同 + // One of them is in reverse order, which means they are different. The others are the same. return !(collation1 == CollationEnum.DESC || collation2 == CollationEnum.DESC); } } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/DataTypeEnum.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/DataTypeEnum.java index 819a5903f..83a6d3606 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/DataTypeEnum.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/DataTypeEnum.java @@ -4,86 +4,86 @@ import lombok.Getter; /** - * 驱动类枚举 + * Driver class enumeration * * @author Jiaju Zhuang */ @Getter public enum DataTypeEnum implements BaseEnum { /** - * 布尔值 + * Boolean value */ - BOOLEAN("布尔值"), + BOOLEAN("Boolean value"), /** - * 数字 + * number */ - NUMERIC("数字"), + NUMERIC("number"), /** - * 字符串 + * string */ - STRING("字符串"), + STRING("string"), /** - * 日期 + * date */ - DATETIME("日期"), + DATETIME("date"), /** - * 二进制 + * binary */ - BINARY("空数据"), + BINARY("binary"), /** - * 内容 + * content */ - CONTENT("内容"), + CONTENT("content"), /** - * 结构 + * structure */ - STRUCT("结构"), + STRUCT("structure"), /** - * 文档 + * document */ - DOCUMENT("文档"), + DOCUMENT("document"), /** - * 数组 + * array */ - ARRAY("数组"), + ARRAY("array"), /** - * 对象 + * object */ - OBJECT("对象"), + OBJECT("object"), /** - * 引用 + * reference */ - REFERENCE("引用"), + REFERENCE("reference"), /** - * 行号 + * rowid */ - ROWID("行号"), + ROWID("rowid"), /** - * 任何 + * any */ - ANY("任何"), + ANY("any"), /** - * 未知 + * unknow */ - UNKNOWN("未知"), + UNKNOWN("unknow"), /** - * 行号 + * Row number */ - CHAT2DB_ROW_NUMBER("行号"), + CHAT2DB_ROW_NUMBER("Row number"), ; final String description; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/DmlType.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/DmlType.java new file mode 100644 index 000000000..170fd5391 --- /dev/null +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/DmlType.java @@ -0,0 +1,5 @@ +package ai.chat2db.spi.enums; + +public enum DmlType { + INSERT, UPDATE, DELETE, SELECT +} diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/IndexTypeEnum.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/IndexTypeEnum.java index d05ff4e3c..33daf1ce6 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/IndexTypeEnum.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/IndexTypeEnum.java @@ -5,26 +5,26 @@ import lombok.Getter; /** - * 索引类型 + * Index type * * @author Jiaju Zhuang */ @Getter public enum IndexTypeEnum implements BaseEnum { /** - * 主键 + * primary key */ - PRIMARY_KEY("主键"), + PRIMARY_KEY("primary key"), /** - * 普通索引 + * Ordinary index */ - NORMAL("普通索引"), + NORMAL("Ordinary index"), /** - * 唯一索引 + * unique index */ - UNIQUE("唯一索引"), + UNIQUE("unique index"), ; final String description; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/SqlTypeEnum.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/SqlTypeEnum.java index a9c827981..3de6234f8 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/SqlTypeEnum.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/enums/SqlTypeEnum.java @@ -4,21 +4,21 @@ import lombok.Getter; /** - * sq类型 + * sql type * * @author Jiaju Zhuang */ @Getter public enum SqlTypeEnum implements BaseEnum { /** - * 查询语句 + * Check for phrases */ - SELECT("查询语句"), + SELECT("Check for phrases"), /** - * 未知 + * unknow */ - UNKNOWN("未知"), + UNKNOWN("unknow"), ; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java index df7981d83..dd54558b1 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultDBManage.java @@ -1,11 +1,15 @@ package ai.chat2db.spi.jdbc; import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.util.Objects; import ai.chat2db.server.tools.base.excption.BusinessException; import ai.chat2db.server.tools.common.exception.ConnectionException; import ai.chat2db.spi.DBManage; +import ai.chat2db.spi.model.Procedure; import ai.chat2db.spi.model.SSHInfo; import ai.chat2db.spi.sql.ConnectInfo; import ai.chat2db.spi.sql.IDriverManager; @@ -22,19 +26,18 @@ public class DefaultDBManage implements DBManage { - @Override public Connection getConnection(ConnectInfo connectInfo) { Connection connection = connectInfo.getConnection(); - if (connection != null) { - return connection; - } - Session session = null; SSHInfo ssh = connectInfo.getSsh(); String url = connectInfo.getUrl(); String host = connectInfo.getHost(); String port = connectInfo.getPort() + ""; + Session session = null; try { + if (connection != null && !connection.isClosed()) { + return connection; + } ssh.setRHost(host); ssh.setRPort(port); session = getSession(ssh); @@ -46,7 +49,7 @@ public Connection getConnection(ConnectInfo connectInfo) { } try { connection = IDriverManager.getConnection(url, connectInfo.getUser(), connectInfo.getPassword(), - connectInfo.getDriverConfig(), connectInfo.getExtendMap()); + connectInfo.getDriverConfig(), connectInfo.getExtendMap()); } catch (Exception e1) { if (connection != null) { @@ -84,37 +87,37 @@ private Session getSession(SSHInfo ssh) { } @Override - public void connectDatabase(Connection connection,String database) { + public void connectDatabase(Connection connection, String database) { } @Override - public void modifyDatabase(Connection connection,String databaseName, String newDatabaseName) { + public void modifyDatabase(Connection connection, String databaseName, String newDatabaseName) { } @Override - public void createDatabase(Connection connection,String databaseName) { + public void createDatabase(Connection connection, String databaseName) { } @Override - public void dropDatabase(Connection connection,String databaseName) { + public void dropDatabase(Connection connection, String databaseName) { } @Override - public void createSchema(Connection connection,String databaseName, String schemaName) { + public void createSchema(Connection connection, String databaseName, String schemaName) { } @Override - public void dropSchema(Connection connection,String databaseName, String schemaName) { + public void dropSchema(Connection connection, String databaseName, String schemaName) { } @Override - public void modifySchema(Connection connection,String databaseName, String schemaName, String newSchemaName) { + public void modifySchema(Connection connection, String databaseName, String schemaName, String newSchemaName) { } @@ -134,8 +137,51 @@ public void dropProcedure(Connection connection, String databaseName, String sch } @Override - public void dropTable(Connection connection,String databaseName, String schemaName, String tableName) { - String sql = "DROP TABLE "+ tableName ; - SQLExecutor.getInstance().execute(connection,sql, resultSet -> null); + public void updateProcedure(Connection connection, String databaseName, String schemaName, Procedure procedure) throws SQLException { + + } + + @Override + public String exportDatabase(Connection connection, String databaseName, String schemaName, boolean containData) throws SQLException { + return null; + } + public String exportDatabaseData(Connection connection, String databaseName, String schemaName, String tableName) throws SQLException { + StringBuilder sqlBuilder = new StringBuilder(); + exportTableData(connection, schemaName,tableName, sqlBuilder); + return sqlBuilder.toString(); + } + + @Override + public void dropTable(Connection connection, String databaseName, String schemaName, String tableName) { + String sql = "DROP TABLE " + tableName; + SQLExecutor.getInstance().execute(connection, sql, resultSet -> null); + } + + public void exportTableData(Connection connection,String schemaName, String tableName, StringBuilder sqlBuilder) throws SQLException { + String sql; + if (Objects.isNull(schemaName)) { + sql = String.format("select * from %s", tableName); + }else{ + sql = String.format("select * from %s.%s",schemaName,tableName); + } + try (ResultSet resultSet = connection.createStatement().executeQuery(sql)) { + ResultSetMetaData metaData = resultSet.getMetaData(); + while (resultSet.next()) { + sqlBuilder.append("INSERT INTO ").append(tableName).append(" VALUES ("); + for (int i = 1; i <= metaData.getColumnCount(); i++) { + String value = resultSet.getString(i); + if (Objects.isNull(value)) { + sqlBuilder.append("NULL"); + } else { + sqlBuilder.append("'").append(value).append("'"); + } + if (i < metaData.getColumnCount()) { + sqlBuilder.append(", "); + } + } + sqlBuilder.append(");\n"); + } + sqlBuilder.append("\n"); + } } } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java index a3ba280bb..a84d43dff 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultMetaService.java @@ -1,20 +1,21 @@ package ai.chat2db.spi.jdbc; -import java.sql.Connection; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - +import ai.chat2db.server.tools.base.wrapper.result.PageResult; import ai.chat2db.spi.CommandExecutor; import ai.chat2db.spi.MetaData; import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.model.*; import ai.chat2db.spi.sql.SQLExecutor; +import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import java.sql.Connection; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + /** * @author jipengfei * @version : DefaultMetaService.java @@ -28,9 +29,9 @@ public List databases(Connection connection) { @Override public List schemas(Connection connection, String databaseName) { List schemas = SQLExecutor.getInstance().schemas(connection, databaseName, null); - if(StringUtils.isNotBlank(databaseName) && CollectionUtils.isNotEmpty(schemas)){ - for ( Schema schema : schemas) { - if(StringUtils.isBlank(schema.getDatabaseName())){ + if (StringUtils.isNotBlank(databaseName) && CollectionUtils.isNotEmpty(schemas)) { + for (Schema schema : schemas) { + if (StringUtils.isBlank(schema.getDatabaseName())) { schema.setDatabaseName(databaseName); } } @@ -45,7 +46,22 @@ public String tableDDL(Connection connection, String databaseName, String schema @Override public List
      tables(Connection connection, String databaseName, String schemaName, String tableName) { - return SQLExecutor.getInstance().tables(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName, tableName, new String[]{"TABLE","SYSTEM TABLE"}); + return SQLExecutor.getInstance().tables(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName, tableName, new String[]{"TABLE", "SYSTEM TABLE"}); + } + + @Override + public List tableNames(Connection connection, String databaseName, String schemaName, String tableName) { + return SQLExecutor.getInstance().tableNames(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName, tableName, new String[]{"TABLE", "SYSTEM TABLE"}); + } + + @Override + public PageResult
      tables(Connection connection, String databaseName, String schemaName, String tableNamePattern, int pageNo, int pageSize) { + List
      tables = tables(connection, databaseName, schemaName, tableNamePattern); + if (CollectionUtils.isEmpty(tables)) { + return PageResult.of(tables, 0L, pageNo, pageSize); + } + List result = tables.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); + return PageResult.of(result, (long) tables.size(), pageNo, pageSize); } @Override @@ -58,13 +74,22 @@ public List
      views(Connection connection, String databaseName, String sche return SQLExecutor.getInstance().tables(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName, null, new String[]{"VIEW"}); } + @Override + public List viewNames(Connection connection, String databaseName, String schemaName) { + return SQLExecutor.getInstance().tableNames(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName, null, new String[]{"VIEW"}); + } + @Override public List functions(Connection connection, String databaseName, String schemaName) { List functions = SQLExecutor.getInstance().functions(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName); - if(CollectionUtils.isEmpty(functions)){ + if (CollectionUtils.isEmpty(functions)) { return functions; } - return functions.stream().filter(function -> StringUtils.isNotBlank(function.getFunctionName())).collect(Collectors.toList()); + return functions.stream().filter(function -> StringUtils.isNotBlank(function.getFunctionName())).map(function -> { + String functionName = function.getFunctionName(); + function.setFunctionName(functionName.trim()); + return function; + }).collect(Collectors.toList()); } @Override @@ -74,12 +99,16 @@ public List triggers(Connection connection, String databaseName, String @Override public List procedures(Connection connection, String databaseName, String schemaName) { - List procedures = SQLExecutor.getInstance().procedures(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName); + List procedures = SQLExecutor.getInstance().procedures(connection, StringUtils.isEmpty(databaseName) ? null : databaseName, StringUtils.isEmpty(schemaName) ? null : schemaName); - if(CollectionUtils.isEmpty(procedures)){ + if (CollectionUtils.isEmpty(procedures)) { return procedures; } - return procedures.stream().filter(function -> StringUtils.isNotBlank(function.getProcedureName())).collect(Collectors.toList()); + return procedures.stream().filter(function -> StringUtils.isNotBlank(function.getProcedureName())).map(procedure -> { + String procedureName = procedure.getProcedureName(); + procedure.setProcedureName(procedureName.trim()); + return procedure; + }).collect(Collectors.toList()); } @Override @@ -142,4 +171,14 @@ public ValueHandler getValueHandler() { public CommandExecutor getCommandExecutor() { return SQLExecutor.getInstance(); } + + @Override + public List getSystemDatabases() { + return Lists.newArrayList(); + } + + @Override + public List getSystemSchemas() { + return Lists.newArrayList(); + } } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultSqlBuilder.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultSqlBuilder.java index 115a6ef8b..d63d1603c 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultSqlBuilder.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultSqlBuilder.java @@ -1,8 +1,8 @@ package ai.chat2db.spi.jdbc; -import ai.chat2db.server.tools.base.wrapper.result.DataResult; import ai.chat2db.spi.MetaData; import ai.chat2db.spi.SqlBuilder; +import ai.chat2db.spi.enums.DmlType; import ai.chat2db.spi.model.*; import ai.chat2db.spi.sql.Chat2DBContext; import ai.chat2db.spi.util.SqlUtils; @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.List; -public class DefaultSqlBuilder implements SqlBuilder { +public class DefaultSqlBuilder implements SqlBuilder
      { @Override @@ -70,18 +70,18 @@ public String buildOrderBySql(String originSql, List orderByList) { Select selectStatement = (Select) statement; PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody(); - // 创建新的 ORDER BY 子句 + // Create a new ORDER BY clause List orderByElements = new ArrayList<>(); for (OrderBy orderBy : orderByList) { OrderByElement orderByElement = new OrderByElement(); orderByElement.setExpression(CCJSqlParserUtil.parseExpression(orderBy.getColumnName())); - orderByElement.setAsc(orderBy.isAsc()); // 设置为升序,使用 setAsc(false) 设置为降序 + orderByElement.setAsc(orderBy.isAsc()); // Set to ascending order, use setAsc(false) to set to descending order orderByElements.add(orderByElement); } - // 替换原有的 ORDER BY 子句 + // Replace the original ORDER BY clause plainSelect.setOrderByElements(orderByElements); - // 输出修改后的 SQL + // Output the modified SQL return plainSelect.toString(); } } catch (Exception e) { @@ -90,8 +90,10 @@ public String buildOrderBySql(String originSql, List orderByList) { } @Override - public String generateSqlBasedOnResults(String tableName, List
      headerList, List operations) { - + public String buildSqlByQuery(QueryResult queryResult) { + List
      headerList = queryResult.getHeaderList(); + List operations = queryResult.getOperations(); + String tableName = queryResult.getTableName(); StringBuilder stringBuilder = new StringBuilder(); MetaData metaSchema = Chat2DBContext.getMetaData(); List keyColumns = getPrimaryColumns(headerList); @@ -101,13 +103,13 @@ public String generateSqlBasedOnResults(String tableName, List
      headerLis List odlRow = operation.getOldDataList(); String sql = ""; if ("UPDATE".equalsIgnoreCase(operation.getType())) { - sql = getUpdateSql(tableName,headerList, row, odlRow, metaSchema, keyColumns, false); + sql = getUpdateSql(tableName, headerList, row, odlRow, metaSchema, keyColumns, false); } else if ("CREATE".equalsIgnoreCase(operation.getType())) { - sql = getInsertSql(tableName,headerList, row, metaSchema); + sql = getInsertSql(tableName, headerList, row, metaSchema); } else if ("DELETE".equalsIgnoreCase(operation.getType())) { - sql = getDeleteSql(tableName,headerList, odlRow, metaSchema, keyColumns); + sql = getDeleteSql(tableName, headerList, odlRow, metaSchema, keyColumns); } else if ("UPDATE_COPY".equalsIgnoreCase(operation.getType())) { - sql = getUpdateSql(tableName,headerList, row, row, metaSchema, keyColumns, true); + sql = getUpdateSql(tableName, headerList, row, row, metaSchema, keyColumns, true); } stringBuilder.append(sql + ";\n"); @@ -115,6 +117,76 @@ public String generateSqlBasedOnResults(String tableName, List
      headerLis return stringBuilder.toString(); } + @Override + public String getTableDmlSql(Table table, String type) { + if (table == null || CollectionUtils.isEmpty(table.getColumnList()) || StringUtils.isBlank(type)) { + return ""; + } + if(DmlType.INSERT.name().equalsIgnoreCase(type)) { + return getInsertSql(table.getName(), table.getColumnList()); + } else if(DmlType.UPDATE.name().equalsIgnoreCase(type)) { + return getUpdateSql(table.getName(), table.getColumnList()); + } else if(DmlType.DELETE.name().equalsIgnoreCase(type)) { + return getDeleteSql(table.getName(), table.getColumnList()); + }else if(DmlType.SELECT.name().equalsIgnoreCase(type)) { + return getSelectSql(table.getName(), table.getColumnList()); + } + return ""; + } + + private String getSelectSql(String name, List columnList) { + StringBuilder script = new StringBuilder(); + script.append("SELECT "); + for (TableColumn column : columnList) { + script.append(column.getName()) + .append(","); + } + script.deleteCharAt(script.length() - 1); + script.append(" FROM where").append(name); + return script.toString(); + } + + private String getDeleteSql(String name, List columnList) { + StringBuilder script = new StringBuilder(); + script.append("DELETE FROM ").append(name) + .append(" where "); + return script.toString(); + } + + private String getUpdateSql(String name, List columnList) { + StringBuilder script = new StringBuilder(); + script.append("UPDATE ").append(name) + .append(" set "); + for (TableColumn column : columnList) { + script.append(column.getName()) + .append(" = ") + .append(" ") + .append(","); + } + script.deleteCharAt(script.length() - 1); + script.append(" where "); + return script.toString(); + } + + private String getInsertSql(String name, List columnList) { + StringBuilder script = new StringBuilder(); + script.append("INSERT INTO ").append(name) + .append(" ("); + for (TableColumn column : columnList) { + script.append(column.getName()) + .append(","); + } + script.deleteCharAt(script.length() - 1); + script.append(") VALUES ("); + for (TableColumn column : columnList) { + script.append(" ") + .append(","); + } + script.deleteCharAt(script.length() - 1); + script.append(")"); + return script.toString(); + } + private List getPrimaryColumns(List
      headerList) { if (CollectionUtils.isEmpty(headerList)) { return Lists.newArrayList(); @@ -132,7 +204,6 @@ private String getDeleteSql(String tableName, List
      headerList, List keyColumns) { StringBuilder script = new StringBuilder(); script.append("DELETE FROM ").append(tableName).append(""); - script.append(buildWhere(headerList, row, metaSchema, keyColumns)); return script.toString(); } @@ -178,7 +249,7 @@ private String buildWhere(List
      headerList, List row, MetaData me return script.toString(); } - private String getInsertSql(String tableName, List
      headerList, List row, MetaData metaSchema) { + private String getInsertSql(String tableName, List
      headerList, List row, MetaData metaSchema) { if (CollectionUtils.isEmpty(row) || ObjectUtils.allNull(row.toArray())) { return ""; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java index 13ea1f384..68c9deac2 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java @@ -6,10 +6,9 @@ import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; @Slf4j public class DefaultValueHandler implements ValueHandler { @@ -35,10 +34,13 @@ public String getString(ResultSet rs, int index, boolean limitSize) throws SQLEx return largeString(rs, index, limitSize); } else if (obj instanceof Blob blob) { return largeStringBlob(blob, limitSize); + } else if (obj instanceof Timestamp || obj instanceof LocalDateTime) { + return largeTime(obj); + } else { + return obj.toString(); } - return obj.toString(); } catch (Exception e) { - log.warn("解析数失败:{},{}", index, obj, e); + log.warn("Failed to parse number:{},{}", index, obj, e); return obj.toString(); } } @@ -62,6 +64,26 @@ private String largeStringBlob(Blob blob, boolean limitSize) throws SQLException return result; } + private String largeTime(Object obj) throws SQLException { + Object timeField = obj; // Assuming a time field of type Object + + LocalDateTime localDateTime; + + if (obj instanceof Timestamp) { + // Convert a time field of type Object to a LocalDateTime object + localDateTime = ((Timestamp) timeField).toLocalDateTime(); + } else { + localDateTime = LocalDateTime.parse(timeField.toString(), DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")); + } + + // Create a DateTimeFormatter instance and specify the output date and time format + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + // Format date time + String formattedDateTime = dtf.format(localDateTime); + return formattedDateTime; + } + private static String largeString(ResultSet rs, int index, boolean limitSize) throws SQLException { String result = rs.getString(index); if (result == null) { diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Cell.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Cell.java index 31f766289..ce8286a88 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Cell.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Cell.java @@ -1,5 +1,6 @@ package ai.chat2db.spi.model; +import java.io.Serializable; import java.math.BigDecimal; @@ -9,7 +10,7 @@ import lombok.experimental.SuperBuilder; /** - * 单元格类型 + * cell type * * @author Jiaju Zhuang */ @@ -17,32 +18,33 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Cell { +public class Cell implements Serializable { + private static final long serialVersionUID = 1L; /** - * 单元格类型 + * cell type * * @see CellTypeEnum */ private String type; /** - * 字符串数据 + * string data */ private String stringValue; /** - * 数字 + * number */ private BigDecimal bigDecimalValue; /** - * 日期数据 + * date data */ private Long dateValue; /** - * 二进制流 + * binary stream */ private byte[] byteValue; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Charset.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Charset.java index 79cf5d29e..37a85e69a 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Charset.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Charset.java @@ -3,9 +3,12 @@ import lombok.AllArgsConstructor; import lombok.Data; +import java.io.Serializable; + @Data @AllArgsConstructor -public class Charset { +public class Charset implements Serializable { + private static final long serialVersionUID = 1L; private String charsetName; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Collation.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Collation.java index 12e7de3af..3a9b17477 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Collation.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Collation.java @@ -3,9 +3,12 @@ import lombok.AllArgsConstructor; import lombok.Data; +import java.io.Serializable; + @Data @AllArgsConstructor -public class Collation { +public class Collation implements Serializable { + private static final long serialVersionUID = 1L; private String collationName; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ColumnType.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ColumnType.java index 3fd15c23a..a432fe522 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ColumnType.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ColumnType.java @@ -3,9 +3,12 @@ import lombok.AllArgsConstructor; import lombok.Data; +import java.io.Serializable; + @Data @AllArgsConstructor -public class ColumnType { +public class ColumnType implements Serializable { + private static final long serialVersionUID = 1L; private String typeName; private boolean supportLength; private boolean supportScale; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Command.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Command.java index cca272e23..67a5e732b 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Command.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Command.java @@ -3,54 +3,61 @@ import jakarta.validation.constraints.NotNull; import lombok.Data; +import java.io.Serializable; + @Data -public class Command { +public class Command implements Serializable { + private static final long serialVersionUID = 1L; /** - * sql语句 + * sql statement */ @NotNull private String script; /** - * 控制台id + * console id */ @NotNull private Long consoleId; /** - * 数据源id + * Data source id */ @NotNull private Long dataSourceId; /** - * DB名称 + * DB name */ @NotNull private String databaseName; - /** - * schema名称 + * schema name */ private String schemaName; /** - * 分页编码 - * 只有select语句才有 + * + */ + private String tableName; + + /** + *Page coding + * Only available for select statements */ private Integer pageNo; /** - * 分页大小 - * 只有select语句才有 + * Paging Size + * Only available for select statements */ private Integer pageSize; /** - * 返回全部数据 - * 只有select语句才有 + * Return all data + * Only available for select statements */ private Boolean pageSizeAll; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/CreateTableSql.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/CreateTableSql.java index 4916e7768..fe1f09cc2 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/CreateTableSql.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/CreateTableSql.java @@ -6,6 +6,8 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** * @author jipengfei * @version : CreateTableSql.java @@ -14,7 +16,8 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class CreateTableSql { +public class CreateTableSql implements Serializable { + private static final long serialVersionUID = 1L; public String tableName; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DataSourceConnect.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DataSourceConnect.java index 18b4b2281..a80f7cfc2 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DataSourceConnect.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DataSourceConnect.java @@ -5,8 +5,10 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** - * 数据库连接对象 + * Database connection object * * @author Jiaju Zhuang */ @@ -14,21 +16,22 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class DataSourceConnect { +public class DataSourceConnect implements Serializable { + private static final long serialVersionUID = 1L; /** - * 是否成功标志位 + * success flag */ private Boolean success; /** - * 失败消息提示 - * 只有失败的情况下会有 + * Failure message prompt + * Only in case of failure */ private String message; /** - * 描述 + * description */ private String description; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Database.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Database.java index 716306267..39c73daaa 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Database.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Database.java @@ -11,7 +11,7 @@ import lombok.experimental.SuperBuilder; /** - * 数据库 + * database * * @author Jiaju Zhuang */ @@ -22,7 +22,7 @@ public class Database implements Serializable { private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID; /** - * 数据库名字 + * Database name */ @JsonAlias({"TABLE_CAT"}) private String name; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DefaultValue.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DefaultValue.java index dfffbf164..f093eecf4 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DefaultValue.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DefaultValue.java @@ -3,9 +3,12 @@ import lombok.AllArgsConstructor; import lombok.Data; +import java.io.Serializable; + @Data @AllArgsConstructor -public class DefaultValue { +public class DefaultValue implements Serializable { + private static final long serialVersionUID = 1L; private String defaultValue; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DriverEntry.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DriverEntry.java index 5c03706f1..0bf10249b 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DriverEntry.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/DriverEntry.java @@ -1,6 +1,7 @@ package ai.chat2db.spi.model; +import java.io.Serializable; import java.sql.Driver; import ai.chat2db.spi.config.DriverConfig; @@ -17,7 +18,8 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class DriverEntry { +public class DriverEntry implements Serializable { + private static final long serialVersionUID = 1L; private DriverConfig driverConfig; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/EngineType.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/EngineType.java new file mode 100644 index 000000000..3785375c4 --- /dev/null +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/EngineType.java @@ -0,0 +1,22 @@ +package ai.chat2db.spi.model; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.io.Serializable; + +@Data +@AllArgsConstructor +public class EngineType implements Serializable { + private static final long serialVersionUID = 1L; + private String name; + private boolean supportTTL; + private boolean supportSortOrder; + private boolean supportSkippingIndices; + private boolean supportDeduplication; + private boolean supportSettings; + private boolean supportParallelInsert; + private boolean supportProjections; + private boolean supportReplication; + +} diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ExecuteResult.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ExecuteResult.java index 1f28b2e2a..e7bba8841 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ExecuteResult.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ExecuteResult.java @@ -1,6 +1,8 @@ package ai.chat2db.spi.model; +import java.io.Serializable; import java.util.List; +import java.util.Map; import lombok.AllArgsConstructor; import lombok.Data; @@ -8,7 +10,7 @@ import lombok.experimental.SuperBuilder; /** - * 执行结果 + * Results of the * * @author Jiaju Zhuang */ @@ -16,21 +18,22 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class ExecuteResult { +public class ExecuteResult implements Serializable { + private static final long serialVersionUID = 1L; /** - * 是否成功标志位 + * success flag */ private Boolean success; /** - * 失败消息提示 - * 只有失败的情况下会有 + * Failure message prompt + * Only in case of failure */ private String message; /** - * 执行的sql + * executed sql */ private String sql; @@ -40,47 +43,47 @@ public class ExecuteResult { private String originalSql; /** - * 描述 + * description */ private String description; /** - * 修改行数 查询sql不会返回 + * Modify the number of rows and query sql will not return */ private Integer updateCount; /** - * 展示头的列表 + * List of display headers */ private List
      headerList; /** - * 数据的列表 + * list of data */ private List> dataList; /** - * sql 类型 + * sql type * * @see ai.chat2db.spi.enums.SqlTypeEnum */ private String sqlType; /** - * 是否存在下一页 - * 只有select语句才有 + * Whether there is a next page + * Only available for select statements */ private Boolean hasNextPage; /** - * 分页编码 - * 只有select语句才有 + * Page coding + * Only available for select statements */ private Integer pageNo; /** - * 分页大小 - * 只有select语句才有 + * Paging Size + * Only available for select statements */ private Integer pageSize; @@ -91,18 +94,23 @@ public class ExecuteResult { private String fuzzyTotal; /** - * 执行持续时间 + * execution duration */ private Long duration; /** - * 返回结果是否可以编辑 + * Whether the returned result can be edited */ private boolean canEdit; /** - * 表名 + * Table Name for the result */ private String tableName; + + /** + * Extra information that can be used by the plugin + */ + private Map extra; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java index b111ed8f1..24894c7dc 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Function.java @@ -7,6 +7,8 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** * @author jipengfei * @version : Function.java @@ -15,7 +17,8 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Function { +public class Function implements Serializable { + private static final long serialVersionUID = 1L; //FUNCTION_CAT String => function catalog (may be null) //FUNCTION_SCHEM String => function schema (may be null) //FUNCTION_NAME String => function name. This is the name used to invoke the function diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Header.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Header.java index 8935a240c..7574df864 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Header.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Header.java @@ -6,8 +6,10 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** - * 单元格头 + * cell header * * @author Jiaju Zhuang */ @@ -15,16 +17,17 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Header{ +public class Header implements Serializable { + private static final long serialVersionUID = 1L; /** - * 单元格类型 + * cell type * * @see DataTypeEnum */ private String dataType; /** - * 展示的名字 + * display name */ private String name; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/IndexType.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/IndexType.java index a32c47212..523493cf8 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/IndexType.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/IndexType.java @@ -3,9 +3,12 @@ import lombok.AllArgsConstructor; import lombok.Data; +import java.io.Serializable; + @Data @AllArgsConstructor -public class IndexType { +public class IndexType implements Serializable { + private static final long serialVersionUID = 1L; /** * diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/KeyValue.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/KeyValue.java index 3edacebdc..d3416455b 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/KeyValue.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/KeyValue.java @@ -16,22 +16,22 @@ @Data public class KeyValue implements Serializable { /** - * 属性名 + * attribute name */ private String key; /** - * 属性值 + * attribute value */ private String value; /** - * 是否必填 + * Is it required? */ private boolean required; /** - * 选项 + * Options */ private List choices; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/OrderBy.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/OrderBy.java index fc90c4dad..8769afbdd 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/OrderBy.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/OrderBy.java @@ -2,16 +2,19 @@ import lombok.Data; +import java.io.Serializable; + @Data -public class OrderBy { +public class OrderBy implements Serializable { + private static final long serialVersionUID = 1L; /** - * 排序字段 + * sort field */ private String columnName; /** - * 排序方式 + * sort by */ private boolean asc; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java index 3c48489d7..93163e3fa 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Procedure.java @@ -7,6 +7,8 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** * @author jipengfei * @version : Procedure.java @@ -15,7 +17,8 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Procedure { +public class Procedure implements Serializable { + private static final long serialVersionUID = 1L; //PROCEDURE_CAT String => procedure catalog (may be null) //PROCEDURE_SCHEM String => procedure schema (may be null) //PROCEDURE_NAME String => procedure name diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/QueryResult.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/QueryResult.java new file mode 100644 index 000000000..e125060e9 --- /dev/null +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/QueryResult.java @@ -0,0 +1,16 @@ +package ai.chat2db.spi.model; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +@Data +public class QueryResult implements Serializable { + + private String tableName; + private List
      headerList; + private List operations; + private Map extra; +} diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ResultOperation.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ResultOperation.java index 91e45eb9a..9774d4fa7 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ResultOperation.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ResultOperation.java @@ -2,10 +2,12 @@ import lombok.Data; +import java.io.Serializable; import java.util.List; @Data -public class ResultOperation { +public class ResultOperation implements Serializable { + private static final long serialVersionUID = 1L; private String type; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java index 76654f17a..ca36f2080 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSHInfo.java @@ -1,6 +1,7 @@ package ai.chat2db.spi.model; +import java.io.Serializable; import java.util.Objects; import lombok.Data; @@ -10,60 +11,61 @@ * @version : SSHInfo.java */ @Data -public class SSHInfo { +public class SSHInfo implements Serializable { + private static final long serialVersionUID = 1L; /** - * 是否使用ssh + * Whether to use ssh */ private boolean use; /** - * ssh主机名 + * ssh hostname */ private String hostName; /** - * ssh端口 + * ssh port */ private String port; /** - * ssh用户名 + * ssh username */ private String userName; /** - * ssh本地端口 + * ssh local port */ private String localPort; /** - * ssh认证类型 + * ssh Certification type */ private String authenticationType; /** - * ssh密码 + * ssh password */ private String password; /** - * ssh密钥文件 + * ssh key file */ private String keyFile; /** - * ssh密钥文件密码 + * ssh key file password */ private String passphrase; /** - * ssh跳板机目标主机 + * ssh springboard target host */ private String rHost; /** - * ssh跳板目标端口 + * ssh springboard target port */ private String rPort; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSLInfo.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSLInfo.java index 7219c30c6..bf8cc749a 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSLInfo.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SSLInfo.java @@ -3,10 +3,13 @@ import lombok.Data; +import java.io.Serializable; + /** * @author jipengfei * @version : SSLInfo.java */ @Data -public class SSLInfo { +public class SSLInfo implements Serializable { + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Schema.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Schema.java index 2b3635f8b..5d2050f28 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Schema.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Schema.java @@ -27,7 +27,7 @@ public class Schema implements Serializable { @JsonAlias({"TABLE_CATALOG","table_catalog"}) private String databaseName; /** - * 数据名字 + * Data name */ @JsonAlias({"TABLE_SCHEM","table_schem"}) private String name; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ShowDatabaseResult.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ShowDatabaseResult.java index bbcc7d2e7..786102fb6 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ShowDatabaseResult.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/ShowDatabaseResult.java @@ -6,6 +6,8 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** * @author jipengfei * @version : ShowDatabaseResult.java @@ -14,6 +16,7 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class ShowDatabaseResult { +public class ShowDatabaseResult implements Serializable { + private static final long serialVersionUID = 1L; String database; } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleColumn.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleColumn.java index cb1139bf7..d88a5e552 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleColumn.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleColumn.java @@ -6,14 +6,17 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + @Data @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class SimpleColumn { +public class SimpleColumn implements Serializable { + private static final long serialVersionUID = 1L; /** - * 列名 + * Column name */ @JsonAlias({"COLUMN_NAME"}) private String name; @@ -23,7 +26,7 @@ public class SimpleColumn { private String columnType; /** - * 注释 + * Comment */ @JsonAlias({"REMARKS"}) private String comment; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleTable.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleTable.java index 2a5159d68..b637f29a1 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleTable.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/SimpleTable.java @@ -6,19 +6,22 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + @Data @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class SimpleTable { +public class SimpleTable implements Serializable { + private static final long serialVersionUID = 1L; /** - * 表名 + * Table Name */ @JsonAlias({"TABLE_NAME"}) private String name; /** - * 描述 + * description */ @JsonAlias({"REMARKS"}) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Sql.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Sql.java index 621a96d91..54965fb3d 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Sql.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Sql.java @@ -5,8 +5,10 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** - * sql对象 + * sql object * * @author Jiaju Zhuang */ @@ -14,7 +16,8 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Sql { +public class Sql implements Serializable { + private static final long serialVersionUID = 1L; /** * sql diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Table.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Table.java index 640f2180c..a75e87cd9 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Table.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Table.java @@ -1,16 +1,16 @@ package ai.chat2db.spi.model; -import java.util.List; - - import com.fasterxml.jackson.annotation.JsonAlias; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; +import java.util.List; + /** - * 表信息 + * Table information * * @author Jiaju Zhuang */ @@ -18,57 +18,58 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Table { +public class Table implements Serializable { + private static final long serialVersionUID = 1L; /** - * 表名 + * Table Name */ @JsonAlias({"TABLE_NAME"}) private String name; /** - * 描述 + * description */ @JsonAlias({"REMARKS"}) private String comment; /** - * DB 名 + * DB name */ @JsonAlias({"TABLE_SCHEM"}) private String schemaName; /** - * 列列表 + * columnList */ private List columnList; /** - * 索引列表 + * indexList */ private List indexList; /** - * DB类型 + * DB type */ private String dbType; /** - * 数据库名 + * Database name */ @JsonAlias("TABLE_CAT") private String databaseName; /** - * 表类型 + * table type */ @JsonAlias("TABLE_TYPE") private String type; /** - * 是否置顶 + * Whether to pin it to the top */ private boolean pinned; @@ -77,7 +78,10 @@ public class Table { */ private String ddl; - + /** + * engine + */ + @JsonAlias("TYPE_NAME") private String engine; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableColumn.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableColumn.java index 215f17344..3f946b6d6 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableColumn.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableColumn.java @@ -6,10 +6,11 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; import java.util.Objects; /** - * 列信息 + * Column information * * @author Jiaju Zhuang */ @@ -17,41 +18,42 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class TableColumn { +public class TableColumn implements Serializable { + private static final long serialVersionUID = 1L; /** * Old column, when modifying a column, you need this parameter */ private TableColumn oldColumn; /** - * 旧的列名,在修改列的时候需要这个参数 - * 在返回的时候oldName=name + * The old column name, this parameter is needed when modifying the column + * oldName=name when returning */ private String oldName; /** - * 列名 + * Column name */ @JsonAlias({"COLUMN_NAME","column_name"}) private String name; /** - * 表名 + * Table Name */ @JsonAlias({"TABLE_NAME","table_name"}) private String tableName; /** - * 列的类型 - * 比如 varchar(100) ,double(10,6) + * Column type + * For example, varchar(100), double(10,6) */ @JsonAlias({"TYPE_NAME","type_name"}) private String columnType; /** - * 列的数据类型 - * 比如 varchar ,double + * Column data type + * For example, varchar, double */ @JsonAlias({"DATA_TYPE","data_type"}) @@ -59,7 +61,7 @@ public class TableColumn { /** - * 默认值 + * default value */ @JsonAlias({"COLUMN_DEF","column_def"}) @@ -68,42 +70,42 @@ public class TableColumn { /** - * 是否自增 - * 为空 代表没有值 数据库的实际语义是 false + * Whether to increase automatically + * Empty means there is no value. The actual semantics of the database are false. */ private Boolean autoIncrement; /** - * 注释 + * Comment */ @JsonAlias({"REMARKS","remarks"}) private String comment; /** - * 是否主键 + * Is it a primary key? */ private Boolean primaryKey; /** - * 主键名 + * primary key name */ private String primaryKeyName; /** - * 主键顺序 + * primaryKeyOrder */ private int primaryKeyOrder; /** - * 空间名 + * Space name */ @JsonAlias({"TABLE_SCHEM","table_schem"}) private String schemaName; /** - * 数据库名 + * Database name */ @JsonAlias({"TABLE_CAT","table_cat"}) private String databaseName; @@ -199,16 +201,22 @@ public class TableColumn { // sqlserver private String defaultConstraintName; + // DM seed + private Integer seed; + + // DM increment + private Integer increment; + @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { return true;} + if (o == null || getClass() != o.getClass()) { return false;} TableColumn that = (TableColumn) o; - return Objects.equals(name, that.name) && Objects.equals(tableName, that.tableName) && Objects.equals(columnType, that.columnType) && Objects.equals(defaultValue, that.defaultValue) && Objects.equals(autoIncrement, that.autoIncrement) && Objects.equals(comment, that.comment) && Objects.equals(columnSize, that.columnSize) && Objects.equals(decimalDigits, that.decimalDigits) && Objects.equals(numPrecRadix, that.numPrecRadix) && Objects.equals(sqlDataType, that.sqlDataType) && Objects.equals(ordinalPosition, that.ordinalPosition) && Objects.equals(nullable, that.nullable) && Objects.equals(extent, that.extent) && Objects.equals(charSetName, that.charSetName) && Objects.equals(collationName, that.collationName) && Objects.equals(value, that.value) && Objects.equals(unit, that.unit) && Objects.equals(sparse, that.sparse) && Objects.equals(defaultConstraintName, that.defaultConstraintName); + return Objects.equals(name, that.name) && Objects.equals(tableName, that.tableName) && Objects.equals(columnType, that.columnType) && Objects.equals(defaultValue, that.defaultValue) && Objects.equals(autoIncrement, that.autoIncrement) && Objects.equals(comment, that.comment) && Objects.equals(columnSize, that.columnSize) && Objects.equals(decimalDigits, that.decimalDigits) && Objects.equals(numPrecRadix, that.numPrecRadix) && Objects.equals(sqlDataType, that.sqlDataType) && Objects.equals(ordinalPosition, that.ordinalPosition) && Objects.equals(nullable, that.nullable) && Objects.equals(extent, that.extent) && Objects.equals(charSetName, that.charSetName) && Objects.equals(collationName, that.collationName) && Objects.equals(value, that.value) && Objects.equals(unit, that.unit) && Objects.equals(sparse, that.sparse) && Objects.equals(defaultConstraintName, that.defaultConstraintName) && Objects.equals(seed, that.seed) && Objects.equals(increment, that.increment); } @Override public int hashCode() { - return Objects.hash(name, tableName, columnType, defaultValue, autoIncrement, comment, columnSize, decimalDigits, numPrecRadix, sqlDataType, ordinalPosition, nullable, extent, charSetName, collationName, value, unit, sparse, defaultConstraintName); + return Objects.hash(name, tableName, columnType, defaultValue, autoIncrement, comment, columnSize, decimalDigits, numPrecRadix, sqlDataType, ordinalPosition, nullable, extent, charSetName, collationName, value, unit, sparse, defaultConstraintName, seed, increment); } } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndex.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndex.java index 4ef9feddf..50e7be1dd 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndex.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndex.java @@ -1,5 +1,6 @@ package ai.chat2db.spi.model; +import java.io.Serializable; import java.util.List; @@ -9,7 +10,7 @@ import lombok.experimental.SuperBuilder; /** - * 索引信息 + * Index information * * @author Jiaju Zhuang */ @@ -17,49 +18,50 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class TableIndex { +public class TableIndex implements Serializable { + private static final long serialVersionUID = 1L; private String oldName; /** - * 索引名称 + * Index name */ private String name; /** - * 表名 + * Table Name */ private String tableName; /** - * 索引类型 + * Index type * * @see IndexTypeEnum */ private String type; /** - * 是否唯一 + * Is it unique? */ private Boolean unique; /** - * 注释 + * Comment */ private String comment; /** - * 索引所属schema + * The schema to which the index belongs */ private String schemaName; /** - * 数据库名 + * Database name */ private String databaseName; /** - * 索引包含的列 + * Columns included in the index */ private List columnList; @@ -67,28 +69,28 @@ public class TableIndex { private String editStatus; /** - * 是否并发 + * Is it concurrent? */ private Boolean concurrently; /** - * 索引方法 + * Index method */ private String method; /** - * 外键指向schema + * Foreign key points to schema */ private String foreignSchemaName; /** - * 外键指向表名 + * Foreign key points to table name */ private String foreignTableName; /** - * 外键指向的列名 + * The column name pointed to by the foreign key */ private List foreignColumnNamelist; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndexColumn.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndexColumn.java index 8feb7bece..6c8f19a42 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndexColumn.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableIndexColumn.java @@ -7,8 +7,10 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** - * 列信息 + * Column information * * @author Jiaju Zhuang */ @@ -16,65 +18,66 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class TableIndexColumn { +public class TableIndexColumn implements Serializable { + private static final long serialVersionUID = 1L; /** - * 索引名称 + * Index name */ @JsonAlias({"INDEX_NAME"}) private String indexName; /** - * 表名 + * Table Name */ @JsonAlias ({"TABLE_NAME"}) private String tableName; /** - * 索引类型 + * Index type * * @see */ private String type; /** - * 注释 + * Comment */ private String comment; /** - * 列名 + * columnName */ @JsonAlias({"COLUMN_NAME"}) private String columnName; /** - * 顺序 + * ordinalPosition */ @JsonAlias({"ORDINAL_POSITION"}) private Short ordinalPosition; /** - * 排序 + * collation * */ private String collation; /** - * 索引所属schema + * The schema to which the index belongs */ @JsonAlias({"TABLE_SCHEM"}) private String schemaName; /** - * 数据库名 + * Database name */ @JsonAlias({"TABLE_CAT"}) private String databaseName; /** - * 是否唯一 + * Is it unique? */ @JsonAlias({"NON_UNIQUE"}) private Boolean nonUnique; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableMeta.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableMeta.java index 6ae0c2d7f..b882db826 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableMeta.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/TableMeta.java @@ -3,11 +3,13 @@ import lombok.Builder; import lombok.Data; +import java.io.Serializable; import java.util.List; @Data @Builder -public class TableMeta { +public class TableMeta implements Serializable { + private static final long serialVersionUID = 1L; private List columnTypes; @@ -21,4 +23,6 @@ public class TableMeta { private List indexTypes; private List defaultValues; + + private List engineTypes; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Trigger.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Trigger.java index 472ef555a..e466c9d2b 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Trigger.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Trigger.java @@ -6,6 +6,8 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + /** * @author jipengfei * @version : Trigger.java @@ -14,7 +16,8 @@ @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Trigger { +public class Trigger implements Serializable { + private static final long serialVersionUID = 1L; private String databaseName; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Type.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Type.java index cb7568c17..812d2f5a3 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Type.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/Type.java @@ -6,11 +6,14 @@ import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import java.io.Serializable; + @Data @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class Type { +public class Type implements Serializable { + private static final long serialVersionUID = 1L; @JsonAlias("TYPE_NAME") private String typeName; diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java index 9e6fce81a..e7fa17825 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/Chat2DBContext.java @@ -1,24 +1,22 @@ package ai.chat2db.spi.sql; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Iterator; -import java.util.Map; -import java.util.ServiceLoader; -import java.util.concurrent.ConcurrentHashMap; - import ai.chat2db.spi.DBManage; import ai.chat2db.spi.MetaData; import ai.chat2db.spi.Plugin; import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.config.DBConfig; import ai.chat2db.spi.config.DriverConfig; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Iterator; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.ConcurrentHashMap; + /** * @author jipengfei * @version : Chat2DBContext.java @@ -27,6 +25,16 @@ public class Chat2DBContext { private static final ThreadLocal CONNECT_INFO_THREAD_LOCAL = new ThreadLocal<>(); +// private static final Cache CONNECT_INFO_CACHE = CacheBuilder.newBuilder() +// .maximumSize(1000) +// .expireAfterAccess(5, TimeUnit.MINUTES) +// .removalListener((RemovalListener) notification -> { +// if (notification.getValue() != null) { +// System.out.println("remove connect info " + notification.getKey()); +// notification.getValue().close(); +// } +// }).build(); + public static Map PLUGIN_MAP = new ConcurrentHashMap<>(); static { @@ -47,7 +55,7 @@ public static SqlBuilder getSqlBuilder() { } /** - * 获取当前线程的ContentContext + * Get the ContentContext of the current thread * * @return */ @@ -81,19 +89,24 @@ public static DBManage getDBManage() { public static Connection getConnection() { ConnectInfo connectInfo = getConnectInfo(); Connection connection = connectInfo.getConnection(); - if (connection == null) { - synchronized (connectInfo) { - connection = connectInfo.getConnection(); - try { - if (connection != null && !connection.isClosed()) { - return connection; - } else { + try { + if (connection == null || connection.isClosed()) { + synchronized (connectInfo) { + connection = connectInfo.getConnection(); + try { + if (connection != null && !connection.isClosed()) { + return connection; + } else { + connection = getDBManage().getConnection(connectInfo); + } + } catch (SQLException e) { connection = getDBManage().getConnection(connectInfo); } - } catch (SQLException e) { - connection = getDBManage().getConnection(connectInfo); + connectInfo.setConnection(connection); } } + } catch (SQLException e) { + log.error("get connection error", e); } return connection; } @@ -119,7 +132,7 @@ public static String getDbVersion() { /** - * 设置context + * Set context * * @param info */ @@ -133,39 +146,18 @@ public static void putContext(ConnectInfo info) { } /** - * 设置context + * Set context */ public static void removeContext() { ConnectInfo connectInfo = CONNECT_INFO_THREAD_LOCAL.get(); if (connectInfo != null) { - Connection connection = connectInfo.getConnection(); - try { - if (connection != null && !connection.isClosed()) { - connection.close(); - } - } catch (SQLException e) { - log.error("close connection error", e); - } - - Session session = connectInfo.getSession(); - if (session != null && session.isConnected() && connectInfo.getSsh() != null - && connectInfo.getSsh().isUse()) { - try { - session.delPortForwardingL(Integer.parseInt(connectInfo.getSsh().getLocalPort())); - } catch (JSchException e) { - } - } + connectInfo.close(); CONNECT_INFO_THREAD_LOCAL.remove(); } } - /** - * 设置context - */ - public static void remove() { - ConnectInfo connectInfo = CONNECT_INFO_THREAD_LOCAL.get(); - if (connectInfo != null) { - CONNECT_INFO_THREAD_LOCAL.remove(); - } + public static void close() { + removeContext(); } + } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/ConnectInfo.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/ConnectInfo.java index eb18d7667..f7188057c 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/ConnectInfo.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/ConnectInfo.java @@ -2,6 +2,7 @@ package ai.chat2db.spi.sql; import java.sql.Connection; +import java.sql.SQLException; import java.time.LocalDateTime; import java.util.LinkedHashMap; import java.util.List; @@ -11,6 +12,7 @@ import ai.chat2db.spi.model.KeyValue; import ai.chat2db.spi.model.SSHInfo; import ai.chat2db.spi.model.SSLInfo; +import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import org.springframework.util.ObjectUtils; @@ -19,23 +21,25 @@ * @version : ConnectInfo.java */ public class ConnectInfo { + + private String loginUser; /** - * 别名 + * alias */ private String alias; /** - * 数据连接ID + * dataSourceId */ private Long dataSourceId; /** - * 创建时间 + * creation time */ private LocalDateTime gmtCreate; /** - * 修改时间 + * modified time */ private LocalDateTime gmtModified; /** @@ -44,44 +48,43 @@ public class ConnectInfo { private String databaseName; - /** * schema */ private String schemaName; /** - * 控制台ID + * console id */ private Long consoleId; /** - * 数据库URL + * Database URL */ private String url; /** - * 用户名 + * user */ private String user; /** - * 密码 + * password */ private String password; /** - * console独立占有连接 + * The console independently owns the connection */ private Boolean consoleOwn = Boolean.FALSE; /** - * 数据库类型 + * Database type */ private String dbType; /** - * 端口 + * port */ private Integer port; @@ -116,17 +119,16 @@ public class ConnectInfo { private String driver; /** - * jdbc版本 + * jdbc version */ private String jdbc; /** - * 扩展信息 + * Extended Information */ private List extendInfo; - public Connection connection; /** @@ -134,7 +136,7 @@ public class ConnectInfo { */ private String dbVersion; - + private DriverConfig driverConfig; @@ -166,21 +168,21 @@ public void setSession(Session session) { public Session session; - public LinkedHashMap getExtendMap() { + public LinkedHashMap getExtendMap() { if (ObjectUtils.isEmpty(extendInfo)) { - if(driverConfig!= null) { + if (driverConfig != null) { extendInfo = driverConfig.getExtendInfo(); - }else { + } else { return new LinkedHashMap<>(); } } - if(ObjectUtils.isEmpty(extendInfo)){ + if (ObjectUtils.isEmpty(extendInfo)) { return new LinkedHashMap<>(); } - LinkedHashMap map = new LinkedHashMap<>(); + LinkedHashMap map = new LinkedHashMap<>(); for (KeyValue keyValue : extendInfo) { - map.put(keyValue.getKey(),keyValue.getValue()); + map.put(keyValue.getKey(), keyValue.getValue()); } return map; } @@ -200,12 +202,16 @@ public void setUrl(String url) { @Override public boolean equals(Object o) { - if (this == o) {return true;} - if (!(o instanceof ConnectInfo)) {return false;} - ConnectInfo that = (ConnectInfo)o; + if (this == o) { + return true; + } + if (!(o instanceof ConnectInfo)) { + return false; + } + ConnectInfo that = (ConnectInfo) o; return Objects.equals(dataSourceId, that.dataSourceId) - && Objects.equals(gmtModified, that.gmtModified) - ; + && Objects.equals(gmtModified, that.gmtModified) + ; } @Override @@ -452,7 +458,6 @@ public List getExtendInfo() { } - /** * Setter method for property extendInfo. * @@ -522,4 +527,64 @@ public String getSchemaName() { public void setSchemaName(String schemaName) { this.schemaName = schemaName; } + + public ConnectInfo copy() { + ConnectInfo copy = new ConnectInfo(); + copy.setDbVersion(this.getDbVersion()); + copy.setDbType(this.getDbType()); + copy.setHost(this.getHost()); + copy.setPort(this.getPort()); + copy.setDatabaseName(this.getDatabaseName()); + copy.setSchemaName(this.getSchemaName()); + copy.setUser(this.getUser()); + copy.setPassword(this.getPassword()); + copy.setUrl(this.getUrl()); + copy.setAlias(this.getAlias()); + copy.setDataSourceId(this.getDataSourceId()); + copy.setConsoleId(this.getConsoleId()); + copy.setConsoleOwn(this.getConsoleOwn()); + copy.setDriver(this.getDriver()); + copy.setSsh(this.getSsh()); + copy.setSsl(this.getSsl()); + copy.setJdbc(this.getJdbc()); + copy.setExtendInfo(this.getExtendInfo()); + copy.setDriverConfig(this.getDriverConfig()); + copy.setSid(this.getSid()); + copy.setUrlWithOutDatabase(this.getUrlWithOutDatabase()); + return copy; + } + + public void close() { + if (this != null) { + Connection connection = this.getConnection(); + try { + if (connection != null && !connection.isClosed()) { + connection.close(); + } + } catch (SQLException e) { + + } + com.jcraft.jsch.Session session = this.getSession(); + if (session != null && session.isConnected() && this.getSsh() != null + && this.getSsh().isUse()) { + try { + session.delPortForwardingL(Integer.parseInt(this.getSsh().getLocalPort())); + } catch (JSchException e) { + } + } + } + } + + + public String getKey() { + return "loginUser:"+loginUser + "_dataSourceId:" + dataSourceId + "_databaseName:" + databaseName + "_schemaName:" + schemaName + "_consoleId:" + consoleId; + } + + public String getLoginUser() { + return loginUser; + } + + public void setLoginUser(String loginUser) { + this.loginUser = loginUser; + } } \ No newline at end of file diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/IDriverManager.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/IDriverManager.java index 32173357a..b7f39b029 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/IDriverManager.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/IDriverManager.java @@ -177,7 +177,7 @@ public static ClassLoader getClassLoader(DriverConfig driverConfig) throws Malfo try { cl.loadClass(driverConfig.getJdbcDriverClass()); } catch (Exception e) { - //如果报错删除目录重试一次 + //If an error is reported, delete the directory and try again. for (int i = 0; i < jarPaths.length; i++) { File driverFile = new File(JdbcJarUtils.getNewFullPath(jarPaths[i])); urls[i] = driverFile.toURI().toURL(); diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/ResultSetConsumer.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/ResultSetConsumer.java new file mode 100644 index 000000000..cfd4abe40 --- /dev/null +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/ResultSetConsumer.java @@ -0,0 +1,10 @@ +package ai.chat2db.spi.sql; + +import java.sql.ResultSet; +import java.sql.SQLException; + +@FunctionalInterface +public interface ResultSetConsumer { + + void accept(ResultSet resultSet) throws SQLException; +} diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java index 9278629b4..e51181743 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/sql/SQLExecutor.java @@ -8,7 +8,6 @@ import java.sql.Statement; import java.util.*; import java.util.function.Consumer; -import java.util.function.Function; import java.util.stream.Collectors; import ai.chat2db.server.tools.base.constant.EasyToolsConstant; @@ -17,6 +16,7 @@ import ai.chat2db.server.tools.common.util.EasyCollectionUtils; import ai.chat2db.server.tools.common.util.I18nUtils; import ai.chat2db.spi.CommandExecutor; +import ai.chat2db.spi.MetaData; import ai.chat2db.spi.ValueHandler; import ai.chat2db.spi.enums.DataTypeEnum; import ai.chat2db.spi.enums.SqlTypeEnum; @@ -40,7 +40,7 @@ import org.springframework.util.Assert; /** - * Dbhub 统一数据库连接管理 + * Dbhub unified database connection management * * @author jipengfei */ @@ -64,7 +64,7 @@ public R execute(Connection connection, String sql, ResultSetFunction fun log.info("execute:{}", sql); try (Statement stmt = connection.createStatement();) { boolean query = stmt.execute(sql); - // 代表是查询 + // Represents the query if (query) { try (ResultSet rs = stmt.getResultSet();) { return function.apply(rs); @@ -76,6 +76,21 @@ public R execute(Connection connection, String sql, ResultSetFunction fun return null; } + public void execute(Connection connection, String sql, ResultSetConsumer consumer) { + log.info("execute:{}", sql); + try (Statement stmt = connection.createStatement()) { + boolean query = stmt.execute(sql); + // Represents the query + if (query) { + try (ResultSet rs = stmt.getResultSet();) { + consumer.accept(rs); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + public void execute(Connection connection, String sql, Consumer> headerConsumer, Consumer> rowConsumer, ValueHandler valueHandler) { execute(connection, sql, headerConsumer, rowConsumer, true, valueHandler); @@ -87,23 +102,23 @@ public void execute(Connection connection, String sql, Consumer> he log.info("execute:{}", sql); try (Statement stmt = connection.createStatement();) { boolean query = stmt.execute(sql); - // 代表是查询 + // Represents the query if (query) { ResultSet rs = null; try { rs = stmt.getResultSet(); - // 获取有几列 + // Get how many columns ResultSetMetaData resultSetMetaData = rs.getMetaData(); int col = resultSetMetaData.getColumnCount(); - // 获取header信息 + // Get header information List
      headerList = Lists.newArrayListWithExpectedSize(col); for (int i = 1; i <= col; i++) { headerList.add(Header.builder() - .dataType(JdbcUtils.resolveDataType( - resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode()) - .name(ResultSetUtils.getColumnName(resultSetMetaData, i)) - .build()); + .dataType(JdbcUtils.resolveDataType( + resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode()) + .name(ResultSetUtils.getColumnName(resultSetMetaData, i)) + .build()); } headerConsumer.accept(headerList); @@ -124,20 +139,20 @@ public void execute(Connection connection, String sql, Consumer> he } /** - * 执行sql + * Execute SQL * * @param sql * @return * @throws SQLException */ public ExecuteResult execute(final String sql, Connection connection, ValueHandler valueHandler) - throws SQLException { + throws SQLException { return execute(sql, connection, true, null, null, valueHandler); } @Override public ExecuteResult executeUpdate(String sql, Connection connection, int n) - throws SQLException { + throws SQLException { Assert.notNull(sql, "SQL must not be null"); log.info("execute:{}", sql); // connection.setAutoCommit(false); @@ -147,29 +162,40 @@ public ExecuteResult executeUpdate(String sql, Connection connection, int n) if (affectedRows != n) { executeResult.setSuccess(false); executeResult.setMessage("Update error " + sql + " update affectedRows = " + affectedRows - + ", Each SQL statement should update no more than one record. Please use a unique key for " - + "updates."); + + ", Each SQL statement should update no more than one record. Please use a unique key for " + + "updates."); // connection.rollback(); } } return executeResult; } + @Override + public List executeSelectTable(Command command) { + MetaData metaData = Chat2DBContext.getMetaData(); + String tableName = metaData.getMetaDataName(command.getDatabaseName(), command.getSchemaName(), + command.getTableName()); + String sql = "select * from " + tableName; + command.setScript(sql); + return execute(command); + } + /** * Executes the given SQL query using the provided connection. - * @param sql The SQL query to be executed. - * @param connection The database connection to use for the query. + * + * @param sql The SQL query to be executed. + * @param connection The database connection to use for the query. * @param limitRowSize Flag to indicate if row size should be limited. - * @param offset The starting point of rows to fetch in the result set. - * @param count The number of rows to fetch from the result set. + * @param offset The starting point of rows to fetch in the result set. + * @param count The number of rows to fetch from the result set. * @param valueHandler Handles the processing of the result set values. * @return ExecuteResult containing the result of the execution. * @throws SQLException If there is any SQL related error. */ public ExecuteResult execute(final String sql, Connection connection, boolean limitRowSize, Integer offset, - Integer count, ValueHandler valueHandler) - throws SQLException { + Integer count, ValueHandler valueHandler) + throws SQLException { Assert.notNull(sql, "SQL must not be null"); log.info("execute:{}", sql); @@ -187,19 +213,19 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li TimeInterval timeInterval = new TimeInterval(); boolean query = stmt.execute(sql); executeResult.setDescription(I18nUtils.getMessage("sqlResult.success")); - // 代表是查询 + // Represents the query if (query) { ResultSet rs = null; try { rs = stmt.getResultSet(); - // 获取有几列 + // Get how many columns ResultSetMetaData resultSetMetaData = rs.getMetaData(); int col = resultSetMetaData.getColumnCount(); - // 获取header信息 + // Get header information List
      headerList = Lists.newArrayListWithExpectedSize(col); executeResult.setHeaderList(headerList); - int chat2dbAutoRowIdIndex = -1;// chat2db自动生成的行分页ID + int chat2dbAutoRowIdIndex = -1;// Row paging ID automatically generated by chat2db boolean isMongoMap = false; for (int i = 1; i <= col; i++) { @@ -214,14 +240,14 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li continue; } String dataType = JdbcUtils.resolveDataType( - resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode(); + resultSetMetaData.getColumnTypeName(i), resultSetMetaData.getColumnType(i)).getCode(); headerList.add(Header.builder() - .dataType(dataType) - .name(name) - .build()); + .dataType(dataType) + .name(name) + .build()); } - // 获取数据信息 + // Get data information List> dataList = Lists.newArrayList(); executeResult.setDataList(dataList); @@ -258,16 +284,16 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li if (o instanceof Document document) { for (String string : document.keySet()) { headerListMap.computeIfAbsent(string, k -> Header.builder() - .dataType("string") - .name(string) - .build()); + .dataType("string") + .name(string) + .build()); row.put(string, Objects.toString(document.get(string))); } } else { headerListMap.computeIfAbsent("_unknown", k -> Header.builder() - .dataType("string") - .name("_unknown") - .build()); + .dataType("string") + .name("_unknown") + .build()); row.put("_unknown", Objects.toString(o)); } } @@ -294,7 +320,7 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li } } else { executeResult.setDuration(timeInterval.interval()); - // 修改或者其他 + // Modification or other executeResult.setUpdateCount(stmt.getUpdateCount()); } } @@ -302,7 +328,7 @@ public ExecuteResult execute(final String sql, Connection connection, boolean li } /** - * 执行sql + * Execute SQL * * @param connection * @param sql @@ -318,7 +344,7 @@ public ExecuteResult execute(Connection connection, String sql) throws SQLExcept } /** - * 获取所有的数据库 + * Get all databases * * @param connection * @return @@ -370,7 +396,7 @@ public List schemas(Connection connection, String databaseName, String s } /** - * 获取所有的数据库表 + * Get all database tables * * @param connection * @param databaseName @@ -380,15 +406,15 @@ public List schemas(Connection connection, String databaseName, String s * @return */ public List
      tables(Connection connection, String databaseName, String schemaName, String tableName, - String types[]) { + String types[]) { try { DatabaseMetaData metadata = connection.getMetaData(); ResultSet resultSet = metadata.getTables(databaseName, schemaName, tableName, - types); - // 如果connection为mysql + types); + // If connection is mysql if ("MySQL".equalsIgnoreCase(metadata.getDatabaseProductName())) { - // 获取mysql表的comment + // Get the comment of mysql table List
      tables = ResultSetUtils.toObjectList(resultSet, Table.class); if (CollectionUtils.isNotEmpty(tables)) { for (Table table : tables) { @@ -414,8 +440,28 @@ public List
      tables(Connection connection, String databaseName, String sch } } + /** query table names + * @param connection + * @param databaseName + * @param schemaName + * @param tableName + * @param types + * @return + */ + public List tableNames(Connection connection, String databaseName, String schemaName, String tableName, String[] types) { + List tableNames = new ArrayList<>(); + try (ResultSet resultSet = connection.getMetaData().getTables(databaseName, schemaName, tableName, types)) { + while (resultSet.next()) { + tableNames.add(resultSet.getString("TABLE_NAME")); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return tableNames; + } + /** - * 获取所有的数据库表列 + * Get all database table columns * * @param connection * @param databaseName @@ -425,10 +471,10 @@ public List
      tables(Connection connection, String databaseName, String sch * @return */ public List columns(Connection connection, String databaseName, String schemaName, String - tableName, - String columnName) { + tableName, + String columnName) { try (ResultSet resultSet = connection.getMetaData().getColumns(databaseName, schemaName, tableName, - columnName)) { + columnName)) { return ResultSetUtils.toObjectList(resultSet, TableColumn.class); } catch (Exception e) { throw new RuntimeException(e); @@ -447,22 +493,22 @@ public List columns(Connection connection, String databaseName, Str public List indexes(Connection connection, String databaseName, String schemaName, String tableName) { List tableIndices = Lists.newArrayList(); try (ResultSet resultSet = connection.getMetaData().getIndexInfo(databaseName, schemaName, tableName, - false, - false)) { + false, + false)) { List tableIndexColumns = ResultSetUtils.toObjectList(resultSet, TableIndexColumn.class); tableIndexColumns.stream().filter(c -> c.getIndexName() != null).collect( - Collectors.groupingBy(TableIndexColumn::getIndexName)).entrySet() - .stream().forEach(entry -> { - TableIndex tableIndex = new TableIndex(); - TableIndexColumn column = entry.getValue().get(0); - tableIndex.setName(entry.getKey()); - tableIndex.setTableName(column.getTableName()); - tableIndex.setSchemaName(column.getSchemaName()); - tableIndex.setDatabaseName(column.getDatabaseName()); - tableIndex.setUnique(!column.getNonUnique()); - tableIndex.setColumnList(entry.getValue()); - tableIndices.add(tableIndex); - }); + Collectors.groupingBy(TableIndexColumn::getIndexName)).entrySet() + .stream().forEach(entry -> { + TableIndex tableIndex = new TableIndex(); + TableIndexColumn column = entry.getValue().get(0); + tableIndex.setName(entry.getKey()); + tableIndex.setTableName(column.getTableName()); + tableIndex.setSchemaName(column.getSchemaName()); + tableIndex.setDatabaseName(column.getDatabaseName()); + tableIndex.setUnique(!column.getNonUnique()); + tableIndex.setColumnList(entry.getValue()); + tableIndices.add(tableIndex); + }); } catch (SQLException e) { throw new RuntimeException(e); } @@ -478,7 +524,7 @@ public List indexes(Connection connection, String databaseName, Stri * @return List */ public List functions(Connection connection, String databaseName, - String schemaName) { + String schemaName) { try (ResultSet resultSet = connection.getMetaData().getFunctions(databaseName, schemaName, null);) { return ResultSetUtils.toObjectList(resultSet, ai.chat2db.spi.model.Function.class); } catch (Exception e) { @@ -534,7 +580,7 @@ public String getDbVersion(Connection connection) { @Override public List execute(Command command) { - // 解析sql + // parse sql String type = Chat2DBContext.getConnectInfo().getDbType(); DbType dbType = JdbcUtils.parse2DruidDbType(type); // if ("SQLSERVER".equalsIgnoreCase(type)) { @@ -547,7 +593,7 @@ public List execute(Command command) { throw new BusinessException("dataSource.sqlAnalysisError"); } List result = new ArrayList<>(); - // 执行sql + // Execute SQL for (String originalSql : sqlList) { ExecuteResult executeResult = executeSQL(originalSql, dbType, command); result.add(executeResult); @@ -561,16 +607,16 @@ private ExecuteResult executeSQL(String originalSql, DbType dbType, Command para Integer offset = null; Integer count = null; String sqlType = SqlTypeEnum.UNKNOWN.getCode(); - // 解析sql + // parse sql String type = Chat2DBContext.getConnectInfo().getDbType(); boolean supportDruid = !DataSourceTypeEnum.MONGODB.getCode().equals(type); - // 解析sql分页 + // Parse sql pagination SQLStatement sqlStatement = null; if (supportDruid) { try { sqlStatement = SQLUtils.parseSingleStatement(originalSql, dbType); - } catch (ParserException e) { - log.warn("解析sql失败:{}", originalSql, e); + } catch (Exception e) { + log.warn("Failed to parse sql: {}", originalSql, e); } } @@ -662,7 +708,7 @@ private ExecuteResult execute(String sql, Integer offset, Integer count) { executeResult = SQLExecutor.getInstance().execute(sql, Chat2DBContext.getConnection(), true, offset, count, valueHandler); } catch (SQLException e) { - log.warn("执行sql:{}异常", sql, e); + log.warn("Execute sql: {} exception", sql, e); executeResult = ExecuteResult.builder() .sql(sql) .success(Boolean.FALSE) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/FileUtils.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/FileUtils.java index 0f04b99ca..18b62ade6 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/FileUtils.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/FileUtils.java @@ -14,7 +14,7 @@ public static T readJsonValue(Class loaderClass, String path, Class cl T value = null; try { value = mapper.readValue(loaderClass.getResourceAsStream(path), clazz); - // 使用obj中的数据 + // Use data in obj } catch (IOException e) { return null; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcJarUtils.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcJarUtils.java index 4b7f3ef23..8022c07d2 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcJarUtils.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcJarUtils.java @@ -133,7 +133,7 @@ public static String getFullPath(String jarPath) { return path; } - public static final String DOWNLOAD_URL_HOST = "https://oss.sqlgpt.cn/lib/"; + public static final String DOWNLOAD_URL_HOST = "https://cdn.chat2db-ai.com/lib/"; private static String getDownloadUrl(String jarPath) { return DOWNLOAD_URL_HOST+jarPath; } diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java index 36b7f8405..e73560202 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/JdbcUtils.java @@ -22,7 +22,7 @@ import org.springframework.lang.Nullable; /** - * jdbc工具类 + * jdbc tool class * * @author Jiaju Zhuang */ @@ -32,7 +32,7 @@ public class JdbcUtils { private static final long MAX_RESULT_SIZE = 256 * 1024; /** - * 获取德鲁伊的的数据库类型 + * Get the database type of Druid * * @param dbType * @return @@ -49,7 +49,7 @@ public static DbType parse2DruidDbType(String dbType) { } /** - * 解析字段的类型 + * Parse field type * * @param typeName * @param type @@ -131,12 +131,12 @@ private static int getTypeByTypeName(String typeName, int type) { } /** - * 测试数据库连接 + * Test database connection * - * @param url 数据库连接 - * @param userName 用户名 - * @param password 密码 - * @param dbType 数据库类型 + * @param url database connection + * @param userName username + * @param password password + * @param dbType database type * @return */ public static DataSourceConnect testConnect(String url, String host, String port, @@ -147,7 +147,7 @@ public static DataSourceConnect testConnect(String url, String host, String port .build(); Session session = null; Connection connection = null; - // 加载驱动 + // Load driver try { if (ssh.isUse()) { ssh.setRHost(host); @@ -155,13 +155,13 @@ public static DataSourceConnect testConnect(String url, String host, String port session = SSHManager.getSSHSession(ssh); url = url.replace(host, "127.0.0.1").replace(port, ssh.getLocalPort()); } - // 创建连接 + // Create connection connection = IDriverManager.getConnection(url, userName, password, driverConfig, properties); } catch (Exception e) { log.error("connection fail:", e); dataSourceConnect.setSuccess(Boolean.FALSE); - // 获取最后一个异常的信息给前端 + // Get the last exception information to the front end Throwable t = e; while (t.getCause() != null) { t = t.getCause(); diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/ResultSetUtils.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/ResultSetUtils.java index aef380919..c308d3555 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/ResultSetUtils.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/ResultSetUtils.java @@ -23,7 +23,7 @@ public class ResultSetUtils { - private static List getRsHeader(ResultSet rs) { + public static List getRsHeader(ResultSet rs) { try { ResultSetMetaData resultSetMetaData = rs.getMetaData(); int col = resultSetMetaData.getColumnCount(); diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/SqlUtils.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/SqlUtils.java index aa5e8e0c5..d5fbab10b 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/SqlUtils.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/util/SqlUtils.java @@ -56,10 +56,10 @@ public static void buildCanEditResult(String sql, DbType dbType, ExecuteResult e } if (item instanceof SelectExpressionItem) { SelectExpressionItem selectExpressionItem = (SelectExpressionItem) item; - // 如果表达式是一个函数 + // if the expression is a function if (selectExpressionItem.getExpression() instanceof Function) { Function function = (Function) selectExpressionItem.getExpression(); - // 检查函数是否为 "COUNT" + // Check if the function is "COUNT" if ("COUNT".equalsIgnoreCase(function.getName())) { executeResult.setCanEdit(false); return; @@ -119,7 +119,7 @@ public static List parse(String sql, DbType dbType) { List list = new ArrayList<>(); try { Statements statements = CCJSqlParserUtil.parseStatements(sql); - // 遍历每个语句 + // Iterate through each statement for (Statement stmt : statements.getStatements()) { list.add(stmt.toString()); } @@ -132,7 +132,7 @@ public static List parse(String sql, DbType dbType) { private static final String DEFAULT_VALUE = "CHAT2DB_UPDATE_TABLE_DATA_USER_FILLED_DEFAULT"; public static String getSqlValue(String value, String dataType) { - if (value == null) { + if (value == null || value == "") { return null; } if (DEFAULT_VALUE.equals(value)) { @@ -148,10 +148,10 @@ public static boolean hasPageLimit(String sql, DbType dbType) { if (statement instanceof Select) { Select selectStatement = (Select) statement; SelectBody selectBody = selectStatement.getSelectBody(); - // 检查常见的分页方法 + // Check out common pagination methods if (selectBody instanceof PlainSelect) { PlainSelect plainSelect = (PlainSelect) selectBody; - // 检查 LIMIT + // CHECK LIMIT if (plainSelect.getLimit() != null || plainSelect.getOffset() != null || plainSelect.getTop() != null || plainSelect.getFetch() != null) { return true; } diff --git a/chat2db-server/lombok.config b/chat2db-server/lombok.config index f6394b21c..e0b476bcb 100644 --- a/chat2db-server/lombok.config +++ b/chat2db-server/lombok.config @@ -1,4 +1,4 @@ -# 转换toString 调用上一层 +# Convert toString and call the previous layer lombok.toString.callSuper = CALL -# 全局配置 equalsAndHashCode 的 callSuper 属性为true +# Globally configure the callSuper attribute of equalsAndHashCode to true lombok.equalsAndHashCode.callSuper=call \ No newline at end of file diff --git a/chat2db-server/pom.xml b/chat2db-server/pom.xml index 16c693477..edaaec74f 100644 --- a/chat2db-server/pom.xml +++ b/chat2db-server/pom.xml @@ -1,7 +1,7 @@ - + org.springframework.boot spring-boot-starter-parent @@ -16,14 +16,14 @@ chat2db-server-parent - + 2.0.0-SNAPSHOT 17 17 17 UTF-8 UTF-8 - + true @@ -40,7 +40,7 @@ - + ai.chat2db chat2db-server-tools-base @@ -133,14 +133,14 @@ mapstruct-processor 1.5.5.Final - + org.projectlombok lombok-mapstruct-binding 0.2.0 - + com.h2database h2 @@ -176,13 +176,13 @@ 1.2.18 - + cn.dev33 sa-token-spring-boot3-starter 1.34.0 - + cn.dev33 sa-token-jwt @@ -207,7 +207,7 @@ 1.5.32 - + org.flywaydb flyway-core @@ -294,7 +294,7 @@ 5.5.13 - + org.apache.pdfbox pdfbox @@ -327,7 +327,7 @@ lombok provided - + org.projectlombok lombok-mapstruct-binding @@ -338,13 +338,13 @@ - + org.apache.maven.plugins maven-compiler-plugin 3.11.0 - + -Amapstruct.disableBuilders=true @@ -353,7 +353,7 @@ - + org.codehaus.mojo flatten-maven-plugin @@ -380,7 +380,7 @@ - + org.apache.maven.plugins maven-surefire-plugin diff --git a/docker/Dockerfile b/docker/Dockerfile index ff6fcddef..eb54ed74e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,12 +1,12 @@ -# 基于jdk17的镜像 +# Mirror based on jdk17 FROM openjdk:17 -# 定义进入容器时默认位置,接下来后续操作的工作位置 +# Define the default location when entering the container and the working location for subsequent operations. WORKDIR /app -# 将当前目录下的jar包复制到docker容器的/app 目录下 +# Copy the jar package in the current directory to the /app directory of the docker container ADD chat2db-server/chat2db-server-web-start/target/chat2db-server-web-start.jar chat2db-server-web-start.jar -# 将当前目录下的lib包复制到docker容器的/app/lib 目录下 +# Copy the lib package in the current directory to the /app/lib directory of the docker container # ADD chat2db-server/chat2db-server-web-start/target/lib lib -# 让当前容器暴露10824 +# Let the current container expose 10824 EXPOSE 10824 -# 运行jar包 +# Run Jar ENTRYPOINT ["java","-Dloader.path=lib","-Dspring.profiles.active=release","-jar","chat2db-server-web-start.jar"] diff --git a/docker/docker-build.sh b/docker/docker-build.sh index 3019033ea..80f4caef0 100644 --- a/docker/docker-build.sh +++ b/docker/docker-build.sh @@ -1,3 +1,3 @@ -# 先打包 出来 chat2db-server/chat2db-server-start/target/chat2db-server-start.jar -# 打包 +# First package it out chat2db-server/chat2db-server-start/target/chat2db-server-start.jar +# Packing docker build -t chat2db/chat2db:test -f docker/Dockerfile . \ No newline at end of file diff --git a/docker/test/docker-compose.yml b/docker/test/docker-compose.yml index 6c3818541..be08df3f3 100644 --- a/docker/test/docker-compose.yml +++ b/docker/test/docker-compose.yml @@ -1,6 +1,6 @@ version: '3' services: - # 连接地址:jdbc:mysql://localhost:3306 用户名:root 密码:ali_dbhub 端口:3306 默认数据库:ali_dbhub_test + # Connection address:jdbc:mysql://localhost:3306 username:root password:ali_dbhub port:3306 Default database:ali_dbhub_test mysql: image: mysql:latest restart: always @@ -11,7 +11,7 @@ services: TZ: Asia/Shanghai ports: - 3306:3306 - # 连接地址:jdbc:postgresql://localhost:5432/ali_dbhub_test, 用户名:ali_dbhub, 密码:ali_dbhub 端口:5432 默认数据库:ali_dbhub_test + # Connection address:jdbc:postgresql://localhost:5432/ali_dbhub_test, username:ali_dbhub, password:ali_dbhub port:5432 Default database:ali_dbhub_test postgres: image: postgres:12-alpine restart: always @@ -23,8 +23,8 @@ services: TZ: Asia/Shanghai ports: - 5432:5432 - # 连接地址:jdbc:oracle:thin:@localhost:1521:XE, 用户名:system, 密码:ali_dbhub - # 默认数据库XEPDB1 启动会快很多 + # Connection address:jdbc:oracle:thin:@localhost:1521:XE, username:system, password:ali_dbhub + # The default database XEPDB1 will start much faster oracle: image: gvenzl/oracle-xe:slim-faststart restart: always @@ -39,16 +39,16 @@ services: image: redis:7 container_name: redis7 restart: always - # 挂载映射,可以让数据或配置持久化 + # Mount mapping, which allows data or configuration to be persisted volumes: - #<本地配置文件>: + #<local configuration file>: - $PWD/redis/redis.conf:/etc/redis/redis. conf:ro - $PWD/redis/data:/data - $PWD/redis/logs:/logs # command: redis-server/etc/redis/redis.conf ports: - 6379:6379 - #服务名称 + #service name # jdbc:mariadb://localhost:3303 ? user=root&password=ali_dbhub mariadb: @@ -64,19 +64,19 @@ services: - "3304:3304" clickhouse-server: - # image:指定镜像,可以为镜像名称或镜像id,如果本地没有该镜像,compose会尝试pull该镜像 + # image:Specify the image, which can be the image name or image id. If the image does not exist locally, compose will try to pull the image. image: yandex/clickhouse-server - # container_name:指定容器名称,默认为 项目名称_服务名称_序号 的格式 + # container_name:Specify the container name, which defaults to the format of project name_service name_serial number container_name: clickhouse - # hostname:指定容器主机名 + # hostname:Specify container hostname hostname: clickhouse - # networks配置该容器连接的网络,指定到文件末尾定义的networks - # ports:暴露端口信息,格式为 宿主机端口:容器端口;仅指定容器端口时,宿主机会随机选择端口,类似于docker run -p + # networks:Configure the network the container is connected to, specifying the networks defined at the end of the file + # ports:Expose port information in the format of host port:container port; when only the container port is specified, the host will randomly select the port, similar to docker run -p ports: - "8123:8123" - "9000:9000" - "9004:9004" - # expose:暴露端口,但不映射到宿主机,所以外部无法访问该端口,仅能容器内部访问使用 + # expose:The port is exposed but not mapped to the host, so the port cannot be accessed from the outside and can only be accessed and used within the container. expose: - 9009 - # volumes:数据卷挂载路径设置,类似于docker run --volumn=hostdir:containerDir,也可指定文件权限 \ No newline at end of file + # volumes:Data volume mounting path setting, similar to docker run --volumn=hostdir:containerDir, file permissions can also be specified \ No newline at end of file diff --git a/docker/test/redis/redis.conf b/docker/test/redis/redis.conf index 67d0643ec..97a050099 100644 --- a/docker/test/redis/redis.conf +++ b/docker/test/redis/redis.conf @@ -1,22 +1,22 @@ -#开启远程可连接 +#Enable remote connection #bind 127.0.0.1 -#自定义密码 +#Custom password requirepass 12345678 -#指定 Redis 监听端口(默认:6379) +#Specify Redis listening port (default: 6379) port 6379 -#客户端闲置指定时长后关闭连接(单位:秒。0:关闭该功能) +#The client closes the connection after being idle for a specified period of time (unit: seconds. 0: close this function) timeout 0 -# 900s内如果至少一次写操作则执行bgsave进行RDB持久化操作 +# If there is at least one write operation within 900s, execute bgsave for RDB persistence operation save 900 1 -# 在300s内,如果至少有10个key进行了修改,则进行持久化操作 +# Within 300s, if at least 10 keys are modified, perform persistence operation save 300 10 -#在60s内,如果至少有10000个key进行了修改,则进行持久化操作 +#Within 60s, if at least 10,000 keys have been modified, the persistence operation will be performed. save 60 10000 -#是否压缩数据存储(默认:yes。Redis采用LZ 压缩,如果为了节省 CPU 时间,可以关闭该选项,但会导致数据库文件变的巨大) +#Whether to compress data storage (default: yes. Redis uses LZ compression. If you want to save CPU time, you can turn off this option, but it will cause the database file to become huge) rdbcompression yes -#指定本地数据文件名(默认:dump.rdb) +#Specify the local data file name (default: dump.rdb) dbfilename dump.rdb -#指定本地数据文件存放目录 -dir /data -#指定日志文件位置(如果是相对路径,redis会将日志存放到指定的dir目录下) +#Specify the local data file storage directory +dir/data +#Specify the log file location (if it is a relative path, redis will store the log in the specified dir directory) logfile "redis.log" diff --git a/document/git/git.sh b/document/git/git.sh index ad7d7c22c..483c59ed2 100644 --- a/document/git/git.sh +++ b/document/git/git.sh @@ -1,5 +1,5 @@ # https://www.zhangbj.com/p/1437.html -# -r 代表递归 +# -r represents recursion # git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch chat2db-client/static' --prune-empty --tag-name-filter cat -- --all git push origin developing --force diff --git a/script/local-client-build.sh b/script/local-client-build.sh index 536d04784..7c7027b79 100644 --- a/script/local-client-build.sh +++ b/script/local-client-build.sh @@ -11,24 +11,24 @@ rm -rf chat2db-client/static rm -rf chat2db-client/versions rm -rf chat2db-client/release -# 使用 mkdir 创建目录,并使用 -p 参数确保如果目录已存在不会报错 +# Use mkdir to create the directory, and use the -p parameter to ensure that no error is reported if the directory already exists mkdir -p "$JRE_TARGET_DIR" -# 使用 cp 命令复制 JAVA_HOME 目录内容到目标目录 -# -r 参数表示递归复制整个目录 +# Use the cp command to copy the contents of the JAVA_HOME directory to the target directory +# -r Parameter means recursively copy the entire directory cp -r "${JRE_DIR}/" "$JRE_TARGET_DIR" chmod -R 777 "$JRE_TARGET_DIR" -# 打包后端代码 +# Packaging backend code mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml mkdir -p chat2db-client/versions/99.0.${CURRENT_ID}/static echo -n 99.0.${CURRENT_ID} > chat2db-client/versions/version cp chat2db-server/chat2db-server-start/target/chat2db-server-start.jar chat2db-client/versions/99.0.${CURRENT_ID}/static/ -# 打包前端代码 +# Packaging front-end code cd chat2db-client yarn install yarn run build:web:desktop --app_port=10822 cp -r dist ./versions/99.0.${CURRENT_ID}/ -# 打包客户端 +# Packaged client yarn run build:main:prod -c.productName=Chat2DB-Test -c.extraMetadata.version=99.0.${CURRENT_ID} --mac --arm64