第一步版
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/mvnw text eol=lf
|
||||||
|
*.cmd text eol=crlf
|
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@ -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/
|
19
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
19
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# 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.
|
||||||
|
wrapperVersion=3.3.2
|
||||||
|
distributionType=only-script
|
||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.10/apache-maven-3.9.10-bin.zip
|
259
mvnw
vendored
Normal file
259
mvnw
vendored
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
#!/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.2
|
||||||
|
#
|
||||||
|
# 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:]'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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 <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||||
|
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.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${0##*/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
|
||||||
|
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
||||||
|
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||||
|
|
||||||
|
clean || :
|
||||||
|
exec_maven "$@"
|
149
mvnw.cmd
vendored
Normal file
149
mvnw.cmd
vendored
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<# : 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.2
|
||||||
|
@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) { "/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_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
||||||
|
if ($env:MAVEN_USER_HOME) {
|
||||||
|
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
||||||
|
}
|
||||||
|
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::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
|
||||||
|
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -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"
|
109
pom.xml
Normal file
109
pom.xml
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<?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>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>3.4.7</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>org</groupId>
|
||||||
|
<artifactId>Traceability</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>Traceability</name>
|
||||||
|
<description>Traceability</description>
|
||||||
|
<url/>
|
||||||
|
<licenses>
|
||||||
|
<license/>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer/>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection/>
|
||||||
|
<developerConnection/>
|
||||||
|
<tag/>
|
||||||
|
<url/>
|
||||||
|
</scm>
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mariadb.jdbc</groupId>
|
||||||
|
<artifactId>mariadb-java-client</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- lombok-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.38</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- mybatis-plus-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||||
|
<version>3.5.12</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.8.0</version> <!-- 或者选择最新的兼容版本 -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>17</source>
|
||||||
|
<target>17</target>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.38</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<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>
|
226
sql/create.sql
Normal file
226
sql/create.sql
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
create database traceabilityCode;
|
||||||
|
|
||||||
|
use traceabilityCode;
|
||||||
|
-- 用户表
|
||||||
|
CREATE TABLE users (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
user_account VARCHAR(255) NOT NULL COMMENT '用户账号',
|
||||||
|
username VARCHAR(50) UNIQUE NOT NULL COMMENT '用户名',
|
||||||
|
password VARCHAR(255) NOT NULL COMMENT '密码(加密)',
|
||||||
|
email VARCHAR(100) COMMENT '邮箱',
|
||||||
|
phone VARCHAR(20) COMMENT '手机号',
|
||||||
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-启用',
|
||||||
|
last_login_time DATETIME COMMENT '最后登录时间',
|
||||||
|
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
isDelete TINYINT DEFAULT 0 comment '逻辑删除'
|
||||||
|
);
|
||||||
|
-- 角色表(优化后)
|
||||||
|
CREATE TABLE roles (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
name VARCHAR(50) NOT NULL COMMENT '角色名称',
|
||||||
|
code VARCHAR(50) UNIQUE NOT NULL COMMENT '角色编码',
|
||||||
|
description TEXT COMMENT '角色描述',
|
||||||
|
permissions JSON COMMENT '角色权限配置,如:["user:read", "user:write", "product:manage"]',
|
||||||
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-启用',
|
||||||
|
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 用户角色关联表
|
||||||
|
CREATE TABLE user_roles (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
user_id BIGINT NOT NULL,
|
||||||
|
role_id BIGINT NOT NULL,
|
||||||
|
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE KEY uk_user_role (user_id, role_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 产品表
|
||||||
|
CREATE TABLE products (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
name VARCHAR(100) NOT NULL COMMENT '产品名称',
|
||||||
|
category_id BIGINT COMMENT '分类ID',
|
||||||
|
sku VARCHAR(50) UNIQUE COMMENT '产品编码',
|
||||||
|
status TINYINT DEFAULT 1 COMMENT '状态',
|
||||||
|
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 属性定义表(定义每种产品可能有的属性)
|
||||||
|
CREATE TABLE product_attributes (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
category_id BIGINT COMMENT '适用的产品分类',
|
||||||
|
name VARCHAR(50) NOT NULL COMMENT '属性名称',
|
||||||
|
code VARCHAR(50) NOT NULL COMMENT '属性编码',
|
||||||
|
data_type ENUM('text', 'number', 'date', 'select') COMMENT '数据类型',
|
||||||
|
is_required TINYINT DEFAULT 0 COMMENT '是否必填',
|
||||||
|
options JSON COMMENT '选项值(用于下拉选择)',
|
||||||
|
section ENUM('raw_material', 'production', 'storage', 'inspection') COMMENT '所属板块'
|
||||||
|
);
|
||||||
|
-- 产品属性值表(存储具体的属性值)
|
||||||
|
CREATE TABLE product_attribute_values (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
product_id BIGINT NOT NULL COMMENT '产品ID',
|
||||||
|
attribute_id BIGINT NOT NULL COMMENT '属性ID',
|
||||||
|
value TEXT COMMENT '属性值',
|
||||||
|
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
INDEX idx_product_attribute (product_id, attribute_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 直播管理表
|
||||||
|
CREATE TABLE live_streams (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
stream_name VARCHAR(100) NOT NULL COMMENT '流名称',
|
||||||
|
stream_key VARCHAR(255) UNIQUE NOT NULL COMMENT '流密钥',
|
||||||
|
push_url VARCHAR(500) COMMENT '推流地址',
|
||||||
|
play_url VARCHAR(500) COMMENT '播放地址',
|
||||||
|
platform VARCHAR(50) COMMENT '平台',
|
||||||
|
account_id BIGINT COMMENT '关联账号ID',
|
||||||
|
status TINYINT DEFAULT 0 COMMENT '状态:0-离线,1-在线',
|
||||||
|
quality JSON COMMENT '画质配置',
|
||||||
|
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 直播记录表
|
||||||
|
CREATE TABLE live_records (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
stream_id BIGINT NOT NULL,
|
||||||
|
start_time DATETIME NOT NULL COMMENT '开始时间',
|
||||||
|
end_time DATETIME COMMENT '结束时间',
|
||||||
|
duration INT COMMENT '直播时长(秒)',
|
||||||
|
viewer_count INT DEFAULT 0 COMMENT '观看人数',
|
||||||
|
peak_viewer INT DEFAULT 0 COMMENT '峰值观看人数',
|
||||||
|
status ENUM('live', 'ended', 'error') DEFAULT 'live',
|
||||||
|
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 素材分类表
|
||||||
|
CREATE TABLE material_categories (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
name VARCHAR(100) NOT NULL COMMENT '分类名称',
|
||||||
|
type ENUM('image', 'video', 'document', 'other') NOT NULL COMMENT '素材类型',
|
||||||
|
parent_id BIGINT DEFAULT 0 COMMENT '父分类ID',
|
||||||
|
sort_order INT DEFAULT 0,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 视频表
|
||||||
|
CREATE TABLE videos (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
title VARCHAR(200) NOT NULL COMMENT '视频标题',
|
||||||
|
description TEXT COMMENT '视频描述',
|
||||||
|
file_path VARCHAR(500) NOT NULL COMMENT '视频文件路径',
|
||||||
|
file_url VARCHAR(500) COMMENT '播放URL',
|
||||||
|
thumbnail VARCHAR(500) COMMENT '缩略图',
|
||||||
|
duration INT COMMENT '时长(秒)',
|
||||||
|
file_size BIGINT COMMENT '文件大小',
|
||||||
|
resolution VARCHAR(20) COMMENT '分辨率',
|
||||||
|
format VARCHAR(20) COMMENT '视频格式',
|
||||||
|
bitrate INT COMMENT '码率',
|
||||||
|
fps INT COMMENT '帧率',
|
||||||
|
category_id BIGINT COMMENT '分类ID',
|
||||||
|
tags JSON COMMENT '标签',
|
||||||
|
view_count INT DEFAULT 0 COMMENT '播放次数',
|
||||||
|
status TINYINT DEFAULT 1 COMMENT '状态:0-处理中,1-正常,2-失败',
|
||||||
|
user_id BIGINT COMMENT '上传用户',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 扫码记录表
|
||||||
|
CREATE TABLE qr_codes (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
name VARCHAR(100) NOT NULL COMMENT '二维码名称',
|
||||||
|
code VARCHAR(100) UNIQUE NOT NULL COMMENT '二维码标识',
|
||||||
|
content TEXT NOT NULL COMMENT '二维码内容',
|
||||||
|
type ENUM('url', 'text', 'product', 'live') NOT NULL COMMENT '类型',
|
||||||
|
related_id BIGINT COMMENT '关联对象ID',
|
||||||
|
qr_image VARCHAR(500) COMMENT '二维码图片',
|
||||||
|
expire_time DATETIME COMMENT '过期时间',
|
||||||
|
scan_limit INT DEFAULT 0 COMMENT '扫描次数限制,0为无限制',
|
||||||
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-启用',
|
||||||
|
user_id BIGINT COMMENT '创建用户',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 扫码统计表
|
||||||
|
CREATE TABLE qr_scan_statistics (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
qr_code_id BIGINT NOT NULL,
|
||||||
|
date DATE NOT NULL COMMENT '统计日期',
|
||||||
|
scan_count INT DEFAULT 0 COMMENT '扫描次数',
|
||||||
|
unique_scan_count INT DEFAULT 0 COMMENT '独立扫描次数',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
-- 操作日志表
|
||||||
|
CREATE TABLE operation_logs (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
user_id BIGINT COMMENT '操作用户ID',
|
||||||
|
username VARCHAR(50) COMMENT '用户名',
|
||||||
|
operation VARCHAR(100) NOT NULL COMMENT '操作类型',
|
||||||
|
method VARCHAR(10) COMMENT '请求方法',
|
||||||
|
path VARCHAR(200) COMMENT '请求路径',
|
||||||
|
ip_address VARCHAR(45) COMMENT 'IP地址',
|
||||||
|
user_agent TEXT COMMENT '用户代理',
|
||||||
|
request_params JSON COMMENT '请求参数',
|
||||||
|
response_data JSON COMMENT '响应数据',
|
||||||
|
execution_time INT COMMENT '执行时间(毫秒)',
|
||||||
|
status TINYINT DEFAULT 1 COMMENT '状态:0-失败,1-成功',
|
||||||
|
error_message TEXT COMMENT '错误信息',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
INDEX idx_user_time (user_id, created_at),
|
||||||
|
INDEX idx_operation_time (operation, created_at)
|
||||||
|
);
|
||||||
|
-- 溯源码生成表
|
||||||
|
CREATE TABLE traceability_codes (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
code VARCHAR(100) UNIQUE NOT NULL COMMENT '溯源码',
|
||||||
|
product_id BIGINT NOT NULL COMMENT '关联产品',
|
||||||
|
batch_no VARCHAR(50) COMMENT '批次号',
|
||||||
|
production_date DATE COMMENT '生产日期',
|
||||||
|
expire_date DATE COMMENT '过期日期',
|
||||||
|
status ENUM('active', 'used', 'expired') DEFAULT 'active',
|
||||||
|
scan_count INT DEFAULT 0 COMMENT '扫描次数',
|
||||||
|
last_scan_time DATETIME COMMENT '最后扫码时间',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 二维码表(修改后)
|
||||||
|
CREATE TABLE qr_codes (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
name VARCHAR(100) NOT NULL COMMENT '二维码名称',
|
||||||
|
code VARCHAR(100) UNIQUE NOT NULL COMMENT '二维码标识',
|
||||||
|
content TEXT NOT NULL COMMENT '二维码内容',
|
||||||
|
type ENUM('url', 'text', 'product', 'live') NOT NULL COMMENT '类型',
|
||||||
|
related_id BIGINT COMMENT '关联对象ID',
|
||||||
|
traceability_code_id BIGINT COMMENT '关联溯源码ID',
|
||||||
|
qr_image VARCHAR(500) COMMENT '二维码图片',
|
||||||
|
expire_time DATETIME COMMENT '过期时间',
|
||||||
|
scan_limit INT DEFAULT 0 COMMENT '扫描次数限制,0为无限制',
|
||||||
|
scan_count INT DEFAULT 0 COMMENT '总扫码次数',
|
||||||
|
unique_scan_count INT DEFAULT 0 COMMENT '独立用户扫码次数',
|
||||||
|
last_scan_time DATETIME COMMENT '最后扫码时间',
|
||||||
|
status TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-启用',
|
||||||
|
user_id BIGINT COMMENT '创建用户',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 扫码记录表
|
||||||
|
CREATE TABLE scan_records (
|
||||||
|
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
qr_code_id BIGINT NOT NULL COMMENT '二维码ID',
|
||||||
|
scan_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '扫码时间',
|
||||||
|
ip_address VARCHAR(45) COMMENT '扫码IP地址',
|
||||||
|
user_agent TEXT COMMENT '用户代理信息',
|
||||||
|
location JSON COMMENT 'GPS位置信息 {"lat": 39.9042, "lng": 116.4074, "address": "北京市朝阳区"}',
|
||||||
|
device_info JSON COMMENT '设备信息 {"os": "iOS", "browser": "Safari", "version": "14.0"}',
|
||||||
|
session_id VARCHAR(100) COMMENT '会话ID',
|
||||||
|
referrer VARCHAR(500) COMMENT '来源页面',
|
||||||
|
scan_source ENUM('wechat', 'alipay', 'browser', 'app') COMMENT '扫码来源',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
INDEX idx_qr_time (qr_code_id, scan_time),
|
||||||
|
INDEX idx_session (session_id),
|
||||||
|
INDEX idx_ip_time (ip_address, scan_time)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
15
src/main/java/org/traceability/TraceabilityApplication.java
Normal file
15
src/main/java/org/traceability/TraceabilityApplication.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package org.traceability;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("org.traceability.mapper")
|
||||||
|
public class TraceabilityApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(TraceabilityApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
42
src/main/java/org/traceability/common/BaseResponse.java
Normal file
42
src/main/java/org/traceability/common/BaseResponse.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package org.traceability.common;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "通用返回对象")
|
||||||
|
public class BaseResponse<T> implements Serializable {
|
||||||
|
|
||||||
|
@Schema(description = "状态码,例如:200 表示成功")
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
@Schema(description = "返回的数据内容")
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
@Schema(description = "提示消息")
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
@Schema(description = "错误描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public BaseResponse(int code, T data, String message, String description) {
|
||||||
|
this.code = code;
|
||||||
|
this.data = data;
|
||||||
|
this.message = message;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseResponse(int code, T data, String message) {
|
||||||
|
this(code, data, message, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseResponse(int code, T data) {
|
||||||
|
this(code, data, "", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseResponse(ErrorCode errorCode) {
|
||||||
|
this(errorCode.getCode(), null , errorCode.getMessage(), errorCode.getDescription());
|
||||||
|
}
|
||||||
|
}
|
49
src/main/java/org/traceability/common/ErrorCode.java
Normal file
49
src/main/java/org/traceability/common/ErrorCode.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package org.traceability.common;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
*/
|
||||||
|
public enum ErrorCode {
|
||||||
|
|
||||||
|
SUCCESS(0, "ok", ""),
|
||||||
|
PARAMS_ERROR(40000, "请求参数错误", ""),
|
||||||
|
NULL_ERROR(40001, "请求数据为空", ""),
|
||||||
|
NOT_LOGIN(40100, "未登录", ""),
|
||||||
|
NO_AUTH(40101, "无权限", ""),
|
||||||
|
NOT_FOUND_ERROR(40400,"请求数据不存在",""),
|
||||||
|
FORBIDDEN_ERROR(40300, "禁止访问",""),
|
||||||
|
SYSTEM_ERROR(50000, "系统内部异常", ""),
|
||||||
|
OPERATION_ERROR(50001, "操作失败", "");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态码
|
||||||
|
*/
|
||||||
|
private final int code;
|
||||||
|
/**
|
||||||
|
* 状态码信息
|
||||||
|
*/
|
||||||
|
private final String message;
|
||||||
|
/**
|
||||||
|
* 状态码的详细描述
|
||||||
|
*/
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
ErrorCode(int code, String message, String description) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
}
|
66
src/main/java/org/traceability/common/ResultUtils.java
Normal file
66
src/main/java/org/traceability/common/ResultUtils.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package org.traceability.common;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回工具类
|
||||||
|
*/
|
||||||
|
public class ResultUtils {
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> BaseResponse<T> success(T data) {
|
||||||
|
return new BaseResponse<>(0, data, "ok");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> BaseResponse<T> success(T data, String message) {
|
||||||
|
return new BaseResponse<>(0, data, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*
|
||||||
|
* @param errorCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BaseResponse error(ErrorCode errorCode) {
|
||||||
|
return new BaseResponse<>(errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*
|
||||||
|
* @param code
|
||||||
|
* @param message
|
||||||
|
* @param description
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BaseResponse error(int code, String message, String description) {
|
||||||
|
return new BaseResponse(code, null, message, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*
|
||||||
|
* @param errorCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BaseResponse error(ErrorCode errorCode, String message, String description) {
|
||||||
|
return new BaseResponse(errorCode.getCode(), null, message, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*
|
||||||
|
* @param errorCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BaseResponse error(ErrorCode errorCode, String description) {
|
||||||
|
return new BaseResponse(errorCode.getCode(), errorCode.getMessage(), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
src/main/java/org/traceability/config/CorsConfig.java
Normal file
28
src/main/java/org/traceability/config/CorsConfig.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package org.traceability.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局跨域配置
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
// 覆盖所有请求
|
||||||
|
registry.addMapping("/**")
|
||||||
|
// 允许发送 Cookie
|
||||||
|
.allowCredentials(true)
|
||||||
|
// 放行哪些域名(必须用 patterns,否则 * 会和 allowCredentials 冲突)
|
||||||
|
.allowedOriginPatterns("*")
|
||||||
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||||
|
.allowedHeaders("*")
|
||||||
|
.exposedHeaders("*");
|
||||||
|
}
|
||||||
|
}
|
25
src/main/java/org/traceability/config/SwaggerConfig.java
Normal file
25
src/main/java/org/traceability/config/SwaggerConfig.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package org.traceability.config;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import io.swagger.v3.oas.models.info.Contact;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 访问链接 http://localhost:7080/swagger-ui/index.html
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI customOpenAPI() {
|
||||||
|
return new OpenAPI()
|
||||||
|
.info(new Info()
|
||||||
|
.title("Traceability API")
|
||||||
|
.version("1.0.0")
|
||||||
|
.description("溯源码系统 API 文档")
|
||||||
|
.contact(new Contact()
|
||||||
|
.name("X&L")));
|
||||||
|
}
|
||||||
|
}
|
18
src/main/java/org/traceability/contant/CommonConstant.java
Normal file
18
src/main/java/org/traceability/contant/CommonConstant.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package org.traceability.contant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用常量
|
||||||
|
*/
|
||||||
|
public interface CommonConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 升序
|
||||||
|
*/
|
||||||
|
String SORT_ORDER_ASC = "ascend";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 降序
|
||||||
|
*/
|
||||||
|
String SORT_ORDER_DESC = " descend";
|
||||||
|
|
||||||
|
}
|
28
src/main/java/org/traceability/contant/RegexConstant.java
Normal file
28
src/main/java/org/traceability/contant/RegexConstant.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package org.traceability.contant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正则表达式常量
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public interface RegexConstant {
|
||||||
|
/**
|
||||||
|
* 手机号正则
|
||||||
|
*/
|
||||||
|
String PHONE_REGEX = "^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱正则
|
||||||
|
*/
|
||||||
|
String EMAIL_REGEX = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码正则。4~32位的字母、数字、下划线
|
||||||
|
*/
|
||||||
|
String PASSWORD_REGEX = "^\\w{4,32}$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 特殊字符校验
|
||||||
|
*/
|
||||||
|
String SPECAIL_REGEX = "[ `~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
|
||||||
|
}
|
14
src/main/java/org/traceability/contant/UserConstant.java
Normal file
14
src/main/java/org/traceability/contant/UserConstant.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package org.traceability.contant;
|
||||||
|
|
||||||
|
public interface UserConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 盐值
|
||||||
|
*/
|
||||||
|
String USER_SALT = "tsuk";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录态
|
||||||
|
*/
|
||||||
|
String USER_LOGIN_STATE = "trace_user";
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package org.traceability.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.traceability.common.BaseResponse;
|
||||||
|
import org.traceability.common.ErrorCode;
|
||||||
|
import org.traceability.common.ResultUtils;
|
||||||
|
import org.traceability.exception.BusinessException;
|
||||||
|
import org.traceability.model.domain.Roles;
|
||||||
|
import org.traceability.model.dto.role.RoleAddRequest;
|
||||||
|
import org.traceability.service.RolesService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Tag(name = "用户角色接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/roles")
|
||||||
|
public class RolesController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RolesService rolesService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加角色
|
||||||
|
* @param roleAddRequest 添加角色请求体
|
||||||
|
* @return 角色id
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
@Operation(summary = "添加角色")
|
||||||
|
public BaseResponse<Long> addRole(@RequestBody RoleAddRequest roleAddRequest) {
|
||||||
|
if (roleAddRequest == null) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前请求体为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
long role = rolesService.addRole(roleAddRequest);
|
||||||
|
return ResultUtils.success(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色
|
||||||
|
* @param code 角色编码
|
||||||
|
* @return 是否删除成功
|
||||||
|
*/
|
||||||
|
@GetMapping("/delete")
|
||||||
|
@Operation(summary = "删除角色")
|
||||||
|
public BaseResponse<Boolean> deleteRole(@RequestParam String code) {
|
||||||
|
boolean b = rolesService.delRole(code);
|
||||||
|
return ResultUtils.success(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/list")
|
||||||
|
public BaseResponse<List<Roles>> listRoles() {
|
||||||
|
List<Roles> list = rolesService.list();
|
||||||
|
return ResultUtils.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package org.traceability.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.traceability.common.BaseResponse;
|
||||||
|
import org.traceability.common.ErrorCode;
|
||||||
|
import org.traceability.common.ResultUtils;
|
||||||
|
import org.traceability.exception.BusinessException;
|
||||||
|
import org.traceability.model.domain.Users;
|
||||||
|
import org.traceability.model.dto.user.UserAddRequest;
|
||||||
|
import org.traceability.model.dto.user.UserLoginRequest;
|
||||||
|
import org.traceability.model.dto.user.UserUpdateRequest;
|
||||||
|
import org.traceability.service.UsersService;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
@Tag(name = "用户接口")
|
||||||
|
@Slf4j
|
||||||
|
public class UsersController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UsersService usersService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加用户
|
||||||
|
* @param userAddRequest 添加用户请求体
|
||||||
|
* @return 用户id
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
@Operation(summary = "添加用户")
|
||||||
|
public BaseResponse<Long> addUser(@RequestBody UserAddRequest userAddRequest) {
|
||||||
|
if (userAddRequest == null) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前请求体为空");
|
||||||
|
}
|
||||||
|
Long users = usersService.addUsers(userAddRequest);
|
||||||
|
return ResultUtils.success(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录
|
||||||
|
* @param userLoginRequest 登录请求体
|
||||||
|
* @param request 用户请求体
|
||||||
|
* @return 登录用户
|
||||||
|
*/
|
||||||
|
@PostMapping("/login")
|
||||||
|
@Operation(summary = "登录用户")
|
||||||
|
public BaseResponse<Users> userLogin (@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) {
|
||||||
|
if (userLoginRequest == null) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前请求体为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
String userAccount = userLoginRequest.getUserAccount();
|
||||||
|
String password = userLoginRequest.getPassword();
|
||||||
|
Users users = usersService.loginUser(userAccount, password, request);
|
||||||
|
return ResultUtils.success(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @PostMapping("/update")
|
||||||
|
// public BaseResponse<Users> updateUser (@RequestBody UserUpdateRequest updateRequest, HttpServletRequest) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package org.traceability.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.traceability.common.ErrorCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义异常类
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class BusinessException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常码
|
||||||
|
*/
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
public BusinessException(String message, int code, String description) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(ErrorCode errorCode) {
|
||||||
|
super(errorCode.getMessage());
|
||||||
|
this.code = errorCode.getCode();
|
||||||
|
this.description = errorCode.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(ErrorCode errorCode, String description) {
|
||||||
|
super(errorCode.getMessage());
|
||||||
|
this.code = errorCode.getCode();
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.traceability.exception;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
import org.traceability.common.BaseResponse;
|
||||||
|
import org.traceability.common.ErrorCode;
|
||||||
|
import org.traceability.common.ResultUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常处理器
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Slf4j
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(BusinessException.class)
|
||||||
|
public BaseResponse<?> businessExceptionHandler(BusinessException e) {
|
||||||
|
log.error("businessException: {}", e.getMessage(), e);
|
||||||
|
return ResultUtils.error(e.getCode(), e.getMessage(), e.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(RuntimeException.class)
|
||||||
|
public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
|
||||||
|
log.error("runtimeException", e);
|
||||||
|
return ResultUtils.error(ErrorCode.SYSTEM_ERROR, e.getMessage(), "");
|
||||||
|
}
|
||||||
|
}
|
44
src/main/java/org/traceability/exception/ThrowUtils.java
Normal file
44
src/main/java/org/traceability/exception/ThrowUtils.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package org.traceability.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import org.traceability.common.ErrorCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抛异常工具类
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class ThrowUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件成立则抛异常
|
||||||
|
*
|
||||||
|
* @param condition 条件
|
||||||
|
* @param runtimeException 运行时异常
|
||||||
|
*/
|
||||||
|
public static void throwIf(boolean condition, RuntimeException runtimeException) {
|
||||||
|
if (condition) {
|
||||||
|
throw runtimeException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件成立则抛异常
|
||||||
|
*
|
||||||
|
* @param condition 条件
|
||||||
|
* @param errorCode 自定义异常
|
||||||
|
*/
|
||||||
|
public static void throwIf(boolean condition, ErrorCode errorCode) {
|
||||||
|
throwIf(condition, new BusinessException(errorCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件成立则抛异常
|
||||||
|
*
|
||||||
|
* @param condition 条件
|
||||||
|
* @param errorCode 自定义异常
|
||||||
|
* @param message 报错信息
|
||||||
|
*/
|
||||||
|
public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
|
||||||
|
throwIf(condition, new BusinessException(errorCode, message));
|
||||||
|
}
|
||||||
|
}
|
17
src/main/java/org/traceability/mapper/RolesMapper.java
Normal file
17
src/main/java/org/traceability/mapper/RolesMapper.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package org.traceability.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.traceability.model.domain.Roles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface RolesMapper extends BaseMapper<Roles> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
17
src/main/java/org/traceability/mapper/UserRolesMapper.java
Normal file
17
src/main/java/org/traceability/mapper/UserRolesMapper.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package org.traceability.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.traceability.model.domain.UserRoles;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UserRolesMapper extends BaseMapper<UserRoles> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
17
src/main/java/org/traceability/mapper/UsersMapper.java
Normal file
17
src/main/java/org/traceability/mapper/UsersMapper.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package org.traceability.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.traceability.model.domain.Users;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UsersMapper extends BaseMapper<Users> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
65
src/main/java/org/traceability/model/domain/Roles.java
Normal file
65
src/main/java/org/traceability/model/domain/Roles.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package org.traceability.model.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName roles
|
||||||
|
*/
|
||||||
|
@TableName(value ="roles")
|
||||||
|
@Data
|
||||||
|
public class Roles implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色权限配置,如:["user:read", "user:write", "product:manage"]
|
||||||
|
*/
|
||||||
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
|
private List<String> permissions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态:0-禁用,1-启用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date updatedTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
41
src/main/java/org/traceability/model/domain/UserRoles.java
Normal file
41
src/main/java/org/traceability/model/domain/UserRoles.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package org.traceability.model.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName user_roles
|
||||||
|
*/
|
||||||
|
@TableName(value ="user_roles")
|
||||||
|
@Data
|
||||||
|
public class UserRoles implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
75
src/main/java/org/traceability/model/domain/Users.java
Normal file
75
src/main/java/org/traceability/model/domain/Users.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package org.traceability.model.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName xy
|
||||||
|
*/
|
||||||
|
@TableName(value ="users")
|
||||||
|
@Data
|
||||||
|
public class Users implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
private String userAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码(加密)
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态:0-禁用,1-启用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最后登录时间
|
||||||
|
*/
|
||||||
|
private Date lastLoginTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除
|
||||||
|
*/
|
||||||
|
@TableLogic
|
||||||
|
private Integer isdelete;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
32
src/main/java/org/traceability/model/dto/PageRequest.java
Normal file
32
src/main/java/org/traceability/model/dto/PageRequest.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package org.traceability.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.traceability.contant.CommonConstant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页请求
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PageRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页号
|
||||||
|
*/
|
||||||
|
private long current = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面大小
|
||||||
|
*/
|
||||||
|
private long pageSize = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序字段
|
||||||
|
*/
|
||||||
|
private String sortField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序顺序(默认升序)
|
||||||
|
*/
|
||||||
|
private String sortOrder = CommonConstant.SORT_ORDER_ASC;
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package org.traceability.model.dto.role;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RoleAddRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色权限配置,如:["user:read", "user:write", "product:manage"]
|
||||||
|
*/
|
||||||
|
private List<String> permissions;
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package org.traceability.model.dto.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserAddRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
private String userAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码(加密)
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户角色
|
||||||
|
*/
|
||||||
|
private String UserCode;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package org.traceability.model.dto.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserLoginRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
private String userAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码(加密)
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.traceability.model.dto.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserUpdateRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号
|
||||||
|
*/
|
||||||
|
private String userAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码(加密)
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
}
|
15
src/main/java/org/traceability/service/RolesService.java
Normal file
15
src/main/java/org/traceability/service/RolesService.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package org.traceability.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.traceability.model.domain.Roles;
|
||||||
|
import org.traceability.model.dto.role.RoleAddRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
public interface RolesService extends IService<Roles> {
|
||||||
|
|
||||||
|
long addRole(RoleAddRequest roleAddRequest);
|
||||||
|
|
||||||
|
boolean delRole(String code);
|
||||||
|
}
|
11
src/main/java/org/traceability/service/UserRolesService.java
Normal file
11
src/main/java/org/traceability/service/UserRolesService.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package org.traceability.service;
|
||||||
|
|
||||||
|
import org.traceability.model.domain.UserRoles;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
public interface UserRolesService extends IService<UserRoles> {
|
||||||
|
|
||||||
|
}
|
17
src/main/java/org/traceability/service/UsersService.java
Normal file
17
src/main/java/org/traceability/service/UsersService.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package org.traceability.service;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.traceability.model.domain.Users;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.traceability.model.dto.user.UserAddRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
public interface UsersService extends IService<Users> {
|
||||||
|
|
||||||
|
Long addUsers (UserAddRequest userAddRequest);
|
||||||
|
|
||||||
|
Users loginUser (String userAccount, String password, HttpServletRequest request);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package org.traceability.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.traceability.common.ErrorCode;
|
||||||
|
import org.traceability.exception.ThrowUtils;
|
||||||
|
import org.traceability.model.domain.Roles;
|
||||||
|
import org.traceability.model.dto.role.RoleAddRequest;
|
||||||
|
import org.traceability.service.RolesService;
|
||||||
|
import org.traceability.mapper.RolesMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.traceability.utils.RegexUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RolesServiceImpl extends ServiceImpl<RolesMapper, Roles>
|
||||||
|
implements RolesService{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long addRole(RoleAddRequest roleAddRequest) {
|
||||||
|
|
||||||
|
Roles roles = new Roles();
|
||||||
|
String code = roleAddRequest.getCode();
|
||||||
|
String name = roleAddRequest.getName();
|
||||||
|
String description = roleAddRequest.getDescription();
|
||||||
|
List<String> permissions = roleAddRequest.getPermissions();
|
||||||
|
boolean invalid = RegexUtils.isUserAccountInvalid(code);
|
||||||
|
boolean invalid1 = RegexUtils.isUserAccountInvalid(name);
|
||||||
|
boolean invalid2 = RegexUtils.isUserAccountInvalid(description);
|
||||||
|
// 权限列表验证 - 检查每个权限字符串是否符合规范
|
||||||
|
boolean invalid3 = permissions == null ||
|
||||||
|
permissions.isEmpty();
|
||||||
|
ThrowUtils.throwIf(!invalid || !invalid1 || !invalid2 || invalid3,
|
||||||
|
ErrorCode.PARAMS_ERROR, "添加的权限不符合规范");
|
||||||
|
|
||||||
|
long count = this.count(Wrappers.<Roles>lambdaQuery()
|
||||||
|
.eq(Roles::getCode, code));
|
||||||
|
ThrowUtils.throwIf(count > 0, ErrorCode.PARAMS_ERROR, "当前角色code已重复");
|
||||||
|
BeanUtils.copyProperties(roleAddRequest, roles);
|
||||||
|
boolean save = this.save(roles);
|
||||||
|
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR, "添加角色失败");
|
||||||
|
|
||||||
|
return roles.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delRole(String code) {
|
||||||
|
boolean invalid = RegexUtils.isUserAccountInvalid(code);
|
||||||
|
ThrowUtils.throwIf(!invalid, ErrorCode.PARAMS_ERROR, "当前角色编码不符合规范");
|
||||||
|
Roles roles = this.getOne(Wrappers.<Roles>lambdaQuery()
|
||||||
|
.eq(Roles::getCode, code));
|
||||||
|
ThrowUtils.throwIf(roles == null, ErrorCode.PARAMS_ERROR, "当前角色编码不正确");
|
||||||
|
|
||||||
|
return this.removeById(roles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
package org.traceability.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.traceability.model.domain.UserRoles;
|
||||||
|
import org.traceability.service.UserRolesService;
|
||||||
|
import org.traceability.mapper.UserRolesMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UserRolesServiceImpl extends ServiceImpl<UserRolesMapper, UserRoles>
|
||||||
|
implements UserRolesService{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,118 @@
|
|||||||
|
package org.traceability.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.util.DigestUtils;
|
||||||
|
import org.traceability.common.ErrorCode;
|
||||||
|
import org.traceability.exception.BusinessException;
|
||||||
|
import org.traceability.exception.ThrowUtils;
|
||||||
|
import org.traceability.model.domain.Roles;
|
||||||
|
import org.traceability.model.domain.UserRoles;
|
||||||
|
import org.traceability.model.domain.Users;
|
||||||
|
import org.traceability.model.dto.user.UserAddRequest;
|
||||||
|
import org.traceability.service.RolesService;
|
||||||
|
import org.traceability.service.UserRolesService;
|
||||||
|
import org.traceability.service.UsersService;
|
||||||
|
import org.traceability.mapper.UsersMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.traceability.utils.RegexUtils;
|
||||||
|
|
||||||
|
import static org.traceability.contant.UserConstant.USER_LOGIN_STATE;
|
||||||
|
import static org.traceability.contant.UserConstant.USER_SALT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users>
|
||||||
|
implements UsersService{
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserRolesService userRolesService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RolesService rolesService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long addUsers(UserAddRequest userAddRequest) {
|
||||||
|
String userAccount = userAddRequest.getUserAccount();
|
||||||
|
String password = userAddRequest.getPassword();
|
||||||
|
String email = userAddRequest.getEmail();
|
||||||
|
String phone = userAddRequest.getPhone();
|
||||||
|
String userCode = userAddRequest.getUserCode();
|
||||||
|
|
||||||
|
Users users = new Users();
|
||||||
|
//校验账号信息
|
||||||
|
this.validUser(userAccount, password);
|
||||||
|
boolean invalid = RegexUtils.isUserAccountInvalid(userAccount);
|
||||||
|
ThrowUtils.throwIf(!invalid, ErrorCode.PARAMS_ERROR, "账号不符合规范");
|
||||||
|
boolean emailInvalid = RegexUtils.isEmailInvalid(email);
|
||||||
|
ThrowUtils.throwIf(!emailInvalid, ErrorCode.PARAMS_ERROR, "邮箱不符合规范");
|
||||||
|
boolean phoneInvalid = RegexUtils.isPhoneInvalid(phone);
|
||||||
|
ThrowUtils.throwIf(!phoneInvalid, ErrorCode.PARAMS_ERROR, "手机号不符合规范");
|
||||||
|
|
||||||
|
LambdaQueryWrapper<Users> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(Users::getUserAccount, userAccount);
|
||||||
|
long count = this.count(queryWrapper);
|
||||||
|
ThrowUtils.throwIf(count > 0 ,ErrorCode.PARAMS_ERROR, "当前账号重复");
|
||||||
|
|
||||||
|
//校验用户角色
|
||||||
|
Roles roles = rolesService.getOne(Wrappers.<Roles>lambdaQuery()
|
||||||
|
.eq(Roles::getCode, userCode));
|
||||||
|
ThrowUtils.throwIf(roles == null, ErrorCode.PARAMS_ERROR, "角色编码不正确");
|
||||||
|
//密码加密
|
||||||
|
DigestUtils.md5DigestAsHex((USER_SALT + password).getBytes());
|
||||||
|
BeanUtils.copyProperties(userAddRequest, users);
|
||||||
|
//存入数据库
|
||||||
|
boolean save = this.save(users);
|
||||||
|
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR, "存储用户失败");
|
||||||
|
|
||||||
|
//关联用户与角色
|
||||||
|
UserRoles userRoles = new UserRoles();
|
||||||
|
userRoles.setUserId(users.getId());
|
||||||
|
userRoles.setRoleId(roles.getId());
|
||||||
|
boolean save1 = userRolesService.save(userRoles);
|
||||||
|
ThrowUtils.throwIf(!save1, ErrorCode.OPERATION_ERROR, "关联用户角色失败");
|
||||||
|
|
||||||
|
return users.getId();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Users loginUser(String userAccount, String password, HttpServletRequest request) {
|
||||||
|
this.validUser(userAccount, password);
|
||||||
|
String newPassword = DigestUtils.md5DigestAsHex((USER_SALT + password).getBytes());
|
||||||
|
LambdaQueryWrapper<Users> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(Users::getUserAccount, userAccount);
|
||||||
|
wrapper.eq(Users::getPassword, newPassword);
|
||||||
|
Users users = this.getOne(wrapper);
|
||||||
|
ThrowUtils.throwIf(users == null, ErrorCode.PARAMS_ERROR, "账号或密码出错");
|
||||||
|
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
session.setAttribute(USER_LOGIN_STATE,users);
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void validUser(String userAccount, String password){
|
||||||
|
//校验用户名密码是否合规
|
||||||
|
if (userAccount.length() <= 4 || userAccount.length() >= 20) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户名长度应在4~20位之间");
|
||||||
|
}
|
||||||
|
if (password.length() <= 8 || password.length() >= 20) {
|
||||||
|
throw new BusinessException(ErrorCode.PARAMS_ERROR, "密码长度应在8~16位");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
50
src/main/java/org/traceability/utils/RegexUtils.java
Normal file
50
src/main/java/org/traceability/utils/RegexUtils.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package org.traceability.utils;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
|
||||||
|
import static org.traceability.contant.RegexConstant.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class RegexUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是无效手机格式
|
||||||
|
*
|
||||||
|
* @param phone 要校验的手机号
|
||||||
|
* @return true:符合,false:不符合
|
||||||
|
*/
|
||||||
|
public static boolean isPhoneInvalid(String phone) {
|
||||||
|
return mismatch(phone, PHONE_REGEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是无效邮箱格式
|
||||||
|
*
|
||||||
|
* @param email 要校验的邮箱
|
||||||
|
* @return true:符合,false:不符合
|
||||||
|
*/
|
||||||
|
public static boolean isEmailInvalid(String email) {
|
||||||
|
return mismatch(email, EMAIL_REGEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是无效账号
|
||||||
|
* @param userAccount 要检验的账号
|
||||||
|
* @return true:符合,false:不符合
|
||||||
|
*/
|
||||||
|
public static boolean isUserAccountInvalid(String userAccount) {
|
||||||
|
return mismatch(userAccount, SPECAIL_REGEX);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验是否不符合正则格式
|
||||||
|
private static boolean mismatch(String str, String regex) {
|
||||||
|
if (StringUtils.isBlank(str)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !str.matches(regex);
|
||||||
|
}
|
||||||
|
}
|
25
src/main/java/org/traceability/utils/SqlUtils.java
Normal file
25
src/main/java/org/traceability/utils/SqlUtils.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package org.traceability.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL 工具
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
public class SqlUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验排序字段是否合法(防止 SQL 注入)
|
||||||
|
*
|
||||||
|
* @param sortField
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean validSortField(String sortField) {
|
||||||
|
if (StringUtils.isBlank(sortField)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !StringUtils.containsAny(sortField, "=", "(", ")", " ");
|
||||||
|
}
|
||||||
|
}
|
45
src/main/resources/application.yml
Normal file
45
src/main/resources/application.yml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: Traceability
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mariadb://localhost:3308/traceabilitycode
|
||||||
|
username: root
|
||||||
|
password: tsukiyalo
|
||||||
|
driver-class-name: org.mariadb.jdbc.Driver
|
||||||
|
hikari:
|
||||||
|
connection-timeout: 20000
|
||||||
|
maximum-pool-size: 10
|
||||||
|
minimum-idle: 5
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: 7080
|
||||||
|
|
||||||
|
# SpringDoc 配置
|
||||||
|
springdoc:
|
||||||
|
swagger-ui:
|
||||||
|
enabled: true
|
||||||
|
path: /swagger-ui.html
|
||||||
|
config-url: /v3/api-docs/swagger-config
|
||||||
|
url: /v3/api-docs
|
||||||
|
api-docs:
|
||||||
|
enabled: true
|
||||||
|
path: /v3/api-docs
|
||||||
|
|
||||||
|
mybatis-plus:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
global-config:
|
||||||
|
db-config:
|
||||||
|
logic-delete-field: isdelete
|
||||||
|
logic-delete-value: 1
|
||||||
|
logic-not-delete-value: 0
|
||||||
|
id-type: auto
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
org.springdoc: INFO
|
||||||
|
org.springframework.web: INFO
|
||||||
|
com.baomidou.mybatisplus: DEBUG
|
||||||
|
org.traceability: DEBUG
|
||||||
|
root: INFO
|
24
src/main/resources/mapper/RolesMapper.xml
Normal file
24
src/main/resources/mapper/RolesMapper.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.traceability.mapper.RolesMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="org.traceability.model.domain.Roles">
|
||||||
|
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="code" column="code" jdbcType="VARCHAR"/>
|
||||||
|
<result property="description" column="description" jdbcType="VARCHAR"/>
|
||||||
|
<result property="permissions" column="permissions"
|
||||||
|
typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
|
||||||
|
<result property="status" column="status" jdbcType="TINYINT"/>
|
||||||
|
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,name,code,
|
||||||
|
description,permissions,status,
|
||||||
|
created_time,updated_time
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
18
src/main/resources/mapper/UserRolesMapper.xml
Normal file
18
src/main/resources/mapper/UserRolesMapper.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.traceability.mapper.UserRolesMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="org.traceability.model.domain.UserRoles">
|
||||||
|
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="userId" column="user_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="roleId" column="role_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,user_id,role_id,
|
||||||
|
created_time
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
27
src/main/resources/mapper/UsersMapper.xml
Normal file
27
src/main/resources/mapper/UsersMapper.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.traceability.mapper.UsersMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="org.traceability.model.domain.Users">
|
||||||
|
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||||
|
<result property="userAccount" column="user_account" jdbcType="VARCHAR"/>
|
||||||
|
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||||
|
<result property="email" column="email" jdbcType="VARCHAR"/>
|
||||||
|
<result property="phone" column="phone" jdbcType="VARCHAR"/>
|
||||||
|
<result property="status" column="status" jdbcType="TINYINT"/>
|
||||||
|
<result property="lastLoginTime" column="last_login_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="isdelete" column="isDelete" jdbcType="TINYINT"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,username,user_account,password,
|
||||||
|
email,phone,avatar,
|
||||||
|
status,last_login_time,created_time,
|
||||||
|
update_time,isDelete
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
@ -0,0 +1,13 @@
|
|||||||
|
package org.traceability;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class TraceabilityApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user