commit ac3252fdb8149657e32c8f0f5e21ea78af9c4ebe Author: 刘孟成 <2151933001@qq.com> Date: Mon Apr 22 10:29:27 2024 +0800 后端 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2a3040 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +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/ diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000..a45eb6b --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,118 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed 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. + */ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..2cc7d4a Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..642d572 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..a16b543 --- /dev/null +++ b/mvnw @@ -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 "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..c8d4337 --- /dev/null +++ b/mvnw.cmd @@ -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% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e7dfaee --- /dev/null +++ b/pom.xml @@ -0,0 +1,224 @@ + + + 4.0.0 + + com.eleadmin + ele-admin-api + 1.5.0 + + ele-admin-api + EleAdminApi project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 2.5.4 + + + + + 1.8 + UTF-8 + UTF-8 + + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-aop + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + org.projectlombok + lombok + true + + + + + mysql + mysql-connector-java + runtime + + + + + com.alibaba + druid-spring-boot-starter + 1.2.6 + + + + + com.baomidou + mybatis-plus-boot-starter + 3.4.3.3 + + + + + com.baomidou + mybatis-plus-generator + 3.4.1 + + + + + cn.hutool + hutool-core + 5.7.11 + + + cn.hutool + hutool-extra + 5.7.11 + + + cn.hutool + hutool-http + 5.7.11 + + + cn.hutool + hutool-crypto + 5.7.11 + + + + + cn.afterturn + easypoi-base + 4.4.0 + + + + + org.apache.tika + tika-core + 2.1.0 + + + + + com.github.livesense + jodconverter-core + 1.0.5 + + + + + org.springframework.boot + spring-boot-starter-mail + + + + + com.ibeetl + beetl + 3.6.1.RELEASE + + + + + io.springfox + springfox-boot-starter + 3.0.0 + + + + + org.springframework.boot + spring-boot-starter-security + + + + + io.jsonwebtoken + jjwt-impl + 0.11.2 + + + io.jsonwebtoken + jjwt-jackson + 0.11.2 + + + + + com.github.whvcse + easy-captcha + 1.6.2 + + + + + + + + src/main/java + + **/*Mapper.xml + + + + src/main/resources + + ** + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + + + aliYunMaven + https://maven.aliyun.com/repository/public + + + + diff --git a/src/main/java/com/eleadmin/EleAdminApplication.java b/src/main/java/com/eleadmin/EleAdminApplication.java new file mode 100644 index 0000000..85185f1 --- /dev/null +++ b/src/main/java/com/eleadmin/EleAdminApplication.java @@ -0,0 +1,26 @@ +package com.eleadmin; + +import com.eleadmin.common.core.config.ConfigProperties; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * 启动类 + * Created by EleAdmin on 2018-02-22 11:29:03 + */ +@EnableAsync +@EnableTransactionManagement +@MapperScan("com.eleadmin.**.mapper") +@EnableConfigurationProperties(ConfigProperties.class) +@SpringBootApplication +public class EleAdminApplication { + + public static void main(String[] args) { + SpringApplication.run(EleAdminApplication.class, args); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/Constants.java b/src/main/java/com/eleadmin/common/core/Constants.java new file mode 100644 index 0000000..a0eecd9 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/Constants.java @@ -0,0 +1,93 @@ +package com.eleadmin.common.core; + +/** + * 系统常量 + * Created by EleAdmin on 2019-10-29 15:55 + */ +public class Constants { + /** + * 默认成功码 + */ + public static final int RESULT_OK_CODE = 0; + + /** + * 默认失败码 + */ + public static final int RESULT_ERROR_CODE = 1; + + /** + * 默认成功信息 + */ + public static final String RESULT_OK_MSG = "操作成功"; + + /** + * 默认失败信息 + */ + public static final String RESULT_ERROR_MSG = "操作失败"; + + /** + * 无权限错误码 + */ + public static final int UNAUTHORIZED_CODE = 403; + + /** + * 无权限提示信息 + */ + public static final String UNAUTHORIZED_MSG = "没有访问权限"; + + /** + * 未认证错误码 + */ + public static final int UNAUTHENTICATED_CODE = 401; + + /** + * 未认证提示信息 + */ + public static final String UNAUTHENTICATED_MSG = "请先登录"; + + /** + * 登录过期错误码 + */ + public static final int TOKEN_EXPIRED_CODE = 401; + + /** + * 登录过期提示信息 + */ + public static final String TOKEN_EXPIRED_MSG = "登录已过期"; + + /** + * 非法token错误码 + */ + public static final int BAD_CREDENTIALS_CODE = 401; + + /** + * 非法token提示信息 + */ + public static final String BAD_CREDENTIALS_MSG = "请退出重新登录"; + + /** + * 表示升序的值 + */ + public static final String ORDER_ASC_VALUE = "asc"; + + /** + * 表示降序的值 + */ + public static final String ORDER_DESC_VALUE = "desc"; + + /** + * token通过header传递的名称 + */ + public static final String TOKEN_HEADER_NAME = "Authorization"; + + /** + * token通过参数传递的名称 + */ + public static final String TOKEN_PARAM_NAME = "access_token"; + + /** + * token认证类型 + */ + public static final String TOKEN_TYPE = "Bearer"; + +} diff --git a/src/main/java/com/eleadmin/common/core/annotation/OperationLog.java b/src/main/java/com/eleadmin/common/core/annotation/OperationLog.java new file mode 100644 index 0000000..05bb33a --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/annotation/OperationLog.java @@ -0,0 +1,41 @@ +package com.eleadmin.common.core.annotation; + +import java.lang.annotation.*; + +/** + * 操作日志记录注解 + * + * @author EleAdmin + * @since 2020-03-21 17:03:08 + */ +@Documented +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface OperationLog { + + /** + * 操作功能 + */ + String value() default ""; + + /** + * 操作模块 + */ + String module() default ""; + + /** + * 备注 + */ + String comments() default ""; + + /** + * 是否记录请求参数 + */ + boolean param() default true; + + /** + * 是否记录返回结果 + */ + boolean result() default true; + +} diff --git a/src/main/java/com/eleadmin/common/core/annotation/OperationModule.java b/src/main/java/com/eleadmin/common/core/annotation/OperationModule.java new file mode 100644 index 0000000..56aa532 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/annotation/OperationModule.java @@ -0,0 +1,21 @@ +package com.eleadmin.common.core.annotation; + +import java.lang.annotation.*; + +/** + * 操作日志模块注解 + * + * @author EleAdmin + * @since 2021-09-01 20:48:16 + */ +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface OperationModule { + + /** + * 模块名称 + */ + String value(); + +} diff --git a/src/main/java/com/eleadmin/common/core/annotation/QueryField.java b/src/main/java/com/eleadmin/common/core/annotation/QueryField.java new file mode 100644 index 0000000..fe9470b --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/annotation/QueryField.java @@ -0,0 +1,22 @@ +package com.eleadmin.common.core.annotation; + +import java.lang.annotation.*; + +/** + * 查询条件注解 + * + * @author EleAdmin + * @since 2021-09-01 20:48:16 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) +public @interface QueryField { + + // 字段名称 + String value() default ""; + + // 查询方式 + QueryType type() default QueryType.LIKE; + +} diff --git a/src/main/java/com/eleadmin/common/core/annotation/QueryType.java b/src/main/java/com/eleadmin/common/core/annotation/QueryType.java new file mode 100644 index 0000000..a6de06e --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/annotation/QueryType.java @@ -0,0 +1,42 @@ +package com.eleadmin.common.core.annotation; + +/** + * 查询方式 + * + * @author EleAdmin + * @since 2021-09-01 20:48:16 + */ +public enum QueryType { + // 等于 + EQ, + // 不等于 + NE, + // 大于 + GT, + // 大于等于 + GE, + // 小于 + LT, + // 小于等于 + LE, + // 包含 + LIKE, + // 不包含 + NOT_LIKE, + // 结尾等于 + LIKE_LEFT, + // 开头等于 + LIKE_RIGHT, + // 为NULL + IS_NULL, + // 不为空 + IS_NOT_NULL, + // IN + IN, + // NOT IN + NOT_IN, + // IN条件解析逗号分割 + IN_STR, + // NOT IN条件解析逗号分割 + NOT_IN_STR +} diff --git a/src/main/java/com/eleadmin/common/core/aspect/OperationLogAspect.java b/src/main/java/com/eleadmin/common/core/aspect/OperationLogAspect.java new file mode 100644 index 0000000..431eed4 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/aspect/OperationLogAspect.java @@ -0,0 +1,210 @@ +package com.eleadmin.common.core.aspect; + +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.servlet.ServletUtil; +import cn.hutool.http.useragent.UserAgent; +import cn.hutool.http.useragent.UserAgentUtil; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.annotation.OperationModule; +import com.eleadmin.common.core.utils.JSONUtil; +import com.eleadmin.common.system.entity.OperationRecord; +import com.eleadmin.common.system.entity.User; +import com.eleadmin.common.system.service.OperationRecordService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.*; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.Method; +import java.util.Map; + +/** + * 操作日志记录 + * + * @author EleAdmin + * @since 2020-03-21 16:58:16:05 + */ +@Aspect +@Component +public class OperationLogAspect { + @Resource + private OperationRecordService operationRecordService; + // 参数、返回结果、错误信息等最大保存长度 + private static final int MAX_LENGTH = 1000; + // 用于记录请求耗时 + private final ThreadLocal startTime = new ThreadLocal<>(); + + @Pointcut("@annotation(com.eleadmin.common.core.annotation.OperationLog)") + public void operationLog() { + } + + @Before("operationLog()") + public void doBefore(JoinPoint joinPoint) throws Throwable { + startTime.set(System.currentTimeMillis()); + } + + @AfterReturning(pointcut = "operationLog()", returning = "result") + public void doAfterReturning(JoinPoint joinPoint, Object result) { + saveLog(joinPoint, result, null); + } + + @AfterThrowing(value = "operationLog()", throwing = "e") + public void doAfterThrowing(JoinPoint joinPoint, Exception e) { + saveLog(joinPoint, null, e); + } + + /** + * 保存操作记录 + */ + private void saveLog(JoinPoint joinPoint, Object result, Exception e) { + OperationRecord record = new OperationRecord(); + // 记录操作耗时 + if (startTime.get() != null) { + record.setSpendTime(System.currentTimeMillis() - startTime.get()); + } + // 记录当前登录用户id、租户id + User user = getLoginUser(); + if (user != null) { + record.setUserId(user.getUserId()); + record.setTenantId(user.getTenantId()); + } + // 记录请求地址、请求方式、ip + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = (attributes == null ? null : attributes.getRequest()); + if (request != null) { + record.setUrl(request.getRequestURI()); + record.setRequestMethod(request.getMethod()); + UserAgent ua = UserAgentUtil.parse(ServletUtil.getHeaderIgnoreCase(request, "User-Agent")); + record.setOs(ua.getPlatform().toString()); + record.setDevice(ua.getOs().toString()); + record.setBrowser(ua.getBrowser().toString()); + record.setIp(ServletUtil.getClientIP(request)); + } + // 记录异常信息 + if (e != null) { + record.setStatus(1); + record.setError(StrUtil.sub(e.toString(), 0, MAX_LENGTH)); + } + // 记录模块名、操作功能、请求方法、请求参数、返回结果 + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + record.setMethod(joinPoint.getTarget().getClass().getName() + "." + signature.getName()); + Method method = signature.getMethod(); + if (method != null) { + OperationLog ol = method.getAnnotation(OperationLog.class); + if (ol != null) { + // 记录操作功能 + record.setDescription(getDescription(method, ol)); + // 记录操作模块 + record.setModule(getModule(joinPoint, ol)); + // 记录备注 + if (StrUtil.isNotEmpty(ol.comments())) { + record.setComments(ol.comments()); + } + // 记录请求参数 + if (ol.param() && request != null) { + record.setParams(StrUtil.sub(getParams(joinPoint, request), 0, MAX_LENGTH)); + } + // 记录请求结果 + if (ol.result() && result != null) { + record.setResult(StrUtil.sub(JSONUtil.toJSONString(result), 0, MAX_LENGTH)); + } + } + } + operationRecordService.saveAsync(record); + } + + /** + * 获取当前登录用户 + */ + private User getLoginUser() { + Authentication subject = SecurityContextHolder.getContext().getAuthentication(); + if (subject != null) { + Object object = subject.getPrincipal(); + if (object instanceof User) { + return (User) object; + } + } + return null; + } + + /** + * 获取请求参数 + * + * @param joinPoint JoinPoint + * @param request HttpServletRequest + * @return String + */ + private String getParams(JoinPoint joinPoint, HttpServletRequest request) { + String params; + Map paramsMap = ServletUtil.getParamMap(request); + if (paramsMap.keySet().size() > 0) { + params = JSONUtil.toJSONString(paramsMap); + } else { + StringBuilder sb = new StringBuilder(); + for (Object arg : joinPoint.getArgs()) { + if (ObjectUtil.isNull(arg) + || arg instanceof MultipartFile + || arg instanceof HttpServletRequest + || arg instanceof HttpServletResponse) { + continue; + } + sb.append(JSONUtil.toJSONString(arg)).append(" "); + } + params = sb.toString(); + } + return params; + } + + /** + * 获取操作模块 + * + * @param joinPoint JoinPoint + * @param ol OperationLog + * @return String + */ + private String getModule(JoinPoint joinPoint, OperationLog ol) { + if (StrUtil.isNotEmpty(ol.module())) { + return ol.module(); + } + OperationModule om = joinPoint.getTarget().getClass().getAnnotation(OperationModule.class); + if (om != null && StrUtil.isNotEmpty(om.value())) { + return om.value(); + } + Api api = joinPoint.getTarget().getClass().getAnnotation(Api.class); + if (api != null && api.tags() != null) { + return ArrayUtil.join(api.tags(), ","); + } + return null; + } + + /** + * 获取操作功能 + * + * @param method Method + * @param ol OperationLog + * @return String + */ + private String getDescription(Method method, OperationLog ol) { + if (StrUtil.isNotEmpty(ol.value())) { + return ol.value(); + } + ApiOperation ao = method.getAnnotation(ApiOperation.class); + if (ao != null && StrUtil.isNotEmpty(ao.value())) { + return ao.value(); + } + return null; + } + +} diff --git a/src/main/java/com/eleadmin/common/core/config/ConfigProperties.java b/src/main/java/com/eleadmin/common/core/config/ConfigProperties.java new file mode 100644 index 0000000..3189c92 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/config/ConfigProperties.java @@ -0,0 +1,75 @@ +package com.eleadmin.common.core.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * 系统配置属性 + * + * @author EleAdmin + * @since 2021-08-30 17:58:16 + */ +@Data +@ConfigurationProperties(prefix = "config") +public class ConfigProperties { + /** + * 文件上传磁盘位置 + */ + private Integer uploadLocation = 0; + + /** + * 文件上传是否使用uuid命名 + */ + private Boolean uploadUuidName = false; + + /** + * 文件上传生成缩略图的大小(kb) + */ + private Integer thumbnailSize = 60; + + /** + * OpenOffice的安装目录 + */ + private String openOfficeHome; + + /** + * swagger扫描包 + */ + private String swaggerBasePackage; + + /** + * swagger文档标题 + */ + private String swaggerTitle; + + /** + * swagger文档描述 + */ + private String swaggerDescription; + + /** + * swagger文档版本号 + */ + private String swaggerVersion; + + /** + * swagger地址 + */ + private String swaggerHost; + + /** + * token过期时间, 单位秒 + */ + private Long tokenExpireTime = 60 * 60 * 24L; + + /** + * token快要过期自动刷新时间, 单位分钟 + */ + private int tokenRefreshTime = 30; + + /** + * 生成token的密钥Key的base64字符 + */ + private String tokenKey; + +} diff --git a/src/main/java/com/eleadmin/common/core/config/MybatisPlusConfig.java b/src/main/java/com/eleadmin/common/core/config/MybatisPlusConfig.java new file mode 100644 index 0000000..cd1db72 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/config/MybatisPlusConfig.java @@ -0,0 +1,77 @@ +package com.eleadmin.common.core.config; + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; +import com.eleadmin.common.system.entity.User; +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.LongValue; +import net.sf.jsqlparser.expression.NullValue; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; + +import java.util.Arrays; + +/** + * MybatisPlus配置 + * + * @author EleAdmin + * @since 2018-02-22 11:29:28 + */ +@Configuration +public class MybatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + + // 多租户插件配置 + TenantLineHandler tenantLineHandler = new TenantLineHandler() { + @Override + public Expression getTenantId() { + return getLoginUserTenantId(); + } + + @Override + public boolean ignoreTable(String tableName) { + return Arrays.asList( + "sys_tenant", + "sys_dictionary", + "sys_dictionary_data" + ).contains(tableName); + } + }; + TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor(tenantLineHandler); + interceptor.addInnerInterceptor(tenantLineInnerInterceptor); + + // 分页插件配置 + PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); + interceptor.addInnerInterceptor(paginationInnerInterceptor); + + return interceptor; + } + + /** + * 获取当前登录用户的租户id + * + * @return Integer + */ + public Expression getLoginUserTenantId() { + try { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null) { + Object object = authentication.getPrincipal(); + if (object instanceof User) { + return new LongValue(((User) object).getTenantId()); + } + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return new NullValue(); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/config/SwaggerConfig.java b/src/main/java/com/eleadmin/common/core/config/SwaggerConfig.java new file mode 100644 index 0000000..d090493 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/config/SwaggerConfig.java @@ -0,0 +1,72 @@ +package com.eleadmin.common.core.config; + +import cn.hutool.core.util.StrUtil; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.oas.annotations.EnableOpenApi; +import springfox.documentation.service.*; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; +import springfox.documentation.spring.web.plugins.Docket; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +/** + * Swagger配置 + * + * @author EleAdmin + * @since 2018-02-22 11:29:05 + */ +@EnableOpenApi +@Configuration +public class SwaggerConfig { + @Resource + private ConfigProperties config; + + @Bean + public Docket createRestApi() { + Docket docket = new Docket(DocumentationType.OAS_30); + if (StrUtil.isNotBlank(config.getSwaggerHost())) { + docket.host(config.getSwaggerHost()); + } + return docket + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage(config.getSwaggerBasePackage())) + .paths(PathSelectors.any()) + .build() + .securitySchemes(securitySchemes()) + .securityContexts(securityContexts()); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title(config.getSwaggerTitle()) + .description(config.getSwaggerDescription()) + .version(config.getSwaggerVersion()) + .termsOfServiceUrl("") + .build(); + } + + private List securitySchemes() { + return Collections.singletonList( + new ApiKey("Authorization", "Authorization", "header") + ); + } + + private List securityContexts() { + AuthorizationScope[] scopes = {new AuthorizationScope("global", "accessEverything")}; + List references = Collections.singletonList( + new SecurityReference("Authorization", scopes) + ); + return Collections.singletonList(SecurityContext.builder() + .securityReferences(references) + .build()); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/config/WebMvcConfig.java b/src/main/java/com/eleadmin/common/core/config/WebMvcConfig.java new file mode 100644 index 0000000..cdee50e --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/config/WebMvcConfig.java @@ -0,0 +1,31 @@ +package com.eleadmin.common.core.config; + +import com.eleadmin.common.core.Constants; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * WebMvc配置, 拦截器、资源映射等都在此配置 + * + * @author EleAdmin + * @since 2019-06-12 10:11:16 + */ +@Configuration +public class WebMvcConfig implements WebMvcConfigurer { + + /** + * 支持跨域访问 + */ + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") + .allowedHeaders("*") + .exposedHeaders(Constants.TOKEN_HEADER_NAME) + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH") + .allowCredentials(true) + .maxAge(3600); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/exception/BusinessException.java b/src/main/java/com/eleadmin/common/core/exception/BusinessException.java new file mode 100644 index 0000000..5a27d96 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/exception/BusinessException.java @@ -0,0 +1,48 @@ +package com.eleadmin.common.core.exception; + +import com.eleadmin.common.core.Constants; + +/** + * 自定义业务异常 + * + * @author EleAdmin + * @since 2018-02-22 11:29:28 + */ +public class BusinessException extends RuntimeException { + private static final long serialVersionUID = 1L; + + private Integer code; + + public BusinessException() { + this(Constants.RESULT_ERROR_MSG); + } + + public BusinessException(String message) { + this(Constants.RESULT_ERROR_CODE, message); + } + + public BusinessException(Integer code, String message) { + super(message); + this.code = code; + } + + public BusinessException(Integer code, String message, Throwable cause) { + super(message, cause); + this.code = code; + } + + public BusinessException(Integer code, String message, Throwable cause, + boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + this.code = code; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + +} diff --git a/src/main/java/com/eleadmin/common/core/exception/GlobalExceptionHandler.java b/src/main/java/com/eleadmin/common/core/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..faa10fd --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/exception/GlobalExceptionHandler.java @@ -0,0 +1,56 @@ +package com.eleadmin.common.core.exception; + +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.core.utils.CommonUtil; +import com.eleadmin.common.core.web.ApiResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletResponse; + +/** + * 全局异常处理器 + * + * @author EleAdmin + * @since 2018-02-22 11:29:30 + */ +@ControllerAdvice +public class GlobalExceptionHandler { + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @ResponseBody + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public ApiResult methodNotSupportedExceptionHandler(HttpRequestMethodNotSupportedException e, + HttpServletResponse response) { + CommonUtil.addCrossHeaders(response); + return new ApiResult<>(Constants.RESULT_ERROR_CODE, "请求方式不正确").setError(e.toString()); + } + + @ResponseBody + @ExceptionHandler(AccessDeniedException.class) + public ApiResult accessDeniedExceptionHandler(AccessDeniedException e, HttpServletResponse response) { + CommonUtil.addCrossHeaders(response); + return new ApiResult<>(Constants.UNAUTHORIZED_CODE, Constants.UNAUTHORIZED_MSG).setError(e.toString()); + } + + @ResponseBody + @ExceptionHandler(BusinessException.class) + public ApiResult businessExceptionHandler(BusinessException e, HttpServletResponse response) { + CommonUtil.addCrossHeaders(response); + return new ApiResult<>(e.getCode(), e.getMessage()); + } + + @ResponseBody + @ExceptionHandler(Throwable.class) + public ApiResult exceptionHandler(Throwable e, HttpServletResponse response) { + logger.error(e.getMessage(), e); + CommonUtil.addCrossHeaders(response); + return new ApiResult<>(Constants.RESULT_ERROR_CODE, Constants.RESULT_ERROR_MSG).setError(e.toString()); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/security/JwtAccessDeniedHandler.java b/src/main/java/com/eleadmin/common/core/security/JwtAccessDeniedHandler.java new file mode 100644 index 0000000..2c1d4d9 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/security/JwtAccessDeniedHandler.java @@ -0,0 +1,29 @@ +package com.eleadmin.common.core.security; + +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.core.utils.CommonUtil; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * 没有访问权限异常处理 + * + * @author EleAdmin + * @since 2020-03-25 00:35:03 + */ +@Component +public class JwtAccessDeniedHandler implements AccessDeniedHandler { + + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) + throws IOException, ServletException { + CommonUtil.responseError(response, Constants.UNAUTHORIZED_CODE, Constants.UNAUTHORIZED_MSG, e.getMessage()); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/security/JwtAuthenticationEntryPoint.java b/src/main/java/com/eleadmin/common/core/security/JwtAuthenticationEntryPoint.java new file mode 100644 index 0000000..4cc1657 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/security/JwtAuthenticationEntryPoint.java @@ -0,0 +1,30 @@ +package com.eleadmin.common.core.security; + +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.core.utils.CommonUtil; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * 没有登录异常处理 + * + * @author EleAdmin + * @since 2020-03-25 00:35:03 + */ +@Component +public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { + + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) + throws IOException, ServletException { + CommonUtil.responseError(response, Constants.UNAUTHENTICATED_CODE, Constants.UNAUTHENTICATED_MSG, + e.getMessage()); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/security/JwtAuthenticationFilter.java b/src/main/java/com/eleadmin/common/core/security/JwtAuthenticationFilter.java new file mode 100644 index 0000000..5242a44 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/security/JwtAuthenticationFilter.java @@ -0,0 +1,85 @@ +package com.eleadmin.common.core.security; + +import cn.hutool.core.util.StrUtil; +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.core.config.ConfigProperties; +import com.eleadmin.common.core.utils.CommonUtil; +import com.eleadmin.common.system.entity.LoginRecord; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.entity.User; +import com.eleadmin.common.system.service.LoginRecordService; +import com.eleadmin.common.system.service.UserService; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.ExpiredJwtException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.annotation.Resource; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 处理携带token的请求过滤器 + * + * @author EleAdmin + * @since 2020-03-30 20:48:05 + */ +@Component +public class JwtAuthenticationFilter extends OncePerRequestFilter { + @Resource + private ConfigProperties configProperties; + @Resource + private UserService userService; + @Resource + private LoginRecordService loginRecordService; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws ServletException, IOException { + String access_token = JwtUtil.getAccessToken(request); + if (StrUtil.isNotBlank(access_token)) { + try { + // 解析token + Claims claims = JwtUtil.parseToken(access_token, configProperties.getTokenKey()); + JwtSubject jwtSubject = JwtUtil.getJwtSubject(claims); + User user = userService.getByUsername(jwtSubject.getUsername(), jwtSubject.getTenantId()); + if (user == null) { + throw new UsernameNotFoundException("Username not found"); + } + List authorities = user.getAuthorities().stream() + .filter(m -> StrUtil.isNotBlank(m.getAuthority())).collect(Collectors.toList()); + UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( + user, null, authorities); + SecurityContextHolder.getContext().setAuthentication(authentication); + // token将要过期签发新token, 防止突然退出登录 + long expiration = (claims.getExpiration().getTime() - new Date().getTime()) / 1000 / 60; + if (expiration < configProperties.getTokenRefreshTime()) { + String token = JwtUtil.buildToken(jwtSubject, configProperties.getTokenExpireTime(), + configProperties.getTokenKey()); + response.addHeader(Constants.TOKEN_HEADER_NAME, token); + loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_REFRESH, null, + user.getTenantId(), request); + } + } catch (ExpiredJwtException e) { + CommonUtil.responseError(response, Constants.TOKEN_EXPIRED_CODE, Constants.TOKEN_EXPIRED_MSG, + e.getMessage()); + return; + } catch (Exception e) { + CommonUtil.responseError(response, Constants.BAD_CREDENTIALS_CODE, Constants.BAD_CREDENTIALS_MSG, + e.toString()); + return; + } + } + chain.doFilter(request, response); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/security/JwtSubject.java b/src/main/java/com/eleadmin/common/core/security/JwtSubject.java new file mode 100644 index 0000000..af4725d --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/security/JwtSubject.java @@ -0,0 +1,31 @@ +package com.eleadmin.common.core.security; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * Jwt载体 + * + * @author EleAdmin + * @since 2021-09-03 00:11:12 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class JwtSubject implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 账号 + */ + private String username; + + /** + * 租户id + */ + private Integer tenantId; + +} diff --git a/src/main/java/com/eleadmin/common/core/security/JwtUtil.java b/src/main/java/com/eleadmin/common/core/security/JwtUtil.java new file mode 100644 index 0000000..858c7e5 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/security/JwtUtil.java @@ -0,0 +1,141 @@ +package com.eleadmin.common.core.security; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.servlet.ServletUtil; +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.core.utils.JSONUtil; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.io.Decoders; +import io.jsonwebtoken.io.Encoders; +import io.jsonwebtoken.security.Keys; + +import javax.servlet.http.HttpServletRequest; +import java.security.Key; +import java.util.Date; + +/** + * JWT工具类 + * + * @author EleAdmin + * @since 2018-01-21 16:30:59 + */ +public class JwtUtil { + + /** + * 获取请求中的access_token + * + * @param request HttpServletRequest + * @return String + */ + public static String getAccessToken(HttpServletRequest request) { + String access_token = ServletUtil.getHeaderIgnoreCase(request, Constants.TOKEN_HEADER_NAME); + if (StrUtil.isNotBlank(access_token)) { + if (access_token.startsWith(Constants.TOKEN_TYPE)) { + access_token = StrUtil.removePrefix(access_token, Constants.TOKEN_TYPE).trim(); + } + } else { + access_token = request.getParameter(Constants.TOKEN_PARAM_NAME); + } + return access_token; + } + + /** + * 生成token + * + * @param subject 载体 + * @param expire 过期时间 + * @param base64EncodedKey base64编码的Key + * @return token + */ + public static String buildToken(JwtSubject subject, Long expire, String base64EncodedKey) { + return buildToken(JSONUtil.toJSONString(subject), expire, decodeKey(base64EncodedKey)); + } + + /** + * 生成token + * + * @param subject 载体 + * @param expire 过期时间 + * @param key 密钥 + * @return token + */ + public static String buildToken(String subject, Long expire, Key key) { + Date expireDate = new Date(new Date().getTime() + 1000 * expire); + return Jwts.builder() + .setSubject(subject) + .setExpiration(expireDate) + .setIssuedAt(new Date()) + .signWith(key) + .compact(); + } + + /** + * 解析token + * + * @param token token + * @param base64EncodedKey base64编码的Key + * @return Claims + */ + public static Claims parseToken(String token, String base64EncodedKey) { + return parseToken(token, decodeKey(base64EncodedKey)); + } + + /** + * 解析token + * + * @param token token + * @param key 密钥 + * @return Claims + */ + public static Claims parseToken(String token, Key key) { + return Jwts.parserBuilder() + .setSigningKey(key) + .build() + .parseClaimsJws(token) + .getBody(); + } + + /** + * 获取JwtSubject + * + * @param claims Claims + * @return JwtSubject + */ + public static JwtSubject getJwtSubject(Claims claims) { + return JSONUtil.parseObject(claims.getSubject(), JwtSubject.class); + } + + /** + * 生成Key + * + * @return Key + */ + public static Key randomKey() { + return Keys.secretKeyFor(SignatureAlgorithm.HS256); + } + + /** + * base64编码key + * + * @return String + */ + public static String encodeKey(Key key) { + return Encoders.BASE64.encode(key.getEncoded()); + } + + /** + * base64编码Key + * + * @param base64EncodedKey base64编码的key + * @return Key + */ + public static Key decodeKey(String base64EncodedKey) { + if (StrUtil.isBlank(base64EncodedKey)) { + return null; + } + return Keys.hmacShaKeyFor(Decoders.BASE64.decode(base64EncodedKey)); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/security/SecurityConfig.java b/src/main/java/com/eleadmin/common/core/security/SecurityConfig.java new file mode 100644 index 0000000..6c1241f --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/security/SecurityConfig.java @@ -0,0 +1,79 @@ +package com.eleadmin.common.core.security; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +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.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.web.authentication.UsernamePasswordAuthenticationFilter; + +import javax.annotation.Resource; + +/** + * Spring Security配置 + * + * @author EleAdmin + * @since 2020-03-23 18:04:52 + */ +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class SecurityConfig extends WebSecurityConfigurerAdapter { + @Resource + private JwtAccessDeniedHandler jwtAccessDeniedHandler; + @Resource + private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; + @Resource + private JwtAuthenticationFilter jwtAuthenticationFilter; + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers(HttpMethod.OPTIONS, "/**") + .permitAll() + .antMatchers(HttpMethod.GET, "/api/file/**", "/api/captcha", "/") + .permitAll() + .antMatchers( + "/api/login", + "/druid/**", + "/swagger-ui.html", + "/swagger-resources/**", + "/webjars/**", + "/v2/api-docs", + "/v3/api-docs", + "/swagger-ui/**" + ) + .permitAll() + .anyRequest() + .authenticated() + .and() + .sessionManagement() + .sessionCreationPolicy(SessionCreationPolicy.STATELESS) + .and() + .csrf() + .disable() + .cors() + .and() + .logout() + .disable() + .headers() + .frameOptions() + .disable() + .and() + .exceptionHandling() + .accessDeniedHandler(jwtAccessDeniedHandler) + .authenticationEntryPoint(jwtAuthenticationEntryPoint) + .and() + .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); + } + + @Bean + public BCryptPasswordEncoder bCryptPasswordEncoder() { + return new BCryptPasswordEncoder(); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/utils/CommonUtil.java b/src/main/java/com/eleadmin/common/core/utils/CommonUtil.java new file mode 100644 index 0000000..6b89b7a --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/utils/CommonUtil.java @@ -0,0 +1,174 @@ +package com.eleadmin.common.core.utils; + +import cn.hutool.core.util.ObjectUtil; +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.core.web.ApiResult; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * 常用工具方法 + * + * @author EleAdmin + * @since 2017-06-10 10:10:22 + */ +public class CommonUtil { + // 生成uuid的字符 + private static final String[] chars = new String[]{ + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", + "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", + "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" + }; + + /** + * 生成8位uuid + * + * @return String + */ + public static String randomUUID8() { + StringBuilder sb = new StringBuilder(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + for (int i = 0; i < 8; i++) { + String str = uuid.substring(i * 4, i * 4 + 4); + int x = Integer.parseInt(str, 16); + sb.append(chars[x % 0x3E]); + } + return sb.toString(); + } + + /** + * 生成16位uuid + * + * @return String + */ + public static String randomUUID16() { + StringBuilder sb = new StringBuilder(); + String uuid = UUID.randomUUID().toString().replace("-", ""); + for (int i = 0; i < 16; i++) { + String str = uuid.substring(i * 2, i * 2 + 2); + int x = Integer.parseInt(str, 16); + sb.append(chars[x % 0x3E]); + } + return sb.toString(); + } + + /** + * 检查List是否有重复元素 + * + * @param list List + * @param mapper 获取需要检查的字段的Function + * @param 数据的类型 + * @param 需要检查的字段的类型 + * @return boolean + */ + public static boolean checkRepeat(List list, Function mapper) { + for (int i = 0; i < list.size(); i++) { + for (int j = 0; j < list.size(); j++) { + if (i != j && mapper.apply(list.get(i)).equals(mapper.apply(list.get(j)))) { + return true; + } + } + } + return false; + } + + /** + * List转为树形结构 + * + * @param data List + * @param parentId 顶级的parentId + * @param parentIdMapper 获取parentId的Function + * @param idMapper 获取id的Function + * @param consumer 赋值children的Consumer + * @param 数据的类型 + * @param parentId的类型 + * @return List + */ + public static List toTreeData(List data, R parentId, + Function parentIdMapper, + Function idMapper, + BiConsumer> consumer) { + List result = new ArrayList<>(); + for (T d : data) { + R dParentId = parentIdMapper.apply(d); + if (ObjectUtil.equals(parentId, dParentId)) { + R dId = idMapper.apply(d); + List children = toTreeData(data, dId, parentIdMapper, idMapper, consumer); + consumer.accept(d, children); + result.add(d); + } + } + return result; + } + + /** + * 遍历树形结构数据 + * + * @param data List + * @param consumer 回调 + * @param mapper 获取children的Function + * @param 数据的类型 + */ + public static void eachTreeData(List data, Consumer consumer, Function> mapper) { + for (T d : data) { + consumer.accept(d); + List children = mapper.apply(d); + if (children != null && children.size() > 0) { + eachTreeData(children, consumer, mapper); + } + } + } + + /** + * 获取集合中的第一条数据 + * + * @param records 集合 + * @return 第一条数据 + */ + public static T listGetOne(List records) { + return records == null || records.size() == 0 ? null : records.get(0); + } + + /** + * 支持跨域 + * + * @param response HttpServletResponse + */ + public static void addCrossHeaders(HttpServletResponse response) { + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Origin", "*"); + response.setHeader("Access-Control-Allow-Methods", "*"); + response.setHeader("Access-Control-Allow-Headers", "*"); + response.setHeader("Access-Control-Expose-Headers", Constants.TOKEN_HEADER_NAME); + } + + /** + * 输出错误信息 + * + * @param response HttpServletResponse + * @param code 错误码 + * @param message 提示信息 + * @param error 错误信息 + */ + public static void responseError(HttpServletResponse response, Integer code, String message, String error) { + response.setContentType("application/json;charset=UTF-8"); + try { + PrintWriter out = response.getWriter(); + out.write(JSONUtil.toJSONString(new ApiResult<>(code, message, null, error))); + out.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/eleadmin/common/core/utils/FileServerUtil.java b/src/main/java/com/eleadmin/common/core/utils/FileServerUtil.java new file mode 100644 index 0000000..02936ff --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/utils/FileServerUtil.java @@ -0,0 +1,378 @@ +package com.eleadmin.common.core.utils; + +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.io.IORuntimeException; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.StrUtil; +import org.apache.tika.Tika; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.MalformedURLException; +import java.net.URLEncoder; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * 文件上传下载工具类 + * + * @author EleAdmin + * @since 2018-12-14 08:38:53 + */ +public class FileServerUtil { + // 除 text/* 外也需要设置输出编码的 content-type + private final static List SET_CHARSET_CONTENT_TYPES = Arrays.asList( + "application/json", + "application/javascript" + ); + + /** + * 上传文件 + * + * @param file MultipartFile + * @param directory 文件保存的目录 + * @param uuidName 是否用uuid命名 + * @return File + */ + public static File upload(MultipartFile file, String directory, boolean uuidName) + throws IOException, IllegalStateException { + File outFile = getUploadFile(file.getOriginalFilename(), directory, uuidName); + if (!outFile.getParentFile().exists()) { + if (!outFile.getParentFile().mkdirs()) { + throw new RuntimeException("make directory fail"); + } + } + file.transferTo(outFile); + return outFile; + } + + /** + * 上传base64格式文件 + * + * @param base64 base64编码字符 + * @param fileName 文件名称, 为空使用uuid命名 + * @param directory 文件保存的目录 + * @return File + */ + public static File upload(String base64, String fileName, String directory) + throws FileNotFoundException, IORuntimeException { + if (StrUtil.isBlank(base64) || !base64.startsWith("data:image/") || !base64.contains(";base64,")) { + throw new RuntimeException("base64 data error"); + } + String suffix = "." + base64.substring(11, base64.indexOf(";")); // 获取文件后缀 + boolean uuidName = StrUtil.isBlank(fileName); + File outFile = getUploadFile(uuidName ? suffix : fileName, directory, uuidName); + byte[] bytes = Base64.getDecoder().decode(base64.substring(base64.indexOf(";") + 8).getBytes()); + IoUtil.write(new FileOutputStream(outFile), true, bytes); + return outFile; + } + + /** + * 获取上传文件位置 + * + * @param name 文件名称 + * @param directory 上传目录 + * @param uuidName 是否使用uuid命名 + * @return File + */ + public static File getUploadFile(String name, String directory, boolean uuidName) { + // 当前日期作为上传子目录 + String dir = new SimpleDateFormat("yyyyMMdd/").format(new Date()); + // 获取文件后缀 + String suffix = (name == null || !name.contains(".")) ? "" : name.substring(name.lastIndexOf(".")); + // 使用uuid命名 + if (uuidName || name == null) { + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + return new File(directory, dir + uuid + suffix); + } + // 使用原名称, 存在相同则加(1) + File file = new File(directory, dir + name); + String prefix = StrUtil.removeSuffix(name, suffix); + int sameSize = 2; + while (file.exists()) { + file = new File(directory, dir + prefix + "(" + sameSize + ")" + suffix); + sameSize++; + } + return file; + } + + /** + * 查看文件, 支持断点续传 + * + * @param file 文件 + * @param pdfDir office转pdf输出目录 + * @param officeHome openOffice安装目录 + * @param response HttpServletResponse + * @param request HttpServletRequest + */ + public static void preview(File file, String pdfDir, String officeHome, + HttpServletResponse response, HttpServletRequest request) { + preview(file, false, pdfDir, officeHome, response, request); + } + + /** + * 查看文件, 支持断点续传 + * + * @param file 文件 + * @param forceDownload 是否强制下载 + * @param pdfDir office转pdf输出目录 + * @param officeHome openOffice安装目录 + * @param response HttpServletResponse + * @param request HttpServletRequest + */ + public static void preview(File file, boolean forceDownload, String pdfDir, String officeHome, + HttpServletResponse response, HttpServletRequest request) { + CommonUtil.addCrossHeaders(response); + if (file == null || !file.exists()) { + outNotFund(response); + return; + } + if (forceDownload) { + setDownloadHeader(response, file.getName()); + } else { + // office转pdf预览 + if (OpenOfficeUtil.canConverter(file.getName())) { + File pdfFile = OpenOfficeUtil.converterToPDF(file.getAbsolutePath(), pdfDir, officeHome); + if (pdfFile != null) { + file = pdfFile; + } + } + // 获取文件类型 + String contentType = getContentType(file); + if (contentType != null) { + response.setContentType(contentType); + // 设置编码 + if (contentType.startsWith("text/") || SET_CHARSET_CONTENT_TYPES.contains(contentType)) { + try { + String charset = JChardetFacadeUtil.detectCodepage(file.toURI().toURL()); + if (charset != null) { + response.setCharacterEncoding(charset); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + } else { + setDownloadHeader(response, file.getName()); + } + } + response.setHeader("Cache-Control", "public"); + output(file, response, request); + } + + /** + * 查看缩略图 + * + * @param file 原文件 + * @param thumbnail 缩略图文件 + * @param size 缩略图文件的最大值(kb) + * @param response HttpServletResponse + * @param request HttpServletRequest + */ + public static void previewThumbnail(File file, File thumbnail, Integer size, + HttpServletResponse response, HttpServletRequest request) { + // 如果是图片并且缩略图不存在则生成 + if (!thumbnail.exists() && isImage(file)) { + long fileSize = file.length(); + if ((fileSize / 1024) > size) { + try { + if (thumbnail.getParentFile().mkdirs()) { + ImgUtil.scale(file, thumbnail, 100f / (fileSize / 1024f)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else { + preview(file, null, null, response, request); + return; + } + } + preview(thumbnail, null, null, response, request); + } + + /** + * 输出文件流, 支持断点续传 + * + * @param file 文件 + * @param response HttpServletResponse + * @param request HttpServletRequest + */ + public static void output(File file, HttpServletResponse response, HttpServletRequest request) { + long length = file.length(); // 文件总大小 + long start = 0, to = length - 1; // 开始读取位置, 结束读取位置 + long lastModified = file.lastModified(); // 文件修改时间 + response.setHeader("Accept-Ranges", "bytes"); + response.setHeader("ETag", "\"" + length + "-" + lastModified + "\""); + response.setHeader("Last-Modified", new Date(lastModified).toString()); + String range = request.getHeader("Range"); + if (range != null) { + response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); + String[] ranges = range.replace("bytes=", "").split("-"); + start = Long.parseLong(ranges[0].trim()); + if (ranges.length > 1) { + to = Long.parseLong(ranges[1].trim()); + } + response.setHeader("Content-Range", "bytes " + start + "-" + to + "/" + length); + } + response.setHeader("Content-Length", String.valueOf(to - start + 1)); + try { + output(file, response.getOutputStream(), 2048, start, to); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 输出文件流 + * + * @param file 文件 + * @param os 输出流 + */ + public static void output(File file, OutputStream os) { + output(file, os, null); + } + + /** + * 输出文件流 + * + * @param file 文件 + * @param os 输出流 + * @param size 读取缓冲区大小 + */ + public static void output(File file, OutputStream os, Integer size) { + output(file, os, size, null, null); + } + + /** + * 输出文件流, 支持分片 + * + * @param file 文件 + * @param os 输出流 + * @param size 读取缓冲区大小 + * @param start 开始位置 + * @param to 结束位置 + */ + public static void output(File file, OutputStream os, Integer size, Long start, Long to) { + BufferedInputStream is = null; + try { + is = new BufferedInputStream(new FileInputStream(file)); + if (start != null) { + long skip = is.skip(start); + if (skip < start) { + System.out.println("ERROR: skip fail[ skipped=" + skip + ", start= " + start + " ]"); + } + to = to - start + 1; + } + byte[] bytes = new byte[size == null ? 2048 : size]; + int len; + if (to == null) { + while ((len = is.read(bytes)) != -1) { + os.write(bytes, 0, len); + } + } else { + while (to > 0 && (len = is.read(bytes)) != -1) { + os.write(bytes, 0, to < len ? (int) ((long) to) : len); + to -= len; + } + } + os.flush(); + } catch (IOException ignored) { + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException ignored) { + } + } + if (is != null) { + try { + is.close(); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + } + } + } + + /** + * 获取文件类型 + * + * @param file 文件 + * @return String + */ + public static String getContentType(File file) { + String contentType = null; + try { + contentType = new Tika().detect(file); + } catch (IOException e) { + e.printStackTrace(); + } + return contentType; + } + + /** + * 判断文件是否是图片类型 + * + * @param file 文件 + * @return boolean + */ + public static boolean isImage(File file) { + String contentType = getContentType(file); + return contentType != null && contentType.startsWith("image/"); + } + + /** + * 设置下载文件的header + * + * @param response HttpServletResponse + * @param fileName 文件名称 + */ + public static void setDownloadHeader(HttpServletResponse response, String fileName) { + response.setContentType("application/force-download"); + try { + fileName = URLEncoder.encode(fileName, "utf-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + response.setHeader("Content-Disposition", "attachment;fileName=" + fileName); + } + + /** + * 输出404错误页面 + * + * @param response HttpServletResponse + */ + public static void outNotFund(HttpServletResponse response) { + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + outMessage("404 Not Found", null, response); + } + + /** + * 输出错误页面 + * + * @param title 标题 + * @param message 内容 + * @param response HttpServletResponse + */ + public static void outMessage(String title, String message, HttpServletResponse response) { + response.setContentType("text/html;charset=UTF-8"); + try { + PrintWriter writer = response.getWriter(); + writer.write(""); + writer.write("" + title + ""); + writer.write("

" + title + "

"); + if (message != null) { + writer.write(message); + } + writer.write("

EleAdmin File Server

"); + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/eleadmin/common/core/utils/JChardetFacadeUtil.java b/src/main/java/com/eleadmin/common/core/utils/JChardetFacadeUtil.java new file mode 100644 index 0000000..6bcbbb9 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/utils/JChardetFacadeUtil.java @@ -0,0 +1,2025 @@ +package com.eleadmin.common.core.utils; + +import java.io.*; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.UnsupportedCharsetException; + +/** + * 文件编码检测工具, 核心代码来自 cpDetector 和 jChardet, 可以检测大多数文件的编码 + * + * @author EleAdmin + * @since 2020-09-15 09:24:20 + */ +public class JChardetFacadeUtil { + + public static String detectCodepage(URL url) { + try { + Charset ret = JChardetFacade.getInstance().detectCodepage(url); + return ret == null ? null : ret.name(); + } catch (Exception ignored) { + } + return null; + } + + /** + * 下面代码来自: https://github.com/r91987/cpdetector + */ + public static class JChardetFacade extends AbstractCodepageDetector implements nsICharsetDetectionObserver { + private static JChardetFacade instance = null; + private static nsDetector det; + private byte[] buf = new byte[4096]; + private Charset codpage = null; + private boolean m_guessing = true; + private int amountOfVerifiers = 0; + + private JChardetFacade() { + det = new nsDetector(0); + det.Init(this); + this.amountOfVerifiers = det.getProbableCharsets().length; + } + + public static JChardetFacade getInstance() { + if (instance == null) { + instance = new JChardetFacade(); + } + + return instance; + } + + public synchronized Charset detectCodepage(InputStream in, int length) throws IOException { + this.Reset(); + int read = 0; + boolean done = false; + boolean isAscii = true; + Charset ret = null; + + int len; + do { + len = in.read(this.buf, 0, Math.min(this.buf.length, length - read)); + if (len > 0) { + read += len; + } + + if (!done) { + done = det.DoIt(this.buf, len, false); + } + } while (len > 0 && !done); + + det.DataEnd(); + if (this.codpage == null) { + if (this.m_guessing) { + ret = this.guess(); + } + } else { + ret = this.codpage; + } + return ret; + } + + private Charset guess() { + Charset ret = null; + String[] possibilities = det.getProbableCharsets(); + if (possibilities.length == this.amountOfVerifiers) { + ret = Charset.forName("US-ASCII"); + } else { + String check = possibilities[0]; + if (!check.equalsIgnoreCase("nomatch")) { + for (int i = 0; ret == null && i < possibilities.length; ++i) { + try { + ret = Charset.forName(possibilities[i]); + } catch (UnsupportedCharsetException ignored) { + } + } + } + } + return ret; + } + + public void Notify(String charset) { + this.codpage = Charset.forName(charset); + } + + public void Reset() { + det.Reset(); + this.codpage = null; + } + + public boolean isGuessing() { + return this.m_guessing; + } + + public synchronized void setGuessing(boolean guessing) { + this.m_guessing = guessing; + } + } + + /** + * + */ + public static abstract class AbstractCodepageDetector implements ICodepageDetector { + public AbstractCodepageDetector() { + } + + public Charset detectCodepage(URL url) throws IOException { + BufferedInputStream in = new BufferedInputStream(url.openStream()); + Charset result = this.detectCodepage(in, 2147483647); + in.close(); + return result; + } + + public final Reader open(URL url) throws IOException { + Reader ret = null; + Charset cs = this.detectCodepage(url); + if (cs != null) { + ret = new InputStreamReader(new BufferedInputStream(url.openStream()), cs); + } + + return ret; + } + + public int compareTo(Object o) { + String other = o.getClass().getName(); + String mine = this.getClass().getName(); + return mine.compareTo(other); + } + } + + /** + * + */ + interface ICodepageDetector extends Serializable, Comparable { + Reader open(URL var1) throws IOException; + + Charset detectCodepage(URL var1) throws IOException; + + Charset detectCodepage(InputStream var1, int var2) throws IOException; + } + + /** + * 以下代码开始是由Mozilla组织提供的JChardet, 它可以检测大多数文件的编码 + * http://jchardet.sourceforge.net/ + */ + public static class nsDetector extends nsPSMDetector implements nsICharsetDetector { + nsICharsetDetectionObserver mObserver = null; + + public nsDetector() { + } + + public nsDetector(int var1) { + super(var1); + } + + public void Init(nsICharsetDetectionObserver var1) { + this.mObserver = var1; + } + + public boolean DoIt(byte[] var1, int var2, boolean var3) { + if (var1 != null && !var3) { + this.HandleData(var1, var2); + return this.mDone; + } else { + return false; + } + } + + public void Done() { + this.DataEnd(); + } + + public void Report(String var1) { + if (this.mObserver != null) { + this.mObserver.Notify(var1); + } + + } + + public boolean isAscii(byte[] var1, int var2) { + for (int var3 = 0; var3 < var2; ++var3) { + if ((128 & var1[var3]) != 0) { + return false; + } + } + + return true; + } + } + + /** + * + */ + public static abstract class nsPSMDetector { + public static final int ALL = 0; + public static final int JAPANESE = 1; + public static final int CHINESE = 2; + public static final int SIMPLIFIED_CHINESE = 3; + public static final int TRADITIONAL_CHINESE = 4; + public static final int KOREAN = 5; + public static final int NO_OF_LANGUAGES = 6; + public static final int MAX_VERIFIERS = 16; + nsVerifier[] mVerifier; + nsEUCStatistics[] mStatisticsData; + nsEUCSampler mSampler = new nsEUCSampler(); + byte[] mState = new byte[16]; + int[] mItemIdx = new int[16]; + int mItems; + int mClassItems; + boolean mDone; + boolean mRunSampler; + boolean mClassRunSampler; + + public nsPSMDetector() { + this.initVerifiers(0); + this.Reset(); + } + + public nsPSMDetector(int var1) { + this.initVerifiers(var1); + this.Reset(); + } + + public nsPSMDetector(int var1, nsVerifier[] var2, nsEUCStatistics[] var3) { + this.mClassRunSampler = var3 != null; + this.mStatisticsData = var3; + this.mVerifier = var2; + this.mClassItems = var1; + this.Reset(); + } + + public void Reset() { + this.mRunSampler = this.mClassRunSampler; + this.mDone = false; + this.mItems = this.mClassItems; + + for (int var1 = 0; var1 < this.mItems; this.mItemIdx[var1] = var1++) { + this.mState[var1] = 0; + } + + this.mSampler.Reset(); + } + + protected void initVerifiers(int var1) { + boolean var2 = false; + int var3; + if (var1 >= 0 && var1 < 6) { + var3 = var1; + } else { + var3 = 0; + } + + this.mVerifier = null; + this.mStatisticsData = null; + if (var3 == 4) { + this.mVerifier = new nsVerifier[]{new nsUTF8Verifier(), new nsBIG5Verifier(), new nsISO2022CNVerifier(), new nsEUCTWVerifier(), new nsCP1252Verifier(), new nsUCS2BEVerifier(), new nsUCS2LEVerifier()}; + this.mStatisticsData = new nsEUCStatistics[]{null, new Big5Statistics(), null, new EUCTWStatistics(), null, null, null}; + } else if (var3 == 5) { + this.mVerifier = new nsVerifier[]{new nsUTF8Verifier(), new nsEUCKRVerifier(), new nsISO2022KRVerifier(), new nsCP1252Verifier(), new nsUCS2BEVerifier(), new nsUCS2LEVerifier()}; + } else if (var3 == 3) { + this.mVerifier = new nsVerifier[]{new nsUTF8Verifier(), new nsGB2312Verifier(), new nsGB18030Verifier(), new nsISO2022CNVerifier(), new nsHZVerifier(), new nsCP1252Verifier(), new nsUCS2BEVerifier(), new nsUCS2LEVerifier()}; + } else if (var3 == 1) { + this.mVerifier = new nsVerifier[]{new nsUTF8Verifier(), new nsSJISVerifier(), new nsEUCJPVerifier(), new nsISO2022JPVerifier(), new nsCP1252Verifier(), new nsUCS2BEVerifier(), new nsUCS2LEVerifier()}; + } else if (var3 == 2) { + this.mVerifier = new nsVerifier[]{new nsUTF8Verifier(), new nsGB2312Verifier(), new nsGB18030Verifier(), new nsBIG5Verifier(), new nsISO2022CNVerifier(), new nsHZVerifier(), new nsEUCTWVerifier(), new nsCP1252Verifier(), new nsUCS2BEVerifier(), new nsUCS2LEVerifier()}; + this.mStatisticsData = new nsEUCStatistics[]{null, new GB2312Statistics(), null, new Big5Statistics(), null, null, new EUCTWStatistics(), null, null, null}; + } else if (var3 == 0) { + this.mVerifier = new nsVerifier[]{new nsUTF8Verifier(), new nsSJISVerifier(), new nsEUCJPVerifier(), new nsISO2022JPVerifier(), new nsEUCKRVerifier(), new nsISO2022KRVerifier(), new nsBIG5Verifier(), new nsEUCTWVerifier(), new nsGB2312Verifier(), new nsGB18030Verifier(), new nsISO2022CNVerifier(), new nsHZVerifier(), new nsCP1252Verifier(), new nsUCS2BEVerifier(), new nsUCS2LEVerifier()}; + this.mStatisticsData = new nsEUCStatistics[]{null, null, new EUCJPStatistics(), null, new EUCKRStatistics(), null, new Big5Statistics(), new EUCTWStatistics(), new GB2312Statistics(), null, null, null, null, null, null}; + } + + this.mClassRunSampler = this.mStatisticsData != null; + this.mClassItems = this.mVerifier.length; + } + + public abstract void Report(String var1); + + public boolean HandleData(byte[] var1, int var2) { + for (int var3 = 0; var3 < var2; ++var3) { + byte var5 = var1[var3]; + int var4 = 0; + + while (var4 < this.mItems) { + byte var6 = nsVerifier.getNextState(this.mVerifier[this.mItemIdx[var4]], var5, this.mState[var4]); + if (var6 == 2) { + this.Report(this.mVerifier[this.mItemIdx[var4]].charset()); + this.mDone = true; + return this.mDone; + } + + if (var6 == 1) { + --this.mItems; + if (var4 < this.mItems) { + this.mItemIdx[var4] = this.mItemIdx[this.mItems]; + this.mState[var4] = this.mState[this.mItems]; + } + } else { + this.mState[var4++] = var6; + } + } + + if (this.mItems <= 1) { + if (1 == this.mItems) { + this.Report(this.mVerifier[this.mItemIdx[0]].charset()); + } + + this.mDone = true; + return this.mDone; + } + + int var7 = 0; + int var8 = 0; + + for (var4 = 0; var4 < this.mItems; ++var4) { + if (!this.mVerifier[this.mItemIdx[var4]].isUCS2() && !this.mVerifier[this.mItemIdx[var4]].isUCS2()) { + ++var7; + var8 = var4; + } + } + + if (1 == var7) { + this.Report(this.mVerifier[this.mItemIdx[var8]].charset()); + this.mDone = true; + return this.mDone; + } + } + + if (this.mRunSampler) { + this.Sample(var1, var2); + } + + return this.mDone; + } + + public void DataEnd() { + if (!this.mDone) { + if (this.mItems == 2) { + if (this.mVerifier[this.mItemIdx[0]].charset().equals("GB18030")) { + this.Report(this.mVerifier[this.mItemIdx[1]].charset()); + this.mDone = true; + } else if (this.mVerifier[this.mItemIdx[1]].charset().equals("GB18030")) { + this.Report(this.mVerifier[this.mItemIdx[0]].charset()); + this.mDone = true; + } + } + + if (this.mRunSampler) { + this.Sample((byte[]) null, 0, true); + } + + } + } + + public void Sample(byte[] var1, int var2) { + this.Sample(var1, var2, false); + } + + public void Sample(byte[] var1, int var2, boolean var3) { + int var4 = 0; + int var6 = 0; + + int var5; + for (var5 = 0; var5 < this.mItems; ++var5) { + if (null != this.mStatisticsData[this.mItemIdx[var5]]) { + ++var6; + } + + if (!this.mVerifier[this.mItemIdx[var5]].isUCS2() && !this.mVerifier[this.mItemIdx[var5]].charset().equals("GB18030")) { + ++var4; + } + } + + this.mRunSampler = var6 > 1; + if (this.mRunSampler) { + this.mRunSampler = this.mSampler.Sample(var1, var2); + if ((var3 && this.mSampler.GetSomeData() || this.mSampler.EnoughData()) && var6 == var4) { + this.mSampler.CalFreq(); + int var7 = -1; + int var8 = 0; + float var9 = 0.0F; + + for (var5 = 0; var5 < this.mItems; ++var5) { + if (null != this.mStatisticsData[this.mItemIdx[var5]] && !this.mVerifier[this.mItemIdx[var5]].charset().equals("Big5")) { + float var10 = this.mSampler.GetScore(this.mStatisticsData[this.mItemIdx[var5]].mFirstByteFreq(), this.mStatisticsData[this.mItemIdx[var5]].mFirstByteWeight(), this.mStatisticsData[this.mItemIdx[var5]].mSecondByteFreq(), this.mStatisticsData[this.mItemIdx[var5]].mSecondByteWeight()); + if (0 == var8++ || var9 > var10) { + var9 = var10; + var7 = var5; + } + } + } + + if (var7 >= 0) { + this.Report(this.mVerifier[this.mItemIdx[var7]].charset()); + this.mDone = true; + } + } + } + + } + + public String[] getProbableCharsets() { + String[] var1; + if (this.mItems <= 0) { + var1 = new String[]{"nomatch"}; + return var1; + } else { + var1 = new String[this.mItems]; + + for (int var2 = 0; var2 < this.mItems; ++var2) { + var1[var2] = this.mVerifier[this.mItemIdx[var2]].charset(); + } + + return var1; + } + } + } + + /** + * + */ + public static interface nsICharsetDetectionObserver { + void Notify(String var1); + } + + /** + * + */ + public static interface nsICharsetDetector { + void Init(nsICharsetDetectionObserver var1); + + boolean DoIt(byte[] var1, int var2, boolean var3); + + void Done(); + } + + /** + * + */ + public static abstract class nsVerifier { + static final byte eStart = 0; + static final byte eError = 1; + static final byte eItsMe = 2; + static final int eidxSft4bits = 3; + static final int eSftMsk4bits = 7; + static final int eBitSft4bits = 2; + static final int eUnitMsk4bits = 15; + + nsVerifier() { + } + + public abstract String charset(); + + public abstract int stFactor(); + + public abstract int[] cclass(); + + public abstract int[] states(); + + public abstract boolean isUCS2(); + + public static byte getNextState(nsVerifier var0, byte var1, byte var2) { + return (byte) (255 & var0.states()[(var2 * var0.stFactor() + (var0.cclass()[(var1 & 255) >> 3] >> ((var1 & 7) << 2) & 15) & 255) >> 3] >> ((var2 * var0.stFactor() + (var0.cclass()[(var1 & 255) >> 3] >> ((var1 & 7) << 2) & 15) & 255 & 7) << 2) & 15); + } + } + + /** + * + */ + public static class nsEUCSampler { + int mTotal = 0; + int mThreshold = 200; + int mState = 0; + public int[] mFirstByteCnt = new int[94]; + public int[] mSecondByteCnt = new int[94]; + public float[] mFirstByteFreq = new float[94]; + public float[] mSecondByteFreq = new float[94]; + + public nsEUCSampler() { + this.Reset(); + } + + public void Reset() { + this.mTotal = 0; + this.mState = 0; + + for (int var1 = 0; var1 < 94; ++var1) { + this.mFirstByteCnt[var1] = this.mSecondByteCnt[var1] = 0; + } + + } + + boolean EnoughData() { + return this.mTotal > this.mThreshold; + } + + boolean GetSomeData() { + return this.mTotal > 1; + } + + boolean Sample(byte[] var1, int var2) { + if (this.mState == 1) { + return false; + } else { + int var3 = 0; + + for (int var4 = 0; var4 < var2 && 1 != this.mState; ++var3) { + int var10002; + switch (this.mState) { + case 0: + if ((var1[var3] & 128) != 0) { + if (255 != (255 & var1[var3]) && 161 <= (255 & var1[var3])) { + ++this.mTotal; + var10002 = this.mFirstByteCnt[(255 & var1[var3]) - 161]++; + this.mState = 2; + } else { + this.mState = 1; + } + } + case 1: + break; + case 2: + if ((var1[var3] & 128) != 0) { + if (255 != (255 & var1[var3]) && 161 <= (255 & var1[var3])) { + ++this.mTotal; + var10002 = this.mSecondByteCnt[(255 & var1[var3]) - 161]++; + this.mState = 0; + } else { + this.mState = 1; + } + } else { + this.mState = 1; + } + break; + default: + this.mState = 1; + } + + ++var4; + } + + return 1 != this.mState; + } + } + + void CalFreq() { + for (int var1 = 0; var1 < 94; ++var1) { + this.mFirstByteFreq[var1] = (float) this.mFirstByteCnt[var1] / (float) this.mTotal; + this.mSecondByteFreq[var1] = (float) this.mSecondByteCnt[var1] / (float) this.mTotal; + } + + } + + float GetScore(float[] var1, float var2, float[] var3, float var4) { + return var2 * this.GetScore(var1, this.mFirstByteFreq) + var4 * this.GetScore(var3, this.mSecondByteFreq); + } + + float GetScore(float[] var1, float[] var2) { + float var4 = 0.0F; + + for (int var5 = 0; var5 < 94; ++var5) { + float var3 = var1[var5] - var2[var5]; + var4 += var3 * var3; + } + + return (float) Math.sqrt((double) var4) / 94.0F; + } + } + + /** + * + */ + public static abstract class nsEUCStatistics { + public abstract float[] mFirstByteFreq(); + + public abstract float mFirstByteStdDev(); + + public abstract float mFirstByteMean(); + + public abstract float mFirstByteWeight(); + + public abstract float[] mSecondByteFreq(); + + public abstract float mSecondByteStdDev(); + + public abstract float mSecondByteMean(); + + public abstract float mSecondByteWeight(); + + public nsEUCStatistics() { + } + } + + /** + * + */ + public static class EUCJPStatistics extends nsEUCStatistics { + static float[] mFirstByteFreq; + static float mFirstByteStdDev; + static float mFirstByteMean; + static float mFirstByteWeight; + static float[] mSecondByteFreq; + static float mSecondByteStdDev; + static float mSecondByteMean; + static float mSecondByteWeight; + + public float[] mFirstByteFreq() { + return mFirstByteFreq; + } + + public float mFirstByteStdDev() { + return mFirstByteStdDev; + } + + public float mFirstByteMean() { + return mFirstByteMean; + } + + public float mFirstByteWeight() { + return mFirstByteWeight; + } + + public float[] mSecondByteFreq() { + return mSecondByteFreq; + } + + public float mSecondByteStdDev() { + return mSecondByteStdDev; + } + + public float mSecondByteMean() { + return mSecondByteMean; + } + + public float mSecondByteWeight() { + return mSecondByteWeight; + } + + public EUCJPStatistics() { + mFirstByteFreq = new float[]{0.364808F, 0.0F, 0.0F, 0.145325F, 0.304891F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.001835F, 0.010771F, 0.006462F, 0.001157F, 0.002114F, 0.003231F, 0.001356F, 0.00742F, 0.004189F, 0.003231F, 0.003032F, 0.03319F, 0.006303F, 0.006064F, 0.009973F, 0.002354F, 0.00367F, 0.009135F, 0.001675F, 0.002792F, 0.002194F, 0.01472F, 0.011928F, 8.78E-4F, 0.013124F, 0.001077F, 0.009295F, 0.003471F, 0.002872F, 0.002433F, 9.57E-4F, 0.001636F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 8.0E-5F, 2.79E-4F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 8.0E-5F, 0.0F}; + mFirstByteStdDev = 0.050407F; + mFirstByteMean = 0.010638F; + mFirstByteWeight = 0.640871F; + mSecondByteFreq = new float[]{0.002473F, 0.039134F, 0.152745F, 0.009694F, 3.59E-4F, 0.02218F, 7.58E-4F, 0.004308F, 1.6E-4F, 0.002513F, 0.003072F, 0.001316F, 0.00383F, 0.001037F, 0.00359F, 9.57E-4F, 1.6E-4F, 2.39E-4F, 0.006462F, 0.001596F, 0.031554F, 0.001316F, 0.002194F, 0.016555F, 0.003271F, 6.78E-4F, 5.98E-4F, 0.206438F, 7.18E-4F, 0.001077F, 0.00371F, 0.001356F, 0.001356F, 4.39E-4F, 0.004388F, 0.005704F, 8.78E-4F, 0.010172F, 0.007061F, 0.01468F, 6.38E-4F, 0.02573F, 0.002792F, 7.18E-4F, 0.001795F, 0.091551F, 7.58E-4F, 0.003909F, 5.58E-4F, 0.031195F, 0.007061F, 0.001316F, 0.022579F, 0.006981F, 0.00726F, 0.001117F, 2.39E-4F, 0.012127F, 8.78E-4F, 0.00379F, 0.001077F, 7.58E-4F, 0.002114F, 0.002234F, 6.78E-4F, 0.002992F, 0.003311F, 0.023416F, 0.001237F, 0.002753F, 0.005146F, 0.002194F, 0.007021F, 0.008497F, 0.013763F, 0.011768F, 0.006303F, 0.001915F, 6.38E-4F, 0.008776F, 9.18E-4F, 0.003431F, 0.057603F, 4.39E-4F, 4.39E-4F, 7.58E-4F, 0.002872F, 0.001675F, 0.01105F, 0.0F, 2.79E-4F, 0.012127F, 7.18E-4F, 0.00738F}; + mSecondByteStdDev = 0.028247F; + mSecondByteMean = 0.010638F; + mSecondByteWeight = 0.359129F; + } + } + + /** + * + */ + public static class nsEUCJPVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsEUCJPVerifier() { + cclass = new int[32]; + cclass[0] = 1145324612; + cclass[1] = 1430537284; + cclass[2] = 1145324612; + cclass[3] = 1145328708; + cclass[4] = 1145324612; + cclass[5] = 1145324612; + cclass[6] = 1145324612; + cclass[7] = 1145324612; + cclass[8] = 1145324612; + cclass[9] = 1145324612; + cclass[10] = 1145324612; + cclass[11] = 1145324612; + cclass[12] = 1145324612; + cclass[13] = 1145324612; + cclass[14] = 1145324612; + cclass[15] = 1145324612; + cclass[16] = 1431655765; + cclass[17] = 827675989; + cclass[18] = 1431655765; + cclass[19] = 1431655765; + cclass[20] = 572662309; + cclass[21] = 572662306; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 572662306; + cclass[25] = 572662306; + cclass[26] = 572662306; + cclass[27] = 572662306; + cclass[28] = 0; + cclass[29] = 0; + cclass[30] = 0; + cclass[31] = 1342177280; + states = new int[5]; + states[0] = 286282563; + states[1] = 572657937; + states[2] = 286265378; + states[3] = 319885329; + states[4] = 4371; + charset = "EUC-JP"; + stFactor = 6; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class EUCKRStatistics extends nsEUCStatistics { + static float[] mFirstByteFreq; + static float mFirstByteStdDev; + static float mFirstByteMean; + static float mFirstByteWeight; + static float[] mSecondByteFreq; + static float mSecondByteStdDev; + static float mSecondByteMean; + static float mSecondByteWeight; + + public float[] mFirstByteFreq() { + return mFirstByteFreq; + } + + public float mFirstByteStdDev() { + return mFirstByteStdDev; + } + + public float mFirstByteMean() { + return mFirstByteMean; + } + + public float mFirstByteWeight() { + return mFirstByteWeight; + } + + public float[] mSecondByteFreq() { + return mSecondByteFreq; + } + + public float mSecondByteStdDev() { + return mSecondByteStdDev; + } + + public float mSecondByteMean() { + return mSecondByteMean; + } + + public float mSecondByteWeight() { + return mSecondByteWeight; + } + + public EUCKRStatistics() { + mFirstByteFreq = new float[]{0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 4.12E-4F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.057502F, 0.033182F, 0.002267F, 0.016076F, 0.014633F, 0.032976F, 0.004122F, 0.011336F, 0.058533F, 0.024526F, 0.025969F, 0.054411F, 0.01958F, 0.063273F, 0.113974F, 0.029885F, 0.150041F, 0.059151F, 0.002679F, 0.009893F, 0.014839F, 0.026381F, 0.015045F, 0.069456F, 0.08986F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F}; + mFirstByteStdDev = 0.025593F; + mFirstByteMean = 0.010638F; + mFirstByteWeight = 0.647437F; + mSecondByteFreq = new float[]{0.016694F, 0.0F, 0.012778F, 0.030091F, 0.002679F, 0.006595F, 0.001855F, 8.24E-4F, 0.005977F, 0.00474F, 0.003092F, 8.24E-4F, 0.01958F, 0.037304F, 0.008244F, 0.014633F, 0.001031F, 0.0F, 0.003298F, 0.002061F, 0.006183F, 0.005977F, 8.24E-4F, 0.021847F, 0.014839F, 0.052968F, 0.017312F, 0.007626F, 4.12E-4F, 8.24E-4F, 0.011129F, 0.0F, 4.12E-4F, 0.001649F, 0.005977F, 0.065746F, 0.020198F, 0.021434F, 0.014633F, 0.004122F, 0.001649F, 8.24E-4F, 8.24E-4F, 0.051937F, 0.01958F, 0.023289F, 0.026381F, 0.040396F, 0.009068F, 0.001443F, 0.00371F, 0.00742F, 0.001443F, 0.01319F, 0.002885F, 4.12E-4F, 0.003298F, 0.025969F, 4.12E-4F, 4.12E-4F, 0.006183F, 0.003298F, 0.066983F, 0.002679F, 0.002267F, 0.011129F, 4.12E-4F, 0.010099F, 0.015251F, 0.007626F, 0.043899F, 0.00371F, 0.002679F, 0.001443F, 0.010923F, 0.002885F, 0.009068F, 0.019992F, 4.12E-4F, 0.00845F, 0.005153F, 0.0F, 0.010099F, 0.0F, 0.001649F, 0.01216F, 0.011542F, 0.006595F, 0.001855F, 0.010923F, 4.12E-4F, 0.023702F, 0.00371F, 0.001855F}; + mSecondByteStdDev = 0.013937F; + mSecondByteMean = 0.010638F; + mSecondByteWeight = 0.352563F; + } + } + + /** + * + */ + public static class nsEUCKRVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsEUCKRVerifier() { + cclass = new int[32]; + cclass[0] = 286331153; + cclass[1] = 1118481; + cclass[2] = 286331153; + cclass[3] = 286327057; + cclass[4] = 286331153; + cclass[5] = 286331153; + cclass[6] = 286331153; + cclass[7] = 286331153; + cclass[8] = 286331153; + cclass[9] = 286331153; + cclass[10] = 286331153; + cclass[11] = 286331153; + cclass[12] = 286331153; + cclass[13] = 286331153; + cclass[14] = 286331153; + cclass[15] = 286331153; + cclass[16] = 0; + cclass[17] = 0; + cclass[18] = 0; + cclass[19] = 0; + cclass[20] = 572662304; + cclass[21] = 858923554; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 572662306; + cclass[25] = 572662322; + cclass[26] = 572662306; + cclass[27] = 572662306; + cclass[28] = 572662306; + cclass[29] = 572662306; + cclass[30] = 572662306; + cclass[31] = 35791394; + states = new int[2]; + states[0] = 286331649; + states[1] = 1122850; + charset = "EUC-KR"; + stFactor = 4; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class EUCTWStatistics extends nsEUCStatistics { + static float[] mFirstByteFreq; + static float mFirstByteStdDev; + static float mFirstByteMean; + static float mFirstByteWeight; + static float[] mSecondByteFreq; + static float mSecondByteStdDev; + static float mSecondByteMean; + static float mSecondByteWeight; + + public float[] mFirstByteFreq() { + return mFirstByteFreq; + } + + public float mFirstByteStdDev() { + return mFirstByteStdDev; + } + + public float mFirstByteMean() { + return mFirstByteMean; + } + + public float mFirstByteWeight() { + return mFirstByteWeight; + } + + public float[] mSecondByteFreq() { + return mSecondByteFreq; + } + + public float mSecondByteStdDev() { + return mSecondByteStdDev; + } + + public float mSecondByteMean() { + return mSecondByteMean; + } + + public float mSecondByteWeight() { + return mSecondByteWeight; + } + + public EUCTWStatistics() { + mFirstByteFreq = new float[]{0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.119286F, 0.052233F, 0.044126F, 0.052494F, 0.045906F, 0.019038F, 0.032465F, 0.026252F, 0.025502F, 0.015963F, 0.052493F, 0.019256F, 0.015137F, 0.031782F, 0.01737F, 0.018494F, 0.015575F, 0.016621F, 0.007444F, 0.011642F, 0.013916F, 0.019159F, 0.016445F, 0.007851F, 0.011079F, 0.022842F, 0.015513F, 0.010033F, 0.00995F, 0.010347F, 0.013103F, 0.015371F, 0.012502F, 0.007436F, 0.018253F, 0.014134F, 0.008907F, 0.005411F, 0.00957F, 0.013598F, 0.006092F, 0.007409F, 0.008432F, 0.005816F, 0.009349F, 0.005472F, 0.00717F, 0.00742F, 0.003681F, 0.007523F, 0.00461F, 0.006154F, 0.003348F, 0.005074F, 0.005922F, 0.005254F, 0.004682F, 0.002093F, 0.0F}; + mFirstByteStdDev = 0.016681F; + mFirstByteMean = 0.010638F; + mFirstByteWeight = 0.715599F; + mSecondByteFreq = new float[]{0.028933F, 0.011371F, 0.011053F, 0.007232F, 0.010192F, 0.004093F, 0.015043F, 0.011752F, 0.022387F, 0.00841F, 0.012448F, 0.007473F, 0.003594F, 0.007139F, 0.018912F, 0.006083F, 0.003302F, 0.010215F, 0.008791F, 0.024236F, 0.014107F, 0.014108F, 0.010303F, 0.009728F, 0.007877F, 0.009719F, 0.007952F, 0.021028F, 0.005764F, 0.009341F, 0.006591F, 0.012517F, 0.005921F, 0.008982F, 0.008771F, 0.012802F, 0.005926F, 0.008342F, 0.003086F, 0.006843F, 0.007576F, 0.004734F, 0.016404F, 0.008803F, 0.008071F, 0.005349F, 0.008566F, 0.01084F, 0.015401F, 0.031904F, 0.00867F, 0.011479F, 0.010936F, 0.007617F, 0.008995F, 0.008114F, 0.008658F, 0.005934F, 0.010452F, 0.009142F, 0.004519F, 0.008339F, 0.007476F, 0.007027F, 0.006025F, 0.021804F, 0.024248F, 0.015895F, 0.003768F, 0.010171F, 0.010007F, 0.010178F, 0.008316F, 0.006832F, 0.006364F, 0.009141F, 0.009148F, 0.012081F, 0.011914F, 0.004464F, 0.014257F, 0.006907F, 0.011292F, 0.018622F, 0.008149F, 0.004636F, 0.006612F, 0.013478F, 0.012614F, 0.005186F, 0.048285F, 0.006816F, 0.006743F, 0.008671F}; + mSecondByteStdDev = 0.00663F; + mSecondByteMean = 0.010638F; + mSecondByteWeight = 0.284401F; + } + } + + /** + * + */ + public static class nsEUCTWVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsEUCTWVerifier() { + cclass = new int[32]; + cclass[0] = 572662306; + cclass[1] = 2236962; + cclass[2] = 572662306; + cclass[3] = 572654114; + cclass[4] = 572662306; + cclass[5] = 572662306; + cclass[6] = 572662306; + cclass[7] = 572662306; + cclass[8] = 572662306; + cclass[9] = 572662306; + cclass[10] = 572662306; + cclass[11] = 572662306; + cclass[12] = 572662306; + cclass[13] = 572662306; + cclass[14] = 572662306; + cclass[15] = 572662306; + cclass[16] = 0; + cclass[17] = 100663296; + cclass[18] = 0; + cclass[19] = 0; + cclass[20] = 1145324592; + cclass[21] = 286331221; + cclass[22] = 286331153; + cclass[23] = 286331153; + cclass[24] = 858985233; + cclass[25] = 858993459; + cclass[26] = 858993459; + cclass[27] = 858993459; + cclass[28] = 858993459; + cclass[29] = 858993459; + cclass[30] = 858993459; + cclass[31] = 53687091; + states = new int[6]; + states[0] = 338898961; + states[1] = 571543825; + states[2] = 269623842; + states[3] = 286330880; + states[4] = 1052949; + states[5] = 16; + charset = "x-euc-tw"; + stFactor = 7; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class Big5Statistics extends nsEUCStatistics { + static float[] mFirstByteFreq; + static float mFirstByteStdDev; + static float mFirstByteMean; + static float mFirstByteWeight; + static float[] mSecondByteFreq; + static float mSecondByteStdDev; + static float mSecondByteMean; + static float mSecondByteWeight; + + public float[] mFirstByteFreq() { + return mFirstByteFreq; + } + + public float mFirstByteStdDev() { + return mFirstByteStdDev; + } + + public float mFirstByteMean() { + return mFirstByteMean; + } + + public float mFirstByteWeight() { + return mFirstByteWeight; + } + + public float[] mSecondByteFreq() { + return mSecondByteFreq; + } + + public float mSecondByteStdDev() { + return mSecondByteStdDev; + } + + public float mSecondByteMean() { + return mSecondByteMean; + } + + public float mSecondByteWeight() { + return mSecondByteWeight; + } + + public Big5Statistics() { + mFirstByteFreq = new float[]{0.0F, 0.0F, 0.0F, 0.114427F, 0.061058F, 0.075598F, 0.048386F, 0.063966F, 0.027094F, 0.095787F, 0.029525F, 0.031331F, 0.036915F, 0.021805F, 0.019349F, 0.037496F, 0.018068F, 0.01276F, 0.030053F, 0.017339F, 0.016731F, 0.019501F, 0.01124F, 0.032973F, 0.016658F, 0.015872F, 0.021458F, 0.012378F, 0.017003F, 0.020802F, 0.012454F, 0.009239F, 0.012829F, 0.007922F, 0.010079F, 0.009815F, 0.010104F, 0.0F, 0.0F, 0.0F, 5.3E-5F, 3.5E-5F, 1.05E-4F, 3.1E-5F, 8.8E-5F, 2.7E-5F, 2.7E-5F, 2.6E-5F, 3.5E-5F, 2.4E-5F, 3.4E-5F, 3.75E-4F, 2.5E-5F, 2.8E-5F, 2.0E-5F, 2.4E-5F, 2.8E-5F, 3.1E-5F, 5.9E-5F, 4.0E-5F, 3.0E-5F, 7.9E-5F, 3.7E-5F, 4.0E-5F, 2.3E-5F, 3.0E-5F, 2.7E-5F, 6.4E-5F, 2.0E-5F, 2.7E-5F, 2.5E-5F, 7.4E-5F, 1.9E-5F, 2.3E-5F, 2.1E-5F, 1.8E-5F, 1.7E-5F, 3.5E-5F, 2.1E-5F, 1.9E-5F, 2.5E-5F, 1.7E-5F, 3.7E-5F, 1.8E-5F, 1.8E-5F, 1.9E-5F, 2.2E-5F, 3.3E-5F, 3.2E-5F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F}; + mFirstByteStdDev = 0.020606F; + mFirstByteMean = 0.010638F; + mFirstByteWeight = 0.675261F; + mSecondByteFreq = new float[]{0.020256F, 0.003293F, 0.045811F, 0.01665F, 0.007066F, 0.004146F, 0.009229F, 0.007333F, 0.003296F, 0.005239F, 0.008282F, 0.003791F, 0.006116F, 0.003536F, 0.004024F, 0.016654F, 0.009334F, 0.005429F, 0.033392F, 0.006121F, 0.008983F, 0.002801F, 0.004221F, 0.010357F, 0.014695F, 0.077937F, 0.006314F, 0.00402F, 0.007331F, 0.00715F, 0.005341F, 0.009195F, 0.00535F, 0.005698F, 0.004472F, 0.007242F, 0.004039F, 0.011154F, 0.016184F, 0.004741F, 0.012814F, 0.007679F, 0.008045F, 0.016631F, 0.009451F, 0.016487F, 0.007287F, 0.012688F, 0.017421F, 0.013205F, 0.03148F, 0.003404F, 0.009149F, 0.008921F, 0.007514F, 0.008683F, 0.008203F, 0.031403F, 0.011733F, 0.015617F, 0.015306F, 0.004004F, 0.010899F, 0.009961F, 0.008388F, 0.01092F, 0.003925F, 0.008585F, 0.009108F, 0.015546F, 0.004659F, 0.006934F, 0.007023F, 0.020252F, 0.005387F, 0.024704F, 0.006963F, 0.002625F, 0.009512F, 0.002971F, 0.008233F, 0.01F, 0.011973F, 0.010553F, 0.005945F, 0.006349F, 0.009401F, 0.008577F, 0.008186F, 0.008159F, 0.005033F, 0.008714F, 0.010614F, 0.006554F}; + mSecondByteStdDev = 0.009909F; + mSecondByteMean = 0.010638F; + mSecondByteWeight = 0.324739F; + } + } + + /** + * + */ + public static class nsBIG5Verifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsBIG5Verifier() { + cclass = new int[32]; + cclass[0] = 286331153; + cclass[1] = 1118481; + cclass[2] = 286331153; + cclass[3] = 286327057; + cclass[4] = 286331153; + cclass[5] = 286331153; + cclass[6] = 286331153; + cclass[7] = 286331153; + cclass[8] = 572662306; + cclass[9] = 572662306; + cclass[10] = 572662306; + cclass[11] = 572662306; + cclass[12] = 572662306; + cclass[13] = 572662306; + cclass[14] = 572662306; + cclass[15] = 304226850; + cclass[16] = 1145324612; + cclass[17] = 1145324612; + cclass[18] = 1145324612; + cclass[19] = 1145324612; + cclass[20] = 858993460; + cclass[21] = 858993459; + cclass[22] = 858993459; + cclass[23] = 858993459; + cclass[24] = 858993459; + cclass[25] = 858993459; + cclass[26] = 858993459; + cclass[27] = 858993459; + cclass[28] = 858993459; + cclass[29] = 858993459; + cclass[30] = 858993459; + cclass[31] = 53687091; + states = new int[3]; + states[0] = 286339073; + states[1] = 304226833; + states[2] = 1; + charset = "Big5"; + stFactor = 5; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class GB2312Statistics extends nsEUCStatistics { + static float[] mFirstByteFreq; + static float mFirstByteStdDev; + static float mFirstByteMean; + static float mFirstByteWeight; + static float[] mSecondByteFreq; + static float mSecondByteStdDev; + static float mSecondByteMean; + static float mSecondByteWeight; + + public float[] mFirstByteFreq() { + return mFirstByteFreq; + } + + public float mFirstByteStdDev() { + return mFirstByteStdDev; + } + + public float mFirstByteMean() { + return mFirstByteMean; + } + + public float mFirstByteWeight() { + return mFirstByteWeight; + } + + public float[] mSecondByteFreq() { + return mSecondByteFreq; + } + + public float mSecondByteStdDev() { + return mSecondByteStdDev; + } + + public float mSecondByteMean() { + return mSecondByteMean; + } + + public float mSecondByteWeight() { + return mSecondByteWeight; + } + + public GB2312Statistics() { + mFirstByteFreq = new float[]{0.011628F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.011628F, 0.012403F, 0.009302F, 0.003876F, 0.017829F, 0.037209F, 0.008527F, 0.010078F, 0.01938F, 0.054264F, 0.010078F, 0.041085F, 0.02093F, 0.018605F, 0.010078F, 0.013178F, 0.016279F, 0.006202F, 0.009302F, 0.017054F, 0.011628F, 0.008527F, 0.004651F, 0.006202F, 0.017829F, 0.024806F, 0.020155F, 0.013953F, 0.032558F, 0.035659F, 0.068217F, 0.010853F, 0.036434F, 0.117054F, 0.027907F, 0.100775F, 0.010078F, 0.017829F, 0.062016F, 0.012403F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.00155F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F}; + mFirstByteStdDev = 0.020081F; + mFirstByteMean = 0.010638F; + mFirstByteWeight = 0.586533F; + mSecondByteFreq = new float[]{0.006202F, 0.031008F, 0.005426F, 0.003101F, 0.00155F, 0.003101F, 0.082171F, 0.014729F, 0.006977F, 0.00155F, 0.013953F, 0.0F, 0.013953F, 0.010078F, 0.008527F, 0.006977F, 0.004651F, 0.003101F, 0.003101F, 0.003101F, 0.008527F, 0.003101F, 0.005426F, 0.005426F, 0.005426F, 0.003101F, 0.00155F, 0.006202F, 0.014729F, 0.010853F, 0.0F, 0.011628F, 0.0F, 0.031783F, 0.013953F, 0.030233F, 0.039535F, 0.008527F, 0.015504F, 0.0F, 0.003101F, 0.008527F, 0.016279F, 0.005426F, 0.00155F, 0.013953F, 0.013953F, 0.044961F, 0.003101F, 0.004651F, 0.006977F, 0.00155F, 0.005426F, 0.012403F, 0.00155F, 0.015504F, 0.0F, 0.006202F, 0.00155F, 0.0F, 0.007752F, 0.006977F, 0.00155F, 0.009302F, 0.011628F, 0.004651F, 0.010853F, 0.012403F, 0.017829F, 0.005426F, 0.024806F, 0.0F, 0.006202F, 0.0F, 0.082171F, 0.015504F, 0.004651F, 0.0F, 0.006977F, 0.004651F, 0.0F, 0.008527F, 0.012403F, 0.004651F, 0.003876F, 0.003101F, 0.022481F, 0.024031F, 0.00155F, 0.047287F, 0.009302F, 0.00155F, 0.005426F, 0.017054F}; + mSecondByteStdDev = 0.014156F; + mSecondByteMean = 0.010638F; + mSecondByteWeight = 0.413467F; + } + } + + /** + * + */ + public static class nsGB2312Verifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsGB2312Verifier() { + cclass = new int[32]; + cclass[0] = 286331153; + cclass[1] = 1118481; + cclass[2] = 286331153; + cclass[3] = 286327057; + cclass[4] = 286331153; + cclass[5] = 286331153; + cclass[6] = 286331153; + cclass[7] = 286331153; + cclass[8] = 286331153; + cclass[9] = 286331153; + cclass[10] = 286331153; + cclass[11] = 286331153; + cclass[12] = 286331153; + cclass[13] = 286331153; + cclass[14] = 286331153; + cclass[15] = 286331153; + cclass[16] = 0; + cclass[17] = 0; + cclass[18] = 0; + cclass[19] = 0; + cclass[20] = 572662304; + cclass[21] = 858993442; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 572662306; + cclass[25] = 572662306; + cclass[26] = 572662306; + cclass[27] = 572662306; + cclass[28] = 572662306; + cclass[29] = 572662306; + cclass[30] = 572662306; + cclass[31] = 35791394; + states = new int[2]; + states[0] = 286331649; + states[1] = 1122850; + charset = "GB2312"; + stFactor = 4; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsGB18030Verifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsGB18030Verifier() { + cclass = new int[32]; + cclass[0] = 286331153; + cclass[1] = 1118481; + cclass[2] = 286331153; + cclass[3] = 286327057; + cclass[4] = 286331153; + cclass[5] = 286331153; + cclass[6] = 858993459; + cclass[7] = 286331187; + cclass[8] = 572662306; + cclass[9] = 572662306; + cclass[10] = 572662306; + cclass[11] = 572662306; + cclass[12] = 572662306; + cclass[13] = 572662306; + cclass[14] = 572662306; + cclass[15] = 1109533218; + cclass[16] = 1717986917; + cclass[17] = 1717986918; + cclass[18] = 1717986918; + cclass[19] = 1717986918; + cclass[20] = 1717986918; + cclass[21] = 1717986918; + cclass[22] = 1717986918; + cclass[23] = 1717986918; + cclass[24] = 1717986918; + cclass[25] = 1717986918; + cclass[26] = 1717986918; + cclass[27] = 1717986918; + cclass[28] = 1717986918; + cclass[29] = 1717986918; + cclass[30] = 1717986918; + cclass[31] = 107374182; + states = new int[6]; + states[0] = 318767105; + states[1] = 571543825; + states[2] = 17965602; + states[3] = 286326804; + states[4] = 303109393; + states[5] = 17; + charset = "GB18030"; + stFactor = 7; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsISO2022CNVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsISO2022CNVerifier() { + cclass = new int[32]; + cclass[0] = 2; + cclass[1] = 0; + cclass[2] = 0; + cclass[3] = 4096; + cclass[4] = 0; + cclass[5] = 48; + cclass[6] = 0; + cclass[7] = 0; + cclass[8] = 16384; + cclass[9] = 0; + cclass[10] = 0; + cclass[11] = 0; + cclass[12] = 0; + cclass[13] = 0; + cclass[14] = 0; + cclass[15] = 0; + cclass[16] = 572662306; + cclass[17] = 572662306; + cclass[18] = 572662306; + cclass[19] = 572662306; + cclass[20] = 572662306; + cclass[21] = 572662306; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 572662306; + cclass[25] = 572662306; + cclass[26] = 572662306; + cclass[27] = 572662306; + cclass[28] = 572662306; + cclass[29] = 572662306; + cclass[30] = 572662306; + cclass[31] = 572662306; + states = new int[8]; + states[0] = 304; + states[1] = 286331152; + states[2] = 572662289; + states[3] = 336663074; + states[4] = 286335249; + states[5] = 286331237; + states[6] = 286335249; + states[7] = 18944273; + charset = "ISO-2022-CN"; + stFactor = 9; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsISO2022JPVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsISO2022JPVerifier() { + cclass = new int[32]; + cclass[0] = 2; + cclass[1] = 570425344; + cclass[2] = 0; + cclass[3] = 4096; + cclass[4] = 458752; + cclass[5] = 3; + cclass[6] = 0; + cclass[7] = 0; + cclass[8] = 1030; + cclass[9] = 1280; + cclass[10] = 0; + cclass[11] = 0; + cclass[12] = 0; + cclass[13] = 0; + cclass[14] = 0; + cclass[15] = 0; + cclass[16] = 572662306; + cclass[17] = 572662306; + cclass[18] = 572662306; + cclass[19] = 572662306; + cclass[20] = 572662306; + cclass[21] = 572662306; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 572662306; + cclass[25] = 572662306; + cclass[26] = 572662306; + cclass[27] = 572662306; + cclass[28] = 572662306; + cclass[29] = 572662306; + cclass[30] = 572662306; + cclass[31] = 572662306; + states = new int[6]; + states[0] = 304; + states[1] = 286331153; + states[2] = 572662306; + states[3] = 1091653905; + states[4] = 303173905; + states[5] = 287445265; + charset = "ISO-2022-JP"; + stFactor = 8; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsISO2022KRVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsISO2022KRVerifier() { + cclass = new int[32]; + cclass[0] = 2; + cclass[1] = 0; + cclass[2] = 0; + cclass[3] = 4096; + cclass[4] = 196608; + cclass[5] = 64; + cclass[6] = 0; + cclass[7] = 0; + cclass[8] = 20480; + cclass[9] = 0; + cclass[10] = 0; + cclass[11] = 0; + cclass[12] = 0; + cclass[13] = 0; + cclass[14] = 0; + cclass[15] = 0; + cclass[16] = 572662306; + cclass[17] = 572662306; + cclass[18] = 572662306; + cclass[19] = 572662306; + cclass[20] = 572662306; + cclass[21] = 572662306; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 572662306; + cclass[25] = 572662306; + cclass[26] = 572662306; + cclass[27] = 572662306; + cclass[28] = 572662306; + cclass[29] = 572662306; + cclass[30] = 572662306; + cclass[31] = 572662306; + states = new int[5]; + states[0] = 285212976; + states[1] = 572657937; + states[2] = 289476898; + states[3] = 286593297; + states[4] = 8465; + charset = "ISO-2022-KR"; + stFactor = 6; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsUCS2BEVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsUCS2BEVerifier() { + cclass = new int[32]; + cclass[0] = 0; + cclass[1] = 2097408; + cclass[2] = 0; + cclass[3] = 12288; + cclass[4] = 0; + cclass[5] = 3355440; + cclass[6] = 0; + cclass[7] = 0; + cclass[8] = 0; + cclass[9] = 0; + cclass[10] = 0; + cclass[11] = 0; + cclass[12] = 0; + cclass[13] = 0; + cclass[14] = 0; + cclass[15] = 0; + cclass[16] = 0; + cclass[17] = 0; + cclass[18] = 0; + cclass[19] = 0; + cclass[20] = 0; + cclass[21] = 0; + cclass[22] = 0; + cclass[23] = 0; + cclass[24] = 0; + cclass[25] = 0; + cclass[26] = 0; + cclass[27] = 0; + cclass[28] = 0; + cclass[29] = 0; + cclass[30] = 0; + cclass[31] = 1409286144; + states = new int[7]; + states[0] = 288626549; + states[1] = 572657937; + states[2] = 291923490; + states[3] = 1713792614; + states[4] = 393569894; + states[5] = 1717659269; + states[6] = 1140326; + charset = "UTF-16BE"; + stFactor = 6; + } + + public boolean isUCS2() { + return true; + } + } + + /** + * + */ + public static class nsUCS2LEVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsUCS2LEVerifier() { + cclass = new int[32]; + cclass[0] = 0; + cclass[1] = 2097408; + cclass[2] = 0; + cclass[3] = 12288; + cclass[4] = 0; + cclass[5] = 3355440; + cclass[6] = 0; + cclass[7] = 0; + cclass[8] = 0; + cclass[9] = 0; + cclass[10] = 0; + cclass[11] = 0; + cclass[12] = 0; + cclass[13] = 0; + cclass[14] = 0; + cclass[15] = 0; + cclass[16] = 0; + cclass[17] = 0; + cclass[18] = 0; + cclass[19] = 0; + cclass[20] = 0; + cclass[21] = 0; + cclass[22] = 0; + cclass[23] = 0; + cclass[24] = 0; + cclass[25] = 0; + cclass[26] = 0; + cclass[27] = 0; + cclass[28] = 0; + cclass[29] = 0; + cclass[30] = 0; + cclass[31] = 1409286144; + states = new int[7]; + states[0] = 288647014; + states[1] = 572657937; + states[2] = 303387938; + states[3] = 1712657749; + states[4] = 357927015; + states[5] = 1427182933; + states[6] = 1381717; + charset = "UTF-16LE"; + stFactor = 6; + } + + public boolean isUCS2() { + return true; + } + } + + /** + * + */ + public static class nsCP1252Verifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsCP1252Verifier() { + cclass = new int[32]; + cclass[0] = 572662305; + cclass[1] = 2236962; + cclass[2] = 572662306; + cclass[3] = 572654114; + cclass[4] = 572662306; + cclass[5] = 572662306; + cclass[6] = 572662306; + cclass[7] = 572662306; + cclass[8] = 572662306; + cclass[9] = 572662306; + cclass[10] = 572662306; + cclass[11] = 572662306; + cclass[12] = 572662306; + cclass[13] = 572662306; + cclass[14] = 572662306; + cclass[15] = 572662306; + cclass[16] = 572662274; + cclass[17] = 16851234; + cclass[18] = 572662304; + cclass[19] = 285286690; + cclass[20] = 572662306; + cclass[21] = 572662306; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 286331153; + cclass[25] = 286331153; + cclass[26] = 554766609; + cclass[27] = 286331153; + cclass[28] = 286331153; + cclass[29] = 286331153; + cclass[30] = 554766609; + cclass[31] = 286331153; + states = new int[3]; + states[0] = 571543601; + states[1] = 340853778; + states[2] = 65; + charset = "windows-1252"; + stFactor = 3; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsHZVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsHZVerifier() { + cclass = new int[32]; + cclass[0] = 1; + cclass[1] = 0; + cclass[2] = 0; + cclass[3] = 4096; + cclass[4] = 0; + cclass[5] = 0; + cclass[6] = 0; + cclass[7] = 0; + cclass[8] = 0; + cclass[9] = 0; + cclass[10] = 0; + cclass[11] = 0; + cclass[12] = 0; + cclass[13] = 0; + cclass[14] = 0; + cclass[15] = 38813696; + cclass[16] = 286331153; + cclass[17] = 286331153; + cclass[18] = 286331153; + cclass[19] = 286331153; + cclass[20] = 286331153; + cclass[21] = 286331153; + cclass[22] = 286331153; + cclass[23] = 286331153; + cclass[24] = 286331153; + cclass[25] = 286331153; + cclass[26] = 286331153; + cclass[27] = 286331153; + cclass[28] = 286331153; + cclass[29] = 286331153; + cclass[30] = 286331153; + cclass[31] = 286331153; + states = new int[6]; + states[0] = 285213456; + states[1] = 572657937; + states[2] = 335548706; + states[3] = 341120533; + states[4] = 336872468; + states[5] = 36; + charset = "HZ-GB-2312"; + stFactor = 6; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsSJISVerifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsSJISVerifier() { + cclass = new int[32]; + cclass[0] = 286331152; + cclass[1] = 1118481; + cclass[2] = 286331153; + cclass[3] = 286327057; + cclass[4] = 286331153; + cclass[5] = 286331153; + cclass[6] = 286331153; + cclass[7] = 286331153; + cclass[8] = 572662306; + cclass[9] = 572662306; + cclass[10] = 572662306; + cclass[11] = 572662306; + cclass[12] = 572662306; + cclass[13] = 572662306; + cclass[14] = 572662306; + cclass[15] = 304226850; + cclass[16] = 858993459; + cclass[17] = 858993459; + cclass[18] = 858993459; + cclass[19] = 858993459; + cclass[20] = 572662308; + cclass[21] = 572662306; + cclass[22] = 572662306; + cclass[23] = 572662306; + cclass[24] = 572662306; + cclass[25] = 572662306; + cclass[26] = 572662306; + cclass[27] = 572662306; + cclass[28] = 858993459; + cclass[29] = 1145393971; + cclass[30] = 1145324612; + cclass[31] = 279620; + states = new int[3]; + states[0] = 286339073; + states[1] = 572657937; + states[2] = 4386; + charset = "Shift_JIS"; + stFactor = 6; + } + + public boolean isUCS2() { + return false; + } + } + + /** + * + */ + public static class nsUTF8Verifier extends nsVerifier { + static int[] cclass; + static int[] states; + static int stFactor; + static String charset; + + public int[] cclass() { + return cclass; + } + + public int[] states() { + return states; + } + + public int stFactor() { + return stFactor; + } + + public String charset() { + return charset; + } + + public nsUTF8Verifier() { + cclass = new int[32]; + cclass[0] = 286331153; + cclass[1] = 1118481; + cclass[2] = 286331153; + cclass[3] = 286327057; + cclass[4] = 286331153; + cclass[5] = 286331153; + cclass[6] = 286331153; + cclass[7] = 286331153; + cclass[8] = 286331153; + cclass[9] = 286331153; + cclass[10] = 286331153; + cclass[11] = 286331153; + cclass[12] = 286331153; + cclass[13] = 286331153; + cclass[14] = 286331153; + cclass[15] = 286331153; + cclass[16] = 858989090; + cclass[17] = 1145324612; + cclass[18] = 1145324612; + cclass[19] = 1145324612; + cclass[20] = 1431655765; + cclass[21] = 1431655765; + cclass[22] = 1431655765; + cclass[23] = 1431655765; + cclass[24] = 1717986816; + cclass[25] = 1717986918; + cclass[26] = 1717986918; + cclass[27] = 1717986918; + cclass[28] = -2004318073; + cclass[29] = -2003269496; + cclass[30] = -1145324614; + cclass[31] = 16702940; + states = new int[26]; + states[0] = -1408167679; + states[1] = 878082233; + states[2] = 286331153; + states[3] = 286331153; + states[4] = 572662306; + states[5] = 572662306; + states[6] = 290805009; + states[7] = 286331153; + states[8] = 290803985; + states[9] = 286331153; + states[10] = 293041937; + states[11] = 286331153; + states[12] = 293015825; + states[13] = 286331153; + states[14] = 295278865; + states[15] = 286331153; + states[16] = 294719761; + states[17] = 286331153; + states[18] = 298634257; + states[19] = 286331153; + states[20] = 297865489; + states[21] = 286331153; + states[22] = 287099921; + states[23] = 286331153; + states[24] = 285212689; + states[25] = 286331153; + charset = "UTF-8"; + stFactor = 16; + } + + public boolean isUCS2() { + return false; + } + } + +} diff --git a/src/main/java/com/eleadmin/common/core/utils/JSONUtil.java b/src/main/java/com/eleadmin/common/core/utils/JSONUtil.java new file mode 100644 index 0000000..7fa3f0f --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/utils/JSONUtil.java @@ -0,0 +1,69 @@ +package com.eleadmin.common.core.utils; + +import cn.hutool.core.util.StrUtil; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +/** + * JSON解析工具类 + * + * @author EleAdmin + * @since 2017-06-10 10:10:39 + */ +public class JSONUtil { + private static final ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter(); + + /** + * 对象转json字符串 + * + * @param value 对象 + * @return String + */ + public static String toJSONString(Object value) { + return toJSONString(value, false); + } + + /** + * 对象转json字符串 + * + * @param value 对象 + * @param pretty 是否格式化输出 + * @return String + */ + public static String toJSONString(Object value, boolean pretty) { + if (value != null) { + if (value instanceof String) { + return (String) value; + } + try { + if (pretty) { + return objectWriter.writeValueAsString(value); + } + return objectMapper.writeValueAsString(value); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * json字符串转对象 + * + * @param json String + * @param clazz Class + * @return T + */ + public static T parseObject(String json, Class clazz) { + if (StrUtil.isNotBlank(json) && clazz != null) { + try { + return objectMapper.readValue(json, clazz); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + +} diff --git a/src/main/java/com/eleadmin/common/core/utils/OpenOfficeUtil.java b/src/main/java/com/eleadmin/common/core/utils/OpenOfficeUtil.java new file mode 100644 index 0000000..f54ebb5 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/utils/OpenOfficeUtil.java @@ -0,0 +1,124 @@ +package com.eleadmin.common.core.utils; + +import cn.hutool.core.util.StrUtil; +import org.artofsolving.jodconverter.OfficeDocumentConverter; +import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; +import org.artofsolving.jodconverter.office.OfficeManager; + +import java.io.File; +import java.util.Arrays; +import java.util.Base64; + +/** + * OpenOfficeUtil + * + * @author EleAdmin + * @since 2018-12-14 08:38:19 + */ +public class OpenOfficeUtil { + // 支持转换pdf的文件后缀列表 + private static final String[] CAN_CONVERTER_FILES = new String[]{ + "doc", "docx", "xls", "xlsx", "ppt", "pptx" + }; + + /** + * 文件转pdf + * + * @param filePath 源文件路径 + * @param outDir 输出目录 + * @param officeHome OpenOffice安装路径 + * @return File + */ + public static File converterToPDF(String filePath, String outDir, String officeHome) { + return converterToPDF(filePath, outDir, officeHome, true); + } + + /** + * 文件转pdf + * + * @param filePath 源文件路径 + * @param outDir 输出目录 + * @param officeHome OpenOffice安装路径 + * @param cache 是否使用上次转换过的文件 + * @return File + */ + public static File converterToPDF(String filePath, String outDir, String officeHome, boolean cache) { + if (StrUtil.isBlank(filePath)) { + return null; + } + File srcFile = new File(filePath); + if (!srcFile.exists()) { + return null; + } + // 是否转换过 + String outPath = Base64.getEncoder().encodeToString(filePath.getBytes()) + .replace("/", "-").replace("+", "-"); + File outFile = new File(outDir, outPath + ".pdf"); + if (cache && outFile.exists()) { + return outFile; + } + // 转换 + OfficeManager officeManager = null; + try { + officeManager = getOfficeManager(officeHome); + OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); + return converterFile(srcFile, outFile, converter); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (officeManager != null) { + officeManager.stop(); + } + } + return null; + } + + /** + * 转换文件 + * + * @param inFile 源文件 + * @param outFile 输出文件 + * @param converter OfficeDocumentConverter + * @return File + */ + public static File converterFile(File inFile, File outFile, OfficeDocumentConverter converter) { + if (!outFile.getParentFile().exists()) { + if (!outFile.getParentFile().mkdirs()) { + return outFile; + } + } + converter.convert(inFile, outFile); + return outFile; + } + + /** + * 判断文件后缀是否可以转换pdf + * + * @param path 文件路径 + * @return boolean + */ + public static boolean canConverter(String path) { + try { + String suffix = path.substring(path.lastIndexOf(".") + 1); + return Arrays.asList(CAN_CONVERTER_FILES).contains(suffix); + } catch (Exception e) { + return false; + } + } + + /** + * 连接并启动OpenOffice + * + * @param officeHome OpenOffice安装路径 + * @return OfficeManager + */ + public static OfficeManager getOfficeManager(String officeHome) { + if (officeHome == null || officeHome.trim().isEmpty()) return null; + DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration(); + config.setOfficeHome(officeHome); // 设置OpenOffice安装目录 + OfficeManager officeManager = config.buildOfficeManager(); + officeManager.start(); // 启动OpenOffice服务 + return officeManager; + } + +} diff --git a/src/main/java/com/eleadmin/common/core/web/ApiResult.java b/src/main/java/com/eleadmin/common/core/web/ApiResult.java new file mode 100644 index 0000000..f95a55d --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/web/ApiResult.java @@ -0,0 +1,88 @@ +package com.eleadmin.common.core.web; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * 返回结果 + * + * @author EleAdmin + * @since 2017-06-10 10:10:50 + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ApiResult implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码") + private Integer code; + + @ApiModelProperty(value = "状态信息") + private String message; + + @ApiModelProperty(value = "返回数据") + private T data; + + @ApiModelProperty(value = "错误信息") + private String error; + + public ApiResult() { + } + + public ApiResult(Integer code) { + this(code, null); + } + + public ApiResult(Integer code, String message) { + this(code, message, null); + } + + public ApiResult(Integer code, String message, T data) { + this(code, message, data, null); + } + + public ApiResult(Integer code, String message, T data, String error) { + setCode(code); + setMessage(message); + setData(data); + setError(error); + } + + public Integer getCode() { + return this.code; + } + + public ApiResult setCode(Integer code) { + this.code = code; + return this; + } + + public String getMessage() { + return this.message; + } + + public ApiResult setMessage(String message) { + this.message = message; + return this; + } + + public T getData() { + return this.data; + } + + public ApiResult setData(T data) { + this.data = data; + return this; + } + + public String getError() { + return this.error; + } + + public ApiResult setError(String error) { + this.error = error; + return this; + } + +} diff --git a/src/main/java/com/eleadmin/common/core/web/BaseController.java b/src/main/java/com/eleadmin/common/core/web/BaseController.java new file mode 100644 index 0000000..ef0da8d --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/web/BaseController.java @@ -0,0 +1,160 @@ +package com.eleadmin.common.core.web; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.system.entity.User; +import org.springframework.beans.propertyeditors.StringTrimmerEditor; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; + +import java.util.List; + +/** + * Controller基类 + * + * @author EleAdmin + * @since 2017-06-10 10:10:19 + */ +public class BaseController { + + /** + * 获取当前登录的user + * + * @return User + */ + public User getLoginUser() { + try { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null) { + Object object = authentication.getPrincipal(); + if (object instanceof User) { + return (User) object; + } + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + return null; + } + + /** + * 获取当前登录的userId + * + * @return userId + */ + public Integer getLoginUserId() { + User loginUser = getLoginUser(); + return loginUser == null ? null : loginUser.getUserId(); + } + + /** + * 返回成功 + * + * @return ApiResult + */ + public ApiResult success() { + return new ApiResult<>(Constants.RESULT_OK_CODE, Constants.RESULT_OK_MSG); + } + + /** + * 返回成功 + * + * @param message 状态信息 + * @return ApiResult + */ + public ApiResult success(String message) { + return success().setMessage(message); + } + + /** + * 返回成功 + * + * @param data 返回数据 + * @return ApiResult + */ + public ApiResult success(T data) { + return new ApiResult<>(Constants.RESULT_OK_CODE, Constants.RESULT_OK_MSG, data); + } + + /** + * 返回成功 + * + * @param message 状态信息 + * @return ApiResult + */ + public ApiResult success(String message, T data) { + return success(data).setMessage(message); + } + + /** + * 返回分页查询数据 + * + * @param list 当前页数据 + * @param count 总数量 + * @return ApiResult + */ + public ApiResult> success(List list, Long count) { + return success(new PageResult<>(list, count)); + } + + /** + * 返回分页查询数据 + * + * @param iPage IPage + * @return ApiResult + */ + public ApiResult> success(IPage iPage) { + return success(iPage.getRecords(), iPage.getTotal()); + } + + /** + * 返回失败 + * + * @return ApiResult + */ + public ApiResult fail() { + return new ApiResult<>(Constants.RESULT_ERROR_CODE, Constants.RESULT_ERROR_MSG); + } + + /** + * 返回失败 + * + * @param message 状态信息 + * @return ApiResult + */ + public ApiResult fail(String message) { + return fail().setMessage(message); + } + + /** + * 返回失败 + * + * @param data 返回数据 + * @return ApiResult + */ + public ApiResult fail(T data) { + return fail(Constants.RESULT_ERROR_MSG, data); + } + + /** + * 返回失败 + * + * @param message 状态信息 + * @param data 返回数据 + * @return ApiResult + */ + public ApiResult fail(String message, T data) { + return new ApiResult<>(Constants.RESULT_ERROR_CODE, message, data); + } + + /** + * 请求参数的空字符串转为null + */ + @InitBinder + public void initBinder(WebDataBinder binder) { + binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/web/BaseParam.java b/src/main/java/com/eleadmin/common/core/web/BaseParam.java new file mode 100644 index 0000000..03f3156 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/web/BaseParam.java @@ -0,0 +1,59 @@ +package com.eleadmin.common.core.web; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.utils.CommonUtil; +import lombok.Data; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +/** + * 查询参数基本字段 + * + * @author EleAdmin + * @since 2021-08-26 22:14:43 + */ +@Data +public class BaseParam implements Serializable { + private static final long serialVersionUID = 1L; + + @TableField(exist = false) + @ApiModelProperty("分页查询页码") + private Long page; + + @TableField(exist = false) + @ApiModelProperty("分页查询每页数量") + private Long limit; + + @TableField(exist = false) + @ApiModelProperty(value = "排序字段", notes = "排序字段或sql, 如果是sql则order字段无用, 如: `id asc, name desc`") + private String sort; + + @TableField(exist = false) + @ApiModelProperty(value = "排序方式", notes = "sort是字段名称时对应的排序方式, asc升序, desc降序") + private String order; + + @QueryField(value = "create_time", type = QueryType.GE) + @TableField(exist = false) + @ApiModelProperty("创建时间起始值") + private String createTimeStart; + + @QueryField(value = "create_time", type = QueryType.LE) + @TableField(exist = false) + @ApiModelProperty("创建时间结束值") + private String createTimeEnd; + + /** + * 获取集合中的第一条数据 + * + * @param records 集合 + * @return 第一条数据 + */ + public T getOne(List records) { + return CommonUtil.listGetOne(records); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/web/BatchParam.java b/src/main/java/com/eleadmin/common/core/web/BatchParam.java new file mode 100644 index 0000000..ed9e83e --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/web/BatchParam.java @@ -0,0 +1,57 @@ +package com.eleadmin.common.core.web; + +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.baomidou.mybatisplus.extension.service.IService; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 批量修改通用参数 + * + * @author EleAdmin + * @since 2020-03-13 00:11:06 + */ +@Data +public class BatchParam implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "需要修改的数据id集合") + private List ids; + + @ApiModelProperty(value = "需要修改的字段和值") + private T data; + + /** + * 通用批量修改方法 + * + * @param service IService + * @param idField id字段名称 + * @return boolean + */ + public boolean update(IService service, String idField) { + if (this.data == null) { + return false; + } + return service.update(this.data, new UpdateWrapper().in(idField, this.ids)); + } + + /** + * 通用批量修改方法 + * + * @param service IService + * @param idField id字段名称 + * @return boolean + */ + public boolean update(IService service, SFunction idField) { + if (this.data == null) { + return false; + } + return service.update(this.data, new LambdaUpdateWrapper().in(idField, this.ids)); + } + +} diff --git a/src/main/java/com/eleadmin/common/core/web/ExistenceParam.java b/src/main/java/com/eleadmin/common/core/web/ExistenceParam.java new file mode 100644 index 0000000..a4f9586 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/web/ExistenceParam.java @@ -0,0 +1,96 @@ +package com.eleadmin.common.core.web; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import com.baomidou.mybatisplus.extension.service.IService; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 检查是否存在通用参数 + * + * @author EleAdmin + * @since 2021-09-07 22:24:39 + */ +@Data +public class ExistenceParam implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "检查的字段") + private String field; + + @ApiModelProperty(value = "字段的值") + private String value; + + @ApiModelProperty(value = "修改时的主键") + private Integer id; + + /** + * 检查是否存在 + * + * @param service IService + * @param idField 修改时的主键字段 + * @return boolean + */ + public boolean isExistence(IService service, String idField) { + return isExistence(service, idField, true); + } + + /** + * 检查是否存在 + * + * @param service IService + * @param idField 修改时的主键字段 + * @param isToUnderlineCase 是否需要把field转为下划线格式 + * @return boolean + */ + public boolean isExistence(IService service, String idField, boolean isToUnderlineCase) { + if (StrUtil.hasBlank(this.field, this.value)) { + return false; + } + String fieldName = isToUnderlineCase ? StrUtil.toUnderlineCase(field) : field; + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(fieldName, value); + if (id != null) { + wrapper.ne(idField, id); + } + return service.count(wrapper) > 0; + } + + /** + * 检查是否存在 + * + * @param service IService + * @param idField 修改时的主键字段 + * @return boolean + */ + public boolean isExistence(IService service, SFunction idField) { + return isExistence(service, idField, true); + } + + /** + * 检查是否存在 + * + * @param service IService + * @param idField 修改时的主键字段 + * @param isToUnderlineCase 是否需要把field转为下划线格式 + * @return boolean + */ + public boolean isExistence(IService service, SFunction idField, boolean isToUnderlineCase) { + if (StrUtil.hasBlank(this.field, this.value)) { + return false; + } + String fieldName = isToUnderlineCase ? StrUtil.toUnderlineCase(field) : field; + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.apply(fieldName + " = {0}", value); + if (id != null) { + wrapper.ne(idField, id); + } + return service.count(wrapper) > 0; + } + +} diff --git a/src/main/java/com/eleadmin/common/core/web/PageParam.java b/src/main/java/com/eleadmin/common/core/web/PageParam.java new file mode 100644 index 0000000..90e1270 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/web/PageParam.java @@ -0,0 +1,343 @@ +package com.eleadmin.common.core.web; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.eleadmin.common.core.Constants; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.utils.CommonUtil; + +import java.lang.reflect.Field; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 分页、排序、搜索参数封装 + * + * @author EleAdmin + * @since 2019-04-26 10:34:35 + */ +public class PageParam extends Page { + private static final long serialVersionUID = 1L; + + /** + * 租户id字段名称 + */ + private static final String TENANT_ID_FIELD = "tenantId"; + + /** + * 查询条件 + */ + private final U where; + + /** + * 是否把字段名称驼峰转下划线 + */ + private final boolean isToUnderlineCase; + + public PageParam() { + this(null); + } + + public PageParam(U where) { + this(where, true); + } + + public PageParam(U where, boolean isToUnderlineCase) { + super(); + this.where = where; + this.isToUnderlineCase = isToUnderlineCase; + if (where != null) { + // 获取分页页码 + if (where.getPage() != null) { + setCurrent(where.getPage()); + } + // 获取分页每页数量 + if (where.getLimit() != null) { + setSize(where.getLimit()); + } + // 获取排序方式 + if (where.getSort() != null) { + if (sortIsSQL(where.getSort())) { + setOrders(parseOrderSQL(where.getSort())); + } else { + List orderItems = new ArrayList<>(); + String column = this.isToUnderlineCase ? StrUtil.toUnderlineCase(where.getSort()) : where.getSort(); + boolean asc = !Constants.ORDER_DESC_VALUE.equals(where.getOrder()); + orderItems.add(new OrderItem(column, asc)); + setOrders(orderItems); + } + } + } + } + + /** + * 排序字段是否是sql + */ + private boolean sortIsSQL(String sort) { + return sort != null && (sort.contains(",") || sort.trim().contains(" ")); + } + + /** + * 解析排序sql + */ + private List parseOrderSQL(String orderSQL) { + List orders = new ArrayList<>(); + if (StrUtil.isNotBlank(orderSQL)) { + for (String item : orderSQL.split(",")) { + String[] temp = item.trim().split(" "); + if (!temp[0].isEmpty()) { + String column = this.isToUnderlineCase ? StrUtil.toUnderlineCase(temp[0]) : temp[0]; + boolean asc = temp.length == 1 || !temp[temp.length - 1].equals(Constants.ORDER_DESC_VALUE); + orders.add(new OrderItem(column, asc)); + } + } + } + return orders; + } + + /** + * 设置默认排序方式 + * + * @param orderItems 排序方式 + * @return PageParam + */ + public PageParam setDefaultOrder(List orderItems) { + if (orders() == null || orders().size() == 0) { + setOrders(orderItems); + } + return this; + } + + /** + * 设置默认排序方式 + * + * @param orderSQL 排序方式 + * @return PageParam + */ + public PageParam setDefaultOrder(String orderSQL) { + setDefaultOrder(parseOrderSQL(orderSQL)); + return this; + } + + /** + * 获取查询条件 + * + * @param excludes 不包含的字段 + * @return QueryWrapper + */ + public QueryWrapper getWrapper(String... excludes) { + return buildWrapper(null, Arrays.asList(excludes)); + } + + /** + * 获取查询条件 + * + * @param columns 只包含的字段 + * @return QueryWrapper + */ + public QueryWrapper getWrapperWith(String... columns) { + return buildWrapper(Arrays.asList(columns), null); + } + + /** + * 构建QueryWrapper + * + * @param columns 包含的字段 + * @param excludes 排除的字段 + * @return QueryWrapper + */ + private QueryWrapper buildWrapper(List columns, List excludes) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + Map map = BeanUtil.beanToMap(where, false, true); + for (String fieldName : map.keySet()) { + Object fieldValue = map.get(fieldName); + Field field = ReflectUtil.getField(where.getClass(), fieldName); + + // 过滤不包含的字段 + if (columns != null && !columns.contains(fieldName)) { + continue; + } + + // 过滤排除的字段 + if (excludes != null && excludes.contains(fieldName)) { + continue; + } + + // 过滤逻辑删除字段 + if (field.getAnnotation(TableLogic.class) != null) { + continue; + } + + // 过滤租户id字段 + if (fieldName.equals(TENANT_ID_FIELD)) { + continue; + } + + // 获取注解指定的查询字段及查询方式 + QueryType queryType = QueryType.LIKE; + QueryField queryField = field.getAnnotation(QueryField.class); + if (queryField != null) { + if (StrUtil.isNotEmpty(queryField.value())) { + fieldName = queryField.value(); + } + if (queryField.type() != null) { + queryType = queryField.type(); + } + } else { + // 过滤非本表的字段 + TableField tableField = field.getAnnotation(TableField.class); + if (tableField != null && !tableField.exist()) { + continue; + } + } + + // 字段名驼峰转下划线 + if (this.isToUnderlineCase) { + fieldName = StrUtil.toUnderlineCase(fieldName); + } + + // + switch (queryType) { + case EQ: + queryWrapper.eq(fieldName, fieldValue); + break; + case NE: + queryWrapper.ne(fieldName, fieldValue); + break; + case GT: + queryWrapper.gt(fieldName, fieldValue); + break; + case GE: + queryWrapper.ge(fieldName, fieldValue); + break; + case LT: + queryWrapper.lt(fieldName, fieldValue); + break; + case LE: + queryWrapper.le(fieldName, fieldValue); + break; + case LIKE: + queryWrapper.like(fieldName, fieldValue); + break; + case NOT_LIKE: + queryWrapper.notLike(fieldName, fieldValue); + break; + case LIKE_LEFT: + queryWrapper.likeLeft(fieldName, fieldValue); + break; + case LIKE_RIGHT: + queryWrapper.likeRight(fieldName, fieldValue); + break; + case IS_NULL: + queryWrapper.isNull(fieldName); + break; + case IS_NOT_NULL: + queryWrapper.isNotNull(fieldName); + break; + case IN: + queryWrapper.in(fieldName, fieldValue); + break; + case NOT_IN: + queryWrapper.notIn(fieldName, fieldValue); + break; + case IN_STR: + if (fieldValue instanceof String) { + queryWrapper.in(fieldName, Arrays.asList(((String) fieldValue).split(","))); + } + break; + case NOT_IN_STR: + if (fieldValue instanceof String) { + queryWrapper.notIn(fieldName, Arrays.asList(((String) fieldValue).split(","))); + } + break; + } + } + return queryWrapper; + } + + /** + * 获取包含排序的查询条件 + * + * @return 包含排序的QueryWrapper + */ + public QueryWrapper getOrderWrapper() { + return getOrderWrapper(getWrapper()); + } + + /** + * 获取包含排序的查询条件 + * + * @param queryWrapper 不含排序的QueryWrapper + * @return 包含排序的QueryWrapper + */ + public QueryWrapper getOrderWrapper(QueryWrapper queryWrapper) { + if (queryWrapper == null) { + queryWrapper = new QueryWrapper<>(); + } + for (OrderItem orderItem : orders()) { + if (orderItem.isAsc()) { + queryWrapper.orderByAsc(orderItem.getColumn()); + } else { + queryWrapper.orderByDesc(orderItem.getColumn()); + } + } + return queryWrapper; + } + + /** + * 获取集合中的第一条数据 + * + * @param records 集合 + * @return 第一条数据 + */ + public T getOne(List records) { + return CommonUtil.listGetOne(records); + } + + /** + * 代码排序集合 + * + * @param records 集合 + * @return 排序后的集合 + */ + public List sortRecords(List records) { + List orderItems = orders(); + if (records == null || records.size() < 2 || orderItems == null || orderItems.size() == 0) { + return records; + } + Comparator comparator = null; + for (OrderItem item : orderItems) { + if (item.getColumn() == null) { + continue; + } + String field = this.isToUnderlineCase ? StrUtil.toCamelCase(item.getColumn()) : item.getColumn(); + Function keyExtractor = t -> ReflectUtil.getFieldValue(t, field); + if (comparator == null) { + if (item.isAsc()) { + comparator = Comparator.comparing(keyExtractor); + } else { + comparator = Comparator.comparing(keyExtractor, Comparator.reverseOrder()); + } + } else { + if (item.isAsc()) { + comparator.thenComparing(keyExtractor); + } else { + comparator.thenComparing(keyExtractor, Comparator.reverseOrder()); + } + } + } + if (comparator != null) { + return records.stream().sorted(comparator).collect(Collectors.toList()); + } + return records; + } + +} diff --git a/src/main/java/com/eleadmin/common/core/web/PageResult.java b/src/main/java/com/eleadmin/common/core/web/PageResult.java new file mode 100644 index 0000000..35f7b91 --- /dev/null +++ b/src/main/java/com/eleadmin/common/core/web/PageResult.java @@ -0,0 +1,51 @@ +package com.eleadmin.common.core.web; + +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +/** + * 分页查询返回结果 + * + * @author EleAdmin + * @since 2017-06-10 10:10:02 + */ +public class PageResult implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "当前页数据") + private List list; + + @ApiModelProperty(value = "总数量") + private Long count; + + public PageResult() { + } + + public PageResult(List list) { + this(list, null); + } + + public PageResult(List list, Long count) { + setList(list); + setCount(count); + } + + public List getList() { + return this.list; + } + + public void setList(List list) { + this.list = list; + } + + public Long getCount() { + return this.count; + } + + public void setCount(Long count) { + this.count = count; + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/DictionaryController.java b/src/main/java/com/eleadmin/common/system/controller/DictionaryController.java new file mode 100644 index 0000000..08aede6 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/DictionaryController.java @@ -0,0 +1,152 @@ +package com.eleadmin.common.system.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.utils.CommonUtil; +import com.eleadmin.common.core.web.*; +import com.eleadmin.common.system.entity.Dictionary; +import com.eleadmin.common.system.param.DictionaryParam; +import com.eleadmin.common.system.service.DictionaryService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 字典控制器 + * + * @author EleAdmin + * @since 2020-03-14 11:29:03 + */ +@Api(tags = "字典管理") +@RestController +@RequestMapping("/api/system/dictionary") +public class DictionaryController extends BaseController { + @Resource + private DictionaryService dictionaryService; + + @PreAuthorize("hasAuthority('sys:dict:list')") + @OperationLog + @ApiOperation("分页查询字典") + @GetMapping("/page") + public ApiResult> page(DictionaryParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return success(dictionaryService.page(page, page.getWrapper())); + } + + @PreAuthorize("hasAuthority('sys:dict:list')") + @OperationLog + @ApiOperation("查询全部字典") + @GetMapping() + public ApiResult> list(DictionaryParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return success(dictionaryService.list(page.getOrderWrapper())); + } + + @PreAuthorize("hasAuthority('sys:dict:list')") + @OperationLog + @ApiOperation("根据id查询字典") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(dictionaryService.getById(id)); + } + + @PreAuthorize("hasAuthority('sys:dict:save')") + @ApiOperation("添加字典") + @PostMapping() + public ApiResult add(@RequestBody Dictionary dictionary) { + if (dictionaryService.count(new LambdaQueryWrapper() + .eq(Dictionary::getDictCode, dictionary.getDictCode())) > 0) { + return fail("字典标识已存在"); + } + if (dictionaryService.count(new LambdaQueryWrapper() + .eq(Dictionary::getDictName, dictionary.getDictName())) > 0) { + return fail("字典名称已存在"); + } + if (dictionaryService.save(dictionary)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:dict:update')") + @OperationLog + @ApiOperation("修改字典") + @PutMapping() + public ApiResult update(@RequestBody Dictionary dictionary) { + if (dictionaryService.count(new LambdaQueryWrapper() + .eq(Dictionary::getDictCode, dictionary.getDictCode()) + .ne(Dictionary::getDictId, dictionary.getDictId())) > 0) { + return fail("字典标识已存在"); + } + if (dictionaryService.count(new LambdaQueryWrapper() + .eq(Dictionary::getDictName, dictionary.getDictName()) + .ne(Dictionary::getDictId, dictionary.getDictId())) > 0) { + return fail("字典名称已存在"); + } + if (dictionaryService.updateById(dictionary)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:dict:remove')") + @OperationLog + @ApiOperation("删除字典") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (dictionaryService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:dict:save')") + @OperationLog + @ApiOperation("批量添加字典") + @PostMapping("/batch") + public ApiResult> saveBatch(@RequestBody List list) { + if (CommonUtil.checkRepeat(list, Dictionary::getDictCode)) { + return fail("字典标识不能重复", null); + } + if (CommonUtil.checkRepeat(list, Dictionary::getDictName)) { + return fail("字典名称不能重复", null); + } + List codeExists = dictionaryService.list(new LambdaQueryWrapper() + .in(Dictionary::getDictCode, list.stream().map(Dictionary::getDictCode) + .collect(Collectors.toList()))); + if (codeExists.size() > 0) { + return fail("字典标识已存在", codeExists.stream().map(Dictionary::getDictCode) + .collect(Collectors.toList())).setCode(2); + } + List nameExists = dictionaryService.list(new LambdaQueryWrapper() + .in(Dictionary::getDictName, list.stream().map(Dictionary::getDictCode) + .collect(Collectors.toList()))); + if (nameExists.size() > 0) { + return fail("字典名称已存在", nameExists.stream().map(Dictionary::getDictName) + .collect(Collectors.toList())).setCode(3); + } + if (dictionaryService.saveBatch(list)) { + return success("添加成功", null); + } + return fail("添加失败", null); + } + + @PreAuthorize("hasAuthority('sys:dict:remove')") + @OperationLog + @ApiOperation("批量删除字典") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (dictionaryService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/DictionaryDataController.java b/src/main/java/com/eleadmin/common/system/controller/DictionaryDataController.java new file mode 100644 index 0000000..ad4e2a6 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/DictionaryDataController.java @@ -0,0 +1,131 @@ +package com.eleadmin.common.system.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.*; +import com.eleadmin.common.system.entity.DictionaryData; +import com.eleadmin.common.system.param.DictionaryDataParam; +import com.eleadmin.common.system.service.DictionaryDataService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 字典数据控制器 + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +@Api(tags = "字典数据管理") +@RestController +@RequestMapping("/api/system/dictionary-data") +public class DictionaryDataController extends BaseController { + @Resource + private DictionaryDataService dictionaryDataService; + + @PreAuthorize("hasAuthority('sys:dict:list')") + @OperationLog + @ApiOperation("分页查询字典数据") + @GetMapping("/page") + public ApiResult> page(DictionaryDataParam param) { + return success(dictionaryDataService.pageRel(param)); + } + + @PreAuthorize("hasAuthority('sys:dict:list')") + @OperationLog + @ApiOperation("查询全部字典数据") + @GetMapping() + public ApiResult> list(DictionaryDataParam param) { + return success(dictionaryDataService.listRel(param)); + } + + @PreAuthorize("hasAuthority('sys:dict:list')") + @OperationLog + @ApiOperation("根据id查询字典数据") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(dictionaryDataService.getByIdRel(id)); + } + + @PreAuthorize("hasAuthority('sys:dict:save')") + @OperationLog + @ApiOperation("添加字典数据") + @PostMapping() + public ApiResult add(@RequestBody DictionaryData dictionaryData) { + if (dictionaryDataService.count(new LambdaQueryWrapper() + .eq(DictionaryData::getDictId, dictionaryData.getDictId()) + .eq(DictionaryData::getDictDataName, dictionaryData.getDictDataName())) > 0) { + return fail("字典数据名称已存在"); + } + if (dictionaryDataService.count(new LambdaQueryWrapper() + .eq(DictionaryData::getDictId, dictionaryData.getDictId()) + .eq(DictionaryData::getDictDataCode, dictionaryData.getDictDataCode())) > 0) { + return fail("字典数据标识已存在"); + } + if (dictionaryDataService.save(dictionaryData)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:dict:update')") + @OperationLog + @ApiOperation("修改字典数据") + @PutMapping() + public ApiResult update(@RequestBody DictionaryData dictionaryData) { + if (dictionaryDataService.count(new LambdaQueryWrapper() + .eq(DictionaryData::getDictId, dictionaryData.getDictId()) + .eq(DictionaryData::getDictDataName, dictionaryData.getDictDataName()) + .ne(DictionaryData::getDictDataId, dictionaryData.getDictDataId())) > 0) { + return fail("字典数据名称已存在"); + } + if (dictionaryDataService.count(new LambdaQueryWrapper() + .eq(DictionaryData::getDictId, dictionaryData.getDictId()) + .eq(DictionaryData::getDictDataCode, dictionaryData.getDictDataCode()) + .ne(DictionaryData::getDictDataId, dictionaryData.getDictDataId())) > 0) { + return fail("字典数据标识已存在"); + } + if (dictionaryDataService.updateById(dictionaryData)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:dict:remove')") + @OperationLog + @ApiOperation("删除字典数据") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (dictionaryDataService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:dict:save')") + @OperationLog + @ApiOperation("批量添加字典数据") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List dictDataList) { + if (dictionaryDataService.saveBatch(dictDataList)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:dict:remove')") + @OperationLog + @ApiOperation("批量删除字典数据") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (dictionaryDataService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/EmailController.java b/src/main/java/com/eleadmin/common/system/controller/EmailController.java new file mode 100644 index 0000000..3346fa2 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/EmailController.java @@ -0,0 +1,49 @@ +package com.eleadmin.common.system.controller; + +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.core.web.BaseController; +import com.eleadmin.common.system.entity.EmailRecord; +import com.eleadmin.common.system.service.EmailRecordService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.mail.MessagingException; + +/** + * 邮件功能控制器 + * + * @author EleAdmin + * @since 2020-03-21 00:37:11 + */ +@Api(tags = "邮件功能") +@RestController +@RequestMapping("/api/system/email") +public class EmailController extends BaseController { + @Resource + private EmailRecordService emailRecordService; + + @PreAuthorize("hasAuthority('sys:email:send')") + @OperationLog + @ApiOperation("发送邮件") + @PostMapping() + public ApiResult send(@RequestBody EmailRecord emailRecord) { + try { + emailRecordService.sendFullTextEmail(emailRecord.getTitle(), emailRecord.getContent(), + emailRecord.getReceiver().split(",")); + emailRecord.setCreateUserId(getLoginUserId()); + emailRecordService.save(emailRecord); + return success("发送成功"); + } catch (MessagingException e) { + e.printStackTrace(); + } + return fail("发送失败"); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/FileController.java b/src/main/java/com/eleadmin/common/system/controller/FileController.java new file mode 100644 index 0000000..13f2ebe --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/FileController.java @@ -0,0 +1,200 @@ +package com.eleadmin.common.system.controller; + +import cn.hutool.core.util.StrUtil; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.config.ConfigProperties; +import com.eleadmin.common.core.utils.FileServerUtil; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.core.web.BaseController; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.FileRecord; +import com.eleadmin.common.system.param.FileRecordParam; +import com.eleadmin.common.system.service.FileRecordService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.util.List; + +/** + * 文件上传下载控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:24 + */ +@Api(tags = "文件上传下载") +@RestController +@RequestMapping("/api/file") +public class FileController extends BaseController { + @Resource + private ConfigProperties config; + @Resource + private FileRecordService fileRecordService; + + @PreAuthorize("hasAuthority('sys:file:upload')") + @OperationLog + @ApiOperation("上传文件") + @PostMapping("/upload") + public ApiResult upload(@RequestParam MultipartFile file, HttpServletRequest request) { + FileRecord result = null; + try { + String dir = getUploadDir(); + File upload = FileServerUtil.upload(file, dir, config.getUploadUuidName()); + String path = upload.getAbsolutePath() + .replace("\\", "/") + .substring(dir.length() - 1) + .replace("\\", "/"); + String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/upload"); + String originalName = file.getOriginalFilename(); + result = new FileRecord(); + result.setCreateUserId(getLoginUserId()); + result.setName(StrUtil.isBlank(originalName) ? upload.getName() : originalName); + result.setLength(upload.length()); + result.setPath(path); + result.setUrl(requestURL + "/" + path); + result.setThumbnail(FileServerUtil.isImage(upload) ? (requestURL + "/thumbnail/" + path) : null); + fileRecordService.save(result); + return success(result); + } catch (Exception e) { + e.printStackTrace(); + return fail("上传失败", result).setError(e.toString()); + } + } + + @PreAuthorize("hasAuthority('sys:file:upload')") + @OperationLog + @ApiOperation("上传base64文件") + @ApiImplicitParams({ + @ApiImplicitParam(name = "base64", value = "base64", required = true, dataType = "string"), + @ApiImplicitParam(name = "fileName", value = "文件名称", dataType = "string") + }) + @PostMapping("/upload/base64") + public ApiResult uploadBase64(String base64, String fileName, HttpServletRequest request) { + FileRecord result = null; + try { + String dir = getUploadDir(); + File upload = FileServerUtil.upload(base64, fileName, getUploadDir()); + String path = upload.getAbsolutePath().substring(dir.length()).replace("\\", "/"); + String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/upload/base64"); + result = new FileRecord(); + result.setCreateUserId(getLoginUserId()); + result.setName(StrUtil.isBlank(fileName) ? upload.getName() : fileName); + result.setLength(upload.length()); + result.setPath(path); + result.setUrl(requestURL + path); + result.setThumbnail(FileServerUtil.isImage(upload) ? (requestURL + "/thumbnail" + path) : null); + fileRecordService.save(result); + return success(result); + } catch (Exception e) { + e.printStackTrace(); + return fail("上传失败", result).setError(e.toString()); + } + } + + @ApiOperation("查看原文件") + @GetMapping("/{dir}/{name:.+}") + public void preview(@PathVariable("dir") String dir, @PathVariable("name") String name, + HttpServletResponse response, HttpServletRequest request) { + File file = new File(getUploadDir(), dir + "/" + name); + FileServerUtil.preview(file, getPdfOutDir(), config.getOpenOfficeHome(), response, request); + } + + @ApiOperation("下载原文件") + @GetMapping("/download/{dir}/{name:.+}") + public void download(@PathVariable("dir") String dir, @PathVariable("name") String name, + HttpServletResponse response, HttpServletRequest request) { + File file = new File(getUploadDir(), dir + "/" + name); + FileServerUtil.preview(file, true, null, null, response, request); + } + + @ApiOperation("查看缩略图") + @GetMapping("/thumbnail/{dir}/{name:.+}") + public void thumbnail(@PathVariable("dir") String dir, @PathVariable("name") String name, + HttpServletResponse response, HttpServletRequest request) { + File file = new File(getUploadDir(), dir + "/" + name); + File thumbnail = new File(getUploadSmDir(), dir + "/" + name); + FileServerUtil.previewThumbnail(file, thumbnail, config.getThumbnailSize(), response, request); + } + + @PreAuthorize("hasAuthority('sys:file:remove')") + @OperationLog + @ApiOperation("删除文件") + @DeleteMapping("/remove/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (fileRecordService.removeById(id)) { + FileRecord record = fileRecordService.getById(id); + if (StrUtil.isNotBlank(record.getPath())) { + new File(getUploadDir(), record.getPath()).delete(); + new File(getUploadSmDir(), record.getPath()).delete(); + } + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:file:list')") + @OperationLog + @ApiOperation("分页查询文件") + @GetMapping("/page") + public ApiResult> page(FileRecordParam param, HttpServletRequest request) { + PageResult result = fileRecordService.pageRel(param); + String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/page"); + for (FileRecord record : result.getList()) { + record.setUrl(requestURL + record.getPath()); + record.setThumbnail(requestURL + "/thumbnail" + record.getPath()); + } + return success(result); + } + + @PreAuthorize("hasAuthority('sys:file:list')") + @OperationLog + @ApiOperation("查询全部文件") + @GetMapping("/list") + public ApiResult> list(FileRecordParam param, HttpServletRequest request) { + List records = fileRecordService.listRel(param); + String requestURL = StrUtil.removeSuffix(request.getRequestURL(), "/list"); + for (FileRecord record : records) { + record.setUrl(requestURL + record.getPath()); + record.setThumbnail(requestURL + "/thumbnail" + record.getPath()); + } + return success(records); + } + + /** + * 文件上传基目录 + */ + private String getUploadBaseDir() { + return File.listRoots()[config.getUploadLocation()].getAbsolutePath() + .replace("\\", "/") + "/upload/"; + } + + /** + * 文件上传位置 + */ + private String getUploadDir() { + return getUploadBaseDir() + "file/"; + } + + /** + * 缩略图生成位置 + */ + private String getUploadSmDir() { + return getUploadBaseDir() + "thumbnail/"; + } + + /** + * office转pdf输出位置 + */ + private String getPdfOutDir() { + return getUploadBaseDir() + "pdf/"; + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/GoodsController.java b/src/main/java/com/eleadmin/common/system/controller/GoodsController.java new file mode 100644 index 0000000..daaa7f6 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/GoodsController.java @@ -0,0 +1,31 @@ +package com.eleadmin.common.system.controller; + +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.system.entity.Goods; +import com.eleadmin.common.system.service.GoodsService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +@Api(tags = "商品管理") +@RestController +@RequestMapping("/api/system/goods") +public class GoodsController { + @Resource + private GoodsService goodsService; + + @PreAuthorize("hasAuthority('sys:goods:list')") + @OperationLog + @ApiOperation + @GetMapping() + public ApiResult> list(){ + + } +} diff --git a/src/main/java/com/eleadmin/common/system/controller/LoginRecordController.java b/src/main/java/com/eleadmin/common/system/controller/LoginRecordController.java new file mode 100644 index 0000000..4777bae --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/LoginRecordController.java @@ -0,0 +1,58 @@ +package com.eleadmin.common.system.controller; + +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.core.web.BaseController; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.LoginRecord; +import com.eleadmin.common.system.param.LoginRecordParam; +import com.eleadmin.common.system.service.LoginRecordService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 登录日志控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:31 + */ +@Api(tags = "登录日志") +@RestController +@RequestMapping("/api/system/login-record") +public class LoginRecordController extends BaseController { + @Resource + private LoginRecordService loginRecordService; + + @PreAuthorize("hasAuthority('sys:login-record:view')") + @OperationLog + @ApiOperation("分页查询登录日志") + @GetMapping("/page") + public ApiResult> page(LoginRecordParam param) { + return success(loginRecordService.pageRel(param)); + } + + @PreAuthorize("hasAuthority('sys:login-record:view')") + @OperationLog + @ApiOperation("查询全部登录日志") + @GetMapping() + public ApiResult> list(LoginRecordParam param) { + return success(loginRecordService.listRel(param)); + } + + @PreAuthorize("hasAuthority('sys:login-record:view')") + @OperationLog + @ApiOperation("根据id查询登录日志") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(loginRecordService.getByIdRel(id)); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/MainController.java b/src/main/java/com/eleadmin/common/system/controller/MainController.java new file mode 100644 index 0000000..4c60e70 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/MainController.java @@ -0,0 +1,140 @@ +package com.eleadmin.common.system.controller; + +import cn.hutool.core.util.StrUtil; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.config.ConfigProperties; +import com.eleadmin.common.core.security.JwtSubject; +import com.eleadmin.common.core.security.JwtUtil; +import com.eleadmin.common.core.utils.CommonUtil; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.core.web.BaseController; +import com.eleadmin.common.system.entity.LoginRecord; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.entity.User; +import com.eleadmin.common.system.result.CaptchaResult; +import com.eleadmin.common.system.param.LoginParam; +import com.eleadmin.common.system.result.LoginResult; +import com.eleadmin.common.system.param.UpdatePasswordParam; +import com.eleadmin.common.system.service.LoginRecordService; +import com.eleadmin.common.system.service.RoleMenuService; +import com.eleadmin.common.system.service.UserService; +import com.wf.captcha.SpecCaptcha; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.*; + +/** + * 登录认证控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:11 + */ +@Api(tags = "登录认证") +@RestController +@RequestMapping("/api") +public class MainController extends BaseController { + @Resource + private ConfigProperties configProperties; + @Resource + private UserService userService; + @Resource + private RoleMenuService roleMenuService; + @Resource + private LoginRecordService loginRecordService; + + @ApiOperation("用户登录") + @PostMapping("/login") + public ApiResult login(@RequestBody LoginParam param, HttpServletRequest request) { + String username = param.getUsername(); + Integer tenantId = param.getTenantId(); + User user = userService.getByUsername(username, tenantId); + if (user == null) { + String message = "账号不存在"; + loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request); + return fail(message, null); + } + if (!user.getStatus().equals(0)) { + String message = "账号被冻结"; + loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request); + return fail(message, null); + } + if (!userService.comparePassword(user.getPassword(), param.getPassword())) { + String message = "密码错误"; + loginRecordService.saveAsync(username, LoginRecord.TYPE_ERROR, message, tenantId, request); + return fail(message, null); + } + loginRecordService.saveAsync(username, LoginRecord.TYPE_LOGIN, null, tenantId, request); + // 签发token + String access_token = JwtUtil.buildToken(new JwtSubject(username, tenantId), + configProperties.getTokenExpireTime(), configProperties.getTokenKey()); + return success("登录成功", new LoginResult(access_token, user)); + } + + @ApiOperation("获取登录用户信息") + @GetMapping("/auth/user") + public ApiResult userInfo() { + return success(userService.getByIdRel(getLoginUserId())); + } + + @ApiOperation("获取登录用户菜单") + @GetMapping("/auth/menu") + public ApiResult> userMenu() { + List menus = roleMenuService.listMenuByUserId(getLoginUserId(), Menu.TYPE_MENU); + return success(CommonUtil.toTreeData(menus, 0, Menu::getParentId, Menu::getMenuId, Menu::setChildren)); + } + + @PreAuthorize("hasAuthority('sys:auth:user')") + @OperationLog + @ApiOperation("修改个人信息") + @PutMapping("/auth/user") + public ApiResult updateInfo(@RequestBody User user) { + user.setUserId(getLoginUserId()); + // 不能修改的字段 + user.setUsername(null); + user.setPassword(null); + user.setEmailVerified(null); + user.setOrganizationId(null); + user.setStatus(null); + if (userService.updateById(user)) { + return success(userService.getByIdRel(user.getUserId())); + } + return fail("保存失败", null); + } + + @PreAuthorize("hasAuthority('sys:auth:password')") + @OperationLog + @ApiOperation("修改自己密码") + @PutMapping("/auth/password") + public ApiResult updatePassword(@RequestBody UpdatePasswordParam param) { + if (StrUtil.hasBlank(param.getOldPassword(), param.getPassword())) { + return fail("参数不能为空"); + } + Integer userId = getLoginUserId(); + if (userId == null) { + return fail("未登录"); + } + if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) { + return fail("原密码输入不正确"); + } + User user = new User(); + user.setUserId(userId); + user.setPassword(userService.encodePassword(param.getPassword())); + if (userService.updateById(user)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("图形验证码") + @GetMapping("/captcha") + public ApiResult captcha() { + SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5); + return success(new CaptchaResult(specCaptcha.toBase64(), specCaptcha.text().toLowerCase())); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/MenuController.java b/src/main/java/com/eleadmin/common/system/controller/MenuController.java new file mode 100644 index 0000000..742640a --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/MenuController.java @@ -0,0 +1,123 @@ +package com.eleadmin.common.system.controller; + +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.*; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.param.MenuParam; +import com.eleadmin.common.system.service.MenuService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 菜单控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:23 + */ +@Api(tags = "菜单管理") +@RestController +@RequestMapping("/api/system/menu") +public class MenuController extends BaseController { + @Resource + private MenuService menuService; + + @PreAuthorize("hasAuthority('sys:menu:list')") + @OperationLog + @ApiOperation("分页查询菜单") + @GetMapping("/page") + public ApiResult> page(MenuParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return success(menuService.page(page, page.getWrapper())); + } + + @PreAuthorize("hasAuthority('sys:menu:list')") + @OperationLog + @ApiOperation("查询全部菜单") + @GetMapping() + public ApiResult> list(MenuParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return success(menuService.list(page.getOrderWrapper())); + } + + @PreAuthorize("hasAuthority('sys:menu:list')") + @OperationLog + @ApiOperation("根据id查询菜单") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(menuService.getById(id)); + } + + @PreAuthorize("hasAuthority('sys:menu:save')") + @OperationLog + @ApiOperation("添加菜单") + @PostMapping() + public ApiResult add(@RequestBody Menu menu) { + if (menuService.save(menu)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:menu:update')") + @OperationLog + @ApiOperation("修改菜单") + @PutMapping() + public ApiResult update(@RequestBody Menu menu) { + if (menuService.updateById(menu)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:menu:remove')") + @OperationLog + @ApiOperation("删除菜单") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (menuService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:menu:save')") + @OperationLog + @ApiOperation("批量添加菜单") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List menus) { + if (menuService.saveBatch(menus)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:menu:update')") + @OperationLog + @ApiOperation("批量修改菜单") + @PutMapping("/batch") + public ApiResult updateBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(menuService, "menu_id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:menu:remove')") + @OperationLog + @ApiOperation("批量删除菜单") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (menuService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/OperationRecordController.java b/src/main/java/com/eleadmin/common/system/controller/OperationRecordController.java new file mode 100644 index 0000000..d7532bc --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/OperationRecordController.java @@ -0,0 +1,62 @@ +package com.eleadmin.common.system.controller; + +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.core.web.BaseController; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.OperationRecord; +import com.eleadmin.common.system.param.OperationRecordParam; +import com.eleadmin.common.system.service.OperationRecordService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 操作日志控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:12 + */ +@Api(tags = "操作日志") +@RestController +@RequestMapping("/api/system/operation-record") +public class OperationRecordController extends BaseController { + @Resource + private OperationRecordService operationRecordService; + + /** + * 分页查询操作日志 + */ + @PreAuthorize("hasAuthority('sys:operation-record:view')") + @ApiOperation("分页查询操作日志") + @GetMapping("/page") + public ApiResult> page(OperationRecordParam param) { + return success(operationRecordService.pageRel(param)); + } + + /** + * 查询全部操作日志 + */ + @PreAuthorize("hasAuthority('sys:operation-record:view')") + @OperationLog + @ApiOperation("查询全部操作日志") + @GetMapping() + public ApiResult> list(OperationRecordParam param) { + return success(operationRecordService.listRel(param)); + } + + /** + * 根据id查询操作日志 + */ + @PreAuthorize("hasAuthority('sys:operation-record:view')") + @ApiOperation("根据id查询操作日志") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(operationRecordService.getByIdRel(id)); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/OrganizationController.java b/src/main/java/com/eleadmin/common/system/controller/OrganizationController.java new file mode 100644 index 0000000..21dec4b --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/OrganizationController.java @@ -0,0 +1,139 @@ +package com.eleadmin.common.system.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.*; +import com.eleadmin.common.system.entity.Organization; +import com.eleadmin.common.system.param.OrganizationParam; +import com.eleadmin.common.system.service.OrganizationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 组织机构控制器 + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +@Api(tags = "组织机构管理") +@RestController +@RequestMapping("/api/system/organization") +public class OrganizationController extends BaseController { + @Resource + private OrganizationService organizationService; + + @PreAuthorize("hasAuthority('sys:org:list')") + @OperationLog + @ApiOperation("分页查询组织机构") + @GetMapping("/page") + public ApiResult> page(OrganizationParam param) { + return success(organizationService.pageRel(param)); + } + + @PreAuthorize("hasAuthority('sys:org:list')") + @OperationLog + @ApiOperation("查询全部组织机构") + @GetMapping() + public ApiResult> list(OrganizationParam param) { + return success(organizationService.listRel(param)); + } + + @PreAuthorize("hasAuthority('sys:org:list')") + @OperationLog + @ApiOperation("根据id查询组织机构") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(organizationService.getByIdRel(id)); + } + + @PreAuthorize("hasAuthority('sys:org:save')") + @OperationLog + @ApiOperation("添加组织机构") + @PostMapping() + public ApiResult add(@RequestBody Organization organization) { + if (organization.getParentId() == null) { + organization.setParentId(0); + } + if (organizationService.count(new LambdaQueryWrapper() + .eq(Organization::getOrganizationName, organization.getOrganizationName()) + .eq(Organization::getParentId, organization.getParentId())) > 0) { + return fail("机构名称已存在"); + } + if (organizationService.save(organization)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:org:update')") + @OperationLog + @ApiOperation("修改组织机构") + @PutMapping() + public ApiResult update(@RequestBody Organization organization) { + if (organization.getOrganizationName() != null) { + if (organization.getParentId() == null) { + organization.setParentId(0); + } + if (organizationService.count(new LambdaQueryWrapper() + .eq(Organization::getOrganizationName, organization.getOrganizationName()) + .eq(Organization::getParentId, organization.getParentId()) + .ne(Organization::getOrganizationId, organization.getOrganizationId())) > 0) { + return fail("机构名称已存在"); + } + } + if (organizationService.updateById(organization)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:org:remove')") + @OperationLog + @ApiOperation("删除组织机构") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (organizationService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:org:save')") + @OperationLog + @ApiOperation("批量添加组织机构") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List organizationList) { + if (organizationService.saveBatch(organizationList)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:org:update')") + @OperationLog + @ApiOperation("批量修改组织机构") + @PutMapping("/batch") + public ApiResult updateBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(organizationService, Organization::getOrganizationId)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:org:remove')") + @OperationLog + @ApiOperation("批量删除组织机构") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (organizationService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/RoleController.java b/src/main/java/com/eleadmin/common/system/controller/RoleController.java new file mode 100644 index 0000000..3575a08 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/RoleController.java @@ -0,0 +1,152 @@ +package com.eleadmin.common.system.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.utils.CommonUtil; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.core.web.BaseController; +import com.eleadmin.common.core.web.PageParam; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.Role; +import com.eleadmin.common.system.param.RoleParam; +import com.eleadmin.common.system.service.RoleService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 角色控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:02 + */ +@Api(tags = "角色管理") +@RestController +@RequestMapping("/api/system/role") +public class RoleController extends BaseController { + @Resource + private RoleService roleService; + + @PreAuthorize("hasAuthority('sys:role:list')") + @OperationLog + @ApiOperation("分页查询角色") + @GetMapping("/page") + public ApiResult> page(RoleParam param) { + PageParam page = new PageParam<>(param); + return success(roleService.page(page, page.getWrapper())); + } + + @PreAuthorize("hasAuthority('sys:role:list')") + @OperationLog + @ApiOperation("查询全部角色") + @GetMapping() + public ApiResult> list(RoleParam param) { + PageParam page = new PageParam<>(param); + return success(roleService.list(page.getOrderWrapper())); + } + + @PreAuthorize("hasAuthority('sys:role:list')") + @OperationLog + @ApiOperation("根据id查询角色") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(roleService.getById(id)); + } + + @PreAuthorize("hasAuthority('sys:role:save')") + @OperationLog + @ApiOperation("添加角色") + @PostMapping() + public ApiResult save(@RequestBody Role role) { + if (roleService.count(new LambdaQueryWrapper().eq(Role::getRoleCode, role.getRoleCode())) > 0) { + return fail("角色标识已存在"); + } + if (roleService.count(new LambdaQueryWrapper().eq(Role::getRoleName, role.getRoleName())) > 0) { + return fail("角色名称已存在"); + } + if (roleService.save(role)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:role:update')") + @OperationLog + @ApiOperation("修改角色") + @PutMapping() + public ApiResult update(@RequestBody Role role) { + if (role.getRoleCode() != null && roleService.count(new LambdaQueryWrapper() + .eq(Role::getRoleCode, role.getRoleCode()) + .ne(Role::getRoleId, role.getRoleId())) > 0) { + return fail("角色标识已存在"); + } + if (role.getRoleName() != null && roleService.count(new LambdaQueryWrapper() + .eq(Role::getRoleName, role.getRoleName()) + .ne(Role::getRoleId, role.getRoleId())) > 0) { + return fail("角色名称已存在"); + } + if (roleService.updateById(role)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:role:remove')") + @OperationLog + @ApiOperation("删除角色") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (roleService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:role:save')") + @OperationLog + @ApiOperation("批量添加角色") + @PostMapping("/batch") + public ApiResult> saveBatch(@RequestBody List list) { + // 校验是否重复 + if (CommonUtil.checkRepeat(list, Role::getRoleName)) { + return fail("角色名称存在重复", null); + } + if (CommonUtil.checkRepeat(list, Role::getRoleCode)) { + return fail("角色标识存在重复", null); + } + // 校验是否存在 + List codeExists = roleService.list(new LambdaQueryWrapper().in(Role::getRoleCode, + list.stream().map(Role::getRoleCode).collect(Collectors.toList()))); + if (codeExists.size() > 0) { + return fail("角色标识已存在", codeExists.stream().map(Role::getRoleCode) + .collect(Collectors.toList())).setCode(2); + } + List nameExists = roleService.list(new LambdaQueryWrapper().in(Role::getRoleName, + list.stream().map(Role::getRoleCode).collect(Collectors.toList()))); + if (nameExists.size() > 0) { + return fail("角色标识已存在", nameExists.stream().map(Role::getRoleCode) + .collect(Collectors.toList())).setCode(3); + } + if (roleService.saveBatch(list)) { + return success("添加成功", null); + } + return fail("添加失败", null); + } + + @PreAuthorize("hasAuthority('sys:role:remove')") + @OperationLog + @ApiOperation("批量删除角色") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (roleService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/RoleMenuController.java b/src/main/java/com/eleadmin/common/system/controller/RoleMenuController.java new file mode 100644 index 0000000..d2f39f3 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/RoleMenuController.java @@ -0,0 +1,100 @@ +package com.eleadmin.common.system.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.web.ApiResult; +import com.eleadmin.common.core.web.BaseController; +import com.eleadmin.common.core.exception.BusinessException; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.entity.RoleMenu; +import com.eleadmin.common.system.service.MenuService; +import com.eleadmin.common.system.service.RoleMenuService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * 角色菜单控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:01 + */ +@Api(tags = "角色菜单管理") +@RestController +@RequestMapping("/api/system/role-menu") +public class RoleMenuController extends BaseController { + @Resource + private RoleMenuService roleMenuService; + @Resource + private MenuService menuService; + + @PreAuthorize("hasAuthority('sys:role:list')") + @OperationLog + @ApiOperation("查询角色菜单") + @GetMapping("/{id}") + public ApiResult> list(@PathVariable("id") Integer roleId) { + List menus = menuService.list(new LambdaQueryWrapper().orderByAsc(Menu::getSortNumber)); + List roleMenus = roleMenuService.list(new LambdaQueryWrapper() + .eq(RoleMenu::getRoleId, roleId)); + for (Menu menu : menus) { + menu.setChecked(roleMenus.stream().anyMatch((d) -> d.getMenuId().equals(menu.getMenuId()))); + } + return success(menus); + } + + @Transactional(rollbackFor = {Exception.class}) + @PreAuthorize("hasAuthority('sys:role:update')") + @OperationLog + @ApiOperation("修改角色菜单") + @PutMapping("/{id}") + public ApiResult update(@PathVariable("id") Integer roleId, @RequestBody List menuIds) { + roleMenuService.remove(new LambdaUpdateWrapper().eq(RoleMenu::getRoleId, roleId)); + if (menuIds != null && menuIds.size() > 0) { + List roleMenuList = new ArrayList<>(); + for (Integer menuId : menuIds) { + RoleMenu roleMenu = new RoleMenu(); + roleMenu.setRoleId(roleId); + roleMenu.setMenuId(menuId); + roleMenuList.add(roleMenu); + } + if (!roleMenuService.saveBatch(roleMenuList)) { + throw new BusinessException("保存失败"); + } + } + return success("保存成功"); + } + + @PreAuthorize("hasAuthority('sys:role:update')") + @OperationLog + @ApiOperation("添加角色菜单") + @PostMapping("/{id}") + public ApiResult addRoleAuth(@PathVariable("id") Integer roleId, @RequestBody Integer menuId) { + RoleMenu roleMenu = new RoleMenu(); + roleMenu.setRoleId(roleId); + roleMenu.setMenuId(menuId); + if (roleMenuService.save(roleMenu)) { + return success(); + } + return fail(); + } + + @PreAuthorize("hasAuthority('sys:role:update')") + @OperationLog + @ApiOperation("移除角色菜单") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer roleId, @RequestBody Integer menuId) { + if (roleMenuService.remove(new LambdaUpdateWrapper() + .eq(RoleMenu::getRoleId, roleId).eq(RoleMenu::getMenuId, menuId))) { + return success(); + } + return fail(); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/controller/UserController.java b/src/main/java/com/eleadmin/common/system/controller/UserController.java new file mode 100644 index 0000000..b783433 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/controller/UserController.java @@ -0,0 +1,298 @@ +package com.eleadmin.common.system.controller; + +import cn.afterturn.easypoi.excel.ExcelImportUtil; +import cn.afterturn.easypoi.excel.entity.ImportParams; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.eleadmin.common.core.annotation.OperationLog; +import com.eleadmin.common.core.utils.CommonUtil; +import com.eleadmin.common.core.web.*; +import com.eleadmin.common.system.entity.DictionaryData; +import com.eleadmin.common.system.entity.Organization; +import com.eleadmin.common.system.entity.Role; +import com.eleadmin.common.system.entity.User; +import com.eleadmin.common.system.param.UserImportParam; +import com.eleadmin.common.system.param.UserParam; +import com.eleadmin.common.system.service.DictionaryDataService; +import com.eleadmin.common.system.service.OrganizationService; +import com.eleadmin.common.system.service.RoleService; +import com.eleadmin.common.system.service.UserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 用户控制器 + * + * @author EleAdmin + * @since 2018-12-24 16:10:41 + */ +@Api(tags = "用户管理") +@RestController +@RequestMapping("/api/system/user") +public class UserController extends BaseController { + @Resource + private UserService userService; + @Resource + private RoleService roleService; + @Resource + private OrganizationService organizationService; + @Resource + private DictionaryDataService dictionaryDataService; + + @PreAuthorize("hasAuthority('sys:user:list')") + @OperationLog + @ApiOperation("分页查询用户") + @GetMapping("/page") + public ApiResult> page(UserParam param) { + return success(userService.pageRel(param)); + } + + @PreAuthorize("hasAuthority('sys:user:list')") + @OperationLog + @ApiOperation("查询全部用户") + @GetMapping() + public ApiResult> list(UserParam param) { + return success(userService.listRel(param)); + } + + @PreAuthorize("hasAuthority('sys:user:list')") + @OperationLog + @ApiOperation("根据id查询用户") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(userService.getByIdRel(id)); + } + + @PreAuthorize("hasAuthority('sys:user:save')") + @OperationLog + @ApiOperation("添加用户") + @PostMapping() + public ApiResult add(@RequestBody User user) { + user.setStatus(0); + user.setPassword(userService.encodePassword(user.getPassword())); + if (userService.saveUser(user)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:user:update')") + @OperationLog + @ApiOperation("修改用户") + @PutMapping() + public ApiResult update(@RequestBody User user) { + user.setStatus(null); + user.setUsername(null); + user.setPassword(null); + if (userService.updateUser(user)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:user:remove')") + @OperationLog + @ApiOperation("删除用户") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (userService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:user:update')") + @OperationLog + @ApiOperation("批量修改用户") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(userService, User::getUserId)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:user:remove')") + @OperationLog + @ApiOperation("批量删除用户") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids", value = "id数组", required = true, dataType = "string") + }) + @DeleteMapping("/batch") + public ApiResult deleteBatch(@RequestBody List ids) { + if (userService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:user:update')") + @OperationLog + @ApiOperation("修改用户状态") + @PutMapping("/status") + public ApiResult updateStatus(@RequestBody User user) { + if (user.getUserId() == null || user.getStatus() == null || !Arrays.asList(0, 1).contains(user.getStatus())) { + return fail("参数不正确"); + } + User u = new User(); + u.setUserId(user.getUserId()); + u.setStatus(user.getStatus()); + if (userService.updateById(u)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:user:update')") + @OperationLog + @ApiOperation("批量修改用户状态") + @PutMapping("/status/batch") + public ApiResult updateStatusBatch(@RequestBody BatchParam batchParam) { + if (!Arrays.asList(0, 1).contains(batchParam.getData())) { + return fail("状态值不正确"); + } + if (userService.update(new LambdaUpdateWrapper() + .in(User::getUserId, batchParam.getIds()) + .set(User::getStatus, batchParam.getData()))) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:user:update')") + @OperationLog + @ApiOperation("重置密码") + @PutMapping("/password") + public ApiResult resetPassword(@RequestBody User user) { + if (user.getUserId() == null || StrUtil.isBlank(user.getPassword())) { + return fail("参数不正确"); + } + User u = new User(); + u.setUserId(user.getUserId()); + u.setPassword(userService.encodePassword(user.getPassword())); + if (userService.updateById(u)) { + return success("重置成功"); + } else { + return fail("重置失败"); + } + } + + @PreAuthorize("hasAuthority('sys:user:update')") + @OperationLog + @ApiOperation("批量重置密码") + @PutMapping("/password/batch") + public ApiResult resetPasswordBatch(@RequestBody BatchParam batchParam) { + if (batchParam.getIds() == null || batchParam.getIds().size() == 0) { + return fail("请选择用户"); + } + if (batchParam.getData() == null) { + return fail("请输入密码"); + } + if (userService.update(new LambdaUpdateWrapper() + .in(User::getUserId, batchParam.getIds()) + .set(User::getPassword, userService.encodePassword(batchParam.getData())))) { + return success("重置成功"); + } else { + return fail("重置失败"); + } + } + + @PreAuthorize("hasAuthority('sys:user:list')") + @OperationLog + @ApiOperation("检查用户是否存在") + @GetMapping("/existence") + public ApiResult existence(ExistenceParam param) { + if (param.isExistence(userService, User::getUserId)) { + return success(param.getValue() + "已存在"); + } + return fail(param.getValue() + "不存在"); + } + + /** + * excel导入用户 + */ + @PreAuthorize("hasAuthority('sys:user:save')") + @OperationLog + @ApiOperation("导入用户") + @Transactional(rollbackFor = {Exception.class}) + @PostMapping("/import") + public ApiResult> importBatch(MultipartFile file) { + ImportParams importParams = new ImportParams(); + try { + List list = ExcelImportUtil.importExcel(file.getInputStream(), + UserImportParam.class, importParams); + // 校验是否重复 + if (CommonUtil.checkRepeat(list, UserImportParam::getUsername)) { + return fail("账号存在重复", null); + } + if (CommonUtil.checkRepeat(list, UserImportParam::getPhone)) { + return fail("手机号存在重复", null); + } + // 校验是否存在 + List usernameExists = userService.list(new LambdaQueryWrapper().in(User::getUsername, + list.stream().map(UserImportParam::getUsername).collect(Collectors.toList()))); + if (usernameExists.size() > 0) { + return fail("账号已经存在", + usernameExists.stream().map(User::getUsername).collect(Collectors.toList())); + } + List phoneExists = userService.list(new LambdaQueryWrapper().in(User::getPhone, + list.stream().map(UserImportParam::getPhone).collect(Collectors.toList()))); + if (phoneExists.size() > 0) { + return fail("手机号已经存在", + phoneExists.stream().map(User::getPhone).collect(Collectors.toList())); + } + // 添加 + List users = new ArrayList<>(); + for (UserImportParam one : list) { + User u = new User(); + u.setStatus(0); + u.setUsername(one.getUsername()); + u.setPassword(userService.encodePassword(one.getPassword())); + u.setNickname(one.getNickname()); + u.setPhone(one.getPhone()); + Role role = roleService.getOne(new QueryWrapper() + .eq("role_name", one.getRoleName()), false); + if (role == null) { + return fail("角色不存在", Collections.singletonList(one.getRoleName())); + } else { + u.setRoles(Collections.singletonList(role)); + } + Organization organization = organizationService.getOne(new QueryWrapper() + .eq("organization_full_name", one.getOrganizationName()), false); + if (organization == null) { + return fail("机构不存在", Collections.singletonList(one.getOrganizationName())); + } else { + u.setOrganizationId(organization.getOrganizationId()); + } + DictionaryData sex = dictionaryDataService.getByDictCodeAndName("sex", one.getSexName()); + if (sex == null) { + return fail("性别不存在", Collections.singletonList(one.getSexName())); + } else { + u.setSex(sex.getDictDataCode()); + } + } + if (userService.saveBatch(users)) { + return success("导入成功", null); + } + } catch (Exception e) { + e.printStackTrace(); + } + return fail("导入失败", null); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/Dictionary.java b/src/main/java/com/eleadmin/common/system/entity/Dictionary.java new file mode 100644 index 0000000..058db6e --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/Dictionary.java @@ -0,0 +1,53 @@ +package com.eleadmin.common.system.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; + +import java.util.Date; +import java.io.Serializable; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 字典 + * + * @author EleAdmin + * @since 2020-03-14 11:29:03 + */ +@Data +@ApiModel(description = "字典") +@TableName("sys_dictionary") +public class Dictionary implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "字典id") + @TableId(type = IdType.AUTO) + private Integer dictId; + + @ApiModelProperty(value = "字典标识") + private String dictCode; + + @ApiModelProperty(value = "字典名称") + private String dictName; + + @ApiModelProperty(value = "排序号") + private Integer sortNumber; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/DictionaryData.java b/src/main/java/com/eleadmin/common/system/entity/DictionaryData.java new file mode 100644 index 0000000..0108863 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/DictionaryData.java @@ -0,0 +1,61 @@ +package com.eleadmin.common.system.entity; + +import com.baomidou.mybatisplus.annotation.*; + +import java.util.Date; +import java.io.Serializable; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 字典数据 + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +@Data +@ApiModel(description = "字典数据") +@TableName("sys_dictionary_data") +public class DictionaryData implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "字典数据id") + @TableId(type = IdType.AUTO) + private Integer dictDataId; + + @ApiModelProperty(value = "字典id") + private Integer dictId; + + @ApiModelProperty(value = "字典数据标识") + private String dictDataCode; + + @ApiModelProperty(value = "字典数据名称") + private String dictDataName; + + @ApiModelProperty(value = "排序号") + private Integer sortNumber; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + + @ApiModelProperty(value = "字典代码") + @TableField(exist = false) + private String dictCode; + + @ApiModelProperty(value = "字典名称") + @TableField(exist = false) + private String dictName; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/EmailRecord.java b/src/main/java/com/eleadmin/common/system/entity/EmailRecord.java new file mode 100644 index 0000000..e24bc2c --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/EmailRecord.java @@ -0,0 +1,56 @@ +package com.eleadmin.common.system.entity; + +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 EleAdmin + * @since 2021-08-29 12:36:35 + */ +@Data +@ApiModel(description = "邮件发送记录") +@TableName("sys_email_record") +public class EmailRecord implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键id") + @TableId(type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("邮件标题") + private String title; + + @ApiModelProperty("邮件内容") + private String content; + + @ApiModelProperty("收件邮箱") + private String receiver; + + @ApiModelProperty("发件邮箱") + private String sender; + + @ApiModelProperty("创建人") + private Integer createUserId; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/FileRecord.java b/src/main/java/com/eleadmin/common/system/entity/FileRecord.java new file mode 100644 index 0000000..51133c2 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/FileRecord.java @@ -0,0 +1,70 @@ +package com.eleadmin.common.system.entity; + +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 java.io.Serializable; +import java.util.Date; + +/** + * 文件上传记录 + * + * @author EleAdmin + * @since 2021-08-29 12:36:32 + */ +@Data +@ApiModel(description = "文件上传记录") +@TableName("sys_file_record") +public class FileRecord implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键id") + @TableId(type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("文件名称") + private String name; + + @ApiModelProperty("文件存储路径") + private String path; + + @ApiModelProperty("文件大小") + private Long length; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty("创建人") + private Integer createUserId; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + + @ApiModelProperty("文件访问地址") + @TableField(exist = false) + private String url; + + @ApiModelProperty("文件缩略图访问地址") + @TableField(exist = false) + private String thumbnail; + + @ApiModelProperty("创建人账号") + @TableField(exist = false) + private String createUsername; + + @ApiModelProperty("创建人名称") + @TableField(exist = false) + private String createNickname; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/Goods.java b/src/main/java/com/eleadmin/common/system/entity/Goods.java new file mode 100644 index 0000000..15f03ec --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/Goods.java @@ -0,0 +1,40 @@ +package com.eleadmin.common.system.entity; + +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.math.BigDecimal; +import java.util.Date; + +@Data +@ApiModel(description = "商品") +@TableName("sys_goods") +public class Goods { + private static final long serialVersionUID = 1L; + public static final int TYPE_MENU = 0; // 菜单类型 + public static final int TYPE_BTN = 1; // 按钮类型 + + @ApiModelProperty("id") + @TableId(type = IdType.AUTO) + private Long id; + @ApiModelProperty("商品编码") + private Long goodsId; + @ApiModelProperty("商品名称") + private String title; + @ApiModelProperty("类型") + private String goodsType; + @ApiModelProperty("商品价格") + private BigDecimal price; + @ApiModelProperty("创建时间") + private Date createTime; + @ApiModelProperty("创建人") + private Integer creator; + @ApiModelProperty("修改时间") + private Date changeDate; + @ApiModelProperty("修改人") + private Integer changorId; +} diff --git a/src/main/java/com/eleadmin/common/system/entity/LoginRecord.java b/src/main/java/com/eleadmin/common/system/entity/LoginRecord.java new file mode 100644 index 0000000..8e9d0aa --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/LoginRecord.java @@ -0,0 +1,72 @@ +package com.eleadmin.common.system.entity; + +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 java.io.Serializable; +import java.util.Date; + +/** + * 登录日志 + * + * @author EleAdmin + * @since 2018-12-24 16:10:41 + */ +@Data +@ApiModel(description = "登录日志") +@TableName("sys_login_record") +public class LoginRecord implements Serializable { + private static final long serialVersionUID = 1L; + public static final int TYPE_LOGIN = 0; // 登录成功 + public static final int TYPE_ERROR = 1; // 登录失败 + public static final int TYPE_LOGOUT = 2; // 退出登录 + public static final int TYPE_REFRESH = 3; // 续签token + + @ApiModelProperty("主键id") + @TableId(type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("用户账号") + private String username; + + @ApiModelProperty("操作系统") + private String os; + + @ApiModelProperty("设备名称") + private String device; + + @ApiModelProperty("浏览器类型") + private String browser; + + @ApiModelProperty("ip地址") + private String ip; + + @ApiModelProperty("操作类型, 0登录成功, 1登录失败, 2退出登录, 3续签token") + private Integer loginType; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("操作时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + + @ApiModelProperty("用户id") + @TableField(exist = false) + private Integer userId; + + @ApiModelProperty("用户昵称") + @TableField(exist = false) + private String nickname; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/Menu.java b/src/main/java/com/eleadmin/common/system/entity/Menu.java new file mode 100644 index 0000000..cb3a834 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/Menu.java @@ -0,0 +1,90 @@ +package com.eleadmin.common.system.entity; + +import com.baomidou.mybatisplus.annotation.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.security.core.GrantedAuthority; + +import java.util.Date; +import java.util.List; + +/** + * 菜单 + * + * @author EleAdmin + * @since 2018-12-24 16:10:17 + */ +@Data +@ApiModel(description = "菜单") +@TableName("sys_menu") +public class Menu implements GrantedAuthority { + private static final long serialVersionUID = 1L; + public static final int TYPE_MENU = 0; // 菜单类型 + public static final int TYPE_BTN = 1; // 按钮类型 + + @ApiModelProperty("菜单id") + @TableId(type = IdType.AUTO) + private Integer menuId; + + @ApiModelProperty("上级id, 0是顶级") + private Integer parentId; + + @ApiModelProperty("菜单名称") + private String title; + + @ApiModelProperty("菜单路由地址") + private String path; + + @ApiModelProperty("菜单组件地址") + private String component; + + @ApiModelProperty("菜单类型, 0菜单, 1按钮") + private Integer menuType; + + @ApiModelProperty("排序号") + private Integer sortNumber; + + @ApiModelProperty("权限标识") + private String authority; + + @ApiModelProperty("打开位置") + private String target; + + @ApiModelProperty("菜单图标") + private String icon; + + @ApiModelProperty("图标颜色") + private String color; + + @ApiModelProperty("是否隐藏, 0否, 1是(仅注册路由不显示左侧菜单)") + private Integer hide; + + @ApiModelProperty("侧栏菜单选中的path") + private String active; + + @ApiModelProperty("路由元信息") + private String meta; + + @ApiModelProperty("是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + + @ApiModelProperty("子菜单") + @TableField(exist = false) + private List children; + + @ApiModelProperty("角色权限树选中状态") + @TableField(exist = false) + private Boolean checked; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/OperationRecord.java b/src/main/java/com/eleadmin/common/system/entity/OperationRecord.java new file mode 100644 index 0000000..7b217a5 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/OperationRecord.java @@ -0,0 +1,95 @@ +package com.eleadmin.common.system.entity; + +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 java.io.Serializable; +import java.util.Date; + +/** + * 操作日志 + * + * @author EleAdmin + * @since 2018-12-24 16:10:33 + */ +@Data +@ApiModel(description = "操作日志") +@TableName("sys_operation_record") +public class OperationRecord implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键id") + @TableId(type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("用户id") + private Integer userId; + + @ApiModelProperty("操作模块") + private String module; + + @ApiModelProperty("操作功能") + private String description; + + @ApiModelProperty("请求地址") + private String url; + + @ApiModelProperty("请求方式") + private String requestMethod; + + @ApiModelProperty("调用方法") + private String method; + + @ApiModelProperty("请求参数") + private String params; + + @ApiModelProperty("返回结果") + private String result; + + @ApiModelProperty("异常信息") + private String error; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty("消耗时间, 单位毫秒") + private Long spendTime; + + @ApiModelProperty("操作系统") + private String os; + + @ApiModelProperty("设备名称") + private String device; + + @ApiModelProperty("浏览器类型") + private String browser; + + @ApiModelProperty("ip地址") + private String ip; + + @ApiModelProperty("状态, 0成功, 1异常") + private Integer status; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("操作时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + + @ApiModelProperty("用户昵称") + @TableField(exist = false) + private String nickname; + + @ApiModelProperty("用户账号") + @TableField(exist = false) + private String username; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/Organization.java b/src/main/java/com/eleadmin/common/system/entity/Organization.java new file mode 100644 index 0000000..1cceb1f --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/Organization.java @@ -0,0 +1,77 @@ +package com.eleadmin.common.system.entity; + +import com.baomidou.mybatisplus.annotation.*; + +import java.util.Date; +import java.io.Serializable; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 组织机构 + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +@Data +@ApiModel(description = "组织机构") +@TableName("sys_organization") +public class Organization implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "机构id") + @TableId(type = IdType.AUTO) + private Integer organizationId; + + @ApiModelProperty(value = "上级id, 0是顶级") + private Integer parentId; + + @ApiModelProperty(value = "机构名称") + private String organizationName; + + @ApiModelProperty(value = "机构全称") + private String organizationFullName; + + @ApiModelProperty(value = "机构代码") + private String organizationCode; + + @ApiModelProperty(value = "机构类型, 字典标识") + private String organizationType; + + @ApiModelProperty(value = "负责人id") + private Integer leaderId; + + @ApiModelProperty(value = "排序号") + private Integer sortNumber; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + + @ApiModelProperty(value = "机构类型名称") + @TableField(exist = false) + private String organizationTypeName; + + @ApiModelProperty(value = "负责人姓名") + @TableField(exist = false) + private String leaderNickname; + + @ApiModelProperty(value = "负责人账号") + @TableField(exist = false) + private String leaderUsername; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/Role.java b/src/main/java/com/eleadmin/common/system/entity/Role.java new file mode 100644 index 0000000..a06d447 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/Role.java @@ -0,0 +1,53 @@ +package com.eleadmin.common.system.entity; + +import com.baomidou.mybatisplus.annotation.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 角色 + * + * @author EleAdmin + * @since 2018-12-24 16:10:01 + */ +@Data +@ApiModel(description = "角色") +@TableName("sys_role") +public class Role implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("角色id") + @TableId(type = IdType.AUTO) + private Integer roleId; + + @ApiModelProperty("角色标识") + private String roleCode; + + @ApiModelProperty("角色名称") + private String roleName; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty("是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + + @ApiModelProperty(hidden = true) + @TableField(exist = false) + private Integer userId; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/RoleMenu.java b/src/main/java/com/eleadmin/common/system/entity/RoleMenu.java new file mode 100644 index 0000000..bc057f6 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/RoleMenu.java @@ -0,0 +1,44 @@ +package com.eleadmin.common.system.entity; + +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 EleAdmin + * @since 2018-12-24 16:10:54 + */ +@Data +@ApiModel(description = "角色权限") +@TableName("sys_role_menu") +public class RoleMenu implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键id") + @TableId(type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("角色id") + private Integer roleId; + + @ApiModelProperty("菜单id") + private Integer menuId; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/Tenant.java b/src/main/java/com/eleadmin/common/system/entity/Tenant.java new file mode 100644 index 0000000..dc8208b --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/Tenant.java @@ -0,0 +1,46 @@ +package com.eleadmin.common.system.entity; + +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 io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 租户 + * + * @author EleAdmin + * @since 2021-08-28 11:31:06 + */ +@Data +@ApiModel(description = "租户") +@TableName("sys_tenant") +public class Tenant implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("租户id") + @TableId(type = IdType.AUTO) + private Integer tenantId; + + @ApiModelProperty("租户名称") + private String tenantName; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty("是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/User.java b/src/main/java/com/eleadmin/common/system/entity/User.java new file mode 100644 index 0000000..a350228 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/User.java @@ -0,0 +1,121 @@ +package com.eleadmin.common.system.entity; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Date; +import java.util.List; + +/** + * 用户 + * + * @author EleAdmin + * @since 2018-12-24 16:10:13 + */ +@Data +@ApiModel(description = "用户") +@TableName("sys_user") +public class User implements UserDetails { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("用户id") + @TableId(type = IdType.AUTO) + private Integer userId; + + @ApiModelProperty("账号") + private String username; + + @ApiModelProperty("密码") + private String password; + + @ApiModelProperty("昵称") + private String nickname; + + @ApiModelProperty("头像") + private String avatar; + + @ApiModelProperty("性别, 字典标识") + private String sex; + + @ApiModelProperty("手机号") + private String phone; + + @ApiModelProperty("邮箱") + private String email; + + @ApiModelProperty("邮箱是否验证, 0否, 1是") + private Integer emailVerified; + + @ApiModelProperty("真实姓名") + private String realName; + + @ApiModelProperty("身份证号") + private String idCard; + + @ApiModelProperty("出生日期") + @JsonFormat(pattern = "yyyy-MM-dd") + private Date birthday; + + @ApiModelProperty("个人简介") + private String introduction; + + @ApiModelProperty("机构id") + private Integer organizationId; + + @ApiModelProperty("状态, 0正常, 1冻结") + private Integer status; + + @ApiModelProperty("是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty("注册时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + + @ApiModelProperty("机构名称") + @TableField(exist = false) + private String organizationName; + + @ApiModelProperty("性别名称") + @TableField(exist = false) + private String sexName; + + @ApiModelProperty("角色列表") + @TableField(exist = false) + private List roles; + + @ApiModelProperty("权限列表") + @TableField(exist = false) + private List authorities; + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return this.status != null && this.status == 0; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } + +} diff --git a/src/main/java/com/eleadmin/common/system/entity/UserRole.java b/src/main/java/com/eleadmin/common/system/entity/UserRole.java new file mode 100644 index 0000000..c7b5551 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/entity/UserRole.java @@ -0,0 +1,46 @@ +package com.eleadmin.common.system.entity; + +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 java.io.Serializable; +import java.util.Date; + +/** + * 用户角色 + * + * @author EleAdmin + * @since 2018-12-24 16:10:23 + */ +@Data +@ApiModel(description = "用户角色") +@TableName("sys_user_role") +public class UserRole implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键id") + @TableId(type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("用户id") + private Integer userId; + + @ApiModelProperty("角色id") + private Integer roleId; + + @ApiModelProperty("创建时间") + private Date createTime; + + @ApiModelProperty("修改时间") + private Date updateTime; + + @ApiModelProperty("角色名称") + @TableField(exist = false) + private String roleName; + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/DictionaryDataMapper.java b/src/main/java/com/eleadmin/common/system/mapper/DictionaryDataMapper.java new file mode 100644 index 0000000..999cedc --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/DictionaryDataMapper.java @@ -0,0 +1,47 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.eleadmin.common.system.entity.DictionaryData; +import com.eleadmin.common.system.param.DictionaryDataParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 字典数据Mapper + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +public interface DictionaryDataMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") DictionaryDataParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") DictionaryDataParam param); + + /** + * 根据dictCode和dictDataName查询 + * + * @param dictCode 字典标识 + * @param dictDataName 字典项名称 + * @return List + */ + List getByDictCodeAndName(@Param("dictCode") String dictCode, + @Param("dictDataName") String dictDataName); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/DictionaryMapper.java b/src/main/java/com/eleadmin/common/system/mapper/DictionaryMapper.java new file mode 100644 index 0000000..873c133 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/DictionaryMapper.java @@ -0,0 +1,14 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.eleadmin.common.system.entity.Dictionary; + +/** + * 字典Mapper + * + * @author EleAdmin + * @since 2020-03-14 11:29:03 + */ +public interface DictionaryMapper extends BaseMapper { + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/EmailRecordMapper.java b/src/main/java/com/eleadmin/common/system/mapper/EmailRecordMapper.java new file mode 100644 index 0000000..1da32b7 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/EmailRecordMapper.java @@ -0,0 +1,14 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.eleadmin.common.system.entity.EmailRecord; + +/** + * 邮件记录Mapper + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +public interface EmailRecordMapper extends BaseMapper { + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/FileRecordMapper.java b/src/main/java/com/eleadmin/common/system/mapper/FileRecordMapper.java new file mode 100644 index 0000000..42400ec --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/FileRecordMapper.java @@ -0,0 +1,37 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.eleadmin.common.system.entity.FileRecord; +import com.eleadmin.common.system.param.FileRecordParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 文件上传记录Mapper + * + * @author EleAdmin + * @since 2021-08-30 11:18:04 + */ +public interface FileRecordMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") FileRecordParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") FileRecordParam param); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/GoodsMapper.java b/src/main/java/com/eleadmin/common/system/mapper/GoodsMapper.java new file mode 100644 index 0000000..e4d3c6d --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/GoodsMapper.java @@ -0,0 +1,4 @@ +package com.eleadmin.common.system.mapper; + +public interface GoodsMapper { +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/LoginRecordMapper.java b/src/main/java/com/eleadmin/common/system/mapper/LoginRecordMapper.java new file mode 100644 index 0000000..b17e651 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/LoginRecordMapper.java @@ -0,0 +1,48 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.eleadmin.common.system.entity.LoginRecord; +import com.eleadmin.common.system.param.LoginRecordParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 登录日志Mapper + * + * @author EleAdmin + * @since 2018-12-24 16:10:11 + */ +public interface LoginRecordMapper extends BaseMapper { + + /** + * 添加, 排除租户拦截 + * + * @param entity LoginRecord + * @return int + */ + @Override + @InterceptorIgnore(tenantLine = "true") + int insert(LoginRecord entity); + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") LoginRecordParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") LoginRecordParam param); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/MenuMapper.java b/src/main/java/com/eleadmin/common/system/mapper/MenuMapper.java new file mode 100644 index 0000000..9758257 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/MenuMapper.java @@ -0,0 +1,14 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.eleadmin.common.system.entity.Menu; + +/** + * 菜单Mapper + * + * @author EleAdmin + * @since 2018-12-24 16:10:32 + */ +public interface MenuMapper extends BaseMapper { + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/OperationRecordMapper.java b/src/main/java/com/eleadmin/common/system/mapper/OperationRecordMapper.java new file mode 100644 index 0000000..af6394a --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/OperationRecordMapper.java @@ -0,0 +1,48 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.eleadmin.common.system.entity.OperationRecord; +import com.eleadmin.common.system.param.OperationRecordParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 操作日志Mapper + * + * @author EleAdmin + * @since 2018-12-24 16:10:03 + */ +public interface OperationRecordMapper extends BaseMapper { + + /** + * 添加, 排除租户拦截 + * + * @param entity OperationRecord + * @return int + */ + @Override + @InterceptorIgnore(tenantLine = "true") + int insert(OperationRecord entity); + + /** + * 分页查询 + * + * @param page 分页参数 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") OperationRecordParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") OperationRecordParam param); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/OrganizationMapper.java b/src/main/java/com/eleadmin/common/system/mapper/OrganizationMapper.java new file mode 100644 index 0000000..965cc05 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/OrganizationMapper.java @@ -0,0 +1,37 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.eleadmin.common.system.entity.Organization; +import com.eleadmin.common.system.param.OrganizationParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 组织机构Mapper + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +public interface OrganizationMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") OrganizationParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") OrganizationParam param); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/RoleMapper.java b/src/main/java/com/eleadmin/common/system/mapper/RoleMapper.java new file mode 100644 index 0000000..d551e11 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/RoleMapper.java @@ -0,0 +1,14 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.eleadmin.common.system.entity.Role; + +/** + * 角色Mapper + * + * @author EleAdmin + * @since 2018-12-24 16:10:44 + */ +public interface RoleMapper extends BaseMapper { + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/RoleMenuMapper.java b/src/main/java/com/eleadmin/common/system/mapper/RoleMenuMapper.java new file mode 100644 index 0000000..784482e --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/RoleMenuMapper.java @@ -0,0 +1,39 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.entity.RoleMenu; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 角色菜单Mapper + * + * @author EleAdmin + * @since 2018-12-24 16:10:21 + */ +public interface RoleMenuMapper extends BaseMapper { + + /** + * 查询用户的菜单 + * + * @param userId 用户id + * @param menuType 菜单类型 + * @return List + */ + @InterceptorIgnore(tenantLine = "true") + List listMenuByUserId(@Param("userId") Integer userId, @Param("menuType") Integer menuType); + + /** + * 根据角色id查询菜单 + * + * @param roleIds 角色id + * @param menuType 菜单类型 + * @return List + */ + @InterceptorIgnore(tenantLine = "true") + List listMenuByRoleIds(@Param("roleIds") List roleIds, @Param("menuType") Integer menuType); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/UserMapper.java b/src/main/java/com/eleadmin/common/system/mapper/UserMapper.java new file mode 100644 index 0000000..9d07ad2 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/UserMapper.java @@ -0,0 +1,48 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.eleadmin.common.system.entity.User; +import com.eleadmin.common.system.param.UserParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 用户Mapper + * + * @author EleAdmin + * @since 2018-12-24 16:10:14 + */ +public interface UserMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") UserParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") UserParam param); + + /** + * 根据账号查询 + * + * @param username 账号 + * @param tenantId 租户id + * @return User + */ + @InterceptorIgnore(tenantLine = "true") + User selectByUsername(@Param("username") String username, @Param("tenantId") Integer tenantId); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/UserRoleMapper.java b/src/main/java/com/eleadmin/common/system/mapper/UserRoleMapper.java new file mode 100644 index 0000000..b9ad78c --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/UserRoleMapper.java @@ -0,0 +1,45 @@ +package com.eleadmin.common.system.mapper; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.eleadmin.common.system.entity.Role; +import com.eleadmin.common.system.entity.UserRole; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 用户角色Mapper + * + * @author EleAdmin + * @since 2018-12-24 16:10:02 + */ +public interface UserRoleMapper extends BaseMapper { + + /** + * 批量添加用户角色 + * + * @param userId 用户id + * @param roleIds 角色id集合 + * @return int + */ + int insertBatch(@Param("userId") Integer userId, @Param("roleIds") List roleIds); + + /** + * 根据用户id查询角色 + * + * @param userId 用户id + * @return List + */ + @InterceptorIgnore(tenantLine = "true") + List selectByUserId(@Param("userId") Integer userId); + + /** + * 批量根据用户id查询角色 + * + * @param userIds 用户id集合 + * @return List + */ + List selectByUserIds(@Param("userIds") List userIds); + +} diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/DictionaryDataMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/DictionaryDataMapper.xml new file mode 100644 index 0000000..dc0ff9e --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/DictionaryDataMapper.xml @@ -0,0 +1,71 @@ + + + + + + + SELECT a.*, + b.dict_code, + b.dict_name + FROM sys_dictionary_data a + LEFT JOIN sys_dictionary b ON a.dict_id = b.dict_id + + AND a.deleted = 0 + + AND a.dict_data_id = #{param.dictDataId} + + + AND a.dict_id = #{param.dictId} + + + AND a.dict_data_code LIKE CONCAT('%', #{param.dictDataCode}, '%') + + + AND a.dict_data_name LIKE CONCAT('%', #{param.dictDataName}, '%') + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND b.dict_code = #{param.dictCode} + + + AND b.dict_name = #{param.dictName} + + + AND ( + a.dict_data_code LIKE CONCAT('%', #{param.keywords}, '%') + OR a.dict_data_name LIKE CONCAT('%', #{param.keywords}, '%') + ) + + + + + + + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/DictionaryMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/DictionaryMapper.xml new file mode 100644 index 0000000..bd5f10f --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/DictionaryMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/EmailRecordMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/EmailRecordMapper.xml new file mode 100644 index 0000000..b1fe884 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/EmailRecordMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/FileRecordMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/FileRecordMapper.xml new file mode 100644 index 0000000..4b4dc96 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/FileRecordMapper.xml @@ -0,0 +1,53 @@ + + + + + + + SELECT a.*, + b.username create_username, + b.nickname create_nickname + FROM sys_file_record a + LEFT JOIN sys_user b ON a.create_user_id = b.user_id + + + AND a.id = #{param.id} + + + AND a.name LIKE CONCAT('%', #{param.name}, '%') + + + AND a.path LIKE CONCAT('%', #{param.path}, '%') + + + AND a.create_user_id = #{param.createUserId} + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND b.username = #{param.createUsername} + + + AND b.nickname LIKE CONCAT('%', #{param.createNickname}, '%') + + + + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/LoginRecordMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/LoginRecordMapper.xml new file mode 100644 index 0000000..1cacef8 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/LoginRecordMapper.xml @@ -0,0 +1,62 @@ + + + + + + + SELECT a.*, + b.user_id, + b.nickname + FROM sys_login_record a + LEFT JOIN sys_user b ON a.username = b.username + + + AND a.id = #{param.id} + + + AND a.username LIKE CONCAT('%', #{param.username}, '%') + + + AND a.os LIKE CONCAT('%', #{param.os}, '%') + + + AND a.device LIKE CONCAT('%', #{param.device}, '%') + + + AND a.browser LIKE CONCAT('%', #{param.browser}, '%') + + + AND a.ip LIKE CONCAT('%', #{param.ip}, '%') + + + AND a.login_type LIKE CONCAT('%', #{param.loginType}, '%') + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND b.user_id = #{param.userId} + + + AND b.nickname LIKE CONCAT('%', #{param.nickname}, '%') + + + + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/MenuMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/MenuMapper.xml new file mode 100644 index 0000000..227011c --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/MenuMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/OperationRecordMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/OperationRecordMapper.xml new file mode 100644 index 0000000..cb83d9f --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/OperationRecordMapper.xml @@ -0,0 +1,71 @@ + + + + + + + SELECT a.*, + b.nickname, + b.username + FROM sys_operation_record a + LEFT JOIN sys_user b ON a.user_id = b.user_id + + + AND a.id = #{param.id} + + + AND a.user_id = #{param.userId} + + + AND a.module LIKE CONCAT('%', #{param.module}, '%') + + + AND a.description LIKE CONCAT('%', #{param.description}, '%') + + + AND a.url LIKE CONCAT('%', #{param.url}, '%') + + + AND a.request_method = #{param.requestMethod} + + + AND a.method LIKE CONCAT('%', #{param.method}, '%') + + + AND a.description LIKE CONCAT('%', #{param.description}, '%') + + + AND a.ip LIKE CONCAT('%', #{param.ip}, '%') + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.status = #{param.status} + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND b.username LIKE CONCAT('%', #{param.username}, '%') + + + AND b.nickname LIKE CONCAT('%', #{param.nickname}, '%') + + + + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/OrganizationMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/OrganizationMapper.xml new file mode 100644 index 0000000..95f7ed5 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/OrganizationMapper.xml @@ -0,0 +1,81 @@ + + + + + + + SELECT ta.* + FROM sys_dictionary_data ta + LEFT JOIN sys_dictionary tb + ON ta.dict_id = tb.dict_id + AND tb.deleted = 0 + WHERE ta.deleted = 0 + AND tb.dict_code = 'organization_type' + + + + + SELECT a.*, + b.dict_data_name organization_type_name, + c.nickname leader_nickname, + c.username leader_username + FROM sys_organization a + LEFT JOIN ( + + ) b ON a.organization_type = b.dict_data_code + LEFT JOIN sys_user c ON a.leader_id = c.user_id + + AND a.deleted = 0 + + AND a.organization_id = #{param.organizationId} + + + AND a.parent_id = #{param.parentId} + + + AND a.organization_name LIKE CONCAT('%', #{param.organizationName}, '%') + + + AND a.organization_full_name LIKE CONCAT('%', #{param.organizationFullName}, '%') + + + AND a.organization_code LIKE CONCAT('%', #{param.organizationCode}, '%') + + + AND a.organization_type = #{param.organizationType} + + + AND a.leader_id = #{param.leaderId} + + + AND a.comments LIKE CONCAT('%', #{param.comments}, '%') + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND b.dict_data_name LIKE CONCAT('%', #{param.organizationTypeName}, '%') + + + AND c.nickname LIKE CONCAT('%', #{param.leaderNickname}, '%') + + + AND c.username LIKE CONCAT('%', #{param.leaderUsername}, '%') + + + + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/RoleMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/RoleMapper.xml new file mode 100644 index 0000000..aa5223d --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/RoleMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/RoleMenuMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/RoleMenuMapper.xml new file mode 100644 index 0000000..1d2b6ac --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/RoleMenuMapper.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/UserMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/UserMapper.xml new file mode 100644 index 0000000..c5c55b6 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/UserMapper.xml @@ -0,0 +1,140 @@ + + + + + + + SELECT ta.* + FROM sys_dictionary_data ta + LEFT JOIN sys_dictionary tb + ON ta.dict_id = tb.dict_id + AND tb.deleted = 0 + WHERE ta.deleted = 0 + AND tb.dict_code = 'sex' + + + + + SELECT a.user_id, + GROUP_CONCAT(b.role_name) role_name + FROM sys_user_role a + LEFT JOIN sys_role b ON a.role_id = b.role_id + GROUP BY a.user_id + + + + + SELECT a.*, + b.organization_name, + c.dict_data_name sex_name + FROM sys_user a + LEFT JOIN sys_organization b ON a.organization_id = b.organization_id + LEFT JOIN ( + + ) c ON a.sex = c.dict_data_code + LEFT JOIN( + + ) d ON a.user_id = d.user_id + + + AND a.user_id = #{param.userId} + + + AND a.username LIKE CONCAT('%', #{param.username}, '%') + + + AND a.nickname LIKE CONCAT('%', #{param.nickname}, '%') + + + AND a.sex = #{param.sex} + + + AND a.phone LIKE CONCAT('%', #{param.phone}, '%') + + + AND a.email LIKE CONCAT('%', #{param.email}, '%') + + + AND a.email_verified = #{param.emailVerified} + + + AND a.real_name LIKE CONCAT('%', #{param.realName}, '%') + + + AND a.id_card LIKE CONCAT('%', #{param.idCard}, '%') + + + AND a.birthday LIKE CONCAT('%', #{param.birthday}, '%') + + + AND a.organization_id = #{param.organizationId} + + + AND a.status = #{param.status} + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND a.deleted = #{param.deleted} + + + AND a.deleted = 0 + + + AND a.user_id IN (SELECT user_id FROM sys_user_role WHERE role_id=#{param.roleId}) + + + AND b.organization_name LIKE CONCAT('%', #{param.organizationName}, '%') + + + AND c.dict_data_name = #{param.sexName} + + + AND ( + a.username LIKE CONCAT('%', #{param.keywords}, '%') + OR a.nickname LIKE CONCAT('%', #{param.keywords}, '%') + OR b.organization_name LIKE CONCAT('%', #{param.keywords}, '%') + OR c.dict_data_name LIKE CONCAT('%', #{param.keywords}, '%') + OR d.role_name LIKE CONCAT('%', #{param.keywords}, '%') + ) + + + + + + + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/mapper/xml/UserRoleMapper.xml b/src/main/java/com/eleadmin/common/system/mapper/xml/UserRoleMapper.xml new file mode 100644 index 0000000..e93ff5d --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/mapper/xml/UserRoleMapper.xml @@ -0,0 +1,34 @@ + + + + + + INSERT INTO sys_user_role(user_id, role_id) VALUES + + (#{userId}, #{roleId}) + + + + + + + + diff --git a/src/main/java/com/eleadmin/common/system/param/DictionaryDataParam.java b/src/main/java/com/eleadmin/common/system/param/DictionaryDataParam.java new file mode 100644 index 0000000..233c6cb --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/DictionaryDataParam.java @@ -0,0 +1,55 @@ +package com.eleadmin.common.system.param; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 字典数据查询参数 + * + * @author EleAdmin + * @since 2021-08-28 22:12:02 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "字典数据查询参数") +public class DictionaryDataParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "字典数据id") + @QueryField(type = QueryType.EQ) + private Integer dictDataId; + + @ApiModelProperty(value = "字典id") + @QueryField(type = QueryType.EQ) + private Integer dictId; + + @ApiModelProperty(value = "字典数据标识") + private String dictDataCode; + + @ApiModelProperty(value = "字典数据名称") + private String dictDataName; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "字典代码") + @TableField(exist = false) + private String dictCode; + + @ApiModelProperty(value = "字典名称") + @TableField(exist = false) + private String dictName; + + @ApiModelProperty(value = "字典数据代码或字典数据名称") + @TableField(exist = false) + private String keywords; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/DictionaryParam.java b/src/main/java/com/eleadmin/common/system/param/DictionaryParam.java new file mode 100644 index 0000000..ab147ce --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/DictionaryParam.java @@ -0,0 +1,38 @@ +package com.eleadmin.common.system.param; + +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 字典查询参数 + * + * @author EleAdmin + * @since 2021-08-28 22:12:01 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "字典查询参数") +public class DictionaryParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @QueryField(type = QueryType.EQ) + @ApiModelProperty(value = "字典id") + private Integer dictId; + + @ApiModelProperty(value = "字典标识") + private String dictCode; + + @ApiModelProperty(value = "字典名称") + private String dictName; + + @ApiModelProperty(value = "备注") + private String comments; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/FileRecordParam.java b/src/main/java/com/eleadmin/common/system/param/FileRecordParam.java new file mode 100644 index 0000000..89c6ab4 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/FileRecordParam.java @@ -0,0 +1,51 @@ +package com.eleadmin.common.system.param; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 文件上传记录查询参数 + * + * @author EleAdmin + * @since 2021-08-30 11:29:31 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "文件上传记录查询参数") +public class FileRecordParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @QueryField(type = QueryType.EQ) + @ApiModelProperty("主键id") + private Integer id; + + @ApiModelProperty("文件名称") + private String name; + + @ApiModelProperty("文件存储路径") + private String path; + + @QueryField(type = QueryType.EQ) + @ApiModelProperty("创建人") + private Integer createUserId; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty("创建人账号") + @TableField(exist = false) + private String createUsername; + + @ApiModelProperty("创建人名称") + @TableField(exist = false) + private String createNickname; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/GoodsParam.java b/src/main/java/com/eleadmin/common/system/param/GoodsParam.java new file mode 100644 index 0000000..a8d43a2 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/GoodsParam.java @@ -0,0 +1,27 @@ +package com.eleadmin.common.system.param; + +import com.eleadmin.common.core.web.BaseParam; +import io.swagger.annotations.ApiModelProperty; + +import java.math.BigDecimal; +import java.util.Date; + +public class GoodsParam extends BaseParam { + + @ApiModelProperty("商品编码") + private Long goodsId; + @ApiModelProperty("商品名称") + private String title; + @ApiModelProperty("类型") + private String goodsType; + @ApiModelProperty("商品价格") + private BigDecimal price; + @ApiModelProperty("创建时间") + private Date createTime; + @ApiModelProperty("创建人") + private Integer creator; + @ApiModelProperty("修改时间") + private Date changeDate; + @ApiModelProperty("修改人") + private Integer changorId; +} diff --git a/src/main/java/com/eleadmin/common/system/param/LoginParam.java b/src/main/java/com/eleadmin/common/system/param/LoginParam.java new file mode 100644 index 0000000..aaff43b --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/LoginParam.java @@ -0,0 +1,31 @@ +package com.eleadmin.common.system.param; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 登录参数 + * + * @author EleAdmin + * @since 2021-08-30 17:35:16 + */ +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "登录参数") +public class LoginParam implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("账号") + private String username; + + @ApiModelProperty("密码") + private String password; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/LoginRecordParam.java b/src/main/java/com/eleadmin/common/system/param/LoginRecordParam.java new file mode 100644 index 0000000..2805e15 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/LoginRecordParam.java @@ -0,0 +1,60 @@ +package com.eleadmin.common.system.param; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 登录日志查询参数 + * + * @author EleAdmin + * @since 2021-08-29 19:09:23 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "登录日志查询参数") +public class LoginRecordParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @QueryField(type = QueryType.EQ) + @ApiModelProperty("主键id") + private Integer id; + + @ApiModelProperty("用户账号") + private String username; + + @ApiModelProperty("操作系统") + private String os; + + @ApiModelProperty("设备名") + private String device; + + @ApiModelProperty("浏览器类型") + private String browser; + + @ApiModelProperty("ip地址") + private String ip; + + @QueryField(type = QueryType.EQ) + @ApiModelProperty("操作类型, 0登录成功, 1登录失败, 2退出登录, 3续签token") + private Integer loginType; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty("用户id") + @TableField(exist = false) + private Integer userId; + + @ApiModelProperty("用户昵称") + @TableField(exist = false) + private String nickname; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/MenuParam.java b/src/main/java/com/eleadmin/common/system/param/MenuParam.java new file mode 100644 index 0000000..63ca8b6 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/MenuParam.java @@ -0,0 +1,56 @@ +package com.eleadmin.common.system.param; + +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 菜单查询参数 + * + * @author EleAdmin + * @since 2021-08-29 19:36:10 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "菜单查询参数") +public class MenuParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("菜单id") + @QueryField(type = QueryType.EQ) + private Integer menuId; + + @ApiModelProperty("上级id, 0是顶级") + @QueryField(type = QueryType.EQ) + private Integer parentId; + + @ApiModelProperty("菜单名称") + private String title; + + @ApiModelProperty("菜单路由关键字") + private String path; + + @ApiModelProperty("菜单组件地址") + private String component; + + @ApiModelProperty("菜单类型, 0菜单, 1按钮") + @QueryField(type = QueryType.EQ) + private Integer menuType; + + @ApiModelProperty("权限标识") + private String authority; + + @ApiModelProperty("菜单图标") + private String icon; + + @ApiModelProperty("是否隐藏, 0否, 1是(仅注册路由不显示左侧菜单)") + @QueryField(type = QueryType.EQ) + private Integer hide; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/OperationRecordParam.java b/src/main/java/com/eleadmin/common/system/param/OperationRecordParam.java new file mode 100644 index 0000000..8cf7d31 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/OperationRecordParam.java @@ -0,0 +1,67 @@ +package com.eleadmin.common.system.param; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 操作日志参数 + * + * @author EleAdmin + * @since 2021-08-29 20:35:09 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "操作日志参数") +public class OperationRecordParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键id") + @QueryField(type = QueryType.EQ) + private Integer id; + + @ApiModelProperty("用户id") + @QueryField(type = QueryType.EQ) + private Integer userId; + + @ApiModelProperty("操作模块") + private String module; + + @ApiModelProperty("操作功能") + private String description; + + @ApiModelProperty("请求地址") + private String url; + + @ApiModelProperty("请求方式") + private String requestMethod; + + @ApiModelProperty("调用方法") + private String method; + + @ApiModelProperty("ip地址") + private String ip; + + @ApiModelProperty("备注") + private String comments; + + @ApiModelProperty("状态, 0成功, 1异常") + @QueryField(type = QueryType.EQ) + private Integer status; + + @ApiModelProperty("用户账号") + @TableField(exist = false) + private String username; + + @ApiModelProperty("用户昵称") + @TableField(exist = false) + private String nickname; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/OrganizationParam.java b/src/main/java/com/eleadmin/common/system/param/OrganizationParam.java new file mode 100644 index 0000000..f3166c6 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/OrganizationParam.java @@ -0,0 +1,65 @@ +package com.eleadmin.common.system.param; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 组织机构查询参数 + * + * @author EleAdmin + * @since 2021-08-29 20:35:09 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "组织机构查询参数") +public class OrganizationParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "机构id") + @QueryField(type = QueryType.EQ) + private Integer organizationId; + + @ApiModelProperty(value = "上级id, 0是顶级") + @QueryField(type = QueryType.EQ) + private Integer parentId; + + @ApiModelProperty(value = "机构名称") + private String organizationName; + + @ApiModelProperty(value = "机构全称") + private String organizationFullName; + + @ApiModelProperty(value = "机构代码") + private String organizationCode; + + @ApiModelProperty(value = "机构类型(字典代码)") + private String organizationType; + + @ApiModelProperty(value = "负责人id") + @QueryField(type = QueryType.EQ) + private Integer leaderId; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "机构类型名称") + @TableField(exist = false) + private String organizationTypeName; + + @ApiModelProperty(value = "负责人姓名") + @TableField(exist = false) + private String leaderNickname; + + @ApiModelProperty(value = "负责人账号") + @TableField(exist = false) + private String leaderUsername; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/RoleParam.java b/src/main/java/com/eleadmin/common/system/param/RoleParam.java new file mode 100644 index 0000000..900fb76 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/RoleParam.java @@ -0,0 +1,38 @@ +package com.eleadmin.common.system.param; + +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 角色查询参数 + * + * @author EleAdmin + * @since 2021-08-29 20:35:09 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "角色查询参数") +public class RoleParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("角色id") + @QueryField(type = QueryType.EQ) + private Integer roleId; + + @ApiModelProperty("角色标识") + private String roleCode; + + @ApiModelProperty("角色名称") + private String roleName; + + @ApiModelProperty("备注") + private String comments; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/UpdatePasswordParam.java b/src/main/java/com/eleadmin/common/system/param/UpdatePasswordParam.java new file mode 100644 index 0000000..d0e9b33 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/UpdatePasswordParam.java @@ -0,0 +1,28 @@ +package com.eleadmin.common.system.param; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 修改密码参数 + * + * @author EleAdmin + * @since 2021-08-30 17:35:16 + */ +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "修改密码参数") +public class UpdatePasswordParam implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("原始密码") + private String oldPassword; + + @ApiModelProperty("新密码") + private String password; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/UserImportParam.java b/src/main/java/com/eleadmin/common/system/param/UserImportParam.java new file mode 100644 index 0000000..219fa27 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/UserImportParam.java @@ -0,0 +1,42 @@ +package com.eleadmin.common.system.param; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.io.Serializable; + +/** + * 用户导入参数 + * + * @author EleAdmin + * @since 2011-10-15 17:33:34 + */ +@Data +public class UserImportParam implements Serializable { + private static final long serialVersionUID = 1L; + + @Excel(name = "账号") + private String username; + + @Excel(name = "密码") + private String password; + + @Excel(name = "昵称") + private String nickname; + + @Excel(name = "手机号") + private String phone; + + @Excel(name = "邮箱") + private String email; + + @Excel(name = "组织机构") + private String organizationName; + + @Excel(name = "性别") + private String sexName; + + @Excel(name = "角色") + private String roleName; + +} diff --git a/src/main/java/com/eleadmin/common/system/param/UserParam.java b/src/main/java/com/eleadmin/common/system/param/UserParam.java new file mode 100644 index 0000000..e684eed --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/param/UserParam.java @@ -0,0 +1,88 @@ +package com.eleadmin.common.system.param; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.eleadmin.common.core.annotation.QueryField; +import com.eleadmin.common.core.annotation.QueryType; +import com.eleadmin.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 用户查询参数 + * + * @author EleAdmin + * @since 2021-08-29 20:35:09 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(description = "用户查询参数") +public class UserParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("用户id") + @QueryField(type = QueryType.EQ) + private Integer userId; + + @ApiModelProperty("账号") + private String username; + + @ApiModelProperty("昵称") + private String nickname; + + @ApiModelProperty("性别(字典)") + @QueryField(type = QueryType.EQ) + private String sex; + + @ApiModelProperty("手机号") + private String phone; + + @ApiModelProperty("邮箱") + private String email; + + @ApiModelProperty("邮箱是否验证, 0否, 1是") + @QueryField(type = QueryType.EQ) + private Integer emailVerified; + + @ApiModelProperty("真实姓名") + private String realName; + + @ApiModelProperty("身份证号") + private String idCard; + + @ApiModelProperty("出生日期") + private String birthday; + + @ApiModelProperty("机构id") + @QueryField(type = QueryType.EQ) + private Integer organizationId; + + @ApiModelProperty("状态, 0正常, 1冻结") + @QueryField(type = QueryType.EQ) + private Integer status; + + @ApiModelProperty("是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty("角色id") + @TableField(exist = false) + private Integer roleId; + + @ApiModelProperty("机构名称") + @TableField(exist = false) + private String organizationName; + + @ApiModelProperty("性别名称") + @TableField(exist = false) + private String sexName; + + @ApiModelProperty("搜索关键字") + @TableField(exist = false) + private String keywords; + +} diff --git a/src/main/java/com/eleadmin/common/system/result/CaptchaResult.java b/src/main/java/com/eleadmin/common/system/result/CaptchaResult.java new file mode 100644 index 0000000..53c4d72 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/result/CaptchaResult.java @@ -0,0 +1,30 @@ +package com.eleadmin.common.system.result; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 验证码返回结果 + * + * @author EleAdmin + * @since 2021-08-30 17:35:16 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(description = "验证码返回结果") +public class CaptchaResult implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("图形验证码base64数据") + private String base64; + + @ApiModelProperty("验证码文本") + private String text; + +} diff --git a/src/main/java/com/eleadmin/common/system/result/LoginResult.java b/src/main/java/com/eleadmin/common/system/result/LoginResult.java new file mode 100644 index 0000000..e910b24 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/result/LoginResult.java @@ -0,0 +1,31 @@ +package com.eleadmin.common.system.result; + +import com.eleadmin.common.system.entity.User; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 登录返回结果 + * + * @author EleAdmin + * @since 2021-08-30 17:35:16 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(description = "登录返回结果") +public class LoginResult implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("access_token") + private String access_token; + + @ApiModelProperty("用户信息") + private User user; + +} diff --git a/src/main/java/com/eleadmin/common/system/service/DictionaryDataService.java b/src/main/java/com/eleadmin/common/system/service/DictionaryDataService.java new file mode 100644 index 0000000..e9df6ea --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/DictionaryDataService.java @@ -0,0 +1,51 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.DictionaryData; +import com.eleadmin.common.system.param.DictionaryDataParam; + +import java.util.List; + +/** + * 字典数据Service + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +public interface DictionaryDataService extends IService { + + /** + * 关联分页查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(DictionaryDataParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(DictionaryDataParam param); + + /** + * 根据id查询 + * + * @param dictDataId 字典数据id + * @return DictionaryData + */ + DictionaryData getByIdRel(Integer dictDataId); + + /** + * 根据dictCode和dictDataName查询 + * + * @param dictCode 字典标识 + * @param dictDataName 字典项名称 + * @return DictionaryData + */ + DictionaryData getByDictCodeAndName(String dictCode, String dictDataName); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/DictionaryService.java b/src/main/java/com/eleadmin/common/system/service/DictionaryService.java new file mode 100644 index 0000000..5821649 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/DictionaryService.java @@ -0,0 +1,14 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.system.entity.Dictionary; + +/** + * 字典Service + * + * @author EleAdmin + * @since 2020-03-14 11:29:03 + */ +public interface DictionaryService extends IService { + +} diff --git a/src/main/java/com/eleadmin/common/system/service/EmailRecordService.java b/src/main/java/com/eleadmin/common/system/service/EmailRecordService.java new file mode 100644 index 0000000..5cd5d95 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/EmailRecordService.java @@ -0,0 +1,50 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.system.entity.EmailRecord; + +import javax.mail.MessagingException; +import java.io.IOException; +import java.util.Map; + +/** + * 邮件发送记录Service + * + * @author EleAdmin + * @since 2019-06-19 04:07:02 + */ +public interface EmailRecordService extends IService { + + /** + * 发送普通邮件 + * + * @param title 标题 + * @param content 内容 + * @param toEmails 收件人 + */ + void sendTextEmail(String title, String content, String[] toEmails); + + /** + * 发送富文本邮件 + * + * @param title 标题 + * @param html 富文本 + * @param toEmails 收件人 + * @throws MessagingException MessagingException + */ + void sendFullTextEmail(String title, String html, String[] toEmails) throws MessagingException; + + /** + * 发送模板邮件 + * + * @param title 标题 + * @param path 模板路径 + * @param map 填充数据 + * @param toEmails 收件人 + * @throws MessagingException MessagingException + * @throws IOException IOException + */ + void sendHtmlEmail(String title, String path, Map map, String[] toEmails) + throws MessagingException, IOException; + +} diff --git a/src/main/java/com/eleadmin/common/system/service/FileRecordService.java b/src/main/java/com/eleadmin/common/system/service/FileRecordService.java new file mode 100644 index 0000000..6a65840 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/FileRecordService.java @@ -0,0 +1,42 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.FileRecord; +import com.eleadmin.common.system.param.FileRecordParam; + +import java.util.List; + +/** + * 文件上传记录Service + * + * @author EleAdmin + * @since 2021-08-30 11:20:15 + */ +public interface FileRecordService extends IService { + + /** + * 关联分页查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(FileRecordParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(FileRecordParam param); + + /** + * 根据id查询 + * + * @param id id + * @return FileRecord + */ + FileRecord getByIdRel(Integer id); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/GoodsService.java b/src/main/java/com/eleadmin/common/system/service/GoodsService.java new file mode 100644 index 0000000..f26ea79 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/GoodsService.java @@ -0,0 +1,4 @@ +package com.eleadmin.common.system.service; + +public interface GoodsService { +} diff --git a/src/main/java/com/eleadmin/common/system/service/LoginRecordService.java b/src/main/java/com/eleadmin/common/system/service/LoginRecordService.java new file mode 100644 index 0000000..1dfe4dc --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/LoginRecordService.java @@ -0,0 +1,54 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.LoginRecord; +import com.eleadmin.common.system.param.LoginRecordParam; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * 登录日志Service + * + * @author EleAdmin + * @since 2018-12-24 16:10:41 + */ +public interface LoginRecordService extends IService { + + /** + * 关联分页查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(LoginRecordParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(LoginRecordParam param); + + /** + * 根据id查询 + * + * @param id id + * @return LoginRecord + */ + LoginRecord getByIdRel(Integer id); + + /** + * 异步添加 + * + * @param username 用户账号 + * @param type 操作类型 + * @param comments 备注 + * @param tenantId 租户id + * @param request HttpServletRequest + */ + void saveAsync(String username, Integer type, String comments, Integer tenantId, HttpServletRequest request); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/MenuService.java b/src/main/java/com/eleadmin/common/system/service/MenuService.java new file mode 100644 index 0000000..4a4808c --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/MenuService.java @@ -0,0 +1,14 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.system.entity.Menu; + +/** + * 菜单Service + * + * @author EleAdmin + * @since 2018-12-24 16:10:31 + */ +public interface MenuService extends IService { + +} diff --git a/src/main/java/com/eleadmin/common/system/service/OperationRecordService.java b/src/main/java/com/eleadmin/common/system/service/OperationRecordService.java new file mode 100644 index 0000000..5e9068c --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/OperationRecordService.java @@ -0,0 +1,49 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.OperationRecord; +import com.eleadmin.common.system.param.OperationRecordParam; + +import java.util.List; + +/** + * 操作日志Service + * + * @author EleAdmin + * @since 2018-12-24 16:10:01 + */ +public interface OperationRecordService extends IService { + + /** + * 关联分页查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(OperationRecordParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(OperationRecordParam param); + + /** + * 根据id查询 + * + * @param id id + * @return OperationRecord + */ + OperationRecord getByIdRel(Integer id); + + /** + * 异步添加 + * + * @param operationRecord OperationRecord + */ + void saveAsync(OperationRecord operationRecord); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/OrganizationService.java b/src/main/java/com/eleadmin/common/system/service/OrganizationService.java new file mode 100644 index 0000000..16e8688 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/OrganizationService.java @@ -0,0 +1,42 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.Organization; +import com.eleadmin.common.system.param.OrganizationParam; + +import java.util.List; + +/** + * 组织机构Service + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +public interface OrganizationService extends IService { + + /** + * 关联分页查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(OrganizationParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(OrganizationParam param); + + /** + * 根据id查询 + * + * @param organizationId 机构id + * @return Organization + */ + Organization getByIdRel(Integer organizationId); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/RoleMenuService.java b/src/main/java/com/eleadmin/common/system/service/RoleMenuService.java new file mode 100644 index 0000000..912178c --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/RoleMenuService.java @@ -0,0 +1,35 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.entity.RoleMenu; + +import java.util.List; + +/** + * 角色菜单Service + * + * @author EleAdmin + * @since 2018-12-24 16:10:44 + */ +public interface RoleMenuService extends IService { + + /** + * 查询用户对应的菜单 + * + * @param userId 用户id + * @param menuType 菜单类型 + * @return List + */ + List listMenuByUserId(Integer userId, Integer menuType); + + /** + * 查询用户对应的菜单 + * + * @param roleIds 角色id + * @param menuType 菜单类型 + * @return List + */ + List listMenuByRoleIds(List roleIds, Integer menuType); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/RoleService.java b/src/main/java/com/eleadmin/common/system/service/RoleService.java new file mode 100644 index 0000000..1bc45d4 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/RoleService.java @@ -0,0 +1,14 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.system.entity.Role; + +/** + * 角色Service + * + * @author EleAdmin + * @since 2018-12-24 16:10:32 + */ +public interface RoleService extends IService { + +} diff --git a/src/main/java/com/eleadmin/common/system/service/UserRoleService.java b/src/main/java/com/eleadmin/common/system/service/UserRoleService.java new file mode 100644 index 0000000..71f7598 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/UserRoleService.java @@ -0,0 +1,42 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.system.entity.Role; +import com.eleadmin.common.system.entity.UserRole; + +import java.util.List; + +/** + * 用户角色Service + * + * @author EleAdmin + * @since 2018-12-24 16:10:35 + */ +public interface UserRoleService extends IService { + + /** + * 批量添加用户角色 + * + * @param userId 用户id + * @param roleIds 角色id集合 + * @return int + */ + int saveBatch(Integer userId, List roleIds); + + /** + * 根据用户id查询角色 + * + * @param userId 用户id + * @return List + */ + List listByUserId(Integer userId); + + /** + * 批量根据用户id查询角色 + * + * @param userIds 用户id集合 + * @return List + */ + List listByUserIds(List userIds); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/UserService.java b/src/main/java/com/eleadmin/common/system/service/UserService.java new file mode 100644 index 0000000..81eb179 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/UserService.java @@ -0,0 +1,93 @@ +package com.eleadmin.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.User; +import com.eleadmin.common.system.param.UserParam; +import org.springframework.security.core.userdetails.UserDetailsService; + +import java.util.List; + +/** + * 用户Service + * + * @author EleAdmin + * @since 2018-12-24 16:10:52 + */ +public interface UserService extends IService, UserDetailsService { + + /** + * 关联分页查询用户 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(UserParam param); + + /** + * 关联查询全部用户 + * + * @param param 查询参数 + * @return List + */ + List listRel(UserParam param); + + /** + * 根据id查询用户 + * + * @param userId 用户id + * @return User + */ + User getByIdRel(Integer userId); + + /** + * 根据账号查询用户 + * + * @param username 账号 + * @return User + */ + User getByUsername(String username); + + /** + * 根据账号查询用户 + * + * @param username 账号 + * @param tenantId 租户id + * @return User + */ + User getByUsername(String username, Integer tenantId); + + /** + * 添加用户 + * + * @param user 用户信息 + * @return boolean + */ + boolean saveUser(User user); + + /** + * 修改用户 + * + * @param user 用户信息 + * @return boolean + */ + boolean updateUser(User user); + + /** + * 比较用户密码 + * + * @param dbPassword 数据库存储的密码 + * @param inputPassword 用户输入的密码 + * @return boolean + */ + boolean comparePassword(String dbPassword, String inputPassword); + + /** + * md5加密用户密码 + * + * @param password 密码明文 + * @return 密文 + */ + String encodePassword(String password); + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/DictionaryDataServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/DictionaryDataServiceImpl.java new file mode 100644 index 0000000..a9e114d --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/DictionaryDataServiceImpl.java @@ -0,0 +1,52 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.core.utils.CommonUtil; +import com.eleadmin.common.core.web.PageParam; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.DictionaryData; +import com.eleadmin.common.system.mapper.DictionaryDataMapper; +import com.eleadmin.common.system.param.DictionaryDataParam; +import com.eleadmin.common.system.service.DictionaryDataService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 字典数据Service实现 + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +@Service +public class DictionaryDataServiceImpl extends ServiceImpl + implements DictionaryDataService { + + @Override + public PageResult pageRel(DictionaryDataParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return new PageResult<>(baseMapper.selectPageRel(page, param), page.getTotal()); + } + + @Override + public List listRel(DictionaryDataParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return page.sortRecords(baseMapper.selectListRel(param)); + } + + @Override + public DictionaryData getByIdRel(Integer dictDataId) { + DictionaryDataParam param = new DictionaryDataParam(); + param.setDictDataId(dictDataId); + return param.getOne(baseMapper.selectListRel(param)); + } + + @Override + public DictionaryData getByDictCodeAndName(String dictCode, String dictDataName) { + List list = baseMapper.getByDictCodeAndName(dictCode, dictDataName); + return CommonUtil.listGetOne(list); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/DictionaryServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/DictionaryServiceImpl.java new file mode 100644 index 0000000..75aacfc --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/DictionaryServiceImpl.java @@ -0,0 +1,18 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.system.entity.Dictionary; +import com.eleadmin.common.system.mapper.DictionaryMapper; +import com.eleadmin.common.system.service.DictionaryService; +import org.springframework.stereotype.Service; + +/** + * 字典Service实现 + * + * @author EleAdmin + * @since 2020-03-14 11:29:03 + */ +@Service +public class DictionaryServiceImpl extends ServiceImpl implements DictionaryService { + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/EmailRecordServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/EmailRecordServiceImpl.java new file mode 100644 index 0000000..d05342b --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/EmailRecordServiceImpl.java @@ -0,0 +1,72 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.system.entity.EmailRecord; +import com.eleadmin.common.system.mapper.EmailRecordMapper; +import com.eleadmin.common.system.service.EmailRecordService; +import org.beetl.core.Configuration; +import org.beetl.core.GroupTemplate; +import org.beetl.core.Template; +import org.beetl.core.resource.ClasspathResourceLoader; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.IOException; +import java.util.Map; + +/** + * 邮件发送记录Service实现 + * + * @author EleAdmin + * @since 2019-06-19 04:07:54 + */ +@Service +public class EmailRecordServiceImpl extends ServiceImpl + implements EmailRecordService { + // 发件邮箱 + @Value("${spring.mail.username}") + private String formEmail; + @Resource + private JavaMailSender mailSender; + + @Override + public void sendTextEmail(String title, String content, String[] toEmails) { + SimpleMailMessage message = new SimpleMailMessage(); + message.setFrom(formEmail); + message.setTo(toEmails); + message.setSubject(title); + message.setText(content); + mailSender.send(message); + } + + @Override + public void sendFullTextEmail(String title, String html, String[] toEmails) throws MessagingException { + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); + helper.setFrom(formEmail); + helper.setTo(toEmails); + helper.setSubject(title); + // 发送邮件 + helper.setText(html, true); + mailSender.send(mimeMessage); + } + + @Override + public void sendHtmlEmail(String title, String path, Map map, String[] toEmails) + throws MessagingException, IOException { + ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader("templates/"); + Configuration cfg = Configuration.defaultConfiguration(); + GroupTemplate gt = new GroupTemplate(resourceLoader, cfg); + Template t = gt.getTemplate(path); // 加载html模板 + t.binding(map); // 填充数据 + String html = t.render(); // 获得渲染后的html + sendFullTextEmail(title, html, toEmails); // 发送邮件 + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/FileRecordServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/FileRecordServiceImpl.java new file mode 100644 index 0000000..8297439 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/FileRecordServiceImpl.java @@ -0,0 +1,44 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.core.web.PageParam; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.FileRecord; +import com.eleadmin.common.system.mapper.FileRecordMapper; +import com.eleadmin.common.system.param.FileRecordParam; +import com.eleadmin.common.system.service.FileRecordService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 文件上传记录Service实现 + * + * @author EleAdmin + * @since 2021-08-30 11:21:01 + */ +@Service +public class FileRecordServiceImpl extends ServiceImpl implements FileRecordService { + + @Override + public PageResult pageRel(FileRecordParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return new PageResult<>(baseMapper.selectPageRel(page, param), page.getTotal()); + } + + @Override + public List listRel(FileRecordParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return page.sortRecords(baseMapper.selectListRel(param)); + } + + @Override + public FileRecord getByIdRel(Integer id) { + FileRecordParam param = new FileRecordParam(); + param.setId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/GoodsServiceImp.java b/src/main/java/com/eleadmin/common/system/service/impl/GoodsServiceImp.java new file mode 100644 index 0000000..f73f72f --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/GoodsServiceImp.java @@ -0,0 +1,8 @@ +package com.eleadmin.common.system.service.impl; + +import com.eleadmin.common.system.service.GoodsService; +import org.springframework.stereotype.Service; + +@Service +public class GoodsServiceImp implements GoodsService { +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/LoginRecordServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/LoginRecordServiceImpl.java new file mode 100644 index 0000000..bf003dd --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/LoginRecordServiceImpl.java @@ -0,0 +1,78 @@ +package com.eleadmin.common.system.service.impl; + +import cn.hutool.extra.servlet.ServletUtil; +import cn.hutool.http.useragent.UserAgent; +import cn.hutool.http.useragent.UserAgentUtil; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.core.web.PageParam; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.LoginRecord; +import com.eleadmin.common.system.mapper.LoginRecordMapper; +import com.eleadmin.common.system.param.LoginRecordParam; +import com.eleadmin.common.system.service.LoginRecordService; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * 登录日志Service实现 + * + * @author EleAdmin + * @since 2018-12-24 16:10:14 + */ +@Service +public class LoginRecordServiceImpl extends ServiceImpl + implements LoginRecordService { + + @Override + public PageResult pageRel(LoginRecordParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return new PageResult<>(baseMapper.selectPageRel(page, param), page.getTotal()); + } + + @Override + public List listRel(LoginRecordParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return page.sortRecords(baseMapper.selectListRel(param)); + } + + @Override + public LoginRecord getByIdRel(Integer id) { + LoginRecordParam param = new LoginRecordParam(); + param.setId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + + @Async + @Override + public void saveAsync(String username, Integer type, String comments, Integer tenantId, + HttpServletRequest request) { + if (username == null) { + return; + } + LoginRecord loginRecord = new LoginRecord(); + loginRecord.setUsername(username); + loginRecord.setLoginType(type); + loginRecord.setComments(comments); + loginRecord.setTenantId(tenantId); + UserAgent ua = UserAgentUtil.parse(ServletUtil.getHeaderIgnoreCase(request, "User-Agent")); + if (ua != null) { + if (ua.getPlatform() != null) { + loginRecord.setOs(ua.getPlatform().toString()); + } + if (ua.getOs() != null) { + loginRecord.setDevice(ua.getOs().toString()); + } + if (ua.getBrowser() != null) { + loginRecord.setBrowser(ua.getBrowser().toString()); + } + } + loginRecord.setIp(ServletUtil.getClientIP(request)); + baseMapper.insert(loginRecord); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/MenuServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/MenuServiceImpl.java new file mode 100644 index 0000000..2e1dc8e --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/MenuServiceImpl.java @@ -0,0 +1,18 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.mapper.MenuMapper; +import com.eleadmin.common.system.service.MenuService; +import org.springframework.stereotype.Service; + +/** + * 菜单Service实现 + * + * @author EleAdmin + * @since 2018-12-24 16:10:10 + */ +@Service +public class MenuServiceImpl extends ServiceImpl implements MenuService { + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/OperationRecordServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/OperationRecordServiceImpl.java new file mode 100644 index 0000000..f2c89d3 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/OperationRecordServiceImpl.java @@ -0,0 +1,52 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.core.web.PageParam; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.OperationRecord; +import com.eleadmin.common.system.mapper.OperationRecordMapper; +import com.eleadmin.common.system.param.OperationRecordParam; +import com.eleadmin.common.system.service.OperationRecordService; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 操作日志Service实现 + * + * @author EleAdmin + * @since 2018-12-24 16:10:02 + */ +@Service +public class OperationRecordServiceImpl extends ServiceImpl + implements OperationRecordService { + + @Override + public PageResult pageRel(OperationRecordParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return new PageResult<>(baseMapper.selectPageRel(page, param), page.getTotal()); + } + + @Override + public List listRel(OperationRecordParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return page.sortRecords(baseMapper.selectListRel(param)); + } + + @Override + public OperationRecord getByIdRel(Integer id) { + OperationRecordParam param = new OperationRecordParam(); + param.setId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + + @Async + @Override + public void saveAsync(OperationRecord operationRecord) { + baseMapper.insert(operationRecord); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/OrganizationServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/OrganizationServiceImpl.java new file mode 100644 index 0000000..82c0e7f --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/OrganizationServiceImpl.java @@ -0,0 +1,45 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.core.web.PageParam; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.entity.Organization; +import com.eleadmin.common.system.mapper.OrganizationMapper; +import com.eleadmin.common.system.param.OrganizationParam; +import com.eleadmin.common.system.service.OrganizationService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 组织机构Service实现 + * + * @author EleAdmin + * @since 2020-03-14 11:29:04 + */ +@Service +public class OrganizationServiceImpl extends ServiceImpl + implements OrganizationService { + + @Override + public PageResult pageRel(OrganizationParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return new PageResult<>(baseMapper.selectPageRel(page, param), page.getTotal()); + } + + @Override + public List listRel(OrganizationParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("sort_number"); + return page.sortRecords(baseMapper.selectListRel(param)); + } + + @Override + public Organization getByIdRel(Integer organizationId) { + OrganizationParam param = new OrganizationParam(); + param.setOrganizationId(organizationId); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/RoleMenuServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/RoleMenuServiceImpl.java new file mode 100644 index 0000000..c4bceac --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/RoleMenuServiceImpl.java @@ -0,0 +1,31 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.system.entity.Menu; +import com.eleadmin.common.system.entity.RoleMenu; +import com.eleadmin.common.system.mapper.RoleMenuMapper; +import com.eleadmin.common.system.service.RoleMenuService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 角色菜单Service实现 + * + * @author EleAdmin + * @since 2018-12-24 16:10:12 + */ +@Service +public class RoleMenuServiceImpl extends ServiceImpl implements RoleMenuService { + + @Override + public List listMenuByUserId(Integer userId, Integer menuType) { + return baseMapper.listMenuByUserId(userId, menuType); + } + + @Override + public List listMenuByRoleIds(List roleIds, Integer menuType) { + return baseMapper.listMenuByRoleIds(roleIds, menuType); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/RoleServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/RoleServiceImpl.java new file mode 100644 index 0000000..bea1c22 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/RoleServiceImpl.java @@ -0,0 +1,18 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.system.entity.Role; +import com.eleadmin.common.system.mapper.RoleMapper; +import com.eleadmin.common.system.service.RoleService; +import org.springframework.stereotype.Service; + +/** + * 角色服务实现类 + * + * @author EleAdmin + * @since 2018-12-24 16:10:11 + */ +@Service +public class RoleServiceImpl extends ServiceImpl implements RoleService { + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/UserRoleServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/UserRoleServiceImpl.java new file mode 100644 index 0000000..1a99e4a --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/UserRoleServiceImpl.java @@ -0,0 +1,37 @@ +package com.eleadmin.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.system.entity.Role; +import com.eleadmin.common.system.entity.UserRole; +import com.eleadmin.common.system.mapper.UserRoleMapper; +import com.eleadmin.common.system.service.UserRoleService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 用户角色Service实现 + * + * @author EleAdmin + * @since 2018-12-24 16:10:36 + */ +@Service +public class UserRoleServiceImpl extends ServiceImpl implements UserRoleService { + + + @Override + public int saveBatch(Integer userId, List roleIds) { + return baseMapper.insertBatch(userId, roleIds); + } + + @Override + public List listByUserId(Integer userId) { + return baseMapper.selectByUserId(userId); + } + + @Override + public List listByUserIds(List userIds) { + return baseMapper.selectByUserIds(userIds); + } + +} diff --git a/src/main/java/com/eleadmin/common/system/service/impl/UserServiceImpl.java b/src/main/java/com/eleadmin/common/system/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..5eaf7b5 --- /dev/null +++ b/src/main/java/com/eleadmin/common/system/service/impl/UserServiceImpl.java @@ -0,0 +1,181 @@ +package com.eleadmin.common.system.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.eleadmin.common.core.web.PageParam; +import com.eleadmin.common.core.exception.BusinessException; +import com.eleadmin.common.core.web.PageResult; +import com.eleadmin.common.system.mapper.UserMapper; +import com.eleadmin.common.system.entity.Role; +import com.eleadmin.common.system.entity.User; +import com.eleadmin.common.system.entity.UserRole; +import com.eleadmin.common.system.param.UserParam; +import com.eleadmin.common.system.service.RoleMenuService; +import com.eleadmin.common.system.service.UserRoleService; +import com.eleadmin.common.system.service.UserService; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 用户Service实现 + * + * @author EleAdmin + * @since 2018-12-24 16:10:14 + */ +@Service +public class UserServiceImpl extends ServiceImpl implements UserService { + @Resource + private UserRoleService userRoleService; + @Resource + private RoleMenuService roleMenuService; + @Resource + private BCryptPasswordEncoder bCryptPasswordEncoder; + + @Override + public PageResult pageRel(UserParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + List list = baseMapper.selectPageRel(page, param); + // 查询用户的角色 + selectUserRoles(list); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(UserParam param) { + List list = baseMapper.selectListRel(param); + // 查询用户的角色 + selectUserRoles(list); + // 排序 + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } + + @Override + public User getByIdRel(Integer userId) { + UserParam param = new UserParam(); + param.setUserId(userId); + User user = param.getOne(baseMapper.selectListRel(param)); + if (user != null) { + user.setRoles(userRoleService.listByUserId(user.getUserId())); + user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null)); + } + return user; + } + + @Override + public User getByUsername(String username) { + return getByUsername(username, null); + } + + @Override + public User getByUsername(String username, Integer tenantId) { + if (StrUtil.isBlank(username)) { + return null; + } + User user = baseMapper.selectByUsername(username, tenantId); + if (user != null) { + user.setRoles(userRoleService.listByUserId(user.getUserId())); + user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null)); + } + return user; + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return getByUsername(username); + } + + @Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE) + @Override + public boolean saveUser(User user) { + if (StrUtil.isNotEmpty(user.getUsername()) && baseMapper.selectCount(new LambdaQueryWrapper() + .eq(User::getUsername, user.getUsername())) > 0) { + throw new BusinessException("账号已存在"); + } + if (StrUtil.isNotEmpty(user.getPhone()) && baseMapper.selectCount(new LambdaQueryWrapper() + .eq(User::getPhone, user.getPhone())) > 0) { + throw new BusinessException("手机号已存在"); + } + if (StrUtil.isNotEmpty(user.getEmail()) && baseMapper.selectCount(new LambdaQueryWrapper() + .eq(User::getEmail, user.getEmail())) > 0) { + throw new BusinessException("邮箱已存在"); + } + boolean result = baseMapper.insert(user) > 0; + if (result && user.getRoles() != null && user.getRoles().size() > 0) { + List roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList()); + if (userRoleService.saveBatch(user.getUserId(), roleIds) < roleIds.size()) { + throw new BusinessException("用户角色添加失败"); + } + } + return result; + } + + @Transactional(rollbackFor = {Exception.class}) + @Override + public boolean updateUser(User user) { + if (StrUtil.isNotEmpty(user.getUsername()) && baseMapper.selectCount(new LambdaQueryWrapper() + .eq(User::getUsername, user.getUsername()) + .ne(User::getUserId, user.getUserId())) > 0) { + throw new BusinessException("账号已存在"); + } + if (StrUtil.isNotEmpty(user.getPhone()) && baseMapper.selectCount(new LambdaQueryWrapper() + .eq(User::getPhone, user.getPhone()) + .ne(User::getUserId, user.getUserId())) > 0) { + throw new BusinessException("手机号已存在"); + } + if (StrUtil.isNotEmpty(user.getEmail()) && baseMapper.selectCount(new LambdaQueryWrapper() + .eq(User::getEmail, user.getEmail()) + .ne(User::getUserId, user.getUserId())) > 0) { + throw new BusinessException("邮箱已存在"); + } + boolean result = baseMapper.updateById(user) > 0; + if (result && user.getRoles() != null && user.getRoles().size() > 0) { + userRoleService.remove(new LambdaUpdateWrapper().eq(UserRole::getUserId, user.getUserId())); + List roleIds = user.getRoles().stream().map(Role::getRoleId).collect(Collectors.toList()); + if (userRoleService.saveBatch(user.getUserId(), roleIds) < roleIds.size()) { + throw new BusinessException("用户角色添加失败"); + } + } + return result; + } + + @Override + public boolean comparePassword(String dbPassword, String inputPassword) { + return bCryptPasswordEncoder.matches(inputPassword, dbPassword); + } + + @Override + public String encodePassword(String password) { + return password == null ? null : bCryptPasswordEncoder.encode(password); + } + + /** + * 批量查询用户的角色 + * + * @param users 用户集合 + */ + private void selectUserRoles(List users) { + if (users != null && users.size() > 0) { + List userIds = users.stream().map(User::getUserId).collect(Collectors.toList()); + List userRoles = userRoleService.listByUserIds(userIds); + for (User user : users) { + List roles = userRoles.stream().filter(d -> user.getUserId().equals(d.getUserId())) + .collect(Collectors.toList()); + user.setRoles(roles); + } + } + } + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..bfb8b3e --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,16 @@ +# 开发环境配置 + +# 数据源配置 +spring: + datasource: + url: jdbc:mysql://49.232.230.199:3306/ele-admin?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 + username: root + password: lmc@123 + driver-class-name: com.mysql.cj.jdbc.Driver + type: com.alibaba.druid.pool.DruidDataSource + +# 日志配置 +logging: + level: + com.eleadmin: DEBUG + com.baomidou.mybatisplus: DEBUG diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..12b3f90 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,19 @@ +# 生产环境配置 + +# 数据源配置 +spring: + datasource: + url: jdbc:mysql://49.232.230.199:3306/ele-admin?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 + username: root + password: lmc@123 + driver-class-name: com.mysql.cj.jdbc.Driver + type: com.alibaba.druid.pool.DruidDataSource + +# 日志配置 +logging: + file: + name: ele-admin-api.log + level: + root: WARN + com.eleadmin: ERROR + com.baomidou.mybatisplus: ERROR diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml new file mode 100644 index 0000000..90615a9 --- /dev/null +++ b/src/main/resources/application-test.yml @@ -0,0 +1,18 @@ +# 测试环境配置 + +# 数据源配置 +spring: + datasource: + url: jdbc:mysql://49.232.230.199:3306/ele-admin?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 + username: root + password: lmc@123 + driver-class-name: com.mysql.cj.jdbc.Driver + type: com.alibaba.druid.pool.DruidDataSource + +# 日志配置 +logging: + file: + name: ele-admin-api.log + level: + com.eleadmin: DEBUG + com.baomidou.mybatisplus: DEBUG diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..bcf2cce --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,79 @@ +# 端口 +server: + port: 8081 + +# 多环境配置 +spring: + profiles: + active: dev + + # 连接池配置 + datasource: + druid: + initial-size: 5 + min-idle: 5 + max-active: 20 + max-wait: 30000 + time-between-eviction-runs-millis: 60000 + min-evictable-idle-time-millis: 300000 + test-while-idle: true + test-on-borrow: true + test-on-return: false + remove-abandoned: true + remove-abandoned-timeout: 1800 + #pool-prepared-statements: false + #max-pool-prepared-statement-per-connection-size: 20 + filters: stat, wall + validation-query: SELECT 'x' + aop-patterns: com.eleadmin.*.*.service.* + stat-view-servlet: + url-pattern: /druid/* + reset-enable: true + login-username: admin + login-password: admin + + # json时间格式设置 + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss + + # 设置上传文件大小 + servlet: + multipart: + max-file-size: 100MB + max-request-size: 100MB + + # 邮件服务器配置 + mail: + host: smtp.qq.com + username: + password: + default-encoding: UTF-8 + properties: + mail: + smtp: + auth: true + socketFactory: + class: javax.net.ssl.SSLSocketFactory + port: 465 + +# Mybatis-plus配置 +mybatis-plus: + mapper-locations: classpath*:com/eleadmin/**/*Mapper.xml + configuration: + map-underscore-to-camel-case: true + cache-enabled: true + global-config: + :banner: false + db-config: + id-type: auto + logic-delete-value: 1 + logic-not-delete-value: 0 + +# 框架配置 +config: + open-office-home: C:/OpenOffice4/ + swagger-base-package: com.eleadmin + swagger-title: EleAdmin API文档 + swagger-version: 1.0 + token-key: ULgNsWJ8rPjRtnjzX/Gv2RGS80Ksnm/ZaLpvIL+NrBg= diff --git a/src/test/java/com/eleadmin/EleAdminApplicationTests.java b/src/test/java/com/eleadmin/EleAdminApplicationTests.java new file mode 100644 index 0000000..e83c8f1 --- /dev/null +++ b/src/test/java/com/eleadmin/EleAdminApplicationTests.java @@ -0,0 +1,13 @@ +package com.eleadmin; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class EleAdminApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/src/test/java/com/eleadmin/TestMain.java b/src/test/java/com/eleadmin/TestMain.java new file mode 100644 index 0000000..091fad5 --- /dev/null +++ b/src/test/java/com/eleadmin/TestMain.java @@ -0,0 +1,45 @@ +package com.eleadmin; + +import org.junit.jupiter.api.Test; + +import com.eleadmin.common.core.security.JwtUtil; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * Created by EleAdmin on 2020-03-23 23:37 + */ +public class TestMain { + + /** + * 生成唯一的key用于jwt工具类 + */ + @Test + public void testGenJwtKey() { + System.out.println(JwtUtil.encodeKey(JwtUtil.randomKey())); + } + + /** + * 生成加密后的登录密码 + */ + @Test + public void testEncodePassword() { + System.out.println(new BCryptPasswordEncoder().encode("admin")); + } + + /** + * 校验密码 + */ + @Test + public void testComparePassword() { + System.out.println(new BCryptPasswordEncoder().matches( + "admin", + "$2a$10$W/218CEDADkJ1iUU3rLI6.x7F3TtScvEIFjKcII2oGb7flKWzznae" + )); + } + + @Test + public void test() { + + } + +} diff --git a/src/test/java/com/eleadmin/generator/CodeGenerator.java b/src/test/java/com/eleadmin/generator/CodeGenerator.java new file mode 100644 index 0000000..69ebfb5 --- /dev/null +++ b/src/test/java/com/eleadmin/generator/CodeGenerator.java @@ -0,0 +1,167 @@ +package com.eleadmin.generator; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import com.eleadmin.generator.engine.BeetlTemplateEnginePlus; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 代码生成工具 + * + * @author EleAdmin + * @since 2021-09-05 00:31:14 + */ +public class CodeGenerator { + // 输出位置 + private static final String OUTPUT_LOCATION = System.getProperty("user.dir"); + //private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径 + // 输出目录 + private static final String OUTPUT_DIR = "/src/main/java"; + // 作者名称 + private static final String AUTHOR = "EleAdmin"; + // 是否在xml中添加二级缓存配置 + private static final boolean ENABLE_CACHE = false; + // 数据库连接配置 + private static final String DB_URL = "jdbc:mysql://localhost:3306/ele-admin?useUnicode=true&useSSL=false&characterEncoding=utf8"; + private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver"; + private static final String DB_USERNAME = "root"; + private static final String DB_PASSWORD = "123456"; + // 包名 + private static final String PACKAGE_NAME = "com.eleadmin"; + // 模块名 + private static final String MODULE_NAME = "test"; + // 需要生成的表 + private static final String[] TABLE_NAMES = new String[]{ + "sys_user", + "sys_role" + }; + // 需要去除的表前缀 + private static final String[] TABLE_PREFIX = new String[]{ + "sys_", + "tb_" + }; + // 不需要作为查询参数的字段 + private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{ + "tenant_id", + "create_time", + "update_time" + }; + // 查询参数使用String的类型 + private static final String[] PARAM_TO_STRING_TYPE = new String[]{ + "Date", + "LocalDate", + "LocalTime", + "LocalDateTime" + }; + // 查询参数使用EQ的类型 + private static final String[] PARAM_EQ_TYPE = new String[]{ + "Integer", + "Boolean", + "BigDecimal" + }; + // 是否添加权限注解 + private static final boolean AUTH_ANNOTATION = true; + // 是否添加日志注解 + private static final boolean LOG_ANNOTATION = true; + // controller的mapping前缀 + private static final String CONTROLLER_MAPPING_PREFIX = "/api"; + // 模板所在位置 + private static final String TEMPLATES_DIR = "/src/test/java/com/eleadmin/generator/templates"; + + public static void main(String[] args) { + // 代码生成器 + AutoGenerator mpg = new AutoGenerator(); + + // 全局配置 + GlobalConfig gc = new GlobalConfig(); + gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR); + gc.setAuthor(AUTHOR); + gc.setOpen(false); + gc.setFileOverride(true); + gc.setEnableCache(ENABLE_CACHE); + gc.setSwagger2(true); + gc.setIdType(IdType.AUTO); + gc.setServiceName("%sService"); + mpg.setGlobalConfig(gc); + + // 数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + dsc.setUrl(DB_URL); + // dsc.setSchemaName("public"); + dsc.setDriverName(DB_DRIVER); + dsc.setUsername(DB_USERNAME); + dsc.setPassword(DB_PASSWORD); + mpg.setDataSource(dsc); + + // 包配置 + PackageConfig pc = new PackageConfig(); + pc.setModuleName(MODULE_NAME); + pc.setParent(PACKAGE_NAME); + mpg.setPackageInfo(pc); + + // 策略配置 + StrategyConfig strategy = new StrategyConfig(); + strategy.setNaming(NamingStrategy.underline_to_camel); + strategy.setColumnNaming(NamingStrategy.underline_to_camel); + strategy.setInclude(TABLE_NAMES); + strategy.setTablePrefix(TABLE_PREFIX); + strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController"); + strategy.setEntityLombokModel(true); + strategy.setRestControllerStyle(true); + strategy.setControllerMappingHyphenStyle(true); + strategy.setLogicDeleteFieldName("deleted"); + mpg.setStrategy(strategy); + + // 模板配置 + TemplateConfig templateConfig = new TemplateConfig(); + templateConfig.setController(TEMPLATES_DIR + "/controller.java"); + templateConfig.setEntity(TEMPLATES_DIR + "/entity.java"); + templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java"); + templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml"); + templateConfig.setService(TEMPLATES_DIR + "/service.java"); + templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java"); + mpg.setTemplate(templateConfig); + mpg.setTemplateEngine(new BeetlTemplateEnginePlus()); + + // 自定义模板配置 + InjectionConfig cfg = new InjectionConfig() { + @Override + public void initMap() { + Map map = new HashMap<>(); + map.put("packageName", PACKAGE_NAME); + map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS); + map.put("paramToStringType", PARAM_TO_STRING_TYPE); + map.put("paramEqType", PARAM_EQ_TYPE); + map.put("authAnnotation", AUTH_ANNOTATION); + map.put("logAnnotation", LOG_ANNOTATION); + map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX); + this.setMap(map); + } + }; + String templatePath = TEMPLATES_DIR + "/param.java.btl"; + List focList = new ArrayList<>(); + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + return OUTPUT_LOCATION + OUTPUT_DIR + "/" + + PACKAGE_NAME.replace(".", "/") + + "/" + pc.getModuleName() + "/param/" + + tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA; + } + }); + cfg.setFileOutConfigList(focList); + mpg.setCfg(cfg); + + mpg.execute(); + } + +} diff --git a/src/test/java/com/eleadmin/generator/engine/BeetlTemplateEnginePlus.java b/src/test/java/com/eleadmin/generator/engine/BeetlTemplateEnginePlus.java new file mode 100644 index 0000000..392602e --- /dev/null +++ b/src/test/java/com/eleadmin/generator/engine/BeetlTemplateEnginePlus.java @@ -0,0 +1,50 @@ +package com.eleadmin.generator.engine; + +import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder; +import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine; +import org.beetl.core.Configuration; +import org.beetl.core.GroupTemplate; +import org.beetl.core.Template; +import org.beetl.core.resource.FileResourceLoader; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Map; + +/** + * Beetl模板引擎实现文件输出 + * + * @author EleAdmin + * @since 2021-09-05 00:30:28 + */ +public class BeetlTemplateEnginePlus extends AbstractTemplateEngine { + private GroupTemplate groupTemplate; + + @Override + public AbstractTemplateEngine init(ConfigBuilder configBuilder) { + super.init(configBuilder); + try { + Configuration cfg = Configuration.defaultConfiguration(); + groupTemplate = new GroupTemplate(new FileResourceLoader(), cfg); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + return this; + } + + @Override + public void writer(Map objectMap, String templatePath, String outputFile) throws Exception { + Template template = groupTemplate.getTemplate(templatePath); + try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) { + template.binding(objectMap); + template.renderTo(fileOutputStream); + } + logger.debug("模板:" + templatePath + "; 文件:" + outputFile); + } + + @Override + public String templateFilePath(String filePath) { + return filePath + ".btl"; + } + +} diff --git a/src/test/java/com/eleadmin/generator/templates/controller.java.btl b/src/test/java/com/eleadmin/generator/templates/controller.java.btl new file mode 100644 index 0000000..70a23b1 --- /dev/null +++ b/src/test/java/com/eleadmin/generator/templates/controller.java.btl @@ -0,0 +1,278 @@ +<% +var serviceIns = strutil.toLowerCase(strutil.subStringTo(table.serviceName, 0, 1)) + strutil.subString(table.serviceName, 1); +var authPre = package.ModuleName + ':' + table.entityPath; +var idFieldName, idPropertyName; +for(field in table.fields) { + if(field.keyFlag) { + idFieldName = field.name; + idPropertyName = field.propertyName; + } +} +%> +package ${package.Controller}; + +<% if(isNotEmpty(superControllerClassPackage)) { %> +import ${superControllerClassPackage}; +<% } %> +import ${cfg.packageName!}.${package.ModuleName}.service.${entity}Service; +import ${cfg.packageName!}.${package.ModuleName}.entity.${entity}; +import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param; +import ${cfg.packageName!}.common.core.web.ApiResult; +import ${cfg.packageName!}.common.core.web.PageResult; +import ${cfg.packageName!}.common.core.web.PageParam; +import ${cfg.packageName!}.common.core.web.BatchParam; +import ${cfg.packageName!}.common.core.annotation.OperationLog; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; +<% if(!restControllerStyle) { %> +import org.springframework.stereotype.Controller; +<% } %> + +import javax.annotation.Resource; +import java.util.List; + +/** + * ${table.comment!}控制器 + * + * @author ${author} + * @since ${date(), 'yyyy-MM-dd HH:mm:ss'} + */ +<% if(swagger2) { %> +@Api(tags = "${table.comment!}管理") +<% } %> +<% if(restControllerStyle) { %> +@RestController +<% } else { %> +@Controller +<% } %> +@RequestMapping("${cfg.controllerMappingPrefix!}<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>") +<% if(kotlin) { %> +class ${table.controllerName}<% if(isNotEmpty(superControllerClass)) { %> : ${superControllerClass}()<% } %> +<% } else if(isNotEmpty(superControllerClass)) { %> +public class ${table.controllerName} extends ${superControllerClass} { +<% } else { %> +public class ${table.controllerName} { +<% } %> + @Resource + private ${table.serviceName} ${serviceIns}; + + <% if(!swagger2) { %> + /** + * 分页查询${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:list')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("分页查询${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @GetMapping("/page") + public ApiResult> page(${entity}Param param) { + PageParam<${entity}, ${entity}Param> page = new PageParam<>(param); + //page.setDefaultOrder("create_time desc"); + return success(${serviceIns}.page(page, page.getWrapper())); + // 使用关联查询 + //return success(${serviceIns}.pageRel(param)); + } + + <% if(!swagger2) { %> + /** + * 查询全部${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:list')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("查询全部${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @GetMapping() + public ApiResult> list(${entity}Param param) { + PageParam<${entity}, ${entity}Param> page = new PageParam<>(param); + //page.setDefaultOrder("create_time desc"); + return success(${serviceIns}.list(page.getOrderWrapper())); + // 使用关联查询 + //return success(${serviceIns}.listRel(param)); + } + + <% if(!swagger2) { %> + /** + * 根据id查询${table.comment!} + */ + <% } %> + @PreAuthorize("hasAuthority('${authPre}:list')") + @OperationLog + @ApiOperation("根据id查询${table.comment!}") + @GetMapping("/{id}") + public ApiResult<${entity}> get(@PathVariable("id") Integer id) { + return success(${serviceIns}.getById(id)); + // 使用关联查询 + //return success(${serviceIns}.getByIdRel(id)); + } + + <% if(!swagger2) { %> + /** + * 添加${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:save')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("添加${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @PostMapping() + public ApiResult save(@RequestBody ${entity} ${table.entityPath}) { + if (${serviceIns}.save(${table.entityPath})) { + return success("添加成功"); + } + return fail("添加失败"); + } + + <% if(!swagger2) { %> + /** + * 修改${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:update')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("修改${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @PutMapping() + public ApiResult update(@RequestBody ${entity} ${table.entityPath}) { + if (${serviceIns}.updateById(${table.entityPath})) { + return success("修改成功"); + } + return fail("修改失败"); + } + + <% if(!swagger2) { %> + /** + * 删除${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:remove')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("删除${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (${serviceIns}.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + <% if(!swagger2) { %> + /** + * 批量添加${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:save')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("批量添加${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List<${entity}> list) { + if (${serviceIns}.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + <% if(!swagger2) { %> + /** + * 批量修改${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:update')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("批量修改${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam<${entity}> batchParam) { + if (batchParam.update(${serviceIns}, "${idFieldName!}")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + <% if(!swagger2) { %> + /** + * 批量删除${table.comment!} + */ + <% } %> + <% if(cfg.authAnnotation) { %> + @PreAuthorize("hasAuthority('${authPre}:remove')") + <% } %> + <% if(cfg.logAnnotation) { %> + @OperationLog + <% } %> + <% if(swagger2) { %> + @ApiOperation("批量删除${table.comment!}") + <% } %> + <% if(!restControllerStyle) { %> + @ResponseBody + <% } %> + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (${serviceIns}.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/test/java/com/eleadmin/generator/templates/entity.java.btl b/src/test/java/com/eleadmin/generator/templates/entity.java.btl new file mode 100644 index 0000000..44015ad --- /dev/null +++ b/src/test/java/com/eleadmin/generator/templates/entity.java.btl @@ -0,0 +1,158 @@ +package ${package.Entity}; + +<% for(pkg in table.importPackages) { %> +import ${pkg}; +<% } %> +<% if(swagger2) { %> +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +<% } %> +<% if(entityLombokModel) { %> +import lombok.Data; +import lombok.EqualsAndHashCode; + <% if(chainModel) { %> +import lombok.experimental.Accessors; + <% } %> +<% } %> + +/** + * ${table.comment!} + * + * @author ${author} + * @since ${date(), 'yyyy-MM-dd HH:mm:ss'} + */ +<% if(entityLombokModel) { %> +@Data + <% if(isNotEmpty(superEntityClass)) { %> +@EqualsAndHashCode(callSuper = true) + <% } else { %> +@EqualsAndHashCode(callSuper = false) + <% } %> + <% if(chainModel) { %> +@Accessors(chain = true) + <% } %> +<% } %> +<% if(swagger2) { %> +@ApiModel(value = "${entity}对象", description = "${table.comment!''}") +<% } %> +<% if(table.convert) { %> +@TableName("${table.name}") +<% } %> +<% if(isNotEmpty(superEntityClass)) { %> +public class ${entity} extends ${superEntityClass}<% if(activeRecord) { %><${entity}><% } %>{ +<% } else if(activeRecord) { %> +public class ${entity} extends Model<${entity}> { +<% } else { %> +public class ${entity} implements Serializable { +<% } %> +<% if(entitySerialVersionUID) { %> + private static final long serialVersionUID = 1L; +<% } %> +<% /** -----------BEGIN 字段循环遍历----------- **/ %> +<% for(field in table.fields) { %> + <% + var keyPropertyName; + if(field.keyFlag) { + keyPropertyName = field.propertyName; + } + %> + + <% if(isNotEmpty(field.comment)) { %> + <% if(swagger2) { %> + @ApiModelProperty(value = "${field.comment}") + <% }else{ %> + /** + * ${field.comment} + */ + <% } %> + <% } %> + <% /* 主键 */ %> + <% if(field.keyFlag) { %> + <% if(field.keyIdentityFlag) { %> + @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO) + <% } else if(isNotEmpty(idType)) { %> + @TableId(value = "${field.annotationColumnName}", type = IdType.${idType}) + <% } else if(field.convert) { %> + @TableId("${field.annotationColumnName}") + <% } %> + <% /* 普通字段 */ %> + <% } else if(isNotEmpty(field.fill)) { %> + <% if(field.convert){ %> + @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}) + <% }else{ %> + @TableField(fill = FieldFill.${field.fill}) + <% } %> + <% } else if(field.convert) { %> + @TableField("${field.annotationColumnName}") + <% } %> + <% /* 乐观锁注解 */ %> + <% if(versionFieldName!'' == field.name) { %> + @Version + <% } %> + <% /* 逻辑删除注解 */ %> + <% if(logicDeleteFieldName!'' == field.name) { %> + @TableLogic + <% } %> + private ${field.propertyType} ${field.propertyName}; +<% } %> +<% /** -----------END 字段循环遍历----------- **/ %> + +<% if(!entityLombokModel) { %> + <% for(field in table.fields) { %> + <% + var getprefix = ''; + if(field.propertyType == 'boolean') { + getprefix = 'is'; + } else { + getprefix = 'get'; + } + %> + public ${field.propertyType} ${getprefix}${field.capitalName}() { + return ${field.propertyName}; + } + + <% if(chainModel) { %> + public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) { + <% } else { %> + public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { + <% } %> + this.${field.propertyName} = ${field.propertyName}; + <% if(chainModel){ %> + return this; + <% } %> + } + + <% } %> +<% } %> +<% if(entityColumnConstant) { %> + <% for(field in table.fields) { %> + public static final String ${strutil.toUpperCase(field.name)} = "${field.name}"; + + <% } %> +<% } %> +<% if(activeRecord) { %> + @Override + protected Serializable pkVal() { + <% if(isNotEmpty(keyPropertyName)){ %> + return this.${keyPropertyName}; + <% }else{ %> + return null; + <% } %> + } + +<% } %> +<% if(!entityLombokModel){ %> + @Override + public String toString() { + return "${entity}{" + + <% for(field in table.fields){ %> + <% if(fieldLP.index==0){ %> + "${field.propertyName}=" + ${field.propertyName} + + <% }else{ %> + ", ${field.propertyName}=" + ${field.propertyName} + + <% } %> + <% } %> + "}"; + } +<% } %> +} diff --git a/src/test/java/com/eleadmin/generator/templates/mapper.java.btl b/src/test/java/com/eleadmin/generator/templates/mapper.java.btl new file mode 100644 index 0000000..54e41a9 --- /dev/null +++ b/src/test/java/com/eleadmin/generator/templates/mapper.java.btl @@ -0,0 +1,41 @@ +package ${package.Mapper}; + +import ${superMapperClassPackage}; +import com.baomidou.mybatisplus.core.metadata.IPage; +import ${package.Entity}.${entity}; +import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * ${table.comment!}Mapper + * + * @author ${author} + * @since ${date(), 'yyyy-MM-dd HH:mm:ss'} + */ +<% if(kotlin){ %> +interface ${table.mapperName} : ${superMapperClass}<${entity}> +<% }else{ %> +public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List<${entity}> + */ + List<${entity}> selectPageRel(@Param("page") IPage<${entity}> page, + @Param("param") ${entity}Param param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List<${entity}> selectListRel(@Param("param") ${entity}Param param); + +} +<% } %> diff --git a/src/test/java/com/eleadmin/generator/templates/mapper.xml.btl b/src/test/java/com/eleadmin/generator/templates/mapper.xml.btl new file mode 100644 index 0000000..6786c0d --- /dev/null +++ b/src/test/java/com/eleadmin/generator/templates/mapper.xml.btl @@ -0,0 +1,96 @@ + + + +<% if(enableCache) { %> + + + +<% } %> +<% if(baseResultMap) { %> + + + + <% /** 生成主键排在第一位 **/ %> + <% for(field in table.fields) { %> + <% if(field.keyFlag){ %> + + <% } %> + <% } %> + <% /** 生成公共字段 **/ %> + <% for(field in table.commonFields) { %> + + <% } %> + <% /** 生成普通字段 **/ %> + <% for(field in table.fields) { %> + <% if(!field.keyFlag) { %> + + <% } %> + <% } %> + +<% } %> +<% if(baseColumnList) { %> + + + + <% for(field in table.commonFields) { %> + ${field.columnName}, + <% } %> + ${table.fieldNames} + +<% } %> + + + + SELECT a.* + FROM ${table.name} a + +<% for(field in table.fields) { %> + <% if(field.keyFlag) { %> + <% /** 主键字段 **/ %> + + AND a.${field.name} = #{param.${field.propertyName}} + + <% } else if(field.name == logicDeleteFieldName) { %> + <% /** 逻辑删除字段 **/ %> + + AND a.deleted = #{param.deleted} + + + AND a.deleted = 0 + + <% } else if(field.name == 'create_time') { %> + <% /** 创建时间字段 **/ %> + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + <% } else if(array.contain(cfg.paramExcludeFields, field.name)) { %> + <% /** 排除的字段 **/ %> + <% } else if(array.contain(cfg.paramEqType, field.propertyType)) { %> + <% /** 使用EQ的字段 **/ %> + + AND a.${field.name} = #{param.${field.propertyName}} + + <% } else { %> + <% /** 其它类型使用LIKE **/ %> + + AND a.${field.name} LIKE CONCAT('%', #{param.${field.propertyName}}, '%') + + <% } %> +<% } %> + + + + + + + + + + diff --git a/src/test/java/com/eleadmin/generator/templates/param.java.btl b/src/test/java/com/eleadmin/generator/templates/param.java.btl new file mode 100644 index 0000000..9c30504 --- /dev/null +++ b/src/test/java/com/eleadmin/generator/templates/param.java.btl @@ -0,0 +1,146 @@ +package ${cfg.packageName!}.${package.ModuleName}.param; + +import ${cfg.packageName!}.common.core.annotation.QueryField; +import ${cfg.packageName!}.common.core.annotation.QueryType; +import ${cfg.packageName!}.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +<% if(swagger2) { %> +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +<% } %> +<% if(entityLombokModel) { %> +import lombok.Data; +import lombok.EqualsAndHashCode; + <% if(chainModel) { %> +import lombok.experimental.Accessors; + <% } %> +<% } %> + +/** + * ${table.comment!}查询参数 + * + * @author ${author} + * @since ${date(), 'yyyy-MM-dd HH:mm:ss'} + */ +<% if(entityLombokModel) { %> +@Data + <% if(isNotEmpty(superEntityClass)) { %> +@EqualsAndHashCode(callSuper = true) + <% } else { %> +@EqualsAndHashCode(callSuper = false) + <% } %> + <% if(chainModel) { %> +@Accessors(chain = true) + <% } %> +<% } %> +@JsonInclude(JsonInclude.Include.NON_NULL) +<% if(swagger2) { %> +@ApiModel(value = "${entity}Param对象", description = "${table.comment!''}查询参数") +<% } %> +public class ${entity}Param extends BaseParam { +<% if(entitySerialVersionUID) { %> + private static final long serialVersionUID = 1L; +<% } %> +<% /** -----------BEGIN 字段循环遍历----------- **/ %> +<% for(field in table.fields) { %> + <% + var keyPropertyName; + if(field.keyFlag) { + keyPropertyName = field.propertyName; + } + // 排除的字段 + if(array.contain(cfg.paramExcludeFields, field.name)) { + continue; + } + %> + + <% if(isNotEmpty(field.comment)) { %> + <% if(swagger2) { %> + @ApiModelProperty(value = "${field.comment}") + <% }else{ %> + /** + * ${field.comment} + */ + <% } %> + <% } %> + <% /* 主键 */ %> + <% if(field.keyFlag) { %> + @QueryField(type = QueryType.EQ) + <% /* 使用EQ的字段 */ %> + <% } else if(array.contain(cfg.paramEqType, field.propertyType)) { %> + @QueryField(type = QueryType.EQ) + <% } %> + <% /* 使用String类型的字段 */ %> + <% if(array.contain(cfg.paramToStringType, field.propertyType)) { %> + private String ${field.propertyName}; + <% } else { %> + <% /* 普通字段 */ %> + private ${field.propertyType} ${field.propertyName}; + <% } %> +<% } %> +<% /** -----------END 字段循环遍历----------- **/ %> + +<% if(!entityLombokModel) { %> + <% for(field in table.fields) { %> + <% + var getprefix = ''; + if(field.propertyType == 'boolean') { + getprefix = 'is'; + } else { + getprefix = 'get'; + } + // 排除的字段 + if(array.contain(cfg.paramExcludeFields, field.name)) { + continue; + } + %> + <% if(array.contain(cfg.paramToStringType, field.propertyType)) { %> + public String ${getprefix}${field.capitalName}() { + <% } else { %> + public ${field.propertyType} ${getprefix}${field.capitalName}() { + <% } %> + return ${field.propertyName}; + } + + <% if(chainModel) { %> + <% if(array.contain(cfg.paramToStringType, field.propertyType)) { %> + public ${entity} set${field.capitalName}(String ${field.propertyName}) { + <% } else { %> + public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) { + <% } %> + <% } else { %> + <% if(array.contain(cfg.paramToStringType, field.propertyType)) { %> + public void set${field.capitalName}(String ${field.propertyName}) { + <% } else { %> + public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { + <% } %> + <% } %> + this.${field.propertyName} = ${field.propertyName}; + <% if(chainModel){ %> + return this; + <% } %> + } + + <% } %> +<% } %> +<% if(!entityLombokModel) { %> + @Override + public String toString() { + return "${entity}{" + + <% for(field in table.fields) { %> + <% + // 排除的字段 + if(array.contain(cfg.paramExcludeFields, field.name)) { + continue; + } + %> + <% if(fieldLP.index == 0) { %> + "${field.propertyName}=" + ${field.propertyName} + + <% } else { %> + ", ${field.propertyName}=" + ${field.propertyName} + + <% } %> + <% } %> + "}"; + } +<% } %> +} diff --git a/src/test/java/com/eleadmin/generator/templates/service.java.btl b/src/test/java/com/eleadmin/generator/templates/service.java.btl new file mode 100644 index 0000000..67efe6a --- /dev/null +++ b/src/test/java/com/eleadmin/generator/templates/service.java.btl @@ -0,0 +1,55 @@ +<% +var idPropertyName, idComment; +for(field in table.fields) { + if(field.keyFlag) { + idPropertyName = field.propertyName; + idComment = field.comment; + } +} +%> +package ${package.Service}; + +import ${superServiceClassPackage}; +import ${cfg.packageName!}.common.core.web.PageResult; +import ${package.Entity}.${entity}; +import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param; + +import java.util.List; + +/** + * ${table.comment!}Service + * + * @author ${author} + * @since ${date(), 'yyyy-MM-dd HH:mm:ss'} + */ +<% if(kotlin){ %> +interface ${table.serviceName} : ${superServiceClass}<${entity}> +<% }else{ %> +public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult<${entity}> + */ + PageResult<${entity}> pageRel(${entity}Param param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List<${entity}> + */ + List<${entity}> listRel(${entity}Param param); + + /** + * 根据id查询 + * + * @param ${idPropertyName!} ${idComment!} + * @return ${entity} + */ + ${entity} getByIdRel(Integer ${idPropertyName!}); + +} +<% } %> diff --git a/src/test/java/com/eleadmin/generator/templates/serviceImpl.java.btl b/src/test/java/com/eleadmin/generator/templates/serviceImpl.java.btl new file mode 100644 index 0000000..e63a0b9 --- /dev/null +++ b/src/test/java/com/eleadmin/generator/templates/serviceImpl.java.btl @@ -0,0 +1,62 @@ +<% +var idPropertyName, idCapitalName; +for(field in table.fields) { + if(field.keyFlag) { + idPropertyName = field.propertyName; + idCapitalName = field.capitalName; + } +} +%> +package ${package.ServiceImpl}; + +import ${superServiceImplClassPackage}; +import ${package.Mapper}.${table.mapperName}; +import ${package.Service}.${table.serviceName}; +import ${package.Entity}.${entity}; +import ${cfg.packageName!}.${package.ModuleName}.param.${entity}Param; +import ${cfg.packageName!}.common.core.web.PageParam; +import ${cfg.packageName!}.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * ${table.comment!}Service实现 + * + * @author ${author} + * @since ${date(), 'yyyy-MM-dd HH:mm:ss'} + */ +@Service +<% if(kotlin){ %> +open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { + +} +<% }else{ %> +public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { + + @Override + public PageResult<${entity}> pageRel(${entity}Param param) { + PageParam<${entity}, ${entity}Param> page = new PageParam<>(param); + //page.setDefaultOrder("create_time desc"); + List<${entity}> list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List<${entity}> listRel(${entity}Param param) { + List<${entity}> list = baseMapper.selectListRel(param); + // 排序 + PageParam<${entity}, ${entity}Param> page = new PageParam<>(); + //page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } + + @Override + public ${entity} getByIdRel(Integer ${idPropertyName!}) { + ${entity}Param param = new ${entity}Param(); + param.set${idCapitalName!}(${idPropertyName!}); + return param.getOne(baseMapper.selectListRel(param)); + } + +} +<% } %>