From f8fb9b561c145915b6afdce5dbd34da5a895dcb7 Mon Sep 17 00:00:00 2001 From: jiangh277 Date: Tue, 22 Jul 2025 23:00:39 +0800 Subject: [PATCH] init --- .gitattributes | 2 + .gitignore | 33 +++ .mvn/wrapper/maven-wrapper.properties | 19 ++ mvnw | 259 ++++++++++++++++++ mvnw.cmd | 149 ++++++++++ pom.xml | 74 +++++ qodana.yaml | 31 +++ timeline-component-common/pom.xml | 67 +++++ .../com/timeline/aop/RequestLogAspect.java | 48 ++++ .../timeline/constants/CommonConstants.java | 12 + .../com/timeline/dto/CommonRelationDTO.java | 17 ++ .../com/timeline/enums/RelationTypeEnum.java | 5 + .../timeline/exception/CustomException.java | 32 +++ .../handler/GlobalExceptionHandler.java | 22 ++ .../com/timeline/response/ResponseEntity.java | 28 ++ .../com/timeline/response/ResponseEnum.java | 32 +++ .../main/java/com/timeline/utils/IdUtils.java | 18 ++ .../com/timeline/dao/CommonRelationMapper.xml | 33 +++ timeline-file-service/pom.xml | 97 +++++++ .../file/TimelineFileServiceApplication.java | 18 ++ .../com/timeline/file/config/MinioConfig.java | 25 ++ .../file/controller/FileController.java | 103 +++++++ .../file/dao/CommonRelationMapper.java | 17 ++ .../timeline/file/dao/ImageInfoMapper.java | 11 + .../com/timeline/file/entity/ImageInfo.java | 18 ++ .../timeline/file/service/FileService.java | 26 ++ .../file/service/impl/FileServiceImpl.java | 185 +++++++++++++ .../com/timeline/file/vo/ImageInfoVo.java | 12 + .../file/vo/StoryItemImageRelationVo.java | 9 + .../src/main/resources/application.properties | 19 ++ .../file/dao/CommonRelationMapper.xml | 33 +++ .../com/timeline/file/dao/ImageInfoMapper.xml | 23 ++ timeline-story-service/pom.xml | 91 ++++++ .../TimelineStoryServiceApplication.java | 14 + .../com/timeline/story/config/CorsConfig.java | 20 ++ .../timeline/story/config/FeignConfig.java | 17 ++ .../timeline/story/config/JacksonConfig.java | 22 ++ .../story/controller/HealthController.java | 15 + .../story/controller/StoryController.java | 62 +++++ .../story/controller/StoryItemController.java | 67 +++++ .../story/dao/CommonRelationMapper.java | 17 ++ .../timeline/story/dao/StoryItemMapper.java | 18 ++ .../com/timeline/story/dao/StoryMapper.java | 16 ++ .../story/entity/CommonRelationDTO.java | 17 ++ .../java/com/timeline/story/entity/Story.java | 21 ++ .../com/timeline/story/entity/StoryItem.java | 25 ++ .../story/feign/FileServiceClient.java | 30 ++ .../story/service/StoryItemService.java | 19 ++ .../timeline/story/service/StoryService.java | 15 + .../service/impl/StoryItemServiceImpl.java | 174 ++++++++++++ .../story/service/impl/StoryServiceImpl.java | 86 ++++++ .../com/timeline/story/vo/StoryItemAddVo.java | 8 + .../com/timeline/story/vo/StoryItemVo.java | 18 ++ .../story/vo/StoryItemWithCoverVo.java | 14 + .../java/com/timeline/story/vo/StoryVo.java | 13 + .../src/main/resources/application.properties | 25 ++ .../story/dao/CommonRelationMapper.xml | 33 +++ .../timeline/story/dao/StoryItemMapper.xml | 88 ++++++ .../com/timeline/story/dao/StoryMapper.xml | 34 +++ 59 files changed, 2456 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 mvnw create mode 100644 mvnw.cmd create mode 100644 pom.xml create mode 100644 qodana.yaml create mode 100644 timeline-component-common/pom.xml create mode 100644 timeline-component-common/src/main/java/com/timeline/aop/RequestLogAspect.java create mode 100644 timeline-component-common/src/main/java/com/timeline/constants/CommonConstants.java create mode 100644 timeline-component-common/src/main/java/com/timeline/dto/CommonRelationDTO.java create mode 100644 timeline-component-common/src/main/java/com/timeline/enums/RelationTypeEnum.java create mode 100644 timeline-component-common/src/main/java/com/timeline/exception/CustomException.java create mode 100644 timeline-component-common/src/main/java/com/timeline/handler/GlobalExceptionHandler.java create mode 100644 timeline-component-common/src/main/java/com/timeline/response/ResponseEntity.java create mode 100644 timeline-component-common/src/main/java/com/timeline/response/ResponseEnum.java create mode 100644 timeline-component-common/src/main/java/com/timeline/utils/IdUtils.java create mode 100644 timeline-component-common/src/main/resources/com/timeline/dao/CommonRelationMapper.xml create mode 100644 timeline-file-service/pom.xml create mode 100644 timeline-file-service/src/main/java/com/timeline/file/TimelineFileServiceApplication.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/config/MinioConfig.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/controller/FileController.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/dao/CommonRelationMapper.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/dao/ImageInfoMapper.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/entity/ImageInfo.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/service/FileService.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/service/impl/FileServiceImpl.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/vo/ImageInfoVo.java create mode 100644 timeline-file-service/src/main/java/com/timeline/file/vo/StoryItemImageRelationVo.java create mode 100644 timeline-file-service/src/main/resources/application.properties create mode 100644 timeline-file-service/src/main/resources/com/timeline/file/dao/CommonRelationMapper.xml create mode 100644 timeline-file-service/src/main/resources/com/timeline/file/dao/ImageInfoMapper.xml create mode 100644 timeline-story-service/pom.xml create mode 100644 timeline-story-service/src/main/java/com/timeline/story/TimelineStoryServiceApplication.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/config/CorsConfig.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/config/FeignConfig.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/config/JacksonConfig.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/controller/HealthController.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/controller/StoryController.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/controller/StoryItemController.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/dao/CommonRelationMapper.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/dao/StoryItemMapper.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/dao/StoryMapper.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/entity/CommonRelationDTO.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/entity/Story.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/entity/StoryItem.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/feign/FileServiceClient.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/service/StoryItemService.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/service/StoryService.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryItemServiceImpl.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryServiceImpl.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemAddVo.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemVo.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemWithCoverVo.java create mode 100644 timeline-story-service/src/main/java/com/timeline/story/vo/StoryVo.java create mode 100644 timeline-story-service/src/main/resources/application.properties create mode 100644 timeline-story-service/src/main/resources/com/timeline/story/dao/CommonRelationMapper.xml create mode 100644 timeline-story-service/src/main/resources/com/timeline/story/dao/StoryItemMapper.xml create mode 100644 timeline-story-service/src/main/resources/com/timeline/story/dao/StoryMapper.xml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..2f94e61 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -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 diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/mvnw @@ -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-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +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 "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/mvnw.cmd @@ -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-,maven-mvnd--}/ +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" diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..44b6c27 --- /dev/null +++ b/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.12 + + + com.timeline + timeline + 0.0.1-SNAPSHOT + pom + + + + timeline-file-service + timeline-component-common + timeline-story-service + + + + + + + 21 + 2023.0.5 + 2023.0.5.0 + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 0000000..962f7de --- /dev/null +++ b/qodana.yaml @@ -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: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +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 can be found at https://plugins.jetbrains.com) + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-jvm:2024.3 diff --git a/timeline-component-common/pom.xml b/timeline-component-common/pom.xml new file mode 100644 index 0000000..138b64a --- /dev/null +++ b/timeline-component-common/pom.xml @@ -0,0 +1,67 @@ + + + 4.0.0 + + com.timeline + timeline + 0.0.1-SNAPSHOT + + timeline-component-common + + + 21 + 21 + UTF-8 + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework + spring-web + + + org.apache.tomcat.embed + tomcat-embed-core + + + org.mybatis + mybatis + 3.5.17 + compile + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + repackage + none + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.4.0 + + false + + + + + + + \ No newline at end of file diff --git a/timeline-component-common/src/main/java/com/timeline/aop/RequestLogAspect.java b/timeline-component-common/src/main/java/com/timeline/aop/RequestLogAspect.java new file mode 100644 index 0000000..7ec14b4 --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/aop/RequestLogAspect.java @@ -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; + } + + } +} diff --git a/timeline-component-common/src/main/java/com/timeline/constants/CommonConstants.java b/timeline-component-common/src/main/java/com/timeline/constants/CommonConstants.java new file mode 100644 index 0000000..c5bde89 --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/constants/CommonConstants.java @@ -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; +} diff --git a/timeline-component-common/src/main/java/com/timeline/dto/CommonRelationDTO.java b/timeline-component-common/src/main/java/com/timeline/dto/CommonRelationDTO.java new file mode 100644 index 0000000..46d7851 --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/dto/CommonRelationDTO.java @@ -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; +} diff --git a/timeline-component-common/src/main/java/com/timeline/enums/RelationTypeEnum.java b/timeline-component-common/src/main/java/com/timeline/enums/RelationTypeEnum.java new file mode 100644 index 0000000..a6d4e62 --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/enums/RelationTypeEnum.java @@ -0,0 +1,5 @@ +package com.timeline.enums; + +public enum RelationTypeEnum { + +} diff --git a/timeline-component-common/src/main/java/com/timeline/exception/CustomException.java b/timeline-component-common/src/main/java/com/timeline/exception/CustomException.java new file mode 100644 index 0000000..597dc21 --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/exception/CustomException.java @@ -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; + } +} diff --git a/timeline-component-common/src/main/java/com/timeline/handler/GlobalExceptionHandler.java b/timeline-component-common/src/main/java/com/timeline/handler/GlobalExceptionHandler.java new file mode 100644 index 0000000..e193caa --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/handler/GlobalExceptionHandler.java @@ -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 handleCustomException(CustomException ex) { + return ResponseEntity.error(ex.getCode(), ex.getMessage()); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity handleGenericException(Exception ex) { + return ResponseEntity.error(ResponseEnum.INTERNAL_SERVER_ERROR.getCode(), + ResponseEnum.INTERNAL_SERVER_ERROR.getMessage() + ": " + ex.getMessage()); + } +} diff --git a/timeline-component-common/src/main/java/com/timeline/response/ResponseEntity.java b/timeline-component-common/src/main/java/com/timeline/response/ResponseEntity.java new file mode 100644 index 0000000..386095e --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/response/ResponseEntity.java @@ -0,0 +1,28 @@ +package com.timeline.response; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ResponseEntity { + private int code; + private String message; + private T data; + + public static ResponseEntity success(T data) { + return new ResponseEntity<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), data); + } + + public static ResponseEntity error(int code, String message) { + return new ResponseEntity<>(code, message, null); + } + + public static ResponseEntity error(ResponseEnum responseEnum) { + return new ResponseEntity<>(responseEnum.getCode(), responseEnum.getMessage(), null); + } + + public static ResponseEntity error(ResponseEnum responseEnum, String detailMessage) { + return new ResponseEntity<>(responseEnum.getCode(), responseEnum.getMessage() + ": " + detailMessage, null); + } +} diff --git a/timeline-component-common/src/main/java/com/timeline/response/ResponseEnum.java b/timeline-component-common/src/main/java/com/timeline/response/ResponseEnum.java new file mode 100644 index 0000000..757f54c --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/response/ResponseEnum.java @@ -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; +} diff --git a/timeline-component-common/src/main/java/com/timeline/utils/IdUtils.java b/timeline-component-common/src/main/java/com/timeline/utils/IdUtils.java new file mode 100644 index 0000000..cbc3d60 --- /dev/null +++ b/timeline-component-common/src/main/java/com/timeline/utils/IdUtils.java @@ -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(); + } +} diff --git a/timeline-component-common/src/main/resources/com/timeline/dao/CommonRelationMapper.xml b/timeline-component-common/src/main/resources/com/timeline/dao/CommonRelationMapper.xml new file mode 100644 index 0000000..2afb3b1 --- /dev/null +++ b/timeline-component-common/src/main/resources/com/timeline/dao/CommonRelationMapper.xml @@ -0,0 +1,33 @@ + + + + + + INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id) + VALUES (#{imageInstanceId}, #{storyItemId}, 1, #{userId}) + + + + + + + + UPDATE common_relation + SET is_delete = 1 + WHERE rela_id = #{imageInstanceId} AND sub_rela_id = #{storyItemId} + + + + INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id) + VALUES (#{relaId}, #{subRelaId}, #{relationType}, #{userId}) + + diff --git a/timeline-file-service/pom.xml b/timeline-file-service/pom.xml new file mode 100644 index 0000000..66d99e7 --- /dev/null +++ b/timeline-file-service/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + + com.timeline + timeline + 0.0.1-SNAPSHOT + ../pom.xml + + + timeline-file-service + timeline-file-service + File service for timeline system + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + io.minio + minio + 8.5.2 + + + + + + + + + com.timeline + timeline-component-common + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.4 + + + com.mysql + mysql-connector-j + 8.2.0 + runtime + + + org.projectlombok + lombok + true + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + diff --git a/timeline-file-service/src/main/java/com/timeline/file/TimelineFileServiceApplication.java b/timeline-file-service/src/main/java/com/timeline/file/TimelineFileServiceApplication.java new file mode 100644 index 0000000..f240532 --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/TimelineFileServiceApplication.java @@ -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); + } + +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/config/MinioConfig.java b/timeline-file-service/src/main/java/com/timeline/file/config/MinioConfig.java new file mode 100644 index 0000000..5c9b650 --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/config/MinioConfig.java @@ -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(); + } +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/controller/FileController.java b/timeline-file-service/src/main/java/com/timeline/file/controller/FileController.java new file mode 100644 index 0000000..ff34eb5 --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/controller/FileController.java @@ -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 getUploadUrl(@PathVariable String fileName) throws Throwable { + String uploadUrl = fileService.generateUploadUrl(fileName); + return ResponseEntity.success(uploadUrl); + } + @GetMapping("/get-download-url/{fileName}") + public ResponseEntity getDownloadUrl(@PathVariable String fileName) throws Throwable { + String downloadUrl = fileService.generateDownloadUrl(fileName); + return ResponseEntity.success(downloadUrl); + } + @PostMapping("/uploaded") + public ResponseEntity uploaded(@RequestBody ImageInfoVo imageInfoVo) throws Throwable { + fileService.saveFileMetadata(imageInfoVo); + return ResponseEntity.success("上传成功"); + } + @PostMapping("/upload-cover") + public ResponseEntity 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 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> getStoryItemImages(@PathVariable String storyItemId) throws Throwable { + List imageIds = fileService.getStoryItemImages(storyItemId); + ArrayList urls = fileService.getAllImageUrls(imageIds); + + return ResponseEntity.success(urls); + } + + /** + * 从 StoryItem 移除一个图片 + */ + @DeleteMapping("/story-item/image/remove") + public ResponseEntity removeImageFromStoryItem( + @RequestParam String imageInstanceId, + @RequestParam String storyItemId) throws Throwable { + + fileService.removeImageFromStoryItem(imageInstanceId, storyItemId); + return ResponseEntity.success("图片已从故事项中移除"); + } +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/dao/CommonRelationMapper.java b/timeline-file-service/src/main/java/com/timeline/file/dao/CommonRelationMapper.java new file mode 100644 index 0000000..431b36a --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/dao/CommonRelationMapper.java @@ -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 getImagesByStoryItemId(String storyItemId); + + List getStoryItemsByImageInstanceId(String imageInstanceId); + + void deleteImageStoryItemRelation(String imageInstanceId, String storyItemId); +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/dao/ImageInfoMapper.java b/timeline-file-service/src/main/java/com/timeline/file/dao/ImageInfoMapper.java new file mode 100644 index 0000000..36fc97a --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/dao/ImageInfoMapper.java @@ -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); +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/entity/ImageInfo.java b/timeline-file-service/src/main/java/com/timeline/file/entity/ImageInfo.java new file mode 100644 index 0000000..c7759e1 --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/entity/ImageInfo.java @@ -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; +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/service/FileService.java b/timeline-file-service/src/main/java/com/timeline/file/service/FileService.java new file mode 100644 index 0000000..48c1403 --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/service/FileService.java @@ -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 listAllImages(); + void deleteImage(String objectKey) throws Throwable; + void associateImageWithStoryItem(String imageInstanceId, String storyItemId, String userId); + List getStoryItemImages(String storyItemId); + void removeImageFromStoryItem(String imageInstanceId, String storyItemId); + ArrayList getAllImageUrls(List images) throws Throwable; + String uploadCover(MultipartFile cover) throws Throwable; + InputStream downloadCover(String coverKey) throws Throwable; +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/service/impl/FileServiceImpl.java b/timeline-file-service/src/main/java/com/timeline/file/service/impl/FileServiceImpl.java new file mode 100644 index 0000000..883f718 --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/service/impl/FileServiceImpl.java @@ -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 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 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 getAllImageUrls(List imageIds) throws Throwable { + ArrayList 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()); + } +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/vo/ImageInfoVo.java b/timeline-file-service/src/main/java/com/timeline/file/vo/ImageInfoVo.java new file mode 100644 index 0000000..da2c8e3 --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/vo/ImageInfoVo.java @@ -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; +} diff --git a/timeline-file-service/src/main/java/com/timeline/file/vo/StoryItemImageRelationVo.java b/timeline-file-service/src/main/java/com/timeline/file/vo/StoryItemImageRelationVo.java new file mode 100644 index 0000000..04656ef --- /dev/null +++ b/timeline-file-service/src/main/java/com/timeline/file/vo/StoryItemImageRelationVo.java @@ -0,0 +1,9 @@ +package com.timeline.file.vo; + +import lombok.Data; + +@Data +public class StoryItemImageRelationVo { + private String imageInstanceId; + private String storyItemId; +} diff --git a/timeline-file-service/src/main/resources/application.properties b/timeline-file-service/src/main/resources/application.properties new file mode 100644 index 0000000..af387c0 --- /dev/null +++ b/timeline-file-service/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/timeline-file-service/src/main/resources/com/timeline/file/dao/CommonRelationMapper.xml b/timeline-file-service/src/main/resources/com/timeline/file/dao/CommonRelationMapper.xml new file mode 100644 index 0000000..0fa26eb --- /dev/null +++ b/timeline-file-service/src/main/resources/com/timeline/file/dao/CommonRelationMapper.xml @@ -0,0 +1,33 @@ + + + + + + INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id) + VALUES (#{imageInstanceId}, #{storyItemId}, 1, #{userId}) + + + + + + + + UPDATE common_relation + SET is_delete = 1 + WHERE rela_id = #{imageInstanceId} AND sub_rela_id = #{storyItemId} + + + + INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id) + VALUES (#{relaId}, #{subRelaId}, #{relationType}, #{userId}) + + diff --git a/timeline-file-service/src/main/resources/com/timeline/file/dao/ImageInfoMapper.xml b/timeline-file-service/src/main/resources/com/timeline/file/dao/ImageInfoMapper.xml new file mode 100644 index 0000000..b140f23 --- /dev/null +++ b/timeline-file-service/src/main/resources/com/timeline/file/dao/ImageInfoMapper.xml @@ -0,0 +1,23 @@ + + + + + + + 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}) + + + + + + DELETE FROM image_info WHERE object_key = #{objectKey} + + + + diff --git a/timeline-story-service/pom.xml b/timeline-story-service/pom.xml new file mode 100644 index 0000000..38a9361 --- /dev/null +++ b/timeline-story-service/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + com.timeline + timeline + 0.0.1-SNAPSHOT + + + timeline-story-service + + + 21 + 21 + UTF-8 + + + + org.projectlombok + lombok + provided + + + org.mybatis + mybatis + 3.5.17 + compile + + + com.timeline + timeline-component-common + 0.0.1-SNAPSHOT + compile + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.4 + + + com.fasterxml.jackson.core + jackson-databind + + + com.alibaba + fastjson + 1.2.83 + + + com.mysql + mysql-connector-j + 8.2.0 + runtime + + + \ No newline at end of file diff --git a/timeline-story-service/src/main/java/com/timeline/story/TimelineStoryServiceApplication.java b/timeline-story-service/src/main/java/com/timeline/story/TimelineStoryServiceApplication.java new file mode 100644 index 0000000..cd6c70b --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/TimelineStoryServiceApplication.java @@ -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); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/config/CorsConfig.java b/timeline-story-service/src/main/java/com/timeline/story/config/CorsConfig.java new file mode 100644 index 0000000..ce8e271 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/config/CorsConfig.java @@ -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); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/config/FeignConfig.java b/timeline-story-service/src/main/java/com/timeline/story/config/FeignConfig.java new file mode 100644 index 0000000..1530b8e --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/config/FeignConfig.java @@ -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(); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/config/JacksonConfig.java b/timeline-story-service/src/main/java/com/timeline/story/config/JacksonConfig.java new file mode 100644 index 0000000..3dac494 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/config/JacksonConfig.java @@ -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")); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/controller/HealthController.java b/timeline-story-service/src/main/java/com/timeline/story/controller/HealthController.java new file mode 100644 index 0000000..8822646 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/controller/HealthController.java @@ -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 ping(){ + return ResponseEntity.success("pong"); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/controller/StoryController.java b/timeline-story-service/src/main/java/com/timeline/story/controller/StoryController.java new file mode 100644 index 0000000..3a087c5 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/controller/StoryController.java @@ -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 hello() { + return ResponseEntity.success("hello"); + } + @GetMapping("/test") + public ResponseEntity test() { + return ResponseEntity.success("Test endpoint"); + } + @PostMapping("/add") + public ResponseEntity createStory(@RequestBody StoryVo storyVo) { + log.info("创建故事: {}", storyVo); + storyService.createStory(storyVo); + return ResponseEntity.success("故事创建成功"); + } + + @PutMapping("/{storyId}") + public ResponseEntity updateStory(@RequestBody StoryVo storyVo, @PathVariable String storyId) { + log.info("更新故事: {},ID: {}", storyVo, storyId); + storyService.updateStory(storyVo, storyId); + return ResponseEntity.success("故事更新成功"); + } + + @DeleteMapping("/{storyId}") + public ResponseEntity deleteStory(@PathVariable String storyId) { + log.info("删除故事, ID: {}", storyId); + storyService.deleteStory(storyId); + return ResponseEntity.success("故事删除成功"); + } + + @GetMapping("/{storyId}") + public ResponseEntity getStoryById(@PathVariable String storyId) { + log.info("获取故事详情, ID: {}", storyId); + Story story = storyService.getStoryById(storyId); + return ResponseEntity.success(story); + } + + @GetMapping("/owner/{ownerId}") + public ResponseEntity> getStoriesByOwnerId(@PathVariable String ownerId) { + log.info("查询用户故事列表, 用户ID: {}", ownerId); + List stories = storyService.getStoriesByOwnerId(ownerId); + return ResponseEntity.success(stories); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/controller/StoryItemController.java b/timeline-story-service/src/main/java/com/timeline/story/controller/StoryItemController.java new file mode 100644 index 0000000..b9dad0d --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/controller/StoryItemController.java @@ -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 createItem(@RequestParam("storyItem") String storyItemVoString, @RequestParam("cover") MultipartFile cover, @RequestParam("images") List images) { + + log.info("创建 StoryItem,{}", storyItemVoString); + storyItemService.createItemWithCover(JSONObject.parseObject(storyItemVoString, StoryItemVo.class), cover, images); + return ResponseEntity.success("StoryItem 创建成功"); + } + + @PutMapping("/{itemId}") + public ResponseEntity 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 deleteItem(@PathVariable String itemId) { + log.info("删除 StoryItem: {}", itemId); + storyItemService.deleteItem(itemId); + return ResponseEntity.success("StoryItem 删除成功"); + } + + @GetMapping("/{itemId}") + public ResponseEntity getItemById(@PathVariable String itemId) { + log.info("获取 StoryItem 详情: {}", itemId); + StoryItem item = storyItemService.getItemById(itemId); + return ResponseEntity.success(item); + } + + @GetMapping("/list") + public ResponseEntity> getItemsByMasterItem(@RequestParam String masterItemId) { + log.info("查询 StoryItem 列表,masterItemId: {}", masterItemId); + List items = storyItemService.getItemsByMasterItem(masterItemId); + return ResponseEntity.success(items); + } + @GetMapping("/images/{itemId}") + public ResponseEntity> getStoryItemImages(@PathVariable String itemId) { + log.info("获取 StoryItem 图片列表,itemId: {}", itemId); + List images = storyItemService.getStoryItemImages(itemId); + return ResponseEntity.success(images); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/dao/CommonRelationMapper.java b/timeline-story-service/src/main/java/com/timeline/story/dao/CommonRelationMapper.java new file mode 100644 index 0000000..b98933c --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/dao/CommonRelationMapper.java @@ -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 getImagesByStoryItemId(String storyItemId); + + List getStoryItemsByImageInstanceId(String imageInstanceId); + + void deleteImageStoryItemRelation(String imageInstanceId, String storyItemId); +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/dao/StoryItemMapper.java b/timeline-story-service/src/main/java/com/timeline/story/dao/StoryItemMapper.java new file mode 100644 index 0000000..7483531 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/dao/StoryItemMapper.java @@ -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 selectByMasterItem(String masterItemId); + List selectImagesByItemId(String itemId); + List selectByMasterItemWithSubItems(String masterItemId); + +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/dao/StoryMapper.java b/timeline-story-service/src/main/java/com/timeline/story/dao/StoryMapper.java new file mode 100644 index 0000000..432de49 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/dao/StoryMapper.java @@ -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 selectByOwnerId(String ownerId); + +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/entity/CommonRelationDTO.java b/timeline-story-service/src/main/java/com/timeline/story/entity/CommonRelationDTO.java new file mode 100644 index 0000000..3ae9321 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/entity/CommonRelationDTO.java @@ -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; +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/entity/Story.java b/timeline-story-service/src/main/java/com/timeline/story/entity/Story.java new file mode 100644 index 0000000..00dd1c7 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/entity/Story.java @@ -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; +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/entity/StoryItem.java b/timeline-story-service/src/main/java/com/timeline/story/entity/StoryItem.java new file mode 100644 index 0000000..22c862d --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/entity/StoryItem.java @@ -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; +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/feign/FileServiceClient.java b/timeline-story-service/src/main/java/com/timeline/story/feign/FileServiceClient.java new file mode 100644 index 0000000..bf7d356 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/feign/FileServiceClient.java @@ -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 uploadCover(@RequestPart("cover") MultipartFile cover); + + @GetMapping("/download/cover/{coverKey}") + InputStreamResource downloadCover(@PathVariable String coverKey); + + @PostMapping("/associate-image") + ResponseEntity associateImageWithStoryItem( + @RequestParam String imageInstanceId, + @RequestParam String storyItemId, + @RequestParam String userId); + + @GetMapping("/story-item/images/{storyItemId}") + ResponseEntity> getStoryItemImages(@PathVariable String storyItemId); +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/service/StoryItemService.java b/timeline-story-service/src/main/java/com/timeline/story/service/StoryItemService.java new file mode 100644 index 0000000..d542b16 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/service/StoryItemService.java @@ -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 images); + StoryItemWithCoverVo getStoryItemWithCover(String itemId); + void updateItem(String itemId, String description, String location); + void deleteItem(String itemId); + StoryItem getItemById(String itemId); + List getItemsByMasterItem(String masterItemId); + List getStoryItemImages(String storyItemId); +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/service/StoryService.java b/timeline-story-service/src/main/java/com/timeline/story/service/StoryService.java new file mode 100644 index 0000000..94e2765 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/service/StoryService.java @@ -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 getStoriesByOwnerId(String ownerId); + +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryItemServiceImpl.java b/timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryItemServiceImpl.java new file mode 100644 index 0000000..099e77c --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryItemServiceImpl.java @@ -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 images) { + try { +// 1. 上传封面到 file 服务 + ResponseEntity 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 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 getItemsByMasterItem(String masterItemId) { + return storyItemMapper.selectByMasterItemWithSubItems(masterItemId); + } + + @Override + public List 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); + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryServiceImpl.java b/timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryServiceImpl.java new file mode 100644 index 0000000..1aeda32 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/service/impl/StoryServiceImpl.java @@ -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 getStoriesByOwnerId(String ownerId) { + try { + return storyMapper.selectByOwnerId(ownerId); + } catch (Exception e) { + log.error("查询用户故事列表失败", e); + throw new CustomException(500, "查询用户故事列表失败"); + } + } +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemAddVo.java b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemAddVo.java new file mode 100644 index 0000000..e9401ba --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemAddVo.java @@ -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; +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemVo.java b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemVo.java new file mode 100644 index 0000000..3b0ce05 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemVo.java @@ -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; + +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemWithCoverVo.java b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemWithCoverVo.java new file mode 100644 index 0000000..1e61356 --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryItemWithCoverVo.java @@ -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; +} diff --git a/timeline-story-service/src/main/java/com/timeline/story/vo/StoryVo.java b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryVo.java new file mode 100644 index 0000000..d4d193e --- /dev/null +++ b/timeline-story-service/src/main/java/com/timeline/story/vo/StoryVo.java @@ -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; +} diff --git a/timeline-story-service/src/main/resources/application.properties b/timeline-story-service/src/main/resources/application.properties new file mode 100644 index 0000000..75f5b3b --- /dev/null +++ b/timeline-story-service/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/timeline-story-service/src/main/resources/com/timeline/story/dao/CommonRelationMapper.xml b/timeline-story-service/src/main/resources/com/timeline/story/dao/CommonRelationMapper.xml new file mode 100644 index 0000000..2afb3b1 --- /dev/null +++ b/timeline-story-service/src/main/resources/com/timeline/story/dao/CommonRelationMapper.xml @@ -0,0 +1,33 @@ + + + + + + INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id) + VALUES (#{imageInstanceId}, #{storyItemId}, 1, #{userId}) + + + + + + + + UPDATE common_relation + SET is_delete = 1 + WHERE rela_id = #{imageInstanceId} AND sub_rela_id = #{storyItemId} + + + + INSERT INTO common_relation (rela_id, sub_rela_id, rela_type, user_id) + VALUES (#{relaId}, #{subRelaId}, #{relationType}, #{userId}) + + diff --git a/timeline-story-service/src/main/resources/com/timeline/story/dao/StoryItemMapper.xml b/timeline-story-service/src/main/resources/com/timeline/story/dao/StoryItemMapper.xml new file mode 100644 index 0000000..fb37c97 --- /dev/null +++ b/timeline-story-service/src/main/resources/com/timeline/story/dao/StoryItemMapper.xml @@ -0,0 +1,88 @@ + + + + + + + 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}) + + + + UPDATE story_item + SET description = #{description}, + location = #{location}, + create_id = #{createId}, + update_time = NOW() + WHERE item_id = #{itemId} + + + + DELETE FROM story_item WHERE item_id = #{itemId} + + + + + + + + + + + diff --git a/timeline-story-service/src/main/resources/com/timeline/story/dao/StoryMapper.xml b/timeline-story-service/src/main/resources/com/timeline/story/dao/StoryMapper.xml new file mode 100644 index 0000000..b1cf8b1 --- /dev/null +++ b/timeline-story-service/src/main/resources/com/timeline/story/dao/StoryMapper.xml @@ -0,0 +1,34 @@ + + + + + + + INSERT INTO story (instance_id, title, description, owner_id, status) + VALUES (#{instanceId}, #{title}, #{description}, #{ownerId}, #{status}) + + + + UPDATE story + SET title = #{title}, + description = #{description}, + update_id = #{updateId}, + status = #{status}, + update_time = NOW() + WHERE instance_id = #{instanceId} + + + + UPDATE story SET story.is_delete = 1 WHERE instance_id = #{instanceId} + + + + + + +