diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..bb58b3c --- /dev/null +++ b/.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.10.0/apache-maven-3.10.0-bin.zip diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..7dd057b --- /dev/null +++ b/compose.yaml @@ -0,0 +1,10 @@ +services: + elasticsearch: + image: 'docker.elastic.co/elasticsearch/elasticsearch:9.3.3' + environment: + - 'ELASTIC_PASSWORD=secret' + - 'discovery.type=single-node' + - 'xpack.security.enabled=false' + ports: + - '9200' + - '9300' diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/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/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/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/pom.xml b/pom.xml new file mode 100644 index 0000000..f994522 --- /dev/null +++ b/pom.xml @@ -0,0 +1,153 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + + com.crrc + crrc-mall + 0.0.1-SNAPSHOT + crrc-mall + crrc-mall + + + 17 + + + + + org.springframework.boot + spring-boot-starter-data-elasticsearch + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-elasticsearch + + + org.springframework.boot + spring-boot-starter-restclient + + + org.springframework.boot + spring-boot-starter-webmvc + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.6.0 + + + + + + + + + + + + com.mysql + mysql-connector-j + runtime + + + + org.projectlombok + lombok + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + compile + + compile + + + + + org.projectlombok + lombok + + + + + + default-testCompile + test-compile + + testCompile + + + + + org.projectlombok + lombok + + + + + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + diff --git a/src/main/java/com/crrc/crrcmall/CrrcMallApplication.java b/src/main/java/com/crrc/crrcmall/CrrcMallApplication.java new file mode 100644 index 0000000..eede8b1 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/CrrcMallApplication.java @@ -0,0 +1,13 @@ +package com.crrc.crrcmall; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CrrcMallApplication { + + public static void main(String[] args) { + SpringApplication.run(CrrcMallApplication.class, args); + } + +} diff --git a/src/main/java/com/crrc/crrcmall/common/CRRCConstant.java b/src/main/java/com/crrc/crrcmall/common/CRRCConstant.java new file mode 100644 index 0000000..f16b94b --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/common/CRRCConstant.java @@ -0,0 +1,8 @@ +package com.crrc.crrcmall.common; + +/** + * @Author:Jinyun.Wang + * @Date:2026/11/2 + **/ +public class CRRCConstant { +} diff --git a/src/main/java/com/crrc/crrcmall/common/enums/MatchTypeEnum.java b/src/main/java/com/crrc/crrcmall/common/enums/MatchTypeEnum.java new file mode 100644 index 0000000..269352e --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/common/enums/MatchTypeEnum.java @@ -0,0 +1,24 @@ +package com.crrc.crrcmall.common.enums; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * AI 匹配类型枚举 + */ +@Getter +@AllArgsConstructor +@Schema(description = "AI 匹配类型") +public enum MatchTypeEnum { + + @Schema(description = "语义匹配") + SEMANTIC("SEMANTIC", "语义匹配"), + + @Schema(description = "图片匹配") + IMAGE("IMAGE", "图片匹配"); + + private final String code; + private final String desc; +} + diff --git a/src/main/java/com/crrc/crrcmall/common/util/SignUtil.java b/src/main/java/com/crrc/crrcmall/common/util/SignUtil.java new file mode 100644 index 0000000..3ead969 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/common/util/SignUtil.java @@ -0,0 +1,52 @@ +package com.crrc.crrcmall.common.util; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +/** + * API 签名工具类 (HMAC-SHA256) + */ +public class SignUtil { + + private static final String HMAC_SHA256 = "HmacSHA256"; + + /** + * 生成签名 + * @param secret 密钥 + * @param content 待签名字符串 (appId + timestamp + nonce + method + uri) + * @return 十六进制签名字符串 + */ + public static String sign(String secret, String content) { + try { + Mac mac = Mac.getInstance(HMAC_SHA256); + SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), HMAC_SHA256); + mac.init(secretKeySpec); + byte[] hash = mac.doFinal(content.getBytes(StandardCharsets.UTF_8)); + + StringBuilder hexString = new StringBuilder(); + for (byte b : hash) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } catch (NoSuchAlgorithmException | InvalidKeyException e) { + throw new RuntimeException("Signature calculation failed", e); + } + } + + /** + * 校验签名 + * @param secret 密钥 + * @param content 待签名字符串 + * @param signature 客户端传来的签名 + * @return 是否匹配 + */ + public static boolean verify(String secret, String content, String signature) { + String calculatedSign = sign(secret, content); + return calculatedSign.equalsIgnoreCase(signature); + } +} diff --git a/src/main/java/com/crrc/crrcmall/config/ApiAuthInterceptor.java b/src/main/java/com/crrc/crrcmall/config/ApiAuthInterceptor.java new file mode 100644 index 0000000..2ed3f17 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/config/ApiAuthInterceptor.java @@ -0,0 +1,84 @@ +package com.crrc.crrcmall.config; + +import com.crrc.crrcmall.common.util.SignUtil; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +/** + * API 鉴权拦截器 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class ApiAuthInterceptor implements HandlerInterceptor { + + private final ApiAuthProperties authProperties; + + // 允许的时间误差(毫秒),默认 5 分钟 + private static final long TIME_TOLERANCE = 5 * 60 * 1000; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + // 1. 获取请求头 + String appId = request.getHeader("X-App-Id"); + String timestampStr = request.getHeader("X-Timestamp"); + String nonce = request.getHeader("X-Nonce"); + String signature = request.getHeader("X-Signature"); + + // 2. 基础参数校验 + if (appId == null || timestampStr == null || nonce == null || signature == null) { + sendErrorResponse(response, 401, "Missing required authentication headers"); + return false; + } + + // 3. 时间戳校验(防重放) + long currentTime = System.currentTimeMillis(); + long requestTime; + try { + requestTime = Long.parseLong(timestampStr); + } catch (NumberFormatException e) { + sendErrorResponse(response, 401, "Invalid timestamp format"); + return false; + } + + if (Math.abs(currentTime - requestTime) > TIME_TOLERANCE) { + log.warn("Request timestamp expired: {}", timestampStr); + sendErrorResponse(response, 401, "Request timestamp expired"); + return false; + } + + // 4. 获取 AppSecret + String appSecret = authProperties.getClients().get(appId); + if (appSecret == null) { + log.warn("Unknown AppId: {}", appId); + sendErrorResponse(response, 401, "Invalid AppId"); + return false; + } + + // 5. 签名校验 + // 签名内容: appId + timestamp + nonce + method + uri + String content = appId + timestampStr + nonce + request.getMethod() + request.getRequestURI(); + + if (!SignUtil.verify(appSecret, content, signature)) { + log.warn("Signature verification failed for AppId: {}", appId); + sendErrorResponse(response, 401, "Signature verification failed"); + return false; + } + + // 6. 校验通过 + return true; + } + + private void sendErrorResponse(HttpServletResponse response, int status, String message) throws IOException { + response.setStatus(status); + response.setContentType("application/json;charset=UTF-8"); + response.getWriter().write("{\"code\":" + status + ",\"message\":\"" + message + "\"}"); + } +} diff --git a/src/main/java/com/crrc/crrcmall/config/ApiAuthProperties.java b/src/main/java/com/crrc/crrcmall/config/ApiAuthProperties.java new file mode 100644 index 0000000..d815b84 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/config/ApiAuthProperties.java @@ -0,0 +1,23 @@ +package com.crrc.crrcmall.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * API 鉴权配置属性 + */ +@Data +@Component +@ConfigurationProperties(prefix = "mall.auth") +public class ApiAuthProperties { + + /** + * 客户端凭证映射: Key=AppId, Value=AppSecret + * 生产环境建议从数据库或配置中心动态加载 + */ + private Map clients = new HashMap<>(); +} diff --git a/src/main/java/com/crrc/crrcmall/config/WebConfig.java b/src/main/java/com/crrc/crrcmall/config/WebConfig.java new file mode 100644 index 0000000..e835c07 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/config/WebConfig.java @@ -0,0 +1,25 @@ +package com.crrc.crrcmall.config; + +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * Web MVC 配置 + */ +@Configuration +@RequiredArgsConstructor +public class WebConfig implements WebMvcConfigurer { + + private final ApiAuthInterceptor apiAuthInterceptor; + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(apiAuthInterceptor) + // 拦截所有 /api/v1/ 开头的请求 + .addPathPatterns("/api/v1/**") + // 排除 Swagger 和错误页面 + .excludePathPatterns("/swagger-ui/**", "/api-docs/**", "/error"); + } +} diff --git a/src/main/java/com/crrc/crrcmall/controller/SearchController.java b/src/main/java/com/crrc/crrcmall/controller/SearchController.java new file mode 100644 index 0000000..cfabe45 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/controller/SearchController.java @@ -0,0 +1,30 @@ +package com.crrc.crrcmall.controller; + +import com.crrc.crrcmall.dto.crrc.SearchGoodsRequestDto; +import com.crrc.crrcmall.service.SearchService; +import com.crrc.crrcmall.vo.crrc.GoodsSearchResultVo; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 商品搜索控制器 + */ +@Tag(name = "AI 搜索服务", description = "提供基于 AI 语义的商品搜索接口") +@RestController +@RequestMapping("/api/v1/search") +public class SearchController { + + @Autowired + private SearchService searchService; + + @Operation(summary = "文本语义搜索", description = "接收自然语言查询,返回 AI 增强后的商品列表") + @PostMapping("/text") + public GoodsSearchResultVo searchByText(@RequestBody SearchGoodsRequestDto request) { + return searchService.searchByText(request); + } +} diff --git a/src/main/java/com/crrc/crrcmall/dto/crrc/SearchGoodsRequestDto.java b/src/main/java/com/crrc/crrcmall/dto/crrc/SearchGoodsRequestDto.java new file mode 100644 index 0000000..a409e36 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/dto/crrc/SearchGoodsRequestDto.java @@ -0,0 +1,159 @@ +package com.crrc.crrcmall.dto.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * 商品搜索请求参数 DTO + * 请根据实际项目包路径修改 package 声明 + * @Author:Jinyun.Wang + * @Date:2026/11/2 + **/ +@Data +@Schema(description = "商品搜索请求参数") +public class SearchGoodsRequestDto implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "是否标准商品:0-非标品 1-标准商品 -1-全部", required = true) + private Integer isStandard; + + @Schema(description = "商品名称(搜索关键字)") + private String goodsName; + + @Schema(description = "搜索关键词(记录搜索日志用,配合 isRecordKey)") + private String searchWords; + + @Schema(description = "是否记录搜索关键词日志") + private Boolean isRecordKey; + + @Schema(description = "采购单位 id") + private String purchaserId; + + @Schema(description = "采购目录(品目)id 列表") + private List purchaserCatalogIds; + + @Schema(description = "标准目录 id 列表") + private List catalogIds; + + @Schema(description = "供应商 id 列表") + private List supplierIds; + + @Schema(description = "供应商名称") + private String supplierName; + + @Schema(description = "品牌 id 列表") + private List brandIds; + + @Schema(description = "商品属性筛选列表") + private List specList; + + @Schema(description = "最低价格(默认 0.0001)") + private Double priceMin; + + @Schema(description = "最高价格") + private Double priceMax; + + @Schema(description = "排序:0-综合升 1-综合降 10-价格升 11-价格降 20-销量升 21-销量降 30-上架时间升 31-上架时间降") + private Integer sortType; + + @Schema(description = "当前页码") + private Integer page; + + @Schema(description = "每页条数") + private Integer limit; + + @Schema(description = "地区 ID") + private String areaId; + + @Schema(description = "包含的商品标签列表") + private List includeTags; + + @Schema(description = "排除的商品标签列表") + private List excludeTags; + + @Schema(description = "包含的单个标签") + private String includeTag; + + @Schema(description = "供应商权重(影响综合排序)") + private Map supplierWeight; + + @Schema(description = "供货类型:1-协议供货 2-自营供货") + private String supplyType; + + @Schema(description = "是否只取今日发货商品") + private Boolean onlyDeliveryToday; + + @Schema(description = "域名(影响未登录价格展示配置)") + private String domain; + + @Schema(description = "是否京东自配送") + private Boolean withSelfDelivery; + + @Schema(description = "页面请求类型") + private String moduleType; + + @Schema(description = "传 1 时服务端按 moduleType 注入已配置的供应商") + private String supplierChooseWay; + + @Schema(description = "协议类型:01-电商 02-供应商 03-EPLUS") + private String protocolType; + + @Schema(description = "传 2 时按 69 码(upc)聚合") + private String goodsListAggByUpc; + + @Schema(description = "专区类型:0-集采专区 1-电商专区") + private String specialAreaType; + + @Schema(description = "69 码列表") + private List upcList; + + @Schema(description = "专区 id") + private Long specialAreaId; + + @Schema(description = "楼层商品 ID") + private Long floorGoodsId; + + @Schema(description = "物料编码(中车)") + private String material; + + @Schema(description = "协议 id 列表") + private List protocolIds; + + @Schema(description = "protocolIds 是否生效:1-生效 2-不生效") + private String protocolIdFilter; + + @Schema(description = "采购品目名称") + private String purchaserCatalogName; + + @Schema(description = "要排除的采购品目 id 列表") + private List filterPurchaserCatalogIds; + + @Schema(description = "要排除的协议 id 列表") + private List filterProtocolIds; + + @Schema(description = "自提点 id 列表") + private List postStationIds; + + @Schema(description = "协议商品上下架状态:0-未上架 1-已上架") + private Integer saleStatus; + + @Schema(description = "是否不使用缓存") + private Boolean noUseCache; + + @Schema(description = "是否需要拆词匹配") + private Boolean matchPhrase; + + @Schema(description = "传 1 强制走非聚合搜索") + private String rowShowSearch; + + @Schema(description = "招标年份列表") + private List tenderYear; + + +} + diff --git a/src/main/java/com/crrc/crrcmall/dto/crrc/SpecFilter.java b/src/main/java/com/crrc/crrcmall/dto/crrc/SpecFilter.java new file mode 100644 index 0000000..84b1228 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/dto/crrc/SpecFilter.java @@ -0,0 +1,26 @@ +package com.crrc.crrcmall.dto.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 商品属性筛选项内部类 + * @Author:Jinyun.Wang + * @Date:2026/11/2 + **/ +@Data +@Schema(description = "商品属性筛选项") +public class SpecFilter implements Serializable { + + @Schema(description = "属性 ID") + private String specId; + + @Schema(description = "属性类型") + private String specType; + + @Schema(description = "属性值 ID 列表") + private List valueIds; +} \ No newline at end of file diff --git a/src/main/java/com/crrc/crrcmall/service/SearchService.java b/src/main/java/com/crrc/crrcmall/service/SearchService.java new file mode 100644 index 0000000..0efb68e --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/service/SearchService.java @@ -0,0 +1,17 @@ +package com.crrc.crrcmall.service; + +import com.crrc.crrcmall.dto.crrc.SearchGoodsRequestDto; +import com.crrc.crrcmall.vo.crrc.GoodsSearchResultVo; + +/** + * 搜索服务接口 + */ +public interface SearchService { + + /** + * 文本语义搜索 + * @param request 搜索请求参数 + * @return 搜索结果 + */ + GoodsSearchResultVo searchByText(SearchGoodsRequestDto request); +} diff --git a/src/main/java/com/crrc/crrcmall/service/impl/SearchServiceImpl.java b/src/main/java/com/crrc/crrcmall/service/impl/SearchServiceImpl.java new file mode 100644 index 0000000..06d2a32 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/service/impl/SearchServiceImpl.java @@ -0,0 +1,30 @@ +package com.crrc.crrcmall.service.impl; + +import com.crrc.crrcmall.dto.crrc.SearchGoodsRequestDto; +import com.crrc.crrcmall.service.SearchService; +import com.crrc.crrcmall.vo.crrc.GoodsSearchResultVo; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; + +/** + * 搜索服务实现类 + */ +@Service +public class SearchServiceImpl implements SearchService { + + @Override + public GoodsSearchResultVo searchByText(SearchGoodsRequestDto request) { + // TODO: 1. 调用 AI 意图识别模块 + // TODO: 2. 调用 ES 混合检索 + // TODO: 3. 组装数据 + + // 目前返回空数据结构 + GoodsSearchResultVo result = new GoodsSearchResultVo(); + result.setGoodsList(new ArrayList<>()); + result.setBrandList(new ArrayList<>()); + result.setCatalogList(new ArrayList<>()); + + return result; + } +} diff --git a/src/main/java/com/crrc/crrcmall/vo/ai/AiSearchInfoVo.java b/src/main/java/com/crrc/crrcmall/vo/ai/AiSearchInfoVo.java new file mode 100644 index 0000000..2513f69 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/ai/AiSearchInfoVo.java @@ -0,0 +1,38 @@ +package com.crrc.crrcmall.vo.ai; + +/** + * @Author:Jinyun.Wang + * @Date:2026/11/2 + **/ +import com.crrc.crrcmall.common.enums.MatchTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * AI 搜索解析信息 VO + * 对应 JSON 中的 ai_search_info 对象 + */ +@Data +@Schema(description = "AI 搜索解析信息") +public class AiSearchInfoVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "用户原始输入词") + private String originalQuery; + + @Schema(description = "AI 识别意图(如:查找办公用品 - 防静电配件)") + private String intent; + + @Schema(description = "AI 纠错/建议(如:您是不是要找:防静电桌垫?)") + private String suggestion; + + @Schema(description = "AI 扩展同义词列表") + private List expandedTerms; + + @Schema(description = "匹配类型") + private MatchTypeEnum matchType; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/crrc/BrandVo.java b/src/main/java/com/crrc/crrcmall/vo/crrc/BrandVo.java new file mode 100644 index 0000000..1ff8553 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/crrc/BrandVo.java @@ -0,0 +1,29 @@ +package com.crrc.crrcmall.vo.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** + * 品牌信息 VO + * 请根据实际项目包路径修改 package 声明 + */ +@Data +@Schema(description = "品牌信息") +public class BrandVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "品牌ID") + private String brandId; + + @Schema(description = "品牌名称") + private String brandName; + + @Schema(description = "首字母") + private String firstLetter; + + @Schema(description = "Logo地址") + private String logoUrl; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/crrc/CatalogVo.java b/src/main/java/com/crrc/crrcmall/vo/crrc/CatalogVo.java new file mode 100644 index 0000000..3d02fde --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/crrc/CatalogVo.java @@ -0,0 +1,23 @@ +package com.crrc.crrcmall.vo.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** + * 标准目录信息 VO + * 请根据实际项目包路径修改 package 声明 + */ +@Data +@Schema(description = "标准目录信息") +public class CatalogVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "目录ID") + private String catalogId; + + @Schema(description = "目录名称") + private String catalogName; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/crrc/GoodsSearchResultVo.java b/src/main/java/com/crrc/crrcmall/vo/crrc/GoodsSearchResultVo.java new file mode 100644 index 0000000..b5ab7ff --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/crrc/GoodsSearchResultVo.java @@ -0,0 +1,49 @@ +package com.crrc.crrcmall.vo.crrc; + +import com.crrc.crrcmall.vo.ai.AiSearchInfoVo; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 商品搜索结果根对象 VO + * 请根据实际项目包路径修改 package 声明 + */ +@Data +@Schema(description = "商品搜索结果根对象") +public class GoodsSearchResultVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "地区ID") + private String areaId; + + @Schema(description = "地区名称") + private String areaName; + + @Schema(description = "品牌列表") + private List brandList; + + @Schema(description = "标准目录列表") + private List catalogList; + + @Schema(description = "商品列表") + private List goodsList; + + @Schema(description = "是否自营") + private Boolean isSelf; + + @Schema(description = "未登录是否显示价格") + private String isShowPriceUnlogin; + + @Schema(description = "采购目录列表") + private List purchaserCatalogList; + + @Schema(description = "规格筛选列表") + private List specList; + + @Schema(description = "ai规则说明") + private AiSearchInfoVo aiSearchInfo; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/crrc/GoodsVo.java b/src/main/java/com/crrc/crrcmall/vo/crrc/GoodsVo.java new file mode 100644 index 0000000..d72782c --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/crrc/GoodsVo.java @@ -0,0 +1,151 @@ +package com.crrc.crrcmall.vo.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.List; + +/** + * 商品列表项信息 VO + * 请根据实际项目包路径修改 package 声明 + */ +@Data +@Schema(description = "商品列表项信息") +public class GoodsVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "商品ID") + private String goodsId; + + @Schema(description = "商品名称") + private String goodsName; + + @Schema(description = "商品编码") + private String goodsCode; + + @Schema(description = "物料编码") + private String materialCode; + + @Schema(description = "商品提示语") + private String goodsTip; + + @Schema(description = "商品主图") + private String goodsImage; + + @Schema(description = "SKU图片") + private String skuImage; + + @Schema(description = "销售价格") + private BigDecimal goodsPrice; + + @Schema(description = "供应商ID") + private String supplierId; + + @Schema(description = "供应商名称") + private String supplierName; + + @Schema(description = "协议类型") + private String protocolType; + + @Schema(description = "采购人目录ID") + private String purchaserCatalogId; + + @Schema(description = "采购人目录名称") + private String purchaserCatalogName; + + @Schema(description = "采购人目录全称") + private String purchaserCatalogFullName; + + @Schema(description = "标准目录ID") + private String catalogId; + + @Schema(description = "标准目录名称") + private String catalogName; + + @Schema(description = "品牌ID") + private String brandId; + + @Schema(description = "规格列表(JSON字符串)") + private String specList; + + @Schema(description = "品牌名称") + private String brandName; + + @Schema(description = "协议ID") + private String protocolId; + + @Schema(description = "商品来源类型") + private Integer goodsSourceType; + + @Schema(description = "剩余数量") + private Integer remainAmount; + + @Schema(description = "产品Logo") + private String productLogo; + + @Schema(description = "商品项Logo") + private String productItemLogo; + + @Schema(description = "是否自营") + private String isSelfOperated; + + @Schema(description = "市场价") + private BigDecimal marketPrice; + + @Schema(description = "市场价链接") + private String marketPriceUrl; + + @Schema(description = "折扣率") + private Double goodsPriceDiscount; + + @Schema(description = "优惠显示文本") + private String goodsDiscount; + + @Schema(description = "是否团购") + private Boolean isGroup; + + @Schema(description = "团购价") + private Object groupPrice; + + @Schema(description = "成团数量") + private Object groupNum; + + @Schema(description = "有效时间") + private Integer effectTime; + + @Schema(description = "销量") + private Integer sales; + + @Schema(description = "上下架状态") + private Integer saleStatus; + + @Schema(description = "原价") + private BigDecimal originalPrice; + + @Schema(description = "专区角标Logo") + private String specialAreaCornerLogo; + + @Schema(description = "门户角标Logo") + private String portalCornerLogo; + + @Schema(description = "高亮商品名称(HTML)") + private String highlightGoodsName; + + @Schema(description = "是否有自提点") + private Boolean isPostStation; + + @Schema(description = "服务商ID") + private String serviceSupplyId; + + @Schema(description = "服务商SKU_ID") + private String serviceSupplySkuId; + + @Schema(description = "采购人标签列表") + private List purchaserTagList; + + @Schema(description = "AI 相关度得分 (0~1) 0.99 = 99%") + private Double aiRelevanceScore; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/crrc/PurchaserCatalogVo.java b/src/main/java/com/crrc/crrcmall/vo/crrc/PurchaserCatalogVo.java new file mode 100644 index 0000000..c3c5b89 --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/crrc/PurchaserCatalogVo.java @@ -0,0 +1,23 @@ +package com.crrc.crrcmall.vo.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** + * 采购人目录信息 VO + * 请根据实际项目包路径修改 package 声明 + */ +@Data +@Schema(description = "采购人目录信息") +public class PurchaserCatalogVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "采购人目录ID") + private String purchaserCatalogId; + + @Schema(description = "采购人目录名称") + private String purchaserCatalogName; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/crrc/SpecValueVo.java b/src/main/java/com/crrc/crrcmall/vo/crrc/SpecValueVo.java new file mode 100644 index 0000000..aadccea --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/crrc/SpecValueVo.java @@ -0,0 +1,26 @@ +package com.crrc.crrcmall.vo.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** + * 规格值信息 VO + * 请根据实际项目包路径修改 package 声明 + */ +@Data +@Schema(description = "规格值信息") +public class SpecValueVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "规格值ID") + private String valueId; + + @Schema(description = "规格值图片") + private String valueImg; + + @Schema(description = "规格值名称") + private String valueName; +} diff --git a/src/main/java/com/crrc/crrcmall/vo/crrc/SpecVo.java b/src/main/java/com/crrc/crrcmall/vo/crrc/SpecVo.java new file mode 100644 index 0000000..a1fcbeb --- /dev/null +++ b/src/main/java/com/crrc/crrcmall/vo/crrc/SpecVo.java @@ -0,0 +1,27 @@ +package com.crrc.crrcmall.vo.crrc; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 商品规格筛选信息 VO + * 请根据实际项目包路径修改 package 声明 + */ +@Data +@Schema(description = "商品规格筛选信息") +public class SpecVo implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "规格ID/Key") + private String specId; + + @Schema(description = "规格名称") + private String specName; + + @Schema(description = "规格值列表") + private List specValueList; +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..3cd6235 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,25 @@ +# 开发环境配置 +server: + port: 8080 + +spring: + elasticsearch: + uris: http://dev-es-server:9200 + username: elastic + password: dev_password + + datasource: + url: jdbc:mysql://localhost:3306/wjy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + + jpa: + hibernate: + ddl-auto: none + show-sql: false + +logging: + level: + root: INFO + com.crrc.crrcmall: INFO diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 0000000..3221d4b --- /dev/null +++ b/src/main/resources/application-local.yml @@ -0,0 +1,28 @@ +# 本地环境配置 +server: + port: 8080 + +spring: + elasticsearch: + uris: http://localhost:9200 + # username: elastic + # password: your_password + + datasource: + url: jdbc:mysql://localhost:3306/wjy?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + + jpa: + hibernate: + ddl-auto: update + show-sql: true + properties: + hibernate: + format_sql: true + +logging: + level: + root: INFO + com.crrc.crrcmall: DEBUG diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..878a51f --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,31 @@ +# 生产环境配置 +server: + port: 8080 + +spring: + elasticsearch: + uris: http://prod-es-server:9200 + username: elastic + password: prod_password + + datasource: + url: jdbc:mysql://prod-db-server:3306/crrc_mall?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai + username: prod_user + password: prod_password + driver-class-name: com.mysql.cj.jdbc.Driver + + jpa: + hibernate: + ddl-auto: none + show-sql: false + +logging: + level: + root: WARN + com.crrc.crrcmall: INFO + file: + name: logs/crrc-mall.log + logback: + rollingpolicy: + max-file-size: 10MB + max-history: 30 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..73aafcd --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,25 @@ +server: + port: 8080 + +spring: + application: + name: crrc-mall + profiles: + active: local # 仍然指向 local,因为 DB 配置在 application-local.yml 中 + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + +springdoc: + api-docs: + path: /api-docs + swagger-ui: + path: /swagger-ui.html + +# API 鉴权配置 (简化版:全局唯一凭证) +mall: + auth: + clients: + # 全局唯一的 AppId 和 Secret + # 部署生产环境时,请务必修改此 Secret 为高强度随机字符串 + crrc-client: crrc-secret-2026-key-99887766554433221100 diff --git a/src/test/java/com/crrc/crrcmall/CrrcMallApplicationTests.java b/src/test/java/com/crrc/crrcmall/CrrcMallApplicationTests.java new file mode 100644 index 0000000..8a0bc3c --- /dev/null +++ b/src/test/java/com/crrc/crrcmall/CrrcMallApplicationTests.java @@ -0,0 +1,13 @@ +package com.crrc.crrcmall; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class CrrcMallApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/test/java/com/crrc/crrcmall/spec/SecretTest.java b/src/test/java/com/crrc/crrcmall/spec/SecretTest.java new file mode 100644 index 0000000..15569db --- /dev/null +++ b/src/test/java/com/crrc/crrcmall/spec/SecretTest.java @@ -0,0 +1,84 @@ +package com.crrc.crrcmall.spec; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.time.Instant; +import java.util.UUID; + +/** + * @Author:Jinyun.Wang + * @Date:2026/11/2 + **/ +public class SecretTest { + + + // --- 配置区 (请替换为平台分配的实际凭证) --- + private static final String APP_ID = "crrc-client"; + private static final String APP_SECRET = "crrc-secret-2026-key-99887766554433221100"; + private static final String API_URL = "http://localhost:8080/api/v1/search/text"; + // ---------------------------------------- + + public static void main(String[] args) throws Exception { + // 1. 准备业务请求参数 (JSON 格式) + String jsonBody = "{\"isStandard\":1, \"goodsName\":\"车间防静电中性笔\", \"page\":1, \"limit\":20}"; + + // 2. 生成鉴权参数 + String timestamp = String.valueOf(Instant.now().toEpochMilli()); // 当前毫秒级时间戳 + String nonce = UUID.randomUUID().toString().replace("-", ""); // 随机字符串 + + // 计算签名 (规则: AppId + Timestamp + Nonce + Method + URI) + String signature = buildSignature(APP_ID, timestamp, nonce, "POST", "/api/v1/search/text", APP_SECRET); + + System.out.println("【调试信息】"); + System.out.println("Timestamp: " + timestamp); + System.out.println("Nonce: " + nonce); + System.out.println("Signature: " + signature); + System.out.println("------------------------------------------------"); + + // 3. 发起 HTTP 请求 + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(API_URL)) + .header("Content-Type", "application/json") + .header("X-App-Id", APP_ID) + .header("X-Timestamp", timestamp) + .header("X-Nonce", nonce) + .header("X-Signature", signature) + .POST(HttpRequest.BodyPublishers.ofString(jsonBody, StandardCharsets.UTF_8)) + .build(); + + // 4. 获取并打印响应 + HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); + + System.out.println(">>> HTTP Status Code: " + response.statusCode()); + System.out.println(">>> Response Body: \n" + response.body()); + } + + /** + * 内部方法:HMAC-SHA256 签名生成 + */ + private static String buildSignature(String appId, String timestamp, String nonce, String method, String uri, String secret) throws Exception { + // 拼接待签名字符串 + String signContent = appId + timestamp + nonce + method + uri; + + // 使用 HMAC-SHA256 算法 + Mac mac = Mac.getInstance("HmacSHA256"); + SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"); + mac.init(secretKeySpec); + + // 加密并转为十六进制字符串 + byte[] hash = mac.doFinal(signContent.getBytes(StandardCharsets.UTF_8)); + StringBuilder hexString = new StringBuilder(); + for (byte b : hash) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } +}