main
parent
80f0ad9a09
commit
60438b47a7
@ -0,0 +1,33 @@ |
|||||||
|
HELP.md |
||||||
|
target/ |
||||||
|
!.mvn/wrapper/maven-wrapper.jar |
||||||
|
!**/src/main/** |
||||||
|
!**/src/test/** |
||||||
|
|
||||||
|
### 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/ |
||||||
|
|
||||||
|
### VS Code ### |
||||||
|
.vscode/ |
||||||
|
|
||||||
|
*.DS_Store |
||||||
@ -0,0 +1,310 @@ |
|||||||
|
#!/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 |
||||||
|
# |
||||||
|
# https://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. |
||||||
|
# ---------------------------------------------------------------------------- |
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------- |
||||||
|
# Maven Start Up Batch script |
||||||
|
# |
||||||
|
# Required ENV vars: |
||||||
|
# ------------------ |
||||||
|
# JAVA_HOME - location of a JDK home dir |
||||||
|
# |
||||||
|
# Optional ENV vars |
||||||
|
# ----------------- |
||||||
|
# M2_HOME - location of maven2's installed home dir |
||||||
|
# MAVEN_OPTS - parameters passed to the Java VM when running Maven |
||||||
|
# e.g. to debug Maven itself, use |
||||||
|
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 |
||||||
|
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files |
||||||
|
# ---------------------------------------------------------------------------- |
||||||
|
|
||||||
|
if [ -z "$MAVEN_SKIP_RC" ] ; then |
||||||
|
|
||||||
|
if [ -f /etc/mavenrc ] ; then |
||||||
|
. /etc/mavenrc |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -f "$HOME/.mavenrc" ] ; then |
||||||
|
. "$HOME/.mavenrc" |
||||||
|
fi |
||||||
|
|
||||||
|
fi |
||||||
|
|
||||||
|
# OS specific support. $var _must_ be set to either true or false. |
||||||
|
cygwin=false; |
||||||
|
darwin=false; |
||||||
|
mingw=false |
||||||
|
case "`uname`" in |
||||||
|
CYGWIN*) cygwin=true ;; |
||||||
|
MINGW*) mingw=true;; |
||||||
|
Darwin*) darwin=true |
||||||
|
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home |
||||||
|
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html |
||||||
|
if [ -z "$JAVA_HOME" ]; then |
||||||
|
if [ -x "/usr/libexec/java_home" ]; then |
||||||
|
export JAVA_HOME="`/usr/libexec/java_home`" |
||||||
|
else |
||||||
|
export JAVA_HOME="/Library/Java/Home" |
||||||
|
fi |
||||||
|
fi |
||||||
|
;; |
||||||
|
esac |
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then |
||||||
|
if [ -r /etc/gentoo-release ] ; then |
||||||
|
JAVA_HOME=`java-config --jre-home` |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -z "$M2_HOME" ] ; then |
||||||
|
## resolve links - $0 may be a link to maven's home |
||||||
|
PRG="$0" |
||||||
|
|
||||||
|
# need this for relative symlinks |
||||||
|
while [ -h "$PRG" ] ; do |
||||||
|
ls=`ls -ld "$PRG"` |
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'` |
||||||
|
if expr "$link" : '/.*' > /dev/null; then |
||||||
|
PRG="$link" |
||||||
|
else |
||||||
|
PRG="`dirname "$PRG"`/$link" |
||||||
|
fi |
||||||
|
done |
||||||
|
|
||||||
|
saveddir=`pwd` |
||||||
|
|
||||||
|
M2_HOME=`dirname "$PRG"`/.. |
||||||
|
|
||||||
|
# make it fully qualified |
||||||
|
M2_HOME=`cd "$M2_HOME" && pwd` |
||||||
|
|
||||||
|
cd "$saveddir" |
||||||
|
# echo Using m2 at $M2_HOME |
||||||
|
fi |
||||||
|
|
||||||
|
# For Cygwin, ensure paths are in UNIX format before anything is touched |
||||||
|
if $cygwin ; then |
||||||
|
[ -n "$M2_HOME" ] && |
||||||
|
M2_HOME=`cygpath --unix "$M2_HOME"` |
||||||
|
[ -n "$JAVA_HOME" ] && |
||||||
|
JAVA_HOME=`cygpath --unix "$JAVA_HOME"` |
||||||
|
[ -n "$CLASSPATH" ] && |
||||||
|
CLASSPATH=`cygpath --path --unix "$CLASSPATH"` |
||||||
|
fi |
||||||
|
|
||||||
|
# For Mingw, ensure paths are in UNIX format before anything is touched |
||||||
|
if $mingw ; then |
||||||
|
[ -n "$M2_HOME" ] && |
||||||
|
M2_HOME="`(cd "$M2_HOME"; pwd)`" |
||||||
|
[ -n "$JAVA_HOME" ] && |
||||||
|
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ]; then |
||||||
|
javaExecutable="`which javac`" |
||||||
|
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then |
||||||
|
# readlink(1) is not available as standard on Solaris 10. |
||||||
|
readLink=`which readlink` |
||||||
|
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then |
||||||
|
if $darwin ; then |
||||||
|
javaHome="`dirname \"$javaExecutable\"`" |
||||||
|
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" |
||||||
|
else |
||||||
|
javaExecutable="`readlink -f \"$javaExecutable\"`" |
||||||
|
fi |
||||||
|
javaHome="`dirname \"$javaExecutable\"`" |
||||||
|
javaHome=`expr "$javaHome" : '\(.*\)/bin'` |
||||||
|
JAVA_HOME="$javaHome" |
||||||
|
export JAVA_HOME |
||||||
|
fi |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -z "$JAVACMD" ] ; then |
||||||
|
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" |
||||||
|
else |
||||||
|
JAVACMD="$JAVA_HOME/bin/java" |
||||||
|
fi |
||||||
|
else |
||||||
|
JAVACMD="`which java`" |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then |
||||||
|
echo "Error: JAVA_HOME is not defined correctly." >&2 |
||||||
|
echo " We cannot execute $JAVACMD" >&2 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then |
||||||
|
echo "Warning: JAVA_HOME environment variable is not set." |
||||||
|
fi |
||||||
|
|
||||||
|
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher |
||||||
|
|
||||||
|
# traverses directory structure from process work directory to filesystem root |
||||||
|
# first directory with .mvn subdirectory is considered project base directory |
||||||
|
find_maven_basedir() { |
||||||
|
|
||||||
|
if [ -z "$1" ] |
||||||
|
then |
||||||
|
echo "Path not specified to find_maven_basedir" |
||||||
|
return 1 |
||||||
|
fi |
||||||
|
|
||||||
|
basedir="$1" |
||||||
|
wdir="$1" |
||||||
|
while [ "$wdir" != '/' ] ; do |
||||||
|
if [ -d "$wdir"/.mvn ] ; then |
||||||
|
basedir=$wdir |
||||||
|
break |
||||||
|
fi |
||||||
|
# workaround for JBEAP-8937 (on Solaris 10/Sparc) |
||||||
|
if [ -d "${wdir}" ]; then |
||||||
|
wdir=`cd "$wdir/.."; pwd` |
||||||
|
fi |
||||||
|
# end of workaround |
||||||
|
done |
||||||
|
echo "${basedir}" |
||||||
|
} |
||||||
|
|
||||||
|
# concatenates all lines of a file |
||||||
|
concat_lines() { |
||||||
|
if [ -f "$1" ]; then |
||||||
|
echo "$(tr -s '\n' ' ' < "$1")" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
BASE_DIR=`find_maven_basedir "$(pwd)"` |
||||||
|
if [ -z "$BASE_DIR" ]; then |
||||||
|
exit 1; |
||||||
|
fi |
||||||
|
|
||||||
|
########################################################################################## |
||||||
|
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central |
||||||
|
# This allows using the maven wrapper in projects that prohibit checking in binary data. |
||||||
|
########################################################################################## |
||||||
|
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo "Found .mvn/wrapper/maven-wrapper.jar" |
||||||
|
fi |
||||||
|
else |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." |
||||||
|
fi |
||||||
|
if [ -n "$MVNW_REPOURL" ]; then |
||||||
|
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
||||||
|
else |
||||||
|
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
||||||
|
fi |
||||||
|
while IFS="=" read key value; do |
||||||
|
case "$key" in (wrapperUrl) jarUrl="$value"; break ;; |
||||||
|
esac |
||||||
|
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo "Downloading from: $jarUrl" |
||||||
|
fi |
||||||
|
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" |
||||||
|
if $cygwin; then |
||||||
|
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` |
||||||
|
fi |
||||||
|
|
||||||
|
if command -v wget > /dev/null; then |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo "Found wget ... using wget" |
||||||
|
fi |
||||||
|
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then |
||||||
|
wget "$jarUrl" -O "$wrapperJarPath" |
||||||
|
else |
||||||
|
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" |
||||||
|
fi |
||||||
|
elif command -v curl > /dev/null; then |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo "Found curl ... using curl" |
||||||
|
fi |
||||||
|
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then |
||||||
|
curl -o "$wrapperJarPath" "$jarUrl" -f |
||||||
|
else |
||||||
|
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f |
||||||
|
fi |
||||||
|
|
||||||
|
else |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo "Falling back to using Java to download" |
||||||
|
fi |
||||||
|
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" |
||||||
|
# For Cygwin, switch paths to Windows format before running javac |
||||||
|
if $cygwin; then |
||||||
|
javaClass=`cygpath --path --windows "$javaClass"` |
||||||
|
fi |
||||||
|
if [ -e "$javaClass" ]; then |
||||||
|
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo " - Compiling MavenWrapperDownloader.java ..." |
||||||
|
fi |
||||||
|
# Compiling the Java class |
||||||
|
("$JAVA_HOME/bin/javac" "$javaClass") |
||||||
|
fi |
||||||
|
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then |
||||||
|
# Running the downloader |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo " - Running MavenWrapperDownloader.java ..." |
||||||
|
fi |
||||||
|
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") |
||||||
|
fi |
||||||
|
fi |
||||||
|
fi |
||||||
|
fi |
||||||
|
########################################################################################## |
||||||
|
# End of extension |
||||||
|
########################################################################################## |
||||||
|
|
||||||
|
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} |
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then |
||||||
|
echo $MAVEN_PROJECTBASEDIR |
||||||
|
fi |
||||||
|
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" |
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java |
||||||
|
if $cygwin; then |
||||||
|
[ -n "$M2_HOME" ] && |
||||||
|
M2_HOME=`cygpath --path --windows "$M2_HOME"` |
||||||
|
[ -n "$JAVA_HOME" ] && |
||||||
|
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` |
||||||
|
[ -n "$CLASSPATH" ] && |
||||||
|
CLASSPATH=`cygpath --path --windows "$CLASSPATH"` |
||||||
|
[ -n "$MAVEN_PROJECTBASEDIR" ] && |
||||||
|
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` |
||||||
|
fi |
||||||
|
|
||||||
|
# Provide a "standardized" way to retrieve the CLI args that will |
||||||
|
# work with both Windows and non-Windows executions. |
||||||
|
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" |
||||||
|
export MAVEN_CMD_LINE_ARGS |
||||||
|
|
||||||
|
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain |
||||||
|
|
||||||
|
exec "$JAVACMD" \ |
||||||
|
$MAVEN_OPTS \ |
||||||
|
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ |
||||||
|
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ |
||||||
|
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" |
||||||
@ -0,0 +1,182 @@ |
|||||||
|
@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 https://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 Maven Start Up Batch script |
||||||
|
@REM |
||||||
|
@REM Required ENV vars: |
||||||
|
@REM JAVA_HOME - location of a JDK home dir |
||||||
|
@REM |
||||||
|
@REM Optional ENV vars |
||||||
|
@REM M2_HOME - location of maven2's installed home dir |
||||||
|
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands |
||||||
|
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending |
||||||
|
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven |
||||||
|
@REM e.g. to debug Maven itself, use |
||||||
|
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 |
||||||
|
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files |
||||||
|
@REM ---------------------------------------------------------------------------- |
||||||
|
|
||||||
|
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' |
||||||
|
@echo off |
||||||
|
@REM set title of command window |
||||||
|
title %0 |
||||||
|
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' |
||||||
|
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% |
||||||
|
|
||||||
|
@REM set %HOME% to equivalent of $HOME |
||||||
|
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") |
||||||
|
|
||||||
|
@REM Execute a user defined script before this one |
||||||
|
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre |
||||||
|
@REM check for pre script, once with legacy .bat ending and once with .cmd ending |
||||||
|
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" |
||||||
|
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" |
||||||
|
:skipRcPre |
||||||
|
|
||||||
|
@setlocal |
||||||
|
|
||||||
|
set ERROR_CODE=0 |
||||||
|
|
||||||
|
@REM To isolate internal variables from possible post scripts, we use another setlocal |
||||||
|
@setlocal |
||||||
|
|
||||||
|
@REM ==== START VALIDATION ==== |
||||||
|
if not "%JAVA_HOME%" == "" goto OkJHome |
||||||
|
|
||||||
|
echo. |
||||||
|
echo Error: JAVA_HOME not found in your environment. >&2 |
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2 |
||||||
|
echo location of your Java installation. >&2 |
||||||
|
echo. |
||||||
|
goto error |
||||||
|
|
||||||
|
:OkJHome |
||||||
|
if exist "%JAVA_HOME%\bin\java.exe" goto init |
||||||
|
|
||||||
|
echo. |
||||||
|
echo Error: JAVA_HOME is set to an invalid directory. >&2 |
||||||
|
echo JAVA_HOME = "%JAVA_HOME%" >&2 |
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2 |
||||||
|
echo location of your Java installation. >&2 |
||||||
|
echo. |
||||||
|
goto error |
||||||
|
|
||||||
|
@REM ==== END VALIDATION ==== |
||||||
|
|
||||||
|
:init |
||||||
|
|
||||||
|
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". |
||||||
|
@REM Fallback to current working directory if not found. |
||||||
|
|
||||||
|
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% |
||||||
|
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir |
||||||
|
|
||||||
|
set EXEC_DIR=%CD% |
||||||
|
set WDIR=%EXEC_DIR% |
||||||
|
:findBaseDir |
||||||
|
IF EXIST "%WDIR%"\.mvn goto baseDirFound |
||||||
|
cd .. |
||||||
|
IF "%WDIR%"=="%CD%" goto baseDirNotFound |
||||||
|
set WDIR=%CD% |
||||||
|
goto findBaseDir |
||||||
|
|
||||||
|
:baseDirFound |
||||||
|
set MAVEN_PROJECTBASEDIR=%WDIR% |
||||||
|
cd "%EXEC_DIR%" |
||||||
|
goto endDetectBaseDir |
||||||
|
|
||||||
|
:baseDirNotFound |
||||||
|
set MAVEN_PROJECTBASEDIR=%EXEC_DIR% |
||||||
|
cd "%EXEC_DIR%" |
||||||
|
|
||||||
|
:endDetectBaseDir |
||||||
|
|
||||||
|
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig |
||||||
|
|
||||||
|
@setlocal EnableExtensions EnableDelayedExpansion |
||||||
|
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a |
||||||
|
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% |
||||||
|
|
||||||
|
:endReadAdditionalConfig |
||||||
|
|
||||||
|
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" |
||||||
|
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" |
||||||
|
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain |
||||||
|
|
||||||
|
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
||||||
|
|
||||||
|
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( |
||||||
|
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B |
||||||
|
) |
||||||
|
|
||||||
|
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central |
||||||
|
@REM This allows using the maven wrapper in projects that prohibit checking in binary data. |
||||||
|
if exist %WRAPPER_JAR% ( |
||||||
|
if "%MVNW_VERBOSE%" == "true" ( |
||||||
|
echo Found %WRAPPER_JAR% |
||||||
|
) |
||||||
|
) else ( |
||||||
|
if not "%MVNW_REPOURL%" == "" ( |
||||||
|
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" |
||||||
|
) |
||||||
|
if "%MVNW_VERBOSE%" == "true" ( |
||||||
|
echo Couldn't find %WRAPPER_JAR%, downloading it ... |
||||||
|
echo Downloading from: %DOWNLOAD_URL% |
||||||
|
) |
||||||
|
|
||||||
|
powershell -Command "&{"^ |
||||||
|
"$webclient = new-object System.Net.WebClient;"^ |
||||||
|
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ |
||||||
|
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ |
||||||
|
"}"^ |
||||||
|
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ |
||||||
|
"}" |
||||||
|
if "%MVNW_VERBOSE%" == "true" ( |
||||||
|
echo Finished downloading %WRAPPER_JAR% |
||||||
|
) |
||||||
|
) |
||||||
|
@REM End of extension |
||||||
|
|
||||||
|
@REM Provide a "standardized" way to retrieve the CLI args that will |
||||||
|
@REM work with both Windows and non-Windows executions. |
||||||
|
set MAVEN_CMD_LINE_ARGS=%* |
||||||
|
|
||||||
|
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* |
||||||
|
if ERRORLEVEL 1 goto error |
||||||
|
goto end |
||||||
|
|
||||||
|
:error |
||||||
|
set ERROR_CODE=1 |
||||||
|
|
||||||
|
:end |
||||||
|
@endlocal & set ERROR_CODE=%ERROR_CODE% |
||||||
|
|
||||||
|
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost |
||||||
|
@REM check for post script, once with legacy .bat ending and once with .cmd ending |
||||||
|
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" |
||||||
|
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" |
||||||
|
:skipRcPost |
||||||
|
|
||||||
|
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' |
||||||
|
if "%MAVEN_BATCH_PAUSE%" == "on" pause |
||||||
|
|
||||||
|
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% |
||||||
|
|
||||||
|
exit /B %ERROR_CODE% |
||||||
@ -0,0 +1,181 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||||
|
<version>2.6.1</version> |
||||||
|
<relativePath/> <!-- lookup parent from repository --> |
||||||
|
</parent> |
||||||
|
<groupId>edu.ncst</groupId> |
||||||
|
<artifactId>carbon</artifactId> |
||||||
|
<version>0.0.1-SNAPSHOT</version> |
||||||
|
<name>carbon</name> |
||||||
|
<description>carbon project for Spring Boot</description> |
||||||
|
<properties> |
||||||
|
<java.version>1.8</java.version> |
||||||
|
</properties> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.mybatis.spring.boot</groupId> |
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId> |
||||||
|
<version>2.2.0</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-devtools</artifactId> |
||||||
|
<scope>runtime</scope> |
||||||
|
<optional>true</optional> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>mysql</groupId> |
||||||
|
<artifactId>mysql-connector-java</artifactId> |
||||||
|
<scope>runtime</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.projectlombok</groupId> |
||||||
|
<artifactId>lombok</artifactId> |
||||||
|
<optional>true</optional> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.alibaba</groupId> |
||||||
|
<artifactId>fastjson</artifactId> |
||||||
|
<version>1.2.35</version> |
||||||
|
</dependency> |
||||||
|
<!-- MyBatis --> |
||||||
|
<dependency> |
||||||
|
<groupId>org.mybatis.spring.boot</groupId> |
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId> |
||||||
|
<version>2.1.3</version> |
||||||
|
</dependency> |
||||||
|
<!-- MyBatis Plus --> |
||||||
|
<dependency> |
||||||
|
<groupId>com.baomidou</groupId> |
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId> |
||||||
|
<version>3.3.2</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.baomidou</groupId> |
||||||
|
<artifactId>mybatis-plus-generator</artifactId> |
||||||
|
<version>3.3.2</version> |
||||||
|
</dependency> |
||||||
|
<!-- 数据校验 --> |
||||||
|
<dependency> |
||||||
|
<groupId>javax.validation</groupId> |
||||||
|
<artifactId>validation-api</artifactId> |
||||||
|
<version>2.0.1.Final</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.hibernate</groupId> |
||||||
|
<artifactId>hibernate-validator</artifactId> |
||||||
|
<version>6.0.13.Final</version> |
||||||
|
</dependency> |
||||||
|
<!-- JWT --> |
||||||
|
<dependency> |
||||||
|
<groupId>io.jsonwebtoken</groupId> |
||||||
|
<artifactId>jjwt</artifactId> |
||||||
|
<version>0.9.0</version> |
||||||
|
</dependency> |
||||||
|
<!-- Redis --> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId> |
||||||
|
</dependency> |
||||||
|
<!-- AOP --> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-aop</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.aspectj</groupId> |
||||||
|
<artifactId>aspectjweaver</artifactId> |
||||||
|
<version>1.9.5</version> |
||||||
|
</dependency> |
||||||
|
<!-- DevTools --> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework</groupId> |
||||||
|
<artifactId>springloaded</artifactId> |
||||||
|
<version>1.2.8.RELEASE</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-devtools</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-security</artifactId> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.bouncycastle</groupId> |
||||||
|
<artifactId>bcprov-jdk15on</artifactId> |
||||||
|
<version>1.64</version> |
||||||
|
</dependency> |
||||||
|
<!-- swagger --> |
||||||
|
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> |
||||||
|
<!-- <dependency>--> |
||||||
|
<!-- <groupId>io.springfox</groupId>--> |
||||||
|
<!-- <artifactId>springfox-swagger2</artifactId>--> |
||||||
|
<!-- <version>2.9.2</version>--> |
||||||
|
<!-- </dependency>--> |
||||||
|
<!-- <!– https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui –>--> |
||||||
|
<!-- <dependency>--> |
||||||
|
<!-- <groupId>io.springfox</groupId>--> |
||||||
|
<!-- <artifactId>springfox-swagger-ui</artifactId>--> |
||||||
|
<!-- <version>2.9.2</version>--> |
||||||
|
<!-- </dependency>--> |
||||||
|
|
||||||
|
<!-- <dependency>--> |
||||||
|
<!-- <groupId>io.springfox</groupId>--> |
||||||
|
<!-- <artifactId>springfox-boot-starter</artifactId>--> |
||||||
|
<!-- <version>3.0.0</version>--> |
||||||
|
<!-- </dependency>--> |
||||||
|
<dependency> |
||||||
|
<groupId>com.spring4all</groupId> |
||||||
|
<artifactId>swagger-spring-boot-starter</artifactId> |
||||||
|
<version>1.9.1.RELEASE</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.google.guava</groupId> |
||||||
|
<artifactId>guava</artifactId> |
||||||
|
<version>25.1-jre</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId> |
||||||
|
<optional>true</optional> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.assertj</groupId> |
||||||
|
<artifactId>assertj-core</artifactId> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<build> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||||
|
<configuration> |
||||||
|
<excludes> |
||||||
|
<exclude> |
||||||
|
<groupId>org.projectlombok</groupId> |
||||||
|
<artifactId>lombok</artifactId> |
||||||
|
</exclude> |
||||||
|
</excludes> |
||||||
|
</configuration> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
</project> |
||||||
@ -0,0 +1,33 @@ |
|||||||
|
package edu.ncst.carbon; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; |
||||||
|
import org.mybatis.spring.annotation.MapperScan; |
||||||
|
import org.springframework.boot.SpringApplication; |
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||||
|
import com.spring4all.swagger.EnableSwagger2Doc; |
||||||
|
import org.springframework.cache.annotation.EnableCaching; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.EnableAspectJAutoProxy; |
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement; |
||||||
|
|
||||||
|
|
||||||
|
@EnableSwagger2Doc |
||||||
|
@SpringBootApplication |
||||||
|
@MapperScan(basePackages = {"edu.ncst.carbon.mapper"}) |
||||||
|
@EnableTransactionManagement |
||||||
|
@EnableCaching |
||||||
|
@EnableAspectJAutoProxy(exposeProxy=true) |
||||||
|
public class CarbonSysApplication { |
||||||
|
/** |
||||||
|
* 分页插件 |
||||||
|
*/ |
||||||
|
@Bean |
||||||
|
public PaginationInterceptor paginationInterceptor() { |
||||||
|
return new PaginationInterceptor(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run(CarbonSysApplication.class, args); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
package edu.ncst.carbon.aspect; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
/** |
||||||
|
* 记录操作日志的注解 |
||||||
|
*/ |
||||||
|
@Target({ElementType.METHOD, ElementType.TYPE}) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface LogOperate { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
package edu.ncst.carbon.aspect; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
/** |
||||||
|
* 登录用户用户访问权限 |
||||||
|
*/ |
||||||
|
@Target({ElementType.METHOD, ElementType.TYPE}) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface LoginUserScope { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
package edu.ncst.carbon.config; |
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.security.access.AccessDeniedException; |
||||||
|
import org.springframework.security.web.access.AccessDeniedHandler; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import javax.servlet.ServletException; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class CustomAccessDeniedHandler implements AccessDeniedHandler { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ObjectMapper objectMapper; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { |
||||||
|
response.setContentType("application/json;charset=UTF-8"); |
||||||
|
Map map = new HashMap(); |
||||||
|
map.put("code",403); |
||||||
|
map.put("msg", "无访问权限"); |
||||||
|
map.put("data",""); |
||||||
|
response.setContentType("application/json"); |
||||||
|
response.setStatus(HttpServletResponse.SC_OK); |
||||||
|
response.getWriter().write(objectMapper.writeValueAsString(map)); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,47 @@ |
|||||||
|
|
||||||
|
package edu.ncst.carbon.config; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.serializer.SerializerFeature; |
||||||
|
import com.alibaba.fastjson.support.config.FastJsonConfig; |
||||||
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.http.converter.HttpMessageConverter; |
||||||
|
|
||||||
|
import java.nio.charset.Charset; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
public class JsonConfig { |
||||||
|
|
||||||
|
|
||||||
|
@Bean |
||||||
|
public HttpMessageConverter configureMessageConverters() { |
||||||
|
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); |
||||||
|
FastJsonConfig config = new FastJsonConfig(); |
||||||
|
config.setSerializerFeatures( |
||||||
|
// 保留map空的字段
|
||||||
|
SerializerFeature.WriteMapNullValue, |
||||||
|
// 将String类型的null转成""
|
||||||
|
SerializerFeature.WriteNullStringAsEmpty, |
||||||
|
// 将Number类型的null转成0
|
||||||
|
SerializerFeature.WriteNullNumberAsZero, |
||||||
|
// 将List类型的null转成[]
|
||||||
|
SerializerFeature.WriteNullListAsEmpty, |
||||||
|
// 将Boolean类型的null转成false
|
||||||
|
SerializerFeature.WriteNullBooleanAsFalse, |
||||||
|
// 避免循环引用
|
||||||
|
SerializerFeature.DisableCircularReferenceDetect); |
||||||
|
|
||||||
|
converter.setFastJsonConfig(config); |
||||||
|
converter.setDefaultCharset(Charset.forName("UTF-8")); |
||||||
|
List<MediaType> mediaTypeList = new ArrayList<>(); |
||||||
|
// 解决中文乱码问题,相当于在Controller上的@RequestMapping中加了个属性produces = "application/json"
|
||||||
|
mediaTypeList.add(MediaType.APPLICATION_JSON); |
||||||
|
converter.setSupportedMediaTypes(mediaTypeList); |
||||||
|
return converter; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,59 @@ |
|||||||
|
package edu.ncst.carbon.config; |
||||||
|
|
||||||
|
import org.springframework.cache.annotation.CachingConfigurerSupport; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.data.redis.cache.RedisCacheConfiguration; |
||||||
|
import org.springframework.data.redis.cache.RedisCacheManager; |
||||||
|
import org.springframework.data.redis.cache.RedisCacheWriter; |
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||||
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; |
||||||
|
import org.springframework.data.redis.serializer.RedisSerializationContext; |
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
public class RedisConfig extends CachingConfigurerSupport { |
||||||
|
|
||||||
|
@Bean |
||||||
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { |
||||||
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>(); |
||||||
|
redisTemplate.setConnectionFactory(redisConnectionFactory); |
||||||
|
|
||||||
|
// 解决 key 序列化方式
|
||||||
|
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); |
||||||
|
redisTemplate.setKeySerializer(stringRedisSerializer); |
||||||
|
redisTemplate.setHashKeySerializer(stringRedisSerializer); |
||||||
|
|
||||||
|
// 解决 value 序列化
|
||||||
|
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(); |
||||||
|
redisTemplate.setValueSerializer(genericJackson2JsonRedisSerializer); |
||||||
|
|
||||||
|
return redisTemplate; |
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
public RedisTemplate<String, Serializable> redisCacheTemplate(RedisConnectionFactory connectionFactory) { |
||||||
|
RedisTemplate<String, Serializable> template = new RedisTemplate<>(); |
||||||
|
template.setKeySerializer(new StringRedisSerializer()); |
||||||
|
template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); |
||||||
|
template.setConnectionFactory(connectionFactory); |
||||||
|
return template; |
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
public RedisCacheManager redisCacheManager(RedisTemplate<String, Object> redisTemplate) { |
||||||
|
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(Objects.requireNonNull(redisTemplate.getConnectionFactory())); |
||||||
|
|
||||||
|
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() |
||||||
|
.serializeValuesWith( |
||||||
|
RedisSerializationContext.SerializationPair.fromSerializer(redisTemplate.getValueSerializer()) |
||||||
|
); |
||||||
|
|
||||||
|
return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,218 @@ |
|||||||
|
package edu.ncst.carbon.config; |
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
import edu.ncst.carbon.config.security.DataBaseUrlVoter; |
||||||
|
|
||||||
|
import edu.ncst.carbon.config.security.filter.AuthCheckFilter; |
||||||
|
import edu.ncst.carbon.config.security.filter.LoginFilter; |
||||||
|
import edu.ncst.carbon.config.security.provider.WechatIdLoginProvider; |
||||||
|
import edu.ncst.carbon.exception.CodeMsg; |
||||||
|
import edu.ncst.carbon.service.ILoginLogService; |
||||||
|
import edu.ncst.carbon.service.impl.system.UserServiceImpl; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||||
|
import org.springframework.security.access.AccessDecisionManager; |
||||||
|
import org.springframework.security.access.AccessDecisionVoter; |
||||||
|
import org.springframework.security.access.vote.AuthenticatedVoter; |
||||||
|
import org.springframework.security.access.vote.RoleVoter; |
||||||
|
import org.springframework.security.access.vote.UnanimousBased; |
||||||
|
import org.springframework.security.authentication.AuthenticationManager; |
||||||
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
||||||
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
||||||
|
import org.springframework.security.config.annotation.web.builders.WebSecurity; |
||||||
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
||||||
|
import org.springframework.security.config.http.SessionCreationPolicy; |
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
||||||
|
import org.springframework.security.crypto.password.PasswordEncoder; |
||||||
|
import org.springframework.security.web.access.expression.WebExpressionVoter; |
||||||
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; |
||||||
|
|
||||||
|
import java.io.PrintWriter; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 安全配置 |
||||||
|
*/ |
||||||
|
@Configuration |
||||||
|
@EnableWebSecurity |
||||||
|
@EnableGlobalMethodSecurity(securedEnabled=true) |
||||||
|
public class SecurityConfig extends WebSecurityConfigurerAdapter { |
||||||
|
|
||||||
|
|
||||||
|
@Autowired |
||||||
|
private UserServiceImpl userService; |
||||||
|
@Autowired |
||||||
|
private ILoginLogService loginLogService; |
||||||
|
@Autowired |
||||||
|
private DataBaseUrlVoter dataBaseUrlVoter; |
||||||
|
@Autowired |
||||||
|
private RedisTemplate<String, String> redisCacheTemplate; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private WechatIdLoginProvider wechatIdLoginProvider; |
||||||
|
/** |
||||||
|
* 认证失败处理类 |
||||||
|
*/ |
||||||
|
@Autowired |
||||||
|
CustomAccessDeniedHandler accessDeniedHandler; |
||||||
|
|
||||||
|
//org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126)
|
||||||
|
/** |
||||||
|
* 解决 无法直接注入 AuthenticationManager |
||||||
|
* |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
@Bean |
||||||
|
@Override |
||||||
|
public AuthenticationManager authenticationManagerBean() throws Exception |
||||||
|
{ |
||||||
|
return super.authenticationManagerBean(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 权限白名单 |
||||||
|
* 注意:该名单下匹配的 URL 不会经过鉴权,因此也无法获取当前用户的信息 |
||||||
|
*/ |
||||||
|
private final String[] WHITE_LIST = { |
||||||
|
"/v2/api-docs", |
||||||
|
"/configuration/ui", |
||||||
|
"/swagger-resources/**", |
||||||
|
"/configuration/**", |
||||||
|
"/swagger-ui.html", |
||||||
|
"/webjars/**", |
||||||
|
"/api/captcha.jpg", |
||||||
|
"/websocket/**", |
||||||
|
"/api/image/get/**", |
||||||
|
"/common/download/**", |
||||||
|
"/test/**", |
||||||
|
"/*.html", |
||||||
|
"/**/*.html", |
||||||
|
"/**/*.css", |
||||||
|
"/**/*.js", |
||||||
|
"/error*" |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* 密码加密器 |
||||||
|
*/ |
||||||
|
@Bean |
||||||
|
public PasswordEncoder passwordEncoderBean() { |
||||||
|
return new BCryptPasswordEncoder(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 权限投票访问决策管理器 |
||||||
|
*/ |
||||||
|
@Bean |
||||||
|
public AccessDecisionManager accessDecisionManager() { |
||||||
|
List<AccessDecisionVoter<? extends Object>> decisionVoters |
||||||
|
= Arrays.asList( |
||||||
|
new WebExpressionVoter(), |
||||||
|
new RoleVoter(),//主要用来判断当前请求是否具备该接口所需要的角色
|
||||||
|
dataBaseUrlVoter, |
||||||
|
new AuthenticatedVoter()); |
||||||
|
return new UnanimousBased(decisionVoters);//要求所有 AccessDecisionVoter 均返回肯定的结果时,才代表授予权限。
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 此处给AuthenticationManager添加登陆验证的逻辑。 |
||||||
|
* 这里添加了两个AuthenticationProvider分别用于用户名密码登陆的验证以及token授权登陆两种方式。 |
||||||
|
* 在处理登陆信息的过滤器执行的时候会调用这两个provider进行登陆验证。 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception { |
||||||
|
auth.userDetailsService(userService); |
||||||
|
auth.authenticationProvider(wechatIdLoginProvider); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* anyRequest | 匹配所有请求路径 |
||||||
|
* access | SpringEl表达式结果为true时可以访问 |
||||||
|
* anonymous | 匿名可以访问 |
||||||
|
* denyAll | 用户不能访问 |
||||||
|
* fullyAuthenticated | 用户完全认证可以访问(非remember-me下自动登录) |
||||||
|
* hasAnyAuthority | 如果有参数,参数表示权限,则其中任何一个权限可以访问 |
||||||
|
* hasAnyRole | 如果有参数,参数表示角色,则其中任何一个角色可以访问 |
||||||
|
* hasAuthority | 如果有参数,参数表示权限,则其权限可以访问 |
||||||
|
* hasIpAddress | 如果有参数,参数表示IP地址,如果用户IP和参数匹配,则可以访问 |
||||||
|
* hasRole | 如果有参数,参数表示角色,则其角色可以访问 |
||||||
|
* permitAll | 用户可以任意访问 |
||||||
|
* rememberMe | 允许通过remember-me登录的用户访问 |
||||||
|
* authenticated | 用户登录后可访问 |
||||||
|
*/ |
||||||
|
//权限验证 基于资源配置
|
||||||
|
// HttpSecurity 及WebSecurity 作用是不一样的:
|
||||||
|
// WebSecurity 主要针对的全局的忽略规则,
|
||||||
|
// HttpSecurity主要是权限控制规则。
|
||||||
|
@Override |
||||||
|
protected void configure(HttpSecurity http) throws Exception { |
||||||
|
|
||||||
|
//允许跨域
|
||||||
|
http.cors().and().anonymous().and() |
||||||
|
// CRSF禁用,因为不使用session
|
||||||
|
.csrf().disable() |
||||||
|
.formLogin().disable().httpBasic().disable() |
||||||
|
.authorizeRequests() |
||||||
|
.accessDecisionManager(accessDecisionManager())//访问决策管理器
|
||||||
|
.antMatchers("/api/login").permitAll() |
||||||
|
.antMatchers("/system/init").permitAll() |
||||||
|
// 除上面外的所有请求全部需要鉴权认证
|
||||||
|
.anyRequest().authenticated() |
||||||
|
// 授权异常处理,权限拦截器,提示用户没有当前权限
|
||||||
|
.and().exceptionHandling().accessDeniedHandler(accessDeniedHandler).and() |
||||||
|
// 不需要session(不创建会话)
|
||||||
|
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); |
||||||
|
|
||||||
|
// LoginFilter:统一登录接口
|
||||||
|
// AuthCheckFilter:用户凭证检查过滤器
|
||||||
|
http.addFilterBefore( new AuthCheckFilter(redisCacheTemplate), UsernamePasswordAuthenticationFilter.class ) |
||||||
|
.addFilterAt( new LoginFilter(authenticationManager(), loginLogService, redisCacheTemplate), UsernamePasswordAuthenticationFilter.class ) |
||||||
|
.exceptionHandling()//登录认证失败
|
||||||
|
.authenticationEntryPoint(((request, response, authException) -> { |
||||||
|
response.setCharacterEncoding("utf-8"); |
||||||
|
response.setContentType("application/json;charset=utf-8"); |
||||||
|
|
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
out.write(new ObjectMapper().writeValueAsString(ResultUtils.error(CodeMsg.USER_NEED_LOGIN))); |
||||||
|
out.flush(); |
||||||
|
out.close(); |
||||||
|
})); |
||||||
|
|
||||||
|
// 退出登录
|
||||||
|
http.logout() |
||||||
|
.logoutUrl("/logout") |
||||||
|
.deleteCookies("JSESSIONID") |
||||||
|
.logoutSuccessHandler(((request, response, authentication) -> { |
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
response.setContentType("application/json"); |
||||||
|
out.write(new ObjectMapper().writeValueAsString(ResultUtils.success("注销成功"))); |
||||||
|
out.flush(); |
||||||
|
out.close(); |
||||||
|
})); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// protected void configure(HttpSecurity httpSecurity) throws Exception{
|
||||||
|
// //调试阶段
|
||||||
|
// httpSecurity.csrf().disable().authorizeRequests();
|
||||||
|
// httpSecurity.authorizeRequests().anyRequest()
|
||||||
|
// .permitAll().and().logout().permitAll();
|
||||||
|
// }
|
||||||
|
|
||||||
|
//用于配置全局的某些通用事物,例如静态资源等
|
||||||
|
@Override |
||||||
|
public void configure(WebSecurity web) throws Exception { |
||||||
|
web.ignoring().antMatchers(WHITE_LIST); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
package edu.ncst.carbon.config.exception; |
||||||
|
|
||||||
|
import org.springframework.security.core.AuthenticationException; |
||||||
|
|
||||||
|
public class CodeBeenUsedException extends AuthenticationException { |
||||||
|
public CodeBeenUsedException(String msg, Throwable t) { |
||||||
|
super(msg, t); |
||||||
|
} |
||||||
|
|
||||||
|
public CodeBeenUsedException(String msg) { |
||||||
|
super(msg); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
package edu.ncst.carbon.config.exception; |
||||||
|
|
||||||
|
import org.springframework.security.core.AuthenticationException; |
||||||
|
|
||||||
|
public class NotBindUserException extends AuthenticationException { |
||||||
|
|
||||||
|
public NotBindUserException(String msg, Throwable t) { |
||||||
|
super(msg, t); |
||||||
|
} |
||||||
|
|
||||||
|
public NotBindUserException(String msg) { |
||||||
|
super(msg); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,109 @@ |
|||||||
|
package edu.ncst.carbon.config.security; |
||||||
|
|
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import edu.ncst.carbon.service.IResourceService; |
||||||
|
import edu.ncst.carbon.utils.URLUtils; |
||||||
|
import edu.ncst.carbon.vo.user.UserInfoVO; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.security.access.AccessDecisionVoter; |
||||||
|
import org.springframework.security.access.ConfigAttribute; |
||||||
|
import org.springframework.security.core.Authentication; |
||||||
|
import org.springframework.security.core.GrantedAuthority; |
||||||
|
import org.springframework.security.web.FilterInvocation; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
import org.springframework.util.AntPathMatcher; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* URL 鉴权投票器 |
||||||
|
*/ |
||||||
|
@Component |
||||||
|
public class DataBaseUrlVoter implements AccessDecisionVoter<FilterInvocation> { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private IResourceService resourceService; |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean supports(ConfigAttribute attribute) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean supports(Class<?> clazz) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int vote(Authentication authentication, FilterInvocation fi, Collection<ConfigAttribute> attributes) { |
||||||
|
if (authentication == null) { |
||||||
|
return ACCESS_DENIED; // 反对票
|
||||||
|
} |
||||||
|
|
||||||
|
String url = fi.getRequestUrl(); // 当前请求的URL
|
||||||
|
String urlWithoutQueryString = URLUtils.removeQueryString(url); |
||||||
|
|
||||||
|
// Current User Info
|
||||||
|
Object details = authentication.getDetails(); |
||||||
|
|
||||||
|
if (details instanceof UserInfoVO) { |
||||||
|
UserInfoVO userInfoVO = (UserInfoVO) details; |
||||||
|
AntPathMatcher antPathMatcher = new AntPathMatcher(); |
||||||
|
|
||||||
|
//获取不限用户角色的资源
|
||||||
|
List<String> permitAllResourceURLs = resourceService.getPermitAllResourceURLs(); |
||||||
|
// Permit All Resource
|
||||||
|
for (String permitUrl : permitAllResourceURLs) { |
||||||
|
boolean match = antPathMatcher.match(permitUrl, urlWithoutQueryString); |
||||||
|
if (match) { |
||||||
|
return ACCESS_GRANTED; // 赞同票
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 判断用户角色信息
|
||||||
|
// 反对票:1、没有角色信息 2、角色未绑定该资源
|
||||||
|
// 赞成票:用户是超级管理员
|
||||||
|
|
||||||
|
List<Role> roles = userInfoVO.getRoles(); |
||||||
|
if (roles == null || roles.isEmpty()) { |
||||||
|
return ACCESS_DENIED; // 反对票
|
||||||
|
} |
||||||
|
|
||||||
|
List<String> roleNames = roles.stream().map(Role::getName).collect(Collectors.toList()); |
||||||
|
|
||||||
|
// Super Admin User Always Pass
|
||||||
|
if (roleNames.contains("SUPER_ADMIN")) { |
||||||
|
return ACCESS_GRANTED; // 赞同票
|
||||||
|
} |
||||||
|
|
||||||
|
List<String> rolesResourceList = resourceService.getRolesResourceList(roleNames);//获取目标角色绑定的资源
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Role Resource
|
||||||
|
if (rolesResourceList == null) { |
||||||
|
return ACCESS_DENIED; // 反对票
|
||||||
|
} |
||||||
|
|
||||||
|
for (String allowUrl : rolesResourceList) { |
||||||
|
boolean match = antPathMatcher.match(allowUrl, urlWithoutQueryString); |
||||||
|
if (match) { |
||||||
|
return ACCESS_GRANTED; // 赞同票
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return ACCESS_DENIED; |
||||||
|
} |
||||||
|
|
||||||
|
Collection<? extends GrantedAuthority> extractAuthorities( |
||||||
|
Authentication authentication) { |
||||||
|
return authentication.getAuthorities(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,121 @@ |
|||||||
|
package edu.ncst.carbon.config.security.filter; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
import edu.ncst.carbon.config.security.token.JwtAuthenticationToken; |
||||||
|
import edu.ncst.carbon.exception.CodeMsg; |
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.user.UserInfoVO; |
||||||
|
import io.jsonwebtoken.Claims; |
||||||
|
import io.jsonwebtoken.ExpiredJwtException; |
||||||
|
import io.jsonwebtoken.Jws; |
||||||
|
import io.jsonwebtoken.Jwts; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||||
|
import org.springframework.security.core.GrantedAuthority; |
||||||
|
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
||||||
|
import org.springframework.security.core.context.SecurityContextHolder; |
||||||
|
import org.springframework.web.filter.OncePerRequestFilter; |
||||||
|
|
||||||
|
import javax.servlet.FilterChain; |
||||||
|
import javax.servlet.ServletException; |
||||||
|
import javax.servlet.http.Cookie; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户凭证检查过滤器 |
||||||
|
* 并不是所有的container都像我们期望的只过滤一次,servlet版本不同,表现也不同 |
||||||
|
* OncePerRequestFilter可以保证一次请求只通过一次过滤器。推荐自定义的授权过滤器继承OncePerRequestFilter |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
public class AuthCheckFilter extends OncePerRequestFilter { |
||||||
|
private final RedisTemplate<String, String> stringRedisTemplate; |
||||||
|
|
||||||
|
public AuthCheckFilter(RedisTemplate<String, String> stringRedisTemplate) { |
||||||
|
super(); |
||||||
|
this.stringRedisTemplate = stringRedisTemplate; |
||||||
|
} |
||||||
|
@Override |
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { |
||||||
|
String jwtToken = null; |
||||||
|
|
||||||
|
// 优先从 Cookie 中获取 TOKEN
|
||||||
|
Cookie[] cookies = request.getCookies(); |
||||||
|
|
||||||
|
boolean cookieHasToken = false; |
||||||
|
if (cookies != null) { |
||||||
|
for (Cookie cookie : cookies) { |
||||||
|
if ("SYS_TOKEN".equals(cookie.getName())) { |
||||||
|
jwtToken = cookie.getValue(); |
||||||
|
cookieHasToken = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 如果 Cookie 中不存在 TOKEN,则尝试从 Header 中获取 TOKEN
|
||||||
|
if (!cookieHasToken) { |
||||||
|
String authorization = request.getHeader("Authorization"); |
||||||
|
log.info("开始鉴权====header Authorization====" + authorization); |
||||||
|
if (authorization != null && authorization.startsWith("Bearer ")) { |
||||||
|
jwtToken = authorization.replace("Bearer ", ""); |
||||||
|
log.info("获取到token====header===="); |
||||||
|
} else { |
||||||
|
log.info("header中无token,进入过滤器链"); |
||||||
|
filterChain.doFilter(request, response); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (jwtToken == null || "".equals(jwtToken)) { |
||||||
|
log.error("鉴权TOKEN:未获取,用户需要登录"); |
||||||
|
ResultVO<Object> resultVO = ResultUtils.error(CodeMsg.USER_NEED_LOGIN); |
||||||
|
ResponseUtils.output(response, resultVO); |
||||||
|
} else { |
||||||
|
log.info("鉴权TOKEN:" +"Bearer " + jwtToken); |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
// 解析TOKEN
|
||||||
|
Jws<Claims> jws = Jwts.parser().setSigningKey("ncst20221003") |
||||||
|
.parseClaimsJws(jwtToken); |
||||||
|
|
||||||
|
Claims claims = jws.getBody(); |
||||||
|
String userName = claims.getSubject(); |
||||||
|
//可以通过控制redis数据从服务端强制下线用户
|
||||||
|
if(!stringRedisTemplate.hasKey("jwt_token:"+userName)){ |
||||||
|
throw new ExpiredJwtException(null,jws.getBody(),"登录失效"); |
||||||
|
} |
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
String userInfoJSON = (String) claims.get("userInfo"); |
||||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||||
|
UserInfoVO userInfoVO = objectMapper.readValue(userInfoJSON, UserInfoVO.class); |
||||||
|
|
||||||
|
// 获取角色列表
|
||||||
|
List<Role> roles = userInfoVO.getRoles(); |
||||||
|
List<GrantedAuthority> authorities = new ArrayList<>(); |
||||||
|
|
||||||
|
if (roles != null && !roles.isEmpty()) { |
||||||
|
for (Role role : roles) { |
||||||
|
authorities.add(new SimpleGrantedAuthority("ROLE_" + role.getName())); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 将 TOKEN 存到 CONTEXT 当中
|
||||||
|
JwtAuthenticationToken token = new JwtAuthenticationToken(userName, authorities, userInfoVO); |
||||||
|
SecurityContextHolder.getContext().setAuthentication(token); |
||||||
|
} catch (ExpiredJwtException e) { |
||||||
|
ResultVO<Object> resultVO = ResultUtils.error(CodeMsg.USER_TOKEN_EXPIRED);// 用户凭证过期
|
||||||
|
ResponseUtils.output(response, resultVO); |
||||||
|
} finally { |
||||||
|
filterChain.doFilter(request, response); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,322 @@ |
|||||||
|
package edu.ncst.carbon.config.security.filter; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
import edu.ncst.carbon.config.security.token.MobileCaptchaAuthenticationToken; |
||||||
|
import edu.ncst.carbon.config.security.token.WechatIdAuthenticationToken; |
||||||
|
import edu.ncst.carbon.exception.BusinessException; |
||||||
|
import edu.ncst.carbon.exception.CodeMsg; |
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import edu.ncst.carbon.model.system.User; |
||||||
|
import edu.ncst.carbon.service.ILoginLogService; |
||||||
|
import edu.ncst.carbon.utils.CookieUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.utils.WeChatUtils; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.user.UserInfoVO; |
||||||
|
import edu.ncst.carbon.vo.user.UserLoginDTO; |
||||||
|
import edu.ncst.carbon.vo.wechat.AccessTokenDTO; |
||||||
|
import io.jsonwebtoken.Jwts; |
||||||
|
import io.jsonwebtoken.SignatureAlgorithm; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||||
|
import org.springframework.http.HttpMethod; |
||||||
|
import org.springframework.security.authentication.*; |
||||||
|
import org.springframework.security.core.Authentication; |
||||||
|
import org.springframework.security.core.AuthenticationException; |
||||||
|
import org.springframework.security.core.GrantedAuthority; |
||||||
|
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; |
||||||
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
||||||
|
|
||||||
|
import javax.servlet.FilterChain; |
||||||
|
import javax.servlet.ServletException; |
||||||
|
import javax.servlet.http.Cookie; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.PrintWriter; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 统一登录入口 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
public class LoginFilter extends AbstractAuthenticationProcessingFilter {//OncePerRequestFilter
|
||||||
|
|
||||||
|
private static final String loginUrl = "/api/login"; |
||||||
|
|
||||||
|
private final ILoginLogService loginLogService; |
||||||
|
|
||||||
|
private final RedisTemplate<String, String> stringRedisTemplate; |
||||||
|
|
||||||
|
private String tempToken=""; |
||||||
|
private final int MAX_ATTEMPT = 20; |
||||||
|
|
||||||
|
public LoginFilter(AuthenticationManager authenticationManager, ILoginLogService loginLogService, RedisTemplate<String, String> stringRedisTemplate) { |
||||||
|
super(new AntPathRequestMatcher(loginUrl, HttpMethod.POST.name())); |
||||||
|
setAuthenticationManager(authenticationManager); |
||||||
|
this.loginLogService = loginLogService; |
||||||
|
this.stringRedisTemplate = stringRedisTemplate; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 尝试登录 |
||||||
|
* 根据登录表单的类型(type)将登录凭证分发给对应的 AuthenticationProvider |
||||||
|
* 当前filter的认证逻辑 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Authentication attemptAuthentication( |
||||||
|
HttpServletRequest request, HttpServletResponse response |
||||||
|
) throws AuthenticationException, IOException, ServletException { |
||||||
|
UserLoginDTO paramUserLoginVO = new ObjectMapper().readValue(request.getInputStream(), UserLoginDTO.class); |
||||||
|
AuthenticationManager authenticationManager = getAuthenticationManager(); |
||||||
|
|
||||||
|
request.setAttribute("userLoginVO", paramUserLoginVO); |
||||||
|
log.info("尝试登录===="+ paramUserLoginVO); |
||||||
|
|
||||||
|
/* |
||||||
|
WechatIdAuthenticationToken token = new WechatIdAuthenticationToken(paramUserLoginVO.getWeChatCode()); |
||||||
|
request.setAttribute("token", token); |
||||||
|
return authenticationManager.authenticate(token); |
||||||
|
*/ |
||||||
|
|
||||||
|
// 登录类型
|
||||||
|
String loginType = paramUserLoginVO.getType(); |
||||||
|
log.info("loginType:" + loginType); |
||||||
|
|
||||||
|
if ("ACCOUNT".equalsIgnoreCase(loginType)) { |
||||||
|
// 校验 TOKEN
|
||||||
|
Cookie tempTokenCookie = CookieUtils.getCookie(request, "TEMP_TOKEN"); |
||||||
|
|
||||||
|
|
||||||
|
if (tempTokenCookie == null || "".equals(tempTokenCookie.getValue())) { |
||||||
|
throw new InternalAuthenticationServiceException("无效的请求"); |
||||||
|
} |
||||||
|
|
||||||
|
String tempToken = tempTokenCookie.getValue(); |
||||||
|
Boolean tokenIsValid = stringRedisTemplate.hasKey("tempToken:" + tempToken); |
||||||
|
|
||||||
|
if (tokenIsValid == null || !tokenIsValid) { |
||||||
|
throw new InternalAuthenticationServiceException("无效的请求"); |
||||||
|
} |
||||||
|
|
||||||
|
// 校验验证码
|
||||||
|
String rightCaptcha = stringRedisTemplate.opsForValue().get("captcha:" + tempToken); |
||||||
|
String loginCaptcha = paramUserLoginVO.getLoginCaptcha(); |
||||||
|
/* |
||||||
|
if (loginCaptcha == null || "".equals(loginCaptcha)) { |
||||||
|
throw new CaptchaIsEmptyException(CodeMsg.CAPTCHA_IS_NOT_RIGHT.getMsg()); |
||||||
|
} else if (rightCaptcha == null || "".equals(rightCaptcha)) { |
||||||
|
throw new CaptchaIsExpiredException(CodeMsg.CAPTCHA_IS_EXPIRED.getMsg()); |
||||||
|
} else if (!loginCaptcha.equalsIgnoreCase(rightCaptcha)) { |
||||||
|
throw new CaptchaIsNotRightException(CodeMsg.CAPTCHA_IS_NOT_RIGHT.getMsg()); |
||||||
|
} |
||||||
|
*/ |
||||||
|
|
||||||
|
// 用户名密码登录,用户名可以是用户账号名、手机号或电子邮箱
|
||||||
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(paramUserLoginVO.getUsername(), paramUserLoginVO.getPassword()); |
||||||
|
request.setAttribute("token", token); |
||||||
|
|
||||||
|
return authenticationManager.authenticate(token); |
||||||
|
} else if ("MOBILE".equalsIgnoreCase(loginType)) { |
||||||
|
// 手机号验证码登录
|
||||||
|
MobileCaptchaAuthenticationToken token = new MobileCaptchaAuthenticationToken(paramUserLoginVO.getPhone(), paramUserLoginVO.getMobileCaptcha()); |
||||||
|
request.setAttribute("token", token); |
||||||
|
|
||||||
|
return authenticationManager.authenticate(token); |
||||||
|
} else if ("WECHAT".equalsIgnoreCase(loginType)) { |
||||||
|
// 微信登录凭证登录
|
||||||
|
// 如何获取登录凭证:https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html
|
||||||
|
// 通过微信登录凭证获取OpenID:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
|
||||||
|
WechatIdAuthenticationToken token = new WechatIdAuthenticationToken(paramUserLoginVO.getWeChatCode()); |
||||||
|
request.setAttribute("token", token); |
||||||
|
|
||||||
|
return authenticationManager.authenticate(token); |
||||||
|
} else { |
||||||
|
throw new AuthenticationServiceException("登录方式错误"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public Authentication attemptAuthentication(
|
||||||
|
// HttpServletRequest request, HttpServletResponse response
|
||||||
|
// ) throws AuthenticationException, IOException, ServletException {
|
||||||
|
// UserLoginDTO paramUserLoginVO = new ObjectMapper().readValue(request.getInputStream(), UserLoginDTO.class);
|
||||||
|
// AuthenticationManager authenticationManager = getAuthenticationManager();
|
||||||
|
//
|
||||||
|
// request.setAttribute("userLoginVO", paramUserLoginVO);
|
||||||
|
// log.info("尝试登录====" + paramUserLoginVO);
|
||||||
|
//
|
||||||
|
// // 登录类型
|
||||||
|
// String loginType = paramUserLoginVO.getType();
|
||||||
|
// log.info("loginType" + loginType);
|
||||||
|
// log.info("尝试登录");
|
||||||
|
//
|
||||||
|
// if ("ACCOUNT".equalsIgnoreCase(loginType)) {
|
||||||
|
// // 校验 TOKEN
|
||||||
|
// Cookie tempTokenCookie = CookieUtils.getCookie(request, "TEMP_TOKEN");
|
||||||
|
//
|
||||||
|
// if (tempTokenCookie == null || "".equals(tempTokenCookie.getValue())) {
|
||||||
|
// throw new InternalAuthenticationServiceException("无效的请求");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// String tempToken = tempTokenCookie.getValue();
|
||||||
|
// Boolean tokenIsValid = stringRedisTemplate.hasKey("tempToken:" + tempToken);
|
||||||
|
//
|
||||||
|
// if (tokenIsValid == null || !tokenIsValid) {
|
||||||
|
// throw new InternalAuthenticationServiceException("无效的请求");
|
||||||
|
// }
|
||||||
|
// // 校验验证码
|
||||||
|
// String rightCaptcha = stringRedisTemplate.opsForValue().get("captcha:" + tempToken);
|
||||||
|
// String loginCaptcha = paramUserLoginVO.getLoginCaptcha();
|
||||||
|
//
|
||||||
|
// // 用户名密码登录,用户名可以是用户账号名、手机号或电子邮箱
|
||||||
|
// UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(paramUserLoginVO.getUsername(), paramUserLoginVO.getPassword());
|
||||||
|
// request.setAttribute("token", token);
|
||||||
|
//
|
||||||
|
// return authenticationManager.authenticate(token);
|
||||||
|
// } else {
|
||||||
|
// throw new AuthenticationServiceException("登录方式错误");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 登录成功 |
||||||
|
* 无论以何种方式登录,登录成功后都向客户端返回 JWT,前端将该 JWT 临时存储到 localStorage 当中,以便后续的请求在请求头中携带 JWT。 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected void successfulAuthentication( |
||||||
|
HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult |
||||||
|
) throws IOException { |
||||||
|
Object principal = authResult.getPrincipal(); |
||||||
|
log.info("principal:" + principal); |
||||||
|
UserInfoVO userInfoVO = new UserInfoVO(); |
||||||
|
if (principal instanceof User) { |
||||||
|
User user = (User) principal; |
||||||
|
BeanUtils.copyProperties(user, userInfoVO); |
||||||
|
} |
||||||
|
log.info("userInfoVO:" + userInfoVO); |
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper(); |
||||||
|
String userInfoJSON = objectMapper.writeValueAsString(userInfoVO); |
||||||
|
|
||||||
|
// UUID uuid = UUID.randomUUID();
|
||||||
|
// String jwtTokenId = uuid.toString();
|
||||||
|
String openId = stringRedisTemplate.opsForValue().get("user_openid:"+ userInfoVO.getUsername()); |
||||||
|
if(openId==null){ |
||||||
|
openId= ""; |
||||||
|
} |
||||||
|
|
||||||
|
log.info("openId:" + openId);//这里是空的???
|
||||||
|
|
||||||
|
/* |
||||||
|
* Jwts组成:第一部分为头部header,第二部分为载荷payload(可以理解为消息主体),第三部分为签证signature |
||||||
|
* */ |
||||||
|
// 生成 jwt
|
||||||
|
String jwt = Jwts.builder() |
||||||
|
// 注入参数
|
||||||
|
.claim("userInfo", userInfoJSON) |
||||||
|
.setSubject(authResult.getName()) |
||||||
|
// 设置过期时间
|
||||||
|
.setExpiration(new Date(System.currentTimeMillis() + 48 * 60 * 60 * 1000)) // 60小时有效
|
||||||
|
// 设置算法及密钥
|
||||||
|
.signWith(SignatureAlgorithm.HS512, "ncst20221003") |
||||||
|
.setId(openId) |
||||||
|
.compact(); |
||||||
|
|
||||||
|
log.info("生成jwt====" + jwt); |
||||||
|
stringRedisTemplate.opsForValue().set("jwt_token:"+authResult.getName(),jwt); |
||||||
|
// stringRedisTemplate.delete("user_attempts:"+request.getRemoteAddr());
|
||||||
|
// 记录登录日志
|
||||||
|
loginLogService.addLoginLog(userInfoVO.getId(), true); |
||||||
|
|
||||||
|
// 返回结果
|
||||||
|
ResultVO<String> result = ResultUtils.success("登录成功", jwt); |
||||||
|
response.setContentType("application/json;charset=utf-8"); |
||||||
|
Cookie cookieToken = new Cookie("SYS_TOKEN", jwt); |
||||||
|
cookieToken.setHttpOnly(true); |
||||||
|
response.addCookie(cookieToken); |
||||||
|
|
||||||
|
log.info("登录成功"); |
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
out.print(new ObjectMapper().writeValueAsString(result)); |
||||||
|
out.flush(); |
||||||
|
out.close(); |
||||||
|
} |
||||||
|
|
||||||
|
// 将权限列表转换成逗号分隔的字符串
|
||||||
|
private String convertRoleToString(List<Role> roleList) { |
||||||
|
StringBuilder roleStrings = new StringBuilder(); |
||||||
|
|
||||||
|
if (roleList == null) { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
for (Role role : roleList) { |
||||||
|
roleStrings.append(role.getName()).append(","); |
||||||
|
} |
||||||
|
|
||||||
|
if (roleStrings.length() > 0) { |
||||||
|
roleStrings.deleteCharAt(roleStrings.length() - 1); |
||||||
|
} |
||||||
|
|
||||||
|
return roleStrings.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
// 将权限列表转换成逗号分隔的字符串
|
||||||
|
private String convertAuthorityToString(Collection<? extends GrantedAuthority> authorities) { |
||||||
|
StringBuilder authorityString = new StringBuilder(); |
||||||
|
|
||||||
|
for (GrantedAuthority authority : authorities) { |
||||||
|
authorityString.append(authority.getAuthority()).append(","); |
||||||
|
} |
||||||
|
|
||||||
|
if (authorityString.length() > 0) { |
||||||
|
authorityString.deleteCharAt(authorityString.length() - 1); |
||||||
|
} |
||||||
|
|
||||||
|
return authorityString.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 登录失败 |
||||||
|
* 向前端返回登录失败的错误信息 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException { |
||||||
|
ResultVO<?> resultVO; |
||||||
|
log.debug("登录失败:"+failed); |
||||||
|
if (failed instanceof LockedException) { |
||||||
|
resultVO = ResultUtils.error(CodeMsg.USER_IS_LOCKED); |
||||||
|
} else if (failed instanceof CredentialsExpiredException) { |
||||||
|
resultVO = ResultUtils.error(CodeMsg.USER_CREDENTIALS_EXPIRED); |
||||||
|
} else if (failed instanceof AccountExpiredException) { |
||||||
|
resultVO = ResultUtils.error(CodeMsg.USER_ACCOUNT_EXPIRED); |
||||||
|
} else if (failed instanceof DisabledException) { |
||||||
|
resultVO = ResultUtils.error(CodeMsg.USER_IS_DISABLED); |
||||||
|
} else if (failed instanceof AuthenticationException) { |
||||||
|
Throwable cause = failed.getCause(); |
||||||
|
if (cause instanceof BusinessException) { |
||||||
|
BusinessException businessException = (BusinessException) cause; |
||||||
|
resultVO = ResultUtils.error(businessException.getError()); |
||||||
|
} else { |
||||||
|
resultVO = ResultUtils.error(CodeMsg.USER_BAD_CREDENTIALS); |
||||||
|
} |
||||||
|
} else { |
||||||
|
resultVO = ResultUtils.error(CodeMsg.LOGIN_FAIL); |
||||||
|
} |
||||||
|
|
||||||
|
// 拦截后直接将错误信息反馈给前端,不经过全局异常处理器(GlobalExceptionHandler)处理
|
||||||
|
response.setCharacterEncoding("utf-8"); |
||||||
|
response.setContentType("application/json;charset=utf-8"); |
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
out.write(new ObjectMapper().writeValueAsString(resultVO)); |
||||||
|
out.flush(); |
||||||
|
out.close(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,94 @@ |
|||||||
|
package edu.ncst.carbon.config.security.provider; |
||||||
|
|
||||||
|
import edu.ncst.carbon.config.exception.CodeBeenUsedException; |
||||||
|
import edu.ncst.carbon.config.security.token.WechatIdAuthenticationToken; |
||||||
|
import edu.ncst.carbon.model.system.User; |
||||||
|
import edu.ncst.carbon.service.IUserService; |
||||||
|
import edu.ncst.carbon.utils.WeChatUtils; |
||||||
|
import edu.ncst.carbon.vo.wechat.AccessTokenDTO; |
||||||
|
import lombok.SneakyThrows; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||||
|
import org.springframework.security.authentication.AuthenticationProvider; |
||||||
|
import org.springframework.security.core.Authentication; |
||||||
|
import org.springframework.security.core.AuthenticationException; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
@Component |
||||||
|
@Slf4j |
||||||
|
public class WechatIdLoginProvider implements AuthenticationProvider { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private IUserService userService; |
||||||
|
|
||||||
|
private final RedisTemplate<String, String> stringRedisTemplate; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
public WechatIdLoginProvider(IUserService userService, RedisTemplate<String, String> stringRedisTemplate) { |
||||||
|
this.userService = userService; |
||||||
|
this.stringRedisTemplate = stringRedisTemplate; |
||||||
|
} |
||||||
|
@SneakyThrows |
||||||
|
@Override |
||||||
|
public Authentication authenticate(Authentication authentication) throws AuthenticationException { |
||||||
|
log.info("进入到微信登录接口"); |
||||||
|
// 获取 Code
|
||||||
|
if (!(authentication instanceof WechatIdAuthenticationToken)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
WechatIdAuthenticationToken token = (WechatIdAuthenticationToken) authentication; |
||||||
|
String code = token.getWechatCode(); |
||||||
|
|
||||||
|
//公众号
|
||||||
|
/* |
||||||
|
SessionKeyDTO sessionKeyDTO = WeChatUtils.code2session(code); |
||||||
|
if (sessionKeyDTO == null) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
String wechatId = sessionKeyDTO.getWeChatId(); |
||||||
|
String sessionKey = sessionKeyDTO.getSessionKey(); |
||||||
|
*/ |
||||||
|
|
||||||
|
//小程序
|
||||||
|
AccessTokenDTO accessTokenDTO = WeChatUtils.code2session(code); |
||||||
|
log.info("========== 通过code2session得到:" + accessTokenDTO); |
||||||
|
|
||||||
|
String openId = accessTokenDTO.getOpenid(); |
||||||
|
stringRedisTemplate.opsForValue().set("session_key:" + accessTokenDTO.getOpenid() , accessTokenDTO.getSessionKey()); |
||||||
|
|
||||||
|
if (openId != null && !"".equals(openId)) { |
||||||
|
|
||||||
|
log.info("小程序登录成功:" + openId); |
||||||
|
|
||||||
|
// 查找该 wechatID 已经绑定用户
|
||||||
|
// UserWeChatDTO userWeChatDTO = userService.loadUserByOpenId(openId);
|
||||||
|
|
||||||
|
//根据openId查询用户
|
||||||
|
Optional<User> userOptional = Optional.ofNullable( (User) userService.loadUserByOpenId(openId)); |
||||||
|
|
||||||
|
//用户存在则获取,不存在则注册
|
||||||
|
User user = userOptional.orElseGet(() -> userService.registerByWechat(openId)); |
||||||
|
|
||||||
|
stringRedisTemplate.opsForValue().set("user_openid:"+ user.getUsername(),openId); |
||||||
|
log.info("user_openid:" + openId); |
||||||
|
return new WechatIdAuthenticationToken(user); |
||||||
|
}else{ |
||||||
|
throw new CodeBeenUsedException("微信登录授权code短时间重复使用."); |
||||||
|
} |
||||||
|
|
||||||
|
// if (userDetails == null) {
|
||||||
|
// throw new NotBindUserException("微信授权openid无效,请重新登陆.");
|
||||||
|
// } else {
|
||||||
|
// return new WechatIdAuthenticationToken(userDetails);
|
||||||
|
// }
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean supports(Class<?> authentication) { |
||||||
|
return authentication.equals(WechatIdAuthenticationToken.class); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,39 @@ |
|||||||
|
package edu.ncst.carbon.config.security.token; |
||||||
|
|
||||||
|
import edu.ncst.carbon.vo.user.UserInfoVO; |
||||||
|
import org.springframework.security.authentication.AbstractAuthenticationToken; |
||||||
|
import org.springframework.security.core.GrantedAuthority; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* JWT认证凭证(Security Context) |
||||||
|
*/ |
||||||
|
public class JwtAuthenticationToken extends AbstractAuthenticationToken { |
||||||
|
|
||||||
|
private final Object principal; |
||||||
|
|
||||||
|
private final Object details; |
||||||
|
|
||||||
|
public JwtAuthenticationToken(Object principal, List<GrantedAuthority> authorities, UserInfoVO userInfoVO) { |
||||||
|
super(authorities); |
||||||
|
this.principal = principal; |
||||||
|
this.details = userInfoVO; |
||||||
|
this.setAuthenticated(true); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getCredentials() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getPrincipal() { |
||||||
|
return this.principal; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getDetails() { |
||||||
|
return this.details; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,39 @@ |
|||||||
|
package edu.ncst.carbon.config.security.token; |
||||||
|
|
||||||
|
import org.springframework.security.authentication.AbstractAuthenticationToken; |
||||||
|
import org.springframework.security.core.GrantedAuthority; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
/** |
||||||
|
* 手机验证码方式登录凭证 |
||||||
|
*/ |
||||||
|
public class MobileCaptchaAuthenticationToken extends AbstractAuthenticationToken { |
||||||
|
|
||||||
|
// 手机号码
|
||||||
|
private String phoneNumber; |
||||||
|
|
||||||
|
// 验证码
|
||||||
|
private String captchaCode; |
||||||
|
|
||||||
|
public MobileCaptchaAuthenticationToken(String phoneNumber, String captchaCode) { |
||||||
|
super(null); |
||||||
|
this.phoneNumber = phoneNumber; |
||||||
|
this.captchaCode = captchaCode; |
||||||
|
} |
||||||
|
|
||||||
|
public MobileCaptchaAuthenticationToken(Collection<? extends GrantedAuthority> authorities) { |
||||||
|
super(authorities); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getCredentials() { |
||||||
|
return this.phoneNumber; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getPrincipal() { |
||||||
|
return this.captchaCode; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
package edu.ncst.carbon.config.security.token; |
||||||
|
|
||||||
|
import org.springframework.security.authentication.AbstractAuthenticationToken; |
||||||
|
import org.springframework.security.core.GrantedAuthority; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
/** |
||||||
|
* OpenId 登录 |
||||||
|
*/ |
||||||
|
public class WechatIdAuthenticationToken extends AbstractAuthenticationToken { |
||||||
|
|
||||||
|
private String wechatCode; |
||||||
|
|
||||||
|
private final Object principal; |
||||||
|
|
||||||
|
public WechatIdAuthenticationToken(String wechatCode) { |
||||||
|
super(null); |
||||||
|
this.principal = wechatCode; |
||||||
|
this.wechatCode = wechatCode; |
||||||
|
} |
||||||
|
|
||||||
|
public WechatIdAuthenticationToken(Object principal) { |
||||||
|
super(null); |
||||||
|
this.principal = principal; |
||||||
|
super.setAuthenticated(true); |
||||||
|
} |
||||||
|
|
||||||
|
public WechatIdAuthenticationToken(String openId, Collection<? extends GrantedAuthority> authorities) { |
||||||
|
super(authorities); |
||||||
|
this.principal = openId; |
||||||
|
setAuthenticated(true); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getCredentials() { |
||||||
|
return this.wechatCode; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getPrincipal() { |
||||||
|
return this.principal; |
||||||
|
} |
||||||
|
|
||||||
|
public String getWechatCode() { |
||||||
|
return wechatCode; |
||||||
|
} |
||||||
|
|
||||||
|
public void setWechatCode(String wechatCode) { |
||||||
|
this.wechatCode = wechatCode; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,78 @@ |
|||||||
|
package edu.ncst.carbon.controller; |
||||||
|
|
||||||
|
import edu.ncst.carbon.utils.CaptchaUtil; |
||||||
|
import edu.ncst.carbon.utils.CookieUtils; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate; |
||||||
|
import org.springframework.stereotype.Controller; |
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
|
||||||
|
import javax.imageio.ImageIO; |
||||||
|
import javax.servlet.ServletOutputStream; |
||||||
|
import javax.servlet.http.Cookie; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
import java.io.IOException; |
||||||
|
import java.util.UUID; |
||||||
|
import java.util.concurrent.TimeUnit; |
||||||
|
|
||||||
|
@Api(description = "验证码") |
||||||
|
@Controller |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api") |
||||||
|
public class CaptchaController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private StringRedisTemplate stringRedisTemplate; |
||||||
|
|
||||||
|
@GetMapping("/captcha.jpg") |
||||||
|
public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException { |
||||||
|
Cookie tempTokenCookie = CookieUtils.getCookie(request, "TEMP_TOKEN"); |
||||||
|
String tempToken = null; |
||||||
|
Boolean tokenIsValid = false; |
||||||
|
|
||||||
|
// 校验 TOKEN 是否存在
|
||||||
|
if (tempTokenCookie != null && tempTokenCookie.getValue() != null && !"".equals(tempTokenCookie.getValue())) { |
||||||
|
tempToken = tempTokenCookie.getValue(); |
||||||
|
} |
||||||
|
|
||||||
|
// 校验 TOKEN 是否有效
|
||||||
|
if (tempToken != null) { |
||||||
|
tokenIsValid = stringRedisTemplate.hasKey("tempToken:" + tempToken); |
||||||
|
} |
||||||
|
|
||||||
|
// 如果没有 TOKEN 或者 TOKEN 失效都会生成一个新的TOKEN
|
||||||
|
if (tokenIsValid == null || !tokenIsValid) { |
||||||
|
UUID uuid = UUID.randomUUID(); |
||||||
|
tempToken = uuid.toString(); |
||||||
|
|
||||||
|
// 将临时 TOKEN 存入Redis,设置24小时的过期时间
|
||||||
|
stringRedisTemplate.opsForValue().set("tempToken:" + tempToken, "1", 24, TimeUnit.HOURS); |
||||||
|
|
||||||
|
// 将临时TOKEN存入Cookie同步设置24小时过期时间
|
||||||
|
Cookie newCookie = new Cookie("TEMP_TOKEN", tempToken); |
||||||
|
newCookie.setMaxAge(24 * 59 * 60); |
||||||
|
newCookie.setHttpOnly(true); |
||||||
|
|
||||||
|
response.addCookie(newCookie); |
||||||
|
} |
||||||
|
|
||||||
|
// 生成验证码
|
||||||
|
response.setHeader("Cache-Control", "no-store, no-cache"); |
||||||
|
response.setContentType("image/jpeg"); |
||||||
|
|
||||||
|
BufferedImage image = CaptchaUtil.createImage(); |
||||||
|
String randomText = CaptchaUtil.drawRandomText(image); |
||||||
|
|
||||||
|
// 将验证码存入 Redis,设置两分钟的过期时间
|
||||||
|
stringRedisTemplate.opsForValue().set("captcha:" + tempToken, randomText, 2, TimeUnit.MINUTES); |
||||||
|
ServletOutputStream out = response.getOutputStream(); |
||||||
|
|
||||||
|
ImageIO.write(image, "jpeg", out); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,109 @@ |
|||||||
|
package edu.ncst.carbon.controller; |
||||||
|
|
||||||
|
import edu.ncst.carbon.exception.BusinessException; |
||||||
|
import edu.ncst.carbon.exception.CodeMsg; |
||||||
|
import edu.ncst.carbon.mapper.system.RoleMapper; |
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import edu.ncst.carbon.service.IResourceService; |
||||||
|
import edu.ncst.carbon.service.ISystemService; |
||||||
|
import edu.ncst.carbon.service.impl.system.UserServiceImpl; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.utils.SessionUtils; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.user.AddUserDTO; |
||||||
|
import edu.ncst.carbon.vo.user.UserInfoVO; |
||||||
|
import edu.ncst.carbon.vo.wechat.BindUserDTO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.security.core.userdetails.UserDetails; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
import org.springframework.util.DigestUtils; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Api(hidden = true) |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/system") |
||||||
|
@Slf4j |
||||||
|
public class SystemController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private UserServiceImpl userService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ISystemService systemService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private IResourceService resourceService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private RoleMapper roleMapper; |
||||||
|
|
||||||
|
@GetMapping("/init") |
||||||
|
@Transactional |
||||||
|
public ResponseEntity<?> initSystem() { |
||||||
|
// 创建角色
|
||||||
|
Role adminRole = roleMapper.getRoleByName("SUPER_ADMIN"); |
||||||
|
|
||||||
|
if (adminRole == null) { |
||||||
|
Role role = new Role(); |
||||||
|
role.setEnable(true); |
||||||
|
role.setName("SUPER_ADMIN"); |
||||||
|
role.setLabel("超级管理员"); |
||||||
|
roleMapper.insert(role); |
||||||
|
adminRole = role; |
||||||
|
} |
||||||
|
|
||||||
|
UserDetails admin = null; |
||||||
|
|
||||||
|
try { |
||||||
|
admin = userService.loadUserByUsername("admin"); |
||||||
|
} catch (BusinessException ex) { |
||||||
|
log.info("没有找到超级管理员账号,重新创建。"); |
||||||
|
} |
||||||
|
|
||||||
|
if (admin == null) { |
||||||
|
AddUserDTO adminUser = new AddUserDTO(); |
||||||
|
adminUser.setUsername("super-admin"); |
||||||
|
adminUser.setFullName("超级管理员"); |
||||||
|
adminUser.setPhone("10100000000"); |
||||||
|
adminUser.setEmail("smart@ncst.com"); |
||||||
|
|
||||||
|
String password = DigestUtils.md5DigestAsHex("123456ncstslat".getBytes()); |
||||||
|
log.info(password); |
||||||
|
adminUser.setPassword(password); |
||||||
|
|
||||||
|
List<Integer> roleIds = new ArrayList<>(); |
||||||
|
roleIds.add(adminRole.getId()); |
||||||
|
adminUser.setRoles(roleIds); |
||||||
|
|
||||||
|
userService.addUser(adminUser); |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseUtils.success("初始化成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("/interface/meta/reimport/") |
||||||
|
public ResultVO<?> reimportInterfaceMeta() { |
||||||
|
UserInfoVO currentUser = SessionUtils.getCurrentUser(); |
||||||
|
List<Role> roles = currentUser.getRoles(); |
||||||
|
|
||||||
|
boolean isSuperAdmin = roles.contains(Role.forName("SUPER_ADMIN")); |
||||||
|
|
||||||
|
if (isSuperAdmin) { |
||||||
|
resourceService.reimportInterfaceMeta(); |
||||||
|
return ResultUtils.success("ok", null); |
||||||
|
} else { |
||||||
|
return ResultUtils.error(CodeMsg.CAN_NOT_DATA_ACCESS); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,108 @@ |
|||||||
|
package edu.ncst.carbon.controller.carbon; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormula; |
||||||
|
import edu.ncst.carbon.service.ICarbonFormulaService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.carbon.CalculationResults; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "碳公式 控制器", tags = "CarbonFormulaController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/carbon-formula") |
||||||
|
public class CarbonFormulaController { |
||||||
|
|
||||||
|
private final ICarbonFormulaService carbonFormulaService; |
||||||
|
|
||||||
|
public CarbonFormulaController(ICarbonFormulaService carbonFormulaService) { |
||||||
|
this.carbonFormulaService = carbonFormulaService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于计算碳排放量和碳积分
|
||||||
|
/* |
||||||
|
* 参数:计算参数 CalculateParameters(内部可自行修改) |
||||||
|
* 返回值:计算结果 CalculationResults(内部可自行修改) |
||||||
|
* |
||||||
|
* */ |
||||||
|
@ApiOperation("计算") |
||||||
|
@GetMapping("/calculation") |
||||||
|
public ResultVO<CalculationResults> calculation(@RequestParam Integer carFormulaId) { |
||||||
|
CalculationResults result = carbonFormulaService.calculation(carFormulaId); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于碳公式的小程序计算页面的渲染
|
||||||
|
/* |
||||||
|
* 参数:分类id(可自行修改) |
||||||
|
* 返回值:列表list,每行为一个碳公式CarFormula |
||||||
|
* |
||||||
|
* */ |
||||||
|
@ApiOperation("按照分类获取碳公式列表") |
||||||
|
@GetMapping("/getListByTypeId") |
||||||
|
public ResultVO<List<CarFormula>> getCarFormulaListByTypeId(@RequestParam Integer typeId) { |
||||||
|
List<CarFormula> CarFormulaList = null; |
||||||
|
|
||||||
|
return ResultUtils.success("ok", CarFormulaList); |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于碳公式的管理页面
|
||||||
|
@ApiOperation("获取碳公式列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<CarFormula>> getCarFormulaList(Query query) { |
||||||
|
ListResultVO<CarFormula> CarFormulaList = carbonFormulaService.getCarFormulaList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", CarFormulaList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取碳公式详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<CarFormula> getCarFormulaDetail(@RequestParam Integer id) { |
||||||
|
CarFormula CarFormulaDetail = carbonFormulaService.getCarFormulaDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", CarFormulaDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加碳公式") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<CarFormula> addCarFormula(@RequestBody CarFormula carFormula) { |
||||||
|
CarFormula result = carbonFormulaService.addCarFormula(carFormula); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改碳公式") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<CarFormula> modifyCarFormula(@RequestBody CarFormula carFormula) { |
||||||
|
CarFormula result = carbonFormulaService.modifyCarFormula(carFormula); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除碳公式") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteCarFormula(@RequestParam Integer id) { |
||||||
|
carbonFormulaService.deleteCarFormula(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,75 @@ |
|||||||
|
package edu.ncst.carbon.controller.carbon; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormulaType; |
||||||
|
import edu.ncst.carbon.service.ICarbonFormulaTypeService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式类别 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "碳公式类别 控制器", tags = "CarbonFormulaTypeController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/carbon-formula-type") |
||||||
|
public class CarbonFormulaTypeController { |
||||||
|
private final ICarbonFormulaTypeService carbonFormulaTypeService; |
||||||
|
|
||||||
|
public CarbonFormulaTypeController(ICarbonFormulaTypeService carbonFormulaTypeService) { |
||||||
|
this.carbonFormulaTypeService = carbonFormulaTypeService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于碳公式类别的管理页面
|
||||||
|
@ApiOperation("获取碳公式类别列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<CarFormulaType>> getCarFormulaTypeList(Query query) { |
||||||
|
ListResultVO<CarFormulaType> CarFormulaTypeList = carbonFormulaTypeService.getCarFormulaTypeList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", CarFormulaTypeList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取碳公式类别详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<CarFormulaType> getCarFormulaTypeDetail(@RequestParam Integer id) { |
||||||
|
CarFormulaType CarFormulaTypeDetail = carbonFormulaTypeService.getCarFormulaTypeDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", CarFormulaTypeDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加碳公式类别") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<CarFormulaType> addCarFormulaType(@RequestBody CarFormulaType carFormulaType) { |
||||||
|
CarFormulaType result = carbonFormulaTypeService.addCarFormulaType(carFormulaType); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改碳公式类别") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<CarFormulaType> modifyCarFormulaType(@RequestBody CarFormulaType carFormulaType) { |
||||||
|
CarFormulaType result = carbonFormulaTypeService.modifyCarFormulaType(carFormulaType); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除碳公式类别") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteCarFormulaType(@RequestParam Integer id) { |
||||||
|
carbonFormulaTypeService.deleteCarFormulaType(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,75 @@ |
|||||||
|
package edu.ncst.carbon.controller.carbon; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormulaUnit; |
||||||
|
import edu.ncst.carbon.service.ICarbonFormulaUnitService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式单位 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "碳公式单位 控制器", tags = "CarbonFormulaUnitController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/carbon-formula-unit") |
||||||
|
public class CarbonFormulaUnitController { |
||||||
|
private final ICarbonFormulaUnitService carbonFormulaUnitService; |
||||||
|
|
||||||
|
public CarbonFormulaUnitController(ICarbonFormulaUnitService carbonFormulaUnitService) { |
||||||
|
this.carbonFormulaUnitService = carbonFormulaUnitService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于碳公式单位的管理页面
|
||||||
|
@ApiOperation("获取碳公式单位列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<CarFormulaUnit>> getCarFormulaUnitList(Query query) { |
||||||
|
ListResultVO<CarFormulaUnit> CarFormulaUnitList = carbonFormulaUnitService.getCarFormulaUnitList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", CarFormulaUnitList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取碳公式单位详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<CarFormulaUnit> getCarFormulaUnitDetail(@RequestParam Integer id) { |
||||||
|
CarFormulaUnit CarFormulaUnitDetail = carbonFormulaUnitService.getCarFormulaUnitDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", CarFormulaUnitDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加碳公式单位") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<CarFormulaUnit> addCarFormulaUnit(@RequestBody CarFormulaUnit carFormulaUnit) { |
||||||
|
CarFormulaUnit result = carbonFormulaUnitService.addCarFormulaUnit(carFormulaUnit); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改碳公式单位") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<CarFormulaUnit> modifyCarFormulaUnit(@RequestBody CarFormulaUnit carFormulaUnit) { |
||||||
|
CarFormulaUnit result = carbonFormulaUnitService.modifyCarFormulaUnit(carFormulaUnit); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除碳公式单位") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteCarFormulaUnit(@RequestParam Integer id) { |
||||||
|
carbonFormulaUnitService.deleteCarFormulaUnit(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,4 @@ |
|||||||
|
package edu.ncst.carbon.controller.charity; |
||||||
|
|
||||||
|
public class CharityController { |
||||||
|
} |
||||||
@ -0,0 +1,81 @@ |
|||||||
|
package edu.ncst.carbon.controller.goods; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.goods.Goods; |
||||||
|
import edu.ncst.carbon.service.IGoodsService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
|
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "商品 控制器", tags = "GoodsController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/goods") |
||||||
|
public class GoodsController { |
||||||
|
|
||||||
|
private final IGoodsService GoodsService; |
||||||
|
|
||||||
|
public GoodsController(IGoodsService GoodsService) { |
||||||
|
this.GoodsService = GoodsService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于商品的管理页面
|
||||||
|
@ApiOperation("获取商品列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<Goods>> getGoodsList(Query query) { |
||||||
|
ListResultVO<Goods> GoodsList = GoodsService.getGoodsList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", GoodsList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取商品详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<Goods> getGoodsDetail(@RequestParam Integer id) { |
||||||
|
Goods GoodsDetail = GoodsService.getGoodsDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", GoodsDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加商品") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<Goods> addGoods(@RequestBody Goods Goods) { |
||||||
|
Goods result = GoodsService.addGoods(Goods); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改商品") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<Goods> modifyGoods(@RequestBody Goods Goods) { |
||||||
|
Goods result = GoodsService.modifyGoods(Goods); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除商品") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteGoods(@RequestParam Integer id) { |
||||||
|
GoodsService.deleteGoods(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,63 @@ |
|||||||
|
package edu.ncst.carbon.controller.image; |
||||||
|
|
||||||
|
import edu.ncst.carbon.service.impl.image.ImageServiceImpl; |
||||||
|
import edu.ncst.carbon.utils.SessionUtils; |
||||||
|
import edu.ncst.carbon.vo.user.UserInfoVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import javax.imageio.ImageIO; |
||||||
|
import javax.servlet.ServletOutputStream; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
import java.io.*; |
||||||
|
|
||||||
|
@RestController |
||||||
|
@Slf4j |
||||||
|
@CrossOrigin |
||||||
|
@Api(description = "图片上传管理", tags = "ImageController") |
||||||
|
@RequestMapping("/api/image") |
||||||
|
public class ImageController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
ImageServiceImpl imageService; |
||||||
|
|
||||||
|
// 读取配置文件中上传路径
|
||||||
|
@Value("${file.file-dir}") |
||||||
|
String imagePath; |
||||||
|
|
||||||
|
@ApiOperation("上传图片") |
||||||
|
@PostMapping("/upload/{namePrefix}") |
||||||
|
public String uploadImage(@RequestParam(value = "file",required = false) MultipartFile file , HttpServletRequest request,@PathVariable String namePrefix) throws FileNotFoundException { |
||||||
|
UserInfoVO currentUser = SessionUtils.getCurrentUser(); |
||||||
|
log.debug("上传图片的用户:" + currentUser.getUsername()); |
||||||
|
String result = imageService.uploadImage(file, request,namePrefix); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("获取图片") |
||||||
|
@GetMapping("/get/{imageName}") |
||||||
|
public void getImage(HttpServletRequest request, HttpServletResponse response, @PathVariable String imageName) throws IOException { |
||||||
|
// UserInfoVO currentUser = SessionUtils.getCurrentUser();
|
||||||
|
log.info(imagePath + imageName); |
||||||
|
BufferedImage image = null; |
||||||
|
try { |
||||||
|
image = ImageIO.read(new File(imagePath + "/" + imageName)); |
||||||
|
} catch (IOException e) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
response.setHeader("Cache-Control", "no-store, no-cache"); |
||||||
|
response.setContentType("image/jpeg"); |
||||||
|
ServletOutputStream out = response.getOutputStream(); |
||||||
|
|
||||||
|
ImageIO.write(image, "jpeg", out); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,87 @@ |
|||||||
|
package edu.ncst.carbon.controller.log; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.log.LogUser; |
||||||
|
import edu.ncst.carbon.service.ILogUserService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户当前数据 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "用户信息 控制器", tags = "LogUserController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/log-user") |
||||||
|
public class LogUserController { |
||||||
|
|
||||||
|
private final ILogUserService logUserService; |
||||||
|
|
||||||
|
public LogUserController(ILogUserService logUserService) { |
||||||
|
this.logUserService = logUserService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于商品的管理页面
|
||||||
|
@ApiOperation("获取商品列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<LogUser>> getLogUserList(Query query) { |
||||||
|
ListResultVO<LogUser> LogUserList = logUserService.getLogUserList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", LogUserList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取商品详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<LogUser> getLogUserDetail(@RequestParam Integer id) { |
||||||
|
LogUser LogUserDetail = logUserService.getLogUserDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", LogUserDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加商品") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<LogUser> addLogUser(@RequestBody LogUser LogUser) { |
||||||
|
LogUser result = logUserService.addLogUser(LogUser); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改商品") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<LogUser> modifyLogUser(@RequestBody LogUser LogUser) { |
||||||
|
LogUser result = logUserService.modifyLogUser(LogUser); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除商品") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteLogUser(@RequestParam Integer id) { |
||||||
|
logUserService.deleteLogUser(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
* 参数:用户id |
||||||
|
* 返回值:碳积分 |
||||||
|
* */ |
||||||
|
@ApiOperation("获取当前用户碳积分总数") |
||||||
|
@GetMapping("/getUserIntegral") |
||||||
|
public ResultVO<Integer> getUserIntegral(Integer userId) { |
||||||
|
Integer result = null; |
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,88 @@ |
|||||||
|
package edu.ncst.carbon.controller.log; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.log.LogUserFootprint; |
||||||
|
import edu.ncst.carbon.service.ILogUserFootprintService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户碳足迹 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "用户碳足迹 控制器", tags = "LogUserFootprintController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/log-user-footprint") |
||||||
|
public class LogUserFootprintController { |
||||||
|
|
||||||
|
private final ILogUserFootprintService logUserFootprintService; |
||||||
|
|
||||||
|
public LogUserFootprintController(ILogUserFootprintService logUserFootprintService) { |
||||||
|
this.logUserFootprintService = logUserFootprintService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于用户碳足迹的管理页面
|
||||||
|
@ApiOperation("获取所有碳足迹列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<LogUserFootprint>> getLogFootprintList(Query query) { |
||||||
|
ListResultVO<LogUserFootprint> LogUserFootprintList = logUserFootprintService.getLogFootprintList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", LogUserFootprintList); |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于用户碳足迹的管理页面
|
||||||
|
@ApiOperation("获取用户碳足迹列表") |
||||||
|
@GetMapping("/listByUserId") |
||||||
|
public ResultVO<List<LogUserFootprint>> getLogUserFootprintList(Integer userId) { |
||||||
|
List<LogUserFootprint> LogUserFootprintList = logUserFootprintService.getLogUserFootprintList(userId); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", LogUserFootprintList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取用户碳足迹详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<LogUserFootprint> getLogUserFootprintDetail(@RequestParam Integer id) { |
||||||
|
LogUserFootprint LogUserFootprintDetail = logUserFootprintService.getLogUserFootprintDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", LogUserFootprintDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加用户碳足迹") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<LogUserFootprint> addLogUserFootprint(@RequestBody LogUserFootprint LogUserFootprint) { |
||||||
|
LogUserFootprint result = logUserFootprintService.addLogUserFootprint(LogUserFootprint); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改用户碳足迹") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<LogUserFootprint> modifyLogUserFootprint(@RequestBody LogUserFootprint LogUserFootprint) { |
||||||
|
LogUserFootprint result = logUserFootprintService.modifyLogUserFootprint(LogUserFootprint); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除用户碳足迹") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteLogUserFootprint(@RequestParam Integer id) { |
||||||
|
logUserFootprintService.deleteLogUserFootprint(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,76 @@ |
|||||||
|
package edu.ncst.carbon.controller.log; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.log.LogUserGoods; |
||||||
|
import edu.ncst.carbon.service.ILogUserGoodsService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户商品购买记录 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "用户商品购买记录 控制器", tags = "LogUserGoodsController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/log-user-goods") |
||||||
|
public class LogUserGoodsController { |
||||||
|
|
||||||
|
private final ILogUserGoodsService LogUserGoodsService; |
||||||
|
|
||||||
|
public LogUserGoodsController(ILogUserGoodsService LogUserGoodsService) { |
||||||
|
this.LogUserGoodsService = LogUserGoodsService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于用户商品购买记录的管理页面
|
||||||
|
@ApiOperation("获取用户商品购买记录列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<LogUserGoods>> getLogUserGoodsList(Query query) { |
||||||
|
ListResultVO<LogUserGoods> LogUserGoodsList = LogUserGoodsService.getLogUserGoodsList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", LogUserGoodsList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取用户商品购买记录详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<LogUserGoods> getLogUserGoodsDetail(@RequestParam Integer id) { |
||||||
|
LogUserGoods LogUserGoodsDetail = LogUserGoodsService.getLogUserGoodsDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", LogUserGoodsDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加用户商品购买记录") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<LogUserGoods> addLogUserGoods(@RequestBody LogUserGoods LogUserGoods) { |
||||||
|
LogUserGoods result = LogUserGoodsService.addLogUserGoods(LogUserGoods); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改用户商品购买记录") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<LogUserGoods> modifyLogUserGoods(@RequestBody LogUserGoods LogUserGoods) { |
||||||
|
LogUserGoods result = LogUserGoodsService.modifyLogUserGoods(LogUserGoods); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除用户商品购买记录") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteLogUserGoods(@RequestParam Integer id) { |
||||||
|
LogUserGoodsService.deleteLogUserGoods(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,130 @@ |
|||||||
|
package edu.ncst.carbon.controller.system; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LoginUserScope; |
||||||
|
import edu.ncst.carbon.model.system.Menu; |
||||||
|
import edu.ncst.carbon.service.IMenuService; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
; |
||||||
|
|
||||||
|
/** |
||||||
|
* 菜单 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "菜单管理", tags = "MenuController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/menu") |
||||||
|
public class MenuController { |
||||||
|
|
||||||
|
private final IMenuService menuService; |
||||||
|
|
||||||
|
public MenuController(IMenuService menuService) { |
||||||
|
this.menuService = menuService; |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取菜单列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<Menu>> getMenuList(Query query) { |
||||||
|
ListResultVO<Menu> menuList = menuService.getMenuList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", menuList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取菜单树") |
||||||
|
@GetMapping("/tree") |
||||||
|
public ResultVO<List<Menu>> getMenuTree() { |
||||||
|
List<Menu> menuTree = menuService.getMenuTree(); |
||||||
|
return ResultUtils.success("ok", menuTree); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取指定角色能够访问的菜单ID列表") |
||||||
|
@GetMapping("/ids/role") |
||||||
|
public ResultVO<List<Integer>> getRoleMenuIds(Integer roleId) { |
||||||
|
List<Integer> menuIds = menuService.getRoleMenuIds(roleId,true); |
||||||
|
return ResultUtils.success("ok", menuIds); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取菜单详情") |
||||||
|
@PostMapping("/detail") |
||||||
|
public ResultVO<Menu> getMenuDetail(@RequestParam Integer id) { |
||||||
|
Menu menuDetail = menuService.getMenuDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", menuDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加菜单") |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<Menu> addMenu(@RequestBody Menu menu) { |
||||||
|
log.info("将要添加的菜单:" + menu); |
||||||
|
Menu result = menuService.addMenu(menu); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改菜单") |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<Menu> modifyMenu(@RequestBody Menu menu) { |
||||||
|
Menu result = menuService.modifyMenu(menu); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除菜单") |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResultVO<Menu> deleteMenu(@RequestParam Integer id) { |
||||||
|
menuService.deleteMenu(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", null); |
||||||
|
} |
||||||
|
|
||||||
|
// @ApiOperation("批量删除菜单")
|
||||||
|
// @PostMapping("/batch/delete")
|
||||||
|
// public ResultVO<Menu> batchDeleteMenu(@RequestBody BatchDeleteDTO batchDeleteDTO) {
|
||||||
|
// menuService.batchDeleteMenu(batchDeleteDTO);
|
||||||
|
//
|
||||||
|
// return ResultUtils.success("ok", null);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@ApiOperation("获取指定用户可访问的菜单列表") |
||||||
|
@GetMapping("/user/{userId}") |
||||||
|
public ResultVO<ListResultVO<Menu>> getUserMenuList(@PathVariable Integer userId) { |
||||||
|
return ResultUtils.success("ok", null); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取当前用户可访问的菜单列表") |
||||||
|
@GetMapping("/user/current") |
||||||
|
public ResultVO<List<Menu>> getCurrentUserMenuTree() { |
||||||
|
List<Menu> currentUserMenuTree = menuService.getCurrentUserMenuTree(); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", currentUserMenuTree); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取当前用户可访问的菜单列表") |
||||||
|
@LoginUserScope |
||||||
|
@GetMapping("/user/authority") |
||||||
|
public ResultVO<List<String>> getCurrentUserMenuAuthority() { |
||||||
|
List<String> currentUserMenuTree = menuService.getCurrentUserMenuAuthority(); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", currentUserMenuTree); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// @ApiOperation("重置菜单元信息")
|
||||||
|
// @PostMapping("/reset")
|
||||||
|
// public ResponseEntity<?> resetMenuMeta(@RequestBody ResetMenuDTO resetMenuDTO) {
|
||||||
|
// menuService.resetMenuMeta(resetMenuDTO);
|
||||||
|
//
|
||||||
|
// return ResponseUtils.success("ok", null);
|
||||||
|
// }
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,120 @@ |
|||||||
|
package edu.ncst.carbon.controller.system; |
||||||
|
|
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import edu.ncst.carbon.service.IRoleService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.role.ModifyRoleInterfacePermissionDTO; |
||||||
|
import edu.ncst.carbon.vo.role.ModifyRoleMenuPermissionDTO; |
||||||
|
import edu.ncst.carbon.vo.role.RoleDetailVO; |
||||||
|
import edu.ncst.carbon.vo.role.RoleShortItemVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "角色管理", tags = "RoleController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/role") |
||||||
|
public class RoleController { |
||||||
|
|
||||||
|
private final IRoleService roleService; |
||||||
|
|
||||||
|
public RoleController(IRoleService roleService) { |
||||||
|
this.roleService = roleService; |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取角色列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<Role>> getRoleList(Query query) { |
||||||
|
ListResultVO<Role> roleList = roleService.getRoleList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", roleList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("选取角色列表") |
||||||
|
@GetMapping("/list/select") |
||||||
|
public ResultVO<List<RoleShortItemVO>> selectRoleList() { |
||||||
|
List<RoleShortItemVO> roleList = roleService.selectRoleList(); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", roleList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取角色详情") |
||||||
|
@PostMapping("/detail") |
||||||
|
public ResultVO<RoleDetailVO> getRoleDetail(@RequestParam Integer id) { |
||||||
|
RoleDetailVO roleDetail = roleService.getRoleDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", roleDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加角色") |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<RoleDetailVO> addRole(@RequestBody RoleDetailVO addRoleDTO) { |
||||||
|
RoleDetailVO result = roleService.addRole(addRoleDTO); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改角色") |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<RoleDetailVO> modifyRole(@RequestBody RoleDetailVO role) { |
||||||
|
RoleDetailVO result = roleService.modifyRole(role); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
// Not OK
|
||||||
|
@ApiOperation("修改角色菜单权限") |
||||||
|
@PostMapping("/modify/permission/menu") |
||||||
|
public ResultVO<RoleDetailVO> modifyRoleMenuPermission(@RequestBody ModifyRoleMenuPermissionDTO modifyDTO) { |
||||||
|
roleService.modifyRoleMenuPermission(modifyDTO); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", null); |
||||||
|
} |
||||||
|
// Not OK
|
||||||
|
@ApiOperation("修改角色资源权限") |
||||||
|
@PostMapping("/modify/permission/resource") |
||||||
|
public ResultVO<RoleDetailVO> modifyRoleInterfacePermission(@RequestBody ModifyRoleInterfacePermissionDTO modifyDTO) { |
||||||
|
roleService.modifyRoleInterfacePermission(modifyDTO); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", null); |
||||||
|
} |
||||||
|
|
||||||
|
// Not OK
|
||||||
|
@ApiOperation("删除角色") |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteRole(@RequestParam Integer id) { |
||||||
|
roleService.deleteRole(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("批量删除角色") |
||||||
|
@PostMapping("/batch/delete") |
||||||
|
public ResponseEntity<?> deleteRoles(@RequestParam List<Integer> ids) { |
||||||
|
roleService.deleteRoles(ids); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改角色启用状态") |
||||||
|
@PostMapping("/enable") |
||||||
|
public ResponseEntity<?> setRoleEnable(Integer roleId, Boolean enable) { |
||||||
|
roleService.setRoleEnable(roleId, enable); |
||||||
|
|
||||||
|
return ResponseUtils.success("ok"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,60 @@ |
|||||||
|
package edu.ncst.carbon.controller.system; |
||||||
|
|
||||||
|
import edu.ncst.carbon.model.system.RoleMenu; |
||||||
|
import edu.ncst.carbon.service.IRoleMenuService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色菜单 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "角色菜单 控制器", tags = "RoleMenuController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/role-menu") |
||||||
|
public class RoleMenuController { |
||||||
|
|
||||||
|
private final IRoleMenuService roleMenuService; |
||||||
|
|
||||||
|
public RoleMenuController(IRoleMenuService roleMenuService) { |
||||||
|
this.roleMenuService = roleMenuService; |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取角色菜单列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<RoleMenu>> getRoleMenuList(Query query) { |
||||||
|
ListResultVO<RoleMenu> roleMenuList = roleMenuService.getRoleMenuList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", roleMenuList); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("添加角色菜单") |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<RoleMenu> addRoleMenu(@RequestBody RoleMenu roleMenu) { |
||||||
|
RoleMenu result = roleMenuService.addRoleMenu(roleMenu); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("删除角色菜单") |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteRoleMenu(@RequestParam Integer id) { |
||||||
|
roleMenuService.deleteRoleMenu(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,174 @@ |
|||||||
|
package edu.ncst.carbon.controller.system; |
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LoginUserScope; |
||||||
|
import edu.ncst.carbon.exception.BusinessException; |
||||||
|
import edu.ncst.carbon.exception.CodeMsg; |
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import edu.ncst.carbon.model.system.User; |
||||||
|
import edu.ncst.carbon.service.IUserService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.utils.SessionUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.query.UserQuery; |
||||||
|
import edu.ncst.carbon.vo.user.*; |
||||||
|
import edu.ncst.carbon.vo.wechat.BindUserDTO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.security.core.userdetails.UserDetails; |
||||||
|
import org.springframework.util.DigestUtils; |
||||||
|
import org.springframework.validation.BindingResult; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "用户管理", tags = "UserController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/user") |
||||||
|
public class UserController { |
||||||
|
|
||||||
|
private final IUserService userService; |
||||||
|
|
||||||
|
public UserController(IUserService userService ) { |
||||||
|
this.userService = userService; |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取用户列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<User>> getUserList(UserQuery query) { |
||||||
|
|
||||||
|
ListResultVO<User> userList = userService.getUserList(query);//List<User>
|
||||||
|
|
||||||
|
return ResultUtils.success("ok", userList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("选择用户列表") |
||||||
|
@GetMapping("/select") |
||||||
|
public ResultVO<List<UserItemVO>> selectUserList(String keyword) { |
||||||
|
List<UserItemVO> userList = userService.selectUserList(keyword); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", userList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取用户详情") |
||||||
|
@PostMapping("/detail") |
||||||
|
public ResultVO<UserInfoVO> getUserDetail(@RequestParam Integer id) { |
||||||
|
UserInfoVO userDetail = userService.getUserDetail(id); |
||||||
|
return ResultUtils.success("ok", userDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加用户") |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<UserInfoVO> addUser(@RequestBody AddUserDTO addUserDTO, BindingResult bindingResult) { |
||||||
|
|
||||||
|
// BindingResult用在实体类校验信息返回结果绑定
|
||||||
|
if (bindingResult.hasErrors()) { |
||||||
|
throw new BusinessException(CodeMsg.BIND_ERROR.fillFieldError(bindingResult)); |
||||||
|
} |
||||||
|
|
||||||
|
UserInfoVO result = userService.addUser(addUserDTO); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改用户") |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<UserInfoVO> modifyUser(@RequestBody UpdateUserDTO updateUserDTO ,BindingResult bindingResult) { |
||||||
|
if (bindingResult.hasErrors()) { |
||||||
|
throw new BusinessException(CodeMsg.BIND_ERROR.fillFieldError(bindingResult)); |
||||||
|
} |
||||||
|
|
||||||
|
UserInfoVO result = userService.modifyUser(updateUserDTO); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除用户") |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteUser(@RequestParam Integer id) { |
||||||
|
userService.deleteUser(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
//not ok
|
||||||
|
@ApiOperation("获取当前用户信息") |
||||||
|
//@LoginUserScope
|
||||||
|
@GetMapping("/current") |
||||||
|
public ResponseEntity<?> getCurrentUser() { |
||||||
|
//if(SessionUtils.userIsLogin()){
|
||||||
|
|
||||||
|
UserInfoVO currentUser = SessionUtils.getCurrentUser(); |
||||||
|
UserInfoVO UserInfoVO = new UserInfoVO(); |
||||||
|
|
||||||
|
CurrentUserDTO currentUserDTO = new CurrentUserDTO(); |
||||||
|
currentUserDTO.setUsername(currentUser.getUsername()); |
||||||
|
currentUserDTO.setFullName(currentUser.getFullName()); |
||||||
|
//currentUserDTO.setNickname(currentUser.getNickname());
|
||||||
|
currentUserDTO.setAvatar("http://pic.17qq.com/img_qqtouxiang/11761377.jpeg"); |
||||||
|
//currentUserDTO.setUnreadCount(0);
|
||||||
|
//currentUserDTO.setUnitId(currentUser.getUnitId());
|
||||||
|
currentUserDTO.setUserId(currentUser.getId()); |
||||||
|
|
||||||
|
//if(1==currentUser.getUnitId()){
|
||||||
|
|
||||||
|
for(Role role:currentUser.getRoles()){ |
||||||
|
if(role.getName().compareTo("EQUIPMENT_ADMIN")==0||role.getName().compareTo("SUPER_ADMIN")==0){ |
||||||
|
// return true;
|
||||||
|
//是否总公司管理员
|
||||||
|
//currentUserDTO.setIsHeadOfficer(Boolean.TRUE);
|
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
//}
|
||||||
|
|
||||||
|
BeanUtils.copyProperties(currentUser, UserInfoVO); |
||||||
|
|
||||||
|
return ResponseUtils.success(currentUserDTO); |
||||||
|
|
||||||
|
// }else{
|
||||||
|
// return ResponseUtils.error(CodeMsg.USER_NEED_LOGIN);
|
||||||
|
// }
|
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改用户启用状态") |
||||||
|
@PostMapping("/enable") |
||||||
|
public ResponseEntity<?> setUserEnable(Integer userId, Boolean enable) { |
||||||
|
userService.setUserEnable(userId, enable); |
||||||
|
|
||||||
|
return ResponseUtils.success("ok"); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("重置用户密码") |
||||||
|
@PostMapping("/resetPassword") |
||||||
|
public ResultVO<UserInfoVO> resetUserPassword(@RequestBody ResetUserPasswordDTO resetUserPasswordDTO, BindingResult bindingResult) { |
||||||
|
if (bindingResult.hasErrors()) { |
||||||
|
throw new BusinessException(CodeMsg.BIND_ERROR.fillFieldError(bindingResult)); |
||||||
|
} |
||||||
|
|
||||||
|
UserInfoVO result = userService.resetUserPassword(resetUserPasswordDTO); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("绑定微信用户信息") |
||||||
|
@PostMapping("/bind") |
||||||
|
public ResponseEntity<?> bindUserInfo(@RequestBody BindUserDTO bindUserInfo) { |
||||||
|
|
||||||
|
userService.bindWeChat(bindUserInfo); |
||||||
|
|
||||||
|
return ResponseUtils.success("绑定成功"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,142 @@ |
|||||||
|
package edu.ncst.carbon.controller.task; |
||||||
|
|
||||||
|
|
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.task.TaskAudit; |
||||||
|
import edu.ncst.carbon.service.ITaskAuditService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.utils.SessionUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.user.UserInfoVO; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import javax.imageio.ImageIO; |
||||||
|
import javax.servlet.ServletOutputStream; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
@Api(description = "任务审核管理", tags = "TaskAuditController") |
||||||
|
@RestController |
||||||
|
@Slf4j |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/task-audit") |
||||||
|
public class TaskAuditController { |
||||||
|
|
||||||
|
private final ITaskAuditService taskAuditService; |
||||||
|
|
||||||
|
// 读取配置文件中上传路径
|
||||||
|
@Value("${file.file-dir}") |
||||||
|
String imagePath; |
||||||
|
|
||||||
|
public TaskAuditController(ITaskAuditService taskAuditService) { |
||||||
|
this.taskAuditService = taskAuditService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于审核任务的管理页面
|
||||||
|
@ApiOperation("获取审核任务列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<TaskAudit>> getTaskAuditList(Query query) { |
||||||
|
ListResultVO<TaskAudit> TaskAuditList = taskAuditService.getTaskAuditList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", TaskAuditList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取审核任务详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<TaskAudit> getTaskAuditDetail(@RequestParam Integer id) { |
||||||
|
TaskAudit TaskAuditDetail = taskAuditService.getTaskAuditDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", TaskAuditDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加审核任务") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<TaskAudit> addTaskAudit(@RequestBody TaskAudit TaskAudit) { |
||||||
|
TaskAudit result = taskAuditService.addTaskAudit(TaskAudit); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改审核任务") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<TaskAudit> modifyTaskAudit(@RequestBody TaskAudit TaskAudit) { |
||||||
|
TaskAudit result = taskAuditService.modifyTaskAudit(TaskAudit); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除审核任务") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteTaskAudit(@RequestParam Integer id) { |
||||||
|
taskAuditService.deleteTaskAudit(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("上传审核任务") |
||||||
|
@PostMapping("/upload") |
||||||
|
public ResponseEntity<?> uploadAudit( @RequestParam(value = "file",required = false) MultipartFile file , |
||||||
|
HttpServletRequest request, |
||||||
|
@RequestParam Integer integral, |
||||||
|
@RequestParam Integer taskId, |
||||||
|
@RequestParam String text) throws FileNotFoundException { |
||||||
|
|
||||||
|
taskAuditService.uploadAudit(file, request, text, taskId, integral); |
||||||
|
return ResponseUtils.success("上传成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取审核任务") |
||||||
|
@GetMapping("/get/{imageName}") |
||||||
|
public void getImage(HttpServletRequest request, HttpServletResponse response, @PathVariable String imageName) throws IOException { |
||||||
|
// UserInfoVO currentUser = SessionUtils.getCurrentUser();
|
||||||
|
log.info(imagePath + imageName); |
||||||
|
BufferedImage image = null; |
||||||
|
try { |
||||||
|
image = ImageIO.read(new File(imagePath + "/" + imageName)); |
||||||
|
} catch (IOException e) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
response.setHeader("Cache-Control", "no-store, no-cache"); |
||||||
|
response.setContentType("image/jpeg"); |
||||||
|
ServletOutputStream out = response.getOutputStream(); |
||||||
|
|
||||||
|
ImageIO.write(image, "jpeg", out); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("开始审核任务") |
||||||
|
@PostMapping("/Audit") |
||||||
|
public ResultVO<TaskAudit> Audit( @RequestParam Integer taskAuditId, @RequestParam Boolean yesNo) { |
||||||
|
|
||||||
|
TaskAudit result = taskAuditService.audit(taskAuditId, yesNo); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("用户确认审核任务") |
||||||
|
@PostMapping("/confirm") |
||||||
|
public ResultVO<TaskAudit> confirmAudit( @RequestParam Integer taskAuditId) { |
||||||
|
|
||||||
|
TaskAudit result = taskAuditService.confirmAudit(taskAuditId); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,101 @@ |
|||||||
|
package edu.ncst.carbon.controller.task; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import edu.ncst.carbon.aspect.LogOperate; |
||||||
|
import edu.ncst.carbon.model.task.Task; |
||||||
|
import edu.ncst.carbon.service.ITaskService; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import edu.ncst.carbon.utils.ResultUtils; |
||||||
|
import edu.ncst.carbon.utils.WeChatUtils; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.ResultVO; |
||||||
|
import edu.ncst.carbon.vo.wechat.SportData; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.Random; |
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
/** |
||||||
|
* 低碳任务 控制器 |
||||||
|
*/ |
||||||
|
@Api(description = "低碳任务 控制器", tags = "TaskController") |
||||||
|
@Slf4j |
||||||
|
@RestController |
||||||
|
@CrossOrigin |
||||||
|
@RequestMapping("/api/task") |
||||||
|
public class TaskController { |
||||||
|
|
||||||
|
private final ITaskService TaskService; |
||||||
|
|
||||||
|
public TaskController(ITaskService TaskService) { |
||||||
|
this.TaskService = TaskService; |
||||||
|
} |
||||||
|
|
||||||
|
// 主要用于低碳任务的管理页面
|
||||||
|
@ApiOperation("获取低碳任务列表") |
||||||
|
@GetMapping("/list") |
||||||
|
public ResultVO<ListResultVO<Task>> getTaskList(Query query) { |
||||||
|
ListResultVO<Task> TaskList = TaskService.getTaskList(query); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", TaskList); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取低碳任务详情") |
||||||
|
@GetMapping("/detail") |
||||||
|
public ResultVO<Task> getTaskDetail(@RequestParam Integer id) { |
||||||
|
Task TaskDetail = TaskService.getTaskDetail(id); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", TaskDetail); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("添加低碳任务") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/add") |
||||||
|
public ResultVO<Task> addTask(@RequestBody Task Task) { |
||||||
|
Task result = TaskService.addTask(Task); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("修改低碳任务") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/modify") |
||||||
|
public ResultVO<Task> modifyTask(@RequestBody Task Task) { |
||||||
|
Task result = TaskService.modifyTask(Task); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", result); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("删除低碳任务") |
||||||
|
@LogOperate |
||||||
|
@PostMapping("/delete") |
||||||
|
public ResponseEntity<?> deleteTask(@RequestParam Integer id) { |
||||||
|
TaskService.deleteTask(id); |
||||||
|
|
||||||
|
return ResponseUtils.success("删除成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取用户微信步数") |
||||||
|
@LogOperate |
||||||
|
@GetMapping("/encryptWeRunData") |
||||||
|
public ResultVO<SportData> encryptWeRunData(@RequestParam String encryptedData, String iv) { |
||||||
|
|
||||||
|
SportData steplist = TaskService.encryptWeRunData(encryptedData, iv); |
||||||
|
|
||||||
|
return ResultUtils.success("ok", steplist); |
||||||
|
} |
||||||
|
@ApiOperation("获取今日骑行数据") |
||||||
|
@LogOperate |
||||||
|
@GetMapping("/getRideData") |
||||||
|
public ResultVO<Integer> getRideData() { |
||||||
|
Random r = new Random(); |
||||||
|
return ResultUtils.success("ok", r.nextInt(20)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
package edu.ncst.carbon.enums; |
||||||
|
|
||||||
|
public interface EnumType { |
||||||
|
|
||||||
|
String getName(); |
||||||
|
|
||||||
|
void setName(String name); |
||||||
|
|
||||||
|
String getLabel(); |
||||||
|
|
||||||
|
void setLabel(String label); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,39 @@ |
|||||||
|
package edu.ncst.carbon.enums; |
||||||
|
|
||||||
|
// 日志类型
|
||||||
|
public enum LogType implements EnumType { |
||||||
|
|
||||||
|
INFO("INFO", "信息"), |
||||||
|
DEBUG("DEBUG", "调试"), |
||||||
|
WARN("WARN", "警告"), |
||||||
|
ERROR("ERROR", "错误"); |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String label; |
||||||
|
|
||||||
|
LogType(String name, String label) { |
||||||
|
this.name = name; |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getLabel() { |
||||||
|
return label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setLabel(String label) { |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
package edu.ncst.carbon.enums; |
||||||
|
|
||||||
|
// 登录方式
|
||||||
|
public enum LoginType implements EnumType { |
||||||
|
|
||||||
|
ACCOUNT("ACCOUNT", "用户名密码方式"), |
||||||
|
MOBILE("MOBILE", "手机验证码方式"), |
||||||
|
WECHAT("WECHAT", "微信登录方式"); |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String label; |
||||||
|
|
||||||
|
LoginType(String name, String label) { |
||||||
|
this.name = name; |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String getLabel() { |
||||||
|
return label; |
||||||
|
} |
||||||
|
|
||||||
|
public void setLabel(String label) { |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
package edu.ncst.carbon.enums; |
||||||
|
|
||||||
|
// 菜单类型
|
||||||
|
public enum MenuType implements EnumType { |
||||||
|
|
||||||
|
MENU("MENU", "菜单"), |
||||||
|
PAGE("PAGE", "页面"), |
||||||
|
BUTTON("BUTTON", "按钮"); |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String label; |
||||||
|
|
||||||
|
MenuType(String name, String label) { |
||||||
|
this.name = name; |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getLabel() { |
||||||
|
return label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setLabel(String label) { |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
package edu.ncst.carbon.enums; |
||||||
|
|
||||||
|
public enum UnitTreeType implements EnumType { |
||||||
|
|
||||||
|
ALL("ALL", "全部单位"), |
||||||
|
COMPANY("COMPANY", "公司单位"), |
||||||
|
DEPARTMENT("DEPARTMENT", "部门级及以上单位"); |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String label; |
||||||
|
|
||||||
|
UnitTreeType(String name, String label) { |
||||||
|
this.name = name; |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getLabel() { |
||||||
|
return label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setLabel(String label) { |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
package edu.ncst.carbon.enums; |
||||||
|
|
||||||
|
// 单位类型
|
||||||
|
public enum UnitType implements EnumType { |
||||||
|
|
||||||
|
COMPANY("COMPANY", "公司"), |
||||||
|
DEPARTMENT("DEPARTMENT", "部门"), |
||||||
|
STATION("STATION","所"); |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String label; |
||||||
|
|
||||||
|
UnitType(String name, String label) { |
||||||
|
this.name = name; |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getLabel() { |
||||||
|
return label; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setLabel(String label) { |
||||||
|
this.label = label; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,41 @@ |
|||||||
|
package edu.ncst.carbon.exception; |
||||||
|
|
||||||
|
import org.springframework.security.core.AuthenticationException; |
||||||
|
|
||||||
|
public class BusinessException extends AuthenticationException { |
||||||
|
|
||||||
|
private CodeMsg codeMsg; |
||||||
|
|
||||||
|
public BusinessException(String msg){ |
||||||
|
super(msg); |
||||||
|
codeMsg = CodeMsg.BUSINESS_ERROR.fillArgs(msg); |
||||||
|
} |
||||||
|
|
||||||
|
public BusinessException(CodeMsg msg){ |
||||||
|
super(msg.getMsg()); |
||||||
|
if(msg==null){ |
||||||
|
msg=CodeMsg.BUSINESS_ERROR.fillArgs("未知错误"); |
||||||
|
} |
||||||
|
|
||||||
|
this.codeMsg = msg; |
||||||
|
} |
||||||
|
public CodeMsg getError() { |
||||||
|
if(codeMsg==null){ |
||||||
|
codeMsg=CodeMsg.BUSINESS_ERROR.fillArgs("未知错误"); |
||||||
|
} |
||||||
|
return codeMsg; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getMessage() { |
||||||
|
if(codeMsg==null){ |
||||||
|
String msg = super.getMessage(); |
||||||
|
if(msg==null){ |
||||||
|
return CodeMsg.BUSINESS_ERROR.fillArgs("未知错误").getMsg(); |
||||||
|
} else{ |
||||||
|
return msg; |
||||||
|
} |
||||||
|
} |
||||||
|
return codeMsg.getMsg(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
//package edu.ncst.carbon.exception;
|
||||||
|
//
|
||||||
|
//import org.springframework.security.core.AuthenticationException;
|
||||||
|
//
|
||||||
|
//public class CaptchaException extends AuthenticationException {
|
||||||
|
//
|
||||||
|
// public Throwable CaptchaIsEmptyException(String msg, Throwable t) {
|
||||||
|
// super(msg, t);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Throwable CaptchaIsEmptyException(String msg) {
|
||||||
|
// super(msg);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Throwable CaptchaIsExpiredException(String msg, Throwable t) {
|
||||||
|
// super(msg, t);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Throwable CaptchaIsExpiredException(String msg) {
|
||||||
|
// super(msg);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Throwable CaptchaIsNotRightException(String msg, Throwable t) {
|
||||||
|
// super(msg, t);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Throwable CaptchaIsNotRightException(String msg) {
|
||||||
|
// super(msg);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@ -0,0 +1,96 @@ |
|||||||
|
package edu.ncst.carbon.exception; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
import org.springframework.validation.BindingResult; |
||||||
|
import org.springframework.validation.ObjectError; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class CodeMsg { |
||||||
|
|
||||||
|
public static final CodeMsg SUCCESS = new CodeMsg(0, "成功"); |
||||||
|
public static final CodeMsg SUCCESS_MSG = new CodeMsg(0, "%s"); |
||||||
|
public final static CodeMsg SERVER_ERROR = new CodeMsg(500, "服务器错误:%s"); |
||||||
|
public static final CodeMsg PARAM_ERROR = new CodeMsg(501, "参数错误:%s"); |
||||||
|
public static final CodeMsg GLOBAL_ERROR = new CodeMsg(502, "全局错误:%s"); |
||||||
|
public static final CodeMsg BUSINESS_ERROR = new CodeMsg(503, "业务错误:%s"); |
||||||
|
; |
||||||
|
public final static CodeMsg BIND_ERROR = new CodeMsg(500, "参数错误:%s"); |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户权限 100XX |
||||||
|
*/ |
||||||
|
public final static CodeMsg USER_NEED_LOGIN = new CodeMsg(10000, "尚未登录,请登录。"); |
||||||
|
public final static CodeMsg USERNAME_REQUIRE_NOT_NULL = new CodeMsg(10001, "用户名不能为空"); |
||||||
|
public final static CodeMsg PASSWORD_REQUIRE_NOT_NULL = new CodeMsg(10002, "用户密码不能为空"); |
||||||
|
public final static CodeMsg USER_NOT_FOUND = new CodeMsg(10003, "该用户不存在。"); |
||||||
|
public final static CodeMsg USERNAME_OR_PASSWORD_ERROR = new CodeMsg(10004, "用户名或密码错误"); |
||||||
|
public final static CodeMsg USER_IS_LOCKED = new CodeMsg(10005, "当前IP已被锁定,请1小时后再试。"); |
||||||
|
public final static CodeMsg USER_CREDENTIALS_EXPIRED = new CodeMsg(10006, "用户登录凭证过期,请重新登录。"); |
||||||
|
public final static CodeMsg USER_ACCOUNT_EXPIRED = new CodeMsg(10007, "用户账号过期,请联系管理员。"); |
||||||
|
public final static CodeMsg USER_IS_DISABLED = new CodeMsg(10008, "该用户已被禁用,请联系管理员。"); |
||||||
|
public final static CodeMsg USER_BAD_CREDENTIALS = new CodeMsg(10009, "无效的登录凭证,请尝试重新登录"); |
||||||
|
public final static CodeMsg USER_TOKEN_EXPIRED = new CodeMsg(10010, "用户凭证已过期,请联系管理员。"); |
||||||
|
public final static CodeMsg NOT_GET_CURRENT_USER_INFO = new CodeMsg(10011, "无法获取当前用户信息。"); |
||||||
|
public final static CodeMsg CAN_NOT_DATA_ACCESS = new CodeMsg(10012, "当前用户没有访问相关数据的权限。"); |
||||||
|
public final static CodeMsg BIND_USER_FAIL = new CodeMsg(10014, "绑定用户失败 %s"); |
||||||
|
public final static CodeMsg LOGIN_FAIL = new CodeMsg(10015, "登录失败,未知原因。"); |
||||||
|
public final static CodeMsg CAN_NOT_GET_OPEN_ID = new CodeMsg(10016, "无法获取 OpenID。"); |
||||||
|
public final static CodeMsg CAPTCHA_IS_NOT_RIGHT = new CodeMsg(10018, "验证码错误。"); |
||||||
|
public final static CodeMsg CAPTCHA_IS_EMPTY = new CodeMsg(10019, "验证码不能为空。"); |
||||||
|
public final static CodeMsg CAPTCHA_IS_EXPIRED = new CodeMsg(10020, "验证码已过期。"); |
||||||
|
public static final CodeMsg TEMP_TOKEN_NOT_FOUND = new CodeMsg(10021, "无法获取临时授权"); |
||||||
|
public static final CodeMsg TEMP_TOKEN_EXPIRED = new CodeMsg(10022, "临时授权已过期"); |
||||||
|
|
||||||
|
/** |
||||||
|
* 基本操作 101XX |
||||||
|
*/ |
||||||
|
public final static CodeMsg FETCH_ERROR = new CodeMsg(10100, "获取数据失败"); |
||||||
|
public final static CodeMsg ADD_ERROR = new CodeMsg(10101, "添加失败%s"); |
||||||
|
public final static CodeMsg MODIFY_ERROR = new CodeMsg(10102, "修改失败"); |
||||||
|
public final static CodeMsg DELETE_ERROR = new CodeMsg(10103, "删除失败"); |
||||||
|
public final static CodeMsg DELETE_ERROR_RELATION_DATA = new CodeMsg(101031, "存在关联业务数据,删除或禁用失败"); |
||||||
|
public final static CodeMsg REPEAT_RECORD = new CodeMsg(10104, "字段与已有记录重复"); |
||||||
|
public final static CodeMsg ENABLE_OR_DISABLE_ERROR = new CodeMsg(10105, "启用或禁用出错。"); |
||||||
|
public final static CodeMsg CAN_FOUND_DICT = new CodeMsg(10106, "找不到字典。"); |
||||||
|
public final static CodeMsg FORM_ERROR = new CodeMsg(10107, "表单参数错误"); |
||||||
|
public static final CodeMsg MORE_THAN_ONE_ITEM = new CodeMsg(10108, "多余一条数据被查出"); |
||||||
|
public static final CodeMsg ALREADY_EXIST_ITEM = new CodeMsg(10109, "数据重复"); |
||||||
|
public static final CodeMsg UPLOAD_ERROR = new CodeMsg(10110, "上传错误"); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 角色管理 102XX |
||||||
|
*/ |
||||||
|
public final static CodeMsg ENABLE_OR_DISABLE_ROLE_ERROR = new CodeMsg(10201, "启用或禁用出错。"); |
||||||
|
|
||||||
|
|
||||||
|
private int code; |
||||||
|
private String msg; |
||||||
|
|
||||||
|
public CodeMsg(int i, String s) { |
||||||
|
this.code = i; |
||||||
|
this.msg = s; |
||||||
|
} |
||||||
|
|
||||||
|
public CodeMsg fillArgs(Object... args) { |
||||||
|
String message = String.format(msg, args); |
||||||
|
return new CodeMsg(code, message); |
||||||
|
} |
||||||
|
|
||||||
|
public CodeMsg fillFieldError(BindingResult bindingResult) { |
||||||
|
String defaultMessage = ""; |
||||||
|
|
||||||
|
if (bindingResult.hasErrors()) { |
||||||
|
List<ObjectError> allErrors = bindingResult.getAllErrors(); |
||||||
|
|
||||||
|
if (!allErrors.isEmpty()) { |
||||||
|
defaultMessage = allErrors.get(0).getDefaultMessage(); |
||||||
|
} |
||||||
|
} |
||||||
|
String message = String.format(msg, defaultMessage); |
||||||
|
return new CodeMsg(code, message); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
package edu.ncst.carbon.exception.handler; |
||||||
|
|
||||||
|
import edu.ncst.carbon.exception.BusinessException; |
||||||
|
import edu.ncst.carbon.exception.CodeMsg; |
||||||
|
import edu.ncst.carbon.utils.ResponseUtils; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice; |
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义异常处理器 |
||||||
|
* |
||||||
|
* @author ieflex |
||||||
|
*/ |
||||||
|
@RestControllerAdvice |
||||||
|
@Slf4j |
||||||
|
public class InterfaceExceptionHandler { |
||||||
|
|
||||||
|
/** |
||||||
|
* 接口 业务异常 |
||||||
|
*/ |
||||||
|
@ResponseBody |
||||||
|
@ExceptionHandler(BusinessException.class) |
||||||
|
public ResponseEntity businessInterfaceException(BusinessException e) { |
||||||
|
log.error(e.getMessage(), e); |
||||||
|
return ResponseUtils.error(CodeMsg.BUSINESS_ERROR.fillArgs(e.getError())); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 拦截所有运行时的全局异常 |
||||||
|
*/ |
||||||
|
@ExceptionHandler(RuntimeException.class) |
||||||
|
@ResponseBody |
||||||
|
public ResponseEntity runtimeException(RuntimeException e) { |
||||||
|
log.error(e.getMessage(), e); |
||||||
|
// 返回 JOSN
|
||||||
|
return ResponseUtils.error(CodeMsg.GLOBAL_ERROR.fillArgs(e.toString())); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 系统异常捕获处理 |
||||||
|
*/ |
||||||
|
@ExceptionHandler(Exception.class) |
||||||
|
@ResponseBody |
||||||
|
public ResponseEntity exception(Exception e) { |
||||||
|
log.error(e.getMessage(), e); |
||||||
|
return ResponseUtils.error(CodeMsg.SERVER_ERROR.fillArgs(e.toString())); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
package edu.ncst.carbon.mapper; |
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.apache.ibatis.logging.Log; |
||||||
|
import org.apache.ibatis.logging.LogFactory; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义 Mapper 接口, 实现 自定义扩展 |
||||||
|
* |
||||||
|
* @param <M> mapper 泛型 |
||||||
|
* @param <T> table 泛型 |
||||||
|
* @param <V> vo 泛型 |
||||||
|
* @author Lion Li |
||||||
|
* @since 2021-05-13 |
||||||
|
*/ |
||||||
|
@SuppressWarnings("unchecked") |
||||||
|
public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> { |
||||||
|
|
||||||
|
Log log = LogFactory.getLog(BaseMapperPlus.class); |
||||||
|
|
||||||
|
int DEFAULT_BATCH_SIZE = 1000; |
||||||
|
|
||||||
|
|
||||||
|
default List<T> selectList() { |
||||||
|
return this.selectList(new QueryWrapper<>()); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
package edu.ncst.carbon.mapper.carbon; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormula; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface CarbonFormulaMapper extends BaseMapper<CarFormula> { |
||||||
|
|
||||||
|
Page<CarFormula> getCarFormulaList(Page<CarFormula> pageRequest, @Param(Constants.WRAPPER) QueryWrapper<CarFormula> queryWrapper); |
||||||
|
|
||||||
|
CarFormula getCarFormulaDetail(Integer id); |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
package edu.ncst.carbon.mapper.carbon; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormulaType; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式类型 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface CarbonFormulaTypeMapper extends BaseMapper<CarFormulaType> { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
package edu.ncst.carbon.mapper.carbon; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormulaUnit; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式单位 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface CarbonFormulaUnitMapper extends BaseMapper<CarFormulaUnit> { |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
package edu.ncst.carbon.mapper.goods; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.goods.Goods; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式类型 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface GoodsMapper extends BaseMapper<Goods> { |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
package edu.ncst.carbon.mapper.image; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.image.Image; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface ImageMapper extends BaseMapper<Image> { |
||||||
|
|
||||||
|
int uploadImage(@Param("image")Image image); |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
package edu.ncst.carbon.mapper.log; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.log.LogUserFootprint; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户碳足迹 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface LogUserFootprintMapper extends BaseMapper<LogUserFootprint> { |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
package edu.ncst.carbon.mapper.log; |
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.log.LogUserGoods; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户碳足迹 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface LogUserGoodsMapper extends BaseMapper<LogUserGoods> { |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
package edu.ncst.carbon.mapper.log; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.log.LogUser; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户当前数据 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface LogUserMapper extends BaseMapper<LogUser> { |
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
package edu.ncst.carbon.mapper.log; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import edu.ncst.carbon.model.log.LoginLog; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 登录日志 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface LoginLogMapper extends BaseMapper<LoginLog> { |
||||||
|
|
||||||
|
Page<LoginLog> getLoginLogList(@Param("pageRequest") Page<LoginLog> pageRequest, @Param(Constants.WRAPPER) QueryWrapper<LoginLog> queryWrapper); |
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
package edu.ncst.carbon.mapper.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import edu.ncst.carbon.model.system.Menu; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 菜单 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface MenuMapper extends BaseMapper<Menu> { |
||||||
|
|
||||||
|
int batchInsert(List<Menu> menuList); |
||||||
|
|
||||||
|
int batchInsertOrUpdate(List<Menu> menuList); |
||||||
|
|
||||||
|
Page<Menu> getMenuList(Page<Menu> pageRequest, @Param("parentId") Integer parentId); |
||||||
|
|
||||||
|
List<Menu> getMenuTree(@Param("parentId") Integer parentId); |
||||||
|
|
||||||
|
// 清空菜单项
|
||||||
|
int removeAllMenuItem(); |
||||||
|
|
||||||
|
// 获取指定角色能够访问的菜单ID
|
||||||
|
List<Integer> getRoleMenuIds(Integer roleId); |
||||||
|
|
||||||
|
List<String> getCurrentUserMenuAuthority(List<String> roleNames); |
||||||
|
|
||||||
|
List<Integer> getParentMenuid(List<Integer> menuIds); |
||||||
|
|
||||||
|
List<Integer> getRoleMenuIdsWithParent(Integer roleId); |
||||||
|
} |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
package edu.ncst.carbon.mapper.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.system.Resource; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface ResourceMapper extends BaseMapper<Resource> { |
||||||
|
|
||||||
|
List<String> getRolesResourceUrls(List<String> roleNames); |
||||||
|
|
||||||
|
int batchReplaceOrInsert(List<Resource> resources); |
||||||
|
|
||||||
|
int batchInsert(List<Resource> resources); |
||||||
|
|
||||||
|
int replaceOrInsert(@RequestParam("resource") Resource resource); |
||||||
|
|
||||||
|
Integer getIdByName(String name); |
||||||
|
|
||||||
|
int insertNotExisted(@RequestParam("resource") Resource resource); |
||||||
|
|
||||||
|
List<Integer> getRoleResourceIds(Integer roleId); |
||||||
|
|
||||||
|
List<Resource> getResourceTree(); |
||||||
|
|
||||||
|
List<Resource> getPermitAllResourceList(); |
||||||
|
List<Resource> getUserScopeResourceList(); |
||||||
|
|
||||||
|
List<String> getPermitAllResourceURLs(); |
||||||
|
|
||||||
|
List<String> getUserScopeResourceURLs(); |
||||||
|
|
||||||
|
// 所有用户都可以访问的查询接口
|
||||||
|
List<Integer> getAllResourceIds(); |
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
package edu.ncst.carbon.mapper.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.mapper.BaseMapperPlus; |
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.apache.ibatis.annotations.Select; |
||||||
|
import org.apache.ibatis.annotations.Update; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色表 数据层 |
||||||
|
* |
||||||
|
* @author Lion Li |
||||||
|
*/ |
||||||
|
public interface RoleMapper extends BaseMapper<Role> { |
||||||
|
|
||||||
|
@Update("UPDATE sys_role SET enable = #{ enable } WHERE id = #{ id }") |
||||||
|
int setRoleEnable(Integer id, Boolean enable); |
||||||
|
|
||||||
|
@Select("SELECT * FROM sys_role WHERE name = #{ name }") |
||||||
|
Role getRoleByName(String name); |
||||||
|
|
||||||
|
void setDefaultResource(@Param("id") Integer id, @Param("resourcesIds") List<Integer> resourcesIds); |
||||||
|
|
||||||
|
int getNumOfUserByRoleId(Integer id); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,17 @@ |
|||||||
|
package edu.ncst.carbon.mapper.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.system.RoleMenu; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色菜单 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface RoleMenuMapper extends BaseMapper<RoleMenu> { |
||||||
|
int batchInsert(Integer roleId, List<Integer> menuIds); |
||||||
|
|
||||||
|
void selectParentMenu(List<Integer> menuIds); |
||||||
|
} |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
package edu.ncst.carbon.mapper.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.system.RoleResource; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色资源 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface RoleResourceMapper extends BaseMapper<RoleResource> { |
||||||
|
int batchInsert(Integer roleId, List<Integer> resourceIds); |
||||||
|
int batchDelete(Integer roleId); |
||||||
|
} |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
package edu.ncst.carbon.mapper.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import edu.ncst.carbon.model.system.User; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.apache.ibatis.annotations.Update; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
//从Service层 到了现在的 Mapper接口层,在之后才是Mapper层
|
||||||
|
public interface UserMapper extends BaseMapper<User> { |
||||||
|
|
||||||
|
Page<Integer> getUserPage( |
||||||
|
@Param("pageRequest") Page<User> pageRequest, |
||||||
|
@Param(Constants.WRAPPER) QueryWrapper queryWrapper |
||||||
|
); |
||||||
|
|
||||||
|
List<User> getUserList( @Param(Constants.WRAPPER) QueryWrapper queryWrapper); |
||||||
|
|
||||||
|
User getUserDetail(Integer userId); |
||||||
|
|
||||||
|
|
||||||
|
//User getUserByWechatId(String wechatId);
|
||||||
|
|
||||||
|
|
||||||
|
@Update("UPDATE sys_user SET enable = #{ enable } WHERE id = #{ userId }") |
||||||
|
int setUserEnable(Integer userId, Boolean enable); |
||||||
|
|
||||||
|
User getUserByAccount(String username); |
||||||
|
|
||||||
|
User getUserByOpenId(String openId); |
||||||
|
|
||||||
|
int bindUserOpenId(Integer id, String openId); |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
package edu.ncst.carbon.mapper.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.system.UserRole; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户角色 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface UserRoleMapper extends BaseMapper<UserRole> { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
package edu.ncst.carbon.mapper.task; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import edu.ncst.carbon.model.task.Task; |
||||||
|
import edu.ncst.carbon.model.task.TaskAudit; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 任务审核 Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface TaskAuditMapper extends BaseMapper<TaskAudit> { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
package edu.ncst.carbon.mapper.task; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import edu.ncst.carbon.model.task.Task; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
/** |
||||||
|
* 低碳任务Mapper 接口 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface TaskMapper extends BaseMapper<Task> { |
||||||
|
Page<Task> getTaskList(Page<Task> pageRequest, @Param(Constants.WRAPPER) QueryWrapper<Task> queryWrapper); |
||||||
|
|
||||||
|
Task getTaskDetail(Integer id); |
||||||
|
|
||||||
|
int deleteByPrimaryKey(Integer id); |
||||||
|
|
||||||
|
int insert(Task record); |
||||||
|
|
||||||
|
int insertSelective(Task record); |
||||||
|
|
||||||
|
Task selectByPrimaryKey(Integer id); |
||||||
|
|
||||||
|
int updateByPrimaryKeySelective(Task record); |
||||||
|
|
||||||
|
int updateByPrimaryKey(Task record); |
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
package edu.ncst.carbon.model; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
@Data |
||||||
|
public abstract class BaseEntity implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间") |
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT) |
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建人") |
||||||
|
@TableField(value = "create_user_id", fill = FieldFill.INSERT) |
||||||
|
private Integer createUserId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "最后更新时间") |
||||||
|
@TableField(value = "last_modify_time", fill = FieldFill.INSERT_UPDATE) |
||||||
|
private Date lastModifyTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "最后更新者") |
||||||
|
@TableField(value = "last_modify_user_id", fill = FieldFill.INSERT_UPDATE) |
||||||
|
private Integer lastModifyUserId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "删除时间") |
||||||
|
@TableField("delete_time") |
||||||
|
@TableLogic |
||||||
|
private Date deleteTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "删除者") |
||||||
|
@TableField("delete_user_id") |
||||||
|
private Integer deleteUserId; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,58 @@ |
|||||||
|
package edu.ncst.carbon.model.carbon; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import edu.ncst.carbon.model.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式 |
||||||
|
* |
||||||
|
* @author 强子烨 |
||||||
|
* @version 1.0 |
||||||
|
* @since 2022-11-24 |
||||||
|
*/ |
||||||
|
@ApiModel(value="CarFormula", description="碳公式") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@TableName(value = "car_formula", autoResultMap = true) |
||||||
|
public class CarFormula extends BaseEntity implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 8919112438414925446L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳公式基础信息表") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳公式名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳排放量/每碳单位") |
||||||
|
private Float emission; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳积分/每碳单位") |
||||||
|
private Float intergral; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳类型id") |
||||||
|
private Integer typeId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳类型") |
||||||
|
@TableField(exist = false) |
||||||
|
private CarFormulaType type; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳排放单位id") |
||||||
|
private Integer unitId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳排放单位") |
||||||
|
@TableField(exist = false) |
||||||
|
private CarFormulaUnit unit; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,47 @@ |
|||||||
|
package edu.ncst.carbon.model.carbon; |
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式类别 |
||||||
|
* |
||||||
|
* @author 强子烨 |
||||||
|
* @version 1.0 |
||||||
|
* @since 2022-11-24 |
||||||
|
*/ |
||||||
|
@ApiModel(value="CarFormulaType", description="碳类别") |
||||||
|
@Data |
||||||
|
//@EqualsAndHashCode(callSuper = true)、
|
||||||
|
@TableName(value = "car_formula_type", autoResultMap = true) |
||||||
|
public class CarFormulaType implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1916757432923294628L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳类别id") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳类别") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳类别名称") |
||||||
|
private String label; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否启用") |
||||||
|
private Boolean enable; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "删除时间") |
||||||
|
@TableLogic |
||||||
|
@JsonIgnore |
||||||
|
private Date deleteTime; |
||||||
|
} |
||||||
@ -0,0 +1,43 @@ |
|||||||
|
package edu.ncst.carbon.model.carbon; |
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式单位 |
||||||
|
* |
||||||
|
* @author 强子烨 |
||||||
|
* @version 1.0 |
||||||
|
* @since 2022-11-24 |
||||||
|
*/ |
||||||
|
@ApiModel(value="CarFormulaUnit", description="碳公式单位") |
||||||
|
@Data |
||||||
|
//@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value = "car_formula_unit", autoResultMap = true) |
||||||
|
public class CarFormulaUnit implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 814435312663136536L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳排放单位id") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳排放单位") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳排放单位名称") |
||||||
|
private String label; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否启用") |
||||||
|
private String enable; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "删除时间") |
||||||
|
private Date deleteTime; |
||||||
|
} |
||||||
@ -0,0 +1,68 @@ |
|||||||
|
package edu.ncst.carbon.model.goods; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import edu.ncst.carbon.model.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* goods_detail |
||||||
|
* @author |
||||||
|
*/ |
||||||
|
@ApiModel(value="GoodsDetail", description="商品基础信息") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@TableName(value = "goods_detail", autoResultMap = true) |
||||||
|
public class Goods extends BaseEntity implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品基础信息id") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品详情 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "商品详情") |
||||||
|
private String detail; |
||||||
|
|
||||||
|
/** |
||||||
|
* 供应商id |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "供应商id") |
||||||
|
private Integer supplierId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 价格 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "价格") |
||||||
|
private Integer price; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数量 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "数量") |
||||||
|
private Integer quantity; |
||||||
|
|
||||||
|
/** |
||||||
|
* 销量 |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "销量") |
||||||
|
private Integer sales; |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品图片id |
||||||
|
*/ |
||||||
|
@ApiModelProperty(value = "商品图片id") |
||||||
|
private Integer imageId; |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
package edu.ncst.carbon.model.image; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* 图片 |
||||||
|
*/ |
||||||
|
@ApiModel(value="Image", description="图片") |
||||||
|
@Data |
||||||
|
@TableName(value = "Image") |
||||||
|
public class Image { |
||||||
|
|
||||||
|
@ApiModelProperty(value = "ID") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty("图片的线上地址") |
||||||
|
private String imgUrl; |
||||||
|
|
||||||
|
@ApiModelProperty("图片名称") |
||||||
|
private String imgName; |
||||||
|
} |
||||||
@ -0,0 +1,47 @@ |
|||||||
|
package edu.ncst.carbon.model.log; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* log_user |
||||||
|
* @author |
||||||
|
*/ |
||||||
|
@ApiModel(value="LogUser", description="用户当前数据") |
||||||
|
@Data |
||||||
|
@TableName(value = "log_user", autoResultMap = true) |
||||||
|
public class LogUser implements Serializable { |
||||||
|
/** |
||||||
|
* 用户当前信息 |
||||||
|
*/ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户id |
||||||
|
*/ |
||||||
|
private Integer userId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前积分总数 |
||||||
|
*/ |
||||||
|
private Integer integralTotal; |
||||||
|
|
||||||
|
/** |
||||||
|
* 累计减碳 |
||||||
|
*/ |
||||||
|
private double emissionTotal; |
||||||
|
|
||||||
|
/** |
||||||
|
* 审批中的碳任务总数 |
||||||
|
*/ |
||||||
|
private Integer auditingTaskTotal; |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
||||||
@ -0,0 +1,69 @@ |
|||||||
|
package edu.ncst.carbon.model.log; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import edu.ncst.carbon.model.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* log_user_footprint |
||||||
|
* @author |
||||||
|
*/ |
||||||
|
@ApiModel(value="LogUserFootprint", description="用户碳足迹") |
||||||
|
@Data |
||||||
|
@TableName(value = "log_user_footprint", autoResultMap = true) |
||||||
|
public class LogUserFootprint implements Serializable { |
||||||
|
/** |
||||||
|
* ID |
||||||
|
*/ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户id |
||||||
|
*/ |
||||||
|
private Integer userId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式id |
||||||
|
*/ |
||||||
|
private Integer formulaId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取积分 |
||||||
|
*/ |
||||||
|
private float integral; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳排放量 |
||||||
|
*/ |
||||||
|
private float emission; |
||||||
|
|
||||||
|
/** |
||||||
|
* 低碳任务id |
||||||
|
*/ |
||||||
|
private Integer taskId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 该记录创建时间 |
||||||
|
*/ |
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否删除 |
||||||
|
*/ |
||||||
|
private Boolean isDelete; |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除时间 |
||||||
|
*/ |
||||||
|
private Date deleteTime; |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
package edu.ncst.carbon.model.log; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import edu.ncst.carbon.model.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* log_user_goods |
||||||
|
* @author |
||||||
|
*/ |
||||||
|
@ApiModel(value="CarFormula", description="碳公式") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@TableName(value = "car_formula", autoResultMap = true) |
||||||
|
public class LogUserGoods extends BaseEntity implements Serializable { |
||||||
|
/** |
||||||
|
* 商品购买记录表 |
||||||
|
*/ |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品id |
||||||
|
*/ |
||||||
|
private Integer goodsId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品名称 |
||||||
|
*/ |
||||||
|
private String goodsName; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户id |
||||||
|
*/ |
||||||
|
private Integer userId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 购买数量 |
||||||
|
*/ |
||||||
|
private Integer number; |
||||||
|
|
||||||
|
/** |
||||||
|
* 消耗积分 |
||||||
|
*/ |
||||||
|
private Integer costIntegral; |
||||||
|
|
||||||
|
/** |
||||||
|
* 购买时间 |
||||||
|
*/ |
||||||
|
private Date buyTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 订单编号 |
||||||
|
*/ |
||||||
|
private String orderNumber; |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
||||||
@ -0,0 +1,50 @@ |
|||||||
|
package edu.ncst.carbon.model.log; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import edu.ncst.carbon.model.system.User; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* 登录日志 |
||||||
|
*/ |
||||||
|
@ApiModel(value="LoginLog", description="登录日志") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@TableName("log_login_log") |
||||||
|
public class LoginLog implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID=1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "ID") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "登录方式") |
||||||
|
private String type; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户ID") |
||||||
|
private Integer userId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "登錄用户") |
||||||
|
@TableField(exist = false) |
||||||
|
private User user; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "登录凭证", notes = "用户名、手机号、电子邮箱或微信登录凭证code") |
||||||
|
private String principal; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "IP地址") |
||||||
|
private String ipAddress; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "登录时间") |
||||||
|
private Date loginTime; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,91 @@ |
|||||||
|
package edu.ncst.carbon.model.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||||
|
import edu.ncst.carbon.enums.MenuType; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
/** |
||||||
|
* 菜单 |
||||||
|
*/ |
||||||
|
@ApiModel(value="Menu", description="菜单") |
||||||
|
@Data |
||||||
|
@TableName("sys_menu") |
||||||
|
public class Menu implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID=1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单ID") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单类型 1:菜单 2:页面 3.按钮 ") |
||||||
|
private MenuType type; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单标题") |
||||||
|
private String title; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单图标") |
||||||
|
private String icon; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单链接") |
||||||
|
private String url; |
||||||
|
|
||||||
|
// @ApiModelProperty(value = "路由名称")
|
||||||
|
// private String routeName;
|
||||||
|
//
|
||||||
|
// @ApiModelProperty(value = "路由路径")
|
||||||
|
// private String routePath;
|
||||||
|
//
|
||||||
|
// @ApiModelProperty(value = "路由组件")
|
||||||
|
// private String routeComponentName;
|
||||||
|
//
|
||||||
|
// @ApiModelProperty(value = "是否开启路由缓存")
|
||||||
|
// private Boolean routeCache;
|
||||||
|
|
||||||
|
// @ApiModelProperty(value = "关联权限ID")
|
||||||
|
// private Integer authorityId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "上级菜单") |
||||||
|
private Integer parentId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "下级菜单") |
||||||
|
@TableField(exist = false) |
||||||
|
private List<Menu> children; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否显示在菜单上") |
||||||
|
private Boolean showInMenu = true; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "显示排序") |
||||||
|
private Integer sort = 0; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "备注") |
||||||
|
private String remark; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "删除时间") |
||||||
|
@TableLogic |
||||||
|
private Date deleteTime; |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object o) { |
||||||
|
if (this == o) return true; |
||||||
|
if (o == null || getClass() != o.getClass()) return false; |
||||||
|
Menu menu = (Menu) o; |
||||||
|
return Objects.equals(name, menu.name); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int hashCode() { |
||||||
|
return Objects.hash(name); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,58 @@ |
|||||||
|
package edu.ncst.carbon.model.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@ApiModel(value="Resource", description="资源") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@TableName("sys_resource") |
||||||
|
public class Resource implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "资源ID") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "显示文本") |
||||||
|
private String label; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "资源名称(方法签名)") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "请求方法类型") |
||||||
|
private String method; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "链接") |
||||||
|
private String url; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "允许所有访问", notes = "不需要用户登录") |
||||||
|
private Boolean permitAll = false; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户作用域") |
||||||
|
private Boolean userScope = false; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "上级菜单ID") |
||||||
|
private Integer parentId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "上级菜单ID") |
||||||
|
@TableField(exist = false) |
||||||
|
private List<Resource> children; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "排序") |
||||||
|
private Integer sort; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否對所有角色開放",notes = "需要用户登录") |
||||||
|
private Boolean isForAll = true; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,77 @@ |
|||||||
|
package edu.ncst.carbon.model.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||||
|
import edu.ncst.carbon.model.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.Objects; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色 |
||||||
|
*/ |
||||||
|
@ApiModel(value="Role", description="角色") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@TableName("sys_role") |
||||||
|
public class Role implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID=1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色ID") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "显示文本") |
||||||
|
private String label; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否启用") |
||||||
|
private Boolean enable; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "删除时间") |
||||||
|
@TableLogic |
||||||
|
@JsonIgnore |
||||||
|
private Date deleteTime; |
||||||
|
|
||||||
|
public Role(Integer id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public Role() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object o) { |
||||||
|
if (this == o) return true; |
||||||
|
|
||||||
|
if (o == null || getClass() != o.getClass()) return false; |
||||||
|
|
||||||
|
Role role = (Role) o; |
||||||
|
|
||||||
|
return Objects.equals(name, role.name); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int hashCode() { |
||||||
|
return Objects.hash(name); |
||||||
|
} |
||||||
|
|
||||||
|
public static Role forName(String name) { |
||||||
|
Role role = new Role(); |
||||||
|
role.setName(name); |
||||||
|
return role; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,28 @@ |
|||||||
|
package edu.ncst.carbon.model.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色菜单 |
||||||
|
*/ |
||||||
|
@ApiModel(value="RoleMenu", description="角色菜单") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@TableName("sys_role_menu") |
||||||
|
public class RoleMenu implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID=1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色ID") |
||||||
|
private Integer roleId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单ID") |
||||||
|
private Integer menuId; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
package edu.ncst.carbon.model.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色资源 |
||||||
|
*/ |
||||||
|
@ApiModel(value="RoleResource", description="角色资源") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@TableName("sys_role_resource") |
||||||
|
public class RoleResource implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色ID") |
||||||
|
private Integer roleId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "资源ID") |
||||||
|
private Integer resourceId; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,114 @@ |
|||||||
|
package edu.ncst.carbon.model.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||||
|
import edu.ncst.carbon.model.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springframework.security.core.GrantedAuthority; |
||||||
|
import org.springframework.security.core.authority.SimpleGrantedAuthority; |
||||||
|
import org.springframework.security.core.userdetails.UserDetails; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户 |
||||||
|
*/ |
||||||
|
@ApiModel(value="User", description="用户") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@TableName("sys_user") |
||||||
|
public class User extends BaseEntity implements Serializable, UserDetails { |
||||||
|
|
||||||
|
private static final long serialVersionUID=1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户ID") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户名") |
||||||
|
private String username; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户密码") |
||||||
|
private String password; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "电子邮箱") |
||||||
|
private String email; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户真实名") |
||||||
|
private String fullName; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "手机号") |
||||||
|
private String phone; |
||||||
|
|
||||||
|
// @ApiModelProperty(value = "微信小程序id")
|
||||||
|
// private Integer OpenId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "OpenID") |
||||||
|
private String openId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色列表") |
||||||
|
@TableField(exist = false) |
||||||
|
private List<Role> roles; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否启用 1:启用 0:禁用") |
||||||
|
private Boolean enable; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "最后登录时间") |
||||||
|
private Date lastLoginTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "最后登录IP地址") |
||||||
|
private String lastLoginIp; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 在角色标识前添加 "ROLE_" 前缀,加入到权限列表当中。 |
||||||
|
* @return 整合的权限列表 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Collection<? extends GrantedAuthority> getAuthorities() { |
||||||
|
List<GrantedAuthority> grantedAuthorities = new ArrayList<>(); |
||||||
|
|
||||||
|
if (this.roles != null && this.roles.size() > 0) { |
||||||
|
List<GrantedAuthority> roleAuthority = roles.stream() |
||||||
|
.map((role) -> new SimpleGrantedAuthority("ROLE_" + role.getName())) |
||||||
|
.collect(Collectors.toList()); |
||||||
|
grantedAuthorities.addAll(roleAuthority); |
||||||
|
} |
||||||
|
|
||||||
|
return grantedAuthorities; |
||||||
|
} |
||||||
|
|
||||||
|
@JsonIgnore |
||||||
|
public boolean isAccountNonExpired() { |
||||||
|
return true; |
||||||
|
}//用户是否未过期
|
||||||
|
|
||||||
|
@JsonIgnore |
||||||
|
@Override |
||||||
|
public boolean isAccountNonLocked() { |
||||||
|
return true; |
||||||
|
}//用户是否未锁定
|
||||||
|
|
||||||
|
@JsonIgnore |
||||||
|
@Override |
||||||
|
public boolean isCredentialsNonExpired() { |
||||||
|
return true; |
||||||
|
}//凭证是否未过期
|
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isEnabled() { |
||||||
|
return this.enable; |
||||||
|
}//是否启用
|
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
package edu.ncst.carbon.model.system; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户角色 |
||||||
|
*/ |
||||||
|
@ApiModel(value="UserRole", description="用户角色") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = false) |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@TableName("sys_user_role") |
||||||
|
public class UserRole implements Serializable { |
||||||
|
|
||||||
|
private static final long serialVersionUID=1L; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户ID") |
||||||
|
private Integer userId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色ID") |
||||||
|
private Integer roleId; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,47 @@ |
|||||||
|
package edu.ncst.carbon.model.task; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
/** |
||||||
|
* 低碳任务 |
||||||
|
* |
||||||
|
* @author |
||||||
|
*/ |
||||||
|
@ApiModel(value="Task", description="低碳任务") |
||||||
|
@Data |
||||||
|
//@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value = "task", autoResultMap = true) |
||||||
|
public class Task implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳公式基础信息表") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "任务名称") |
||||||
|
private String name; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否启用") |
||||||
|
private Boolean enable; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "删除时间") |
||||||
|
private Date deleteTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "对应碳公式id") |
||||||
|
private Integer carbonFormulaId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "供应商id") |
||||||
|
private Integer supplierId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "图像url") |
||||||
|
private Integer imageId; |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
package edu.ncst.carbon.model.task; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import edu.ncst.carbon.model.BaseEntity; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* task_audit |
||||||
|
* @author 强子烨 |
||||||
|
*/ |
||||||
|
@ApiModel(value="Task", description="低碳任务") |
||||||
|
@Data |
||||||
|
@TableName(value = "task_audit", autoResultMap = true) |
||||||
|
public class TaskAudit implements Serializable { |
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "任务审核ID") |
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Integer id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "审核图片id") |
||||||
|
private Integer imageId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "审核文本") |
||||||
|
private String text; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "审批积分") |
||||||
|
private Integer integral; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "碳排放量") |
||||||
|
private double emission; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建用户id") |
||||||
|
private Integer createUserId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建用户时间") |
||||||
|
private Integer createTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "审核者id") |
||||||
|
private Integer auditUserId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "审核时间") |
||||||
|
private Date auditTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "审批状态:待审核 1 审核通过 2 审核未通过 3 完成 0") |
||||||
|
private String status; |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
} |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormula; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.carbon.CalculationResults; |
||||||
|
|
||||||
|
/** |
||||||
|
* 碳公式 服务类 |
||||||
|
*/ |
||||||
|
public interface ICarbonFormulaService extends IService<CarFormula> { |
||||||
|
CarFormula getCarFormulaDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<CarFormula> getCarFormulaList(Query query); |
||||||
|
|
||||||
|
//ListResultVO<CarFormula> getCarFormulaListByTypeId(Integer id);
|
||||||
|
|
||||||
|
CarFormula addCarFormula(CarFormula carFormula); |
||||||
|
|
||||||
|
CarFormula modifyCarFormula(CarFormula carFormula); |
||||||
|
|
||||||
|
boolean deleteCarFormula(Integer id); |
||||||
|
|
||||||
|
CalculationResults calculation(Integer id); |
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormulaType; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
public interface ICarbonFormulaTypeService extends IService<CarFormulaType> { |
||||||
|
CarFormulaType getCarFormulaTypeDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<CarFormulaType> getCarFormulaTypeList(Query query); |
||||||
|
|
||||||
|
CarFormulaType addCarFormulaType(CarFormulaType carFormulaType); |
||||||
|
|
||||||
|
CarFormulaType modifyCarFormulaType(CarFormulaType carFormulaType); |
||||||
|
|
||||||
|
boolean deleteCarFormulaType(Integer id); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.carbon.CarFormulaUnit; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
public interface ICarbonFormulaUnitService extends IService<CarFormulaUnit> { |
||||||
|
CarFormulaUnit getCarFormulaUnitDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<CarFormulaUnit> getCarFormulaUnitList(Query query); |
||||||
|
|
||||||
|
CarFormulaUnit addCarFormulaUnit(CarFormulaUnit carFormulaUnit); |
||||||
|
|
||||||
|
CarFormulaUnit modifyCarFormulaUnit(CarFormulaUnit carFormulaUnit); |
||||||
|
|
||||||
|
boolean deleteCarFormulaUnit(Integer id); |
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.goods.Goods; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品 服务类 |
||||||
|
* */ |
||||||
|
public interface IGoodsService extends IService<Goods> { |
||||||
|
Goods getGoodsDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<Goods> getGoodsList(Query query); |
||||||
|
|
||||||
|
Goods addGoods(Goods Goods); |
||||||
|
|
||||||
|
Goods modifyGoods(Goods Goods); |
||||||
|
|
||||||
|
boolean deleteGoods(Integer id); |
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.image.Image; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 图片处理 服务类 |
||||||
|
* */ |
||||||
|
public interface IImageService extends IService<Image> { |
||||||
|
|
||||||
|
String uploadImage(@RequestParam MultipartFile uploadFile, HttpServletRequest request, String recordID) throws FileNotFoundException; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.log.LogUserFootprint; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public interface ILogUserFootprintService extends IService<LogUserFootprint> { |
||||||
|
|
||||||
|
LogUserFootprint getLogUserFootprintDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<LogUserFootprint> getLogFootprintList(Query query); |
||||||
|
|
||||||
|
List<LogUserFootprint> getLogUserFootprintList(Integer userId); |
||||||
|
|
||||||
|
LogUserFootprint addLogUserFootprint(LogUserFootprint LogUserFootprint); |
||||||
|
|
||||||
|
LogUserFootprint modifyLogUserFootprint(LogUserFootprint LogUserFootprint); |
||||||
|
|
||||||
|
boolean deleteLogUserFootprint(Integer id); |
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.log.LogUserGoods; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
public interface ILogUserGoodsService extends IService<LogUserGoods> { |
||||||
|
LogUserGoods getLogUserGoodsDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<LogUserGoods> getLogUserGoodsList(Query query); |
||||||
|
|
||||||
|
LogUserGoods addLogUserGoods(LogUserGoods LogUserGoods); |
||||||
|
|
||||||
|
LogUserGoods modifyLogUserGoods(LogUserGoods LogUserGoods); |
||||||
|
|
||||||
|
boolean deleteLogUserGoods(Integer id); |
||||||
|
} |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.log.LogUser; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
/** |
||||||
|
* 商品 服务类 |
||||||
|
* */ |
||||||
|
public interface ILogUserService extends IService<LogUser>{ |
||||||
|
|
||||||
|
LogUser getLogUserDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<LogUser> getLogUserList(Query query); |
||||||
|
|
||||||
|
LogUser addLogUser(LogUser LogUser); |
||||||
|
|
||||||
|
LogUser modifyLogUser(LogUser LogUser); |
||||||
|
|
||||||
|
boolean deleteLogUser(Integer id); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,18 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import edu.ncst.carbon.model.log.LoginLog; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.query.LoginLogQuery; |
||||||
|
|
||||||
|
/** |
||||||
|
* 登录日志 服务类 |
||||||
|
*/ |
||||||
|
public interface ILoginLogService { |
||||||
|
|
||||||
|
// 查询登录日志列表
|
||||||
|
ListResultVO<LoginLog> getLoginLogList(LoginLogQuery query); |
||||||
|
|
||||||
|
// 添加登录日志
|
||||||
|
void addLoginLog(Integer userId, Boolean success); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.system.Menu; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 菜单 服务类 |
||||||
|
*/ |
||||||
|
public interface IMenuService extends IService<Menu> { |
||||||
|
|
||||||
|
// 获取菜单列表
|
||||||
|
ListResultVO<Menu> getMenuList(Query query); |
||||||
|
|
||||||
|
// 获取菜单详情
|
||||||
|
Menu getMenuDetail(Integer id); |
||||||
|
|
||||||
|
// 添加菜单
|
||||||
|
Menu addMenu(Menu menu); |
||||||
|
|
||||||
|
// 修改菜单
|
||||||
|
Menu modifyMenu(Menu menu); |
||||||
|
|
||||||
|
// 删除菜单
|
||||||
|
boolean deleteMenu(Integer id); |
||||||
|
|
||||||
|
// // 批量删除菜单
|
||||||
|
// boolean batchDeleteMenu(BatchDeleteDTO deleteDTO);
|
||||||
|
|
||||||
|
/** |
||||||
|
* 导入菜单元信息 |
||||||
|
* @param resetMenuDTO |
||||||
|
*/ |
||||||
|
// void resetMenuMeta(ResetMenuDTO resetMenuDTO);
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取菜单树 |
||||||
|
* @return 菜单树 |
||||||
|
*/ |
||||||
|
List<Menu> getMenuTree(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前用户菜单树 |
||||||
|
* @return 菜单树 |
||||||
|
*/ |
||||||
|
List<Menu> getCurrentUserMenuTree(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前用户菜单权限列表 |
||||||
|
* @return 菜单树 |
||||||
|
*/ |
||||||
|
List<String> getCurrentUserMenuAuthority(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取指定角色能够访问的菜单ID |
||||||
|
* @param roleId |
||||||
|
*/ |
||||||
|
List<Integer> getRoleMenuIds(Integer roleId, boolean withParent); |
||||||
|
} |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import edu.ncst.carbon.model.system.Resource; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public interface IResourceService { |
||||||
|
|
||||||
|
ListResultVO<Resource> getResourceList(Query query); |
||||||
|
|
||||||
|
|
||||||
|
List<Integer> getRoleResourceIds(Integer roleId); |
||||||
|
|
||||||
|
List<String> getRolesResourceList(List<String> roleNames); |
||||||
|
|
||||||
|
List<Resource> getPermitAllResourceList(); |
||||||
|
|
||||||
|
List<Resource> getResourceTree(); |
||||||
|
|
||||||
|
List<String> getPermitAllResourceURLs(); |
||||||
|
|
||||||
|
void reimportInterfaceMeta(); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.system.RoleMenu; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色菜单 服务类 |
||||||
|
*/ |
||||||
|
public interface IRoleMenuService extends IService<RoleMenu> { |
||||||
|
|
||||||
|
ListResultVO<RoleMenu> getRoleMenuList(Query query); |
||||||
|
|
||||||
|
|
||||||
|
RoleMenu addRoleMenu(RoleMenu roleMenu); |
||||||
|
|
||||||
|
|
||||||
|
boolean deleteRoleMenu(Integer id); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.system.Role; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import edu.ncst.carbon.vo.role.ModifyRoleInterfacePermissionDTO; |
||||||
|
import edu.ncst.carbon.vo.role.ModifyRoleMenuPermissionDTO; |
||||||
|
import edu.ncst.carbon.vo.role.RoleDetailVO; |
||||||
|
import edu.ncst.carbon.vo.role.RoleShortItemVO; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 角色业务层 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public interface IRoleService extends IService<Role> { |
||||||
|
|
||||||
|
ListResultVO<Role> getRoleList(Query query); |
||||||
|
|
||||||
|
RoleDetailVO getRoleDetail(Integer id); |
||||||
|
|
||||||
|
RoleDetailVO addRole(RoleDetailVO addRoleDTO); |
||||||
|
|
||||||
|
RoleDetailVO modifyRole(RoleDetailVO modifyRoleDTO); |
||||||
|
|
||||||
|
boolean deleteRole(Integer id); |
||||||
|
|
||||||
|
boolean deleteRoles(List<Integer> ids); |
||||||
|
|
||||||
|
boolean setRoleEnable(Integer id, Boolean enable); |
||||||
|
|
||||||
|
List<RoleShortItemVO> selectRoleList(); |
||||||
|
|
||||||
|
void modifyRoleMenuPermission(ModifyRoleMenuPermissionDTO modifyDTO); |
||||||
|
|
||||||
|
void modifyRoleInterfacePermission(ModifyRoleInterfacePermissionDTO modifyDTO); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,6 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
|
||||||
|
public interface ISystemService { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
package edu.ncst.carbon.service; |
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import edu.ncst.carbon.model.task.TaskAudit; |
||||||
|
import edu.ncst.carbon.vo.ListResultVO; |
||||||
|
import edu.ncst.carbon.vo.Query; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
|
||||||
|
/** |
||||||
|
* 任务审核 服务类 |
||||||
|
* */ |
||||||
|
public interface ITaskAuditService extends IService<TaskAudit>{ |
||||||
|
TaskAudit getTaskAuditDetail(Integer id); |
||||||
|
|
||||||
|
ListResultVO<TaskAudit> getTaskAuditList(Query query); |
||||||
|
|
||||||
|
TaskAudit addTaskAudit(TaskAudit TaskAudit); |
||||||
|
|
||||||
|
TaskAudit modifyTaskAudit(TaskAudit TaskAudit); |
||||||
|
|
||||||
|
boolean deleteTaskAudit(Integer id); |
||||||
|
|
||||||
|
void uploadAudit(MultipartFile uploadFile, HttpServletRequest request, String text, Integer taskId, Integer integral) throws FileNotFoundException; |
||||||
|
|
||||||
|
TaskAudit audit(Integer taskAuditId, Boolean yesNo); |
||||||
|
|
||||||
|
TaskAudit confirmAudit(Integer taskAuditId); |
||||||
|
} |
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue