新增 xiaoqu-agent-service:P1 骨架(Spring Boot 3.5.16 + Spring AI 1.1.8 MCP Streamable,三数据源连通,codegen 生成 m0/m2 实体,sys.ping/agent.count demo 工具实测调通)

This commit is contained in:
xiaoqu
2026-09-03 11:18:51 +08:00
parent 61fb960435
commit 7a9ea1e888
33 changed files with 2294 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
target/
*.log
.idea/
*.iml
.vscode/
.DS_Store
@@ -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
+105
View File
@@ -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: <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: <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 文件,避免覆盖人工改动。
Vendored Executable
+295
View File
@@ -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-<version>,maven-mvnd-<version>-<platform>}/<hash>
[ -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 "$@"
+189
View File
@@ -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-<version>,maven-mvnd-<version>-<platform>}/<hash>
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"
+117
View File
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--
版本组合(2026-09-03 实测验证通过):
Spring Boot 3.5.16 + Spring AI 1.1.8 + MyBatis-Plus 3.5.12 + JDK 17
背景:Spring Boot 3.5.x + Spring AI 1.0.0 的 streamable MCP 传输存在 NPE
(spring-projects/spring-ai#6274),已在 Spring AI 1.0.1+ / 1.1.x 修复。
本工程选用 Spring AI 1.1.8(已修复版本),STREAMABLE 握手实测通过,详见 README.md。
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.16</version>
<relativePath/>
</parent>
<groupId>me.iiv</groupId>
<artifactId>xiaoqu-agent-service</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>xiaoqu-agent-service</name>
<description>面向 MCP 客户端的小趣业务数据服务(只读查询现有三库)</description>
<properties>
<java.version>17</java.version>
<spring-ai.version>1.1.8</spring-ai.version>
<mybatis-plus.version>3.5.12</mybatis-plus.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MCP Server(Streamable HTTP,端点 /mcp) -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
<!-- MyBatis-Plus(Spring Boot 3 starter) -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- Redis(db5,用户热缓存/字典,P1 仅做连通性自检) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- codegen(run-once,仅 test scope,不进主启动流程) -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>${mybatis-plus.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>xiaoqu-agent-service</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -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);
}
}
@@ -0,0 +1,4 @@
/**
* 管理后台REST,用户/token、作用域、审计(P4)
*/
package me.iiv.agent.admin;
@@ -0,0 +1,4 @@
/**
* 审计AOP、限流、结果包装(P2+)
*/
package me.iiv.agent.common;
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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;
/**
* <p>
* 代理商表
* </p>
*
* @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;
}
@@ -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;
/**
* <p>
* 代管权限
* </p>
*
* @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;
}
@@ -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;
/**
* <p>
* 权限组
* </p>
*
* @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;
}
@@ -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;
/**
* <p>
* 物业表
* </p>
*
* @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;
}
@@ -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;
/**
* <p>
* 用户表
* </p>
*
* @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;
}
@@ -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;
/**
* <p>
* 仓库代理权限
* </p>
*
* @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;
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m0;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m0.AgentManageDistrictAuth;
/**
* <p>
* 代管权限 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-03
*/
public interface AgentManageDistrictAuthMapper extends BaseMapper<AgentManageDistrictAuth> {
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m0;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m0.Agent;
/**
* <p>
* 代理商表 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-03
*/
public interface AgentMapper extends BaseMapper<Agent> {
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m0;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m0.Authority;
/**
* <p>
* 权限组 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-03
*/
public interface AuthorityMapper extends BaseMapper<Authority> {
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m0;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m0.Properyt;
/**
* <p>
* 物业表 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-03
*/
public interface ProperytMapper extends BaseMapper<Properyt> {
}
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m0;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m0.User;
/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-03
*/
public interface UserMapper extends BaseMapper<User> {
}
@@ -0,0 +1,4 @@
/**
* m1商城库Mapper包,按需生成实体后启用
*/
package me.iiv.agent.mapper.m1;
@@ -0,0 +1,16 @@
package me.iiv.agent.mapper.m2;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import me.iiv.agent.entity.m2.WarehouseAgentAuth;
/**
* <p>
* 仓库代理权限 Mapper 接口
* </p>
*
* @author codegen
* @since 2026-09-03
*/
public interface WarehouseAgentAuthMapper extends BaseMapper<WarehouseAgentAuth> {
}
@@ -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<String, Object> agentCount() {
Long count = agentMapper.selectCount(
new LambdaQueryWrapper<Agent>().eq(Agent::getSoftDelete, 0));
Map<String, Object> result = new LinkedHashMap<>();
result.put("count", count);
return result;
}
}
@@ -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<String, Object> ping() {
Map<String, Object> 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;
}
}
@@ -0,0 +1,4 @@
/**
* 行级数据权限引擎,移植getByIsAgent规则(P2)
*/
package me.iiv.agent.permission;
@@ -0,0 +1,4 @@
/**
* ak鉴权Filter、身份上下文、scope校验(P2)
*/
package me.iiv.agent.security;
@@ -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
@@ -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
@@ -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));
}
}