From 7a9ea1e888aa1305307c5f5b20a467822796949b Mon Sep 17 00:00:00 2001 From: xiaoqu Date: Thu, 3 Sep 2026 11:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20xiaoqu-agent-service?= =?UTF-8?q?=EF=BC=9AP1=20=E9=AA=A8=E6=9E=B6=EF=BC=88Spring=20Boot=203.5.16?= =?UTF-8?q?=20+=20Spring=20AI=201.1.8=20MCP=20Streamable=EF=BC=8C=E4=B8=89?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90=E8=BF=9E=E9=80=9A=EF=BC=8Ccodegen?= =?UTF-8?q?=20=E7=94=9F=E6=88=90=20m0/m2=20=E5=AE=9E=E4=BD=93=EF=BC=8Csys.?= =?UTF-8?q?ping/agent.count=20demo=20=E5=B7=A5=E5=85=B7=E5=AE=9E=E6=B5=8B?= =?UTF-8?q?=E8=B0=83=E9=80=9A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaoqu-agent-service/.gitignore | 6 + .../.mvn/wrapper/maven-wrapper.properties | 3 + xiaoqu-agent-service/README.md | 105 +++++ xiaoqu-agent-service/mvnw | 295 +++++++++++++ xiaoqu-agent-service/mvnw.cmd | 189 ++++++++ xiaoqu-agent-service/pom.xml | 117 +++++ .../me/iiv/agent/AgentServiceApplication.java | 16 + .../java/me/iiv/agent/admin/package-info.java | 4 + .../me/iiv/agent/common/package-info.java | 4 + .../iiv/agent/config/M0DataSourceConfig.java | 42 ++ .../iiv/agent/config/M1DataSourceConfig.java | 38 ++ .../iiv/agent/config/M2DataSourceConfig.java | 38 ++ .../me/iiv/agent/config/McpToolConfig.java | 23 + .../java/me/iiv/agent/entity/m0/Agent.java | 259 +++++++++++ .../entity/m0/AgentManageDistrictAuth.java | 81 ++++ .../me/iiv/agent/entity/m0/Authority.java | 79 ++++ .../java/me/iiv/agent/entity/m0/Properyt.java | 209 +++++++++ .../java/me/iiv/agent/entity/m0/User.java | 403 ++++++++++++++++++ .../agent/entity/m2/WarehouseAgentAuth.java | 81 ++++ .../m0/AgentManageDistrictAuthMapper.java | 16 + .../me/iiv/agent/mapper/m0/AgentMapper.java | 16 + .../iiv/agent/mapper/m0/AuthorityMapper.java | 16 + .../iiv/agent/mapper/m0/ProperytMapper.java | 16 + .../me/iiv/agent/mapper/m0/UserMapper.java | 16 + .../me/iiv/agent/mapper/m1/package-info.java | 4 + .../mapper/m2/WarehouseAgentAuthMapper.java | 16 + .../me/iiv/agent/mcp/tool/AgentTools.java | 32 ++ .../java/me/iiv/agent/mcp/tool/SysTools.java | 45 ++ .../me/iiv/agent/permission/package-info.java | 4 + .../me/iiv/agent/security/package-info.java | 4 + .../src/main/resources/application-dev.yml | 28 ++ .../src/main/resources/application.yml | 20 + .../me/iiv/agent/codegen/CodeGenerator.java | 69 +++ 33 files changed, 2294 insertions(+) create mode 100644 xiaoqu-agent-service/.gitignore create mode 100644 xiaoqu-agent-service/.mvn/wrapper/maven-wrapper.properties create mode 100644 xiaoqu-agent-service/README.md create mode 100755 xiaoqu-agent-service/mvnw create mode 100644 xiaoqu-agent-service/mvnw.cmd create mode 100644 xiaoqu-agent-service/pom.xml create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/AgentServiceApplication.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/admin/package-info.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/common/package-info.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M0DataSourceConfig.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M1DataSourceConfig.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M2DataSourceConfig.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/config/McpToolConfig.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Agent.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/AgentManageDistrictAuth.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Authority.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Properyt.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/User.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m2/WarehouseAgentAuth.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentManageDistrictAuthMapper.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentMapper.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AuthorityMapper.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/ProperytMapper.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/UserMapper.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m1/package-info.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m2/WarehouseAgentAuthMapper.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/AgentTools.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/SysTools.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/permission/package-info.java create mode 100644 xiaoqu-agent-service/src/main/java/me/iiv/agent/security/package-info.java create mode 100644 xiaoqu-agent-service/src/main/resources/application-dev.yml create mode 100644 xiaoqu-agent-service/src/main/resources/application.yml create mode 100644 xiaoqu-agent-service/src/test/java/me/iiv/agent/codegen/CodeGenerator.java diff --git a/xiaoqu-agent-service/.gitignore b/xiaoqu-agent-service/.gitignore new file mode 100644 index 0000000..458d8f9 --- /dev/null +++ b/xiaoqu-agent-service/.gitignore @@ -0,0 +1,6 @@ +target/ +*.log +.idea/ +*.iml +.vscode/ +.DS_Store diff --git a/xiaoqu-agent-service/.mvn/wrapper/maven-wrapper.properties b/xiaoqu-agent-service/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..216df05 --- /dev/null +++ b/xiaoqu-agent-service/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip diff --git a/xiaoqu-agent-service/README.md b/xiaoqu-agent-service/README.md new file mode 100644 index 0000000..c9f4dca --- /dev/null +++ b/xiaoqu-agent-service/README.md @@ -0,0 +1,105 @@ +# xiaoqu-agent-service + +面向 MCP 客户端(Kimi Code / Claude 等)的小趣业务数据服务:独立 Spring Boot 应用,只读查询现有三库(m0 权限库 / m1 商城库 / m2 业务库),以 MCP(Streamable HTTP)形式对外暴露工具。 + +设计方案见 `../xiaoqu-franchisee/doc/agent-mcp-service-design.md`。当前为 **P1 骨架**:工程初始化、版本组合验证、三数据源连通、codegen 跑通、demo 工具经 MCP 调通。鉴权 / 权限引擎 / 管理后台为 P2+,未实现。 + +## 技术栈与已验证版本组合 + +| 组件 | 版本 | +|---|---| +| JDK | 17(Temurin 17.0.20.1) | +| Spring Boot | 3.5.16 | +| Spring AI(MCP server webmvc) | 1.1.8 | +| MyBatis-Plus | 3.5.12(`mybatis-plus-spring-boot3-starter`) | +| MySQL 驱动 | mysql-connector-j(Boot 管理) | +| Redis | spring-boot-starter-data-redis(db5) | + +> ⚠️ 版本组合说明:Spring Boot 3.5.x + Spring AI 1.0.0 的 streamable 传输存在 NPE([spring-projects/spring-ai#6274](https://github.com/spring-projects/spring-ai/issues/6274)),本工程选用已修复的 **Spring AI 1.1.8**,2026-09-03 实测 STREAMABLE 握手(initialize → tools/list → tools/call)通过。 + +## 工程结构 + +``` +xiaoqu-agent-service/ +├── mvnw / .mvn/wrapper/ # Maven Wrapper(本机无全局 mvn) +├── pom.xml +├── src/main/java/me/iiv/agent/ +│ ├── AgentServiceApplication.java +│ ├── config/ # M0/M1/M2DataSourceConfig(独立 SqlSessionFactory + MapperScan)、McpToolConfig +│ ├── mcp/tool/ # @Tool 工具(SysTools: sys.ping;AgentTools: agent.count) +│ ├── security/ permission/ admin/ common/ # P2+ 占位包 +│ ├── entity/m0、m2 mapper/m0、m1、m2 # codegen 生成物(提交进仓库) +├── src/main/resources/ +│ ├── application.yml # MCP server: protocol=STREAMABLE, 端点 /mcp;默认 dev profile +│ └── application-dev.yml # 三数据源 + Redis,密码用环境变量占位符带默认值 +└── src/test/java/me/iiv/agent/codegen/CodeGenerator.java # run-once 代码生成器 +``` + +数据源分包约定:`entity/m0|m1|m2` 与 `mapper/m0|m1|m2` 一一对应各自的 `SqlSessionFactory`(`@MapperScan` + `sqlSessionFactoryRef`)。 + +## 启动 + +```bash +./mvnw clean package -DskipTests +java -jar target/xiaoqu-agent-service.jar +# 或 +./mvnw spring-boot:run +``` + +- 默认 `spring.profiles.active=dev`,端口 **8088**,MCP 端点 `http://localhost:8088/mcp`。 +- 数据库/Redis 密码默认值仅供本地 dev,可用环境变量覆盖:`M0_DB_PASSWORD` / `M1_DB_PASSWORD` / `M2_DB_PASSWORD` / `REDIS_PASSWORD`。 + +## MCP 工具 + +| 工具名 | 说明 | +|---|---| +| `sys.ping` | 服务自检:服务名、版本、当前时间、Redis PING | +| `agent.count` | 查 m0 库 `agent` 表 `soft_delete=0` 总数(真实查库) | + +工具名使用点号分隔(MCP 规范允许 `[a-zA-Z0-9._-]`,实测 Spring AI 1.1.8 与握手流程均正常)。若未来接入的客户端不接受点号,改为下划线即可。 + +## curl 验证(Streamable HTTP 握手) + +```bash +# 1) initialize(从响应头取 Mcp-Session-Id) +curl -i -X POST http://localhost:8088/mcp \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json, text/event-stream' \ + -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}' + +# 2) notifications/initialized(带 session id) +curl -X POST http://localhost:8088/mcp \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json, text/event-stream' \ + -H 'Mcp-Session-Id: <上一步的session-id>' \ + -d '{"jsonrpc":"2.0","method":"notifications/initialized"}' + +# 3) tools/list +curl -X POST http://localhost:8088/mcp \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json, text/event-stream' \ + -H 'Mcp-Session-Id: ' \ + -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' + +# 4) tools/call +curl -X POST http://localhost:8088/mcp \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json, text/event-stream' \ + -H 'Mcp-Session-Id: ' \ + -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"agent.count","arguments":{}}}' +``` + +响应为 SSE 帧(`event: message` / `data: {...}`)。 + +## codegen(run-once) + +表白名单:m0 `user, agent, authority, properyt, agent_manage_district_auth`;m2 `warehouse_agent_auth`(注:物业表真实表名为老系统遗留拼写 `properyt`)。生成物落在 `src/main/java` 对应分包并提交进仓库。 + +```bash +# 生成(依赖已下载后执行;连 dev 库) +./mvnw -q dependency:build-classpath -Dmdep.includeScope=test -Dmdep.outputFile=target/cp.txt +javac -cp "$(cat target/cp.txt)" -d target/codegen-classes src/test/java/me/iiv/agent/codegen/CodeGenerator.java +java -cp "target/codegen-classes:$(cat target/cp.txt)" me.iiv.agent.codegen.CodeGenerator +``` + +重新生成前请先删除目标 entity/mapper 文件,避免覆盖人工改动。 diff --git a/xiaoqu-agent-service/mvnw b/xiaoqu-agent-service/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/xiaoqu-agent-service/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/xiaoqu-agent-service/mvnw.cmd b/xiaoqu-agent-service/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/xiaoqu-agent-service/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/xiaoqu-agent-service/pom.xml b/xiaoqu-agent-service/pom.xml new file mode 100644 index 0000000..9c5af43 --- /dev/null +++ b/xiaoqu-agent-service/pom.xml @@ -0,0 +1,117 @@ + + + 4.0.0 + + + + org.springframework.boot + spring-boot-starter-parent + 3.5.16 + + + + me.iiv + xiaoqu-agent-service + 0.1.0-SNAPSHOT + xiaoqu-agent-service + 面向 MCP 客户端的小趣业务数据服务(只读查询现有三库) + + + 17 + 1.1.8 + 3.5.12 + + + + + + org.springframework.ai + spring-ai-bom + ${spring-ai.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.ai + spring-ai-starter-mcp-server-webmvc + + + + + com.baomidou + mybatis-plus-spring-boot3-starter + ${mybatis-plus.version} + + + com.mysql + mysql-connector-j + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.baomidou + mybatis-plus-generator + ${mybatis-plus.version} + test + + + org.freemarker + freemarker + test + + + + + xiaoqu-agent-service + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/AgentServiceApplication.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/AgentServiceApplication.java new file mode 100644 index 0000000..4999f27 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/AgentServiceApplication.java @@ -0,0 +1,16 @@ +package me.iiv.agent; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * xiaoqu-agent-service:面向 MCP 客户端(Kimi/Claude)的业务数据服务。 + * P1 骨架:三数据源连通 + MCP Streamable HTTP 端点 + demo 工具。 + */ +@SpringBootApplication +public class AgentServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(AgentServiceApplication.class, args); + } +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/admin/package-info.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/admin/package-info.java new file mode 100644 index 0000000..63080ce --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/admin/package-info.java @@ -0,0 +1,4 @@ +/** + * 管理后台REST,用户/token、作用域、审计(P4) + */ +package me.iiv.agent.admin; diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/common/package-info.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/common/package-info.java new file mode 100644 index 0000000..e5e1b0e --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/common/package-info.java @@ -0,0 +1,4 @@ +/** + * 审计AOP、限流、结果包装(P2+) + */ +package me.iiv.agent.common; diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M0DataSourceConfig.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M0DataSourceConfig.java new file mode 100644 index 0000000..438845c --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M0DataSourceConfig.java @@ -0,0 +1,42 @@ +package me.iiv.agent.config; + +import com.baomidou.mybatisplus.core.MybatisConfiguration; +import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +import javax.sql.DataSource; + +/** + * m0 数据源(权限库 xiaoqu_comples_d:user/agent/authority 等)。 + * 参考老项目 app-db.xml 的多 SqlSessionFactory 模式,JavaConfig 重写。 + */ +@Configuration +@MapperScan(basePackages = "me.iiv.agent.mapper.m0", sqlSessionFactoryRef = "m0SqlSessionFactory") +public class M0DataSourceConfig { + + @Primary + @Bean(name = "m0DataSource") + @ConfigurationProperties(prefix = "app.datasource.m0") + public DataSource m0DataSource() { + return DataSourceBuilder.create().type(HikariDataSource.class).build(); + } + + @Primary + @Bean(name = "m0SqlSessionFactory") + public SqlSessionFactory m0SqlSessionFactory(@Qualifier("m0DataSource") DataSource dataSource) throws Exception { + MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean(); + bean.setDataSource(dataSource); + MybatisConfiguration configuration = new MybatisConfiguration(); + configuration.setMapUnderscoreToCamelCase(true); + bean.setConfiguration(configuration); + return bean.getObject(); + } +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M1DataSourceConfig.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M1DataSourceConfig.java new file mode 100644 index 0000000..8acdc5a --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M1DataSourceConfig.java @@ -0,0 +1,38 @@ +package me.iiv.agent.config; + +import com.baomidou.mybatisplus.core.MybatisConfiguration; +import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.sql.DataSource; + +/** + * m1 数据源(商城库 xiaoqu_mall_d,按需启用)。 + */ +@Configuration +@MapperScan(basePackages = "me.iiv.agent.mapper.m1", sqlSessionFactoryRef = "m1SqlSessionFactory") +public class M1DataSourceConfig { + + @Bean(name = "m1DataSource") + @ConfigurationProperties(prefix = "app.datasource.m1") + public DataSource m1DataSource() { + return DataSourceBuilder.create().type(HikariDataSource.class).build(); + } + + @Bean(name = "m1SqlSessionFactory") + public SqlSessionFactory m1SqlSessionFactory(@Qualifier("m1DataSource") DataSource dataSource) throws Exception { + MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean(); + bean.setDataSource(dataSource); + MybatisConfiguration configuration = new MybatisConfiguration(); + configuration.setMapUnderscoreToCamelCase(true); + bean.setConfiguration(configuration); + return bean.getObject(); + } +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M2DataSourceConfig.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M2DataSourceConfig.java new file mode 100644 index 0000000..caba3e1 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/M2DataSourceConfig.java @@ -0,0 +1,38 @@ +package me.iiv.agent.config; + +import com.baomidou.mybatisplus.core.MybatisConfiguration; +import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.sql.DataSource; + +/** + * m2 数据源(业务库 xiaoqu_franchisee_d:warehouse_agent_auth 等)。 + */ +@Configuration +@MapperScan(basePackages = "me.iiv.agent.mapper.m2", sqlSessionFactoryRef = "m2SqlSessionFactory") +public class M2DataSourceConfig { + + @Bean(name = "m2DataSource") + @ConfigurationProperties(prefix = "app.datasource.m2") + public DataSource m2DataSource() { + return DataSourceBuilder.create().type(HikariDataSource.class).build(); + } + + @Bean(name = "m2SqlSessionFactory") + public SqlSessionFactory m2SqlSessionFactory(@Qualifier("m2DataSource") DataSource dataSource) throws Exception { + MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean(); + bean.setDataSource(dataSource); + MybatisConfiguration configuration = new MybatisConfiguration(); + configuration.setMapUnderscoreToCamelCase(true); + bean.setConfiguration(configuration); + return bean.getObject(); + } +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/McpToolConfig.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/McpToolConfig.java new file mode 100644 index 0000000..03d430e --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/config/McpToolConfig.java @@ -0,0 +1,23 @@ +package me.iiv.agent.config; + +import me.iiv.agent.mcp.tool.AgentTools; +import me.iiv.agent.mcp.tool.SysTools; +import org.springframework.ai.tool.ToolCallbackProvider; +import org.springframework.ai.tool.method.MethodToolCallbackProvider; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * MCP 工具注册:@Tool 注解方法 → ToolCallbackProvider, + * 由 spring-ai-starter-mcp-server-webmvc 自动暴露到 /mcp 端点。 + */ +@Configuration +public class McpToolConfig { + + @Bean + public ToolCallbackProvider xiaoquTools(SysTools sysTools, AgentTools agentTools) { + return MethodToolCallbackProvider.builder() + .toolObjects(sysTools, agentTools) + .build(); + } +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Agent.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Agent.java new file mode 100644 index 0000000..bc4b07d --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Agent.java @@ -0,0 +1,259 @@ +package me.iiv.agent.entity.m0; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 代理商表 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +@Getter +@Setter +@ToString +public class Agent implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 创建id + */ + private Long createId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改id + */ + private Long modifyId; + + /** + * 修改时间 + */ + private Date modifyTime; + + /** + * 数据状态 + */ + private Integer softDelete; + + /** + * 类型(0:区域主管1:代理2:物业,3....) + */ + private Integer type; + + /** + * 企业名称 + */ + private String name; + + /** + * 渠道编号(Z:总部;F:分公司;D:代理) + */ + private String channelNo; + + /** + * 上级id + */ + private Long supervisorId; + + /** + * 上级代理 + */ + private String supervisorName; + + /** + * 企业地址 + */ + private String address; + + /** + * 企业联系方式 + */ + private String phone; + + /** + * 省 + */ + private String province; + + /** + * 市 + */ + private String city; + + /** + * 县 + */ + private String countyseat; + + /** + * 备注信息 + */ + private String memo; + + /** + * 联系人 + */ + private String contact; + + /** + * 联系人邮箱 + */ + private String mail; + + /** + * 代理地区 + */ + private String agencyarea; + + /** + * 上级id + */ + private Long parentsId; + + /** + * 编号 + */ + private String serialnumber; + + /** + * 代理级别(0:总部;1:一级代理;2:二级代理) + */ + private Integer level; + + /** + * 户名 + */ + private String accountName; + + /** + * 账户号 + */ + private String accountNo; + + /** + * 开户行 + */ + private String accountBank; + + /** + * 纳税人识别号 + */ + private String identificationNumber; + + /** + * 纳税人类型(0:一般纳税人;1:小规模纳税人;2:个人) + */ + private Integer taxpayerType; + + /** + * 纳税人税点 + */ + private Double taxpayerPoint; + + /** + * 代理商承担手续费 + */ + private Double taxpayerServiceCharge; + + /** + * 订单出库验证0:不验证;1:验证 + */ + private Integer orderOutCheck; + + /** + * 开票名称 + */ + private String invoiceName; + + /** + * 身份编码 + */ + private String identifier; + + /** + * 简称 + */ + private String shortName; + + /** + * 金蝶客户编号 + */ + private String jindieCustid; + + /** + * 销售id + */ + private Long saleId; + + /** + * 销售名称 + */ + private String saleName; + + /** + * 销售组织 + */ + private String saleOrgId; + + /** + * 金蝶内码 + */ + private Long jindieInternalId; + + /** + * 组织内码 + */ + private String saleOrgInternalId; + + /** + * 客户分组 + */ + private String custerGroupNo; + + /** + * 金蝶供应商编号 + */ + private String supplierNo; + + /** + * 开票通讯地址 + */ + private String invoiceAddress; + + /** + * 开票联系电话 + */ + private String invoiceContact; + + /** + * 金蝶客户名称 + */ + private String jinideName; + + /** + * 最后开票时间 + */ + private Date lastInvoiceTime; + + /** + * 发票抬头类型(0:企业单位;1:个人|非企业) + */ + private Integer invoiceType; +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/AgentManageDistrictAuth.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/AgentManageDistrictAuth.java new file mode 100644 index 0000000..27e8871 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/AgentManageDistrictAuth.java @@ -0,0 +1,81 @@ +package me.iiv.agent.entity.m0; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 代管权限 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +@Getter +@Setter +@ToString +@TableName("agent_manage_district_auth") +public class AgentManageDistrictAuth implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 创建id + */ + private Long createId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改id + */ + private Long modifyId; + + /** + * 修改时间 + */ + private Date modifyTime; + + /** + * 数据状态 + */ + private Integer softDelete; + + /** + * 区域名称 + */ + private String districtName; + + /** + * 站点ID + */ + private Long districtId; + + /** + * 所属物业 + */ + private Long propertyId; + + /** + * 原代理商id + */ + private Long agentId; + + /** + * 管理代理商id + */ + private Long manageAgentId; +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Authority.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Authority.java new file mode 100644 index 0000000..e3b6d82 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Authority.java @@ -0,0 +1,79 @@ +package me.iiv.agent.entity.m0; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 权限组 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +@Getter +@Setter +@ToString +public class Authority implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 创建id + */ + private Long createId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改id + */ + private Long modifyId; + + /** + * 修改时间 + */ + private Date modifyTime; + + /** + * 数据状态 + */ + private Integer softDelete; + + /** + * 权限组名 + */ + private String name; + + /** + * 所属代理 + */ + private Long agentId; + + /** + * 备注 + */ + private String memo; + + /** + * 父关联 + */ + private Long parentId; + + /** + * 行权限 + */ + private Integer isagent; +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Properyt.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Properyt.java new file mode 100644 index 0000000..36a9581 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/Properyt.java @@ -0,0 +1,209 @@ +package me.iiv.agent.entity.m0; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 物业表 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +@Getter +@Setter +@ToString +public class Properyt implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 销售id + */ + private Long createId; + + /** + * 销售名称 + */ + private String createName; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改id + */ + private Long modifyId; + + /** + * 修改时间 + */ + private Date modifyTime; + + /** + * 数据状态 + */ + private Integer softDelete; + + /** + * 类型(0:区域主管1:代理2:物业,3....) + */ + private Integer type; + + /** + * 金蝶客户名称 + */ + private String jinideName; + + /** + * 企业名称 + */ + private String name; + + /** + * 代理商id + */ + private Long agentId; + + /** + * 代理名称 + */ + private String agentName; + + /** + * 企业地址 + */ + private String address; + + /** + * 企业联系方式 + */ + private String phone; + + /** + * 上级id + */ + private Long supervisorId; + + /** + * 物业编号 + */ + private String serialnumber; + + /** + * 省 + */ + private String province; + + /** + * 市 + */ + private String city; + + /** + * 县 + */ + private String countyseat; + + /** + * 备注信息 + */ + private String memo; + + /** + * 联系人 + */ + private String contact; + + /** + * 联系人邮箱 + */ + private String mail; + + /** + * 客户id自动生成 + */ + private String customerId; + + /** + * 上线站点数 + */ + private Integer districtOnCount; + + /** + * 上线设备数 + */ + private Integer hardOnCount; + + /** + * 物业账号数 + */ + private Integer userCount; + + /** + * 户名 + */ + private String accountName; + + /** + * 账号 + */ + private String accountNo; + + /** + * 开户行 + */ + private String accountBank; + + /** + * 纳税人识别号 + */ + private String identificationNumber; + + /** + * 开票名称 + */ + private String invoiceName; + + /** + * 金蝶客户编号 + */ + private String identifier; + + /** + * 金蝶内码 + */ + private Long jindieInternalId; + + /** + * 开票通讯地址 + */ + private String invoiceAddress; + + /** + * 开票联系电话 + */ + private String invoiceContact; + + /** + * 最后开票时间 + */ + private Date lastInvoiceTime; + + /** + * 发票抬头类型(0:企业单位;1:个人|非企业) + */ + private Integer invoiceType; +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/User.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/User.java new file mode 100644 index 0000000..394ba01 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m0/User.java @@ -0,0 +1,403 @@ +package me.iiv.agent.entity.m0; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 用户表 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +@Getter +@Setter +@ToString +public class User implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改id + */ + private Long modifyId; + + /** + * 修改时间 + */ + private Date modifyTime; + + /** + * 数据状态(0:启用:1:删除) + */ + private Integer softDelete; + + /** + * 创建id + */ + private Long createId; + + /** + * 手机号 + */ + private String mobile; + + /** + * 姓名 + */ + private String name; + + /** + * 管理员账号(例如:8534715) + */ + private String loginAccount; + + /** + * 密码 + */ + private String password; + + /** + * 所属公司名称 + */ + private String companyName; + + /** + * 极光推送id/个推 + */ + private String registrationId; + + /** + * 最后登录时间 + */ + private Date lastLoginTime; + + /** + * 角色类别 + */ + private Long roleId; + + /** + * 企业类别1:代理;2:物业 + */ + private Integer enterpriseType; + + /** + * 账号角色类型1:运维;2:保洁;3:富士康;4:老化;5:物业;6:代理 + */ + private Integer approle; + + /** + * 系统权限0:管理权限;1:普通权限 + */ + private Integer roleType; + + /** + * 如果是保洁存储当前设置的站点 + */ + private Long districtId; + + /** + * 代理ID + */ + private Long agentId; + + /** + * 物业ID + */ + private Long propertyId; + + /** + * 推送标记 + */ + private Long supervisorId; + + /** + * 考勤状态0:上班;1:下班;2:请假;3休息 + */ + private Integer workStatus; + + /** + * 员工编号 + */ + private String no; + + /** + * 邮箱 + */ + private String email; + + private String emailMask; + + /** + * 身份证号 + */ + private String idcard; + + /** + * 性别(男,女) + */ + private String sex; + + /** + * 是否推送rfid变化 + */ + private Long rfidFlag; + + /** + * 备注(职位信息等) + */ + private String memo; + + /** + * 日志开关 + */ + private Integer logFlag; + + /** + * 备用机开关 0:否;1:是 + */ + private Integer backHardFlag; + + /** + * 权限id + */ + private Long authorityId; + + /** + * 0:否;1:是 + */ + private Integer weixinBindFlag; + + /** + * 微信openid + */ + private String weixinOpenid; + + /** + * 0:否;1:是 + */ + private Integer authenticationFlag; + + private String weixinName; + + /** + * ota升级开关0:关;1:开 + */ + private Integer otaFlag; + + /** + * 生日 + */ + private String birthday; + + /** + * 聘用日期 + */ + private String employDate; + + /** + * 终止日期 + */ + private String terminationDate; + + /** + * 创建人 + */ + private String createName; + + /** + * 编辑人 + */ + private String modifyName; + + /** + * 物业权限id + */ + private Long propertyAuthorityId; + + /** + * 钉钉平台用户ID + */ + private String dingUserId; + + /** + * 工作中状态0:作业;1:转场;2:空闲;3:休息 + */ + private Integer workAtStatus; + + /** + * 年龄 + */ + private Integer age; + + /** + * 试用期保护0:未启用;1:启用 + */ + private Integer probationProtection; + + /** + * 备注 + */ + private String note; + + /** + * 上班时间 + */ + private String onTime; + + /** + * 下班时间 + */ + private String offTime; + + /** + * 出纸机权限 + */ + private Integer czjAuth; + + /** + * 空感权限 + */ + private Integer kgAuth; + + /** + * 信标权限 + */ + private Integer xbAuth; + + /** + * 电商价格权限0:不展示;1:展示; + */ + private Integer priceAuth; + + /** + * 空感设置权限0:关闭;1:打开; + */ + private Integer kongganAuth; + + /** + * 出纸机功能权限0:否;1:是 + */ + private Integer czjFunctionAuth; + + /** + * 空感功能权限0:否;1:是 + */ + private Integer kgFunctionAuth; + + /** + * 未清理已用卷数0:关闭;1:打开; + */ + private Integer noCleanUsePaperAuth; + + /** + * 产品清单操作功能0:关闭;1:打开; + */ + private Integer productOpAuth; + + /** + * 金蝶人员销售订单编号 + */ + private String jindieSalerid; + + /** + * 泡沫机APP显示0:关闭;1:打开; + */ + private Integer foamFunctionAuth; + + /** + * 金蝶内码 + */ + private String jindieInternalId; + + /** + * 主任部门id + */ + private Long deptId; + + /** + * 主任部门 + */ + private String deptName; + + /** + * 主任岗位 + */ + private Long postId; + + /** + * 主任岗位 + */ + private String postName; + + /** + * 工作流设置功能0:关闭;1:打开; + */ + private Integer flowAuth; + + /** + * xiaoqu-ai 用户ID + */ + private Long xiaoquAiUserId; + + /** + * 同步到 xiaoqu-ai 的时间 + */ + private Date xiaoquAiSyncedAt; + + /** + * 0待回填/1已解析/2歧义/3悬空;property_id非空→初始UPDATE=1 + */ + private Byte tenantResolveStatus; + + /** + * 0正常/1身份待核(冲突fail-closed锁B3人证比对;⊥tenant_resolve_status,不进PEP单路) + */ + private Byte idcardResolveStatus; + + /** + * AES-256-GCM(IV‖ct‖tag);canonical后加密;明文绝不落盘 + */ + private byte[] idcardEnc; + + /** + * keyed HMAC-SHA256(canonical idcard);等值/dedup/唯一 + */ + private byte[] idcardBidx; + + /** + * 存储预算掩码 前3后4(默认零解密展示) + */ + private String idcardMask; + + /** + * AES-256-GCM + */ + private byte[] mobileEnc; + + /** + * keyed HMAC-SHA256(canonical mobile);等值查找(非唯一) + */ + private byte[] mobileBidx; + + /** + * 展示掩码 前3后4 + */ + private String mobileMask; +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m2/WarehouseAgentAuth.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m2/WarehouseAgentAuth.java new file mode 100644 index 0000000..ec2dfc0 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/entity/m2/WarehouseAgentAuth.java @@ -0,0 +1,81 @@ +package me.iiv.agent.entity.m2; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 仓库代理权限 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +@Getter +@Setter +@ToString +@TableName("warehouse_agent_auth") +public class WarehouseAgentAuth implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 创建id + */ + private Long createId; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 创建人 + */ + private String createName; + + /** + * 修改id + */ + private Long modifyId; + + /** + * 修改人 + */ + private String modifyName; + + /** + * 修改时间 + */ + private Date modifyTime; + + /** + * 数据状态 + */ + private Integer softDelete; + + /** + * 负责人ID + */ + private Long userId; + + /** + * 管理公司ID + */ + private Long managerAgentId; + + /** + * 管理公司 + */ + private String managerAgentName; +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentManageDistrictAuthMapper.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentManageDistrictAuthMapper.java new file mode 100644 index 0000000..dd62953 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentManageDistrictAuthMapper.java @@ -0,0 +1,16 @@ +package me.iiv.agent.mapper.m0; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import me.iiv.agent.entity.m0.AgentManageDistrictAuth; + +/** + *

+ * 代管权限 Mapper 接口 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +public interface AgentManageDistrictAuthMapper extends BaseMapper { + +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentMapper.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentMapper.java new file mode 100644 index 0000000..5756068 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AgentMapper.java @@ -0,0 +1,16 @@ +package me.iiv.agent.mapper.m0; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import me.iiv.agent.entity.m0.Agent; + +/** + *

+ * 代理商表 Mapper 接口 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +public interface AgentMapper extends BaseMapper { + +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AuthorityMapper.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AuthorityMapper.java new file mode 100644 index 0000000..5af602d --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/AuthorityMapper.java @@ -0,0 +1,16 @@ +package me.iiv.agent.mapper.m0; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import me.iiv.agent.entity.m0.Authority; + +/** + *

+ * 权限组 Mapper 接口 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +public interface AuthorityMapper extends BaseMapper { + +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/ProperytMapper.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/ProperytMapper.java new file mode 100644 index 0000000..25ad35b --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/ProperytMapper.java @@ -0,0 +1,16 @@ +package me.iiv.agent.mapper.m0; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import me.iiv.agent.entity.m0.Properyt; + +/** + *

+ * 物业表 Mapper 接口 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +public interface ProperytMapper extends BaseMapper { + +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/UserMapper.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/UserMapper.java new file mode 100644 index 0000000..072759c --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m0/UserMapper.java @@ -0,0 +1,16 @@ +package me.iiv.agent.mapper.m0; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import me.iiv.agent.entity.m0.User; + +/** + *

+ * 用户表 Mapper 接口 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +public interface UserMapper extends BaseMapper { + +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m1/package-info.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m1/package-info.java new file mode 100644 index 0000000..140fc4e --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m1/package-info.java @@ -0,0 +1,4 @@ +/** + * m1商城库Mapper包,按需生成实体后启用 + */ +package me.iiv.agent.mapper.m1; diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m2/WarehouseAgentAuthMapper.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m2/WarehouseAgentAuthMapper.java new file mode 100644 index 0000000..7bc2628 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mapper/m2/WarehouseAgentAuthMapper.java @@ -0,0 +1,16 @@ +package me.iiv.agent.mapper.m2; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import me.iiv.agent.entity.m2.WarehouseAgentAuth; + +/** + *

+ * 仓库代理权限 Mapper 接口 + *

+ * + * @author codegen + * @since 2026-09-03 + */ +public interface WarehouseAgentAuthMapper extends BaseMapper { + +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/AgentTools.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/AgentTools.java new file mode 100644 index 0000000..f9c90e3 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/AgentTools.java @@ -0,0 +1,32 @@ +package me.iiv.agent.mcp.tool; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import me.iiv.agent.entity.m0.Agent; +import me.iiv.agent.mapper.m0.AgentMapper; +import org.springframework.ai.tool.annotation.Tool; +import org.springframework.stereotype.Component; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 代理商域 demo 工具:证明 m0 数据源连通(真实查库)。 + */ +@Component +public class AgentTools { + + final AgentMapper agentMapper; + + public AgentTools(AgentMapper agentMapper) { + this.agentMapper = agentMapper; + } + + @Tool(name = "agent.count", description = "统计 m0 库 agent 表中 soft_delete=0 的代理商总数") + public Map agentCount() { + Long count = agentMapper.selectCount( + new LambdaQueryWrapper().eq(Agent::getSoftDelete, 0)); + Map result = new LinkedHashMap<>(); + result.put("count", count); + return result; + } +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/SysTools.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/SysTools.java new file mode 100644 index 0000000..5e77aab --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/mcp/tool/SysTools.java @@ -0,0 +1,45 @@ +package me.iiv.agent.mcp.tool; + +import org.springframework.ai.tool.annotation.Tool; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 系统级 demo 工具:证明 MCP 链路连通。 + */ +@Component +public class SysTools { + + @Value("${spring.application.name}") + String appName; + + @Value("${spring.ai.mcp.server.version}") + String appVersion; + + final StringRedisTemplate redisTemplate; + + public SysTools(StringRedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + @Tool(name = "sys.ping", description = "服务自检:返回服务名、版本、当前时间与 Redis 连通性") + public Map ping() { + Map result = new LinkedHashMap<>(); + result.put("service", appName); + result.put("version", appVersion); + result.put("time", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); + try { + String pong = redisTemplate.getConnectionFactory().getConnection().ping(); + result.put("redis", pong); + } catch (Exception e) { + result.put("redis", "ERROR: " + e.getMessage()); + } + return result; + } +} diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/permission/package-info.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/permission/package-info.java new file mode 100644 index 0000000..7509614 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/permission/package-info.java @@ -0,0 +1,4 @@ +/** + * 行级数据权限引擎,移植getByIsAgent规则(P2) + */ +package me.iiv.agent.permission; diff --git a/xiaoqu-agent-service/src/main/java/me/iiv/agent/security/package-info.java b/xiaoqu-agent-service/src/main/java/me/iiv/agent/security/package-info.java new file mode 100644 index 0000000..29418f7 --- /dev/null +++ b/xiaoqu-agent-service/src/main/java/me/iiv/agent/security/package-info.java @@ -0,0 +1,4 @@ +/** + * ak鉴权Filter、身份上下文、scope校验(P2) + */ +package me.iiv.agent.security; diff --git a/xiaoqu-agent-service/src/main/resources/application-dev.yml b/xiaoqu-agent-service/src/main/resources/application-dev.yml new file mode 100644 index 0000000..0d0350c --- /dev/null +++ b/xiaoqu-agent-service/src/main/resources/application-dev.yml @@ -0,0 +1,28 @@ +# dev 环境:内网 192.168.1.181(沿用 xiaoqu-franchisee pom.xml dev profile) +# 密码走环境变量占位符,默认值仅供本地 dev 使用 +app: + datasource: + m0: # 权限库 xiaoqu_comples_d(user/agent/authority/propery/agent_manage_district_auth) + driver-class-name: com.mysql.cj.jdbc.Driver + jdbc-url: jdbc:mysql://192.168.1.181:3306/xiaoqu_comples_d?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true + username: root + password: ${M0_DB_PASSWORD:kaixinjiuhao} + m1: # 商城库 xiaoqu_mall_d(按需启用) + driver-class-name: com.mysql.cj.jdbc.Driver + jdbc-url: jdbc:mysql://192.168.1.181:3306/xiaoqu_mall_d?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true + username: root + password: ${M1_DB_PASSWORD:kaixinjiuhao} + m2: # 业务库 xiaoqu_franchisee_d(warehouse_agent_auth 等) + driver-class-name: com.mysql.cj.jdbc.Driver + jdbc-url: jdbc:mysql://192.168.1.181:3306/xiaoqu_franchisee_d?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true + username: root + password: ${M2_DB_PASSWORD:kaixinjiuhao} + +spring: + data: + redis: + host: 192.168.1.181 + port: 6379 + password: ${REDIS_PASSWORD:kaixinjiuhao} + database: 5 + timeout: 5s diff --git a/xiaoqu-agent-service/src/main/resources/application.yml b/xiaoqu-agent-service/src/main/resources/application.yml new file mode 100644 index 0000000..714f67f --- /dev/null +++ b/xiaoqu-agent-service/src/main/resources/application.yml @@ -0,0 +1,20 @@ +server: + port: 8088 + +spring: + application: + name: xiaoqu-agent-service + profiles: + active: dev + ai: + mcp: + server: + name: xiaoqu-agent-service + version: 0.1.0 + # Streamable HTTP 传输(Spring AI 1.1.8 已修复 Boot 3.5.x 下的 streamable NPE, + # 见 spring-projects/spring-ai#6274),默认端点 /mcp + protocol: STREAMABLE + +logging: + level: + me.iiv.agent: debug diff --git a/xiaoqu-agent-service/src/test/java/me/iiv/agent/codegen/CodeGenerator.java b/xiaoqu-agent-service/src/test/java/me/iiv/agent/codegen/CodeGenerator.java new file mode 100644 index 0000000..e3aa15a --- /dev/null +++ b/xiaoqu-agent-service/src/test/java/me/iiv/agent/codegen/CodeGenerator.java @@ -0,0 +1,69 @@ +package me.iiv.agent.codegen; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.generator.FastAutoGenerator; +import com.baomidou.mybatisplus.generator.config.OutputFile; +import com.baomidou.mybatisplus.generator.config.rules.DateType; +import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; + +import java.util.Arrays; + +/** + * Entity/Mapper 代码生成器(run-once,手动执行 main 方法,不进主启动流程)。 + * + * 表白名单制: + * m0(xiaoqu_comples_d): user, agent, authority, properyt, agent_manage_district_auth + * m2(xiaoqu_franchisee_d): warehouse_agent_auth + * + * 生成物直接落到 src/main/java 对应分包(entity.m0/mapper.m0 等),生成后提交进仓库。 + * + * 运行方式: + * ./mvnw -q test-compile org.codehaus.mojo:exec-maven-plugin:3.5.0:java \ + * -Dexec.mainClass=me.iiv.agent.codegen.CodeGenerator -Dexec.classpathScope=test + */ +public class CodeGenerator { + + private static final String BASE_URL = "jdbc:mysql://192.168.1.181:3306/"; + private static final String URL_PARAMS = "?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true"; + private static final String USERNAME = "root"; + private static final String PASSWORD = System.getenv().getOrDefault("CODEGEN_DB_PASSWORD", "kaixinjiuhao"); + private static final String OUTPUT_DIR = System.getProperty("user.dir") + "/src/main/java"; + + public static void main(String[] args) { + generate("xiaoqu_comples_d", "m0", + "user", "agent", "authority", "properyt", "agent_manage_district_auth"); + generate("xiaoqu_franchisee_d", "m2", + "warehouse_agent_auth"); + } + + private static void generate(String schema, String module, String... tables) { + FastAutoGenerator.create(BASE_URL + schema + URL_PARAMS, USERNAME, PASSWORD) + .globalConfig(builder -> builder + .author("codegen") + .outputDir(OUTPUT_DIR) + .dateType(DateType.ONLY_DATE) + .disableOpenDir()) + .packageConfig(builder -> builder + .parent("me.iiv.agent") + .entity("entity." + module) + .mapper("mapper." + module) + .pathInfo(java.util.Collections.singletonMap( + OutputFile.xml, System.getProperty("user.dir") + "/target/codegen-xml"))) + .strategyConfig(builder -> builder + .addInclude(Arrays.asList(tables)) + .entityBuilder() + .enableLombok() + .idType(IdType.AUTO) + .mapperBuilder() + .serviceBuilder() + .disableService() + .disableServiceImpl() + .controllerBuilder() + .disable()) + .templateConfig(builder -> builder + .disable(com.baomidou.mybatisplus.generator.config.TemplateType.XML)) + .templateEngine(new FreemarkerTemplateEngine()) + .execute(); + System.out.println("generated " + module + " from " + schema + ": " + Arrays.toString(tables)); + } +}