init
This commit is contained in:
commit
f8fb9b561c
|
@ -0,0 +1,2 @@
|
||||||
|
/mvnw text eol=lf
|
||||||
|
*.cmd text eol=crlf
|
|
@ -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/
|
|
@ -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
|
|
@ -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 "$@"
|
|
@ -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"
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?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.3.12</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.timeline</groupId>
|
||||||
|
<artifactId>timeline</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<!-- <module>timeline-common</module>-->
|
||||||
|
<!-- <module>timeline-user-service</module>-->
|
||||||
|
<module>timeline-file-service</module>
|
||||||
|
<module>timeline-component-common</module>
|
||||||
|
<module>timeline-story-service</module>
|
||||||
|
<!-- <module>timeline-gateway</module>-->
|
||||||
|
<!-- <module>timeline-registry</module>-->
|
||||||
|
<!-- <module>timeline-config-server</module>-->
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>21</java.version>
|
||||||
|
<spring-cloud.version>2023.0.5</spring-cloud.version> <!-- Spring Cloud 版本 -->
|
||||||
|
<spring-cloud-alibaba.version>2023.0.5.0</spring-cloud-alibaba.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Spring Cloud -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>${spring-cloud.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</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>
|
|
@ -0,0 +1,31 @@
|
||||||
|
#-------------------------------------------------------------------------------#
|
||||||
|
# Qodana analysis is configured by qodana.yaml file #
|
||||||
|
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
|
||||||
|
#-------------------------------------------------------------------------------#
|
||||||
|
version: "1.0"
|
||||||
|
|
||||||
|
#Specify inspection profile for code analysis
|
||||||
|
profile:
|
||||||
|
name: qodana.starter
|
||||||
|
|
||||||
|
#Enable inspections
|
||||||
|
#include:
|
||||||
|
# - name: <SomeEnabledInspectionId>
|
||||||
|
|
||||||
|
#Disable inspections
|
||||||
|
#exclude:
|
||||||
|
# - name: <SomeDisabledInspectionId>
|
||||||
|
# paths:
|
||||||
|
# - <path/where/not/run/inspection>
|
||||||
|
|
||||||
|
projectJDK: "21" #(Applied in CI/CD pipeline)
|
||||||
|
|
||||||
|
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
|
||||||
|
#bootstrap: sh ./prepare-qodana.sh
|
||||||
|
|
||||||
|
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
|
||||||
|
#plugins:
|
||||||
|
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
|
||||||
|
|
||||||
|
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
|
||||||
|
linter: jetbrains/qodana-jvm:2024.3
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.timeline</groupId>
|
||||||
|
<artifactId>timeline</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>timeline-component-common</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis</artifactId>
|
||||||
|
<version>3.5.17</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>repackage</id>
|
||||||
|
<phase>none</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
<configuration>
|
||||||
|
<addClasspath>false</addClasspath>
|
||||||
|
<mainClass />
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.timeline.aop;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class RequestLogAspect {
|
||||||
|
@Pointcut("execution(* com..controller.*.*(..))")
|
||||||
|
public void log() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Around("log()")
|
||||||
|
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
// 获取请求信息
|
||||||
|
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
HttpServletRequest request = requestAttributes.getRequest();
|
||||||
|
log.info("【请求开始】");
|
||||||
|
log.info("接受请求, URL : {}", request.getRequestURL());
|
||||||
|
log.info("HTTP Method : {}", request.getMethod());
|
||||||
|
log.info("IP Address : {}", request.getRemoteAddr());
|
||||||
|
log.info("Class Method: {}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
|
||||||
|
|
||||||
|
// 执行原方法
|
||||||
|
Object result = joinPoint.proceed();
|
||||||
|
|
||||||
|
// 输出返回值
|
||||||
|
log.info("响应结果 : {}", result);
|
||||||
|
log.info("结束请求, 请求耗时 : {} ms", System.currentTimeMillis() - startTime);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("请求发生异常", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.timeline.constants;
|
||||||
|
|
||||||
|
public class CommonConstants {
|
||||||
|
private static final int RELATION_USER_AND_STORY = 1;
|
||||||
|
public static final int RELATION_USER_AND_STORY_ITEM = 2;
|
||||||
|
public static final int RELATION_USER_AND_IMAGE = 3;
|
||||||
|
public static final int RELATION_STORY_AND_IMAGE = 4;
|
||||||
|
public static final int RELATION_STORY_ITEM_AND_IMAGE = 5;
|
||||||
|
public static final int RELATION_STORY_ITEM_AND_COVER = 6;
|
||||||
|
public static final int STORY_ITEM_IS_ROOT = 1;
|
||||||
|
public static final int STORY_ITEM_IS_NOT_ROOT = 0;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.timeline.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CommonRelationDTO {
|
||||||
|
private Integer id;
|
||||||
|
private String relaId;
|
||||||
|
private String subRelaId;
|
||||||
|
private Integer relationType;
|
||||||
|
private String userId;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
private Integer isDeleted;
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.timeline.enums;
|
||||||
|
|
||||||
|
public enum RelationTypeEnum {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.timeline.exception;
|
||||||
|
|
||||||
|
import com.timeline.response.ResponseEnum;
|
||||||
|
|
||||||
|
public class CustomException extends RuntimeException {
|
||||||
|
private final int code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
public CustomException(ResponseEnum responseEnum) {
|
||||||
|
this.code = responseEnum.getCode();
|
||||||
|
this.message = responseEnum.getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomException(ResponseEnum responseEnum, String detailMessage) {
|
||||||
|
this.code = responseEnum.getCode();
|
||||||
|
this.message = responseEnum.getMessage() + ": " + detailMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomException(int code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.timeline.handler;
|
||||||
|
|
||||||
|
import com.timeline.exception.CustomException;
|
||||||
|
import com.timeline.response.ResponseEntity;
|
||||||
|
import com.timeline.response.ResponseEnum;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(CustomException.class)
|
||||||
|
public ResponseEntity<String> handleCustomException(CustomException ex) {
|
||||||
|
return ResponseEntity.error(ex.getCode(), ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public ResponseEntity<String> handleGenericException(Exception ex) {
|
||||||
|
return ResponseEntity.error(ResponseEnum.INTERNAL_SERVER_ERROR.getCode(),
|
||||||
|
ResponseEnum.INTERNAL_SERVER_ERROR.getMessage() + ": " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.timeline.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ResponseEntity<T> {
|
||||||
|
private int code;
|
||||||
|
private String message;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static <T> ResponseEntity<T> success(T data) {
|
||||||
|
return new ResponseEntity<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ResponseEntity<T> error(int code, String message) {
|
||||||
|
return new ResponseEntity<>(code, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ResponseEntity<T> error(ResponseEnum responseEnum) {
|
||||||
|
return new ResponseEntity<>(responseEnum.getCode(), responseEnum.getMessage(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ResponseEntity<T> error(ResponseEnum responseEnum, String detailMessage) {
|
||||||
|
return new ResponseEntity<>(responseEnum.getCode(), responseEnum.getMessage() + ": " + detailMessage, null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.timeline.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum ResponseEnum {
|
||||||
|
// 成功
|
||||||
|
SUCCESS(200, "请求成功"),
|
||||||
|
|
||||||
|
// 客户端错误
|
||||||
|
BAD_REQUEST(400, "客户端错误"),
|
||||||
|
UNAUTHORIZED(401, "未授权访问"),
|
||||||
|
FORBIDDEN(403, "禁止访问"),
|
||||||
|
NOT_FOUND(404, "资源不存在"),
|
||||||
|
METHOD_NOT_ALLOWED(405, "方法不允许"),
|
||||||
|
REQUEST_TIMEOUT(408, "请求超时"),
|
||||||
|
CONFLICT(409, "操作冲突"),
|
||||||
|
UNSUPPORTED_MEDIA_TYPE(415, "不支持的媒体类型"),
|
||||||
|
TOO_MANY_REQUESTS(429, "请求过多,请稍后再试"),
|
||||||
|
|
||||||
|
// 服务端错误
|
||||||
|
INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
|
||||||
|
NOT_IMPLEMENTED(501, "功能未实现"),
|
||||||
|
BAD_GATEWAY(502, "网关错误"),
|
||||||
|
SERVICE_UNAVAILABLE(503, "服务不可用"),
|
||||||
|
GATEWAY_TIMEOUT(504, "网关超时");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String message;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.timeline.utils;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class IdUtils {
|
||||||
|
public static String randomUuid() {
|
||||||
|
return UUID.randomUUID().toString().replace("-", "");
|
||||||
|
}
|
||||||
|
public static String randomUuid(boolean dash) {
|
||||||
|
return dash ? UUID.randomUUID().toString() : UUID.randomUUID().toString().replace("-", "");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取无分隔符的 UUID(大写)
|
||||||
|
*/
|
||||||
|
public static String randomUuidUpper() {
|
||||||
|
return randomUuid().toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?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="com.timeline.story.dao.CommonRelationMapper">
|
||||||
|
|
||||||
|
<insert id="insertImageStoryItemRelation">
|
||||||
|
INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id)
|
||||||
|
VALUES (#{imageInstanceId}, #{storyItemId}, 1, #{userId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<select id="getImagesByStoryItemId" resultType="string">
|
||||||
|
SELECT rela_id
|
||||||
|
FROM common_relation
|
||||||
|
WHERE sub_rela_id = #{storyItemId} AND rela_type = 1 AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getStoryItemsByImageInstanceId" resultType="string">
|
||||||
|
SELECT sub_rela_id
|
||||||
|
FROM common_relation
|
||||||
|
WHERE rela_id = #{imageInstanceId} AND rela_type = 1 AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="deleteImageStoryItemRelation">
|
||||||
|
UPDATE common_relation
|
||||||
|
SET is_delete = 1
|
||||||
|
WHERE rela_id = #{imageInstanceId} AND sub_rela_id = #{storyItemId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<insert id="insertRelation">
|
||||||
|
INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id)
|
||||||
|
VALUES (#{relaId}, #{subRelaId}, #{relationType}, #{userId})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?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>com.timeline</groupId>
|
||||||
|
<artifactId>timeline</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>timeline-file-service</artifactId>
|
||||||
|
<name>timeline-file-service</name>
|
||||||
|
<description>File service for timeline system</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Spring Boot -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Cloud -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.minio</groupId>
|
||||||
|
<artifactId>minio</artifactId>
|
||||||
|
<version>8.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
|
||||||
|
<!-- Spring Cloud Alibaba (如使用 Nacos) -->
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>-->
|
||||||
|
|
||||||
|
<!-- 公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.timeline</groupId>
|
||||||
|
<artifactId>timeline-component-common</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 数据库相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>8.2.0</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.timeline.file;
|
||||||
|
|
||||||
|
import com.timeline.file.config.MinioConfig;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@ComponentScan({"com.timeline", "com.timeline.file"})
|
||||||
|
@EnableConfigurationProperties(MinioConfig.class)
|
||||||
|
public class TimelineFileServiceApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(TimelineFileServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.timeline.file.config;
|
||||||
|
|
||||||
|
import io.minio.MinioClient;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "minio")
|
||||||
|
public class MinioConfig {
|
||||||
|
private String endpoint;
|
||||||
|
private String accessKey;
|
||||||
|
private String secretKey;
|
||||||
|
private String bucketName;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MinioClient minioClient() {
|
||||||
|
return MinioClient.builder()
|
||||||
|
.endpoint(endpoint)
|
||||||
|
.credentials(accessKey, secretKey)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
package com.timeline.file.controller;
|
||||||
|
|
||||||
|
import com.timeline.file.service.FileService;
|
||||||
|
import com.timeline.file.service.impl.FileServiceImpl;
|
||||||
|
import com.timeline.file.vo.ImageInfoVo;
|
||||||
|
import com.timeline.response.ResponseEntity;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/file")
|
||||||
|
public class FileController {
|
||||||
|
@Autowired
|
||||||
|
private FileService fileService;
|
||||||
|
@GetMapping("/hello")
|
||||||
|
public String hello(){
|
||||||
|
return "file service hello";
|
||||||
|
}
|
||||||
|
@GetMapping("/create-default-bucket")
|
||||||
|
public String createDefaultBucket() throws Throwable {
|
||||||
|
fileService.createBucketIfNotExist();
|
||||||
|
return "create default bucket success";
|
||||||
|
}
|
||||||
|
@GetMapping("/get-upload-url/{fileName}")
|
||||||
|
public ResponseEntity<String> getUploadUrl(@PathVariable String fileName) throws Throwable {
|
||||||
|
String uploadUrl = fileService.generateUploadUrl(fileName);
|
||||||
|
return ResponseEntity.success(uploadUrl);
|
||||||
|
}
|
||||||
|
@GetMapping("/get-download-url/{fileName}")
|
||||||
|
public ResponseEntity<String> getDownloadUrl(@PathVariable String fileName) throws Throwable {
|
||||||
|
String downloadUrl = fileService.generateDownloadUrl(fileName);
|
||||||
|
return ResponseEntity.success(downloadUrl);
|
||||||
|
}
|
||||||
|
@PostMapping("/uploaded")
|
||||||
|
public ResponseEntity<String> uploaded(@RequestBody ImageInfoVo imageInfoVo) throws Throwable {
|
||||||
|
fileService.saveFileMetadata(imageInfoVo);
|
||||||
|
return ResponseEntity.success("上传成功");
|
||||||
|
}
|
||||||
|
@PostMapping("/upload-cover")
|
||||||
|
public ResponseEntity<String> uploadCover(@RequestPart("cover") MultipartFile cover) throws Throwable {
|
||||||
|
String objectKey = fileService.uploadCover(cover);
|
||||||
|
return ResponseEntity.success(objectKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/download/cover/{coverInstanceId}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
|
||||||
|
public void downloadCover(@PathVariable String coverInstanceId, HttpServletResponse response) throws Throwable {
|
||||||
|
log.info("downloadCover");
|
||||||
|
InputStream inputStream = fileService.downloadCover(coverInstanceId);
|
||||||
|
response.setContentType("image/jpeg");
|
||||||
|
IOUtils.copy(inputStream, response.getOutputStream());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传图片后绑定到某个 StoryItem
|
||||||
|
*/
|
||||||
|
@PostMapping("/upload-story-item-image")
|
||||||
|
public ResponseEntity<String> uploadStoryItemImage(
|
||||||
|
@RequestParam String storyItemId,
|
||||||
|
@RequestBody ImageInfoVo imageInfoVo) throws Throwable {
|
||||||
|
|
||||||
|
// 1. 存储图片元数据
|
||||||
|
fileService.saveFileMetadata(imageInfoVo);
|
||||||
|
|
||||||
|
// 2. 关联图片和 StoryItem
|
||||||
|
fileService.associateImageWithStoryItem(imageInfoVo.getInstanceId(), storyItemId, "9999");
|
||||||
|
|
||||||
|
return ResponseEntity.success("上传并绑定成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某个 StoryItem 的所有图片链接
|
||||||
|
*/
|
||||||
|
@GetMapping("/story-item/images/{storyItemId}")
|
||||||
|
public ResponseEntity<List<String>> getStoryItemImages(@PathVariable String storyItemId) throws Throwable {
|
||||||
|
List<String> imageIds = fileService.getStoryItemImages(storyItemId);
|
||||||
|
ArrayList<String> urls = fileService.getAllImageUrls(imageIds);
|
||||||
|
|
||||||
|
return ResponseEntity.success(urls);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从 StoryItem 移除一个图片
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/story-item/image/remove")
|
||||||
|
public ResponseEntity<String> removeImageFromStoryItem(
|
||||||
|
@RequestParam String imageInstanceId,
|
||||||
|
@RequestParam String storyItemId) throws Throwable {
|
||||||
|
|
||||||
|
fileService.removeImageFromStoryItem(imageInstanceId, storyItemId);
|
||||||
|
return ResponseEntity.success("图片已从故事项中移除");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.timeline.file.dao;
|
||||||
|
|
||||||
|
import com.timeline.dto.CommonRelationDTO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CommonRelationMapper {
|
||||||
|
void insertImageStoryItemRelation(String imageInstanceId, String storyItemId, String userId);
|
||||||
|
void insertRelation(CommonRelationDTO relationData);
|
||||||
|
List<String> getImagesByStoryItemId(String storyItemId);
|
||||||
|
|
||||||
|
List<String> getStoryItemsByImageInstanceId(String imageInstanceId);
|
||||||
|
|
||||||
|
void deleteImageStoryItemRelation(String imageInstanceId, String storyItemId);
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.timeline.file.dao;
|
||||||
|
|
||||||
|
import com.timeline.file.entity.ImageInfo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ImageInfoMapper {
|
||||||
|
void insert(ImageInfo imageInfo);
|
||||||
|
String selectObjectKeyById(String objectKey);
|
||||||
|
void delete(String objectKey);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.timeline.file.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ImageInfo {
|
||||||
|
private Long imageId;
|
||||||
|
private String instanceId;
|
||||||
|
private String imageName;
|
||||||
|
private String objectKey;
|
||||||
|
private LocalDateTime uploadTime;
|
||||||
|
private Long size;
|
||||||
|
private String contentType;
|
||||||
|
private String userId;
|
||||||
|
private Integer isDeleted;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.timeline.file.service;
|
||||||
|
|
||||||
|
import com.timeline.file.entity.ImageInfo;
|
||||||
|
import com.timeline.file.vo.ImageInfoVo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface FileService {
|
||||||
|
void createBucketIfNotExist() throws Throwable;
|
||||||
|
String generateUploadUrl(String fileName) throws Throwable;
|
||||||
|
String generateDownloadUrl(String fileName) throws Throwable;
|
||||||
|
void saveFileMetadata(ImageInfoVo imageInfoVo);
|
||||||
|
List<ImageInfo> listAllImages();
|
||||||
|
void deleteImage(String objectKey) throws Throwable;
|
||||||
|
void associateImageWithStoryItem(String imageInstanceId, String storyItemId, String userId);
|
||||||
|
List<String> getStoryItemImages(String storyItemId);
|
||||||
|
void removeImageFromStoryItem(String imageInstanceId, String storyItemId);
|
||||||
|
ArrayList<String> getAllImageUrls(List<String> images) throws Throwable;
|
||||||
|
String uploadCover(MultipartFile cover) throws Throwable;
|
||||||
|
InputStream downloadCover(String coverKey) throws Throwable;
|
||||||
|
}
|
|
@ -0,0 +1,185 @@
|
||||||
|
package com.timeline.file.service.impl;
|
||||||
|
|
||||||
|
import com.timeline.exception.CustomException;
|
||||||
|
import com.timeline.file.config.MinioConfig;
|
||||||
|
import com.timeline.file.dao.CommonRelationMapper;
|
||||||
|
import com.timeline.file.dao.ImageInfoMapper;
|
||||||
|
import com.timeline.file.entity.ImageInfo;
|
||||||
|
import com.timeline.file.service.FileService;
|
||||||
|
import com.timeline.file.vo.ImageInfoVo;
|
||||||
|
import com.timeline.utils.IdUtils;
|
||||||
|
import io.minio.*;
|
||||||
|
import io.minio.errors.MinioException;
|
||||||
|
import io.minio.http.Method;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class FileServiceImpl implements FileService {
|
||||||
|
private final MinioClient minioClient;
|
||||||
|
private final MinioConfig minioConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImageInfoMapper imageInfoMapper;
|
||||||
|
@Autowired
|
||||||
|
private CommonRelationMapper commonRelationMapper;
|
||||||
|
@Autowired
|
||||||
|
public FileServiceImpl(MinioClient minioClient, MinioConfig minioConfig) {
|
||||||
|
this.minioClient = minioClient;
|
||||||
|
this.minioConfig = minioConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createBucketIfNotExist() throws Throwable {
|
||||||
|
try {
|
||||||
|
boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(minioConfig.getBucketName()).build());
|
||||||
|
if (!found) {
|
||||||
|
log.info("bucket不存在,创建bucket:{}", minioConfig.getBucketName());
|
||||||
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(minioConfig.getBucketName()).build());
|
||||||
|
}
|
||||||
|
} catch (MinioException e) {
|
||||||
|
log.error("MinIO 操作失败:", e);
|
||||||
|
throw new CustomException(500, "创建bucket失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateUploadUrl(String fileName) throws Throwable {
|
||||||
|
return minioClient.getPresignedObjectUrl(
|
||||||
|
GetPresignedObjectUrlArgs.builder()
|
||||||
|
.method(Method.PUT)
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(fileName).build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateDownloadUrl(String fileName) throws Throwable {
|
||||||
|
return minioClient.getPresignedObjectUrl(
|
||||||
|
GetPresignedObjectUrlArgs.builder()
|
||||||
|
.method(Method.GET)
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(fileName).build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveFileMetadata(ImageInfoVo imageInfoVo) {
|
||||||
|
try {
|
||||||
|
ImageInfo imageInfo = new ImageInfo();
|
||||||
|
imageInfo.setInstanceId(IdUtils.randomUuidUpper());
|
||||||
|
imageInfo.setObjectKey(imageInfoVo.getObjectKey());
|
||||||
|
imageInfo.setImageName(imageInfoVo.getImageName());
|
||||||
|
imageInfo.setContentType(imageInfoVo.getContentType());
|
||||||
|
imageInfo.setSize(imageInfoVo.getSize());
|
||||||
|
imageInfo.setUploadTime(LocalDateTime.now());
|
||||||
|
imageInfo.setUserId("9999");
|
||||||
|
imageInfoMapper.insert(imageInfo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存图片元数据失败", e);
|
||||||
|
throw new CustomException(500, "保存图片信息失败");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ImageInfo> listAllImages() {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteImage(String objectKey) throws Throwable {
|
||||||
|
try {
|
||||||
|
// 删除 MinIO 中的对象
|
||||||
|
minioClient.removeObject(RemoveObjectArgs.builder()
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(objectKey)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
// 删除 MySQL 记录
|
||||||
|
imageInfoMapper.delete(objectKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("删除图片失败", e);
|
||||||
|
throw new CustomException(500, "删除图片失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void associateImageWithStoryItem(String imageInstanceId, String storyItemId, String userId) {
|
||||||
|
try {
|
||||||
|
commonRelationMapper.insertImageStoryItemRelation(imageInstanceId, storyItemId, userId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("关联图片和故事项失败", e);
|
||||||
|
throw new CustomException(500, "关联图片和故事项失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getStoryItemImages(String storyItemId) {
|
||||||
|
return commonRelationMapper.getImagesByStoryItemId(storyItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeImageFromStoryItem(String imageInstanceId, String storyItemId) {
|
||||||
|
try {
|
||||||
|
commonRelationMapper.deleteImageStoryItemRelation(imageInstanceId, storyItemId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("从故事项移除图片失败", e);
|
||||||
|
throw new CustomException(500, "从故事项移除图片失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<String> getAllImageUrls(List<String > imageIds) throws Throwable {
|
||||||
|
ArrayList<String> urls = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String imageInstanceId : imageIds) {
|
||||||
|
String objectKey = imageInfoMapper.selectObjectKeyById(imageInstanceId);
|
||||||
|
String url = this.generateDownloadUrl(objectKey);
|
||||||
|
urls.add(url);
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String uploadCover(MultipartFile cover) throws Throwable {
|
||||||
|
String fileName = "cover-" + IdUtils.randomUuidUpper() + ".jpg";
|
||||||
|
// 1. 上传到 MinIO
|
||||||
|
minioClient.putObject(PutObjectArgs.builder()
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(fileName)
|
||||||
|
.stream(cover.getInputStream(), cover.getSize(), -1)
|
||||||
|
.contentType(cover.getContentType())
|
||||||
|
.build());
|
||||||
|
|
||||||
|
// 2. 保存元数据到 MySQL
|
||||||
|
ImageInfo imageInfo = new ImageInfo();
|
||||||
|
imageInfo.setInstanceId(IdUtils.randomUuidUpper());
|
||||||
|
imageInfo.setObjectKey(fileName);
|
||||||
|
imageInfo.setImageName(fileName);
|
||||||
|
imageInfo.setContentType(cover.getContentType());
|
||||||
|
imageInfo.setSize(cover.getSize());
|
||||||
|
imageInfo.setUserId("9999");
|
||||||
|
imageInfo.setUploadTime(LocalDateTime.now());
|
||||||
|
imageInfoMapper.insert(imageInfo);
|
||||||
|
|
||||||
|
return imageInfo.getInstanceId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream downloadCover(String coverInstanceId) throws Throwable {
|
||||||
|
log.info("获取");
|
||||||
|
String objectKey = imageInfoMapper.selectObjectKeyById(coverInstanceId);
|
||||||
|
return minioClient.getObject(GetObjectArgs.builder()
|
||||||
|
.bucket(minioConfig.getBucketName())
|
||||||
|
.object(objectKey)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.timeline.file.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ImageInfoVo {
|
||||||
|
private String objectKey;
|
||||||
|
private String imageName;
|
||||||
|
private String contentType;
|
||||||
|
private Long size;
|
||||||
|
private String instanceId;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.timeline.file.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StoryItemImageRelationVo {
|
||||||
|
private String imageInstanceId;
|
||||||
|
private String storyItemId;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
spring.application.name=timeline.file
|
||||||
|
spring.datasource.url=jdbc:mysql://8.137.148.196:33306/timeline?serverTimezone=UTC&allowPublicKeyRetrieval=true
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=your_password
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
# MinIO ??
|
||||||
|
minio.endpoint=http://8.137.148.196:9000
|
||||||
|
minio.accessKey=dasdqq22211AAdsda2
|
||||||
|
minio.secretKey=2123sda2AADDsa4
|
||||||
|
minio.bucketName=timeline-test
|
||||||
|
|
||||||
|
# MyBatis ??
|
||||||
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
|
mybatis.type-aliases-package=com.timeline.file.entity
|
||||||
|
|
||||||
|
server.port=30002
|
||||||
|
spring.servlet.multipart.enabled=true
|
||||||
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
|
spring.servlet.multipart.max-request-size=10MB
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?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="com.timeline.file.dao.CommonRelationMapper">
|
||||||
|
|
||||||
|
<insert id="insertImageStoryItemRelation">
|
||||||
|
INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id)
|
||||||
|
VALUES (#{imageInstanceId}, #{storyItemId}, 1, #{userId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<select id="getImagesByStoryItemId" resultType="string">
|
||||||
|
SELECT rela_id
|
||||||
|
FROM common_relation
|
||||||
|
WHERE sub_rela_id = #{storyItemId} AND rela_type = 1 AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getStoryItemsByImageInstanceId" resultType="string">
|
||||||
|
SELECT sub_rela_id
|
||||||
|
FROM common_relation
|
||||||
|
WHERE rela_id = #{imageInstanceId} AND rela_type = 1 AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="deleteImageStoryItemRelation">
|
||||||
|
UPDATE common_relation
|
||||||
|
SET is_delete = 1
|
||||||
|
WHERE rela_id = #{imageInstanceId} AND sub_rela_id = #{storyItemId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<insert id="insertRelation">
|
||||||
|
INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id)
|
||||||
|
VALUES (#{relaId}, #{subRelaId}, #{relationType}, #{userId})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?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="com.timeline.file.dao.ImageInfoMapper">
|
||||||
|
|
||||||
|
<insert id="insert">
|
||||||
|
INSERT INTO image_info (instance_id, image_name, object_key, upload_time, size, content_type, user_id)
|
||||||
|
VALUES (#{instanceId}, #{imageName}, #{objectKey}, #{uploadTime}, #{size}, #{contentType}, #{userId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<select id="findByObjectKey" resultType="com.timeline.file.entity.ImageInfo">
|
||||||
|
SELECT * FROM image_info WHERE object_key = #{objectKey}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<delete id="deleteByObjectKey">
|
||||||
|
DELETE FROM image_info WHERE object_key = #{objectKey}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="selectObjectKeyById" resultType="string">
|
||||||
|
SELECT object_key FROM image_info WHERE instance_id = #{instanceId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.timeline</groupId>
|
||||||
|
<artifactId>timeline</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>timeline-story-service</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis</artifactId>
|
||||||
|
<version>3.5.17</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.timeline</groupId>
|
||||||
|
<artifactId>timeline-component-common</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Spring Boot Actuator -->
|
||||||
|
<!-- Spring Boot -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Spring Cloud -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 数据库相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>3.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.83</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>8.2.0</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.timeline.story;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@ComponentScan(basePackages = {"com.timeline"})
|
||||||
|
@EnableFeignClients(basePackages = {"com.timeline"})
|
||||||
|
public class TimelineStoryServiceApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
org.springframework.boot.SpringApplication.run(TimelineStoryServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.timeline.story.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
public class CorsConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/api/**")
|
||||||
|
.allowedOrigins("http://localhost:8000")
|
||||||
|
.allowedMethods("GET", "POST", "PUT", "DELETE")
|
||||||
|
.allowCredentials(true)
|
||||||
|
.maxAge(3600);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.timeline.story.config;
|
||||||
|
|
||||||
|
import feign.codec.Encoder;
|
||||||
|
import feign.form.spring.SpringFormEncoder;
|
||||||
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
|
import org.springframework.cloud.openfeign.support.SpringEncoder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class FeignConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Encoder feignEncoder() {
|
||||||
|
return new SpringFormEncoder();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.timeline.story.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeFormatterBuilder;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class JacksonConfig implements Jackson2ObjectMapperBuilderCustomizer {
|
||||||
|
@Override
|
||||||
|
public void customize(Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
|
||||||
|
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
|
||||||
|
.appendPattern("yyyy-MM-dd HH:mm:ss")
|
||||||
|
.toFormatter(Locale.CHINA);
|
||||||
|
|
||||||
|
jackson2ObjectMapperBuilder.simpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
jackson2ObjectMapperBuilder.timeZone(java.util.TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.timeline.story.controller;
|
||||||
|
|
||||||
|
import com.timeline.response.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/ping")
|
||||||
|
public class HealthController {
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<String> ping(){
|
||||||
|
return ResponseEntity.success("pong");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.timeline.story.controller;
|
||||||
|
|
||||||
|
import com.timeline.response.ResponseEntity;
|
||||||
|
import com.timeline.story.entity.Story;
|
||||||
|
import com.timeline.story.service.StoryService;
|
||||||
|
import com.timeline.story.vo.StoryVo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/story")
|
||||||
|
@Slf4j
|
||||||
|
public class StoryController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StoryService storyService;
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<String> hello() {
|
||||||
|
return ResponseEntity.success("hello");
|
||||||
|
}
|
||||||
|
@GetMapping("/test")
|
||||||
|
public ResponseEntity<String> test() {
|
||||||
|
return ResponseEntity.success("Test endpoint");
|
||||||
|
}
|
||||||
|
@PostMapping("/add")
|
||||||
|
public ResponseEntity<String> createStory(@RequestBody StoryVo storyVo) {
|
||||||
|
log.info("创建故事: {}", storyVo);
|
||||||
|
storyService.createStory(storyVo);
|
||||||
|
return ResponseEntity.success("故事创建成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{storyId}")
|
||||||
|
public ResponseEntity<String> updateStory(@RequestBody StoryVo storyVo, @PathVariable String storyId) {
|
||||||
|
log.info("更新故事: {},ID: {}", storyVo, storyId);
|
||||||
|
storyService.updateStory(storyVo, storyId);
|
||||||
|
return ResponseEntity.success("故事更新成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{storyId}")
|
||||||
|
public ResponseEntity<String> deleteStory(@PathVariable String storyId) {
|
||||||
|
log.info("删除故事, ID: {}", storyId);
|
||||||
|
storyService.deleteStory(storyId);
|
||||||
|
return ResponseEntity.success("故事删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{storyId}")
|
||||||
|
public ResponseEntity<Story> getStoryById(@PathVariable String storyId) {
|
||||||
|
log.info("获取故事详情, ID: {}", storyId);
|
||||||
|
Story story = storyService.getStoryById(storyId);
|
||||||
|
return ResponseEntity.success(story);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/owner/{ownerId}")
|
||||||
|
public ResponseEntity<List<Story>> getStoriesByOwnerId(@PathVariable String ownerId) {
|
||||||
|
log.info("查询用户故事列表, 用户ID: {}", ownerId);
|
||||||
|
List<Story> stories = storyService.getStoriesByOwnerId(ownerId);
|
||||||
|
return ResponseEntity.success(stories);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.timeline.story.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.timeline.response.ResponseEntity;
|
||||||
|
import com.timeline.story.entity.StoryItem;
|
||||||
|
import com.timeline.story.service.StoryItemService;
|
||||||
|
import com.timeline.story.vo.StoryItemVo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/story/item")
|
||||||
|
@Slf4j
|
||||||
|
public class StoryItemController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StoryItemService storyItemService;
|
||||||
|
|
||||||
|
@PostMapping()
|
||||||
|
public ResponseEntity<String> createItem(@RequestParam("storyItem") String storyItemVoString, @RequestParam("cover") MultipartFile cover, @RequestParam("images") List<MultipartFile> images) {
|
||||||
|
|
||||||
|
log.info("创建 StoryItem,{}", storyItemVoString);
|
||||||
|
storyItemService.createItemWithCover(JSONObject.parseObject(storyItemVoString, StoryItemVo.class), cover, images);
|
||||||
|
return ResponseEntity.success("StoryItem 创建成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{itemId}")
|
||||||
|
public ResponseEntity<String> updateItem(@PathVariable String itemId,
|
||||||
|
@RequestParam String description,
|
||||||
|
@RequestParam String location) {
|
||||||
|
log.info("更新 StoryItem: {}", itemId);
|
||||||
|
storyItemService.updateItem(itemId, description, location);
|
||||||
|
return ResponseEntity.success("StoryItem 更新成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{itemId}")
|
||||||
|
public ResponseEntity<String> deleteItem(@PathVariable String itemId) {
|
||||||
|
log.info("删除 StoryItem: {}", itemId);
|
||||||
|
storyItemService.deleteItem(itemId);
|
||||||
|
return ResponseEntity.success("StoryItem 删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{itemId}")
|
||||||
|
public ResponseEntity<StoryItem> getItemById(@PathVariable String itemId) {
|
||||||
|
log.info("获取 StoryItem 详情: {}", itemId);
|
||||||
|
StoryItem item = storyItemService.getItemById(itemId);
|
||||||
|
return ResponseEntity.success(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public ResponseEntity<List<StoryItem>> getItemsByMasterItem(@RequestParam String masterItemId) {
|
||||||
|
log.info("查询 StoryItem 列表,masterItemId: {}", masterItemId);
|
||||||
|
List<StoryItem> items = storyItemService.getItemsByMasterItem(masterItemId);
|
||||||
|
return ResponseEntity.success(items);
|
||||||
|
}
|
||||||
|
@GetMapping("/images/{itemId}")
|
||||||
|
public ResponseEntity<List<String>> getStoryItemImages(@PathVariable String itemId) {
|
||||||
|
log.info("获取 StoryItem 图片列表,itemId: {}", itemId);
|
||||||
|
List<String> images = storyItemService.getStoryItemImages(itemId);
|
||||||
|
return ResponseEntity.success(images);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.timeline.story.dao;
|
||||||
|
|
||||||
|
import com.timeline.dto.CommonRelationDTO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CommonRelationMapper {
|
||||||
|
void insertImageStoryItemRelation(String imageInstanceId, String storyItemId, String userId);
|
||||||
|
void insertRelation(CommonRelationDTO relationData);
|
||||||
|
List<String> getImagesByStoryItemId(String storyItemId);
|
||||||
|
|
||||||
|
List<String> getStoryItemsByImageInstanceId(String imageInstanceId);
|
||||||
|
|
||||||
|
void deleteImageStoryItemRelation(String imageInstanceId, String storyItemId);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.timeline.story.dao;
|
||||||
|
|
||||||
|
import com.timeline.story.entity.StoryItem;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface StoryItemMapper {
|
||||||
|
void insert(StoryItem storyItem);
|
||||||
|
void update(StoryItem storyItem);
|
||||||
|
void deleteById(String itemId);
|
||||||
|
StoryItem selectById(String itemId);
|
||||||
|
List<StoryItem> selectByMasterItem(String masterItemId);
|
||||||
|
List<String> selectImagesByItemId(String itemId);
|
||||||
|
List<StoryItem> selectByMasterItemWithSubItems(String masterItemId);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.timeline.story.dao;
|
||||||
|
|
||||||
|
import com.timeline.story.entity.Story;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface StoryMapper {
|
||||||
|
void insert(Story story);
|
||||||
|
void update(Story story);
|
||||||
|
void deleteByInstanceId(String instanceId);
|
||||||
|
Story selectById(String instanceId);
|
||||||
|
List<Story> selectByOwnerId(String ownerId);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.timeline.story.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CommonRelationDTO {
|
||||||
|
private Integer id;
|
||||||
|
private String relaId;
|
||||||
|
private String subRelaId;
|
||||||
|
private Integer relationType;
|
||||||
|
private String userId;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
private Integer isDeleted;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.timeline.story.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Story {
|
||||||
|
private String instanceId;
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
private String updateId;
|
||||||
|
private Integer isDelete;
|
||||||
|
private String ownerId;
|
||||||
|
private String status;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.timeline.story.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StoryItem {
|
||||||
|
private String itemId;
|
||||||
|
private String masterItem;
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String location;
|
||||||
|
private String createId;
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime storyItemTime;
|
||||||
|
private Integer isRoot;
|
||||||
|
private Integer isDelete;
|
||||||
|
private String coverInstanceId;
|
||||||
|
private StoryItem[] subItems;
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.timeline.story.feign;
|
||||||
|
|
||||||
|
import com.timeline.response.ResponseEntity;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@FeignClient(name = "timeline.file", url = "${file.service.url}")
|
||||||
|
public interface FileServiceClient {
|
||||||
|
|
||||||
|
@PostMapping(value = "/upload-cover", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
ResponseEntity<String> uploadCover(@RequestPart("cover") MultipartFile cover);
|
||||||
|
|
||||||
|
@GetMapping("/download/cover/{coverKey}")
|
||||||
|
InputStreamResource downloadCover(@PathVariable String coverKey);
|
||||||
|
|
||||||
|
@PostMapping("/associate-image")
|
||||||
|
ResponseEntity<String> associateImageWithStoryItem(
|
||||||
|
@RequestParam String imageInstanceId,
|
||||||
|
@RequestParam String storyItemId,
|
||||||
|
@RequestParam String userId);
|
||||||
|
|
||||||
|
@GetMapping("/story-item/images/{storyItemId}")
|
||||||
|
ResponseEntity<List<String>> getStoryItemImages(@PathVariable String storyItemId);
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.timeline.story.service;
|
||||||
|
|
||||||
|
import com.timeline.story.entity.StoryItem;
|
||||||
|
import com.timeline.story.vo.StoryItemVo;
|
||||||
|
import com.timeline.story.vo.StoryItemWithCoverVo;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface StoryItemService {
|
||||||
|
void createItem(StoryItemVo storyItemVo);
|
||||||
|
void createItemWithCover(StoryItemVo storyItemVo, MultipartFile cover, List<MultipartFile> images);
|
||||||
|
StoryItemWithCoverVo getStoryItemWithCover(String itemId);
|
||||||
|
void updateItem(String itemId, String description, String location);
|
||||||
|
void deleteItem(String itemId);
|
||||||
|
StoryItem getItemById(String itemId);
|
||||||
|
List<StoryItem> getItemsByMasterItem(String masterItemId);
|
||||||
|
List<String> getStoryItemImages(String storyItemId);
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.timeline.story.service;
|
||||||
|
|
||||||
|
import com.timeline.story.entity.Story;
|
||||||
|
import com.timeline.story.vo.StoryVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface StoryService {
|
||||||
|
void createStory(StoryVo storyVo);
|
||||||
|
void updateStory(StoryVo storyVo, String storyId);
|
||||||
|
void deleteStory(String storyId);
|
||||||
|
Story getStoryById(String storyId);
|
||||||
|
List<Story> getStoriesByOwnerId(String ownerId);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,174 @@
|
||||||
|
package com.timeline.story.service.impl;
|
||||||
|
|
||||||
|
import com.timeline.constants.CommonConstants;
|
||||||
|
import com.timeline.story.dao.CommonRelationMapper;
|
||||||
|
import com.timeline.dto.CommonRelationDTO;
|
||||||
|
import com.timeline.exception.CustomException;
|
||||||
|
import com.timeline.response.ResponseEntity;
|
||||||
|
import com.timeline.response.ResponseEnum;
|
||||||
|
import com.timeline.story.dao.StoryItemMapper;
|
||||||
|
import com.timeline.story.entity.StoryItem;
|
||||||
|
import com.timeline.story.feign.FileServiceClient;
|
||||||
|
import com.timeline.story.service.StoryItemService;
|
||||||
|
import com.timeline.story.vo.StoryItemVo;
|
||||||
|
import com.timeline.story.vo.StoryItemWithCoverVo;
|
||||||
|
import com.timeline.utils.IdUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class StoryItemServiceImpl implements StoryItemService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StoryItemMapper storyItemMapper;
|
||||||
|
@Autowired
|
||||||
|
private FileServiceClient fileServiceClient;
|
||||||
|
@Autowired
|
||||||
|
private CommonRelationMapper commonRelationMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createItem(StoryItemVo storyItemVo) {
|
||||||
|
try {
|
||||||
|
StoryItem item = new StoryItem();
|
||||||
|
item.setItemId(IdUtils.randomUuidUpper());
|
||||||
|
item.setMasterItem(storyItemVo.getMasterItemId());
|
||||||
|
item.setDescription(storyItemVo.getDescription());
|
||||||
|
item.setTitle(storyItemVo.getTitle());
|
||||||
|
item.setLocation(storyItemVo.getLocation());
|
||||||
|
item.setCreateId("createId");
|
||||||
|
item.setIsRoot(storyItemVo.getIsRoot());
|
||||||
|
item.setIsDelete(0);
|
||||||
|
item.setCreateTime(LocalDateTime.now());
|
||||||
|
item.setUpdateTime(LocalDateTime.now());
|
||||||
|
item.setStoryItemTime(storyItemVo.getStoryItemTime());
|
||||||
|
storyItemMapper.insert(item);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建 StoryItem 失败", e);
|
||||||
|
throw new RuntimeException("创建 StoryItem 失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createItemWithCover(StoryItemVo storyItemVo, MultipartFile cover, List<MultipartFile> images) {
|
||||||
|
try {
|
||||||
|
// 1. 上传封面到 file 服务
|
||||||
|
ResponseEntity<String> coverResponse = fileServiceClient.uploadCover(cover);
|
||||||
|
String coverKey = coverResponse.getData();
|
||||||
|
log.info("上传成功,文件instanceId:{}", coverKey);
|
||||||
|
|
||||||
|
// 2. 创建 StoryItem 实体
|
||||||
|
StoryItem item = new StoryItem();
|
||||||
|
item.setItemId(IdUtils.randomUuidUpper());
|
||||||
|
item.setMasterItem(storyItemVo.getMasterItemId());
|
||||||
|
item.setTitle(storyItemVo.getTitle());
|
||||||
|
item.setDescription(storyItemVo.getDescription());
|
||||||
|
item.setLocation(storyItemVo.getLocation());
|
||||||
|
item.setCreateId("createId");
|
||||||
|
item.setStoryItemTime(storyItemVo.getStoryItemTime());
|
||||||
|
item.setIsRoot(storyItemVo.getIsRoot());
|
||||||
|
item.setIsDelete(0);
|
||||||
|
item.setCoverInstanceId(coverKey);
|
||||||
|
if (storyItemVo.getIsRoot() == CommonConstants.STORY_ITEM_IS_ROOT){
|
||||||
|
item.setIsRoot(CommonConstants.STORY_ITEM_IS_ROOT);
|
||||||
|
} else {
|
||||||
|
item.setIsRoot(CommonConstants.STORY_ITEM_IS_NOT_ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 3. 上传所有图片并建立关联
|
||||||
|
for (MultipartFile image : images) {
|
||||||
|
ResponseEntity<String> response = fileServiceClient.uploadCover(image);
|
||||||
|
String key = response.getData();
|
||||||
|
log.info("上传成功,文件instanceId:{}", key);
|
||||||
|
// 4. 保存封面与 StoryItem 的关联关系
|
||||||
|
buildStoryItemImageRelation(item.getItemId(), key);
|
||||||
|
}
|
||||||
|
// 4. 记录封面与 StoryItem 的关联关系
|
||||||
|
buildStoryItemImageRelation(item.getItemId(), coverKey);
|
||||||
|
// 3. 插入到 story_item 表
|
||||||
|
storyItemMapper.insert(item);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建 StoryItem 并上传封面失败", e);
|
||||||
|
throw new CustomException(ResponseEnum.INTERNAL_SERVER_ERROR, "上传封面失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StoryItemWithCoverVo getStoryItemWithCover(String itemId) {
|
||||||
|
StoryItem item = storyItemMapper.selectById(itemId);
|
||||||
|
if (item == null) {
|
||||||
|
throw new CustomException(ResponseEnum.NOT_FOUND, "未找到 StoryItem ");
|
||||||
|
}
|
||||||
|
InputStreamResource coverStream = null;
|
||||||
|
if (item.getCoverInstanceId() != null) {
|
||||||
|
// 从 file 服务下载封面流
|
||||||
|
coverStream = fileServiceClient.downloadCover(item.getCoverInstanceId());
|
||||||
|
|
||||||
|
}
|
||||||
|
return new StoryItemWithCoverVo(item, coverStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateItem(String itemId, String description, String location) {
|
||||||
|
try {
|
||||||
|
StoryItem item = storyItemMapper.selectById(itemId);
|
||||||
|
if (item == null) {
|
||||||
|
throw new RuntimeException("StoryItem 不存在");
|
||||||
|
}
|
||||||
|
item.setDescription(description);
|
||||||
|
item.setLocation(location);
|
||||||
|
item.setUpdateTime(LocalDateTime.now());
|
||||||
|
storyItemMapper.update(item);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新 StoryItem 失败", e);
|
||||||
|
throw new RuntimeException("更新 StoryItem 失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteItem(String itemId) {
|
||||||
|
try {
|
||||||
|
StoryItem item = storyItemMapper.selectById(itemId);
|
||||||
|
if (item == null) {
|
||||||
|
throw new RuntimeException("StoryItem 不存在");
|
||||||
|
}
|
||||||
|
storyItemMapper.deleteById(itemId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("删除 StoryItem 失败", e);
|
||||||
|
throw new RuntimeException("删除 StoryItem 失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StoryItem getItemById(String itemId) {
|
||||||
|
return storyItemMapper.selectById(itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<StoryItem> getItemsByMasterItem(String masterItemId) {
|
||||||
|
return storyItemMapper.selectByMasterItemWithSubItems(masterItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getStoryItemImages(String storyItemId) {
|
||||||
|
return storyItemMapper.selectImagesByItemId(storyItemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildStoryItemImageRelation(String storyItemId, String imageIds) {
|
||||||
|
CommonRelationDTO relationDTO = new CommonRelationDTO();
|
||||||
|
relationDTO.setRelaId(storyItemId);
|
||||||
|
relationDTO.setSubRelaId(imageIds);
|
||||||
|
relationDTO.setRelationType(CommonConstants.RELATION_STORY_ITEM_AND_IMAGE);
|
||||||
|
relationDTO.setUserId("9999");
|
||||||
|
relationDTO.setCreateTime(LocalDateTime.now());
|
||||||
|
relationDTO.setUpdateTime(LocalDateTime.now());
|
||||||
|
commonRelationMapper.insertRelation(relationDTO);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.timeline.story.service.impl;
|
||||||
|
|
||||||
|
import com.timeline.exception.CustomException;
|
||||||
|
import com.timeline.response.ResponseEnum;
|
||||||
|
import com.timeline.story.entity.Story;
|
||||||
|
import com.timeline.story.dao.StoryMapper;
|
||||||
|
import com.timeline.story.service.StoryService;
|
||||||
|
import com.timeline.story.vo.StoryVo;
|
||||||
|
import com.timeline.utils.IdUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class StoryServiceImpl implements StoryService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StoryMapper storyMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createStory(StoryVo storyVo) {
|
||||||
|
try {
|
||||||
|
Story story = new Story();
|
||||||
|
story.setOwnerId("test11");
|
||||||
|
story.setTitle(storyVo.getTitle());
|
||||||
|
story.setInstanceId(IdUtils.randomUuidUpper());
|
||||||
|
story.setDescription(storyVo.getDescription());
|
||||||
|
story.setStatus(storyVo.getStatus());
|
||||||
|
story.setCreateTime(LocalDateTime.now());
|
||||||
|
story.setUpdateTime(LocalDateTime.now());
|
||||||
|
story.setIsDelete(0);
|
||||||
|
storyMapper.insert(story);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建故事失败", e);
|
||||||
|
throw new CustomException(500, "创建故事失败: " + e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateStory(StoryVo storyVo, String storyId) {
|
||||||
|
|
||||||
|
Story story = storyMapper.selectById(storyId);
|
||||||
|
if (story == null) {
|
||||||
|
throw new CustomException(ResponseEnum.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
story.setTitle(storyVo.getTitle());
|
||||||
|
story.setDescription(storyVo.getDescription());
|
||||||
|
story.setStatus(storyVo.getStatus());
|
||||||
|
story.setUpdateTime(LocalDateTime.now());
|
||||||
|
storyMapper.update(story);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteStory(String storyId) {
|
||||||
|
Story story = storyMapper.selectById(storyId);
|
||||||
|
if (story == null) {
|
||||||
|
throw new CustomException(ResponseEnum.NOT_FOUND);
|
||||||
|
}
|
||||||
|
storyMapper.deleteByInstanceId(storyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Story getStoryById(String storyId) {
|
||||||
|
Story story = storyMapper.selectById(storyId);
|
||||||
|
if (story == null) {
|
||||||
|
throw new CustomException(ResponseEnum.NOT_FOUND);
|
||||||
|
}
|
||||||
|
return story;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Story> getStoriesByOwnerId(String ownerId) {
|
||||||
|
try {
|
||||||
|
return storyMapper.selectByOwnerId(ownerId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("查询用户故事列表失败", e);
|
||||||
|
throw new CustomException(500, "查询用户故事列表失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.timeline.story.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@Data
|
||||||
|
public class StoryItemAddVo extends StoryItemVo{
|
||||||
|
private MultipartFile cover;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.timeline.story.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
|
||||||
|
public class StoryItemVo {
|
||||||
|
private String instanceId;
|
||||||
|
private String masterItemId;
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String location;
|
||||||
|
private LocalDateTime storyItemTime;
|
||||||
|
private Integer isRoot;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.timeline.story.vo;
|
||||||
|
|
||||||
|
import com.timeline.story.entity.StoryItem;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class StoryItemWithCoverVo {
|
||||||
|
private StoryItem storyItem;
|
||||||
|
private InputStreamResource coverStream;
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.timeline.story.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StoryVo {
|
||||||
|
private String id;
|
||||||
|
private String instanceId;
|
||||||
|
private String ownerId;
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
|
private String status;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
spring.application.name=timeline.story
|
||||||
|
spring.datasource.url=jdbc:mysql://8.137.148.196:33306/timeline?serverTimezone=UTC&allowPublicKeyRetrieval=true
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=your_password
|
||||||
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
# MyBatis ??
|
||||||
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
|
mybatis.type-aliases-package=com.timeline.story.entity
|
||||||
|
mybatis.configuration.log4j=true
|
||||||
|
server.port=30001
|
||||||
|
spring.web.mvc.use-trailing-slash=true
|
||||||
|
mybatis.configuration.mapUnderscoreToCamelCase=true
|
||||||
|
# ??????????
|
||||||
|
logging.level.org.mybatis.spring=DEBUG
|
||||||
|
logging.level.org.apache.ibatis=DEBUG
|
||||||
|
|
||||||
|
# LocalDateTime ???????
|
||||||
|
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
|
||||||
|
spring.jackson.time-zone=UTC
|
||||||
|
|
||||||
|
file.service.url=http://localhost:30002/file/
|
||||||
|
|
||||||
|
spring.servlet.multipart.enabled=true
|
||||||
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
|
spring.servlet.multipart.max-request-size=10MB
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?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="com.timeline.story.dao.CommonRelationMapper">
|
||||||
|
|
||||||
|
<insert id="insertImageStoryItemRelation">
|
||||||
|
INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id)
|
||||||
|
VALUES (#{imageInstanceId}, #{storyItemId}, 1, #{userId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<select id="getImagesByStoryItemId" resultType="string">
|
||||||
|
SELECT rela_id
|
||||||
|
FROM common_relation
|
||||||
|
WHERE sub_rela_id = #{storyItemId} AND rela_type = 1 AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getStoryItemsByImageInstanceId" resultType="string">
|
||||||
|
SELECT sub_rela_id
|
||||||
|
FROM common_relation
|
||||||
|
WHERE rela_id = #{imageInstanceId} AND rela_type = 1 AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="deleteImageStoryItemRelation">
|
||||||
|
UPDATE common_relation
|
||||||
|
SET is_delete = 1
|
||||||
|
WHERE rela_id = #{imageInstanceId} AND sub_rela_id = #{storyItemId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<insert id="insertRelation">
|
||||||
|
INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id)
|
||||||
|
VALUES (#{relaId}, #{subRelaId}, #{relationType}, #{userId})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?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="com.timeline.story.dao.StoryItemMapper">
|
||||||
|
|
||||||
|
<insert id="insert">
|
||||||
|
INSERT INTO story_item (item_id, master_item, description, location, title, create_id, is_root, is_delete, story_item_time, cover_instance_id)
|
||||||
|
VALUES (#{itemId}, #{masterItem}, #{description}, #{location}, #{title},#{createId}, #{isRoot}, #{isDelete}, #{storyItemTime}, #{coverInstanceId})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="update">
|
||||||
|
UPDATE story_item
|
||||||
|
SET description = #{description},
|
||||||
|
location = #{location},
|
||||||
|
create_id = #{createId},
|
||||||
|
update_time = NOW()
|
||||||
|
WHERE item_id = #{itemId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteById">
|
||||||
|
DELETE FROM story_item WHERE item_id = #{itemId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="selectById" resultType="com.timeline.story.entity.StoryItem">
|
||||||
|
SELECT * FROM story_item WHERE item_id = #{itemId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByMasterItem" resultType="com.timeline.story.entity.StoryItem">
|
||||||
|
SELECT * FROM story_item WHERE master_item = #{masterItemId} AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectImagesByItemId" resultType="java.lang.String">
|
||||||
|
SELECT sub_rela_id FROM common_relation WHERE rela_id = #{itemId} AND rela_type = 5 AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
<select id="selectByMasterItemWithSubItems" resultType="com.timeline.story.entity.StoryItem">
|
||||||
|
WITH RECURSIVE StoryItemTree AS (
|
||||||
|
SELECT
|
||||||
|
item_id,
|
||||||
|
master_item,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
location,
|
||||||
|
create_id,
|
||||||
|
create_time,
|
||||||
|
update_time,
|
||||||
|
story_item_time,
|
||||||
|
is_root,
|
||||||
|
is_delete,
|
||||||
|
cover_instance_id,
|
||||||
|
0 AS level,
|
||||||
|
CAST(item_id AS CHAR(255)) AS path
|
||||||
|
FROM
|
||||||
|
story_item
|
||||||
|
WHERE
|
||||||
|
master_item = #{masterItemId}
|
||||||
|
AND is_delete = 0
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
si.item_id,
|
||||||
|
si.master_item,
|
||||||
|
si.title,
|
||||||
|
si.description,
|
||||||
|
si.location,
|
||||||
|
si.create_id,
|
||||||
|
si.create_time,
|
||||||
|
si.update_time,
|
||||||
|
si.story_item_time,
|
||||||
|
si.is_root,
|
||||||
|
si.is_delete,
|
||||||
|
si.cover_instance_id,
|
||||||
|
t.level + 1,
|
||||||
|
CONCAT(t.path, '->', si.item_id)
|
||||||
|
FROM
|
||||||
|
story_item si
|
||||||
|
INNER JOIN
|
||||||
|
StoryItemTree t ON si.master_item = t.item_id
|
||||||
|
WHERE
|
||||||
|
si.is_delete = 0
|
||||||
|
)
|
||||||
|
SELECT * FROM StoryItemTree
|
||||||
|
ORDER BY story_item_time ASC;
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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="com.timeline.story.dao.StoryMapper">
|
||||||
|
|
||||||
|
<insert id="insert">
|
||||||
|
INSERT INTO story (instance_id, title, description, owner_id, status)
|
||||||
|
VALUES (#{instanceId}, #{title}, #{description}, #{ownerId}, #{status})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="update">
|
||||||
|
UPDATE story
|
||||||
|
SET title = #{title},
|
||||||
|
description = #{description},
|
||||||
|
update_id = #{updateId},
|
||||||
|
status = #{status},
|
||||||
|
update_time = NOW()
|
||||||
|
WHERE instance_id = #{instanceId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteByInstanceId">
|
||||||
|
UPDATE story SET story.is_delete = 1 WHERE instance_id = #{instanceId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="selectById" resultType="com.timeline.story.entity.Story">
|
||||||
|
SELECT * FROM story WHERE instance_id = #{instanceId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByOwnerId" resultType="com.timeline.story.entity.Story">
|
||||||
|
SELECT * FROM story WHERE owner_id = #{ownerId} AND is_delete = 0
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue