1、搭建了乐益播商家版app的开发框架。
2、开发了用户注册,账号密码登录,手机验证码登录的功能模块。 3、开发了商家模块的部分功能。 4、开发了总部审核用户,禁用,启用用户等功能模块。 5、整合了七牛云存储的功能模块(暂时没有账号,密钥等信息,待测试)。 6、创建了联盟商家,商品的数据库表
This commit is contained in:
commit
6fbb29ed74
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.3-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
310
mvnw
vendored
Normal file
310
mvnw
vendored
Normal file
@ -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 "$@"
|
182
mvnw.cmd
vendored
Normal file
182
mvnw.cmd
vendored
Normal file
@ -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%
|
268
pom.xml
Normal file
268
pom.xml
Normal file
@ -0,0 +1,268 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.xkrs</groupId>
|
||||
<artifactId>business_shopping</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>business_shopping</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<yauaa.version>5.19</yauaa.version>
|
||||
<jjwt.version>0.11.2</jjwt.version>
|
||||
<httpmime.version>4.5.12</httpmime.version>
|
||||
<hibernate-validator.version>6.1.5.Final</hibernate-validator.version>
|
||||
<hibernate-spatial.version>5.4.20.Final</hibernate-spatial.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>11</java.version>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<fastjson.version>1.2.76</fastjson.version>
|
||||
<springfox-swagger-ui.version>2.10.5</springfox-swagger-ui.version>
|
||||
<springfox-swagger2.version>2.10.5</springfox-swagger2.version>
|
||||
<poi.version>5.0.0</poi.version>
|
||||
<poi-ooxml.version>5.0.0</poi-ooxml.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
<poi.version>5.0.0</poi.version>
|
||||
<poi-ooxml.version>5.0.0</poi-ooxml.version>
|
||||
<dysmsapi20170525.version>2.0.4</dysmsapi20170525.version>
|
||||
<hutool-all.version>4.4.3</hutool-all.version>
|
||||
<tus-client.version>0.4.0</tus-client.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-messaging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId> mysql</groupId>
|
||||
<artifactId> mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.basjes.parse.useragent</groupId>
|
||||
<artifactId>yauaa</artifactId>
|
||||
<version>${yauaa.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>${httpmime.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate-validator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-spatial</artifactId>
|
||||
<version>${hibernate-spatial.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--swagger的依赖-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-swagger-ui.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-swagger2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--excel依赖-->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>${poi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>${poi-ooxml.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
<version>2.4</version>
|
||||
<classifier>jdk15</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
</dependency>
|
||||
<!--excel依赖-->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>${poi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>${poi-ooxml.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--阿里云短信服务-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
<version>4.0.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool-all.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.tus.java.client</groupId>
|
||||
<artifactId>tus-java-client</artifactId>
|
||||
<version>${tus-client.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
<version>2.5.10.RELEASE</version>
|
||||
</dependency>
|
||||
<!--七牛云-->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>[7.2.0, 7.2.99]</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.xml</include>
|
||||
<include>**/*.txt</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
13
src/main/java/com/xkrs/BusinessShoppingApplication.java
Normal file
13
src/main/java/com/xkrs/BusinessShoppingApplication.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.xkrs;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class BusinessShoppingApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BusinessShoppingApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.xkrs.common.account;
|
||||
|
||||
/**
|
||||
* 账户实体
|
||||
* @author tajochen
|
||||
*/
|
||||
public class AccountCredentials {
|
||||
|
||||
private String userName;
|
||||
private String password;
|
||||
private boolean remember;
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean isRemember() {
|
||||
return remember;
|
||||
}
|
||||
|
||||
public void setRemember(boolean remember) {
|
||||
this.remember = remember;
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.xkrs.common.account;
|
||||
|
||||
import com.xkrs.model.entity.SysAuthorityEntity;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.service.SysAuthorityService;
|
||||
import com.xkrs.service.SysRoleService;
|
||||
import com.xkrs.service.SysUserService;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.DisabledException;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.xkrs.utils.EncryptDecryptUtil.encry256;
|
||||
|
||||
/**
|
||||
* 自定义认证Provider
|
||||
* @author tajochen
|
||||
*/
|
||||
@Component
|
||||
public class CustomAuthenticationProvider implements AuthenticationProvider {
|
||||
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Resource
|
||||
private SysAuthorityService sysAuthorityService;
|
||||
|
||||
/**
|
||||
* 初使化时将已静态化的Service实例化
|
||||
*/
|
||||
protected static CustomAuthenticationProvider customAuthenticationProvider;
|
||||
|
||||
/**
|
||||
* 通过@PostConstruct实现初始化bean之前进行的操作
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
customAuthenticationProvider = this;
|
||||
customAuthenticationProvider.sysUserService = this.sysUserService;
|
||||
customAuthenticationProvider.sysRoleService = this.sysRoleService;
|
||||
customAuthenticationProvider.sysAuthorityService = this.sysAuthorityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户认证授权
|
||||
* @param authentication
|
||||
* @return
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
// 获取认证的用户名 & 密码
|
||||
String userName = authentication.getName();
|
||||
String password = authentication.getCredentials().toString();
|
||||
|
||||
SysUserEntity userEntity = customAuthenticationProvider.sysUserService.getSysUserByUserName(userName);
|
||||
|
||||
// 检查用户是否存在
|
||||
if(userEntity == null){
|
||||
throw new BadCredentialsException("user don't exist");
|
||||
}
|
||||
|
||||
// 检查用户是否激活
|
||||
if(userEntity.getActiveFlag().intValue() != 0){
|
||||
throw new DisabledException("user not activated");
|
||||
}
|
||||
|
||||
//检查用户状态是否正常
|
||||
if(userEntity.getStatusCode() != 0){
|
||||
throw new DisabledException("user state exception");
|
||||
}
|
||||
// 认证逻辑
|
||||
String encryptPassword = encry256(password + userEntity.getSalt());
|
||||
if (encryptPassword.equals(userEntity.getPassword())) {
|
||||
// 设置权限列表
|
||||
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
|
||||
List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService.
|
||||
getSysAuthorityListByUserName(userName);
|
||||
for(SysAuthorityEntity sysAuthorityEntity : permissionList) {
|
||||
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
|
||||
}
|
||||
// 生成令牌
|
||||
Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions);
|
||||
return authToken;
|
||||
}else if(password.equals(userEntity.getPassword())){
|
||||
// 设置权限列表
|
||||
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
|
||||
List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService.
|
||||
getSysAuthorityListByUserName(userName);
|
||||
for(SysAuthorityEntity sysAuthorityEntity : permissionList) {
|
||||
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
|
||||
}
|
||||
// 生成令牌
|
||||
Authentication authToken = new UsernamePasswordAuthenticationToken(userName, encryptPassword, permissions);
|
||||
return authToken;
|
||||
}
|
||||
else {
|
||||
throw new BadCredentialsException("user password error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以提供输入类型的认证服务
|
||||
* @param authentication
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(Class<?> authentication) {
|
||||
return authentication.equals(UsernamePasswordAuthenticationToken.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.xkrs.common.account;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
||||
/**
|
||||
* 权限认证服务
|
||||
* @author tajochen
|
||||
*/
|
||||
public class GrantedAuthorityImpl implements GrantedAuthority {
|
||||
|
||||
private String authority;
|
||||
|
||||
public GrantedAuthorityImpl(String authority) {
|
||||
this.authority = authority;
|
||||
}
|
||||
|
||||
public void setAuthority(String authority) {
|
||||
this.authority = authority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthority() {
|
||||
return this.authority;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.xkrs.common.account;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 拦截所有需要JWT的请求,然后调用TokenAuthenticationService类的静态方法去做JWT验证
|
||||
* @author tajochen
|
||||
*/
|
||||
public class JwtAuthenticationFilter extends GenericFilterBean {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request,
|
||||
ServletResponse response,
|
||||
FilterChain filterChain) throws IOException, ServletException {
|
||||
Authentication authentication = TokenAuthenticationService.getAuthentication((HttpServletRequest)request);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
filterChain.doFilter(request,response);
|
||||
}
|
||||
}
|
132
src/main/java/com/xkrs/common/account/JwtLoginFilter.java
Normal file
132
src/main/java/com/xkrs/common/account/JwtLoginFilter.java
Normal file
@ -0,0 +1,132 @@
|
||||
package com.xkrs.common.account;
|
||||
|
||||
import com.xkrs.common.encapsulation.OutputEncapsulation;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.model.vo.SysUserVo;
|
||||
import com.xkrs.service.SysUserService;
|
||||
import com.xkrs.utils.IpUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* jwt登录过滤器
|
||||
* @author tajochen
|
||||
*/
|
||||
public class JwtLoginFilter extends AbstractAuthenticationProcessingFilter {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JwtLoginFilter.class);
|
||||
|
||||
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
|
||||
public JwtLoginFilter(String url, AuthenticationManager authManager) {
|
||||
super(new AntPathRequestMatcher(url));
|
||||
setAuthenticationManager(authManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录时验证
|
||||
* @param req
|
||||
* @param res
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res) throws UnsupportedEncodingException {
|
||||
req.setCharacterEncoding("UTF-8");
|
||||
res.setHeader("Access-Control-Allow-Origin","*");
|
||||
res.setHeader("Access-Control-Allow-Credentials", "false");
|
||||
AccountCredentials creds = new AccountCredentials();
|
||||
//获取表单数据
|
||||
String userName = req.getParameter("userName");
|
||||
String password = req.getParameter("password");
|
||||
String rememberMe = req.getParameter("remember");
|
||||
//如果用户名密码为空
|
||||
if(userName == null||password == null|| userName.trim().isEmpty()||password.trim().isEmpty()){
|
||||
throw new BadCredentialsException("user or password is null");
|
||||
}
|
||||
if(rememberMe == null||rememberMe.isEmpty()){
|
||||
rememberMe = "false";
|
||||
}
|
||||
creds.setUserName(userName.trim());
|
||||
creds.setPassword(password.trim());
|
||||
creds.setRemember(Boolean.parseBoolean(rememberMe));
|
||||
// 返回一个验证令牌
|
||||
return getAuthenticationManager().authenticate(
|
||||
new UsernamePasswordAuthenticationToken(
|
||||
creds.getUserName(),
|
||||
creds.getPassword()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证成功后调用
|
||||
* @param req
|
||||
* @param response
|
||||
* @param chain
|
||||
* @param auth
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
protected void successfulAuthentication(
|
||||
HttpServletRequest req, HttpServletResponse response, FilterChain chain, Authentication auth) {
|
||||
if(sysUserService==null){
|
||||
ServletContext servletContext = req.getServletContext();
|
||||
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
|
||||
sysUserService = webApplicationContext.getBean(SysUserService.class);
|
||||
}
|
||||
//更新用户登录信息
|
||||
sysUserService.updateSysUserLogin(auth.getName(), IpUtil.getIpAddr(req));
|
||||
SysUserVo sysUserVo = sysUserService.selectUserByUserName(auth.getName());
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "false");
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
TokenAuthenticationService.addAuthentication(response, auth.getName(),auth.getAuthorities(),sysUserVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证失败后调用
|
||||
* @param request
|
||||
* @param response
|
||||
* @param failed
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
protected void unsuccessfulAuthentication(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
AuthenticationException failed) throws IOException {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "false");
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
// 将 JWT 写入 body
|
||||
PrintWriter out = response.getWriter();
|
||||
out.append(OutputEncapsulation.outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, failed.getLocalizedMessage(), locale));
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package com.xkrs.common.account;
|
||||
|
||||
import com.xkrs.common.encapsulation.OutputEncapsulation;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.model.vo.SysUserVo;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* token认证服务
|
||||
* @author tajochen
|
||||
*/
|
||||
public class TokenAuthenticationService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TokenAuthenticationService.class);
|
||||
/**
|
||||
* 过期时间6小时
|
||||
*/
|
||||
static public final long EXPIRATIONTIME = 21_600_000;
|
||||
/**
|
||||
* 加密密钥
|
||||
*/
|
||||
static public final String SECRET_KEY = "0Y9H364Q9Y908262F25LMXGIKIN5N858XM3674GWL2DD8X1DS4W6I722IRY8PS4XPNB6U303" +
|
||||
"45HBVCUL94STG8C3Z53T7A09JJ100I56YE9894CI11PX9J71HIZ8L5Y2O504C4E2K8276425UA8734833F45K36878FXAG799QV9LXU" +
|
||||
"JOI3XA2046UPG8TB2OT84R5T6ZB127N9ZPJ7AJMC41JVHB2WK2B6H8NL45LZNAZ666KHZH3QUT65UX6F8";
|
||||
/**
|
||||
* Token前缀
|
||||
*/
|
||||
static public final String TOKEN_PREFIX = "Bearer";
|
||||
|
||||
/**
|
||||
* 存放Token的Header Key
|
||||
*/
|
||||
static final String HEADER_STRING = "Authorization";
|
||||
static SecretKey key = Keys.hmacShaKeyFor(SECRET_KEY.getBytes());
|
||||
|
||||
/**
|
||||
* JWT生成方法
|
||||
* @param response
|
||||
* @param userName
|
||||
* @param authorities
|
||||
*/
|
||||
static void addAuthentication(HttpServletResponse response, String userName,
|
||||
Collection<? extends GrantedAuthority> authorities, SysUserVo sysUserVo) {
|
||||
|
||||
Locale locale = new Locale("zh", "CN");
|
||||
Map map = new HashMap(3);
|
||||
StringBuffer auths = new StringBuffer();
|
||||
String authsList = "";
|
||||
for(GrantedAuthority r : authorities) {
|
||||
auths.append("," + r.getAuthority());
|
||||
}
|
||||
authsList = auths.toString();
|
||||
if(authsList.length()>1){
|
||||
authsList=authsList.substring(1,authsList.length());
|
||||
}else{
|
||||
logger.warn(userName +" has no permission!");
|
||||
}
|
||||
// 生成JWT
|
||||
String jwt = Jwts.builder()
|
||||
.setSubject(userName)
|
||||
.setIssuer("https://www.microservice.com")
|
||||
.setAudience(userName)
|
||||
// 保存权限
|
||||
.claim("auths", authsList)
|
||||
// 有效期设置
|
||||
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
|
||||
// 签名设置
|
||||
.signWith(key)
|
||||
.compact();
|
||||
// 将 JWT 写入 body
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
map.put("user",sysUserVo);
|
||||
map.put("token",jwt);
|
||||
map.put("role",authsList);
|
||||
out.append(OutputEncapsulation.outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale));
|
||||
}
|
||||
|
||||
/**
|
||||
* JWT验证方法
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
static Authentication getAuthentication(HttpServletRequest request) {
|
||||
// 从Header中拿到token
|
||||
String token = request.getHeader(HEADER_STRING);
|
||||
if (token != null) {
|
||||
try {
|
||||
// 解析 Token
|
||||
Claims claims = Jwts.parserBuilder()
|
||||
.setSigningKey(key).build()
|
||||
// 去掉 Bearer
|
||||
.parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
|
||||
.getBody();
|
||||
// 获取用户名
|
||||
String userName = claims.getSubject();
|
||||
// 获取权限
|
||||
List<GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList((String) claims.get("auths"));
|
||||
return new UsernamePasswordAuthenticationToken(userName, null, authorities);
|
||||
} catch(Exception e) {
|
||||
// the sub field was missing or did not have a value
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
23
src/main/java/com/xkrs/common/config/CorsConfig.java
Normal file
23
src/main/java/com/xkrs/common/config/CorsConfig.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 系统跨域配置
|
||||
* @author tajochen
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Resource
|
||||
private CorsInterceptor corsInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(corsInterceptor);
|
||||
}
|
||||
}
|
29
src/main/java/com/xkrs/common/config/CorsInterceptor.java
Normal file
29
src/main/java/com/xkrs/common/config/CorsInterceptor.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 跨域处理
|
||||
* @author tajochen
|
||||
*/
|
||||
@Component
|
||||
public class CorsInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
|
||||
//添加跨域CORS
|
||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "false");
|
||||
response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||
response.setHeader("Access-Control-Allow-Headers", "Content-Type , Authorization," +
|
||||
"Accept,Origin,X-Requested-With");
|
||||
response.setHeader("Access-Control-Max-Age", "216000");
|
||||
response.setHeader("Content-Type","application/json;charset=UTF-8");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
37
src/main/java/com/xkrs/common/config/MvcConfig.java
Normal file
37
src/main/java/com/xkrs/common/config/MvcConfig.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* WebMVC配置
|
||||
* @author Tajochen
|
||||
*/
|
||||
@Configuration
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* 放行跨域请求
|
||||
*/
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("*");
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务线程池更改,防止多个任务并行
|
||||
*/
|
||||
@Bean
|
||||
public TaskScheduler taskScheduler() {
|
||||
final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.setPoolSize(5);
|
||||
return scheduler;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Redis 缓存自动配置
|
||||
* @author tajochen
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureAfter(RedisAutoConfiguration.class)
|
||||
public class RedisCacheAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Serializable> redisCacheTemplate(LettuceConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, Serializable> template = new RedisTemplate<>();
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
template.setConnectionFactory(redisConnectionFactory);
|
||||
return template;
|
||||
}
|
||||
}
|
187
src/main/java/com/xkrs/common/config/RedisConfig.java
Normal file
187
src/main/java/com/xkrs/common/config/RedisConfig.java
Normal file
@ -0,0 +1,187 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.CacheErrorHandler;
|
||||
import org.springframework.cache.interceptor.CacheResolver;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* redis配置
|
||||
* @author tajochen
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class RedisConfig extends CachingConfigurerSupport{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);
|
||||
|
||||
@Resource
|
||||
private LettuceConnectionFactory lettuceConnectionFactory;
|
||||
|
||||
private static final Duration TIME_TO_LIVE = Duration.ofSeconds(3600*6);
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public KeyGenerator keyGenerator() {
|
||||
|
||||
// 设置自动key的生成规则,配置spring boot的注解,进行方法级别的缓存
|
||||
return (target, method, params) -> {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(target.getClass().getName());
|
||||
sb.append(":");
|
||||
sb.append(method.getName());
|
||||
for (Object obj : params) {
|
||||
sb.append(":").append(obj);
|
||||
}
|
||||
// logger.info("自动生成Redis Key -> [{}]", rsToUse);
|
||||
return String.valueOf(sb);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public CacheManager cacheManager() {
|
||||
// 关键点,spring cache的注解使用的序列化都从这来,没有这个配置的话使用的jdk自己的序列化
|
||||
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
|
||||
//key序列化方式
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(keySerializer()))
|
||||
//value序列化方式
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(valueSerializer()))
|
||||
.disableCachingNullValues()
|
||||
.entryTtl(TIME_TO_LIVE);
|
||||
|
||||
RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder
|
||||
.fromConnectionFactory(lettuceConnectionFactory)
|
||||
.cacheDefaults(config)
|
||||
.transactionAware();
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* RedisTemplate配置 在单独使用redisTemplate的时候 重新定义序列化方式
|
||||
*/
|
||||
@Bean(name = "redisTemplate")
|
||||
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
||||
// 设置序列化
|
||||
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
// 配置null值序列化成空字符串
|
||||
om.getSerializerProvider().setNullValueSerializer(new JsonSerializer<>() {
|
||||
@Override
|
||||
public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||
jsonGenerator.writeString("");
|
||||
}
|
||||
});
|
||||
// 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
om.registerModule(javaTimeModule);
|
||||
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
// 其他设置
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance ,
|
||||
ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
// 配置redisTemplate
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||
RedisSerializer<?> stringSerializer = new StringRedisSerializer();
|
||||
redisTemplate.setKeySerializer(stringSerializer);
|
||||
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
|
||||
redisTemplate.setHashKeySerializer(stringSerializer);
|
||||
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
private RedisSerializer<String> keySerializer() {
|
||||
return new StringRedisSerializer();
|
||||
}
|
||||
|
||||
private RedisSerializer<Object> valueSerializer() {
|
||||
// 设置序列化
|
||||
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(
|
||||
Object.class);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
// 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
om.registerModule(javaTimeModule);
|
||||
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
// 其他设置
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance ,
|
||||
ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
|
||||
jackson2JsonRedisSerializer.setObjectMapper(om);
|
||||
return jackson2JsonRedisSerializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CacheResolver cacheResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据存入 redis 的序列化方式,并开启事务
|
||||
*
|
||||
* @param redisTemplate
|
||||
* @param factory
|
||||
*/
|
||||
private void initRedisTemplate(RedisTemplate<String, Object> redisTemplate, RedisConnectionFactory factory) {
|
||||
//如果不配置Serializer,那么存储的时候缺省使用String,如果用User类型存储,那么会提示错误User can't cast to String!
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
// 开启事务
|
||||
redisTemplate.setEnableTransactionSupport(true);
|
||||
redisTemplate.setConnectionFactory(factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入封装RedisTemplate 给RedisUtil提供操作类
|
||||
* @param redisTemplate
|
||||
* @return RedisUtil
|
||||
*/
|
||||
@Bean(name = "redisUtil")
|
||||
public RedisUtil redisUtil(RedisTemplate<String, Object> redisTemplate) {
|
||||
RedisUtil redisUtil = new RedisUtil();
|
||||
redisUtil.setRedisTemplate(redisTemplate);
|
||||
return redisUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public CacheErrorHandler errorHandler() {
|
||||
// 异常处理,当Redis发生异常时,打印日志,但是程序正常走
|
||||
logger.info("初始化 -> [{}]", "Redis CacheErrorHandler");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
533
src/main/java/com/xkrs/common/config/RedisUtil.java
Normal file
533
src/main/java/com/xkrs/common/config/RedisUtil.java
Normal file
@ -0,0 +1,533 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* redis工具类
|
||||
* @author tajochen
|
||||
*/
|
||||
public class RedisUtil {
|
||||
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定缓存失效时间
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
* @return
|
||||
*/
|
||||
public boolean expire(String key,long time){
|
||||
try {
|
||||
if(time>0){
|
||||
redisTemplate.expire(key, time, TimeUnit.SECONDS);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key 获取过期时间
|
||||
* @param key 键 不能为null
|
||||
* @return 时间(秒) 返回0 代表为永久有效
|
||||
*/
|
||||
public long getExpire(String key){
|
||||
return redisTemplate.getExpire(key,TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断key是否存在
|
||||
* @param key 键
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean hasKey(String key){
|
||||
try {
|
||||
return redisTemplate.hasKey(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @param key 可以传一个值 或多个
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void del(String ... key){
|
||||
if(key!=null&&key.length>0){
|
||||
if(key.length==1){
|
||||
redisTemplate.delete(key[0]);
|
||||
}else{
|
||||
redisTemplate.delete(String.valueOf(CollectionUtils.arrayToList(key)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//============================String=============================
|
||||
/**
|
||||
* 普通缓存获取
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public Object get(String key){
|
||||
return key==null?null:redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通缓存放入
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public boolean set(String key,Object value) {
|
||||
try {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通缓存放入并设置时间
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
|
||||
* @return true成功 false 失败
|
||||
*/
|
||||
public boolean set(String key,Object value,long time){
|
||||
try {
|
||||
if(time>0){
|
||||
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
||||
} else {
|
||||
set(key, value);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递增
|
||||
* @param key 键
|
||||
* @param delta 要增加几(大于0)
|
||||
* @return
|
||||
*/
|
||||
public long incr(String key, long delta){
|
||||
if(delta<0){
|
||||
throw new RuntimeException("递增因子必须大于0");
|
||||
}
|
||||
return redisTemplate.opsForValue().increment(key, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递减
|
||||
* @param key 键
|
||||
* @param delta 要减少几(小于0)
|
||||
* @return
|
||||
*/
|
||||
public long decr(String key, long delta){
|
||||
if(delta<0){
|
||||
throw new RuntimeException("递减因子必须大于0");
|
||||
}
|
||||
return redisTemplate.opsForValue().increment(key, -delta);
|
||||
}
|
||||
|
||||
//================================Map=================================
|
||||
/**
|
||||
* HashGet
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return 值
|
||||
*/
|
||||
public Object hget(String key,String item){
|
||||
return redisTemplate.opsForHash().get(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取hashKey对应的所有键值
|
||||
* @param key 键
|
||||
* @return 对应的多个键值
|
||||
*/
|
||||
public Map<Object,Object> hmget(String key){
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @return true 成功 false 失败
|
||||
*/
|
||||
public boolean hmset(String key, Map<String,Object> map){
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet 并设置时间
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @param time 时间(秒)
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public boolean hmset(String key, Map<String,Object> map, long time){
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
if(time>0){
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public boolean hset(String key,String item,Object value) {
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public boolean hset(String key,String item,Object value,long time) {
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
if(time>0){
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除hash表中的值
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 可以使多个 不能为null
|
||||
*/
|
||||
public void hdel(String key, Object... item){
|
||||
redisTemplate.opsForHash().delete(key,item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断hash表中是否有该项的值
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean hHasKey(String key, String item){
|
||||
return redisTemplate.opsForHash().hasKey(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要增加几(大于0)
|
||||
* @return
|
||||
*/
|
||||
public double hincr(String key, String item,double by){
|
||||
return redisTemplate.opsForHash().increment(key, item, by);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash递减
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要减少记(小于0)
|
||||
* @return
|
||||
*/
|
||||
public double hdecr(String key, String item,double by){
|
||||
return redisTemplate.opsForHash().increment(key, item,-by);
|
||||
}
|
||||
|
||||
//============================set=============================
|
||||
/**
|
||||
* 根据key获取Set中的所有值
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
public Set<Object> sGet(String key){
|
||||
try {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据value从一个set中查询,是否存在
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean sHasKey(String key,Object value){
|
||||
try {
|
||||
return Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(key, value));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据放入set缓存
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
*/
|
||||
public long sSet(String key, Object...values) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().add(key, values);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将set数据放入缓存
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
*/
|
||||
public long sSetAndTime(String key,long time,Object...values) {
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().add(key, values);
|
||||
if(time>0)
|
||||
{expire(key, time);}
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取set缓存的长度
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
public long sGetSetSize(String key){
|
||||
try {
|
||||
return redisTemplate.opsForSet().size(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除值为value的
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 移除的个数
|
||||
*/
|
||||
public long setRemove(String key, Object ...values) {
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().remove(key, values);
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
//===============================list=================================
|
||||
|
||||
/**
|
||||
* 获取list缓存的内容
|
||||
* @param key 键
|
||||
* @param start 开始
|
||||
* @param end 结束 0 到 -1代表所有值
|
||||
* @return
|
||||
*/
|
||||
public List<Object> lGet(String key, long start, long end){
|
||||
try {
|
||||
return redisTemplate.opsForList().range(key, start, end);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取list缓存的长度
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
public long lGetListSize(String key){
|
||||
try {
|
||||
return redisTemplate.opsForList().size(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过索引 获取list中的值
|
||||
* @param key 键
|
||||
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
|
||||
* @return
|
||||
*/
|
||||
public Object lGetIndex(String key,long index){
|
||||
try {
|
||||
return redisTemplate.opsForList().index(key, index);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return
|
||||
*/
|
||||
public boolean lSet(String key, Object value) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒)
|
||||
* @return
|
||||
*/
|
||||
public boolean lSet(String key, Object value, long time) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
if (time > 0)
|
||||
{expire(key, time);}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return
|
||||
*/
|
||||
public boolean lSet(String key, List<Object> value) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒)
|
||||
* @return
|
||||
*/
|
||||
public boolean lSet(String key, List<Object> value, long time) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据索引修改list中的某条数据
|
||||
* @param key 键
|
||||
* @param index 索引
|
||||
* @param value 值
|
||||
* @return
|
||||
*/
|
||||
public boolean lUpdateIndex(String key, long index,Object value) {
|
||||
try {
|
||||
redisTemplate.opsForList().set(key, index, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除N个值为value
|
||||
* @param key 键
|
||||
* @param count 移除多少个
|
||||
* @param value 值
|
||||
* @return 移除的个数
|
||||
*/
|
||||
public long lRemove(String key,long count,Object value) {
|
||||
try {
|
||||
Long remove = redisTemplate.opsForList().remove(key, count, value);
|
||||
return remove;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
63
src/main/java/com/xkrs/common/config/WebSecurityConfig.java
Normal file
63
src/main/java/com/xkrs/common/config/WebSecurityConfig.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.xkrs.common.config;
|
||||
|
||||
import com.xkrs.common.account.CustomAuthenticationProvider;
|
||||
import com.xkrs.common.account.JwtAuthenticationFilter;
|
||||
import com.xkrs.common.account.JwtLoginFilter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled=true)
|
||||
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
/**
|
||||
* 设置 HTTP 验证规则
|
||||
* @param http
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// 关闭csrf验证
|
||||
http.csrf().disable()
|
||||
// 对请求进行认证
|
||||
.authorizeRequests()
|
||||
// 所有 / 的所有请求 都放行
|
||||
.antMatchers("/").permitAll()
|
||||
// 所有OPTIONS请求都放行
|
||||
.antMatchers(HttpMethod.OPTIONS).permitAll()
|
||||
// 所有 /user/add 用户注册 的POST请求 都放行
|
||||
.antMatchers(HttpMethod.POST, "/api/user/add").permitAll()
|
||||
// 所有 /user/check/duplicate 检查用户名是否重复 的POST请求 都放行
|
||||
.antMatchers(HttpMethod.POST, "/api/user/check/duplicate").permitAll()
|
||||
// 所有 /login 用户登录 的POST请求 都放行
|
||||
.antMatchers(HttpMethod.POST, "/api/login").permitAll()
|
||||
// 所有 app 用户注册 的POST请求 都放行
|
||||
.antMatchers(HttpMethod.POST, "/api/person-investigator/add").permitAll()
|
||||
.antMatchers(HttpMethod.GET,"/api/user/verificationCode").permitAll()
|
||||
// 手机号登录
|
||||
.antMatchers(HttpMethod.POST,"/api/user/loginByPhone").permitAll()
|
||||
// 所有其它请求需要身份认证
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
// 添加一个过滤器 所有访问 /login 的请求交给 JWTLoginFilter 来处理 这个类处理所有的JWT相关内容
|
||||
.addFilterBefore(new JwtLoginFilter("/api/login", authenticationManager()),
|
||||
UsernamePasswordAuthenticationFilter.class)
|
||||
// 添加一个过滤器验证其他请求的Token是否合法
|
||||
.addFilterBefore(new JwtAuthenticationFilter(),
|
||||
UsernamePasswordAuthenticationFilter.class);
|
||||
;}
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// 使用自定义身份验证组件
|
||||
auth.authenticationProvider(new CustomAuthenticationProvider());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.xkrs.common.encapsulation;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 输出信息对象
|
||||
* @author tajochen
|
||||
* @param <T>
|
||||
*/
|
||||
public class EncapsulationObejct<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
int status;
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
*/
|
||||
String msg;
|
||||
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
T data;
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EncapsulationObejct{" +
|
||||
"status=" + status +
|
||||
", msg='" + msg + '\'' +
|
||||
", data=" + data +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.xkrs.common.encapsulation;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.FieldError;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 输出信息封装
|
||||
* @author tajochen
|
||||
*/
|
||||
@Component
|
||||
public class OutputEncapsulation {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(OutputEncapsulation.class);
|
||||
|
||||
/**
|
||||
* 读取多国语言文件
|
||||
* @return
|
||||
*/
|
||||
public static MessageSource messageSource() {
|
||||
Properties properties = new Properties();
|
||||
// 使用ClassLoader加载properties配置文件生成对应的输入流
|
||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties");
|
||||
// 使用properties对象加载输入流
|
||||
try {
|
||||
properties.load(in);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
||||
messageSource.setBasename("i18n/messages");
|
||||
messageSource.setDefaultEncoding("UTF-8");
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装输出数据
|
||||
* @param promptMessageEnum
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static String outputEncapsulationObject(PromptMessageEnum promptMessageEnum, Object obj, Locale locale) {
|
||||
|
||||
EncapsulationObejct encapsulationObejct = new EncapsulationObejct();
|
||||
encapsulationObejct.setStatus(promptMessageEnum.getCode());
|
||||
encapsulationObejct.setMsg(messageSource().getMessage(promptMessageEnum.getText(),null,locale));
|
||||
encapsulationObejct.setData(obj);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// 忽略无法转换的对象
|
||||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
|
||||
// 忽略json字符串中不识别的属性
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
// 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
objectMapper.registerModule(javaTimeModule);
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
String strByEo = "";
|
||||
try {
|
||||
strByEo = objectMapper.writeValueAsString(encapsulationObejct);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
logger.warn(e.toString());
|
||||
}
|
||||
return strByEo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出请求值检验错误信息
|
||||
* @param fieldErrors
|
||||
* @return
|
||||
*/
|
||||
public static String outputEncapsulationErrorList(List<FieldError> fieldErrors, Locale locale){
|
||||
List<String> errorMsg = new ArrayList<>();
|
||||
for (FieldError fieldError : fieldErrors) {
|
||||
String errMessage = fieldError.getDefaultMessage().subSequence(1,fieldError.getDefaultMessage().length()-1).toString();
|
||||
errorMsg.add(messageSource().getMessage(errMessage,null,locale));
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,errorMsg,locale);
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.xkrs.common.encapsulation;
|
||||
|
||||
/**
|
||||
* 提示信息枚举
|
||||
* @author tajochen
|
||||
*/
|
||||
public enum PromptMessageEnum{
|
||||
|
||||
// 执行成功
|
||||
SUCCESS(0, "sys.message.success"),
|
||||
|
||||
// 用户权限错误或非法操作: 1001-1999
|
||||
USER_NOT_LOGGED(1001, "sys.message.user.not_logged_in"),
|
||||
USER_LOGIN_ERROR(1002, "sys.message.user.login_error"),
|
||||
USER_ACCOUNT_FORBIDDEN(1003, "sys.message.user.account_forbidden"),
|
||||
USER_ACCOUNT_NOT_ACTIVATED(1004, "sys.message.user.account_not_activated"),
|
||||
USER_HAS_OVERTIME(1005, "sys.message.user.overtime"),
|
||||
USER_NO_PERMISSION(1006,"sys.message.user.no_permission"),
|
||||
USER_ALREADY_LOGGED(1007, "sys.message.user.already_logged"),
|
||||
|
||||
// 请求参数错误或非法:2001-2999
|
||||
PARAM_NULL(2001, "sys.message.param.null"),
|
||||
PARAM_ILLEGAL(2002, "sys.message.param.illegal"),
|
||||
|
||||
// 数据返回错误:3001-3999
|
||||
DATA_NONE(3001, "sys.message.data.none"),
|
||||
DATA_WRONG(3002, "sys.message.data.wrong"),
|
||||
|
||||
// 操作失败:4001-4999
|
||||
PROCESS_FAIL(4001,"sys.message.process.fail"),
|
||||
PROCESS_OVERTIME(4002,"sys.message.process.overtime"),
|
||||
FILE_EXISTS(4003,"sys.message.file.exists"),
|
||||
FILE_WRITE_ERROR(4004,"sys.message.file.write.error"),
|
||||
FILE_READ_ERROR(4005,"sys.message.file.read.error"),
|
||||
|
||||
// 系统内部错误或异常:5001-5999
|
||||
SYSTEM_INNER_ERROR(5001,"sys.message.system.inner_error"),
|
||||
SYSTEM_ABNORMAL(5002,"sys.message.system.abnormal"),
|
||||
SYSTEM_BUSY(5003,"sys.message.system.busy"),
|
||||
SYSTEM_MAINTAIN(5004,"sys.message.system.maintain"),
|
||||
|
||||
// 数据库错误:6001-6999
|
||||
DATABASE_ERROR(6001,"sys.message.database.error");
|
||||
|
||||
private int code;
|
||||
|
||||
private String text;
|
||||
|
||||
private PromptMessageEnum(int code,String text) {
|
||||
this.code = code;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
}
|
33
src/main/java/com/xkrs/common/tool/CompareVersion.java
Normal file
33
src/main/java/com/xkrs/common/tool/CompareVersion.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.xkrs.common.tool;
|
||||
|
||||
/**
|
||||
* CompareVersion 比较版本号
|
||||
* @author tajochen
|
||||
*/
|
||||
public class CompareVersion {
|
||||
|
||||
/**
|
||||
* 比较三位版本号 ,若 版本1>版本2 返回 1,若版本1<版本2 返回 -1,否则返回0
|
||||
* @param version1 版本1
|
||||
* @param version2 版本2
|
||||
* @return
|
||||
*/
|
||||
public static int compareVersion(String version1, String version2) {
|
||||
String[] v1 = version1.split("\\.");
|
||||
String[] v2 = version2.split("\\.");
|
||||
int n = Math.max(v1.length, v2.length);
|
||||
for (int i = 0; i < n; i++) {
|
||||
int v1Int = i < v1.length ? Integer.parseInt(v1[i]) : 0;
|
||||
int v2Int = i < v2.length ? Integer.parseInt(v2[i]) : 0;
|
||||
if (v1Int == v2Int) {
|
||||
continue;
|
||||
}
|
||||
if (v1Int > v2Int){
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
98
src/main/java/com/xkrs/common/tool/EntityUtil.java
Normal file
98
src/main/java/com/xkrs/common/tool/EntityUtil.java
Normal file
@ -0,0 +1,98 @@
|
||||
package com.xkrs.common.tool;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* dao接口类处理工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class EntityUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EntityUtil.class);
|
||||
|
||||
/**
|
||||
* 将数组数据转换为实体类
|
||||
* 此处数组元素的顺序必须与实体类构造函数中的属性顺序一致
|
||||
* @param list 数组对象集合
|
||||
* @param clazz 实体类
|
||||
* @param <T> 实体类
|
||||
* @param model 实例化的实体类
|
||||
* @return 实体类集合
|
||||
*/
|
||||
public static <T> List<T> castEntity(List<Object[]> list, Class<T> clazz, Object model) {
|
||||
List<T> returnList = new ArrayList<T>();
|
||||
if (list.isEmpty()) {
|
||||
return returnList;
|
||||
}
|
||||
//获取每个数组集合的元素个数
|
||||
Object[] co = list.get(0);
|
||||
|
||||
//获取当前实体类的属性名、属性值、属性类别
|
||||
List<Map> attributeInfoList = getFiledsInfo(model);
|
||||
//创建属性类别数组
|
||||
Class[] c2 = new Class[attributeInfoList.size()];
|
||||
//如果数组集合元素个数与实体类属性个数不一致则发生错误
|
||||
if (attributeInfoList.size() != co.length) {
|
||||
return returnList;
|
||||
}
|
||||
//确定构造方法
|
||||
for (int i = 0; i < attributeInfoList.size(); i++) {
|
||||
c2[i] = (Class) attributeInfoList.get(i).get("type");
|
||||
}
|
||||
try {
|
||||
for (Object[] o : list) {
|
||||
Constructor<T> constructor = clazz.getConstructor(c2);
|
||||
returnList.add(constructor.newInstance(o));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("实体数据转化为实体类发生异常:异常信息:{}", ex.getMessage());
|
||||
return returnList;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性名获取属性值
|
||||
* @param fieldName 属性名
|
||||
* @param modle 实体类
|
||||
* @return 属性值
|
||||
*/
|
||||
private static Object getFieldValueByName(String fieldName, Object modle) {
|
||||
try {
|
||||
String firstLetter = fieldName.substring(0, 1).toUpperCase();
|
||||
String getter = "get" + firstLetter + fieldName.substring(1);
|
||||
Method method = modle.getClass().getMethod(getter, new Class[]{});
|
||||
Object value = method.invoke(modle, new Object[]{});
|
||||
return value;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取属性类型(type),属性名(name),属性值(value)的map组成的list
|
||||
* @param model 实体类
|
||||
* @return list集合
|
||||
*/
|
||||
private static List<Map> getFiledsInfo(Object model) {
|
||||
Field[] fields = model.getClass().getDeclaredFields();
|
||||
List<Map> list = new ArrayList(fields.length);
|
||||
Map infoMap = null;
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
infoMap = new HashMap(3);
|
||||
infoMap.put("type", fields[i].getType());
|
||||
infoMap.put("name", fields[i].getName());
|
||||
infoMap.put("value", getFieldValueByName(fields[i].getName(), model));
|
||||
list.add(infoMap);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
51
src/main/java/com/xkrs/common/tool/TokenUtil.java
Normal file
51
src/main/java/com/xkrs/common/tool/TokenUtil.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.xkrs.common.tool;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* token工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class TokenUtil {
|
||||
/**
|
||||
* Token前缀
|
||||
*/
|
||||
static public final String TOKEN_PREFIX = "Bearer";
|
||||
|
||||
static public final String SECRETKEY = "0Y9H364Q9Y908262F25LMXGIKIN5N858XM3674GWL2DD8X1DS4W6I722IRY8PS4XPNB6U30345" +
|
||||
"HBVCUL94STG8C3Z53T7A09JJ100I56YE9894CI11PX9J71HIZ8L5Y2O504C4E2K8276425UA8734833F45K36878FXAG799QV9LXUJ" +
|
||||
"OI3XA2046UPG8TB2OT84R5T6ZB127N9ZPJ7AJMC41JVHB2WK2B6H8NL45LZNAZ666KHZH3QUT65UX6F8";
|
||||
|
||||
static SecretKey key = Keys.hmacShaKeyFor(SECRETKEY.getBytes());
|
||||
|
||||
public static String getTokenUserName(String token) {
|
||||
String userName = "";
|
||||
if (token != null) {
|
||||
try {
|
||||
// 解析 Token
|
||||
Claims claims = Jwts.parserBuilder()
|
||||
.setSigningKey(key).build()
|
||||
// 去掉 Bearer
|
||||
.parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
|
||||
.getBody();
|
||||
// 获取用户名
|
||||
userName = claims.getSubject();
|
||||
// 获取权限
|
||||
List<GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList((String) claims.get("auths"));
|
||||
} catch(Exception e) {
|
||||
// the sub field was missing or did not have a 'jsmith' value
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.model.entity.FileDocumentEntity;
|
||||
import com.xkrs.model.qo.FileDocumentQo;
|
||||
import com.xkrs.model.validation.FileDocumentQoInsert;
|
||||
import com.xkrs.model.vo.FileServerResultVo;
|
||||
import com.xkrs.service.FileDocumentService;
|
||||
import com.xkrs.service.FileServerService;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationErrorList;
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
import static com.xkrs.common.tool.TokenUtil.getTokenUserName;
|
||||
import static com.xkrs.utils.NumberUtil.isStrNumeric;
|
||||
|
||||
/**
|
||||
* 文档管理服务
|
||||
* @author tajochen
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/document")
|
||||
public class FileDocumentController {
|
||||
|
||||
@Resource
|
||||
private FileDocumentService fileDocumentService;
|
||||
|
||||
@Resource
|
||||
private FileServerService fileServerService;
|
||||
|
||||
@RequestMapping(value="/get/all",method = RequestMethod.GET)
|
||||
public String getAllFiles() {
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
Iterable<FileDocumentEntity> list = fileDocumentService.getAllFile();
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,list,locale);
|
||||
}
|
||||
|
||||
@RequestMapping(value="/add",method = RequestMethod.POST)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_general_user','auth_administor')")
|
||||
@CrossOrigin
|
||||
public String fileUpload(@Validated({FileDocumentQoInsert.class}) @RequestBody FileDocumentQo fileDocumentQo,
|
||||
BindingResult bindingResult, @RequestHeader(value="Authorization") String token) {
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 验证数据合法性
|
||||
if(bindingResult.hasErrors()){
|
||||
return outputEncapsulationErrorList(bindingResult.getFieldErrors(),locale);
|
||||
}
|
||||
// 获取当前用户名
|
||||
String userName = getTokenUserName(token);
|
||||
fileDocumentService.add(fileDocumentQo,userName);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
|
||||
}
|
||||
|
||||
@RequestMapping(value="/delete",method = RequestMethod.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_administor')")
|
||||
@CrossOrigin
|
||||
public String fileDelete(@RequestParam("id") String id) {
|
||||
//获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
if(!isStrNumeric(id)){
|
||||
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,"参数错误",locale);
|
||||
}
|
||||
Optional <FileDocumentEntity> sf = fileDocumentService.getById(Integer.parseInt(id));
|
||||
if(!sf.isPresent()){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"指定id文件不存在",locale);
|
||||
}
|
||||
try {
|
||||
FileServerResultVo fileServerResultVo = fileServerService.deleteFile(sf.get().getMd5(),"");
|
||||
fileDocumentService.delete(Integer.parseInt(id));
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,fileServerResultVo,locale);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"文件服务器出错",locale);
|
||||
}
|
||||
}
|
||||
}
|
114
src/main/java/com/xkrs/controller/FileServerController.java
Normal file
114
src/main/java/com/xkrs/controller/FileServerController.java
Normal file
@ -0,0 +1,114 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import com.xkrs.model.vo.FileServerResultVo;
|
||||
import com.xkrs.service.FileServerService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 文件服务器管理服务
|
||||
* @author tajochen
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/file")
|
||||
public class FileServerController {
|
||||
|
||||
@Resource
|
||||
private FileServerService fileServerService;
|
||||
|
||||
/**
|
||||
* 文件统计
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/stat",method = RequestMethod.GET)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_administor')")
|
||||
@CrossOrigin
|
||||
public FileServerResultVo getFileStat() {
|
||||
|
||||
return fileServerService.getFileStat();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件删除
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/delete",method = RequestMethod.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','role_administor')")
|
||||
@CrossOrigin
|
||||
public FileServerResultVo deleteFile(@RequestParam(value = "md5",required = false) String md5,
|
||||
@RequestParam(value = "path",required = false) String path) {
|
||||
FileServerResultVo fileServerResultVo = new FileServerResultVo();
|
||||
Boolean existed = (md5==null||md5.isEmpty())&&(path==null||path.isEmpty());
|
||||
if(existed){
|
||||
fileServerResultVo.setStatus("fail");
|
||||
fileServerResultVo.setData("");
|
||||
fileServerResultVo.setMessage("参数为空");
|
||||
return fileServerResultVo;
|
||||
}
|
||||
return fileServerService.deleteFile(md5,path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/get/info",method = RequestMethod.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','role_administor')")
|
||||
@CrossOrigin
|
||||
public FileServerResultVo getFileInfo(@RequestParam(value = "md5",required = false) String md5,
|
||||
@RequestParam(value = "path",required = false) String path) {
|
||||
|
||||
FileServerResultVo fileServerResultVo = new FileServerResultVo();
|
||||
Boolean existed = (md5==null||md5.isEmpty())&&(path==null||path.isEmpty());
|
||||
if(existed){
|
||||
fileServerResultVo.setStatus("fail");
|
||||
fileServerResultVo.setData("");
|
||||
fileServerResultVo.setMessage("参数为空");
|
||||
return fileServerResultVo;
|
||||
}
|
||||
return fileServerService.getFileInfo(md5,path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @param dir 文件夹
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/get/list",method = RequestMethod.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','role_administor')")
|
||||
@CrossOrigin
|
||||
public FileServerResultVo getFileList(@RequestParam(value = "dir") String dir) {
|
||||
return fileServerService.getFileList(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复统计信息
|
||||
* @param date 要修复的日期,格式如:20190725
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/get/repair_stat",method = RequestMethod.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','role_administor')")
|
||||
@CrossOrigin
|
||||
public FileServerResultVo getFileRepairStat(@RequestParam(value = "date") String date) {
|
||||
return fileServerService.getFileRepairStat(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步失败修复
|
||||
* @param force 是否强行修复(0|1)
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/get/repair",method = RequestMethod.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','role_administor')")
|
||||
@CrossOrigin
|
||||
public FileServerResultVo getFileRepair(@RequestParam(value = "force") String force) {
|
||||
return fileServerService.getFileRepair(force);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import com.xkrs.common.config.RedisUtil;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.common.tool.TokenUtil;
|
||||
import com.xkrs.dao.SysUserDao;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.qo.BankCardQo;
|
||||
import com.xkrs.model.qo.BusinessQo;
|
||||
import com.xkrs.service.MerchantSettlementService;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 14:40
|
||||
*/
|
||||
@RestController
|
||||
public class MerchantSettlementController {
|
||||
|
||||
@Resource
|
||||
private MerchantSettlementService merchantSettlementService;
|
||||
|
||||
@Resource
|
||||
private SysUserDao sysUserDao;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 商家入驻
|
||||
* @param
|
||||
* @param businessPhoto
|
||||
* @param businessLicense
|
||||
* @param
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/merchantSettlement")
|
||||
public String merchantSettlement(@RequestBody Map map, @RequestParam("businessPhoto") MultipartFile businessPhoto,
|
||||
@RequestParam("businessLicense") MultipartFile businessLicense) throws IOException {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
String businessName = (String) map.get("businessName");
|
||||
String businessPro = (String) map.get("businessPro");
|
||||
String businessCity = (String) map.get("businessCity");
|
||||
String businessCountry = (String) map.get("businessCountry");
|
||||
String businessAddress = (String) map.get("businessAddress");
|
||||
String businessPhone = (String) map.get("businessPhone");
|
||||
Double businessDiscount = (Double) map.get("businessDiscount");
|
||||
String headIdentifier = (String) map.get("headIdentifier");
|
||||
List<BankCardQo> bankCardQos = (List<BankCardQo>) map.get("bankCardQos");
|
||||
String verificationCode = (String) map.get("verificationCode");
|
||||
BusinessQo businessQo = new BusinessQo();
|
||||
businessQo.setBusinessName(businessName);
|
||||
businessQo.setBusinessPro(businessPro);
|
||||
businessQo.setBusinessCity(businessCity);
|
||||
businessQo.setBusinessCountry(businessCountry);
|
||||
businessQo.setBusinessAddress(businessAddress);
|
||||
businessQo.setBusinessPhone(businessPhone);
|
||||
businessQo.setBusinessDiscount(businessDiscount);
|
||||
businessQo.setHeadIdentifier(headIdentifier);
|
||||
String o = (String) redisUtil.get(businessPhone);
|
||||
if("".equals(o) || o == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale);
|
||||
}
|
||||
if(!redisUtil.get(businessPhone).equals(verificationCode)){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
|
||||
}
|
||||
return merchantSettlementService.merchantSettlement(businessQo,businessPhoto,businessLicense,bankCardQos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商家入驻状态查询待审核,审核通过,审核不通过商家的信息
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/findAllByBusinessType")
|
||||
@PreAuthorize("hasAnyAuthority('auth_administor')")
|
||||
public String findAllByBusinessType(@RequestParam("type") String type){
|
||||
return merchantSettlementService.findAllByBusinessType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家查询自己的入驻信息
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/findBusinessById")
|
||||
public String findBusinessById(@RequestHeader(value="Authorization") String token){
|
||||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||||
return merchantSettlementService.findBusinessById(sysUserEntity.getId());
|
||||
}
|
||||
}
|
57
src/main/java/com/xkrs/controller/SysManageController.java
Normal file
57
src/main/java/com/xkrs/controller/SysManageController.java
Normal file
@ -0,0 +1,57 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import nl.basjes.parse.useragent.UserAgent;
|
||||
import nl.basjes.parse.useragent.UserAgentAnalyzer;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
|
||||
/**
|
||||
* 系统管理测试服务
|
||||
* @author tajochen
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api")
|
||||
public class SysManageController {
|
||||
|
||||
@RequestMapping(value="/hello/role",method = RequestMethod.GET)
|
||||
@PreAuthorize("hasAnyRole('role_administor','role_system_manager')")
|
||||
public String hello() {
|
||||
//获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"hello vip",locale);
|
||||
}
|
||||
|
||||
@RequestMapping(value="/hello/auth",method = RequestMethod.GET)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_general_user')")
|
||||
public String world() {
|
||||
//获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"world",locale);
|
||||
}
|
||||
|
||||
@RequestMapping(value="/greeting",method = RequestMethod.GET)
|
||||
public String greeting(@RequestParam(required=false, defaultValue="World") String name,
|
||||
@RequestHeader(value="User-Agent") String userAgent) {
|
||||
//获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
System.out.println("==== in greeting ====");
|
||||
System.out.println(userAgent);
|
||||
UserAgentAnalyzer uaa = UserAgentAnalyzer
|
||||
.newBuilder()
|
||||
.hideMatcherLoadStats()
|
||||
.withCache(10000)
|
||||
.build();
|
||||
|
||||
UserAgent agent = uaa.parse(userAgent);
|
||||
for (String fieldName: agent.getAvailableFieldNamesSorted()) {
|
||||
System.out.println(fieldName + " = " + agent.getValue(fieldName));
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,name,locale);
|
||||
}
|
||||
}
|
299
src/main/java/com/xkrs/controller/SysUserController.java
Normal file
299
src/main/java/com/xkrs/controller/SysUserController.java
Normal file
@ -0,0 +1,299 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.xkrs.common.config.RedisUtil;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.common.tool.TokenUtil;
|
||||
import com.xkrs.dao.SysUserDao;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.qo.SysUserQo;
|
||||
import com.xkrs.model.qo.UserUpdate;
|
||||
import com.xkrs.model.validation.SysUserQoInsert;
|
||||
import com.xkrs.model.validation.SysUserQoUpdate;
|
||||
import com.xkrs.model.vo.SysUserVo;
|
||||
import com.xkrs.service.SysUserService;
|
||||
import com.xkrs.utils.RandomUtil;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationErrorList;
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
import static com.xkrs.utils.AliYunSmsUtils.sendSms;
|
||||
|
||||
/**
|
||||
* 系统用户Controller
|
||||
* @author tajocehn
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/user")
|
||||
public class SysUserController {
|
||||
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Resource
|
||||
private SysUserDao sysUserDao;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 登录用户Token验证
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/logged/check",method = RequestMethod.POST)
|
||||
public String loginUserTokenCheck(){
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/check/duplicate", method = RequestMethod.POST)
|
||||
public String checkDuplicate(@RequestParam(value="userName", required=false) String userName){
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 验证用户名是否重复
|
||||
if(!sysUserService.checkUserName(userName)){
|
||||
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,"",locale);
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"OK",locale);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||
public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo,
|
||||
BindingResult bindingResult){
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 验证数据合法性
|
||||
if(bindingResult.hasErrors()){
|
||||
return outputEncapsulationErrorList(bindingResult.getFieldErrors(),locale);
|
||||
}
|
||||
// 验证用户名是否重复
|
||||
if(!sysUserService.checkUserName(userQo.getUserName())){
|
||||
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,"该账号已注册,请勿重复注册!",locale);
|
||||
}
|
||||
// 添加新用户
|
||||
sysUserService.addUser(userQo);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"OK",locale);
|
||||
}
|
||||
|
||||
|
||||
/*@RequestMapping(value="/get/all", method = RequestMethod.GET)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_administor')")
|
||||
public String getAllSysUser(){
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
Iterable<SysUserVo> sysUserDtoList = sysUserService.getAllSysUser();
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,sysUserDtoList,locale);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 软删除指定id的普通用户
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/general/delete", method = RequestMethod.DELETE)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_general_user')")
|
||||
public String deleteCustomUser(@RequestParam(value="userId", required=false) int id){
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 验证数据合法性
|
||||
int res = sysUserService.softDeleteGeneralUser(id);
|
||||
if(res==1){
|
||||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"",locale);
|
||||
} else {
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_administor')")
|
||||
public String updateUser(@Validated({SysUserQoUpdate.class}) @RequestBody SysUserQo userQo,
|
||||
BindingResult bindingResult){
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 验证数据合法性
|
||||
if(bindingResult.hasErrors()){
|
||||
return outputEncapsulationErrorList(bindingResult.getFieldErrors(),locale);
|
||||
}
|
||||
// 修改用户
|
||||
sysUserService.updateSysUser(userQo);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"OK",locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
* @param map
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/bindPhone")
|
||||
public String bindPhone(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
String phone = (String) map.get("phone");
|
||||
String verificationCode = (String) map.get("verificationCode");
|
||||
// 验证token
|
||||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||||
if(sysUserEntity == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
|
||||
}
|
||||
String o = (String) redisUtil.get(phone);
|
||||
if("".equals(o) || o == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale);
|
||||
}
|
||||
if(!redisUtil.get(phone).equals(verificationCode)){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
|
||||
}
|
||||
return sysUserService.bindPhone(sysUserEntity.getId(),phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送手机号
|
||||
* @param phone
|
||||
* @return
|
||||
* @throws ClientException
|
||||
*/
|
||||
@GetMapping("/verificationCode")
|
||||
public String verificationCode(@RequestParam("phone") String phone) throws ClientException {
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
String optCode = String.valueOf(RandomUtil.returnCode());
|
||||
redisUtil.set(phone,optCode,60*10);
|
||||
SendSmsResponse response =sendSms(phone,optCode);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale); }
|
||||
|
||||
/**
|
||||
* 手机号登录
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/loginByPhone")
|
||||
public String loginByPhone(@RequestBody Map map){
|
||||
String phone = (String) map.get("phone");
|
||||
String verificationCode = (String) map.get("verificationCode");
|
||||
return sysUserService.loginByPhone(phone,verificationCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 填写手机号发送验证码,用于用户忘记密码
|
||||
* @param phone
|
||||
* @return
|
||||
* @throws ClientException
|
||||
*/
|
||||
@GetMapping("/verificationCodeUpdate")
|
||||
public String verificationCodeUpdate(@RequestParam("phone") String phone) throws ClientException {
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
SysUserVo sysUserVo = sysUserDao.selectUserByUserName(phone);
|
||||
if(sysUserVo == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"手机号错误,请使用您注册的手机号",locale);
|
||||
}
|
||||
String optCode = String.valueOf(RandomUtil.returnCode());
|
||||
redisUtil.set(phone,optCode,60*10);
|
||||
SendSmsResponse response =sendSms(phone,optCode);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入验证码进行判断
|
||||
* @param phone
|
||||
* @param verificationCode
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getVerificationCode")
|
||||
public String getVerificationCode(@RequestParam("phone") String phone, @RequestParam("verificationCode") String verificationCode){
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
String o = (String) redisUtil.get(phone);
|
||||
if("".equals(o) || o == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale);
|
||||
}
|
||||
if(!redisUtil.get(phone).equals(verificationCode)){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"true",locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户完善信息
|
||||
* @param files
|
||||
* @param userUpdate
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updateUserByUserId")
|
||||
public String updateUserByUserId(@RequestParam("file") MultipartFile files, UserUpdate userUpdate, @RequestHeader(value="Authorization") String token) throws IOException {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
if(userUpdate.getNickName() != null){
|
||||
SysUserEntity byNickName = sysUserDao.findByNickName(userUpdate.getNickName());
|
||||
if(byNickName != null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.FILE_EXISTS,"该昵称已存在!",locale);
|
||||
}
|
||||
}
|
||||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||||
return sysUserService.updateUserByUserId(files,userUpdate,sysUserEntity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员进行启用禁用的操作
|
||||
* @param map
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/operateActiveFlag")
|
||||
@PreAuthorize("hasAnyAuthority('auth_administor')")
|
||||
public String operateActiveFlag(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
|
||||
Integer userId = (Integer) map.get("userId");
|
||||
String keepType = (String) map.get("keepType");
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 验证token
|
||||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||||
if(sysUserEntity == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
|
||||
}
|
||||
// 如果keepType等于1进行启用操作
|
||||
if("1".equals(keepType)){
|
||||
sysUserService.updateEnable(userId);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"启用成功",locale);
|
||||
}else {
|
||||
sysUserService.updateDisable(userId);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"禁用成功",locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户名是否存在
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/booleanUserName")
|
||||
public String booleanUserName(@RequestParam("userName") String userName){
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
Map map = new HashMap(3);
|
||||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(userName);
|
||||
if(sysUserEntity == null){
|
||||
map.put("status",0);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale);
|
||||
}else {
|
||||
map.put("status",1);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
src/main/java/com/xkrs/dao/BankCardDao.java
Normal file
11
src/main/java/com/xkrs/dao/BankCardDao.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.BankCardEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 9:38
|
||||
*/
|
||||
public interface BankCardDao extends JpaRepository<BankCardEntity,Long> {
|
||||
}
|
65
src/main/java/com/xkrs/dao/BusinessDao.java
Normal file
65
src/main/java/com/xkrs/dao/BusinessDao.java
Normal file
@ -0,0 +1,65 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.BusinessEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 9:37
|
||||
*/
|
||||
public interface BusinessDao extends JpaRepository<BusinessEntity,Long> {
|
||||
|
||||
/**
|
||||
* 根据商家名称查询商家信息
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
BusinessEntity findByBusinessName(String name);
|
||||
|
||||
/**
|
||||
* 根据手机号查询商家入驻信息
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
BusinessEntity findByBusinessPhone(String phone);
|
||||
|
||||
/**
|
||||
* 根据商家入驻状态查询待审核,审核通过,审核不通过商家的信息
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
List<BusinessEntity> findAllByBusinessType(String type);
|
||||
|
||||
/**
|
||||
* 根据省查询审核通过的商家的信息
|
||||
* @param businessPro
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
List<BusinessEntity> findAllByBusinessProAndAndBusinessType(String businessPro, String type);
|
||||
|
||||
/**
|
||||
* 根据市查询审核通过的商家的信息
|
||||
* @param businessCity
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
List<BusinessEntity> findAllByBusinessCityAndAndBusinessType(String businessCity, String type);
|
||||
|
||||
/**
|
||||
* 根据区县查询审核通过的商家的信息
|
||||
* @param businessCounty
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
List<BusinessEntity> findAllByBusinessCountryAndAndBusinessType(String businessCounty, String type);
|
||||
|
||||
/**|
|
||||
* 根据商家用户id查询自己的入驻信息
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
BusinessEntity findByBusinessId(Integer id);
|
||||
}
|
12
src/main/java/com/xkrs/dao/FileDocumentDao.java
Normal file
12
src/main/java/com/xkrs/dao/FileDocumentDao.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.FileDocumentEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* FileDocumentDao
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface FileDocumentDao extends JpaRepository<FileDocumentEntity,Integer> {
|
||||
|
||||
}
|
11
src/main/java/com/xkrs/dao/ProductCoverDao.java
Normal file
11
src/main/java/com/xkrs/dao/ProductCoverDao.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.ProductCoverEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 11:42
|
||||
*/
|
||||
public interface ProductCoverDao extends JpaRepository<ProductCoverEntity,Long> {
|
||||
}
|
10
src/main/java/com/xkrs/dao/RelRoleAuthorityDao.java
Normal file
10
src/main/java/com/xkrs/dao/RelRoleAuthorityDao.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.RelRoleAuthorityEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public interface RelRoleAuthorityDao extends JpaRepository<RelRoleAuthorityEntity,Long> {
|
||||
}
|
10
src/main/java/com/xkrs/dao/RelUserRoleDao.java
Normal file
10
src/main/java/com/xkrs/dao/RelUserRoleDao.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.RelUserRoleEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public interface RelUserRoleDao extends JpaRepository<RelUserRoleEntity,Long> {
|
||||
}
|
25
src/main/java/com/xkrs/dao/SysAuthorityDao.java
Normal file
25
src/main/java/com/xkrs/dao/SysAuthorityDao.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.SysAuthorityEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SysAuthorityDao
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity,Integer> {
|
||||
/**
|
||||
* 查询权限实体列表根据用户名 Object[]
|
||||
* @param userName 用户名
|
||||
* @return 用户实体
|
||||
*/
|
||||
@Query(value = "SELECT a.id, a.authority_name, a.authority_name_zh, a.authority_desc " +
|
||||
"FROM sys_authority a,rel_role_authority ra,sys_role r WHERE r.id = ra.role_id AND ra.authority_id = a.id AND r.id " +
|
||||
"IN (SELECT r.id FROM sys_user u,sys_role r,rel_user_role ur " +
|
||||
" WHERE u.user_name = :userName AND u.id = ur.user_id AND ur.role_id = r.id)", nativeQuery = true)
|
||||
List<SysAuthorityEntity> selectByUserName(@Param("userName") String userName);
|
||||
}
|
60
src/main/java/com/xkrs/dao/SysRoleDao.java
Normal file
60
src/main/java/com/xkrs/dao/SysRoleDao.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.SysRoleEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SysRoleDao
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysRoleDao extends JpaRepository<SysRoleEntity,Integer> {
|
||||
|
||||
/**
|
||||
* 查询用户角色列表根据用户id
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "SELECT sys_role.id,sys_role.role_name,sys_role.role_name_zh,sys_role.role_desc " +
|
||||
"FROM sys_role,rel_user_role " +
|
||||
"WHERE sys_role.id = rel_user_role.role_id " +
|
||||
"AND rel_user_role.user_id = :id ", nativeQuery = true)
|
||||
List<SysRoleEntity> selectByUserId(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 查询用户角色列表根据用户名
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "SELECT sys_role.id,sys_role.role_name,sys_role.role_name_zh,sys_role.role_desc " +
|
||||
"FROM sys_role.ID = rel_user_role.role_id " +
|
||||
"WHERE rel_user_role.user_id = sys_user.id " +
|
||||
"AND rel_user_role.user_id = sys_user.id " +
|
||||
"AND sys_user.user_name = :userName ", nativeQuery = true)
|
||||
List<SysRoleEntity> selectByUserName(@Param("userName") String userName);
|
||||
|
||||
|
||||
// /**
|
||||
// * 根据用户名修改用户角色
|
||||
// */
|
||||
// @Modifying
|
||||
// @Query(value = "UPDATE sys_user SET last_entry_time = now(), last_entry_ip = :ipAddress " +
|
||||
// "WHERE user_name = :userName ;", nativeQuery = true)
|
||||
// int updateUserRoleByUserName(@Param("userName") String userName);
|
||||
|
||||
/**
|
||||
* 添加用户角色根据用户名和角色名
|
||||
* @param userName
|
||||
* @param roleName
|
||||
* @return
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "INSERT INTO rel_user_role (id,role_id, user_id) " +
|
||||
"SELECT nextval('rel_user_role_seq'),sys_role.ID,sys_user.ID FROM sys_role,sys_user " +
|
||||
"WHERE sys_role.role_name = :roleName AND sys_user.user_name = :userName ", nativeQuery = true)
|
||||
int insertRelUserRole(@Param("userName") String userName, @Param("roleName") String roleName);
|
||||
}
|
144
src/main/java/com/xkrs/dao/SysUserDao.java
Normal file
144
src/main/java/com/xkrs/dao/SysUserDao.java
Normal file
@ -0,0 +1,144 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.vo.SysUserVo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
/**
|
||||
* SysUserDao
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
|
||||
|
||||
/**
|
||||
* 检查系统用户名是否存在
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "SELECT COUNT(*) FROM sys_user WHERE user_name = :userName", nativeQuery = true)
|
||||
int checkUserName(@Param("userName") String userName);
|
||||
|
||||
/**
|
||||
* 查找用户实体根据用户名
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "SELECT * FROM sys_user WHERE user_name = :userName", nativeQuery = true)
|
||||
SysUserEntity selectByUserName(@Param("userName") String userName);
|
||||
|
||||
/**
|
||||
* 根据用户名查询实体信息
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "select new com.xkrs.model.vo.SysUserVo (id,userName,nickName,telephone,addTime,lastEntryTime,lastEntryIp,avatar,province,city,county,identifier,identity) " +
|
||||
"from SysUserEntity where userName = :userName")
|
||||
SysUserVo selectUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 更新用户登录信息
|
||||
* @param userName
|
||||
* @param ipAddress
|
||||
* @return
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "UPDATE sys_user SET last_entry_time = now(), last_entry_ip = :ipAddress " +
|
||||
"WHERE user_name = :userName ;", nativeQuery = true)
|
||||
int updateSysUserLogin(@Param("userName") String userName, @Param("ipAddress") String ipAddress);
|
||||
|
||||
/**
|
||||
* 软删除系统用户根据用户名
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "UPDATE sys_user SET delete_flag = 1 " +
|
||||
"WHERE user_name = :userName ;", nativeQuery = true)
|
||||
int softDeleteSysUserByUserName(@Param("userName") String userName);
|
||||
|
||||
/**
|
||||
* 软删除系统用户根据id
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "UPDATE sys_user SET delete_flag = 1 " +
|
||||
"WHERE id = :id ;", nativeQuery = true)
|
||||
int softDeleteGeneralUserById(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 删除系统用户(危险操作!)
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "DELETE FROM sys_user WHERE user_name = :userName ;", nativeQuery = true)
|
||||
int deleteSysUser(@Param("userName") String userName);
|
||||
|
||||
/**
|
||||
* 获取所有存在的系统用户Vo
|
||||
* @return
|
||||
*/
|
||||
/*@Query(value = "select new com.xkrs.model.vo.SysUserVo (u.id, u.userName, u.nickName, u.userCode, " +
|
||||
"u.telephone, u.signature," +
|
||||
"u.statusCode,u.addTime,u.lastEntryTime) from SysUserEntity u ,SysRoleEntity r," +
|
||||
"RelUserRoleEntity u_r " +
|
||||
"WHERE u.deleteFlag = 0 AND u.activeFlag = 0 AND r.id = u_r.roleId AND u.id = u_r.userId")
|
||||
List<SysUserVo> selectAllSysUser();*/
|
||||
|
||||
/**
|
||||
* 通过userId修改手机号(绑定手机号)
|
||||
* @param userId
|
||||
* @param phone
|
||||
*/
|
||||
@Modifying(clearAutomatically=true)
|
||||
@Query(value = "update sys_user set telephone = ?2 where id = ?1",nativeQuery = true)
|
||||
void updatePhoneByUserId(Integer userId, String phone);
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户信息
|
||||
* @param telephone
|
||||
* @return
|
||||
*/
|
||||
SysUserEntity findByTelephone(String telephone);
|
||||
|
||||
/**
|
||||
* 用户完善信息
|
||||
* @param userId
|
||||
* @param nickName
|
||||
* @param avatar
|
||||
* @param province
|
||||
* @param city
|
||||
* @param county
|
||||
*/
|
||||
@Modifying(clearAutomatically=true)
|
||||
@Query(value = "update sys_user set nick_name = ?2,avatar = ?3,province = ?4,city = ?5,county = ?6 where id = ?1",nativeQuery = true)
|
||||
void updateUserByUserId(Integer userId,String nickName,String avatar,String province,String city,String county);
|
||||
|
||||
/**
|
||||
* 通过用户昵称查询用户信息
|
||||
* @param nickName
|
||||
* @return
|
||||
*/
|
||||
SysUserEntity findByNickName(String nickName);
|
||||
|
||||
/**
|
||||
* 启用
|
||||
* @param userId
|
||||
*/
|
||||
@Query(value = "update sys_user set active_flag = 0 where id = ?",nativeQuery = true)
|
||||
@Modifying(clearAutomatically=true)
|
||||
void updateEnable(Integer userId);
|
||||
|
||||
/**
|
||||
* 禁用
|
||||
* @param userId
|
||||
*/
|
||||
@Query(value = "update sys_user set active_flag = 1 where id = ?",nativeQuery = true)
|
||||
@Modifying(clearAutomatically=true)
|
||||
void updateDisable(Integer userId);
|
||||
|
||||
}
|
120
src/main/java/com/xkrs/model/entity/BankCardEntity.java
Normal file
120
src/main/java/com/xkrs/model/entity/BankCardEntity.java
Normal file
@ -0,0 +1,120 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/13 17:43
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="bank_card")
|
||||
public class BankCardEntity {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bank_card_seq_gen")
|
||||
@SequenceGenerator(name = "bank_card_seq_gen", sequenceName = "bank_card_id_seq")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 银行卡号
|
||||
*/
|
||||
@Column(length = 85, columnDefinition = "varchar(85)")
|
||||
private String bankCardNumber;
|
||||
|
||||
/**
|
||||
* 开户行
|
||||
*/
|
||||
private String accountBank;
|
||||
|
||||
/**
|
||||
* 银行名称
|
||||
*/
|
||||
@Column(length = 65, columnDefinition = "varchar(65)")
|
||||
private String bankName;
|
||||
|
||||
/**
|
||||
* 商家用户id
|
||||
*/
|
||||
private Integer businessId;
|
||||
|
||||
/**
|
||||
* 商家手机号
|
||||
*/
|
||||
@Column(length = 85, columnDefinition = "varchar(85)")
|
||||
private String businessPhone;
|
||||
|
||||
public BankCardEntity() {
|
||||
}
|
||||
|
||||
public BankCardEntity(Integer id, String bankCardNumber, String accountBank, String bankName, Integer businessId, String businessPhone) {
|
||||
this.id = id;
|
||||
this.bankCardNumber = bankCardNumber;
|
||||
this.accountBank = accountBank;
|
||||
this.bankName = bankName;
|
||||
this.businessId = businessId;
|
||||
this.businessPhone = businessPhone;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getBankCardNumber() {
|
||||
return bankCardNumber;
|
||||
}
|
||||
|
||||
public void setBankCardNumber(String bankCardNumber) {
|
||||
this.bankCardNumber = bankCardNumber;
|
||||
}
|
||||
|
||||
public String getAccountBank() {
|
||||
return accountBank;
|
||||
}
|
||||
|
||||
public void setAccountBank(String accountBank) {
|
||||
this.accountBank = accountBank;
|
||||
}
|
||||
|
||||
public String getBankName() {
|
||||
return bankName;
|
||||
}
|
||||
|
||||
public void setBankName(String bankName) {
|
||||
this.bankName = bankName;
|
||||
}
|
||||
|
||||
public Integer getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(Integer businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public String getBusinessPhone() {
|
||||
return businessPhone;
|
||||
}
|
||||
|
||||
public void setBusinessPhone(String businessPhone) {
|
||||
this.businessPhone = businessPhone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BankCardEntity{" +
|
||||
"id=" + id +
|
||||
", bankCardNumber='" + bankCardNumber + '\'' +
|
||||
", accountBank='" + accountBank + '\'' +
|
||||
", bankName='" + bankName + '\'' +
|
||||
", businessId=" + businessId +
|
||||
", businessPhone='" + businessPhone + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
244
src/main/java/com/xkrs/model/entity/BusinessEntity.java
Normal file
244
src/main/java/com/xkrs/model/entity/BusinessEntity.java
Normal file
@ -0,0 +1,244 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/13 16:54
|
||||
* 商家信息
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="business")
|
||||
public class BusinessEntity {
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "business_seq_gen")
|
||||
@SequenceGenerator(name = "business_seq_gen", sequenceName = "business_id_seq")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 商户名称
|
||||
*/
|
||||
@Column(length = 85, columnDefinition = "varchar(85)")
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
@Column(length = 32, columnDefinition = "varchar(32)")
|
||||
private String businessPro;
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
@Column(length = 32, columnDefinition = "varchar(32)")
|
||||
private String businessCity;
|
||||
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
private String businessCountry;
|
||||
|
||||
/**
|
||||
* 详细地址
|
||||
*/
|
||||
private String businessAddress;
|
||||
|
||||
/**
|
||||
* 商家电话
|
||||
*/
|
||||
@Column(length = 85, columnDefinition = "varchar(85)")
|
||||
private String businessPhone;
|
||||
|
||||
/**
|
||||
* 商家图片
|
||||
*/
|
||||
private String businessPhoto;
|
||||
|
||||
/**
|
||||
* 营业执照
|
||||
*/
|
||||
private String businessLicense;
|
||||
|
||||
/**
|
||||
* 商家折扣
|
||||
*/
|
||||
private Double businessDiscount;
|
||||
|
||||
/**
|
||||
* 商家状态(入驻默认0,审核通过1 审核不通过2)
|
||||
*/
|
||||
@Column(length = 32, columnDefinition = "varchar(32)")
|
||||
private String businessType;
|
||||
|
||||
/**
|
||||
* 团长识别码
|
||||
*/
|
||||
@Column(length = 32, columnDefinition = "varchar(32)")
|
||||
private String headIdentifier;
|
||||
|
||||
/**
|
||||
* 商家用户id
|
||||
*/
|
||||
private Integer businessId;
|
||||
|
||||
/**
|
||||
* 商家入驻时间
|
||||
*/
|
||||
@Column(length = 65, columnDefinition = "varchar(65)")
|
||||
private String settleInTime;
|
||||
|
||||
public BusinessEntity() {
|
||||
}
|
||||
|
||||
public BusinessEntity(Integer id, String businessName, String businessPro, String businessCity, String businessCountry, String businessAddress, String businessPhone, String businessPhoto, String businessLicense, Double businessDiscount, String businessType, String headIdentifier, Integer businessId, String settleInTime) {
|
||||
this.id = id;
|
||||
this.businessName = businessName;
|
||||
this.businessPro = businessPro;
|
||||
this.businessCity = businessCity;
|
||||
this.businessCountry = businessCountry;
|
||||
this.businessAddress = businessAddress;
|
||||
this.businessPhone = businessPhone;
|
||||
this.businessPhoto = businessPhoto;
|
||||
this.businessLicense = businessLicense;
|
||||
this.businessDiscount = businessDiscount;
|
||||
this.businessType = businessType;
|
||||
this.headIdentifier = headIdentifier;
|
||||
this.businessId = businessId;
|
||||
this.settleInTime = settleInTime;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getBusinessName() {
|
||||
return businessName;
|
||||
}
|
||||
|
||||
public void setBusinessName(String businessName) {
|
||||
this.businessName = businessName;
|
||||
}
|
||||
|
||||
public String getBusinessPro() {
|
||||
return businessPro;
|
||||
}
|
||||
|
||||
public void setBusinessPro(String businessPro) {
|
||||
this.businessPro = businessPro;
|
||||
}
|
||||
|
||||
public String getBusinessCity() {
|
||||
return businessCity;
|
||||
}
|
||||
|
||||
public void setBusinessCity(String businessCity) {
|
||||
this.businessCity = businessCity;
|
||||
}
|
||||
|
||||
public String getBusinessCountry() {
|
||||
return businessCountry;
|
||||
}
|
||||
|
||||
public void setBusinessCountry(String businessCountry) {
|
||||
this.businessCountry = businessCountry;
|
||||
}
|
||||
|
||||
public String getBusinessAddress() {
|
||||
return businessAddress;
|
||||
}
|
||||
|
||||
public void setBusinessAddress(String businessAddress) {
|
||||
this.businessAddress = businessAddress;
|
||||
}
|
||||
|
||||
public String getBusinessPhone() {
|
||||
return businessPhone;
|
||||
}
|
||||
|
||||
public void setBusinessPhone(String businessPhone) {
|
||||
this.businessPhone = businessPhone;
|
||||
}
|
||||
|
||||
public String getBusinessPhoto() {
|
||||
return businessPhoto;
|
||||
}
|
||||
|
||||
public void setBusinessPhoto(String businessPhoto) {
|
||||
this.businessPhoto = businessPhoto;
|
||||
}
|
||||
|
||||
public String getBusinessLicense() {
|
||||
return businessLicense;
|
||||
}
|
||||
|
||||
public void setBusinessLicense(String businessLicense) {
|
||||
this.businessLicense = businessLicense;
|
||||
}
|
||||
|
||||
public Double getBusinessDiscount() {
|
||||
return businessDiscount;
|
||||
}
|
||||
|
||||
public void setBusinessDiscount(Double businessDiscount) {
|
||||
this.businessDiscount = businessDiscount;
|
||||
}
|
||||
|
||||
public String getBusinessType() {
|
||||
return businessType;
|
||||
}
|
||||
|
||||
public void setBusinessType(String businessType) {
|
||||
this.businessType = businessType;
|
||||
}
|
||||
|
||||
public String getHeadIdentifier() {
|
||||
return headIdentifier;
|
||||
}
|
||||
|
||||
public void setHeadIdentifier(String headIdentifier) {
|
||||
this.headIdentifier = headIdentifier;
|
||||
}
|
||||
|
||||
public Integer getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(Integer businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public String getSettleInTime() {
|
||||
return settleInTime;
|
||||
}
|
||||
|
||||
public void setSettleInTime(String settleInTime) {
|
||||
this.settleInTime = settleInTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BusinessEntity{" +
|
||||
"id=" + id +
|
||||
", businessName='" + businessName + '\'' +
|
||||
", businessPro='" + businessPro + '\'' +
|
||||
", businessCity='" + businessCity + '\'' +
|
||||
", businessCountry='" + businessCountry + '\'' +
|
||||
", businessAddress='" + businessAddress + '\'' +
|
||||
", businessPhone='" + businessPhone + '\'' +
|
||||
", businessPhoto='" + businessPhoto + '\'' +
|
||||
", businessLicense='" + businessLicense + '\'' +
|
||||
", businessDiscount=" + businessDiscount +
|
||||
", businessType='" + businessType + '\'' +
|
||||
", headIdentifier='" + headIdentifier + '\'' +
|
||||
", businessId=" + businessId +
|
||||
", settleInTime='" + settleInTime + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
132
src/main/java/com/xkrs/model/entity/FileDocumentEntity.java
Normal file
132
src/main/java/com/xkrs/model/entity/FileDocumentEntity.java
Normal file
@ -0,0 +1,132 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* file_document 表实体类
|
||||
* @author tajochen
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="file_document")
|
||||
public class FileDocumentEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "file_document_seq_gen")
|
||||
@SequenceGenerator(name = "file_document_seq_gen", sequenceName = "file_document_seq")
|
||||
private Integer id;
|
||||
|
||||
@Column(length = 64, nullable = false, columnDefinition = "varchar(64)")
|
||||
private String name;
|
||||
|
||||
@Column( columnDefinition = "int4")
|
||||
private Integer category;
|
||||
|
||||
@Column(length = 192 , columnDefinition = "varchar(192)")
|
||||
private String filePath;
|
||||
|
||||
@Column( length = 128, columnDefinition = "varchar(128)")
|
||||
private String size;
|
||||
|
||||
@Column( length = 192, columnDefinition = "varchar(192)")
|
||||
private String md5;
|
||||
|
||||
@Column( length = 128, columnDefinition = "varchar(128)")
|
||||
private String memo;
|
||||
|
||||
@Column( length = 16, columnDefinition = "varchar(16)")
|
||||
private String addUserName;
|
||||
|
||||
private LocalDateTime addTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(Integer category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public String getMemo() {
|
||||
return memo;
|
||||
}
|
||||
|
||||
public void setMemo(String memo) {
|
||||
this.memo = memo;
|
||||
}
|
||||
|
||||
public String getAddUserName() {
|
||||
return addUserName;
|
||||
}
|
||||
|
||||
public void setAddUserName(String addUserName) {
|
||||
this.addUserName = addUserName;
|
||||
}
|
||||
|
||||
public LocalDateTime getAddTime() {
|
||||
return addTime;
|
||||
}
|
||||
|
||||
public void setAddTime(LocalDateTime addTime) {
|
||||
this.addTime = addTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FileDocumentEntity{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", category=" + category +
|
||||
", filePath='" + filePath + '\'' +
|
||||
", size='" + size + '\'' +
|
||||
", md5='" + md5 + '\'' +
|
||||
", memo='" + memo + '\'' +
|
||||
", addUserName='" + addUserName + '\'' +
|
||||
", addTime=" + addTime +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 11:27
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="product_content_photo")
|
||||
public class ProductContentPhotoEntity {
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_content_photo_seq_gen")
|
||||
@SequenceGenerator(name = "product_content_photo_seq_gen", sequenceName = "product_content_photo_id_seq")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 商品内容图片
|
||||
*/
|
||||
private String productContentPhoto;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer productId;
|
||||
|
||||
public ProductContentPhotoEntity() {
|
||||
}
|
||||
|
||||
public ProductContentPhotoEntity(Integer id, String productContentPhoto, Integer productId) {
|
||||
this.id = id;
|
||||
this.productContentPhoto = productContentPhoto;
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getProductContentPhoto() {
|
||||
return productContentPhoto;
|
||||
}
|
||||
|
||||
public void setProductContentPhoto(String productContentPhoto) {
|
||||
this.productContentPhoto = productContentPhoto;
|
||||
}
|
||||
|
||||
public Integer getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Integer productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProductContentPhotoEntity{" +
|
||||
"id=" + id +
|
||||
", productContentPhoto='" + productContentPhoto + '\'' +
|
||||
", productId=" + productId +
|
||||
'}';
|
||||
}
|
||||
}
|
71
src/main/java/com/xkrs/model/entity/ProductCoverEntity.java
Normal file
71
src/main/java/com/xkrs/model/entity/ProductCoverEntity.java
Normal file
@ -0,0 +1,71 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 11:18
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="product_cover")
|
||||
public class ProductCoverEntity {
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_cover_seq_gen")
|
||||
@SequenceGenerator(name = "product_cover_seq_gen", sequenceName = "product_cover_id_seq")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 商品封面图片
|
||||
*/
|
||||
private String productCoverPhoto;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer productId;
|
||||
|
||||
public ProductCoverEntity() {
|
||||
}
|
||||
|
||||
public ProductCoverEntity(Integer id, String productCoverPhoto, Integer productId) {
|
||||
this.id = id;
|
||||
this.productCoverPhoto = productCoverPhoto;
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getProductCoverPhoto() {
|
||||
return productCoverPhoto;
|
||||
}
|
||||
|
||||
public void setProductCoverPhoto(String productCoverPhoto) {
|
||||
this.productCoverPhoto = productCoverPhoto;
|
||||
}
|
||||
|
||||
public Integer getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Integer productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProductCoverEntity{" +
|
||||
"id=" + id +
|
||||
", productCoverPhoto='" + productCoverPhoto + '\'' +
|
||||
", productId=" + productId +
|
||||
'}';
|
||||
}
|
||||
}
|
149
src/main/java/com/xkrs/model/entity/ProductEntity.java
Normal file
149
src/main/java/com/xkrs/model/entity/ProductEntity.java
Normal file
@ -0,0 +1,149 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 13:41
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="product")
|
||||
public class ProductEntity {
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_seq_gen")
|
||||
@SequenceGenerator(name = "product_seq_gen", sequenceName = "product_id_seq")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String productName;
|
||||
|
||||
/**
|
||||
* 商品描述
|
||||
*/
|
||||
private String productDescription;
|
||||
|
||||
/**
|
||||
* 商品分类
|
||||
*/
|
||||
private Integer productCategories;
|
||||
|
||||
/**
|
||||
* 商品价格
|
||||
*/
|
||||
private BigDecimal productPrice;
|
||||
|
||||
/**
|
||||
* 商品上架状态(默认0 待审核,1审核通过,2审核不通过)
|
||||
*/
|
||||
@Column(length = 32, columnDefinition = "varchar(32)")
|
||||
private String shelfType;
|
||||
|
||||
/**
|
||||
* 商家id
|
||||
*/
|
||||
private Integer businessId;
|
||||
|
||||
/**
|
||||
* 商品上架的时间
|
||||
*/
|
||||
@Column(length = 65, columnDefinition = "varchar(65)")
|
||||
private String productTime;
|
||||
|
||||
public ProductEntity() {
|
||||
}
|
||||
|
||||
public ProductEntity(Integer id, String productName, String productDescription, Integer productCategories, BigDecimal productPrice, String shelfType, Integer businessId, String productTime) {
|
||||
this.id = id;
|
||||
this.productName = productName;
|
||||
this.productDescription = productDescription;
|
||||
this.productCategories = productCategories;
|
||||
this.productPrice = productPrice;
|
||||
this.shelfType = shelfType;
|
||||
this.businessId = businessId;
|
||||
this.productTime = productTime;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
|
||||
public String getProductDescription() {
|
||||
return productDescription;
|
||||
}
|
||||
|
||||
public void setProductDescription(String productDescription) {
|
||||
this.productDescription = productDescription;
|
||||
}
|
||||
|
||||
public Integer getProductCategories() {
|
||||
return productCategories;
|
||||
}
|
||||
|
||||
public void setProductCategories(Integer productCategories) {
|
||||
this.productCategories = productCategories;
|
||||
}
|
||||
|
||||
public BigDecimal getProductPrice() {
|
||||
return productPrice;
|
||||
}
|
||||
|
||||
public void setProductPrice(BigDecimal productPrice) {
|
||||
this.productPrice = productPrice;
|
||||
}
|
||||
|
||||
public String getShelfType() {
|
||||
return shelfType;
|
||||
}
|
||||
|
||||
public void setShelfType(String shelfType) {
|
||||
this.shelfType = shelfType;
|
||||
}
|
||||
|
||||
public Integer getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(Integer businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public String getProductTime() {
|
||||
return productTime;
|
||||
}
|
||||
|
||||
public void setProductTime(String productTime) {
|
||||
this.productTime = productTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProductEntity{" +
|
||||
"id=" + id +
|
||||
", productName='" + productName + '\'' +
|
||||
", productDescription='" + productDescription + '\'' +
|
||||
", productCategories=" + productCategories +
|
||||
", productPrice=" + productPrice +
|
||||
", shelfType='" + shelfType + '\'' +
|
||||
", businessId=" + businessId +
|
||||
", productTime='" + productTime + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* RelRoleAuthority 表实体类
|
||||
* @author tajochen
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="rel_role_authority")
|
||||
public class RelRoleAuthorityEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_role_authority_seq_gen")
|
||||
@SequenceGenerator(name = "rel_role_authority_seq_gen", sequenceName = "rel_role_authority_id_seq")
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer roleId;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer authorityId;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Integer roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public Integer getAuthorityId() {
|
||||
return authorityId;
|
||||
}
|
||||
|
||||
public void setAuthorityId(Integer authorityId) {
|
||||
this.authorityId = authorityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RelRoleAuthorityEntity{" +
|
||||
"id=" + id +
|
||||
", roleId=" + roleId +
|
||||
", authorityId=" + authorityId +
|
||||
'}';
|
||||
}
|
||||
}
|
60
src/main/java/com/xkrs/model/entity/RelUserRoleEntity.java
Normal file
60
src/main/java/com/xkrs/model/entity/RelUserRoleEntity.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* RelUserRole 表实体类
|
||||
* @author tajochen
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="rel_user_role")
|
||||
public class RelUserRoleEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_user_role_seq_gen")
|
||||
@SequenceGenerator(name = "rel_user_role_seq_gen", sequenceName = "rel_user_role_id_seq")
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer roleId;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Integer getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Integer roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RelUserRoleEntity{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", roleId=" + roleId +
|
||||
'}';
|
||||
}
|
||||
}
|
72
src/main/java/com/xkrs/model/entity/SysAuthorityEntity.java
Normal file
72
src/main/java/com/xkrs/model/entity/SysAuthorityEntity.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* SysAuthority 表实体类
|
||||
* @author tajochen
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="sys_authority")
|
||||
public class SysAuthorityEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_authority_seq_gen")
|
||||
@SequenceGenerator(name = "sys_authority_seq_gen", sequenceName = "sys_authority_id_seq")
|
||||
private Integer id;
|
||||
|
||||
@Column(length = 64, nullable = false, unique = true,columnDefinition = "varchar(64)")
|
||||
private String authorityName;
|
||||
|
||||
@Column(length = 64, columnDefinition = "varchar(64)")
|
||||
private String authorityNameZh;
|
||||
|
||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||
private String authorityDesc;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAuthorityName() {
|
||||
return authorityName;
|
||||
}
|
||||
|
||||
public void setAuthorityName(String authorityName) {
|
||||
this.authorityName = authorityName == null ? null : authorityName.trim();
|
||||
}
|
||||
|
||||
public String getAuthorityNameZh() {
|
||||
return authorityNameZh;
|
||||
}
|
||||
|
||||
public void setAuthorityNameZh(String authorityNameZh) {
|
||||
this.authorityNameZh = authorityNameZh == null ? null : authorityNameZh.trim();
|
||||
}
|
||||
|
||||
public String getAuthorityDesc() {
|
||||
return authorityDesc;
|
||||
}
|
||||
|
||||
public void setAuthorityDesc(String authorityDesc) {
|
||||
this.authorityDesc = authorityDesc == null ? null : authorityDesc.trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysAuthorityEntity{" +
|
||||
"id=" + id +
|
||||
", authorityName='" + authorityName + '\'' +
|
||||
", authorityDesc='" + authorityDesc + '\'' +
|
||||
", authorityNameZh='" + authorityNameZh + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
72
src/main/java/com/xkrs/model/entity/SysRoleEntity.java
Normal file
72
src/main/java/com/xkrs/model/entity/SysRoleEntity.java
Normal file
@ -0,0 +1,72 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* SysRole 表实体类
|
||||
* @author tajochen
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="sys_role")
|
||||
public class SysRoleEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_role_seq_gen")
|
||||
@SequenceGenerator(name = "sys_role_seq_gen", sequenceName = "sys_role_id_seq")
|
||||
private Integer id;
|
||||
|
||||
@Column(length = 32, nullable = false, unique = true,columnDefinition = "varchar(32)")
|
||||
private String roleName;
|
||||
|
||||
@Column(length = 32, columnDefinition = "varchar(32)")
|
||||
private String roleNameZh;
|
||||
|
||||
@Column(length = 64, columnDefinition = "varchar(64)")
|
||||
private String roleDesc;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRoleName() {
|
||||
return roleName;
|
||||
}
|
||||
|
||||
public void setRoleName(String roleName) {
|
||||
this.roleName = roleName == null ? null : roleName.trim();
|
||||
}
|
||||
|
||||
public String getRoleDesc() {
|
||||
return roleDesc;
|
||||
}
|
||||
|
||||
public void setRoleDesc(String roleDesc) {
|
||||
this.roleDesc = roleDesc == null ? null : roleDesc.trim();
|
||||
}
|
||||
|
||||
public String getRoleNameZh() {
|
||||
return roleNameZh;
|
||||
}
|
||||
|
||||
public void setRoleNameZh(String roleNameZh) {
|
||||
this.roleNameZh = roleNameZh == null ? null : roleNameZh.trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysRoleEntity{" +
|
||||
"id=" + id +
|
||||
", roleName='" + roleName + '\'' +
|
||||
", roleNameZh='" + roleNameZh + '\'' +
|
||||
", roleDesc='" + roleDesc + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
278
src/main/java/com/xkrs/model/entity/SysUserEntity.java
Normal file
278
src/main/java/com/xkrs/model/entity/SysUserEntity.java
Normal file
@ -0,0 +1,278 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* SysUser 表实体类
|
||||
* @author tajochen
|
||||
* 用户信息
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="sys_user")
|
||||
public class SysUserEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_user_seq_gen")
|
||||
@SequenceGenerator(name = "sys_user_seq_gen", sequenceName = "sys_user_id_seq")
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Column(length = 16, nullable = false, unique = true, columnDefinition = "varchar(16)")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
@Column(length = 32, columnDefinition = "varchar(32)")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@Column(length = 64, nullable = false, columnDefinition = "varchar(64)")
|
||||
private String password;
|
||||
|
||||
@Column(length = 32, nullable = false, columnDefinition = "varchar(32)")
|
||||
private String salt;
|
||||
|
||||
@Column(length = 16, unique = true, columnDefinition = "varchar(16)")
|
||||
private String telephone;
|
||||
|
||||
@Column(columnDefinition = "varchar(192)")
|
||||
private String signature;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer activeFlag;
|
||||
|
||||
@Column(nullable = false,columnDefinition = "smallint")
|
||||
private Integer statusCode;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime addTime;
|
||||
|
||||
private LocalDateTime lastEntryTime;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer deleteFlag;
|
||||
|
||||
@Column(columnDefinition = "varchar(64)")
|
||||
private String lastEntryIp;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
@Column(columnDefinition = "varchar(32)")
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
@Column(columnDefinition = "varchar(32)")
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
@Column(columnDefinition = "varchar(32)")
|
||||
private String county;
|
||||
|
||||
/**
|
||||
* 识别码,身份id
|
||||
*/
|
||||
private String identifier;
|
||||
|
||||
/**
|
||||
* 用户身份
|
||||
*/
|
||||
private String identity;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(String signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public Integer getActiveFlag() {
|
||||
return activeFlag;
|
||||
}
|
||||
|
||||
public void setActiveFlag(Integer activeFlag) {
|
||||
this.activeFlag = activeFlag;
|
||||
}
|
||||
|
||||
public Integer getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(Integer statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public LocalDateTime getAddTime() {
|
||||
return addTime;
|
||||
}
|
||||
|
||||
public void setAddTime(LocalDateTime addTime) {
|
||||
this.addTime = addTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getLastEntryTime() {
|
||||
return lastEntryTime;
|
||||
}
|
||||
|
||||
public void setLastEntryTime(LocalDateTime lastEntryTime) {
|
||||
this.lastEntryTime = lastEntryTime;
|
||||
}
|
||||
|
||||
public Integer getDeleteFlag() {
|
||||
return deleteFlag;
|
||||
}
|
||||
|
||||
public void setDeleteFlag(Integer deleteFlag) {
|
||||
this.deleteFlag = deleteFlag;
|
||||
}
|
||||
|
||||
public String getLastEntryIp() {
|
||||
return lastEntryIp;
|
||||
}
|
||||
|
||||
public void setLastEntryIp(String lastEntryIp) {
|
||||
this.lastEntryIp = lastEntryIp;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCounty() {
|
||||
return county;
|
||||
}
|
||||
|
||||
public void setCounty(String county) {
|
||||
this.county = county;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public void setIdentity(String identity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUserEntity{" +
|
||||
"id=" + id +
|
||||
", userName='" + userName + '\'' +
|
||||
", nickName='" + nickName + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", salt='" + salt + '\'' +
|
||||
", telephone='" + telephone + '\'' +
|
||||
", signature='" + signature + '\'' +
|
||||
", activeFlag=" + activeFlag +
|
||||
", statusCode=" + statusCode +
|
||||
", addTime=" + addTime +
|
||||
", lastEntryTime=" + lastEntryTime +
|
||||
", deleteFlag=" + deleteFlag +
|
||||
", lastEntryIp='" + lastEntryIp + '\'' +
|
||||
", avatar='" + avatar + '\'' +
|
||||
", province='" + province + '\'' +
|
||||
", city='" + city + '\'' +
|
||||
", county='" + county + '\'' +
|
||||
", identifier='" + identifier + '\'' +
|
||||
", identity='" + identity + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
34
src/main/java/com/xkrs/model/qo/BankCardQo.java
Normal file
34
src/main/java/com/xkrs/model/qo/BankCardQo.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.xkrs.model.qo;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 9:25
|
||||
*/
|
||||
public class BankCardQo {
|
||||
/**
|
||||
* 银行卡号
|
||||
*/
|
||||
private String bankCardNumber;
|
||||
|
||||
/**
|
||||
* 开户行
|
||||
*/
|
||||
private String accountBank;
|
||||
|
||||
public String getBankCardNumber() {
|
||||
return bankCardNumber;
|
||||
}
|
||||
|
||||
public void setBankCardNumber(String bankCardNumber) {
|
||||
this.bankCardNumber = bankCardNumber;
|
||||
}
|
||||
|
||||
public String getAccountBank() {
|
||||
return accountBank;
|
||||
}
|
||||
|
||||
public void setAccountBank(String accountBank) {
|
||||
this.accountBank = accountBank;
|
||||
}
|
||||
}
|
147
src/main/java/com/xkrs/model/qo/BusinessQo.java
Normal file
147
src/main/java/com/xkrs/model/qo/BusinessQo.java
Normal file
@ -0,0 +1,147 @@
|
||||
package com.xkrs.model.qo;
|
||||
|
||||
import com.xkrs.model.validation.BusinessQoInsert;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 9:11
|
||||
*/
|
||||
public class BusinessQo {
|
||||
/**
|
||||
* 商户名称
|
||||
*/
|
||||
@NotBlank(message = "{Business.businessName.null}",groups={BusinessQoInsert.class})
|
||||
private String businessName;
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
@NotBlank(message = "{Business.businessPro.null}",groups={BusinessQoInsert.class})
|
||||
private String businessPro;
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
@NotBlank(message = "{Business.businessCity.null}",groups={BusinessQoInsert.class})
|
||||
private String businessCity;
|
||||
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
@NotBlank(message = "{Business.businessCountry.null}",groups={BusinessQoInsert.class})
|
||||
private String businessCountry;
|
||||
|
||||
/**
|
||||
* 详细地址
|
||||
*/
|
||||
private String businessAddress;
|
||||
|
||||
/**
|
||||
* 商家电话
|
||||
*/
|
||||
@Pattern(regexp = "^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\\d{8}$", message = "{Business.businessPhone.null}",groups={BusinessQoInsert.class})
|
||||
private String businessPhone;
|
||||
|
||||
/**
|
||||
* 商家折扣
|
||||
*/
|
||||
@NotBlank(message = "{Business.businessDiscount.null}",groups={BusinessQoInsert.class})
|
||||
private Double businessDiscount;
|
||||
|
||||
/**
|
||||
* 团长识别码
|
||||
*/
|
||||
private String headIdentifier;
|
||||
|
||||
/**
|
||||
* 商家图片
|
||||
*/
|
||||
private String businessPhoto;
|
||||
|
||||
/**
|
||||
* 营业执照
|
||||
*/
|
||||
private String businessLicense;
|
||||
|
||||
public String getBusinessName() {
|
||||
return businessName;
|
||||
}
|
||||
|
||||
public void setBusinessName(String businessName) {
|
||||
this.businessName = businessName;
|
||||
}
|
||||
|
||||
public String getBusinessPro() {
|
||||
return businessPro;
|
||||
}
|
||||
|
||||
public void setBusinessPro(String businessPro) {
|
||||
this.businessPro = businessPro;
|
||||
}
|
||||
|
||||
public String getBusinessCity() {
|
||||
return businessCity;
|
||||
}
|
||||
|
||||
public void setBusinessCity(String businessCity) {
|
||||
this.businessCity = businessCity;
|
||||
}
|
||||
|
||||
public String getBusinessCountry() {
|
||||
return businessCountry;
|
||||
}
|
||||
|
||||
public void setBusinessCountry(String businessCountry) {
|
||||
this.businessCountry = businessCountry;
|
||||
}
|
||||
|
||||
public String getBusinessAddress() {
|
||||
return businessAddress;
|
||||
}
|
||||
|
||||
public void setBusinessAddress(String businessAddress) {
|
||||
this.businessAddress = businessAddress;
|
||||
}
|
||||
|
||||
public String getBusinessPhone() {
|
||||
return businessPhone;
|
||||
}
|
||||
|
||||
public void setBusinessPhone(String businessPhone) {
|
||||
this.businessPhone = businessPhone;
|
||||
}
|
||||
|
||||
public Double getBusinessDiscount() {
|
||||
return businessDiscount;
|
||||
}
|
||||
|
||||
public void setBusinessDiscount(Double businessDiscount) {
|
||||
this.businessDiscount = businessDiscount;
|
||||
}
|
||||
|
||||
public String getHeadIdentifier() {
|
||||
return headIdentifier;
|
||||
}
|
||||
|
||||
public void setHeadIdentifier(String headIdentifier) {
|
||||
this.headIdentifier = headIdentifier;
|
||||
}
|
||||
|
||||
public String getBusinessPhoto() {
|
||||
return businessPhoto;
|
||||
}
|
||||
|
||||
public void setBusinessPhoto(String businessPhoto) {
|
||||
this.businessPhoto = businessPhoto;
|
||||
}
|
||||
|
||||
public String getBusinessLicense() {
|
||||
return businessLicense;
|
||||
}
|
||||
|
||||
public void setBusinessLicense(String businessLicense) {
|
||||
this.businessLicense = businessLicense;
|
||||
}
|
||||
}
|
106
src/main/java/com/xkrs/model/qo/FileDocumentQo.java
Normal file
106
src/main/java/com/xkrs/model/qo/FileDocumentQo.java
Normal file
@ -0,0 +1,106 @@
|
||||
package com.xkrs.model.qo;
|
||||
|
||||
import com.xkrs.model.validation.FileDocumentQoInsert;
|
||||
import com.xkrs.model.validation.FileDocumentQoUpdate;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* AssistantInvestigatorQo
|
||||
* @author tajochen
|
||||
*/
|
||||
public class FileDocumentQo {
|
||||
|
||||
@NotBlank(message = "{FileDocument.id.null}",groups={FileDocumentQoUpdate.class})
|
||||
private Integer id;
|
||||
|
||||
@NotBlank(message = "{FileDocument.name.null}",groups = {FileDocumentQoInsert.class})
|
||||
@Size(max = 64, message = "{FileDocument.name.length.illegal}", groups={FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
private String name;
|
||||
|
||||
@Min(value = 0, message = "{FileDocument.category.length.illegal}", groups={FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
private Integer category;
|
||||
|
||||
@NotBlank(message = "{FileDocument.filePath.null}",groups = {FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
@Size(max = 192, message = "{FileDocument.filePath.length.illegal}",groups = {FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
private String filePath;
|
||||
|
||||
@Size(max = 128, message = "{FileDocument.size.length.illegal}",groups = {FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
private String size;
|
||||
|
||||
@NotBlank(message = "{FileDocument.md5.null}",groups = {FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
@Size(max = 192, message = "{FileDocument.md5.length.illegal}",groups = {FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
private String md5;
|
||||
|
||||
@Size(max = 128, message = "{FileDocument.memo.length.illegal}",groups = {FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
private String memo;
|
||||
|
||||
@Size(max = 128, message = "{FileDocument.checkingToken.length.illegal}",groups = {FileDocumentQoInsert.class, FileDocumentQoUpdate.class})
|
||||
private String checkingToken;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(Integer category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public String getMemo() {
|
||||
return memo;
|
||||
}
|
||||
|
||||
public void setMemo(String memo) {
|
||||
this.memo = memo;
|
||||
}
|
||||
|
||||
public String getCheckingToken() {
|
||||
return checkingToken;
|
||||
}
|
||||
|
||||
public void setCheckingToken(String checkingToken) {
|
||||
this.checkingToken = checkingToken;
|
||||
}
|
||||
}
|
137
src/main/java/com/xkrs/model/qo/SysUserQo.java
Normal file
137
src/main/java/com/xkrs/model/qo/SysUserQo.java
Normal file
@ -0,0 +1,137 @@
|
||||
package com.xkrs.model.qo;
|
||||
|
||||
import com.xkrs.model.validation.SysUserQoInsert;
|
||||
import com.xkrs.model.validation.SysUserQoUpdate;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* SysUserQo
|
||||
* @author tajochen
|
||||
*/
|
||||
public class SysUserQo {
|
||||
|
||||
@NotNull( message = "{SysUser.id.blank}",groups={SysUserQoUpdate.class})
|
||||
private Integer id;
|
||||
|
||||
@NotBlank(message = "{SysUser.userName.blank}",groups={SysUserQoInsert.class})
|
||||
@Size(min = 4,max = 16, message = "{SysUser.userName.length.illegal}",groups = {SysUserQoInsert.class,
|
||||
SysUserQoUpdate.class})
|
||||
@Pattern(regexp = "^([A-Za-z0-9_]+)$",message = "{SysUser.userName.format.illegal}",groups = {SysUserQoInsert.class,
|
||||
SysUserQoUpdate.class})
|
||||
private String userName;
|
||||
|
||||
@Size(max = 32, message = "{SysUser.nickName.length.illegal}",groups = {SysUserQoInsert.class,
|
||||
SysUserQoUpdate.class})
|
||||
private String nickName;
|
||||
|
||||
@NotBlank(message = "{SysUser.password.blank}",groups = {SysUserQoInsert.class})
|
||||
@Size(min = 6,max = 16, message = "{SysUser.password.length.illegal}",groups = {SysUserQoInsert.class,
|
||||
SysUserQoUpdate.class})
|
||||
@Pattern(regexp = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$",message = "{SysUser.password.format.illegal}",
|
||||
groups = {SysUserQoInsert.class,SysUserQoUpdate.class})
|
||||
private String password;
|
||||
|
||||
@Pattern(regexp = "^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\\d{8}$",
|
||||
message = "{SysUser.telephone.format.illegal}",groups = {SysUserQoInsert.class,SysUserQoUpdate.class})
|
||||
private String telephone;
|
||||
|
||||
@NotNull(message = "{SysUser.statusCode.illegal}",groups={SysUserQoUpdate.class})
|
||||
@Range(min=0,max=2,message = "{SysUser.statusCode.illegal}",groups = {SysUserQoInsert.class, SysUserQoUpdate.class})
|
||||
private Integer statusCode;
|
||||
|
||||
@NotNull(message = "{SysUser.deleteFlag.null}",groups={SysUserQoUpdate.class})
|
||||
private Integer deleteFlag;
|
||||
|
||||
private Integer roleId;
|
||||
|
||||
private Integer authorityId;
|
||||
|
||||
private String identity;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public Integer getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(Integer statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public Integer getDeleteFlag() {
|
||||
return deleteFlag;
|
||||
}
|
||||
|
||||
public void setDeleteFlag(Integer deleteFlag) {
|
||||
this.deleteFlag = deleteFlag;
|
||||
}
|
||||
|
||||
public Integer getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Integer roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public Integer getAuthorityId() {
|
||||
return authorityId;
|
||||
}
|
||||
|
||||
public void setAuthorityId(Integer authorityId) {
|
||||
this.authorityId = authorityId;
|
||||
}
|
||||
|
||||
public String getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public void setIdentity(String identity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
}
|
62
src/main/java/com/xkrs/model/qo/UserUpdate.java
Normal file
62
src/main/java/com/xkrs/model/qo/UserUpdate.java
Normal file
@ -0,0 +1,62 @@
|
||||
package com.xkrs.model.qo;
|
||||
|
||||
import javax.persistence.Column;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/10 16:37
|
||||
*/
|
||||
public class UserUpdate {
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
private String county;
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCounty() {
|
||||
return county;
|
||||
}
|
||||
|
||||
public void setCounty(String county) {
|
||||
this.county = county;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.xkrs.model.validation;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 9:13
|
||||
*/
|
||||
public interface BusinessQoInsert {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.xkrs.model.validation;
|
||||
|
||||
/**
|
||||
* FileDocumentQoInsert
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface FileDocumentQoInsert {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.xkrs.model.validation;
|
||||
|
||||
/**
|
||||
* FileDocumentQoUpdate
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface FileDocumentQoUpdate {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.xkrs.model.validation;
|
||||
|
||||
/**
|
||||
* SysUserQoInsert
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysUserQoInsert {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.xkrs.model.validation;
|
||||
|
||||
/**
|
||||
* SysUserQoUpdate
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysUserQoUpdate {
|
||||
}
|
67
src/main/java/com/xkrs/model/vo/FileServerResultVo.java
Normal file
67
src/main/java/com/xkrs/model/vo/FileServerResultVo.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.xkrs.model.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* FileServerResultVo 文件服务器查询结果
|
||||
* @author tajochen
|
||||
*/
|
||||
public class FileServerResultVo<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 状态信息
|
||||
*/
|
||||
String status;
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
*/
|
||||
String message;
|
||||
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
T data;
|
||||
|
||||
public FileServerResultVo() {
|
||||
}
|
||||
|
||||
public FileServerResultVo(String status, String msg, T data) {
|
||||
this.status = status;
|
||||
this.message = msg;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FileServerResultVo{" +
|
||||
"status='" + status + '\'' +
|
||||
", message='" + message + '\'' +
|
||||
", data=" + data +
|
||||
'}';
|
||||
}
|
||||
}
|
198
src/main/java/com/xkrs/model/vo/SysUserVo.java
Normal file
198
src/main/java/com/xkrs/model/vo/SysUserVo.java
Normal file
@ -0,0 +1,198 @@
|
||||
package com.xkrs.model.vo;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* SysUserVo
|
||||
* @Author tajochen
|
||||
*/
|
||||
public class SysUserVo implements Serializable {
|
||||
private Integer id;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String telephone;
|
||||
|
||||
private LocalDateTime addTime;
|
||||
|
||||
private LocalDateTime lastEntryTime;
|
||||
|
||||
private String lastEntryIp;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 省
|
||||
*/
|
||||
@Column(columnDefinition = "varchar(32)")
|
||||
private String province;
|
||||
|
||||
/**
|
||||
* 市
|
||||
*/
|
||||
@Column(columnDefinition = "varchar(32)")
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
@Column(columnDefinition = "varchar(32)")
|
||||
private String county;
|
||||
|
||||
/**
|
||||
* 识别码,身份id
|
||||
*/
|
||||
private String identifier;
|
||||
|
||||
/**
|
||||
* 用户身份
|
||||
*/
|
||||
private String identity;
|
||||
|
||||
public SysUserVo(Integer id, String userName, String nickName, String telephone, LocalDateTime addTime, LocalDateTime lastEntryTime, String lastEntryIp, String avatar, String province, String city, String county, String identifier, String identity) {
|
||||
this.id = id;
|
||||
this.userName = userName;
|
||||
this.nickName = nickName;
|
||||
this.telephone = telephone;
|
||||
this.addTime = addTime;
|
||||
this.lastEntryTime = lastEntryTime;
|
||||
this.lastEntryIp = lastEntryIp;
|
||||
this.avatar = avatar;
|
||||
this.province = province;
|
||||
this.city = city;
|
||||
this.county = county;
|
||||
this.identifier = identifier;
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public LocalDateTime getAddTime() {
|
||||
return addTime;
|
||||
}
|
||||
|
||||
public void setAddTime(LocalDateTime addTime) {
|
||||
this.addTime = addTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getLastEntryTime() {
|
||||
return lastEntryTime;
|
||||
}
|
||||
|
||||
public void setLastEntryTime(LocalDateTime lastEntryTime) {
|
||||
this.lastEntryTime = lastEntryTime;
|
||||
}
|
||||
|
||||
public String getLastEntryIp() {
|
||||
return lastEntryIp;
|
||||
}
|
||||
|
||||
public void setLastEntryIp(String lastEntryIp) {
|
||||
this.lastEntryIp = lastEntryIp;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCounty() {
|
||||
return county;
|
||||
}
|
||||
|
||||
public void setCounty(String county) {
|
||||
this.county = county;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getIdentity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public void setIdentity(String identity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUserVo{" +
|
||||
"id=" + id +
|
||||
", userName='" + userName + '\'' +
|
||||
", nickName='" + nickName + '\'' +
|
||||
", telephone='" + telephone + '\'' +
|
||||
", addTime=" + addTime +
|
||||
", lastEntryTime=" + lastEntryTime +
|
||||
", lastEntryIp='" + lastEntryIp + '\'' +
|
||||
", avatar='" + avatar + '\'' +
|
||||
", province='" + province + '\'' +
|
||||
", city='" + city + '\'' +
|
||||
", county='" + county + '\'' +
|
||||
", identifier='" + identifier + '\'' +
|
||||
", identity='" + identity + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
64
src/main/java/com/xkrs/qiniu/config/QiNiuYunConfig.java
Normal file
64
src/main/java/com/xkrs/qiniu/config/QiNiuYunConfig.java
Normal file
@ -0,0 +1,64 @@
|
||||
package com.xkrs.qiniu.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 16:39
|
||||
*/
|
||||
@Configuration
|
||||
public class QiNiuYunConfig {
|
||||
/**
|
||||
* 七牛域名domain
|
||||
*/
|
||||
@Value("${qiniu.domain}")
|
||||
private String url;
|
||||
/**
|
||||
* 七牛ACCESS_KEY
|
||||
*/
|
||||
@Value("${qiniu.accessKey}")
|
||||
private String AccessKey;
|
||||
/**
|
||||
* 七牛SECRET_KEY
|
||||
*/
|
||||
@Value("${qiniu.secretKey}")
|
||||
private String SecretKey;
|
||||
/**
|
||||
* 七牛空间名
|
||||
*/
|
||||
@Value("${qiniu.bucket}")
|
||||
private String BucketName;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return AccessKey;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
AccessKey = accessKey;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return SecretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
SecretKey = secretKey;
|
||||
}
|
||||
|
||||
public String getBucketName() {
|
||||
return BucketName;
|
||||
}
|
||||
|
||||
public void setBucketName(String bucketName) {
|
||||
BucketName = bucketName;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.xkrs.qiniu.controller;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.qiniu.service.UploadImageService;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 15:01
|
||||
*/
|
||||
@RestController
|
||||
public class UploadFileController {
|
||||
|
||||
@Resource
|
||||
private UploadImageService uploadImageService;
|
||||
|
||||
/**
|
||||
* 将图片上传到七牛云
|
||||
* @param files
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/qiNiuUploadFile")
|
||||
public String uploadFile(@RequestParam("files") MultipartFile files){
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
String uploadQiNiuImg = uploadImageService.uploadQiNiuImg(files);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,uploadQiNiuImg,locale);
|
||||
}
|
||||
}
|
32
src/main/java/com/xkrs/qiniu/service/UploadImageService.java
Normal file
32
src/main/java/com/xkrs/qiniu/service/UploadImageService.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.xkrs.qiniu.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 16:52
|
||||
*/
|
||||
public interface UploadImageService {
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
String uploadQiNiuImg(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 获取私有空间文件
|
||||
* @param fileKey
|
||||
* @return
|
||||
*/
|
||||
String getPrivateFile(String fileKey);
|
||||
|
||||
/**
|
||||
* 根据空间名、文件名删除文件
|
||||
* @param bucketName
|
||||
* @param fileKey
|
||||
* @return
|
||||
*/
|
||||
boolean removeFile(String bucketName, String fileKey);
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
package com.xkrs.qiniu.service.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.qiniu.common.QiniuException;
|
||||
import com.qiniu.common.Zone;
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.BucketManager;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.util.Auth;
|
||||
import com.xkrs.qiniu.config.QiNiuYunConfig;
|
||||
import com.xkrs.qiniu.service.UploadImageService;
|
||||
import com.xkrs.qiniu.util.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 16:53
|
||||
*/
|
||||
@Service
|
||||
public class UploadImageServiceImpl implements UploadImageService {
|
||||
|
||||
private QiNiuYunConfig qiNiuYunConfig;
|
||||
|
||||
// 七牛文件上传管理器
|
||||
private UploadManager uploadManager;
|
||||
//上传的token
|
||||
private String token;
|
||||
// 七牛认证管理
|
||||
private Auth auth;
|
||||
|
||||
private BucketManager bucketManager;
|
||||
|
||||
public UploadImageServiceImpl(QiNiuYunConfig qiNiuYunConfig) {
|
||||
this.qiNiuYunConfig = qiNiuYunConfig;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
// 构造一个带指定Zone对象的配置类, 注意这里的Zone.zone0需要根据主机选择
|
||||
uploadManager = new UploadManager(new Configuration(Zone.zone2()));
|
||||
auth = Auth.create(qiNiuYunConfig.getAccessKey(), qiNiuYunConfig.getSecretKey());
|
||||
// 根据命名空间生成的上传token
|
||||
bucketManager = new BucketManager(auth, new Configuration(Zone.zone2()));
|
||||
token = auth.uploadToken(qiNiuYunConfig.getBucketName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String uploadQiNiuImg(MultipartFile file) {
|
||||
try {
|
||||
// 获取文件的名称
|
||||
String fileName = file.getOriginalFilename();
|
||||
if(fileName != null){
|
||||
// 使用工具类根据上传文件生成唯一图片名称
|
||||
String imgName = StringUtil.getRandomImgName(fileName);
|
||||
|
||||
FileInputStream inputStream = (FileInputStream) file.getInputStream();
|
||||
// 上传图片文件
|
||||
Response res = uploadManager.put(inputStream, imgName, token, null, null);
|
||||
if (!res.isOK()) {
|
||||
throw new RuntimeException("上传七牛出错:" + res.toString());
|
||||
}
|
||||
// 解析上传成功的结果
|
||||
DefaultPutRet putRet = new Gson().fromJson(res.bodyString(), DefaultPutRet.class);
|
||||
|
||||
// 直接返回外链地址
|
||||
return getPrivateFile(imgName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取私有空间文件
|
||||
*
|
||||
* @param fileKey
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getPrivateFile(String fileKey) {
|
||||
String encodedFileName = null;
|
||||
String finalUrl = null;
|
||||
try {
|
||||
encodedFileName = URLEncoder.encode(fileKey, "utf-8").replace("+", "%20");
|
||||
String publicUrl = String.format("%s/%s", this.qiNiuYunConfig.getUrl(), encodedFileName);
|
||||
// 1小时,可以自定义链接过期时间
|
||||
long expireInSeconds = 3600;
|
||||
finalUrl = auth.privateDownloadUrl(publicUrl, expireInSeconds);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return finalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据空间名、文件名删除文件
|
||||
* @param bucketName
|
||||
* @param fileKey
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean removeFile(String bucketName, String fileKey) {
|
||||
try {
|
||||
bucketManager.delete(bucketName, fileKey);
|
||||
} catch (QiniuException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
30
src/main/java/com/xkrs/qiniu/util/StringUtil.java
Normal file
30
src/main/java/com/xkrs/qiniu/util/StringUtil.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.xkrs.qiniu.util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 16:43
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
/**
|
||||
* @Description: 生成唯一图片名称
|
||||
* @Param: fileName
|
||||
* @return: 云服务器fileName
|
||||
*/
|
||||
public static String getRandomImgName(String fileName) {
|
||||
int index = fileName.lastIndexOf(".");
|
||||
if ((fileName == null || fileName.isEmpty()) || index == -1){
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
// 获取文件后缀
|
||||
String suffix = fileName.substring(index);
|
||||
// 生成UUID
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
// 生成上传至云服务器的路径
|
||||
// String path = "news/crush/"+ DateUtil.today() + "-" + uuid + suffix;
|
||||
String path = uuid + suffix;
|
||||
return path;
|
||||
}
|
||||
}
|
45
src/main/java/com/xkrs/service/FileDocumentService.java
Normal file
45
src/main/java/com/xkrs/service/FileDocumentService.java
Normal file
@ -0,0 +1,45 @@
|
||||
package com.xkrs.service;
|
||||
|
||||
import com.xkrs.model.entity.FileDocumentEntity;
|
||||
import com.xkrs.model.qo.FileDocumentQo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 文档管理接口
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface FileDocumentService {
|
||||
|
||||
/**
|
||||
* 文档列表
|
||||
* @return
|
||||
*/
|
||||
Iterable<FileDocumentEntity> getAllFile();
|
||||
|
||||
/**
|
||||
* 获取指定id记录
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Optional getById(Integer id);
|
||||
|
||||
/**
|
||||
* 新增文档记录
|
||||
* @param fileDocumentQo
|
||||
* @param userName
|
||||
*/
|
||||
void add(FileDocumentQo fileDocumentQo, String userName);
|
||||
|
||||
/**
|
||||
* 删除文档记录
|
||||
* @param id
|
||||
*/
|
||||
void delete(Integer id);
|
||||
|
||||
/**
|
||||
* 修改文档记录
|
||||
* @param fileDocumentEntity
|
||||
*/
|
||||
void update(FileDocumentEntity fileDocumentEntity);
|
||||
}
|
53
src/main/java/com/xkrs/service/FileServerService.java
Normal file
53
src/main/java/com/xkrs/service/FileServerService.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.xkrs.service;
|
||||
|
||||
import com.xkrs.model.vo.FileServerResultVo;
|
||||
|
||||
/**
|
||||
* 文件服务器接口
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface FileServerService {
|
||||
|
||||
/**
|
||||
* 获取文件统计信息
|
||||
* @return
|
||||
*/
|
||||
FileServerResultVo getFileStat();
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
FileServerResultVo deleteFile(String md5, String path);
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
FileServerResultVo getFileInfo(String md5, String path);
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @param dir 目录名
|
||||
* @return
|
||||
*/
|
||||
FileServerResultVo getFileList(String dir);
|
||||
|
||||
/**
|
||||
* 修复统计信息
|
||||
* @param date 要修复的日期,格式如:20190725
|
||||
* @return
|
||||
*/
|
||||
FileServerResultVo getFileRepairStat(String date);
|
||||
|
||||
/**
|
||||
* 同步失败修复
|
||||
* @param force 是否强行修复(0|1)
|
||||
* @return
|
||||
*/
|
||||
FileServerResultVo getFileRepair(String force);
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.xkrs.service;
|
||||
|
||||
import com.xkrs.model.qo.BankCardQo;
|
||||
import com.xkrs.model.qo.BusinessQo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 9:51
|
||||
* 商家模块
|
||||
*/
|
||||
public interface MerchantSettlementService {
|
||||
|
||||
/**
|
||||
* 商家入驻
|
||||
* @param businessQo
|
||||
* @param businessPhoto
|
||||
* @param businessLicense
|
||||
* @param bankCardQos
|
||||
* @param businessId
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
String merchantSettlement(BusinessQo businessQo, MultipartFile businessPhoto, MultipartFile businessLicense, List<BankCardQo> bankCardQos) throws IOException;
|
||||
|
||||
/**
|
||||
* 通过状态查询商家入驻信息
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
String findAllByBusinessType(String type);
|
||||
|
||||
/**
|
||||
* 根据省市区查询审核通过的商家的信息
|
||||
* @param countyName
|
||||
* @param keepType
|
||||
* @return
|
||||
*/
|
||||
String findAllByCountyName(String countyName, String keepType);
|
||||
|
||||
/**
|
||||
* 根据商家用户id查询商家入驻信息
|
||||
* @param businessId
|
||||
* @return
|
||||
*/
|
||||
String findBusinessById(Integer businessId);
|
||||
}
|
19
src/main/java/com/xkrs/service/SysAuthorityService.java
Normal file
19
src/main/java/com/xkrs/service/SysAuthorityService.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.xkrs.service;
|
||||
|
||||
import com.xkrs.model.entity.SysAuthorityEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统权限服务接口
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysAuthorityService {
|
||||
|
||||
/**
|
||||
* 获取权限实体列表根据用户名
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName);
|
||||
}
|
19
src/main/java/com/xkrs/service/SysRoleService.java
Normal file
19
src/main/java/com/xkrs/service/SysRoleService.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.xkrs.service;
|
||||
|
||||
import com.xkrs.model.entity.SysRoleEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统角色服务接口
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysRoleService {
|
||||
|
||||
/**
|
||||
* 获取角色实体列表根据用户名
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
List<SysRoleEntity> getSysRoleListByUserName(String userName);
|
||||
}
|
108
src/main/java/com/xkrs/service/SysUserService.java
Normal file
108
src/main/java/com/xkrs/service/SysUserService.java
Normal file
@ -0,0 +1,108 @@
|
||||
package com.xkrs.service;
|
||||
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.qo.SysUserQo;
|
||||
import com.xkrs.model.qo.UserUpdate;
|
||||
import com.xkrs.model.vo.SysUserVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 系统用户服务接口
|
||||
* @author tajochen
|
||||
*/
|
||||
public interface SysUserService {
|
||||
|
||||
/**
|
||||
* 检查用户名
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
boolean checkUserName(String userName);
|
||||
|
||||
/**
|
||||
* 获取所有用户
|
||||
* @return
|
||||
*/
|
||||
//Iterable<SysUserVo> getAllSysUser();
|
||||
|
||||
/**
|
||||
* 保存用户
|
||||
* @param sysUserQo
|
||||
*/
|
||||
void addUser(SysUserQo sysUserQo);
|
||||
|
||||
/**
|
||||
* 获取系统用户实体根据用户名
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
SysUserEntity getSysUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
SysUserVo selectUserByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 用户登录更新
|
||||
* @param userName
|
||||
* @param ipAddress
|
||||
* @return
|
||||
*/
|
||||
int updateSysUserLogin(String userName, String ipAddress);
|
||||
|
||||
/**
|
||||
* 系统用户更新
|
||||
* @param sysUserQo
|
||||
* @return
|
||||
*/
|
||||
int updateSysUser(SysUserQo sysUserQo);
|
||||
|
||||
/**
|
||||
* 软删除系统用户
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
int softDeleteGeneralUser(Integer id);
|
||||
|
||||
/**
|
||||
* 用户绑定手机号
|
||||
* @param userId
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
String bindPhone(Integer userId, String phone);
|
||||
|
||||
/**
|
||||
* 手机号登录
|
||||
* @param phone
|
||||
* @param verificationCode
|
||||
* @return
|
||||
*/
|
||||
String loginByPhone(String phone, String verificationCode);
|
||||
|
||||
/**
|
||||
* 用户完善个人信息
|
||||
* @param files
|
||||
* @param userUpdate
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
String updateUserByUserId(MultipartFile files, UserUpdate userUpdate, Integer userId) throws IOException;
|
||||
|
||||
/**
|
||||
* 启用
|
||||
* @param userId
|
||||
*/
|
||||
void updateEnable(Integer userId);
|
||||
|
||||
/**
|
||||
* 禁用
|
||||
* @param userId
|
||||
*/
|
||||
void updateDisable(Integer userId);
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.xkrs.dao.FileDocumentDao;
|
||||
import com.xkrs.model.entity.FileDocumentEntity;
|
||||
import com.xkrs.model.qo.FileDocumentQo;
|
||||
import com.xkrs.service.FileDocumentService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.xkrs.utils.DateTimeUtil.getNowTime;
|
||||
|
||||
/**
|
||||
* 文档管理接口
|
||||
* @author tajochen
|
||||
*/
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "FileDocumentServiceCache")
|
||||
public class FileDocumentServiceImpl implements FileDocumentService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(FileDocumentServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private FileDocumentDao fileDocumentDao;
|
||||
|
||||
/**
|
||||
* 文档列表
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null")
|
||||
@Override
|
||||
public Iterable<FileDocumentEntity> getAllFile() {
|
||||
Iterable<FileDocumentEntity> list = fileDocumentDao.findAll();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定id记录
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Cacheable(keyGenerator = "keyGenerator",unless="#result == null")
|
||||
@Override
|
||||
public Optional getById(Integer id) {
|
||||
Optional <FileDocumentEntity> obj = fileDocumentDao.findById(id);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增文档记录
|
||||
* @param fileDocumentQo
|
||||
* @param userName
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
@CacheEvict(value = "FileDocumentServiceCache",allEntries = true)
|
||||
public void add(FileDocumentQo fileDocumentQo, String userName) {
|
||||
FileDocumentEntity fileDocumentEntity = new FileDocumentEntity();
|
||||
fileDocumentEntity.setName(fileDocumentQo.getName());
|
||||
fileDocumentEntity.setFilePath(fileDocumentQo.getFilePath());
|
||||
fileDocumentEntity.setAddUserName(userName);
|
||||
fileDocumentEntity.setCategory(fileDocumentQo.getCategory());
|
||||
fileDocumentEntity.setMemo(fileDocumentQo.getMemo());
|
||||
fileDocumentEntity.setMd5(fileDocumentQo.getMd5());
|
||||
fileDocumentEntity.setSize(fileDocumentQo.getSize());
|
||||
// 设置系统时间
|
||||
fileDocumentEntity.setAddTime(getNowTime());
|
||||
fileDocumentDao.save(fileDocumentEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文档记录
|
||||
* @param id
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
@CacheEvict(value = "FileDocumentServiceCache",allEntries = true)
|
||||
public void delete(Integer id) {
|
||||
fileDocumentDao.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文档记录
|
||||
* @param fileDocumentEntity
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
@CacheEvict(value = "FileDocumentServiceCache",allEntries = true)
|
||||
public void update(FileDocumentEntity fileDocumentEntity) {
|
||||
fileDocumentDao.save(fileDocumentEntity);
|
||||
}
|
||||
}
|
121
src/main/java/com/xkrs/service/impl/FileServerServiceImpl.java
Normal file
121
src/main/java/com/xkrs/service/impl/FileServerServiceImpl.java
Normal file
@ -0,0 +1,121 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.xkrs.model.vo.FileServerResultVo;
|
||||
import com.xkrs.service.FileServerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.utils.RequestUtil.postFileManage;
|
||||
|
||||
/**
|
||||
* 文件服务器接口
|
||||
* @author tajochen
|
||||
*/
|
||||
@Service
|
||||
public class FileServerServiceImpl implements FileServerService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(FileServerServiceImpl.class);
|
||||
|
||||
@Value("${my.FileServerAdminAdress}")
|
||||
private String fileServerAdminAdress;
|
||||
|
||||
/**
|
||||
* 获取文件统计信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileStat(){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/stat";
|
||||
Map<String,String> map = new HashMap<String, String>(16);
|
||||
FileServerResultVo fileServerResultVo = postFileManage(requestUrl,map);
|
||||
return fileServerResultVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo deleteFile(String md5,String path){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/delete";
|
||||
Map<String,String> map = new HashMap<String, String>(16);
|
||||
if(md5 != null && !md5.isEmpty()){
|
||||
map.put("md5",md5);
|
||||
}
|
||||
if(path != null && !path.isEmpty()){
|
||||
map.put("path",path);
|
||||
}
|
||||
FileServerResultVo fileServerResultVo = postFileManage(requestUrl,map);
|
||||
return fileServerResultVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileInfo(String md5,String path){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/get_file_info";
|
||||
Map<String,String> map = new HashMap<String, String>(16);
|
||||
if(md5 != null && !md5.isEmpty()){
|
||||
map.put("md5",md5);
|
||||
}
|
||||
if(path != null && !path.isEmpty()){
|
||||
map.put("path",path);
|
||||
}
|
||||
FileServerResultVo fileServerResultVo = postFileManage(requestUrl,map);
|
||||
return fileServerResultVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @param dir 目录名
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileList(String dir){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/list_dir";
|
||||
Map<String,String> map = new HashMap<String, String>(16);
|
||||
map.put("dir",dir);
|
||||
FileServerResultVo fileServerResultVo = postFileManage(requestUrl,map);
|
||||
return fileServerResultVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复统计信息
|
||||
* @param date 要修复的日期,格式如:20190725
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileRepairStat(String date){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/repair_stat";
|
||||
Map<String,String> map = new HashMap<String, String>(16);
|
||||
map.put("date",date);
|
||||
FileServerResultVo fileServerResultVo = postFileManage(requestUrl,map);
|
||||
return fileServerResultVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步失败修复
|
||||
* @param force 是否强行修复(0|1)
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileRepair(String force){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/repair";
|
||||
Map<String,String> map = new HashMap<String, String>(16);
|
||||
map.put("force",force);
|
||||
FileServerResultVo fileServerResultVo = postFileManage(requestUrl,map);
|
||||
return fileServerResultVo;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.dao.BankCardDao;
|
||||
import com.xkrs.dao.BusinessDao;
|
||||
import com.xkrs.model.entity.BankCardEntity;
|
||||
import com.xkrs.model.entity.BusinessEntity;
|
||||
import com.xkrs.model.qo.BankCardQo;
|
||||
import com.xkrs.model.qo.BusinessQo;
|
||||
import com.xkrs.service.MerchantSettlementService;
|
||||
import com.xkrs.utils.DateTimeUtil;
|
||||
import com.xkrs.utils.PhotoUtil;
|
||||
import com.xkrs.utils.VerifyBankCardUtil;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/14 9:52
|
||||
* 商家模块
|
||||
*/
|
||||
@Service
|
||||
public class MerchantSettlementServiceImpl implements MerchantSettlementService {
|
||||
|
||||
@Resource
|
||||
private BusinessDao businessDao;
|
||||
|
||||
@Resource
|
||||
private BankCardDao bankCardDao;
|
||||
|
||||
/**
|
||||
* 商家入驻
|
||||
* @param businessQo
|
||||
* @param businessPhoto
|
||||
* @param businessLicense
|
||||
* @param bankCardQos
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String merchantSettlement(BusinessQo businessQo, MultipartFile businessPhoto, MultipartFile businessLicense, List<BankCardQo> bankCardQos) throws IOException {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
BusinessEntity byBusinessName = businessDao.findByBusinessName(businessQo.getBusinessName());
|
||||
if(byBusinessName != null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.FILE_EXISTS,"您已入驻,请勿重复入驻或提交!",locale);
|
||||
}
|
||||
BusinessEntity byBusinessPhone = businessDao.findByBusinessPhone(businessQo.getBusinessPhone());
|
||||
if(byBusinessPhone != null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.FILE_EXISTS,"您已入驻,请勿重复入驻或提交!",locale);
|
||||
}
|
||||
if(businessPhoto == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"商家图片不能为空!",locale);
|
||||
}
|
||||
if(businessLicense == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"营业执照不能为空!",locale);
|
||||
}
|
||||
// 上传商家图片
|
||||
//String busPhoto = PhotoUtil.memoryPhoto(businessPhoto);
|
||||
// 上传商家营业执照
|
||||
//String photo = PhotoUtil.memoryPhoto(businessLicense);
|
||||
for(BankCardQo bankCardQo : bankCardQos){
|
||||
Map<String, Object> stringObjectMap = VerifyBankCardUtil.checkBankCar(bankCardQo.getBankCardNumber());
|
||||
if(!((Boolean) stringObjectMap.get("card")) || "findNotName".equals(stringObjectMap.get("cardName").toString())){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"银行卡信息有误,请检查重新填写!",locale);
|
||||
}
|
||||
BankCardEntity bankCardEntity = new BankCardEntity();
|
||||
bankCardEntity.setBankCardNumber(bankCardQo.getBankCardNumber());
|
||||
bankCardEntity.setAccountBank(bankCardQo.getAccountBank());
|
||||
bankCardEntity.setBankName(stringObjectMap.get("cardName").toString());
|
||||
// bankCardEntity.setBusinessId(businessId);
|
||||
bankCardEntity.setBusinessPhone(businessQo.getBusinessPhone());
|
||||
bankCardDao.save(bankCardEntity);
|
||||
}
|
||||
BusinessEntity businessEntity = new BusinessEntity();
|
||||
businessEntity.setBusinessName(businessQo.getBusinessName());
|
||||
businessEntity.setBusinessPro(businessQo.getBusinessPro());
|
||||
businessEntity.setBusinessCity(businessQo.getBusinessCity());
|
||||
businessEntity.setBusinessCountry(businessQo.getBusinessCountry());
|
||||
businessEntity.setBusinessAddress(businessQo.getBusinessAddress());
|
||||
businessEntity.setBusinessPhone(businessQo.getBusinessPhone());
|
||||
businessEntity.setBusinessPhoto(businessQo.getBusinessPhoto());
|
||||
businessEntity.setBusinessLicense(businessQo.getBusinessLicense());
|
||||
businessEntity.setBusinessDiscount(businessQo.getBusinessDiscount());
|
||||
businessEntity.setHeadIdentifier(businessQo.getHeadIdentifier());
|
||||
businessEntity.setBusinessType("0");
|
||||
businessEntity.setSettleInTime(DateTimeUtil.dateTimeToString(LocalDateTime.now()));
|
||||
businessDao.save(businessEntity);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"入驻成功!",locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过状态查询商家入驻的信息
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String findAllByBusinessType(String type) {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
List<BusinessEntity> allByBusinessType = businessDao.findAllByBusinessType(type);
|
||||
if(allByBusinessType == null || allByBusinessType.size() == 0){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有您所需要的商家的信息!",locale);
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,allByBusinessType,locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据省市区查询审核通过的商家的信息
|
||||
* @param countyName
|
||||
* @param keepType
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String findAllByCountyName(String countyName, String keepType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商家用户id查询入驻信息
|
||||
* @param businessId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String findBusinessById(Integer businessId) {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
BusinessEntity byBusinessId = businessDao.findByBusinessId(businessId);
|
||||
if(byBusinessId == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"你还未入驻,请先入驻!",locale);
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,byBusinessId,locale);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.xkrs.dao.SysAuthorityDao;
|
||||
import com.xkrs.model.entity.SysAuthorityEntity;
|
||||
import com.xkrs.service.SysAuthorityService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统权限服务实现
|
||||
* @author tajochen
|
||||
*/
|
||||
@Service
|
||||
public class SysAuthorityServiceImpl implements SysAuthorityService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(SysAuthorityServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private SysAuthorityDao sysAuthorityDao;
|
||||
|
||||
@Override
|
||||
public List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName) {
|
||||
return sysAuthorityDao.selectByUserName(userName);
|
||||
}
|
||||
}
|
29
src/main/java/com/xkrs/service/impl/SysRoleServiceImpl.java
Normal file
29
src/main/java/com/xkrs/service/impl/SysRoleServiceImpl.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.xkrs.dao.SysRoleDao;
|
||||
import com.xkrs.model.entity.SysRoleEntity;
|
||||
import com.xkrs.service.SysRoleService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统角色服务实现
|
||||
* @author tajochen
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements SysRoleService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(SysRoleServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private SysRoleDao sysRoleDao;
|
||||
|
||||
@Override
|
||||
public List<SysRoleEntity> getSysRoleListByUserName(String userName) {
|
||||
return sysRoleDao.selectByUserName(userName);
|
||||
}
|
||||
}
|
272
src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java
Normal file
272
src/main/java/com/xkrs/service/impl/SysUserServiceImpl.java
Normal file
@ -0,0 +1,272 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xkrs.common.config.RedisUtil;
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.dao.RelRoleAuthorityDao;
|
||||
import com.xkrs.dao.RelUserRoleDao;
|
||||
import com.xkrs.dao.SysRoleDao;
|
||||
import com.xkrs.dao.SysUserDao;
|
||||
import com.xkrs.model.entity.RelRoleAuthorityEntity;
|
||||
import com.xkrs.model.entity.RelUserRoleEntity;
|
||||
import com.xkrs.model.entity.SysRoleEntity;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.qo.SysUserQo;
|
||||
import com.xkrs.model.qo.UserUpdate;
|
||||
import com.xkrs.model.vo.SysUserVo;
|
||||
import com.xkrs.service.SysUserService;
|
||||
import com.xkrs.utils.PhotoUtil;
|
||||
import com.xkrs.utils.RequestUtil;
|
||||
import org.apache.kafka.common.requests.RequestUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
import static com.xkrs.utils.DateTimeUtil.getNowTime;
|
||||
import static com.xkrs.utils.EncryptDecryptUtil.encry256;
|
||||
|
||||
/**
|
||||
* 系统用户服务实现
|
||||
* @author tajochen
|
||||
*/
|
||||
@Service
|
||||
public class SysUserServiceImpl implements SysUserService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(SysUserServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private SysUserDao sysUserDao;
|
||||
|
||||
@Resource
|
||||
private SysRoleDao sysRoleDao;
|
||||
|
||||
@Resource
|
||||
private RelUserRoleDao relUserRoleDao;
|
||||
|
||||
@Resource
|
||||
private RelRoleAuthorityDao relRoleAuthorityDao;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 检查用户名是否存在
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean checkUserName(String userName) {
|
||||
int num = sysUserDao.checkUserName(userName);
|
||||
return (num == 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
* @param sysUserQo
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public void addUser(SysUserQo sysUserQo) {
|
||||
String salt = KeyGenerators.string().generateKey();
|
||||
SysUserEntity sysUserEntity = new SysUserEntity();
|
||||
sysUserEntity.setUserName(sysUserQo.getUserName());
|
||||
sysUserEntity.setSalt(salt);
|
||||
sysUserEntity.setPassword(encry256(sysUserQo.getPassword() + salt));
|
||||
// sysUserEntity.setTelephone(sysUserQo.getTelephone());
|
||||
sysUserEntity.setActiveFlag(0);
|
||||
sysUserEntity.setStatusCode(0);
|
||||
sysUserEntity.setAddTime(getNowTime());
|
||||
sysUserEntity.setDeleteFlag(0);
|
||||
int i = (int)(Math.random()*9+1)*100000;
|
||||
sysUserEntity.setIdentifier(String.valueOf(i));
|
||||
sysUserEntity.setIdentity(sysUserQo.getIdentity());
|
||||
|
||||
sysUserDao.save(sysUserEntity);
|
||||
|
||||
RelUserRoleEntity relUserRoleEntity = new RelUserRoleEntity();
|
||||
relUserRoleEntity.setUserId(sysUserEntity.getId().longValue());
|
||||
relUserRoleEntity.setRoleId(sysUserQo.getRoleId());
|
||||
|
||||
RelRoleAuthorityEntity relRoleAuthorityEntity = new RelRoleAuthorityEntity();
|
||||
relRoleAuthorityEntity.setRoleId(sysUserQo.getRoleId());
|
||||
relRoleAuthorityEntity.setAuthorityId(sysUserQo.getAuthorityId());
|
||||
relUserRoleDao.save(relUserRoleEntity);
|
||||
|
||||
relRoleAuthorityDao.save(relRoleAuthorityEntity);
|
||||
|
||||
//sysRoleDao.insertRelUserRole(sysUserEntity.getUserName(),"role_general_user");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有用户Vo
|
||||
* @return
|
||||
*/
|
||||
/*@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public Iterable<SysUserVo> getAllSysUser() {
|
||||
Iterable<SysUserVo> ls = sysUserDao.selectAllSysUser();
|
||||
return ls;
|
||||
}*/
|
||||
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public SysUserEntity getSysUserByUserName(String userName) {
|
||||
return sysUserDao.selectByUserName(userName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public SysUserVo selectUserByUserName(String userName) {
|
||||
return sysUserDao.selectUserByUserName(userName);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public int updateSysUserLogin(String userName,String ipAddress) {
|
||||
return sysUserDao.updateSysUserLogin(userName,ipAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
* @param sysUserQo
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public int updateSysUser(SysUserQo sysUserQo) {
|
||||
SysUserEntity sysUserEntity = new SysUserEntity();
|
||||
sysUserEntity.setNickName(sysUserQo.getNickName());
|
||||
sysUserDao.save(sysUserEntity);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除普通用户
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public int softDeleteGeneralUser(Integer id) {
|
||||
String adminRole = "role_administor";
|
||||
String sysRole ="role_system_manager";
|
||||
|
||||
List<SysRoleEntity> list = sysRoleDao.selectByUserId(id);
|
||||
if(list.size()>0){
|
||||
SysRoleEntity sysRoleEntity = list.get(1);
|
||||
if(sysRole.equals(sysRoleEntity.getRoleName())||adminRole.equals(sysRoleEntity.getRoleName())){
|
||||
sysUserDao.softDeleteGeneralUserById(id);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户绑定手机号
|
||||
* @param userId
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public String bindPhone(Integer userId, String phone) {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
SysUserEntity byTelephone = sysUserDao.findByTelephone(phone);
|
||||
if(byTelephone != null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.FILE_EXISTS,"该手机号已用于该平台的绑定!",locale);
|
||||
}
|
||||
sysUserDao.updatePhoneByUserId(userId,phone);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!!",locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号登录
|
||||
* @param phone
|
||||
* @param verificationCode
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String loginByPhone(String phone, String verificationCode) {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
SysUserEntity byTelephone = sysUserDao.findByTelephone(phone);
|
||||
if(byTelephone == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"您还未绑定手机号!不能使用手机号登录!",locale);
|
||||
}
|
||||
String o = (String) redisUtil.get(phone);
|
||||
if("".equals(o) || o == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale);
|
||||
}
|
||||
if(!redisUtil.get(phone).equals(verificationCode)){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
|
||||
}
|
||||
String url = "http://localhost:6809/api/login";
|
||||
Map<String,String> map = new HashMap(3);
|
||||
map.put("userName",byTelephone.getUserName());
|
||||
map.put("password",byTelephone.getPassword());
|
||||
String userLogin = RequestUtil.doGet(url, map);
|
||||
JSONObject jsonObject = JSON.parseObject(userLogin);
|
||||
JSONObject data = (JSONObject) jsonObject.get("data");
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,data,locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户完善个人信息
|
||||
* @param files
|
||||
* @param userUpdate
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public String updateUserByUserId(MultipartFile files, UserUpdate userUpdate, Integer userId) throws IOException {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
if(files == null){
|
||||
String uploadAvatar = "";
|
||||
sysUserDao.updateUserByUserId(userId,userUpdate.getNickName(),uploadAvatar,userUpdate.getProvince(),userUpdate.getCity(),userUpdate.getCounty());
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"提交成功!",locale);
|
||||
}
|
||||
String memoryPhoto = PhotoUtil.memoryPhoto(files);
|
||||
sysUserDao.updateUserByUserId(userId,userUpdate.getNickName(),memoryPhoto,userUpdate.getProvince(),userUpdate.getCity(),userUpdate.getCounty());
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"提交成功!",locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用
|
||||
* @param userId
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public void updateEnable(Integer userId) {
|
||||
sysUserDao.updateEnable(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用
|
||||
* @param userId
|
||||
*/
|
||||
@Transactional(rollbackFor=Exception.class)
|
||||
@Override
|
||||
public void updateDisable(Integer userId) {
|
||||
sysUserDao.updateDisable(userId);
|
||||
}
|
||||
|
||||
}
|
293
src/main/java/com/xkrs/utils/AddressUtils.java
Normal file
293
src/main/java/com/xkrs/utils/AddressUtils.java
Normal file
@ -0,0 +1,293 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 根据经纬度获取地址:省 市 区 位置名称
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public class AddressUtils {
|
||||
|
||||
/*public static String getLatAndLng(String lat, String lng) {
|
||||
String key = "O7QBZ-ZYDKI-EMKGN-53UHG-5XSJF-AAFBP";
|
||||
try {
|
||||
String hsUrl = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + lat + "," + lng + "&key=" + key + "&get_poi=1";
|
||||
|
||||
URL url;
|
||||
|
||||
url = new URL(hsUrl);
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
||||
// 提交模式
|
||||
con.setRequestMethod("GET");
|
||||
X509TrustManager xtm = new X509TrustManager() {
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
|
||||
throws CertificateException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
|
||||
throws CertificateException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
};
|
||||
|
||||
TrustManager[] tm = {xtm};
|
||||
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(null, tm, null);
|
||||
|
||||
con.setSSLSocketFactory(ctx.getSocketFactory());
|
||||
con.setHostnameVerifier(new HostnameVerifier() {
|
||||
@Override
|
||||
public boolean verify(String arg0, SSLSession arg1) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
InputStream inStream = con.getInputStream();
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = inStream.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, len);
|
||||
}
|
||||
//网页的二进制数据
|
||||
byte[] b = outStream.toByteArray();
|
||||
outStream.close();
|
||||
inStream.close();
|
||||
String rtn = new String(b, "utf-8");
|
||||
if (StringUtils.isNotBlank(rtn)) {
|
||||
JSONObject object = JSONObject.fromObject(rtn);
|
||||
if (object != null) {
|
||||
if (object.has("status") && object.getInt("status") == 0) {
|
||||
JSONObject result = JSONObject.fromObject(object.get("result"));
|
||||
if (result != null) {
|
||||
JSONObject addressComponent = JSONObject.fromObject(result.get("address_component"));
|
||||
if (addressComponent != null) {
|
||||
String province = (String) addressComponent.get("province");
|
||||
String city = (String) addressComponent.get("city");
|
||||
String district = (String) addressComponent.get("district");
|
||||
String street = (String) addressComponent.get("street");
|
||||
String street_number = (String) addressComponent.get("street_number");
|
||||
String address = province + city + district + street + street_number;
|
||||
return address;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
|
||||
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36";
|
||||
|
||||
/**
|
||||
* 获取指定经纬度的地理位置
|
||||
* @param latitude 纬度
|
||||
* @param longitude 经度
|
||||
* @return
|
||||
*/
|
||||
public static String getLocal(String latitude, String longitude) {
|
||||
String ok = "ok";
|
||||
String msg = "msg";
|
||||
String info = getAdd(latitude, longitude);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = null;
|
||||
try {
|
||||
node = mapper.readTree(info);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assert node != null;
|
||||
String province = null;
|
||||
String city = null;
|
||||
String county = null;
|
||||
String road = null;
|
||||
String address = null;
|
||||
if (ok.equals(node.path(msg).asText())) {
|
||||
province = node.path("result").path("addressComponent").path("province").asText();
|
||||
city = node.path("result").path("addressComponent").path("city").asText();
|
||||
county = node.path("result").path("addressComponent").path("county").asText();
|
||||
road = node.path("result").path("addressComponent").path("road").asText();
|
||||
address = node.path("result").path("addressComponent").path("address").asText();
|
||||
}
|
||||
String fireAddress = province + city + county + road + address;
|
||||
return fireAddress;
|
||||
}
|
||||
/**
|
||||
* 根据经纬度获取位置信息
|
||||
* @param latitude 纬度
|
||||
* @param longitude 经度
|
||||
* @return
|
||||
*/
|
||||
public static String getAdd(String latitude, String longitude) {
|
||||
// 读取成功标志
|
||||
boolean isSuccess = false;
|
||||
// 重复次数
|
||||
int count = 10;
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> paramMap = new HashMap<>(3);
|
||||
paramMap.put("lon", longitude);
|
||||
paramMap.put("lat", latitude);
|
||||
paramMap.put("ver", "1");
|
||||
String paramStr = null;
|
||||
try {
|
||||
paramStr = mapper.writeValueAsString(paramMap);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("转json失败,{}", (Object) e.getStackTrace());
|
||||
}
|
||||
String url = String.format("http://api.tianditu.gov.cn/geocoder?type=geocode&tk=5a1d34815475f88e6d8802da6be832ae&postStr=%s",
|
||||
paramStr);
|
||||
// 创建http对象
|
||||
RequestConfig defaultRequestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(60000).setConnectTimeout(60000)
|
||||
.setConnectionRequestTimeout(60000)
|
||||
.build();
|
||||
CloseableHttpClient client = HttpClients.custom()
|
||||
.setDefaultRequestConfig(defaultRequestConfig).build();
|
||||
|
||||
// 创建并设置URI
|
||||
URIBuilder uri = null;
|
||||
// 创建Get请求
|
||||
HttpGet get = null;
|
||||
|
||||
try {
|
||||
URL url1 = new URL(url);
|
||||
URI uri1 = new URI(url1.getProtocol(), url1.getHost(), url1.getPath(), url1.getQuery(), null);
|
||||
uri = new URIBuilder(uri1);
|
||||
get = new HttpGet(uri.build());
|
||||
// 设置请求头
|
||||
setGet(get);
|
||||
} catch (URISyntaxException | MalformedURLException e) {
|
||||
log.info("错误{}", (Object) e.getStackTrace());
|
||||
}
|
||||
//发送请求
|
||||
HttpEntity entity = null;
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
// 创建响应对象
|
||||
CloseableHttpResponse response = null;
|
||||
String line;
|
||||
String sLine = null;
|
||||
|
||||
String json = null;
|
||||
while (!isSuccess && count > 0) {
|
||||
try {
|
||||
response = client.execute(get);
|
||||
// 获取请求结果
|
||||
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||
log.info("实时定位数据未请求成功");
|
||||
count--;
|
||||
//close(is, br, response, client);
|
||||
continue;
|
||||
}
|
||||
entity = response.getEntity();
|
||||
is = entity.getContent();
|
||||
br = new BufferedReader(
|
||||
new InputStreamReader(is, StandardCharsets.UTF_8)
|
||||
);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
sLine = sb.toString();
|
||||
sLine = sLine.substring(sLine.indexOf("{"));
|
||||
//使用ObjectMapper对象对 User对象进行转换
|
||||
try {
|
||||
json = mapper.writeValueAsString(sLine);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.info("json字符串转化异常{}", (Object) e.getStackTrace());
|
||||
}
|
||||
isSuccess = true;
|
||||
|
||||
} catch (ClientProtocolException e) {
|
||||
log.info("请求超时等问题:{}", (Object) e.getStackTrace());
|
||||
} catch (IOException e) {
|
||||
log.info("I/O问题:{}", (Object) e.getStackTrace());
|
||||
} finally {
|
||||
close(is, br, response, client);
|
||||
}
|
||||
}
|
||||
return sLine;
|
||||
}
|
||||
|
||||
private static void close(InputStream is, BufferedReader br, CloseableHttpResponse response, CloseableHttpClient client){
|
||||
try {
|
||||
if (null != is){
|
||||
is.close();
|
||||
}
|
||||
if (null != br){
|
||||
br.close();
|
||||
}
|
||||
if (null != response){
|
||||
response.close();
|
||||
}
|
||||
if (null != client){
|
||||
client.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
private static HttpGet setGet(HttpGet get) {
|
||||
get.setHeader("Accept"
|
||||
, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
get.setHeader("Accept-Encoding"
|
||||
, "gzip, deflate");
|
||||
get.setHeader("Accept-Language"
|
||||
, "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6");
|
||||
get.setHeader("Connection"
|
||||
, "keep-alive");
|
||||
get.setHeader("Cache-Control"
|
||||
, "no-cache");
|
||||
get.setHeader("Upgrade-Insecure-Requests"
|
||||
, "1");
|
||||
get.setHeader("User-Agent", USER_AGENT);
|
||||
return get;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String latAndLng = getLocal("36.89", "115.90");
|
||||
System.out.println(latAndLng);
|
||||
}
|
||||
}
|
67
src/main/java/com/xkrs/utils/AliYunSmsUtils.java
Normal file
67
src/main/java/com/xkrs/utils/AliYunSmsUtils.java
Normal file
@ -0,0 +1,67 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.aliyuncs.profile.IClientProfile;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Xin
|
||||
*/
|
||||
public class AliYunSmsUtils {
|
||||
public static Logger log = LoggerFactory.getLogger(AliYunSmsUtils.class);
|
||||
/**
|
||||
* 产品名称:云通信短信API产品,开发者无需替换
|
||||
*/
|
||||
static final String product = "Dysmsapi";
|
||||
/**
|
||||
* 产品域名,开发者无需替换
|
||||
*/
|
||||
static final String domain = "dysmsapi.aliyuncs.com";
|
||||
/**
|
||||
* TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
|
||||
* TODO 修改成自己的
|
||||
*/
|
||||
static final String accessKeyId = "LTAI5tMSjLfu8Xu2w6WeguFF";
|
||||
/**
|
||||
* TODO 修改成自己的
|
||||
*/
|
||||
static final String accessKeySecret = "hvqM5zpi72hvX4VXM71wq6AE0XYtDI";
|
||||
|
||||
public static SendSmsResponse sendSms(String telephone, String code) throws ClientException {
|
||||
//可自助调整超时时间
|
||||
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
|
||||
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
|
||||
//初始化acsClient,暂不支持region化
|
||||
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
|
||||
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
|
||||
IAcsClient acsClient = new DefaultAcsClient(profile);
|
||||
//组装请求对象-具体描述见控制台-文档部分内容
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
//必填:待发送手机号
|
||||
request.setPhoneNumbers(telephone);
|
||||
//必填:短信签名-可在短信控制台中找到
|
||||
request.setSignName("青岛星科瑞升");
|
||||
//必填:短信模板-可在短信控制台中找到
|
||||
request.setTemplateCode("SMS_221082764");
|
||||
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
|
||||
//如果为发送验证码 无需修改
|
||||
request.setTemplateParam("{\"code\":\"" + code + "\"}");
|
||||
//选填-上行短信扩展码(无特殊需求用户请忽略此字段)
|
||||
//request.setSmsUpExtendCode("90997");
|
||||
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
|
||||
//hint 此处可能会抛出异常,注意catch
|
||||
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
||||
if(sendSmsResponse.getCode()!= null && sendSmsResponse.getCode().equals("OK")){
|
||||
log.info("------------>短信发送成功!");
|
||||
}else {
|
||||
log.info("------------>短信发送失败!");
|
||||
}
|
||||
return sendSmsResponse;
|
||||
}
|
||||
}
|
73
src/main/java/com/xkrs/utils/BeanUtils.java
Normal file
73
src/main/java/com/xkrs/utils/BeanUtils.java
Normal file
@ -0,0 +1,73 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author xkrs
|
||||
*/
|
||||
public class BeanUtils {
|
||||
|
||||
/**
|
||||
* 缓存BeanCopier 对象 提升性能
|
||||
*/
|
||||
private static final ConcurrentHashMap<String, org.springframework.cglib.beans.BeanCopier> BEAN_COPIER_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Bean属性复制工具方法。
|
||||
* @param sources 原始集合
|
||||
* @param supplier: 目标类::new(eg: UserVO::new)
|
||||
*/
|
||||
public static <S, T> List<T> cgLibCopyList(List<S> sources, Supplier<T> supplier) {
|
||||
List<T> list = new ArrayList<>(sources.size());
|
||||
org.springframework.cglib.beans.BeanCopier beanCopier = null;
|
||||
for (S source : sources) {
|
||||
T t = supplier.get();
|
||||
if (beanCopier == null) {
|
||||
beanCopier = getBeanCopier(source.getClass(), t.getClass());
|
||||
}
|
||||
beanCopier.copy(source, t, null);
|
||||
list.add(t);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bean属性复制工具方法。
|
||||
* @param source 目标对象
|
||||
* @param supplier: 目标类::new(eg: UserVO::new)
|
||||
*/
|
||||
public static <T> T cgLibCopyBean(Object source, Supplier<T> supplier) {
|
||||
T t = supplier.get();
|
||||
getBeanCopier(source.getClass(), t.getClass()).copy(source, t, null);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取BeanCopier对象 如果缓存中有从缓存中获取 如果没有则新创建对象并加入缓存
|
||||
* @param sourceClass
|
||||
* @param targetClass
|
||||
* @return
|
||||
*/
|
||||
private static org.springframework.cglib.beans.BeanCopier getBeanCopier(Class<?> sourceClass, Class<?> targetClass) {
|
||||
String key = getKey(sourceClass.getName(), targetClass.getName());
|
||||
org.springframework.cglib.beans.BeanCopier beanCopier;
|
||||
beanCopier = BEAN_COPIER_MAP.get(key);
|
||||
if (beanCopier == null) {
|
||||
beanCopier = org.springframework.cglib.beans.BeanCopier.create(sourceClass, targetClass, false);
|
||||
BEAN_COPIER_MAP.put(key, beanCopier);
|
||||
}
|
||||
return beanCopier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成缓存key
|
||||
*/
|
||||
private static String getKey(String sourceClassName, String targetClassName) {
|
||||
return sourceClassName + targetClassName;
|
||||
}
|
||||
}
|
177
src/main/java/com/xkrs/utils/CommonConstant.java
Normal file
177
src/main/java/com/xkrs/utils/CommonConstant.java
Normal file
@ -0,0 +1,177 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public interface CommonConstant {
|
||||
|
||||
/**
|
||||
* 正常状态
|
||||
*/
|
||||
public static final String STATUS_NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 禁用状态
|
||||
*/
|
||||
public static final String STATUS_DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 删除标志
|
||||
*/
|
||||
public static final String DEL_FLAG_1 = "1";
|
||||
|
||||
/**
|
||||
* 未删除
|
||||
*/
|
||||
public static final String DEL_FLAG_0 = "0";
|
||||
|
||||
/**
|
||||
* 系统日志类型: 登录
|
||||
*/
|
||||
public static final int LOG_TYPE_1 = 1;
|
||||
|
||||
/**
|
||||
* 系统日志类型: 操作
|
||||
*/
|
||||
public static final int LOG_TYPE_2 = 2;
|
||||
|
||||
/**
|
||||
* 操作日志类型: 查询
|
||||
*/
|
||||
public static final int OPERATE_TYPE_1 = 1;
|
||||
|
||||
/**
|
||||
* 操作日志类型: 添加
|
||||
*/
|
||||
public static final int OPERATE_TYPE_2 = 2;
|
||||
|
||||
/**
|
||||
* 操作日志类型: 更新
|
||||
*/
|
||||
public static final int OPERATE_TYPE_3 = 3;
|
||||
|
||||
/**
|
||||
* 操作日志类型: 删除
|
||||
*/
|
||||
public static final int OPERATE_TYPE_4 = 4;
|
||||
|
||||
/**
|
||||
* 操作日志类型: 倒入
|
||||
*/
|
||||
public static final int OPERATE_TYPE_5 = 5;
|
||||
|
||||
/**
|
||||
* 操作日志类型: 导出
|
||||
*/
|
||||
public static final int OPERATE_TYPE_6 = 6;
|
||||
|
||||
|
||||
/** {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */
|
||||
public static final Integer SC_INTERNAL_SERVER_ERROR_500 = 500;
|
||||
public static final Integer SC_INTERNAL_SERVER_ERROR_501 = 501;
|
||||
public static final Integer SC_INTERNAL_SERVER_ERROR_502 = 502;
|
||||
/** {@code 200 OK} (HTTP/1.0 - RFC 1945) */
|
||||
public static final Integer SC_OK_200 = 200;
|
||||
public static final Integer SC_OK_201 = 201;
|
||||
public static final Integer SC_OK_202 = 202;
|
||||
|
||||
public static final Integer SC_OK_300 = 300;
|
||||
public static final Integer SC_OK_301 = 301;
|
||||
/**访问权限认证未通过 510*/
|
||||
public static final Integer SC_JEECG_NO_AUTHZ=510;
|
||||
|
||||
/** 登录用户Shiro权限缓存KEY前缀 */
|
||||
public static String PREFIX_USER_SHIRO_CACHE = "shiro:cache:org.jeecg.modules.shiro.authc.ShiroRealm.authorizationCache:";
|
||||
/** 登录用户Token令牌缓存KEY前缀 */
|
||||
public static final String PREFIX_USER_TOKEN = "prefix_user_token_";
|
||||
/** Token缓存时间:3600秒即一小时 */
|
||||
public static final int TOKEN_EXPIRE_TIME = 3600;
|
||||
|
||||
|
||||
/**
|
||||
* 0:一级菜单
|
||||
*/
|
||||
public static final Integer MENU_TYPE_0 = 0;
|
||||
/**
|
||||
* 1:子菜单
|
||||
*/
|
||||
public static final Integer MENU_TYPE_1 = 1;
|
||||
/**
|
||||
* 2:按钮权限
|
||||
*/
|
||||
public static final Integer MENU_TYPE_2 = 2;
|
||||
|
||||
/**通告对象类型(USER:指定用户,ALL:全体用户)*/
|
||||
public static final String MSG_TYPE_UESR = "USER";
|
||||
public static final String MSG_TYPE_ALL = "ALL";
|
||||
|
||||
/**发布状态(0未发布,1已发布,2已撤销)*/
|
||||
public static final String NO_SEND = "0";
|
||||
public static final String HAS_SEND = "1";
|
||||
public static final String HAS_CANCLE = "2";
|
||||
|
||||
/**阅读状态(0未读,1已读)*/
|
||||
public static final String HAS_READ_FLAG = "1";
|
||||
public static final String NO_READ_FLAG = "0";
|
||||
|
||||
/**优先级(L低,M中,H高)*/
|
||||
public static final String PRIORITY_L = "L";
|
||||
public static final String PRIORITY_M = "M";
|
||||
public static final String PRIORITY_H = "H";
|
||||
|
||||
/**
|
||||
* 短信模板方式 0 .登录模板、1.注册模板、2.忘记密码模板
|
||||
* 3 信息变更
|
||||
*/
|
||||
public static final String SMS_TPL_TYPE_0 = "0";
|
||||
public static final String SMS_TPL_TYPE_1 = "1";
|
||||
public static final String SMS_TPL_TYPE_2 = "2";
|
||||
public static final String SMS_TPL_TYPE_3 = "3";
|
||||
/**
|
||||
* 状态(0无效1有效)
|
||||
*/
|
||||
public static final String STATUS_0 = "0";
|
||||
public static final String STATUS_1 = "1";
|
||||
|
||||
/**
|
||||
* 同步工作流引擎1同步0不同步
|
||||
*/
|
||||
public static final Integer ACT_SYNC_1 = 1;
|
||||
public static final Integer ACT_SYNC_0 = 0;
|
||||
|
||||
/**
|
||||
* 消息类型1:通知公告2:系统消息
|
||||
*/
|
||||
public static final String MSG_CATEGORY_1 = "1";
|
||||
public static final String MSG_CATEGORY_2 = "2";
|
||||
|
||||
/**
|
||||
* 是否配置菜单的数据权限 1是0否
|
||||
*/
|
||||
public static final Integer RULE_FLAG_0 = 0;
|
||||
public static final Integer RULE_FLAG_1 = 1;
|
||||
|
||||
/**
|
||||
* 是否用户已被冻结 1正常(解冻) 2冻结
|
||||
*/
|
||||
public static final String USER_UNFREEZE = "1";
|
||||
public static final String USER_FREEZE = "2";
|
||||
|
||||
/**
|
||||
* 文件上传类型(本地:local,Minio:minio,阿里云:alioss)
|
||||
*/
|
||||
public static final String UPLOAD_TYPE_LOCAL = "local";
|
||||
public static final String UPLOAD_TYPE_MINIO = "minio";
|
||||
public static final String UPLOAD_TYPE_OSS = "alioss";
|
||||
|
||||
|
||||
/**
|
||||
* 收入明细 (1:收入 2:支出)
|
||||
*/
|
||||
public static final Integer USER_IDENTITY_1 = 1;
|
||||
public static final Integer USER_IDENTITY_2 = 2;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
54
src/main/java/com/xkrs/utils/CopyPropertiesUtil.java
Normal file
54
src/main/java/com/xkrs/utils/CopyPropertiesUtil.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 复制源对象的属性值
|
||||
* @Author tajochen
|
||||
*/
|
||||
public class CopyPropertiesUtil {
|
||||
|
||||
/**
|
||||
* 复制源对象和目标对象的属性值
|
||||
* @param source 源对象
|
||||
* @param target 目标对象
|
||||
* @throws SecurityException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public static void copy(Object source, Object target) {
|
||||
//得到对象的Class
|
||||
Class sourceClass = source.getClass();
|
||||
Class targetClass = target.getClass();
|
||||
//得到Class对象的所有属性
|
||||
Field[] sourceFields = sourceClass.getDeclaredFields();
|
||||
Field[] targetFields = targetClass.getDeclaredFields();
|
||||
|
||||
for(Field sourceField : sourceFields){
|
||||
//属性名
|
||||
String name = sourceField.getName();
|
||||
//属性类型
|
||||
Class type = sourceField.getType();
|
||||
String methodName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
try{
|
||||
//得到属性对应get方法
|
||||
Method getMethod = sourceClass.getMethod("get" + methodName);
|
||||
//执行源对象的get方法得到属性值
|
||||
Object value = getMethod.invoke(source);
|
||||
//目标对象的属性名
|
||||
for(Field targetField : targetFields){
|
||||
String targetName = targetField.getName();
|
||||
if(targetName.equals(name)){
|
||||
//属性对应的set方法
|
||||
Method setMethod = targetClass.getMethod("set" + methodName, type);
|
||||
//执行目标对象的set方法
|
||||
setMethod.invoke(target, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
231
src/main/java/com/xkrs/utils/DateTimeUtil.java
Normal file
231
src/main/java/com/xkrs/utils/DateTimeUtil.java
Normal file
@ -0,0 +1,231 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 日期时间工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class DateTimeUtil {
|
||||
|
||||
private final static String COMMON_PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss";
|
||||
private final static String COMMON_PATTERN_DATE = "yyyy-MM-dd";
|
||||
private final static DateTimeFormatter COMMON_FORMATTER_DATETIME = DateTimeFormatter.ofPattern(COMMON_PATTERN_DATETIME);
|
||||
private final static DateTimeFormatter COMMON_FORMATTER_DATE = DateTimeFormatter.ofPattern(COMMON_PATTERN_DATE);
|
||||
private final static ZoneOffset DEFAULT_ZONE_OFFSET = ZoneOffset.of("+8");
|
||||
|
||||
/**
|
||||
* 字符串转LocalDate
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static LocalDate stringToDate(String date) {
|
||||
assert date != null;
|
||||
return LocalDate.parse(date, COMMON_FORMATTER_DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* LocalDate转字符串
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static String dateToString(LocalDate date) {
|
||||
assert date != null;
|
||||
return COMMON_FORMATTER_DATE.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* LocalDateTime转字符串
|
||||
* @param dateTime
|
||||
* @return
|
||||
*/
|
||||
public static String dateTimeToString(LocalDateTime dateTime) {
|
||||
assert dateTime != null;
|
||||
return COMMON_FORMATTER_DATETIME.format(dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转LocalDateTime
|
||||
* @param dateStr
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime stringToDateTime(String dateStr) {
|
||||
assert dateStr != null;
|
||||
return LocalDateTime.parse(dateStr, COMMON_FORMATTER_DATETIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转Instant时间戳
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static Instant stringToInstant(String str) {
|
||||
assert str != null;
|
||||
return stringToDateTime(str).toInstant(DEFAULT_ZONE_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* LocalDateTime转字符串(格式化)
|
||||
* @param dateTime
|
||||
* @param formatter
|
||||
* @return
|
||||
*/
|
||||
public static String dateToStringFormatter(LocalDateTime dateTime, DateTimeFormatter formatter) {
|
||||
assert dateTime != null;
|
||||
return formatter.format(dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转LocalDateTime(格式化)
|
||||
* @param dateStr
|
||||
* @param formatter
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime stringToDateTimeFormatter(String dateStr, DateTimeFormatter formatter) {
|
||||
assert dateStr != null;
|
||||
return LocalDateTime.parse(dateStr, formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转 local date
|
||||
* @param dateStr
|
||||
* @return
|
||||
*/
|
||||
public static LocalDate stringToDateFormatter(String dateStr){
|
||||
LocalDate date = LocalDate.parse(dateStr, COMMON_FORMATTER_DATE);
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 日期转时间戳
|
||||
* @param dateTime
|
||||
* @return
|
||||
*/
|
||||
public static long dateToTimeMillis(LocalDateTime dateTime) {
|
||||
assert dateTime != null;
|
||||
return dateTime.toInstant(DEFAULT_ZONE_OFFSET).toEpochMilli();
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间戳转日期
|
||||
* @param timeMillis
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime timeMillisToDate(long timeMillis) {
|
||||
Instant instant = Instant.ofEpochMilli(timeMillis);
|
||||
return LocalDateTime.ofInstant(instant, DEFAULT_ZONE_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间戳转时间
|
||||
* @param timeMillis
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime timeMillisToTime(long timeMillis) {
|
||||
LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(timeMillis, 0, ZoneOffset.ofHours(8));
|
||||
return localDateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间戳转时间再转字符串
|
||||
* @param timeMillis
|
||||
* @return
|
||||
*/
|
||||
public static String timeMillisToString(long timeMillis){
|
||||
LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(timeMillis, 0, ZoneOffset.ofHours(8));
|
||||
return COMMON_FORMATTER_DATETIME.format(localDateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间 hh:mm:ss:nnn
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime getNowTime() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return now;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期 yyyy-MM-dd
|
||||
* @return
|
||||
*/
|
||||
public static LocalDate getToday() {
|
||||
LocalDate now = LocalDate.now();
|
||||
return now;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 Instant 时间戳
|
||||
* @return
|
||||
*/
|
||||
public static Instant getInstant() {
|
||||
Instant timeStamp = Instant.now();
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间 yyyy-MM-ss hh:mm:ss
|
||||
* @return
|
||||
*/
|
||||
public static String getNowTimeStr(){
|
||||
return COMMON_FORMATTER_DATETIME.format(getNowTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断日期格式是否合法 "yyyy-MM-dd"
|
||||
* @param strDate
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidDate(String strDate) {
|
||||
final int minLen = 10;
|
||||
if(strDate == null || strDate.length() < minLen) {
|
||||
return false;
|
||||
}
|
||||
//正则表达式校验日期格式 yyyy-MM-dd
|
||||
String eL = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-" +
|
||||
"(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})" +
|
||||
"(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)(([0-9]{3}[1-9]|[0-9]{2}[1-9]" +
|
||||
"[0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-" +
|
||||
"(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|" +
|
||||
"((0[48]|[2468][048]|[3579][26])00))-02-29)";
|
||||
Pattern pat = Pattern.compile(eL);
|
||||
Matcher matcher = pat.matcher(strDate);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间格式 格式必须为 "YYYY-MM-DD HH:mm:ss"
|
||||
* @param sDateTime
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidDateTime(String sDateTime) {
|
||||
final int minLen = 19;
|
||||
if ((sDateTime == null) || (sDateTime.length() < minLen)) {
|
||||
return false;
|
||||
}
|
||||
String eL = "(((01[0-9]{2}|0[2-9][0-9]{2}|[1-9][0-9]{3})-(0?[13578]|1[02])-" +
|
||||
"(0?[1-9]|[12]\\\\d|3[01]))|((01[0-9]{2}|0[2-9][0-9]{2}|[1-9][0-9]{3})-" +
|
||||
"(0?[13456789]|1[012])-(0?[1-9]|[12]\\\\d|30))|((01[0-9]{2}|0[2-9][0-9]{2}|[1-9][0-9]{3})-0?2-" +
|
||||
"(0?[1-9]|1\\\\d|2[0-8]))|(((1[6-9]|[2-9]\\\\d)(0[48]|[2468][048]|[13579][26])|((04|08|12|16|[2468][048]|" +
|
||||
"[3579][26])00))-0?2-29)) (20|21|22|23|[0-1]?\\\\d):[0-5]?\\\\d:[0-5]?\\\\d";
|
||||
Pattern pat = Pattern.compile(eL);
|
||||
Matcher matcher = pat.matcher(sDateTime);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate localDate = now.plusDays(1);
|
||||
String s = dateToString(localDate);
|
||||
LocalDate localDate1 = stringToDate(s);
|
||||
System.out.println(localDate1);
|
||||
}
|
||||
|
||||
}
|
66
src/main/java/com/xkrs/utils/EncryptDecryptUtil.java
Normal file
66
src/main/java/com/xkrs/utils/EncryptDecryptUtil.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* SHA加密解密工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class EncryptDecryptUtil {
|
||||
|
||||
/**
|
||||
* SHA-256加密
|
||||
* @param strText
|
||||
* @return
|
||||
*/
|
||||
public static String encry256(final String strText){
|
||||
return encrySha(strText,"SHA-256");
|
||||
}
|
||||
|
||||
/**
|
||||
* SHA-512加密
|
||||
* @param strText
|
||||
* @return
|
||||
*/
|
||||
public static String encry512(final String strText){
|
||||
return encrySha(strText,"SHA-512");
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础SHA加密
|
||||
* @param strText
|
||||
* @param strType
|
||||
* @return
|
||||
*/
|
||||
private static String encrySha(final String strText, final String strType){
|
||||
// 返回值
|
||||
String strResult=null;
|
||||
// 是否是有效的字符串
|
||||
if (strText != null && strText.length()>0){
|
||||
// 加密开始,创建加密对象,并传入加密类型
|
||||
try {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance(strType);
|
||||
// 传入加密的字符串
|
||||
messageDigest.update(strText.getBytes());
|
||||
// 得到bytes类型结果
|
||||
byte[] byteBuffer = messageDigest.digest();
|
||||
StringBuilder strHexString = new StringBuilder();
|
||||
for (byte b : byteBuffer) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
strHexString.append('0');
|
||||
}
|
||||
strHexString.append(hex);
|
||||
}
|
||||
// 得到返回的结果
|
||||
strResult = strHexString.toString();
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return strResult;
|
||||
}
|
||||
}
|
||||
|
36
src/main/java/com/xkrs/utils/EntityManagerUtil.java
Normal file
36
src/main/java/com/xkrs/utils/EntityManagerUtil.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public class EntityManagerUtil {
|
||||
/**
|
||||
* 把List<Object[]>转换成List<T>
|
||||
*/
|
||||
public static <T> List<T> objectToBean(List<Object[]> objList, Class<T> clz) throws Exception{
|
||||
if (objList==null || objList.size()==0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Class<?>[] cz = null;
|
||||
Constructor<?>[] cons = clz.getConstructors();
|
||||
for (Constructor<?> ct : cons) {
|
||||
Class<?>[] clazz = ct.getParameterTypes();
|
||||
if (objList.get(0).length == clazz.length) {
|
||||
cz = clazz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
List<T> list = new ArrayList<T>();
|
||||
for (Object[] obj : objList) {
|
||||
Constructor<T> cr = clz.getConstructor(cz);
|
||||
list.add(cr.newInstance(obj));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
193
src/main/java/com/xkrs/utils/ExcelImportUtil.java
Normal file
193
src/main/java/com/xkrs/utils/ExcelImportUtil.java
Normal file
@ -0,0 +1,193 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author ZHY
|
||||
* @date 2020/6/17 15:56
|
||||
*/
|
||||
public class ExcelImportUtil {
|
||||
private Workbook wb;
|
||||
private Sheet sheet;
|
||||
private Row row;
|
||||
|
||||
String xls = ".xls";
|
||||
String xlsx = ".xlsx";
|
||||
|
||||
/**
|
||||
* 读取Excel
|
||||
*
|
||||
* @author ZHY
|
||||
*/
|
||||
public ExcelImportUtil(MultipartFile file) throws Exception {
|
||||
String filename = file.getOriginalFilename();
|
||||
String ext = filename.substring(filename.lastIndexOf("."));
|
||||
InputStream is = file.getInputStream();
|
||||
if (xls.equals(ext)) {
|
||||
wb = new HSSFWorkbook(is);
|
||||
} else if (xlsx.equals(ext)) {
|
||||
wb = new XSSFWorkbook(is);
|
||||
} else {
|
||||
wb = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Excel表格表头的内容输出
|
||||
*
|
||||
*/
|
||||
public List<Map<String, Object>> readExcelTitleOut() {
|
||||
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
||||
if (wb != null) {
|
||||
sheet = wb.getSheetAt(0);
|
||||
row = sheet.getRow(0);
|
||||
// 标题总列数
|
||||
int colNum = row.getPhysicalNumberOfCells();
|
||||
|
||||
System.out.println("colNum:" + colNum);
|
||||
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
|
||||
for (int i = 0; i < colNum; i++) {
|
||||
String stringCellValue = row.getCell(i).getStringCellValue();
|
||||
map.put(stringCellValue, null);
|
||||
}
|
||||
list.add(map);
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Excel表格表头
|
||||
*
|
||||
*/
|
||||
public String[] readExcelTitle() {
|
||||
String[] title = {};
|
||||
if (wb != null) {
|
||||
sheet = wb.getSheetAt(0);
|
||||
row = sheet.getRow(0);
|
||||
// 标题总列数
|
||||
int colNum = row.getPhysicalNumberOfCells();
|
||||
|
||||
System.out.println("colNum:" + colNum);
|
||||
|
||||
title = new String[colNum];
|
||||
|
||||
for (int i = 0; i < colNum; i++) {
|
||||
Cell cell = row.getCell(i);
|
||||
title[i] = cell.getStringCellValue().replaceAll("\\s+", "");
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Excel表格的某一个数值
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> readExcelSomeTitle(){
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
if (wb != null) {
|
||||
sheet = wb.getSheetAt(0);
|
||||
String title = parseExcel(sheet.getRow(2).getCell(1));
|
||||
String remark = parseExcel(sheet.getRow(3).getCell(1));
|
||||
map.put("date",title);
|
||||
map.put("remark",remark);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Excel数据内容
|
||||
*
|
||||
*/
|
||||
public List<Map<String, String>> readExcelContent() {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
if (wb != null) {
|
||||
//获取sheet表
|
||||
sheet = wb.getSheetAt(0);
|
||||
// 得到总行数
|
||||
int rowNum = sheet.getLastRowNum();
|
||||
//获取表头的标题
|
||||
String[] readExcelTitle = readExcelTitle();
|
||||
// 正文内容应该从第二行开始,第一行为表头的标题
|
||||
for (int i = 1; i <= rowNum; i++) {
|
||||
row = sheet.getRow(i);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
for (int j = 0; j < readExcelTitle.length; j++) {
|
||||
//获取每一列的数据值
|
||||
String str = parseExcel(row.getCell(j));
|
||||
//判断对应行的列值是否为空
|
||||
if (str != null || "".equals(str)) {
|
||||
//表头的标题为键值,列值为值
|
||||
map.put(readExcelTitle[j], str);
|
||||
}
|
||||
}
|
||||
//判段添加的对象是否为空
|
||||
if (!map.isEmpty()){
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 根据Cell类型设置数据
|
||||
*
|
||||
*/
|
||||
int ss = 20;
|
||||
int xx = 58;
|
||||
private String parseExcel(Cell cell) {
|
||||
String result = "";
|
||||
if (cell != null) {
|
||||
SimpleDateFormat sdf = null;
|
||||
switch (cell.getCellType()) {
|
||||
// 数字类型
|
||||
case NUMERIC:
|
||||
// 处理日期格式、时间格式
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
if (cell.getCellStyle().getDataFormat() == ss) {
|
||||
sdf = new SimpleDateFormat("HH:mm");
|
||||
} else {// 日期
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
String dateFormat = sdf.format(cell.getDateCellValue());
|
||||
result = dateFormat;
|
||||
} else if (cell.getCellStyle().getDataFormat() == xx) {
|
||||
// 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
double value = cell.getNumericCellValue();
|
||||
Date date = DateUtil.getJavaDate(value);
|
||||
result = sdf.format(date);
|
||||
} else {
|
||||
double value = cell.getNumericCellValue();
|
||||
DecimalFormat format = new DecimalFormat("#.###########");
|
||||
String strVal = format.format(value);
|
||||
result = strVal;
|
||||
}
|
||||
break;
|
||||
// String类型
|
||||
case STRING:
|
||||
result = cell.getRichStringCellValue().toString();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
477
src/main/java/com/xkrs/utils/FileFastDfs.java
Normal file
477
src/main/java/com/xkrs/utils/FileFastDfs.java
Normal file
@ -0,0 +1,477 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import cn.hutool.core.io.resource.InputStreamResource;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.tus.java.client.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author dong
|
||||
* @date 2020/12/31
|
||||
*/
|
||||
@Component
|
||||
public class FileFastDfs {
|
||||
|
||||
@Value("${dfs.ip}")
|
||||
public String ip;
|
||||
@Value("${dfs.port}")
|
||||
public String port;
|
||||
|
||||
// @Value("${dfs.upload}")
|
||||
// public String upload;
|
||||
//
|
||||
// @Value("${dfs.delete}")
|
||||
// public String delete;
|
||||
|
||||
@Resource
|
||||
private KafkaTemplate<String, Object> kafkaTemplate;
|
||||
private static final Logger log = LoggerFactory.getLogger(FileFastDfs.class);
|
||||
private static final String STATUS = "status";
|
||||
private static final String UPLOAD_BIG_PATH = "http://192.168.2.166:2001/group1/big/upload";
|
||||
private static final String UPLOAD_PATH = "http://192.168.2.166:2001/group1/upload";
|
||||
|
||||
/**
|
||||
* 文件上传到dfs服务器
|
||||
* @param file
|
||||
* @param dir
|
||||
* @return
|
||||
*/
|
||||
public String uploadFile(MultipartFile file, String dir) {
|
||||
File file1 = null;
|
||||
InputStreamResource isr = null;
|
||||
try {
|
||||
file1 = multipartFileToFile(file);
|
||||
isr=new InputStreamResource(file.getInputStream(),
|
||||
file.getOriginalFilename());
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//文件地址
|
||||
//声明参数集合
|
||||
HashMap<String, Object> paramMap = new HashMap<>(7);
|
||||
//文件
|
||||
paramMap.put("file", isr);
|
||||
//输出
|
||||
paramMap.put("output", "json");
|
||||
//自定义路径
|
||||
paramMap.put("path", dir);
|
||||
//场景 文件分类
|
||||
if (null == file1) {
|
||||
return null;
|
||||
}
|
||||
String name = file1.getName();
|
||||
System.err.println("file:" + file1.getName());
|
||||
paramMap.put("scene", name.substring(name.lastIndexOf(".") + 1));
|
||||
paramMap.put("fileName", System.currentTimeMillis() + ""
|
||||
+ Objects.requireNonNull(file.getOriginalFilename())
|
||||
.substring(file.getOriginalFilename().lastIndexOf(".")));
|
||||
System.err.println(paramMap);
|
||||
//
|
||||
String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/upload", paramMap);
|
||||
System.err.println(result);
|
||||
|
||||
// 拿出状态码,判断上传状态
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = null;
|
||||
try {
|
||||
node = mapper.readTree(result);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final String fail = "fail";
|
||||
if (null != node) {
|
||||
if (fail.equals(node.path(STATUS).asText())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 文件上传到dfs服务器
|
||||
* @params [file:File 文件, dir 文件存放路径]
|
||||
* @author: wd
|
||||
* @time: 2020/3/31 2020/3/31
|
||||
*/
|
||||
public String uploadFile(File file, String dir) {
|
||||
//文件地址
|
||||
//声明参数集合
|
||||
HashMap<String, Object> paramMap = new HashMap<>(7);
|
||||
//文件
|
||||
paramMap.put("file", file);
|
||||
//输出
|
||||
paramMap.put("output", "json");
|
||||
//自定义路径
|
||||
paramMap.put("path", dir);
|
||||
//场景
|
||||
// System.err.println(file.getName());
|
||||
|
||||
// paramMap.put("fileName", System.currentTimeMillis() + "" + file.getName().substring(file.getName().lastIndexOf(".")));
|
||||
paramMap.put("fileName", file.getName());
|
||||
System.err.println(paramMap);
|
||||
//上传
|
||||
String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/upload", paramMap);
|
||||
System.err.println(result);
|
||||
// 拿出状态码,判断上传状态
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = null;
|
||||
try {
|
||||
node = mapper.readTree(result);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final String status = "status";
|
||||
final String statusFail = "fail";
|
||||
if (null != node) {
|
||||
if (statusFail.equals(node.path(status).asText())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 文件上传到dfs服务器
|
||||
* @params [file:File 文件, dir 文件存放路径]
|
||||
* @author: wd
|
||||
* @time: 2020/3/31 2020/3/31
|
||||
*/
|
||||
public String uploadFile(File file, String dir, String fileType) {
|
||||
//文件地址
|
||||
//声明参数集合
|
||||
HashMap<String, Object> paramMap = new HashMap<>(7);
|
||||
//文件
|
||||
paramMap.put("file", file);
|
||||
//输出
|
||||
paramMap.put("output", "json");
|
||||
//自定义路径
|
||||
paramMap.put("path", dir);
|
||||
//场景
|
||||
System.err.println(file.getName());
|
||||
|
||||
// paramMap.put("fileName", System.currentTimeMillis() + "" + file.getName().substring(file.getName().lastIndexOf(".")));
|
||||
paramMap.put("fileName", file.getName());
|
||||
paramMap.put("scene", fileType);
|
||||
System.err.println(paramMap);
|
||||
//上传
|
||||
String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/upload", paramMap);
|
||||
System.err.println(result);
|
||||
// 拿出状态码,判断上传状态
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = null;
|
||||
try {
|
||||
node = mapper.readTree(result);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final String status = "status";
|
||||
final String statusFail = "fail";
|
||||
if (null != node) {
|
||||
if (statusFail.equals(node.path(status).asText())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String uploadBigFile(File file, String dir, String fileType) {
|
||||
// 下面这个一定要注意,如果不设置为true,将会直接返回301
|
||||
System.setProperty("http.strictPostRedirect", Boolean.toString(true));
|
||||
TusClient tusClient = new TusClient();
|
||||
try {
|
||||
tusClient.setUploadCreationURL(new URL(UPLOAD_BIG_PATH));
|
||||
|
||||
// tusClient.enableResuming(new TusRedisUrlStrore());
|
||||
tusClient.enableResuming(new TusURLMemoryStore());
|
||||
|
||||
final TusUpload upload = new TusUpload(file);
|
||||
System.out.println("start upload......");
|
||||
TusExecutor executor = new TusExecutor() {
|
||||
@Override
|
||||
protected void makeAttempt() throws ProtocolException, IOException {
|
||||
TusUploader uploader = tusClient.resumeOrCreateUpload(upload);
|
||||
uploader.setChunkSize(1024 * 1024);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
do {
|
||||
long totalBytes = upload.getSize();
|
||||
long bytesUploaded = uploader.getOffset();
|
||||
double progress = (double) bytesUploaded / totalBytes * 100;
|
||||
|
||||
System.out.printf("Upload at %06.2f%%.\n", progress);
|
||||
} while (uploader.uploadChunk() > -1);
|
||||
|
||||
uploader.finish();
|
||||
|
||||
String uploadUrl = uploader.getUploadURL().toString();
|
||||
System.out.println("Upload finished.");
|
||||
System.out.format("Upload available at: %s\n", uploadUrl);
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
System.out.println((end - start) + "ms");
|
||||
// 使用hutool进行秒传置换url
|
||||
String fileId = StrUtil.subAfter(uploadUrl, UPLOAD_BIG_PATH + "/", true);
|
||||
System.out.println("fileId: " + fileId);
|
||||
String url = StrUtil.format("{}?md5={}&output=json", UPLOAD_PATH, fileId);
|
||||
System.out.println("url: " + url);
|
||||
// 上传大文件的时候(1.xG)需要sleep一下,要不然会有问题
|
||||
ThreadUtil.sleep(5000);
|
||||
String result = HttpUtil.get(url);
|
||||
}
|
||||
};
|
||||
executor.makeAttempts();
|
||||
} catch (IOException | ProtocolException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 文件base64流获取
|
||||
* @params [fileName : 文件路径]
|
||||
* @return: java.lang.String
|
||||
* @author: chqf
|
||||
* @time: 2020/3/31 2020/3/31
|
||||
*/
|
||||
public String getBase64(String fileName) {
|
||||
if (fileName == null || "".equals(fileName)) {
|
||||
return null;
|
||||
}
|
||||
InputStream fis = null;
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL("http://" + ip + ":" + port + "/" + URLEncoder.encode(fileName, StandardCharsets.UTF_8));
|
||||
System.err.println(url);
|
||||
fis = url.openStream();
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}
|
||||
final ByteArrayOutputStream data = new ByteArrayOutputStream();
|
||||
String imgStr = "";
|
||||
try {
|
||||
if (fis == null) {
|
||||
return null;
|
||||
}
|
||||
int len = -1;
|
||||
byte[] buf = new byte[2048];
|
||||
while (-1 != (len = fis.read(buf, 0, buf.length))) {
|
||||
data.write(buf, 0, len);
|
||||
}
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
imgStr = encoder.encodeToString(data.toByteArray());
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}finally {
|
||||
try {
|
||||
if (null != fis) {
|
||||
fis.close();
|
||||
}
|
||||
data.close();
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
return "data:image/jpeg;base64," + imgStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 文件格式转换multipartFil 转为 File 格式
|
||||
* @params [file]
|
||||
* @return: java.io.File
|
||||
* @author: dong
|
||||
* @time: 2020/3/31 2020/3/31
|
||||
*/
|
||||
public File multipartFileToFile(MultipartFile file) throws Exception {
|
||||
|
||||
File toFile = null;
|
||||
if ("".equals(file) || file.getSize() <= 0) {
|
||||
file = null;
|
||||
} else {
|
||||
InputStream ins;
|
||||
ins = file.getInputStream();
|
||||
toFile = new File(Objects.requireNonNull(file.getOriginalFilename()));
|
||||
inputStreamToFile(ins, toFile);
|
||||
ins.close();
|
||||
}
|
||||
return toFile;
|
||||
}
|
||||
|
||||
private static void inputStreamToFile(InputStream ins, File file) {
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(file);
|
||||
int bytesRead = 0;
|
||||
byte[] buffer = new byte[8192];
|
||||
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}finally {
|
||||
try {
|
||||
if (null != os) {
|
||||
os.close();
|
||||
}
|
||||
if (null != ins) {
|
||||
ins.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 文件base64流获取
|
||||
* @params [fileName : 文件路径]
|
||||
* @return: java.lang.String
|
||||
* @author: dong
|
||||
* @time: 2020/3/31 2020/3/31
|
||||
*/
|
||||
public Boolean getFile(String fileName, HttpServletResponse response) {
|
||||
if (fileName == null || "".equals(fileName)) {
|
||||
return null;
|
||||
}
|
||||
InputStream fis = null;
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL("http://" + ip + ":" + port + "/" + URLEncoder.encode(fileName, StandardCharsets.UTF_8));
|
||||
System.err.println(url);
|
||||
fis = url.openStream();
|
||||
response.reset();
|
||||
response.setContentType("bin");
|
||||
response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}
|
||||
//
|
||||
byte[] b = new byte[256];
|
||||
int len;
|
||||
try {
|
||||
assert fis != null;
|
||||
while ((len = fis.read(b)) > 0){
|
||||
response.getOutputStream().write(b, 0, len);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}finally {
|
||||
try {
|
||||
if (null != fis) {
|
||||
fis.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("IO错误{}", (Object) e.getStackTrace());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件 path
|
||||
* @param filePath 文件路径 上传返回的path
|
||||
* @return
|
||||
*/
|
||||
public Boolean deleteFileByPath(String filePath) {
|
||||
if (filePath == null || "".equals(filePath)) {
|
||||
return false;
|
||||
}
|
||||
HashMap<String, Object> paramMap = new HashMap<>(1);
|
||||
// 参数
|
||||
paramMap.put("path", filePath);
|
||||
|
||||
String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/delete", paramMap);
|
||||
System.out.println(result);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = null;
|
||||
try {
|
||||
node = mapper.readTree(result);
|
||||
} catch (JsonProcessingException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
final String statusOk = "ok";
|
||||
|
||||
if (null == node) {
|
||||
log.error("返回结果为空");
|
||||
return false;
|
||||
}
|
||||
if (!statusOk.equals(node.path(STATUS).asText())) {
|
||||
log.error("未删除成功");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件 path
|
||||
* @param md5 上传返回的md5
|
||||
* @return
|
||||
*/
|
||||
public Boolean deleteFileByMd5(String md5) {
|
||||
if (md5 == null || "".equals(md5)) {
|
||||
return false;
|
||||
}
|
||||
HashMap<String, Object> paramMap = new HashMap<>(1);
|
||||
// 参数
|
||||
paramMap.put("md5", md5);
|
||||
|
||||
String result = HttpUtil.post("http://" + ip + ":" + port + "/group1/delete", paramMap);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = null;
|
||||
try {
|
||||
node = mapper.readTree(result);
|
||||
} catch (JsonProcessingException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
final String status = "status";
|
||||
final String statusOk = "ok";
|
||||
|
||||
if (null == node) {
|
||||
log.error("返回结果为空");
|
||||
return false;
|
||||
}
|
||||
if (!statusOk.equals(node.path(status).asText())) {
|
||||
log.error("未删除成功");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
File file = new File("C:\\Users\\dong\\Desktop\\遥感影像\\遥感影像\\GF1\\GF1_PMS1_E116.8_N36.6_20190528_L1A0004026837-MSS1_ORTHO_MS.tif");
|
||||
FileFastDfs fileFastDfs = new FileFastDfs();
|
||||
}
|
||||
}
|
||||
|
||||
|
250
src/main/java/com/xkrs/utils/FileUtil.java
Normal file
250
src/main/java/com/xkrs/utils/FileUtil.java
Normal file
@ -0,0 +1,250 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.utils.DateTimeUtil.getNowTimeStr;
|
||||
|
||||
public class FileUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||
|
||||
/**
|
||||
* 判断目录是否存在, 不存在创建
|
||||
* @param path 路径,目录最后带 File.separator
|
||||
* @return
|
||||
*/
|
||||
public static boolean isFileExit(String path){
|
||||
path = path.replace("/",File.separator);
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
log.info("文件已存在");
|
||||
return true;
|
||||
}
|
||||
if(path.endsWith(File.separator)) {
|
||||
log.info("创建单个文件" + path + "失败,目标不能是目录!");
|
||||
return false;
|
||||
}
|
||||
if(!file.getParentFile().exists()) {
|
||||
log.info("目标文件所在路径不存在,准备创建。。。");
|
||||
if (file.getParentFile().mkdirs()) {
|
||||
if (file.mkdir()) {
|
||||
log.info("创建目录文件成功!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.info("目标文件所在路径存在");
|
||||
if (file.mkdir()) {
|
||||
log.info("创建目录文件成功!");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取目录下的所有文件
|
||||
* @param filePath 目录
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<String> showListFile(String filePath) {
|
||||
File dir = new File(filePath);
|
||||
List<String> list = new ArrayList<>();
|
||||
// 查找参数文件是否存在,只检查第一个入参
|
||||
if(!dir.exists()) {
|
||||
log.error("找不到文件");
|
||||
}
|
||||
// 如果是目录那么进行递归调用
|
||||
if(dir.isDirectory()) {
|
||||
// 获取目录下的所有文件
|
||||
File[] f = dir.listFiles();
|
||||
// 进行递归调用,最后总会返回一个list
|
||||
assert f != null;
|
||||
for (File file : f) {
|
||||
list.addAll(showListFile(file.getPath()));
|
||||
}
|
||||
}else {
|
||||
// 不是目录直接添加进去,判断是否为xml文件
|
||||
list.add(dir.getPath());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动文件到目标目录
|
||||
* @param path 文件路径
|
||||
* @return
|
||||
*/
|
||||
/*public static FileEntity mvFile(String path){
|
||||
String savePath = "D:" + File.separator + "dms" + File.separator + "data" ;
|
||||
|
||||
File file = new File(path);
|
||||
if (!file.isFile()) {
|
||||
log.info("{}不是文件。",path);
|
||||
return null;
|
||||
}
|
||||
// 从文件名获取到入库信息 暂时不知道
|
||||
String[] infos = path.split("/");
|
||||
String fileNameUnHandler = infos[infos.length - 1];
|
||||
String[] fileNameUnHandlerSplitWithPoint = fileNameUnHandler.split(".");
|
||||
String fileName = fileNameUnHandlerSplitWithPoint[0];
|
||||
String scene = fileNameUnHandlerSplitWithPoint[1];
|
||||
String[] fileNames = fileNameUnHandler.split("_");
|
||||
long length = file.length();
|
||||
String filePath = File.separator + scene + File.separator + fileName;
|
||||
// savePath = savePath + File.separator + dir + File.separator + fileName;
|
||||
if (isFileExit(savePath + File.separator + scene)) {
|
||||
if (file.renameTo(new File(filePath))) {
|
||||
log.info("移动文件{}到{}目录",file.getName(), savePath + filePath);
|
||||
} else {
|
||||
log.info("文件{}移动失败",file.getName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 读取txt文件内容
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String txt2String(File file){
|
||||
StringBuilder result = new StringBuilder();
|
||||
try{
|
||||
//构造一个BufferedReader类来读取文件
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
String s = null;
|
||||
//使用readLine方法,一次读一行
|
||||
while((s = br.readLine())!=null){
|
||||
result.append(System.lineSeparator()).append(s);
|
||||
}
|
||||
br.close();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定上传文件路径遥感数据 栅格
|
||||
* @param file 文件
|
||||
* @return
|
||||
*/
|
||||
public static String fileRsSaveType(File file) {
|
||||
String name = file.getName();
|
||||
String suffix = name.substring(name.indexOf("."));
|
||||
// 判断是否为栅格数据
|
||||
if (!suffix.contains("tif")) {
|
||||
return null;
|
||||
}
|
||||
// GF1_PMS1_E116.8_N36.6_20190528_L1A0004026837-MSS1_ORTHO_MS.tif
|
||||
String[] s = name.split("_");
|
||||
// 卫星种类
|
||||
String satelliteType = s[0];
|
||||
// 传感器种类
|
||||
String sensorType = s[1];
|
||||
// 中心点经度
|
||||
String lat = s[2];
|
||||
// 中心点纬度
|
||||
String lon = s[3];
|
||||
// 时间
|
||||
String time = s[4];
|
||||
String year = time.substring(0, 4);
|
||||
String month = time.substring(4, 6);
|
||||
String day = time.substring(6);
|
||||
// 产品号
|
||||
String product = s[5];
|
||||
String productLevel = product.substring(0, 3);
|
||||
String productCode = product.substring(3);
|
||||
// 种类
|
||||
String type = s[6];
|
||||
// 文件路径
|
||||
String filePath = "/" + satelliteType + "/" + sensorType + "/" + productLevel + "/" + year + "/" + month + "/"
|
||||
+ day + "/" + productCode + "/";
|
||||
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 矢量数据路径
|
||||
* C:\Users\dong\Desktop\2018年山东省矢量数据\2018年山东省矢量数据\2018年动态\分县动态\山东.gdb\sa.gdb
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String fileShpSavePath(File file) {
|
||||
if (file.exists()) {
|
||||
if (file.isFile()) {
|
||||
String path = file.getPath();
|
||||
String[] dirNames = path.split("\\\\");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int length = dirNames.length;
|
||||
final int minLength = 5;
|
||||
if (length >= minLength) {
|
||||
for (int i = 5; i > 1; i--) {
|
||||
sb.append("/").append(dirNames[length - i]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, String> getUploadInfo(String info) {
|
||||
final String statusFail = "fail";
|
||||
final String status = "status";
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode resultNode = null;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
try {
|
||||
resultNode = mapper.readTree(info);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!statusFail.equals(resultNode.path(status).asText())) {
|
||||
String path = resultNode.path("path").asText();
|
||||
String fileName = path.substring(path.lastIndexOf("/") + 1);
|
||||
map.put("md5", resultNode.path("md5").asText());
|
||||
map.put("mtime", getNowTimeStr());
|
||||
map.put("path", path);
|
||||
map.put("scene", resultNode.path("scene").asText());
|
||||
map.put("size", resultNode.path("size").asText());
|
||||
map.put("url", resultNode.path("url").asText());
|
||||
map.put("fileName", fileName);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static boolean checkFileSize(Long len, int size, String unit) {
|
||||
double fileSize = 0;
|
||||
if ("B".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len;
|
||||
} else if ("K".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len / 1024;
|
||||
} else if ("M".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len / 1048576;
|
||||
} else if ("G".equals(unit.toUpperCase())) {
|
||||
fileSize = (double) len / 1073741824;
|
||||
}
|
||||
if (fileSize > size) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "C:/Users/dong/Desktop/2018年山东省矢量数据/2018年山东省矢量数据/2018年动态/分县动态/山东.gdb/a0000000a.gdbindexes";
|
||||
fileShpSavePath(new File(s));
|
||||
}
|
||||
}
|
40
src/main/java/com/xkrs/utils/HashUtil.java
Normal file
40
src/main/java/com/xkrs/utils/HashUtil.java
Normal file
@ -0,0 +1,40 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* md5加密解密工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class HashUtil {
|
||||
|
||||
/**
|
||||
* MD5加密
|
||||
*
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
public static String md5Encode(String password) {
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
char[] charArray = password.toCharArray();
|
||||
byte[] byteArray = new byte[charArray.length];
|
||||
for (int i = 0; i < charArray.length; i++){
|
||||
byteArray[i] = (byte) charArray[i];
|
||||
}
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
StringBuilder hexValue = new StringBuilder();
|
||||
for (byte md5Byte : md5Bytes) {
|
||||
int val = ((int) md5Byte) & 0xff;
|
||||
if (val < 16) {
|
||||
hexValue.append("0");
|
||||
}
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
}
|
||||
}
|
42
src/main/java/com/xkrs/utils/IpUtil.java
Normal file
42
src/main/java/com/xkrs/utils/IpUtil.java
Normal file
@ -0,0 +1,42 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* IP地址处理工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class IpUtil {
|
||||
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
final String unkonwMsg = "unknown";
|
||||
final char splitChar = ',';
|
||||
if (ip != null && ip.length() != 0 && !unkonwMsg.equalsIgnoreCase(ip)) {
|
||||
// 多次反向代理后会有多个ip值,第一个ip才是真实ip
|
||||
if( ip.indexOf(splitChar)!=-1 ){
|
||||
ip = ip.split(",")[0];
|
||||
}
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unkonwMsg.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unkonwMsg.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unkonwMsg.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unkonwMsg.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unkonwMsg.equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("X-Real-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || unkonwMsg.equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
System.out.println("获取客户端ip: " + ip);
|
||||
return ip;
|
||||
}
|
||||
}
|
21
src/main/java/com/xkrs/utils/NumberUtil.java
Normal file
21
src/main/java/com/xkrs/utils/NumberUtil.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
/**
|
||||
* 数字工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class NumberUtil {
|
||||
|
||||
public static boolean isStrNumeric(String str) {
|
||||
if(str==null||str.length()==0){
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
System.out.println(str.charAt(i));
|
||||
if (!Character.isDigit(str.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
152
src/main/java/com/xkrs/utils/ObjectToBeanUtils.java
Normal file
152
src/main/java/com/xkrs/utils/ObjectToBeanUtils.java
Normal file
@ -0,0 +1,152 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public class ObjectToBeanUtils {
|
||||
|
||||
public static Logger log = LoggerFactory.getLogger(ObjectToBeanUtils.class);
|
||||
|
||||
/**
|
||||
* 把List<Object[]>转换成List<T>
|
||||
*/
|
||||
public static <T> List<T> objectToBean(List<Object[]> objList, Class<T> clz) throws Exception{
|
||||
if (objList==null || objList.size()==0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Class<?>[] cz = null;
|
||||
Constructor<?>[] cons = clz.getConstructors();
|
||||
for (Constructor<?> ct : cons) {
|
||||
Class<?>[] clazz = ct.getParameterTypes();
|
||||
if (objList.get(0).length == clazz.length) {
|
||||
cz = clazz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
List<T> list = new ArrayList<T>();
|
||||
for (Object[] obj : objList) {
|
||||
Constructor<T> cr = clz.getConstructor(cz);
|
||||
list.add(cr.newInstance(obj));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static <T> List<T> objectToBeans(List<Object[]> objList, Class<T> clz) throws Exception{
|
||||
if (objList==null || objList.size()==0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int length = objList.get(0).length;
|
||||
log.info("*************>"+length);
|
||||
|
||||
Class<?>[] cz = null;
|
||||
Constructor<?>[] cons = clz.getConstructors();
|
||||
for (Constructor<?> ct : cons) {
|
||||
Class<?>[] clazz = ct.getParameterTypes();
|
||||
if (objList.get(0).length == clazz.length) {
|
||||
cz = clazz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
List<T> list = new ArrayList<T>();
|
||||
log.info("---------->"+objList.get(0));
|
||||
Constructor<T> cr = clz.getConstructor(cz);
|
||||
T newInstance = cr.newInstance((Object) objList.get(0));
|
||||
list.add(newInstance);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static <T> List<T> castEntity(List<Object[]> list, Class<T> clazz, Object model) {
|
||||
List<T> returnList = new ArrayList<T>();
|
||||
if (list.isEmpty()) {
|
||||
return returnList;
|
||||
}
|
||||
//获取每个数组集合的元素个数
|
||||
Object[] co = list.get(0);
|
||||
|
||||
//获取当前实体类的属性名、属性值、属性类别
|
||||
List<Map> attributeInfoList = getFiledsInfo(model);
|
||||
//创建属性类别数组
|
||||
Class[] c2 = new Class[attributeInfoList.size()];
|
||||
//如果数组集合元素个数与实体类属性个数不一致则发生错误
|
||||
if (attributeInfoList.size() != co.length) {
|
||||
return returnList;
|
||||
}
|
||||
//确定构造方法
|
||||
for (int i = 0; i < attributeInfoList.size(); i++) {
|
||||
c2[i] = (Class) attributeInfoList.get(i).get("type");
|
||||
}
|
||||
try {
|
||||
for (Object[] o : list) {
|
||||
Constructor<T> constructor = clazz.getConstructor(c2);
|
||||
returnList.add(constructor.newInstance(o));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.info("实体数据转化为实体类发生异常:异常信息:{}", ex.getMessage());
|
||||
return returnList;
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性名获取属性值
|
||||
*
|
||||
* @param fieldName 属性名
|
||||
* @param modle 实体类
|
||||
* @return 属性值
|
||||
*/
|
||||
private static Object getFieldValueByName(String fieldName, Object modle) {
|
||||
try {
|
||||
String firstLetter = fieldName.substring(0, 1).toUpperCase();
|
||||
String getter = "get" + firstLetter + fieldName.substring(1);
|
||||
Method method = modle.getClass().getMethod(getter, new Class[]{});
|
||||
Object value = method.invoke(modle, new Object[]{});
|
||||
return value;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取属性类型(type),属性名(name),属性值(value)的map组成的list
|
||||
*
|
||||
* @param model 实体类
|
||||
* @return list集合
|
||||
*/
|
||||
private static List<Map> getFiledsInfo(Object model) {
|
||||
Field[] fields = model.getClass().getDeclaredFields();
|
||||
List<Map> list = new ArrayList(fields.length);
|
||||
Map infoMap = null;
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
infoMap = new HashMap(3);
|
||||
infoMap.put("type", fields[i].getType());
|
||||
infoMap.put("name", fields[i].getName());
|
||||
infoMap.put("value", getFieldValueByName(fields[i].getName(), model));
|
||||
list.add(infoMap);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
}
|
37
src/main/java/com/xkrs/utils/OpenGeoUtil.java
Normal file
37
src/main/java/com/xkrs/utils/OpenGeoUtil.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.Point;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 开源Gis工具集
|
||||
* @author tajochen
|
||||
*/
|
||||
public class OpenGeoUtil {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(OpenGeoUtil.class);
|
||||
|
||||
/**
|
||||
* wkt文本转为点数据
|
||||
* @param wkt
|
||||
* @return
|
||||
*/
|
||||
public static Point wktStrToPoint(String wkt) {
|
||||
Point point = (Point) Wkt.fromWkt(wkt);
|
||||
return point;
|
||||
}
|
||||
|
||||
/**
|
||||
* wkt文本转geometry
|
||||
* @param wkt
|
||||
* @return
|
||||
*/
|
||||
public static Geometry wktStrToGeom(String wkt) {
|
||||
Geometry geom = Wkt.fromWkt(wkt);
|
||||
return geom;
|
||||
}
|
||||
|
||||
}
|
190
src/main/java/com/xkrs/utils/PhotoUtil.java
Normal file
190
src/main/java/com/xkrs/utils/PhotoUtil.java
Normal file
@ -0,0 +1,190 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public class PhotoUtil {
|
||||
|
||||
public static Logger log = LoggerFactory.getLogger(PhotoUtil.class);
|
||||
|
||||
/**
|
||||
* 上传单张图片
|
||||
* @param imgFile
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String memoryPhoto(MultipartFile imgFile) throws IOException {
|
||||
//String uploadPath = "http://139.199.98.175:2088/wfTaskImage/";
|
||||
// String uploadPath = "http://192.168.2.139";
|
||||
String uploadPath = "/";
|
||||
//获取原始文件名
|
||||
String originalFilename = imgFile.getOriginalFilename();
|
||||
if (originalFilename != null && !"".equals(originalFilename)) {
|
||||
//找到 . 的位置
|
||||
int index = originalFilename.lastIndexOf(".");
|
||||
//根据 . 的位置进行分割,拿到文件后缀名
|
||||
String suffix = originalFilename.substring(index);
|
||||
//uuid生成新的文件名
|
||||
String newName = UUID.randomUUID().toString() + suffix;
|
||||
|
||||
//将图片保存到本地/usr/etc/images/Folder
|
||||
File file = new File("E:/img/");
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
String path = "E:/img/" + newName;
|
||||
String uploadsImage = uploadPath + newName;
|
||||
//实现上传
|
||||
imgFile.transferTo(new File(path));
|
||||
|
||||
|
||||
return uploadsImage;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以文件形式,批量上传图片
|
||||
* @param files
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
/*public static List<FireTaskPhoto> uploadImage(MultipartFile[] files, String fireCode) throws IOException {
|
||||
//String uploadPath = "http://139.199.98.175:2099/forestTaskImage/";
|
||||
String uploadPath = "http://118.24.27.47:2088/";
|
||||
String newName = "";
|
||||
String oldName = "";
|
||||
List<FireTaskPhoto> fireTaskPhotos = new ArrayList<>();
|
||||
for(MultipartFile file : files){
|
||||
//获取file图片名称
|
||||
oldName = file.getOriginalFilename();
|
||||
//找到 . 的位置
|
||||
int index = oldName.lastIndexOf(".");
|
||||
//根据 . 的位置进行分割,拿到文件后缀名
|
||||
String suffix = oldName.substring(index);
|
||||
//uuid生成新的文件名
|
||||
newName = UUID.randomUUID().toString() + suffix;
|
||||
//将图片保存到本地/usr/etc/images/Folder
|
||||
File file1 = new File("/home/sxy/server/fire_point/firePointImage/");
|
||||
//File file1 = new File("E:/file/work/image/");
|
||||
if (!file1.exists()) {
|
||||
file1.mkdirs();
|
||||
}
|
||||
String path = "/home/sxy/server/fire_point/firePointImage/" + newName;
|
||||
//String path = "E:/file/work/image/" + newName;
|
||||
String uploadPaths = "/firePointImage/" + newName;
|
||||
//实现上传
|
||||
file.transferTo(new File(path));
|
||||
FireTaskPhoto fireTaskPhoto = new FireTaskPhoto();
|
||||
fireTaskPhoto.setPhotoFireCode(fireCode);
|
||||
fireTaskPhoto.setTaskPhoto(uploadPaths);
|
||||
|
||||
fireTaskPhotos.add(fireTaskPhoto);
|
||||
}
|
||||
return fireTaskPhotos;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除本地或服务器储存的图片
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public static String delFile(String path){
|
||||
String resultInfo = null;
|
||||
int lastIndexOf = path.lastIndexOf("/");
|
||||
String imgPath = path.substring(lastIndexOf + 1,path.length());
|
||||
System.out.println(imgPath);
|
||||
imgPath = "/usr/local/etc/images/" + imgPath;
|
||||
// img_path = "/usr/etc/images/Folder/" + img_path;
|
||||
File file = new File(imgPath);
|
||||
if(file.exists()){
|
||||
if(file.delete()){
|
||||
resultInfo = "删除成功!";
|
||||
}else {
|
||||
resultInfo = "删除失败!";
|
||||
}
|
||||
}else {
|
||||
resultInfo = "文件不存在";
|
||||
}
|
||||
return resultInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过图片路径解析 ,上传保存
|
||||
* @param listImgSrc
|
||||
* @return
|
||||
*/
|
||||
public static List downloadImage(List<String> listImgSrc) {
|
||||
try {
|
||||
List list = new ArrayList();
|
||||
//开始时间
|
||||
Date beginDate = new Date();
|
||||
for (String url : listImgSrc) {
|
||||
//开始时间
|
||||
Date beginDate2 = new Date();
|
||||
String imageName = url.substring(url.lastIndexOf("/") + 1, url.length());
|
||||
URL uri = new URL(url);
|
||||
InputStream in = uri.openStream();
|
||||
//String pathUpload = "E:/img/" + imageName;
|
||||
String pathUpload = "/home/web/wf-fire-service/wfimage/" + imageName;
|
||||
FileOutputStream fo = new FileOutputStream(new File(pathUpload));
|
||||
byte[] buf = new byte[1024];
|
||||
int length = 0;
|
||||
log.info("-------开始下载:" + url);
|
||||
while ((length = in.read(buf, 0, buf.length)) != -1) {
|
||||
fo.write(buf, 0, length);
|
||||
}
|
||||
in.close();
|
||||
fo.close();
|
||||
list.add(imageName);
|
||||
log.info(imageName + "------下载完成");
|
||||
//结束时间
|
||||
Date overDate2 = new Date();
|
||||
double time = overDate2.getTime() - beginDate2.getTime();
|
||||
log.info("-----耗时:" + time / 1000 + "s");
|
||||
}
|
||||
Date overDate = new Date();
|
||||
double time = overDate.getTime() - beginDate.getTime();
|
||||
log.info("======总耗时:" + time / 1000 + "s");
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
log.info("++++++下载失败");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除本地文件夹图片
|
||||
* @param url
|
||||
*/
|
||||
public static void deleteImage(String url){
|
||||
File file=new File(url);
|
||||
//判断file是否是文件目录 若是返回TRUE
|
||||
if (file.isDirectory()){
|
||||
//name存储file文件夹中的文件名
|
||||
String[] name =file.list();
|
||||
for (int i=0; i<name.length; i++){
|
||||
//此时就可得到文件夹中的文件
|
||||
File f=new File(url, name[i]);
|
||||
//删除文件
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
src/main/java/com/xkrs/utils/Query.java
Normal file
54
src/main/java/com/xkrs/utils/Query.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class Query {
|
||||
|
||||
/**
|
||||
* 查询近一个月的火点信息(县)
|
||||
* @param countyCode
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
/*public List<FirePointEntity> selectFirePointByMonthCounty(String proName, String countyCode,String startTime,String endTime) {
|
||||
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
||||
List<Predicate> list = new ArrayList<>();
|
||||
if(countyCode != null && !"".equals(countyCode)){
|
||||
list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), countyCode));
|
||||
}
|
||||
if(startTime != null && !"".equals(startTime)){
|
||||
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime));
|
||||
}
|
||||
if(endTime != null && !"".equals(endTime)){
|
||||
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime));
|
||||
}
|
||||
if(proName.equals("山东省")){
|
||||
list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地"));
|
||||
}
|
||||
Predicate[] predicates = new Predicate[list.size()];
|
||||
return criteriaBuilder.and(list.toArray(predicates));
|
||||
}
|
||||
};
|
||||
return firePointDao.findAll(specification);
|
||||
}*/
|
||||
|
||||
|
||||
}
|
71
src/main/java/com/xkrs/utils/RandomUtil.java
Normal file
71
src/main/java/com/xkrs/utils/RandomUtil.java
Normal file
@ -0,0 +1,71 @@
|
||||
package com.xkrs.utils;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 随机字符串产生工具
|
||||
* @author tajochen
|
||||
*/
|
||||
public class RandomUtil {
|
||||
/**
|
||||
* 获取随机字母数字组合
|
||||
* @param length
|
||||
* 字符串长度
|
||||
* @return
|
||||
*/
|
||||
public static String getRandomCharAndNumr(Integer length) {
|
||||
String str = "";
|
||||
StringBuilder strBuffer = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < length; i++) {
|
||||
boolean b = random.nextBoolean();
|
||||
// 字符串
|
||||
if (b) {
|
||||
//取得65大写字母还是97小写字母
|
||||
int choice = random.nextBoolean() ? 65 : 97;
|
||||
strBuffer.append((char) (choice + random.nextInt(26)));
|
||||
} else {
|
||||
// 数字
|
||||
strBuffer.append(random.nextInt(10));
|
||||
}
|
||||
}
|
||||
str = strBuffer.toString();
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证随机字母数字组合是否纯数字与纯字母
|
||||
* @param str
|
||||
* @return true 是 , false 否
|
||||
*/
|
||||
public static boolean isRandomUsable(String str) {
|
||||
// String regExp =
|
||||
// "^[A-Za-z]+(([0-9]+[A-Za-z0-9]+)|([A-Za-z0-9]+[0-9]+))|[0-9]+(([A-Za-z]+[A-Za-z0-9]+)|([A-Za-z0-9]+[A-Za-z]+))$";
|
||||
String regExp = "^([0-9]+)|([A-Za-z]+)$";
|
||||
Pattern pat = Pattern.compile(regExp);
|
||||
Matcher mat = pat.matcher(str);
|
||||
return mat.matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成UUID
|
||||
* @return
|
||||
*/
|
||||
public static String getUuid32(){
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
return uuid;
|
||||
// return UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成六位数
|
||||
* @return
|
||||
*/
|
||||
public static int returnCode() {
|
||||
Random rand = new Random();
|
||||
return rand.nextInt(899999) + 100000;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user