Commit d6a46aaf authored by youjj's avatar youjj

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	pom.xml
parents 761b2770 9a5b8c8b
...@@ -35,6 +35,7 @@ Cloud`微`服务`化`开发平台`,具有统一授权、认证后台管理系 ...@@ -35,6 +35,7 @@ Cloud`微`服务`化`开发平台`,具有统一授权、认证后台管理系
------ ------
## 功能截图 ## 功能截图
### 基本功能 ### 基本功能
......
...@@ -4,8 +4,8 @@ spring: ...@@ -4,8 +4,8 @@ spring:
cloud: cloud:
nacos: nacos:
config: config:
server-addr: 127.0.0.1:8848 # server-addr: 127.0.0.1:8848
# server-addr: 10.5.52.2:8848 server-addr: 10.5.52.3:8848
file-extension: yaml file-extension: yaml
profiles: profiles:
active: dev active: dev
\ No newline at end of file
...@@ -4,8 +4,8 @@ spring: ...@@ -4,8 +4,8 @@ spring:
cloud: cloud:
nacos: nacos:
config: config:
server-addr: 127.0.0.1:8848 # server-addr: 127.0.0.1:8848
# server-addr: 10.5.52.2:8848 server-addr: 10.5.52.3:8848
file-extension: yaml file-extension: yaml
profiles: profiles:
active: dev active: dev
......
...@@ -4,8 +4,8 @@ spring: ...@@ -4,8 +4,8 @@ spring:
cloud: cloud:
nacos: nacos:
config: config:
server-addr: 127.0.0.1:8848 # server-addr: 127.0.0.1:8848
# server-addr: 10.5.52.2:8848 server-addr: 10.5.52.3:8848
file-extension: yaml file-extension: yaml
profiles: profiles:
active: dev active: dev
\ No newline at end of file
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
<module>ace-modules</module> <module>ace-modules</module>
<module>xx-member</module> <module>xx-member</module>
<module>xx-member-api</module> <module>xx-member-api</module>
<module>xx-third-party</module> <module>vehicle</module>
<module>xx-third-party-api</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>
<developers> <developers>
......
HELP.md
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/
### VS Code ###
.vscode/
/*
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.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* 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/0.4.2/maven-wrapper-0.4.2.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 direcrory '" + 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 {
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();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
#!/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.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 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)`"
# TODO classpath?
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
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
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 command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
curl -o "$wrapperJarPath" "$jarUrl"
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
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
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 "$@"
@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 Maven2 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 key stroke 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 my 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.4.2/maven-wrapper-0.4.2.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% (
echo Found %WRAPPER_JAR%
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
echo Finished downloading %WRAPPER_JAR%
)
@REM End of extension
%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%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-security</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>vehicle</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>vehicle</name>
<description>车辆管理</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
<!-- MyBatis Generator -->
<!-- Java接口和实体类 -->
<targetJavaProject>${basedir}/src/main/java</targetJavaProject>
<targetMapperPackage>com.xinxincaravan.caravan.vehicle.mapper
</targetMapperPackage>
<targetModelPackage>com.xinxincaravan.caravan.vehicle.entity
</targetModelPackage>
<!-- XML生成路径 -->
<targetResourcesProject>${basedir}/src/main/resources
</targetResourcesProject>
<targetXMLPackage>mapper</targetXMLPackage>
<!-- 依赖版本 -->
<mapper.version>3.4.0</mapper.version>
<mybatis.version>3.3.1</mybatis.version>
<mybatis.spring.version>1.2.4</mybatis.spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!--nacos相关配置-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>0.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<!--引入开源后台项目的公共包-->
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-common</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-interface</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-auth-client</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<!-- 持久层 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 加入batis通用mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.2</version>
</dependency>
<!-- 加入mybatis通用分页组件支持-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.github.drtrang</groupId>
<artifactId>druid-spring-boot2-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!-- 引用缓存开源项目 -->
<dependency>
<groupId>com.github.wxiaoqi</groupId>
<artifactId>ace-cache</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 此插件用来生成通用mapper的代码 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>
${basedir}/src/main/resources/builder/generatorConfig.xml
</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
</dependencies>
</plugin>
<!--<plugin>-->
<!--<groupId>org.asciidoctor</groupId>-->
<!--<artifactId>asciidoctor-maven-plugin</artifactId>-->
<!--<version>1.5.3</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>generate-docs</id>-->
<!--<phase>prepare-package</phase>-->
<!--<goals>-->
<!--<goal>process-asciidoc</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<backend>html</backend>-->
<!--<doctype>book</doctype>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>org.springframework.restdocs</groupId>-->
<!--<artifactId>spring-restdocs-asciidoctor</artifactId>-->
<!--</dependency>-->
<!--</dependencies>-->
<!--</plugin>-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.xinxincaravan.caravan.vehicle;
import com.ace.cache.EnableAceCache;
import com.github.wxiaoqi.security.auth.client.EnableAceAuthClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableDiscoveryClient
@EnableScheduling
@EnableAceAuthClient
@EnableFeignClients({"com.github.wxiaoqi.security.auth.client.feign"})
@EnableAceCache
@MapperScan("com.xinxincaravan.caravan.vehicle.mapper")
public class VehicleApplication {
public static void main(String[] args) {
SpringApplication.run(VehicleApplication.class, args);
}
}
package com.xinxincaravan.caravan.vehicle.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Lists;
import com.xinxincaravan.caravan.vehicle.constant.RedisKey;
import com.xinxincaravan.caravan.vehicle.entity.BranchCompany;
import com.xinxincaravan.caravan.vehicle.mapper.BranchCompanyMapper;
import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyVo;
import com.xinxincaravan.caravan.vehicle.vo.PageDataVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
@Service
@Slf4j
public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany> {
/**
* 按主键获取公司
* @param id
* @return
*/
public BranchCompany getById(Integer id){
return mapper.selectByPrimaryKey(id);
}
public Boolean exits(Integer id){
BranchCompany param = new BranchCompany();
param.setId(id);
return mapper.selectCount(param)>0;
}
/**
* 转换为vo类
* @param branchCompanies
* @returns
*/
private List<BranchCompanyVo> branchCompany2VO(List<BranchCompany> branchCompanies){
List<BranchCompanyVo> branchCompanyVoList = Lists.newArrayList();
if(CollectionUtils.isNotEmpty(branchCompanies)){
for(BranchCompany branchCompany:branchCompanies){
BranchCompanyVo branchCompanyVo = new BranchCompanyVo();
BeanUtils.copyProperties(branchCompany,branchCompanyVo);
branchCompanyVoList.add(branchCompanyVo);
}
}
return branchCompanyVoList;
}
public PageDataVo<BranchCompany> getAll(Integer page,Integer limit,Integer addrProvince, Integer addrCity,
Integer addrTown){
Example example = new Example(BranchCompany.class);
Example.Criteria criteria = example.createCriteria();
if(addrProvince!=null) {
criteria.andCondition(" addr_province = '" + addrProvince + "'");
}
if(addrCity!=null) {
criteria.andCondition(" addr_city = '" + addrCity + "'");
}
if(addrTown!=null) {
criteria.andCondition(" addr_town = '" + addrTown + "'");
}
example.setOrderByClause("`id` asc");
PageHelper.startPage(page,limit);
PageInfo<BranchCompany> branchCompanyPageInfo = new PageInfo<>(mapper.selectByExample(example));
return PageDataVo.pageInfo(branchCompanyPageInfo);
}
@Cache(key= RedisKey.BRANCH_COMPANY_CACHE_ALL)
public List<BranchCompany> getAll(){
return mapper.selectAll();
}
/**
* 增加公司,返回id
* @param branchCompanyVo
* @return
*/
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE_ALL)
public Integer add(BranchCompanyVo branchCompanyVo){
BranchCompany branchCompany = new BranchCompany();
BeanUtils.copyProperties(branchCompanyVo,branchCompany);
mapper.insertSelective(branchCompany);
return branchCompany.getId();
}
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE_ALL)
public void del(Integer id){
mapper.deleteByPrimaryKey(id);
}
/**
* 更新公司信息
* @param branchCompany
* @return
*/
@CacheClear(key= RedisKey.BRANCH_COMPANY_CACHE_ALL)
public Integer update(BranchCompany branchCompany){
return mapper.updateByPrimaryKeySelective(branchCompany);
}
}
package com.xinxincaravan.caravan.vehicle.biz;
import com.alibaba.fastjson.JSON;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xinxincaravan.caravan.vehicle.common.CustomIllegalParamException;
import com.xinxincaravan.caravan.vehicle.constant.ConstantType;
import com.xinxincaravan.caravan.vehicle.constant.RedisKey;
import com.xinxincaravan.caravan.vehicle.entity.Constant;
import com.xinxincaravan.caravan.vehicle.mapper.ConstantMapper;
import com.xinxincaravan.caravan.vehicle.vo.ConstantVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class ConstantBiz extends BaseBiz<ConstantMapper,Constant> {
@Autowired
private RedisTemplate customRedisTemplate;
@Autowired
private TaskExecutor customTaskExecutor;
/**
* 每批次最大更新常量条目数
*/
public static final Integer MAX_BATCH_SIZE_CONSTANT_UPDATE = 1000;
/**
* 转换实体类为VO
* @param constant
* @return
*/
private ConstantVo constant2VO(Constant constant){
ConstantVo constantVo = new ConstantVo();
constantVo.setType(constant.getType());
constantVo.setCode(constant.getCode());
constantVo.setVal(constant.getVal());
return constantVo;
}
/**
* 获取对应redis中的hash的key
* @param type
* @return
*/
private String getConstantRedisKey(Integer type){
return RedisKey.CONSTANT_CACHE_PREFIX +type;
}
/**
* 查询所有类型下的常量数据,先从缓存读
* @param type
* @return
*/
public List<ConstantVo> getAllConstantByType(Integer type) {
String cacheConstantsJsonStr = String.valueOf(customRedisTemplate.opsForValue().get(getConstantRedisKey(type)));
Map<String,Object> constantMap = new HashMap<>();
if(StringUtils.isNotBlank(cacheConstantsJsonStr)){
constantMap = JSON.parseObject(cacheConstantsJsonStr);
}
List<ConstantVo> constantVoList = Lists.newArrayList();
//尝试从缓存中查询
if(MapUtils.isNotEmpty(constantMap)){
for(Map.Entry<String,Object> constantEntry:constantMap.entrySet()){
ConstantVo constant = new ConstantVo();
constant.setType(type);
constant.setCode(Integer.valueOf(constantEntry.getKey()));
constant.setVal(String.valueOf(constantEntry.getValue()));
constantVoList.add(constant);
}
return constantVoList;
}
//刷新缓存
refreshCacheAsync();
//缓存中不存在则从bd中查询
return getAllConstantByTypeNoCache(type);
}
/**
* 获取db中所有类型下的常量数据
* @param type
* @return
*/
public List<ConstantVo> getAllConstantByTypeNoCache(Integer type) {
List<ConstantVo> constantVoList = Lists.newArrayList();
Constant param = new Constant();
param.setType(type);
List<Constant> constantListFromDb= mapper.select(param);
if(CollectionUtils.isNotEmpty(constantListFromDb)){
for(Constant constant:constantListFromDb){
constantVoList.add(constant2VO(constant));
}
}
return constantVoList;
}
public void refreshCacheAsync(){
customTaskExecutor.execute(new Runnable() {
@Override
public void run() {
refreshCache();
}
});
}
/**
* 5分钟内刷新数据到缓存
*/
@Scheduled(cron = "0 */5 * * * *")//每5分钟刷新一次数据
public void refreshCache(){
log.info("刷新常量数据任务开始");
List<Integer> types = mapper.getAllConstantTypes();
for(Integer type : types){
log.info("刷新类型【"+type+"】常量数据任务开始");
//redis方式实现乐观锁
String redisLockKey = RedisKey.CONSTANT_REFRESH_LOCK_PREFIX +type+":"+(DateTime.now().getMinuteOfDay()/5);//同一日每5分钟只刷新一次
Boolean suc = customRedisTemplate.opsForValue().setIfAbsent(redisLockKey, String.valueOf(DateTime.now().getMillis()));
if(!suc){
continue;
}
customRedisTemplate.expire(redisLockKey,5, TimeUnit.MINUTES);//5分钟内过期
List<ConstantVo> constantVoList = getAllConstantByTypeNoCache(type);
if(CollectionUtils.isNotEmpty(constantVoList)){
Map<String,String> constantMap = new HashMap<>();
for(ConstantVo constantVo:constantVoList){
constantMap.put(String.valueOf(constantVo.getCode()),constantVo.getVal());
}
customRedisTemplate.opsForValue().set(getConstantRedisKey(type), JSON.toJSONString(constantMap));
}
log.info("刷新类型【"+type+"】常量数据任务完成");
}
log.info("刷新常量数据任务成功");
}
/**
* 检查批量操作批次大小是否合法
* @param constants
* @return
*/
private Boolean checkBatchSize(List<Constant> constants){
if(CollectionUtils.isEmpty(constants)){
return Boolean.FALSE;
}
if(constants.size()>MAX_BATCH_SIZE_CONSTANT_UPDATE){
throw new IllegalArgumentException(" exceed max batch size");
}
return Boolean.TRUE;
}
/**
* 批量更新常量
* @param type
* @param constants
*/
@Transactional
public Integer updateConstants(Integer type, List<Constant> constants) {
if(!checkBatchSize(constants)){
return 0;
}
Map<Integer,String> codeAndVal = Maps.newHashMap();
for(Constant constant:constants){
constant.setType(type);
Integer affected = mapper.updateByTypeAndCode(constant);
if(affected>0){
codeAndVal.put(constant.getCode(),constant.getVal());
}
}
return codeAndVal.size();
}
/**
* 删除常量
* @param type
* @param codes
*/
@Transactional
public Integer delConstant(Integer type, List<Integer> codes){
if(codes ==null||codes.size()==0){
return 0;
}
if(codes.size()>MAX_BATCH_SIZE_CONSTANT_UPDATE){
throw new IllegalArgumentException(" exceed max batch size");
}
List<String> delCodes = Lists.newArrayList();
for(Integer code:codes){
Constant param = new Constant();
param.setType(type);
param.setCode(code);
Integer affected = mapper.delByTypeAndCode(param);
if(affected>0){
delCodes.add(String.valueOf(code));
}
}
return delCodes.size();
}
/**
* 增加常量
* @param type
* @param constants
*/
public Integer addConstants(Integer type, List<Constant> constants){
if(!checkBatchSize(constants)){
return 0;
}
Map<String,String> codeAndVal = Maps.newHashMap();
for(Constant constant:constants){
constant.setType(type);
Integer affected = mapper.insertIgnoreOnDuplicate(constant);
if(affected>0){
codeAndVal.put(constant.getCode().toString(),constant.getVal());
}
}
return codeAndVal.size();
}
/**
* 检查常量是否已存在
* @param type
* @param code
* @return
*/
public Boolean checkIfExists(Integer type,Integer code){
if(!ConstantType.exists(type)){
throw new CustomIllegalParamException(" no such type of constant");
}
List<ConstantVo> constantVoList = getAllConstantByType(type);
if(CollectionUtils.isEmpty(constantVoList)){
throw new CustomIllegalParamException(" no such code of constant in relative type");
}
for(ConstantVo constantVo:constantVoList){
if(NumberUtils.compare(code,constantVo.getCode())==0){
return Boolean.TRUE;
}
}
throw new CustomIllegalParamException(" no such code of constant in relative type");
}
}
package com.xinxincaravan.caravan.vehicle.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Lists;
import com.xinxincaravan.caravan.vehicle.common.CustomIllegalParamException;
import com.xinxincaravan.caravan.vehicle.constant.RedisKey;
import com.xinxincaravan.caravan.vehicle.constant.RegionType;
import com.xinxincaravan.caravan.vehicle.entity.SysRegion;
import com.xinxincaravan.caravan.vehicle.mapper.SysRegionMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Slf4j
public class SysRegionBiz extends BaseBiz<SysRegionMapper, SysRegion> {
@Autowired
private RedisTemplate customRedisTemplate;//todo redis需要改为多实例
@Autowired
private TaskExecutor customTaskExecutor;
/**
* 国家没有父地区,其parentId为0
*/
private static final Long PARENT_ID_NONE = 0l;
public List<SysRegion> getRegionsByCodes(List<Long> ids){
List<String> redisCacheKeys = Lists.newArrayList();
if(CollectionUtils.isEmpty(ids)){
throw new CustomIllegalParamException("empty id list");
}
for(Long id:ids){
redisCacheKeys.add(RedisKey.SYS_REGION_CACHE_PREFIX+id);
}
List<String> cachedRegionStrList = customRedisTemplate.opsForValue().multiGet(redisCacheKeys);
List<SysRegion> rs = Lists.newArrayList();
Boolean hasCache = Boolean.TRUE;
for(String cachedRegionStr:cachedRegionStrList){
if(StringUtils.isBlank(cachedRegionStr)){
hasCache = Boolean.FALSE;
continue;
}else{
rs.add(JSONObject.parseObject(cachedRegionStr,SysRegion.class));
}
}
if(!hasCache){//从db读
rs = mapper.getByIdList(ids);
}
return rs;
}
//获取相应地区类型对应在id的位数,作为对应parent查找其下地区的redis key组成部分
private String getPrefixOfAgencyId(Integer type,Long parentId){
switch(type){
case -1:
return String.valueOf(-1);
case 0:
return String.valueOf(0);
case 1:
return String.valueOf(parentId).substring(0,2);
case 2:
return String.valueOf(parentId).substring(0,4);
default:
throw new CustomIllegalParamException("not valid region");
}
}
//获取相应地区类型对应在id的位数,作为对应parent查找其下地区的redis key组成部分
private String getPrefixOfAgencyId(Long parentId){
Integer type = getTypeFromId(parentId);
return getPrefixOfAgencyId(type,parentId);
}
/**
* 根据id获得所属类型
* @param id
* @return
*/
private Integer getTypeFromId(Long id){
if(id == 0){
return RegionType.ALL.getCode();
}if(id < 10){
return RegionType.COUNTRY.getCode();
}else if(id%100>0){//第1、2非零,即3级地区
return RegionType.TOWN.getCode();
}else if(id%10000>0){//第1、2为零,第3、4位非0,即2级地区
return RegionType.CITY.getCode();
}else{//第1、2、3、4为零,第5、6位非0,即2级地区
return RegionType.PROVINCE.getCode();
}
}
/**
* 获取对应redis中的hash的key
* @param parentId
* @return
*/
private String getCacheRedisKey(Long parentId){
//获取相应地区类型对应在agencyId的位数
return RedisKey.SYS_REGION_SONS_CACHE_PREFIX +getPrefixOfAgencyId(parentId);
}
/**
* 查询对应地区之下的地区
* @param id
* @return
*/
public List<SysRegion> getSonRegion(Long id){
//从缓存中查询
String redisKey = getCacheRedisKey(id);
String sysRegionListJson = String.valueOf(customRedisTemplate.opsForValue().get(redisKey));
List<SysRegion> sysRegions = null;
if(StringUtils.isNotBlank(sysRegionListJson)){
sysRegions = JSONObject.parseArray(sysRegionListJson,SysRegion.class);
}
if(CollectionUtils.isNotEmpty(sysRegions)){
return sysRegions;
}
//不存在则异步开启刷新缓存任务
refreshCacheAsync();
//从db中查询
return getSonRegionNoCache(id);
}
public List<SysRegion> getSonRegionNoCache(Long id){
//从db中查询
SysRegion param = new SysRegion();
param.setParentId(id);
return mapper.select(param);
}
public void refreshCacheAsync(){
customTaskExecutor.execute(new Runnable() {
@Override
public void run() {
refreshCache();
}
});
}
/**
* 刷新其孩子节点到缓存,并对其孩子迭代执行此操作
* @param id
*/
private void refreshCacheRegionAndSon(Long id){
List<SysRegion> sonRegions = getSonRegionNoCache(id);
//把当前节点的子节点数据缓存
String redisKey = getCacheRedisKey(id);
customRedisTemplate.opsForValue().set(redisKey,JSON.toJSON(sonRegions).toString());
log.info("完成地区【"+id+"】的子地区数据缓存");
if(CollectionUtils.isEmpty(sonRegions) || getTypeFromId(id).equals(RegionType.CITY.getCode())){
return;
}
for(SysRegion sonRegion:sonRegions){
//缓存每个地区
customRedisTemplate.opsForValue().set(RedisKey.SYS_REGION_CACHE_PREFIX+sonRegion.getId(),JSON.toJSON(sonRegion).toString());
refreshCacheRegionAndSon(sonRegion.getId());
}
}
/**
* 5分钟内刷新数据到缓存
*/
@Scheduled(cron = "0 */5 * * * *")//每5分钟刷新一次数据
public void refreshCache(){
String redisLockKey = RedisKey.SYS_REGION_REFRESH_LOCK +(DateTime.now().getMinuteOfDay()/5);//同一日每5分钟只刷新一次
Boolean suc = customRedisTemplate.opsForValue().setIfAbsent(redisLockKey, String.valueOf(DateTime.now().getMillis()));
if(!suc){
log.info("刷新地区数据:获取乐观锁失败,不执行任务");
return;
}
log.info("刷新地区数据任务开始");
refreshCacheRegionAndSon(PARENT_ID_NONE);
log.info("刷新常量数据任务成功");
}
}
package com.xinxincaravan.caravan.vehicle.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Maps;
import com.xinxincaravan.caravan.vehicle.constant.RedisKey;
import com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo;
import com.xinxincaravan.caravan.vehicle.mapper.VehicleBookInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBookInfo> {
public static final String TB_NAME_PREFIX = "vehicle_book_info_his_";
public static final DateTimeFormatter YEAR_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy");
public static final DateTimeFormatter YEARMONTH_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM");
public static final Integer DEL_BATCH_SIZE = 1000;
public static final Integer COPY_BATCH_SIZE = 100;
@Autowired
private RedisTemplate customRedisTemplate;
/**
* 迁移数据到历史表
* 每年一张表
*/
@Scheduled(cron = "0 0 0 1 * ?")//每月1号0点触发
@Transactional
public void transfer2HistoryTb(){
//获取表格名称
String tbName = getTbNameNow();
DateTime now = DateTime.now();//当前获取的时间为标准
log.info("开始预定信息迁移至历史表的定时任务。");
//每月初将上月数据复制到历史表
Boolean needRun= copyDataLastMoth(now,tbName);
if(needRun) {
//每月初将上上月数据从当前信息表中删除
delDataTheMonthBeforeLast(now, tbName);
}
}
/**
* 获取上月数据,并复制到历史表
*/
@Transactional
public Boolean copyDataLastMoth(DateTime now,String tbName){
String lastMonthStr = now.plusMonths(-1).toString(YEARMONTH_DATE_TIME_FORMATTER);
String redisKey = RedisKey.DEL_BOOK_INFO_LOCK_PREFIX +lastMonthStr;
Boolean hasSuc = customRedisTemplate.opsForValue().setIfAbsent(redisKey,String.valueOf(DateTime.now().getMillis()));
if(hasSuc){//设置1天后过期
customRedisTemplate.expire(redisKey,1, TimeUnit.DAYS);
}else{
log.info("[预定信息迁移]乐观锁获取失败,该线程不执行任务。");
return Boolean.FALSE;
}
createTbIfNotExists(tbName);
//逐页查出数据
Integer curPageNo = 1;
List<VehicleBookInfo> vehicleBookInfoList = null;
do {
Map<String, Object> params = Maps.newHashMap();
params.put("yearMonth", lastMonthStr);
params.put("pageStart", (curPageNo - 1) * COPY_BATCH_SIZE);
params.put("pageSize", COPY_BATCH_SIZE);
vehicleBookInfoList = mapper.getByPage4YearMonth(params);
if(CollectionUtils.isNotEmpty(vehicleBookInfoList)){
//插入数据到历史表
for(VehicleBookInfo vehicleBookInfo : vehicleBookInfoList){
Map<String, Object> insertHisParams = Maps.newHashMap();
insertHisParams.put("tbName", tbName);
insertHisParams.put("id", vehicleBookInfo.getId());
insertHisParams.put("vehicle", vehicleBookInfo.getVehicle());
insertHisParams.put("yearMonth", vehicleBookInfo.getYearMonth());
insertHisParams.put("bookedDate", vehicleBookInfo.getBookedDate());
mapper.insertHis(insertHisParams);
}
}
curPageNo++;
log.info("【复制上月预定信息至历史表中】,当前复制页【"+curPageNo+"】,页大小【"+COPY_BATCH_SIZE+"】");
}while(CollectionUtils.isNotEmpty(vehicleBookInfoList));
log.info("复制上月预定信息至历史表中完成,总页数【"+(curPageNo-1)+"】");
; return Boolean.TRUE;
}
/**
* 删除上上月数据
*/
@Transactional
public void delDataTheMonthBeforeLast(DateTime now,String tbName){
String theMonthBeforeLastStr = now.plusMonths(-2).toString(YEARMONTH_DATE_TIME_FORMATTER);
Integer effected = 0;
Integer total = 0;
Map<String, Object> params = Maps.newHashMap();
params.put("yearMonth", theMonthBeforeLastStr);
params.put("batchSize", DEL_BATCH_SIZE);
do {
effected = mapper.del4YearMoth(params);
total+=effected;
log.info("开始删除预定信息数据,删除总数【"+total+"】");
}while(effected!=0);
log.info("删除预定信息数据完成");
}
private String getTbNameNow(){
return TB_NAME_PREFIX+ DateTime.now().toString(YEAR_DATE_TIME_FORMATTER);
}
/**
* 创建当年相关表格
*/
private void createTbIfNotExists(String tbName){
mapper.createTbIfNotExists(tbName);
}
}
package com.xinxincaravan.caravan.vehicle.common;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
@Slf4j
public class BaseController<Biz extends BaseBiz> {
@Autowired
protected HttpServletRequest request;
@Autowired
protected Biz baseBiz;
}
package com.xinxincaravan.caravan.vehicle.common;
public class CustomIllegalParamException extends RuntimeException {
public CustomIllegalParamException(String msg){
super(msg);
}
}
package com.xinxincaravan.caravan.vehicle.common;
/**
* 以Integer代表布尔值时使用
*/
public class Int4Boolean {
public static final Integer TRUE = 1;
public static final Integer FALSE = 0;
}
package com.xinxincaravan.caravan.vehicle.common;
import com.github.wxiaoqi.security.common.msg.BaseResponse;
public class RestResponse<T> extends BaseResponse {
public static final Integer SUC_CODE = 1;
T data;
Integer code;
public RestResponse(){
code = SUC_CODE;
}
public static <M> RestResponse<M> sucResponse(){
return new RestResponse<M>();
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public static <M> RestResponse<M> data(M data){
RestResponse<M> restResponse = new RestResponse<M>();
restResponse.setData(data);
return restResponse;
}
public static <M> RestResponse<M> suc(){
return new RestResponse<M>();
}
public static <M> RestResponse<M> code(Integer code){
RestResponse<M> restResponse = new RestResponse<M>();
restResponse.setCode(code);
return restResponse;
}
public static <M> RestResponse<M> codeAndData(Integer code,M data){
RestResponse<M> restResponse = new RestResponse<M>();
restResponse.setCode(code);
restResponse.setData(data);
return restResponse;
}
public static <M> RestResponse<M> codeAndMessage(Integer code,String msg){
RestResponse<M> restResponse = new RestResponse<M>();
restResponse.setCode(code);
restResponse.setMessage(msg);
return restResponse;
}
}
package com.xinxincaravan.caravan.vehicle.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-06-21 8:39
*/
@Configuration
@Primary
public class RedisConfiguration {
@Bean
public RedisTemplate<String, Object> customRedisTemplate(RedisConnectionFactory factory) {
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(factory);
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(stringSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
package com.xinxincaravan.caravan.vehicle.config;
import com.github.wxiaoqi.security.auth.client.interceptor.ServiceAuthRestInterceptor;
import com.github.wxiaoqi.security.auth.client.interceptor.UserAuthRestInterceptor;
import com.github.wxiaoqi.security.common.handler.GlobalExceptionHandler;
import com.xinxincaravan.caravan.vehicle.interceptor.CorsInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.ArrayList;
import java.util.Collections;
/**
*
*/
@Configuration("vehicleWebConfig")
@Primary
public class WebConfiguration implements WebMvcConfigurer {
@Bean
GlobalExceptionHandler getGlobalExceptionHandler() {
return new GlobalExceptionHandler();
}
/**
* 加入拦截器,介入相关权限验证(服务+用户)
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(getCorsInterceptor()).addPathPatterns("/**");
registry.addInterceptor(getServiceAuthRestInterceptor()).
addPathPatterns(getIncludePathPatterns());
registry.addInterceptor(getUserAuthRestInterceptor()).
addPathPatterns(getIncludePathPatterns());
}
@Bean
ServiceAuthRestInterceptor getServiceAuthRestInterceptor() {
return new ServiceAuthRestInterceptor();
}
@Bean
CorsInterceptor getCorsInterceptor() {
return new CorsInterceptor();
}
@Bean
UserAuthRestInterceptor getUserAuthRestInterceptor() {
return new UserAuthRestInterceptor();
}
/**
* 需要用户和服务认证判断的路径
* @return
*/
private ArrayList<String> getIncludePathPatterns() {
ArrayList<String> list = new ArrayList<>();
String[] urls = {
"/vehicleInfo/**",
"/branchCompany/**"
};
Collections.addAll(list, urls);
return list;
}
/**
* 增加执行异步任务的自定义线程池执行器
* @return
*/
@Bean(name = "customTaskExecutor")
TaskExecutor getTaskExecutor(){
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(5);// 线程池维护线程的最少数量
threadPoolTaskExecutor.setMaxPoolSize(10);// 线程池维护线程的最大数量
threadPoolTaskExecutor.setQueueCapacity(50);// 缓存队列
return threadPoolTaskExecutor;
}
}
package com.xinxincaravan.caravan.vehicle.constant;
import com.google.common.collect.Maps;
import java.util.Map;
public enum BookType {
USER_RENT(1,"用户租赁"),
EMPLOYEE_APPLY(2,"内部员工申请"),
REPAIRING(3,"维修"),
;
/**
* 编码
*/
private Integer code;
/**
* 类型描述
*/
private String desc;
private static Map<Integer,String> codeAndDesc = Maps.newHashMap();
static{
for(BookType constantType : BookType.values()){
codeAndDesc.put(constantType.getCode(),constantType.getDesc());
}
}
BookType(Integer code, String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static Boolean exists(Integer code){
return codeAndDesc.containsKey(code);
}
}
package com.xinxincaravan.caravan.vehicle.constant;
import com.google.common.collect.Maps;
import java.util.Map;
public enum ConstantType {
VEHICLE_BRAND(1,"车辆品牌"),
VEHICLE_USE(2,"车辆用途"),
INSURANCE_COMPANY(3,"保险公司"),
;
/**
* 编码
*/
private Integer code;
/**
* 类型描述
*/
private String desc;
private static Map<Integer,String> codeAndDesc = Maps.newHashMap();
static{
for(ConstantType constantType :ConstantType.values()){
codeAndDesc.put(constantType.getCode(),constantType.getDesc());
}
}
ConstantType(Integer code,String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static Boolean exists(Integer code){
return codeAndDesc.containsKey(code);
}
}
package com.xinxincaravan.caravan.vehicle.constant;
public class RedisKey {
/**
* 常量缓存key前缀
*/
public static final String CONSTANT_CACHE_PREFIX ="cache:constant:";
/**
* 地区常量缓存key前缀(子读取列表)
*/
public static final String SYS_REGION_SONS_CACHE_PREFIX ="cache:sysRegion:sons:";
/**
* 地区常量缓存key前缀(子读取列表)
*/
public static final String SYS_REGION_CACHE_PREFIX ="cache:sysRegion:";
/**
* 刷新常量缓存乐观锁前缀
*/
public static final String CONSTANT_REFRESH_LOCK_PREFIX ="lock:constant:";
/**
* 地区常量缓存key前缀
*/
public static final String SYS_REGION_REFRESH_LOCK ="lock:sysRegion:";
/**
* 迁移预定信息rediseky
*/
public static final String DEL_BOOK_INFO_LOCK_PREFIX ="lock:del:bookInfo:";
/**
* 迁移预定记录rediseky
*/
public static final String DEL_BOOK_RECORD_LOCK_PREFIX ="lock:del:bookRecord:";
/**
* 子公司列表缓存key前缀
*/
public static final String BRANCH_COMPANY_CACHE_ALL ="cache:bracnCompany:all";
}
package com.xinxincaravan.caravan.vehicle.constant;
import com.google.common.collect.Maps;
import java.util.Map;
public enum RegionType {
ALL(-1,"全国"),//这一类型不存在db中,只是用于查询所有国家
COUNTRY(0,"国家"),
PROVINCE(1,"省/直辖市"),
CITY(2,"市"),
TOWN(3,"镇/县"),
;
/**
* 编码
*/
private Integer code;
/**
* 类型描述
*/
private String desc;
private static Map<Integer,String> codeAndDesc = Maps.newHashMap();
static{
for(RegionType constantType : RegionType.values()){
codeAndDesc.put(constantType.getCode(),constantType.getDesc());
}
}
RegionType(Integer code, String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static Boolean exists(Integer code){
return codeAndDesc.containsKey(code);
}
}
package com.xinxincaravan.caravan.vehicle.constant.ResCode;
public enum ResCode {
AUTH_FAIL(-1,"权限验证不通过"),
INVALID_REST_REQ_PARAM(100000,"rest请求参数非法"),
//车辆信息相关返回码-预定信息
VEHICLE_BOOKED_INFO_ALREADY_CHANGED(101001,"车辆预定信息已更改,请刷新后继续操作"),
//车辆信息相关返回码-车辆信息
VEHICLE_INFO_SAME_NUM_PLATE_EXISTS(102001,"该车牌车辆已经存在"),
VEHICLE_INFO_BRANCH_NOT_EXIST(102002,"分公司信息非法"),
VEHICLE_INFO_CODE_EXIST(102003,"车辆编码已存在"),
//车辆信息相关返回码-预定申请信息
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED(103001,"车辆预定申请已被审批,请刷新后继续操作"),
VEHICLE_BOOKED_RECORD_STATUS_CHANGED(103002,"车辆预定申请状态已变更,请刷新后继续操作"),
;
/**
* 返回码
*/
private Integer code;
/**
* 描述
*/
private String desc;
ResCode(Integer code, String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
package com.xinxincaravan.caravan.vehicle.constant;
import com.google.common.collect.Maps;
import java.util.Map;
public enum VehicleBookRecordStatus {
APPLY(1,"申请中"),
APPROVE(2,"已通过"),
RETURNED(3,"已归还"),
REJECTED(4,"拒绝"),
RETURNED_OUT_DATE(5,"逾期归还"),
CANCEL_APPLY(6,"取消预订"),
LIFTED(7,"已提车"),
;
/**
* 编码
*/
private Integer code;
/**
* 类型描述
*/
private String desc;
private static Map<Integer,String> codeAndDesc = Maps.newHashMap();
static{
for(VehicleBookRecordStatus constantType : VehicleBookRecordStatus.values()){
codeAndDesc.put(constantType.getCode(),constantType.getDesc());
}
}
VehicleBookRecordStatus(Integer code, String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static Boolean exists(Integer code){
return codeAndDesc.containsKey(code);
}
}
package com.xinxincaravan.caravan.vehicle.constant;
import com.google.common.collect.Maps;
import java.util.Map;
public enum VehicleStatus {
NORMAL(1,"正常运行"),
REPAIRING(2,"维修"),
DISCARD(3,"报废"),
;
/**
* 编码
*/
private Integer code;
/**
* 类型描述
*/
private String desc;
private static Map<Integer,String> codeAndDesc = Maps.newHashMap();
static{
for(VehicleStatus constantType : VehicleStatus.values()){
codeAndDesc.put(constantType.getCode(),constantType.getDesc());
}
}
VehicleStatus(Integer code, String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static Boolean exists(Integer code){
return codeAndDesc.containsKey(code);
}
}
package com.xinxincaravan.caravan.vehicle.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Table(name = "branch_company")
@Data
public class BranchCompany {
@Id
@GeneratedValue(generator = "JDBC")
private Integer id;
/**
* 分公司名称
*/
private String name;
/**
* 分支机构类型
*/
@Column(name = "branch_type")
private Integer branchType;
/**
* 分支机构所属机构
*/
@Column(name = "subordinate_branch")
private Integer subordinateBranch;
/**
* 分支机构地址:经纬度
*/
private String location;
/**
* 地址-省/直辖市(编码)
*/
@Column(name = "addr_province")
private Integer addrProvince;
/**
* 地址-市(编码)
*/
@Column(name = "addr_city")
private Integer addrCity;
/**
* 地址-镇/县(编码)
*/
@Column(name = "addr_town")
private Integer addrTown;
/**
* 详细地址
*/
@Column(name = "addr_detail")
private String addrDetail;
private Date createTime;
private Date updateTime;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.entity;
import lombok.Data;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Data
public class Constant {
@Id
@GeneratedValue(generator = "JDBC")
private Integer id;
/**
* 常量类型
*/
private Integer type;
/**
* 常量编码
*/
private Integer code;
/**
* 值
*/
private String val;
}
package com.xinxincaravan.caravan.vehicle.entity;
import lombok.Data;
@Data
public class SysRegion {
private Long id;
/**
* 所属父地区id
*/
private Long parentId;
private String name;
/**
* 地区类型 0-国家 1-省/直辖市 2-市 3 - 镇、县
*/
private Integer type;
/**
* 从左往右,第1,2位代表省代码,3、4为代表市代码,5-6位代表镇或县代码
*/
private Integer agencyId;
}
package com.xinxincaravan.caravan.vehicle.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Data
public class Vehicle {
/**
* 主键(uuid)
*/
@Id
private String id;
/**
* 车辆编号,0-没有
*/
private Integer code;
/**
* 车辆状态: 1-正常运行 2-维修 3-报废
*/
private Integer status;
/**
* 车牌号,空字符串-没有
*/
@Column(name = "number_plate")
private String numberPlate;
/**
* 品牌(编码,对应关系见相关常量),0-未填写
*/
private Integer brand;
/**
* 所属分支机构(id)
*/
@Column(name = "subordinate_branch")
private Integer subordinateBranch;
/**
* 用途类型:租赁房车(1)、展车等,对应关系见车辆常量表
*/
@Column(name = "use_type")
private Integer useType;
/**
* 备注信息
*/
private String remark;
/**
* 车架号
*/
private String vin;
/**
* 里程数
*/
private Integer mileage;
/**
* 保险公司,见常量表
*/
private Integer insuranceCompany;
/**
* 保险单号
*/
private String insuranceNo;
/**
* 保险开始时间
*/
private Date insuranceStartDate;
/**
* 保险结束时间
*/
private Date insuranceEndDate;
/**
* 年审时间
*/
private Date annualVerificationDate;
/**
* 保养时间
*/
private Date maintenanceDate;
/**
* 保养里程数
*/
private Integer maintenanceMileage;
/**
* 是否违章
*/
private Integer haveViolation;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = "vehicle_book_info")
@Data
public class VehicleBookInfo {
@Id
private Long id;
/**
* 车辆id
*/
private String vehicle;
/**
* 预定信息所属年月(格式yyyy-MM)
*/
@Column(name = "year_month")
private String yearMonth;
/**
* 预定信息,int格式保存,当作位图使用(从左到右每位代表每个月1-31号)
*/
@Column(name = "booked_date")
private Integer bookedDate;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.entity;
import lombok.Data;
import java.util.Date;
import javax.persistence.*;
@Table(name = "vehicle_book_record")
@Data
public class VehicleBookRecord {
/**
* 主键
*/
@Id
private Long id;
/**
* 车辆id
*/
private String vehicle;
/**
* 申请状态:1-申请中 2-已通过 3-已归还 4-拒绝 5-逾期归还
*/
private Integer status;
/**
* 预定类型,1-用户租赁、2-分公司使用、3-维修
*/
@Column(name = "book_type")
private Integer bookType;
/**
* 预定用户id
*/
@Column(name = "book_user")
private Integer bookUser;
/**
* 预定用户姓名
*/
@Column(name = "book_user_name")
private String bookUserName;
/**
* 联系信息,比如电话、联系人姓名等(json)
*/
@Column(name = "contact_info")
private String contactInfo;
/**
* 申请开始日期
*/
@Column(name = "book_start_date")
private Date bookStartDate;
/**
* 提车地点(经纬度)
*/
@Column(name = "lift_location")
private String liftLocation;
/**
* 提车地址
*/
@Column(name = "lift_addr")
private String liftAddr;
private String remark;
/**
* 目的地
*/
private String destination;
/**
* 申请审核人,-1代表系统
*/
@Column(name = "reviewer_apply")
private Integer reviewerApply;
/**
* 申请审核人姓名
*/
@Column(name = "reviewer_name_apply")
private String reviewerNameApply;
/**
* 归还审核人,-1代表系统
*/
@Column(name = "reviewer_return")
private Integer reviewerReturn;
/**
* 归还审核人姓名
*/
@Column(name = "reviewer_name_return")
private String reviewerNameReturn;
/**
* 取消人,-1代表系统
*/
@Column(name = "reviewer_cancel")
private Integer reviewerCancel;
/**
* 取消人姓名
*/
@Column(name = "reviewer_name_cancel")
private String reviewerNameCancel;
/**
* 提车审核人,-1代表系统
*/
private Integer reviewerLift;
/**
* 提车审核人姓名
*/
private String reviewerNameLift;
/**
* 申请结束日期
*/
@Column(name = "book_end_date")
private Date bookEndDate;
/**
* 实际开始日期
*/
@Column(name = "actual_start_date")
private Date actualStartDate;
/**
* 实际结束日期
*/
@Column(name = "actual_end_date")
private Date actualEndDate;
/**
* 提车公司
*/
private Integer liftCompany;
/**
* 提车备注
*/
private String liftRemark;
/**
* 还车公司
*/
private Integer retCompany;
/**
* 还车备注
*/
private String retRemark;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.interceptor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.cors.CorsUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by ace on 2017/9/12.
*/
public class CorsInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (request.getHeader(HttpHeaders.ORIGIN) != null) {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Credentials", "true");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD");
response.addHeader("Access-Control-Allow-Headers", "Content-Type,authorization");
response.addHeader("Access-Control-Max-Age", "3600");
}
if(CorsUtils.isPreFlightRequest(request)){//是否跨域前option请求,使得话不执行后面拦截器
return Boolean.FALSE;
}
return super.preHandle(request, response, handler);
}
}
package com.xinxincaravan.caravan.vehicle.mapper;
import com.xinxincaravan.caravan.vehicle.entity.BranchCompany;
import tk.mybatis.mapper.common.Mapper;
public interface BranchCompanyMapper extends Mapper<BranchCompany> {
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.mapper;
import com.xinxincaravan.caravan.vehicle.entity.Constant;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
public interface ConstantMapper extends Mapper<Constant> {
public List<Integer> getAllConstantTypes();
public int updateByTypeAndCode(Constant constant);
public int delByTypeAndCode(Constant constant);
/**
* 插入重复时则忽略
* @param constant
* @return
*/
public int insertIgnoreOnDuplicate(Constant constant);
}
package com.xinxincaravan.caravan.vehicle.mapper;
import com.xinxincaravan.caravan.vehicle.entity.SysRegion;
import org.springframework.data.repository.query.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
import java.util.Map;
public interface SysRegionMapper extends Mapper<SysRegion> {
public List<SysRegion> getAllByPage(Map<String,Object> params);
public List<SysRegion> getByIdList(List<Long> idList);
}
package com.xinxincaravan.caravan.vehicle.mapper;
import com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
import java.util.Map;
public interface VehicleBookInfoMapper extends Mapper<VehicleBookInfo> {
/**
* 根据车辆id和对应年月查询预定记录
* @param params
* @return
*/
public List<VehicleBookInfo> getByVehicleIdAndYearMonth(Map<String,Object> params);
/**
* 根据车辆id和对应年月查询预定记录
* @param params
* @return
*/
public List<VehicleBookInfo> getByVehicleIdAndYearMonths(Map<String,Object> params);
/**
* 不存在插入、存在更新
* @param vehicleBookInfo
* @return
*/
public Integer insertIgnore(VehicleBookInfo vehicleBookInfo);
/**
* 更新预定信息,如果位操作正确的话(以此实现未预定才预定,已预定才可取消)
* @param params
* @return
*/
public Integer updateBookedInfo(Map<String,Object> params);
public void createTbIfNotExists(String tbName);
public List<VehicleBookInfo> getByPage4YearMonth(Map<String,Object> params);
public Integer insertHis(Map<String,Object> params);
public Integer del4YearMoth(Map<String,Object> params);
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.mapper;
import com.xinxincaravan.caravan.vehicle.entity.VehicleBookRecord;
import com.xinxincaravan.caravan.vehicle.vo.QueryVehicleBookRecordVo;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
import java.util.Map;
public interface VehicleBookRecordMapper extends Mapper<VehicleBookRecord> {
Integer changeRecordStatus(Map<String,Object> params);
public List<VehicleBookRecord> getByPage4Month(Map<String,Object> params);
public Integer insertHis(Map<String,Object> params);
public Integer del4YearMoth(Map<String,Object> params);
public void createTbIfNotExists(String tbName);
public List<QueryVehicleBookRecordVo> getByPage(Map<String,Object> params);
public Integer liftOrRet(Map<String,Object> params);
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.mapper;
import com.xinxincaravan.caravan.vehicle.entity.Vehicle;
import com.xinxincaravan.caravan.vehicle.vo.AddOrUpdateVehicleVo;
import com.xinxincaravan.caravan.vehicle.vo.QueryVehicleVo;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
import java.util.Map;
public interface VehicleMapper extends Mapper<Vehicle> {
public List<QueryVehicleVo> getByPage(Map<String,Object> params);
public int updateStatusById(Map<String,Object> params);
/**
* 锁定相关编码 或 车牌 的行
* @param addOrUpdateVehicleVo
* @return
*/
public List<Vehicle> lockByCode(AddOrUpdateVehicleVo addOrUpdateVehicleVo);
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.rest;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.xinxincaravan.caravan.vehicle.biz.BranchCompanyBiz;
import com.xinxincaravan.caravan.vehicle.common.BaseController;
import com.xinxincaravan.caravan.vehicle.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.entity.BranchCompany;
import com.xinxincaravan.caravan.vehicle.vo.BranchCompanyVo;
import com.xinxincaravan.caravan.vehicle.vo.PageDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/branchCompany")
@Slf4j
@IgnoreClientToken
public class BranchCompanyController extends BaseController<BranchCompanyBiz> {
@RequestMapping(value ="/page",method = RequestMethod.GET)
public RestResponse<PageDataVo<BranchCompany>> page(@RequestParam Integer page, @RequestParam Integer limit,
@RequestParam(required = false) Integer addrProvince, @RequestParam(required = false) Integer addrCity,
@RequestParam(required = false) Integer addrTown) {
return RestResponse.data(baseBiz.getAll(page,limit,addrProvince, addrCity,
addrTown));
}
@RequestMapping(value ="",method = RequestMethod.GET)
public RestResponse<List<BranchCompany>> getAll() {
return RestResponse.data(baseBiz.getAll());
}
@RequestMapping(value ="/{id}",method = RequestMethod.GET)
public RestResponse<BranchCompany> get(@PathVariable Integer id) {
return RestResponse.data(baseBiz.getById(id));
}
@RequestMapping(value ="",method = RequestMethod.POST)
public RestResponse<Integer> add(@RequestBody BranchCompanyVo branchCompanyVo) {
return RestResponse.data(baseBiz.add(branchCompanyVo));
}
@RequestMapping(value ="",method = RequestMethod.PUT)
public RestResponse update(@RequestBody BranchCompany branchCompany) {
baseBiz.update(branchCompany);
return RestResponse.sucResponse();
}
@RequestMapping(value ="/{id}",method = RequestMethod.DELETE)
public RestResponse del(@PathVariable Integer id) {
baseBiz.del(id);
return RestResponse.sucResponse();
}
}
package com.xinxincaravan.caravan.vehicle.rest;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.xinxincaravan.caravan.vehicle.biz.ConstantBiz;
import com.xinxincaravan.caravan.vehicle.common.BaseController;
import com.xinxincaravan.caravan.vehicle.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.constant.ConstantType;
import com.xinxincaravan.caravan.vehicle.constant.ResCode.ResCode;
import com.xinxincaravan.caravan.vehicle.entity.Constant;
import com.xinxincaravan.caravan.vehicle.vo.ConstantVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/constant")
@Slf4j
@IgnoreClientToken
public class ConstantController extends BaseController<ConstantBiz> {
@RequestMapping(value ="/type/{type}",method = RequestMethod.GET)
public RestResponse<List<ConstantVo>> getAllConstantByType(@PathVariable Integer type){
if(!checkIfTypeValid(type)){
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
}
return RestResponse.data(baseBiz.getAllConstantByType(type));
}
/**
* 检查类型是否合法
* @param type
* @return
*/
private Boolean checkIfTypeValid(Integer type){
Boolean exists = Boolean.FALSE;
for(ConstantType constantType: ConstantType.values()){
if(constantType.getCode().equals(type)){
exists = Boolean.TRUE;
}
}
return exists;
}
@RequestMapping(value ="/type/{type}",method = RequestMethod.POST)
public RestResponse<Integer> add(@PathVariable Integer type,@RequestBody List<Constant> constants){
if(!checkIfTypeValid(type)){
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
}
if(CollectionUtils.isEmpty(constants)){
return RestResponse.sucResponse();
}
for(Constant constant:constants){
//编码和值不能为空
if(constant.getCode()==null|| StringUtils.isBlank(constant.getVal())) {
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
}
}
return RestResponse.data(baseBiz.addConstants(type,constants));
}
@RequestMapping(value ="/type/{type}",method = RequestMethod.PUT)
public RestResponse<Integer> update(@PathVariable Integer type,@RequestBody List<Constant> constants){
if(!checkIfTypeValid(type)){
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
}
if(CollectionUtils.isEmpty(constants)){
return RestResponse.sucResponse();
}
for(Constant constant:constants){
//编码和值不能为空
if(constant.getCode()==null|| StringUtils.isBlank(constant.getVal())) {
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
}
}
return RestResponse.data(baseBiz.updateConstants(type,constants));
}
@RequestMapping(value ="/type/{type}",method = RequestMethod.DELETE)
public RestResponse<Integer> del(@PathVariable Integer type,@RequestBody List<Integer> codes){
if(!checkIfTypeValid(type)){
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
}
if(CollectionUtils.isEmpty(codes)){
return RestResponse.sucResponse();
}
for(Integer code:codes){
//编码和值不能为空
if(code==null) {
return RestResponse.codeAndMessage(ResCode.INVALID_REST_REQ_PARAM.getCode(),
ResCode.INVALID_REST_REQ_PARAM.getDesc());
}
}
return RestResponse.data(baseBiz.delConstant(type,codes));
}
}
package com.xinxincaravan.caravan.vehicle.rest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.nacos.client.logger.json.JSONArray;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.xinxincaravan.caravan.vehicle.biz.SysRegionBiz;
import com.xinxincaravan.caravan.vehicle.common.BaseController;
import com.xinxincaravan.caravan.vehicle.common.CustomIllegalParamException;
import com.xinxincaravan.caravan.vehicle.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.constant.ConstantType;
import com.xinxincaravan.caravan.vehicle.constant.ResCode.ResCode;
import com.xinxincaravan.caravan.vehicle.entity.Constant;
import com.xinxincaravan.caravan.vehicle.entity.SysRegion;
import com.xinxincaravan.caravan.vehicle.vo.ConstantVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/sysRegion")
@IgnoreClientToken
@Slf4j
public class SysRegionController extends BaseController<SysRegionBiz> {
@RequestMapping(value ="/sons/{id}",method = RequestMethod.GET)
public RestResponse<List<SysRegion>> getSonRegion(@PathVariable Long id){
return RestResponse.data(baseBiz.getSonRegion(id));
}
@RequestMapping(value ="",method = RequestMethod.GET)
public RestResponse<List<SysRegion>> getRegion(@RequestParam String idListJson){
try {
List<Long> ids = JSON.parseArray(idListJson,Long.class);
return RestResponse.data(baseBiz.getRegionsByCodes(ids));
} catch (JSONException ex) {
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
} catch (CustomIllegalParamException ex){
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
}
}
package com.xinxincaravan.caravan.vehicle.rest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo;
import com.github.wxiaoqi.security.auth.common.util.jwt.JWTHelper;
import com.github.wxiaoqi.security.common.context.BaseContextHandler;
import com.github.wxiaoqi.security.common.msg.auth.TokenForbiddenResponse;
import com.xinxincaravan.caravan.vehicle.biz.VehicleBiz;
import com.xinxincaravan.caravan.vehicle.biz.VehicleBookRecordBiz;
import com.xinxincaravan.caravan.vehicle.common.BaseController;
import com.xinxincaravan.caravan.vehicle.common.CustomIllegalParamException;
import com.xinxincaravan.caravan.vehicle.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.constant.ResCode.ResCode;
import com.xinxincaravan.caravan.vehicle.constant.VehicleBookRecordStatus;
import com.xinxincaravan.caravan.vehicle.entity.Vehicle;
import com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo;
import com.xinxincaravan.caravan.vehicle.entity.VehicleBookRecord;
import com.xinxincaravan.caravan.vehicle.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/vehicleInfo")
@Slf4j
@IgnoreClientToken
public class VehicleController extends BaseController<VehicleBiz> {
@Autowired
private VehicleBookRecordBiz vehicleBookRecordBiz;
@RequestMapping(value ="/{id}",method = RequestMethod.GET)
public RestResponse<Vehicle> get(@PathVariable String id) {
return RestResponse.data(baseBiz.get(id));
}
@RequestMapping(value ="",method = RequestMethod.POST)
public RestResponse add(@RequestBody List<AddOrUpdateVehicleVo> addOrUpdateVehicleVoList) throws Exception{
return baseBiz.add(addOrUpdateVehicleVoList);
}
@RequestMapping(value ="",method = RequestMethod.PUT)
public RestResponse update(@RequestBody List<AddOrUpdateVehicleVo> addOrUpdateVehicleVoList) throws Exception{
return baseBiz.update(addOrUpdateVehicleVoList);
}
@RequestMapping(value ="",method = RequestMethod.DELETE)
public RestResponse discard(@RequestBody List<String> idList) throws Exception{
return baseBiz.discard(idList);
}
@RequestMapping(value ="/page",method = RequestMethod.GET)
public RestResponse<PageDataVo<QueryVehicleVo>> getByPage(@RequestParam String vehiclePageQueryVoJson) throws Exception{
VehiclePageQueryVo vehiclePageQueryVo = null;
try {
vehiclePageQueryVo = JSON.parseObject(vehiclePageQueryVoJson,VehiclePageQueryVo.class);
return RestResponse.data(baseBiz.getByPage(vehiclePageQueryVo));
} catch (JSONException ex) {
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
} catch (CustomIllegalParamException ex){
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
}
@RequestMapping(value ="/bookedInfo/{vehicleId}/{yearMonth}",method = RequestMethod.GET)
public RestResponse<VehicleBookInfo> getBookedInfo(@PathVariable String vehicleId, @PathVariable String yearMonth) {
return RestResponse.data(baseBiz.getByVehicleIdAndYearMonth(vehicleId,yearMonth));
}
@RequestMapping(value ="/bookedInfo/{vehicleId}",method = RequestMethod.GET)
public RestResponse<List<VehicleBookInfo>> getBookedInfo(@PathVariable String vehicleId) {
return RestResponse.data(baseBiz.getByVehicleIdAndYearMonth(vehicleId));
}
/**
* 申请预定车辆
* @param bookVehicleVo
* @return
*/
@RequestMapping(value ="/book/4employee",method = RequestMethod.POST)
public RestResponse<Integer> applyVehicle(@RequestBody BookVehicleVo bookVehicleVo){
Integer operatorId = Integer.parseInt(BaseContextHandler.getUserID());
String userName = BaseContextHandler.getName();
return baseBiz.applyVehicle4Employee(operatorId,bookVehicleVo,userName);
}
/**
* 批准预定车辆预定
* @param bookRecordId
* @return
*/
@RequestMapping(value ="/book/4employee/prove/{bookRecordId}",method = RequestMethod.PUT)
public RestResponse<Integer> proveVehicleBooking(@PathVariable Long bookRecordId) throws Exception{
Integer operatorId = Integer.parseInt(BaseContextHandler.getUserID());
String userName = BaseContextHandler.getName();
return baseBiz.reviewVehicleBooking(operatorId, bookRecordId, VehicleBookRecordStatus.APPROVE.getCode(),userName);
}
/**
* 拒绝预定车辆申请
* @param bookRecordId
* @return
*/
@RequestMapping(value ="/book/4employee/reject/{bookRecordId}",method = RequestMethod.PUT)
public RestResponse<Integer> rejectVehicleBooking(@PathVariable Long bookRecordId) throws Exception{
Integer operatorId = Integer.parseInt(BaseContextHandler.getUserID());
String userName = BaseContextHandler.getName();
return baseBiz.reviewVehicleBooking(operatorId, bookRecordId, VehicleBookRecordStatus.REJECTED.getCode(),userName);
}
// /**
// * 车辆归还
// * @param bookRecordId
// * @return
// */
// @RequestMapping(value ="/book/4employee/return/{bookRecordId}",method = RequestMethod.PUT)
// public RestResponse<Integer> returnVehicle(@PathVariable String bookRecordId){
// //此处待加入获取当前操作用户id信息以及相关权限验证
// Integer operator = -1;//测试用
// return baseBiz.returnVehicle(operator, bookRecordId);
//
// }
/**
* 取消车辆预订
* @param bookRecordId
* @return
*/
@RequestMapping(value ="/unbook/4employee/{bookRecordId}",method = RequestMethod.DELETE)
public RestResponse<Integer> unbookVehicle(@PathVariable Long bookRecordId) throws Exception{
Integer operatorId = Integer.parseInt(BaseContextHandler.getUserID());
String userName = BaseContextHandler.getName();
return baseBiz.unbookVehicle4Employee(operatorId,bookRecordId,userName);
}
@RequestMapping(value ="/bookedRecord/{id}",method = RequestMethod.GET)
public RestResponse<VehicleBookRecord> getBookedRecord(@PathVariable Long id) throws Exception{
try {
return RestResponse.codeAndData(RestResponse.SUC_CODE,vehicleBookRecordBiz.getById(id));
} catch (JSONException ex) {
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
} catch (CustomIllegalParamException ex){
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
}
@RequestMapping(value ="/bookedRecord",method = RequestMethod.GET)
public RestResponse<PageDataVo<QueryVehicleBookRecordVo>> getBookedRecord(@RequestParam String vehicleBookRecordQueryVoJson) throws Exception{
VehicleBookRecordQueryVo vehicleBookRecordQueryVo = null;
try {
vehicleBookRecordQueryVo = JSON.parseObject(vehicleBookRecordQueryVoJson,VehicleBookRecordQueryVo.class);
return RestResponse.data(vehicleBookRecordBiz.page(vehicleBookRecordQueryVo));
} catch (JSONException ex) {
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
} catch (CustomIllegalParamException ex){
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
}
/**
* 提车
* @param liftVehicleVo
* @return
*/
@RequestMapping(value ="/book/4employee/lift",method = RequestMethod.PUT)
public RestResponse<Integer> liftVehicle(@RequestBody LiftVehicleVo liftVehicleVo) throws Exception{
Integer operatorId = Integer.parseInt(BaseContextHandler.getUserID());
String userName = BaseContextHandler.getName();
return vehicleBookRecordBiz.lift(operatorId,userName,liftVehicleVo);
}
/**
* 还车
* @param retVehicleVo
* @return
*/
@RequestMapping(value ="/book/4employee/ret",method = RequestMethod.PUT)
public RestResponse<Integer> retVehicle(@RequestBody RetVehicleVo retVehicleVo) throws Exception{
Integer operatorId = Integer.parseInt(BaseContextHandler.getUserID());
String userName = BaseContextHandler.getName();
return vehicleBookRecordBiz.retVehicle(operatorId,userName,retVehicleVo);
}
}
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Data
public class AddOrUpdateVehicleVo {
/**
* 主键(uuid)
*/
private String id;
/**
* 车辆状态: 1-正常运行 2-维修 3-报废
*/
private Integer status;
/**
* 车辆编号,0-没有
*/
private Integer code;
/**
* 车牌号,空字符串-没有
*/
@Column(name = "number_plate")
private String numberPlate;
/**
* 品牌(编码,对应关系见相关常量),0-未填写
*/
private Integer brand;
/**
* 所属分支机构(id)
*/
@Column(name = "subordinate_branch")
private Integer subordinateBranch;
/**
* 用途类型:租赁房车(1)、展车等,对应关系见车辆常量表
*/
@Column(name = "use_type")
private Integer useType;
/**
* 备注信息
*/
private String remark;
/**
* 车架号
*/
private String vin;
/**
* 里程数
*/
private Integer mileage;
/**
* 保险公司,见常量表
*/
private Integer insuranceCompany;
/**
* 保险单号
*/
private String insuranceNo;
/**
* 保险开始时间
*/
private Date insuranceStartDate;
/**
* 保险结束时间
*/
private Date insuranceEndDate;
/**
* 年审时间
*/
private Date annualVerificationDate;
/**
* 保养时间
*/
private Date maintenanceDate;
/**
* 保养里程数
*/
private Integer maintenanceMileage;
/**
* 是否违章
*/
private Integer haveViolation;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.List;
@Data
public class BookVehicleVo {
/**
* 车辆id
*/
private String vehicle;
/**
* 预定目标日期(开始)
*/
private String bookStartDate;
/**
* 预定目标日期(结束)
*/
private String bookEndDate;
/**
* 取消预定目标日期(开始)
*/
private String unbookStartDate;
/**
* 取消预定目标日期(结束)
*/
private String unbookEndDate;
/**
* 提车地点
*/
private String liftAddr;
/**
* 提车地点
*/
private Integer liftCompany;
/**
* 目的地
*/
private String destination;
/**
* 备注
*/
private String remark;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Data
public class BranchCompanyVo {
/**
* 分公司名称
*/
private String name;
/**
* 分支机构类型
*/
private Integer branchType;
/**
* 分支机构所属机构
*/
private Integer subordinateBranch;
/**
* 分支机构地址:经纬度
*/
private String location;
/**
* 地址-省/直辖市(编码)
*/
private Integer addrProvince;
/**
* 地址-市(编码)
*/
private Integer addrCity;
/**
* 地址-镇/县(编码)
*/
private Integer addrTown;
/**
* 详细地址
*/
private String addrDetail;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
@Data
public class ConstantVo {
/**
* 常量类型
*/
private Integer type;
/**
* 常量编码
*/
private Integer code;
/**
* 值
*/
private String val;
}
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
@Data
public class LiftVehicleVo {
/**
* 预定记录id
*/
private Long id;
/**
* 提车公司
*/
private Integer liftCompany;
/**
* 备注
*/
private String liftRemark;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.vo;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import java.util.List;
@Data
public class PageDataVo<T> {
/**
* 符合条件记录总数
*/
private Long totalCount;
/**
* 实际数据
*/
private List<T> data;
public static <M> PageDataVo<M> pageInfo(PageInfo<M> pageInfo){
PageDataVo<M> pageDataVo = new PageDataVo<>();
pageDataVo.setTotalCount(pageInfo.getTotal());
pageDataVo.setData(pageInfo.getList());
return pageDataVo;
}
}
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Data
public class QueryVehicleBookRecordVo {
/**
* 主键
*/
private Long id;
/**
* 车辆id
*/
private String vehicle;
/**
* 申请状态:1-申请中 2-已通过 3-已归还 4-拒绝 5-逾期归还
*/
private Integer status;
/**
* 预定类型,1-用户租赁、2-分公司使用、3-维修
*/
private Integer bookType;
/**
* 预定用户id
*/
private Integer bookUser;
/**
* 预定用户名称
*/
private String bookUserName;
/**
* 联系信息,比如电话、联系人姓名等(json)
*/
private String contactInfo;
/**
* 申请开始日期
*/
private Date bookStartDate;
/**
* 提车地点(经纬度)
*/
private String liftLocation;
/**
* 提车地址
*/
private String liftAddr;
private String remark;
/**
* 目的地
*/
private String destination;
/**
* 申请审核人,-1代表系统
*/
private Integer reviewerApply;
/**
* 归还审核人,-1代表系统
*/
private Integer reviewerReturn;
/**
* 取消人,-1代表系统
*/
private Integer reviewerCancel;
/**
* 申请审核人姓名
*/
private String reviewerNameApply;
/**
* 归还审核人姓名
*/
private String reviewerNameReturn;
/**
* 取消人姓名
*/
private String reviewerNameCancel;
/**
* 申请结束日期
*/
private Date bookEndDate;
/**
* 实际开始日期
*/
private Date actualStartDate;
/**
* 实际结束日期
*/
private Date actualEndDate;
/**
* 车辆编号,0-没有
*/
private Integer vehicleCode;
/**
* 车牌号,空字符串-没有
*/
private String numberPlate;
/**
* 所属分支机构(id)
*/
private Integer subordinateBranch;
/**
* 所属分支机构(名称)
*/
private String subBranchName;
/**
* 当前月份预定记录
*/
private Integer bookedDate;
/**
* 提车公司
*/
private Integer liftCompany;
/**
* 提车公司名称
*/
private String liftCompanyName;
/**
* 提车备注
*/
private String liftRemark;
/**
* 还车公司
*/
private Integer retCompany;
/**
* 还车公司名称
*/
private String retCompanyName;
/**
* 还车备注
*/
private String retRemark;
/**
* 提车审核人,-1代表系统
*/
private Integer reviewerLift;
/**
* 提车审核人姓名
*/
private String reviewerNameLift;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Data
public class QueryVehicleVo {
/**
* 主键(uuid)
*/
private String id;
/**
* 车辆编号,0-没有
*/
private Integer code;
/**
* 车辆状态: 1-正常运行 2-维修 3-报废
*/
private Integer status;
/**
* 车牌号,空字符串-没有
*/
private String numberPlate;
/**
* 品牌(编码,对应关系见相关常量),0-未填写
*/
private Integer brand;
/**
* 所属分支机构(id)
*/
private Integer subordinateBranch;
/**
* 所属分支机构(名称)
*/
private String subBranchName;
/**
* 用途类型:租赁房车(1)、展车等,对应关系见车辆常量表
*/
private Integer useType;
/**
* 备注信息
*/
private String remark;
private Date createTime;
private Date updateTime;
/**
* 车架号
*/
private String vin;
/**
* 里程数
*/
private Integer mileage;
/**
* 保险公司,见常量表
*/
private Integer insuranceCompany;
/**
* 保险单号
*/
private String insuranceNo;
/**
* 保险开始时间
*/
private Date insuranceStartDate;
/**
* 保险结束时间
*/
private Date insuranceEndDate;
/**
* 年审时间
*/
private Date annualVerificationDate;
/**
* 保养时间
*/
private Date maintenanceDate;
/**
* 保养里程数
*/
private Integer maintenanceMileage;
/**
* 是否违章
*/
private Integer haveViolation;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
@Data
public class RetVehicleVo {
/**
* 预定记录id
*/
private Long id;
/**
* 提车公司
*/
private Integer retCompany;
/**
* 备注
*/
private String retRemark;
}
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
import java.util.Date;
@Data
public class VehicleBookRecordQueryVo {
/**
* 车辆编号,0-没有
*/
private Integer vehicleCode;
/**
* 车牌号,空字符串-没有
*/
private String numberPlate;
/**
* 所属分支机构(id)
*/
private Integer subordinateBranch;
/**
* 查询月份 yyyy-MM
*/
private String selectedMonth;
/**
* 申请状态
*/
private Integer status;
/**
* 提车公司
*/
private Integer liftCompany;
/**
* 还车公司
*/
private Integer retCompany;
private Integer page;
private Integer limit;
}
\ No newline at end of file
server:
port: 8091
tomcat:
uri-encoding: UTF-8
logging:
level:
com.xinxincaravan.caravan.vehicle.mapper: debug
spring:
application:
name: vehicle
datasource:
name: test
url: jdbc:mysql://${MYSQL_HOST:10.5.52.2}:${MYSQL_PORT:3306}/vehicle?useUnicode=true&characterEncoding=UTF8
username: root
password: xx2019fc
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
cloud:
nacos:
discovery:
server-addr: 10.5.52.2:8848
sentinel:
transport:
dashboard: 10.5.52.2:8080
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
default-property-inclusion: non_null
#--------------------以下为redis相关配置----------------------
redis:
database: 2
host: ${REDIS_HOST:10.5.52.2}
port: ${REDIS_PORT:6379}
password: xx2019fc
jedis:
pool:
max-active: 20
#--------------------以下为mybatis相关配置----------------------
mybatis:
type-aliases-package: com.xinxincaravan.caravan.vehicle.entity
mapper-locations: classpath*:mapper/*.xml
basepackage: com.xinxincaravan.caravan.vehicle.mapper
xmlLocation: classpath*:mapper/*.xml
configuration:
map-underscore-to-camel-case: true
spring:
application:
name: vehicle
cloud:
nacos:
config:
server-addr: 10.5.52.3:8848
file-extension: yaml
profiles:
active: dev
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!--<properties resource="dev.properties"/>-->
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<property name="mergeable" value="false"></property>
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
</plugin>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://10.5.52.2:3306/vehicle?useUnicode=true&amp;characterEncoding=UTF8"
userId="root"
password="xx2019fc">
</jdbcConnection>
<javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}"/>
<sqlMapGenerator targetPackage="${targetXMLPackage}" targetProject="${targetResourcesProject}"/>
<javaClientGenerator targetPackage="${targetMapperPackage}" targetProject="${targetJavaProject}"
type="XMLMAPPER"/>
<table tableName="vehicle" domainObjectName="Vehicle">
</table>
<table tableName="vehicle_book_info" domainObjectName="VehicleBookInfo">
</table>
<table tableName="vehicle_book_record" domainObjectName="VehicleBookRecord">
</table>
<table tableName="branch_company" domainObjectName="BranchCompany">
</table>
</context>
</generatorConfiguration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xinxincaravan.caravan.vehicle.mapper.BranchCompanyMapper" >
<resultMap id="BaseResultMap" type="com.xinxincaravan.caravan.vehicle.entity.BranchCompany" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="branch_type" property="branchType" jdbcType="INTEGER" />
<result column="subordinate_branch" property="subordinateBranch" jdbcType="INTEGER" />
<result column="location" property="location" jdbcType="VARCHAR" />
<result column="addr_province" property="addrProvince" jdbcType="INTEGER" />
<result column="addr_city" property="addrCity" jdbcType="INTEGER" />
<result column="addr_town" property="addrTown" jdbcType="INTEGER" />
<result column="addr_detail" property="addrDetail" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
</mapper>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment