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.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.constant.BookType;
import com.xinxincaravan.caravan.vehicle.constant.ConstantType;
import com.xinxincaravan.caravan.vehicle.constant.ResCode.ResCode;
import com.xinxincaravan.caravan.vehicle.constant.VehicleBookRecordStatus;
import com.xinxincaravan.caravan.vehicle.constant.VehicleStatus;
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.mapper.VehicleBookInfoMapper;
import com.xinxincaravan.caravan.vehicle.mapper.VehicleBookRecordMapper;
import com.xinxincaravan.caravan.vehicle.mapper.VehicleMapper;
import com.xinxincaravan.caravan.vehicle.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.*;
@Service
@Slf4j
public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> {
public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
public static final DateTimeFormatter YEARMONTH_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM");
/**
* 允许查询预定信息的最大月份数
*/
public static final Integer MAX_MONTH_COUNT_BOOKED_INFO_QUERY = 3;
@Autowired
private VehicleBookInfoMapper vehicleBookInfoMapper;
@Autowired
private VehicleBookRecordMapper vehicleBookRecordMapper;
@Autowired
private ConstantBiz constantBiz;
@Autowired
private BranchCompanyBiz branchCompanyBiz;
/**
* 每批次最大更、插入车辆最大条目数
*/
public static final Integer MAX_BATCH_SIZE_VEHICLE = 1;//使用了悲观锁,不开放批量更新
public Vehicle get(String id){
return mapper.selectByPrimaryKey(id);
}
/**
* 获取相关预订记录
* @param vehicle
* @param yearMonth
* @return
*/
public VehicleBookInfo getByVehicleIdAndYearMonth(String vehicle,String yearMonth){
Map<String,Object> params = Maps.newHashMap();
params.put("vehicle",vehicle);
params.put("yearMonth",yearMonth);
List<VehicleBookInfo> vehicleBookInfoList = vehicleBookInfoMapper.getByVehicleIdAndYearMonth(params);
return CollectionUtils.isEmpty(vehicleBookInfoList)?null:vehicleBookInfoList.get(0);
}
/**
* 获取相关预订记录
* @param vehicle
* @return
*/
public List<VehicleBookInfo> getByVehicleIdAndYearMonth(String vehicle){
Map<String,Object> params = Maps.newHashMap();
params.put("vehicle",vehicle);
params.put("yearMonths",
Lists.newArrayList(
DateTime.now().toString(YEARMONTH_DATE_TIME_FORMATTER),
DateTime.now().plusMonths(1).toString(YEARMONTH_DATE_TIME_FORMATTER),
DateTime.now().plusMonths(2).toString(YEARMONTH_DATE_TIME_FORMATTER)
)
);
List<VehicleBookInfo> vehicleBookInfoList = vehicleBookInfoMapper.getByVehicleIdAndYearMonths(params);
return vehicleBookInfoList;
}
/**
* 检查常量是否合法
*/
private void checkIfConstantValid(AddOrUpdateVehicleVo addOrUpdateVehicleVo){
//检查常量是否合法
if (addOrUpdateVehicleVo.getUseType() != null && addOrUpdateVehicleVo.getUseType() > 0) {
constantBiz.checkIfExists(ConstantType.VEHICLE_USE.getCode(), addOrUpdateVehicleVo.getUseType());
}
if (addOrUpdateVehicleVo.getBrand() != null && addOrUpdateVehicleVo.getBrand() > 0) {
constantBiz.checkIfExists(ConstantType.VEHICLE_BRAND.getCode(), addOrUpdateVehicleVo.getBrand());
}
}
/**
* 增加车辆
* @param addOrUpdateVehicleVoList
*/
@Transactional
public RestResponse add(List<AddOrUpdateVehicleVo> addOrUpdateVehicleVoList) throws Exception{
if(addOrUpdateVehicleVoList.size()>MAX_BATCH_SIZE_VEHICLE){
throw new CustomIllegalParamException("exceed max batch size");
}
for(AddOrUpdateVehicleVo addOrUpdateVehicleVo:addOrUpdateVehicleVoList) {
Vehicle vehicle = new Vehicle();
BeanUtils.copyProperties(vehicle, addOrUpdateVehicleVo);
vehicle.setId(UUID.randomUUID().toString());
// 检查车牌或者编码是否已存在,已存在则返回失败
List<Vehicle> exitsVehicles = lockByCode(addOrUpdateVehicleVo);
if(CollectionUtils.isNotEmpty(exitsVehicles)){
if(addOrUpdateVehicleVo.getCode()!= null &&
addOrUpdateVehicleVo.getCode().equals(exitsVehicles.get(0).getCode())){
return RestResponse.code(ResCode.VEHICLE_INFO_CODE_EXIST.getCode());
}else{
return RestResponse.code(ResCode.VEHICLE_INFO_SAME_NUM_PLATE_EXISTS.getCode());
}
}
mapper.insertSelective(vehicle);
}
return RestResponse.suc();
}
/**
* 此方法必须置于事务中以使锁生效
* 符合查询条件记录的修改活且相关记录的锁获取操作将被锁定
* @param addOrUpdateVehicleVo
* @return 锁定成功返回
*/
private List<Vehicle> lockByCode(AddOrUpdateVehicleVo addOrUpdateVehicleVo){
if(addOrUpdateVehicleVo.getCode() == null){
return null;
}
List<Vehicle> vehicles = mapper.lockByCode(addOrUpdateVehicleVo);
return vehicles;
}
/**
* 修改汽车信息
* @param addOrUpdateVehicleVoList
* @return
*/
@Transactional
public RestResponse update(List<AddOrUpdateVehicleVo> addOrUpdateVehicleVoList) throws Exception{
if(addOrUpdateVehicleVoList.size()>MAX_BATCH_SIZE_VEHICLE){
throw new CustomIllegalParamException("exceed max batch size");
}
for(AddOrUpdateVehicleVo addOrUpdateVehicleVo:addOrUpdateVehicleVoList){
Vehicle vehicle = new Vehicle();
BeanUtils.copyProperties(vehicle, addOrUpdateVehicleVo);
//悲观锁,检查是否已存在车牌或编码
List<Vehicle> exitsVehicles = lockByCode(addOrUpdateVehicleVo);
if(CollectionUtils.isNotEmpty(exitsVehicles)){
for(Vehicle exitsVehicle:exitsVehicles){
if(exitsVehicle.getId().equals(addOrUpdateVehicleVo.getId())){
continue;
}
if(addOrUpdateVehicleVo.getCode()!= null &&
addOrUpdateVehicleVo.getCode().equals(exitsVehicles.get(0).getCode())){
return RestResponse.code(ResCode.VEHICLE_INFO_CODE_EXIST.getCode());
}else{
return RestResponse.code(ResCode.VEHICLE_INFO_SAME_NUM_PLATE_EXISTS.getCode());
}
}
}
mapper.updateByPrimaryKeySelective(vehicle);
}
return RestResponse.suc();
}
/**
* 废弃车辆(状态设置为废弃)
* @param idList
* @return
*/
public RestResponse discard(List<String> idList){
if(idList.size()>MAX_BATCH_SIZE_VEHICLE){
throw new CustomIllegalParamException("exceed max batch size");
}
Map<String,Object> params = Maps.newHashMap();
params.put("idList",idList);
params.put("status", VehicleStatus.DISCARD.getCode());
mapper.updateStatusById(params);
return RestResponse.suc();
}
/**
* 申请汽车预定(内部)
* 检查是否可预定,修改相关预定记录状态
* @param userId
* @param bookVehicleVo
* @return
*/
public RestResponse applyVehicle4Employee(Integer userId,BookVehicleVo bookVehicleVo,String userName){
//检查车辆信息是否合法
checkIfVehicleExists(bookVehicleVo.getVehicle());
//提取日期和相应的预定目标日期
Map<String,List<String>> yearMonthAndDate = Maps.newHashMap();
DateTime startDay =DateTime.parse(bookVehicleVo.getBookStartDate(), DEFAULT_DATE_TIME_FORMATTER);
DateTime endDay =DateTime.parse(bookVehicleVo.getBookEndDate(), DEFAULT_DATE_TIME_FORMATTER);
//转换日期范围为列表,并检查是否合法
fillDateList4DatePeriod(yearMonthAndDate,startDay,endDay);
if(yearMonthAndDate.size()>3){//连续的日期最多夸3个月
throw new CustomIllegalParamException(" you can only within 2 month");
}
for(Map.Entry<String,List<String>> entry:yearMonthAndDate.entrySet()){
Boolean rsEach = applyVehicle4EmployeePerMonth(bookVehicleVo.getVehicle(),entry.getValue(),entry.getKey());
if(Boolean.FALSE.equals(rsEach)){
return RestResponse.code(ResCode.VEHICLE_BOOKED_INFO_ALREADY_CHANGED.getCode());
}
}
//加入预定申请记录
VehicleBookRecord vehicleBookRecord = new VehicleBookRecord();
vehicleBookRecord.setVehicle(bookVehicleVo.getVehicle());
vehicleBookRecord.setBookType(BookType.EMPLOYEE_APPLY.getCode());
vehicleBookRecord.setStatus(VehicleBookRecordStatus.APPLY.getCode());
vehicleBookRecord.setBookUser(userId);
vehicleBookRecord.setBookUserName(userName);
vehicleBookRecord.setBookStartDate(DateTime.
parse(bookVehicleVo.getBookStartDate(),DEFAULT_DATE_TIME_FORMATTER).toDate());
vehicleBookRecord.setBookEndDate(DateTime.
parse(bookVehicleVo.getBookEndDate(),DEFAULT_DATE_TIME_FORMATTER).toDate());
vehicleBookRecord.setLiftAddr(bookVehicleVo.getLiftAddr());
vehicleBookRecord.setRemark(bookVehicleVo.getRemark());
vehicleBookRecord.setDestination(bookVehicleVo.getDestination());
vehicleBookRecord.setLiftCompany(bookVehicleVo.getLiftCompany());
vehicleBookRecordMapper.insertSelective(vehicleBookRecord);
return RestResponse.suc();
}
@Transactional
public Boolean applyVehicle4EmployeePerMonth(String vehicleId, List<String> bookedDates, String yearMonth){
//检查车辆是否有空档
//获得当月预定记录
VehicleBookInfo vehicleBookInfo = getByVehicleIdAndYearMonth(vehicleId,yearMonth);
//位操作确定目标日期是否可预订
Map<String,Object> params = Maps.newHashMap();
Map<String,List<String>> yearMonthAndDate = new HashMap<>();
yearMonthAndDate.put(yearMonth,bookedDates);
fillBookedDateSearchParam(params,null,yearMonthAndDate);//转换为查询对应日期未预定的条件
Map<String,Map<String,Integer>> yearMonthAndParam = (Map<String,Map<String,Integer>>)params.get("yearMonthAndParam");
Map<String,Integer> andOpratorParam = yearMonthAndParam.get(yearMonth);
Integer andOperationFactor = andOpratorParam.get("andOperationFactor");
Integer andOperationRs = andOpratorParam.get("andOperationRs");
if(vehicleBookInfo!=null&&vehicleBookInfo.getBookedDate()!=null &&
((vehicleBookInfo.getBookedDate() & andOperationFactor) != andOperationRs)){
return Boolean.FALSE;
}
return Boolean.TRUE;
}
/**
* 批准预定车辆预定
* @param operatorId
* @param bookRecordId
* @return
*/
@Transactional
public RestResponse<Integer> reviewVehicleBooking(Integer operatorId, Long bookRecordId,Integer rsStatus,String userName) throws Exception{
//获取相关申请记录
VehicleBookRecord vehicleBookRecord = vehicleBookRecordMapper.selectByPrimaryKey(bookRecordId);
//申请记录验证
if(vehicleBookRecord == null){
throw new CustomIllegalParamException(" invalid book record");
}
if(!VehicleBookRecordStatus.APPLY.getCode().equals(vehicleBookRecord.getStatus())){
return RestResponse.code(ResCode.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED.getCode());
}
//转换为相应预定参数
BookVehicleVo bookVehicleVo = new BookVehicleVo();
BeanUtils.copyProperties(bookVehicleVo,vehicleBookRecord);
bookVehicleVo.setBookStartDate(new DateTime(vehicleBookRecord.getBookStartDate()).toString(DEFAULT_DATE_TIME_FORMATTER));
bookVehicleVo.setBookEndDate(new DateTime(vehicleBookRecord.getBookEndDate()).toString(DEFAULT_DATE_TIME_FORMATTER));
//审核通过的话,需要修改相关车辆预定记录
if(VehicleBookRecordStatus.APPROVE.getCode().equals(rsStatus)) {
Boolean hasSuc = bookedVehicle(bookVehicleVo);
if(!hasSuc){
return RestResponse.code(ResCode.VEHICLE_BOOKED_INFO_ALREADY_CHANGED.getCode());
}
}
//成功后修改预定记录状态
Map<String,Object> updateParam = Maps.newHashMap();
updateParam.put("id",bookRecordId);
updateParam.put("status",rsStatus);
updateParam.put("reviewerApply",operatorId);
updateParam.put("reviewerNameApply",userName);
updateParam.put("statusCondition",VehicleBookRecordStatus.APPLY.getCode());
Integer effected = vehicleBookRecordMapper.changeRecordStatus(updateParam);
if(effected == 0){//修改失败,手动回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动回滚
return RestResponse.code(ResCode.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED.getCode());
}
return RestResponse.suc();
}
/**
* 取消预定
* @return
*/
@Transactional
public RestResponse unbookVehicle4Employee(Integer operatorId,Long bookRecordId,String userName) throws Exception{
//获取相关申请记录
VehicleBookRecord vehicleBookRecord = vehicleBookRecordMapper.selectByPrimaryKey(bookRecordId);
//申请记录验证
if(vehicleBookRecord == null){
throw new CustomIllegalParamException(" invalid book record");
}
if(!VehicleBookRecordStatus.APPROVE.getCode().equals(vehicleBookRecord.getStatus())){
return RestResponse.code(ResCode.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED.getCode());
}
//转换为相应取消预定参数
BookVehicleVo bookVehicleVo = new BookVehicleVo();
BeanUtils.copyProperties(bookVehicleVo,vehicleBookRecord);
bookVehicleVo.setBookStartDate(null);
bookVehicleVo.setBookEndDate(null);
bookVehicleVo.setUnbookStartDate(new DateTime(vehicleBookRecord.getBookStartDate()).toString(DEFAULT_DATE_TIME_FORMATTER));
bookVehicleVo.setUnbookEndDate(new DateTime(vehicleBookRecord.getBookEndDate()).toString(DEFAULT_DATE_TIME_FORMATTER));
//取消预定
Boolean hasSuc = unbookVehicle(bookVehicleVo);
if(!hasSuc){
throw new IllegalArgumentException(" invalid book record ");
}
//修改预定状态,写入取消人
Map<String,Object> updateParam = Maps.newHashMap();
updateParam.put("id",bookRecordId);
updateParam.put("status",VehicleBookRecordStatus.CANCEL_APPLY.getCode());
updateParam.put("reviewerCancel",operatorId);
updateParam.put("reviewerNameCancel",userName);
updateParam.put("statusCondition",VehicleBookRecordStatus.APPROVE.getCode());
Integer effected = vehicleBookRecordMapper.changeRecordStatus(updateParam);
if(effected == 0){//修改失败,手动回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动回滚
return RestResponse.code(ResCode.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED.getCode());
}
return RestResponse.suc();
}
/**
* 车辆归还
* @param operatorId
* @param bookRecordId
* @return
*/
@Deprecated //相关是否存在提车流程?暂废弃
public RestResponse<Integer> returnVehicle(Integer operatorId, String bookRecordId){
//获取相关申请记录
VehicleBookRecord vehicleBookRecord = vehicleBookRecordMapper.selectByPrimaryKey(bookRecordId);
//申请记录验证
if(vehicleBookRecord == null){
throw new CustomIllegalParamException(" invalid book record");
}
if(!VehicleBookRecordStatus.APPROVE.getCode().equals(vehicleBookRecord.getStatus())){
return RestResponse.code(ResCode.VEHICLE_BOOKED_RECORD_ALREADY_CHANGED.getCode());
}
//对比预定日期,逾期状态即为逾期归还
DateTime startDate = new DateTime(vehicleBookRecord.getBookStartDate());
DateTime endDate = new DateTime(vehicleBookRecord.getBookEndDate());
Integer status = VehicleBookRecordStatus.RETURNED.getCode();
if(DateTime.now().toString(DEFAULT_DATE_TIME_FORMATTER).
compareTo(endDate.toString(DEFAULT_DATE_TIME_FORMATTER))>0){
status = VehicleBookRecordStatus.RETURNED_OUT_DATE.getCode();
}
//若提早归还则需要修改相关预定记录
//修改状态为已归还,写入实际归还日期
return null;
}
/**
* 获取预定车辆相关与操作参数
* @return
*/
private Integer getBitOpratorFactor4Booked(List<String> dates){
Integer andOperationFactor = 0;
for (String dateStr:dates) {//已预定作为条件,该位与1作与运算必定为1
DateTime dateTime = DateTime.parse(dateStr, DEFAULT_DATE_TIME_FORMATTER);
//仅对应位为1的整形值
andOperationFactor |= 1<<(dateTime.dayOfMonth().get()-1);
}
return andOperationFactor;
}
/**
* 获取预定车辆相关与操作参数
* @return
*/
private Integer getBitOpratorFactor4UnBooked(List<String> dates){
Integer andOperationFactor = Integer.MAX_VALUE;
for (String dateStr:dates) {//已预定作为条件,该位与1作与运算必定为1
DateTime dateTime = DateTime.parse(dateStr, DEFAULT_DATE_TIME_FORMATTER);
//仅对应位为1的整形值
andOperationFactor ^= 1<<(dateTime.dayOfMonth().get()-1);
}
return andOperationFactor;
}
/**
* 根据预定日期逐条修改预定记录
* @param bookVehicleVo
* @return
*/
@Transactional
public Boolean bookedVehicle( BookVehicleVo bookVehicleVo) throws Exception{
//提取日期和相应的预定目标日期
Map<String,List<String>> yearMonthAndDate = Maps.newHashMap();
DateTime startDay =DateTime.parse(bookVehicleVo.getBookStartDate(), DEFAULT_DATE_TIME_FORMATTER);
DateTime endDay =DateTime.parse(bookVehicleVo.getBookEndDate(), DEFAULT_DATE_TIME_FORMATTER);
//转换日期范围为列表,并检查是否合法
fillDateList4DatePeriod(yearMonthAndDate,startDay,endDay);
if(yearMonthAndDate.size()>3){//连续的日期最多夸3个月
throw new CustomIllegalParamException(" you can only within 2 month");
}
Boolean rs = Boolean.TRUE;
for(Map.Entry<String,List<String>> entry:yearMonthAndDate.entrySet()){
Boolean rsEach = bookedVehiclePerMonth(bookVehicleVo.getVehicle(),entry.getValue(),entry.getKey());
if(Boolean.FALSE.equals(rsEach)){
rs = Boolean.FALSE;
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动回滚
}
}
return rs;
}
/**
* 不存在插入、存在更新,利用唯一索引确保相同车辆以及年月序列化提交事务
* @param vehicleId
* @param bookedDates
* @param yearMonth
* @return 是否更新或插入成功
*/
@Transactional
public Boolean bookedVehiclePerMonth(String vehicleId, List<String> bookedDates, String yearMonth) throws Exception{
VehicleBookInfo vehicleBookInfo = new VehicleBookInfo();
vehicleBookInfo.setVehicle(vehicleId);
vehicleBookInfo.setYearMonth(yearMonth);
//检查是否存在相关车辆
Vehicle param = new Vehicle();
param.setId(vehicleId);
checkIfVehicleExists(vehicleId);
Integer orRsOperationFactor = getBitOpratorFactor4Booked(bookedDates);//预定的相关或运算因子,当前月份没有预定记录时同时也是结果
vehicleBookInfo.setBookedDate(orRsOperationFactor);
Integer effected = vehicleBookInfoMapper.insertIgnore(vehicleBookInfo);
if(effected == 0){//已存在则需要更新
Map<String,Object> params = Maps.newHashMap();
params.put("vehicle",vehicleBookInfo.getVehicle());
params.put("yearMonth",yearMonth);
//加入更新条件
if(CollectionUtils.isEmpty(bookedDates)){
throw new CustomIllegalParamException(" there are no day to book");
}
Map<String,List<String>> yearMonthAndDate = new HashMap<>();
yearMonthAndDate.put(vehicleBookInfo.getYearMonth(),bookedDates);
//转换为查询对应日期未预定的条件
fillBookedDateSearchParam(params,null,yearMonthAndDate);
//提取相关参数组装更细条件
Map<String,Map<String,Integer>> yearMonthAndParam = (Map<String,Map<String,Integer>>)params.get("yearMonthAndParam");
Map<String,Integer> andOpratorParam = yearMonthAndParam.get(vehicleBookInfo.getYearMonth());
params.putAll(andOpratorParam);
params.put("orRsOperationFactor",
orRsOperationFactor);
effected = vehicleBookInfoMapper.updateBookedInfo(params);
}
return effected>0?Boolean.TRUE:Boolean.FALSE;
}
/**
* 检查车辆是否存在
* @param id
*/
public void checkIfVehicleExists(String id){
Vehicle param = new Vehicle();
param.setId(id);
Integer count = mapper.selectCount(param);
if(count<=0){
throw new CustomIllegalParamException(" no such vehicle");
}
}
/**
* 把日期范围转换为列表,并检查操作范围是否合法
* @param yearMonthAndDate
* @param startDay
* @param endDay
*/
private void fillDateList4DatePeriod(Map<String,List<String>> yearMonthAndDate,DateTime startDay,DateTime endDay){
for( DateTime curDate = startDay;curDate.compareTo(endDay)<=0;curDate=curDate.plusDays(1)){
String curDateStr = curDate.toString(DEFAULT_DATE_TIME_FORMATTER);
if(curDateStr.compareTo(DateTime.now().toString(DEFAULT_DATE_TIME_FORMATTER))<0){
throw new CustomIllegalParamException("you can only unbook from today");
}
String curYearMonth = curDate.toString(YEARMONTH_DATE_TIME_FORMATTER);
if(!yearMonthAndDate.containsKey(curYearMonth)){
yearMonthAndDate.put(curYearMonth,Lists.newArrayList());
}
List<String> curBookedDateList = yearMonthAndDate.get(curYearMonth);
curBookedDateList.add(curDateStr);
}
if(yearMonthAndDate.size()>3){//连续的日期最多夸3个月
throw new CustomIllegalParamException(" you can only within 2 month");
}
}
/**
* 取消预定
* @return
*/
@Transactional
public Boolean unbookVehicle(BookVehicleVo bookVehicleVo){
//提取日期参数,改为每月一份
//提取日期和相应的预定目标日期
Map<String,List<String>> yearMonthAndDate = Maps.newHashMap();
DateTime startDay =DateTime.parse(bookVehicleVo.getUnbookStartDate(), DEFAULT_DATE_TIME_FORMATTER);
DateTime endDay =DateTime.parse(bookVehicleVo.getUnbookEndDate(), DEFAULT_DATE_TIME_FORMATTER);
//转换日期范围为列表,并检查是否合法
fillDateList4DatePeriod(yearMonthAndDate,startDay,endDay);
if(yearMonthAndDate.size()>3){//连续的日期最多夸3个月
throw new CustomIllegalParamException(" you can only within 2 month");
}
Boolean rs = Boolean.TRUE;
for(Map.Entry<String,List<String>> entry:yearMonthAndDate.entrySet()){
Boolean rsEach = unbookVehiclePerMonth(bookVehicleVo.getVehicle(),entry.getValue(),entry.getKey());
if(Boolean.FALSE.equals(rsEach)){
rs = Boolean.FALSE;
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动回滚
}
}
return rs;
}
@Transactional
public Boolean unbookVehiclePerMonth(String vehicleId, List<String> unbookDates, String yearMonth){
checkIfVehicleExists(vehicleId);
Map<String,Object> params = Maps.newHashMap();
params.put("vehicle",vehicleId);
params.put("yearMonth",yearMonth);
//加入更新条件
if(CollectionUtils.isEmpty(unbookDates)){
throw new CustomIllegalParamException(" there are no day to unbook ");
}
Map<String,List<String>> yearMonthAndDate = new HashMap<>();
yearMonthAndDate.put(yearMonth,unbookDates);
//转换为查询对应日期未预定的条件
fillBookedDateSearchParam(params,yearMonthAndDate,null);
//提取相关参数组装更细条件
Map<String,Map<String,Integer>> yearMonthAndParam = (Map<String,Map<String,Integer>>)params.get("yearMonthAndParam");
Map<String,Integer> andOpratorParam = yearMonthAndParam.get(yearMonth);
params.putAll(andOpratorParam);
Integer andRsOperationFactor = getBitOpratorFactor4UnBooked(unbookDates);//预定的相关或运算因子,当前月份没有预定记录时同时也是结果
params.put("andRsOperationFactor",
andRsOperationFactor);
Integer effected = vehicleBookInfoMapper.updateBookedInfo(params);
return effected>0?Boolean.TRUE:Boolean.FALSE;
}
/**
* 获取某月份相应预定日期查询条件
* @param yearMonthAndDate 年月 - 预定日期条件字符串(yyyy-MM-dd)
* @param yearMonthAndDateNotBooked 年月 - 未预定日期条件字符串
* @return
*/
public void fillBookedDateSearchParam(Map<String, Object> params,
Map<String,List<String>> yearMonthAndDate,Map<String,List<String>> yearMonthAndDateNotBooked){
if(MapUtils.isEmpty(yearMonthAndDate)&&MapUtils.isEmpty(yearMonthAndDateNotBooked)){//没有预定信息查询条件
throw new CustomIllegalParamException(" at least apply one book info condition.");
}
Map<String,Map<String,Integer>> yearMonthAndParam = new HashMap<>();
Set<String> bookedYearMonth = new HashSet<>();//记录未预定查询条件,供检查是否是否存在同一天既是已预定,又是没有预定
if(MapUtils.isNotEmpty(yearMonthAndDate)) {
for(Map.Entry<String,List<String>> entry:yearMonthAndDate.entrySet()){
String curYearMonth = entry.getKey();
if(CollectionUtils.isEmpty(entry.getValue())){
continue;
}
Integer andOperationFactor = 0;//查找条件中作与运算的参数
Integer andOperationRs = 0;//与运算结果
for (String dateStr:entry.getValue()) {//已预定作为条件,该位与1作与运算必定为1
DateTime dateTime = DateTime.parse(dateStr, DEFAULT_DATE_TIME_FORMATTER);
bookedYearMonth.add(dateStr);
//仅对应位为1的整形值
andOperationFactor |= 1<<(dateTime.dayOfMonth().get()-1);
andOperationRs |= 1<<(dateTime.dayOfMonth().get()-1);
}
Map<String,Integer> andOperationParam = Maps.newHashMap();
andOperationParam.put("andOperationFactor",andOperationFactor);
andOperationParam.put("andOperationRs",andOperationRs);
yearMonthAndParam.put(curYearMonth,andOperationParam);
}
}
if(MapUtils.isNotEmpty(yearMonthAndDateNotBooked)) {
for(Map.Entry<String,List<String>> entry:yearMonthAndDateNotBooked.entrySet()){
String curYearMonth = entry.getKey();
if(CollectionUtils.isEmpty(entry.getValue())){
continue;
}
Map<String,Integer> andOperationParam = Maps.newHashMap();
andOperationParam.put("andOperationFactor",0);
andOperationParam.put("andOperationRs",0);
Integer andOperationFactor=0;//查找条件中作与运算的参数
if(yearMonthAndParam.containsKey(curYearMonth)){
andOperationParam = yearMonthAndParam.get(curYearMonth);
andOperationFactor = andOperationParam.get("andOperationFactor");
}else{
yearMonthAndParam.put(curYearMonth,andOperationParam);
}
for (String dateStr:entry.getValue()) {//已预定作为条件,该位与1作与运算必定为1
if(bookedYearMonth.contains(dateStr)){
throw new CustomIllegalParamException(" 同一天既作为未预定查询条件又作为已预定查询条件");
}
DateTime dateTime = DateTime.parse(dateStr, DEFAULT_DATE_TIME_FORMATTER);
//仅对应位为1的整形值
andOperationFactor |= 1<<(dateTime.dayOfMonth().get()-1);
}
andOperationParam.put("andOperationFactor",andOperationFactor);
// if(!bookedYearMonth.contains(curYearMonth)){//仅以未预定日期条件查询时,不存在预定记录即为没有预定
// andOperationParam.put("notBookedOnly",1);
// }
}
}
if(MapUtils.isNotEmpty(yearMonthAndParam)){
params.put("yearMonthAndParam",yearMonthAndParam);
}
}
/**
* 根据月份分类到map中
*/
private void classifyByYearMonth(List<String> target,Map<String,List<String>> yearMonthAndDate,Set<String> allYearMonth){
if(CollectionUtils.isNotEmpty(target)) {//已预约
for (String dateStr : target) {
String curYearMonth = DateTime.parse(dateStr, DEFAULT_DATE_TIME_FORMATTER).toString(YEARMONTH_DATE_TIME_FORMATTER);
allYearMonth.add(curYearMonth);
List<String> dateStrList = yearMonthAndDate.get(curYearMonth);
if(dateStrList == null ){
dateStrList = Lists.newArrayList();
yearMonthAndDate.put(curYearMonth,dateStrList);
}
dateStrList.add(dateStr);
}
}
}
/**
* 把日期范围转换成列表
* @param startDate
* @param endDate
* @return
*/
private List<String> convertDatePeriod2List(String startDate,String endDate){
DateTime startDay =DateTime.parse(startDate, DEFAULT_DATE_TIME_FORMATTER);
DateTime endDay =DateTime.parse(endDate, DEFAULT_DATE_TIME_FORMATTER);
List<String> rs = Lists.newArrayList();
for( DateTime curDate = startDay;curDate.compareTo(endDay)<=0;curDate=curDate.plusDays(1)){
String curDateStr = curDate.toString(DEFAULT_DATE_TIME_FORMATTER);
rs.add(curDateStr);
}
return rs;
}
/**
* 根据前端预定日期查询条件转换为实际查询条件
* @param params
* @return
*/
public void adjustBookedInfoParam(Map<String, Object> params,VehiclePageQueryVo vehiclePageQueryVo){
//加入每月预定信息查询条件
List<String> bookedDates = Lists.newArrayList();
if(StringUtils.isNotBlank(vehiclePageQueryVo.getBookedStartDate())&&
StringUtils.isNotBlank(vehiclePageQueryVo.getBookedEndDate())) {
bookedDates = convertDatePeriod2List(vehiclePageQueryVo.getBookedStartDate(),
vehiclePageQueryVo.getBookedEndDate());
}
params.remove("bookStartDate");
params.remove("bookEndDate");
List<String> notBookedDates = Lists.newArrayList();
if(StringUtils.isNotBlank(vehiclePageQueryVo.getNotBookedStartDate())&&
StringUtils.isNotBlank(vehiclePageQueryVo.getNotBookedEndDate())) {
notBookedDates = convertDatePeriod2List(vehiclePageQueryVo.getNotBookedStartDate(),
vehiclePageQueryVo.getNotBookedEndDate());
}
params.remove("notBookedStartDate");
params.remove("norBookedEndDate");
//若传入预定信息查询条件,则查询对应月份预定信息查询条件(不超过3个月)
if(CollectionUtils.isEmpty(bookedDates) && CollectionUtils.isEmpty(notBookedDates)){
return;
}
//筛选出查询条件所在月份
Set<String> allYearMonth = new HashSet<>();//记录所有年月
Map<String,List<String>> yearMonthAndDate = new HashMap<>();//预定年月 - 预定日期列表
classifyByYearMonth(bookedDates,yearMonthAndDate,allYearMonth);
Map<String,List<String>> yearMonthAndDateNotBooked = new HashMap<>();//未预定年月 - 未预定日期列表
classifyByYearMonth(notBookedDates,yearMonthAndDateNotBooked,allYearMonth);
if(allYearMonth.size()>0 && params.get("subordinateBranch") == null){
throw new CustomIllegalParamException(" <subordinateBranch> must included in params while using <bookedInfo> param. ");
}
if(allYearMonth.size()>MAX_MONTH_COUNT_BOOKED_INFO_QUERY){
throw new CustomIllegalParamException(" only 3 month can be included <bookedInfo> param.");
}
//加入预定信息查询条件
fillBookedDateSearchParam(params,yearMonthAndDate,yearMonthAndDateNotBooked);
}
/**
* 按页查询
* @param vehiclePageQueryVo
* @return
* @throws Exception
*/
public PageDataVo<QueryVehicleVo> getByPage(VehiclePageQueryVo vehiclePageQueryVo) throws Exception{
Map<String, Object> params = PropertyUtils.describe(vehiclePageQueryVo);
Integer pageSize = (Integer) params.get("limit");
params.remove("pageSize");
Integer pageNo = (Integer) params.get("page");
params.remove("pageNo");
//处理预定日期相关参数
adjustBookedInfoParam(params,vehiclePageQueryVo);
PageHelper.startPage(pageNo,pageSize);
List<QueryVehicleVo> vehicles = mapper.getByPage(params);
PageInfo<QueryVehicleVo> vehiclePageInfo = new PageInfo<>(vehicles);
return PageDataVo.pageInfo(vehiclePageInfo);
}
}
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.biz;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.google.common.collect.Maps;
import com.xinxincaravan.caravan.vehicle.common.CustomIllegalParamException;
import com.xinxincaravan.caravan.vehicle.common.RestResponse;
import com.xinxincaravan.caravan.vehicle.constant.RedisKey;
import com.xinxincaravan.caravan.vehicle.constant.ResCode.ResCode;
import com.xinxincaravan.caravan.vehicle.constant.VehicleBookRecordStatus;
import com.xinxincaravan.caravan.vehicle.entity.VehicleBookRecord;
import com.xinxincaravan.caravan.vehicle.mapper.VehicleBookRecordMapper;
import com.xinxincaravan.caravan.vehicle.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class VehicleBookRecordBiz extends BaseBiz<VehicleBookRecordMapper, VehicleBookRecord> {
public static final String TB_NAME_PREFIX = "vehicle_book_record_his_";
public static final String TB_NAME_REAL = "vehicle_book_record";//实际表名
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;
public VehicleBookRecord getById(Long id){
return mapper.selectByPrimaryKey(id);
}
public RestResponse<Integer> lift(Integer operatorId,String userName,LiftVehicleVo liftVehicleVo) throws Exception{
Map<String, Object> params = PropertyUtils.describe(liftVehicleVo);
params.put("reviewerLift", operatorId);
params.put("reviewerNameLift", userName);
params.put("targetStatus", VehicleBookRecordStatus.LIFTED.getCode());
params.put("conditionStatus", VehicleBookRecordStatus.APPROVE.getCode());
Integer effected = mapper.liftOrRet(params);
if(effected == 0){
return RestResponse.code(ResCode.VEHICLE_BOOKED_RECORD_STATUS_CHANGED.getCode());
}
return RestResponse.suc();
}
public RestResponse<Integer> retVehicle(Integer operatorId,String userName,RetVehicleVo retVehicleVo) throws Exception{
Map<String, Object> params = PropertyUtils.describe(retVehicleVo);
params.put("targetStatus", VehicleBookRecordStatus.RETURNED.getCode());
params.put("conditionStatus", VehicleBookRecordStatus.LIFTED.getCode());
params.put("reviewerReturn", operatorId);
params.put("reviewerNameReturn", userName);
Integer effected = mapper.liftOrRet(params);
if(effected == 0){
return RestResponse.code(ResCode.VEHICLE_BOOKED_RECORD_STATUS_CHANGED.getCode());
}
return RestResponse.suc();
}
/**
* 按页查询
* @param vehicleBookRecordQueryVo
* @return
* @throws Exception
*/
public PageDataVo<QueryVehicleBookRecordVo> page(VehicleBookRecordQueryVo vehicleBookRecordQueryVo) throws Exception{
Map<String, Object> params = PropertyUtils.describe(vehicleBookRecordQueryVo);
String selectedMonth = (String)params.get("selectedMonth");
if(StringUtils.isBlank(selectedMonth)){
throw new CustomIllegalParamException(" no month selected ");
}
params.put("tbName",TB_NAME_REAL);
DateTime selectedMonthDate = DateTime.parse(selectedMonth,YEARMONTH_DATE_TIME_FORMATTER);
if(selectedMonthDate.compareTo(DateTime.now().plusMonths(-1).withDayOfMonth(1).withMillisOfDay(0)) < 0){
params.put("tbName",getTbName(String.valueOf(selectedMonthDate.getYear())));
}
params.put("bookedStartDate",selectedMonthDate.withDayOfMonth(1).toString());
params.put("bookedEndDate",selectedMonthDate.plusMonths(1).withDayOfMonth(1).toDate());
Integer pageSize = (Integer) params.get("limit");
params.remove("pageSize");
Integer pageNo = (Integer) params.get("page");
params.remove("pageNo");
PageHelper.startPage(pageNo,pageSize);
List<QueryVehicleBookRecordVo> bookRecordAndVehicleInfo = mapper.getByPage(params);
PageInfo<QueryVehicleBookRecordVo> vehiclePageInfo = new PageInfo<>(bookRecordAndVehicleInfo);
return PageDataVo.pageInfo(vehiclePageInfo);
}
/**
* 迁移数据到历史表
* 每年一张表
*/
@Scheduled(cron = "0 0 1 1 * ?")//每月1号1点触发
@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_RECORD_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<VehicleBookRecord> vehicleBookRecords = null;
do {
Map<String, Object> params = Maps.newHashMap();
params.put("startDate", now.plusMonths(-1).withMillisOfDay(0).toDate());
params.put("endDate", now.plusDays(-1).withMillisOfDay(0).toDate());
params.put("pageStart", (curPageNo - 1) * COPY_BATCH_SIZE);
params.put("pageSize", COPY_BATCH_SIZE);
vehicleBookRecords = mapper.getByPage4Month(params);
if(CollectionUtils.isNotEmpty(vehicleBookRecords)){
//插入数据到历史表
for(VehicleBookRecord vehicleBookRecord : vehicleBookRecords){
Map<String, Object> insertHisParams = Maps.newHashMap();
insertHisParams.put("tbName", tbName);
insertHisParams.put("id", vehicleBookRecord.getId());
insertHisParams.put("vehicle", vehicleBookRecord.getVehicle());
insertHisParams.put("status", vehicleBookRecord.getStatus());
insertHisParams.put("bookType", vehicleBookRecord.getBookType());
insertHisParams.put("bookUser", vehicleBookRecord.getBookUser());
insertHisParams.put("contactInfo", vehicleBookRecord.getContactInfo());
insertHisParams.put("bookStartDate", vehicleBookRecord.getBookStartDate());
insertHisParams.put("bookEndDate", vehicleBookRecord.getBookEndDate());
insertHisParams.put("liftLocation", vehicleBookRecord.getLiftLocation());
insertHisParams.put("liftAddr", vehicleBookRecord.getLiftAddr());
insertHisParams.put("remark", vehicleBookRecord.getRemark());
insertHisParams.put("destination", vehicleBookRecord.getDestination());
insertHisParams.put("reviewerApply", vehicleBookRecord.getReviewerApply());
insertHisParams.put("reviewerReturn", vehicleBookRecord.getReviewerReturn());
insertHisParams.put("reviewerCancel", vehicleBookRecord.getReviewerCancel());
insertHisParams.put("actualStartDate", vehicleBookRecord.getActualStartDate());
insertHisParams.put("actualEndDate", vehicleBookRecord.getActualEndDate());
mapper.insertHis(insertHisParams);
}
}
curPageNo++;
log.info("【复制上月预定记录至历史表中】,当前复制页【"+curPageNo+"】,页大小【"+COPY_BATCH_SIZE+"】");
}while(CollectionUtils.isNotEmpty(vehicleBookRecords));
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("startDate", now.plusMonths(-2).withMillisOfDay(0).toDate());
params.put("endDate", now.plusMonths(-1).plusDays(-1).withMillisOfDay(0).toDate());
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);
}
/**
* 获取历史表名称
* @param year
* @return
*/
private String getTbName(String year){
return TB_NAME_PREFIX+ year;
}
/**
* 创建当年相关表格
*/
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
package com.xinxincaravan.caravan.vehicle.vo;
import lombok.Data;
import java.util.Date;
@Data
public class VehiclePageQueryVo {
/**
* 车辆编号,0-没有
*/
private Integer code;
/**
* 车辆状态: 1-正常运行 2-维修 3-报废
*/
private Integer status;
/**
* 车牌号,空字符串-没有
*/
private String numberPlate;
/**
* 品牌(编码,对应关系见相关常量),0-未填写
*/
private Integer brand;
/**
* 所属分支机构(id)
*/
private Integer subordinateBranch;
/**
* 用途类型:租赁房车(1)、展车等,对应关系见车辆常量表
*/
private Integer useType;
/**
* 预定目标日期(开始)
*/
private String bookedStartDate;
/**
* 预定目标日期(结束)
*/
private String bookedEndDate;
/**
* 未预定目标日期(开始)
*/
private String notBookedStartDate;
/**
* 未预定目标日期(结束)
*/
private String notBookedEndDate;
private Integer page;
private Integer limit;
/**
* 车架号
*/
private String vin;
/**
* 里程数
*/
private Integer mileageRangeStart;
/**
* 里程数
*/
private Integer mileageRangeEnd;
/**
* 保险公司,见常量表
*/
private Integer insuranceCompany;
/**
* 保险结束时间查询范围 - 开始
*/
private Date insuranceDateRangeStart;
/**
* 保险结束时间查询范围 - 结束
*/
private Date insuranceDateRangeEnd;
/**
* 年审日期查询范围 - 开始
*/
private Date aVRangeDateStart;
/**
* 年审日期查询范围 - 结束
*/
private Date aVRangeDateEnd;
/**
* 保养日期查询范围 - 开始
*/
private Date mRangeDateStart;
/**
* 保养日期查询范围 - 结束
*/
private Date mRangeDateEnd;
/**
* 是否违章
*/
private Integer haveViolation;
public Integer getMileageRangeStart() {
return mileageRangeStart;
}
public void setMileageRangeStart(Integer mileageRangeStart) {
this.mileageRangeStart = mileageRangeStart;
}
public Integer getMileageRangeEnd() {
return mileageRangeEnd;
}
public void setMileageRangeEnd(Integer mileageRangeEnd) {
this.mileageRangeEnd = mileageRangeEnd;
}
public Integer getInsuranceCompany() {
return insuranceCompany;
}
public void setInsuranceCompany(Integer insuranceCompany) {
this.insuranceCompany = insuranceCompany;
}
public Date getInsuranceDateRangeStart() {
return insuranceDateRangeStart;
}
public void setInsuranceDateRangeStart(Date insuranceDateRangeStart) {
this.insuranceDateRangeStart = insuranceDateRangeStart;
}
public Date getInsuranceDateRangeEnd() {
return insuranceDateRangeEnd;
}
public void setInsuranceDateRangeEnd(Date insuranceDateRangeEnd) {
this.insuranceDateRangeEnd = insuranceDateRangeEnd;
}
public Date getaVRangeDateStart() {
return aVRangeDateStart;
}
public void setaVRangeDateStart(Date aVRangeDateStart) {
this.aVRangeDateStart = aVRangeDateStart;
}
public Date getaVRangeDateEnd() {
return aVRangeDateEnd;
}
public void setaVRangeDateEnd(Date aVRangeDateEnd) {
this.aVRangeDateEnd = aVRangeDateEnd;
}
public Date getmRangeDateStart() {
return mRangeDateStart;
}
public void setmRangeDateStart(Date mRangeDateStart) {
this.mRangeDateStart = mRangeDateStart;
}
public Date getmRangeDateEnd() {
return mRangeDateEnd;
}
public void setmRangeDateEnd(Date mRangeDateEnd) {
this.mRangeDateEnd = mRangeDateEnd;
}
}
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
<?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.ConstantMapper">
<select id="getAllConstantTypes" resultType="java.lang.Integer">
select distinct `type` from constant
</select>
<update id="updateByTypeAndCode" parameterType="com.xinxincaravan.caravan.vehicle.entity.Constant" >
update constant set val = #{val} where type = #{type} and code = #{code}
</update>
<delete id="delByTypeAndCode" parameterType="com.xinxincaravan.caravan.vehicle.entity.Constant">
delete from constant where type = #{type} and code = #{code};
</delete>
<insert id="insertIgnoreOnDuplicate" parameterType="com.xinxincaravan.caravan.vehicle.entity.Constant">
insert ignore into constant(type,code,val) values (#{type},#{code},#{val})
</insert>
</mapper>
\ 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.SysRegionMapper">
<select id="getAllByPage" parameterType="java.util.Map" resultType="com.xinxincaravan.caravan.vehicle.entity.SysRegion">
select `id`, parent_id, `name`, `type`, agency_id from sys_region limit #{pageStart},${pageSize}
</select>
<select id="getByIdList" parameterType="java.util.List" resultType="com.xinxincaravan.caravan.vehicle.entity.SysRegion">
select `id`, parent_id, `name`, `type`, agency_id from sys_region where id in
<foreach collection="list" index="i" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
</mapper>
\ 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.VehicleBookInfoMapper" >
<resultMap id="BaseResultMap" type="com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="BIGINT" />
<result column="vehicle" property="vehicle" jdbcType="VARCHAR" />
<result column="year_month" property="yearMonth" jdbcType="VARCHAR" />
<result column="booked_date" property="bookedDate" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<select id="getByVehicleIdAndYearMonth" resultType="com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo" parameterType="java.util.Map">
select id, vehicle, `year_month`, booked_date from vehicle_book_info where vehicle = #{vehicle} and `year_month`=#{yearMonth}
</select>
<select id="getByVehicleIdAndYearMonths" resultType="com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo" parameterType="java.util.Map">
select id, vehicle, `year_month`, booked_date from vehicle_book_info
where vehicle = #{vehicle}
and `year_month` in
<foreach collection="yearMonths" index="i" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
<insert id="insertIgnore" parameterType="com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo">
insert ignore into vehicle_book_info ( vehicle, `year_month`, booked_date)
values(#{vehicle},#{yearMonth},#{bookedDate})
</insert>
<update id="updateBookedInfo" parameterType="java.util.Map">
update vehicle_book_info set
<choose>
<when test="orRsOperationFactor!=null">
booked_date = booked_date | #{orRsOperationFactor}
</when>
<when test="andRsOperationFactor!=null">
booked_date = booked_date &amp; #{andRsOperationFactor}
</when>
</choose>
where
vehicle = #{vehicle} and `year_month`=#{yearMonth} and
booked_date &amp; #{andOperationFactor} = #{andOperationRs}
</update>
<select id="getByPage4YearMonth" parameterType="java.util.Map" resultType="com.xinxincaravan.caravan.vehicle.entity.VehicleBookInfo">
select id, vehicle, `year_month`, booked_date, create_time, update_time from vehicle_book_info where `year_month` = #{yearMonth} order by id limit #{pageStart},#{pageSize}
</select>
<delete id="del4YearMoth" parameterType="java.util.Map">
delete from vehicle_book_info where `year_month` = #{yearMonth} limit #{batchSize}
</delete>
<insert id="insertHis" parameterType="java.util.Map">
insert into
${tbName}(
`id`,
vehicle,
`year_month`,
booked_date
)
values(
#{id},
#{vehicle},
#{yearMonth},
#{bookedDate}
);
</insert>
<insert id="createTbIfNotExists" parameterType="java.lang.String">
CREATE TABLE IF NOT EXISTS ${_parameter} (
`id` bigint(10) NOT NULL,
`vehicle` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '车辆id',
`year_month` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '预定信息所属年月(格式yyyy-MM)',
`booked_date` int(10) NOT NULL COMMENT '预定信息,int格式保存,当作位图使用(从小到大每位代表每个月1-31号)',
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`update_time` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `i_vehicle_year_month`(`vehicle`, `year_month`) USING BTREE,
INDEX `i_year_month`(`year_month`) USING BTREE COMMENT '迁移历史表查询时使用'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '预定信息历史表,按年分表' ROW_FORMAT = Dynamic;
</insert>
</mapper>
\ 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.VehicleBookRecordMapper" >
<resultMap id="BaseResultMap" type="com.xinxincaravan.caravan.vehicle.entity.VehicleBookRecord" >
<!--
WARNING - @mbg.generated
-->
<id column="id" property="id" jdbcType="BIGINT" />
<result column="vehicle" property="vehicle" jdbcType="VARCHAR" />
<result column="statu" property="statu" jdbcType="INTEGER" />
<result column="book_type" property="bookType" jdbcType="INTEGER" />
<result column="book_user" property="bookUser" jdbcType="INTEGER" />
<result column="contact_info" property="contactInfo" jdbcType="VARCHAR" />
<result column="book_start_date" property="bookStartDate" jdbcType="TIMESTAMP" />
<result column="
lift_location" property="
liftLocation" jdbcType="VARCHAR" />
<result column="lift_addr" property="liftAddr" jdbcType="VARCHAR" />
<result column="remark" property="remark" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="destination" property="destination" jdbcType="VARCHAR" />
<result column="book_end_date" property="bookEndDate" jdbcType="TIMESTAMP" />
<result column="actal_start_date" property="actalStartDate" jdbcType="TIMESTAMP" />
<result column="actual_end_date" property="actualEndDate" jdbcType="TIMESTAMP" />
</resultMap>
<update id="changeRecordStatus" parameterType="java.util.Map">
update vehicle_book_record set
<if test="reviewerApply != null ">
reviewer_apply =#{reviewerApply},
</if>
<if test="reviewerNameApply != null and reviewerNameApply !=''">
reviewer_name_apply =#{reviewerNameApply},
</if>
<if test="reviewerReturn != null ">
reviewer_return =#{reviewerReturn},
</if>
<if test="reviewerNameReturn != null and reviewerNameReturn !=''">
reviewer_name_return =#{reviewerNameReturn},
</if>
<if test="reviewerCancel != null">
reviewer_cancel =#{reviewerCancel},
</if>
<if test="reviewerNameCancel != null and reviewerNameCancel !=''">
reviewer_name_cancel =#{reviewerNameCancel},
</if>
`status` = #{status}
where id = #{id} and `status` = #{statusCondition}
</update>
<delete id="del4YearMoth" parameterType="java.util.Map">
delete from vehicle_book_record where `book_end_date` between #{startDate} and #{endDate} limit #{batchSize}
</delete>
<update id="liftOrRet" parameterType="java.util.Map">
update vehicle_book_record
set `status` = #{targetStatus},
<if test="reviewerLift != null">
`reviewer_lift` = #{reviewerLift},
`reviewer_name_lift` = #{reviewerNameLift},
</if>
<if test="reviewerReturn != null">
`reviewer_return` = #{reviewerReturn},
`reviewer_name_return` = #{reviewerNameReturn},
</if>
<if test="liftRemark != null and liftRemark != ''">
`lift_remark` = #{liftRemark},
</if>
<if test="retRemark != null and retRemark != ''">
`ret_remark` = #{retRemark},
</if>
<if test="retCompany != null">
`ret_company` = #{retCompany},
</if>
<if test="liftCompany != null">
`lift_company` = #{liftCompany},
</if>
`actual_start_date` = now()
where id = #{id} and `status` = #{conditionStatus}
</update>
<insert id="insertHis" parameterType="java.util.Map">
insert into ${tbName} (
`id`,
`vehicle`,
`status`,
`book_type`,
`book_user`,
`book_user_name`,
`contact_info`,
`book_start_date`,
`book_end_date`,
`lift_location`,
`lift_addr`,
`remark`,
`destination`,
`reviewer_apply`,
`reviewer_name_apply`,
`reviewer_return`,
`reviewer_name_return`,
`reviewer_cancel`,
`reviewer_name_cancel`,
`actual_start_date`,
`actual_end_date`
)
values(
#{id},
#{vehicle},
#{status},
#{bookType},
#{bookUser},
#{bookUserName},
#{contactInfo},
#{bookStartDate},
#{bookEndDate},
#{liftLocation},
#{liftAddr},
#{remark},
#{destination},
#{reviewerApply},
#{reviewerNameApply},
#{reviewerReturn},
#{reviewerNameReturn},
#{reviewerCancel},
#{reviewerNameCancel},
#{actualStartDate},
#{actualEndDate}
);
</insert>
<select id="getByPage4Month" parameterType="java.util.Map" resultType="com.xinxincaravan.caravan.vehicle.entity.VehicleBookRecord">
select
`id`,
`vehicle`,
`status`,
`book_type`,
`book_user`,
`book_user_name`,
`contact_info`,
`book_start_date`,
`book_end_date`,
`lift_location`,
`lift_addr`,
`remark`,
`create_time`,
`update_time`,
`destination`,
`reviewer_apply`,
`reviewer_name_apply`,
`reviewer_return`,
`reviewer_name_return`,
`reviewer_cancel`,
`reviewer_name_cancel`,
`actual_start_date`,
`actual_end_date`
from
vehicle_book_record
where
`book_end_date` between #{startDate} and #{endDate}
order by id
limit #{pageStart},#{pageSize}
</select>
<select id="getByPage" parameterType="java.util.Map" resultType="com.xinxincaravan.caravan.vehicle.vo.QueryVehicleBookRecordVo">
select
vbr.`id`,
vbr.`vehicle`,
vbr.`status`,
vbr.`book_type`,
vbr.`book_user`,
vbr.`book_user_name`,
vbr.`contact_info`,
vbr.`book_start_date`,
vbr.`book_end_date`,
vbr.`lift_location`,
vbr.`lift_addr`,
vbr.`remark`,
vbr.`create_time`,
vbr.`update_time`,
vbr.`destination`,
vbr.`reviewer_apply`,
vbr.`reviewer_name_apply`,
vbr.`reviewer_return`,
vbr.`reviewer_name_return`,
vbr.`reviewer_cancel`,
vbr.`reviewer_name_cancel`,
vbr.`actual_start_date`,
vbr.`actual_end_date`,
vbr.`reviewer_lift`,
vbr.`reviewer_name_lift`,
vbr.lift_company,
bcl.name as liftCompanyName ,
vbr.lift_remark,
vbr.ret_company,
bcr.name as retCompanyName ,
vbr.ret_remark,
v.`code` as vehicleCode,
v.number_plate as numberPlate,
v.subordinate_branch,
bc.name as subBranchName,
vbf.booked_date as bookedDate
from
${tbName} vbr left join
vehicle v on vbr.vehicle = v.id left join
branch_company bc on bc.id = v.subordinate_branch left join
branch_company bcl on bcl.id = vbr.lift_company left join
branch_company bcr on bcr.id = vbr.ret_company left join
vehicle_book_info vbf on vbf.vehicle = vbr.vehicle and vbf.year_month = #{selectedMonth}
where
1=1
<if test="liftCompany !=null">
and vbr.lift_company = #{liftCompany}
</if>
<if test="retCompany !=null">
and vbr.ret_company = #{retCompany}
</if>
<if test="numberPlate !=null and numberPlate !=''">
and v.number_plate = #{numberPlate}
</if>
<if test="vehicleCode !=null and vehicleCode !=''">
and v.code = #{vehicleCode}
</if>
<if test="status !=null ">
and vbr.status = #{status}
</if>
<if test="subordinateBranch !=null">
and v.subordinate_branch = #{subordinateBranch}
</if>
<if test="bookedStartDate !=null">
and vbr.book_start_date &gt;= #{bookedStartDate}
</if>
<if test="bookedEndDate !=null">
and vbr.book_end_date &lt;= #{bookedEndDate}
</if>
order by vbr.id desc
</select>
<insert id="createTbIfNotExists" parameterType="java.lang.String">
CREATE TABLE IF NOT EXISTS ${_parameter} (
`id` bigint(20) NOT NULL COMMENT '主键',
`vehicle` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '车辆id',
`status` int(255) NULL DEFAULT NULL COMMENT '申请状态:1-申请中 2-已通过 3-已归还 4-拒绝 5-逾期归还 6-已取消',
`book_type` int(11) NOT NULL COMMENT '预定类型,1-用户租赁、2-内部员工申请 3-维修',
`book_user` int(11) NOT NULL COMMENT '预定用户id',
`book_user_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '申请人姓名',
`contact_info` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '联系信息,比如电话、联系人姓名等(json)',
`book_start_date` datetime(0) NOT NULL COMMENT '申请开始日期',
`book_end_date` datetime(0) NOT NULL COMMENT '申请结束日期',
`lift_location` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '提车地点(经纬度)',
`lift_addr` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '提车地址',
`remark` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`update_time` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
`destination` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '目的地',
`reviewer_apply` int(10) NULL DEFAULT NULL COMMENT '申请审核人,-1代表系统',
`reviewer_name_apply` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '申请审核人姓名',
`reviewer_return` int(10) NULL DEFAULT NULL COMMENT '归还审核人,-1代表系统',
`reviewer_name_return` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '归还审核人姓名',
`reviewer_cancel` int(10) NULL DEFAULT NULL COMMENT '取消人,-1代表系统',
`reviewer_name_cancel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '取消预定人姓名',
`actual_start_date` datetime(0) NULL DEFAULT NULL COMMENT '实际开始日期',
`actual_end_date` datetime(0) NULL DEFAULT NULL COMMENT '实际结束日期',
PRIMARY KEY (`id`) USING BTREE,
INDEX `i_vehicle`(`vehicle`) USING BTREE,
INDEX `i_book_user`(`book_user`) USING BTREE,
INDEX `i_book_end_date`(`book_end_date`) USING BTREE COMMENT '迁移至历史表时查询用到该索引(暂时)'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '汽车预定记录历史表,按年分表' ROW_FORMAT = Dynamic;
</insert>
</mapper>
\ 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.VehicleMapper" >
<update id="updateStatusById" parameterType="java.util.Map" >
update vehicle set status = #{status} where id in
<foreach collection="idList" index="i" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</update>
<select id="getByPage" parameterType="java.util.Map" resultType="com.xinxincaravan.caravan.vehicle.vo.QueryVehicleVo">
select v.`id`,
v.`code`,
v.`status`,
v.number_plate,
v.brand,
v.subordinate_branch,
bc.name as subBranchName,
v.use_type,
v.remark,
v.create_time,
v.vin,
v.mileage,
v.insurance_company,
v.insurance_no,
v.insurance_start_date,
v.insurance_end_date,
v.annual_verification_date,
v.maintenance_date,
v.maintenance_mileage,
v.have_violation,
v.update_time
<if test=" yearMonthAndParam !=null ">
,vbi.booked_date
</if>
from vehicle v
<if test=" yearMonthAndParam !=null ">
left join
vehicle_book_info vbi on v.`id` = vbi.vehicle
</if>
left join branch_company bc on v.`subordinate_branch` = bc.id
where
1=1
<if test="haveViolation !=null">
and v.have_violation = #{haveViolation}
</if>
<if test="mRangeDateEnd !=null">
and v.maintenance_date &lt;= #{mRangeDateEnd}
</if>
<if test="mRangeDateStart !=null">
and v.maintenance_date &gt;= #{mRangeDateStart}
</if>
<if test="aVRangeDateStart !=null">
and v.annual_verification_date &lt;= #{aVRangeDateEnd}
</if>
<if test="aVRangeDateEnd !=null">
and v.annual_verification_date &gt;= #{aVRangeDateStart}
</if>
<if test="insuranceDateRangeStart !=null">
and v.insurance_end_date &lt;= #{insuranceDateRangeEnd}
</if>
<if test="insuranceDateRangeEnd !=null">
and v.insurance_end_date &gt;= #{insuranceDateRangeStart}
</if>
<if test="insuranceCompany !=null">
and v.insurance_company = #{insuranceCompany}
</if>
<if test="mileageRangeEnd !=null">
and v.mileage &lt;= #{mileageRangeEnd}
</if>
<if test="mileageRangeStart !=null">
and v.mileage &gt;= #{mileageRangeStart}
</if>
<if test="vin !=null and vin != ''">
and v.vin = #{vin}
</if>
<if test="subordinateBranch !=null">
and v.subordinate_branch = #{subordinateBranch}
</if>
<if test="code !=null">
and v.code = #{code}
</if>
<if test="status !=null">
and v.status = #{status}
</if>
<if test="numberPlate !=null and numberPlate != ''">
and v.number_plate = #{numberPlate}
</if>
<if test="brand !=null">
and v.brand = #{brand}
</if>
<if test="useType !=null">
and v.use_type = #{useType}
</if>
<!-- 若需根据预定日期条件查询,针对换为位操作 -->
<if test=" yearMonthAndParam !=null ">
<foreach collection="yearMonthAndParam" index="yearMonth" item="andOperation" >
and
( (vbi.`year_month` = #{yearMonth} or vbi.`year_month` is null) and
ifnull(vbi.`booked_date`,0) &amp; #{andOperation.andOperationFactor} = #{andOperation.andOperationRs}
)
</foreach>
</if>
order by v.code
</select>
<select id="lockByCode" resultType="com.xinxincaravan.caravan.vehicle.entity.Vehicle" parameterType="com.xinxincaravan.caravan.vehicle.vo.AddOrUpdateVehicleVo">
select
v.`id`,
v.`code`,
v.`status`,
v.number_plate,
v.brand,
v.subordinate_branch,
v.use_type,
v.remark,
v.create_time,
v.update_time
from vehicle v
where
`code` = #{code}
for update
</select>
</mapper>
\ No newline at end of file
package com.xinxincaravan.caravan.vehicle;
import com.github.wxiaoqi.security.auth.client.EnableAceAuthClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.test.context.junit4.SpringRunner;
//@RunWith(SpringRunner.class)
//@SpringBootTest
public class VehicleApplicationTests {
// @Test
public void contextLoads() {
}
}
...@@ -5,7 +5,7 @@ spring: ...@@ -5,7 +5,7 @@ spring:
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
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