init commit-resource/role/account
commit
6fbad28ca4
|
@ -0,0 +1,28 @@
|
||||||
|
.gradle
|
||||||
|
/build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
/.idea/workspace.xml
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
/out/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
/logs/
|
|
@ -0,0 +1,84 @@
|
||||||
|
group 'cn.palmte'
|
||||||
|
//version '1.0'
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
ext {
|
||||||
|
springBootVersion = '1.5.7.RELEASE'
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'war'
|
||||||
|
apply plugin: 'application'
|
||||||
|
apply plugin: 'org.springframework.boot'
|
||||||
|
//apply plugin: 'findbugs'
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
jcenter()
|
||||||
|
maven { url 'https://jitpack.io' }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile "org.springframework.boot:spring-boot-starter:${springBootVersion}"
|
||||||
|
compile 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
compile 'org.springframework.boot:spring-boot-starter-freemarker'
|
||||||
|
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
|
||||||
|
//compile('org.springframework.boot:spring-boot-starter-data-redis')
|
||||||
|
|
||||||
|
compile 'com.gitee.xxssyyyyssxx.unihttp:unihttp-jdk:v2.0.2'
|
||||||
|
compile 'com.gitee.xxssyyyyssxx:common-crypto:v1.8.1'
|
||||||
|
compile 'com.gitee.xxssyyyyssxx:common-db:v1.8.7'
|
||||||
|
compile 'com.gitee.xxssyyyyssxx.json:json-fastjson:v1.8.8'
|
||||||
|
compile 'com.gitee.xxssyyyyssxx:token:v1.0'
|
||||||
|
|
||||||
|
compile 'com.jfinal:jfinal:2.2'
|
||||||
|
compile 'com.alibaba:druid:1.1.9'
|
||||||
|
compile 'mysql:mysql-connector-java:6.0.6'
|
||||||
|
//compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
|
||||||
|
//shiro
|
||||||
|
compile group: 'org.apache.shiro', name: 'shiro-spring', version: '1.4.0'
|
||||||
|
compile group: 'org.apache.shiro', name: 'shiro-core', version: '1.4.0'
|
||||||
|
compile group: 'net.mingsoft', name: 'shiro-freemarker-tags', version: '0.1'
|
||||||
|
|
||||||
|
compile group: 'org.apache.poi', name: 'poi', version: '3.17'
|
||||||
|
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
|
||||||
|
compile group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
|
||||||
|
compile group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.17'
|
||||||
|
|
||||||
|
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
|
||||||
|
|
||||||
|
compileOnly 'org.springframework.boot:spring-boot-configuration-processor'
|
||||||
|
|
||||||
|
testCompile 'junit:junit:4.12'
|
||||||
|
testCompile 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
}
|
||||||
|
|
||||||
|
compileJava.dependsOn(processResources){
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
findbugs{
|
||||||
|
ignoreFailures=true
|
||||||
|
findbugsTest.enabled=false
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(FindBugs) {
|
||||||
|
reports {
|
||||||
|
// 指定分析结果格式为xml 只能选一种格式
|
||||||
|
xml.enabled = true
|
||||||
|
html.enabled = false
|
||||||
|
}
|
||||||
|
}*/
|
Binary file not shown.
|
@ -0,0 +1,6 @@
|
||||||
|
#Thu Oct 28 15:13:01 CST 2021
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-bin.zip
|
|
@ -0,0 +1,172 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Gradle start up script for UN*X
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
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
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS=""
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD="maximum"
|
||||||
|
|
||||||
|
warn ( ) {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
die ( ) {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN* )
|
||||||
|
cygwin=true
|
||||||
|
;;
|
||||||
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
NONSTOP* )
|
||||||
|
nonstop=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
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
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="java"
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
ulimit -n $MAX_FD
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
|
if $darwin; then
|
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
|
if $cygwin ; then
|
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
SEP=""
|
||||||
|
for dir in $ROOTDIRSRAW ; do
|
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
|
SEP="|"
|
||||||
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
(0) set -- ;;
|
||||||
|
(1) set -- "$args0" ;;
|
||||||
|
(2) set -- "$args0" "$args1" ;;
|
||||||
|
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Escape application args
|
||||||
|
save ( ) {
|
||||||
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
|
echo " "
|
||||||
|
}
|
||||||
|
APP_ARGS=$(save "$@")
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||||
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||||
|
|
||||||
|
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||||
|
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
|
@ -0,0 +1,84 @@
|
||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:init
|
||||||
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
|
||||||
|
:win9xME_args
|
||||||
|
@rem Slurp the command line arguments.
|
||||||
|
set CMD_LINE_ARGS=
|
||||||
|
set _SKIP=2
|
||||||
|
|
||||||
|
:win9xME_args_slurp
|
||||||
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
|
@ -0,0 +1,2 @@
|
||||||
|
rootProject.name = 'fourcal'
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package cn.palmte.work;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 四算项目
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class FourCalApplication extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(FourCalApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||||
|
/**
|
||||||
|
* war包运行的话,为了不修改配置文件,在运行的tomcat的catalina.sh中添加jvm参数-Dspring.profiles.active=test,
|
||||||
|
* 因为我们现在已经有一个env了,所以可以根据这个设置profile
|
||||||
|
* 命令行java -jar运行的话直接通过-Dspring.profiles.active=test来指定
|
||||||
|
*/
|
||||||
|
setRegisterErrorPageFilter(false);
|
||||||
|
String env = System.getProperty("env");
|
||||||
|
if (null != env) {
|
||||||
|
Map<String, Object> map = new HashMap<>(1);
|
||||||
|
map.put("spring.profiles.active", env);
|
||||||
|
builder.properties(map);
|
||||||
|
//不能使用 builder.profiles(env);否则可能出现两个环境的都配置了
|
||||||
|
}
|
||||||
|
return builder.sources(FourCalApplication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package cn.palmte.work.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源等信息常量化
|
||||||
|
* @author xiongshiyan
|
||||||
|
*/
|
||||||
|
public class Constant {
|
||||||
|
|
||||||
|
public static final String DATA = "Data";
|
||||||
|
|
||||||
|
public static final int ROLE_TYPE_SUPER_ADMIN = 0; // 系统管理员
|
||||||
|
public static final int ROLE_TYPE_CMCC_ADMIN = 1;// 移动管理员
|
||||||
|
public static final int ROLE_TYPE_ZJPT_ADMIN = 2; //资金平台管理员
|
||||||
|
|
||||||
|
|
||||||
|
private Constant(){}
|
||||||
|
/**
|
||||||
|
* 全局状态码
|
||||||
|
*/
|
||||||
|
public static final class Status {
|
||||||
|
private Status() {
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
public static final int STATUS_SUCCESS = 0;
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*/
|
||||||
|
public static final int STATUS_FAILED = 1;
|
||||||
|
/**
|
||||||
|
* 异常
|
||||||
|
*/
|
||||||
|
public static final int STATUS_EXCEPTION = 2;
|
||||||
|
/**
|
||||||
|
* 提示登录
|
||||||
|
*/
|
||||||
|
public static final int STATUS_PROMPT_LOGIN = 1009;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package cn.palmte.work.bean;
|
||||||
|
|
||||||
|
public interface RegexConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号校验正则
|
||||||
|
*/
|
||||||
|
String REGEX = "^1[0-9][0-9]\\d{8}$";
|
||||||
|
|
||||||
|
String SERVERADDRESS = "^(http|https|ftp)\\://(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])|([a-zA-Z0-9_\\-\\.])+\\.(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|uk|me))((:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\\\+&%\\$#\\=~])*)$";
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
package cn.palmte.work.bean;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.config.Constant;
|
||||||
|
|
||||||
|
|
||||||
|
public class ResponseMsg {
|
||||||
|
private int status;
|
||||||
|
private String msg;
|
||||||
|
private Object data;
|
||||||
|
|
||||||
|
public ResponseMsg() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseMsg(int status, String msg) {
|
||||||
|
this.status = status;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseMsg buildSuccessMsg(String msg) {
|
||||||
|
return new ResponseMsg(Constant.Status.STATUS_SUCCESS, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseMsg buildSuccessData(Object data) {
|
||||||
|
return buildSuccessMsg("ok", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseMsg buildSuccessMsg(String msg, Object data) {
|
||||||
|
ResponseMsg responseMsg = new ResponseMsg(Constant.Status.STATUS_SUCCESS, msg);
|
||||||
|
responseMsg.setData(data);
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseMsg buildMsg(int status, String msg, Object data) {
|
||||||
|
ResponseMsg responseMsg = new ResponseMsg(status, msg);
|
||||||
|
responseMsg.setData(data);
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseMsg buildFailedMsg(String msg) {
|
||||||
|
return new ResponseMsg(Constant.Status.STATUS_FAILED, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResponseMsg buildFailedMsg(String msg, Object data) {
|
||||||
|
ResponseMsg responseMsg = new ResponseMsg(Constant.Status.STATUS_FAILED, msg);
|
||||||
|
responseMsg.setData(data);
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(Object data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return Constant.Status.STATUS_SUCCESS == this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ResponseMsg{" +
|
||||||
|
"status=" + status +
|
||||||
|
", msg='" + msg + '\'' +
|
||||||
|
", data=" + data +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注入配置属性
|
||||||
|
*
|
||||||
|
* @author pengqiang
|
||||||
|
* @date 2018/6/26
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ConfigProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传路径
|
||||||
|
*/
|
||||||
|
//@Value("${upload.path}")
|
||||||
|
private String uploadPath = "/mnt/dzg/image";
|
||||||
|
/**
|
||||||
|
* 上传前缀
|
||||||
|
*/
|
||||||
|
//@Value("${upload.prefix}")
|
||||||
|
private String uploadPrefix = "/upload";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* admin服务器域名
|
||||||
|
* 格式: https://dzgtest.palmte.cn
|
||||||
|
*/
|
||||||
|
//@Value("${admin.domain}")
|
||||||
|
private String adminDomain = "";
|
||||||
|
|
||||||
|
public String getUploadPath() {
|
||||||
|
return uploadPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUploadPrefix() {
|
||||||
|
return uploadPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAdminDomain() {
|
||||||
|
return adminDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源等信息常量化
|
||||||
|
* @author xiongshiyan
|
||||||
|
*/
|
||||||
|
public class Constant {
|
||||||
|
public static final String PAGINATION = "pagination";
|
||||||
|
public static final String PRIVATEKEY = "privatekey";
|
||||||
|
public static final String PUBLICKEY = "publickey";
|
||||||
|
public static final String HEADER_TOKEN = "token";
|
||||||
|
public static final String API_TOKEN_MANAGER = "apiTokenManager";
|
||||||
|
public static final String PC_TOKEN_MANAGER = "pcTokenManager";
|
||||||
|
public static final String API_ERROR_COUNT_MANAGER = "apiErrorCountManager";
|
||||||
|
public static final String PC_ERROR_COUNT_MANAGER = "pcErrorCountManager";
|
||||||
|
public static final String API_CAPTCHA_MANGER = "apiCaptchaManger";
|
||||||
|
public static final String PC_CAPTCHA_MANGER = "pcCaptchaManger";
|
||||||
|
|
||||||
|
public static final String PREFIX_API_V3 = "/api/v3";
|
||||||
|
public static final String PREFIX_API_PC = "/api/pc";
|
||||||
|
public static final String PREFIX_API_DRAG = "/api/drag";
|
||||||
|
|
||||||
|
private Constant() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局状态码
|
||||||
|
*/
|
||||||
|
public static final class Status {
|
||||||
|
private Status() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
public static final int STATUS_SUCCESS = 0;
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*/
|
||||||
|
public static final int STATUS_FAILED = 1;
|
||||||
|
/**
|
||||||
|
* 异常
|
||||||
|
*/
|
||||||
|
public static final int STATUS_EXCEPTION = 2;
|
||||||
|
/**
|
||||||
|
* 提示登录
|
||||||
|
*/
|
||||||
|
public static final int STATUS_PROMPT_LOGIN = 1009;
|
||||||
|
public static final int STATUS_PROMPT_UNAUTH = 1010;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
public static final int STATUS_SUCCESS = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*/
|
||||||
|
public static final int STATUS_FAILED = 1;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
import cn.palmte.work.config.interceptor.TokenLoggingInterceptor;
|
||||||
|
import cn.palmte.work.utils.StrKit;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置拦截器等
|
||||||
|
* @author xiongshiyan
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GoodWebAppConfigurer extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenLoggingInterceptor tokenLoggingInterceptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排除某些url不需要校验
|
||||||
|
*/
|
||||||
|
@Value("${fourcal.excluded.client.urls}")
|
||||||
|
private String excludesClientUrls;
|
||||||
|
@Value("${fourcal.excluded.pc.urls}")
|
||||||
|
private String excludesPCUrls;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
/**拦截任意URL,打印token header参数*/
|
||||||
|
addInterceptor(registry , tokenLoggingInterceptor , "" , "/**");
|
||||||
|
|
||||||
|
/**拦截所有排除指定的*/
|
||||||
|
}
|
||||||
|
private void addInterceptor(InterceptorRegistry registry , HandlerInterceptor handlerInterceptor , String excludeUrls , String... addPartterns) {
|
||||||
|
InterceptorRegistration registration = registry.addInterceptor(handlerInterceptor)
|
||||||
|
.addPathPatterns(addPartterns);
|
||||||
|
String[] p = excludeUrls.split(",");
|
||||||
|
StrKit.trim(p);
|
||||||
|
if( p.length > 0 ){
|
||||||
|
registration.excludePathPatterns(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许跨域
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/**")
|
||||||
|
.allowedHeaders("*")
|
||||||
|
.allowedOrigins("*")
|
||||||
|
.allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
|
||||||
|
.allowCredentials(false).maxAge(3600);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
import cn.palmte.work.security.ReplaceSpecialCharFilter;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import top.jfunc.http.SmartHttpClient;
|
||||||
|
import top.jfunc.http.smart.JdkSmartHttpClient;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan at 2020/9/30 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class HttpConfig {
|
||||||
|
@Bean
|
||||||
|
public SmartHttpClient smartHttpClient(){
|
||||||
|
return new JdkSmartHttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xss过滤拦截器
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public FilterRegistrationBean xssFilterRegistrationBean() {
|
||||||
|
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
|
||||||
|
filterRegistrationBean.setFilter(new ReplaceSpecialCharFilter());
|
||||||
|
filterRegistrationBean.setOrder(1);
|
||||||
|
filterRegistrationBean.setEnabled(true);
|
||||||
|
filterRegistrationBean.addUrlPatterns("/*");
|
||||||
|
Map<String, String> initParameters = new HashMap<>();
|
||||||
|
initParameters.put("includes", "/fourcal/admin/err");
|
||||||
|
filterRegistrationBean.setInitParameters(initParameters);
|
||||||
|
return filterRegistrationBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import top.jfunc.common.db.utils.Pagination;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan at 2018/7/23 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class PaginationConfig {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
@Autowired
|
||||||
|
private EntityManager entityManagerPrimary;
|
||||||
|
|
||||||
|
///错误的注入方式
|
||||||
|
/*@Primary
|
||||||
|
@Bean(Constant.PRIMARY_PAGINATION)
|
||||||
|
public Pagination primary(@Qualifier(Constant.ENTITY_MANAGER_PRIMARY_DB) EntityManager entityManager){
|
||||||
|
return new Pagination(entityManager);
|
||||||
|
}*/
|
||||||
|
@Primary
|
||||||
|
@Bean
|
||||||
|
public Pagination primaryPagination(){
|
||||||
|
return new Pagination(entityManagerPrimary);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
@Configuration //1.主要用于标记配置类,兼备Component的效果。
|
||||||
|
@EnableScheduling // 2.开启定时任务
|
||||||
|
public class StaticScheduleTask {
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0/5 * * * ?")
|
||||||
|
private void temp() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
import cn.palmte.work.service.map.MemorySimpleMap;
|
||||||
|
import cn.palmte.work.service.map.SimpleMap;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan at 2018/8/14 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SystemConfigWithMemory {
|
||||||
|
|
||||||
|
@Value("${fourcal.token.api.prefix}")
|
||||||
|
private String apiTokenPrefix;
|
||||||
|
|
||||||
|
@Value("#{${fourcal.token.api.expires}}")
|
||||||
|
private long apiExpires;
|
||||||
|
|
||||||
|
@Value("${fourcal.token.pc.prefix}")
|
||||||
|
private String pcTokenPrefix;
|
||||||
|
|
||||||
|
@Value("#{${fourcal.token.pc.expires}}")
|
||||||
|
private long pcExpires;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SimpleMap<String, String> simpleMap() {
|
||||||
|
return new MemorySimpleMap<>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
/*import cn.palmte.work.model.Manager;
|
||||||
|
import cn.palmte.work.service.CaptchaCodeService;
|
||||||
|
import cn.palmte.work.service.token.redis.ApiTokenManager;
|
||||||
|
import cn.palmte.work.service.token.redis.RedisCaptchaManager;
|
||||||
|
import cn.palmte.work.service.token.redis.RedisErrorCountManager;
|
||||||
|
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
import top.jfunc.token.CaptchaManger;
|
||||||
|
import top.jfunc.token.ErrorCountManager;
|
||||||
|
import top.jfunc.token.TokenManager;
|
||||||
|
|
||||||
|
import static cn.palmte.work.config.SystemConfigWithMemory.API_TOKEN_MANAGER;*/
|
||||||
|
|
||||||
|
|
||||||
|
/*@Configuration
|
||||||
|
public class SystemConfigWithRedis {
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
RedisConnectionFactory connectionFactory;
|
||||||
|
|
||||||
|
@Bean(name = "stringRedisTemplate")
|
||||||
|
public StringRedisTemplate stringRedisTemplate() {
|
||||||
|
return new StringRedisTemplate(connectionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "redisTemplate")
|
||||||
|
public RedisTemplate<Object, Object> redisTemplate(){
|
||||||
|
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||||
|
template.setConnectionFactory(connectionFactory);
|
||||||
|
//避免key出现乱码
|
||||||
|
template.setKeySerializer(new StringRedisSerializer());
|
||||||
|
//value使用FastJson转换
|
||||||
|
template.setValueSerializer(new GenericFastJsonRedisSerializer());
|
||||||
|
template.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
template.setHashValueSerializer(new GenericFastJsonRedisSerializer());
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
@Value("${fourcal.token.api.prefix}")
|
||||||
|
private String apiTokenPrefix;
|
||||||
|
|
||||||
|
@Value("#{${fourcal.token.api.expires}}")
|
||||||
|
private long apiExpires;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(Constant.API_TOKEN_MANAGER)
|
||||||
|
public TokenManager<Manager> apiTokenManagerRedis(){
|
||||||
|
ApiTokenManager apiTokenManager = new ApiTokenManager();
|
||||||
|
apiTokenManager.setRedisTemplate(redisTemplate());
|
||||||
|
apiTokenManager.setApiExpires(apiExpires);
|
||||||
|
apiTokenManager.setMulti(true);
|
||||||
|
apiTokenManager.setTokenPrefix(apiTokenPrefix);
|
||||||
|
return apiTokenManager;
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public ErrorCountManager errorCountManager() {
|
||||||
|
RedisErrorCountManager redisErrorCountManager = new RedisErrorCountManager();
|
||||||
|
redisErrorCountManager.setThreshold(3);
|
||||||
|
redisErrorCountManager.setRedisTemplate(redisTemplate());
|
||||||
|
return redisErrorCountManager;
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public CaptchaManger captchaManger(@Autowired CaptchaCodeService captchaCodeService) {
|
||||||
|
RedisCaptchaManager captchaManger = new RedisCaptchaManager();
|
||||||
|
captchaManger.setRedisTemplate(redisTemplate());
|
||||||
|
captchaManger.setCaptchaCodeService(captchaCodeService);
|
||||||
|
return captchaManger;
|
||||||
|
}
|
||||||
|
}*/
|
|
@ -0,0 +1,27 @@
|
||||||
|
package cn.palmte.work.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "upload")
|
||||||
|
public class UploadProperties {
|
||||||
|
private String path;
|
||||||
|
private String prefix;
|
||||||
|
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefix() {
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
public void setPrefix(String prefix) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
package cn.palmte.work.config.interceptor;
|
||||||
|
|
||||||
|
import cn.palmte.work.bean.ResponseMsg;
|
||||||
|
import cn.palmte.work.config.Constant;
|
||||||
|
import cn.palmte.work.config.log.LogExcluder;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||||
|
import top.jfunc.token.TokenManager;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static cn.palmte.work.config.Constant.HEADER_TOKEN;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan
|
||||||
|
*/
|
||||||
|
public abstract class AbstractLoginInterceptor extends HandlerInterceptorAdapter {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AbstractLoginInterceptor.class);
|
||||||
|
|
||||||
|
protected void printNeccery(HttpServletRequest request, LogExcluder logExcluder) {
|
||||||
|
//拦截特殊字符
|
||||||
|
String[] specialStr = {"|", "&", ";", "$", "%", "@", "'", "\"", "\\'", "\\\"", "<", ">", "(", ")", "+", "CR", "LF", ",", "\\"};
|
||||||
|
for (String s : specialStr) {
|
||||||
|
if (request.getRequestURI().contains(s)) {
|
||||||
|
logger.info("uri:" + request.getRequestURI() + "含有特殊字符:" + s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (logExcluder.needExcluded(request.getRequestURI())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("uri:" + request.getRequestURI() + ",token:" + request.getHeader(HEADER_TOKEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean verifyLogin(HttpServletResponse response, TokenManager<?> tokenManager, String token, boolean cors) throws IOException {
|
||||||
|
/// Object o = tokenManager.findByToken(token);
|
||||||
|
boolean exist = tokenManager.existByToken(token);
|
||||||
|
if (!exist) {
|
||||||
|
promptLogin(response, cors);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
tokenManager.updateExpires(token);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean verifyLogin(HttpServletResponse response, TokenManager<String> tokenManager, String token, boolean cors, String phone) throws IOException {
|
||||||
|
if (null == phone) {
|
||||||
|
promptLogin(response, cors);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
tokenManager.updateExpires(token);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void promptLogin(HttpServletResponse response, boolean cors) throws IOException {
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
if (cors) {
|
||||||
|
cors(response);
|
||||||
|
}
|
||||||
|
response.getWriter().write(JSON.toJSONString(ResponseMsg.buildMsg(Constant.Status.STATUS_PROMPT_LOGIN, "login first please", "")));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void promptNoPermission(HttpServletResponse response, boolean cors) throws IOException {
|
||||||
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
if (cors) {
|
||||||
|
cors(response);
|
||||||
|
}
|
||||||
|
response.getWriter().write(JSON.toJSONString(ResponseMsg.buildMsg(Constant.Status.STATUS_PROMPT_UNAUTH, "you have no permission", "")));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void promptLogin(HttpServletResponse response) throws IOException {
|
||||||
|
promptLogin(response, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理跨域
|
||||||
|
*
|
||||||
|
* @param response HttpServletResponse
|
||||||
|
*/
|
||||||
|
private void cors(HttpServletResponse response) {
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||||
|
response.setHeader("Access-Control-Allow-Methods", "POST,GET,DELETE,PUT,OPTIONS");
|
||||||
|
response.setHeader("Access-Control-Max-Age", "3600");
|
||||||
|
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package cn.palmte.work.config.interceptor;
|
||||||
|
|
||||||
|
import cn.palmte.work.config.log.LogExcluder;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印header中的token,有助于排查问题
|
||||||
|
* @author xiongshiyan
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TokenLoggingInterceptor extends AbstractLoginInterceptor {
|
||||||
|
@Autowired
|
||||||
|
private LogExcluder logExcluder;
|
||||||
|
/**
|
||||||
|
* 在Handler执行之前处理
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||||
|
throws Exception {
|
||||||
|
printNeccery(request , logExcluder);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package cn.palmte.work.config.log;
|
||||||
|
|
||||||
|
import cn.palmte.work.utils.StrKit;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志打印排除器,排除某些日志的打印
|
||||||
|
* @author xiongshiyan at 2018/12/23 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class LogExcluder implements InitializingBean{
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(LogExcluder.class);
|
||||||
|
|
||||||
|
@Value("${server.context-path:/fourcal}")
|
||||||
|
private String contextPath;
|
||||||
|
@Value("${fourcal.log.excluded.urls:}")
|
||||||
|
private String[] logExcludedUrls;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
if(isEmpty(logExcludedUrls)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StrKit.trim(logExcludedUrls);
|
||||||
|
logger.info(Arrays.asList(logExcludedUrls).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean needExcluded(String uri){
|
||||||
|
//没有需要排除的
|
||||||
|
if(isEmpty(logExcludedUrls)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//去除前端轮询的
|
||||||
|
if(uri.contains("api/pc/alarm/fetchAlarm")){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//去掉前缀
|
||||||
|
uri = uri.replace(contextPath , "");
|
||||||
|
return StrKit.targetInArray(logExcludedUrls , uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> boolean isEmpty(T[] array){
|
||||||
|
return null == array || 0 == array.length;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package cn.palmte.work.config.log;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan
|
||||||
|
* 统一打印日志
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
@Order(1)
|
||||||
|
public class WebLogAspect {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LogExcluder logExcluder;
|
||||||
|
|
||||||
|
@Pointcut("execution(public * cn.palmte.work.controller..*.*(..))")
|
||||||
|
public void webLog(){}
|
||||||
|
|
||||||
|
@Around(value = "webLog()")
|
||||||
|
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
HttpServletRequest request = attributes.getRequest();
|
||||||
|
|
||||||
|
if(logExcluder.needExcluded(request.getRequestURI())){
|
||||||
|
return proceedingJoinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("REQUEST : " + request.getRequestURI() + " : "
|
||||||
|
+(proceedingJoinPoint.getSignature().getDeclaringTypeName() + "." + proceedingJoinPoint.getSignature().getName() + " : ")
|
||||||
|
+ Arrays.toString(proceedingJoinPoint.getArgs()));
|
||||||
|
|
||||||
|
Object proceed = proceedingJoinPoint.proceed();
|
||||||
|
|
||||||
|
logger.info("RESPONSE : " + proceed);
|
||||||
|
return proceed;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,210 @@
|
||||||
|
package cn.palmte.work.controller.backend;
|
||||||
|
|
||||||
|
import cn.palmte.work.bean.ResponseMsg;
|
||||||
|
import cn.palmte.work.config.Constant;
|
||||||
|
import cn.palmte.work.model.Admin;
|
||||||
|
import cn.palmte.work.pojo.ModifyPasswordRequest;
|
||||||
|
import cn.palmte.work.service.AccountService;
|
||||||
|
import cn.palmte.work.service.AdminService;
|
||||||
|
import cn.palmte.work.service.SysRoleService;
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import top.jfunc.common.crypto.symmetric.DESAS;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/account")
|
||||||
|
public class AccountController extends BaseController {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AccountController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AccountService accountService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdminService adminService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRoleService sysRoleService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/updatePassword")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg updatePassword(HttpServletRequest request, ModifyPasswordRequest modifyPasswordRequest){
|
||||||
|
ResponseMsg responseMsg = new ResponseMsg();
|
||||||
|
try{
|
||||||
|
String privateKey = (String) request.getSession().getAttribute(Constant.PRIVATEKEY);
|
||||||
|
adminService.updatePassword(modifyPasswordRequest.getId(), modifyPasswordRequest.getPassword(),
|
||||||
|
modifyPasswordRequest.getNewPassword(), privateKey);
|
||||||
|
responseMsg.setStatus(0);
|
||||||
|
responseMsg.setMsg("密码修改成功");
|
||||||
|
}
|
||||||
|
catch(Exception e){
|
||||||
|
responseMsg.setStatus(1);
|
||||||
|
responseMsg.setMsg("密码修改失败:"+e.getMessage());
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/list")
|
||||||
|
public String list(@RequestParam(value = KEYWORDS, required = false) String keywords,
|
||||||
|
@RequestParam(value = PAGE_NUMBER, defaultValue = DEFAULT_PAGE_NUMBER) int pageNumber,
|
||||||
|
@RequestParam(value = PAGE_SIZE, defaultValue = DEFAULT_PAGE_SIZE) int pageSize,
|
||||||
|
Map<String, Object> model) {
|
||||||
|
// 初始化参数
|
||||||
|
setModel(keywords, model);
|
||||||
|
ConcurrentHashMap<String, String> searchInfo = getSearchInfo(keywords, model);
|
||||||
|
model.put("roleList", sysRoleService.getAllEnableSysRole());
|
||||||
|
model.put("pager", accountService.getAdminList(searchInfo, pageSize, pageNumber));
|
||||||
|
return "/admin/account_list";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存或更新用户
|
||||||
|
*/
|
||||||
|
@RequestMapping("/save")
|
||||||
|
public String save(@RequestParam("userId") int userId,Admin admin, HttpServletRequest request, Map<String, Object> model) throws IOException {
|
||||||
|
if(admin.getRoleId()<=0){
|
||||||
|
model.put("errorMessage","角色不能为空!");
|
||||||
|
return "/common/error";
|
||||||
|
}
|
||||||
|
//获取验证用户信息
|
||||||
|
String message = accountService.validateUserExistInfo(userId,admin);
|
||||||
|
if(StringUtils.isNotEmpty(message)){
|
||||||
|
model.put("errorMessage",message);
|
||||||
|
return "/common/error";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
String privateKey = (String) session.getAttribute(Constant.PRIVATEKEY);
|
||||||
|
|
||||||
|
accountService.saveOrUpdateAccount(userId,admin.getRoleId(),admin, privateKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("保存账号出错!" + e.toString());
|
||||||
|
return "新增账号出错!请联系管理员处理!";
|
||||||
|
}
|
||||||
|
return "redirect:/account/list";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转到新增页面
|
||||||
|
*/
|
||||||
|
@RequestMapping("/add")
|
||||||
|
public String add(HttpServletRequest request, Map<String, Object> model) {
|
||||||
|
genRSAKeyPair(request, model);
|
||||||
|
model.put("userId", -1);
|
||||||
|
model.put("account", new Admin());
|
||||||
|
//获取所有角色
|
||||||
|
model.put("roleList", sysRoleService.getAllEnableSysRole());
|
||||||
|
return "/admin/account_input";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用、禁用用户
|
||||||
|
*/
|
||||||
|
@RequestMapping("/changeStatus")
|
||||||
|
public ResponseMsg changeStatus(Admin admin) {
|
||||||
|
boolean locked = accountService.changeStatus(admin.getId(),admin.getEnabled());
|
||||||
|
if (locked) {
|
||||||
|
return ResponseMsg.buildSuccessMsg("操作成功");
|
||||||
|
} else {
|
||||||
|
return ResponseMsg.buildFailedMsg("操作失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询用户信息编辑
|
||||||
|
*/
|
||||||
|
@RequestMapping("/edit")
|
||||||
|
public String edit(@RequestParam("userId") int userId, Map<String, Object> model) {
|
||||||
|
model.put("userId", userId);
|
||||||
|
Admin admin = accountService.findUserById(userId);
|
||||||
|
model.put("roleId", String.valueOf(admin.getRoleId()));
|
||||||
|
model.put("roleType", admin.getRoleType());
|
||||||
|
model.put("roleLevel", admin.getRoleLevel());
|
||||||
|
model.put("realName", admin.getRealName());
|
||||||
|
model.put("userName", admin.getUserName());
|
||||||
|
model.put("telephone", admin.getTelephone());
|
||||||
|
model.put("regionId", admin.getRegionId());
|
||||||
|
model.put("account", admin);
|
||||||
|
//获取所有角色
|
||||||
|
model.put("roleList", sysRoleService.getAllEnableSysRole());
|
||||||
|
return "/admin/account_input";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据删除用户
|
||||||
|
*/
|
||||||
|
@RequestMapping("/delete")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg delete(@RequestParam("userId") int userId) {
|
||||||
|
ResponseMsg responseMsg = new ResponseMsg();
|
||||||
|
boolean deleted = accountService.deleteAccount(userId);
|
||||||
|
|
||||||
|
if (deleted) {
|
||||||
|
responseMsg.setStatus(0);
|
||||||
|
responseMsg.setMsg("删除成功");
|
||||||
|
} else {
|
||||||
|
responseMsg.setStatus(1);
|
||||||
|
responseMsg.setMsg("删除失败");
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID重置用户密码
|
||||||
|
*/
|
||||||
|
@RequestMapping("/resetPassword")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg resetPassword(@RequestParam("userId") int userId,HttpServletRequest request) {
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
String privateKey = (String) session.getAttribute(Constant.PRIVATEKEY);
|
||||||
|
boolean flag = accountService.resetPassword(userId,privateKey);
|
||||||
|
ResponseMsg responseMsg = new ResponseMsg();
|
||||||
|
if (flag) {
|
||||||
|
responseMsg.setStatus(0);
|
||||||
|
responseMsg.setMsg("重置密码成功");
|
||||||
|
} else {
|
||||||
|
responseMsg.setStatus(1);
|
||||||
|
responseMsg.setMsg("重置密码失败");
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码请求
|
||||||
|
*/
|
||||||
|
@RequestMapping("/password")
|
||||||
|
public String password(HttpServletRequest request,Map<String, Object> model){
|
||||||
|
Admin admin = adminService.getAdminById(InterfaceUtil.getAdminId());
|
||||||
|
try {
|
||||||
|
String id = new DESAS().encrypt(admin.getId().toString());
|
||||||
|
model.put("userId", id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
model.put("SysUser", admin);
|
||||||
|
genRSAKeyPair(request,model);
|
||||||
|
return "/admin/account_password";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setModel(@RequestParam(value = "keywords", required = false) String keywords, Map<String, Object> model) {
|
||||||
|
model.put("roleType", "-1");
|
||||||
|
model.put("keywords", keywords);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,259 @@
|
||||||
|
package cn.palmte.work.controller.backend;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.config.Constant;
|
||||||
|
import cn.palmte.work.model.Admin;
|
||||||
|
import cn.palmte.work.model.LoginLog;
|
||||||
|
import cn.palmte.work.model.SysRole;
|
||||||
|
import cn.palmte.work.model.SysRoleRepository;
|
||||||
|
import cn.palmte.work.pojo.LoginRequest;
|
||||||
|
import cn.palmte.work.pojo.LoginResponse;
|
||||||
|
import cn.palmte.work.service.AdminService;
|
||||||
|
import cn.palmte.work.service.LoginLogService;
|
||||||
|
import cn.palmte.work.utils.*;
|
||||||
|
import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||||
|
import org.apache.shiro.authc.LockedAccountException;
|
||||||
|
import org.apache.shiro.authc.UnknownAccountException;
|
||||||
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||||
|
import org.apache.shiro.subject.Subject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/admin")
|
||||||
|
public class AdminController extends BaseController {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
|
||||||
|
@Autowired
|
||||||
|
private AdminService adminService;
|
||||||
|
@Autowired
|
||||||
|
private LoginLogService loginLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRoleRepository sysRoleRepository;
|
||||||
|
|
||||||
|
@PostMapping(value = "/singIn")
|
||||||
|
public String singIn(RedirectAttributes attr, LoginRequest loginRequest, HttpServletRequest request) throws Exception {
|
||||||
|
String userName = loginRequest.getUserName();
|
||||||
|
String password = loginRequest.getPassword();
|
||||||
|
String message;
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
String privateKey = request.getSession().getAttribute(Constant.PRIVATEKEY).toString();
|
||||||
|
userName = new String(RSAUtils.decryptByPrivateKey(Base64Utils.decode(userName), privateKey));
|
||||||
|
password = new String(RSAUtils.decryptByPrivateKey(Base64Utils.decode(password), privateKey));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("解密出错", e);
|
||||||
|
attr.addAttribute("errorMessages", "用户名密码错误");
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
attr.addAttribute("userName", userName);
|
||||||
|
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
|
||||||
|
message = "用户名或密码错误!";
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
Admin admin = adminService.getAdminByUsername(userName);
|
||||||
|
if (null == admin) {
|
||||||
|
message = "用户名或密码错误~~~";
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
if (admin.getEnabled() == 0) {
|
||||||
|
message = "该用户已禁用~~~";
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
if (adminService.isLocked(admin)) {
|
||||||
|
message = "该用户已被锁定~~~";
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
int roleId = admin.getRoleId();
|
||||||
|
SysRole role = sysRoleRepository.findOne(roleId);
|
||||||
|
|
||||||
|
if (role.getIsEnable() == 0) {
|
||||||
|
message = "该用户绑定的角色已禁用~~~";
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
|
||||||
|
String salt = admin.getSalt();
|
||||||
|
request.getSession().setAttribute("realsName", admin.getRealName());
|
||||||
|
//request.getSession().setAttribute("telephone", admin.getTelephone());
|
||||||
|
request.getSession().setAttribute("lastLoginTime", admin.getLoginDate());
|
||||||
|
String newPassword;
|
||||||
|
try {
|
||||||
|
newPassword = DESCrypto.encryptPassword(password, salt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("加密出错", e);
|
||||||
|
message = "密码出错";
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean bool = checkUpdatePasswordTime(admin);
|
||||||
|
if (bool) {
|
||||||
|
request.getSession().setAttribute("message", "您已超过90天未修改密码!");
|
||||||
|
} else {
|
||||||
|
request.getSession().setAttribute("message", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
message = login(userName, newPassword, false, false);
|
||||||
|
if (!message.isEmpty()) {
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
|
||||||
|
//增加登录失败次数
|
||||||
|
adminService.addLoginError(admin);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
adminService.updateLoginInfo(admin, request);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.SUCCESS, "登录成功");
|
||||||
|
/**
|
||||||
|
* admin用户去检查,如果检查job有失败的,显示弹出框[1]
|
||||||
|
*/
|
||||||
|
return "redirect:/admin/center?uid=0";
|
||||||
|
} catch (Exception e) {
|
||||||
|
message = "登录发生未知错误,e=" + e.getMessage();
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
} catch (Throwable t) {
|
||||||
|
message = "登录发生未知错误,t=" + t.getMessage();
|
||||||
|
attr.addAttribute("errorMessages", message);
|
||||||
|
loginLogService.saveLog(userName, LoginLog.FAILED, message);
|
||||||
|
return "redirect:/admin/err";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算当前时间和最后一次修改密码的天数
|
||||||
|
* @param admin
|
||||||
|
* @return
|
||||||
|
* @throws ParseException
|
||||||
|
*/
|
||||||
|
public boolean checkUpdatePasswordTime(Admin admin) throws ParseException {
|
||||||
|
if (null != admin.getUpdatedPasswordTime()) {
|
||||||
|
int days = DateKit.daysBetween(admin.getUpdatedPasswordTime(), new Date());
|
||||||
|
if (days >= 90) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一的的登录方法
|
||||||
|
*
|
||||||
|
* @param returnJson 是否返回json格式的数据,否就是返回登录页面
|
||||||
|
*/
|
||||||
|
public String login(String username, String password, boolean rememberMe, boolean returnJson) {
|
||||||
|
//TODO:登录验证逻辑(待补充)
|
||||||
|
String errorMessage = "";
|
||||||
|
Subject subject = SecurityUtils.getSubject();
|
||||||
|
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
|
||||||
|
token.setRememberMe(rememberMe);
|
||||||
|
|
||||||
|
try {
|
||||||
|
subject.login(token);
|
||||||
|
} catch (UnknownAccountException | LockedAccountException ue) {
|
||||||
|
token.clear();
|
||||||
|
errorMessage = ue.getMessage();
|
||||||
|
} catch (IncorrectCredentialsException ie) {
|
||||||
|
token.clear();
|
||||||
|
errorMessage = "用户名或密码错误~~~";
|
||||||
|
} catch (RuntimeException re) {
|
||||||
|
re.printStackTrace();
|
||||||
|
token.clear();
|
||||||
|
errorMessage = "登录失败!";
|
||||||
|
}
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/login", method = {RequestMethod.GET})
|
||||||
|
public String login(HttpServletRequest request) throws Exception {
|
||||||
|
//TODO:登录页面初始化代码
|
||||||
|
InterfaceUtil.genRSAKeyPair(request);
|
||||||
|
return "/admin/admin_login";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/center", method = RequestMethod.GET)
|
||||||
|
public String center(@ModelAttribute("userName") String userName, @RequestParam("uid") int uid,
|
||||||
|
@RequestParam(value = "showJobMonitorError", defaultValue = "0") int showJobMonitorError, Map<String, Object> model) {
|
||||||
|
logger.info("------------------------------------------重定向到首页信息查询center方法内部-----------------------用户名====" + userName);
|
||||||
|
|
||||||
|
LoginResponse loginResponse = adminService.initMenuList(uid);
|
||||||
|
model.put("userName", userName);
|
||||||
|
model.put("loginResponse", loginResponse);
|
||||||
|
if (uid == 0) {
|
||||||
|
uid = (loginResponse.getTopMenuList() != null && loginResponse.getTopMenuList().size() > 0) ? loginResponse.getTopMenuList().get(0).getId() : 0;
|
||||||
|
}
|
||||||
|
model.put("uid", uid);
|
||||||
|
model.put("showJobMonitorError", showJobMonitorError);
|
||||||
|
logger.info("------------------------------------------跳转到admin_index-----------------------");
|
||||||
|
return "/admin/admin_index";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/topMenu", method = RequestMethod.GET)
|
||||||
|
public String topMenu(@RequestParam("uid") int uid, Map<String, Object> model) {
|
||||||
|
LoginResponse loginResponse = adminService.initMenuList(uid);
|
||||||
|
model.put("loginResponse", loginResponse);
|
||||||
|
return "/admin/admin_index";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/console", method = RequestMethod.GET)
|
||||||
|
public String console(@RequestParam("uid") int uid, Map<String, Object> model, HttpServletRequest request) {
|
||||||
|
logger.info(uid + "");
|
||||||
|
model.put("statistic", "");
|
||||||
|
return "/admin/console";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/err", method = RequestMethod.GET)
|
||||||
|
public String loginErr(HttpServletRequest request, @ModelAttribute("errorMessages") String errorMessages) {
|
||||||
|
InterfaceUtil.genRSAKeyPair(request);
|
||||||
|
request.setAttribute("base", request.getContextPath());
|
||||||
|
return "/admin/admin_login";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 管理员退出
|
||||||
|
@RequestMapping(value = "/logout", method = RequestMethod.GET)
|
||||||
|
public String logout(HttpServletRequest request) {
|
||||||
|
// ShiroPrincipal principal = (ShiroPrincipal) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
// // 如果已经登录,则跳转到管理首页
|
||||||
|
// if(principal != null){
|
||||||
|
// SecurityUtils.getSubject().logout();
|
||||||
|
// }
|
||||||
|
return "redirect:/admin/login";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成随机验证码图片
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = "/captcha", method = RequestMethod.GET)
|
||||||
|
public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
new CaptchaUtils().getRandCode(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,157 @@
|
||||||
|
package cn.palmte.work.controller.backend;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.config.Constant;
|
||||||
|
import cn.palmte.work.model.Admin;
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import cn.palmte.work.utils.RSAUtils;
|
||||||
|
import cn.palmte.work.utils.Utils;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
|
||||||
|
public class BaseController {
|
||||||
|
public static final String KEYWORDS = "keywords";
|
||||||
|
public static final String PAGE_NUMBER = "pageNumber";
|
||||||
|
public static final String PAGE_SIZE = "pageSize";
|
||||||
|
public static final String PAGER = "pager";
|
||||||
|
public static final String DEFAULT_PAGE_NUMBER = "1";
|
||||||
|
public static final String DEFAULT_PAGE_SIZE = "10";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the request.
|
||||||
|
*
|
||||||
|
* @return the request
|
||||||
|
*/
|
||||||
|
protected HttpServletRequest getRequest() {
|
||||||
|
return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the response.
|
||||||
|
*
|
||||||
|
* @return the response
|
||||||
|
*/
|
||||||
|
protected HttpServletResponse getResponse() {
|
||||||
|
return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the session
|
||||||
|
*
|
||||||
|
* @return the session
|
||||||
|
*/
|
||||||
|
protected HttpSession getSession() {
|
||||||
|
return getRequest().getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理下载文件的http header
|
||||||
|
*
|
||||||
|
* @param response HttpServletResponse
|
||||||
|
* @param fileName 文件名
|
||||||
|
*/
|
||||||
|
protected void downloadHearder(HttpServletResponse response, String fileName, String contentType) {
|
||||||
|
response.setContentType(contentType);
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
try {
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + java.net.URLEncoder.encode(fileName, "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see BaseController {@link #downloadHearder(HttpServletResponse, String, String)}
|
||||||
|
*/
|
||||||
|
protected void downloadHearder(HttpServletResponse response, String fileName) {
|
||||||
|
downloadHearder(response, fileName, "application/octet-stream");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ConcurrentHashMap<String, String> getSearchInfo(String keywords, Map<String, Object> model) {
|
||||||
|
ConcurrentHashMap<String, String> searchMap = Utils.parseMap(keywords);
|
||||||
|
setModers(searchMap, model);
|
||||||
|
return searchMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存搜索条件到model
|
||||||
|
*/
|
||||||
|
public void setModers(ConcurrentHashMap<String, String> searchInfo, Map<String, Object> model) {
|
||||||
|
for (Map.Entry<String, String> item : searchInfo.entrySet()) {
|
||||||
|
model.put(item.getKey(), item.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存搜索条件到request
|
||||||
|
*/
|
||||||
|
public void setAttrs(Map<String, String> searchInfo) {
|
||||||
|
HttpServletRequest request = getRequest();
|
||||||
|
for (Map.Entry<String, String> item : searchInfo.entrySet()) {
|
||||||
|
request.setAttribute(item.getKey(), item.getValue());
|
||||||
|
}
|
||||||
|
keepKeywords(searchInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getSearchInfo(String keywords) {
|
||||||
|
|
||||||
|
Map<String, String> searchMap = Utils.parseMap(keywords);
|
||||||
|
setAttrs(searchMap);
|
||||||
|
return searchMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将搜索条件按“keywords”保存 ,分页才能带上搜索条件
|
||||||
|
*/
|
||||||
|
protected void keepKeywords(Map<String, String> map) {
|
||||||
|
HttpServletRequest request = getRequest();
|
||||||
|
request.setAttribute(KEYWORDS, JSON.toJSONString(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void genRSAKeyPair(HttpServletRequest request, Map<String, Object> model) {
|
||||||
|
/* 生成KeyPair */
|
||||||
|
Map<String, Object> keyMap;
|
||||||
|
try {
|
||||||
|
keyMap = RSAUtils.genKeyPair();
|
||||||
|
String publicKey = RSAUtils.getPublicKey(keyMap);
|
||||||
|
String privateKey = RSAUtils.getPrivateKey(keyMap);
|
||||||
|
|
||||||
|
/* 保存私钥到session */
|
||||||
|
request.getSession().setAttribute(Constant.PRIVATEKEY, privateKey);
|
||||||
|
|
||||||
|
/* 公钥给前端页面 */
|
||||||
|
model.put(Constant.PUBLICKEY, publicKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户对象
|
||||||
|
*/
|
||||||
|
public Admin getAdmin() {
|
||||||
|
return InterfaceUtil.getAdmin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户对象Id
|
||||||
|
*/
|
||||||
|
public int getAdminId() {
|
||||||
|
return InterfaceUtil.getAdmin().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package cn.palmte.work.controller.backend;
|
||||||
|
|
||||||
|
import cn.palmte.work.bean.ResponseMsg;
|
||||||
|
import cn.palmte.work.config.Constant;
|
||||||
|
import cn.palmte.work.config.UploadProperties;
|
||||||
|
import cn.palmte.work.pojo.UploadResult;
|
||||||
|
import cn.palmte.work.utils.UploadUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author pengqiang
|
||||||
|
* @date 2018/4/21
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/file")
|
||||||
|
public class FileController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UploadProperties uploadProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
* @return 返回状态和下载地址
|
||||||
|
*/
|
||||||
|
@PostMapping("/upload")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg upload(@RequestParam(value = "files[]") MultipartFile[] multipartfiles) {
|
||||||
|
ResponseMsg responseMsg = ResponseMsg.buildFailedMsg("failed");
|
||||||
|
if (null != multipartfiles && multipartfiles.length > 0) {
|
||||||
|
MultipartFile file = multipartfiles[0];
|
||||||
|
UploadResult result = UploadUtil.upload(file,
|
||||||
|
uploadProperties.getPath() , uploadProperties.getPrefix());
|
||||||
|
if (Constant.STATUS_SUCCESS == result.getStatus()) {
|
||||||
|
responseMsg = ResponseMsg.buildSuccessMsg("成功", result);
|
||||||
|
} else {
|
||||||
|
responseMsg.setMsg(result.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package cn.palmte.work.controller.backend;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/")
|
||||||
|
public class IndexController extends BaseController{
|
||||||
|
@GetMapping(value = "/")
|
||||||
|
public String index() throws Exception {
|
||||||
|
return "redirect:/admin/login";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
package cn.palmte.work.controller.backend;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.bean.ResponseMsg;
|
||||||
|
import cn.palmte.work.model.SysPermission;
|
||||||
|
import cn.palmte.work.model.SysPermissionRepository;
|
||||||
|
import cn.palmte.work.service.SysPermissionService;
|
||||||
|
import cn.palmte.work.service.SysRolePermissionService;
|
||||||
|
import cn.palmte.work.utils.DateKit;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理
|
||||||
|
*@author nsp
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/permission")
|
||||||
|
|
||||||
|
public class SysPermissionController extends BaseController{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysPermissionService sysPermissionService;
|
||||||
|
@Autowired
|
||||||
|
private SysPermissionRepository sysPermissionRepository;
|
||||||
|
@Autowired
|
||||||
|
private SysRolePermissionService sysRolePermissionService;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SysPermissionController.class);
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("/list")
|
||||||
|
public String list(@RequestParam(value = "keywords",required = false) String keywords,
|
||||||
|
@RequestParam(value = "pageNumber",defaultValue = "1") String pageNumber,
|
||||||
|
@RequestParam(value = "sql", required = false) String sql,
|
||||||
|
Map<String, Object> model){
|
||||||
|
// 初始化参数
|
||||||
|
setModel(keywords, model);
|
||||||
|
ConcurrentHashMap<String, String> searchInfo = getSearchInfo(keywords,model);
|
||||||
|
model.put("pager",sysPermissionService.getAllPermissionListByPage(searchInfo,pageNumber));
|
||||||
|
model.put("sql", sql);
|
||||||
|
|
||||||
|
return "/admin/sys_permission_list";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setModel(String keywords, Map<String, Object> model){
|
||||||
|
model.put("pmsLevel","0");
|
||||||
|
model.put("pmsType","0");
|
||||||
|
model.put("pmsDeleted","-1");
|
||||||
|
model.put("permissionID","-1");
|
||||||
|
model.put("keywords",keywords);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/add")
|
||||||
|
public String add( Map<String, Object> model){
|
||||||
|
SysPermission permission=new SysPermission();
|
||||||
|
model.put("permissionID","-1");
|
||||||
|
model.put("permission",permission);
|
||||||
|
model.put("ps", sysPermissionRepository.findPermissions());
|
||||||
|
return "/admin/sys_permission_input";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/save")
|
||||||
|
public String save(@RequestParam("permissionID") String permissionID,
|
||||||
|
SysPermission sysPermission, RedirectAttributes attr) throws IOException{
|
||||||
|
|
||||||
|
final SysPermission parent = sysPermissionRepository.findOne(sysPermission.getParentId());
|
||||||
|
sysPermission.setLevel(parent.getLevel()+1);
|
||||||
|
int type = (parent.getLevel()==4) ? 2 : 1;
|
||||||
|
sysPermission.setType(type);
|
||||||
|
|
||||||
|
if ("-1".equals(permissionID)){
|
||||||
|
getSql(sysPermission, attr, parent);
|
||||||
|
sysPermissionService.addPermission(sysPermission); //新增
|
||||||
|
}else {
|
||||||
|
sysPermissionService.updatePermission(sysPermission,permissionID); // 修改
|
||||||
|
}
|
||||||
|
return "redirect:/permission/list";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getSql(SysPermission sysPermission, RedirectAttributes attr, SysPermission parent) {
|
||||||
|
String sql1 = "INSERT INTO `sys_permission` (`name`, `icon`, `url`, `permission`, `parent_id`, `level`, `type`, `sort`, `remark`, `is_deleted`, `created_by`, `created_time`, `last_updated_by`, `last_updated_time`) VALUES ('{name}', '', '{url}', '{permission}', (SELECT id FROM sys_permission sp WHERE sp.permission = '{parentPermission}'), '{level}', '{type}', '{sort}', '', b'0', '1', '{time}', '1', '{time}');"
|
||||||
|
.replace("{name}", sysPermission.getName())
|
||||||
|
.replace("{url}", sysPermission.getUrl())
|
||||||
|
.replace("{permission}", sysPermission.getPermission())
|
||||||
|
.replace("{parentPermission}", parent.getPermission())
|
||||||
|
.replace("{level}", sysPermission.getLevel()+"")
|
||||||
|
.replace("{type}", sysPermission.getType()+"")
|
||||||
|
.replace("{sort}", sysPermission.getSort()+"")
|
||||||
|
.replace("{time}", DateKit.toStr(new Date(), DateKit.TIME_FORMAT));
|
||||||
|
|
||||||
|
String sql2 = "INSERT INTO `sys_role_permission` (`role_id`, `permission_id`, `is_deleted`, `created_by`, `created_time`, `last_updated_by`, `last_updated_time`) VALUES ('1', (SELECT id FROM sys_permission WHERE permission = '{permission}'), b'0', '1', '{time}', '1', '{time}');"
|
||||||
|
.replace("{permission}", sysPermission.getPermission())
|
||||||
|
.replace("{time}", DateKit.toStr(new Date(), DateKit.TIME_FORMAT));
|
||||||
|
attr.addAttribute("sql", sql1 + "</br>" + sql2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/edit")
|
||||||
|
public String edit(@RequestParam("id") String permissionID,Map<String, Object> model){
|
||||||
|
SysPermission permission =sysPermissionRepository.findOne(Integer.parseInt(permissionID));
|
||||||
|
model.put("permissionID",permissionID);
|
||||||
|
model.put("permission",permission);
|
||||||
|
model.put("ps", sysPermissionRepository.findPermissions());
|
||||||
|
return "/admin/sys_permission_input";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/delete")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg delete(@RequestParam("ids") String ids){
|
||||||
|
String[] deleteIds=ids.split("#%#");
|
||||||
|
boolean deleted = sysPermissionService.deletePermissionByIDs(deleteIds);
|
||||||
|
boolean bDel = sysRolePermissionService.deleteSysRolePermissionByIDs(deleteIds);
|
||||||
|
|
||||||
|
ResponseMsg responseMsge=new ResponseMsg();
|
||||||
|
if(deleted && bDel){
|
||||||
|
logger.info("删除成功");
|
||||||
|
responseMsge.setStatus(0);
|
||||||
|
responseMsge.setMsg("删除成功");
|
||||||
|
} else{
|
||||||
|
responseMsge.setStatus(1);
|
||||||
|
responseMsge.setMsg("删除失败");
|
||||||
|
}
|
||||||
|
return responseMsge;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,262 @@
|
||||||
|
package cn.palmte.work.controller.backend;
|
||||||
|
|
||||||
|
import cn.palmte.work.bean.Constant;
|
||||||
|
import cn.palmte.work.bean.ResponseMsg;
|
||||||
|
import cn.palmte.work.model.SysRole;
|
||||||
|
import cn.palmte.work.pojo.PermissionNode;
|
||||||
|
import cn.palmte.work.pojo.RoleBean;
|
||||||
|
import cn.palmte.work.service.AdminService;
|
||||||
|
import cn.palmte.work.service.SysRoleService;
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色管理
|
||||||
|
* @author nsp
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/role")
|
||||||
|
public class SysRoleController extends BaseController{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRoleService sysRoleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdminService adminService;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SysRoleController.class);
|
||||||
|
private static final int[] ROLE_TYPE_ARRAY = new int[] { Constant.ROLE_TYPE_CMCC_ADMIN,Constant.ROLE_TYPE_ZJPT_ADMIN};
|
||||||
|
|
||||||
|
@RequestMapping("/list")
|
||||||
|
public String list(@RequestParam(value = "keywords",required = false) String keywords,
|
||||||
|
@RequestParam(value = PAGE_NUMBER, defaultValue = DEFAULT_PAGE_NUMBER) int pageNumber,
|
||||||
|
@RequestParam(value = PAGE_SIZE, defaultValue = DEFAULT_PAGE_SIZE) int pageSize,
|
||||||
|
Map<String, Object> model) {
|
||||||
|
logger.info("获取角色列表");
|
||||||
|
//当前登录人的角色类型
|
||||||
|
model.put("keywords",keywords);
|
||||||
|
SysRole adminSysRole=adminService.getRole(InterfaceUtil.getAdminId()+"");
|
||||||
|
ConcurrentHashMap<String, String> searchInfo = getSearchInfo(keywords,model);
|
||||||
|
model.put("pager",sysRoleService.list(searchInfo,pageNumber,pageSize));
|
||||||
|
return "admin/role_list";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/add")
|
||||||
|
public String add( Map<String, Object> model){
|
||||||
|
//当前登录人的角色
|
||||||
|
SysRole adminSysRole=adminService.getRole(InterfaceUtil.getAdminId()+"");
|
||||||
|
PermissionNode root= sysRoleService.getPermissionNodeTree(adminSysRole.getId());
|
||||||
|
List<RoleBean> roleLevels = getRoleLevels(adminSysRole.getId(), 0);
|
||||||
|
List<RoleBean> roleTypes = getRoleTypes(adminSysRole.getId(), adminSysRole.getType(),0);
|
||||||
|
SysRole role = new SysRole();
|
||||||
|
model.put("permnode",root);
|
||||||
|
model.put("roleID",-1);
|
||||||
|
model.put("isActive",1);
|
||||||
|
model.put("level",roleLevels);//默认 省级
|
||||||
|
model.put("type",roleTypes);//角色类型
|
||||||
|
model.put("role",role);
|
||||||
|
model.put("selectedType",roleLevels.get(0).getValue());
|
||||||
|
|
||||||
|
return "/admin/role_input";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/edit")
|
||||||
|
public String edit(@RequestParam(value = "id")int id, Map<String, Object> model){
|
||||||
|
//当前登录人的角色
|
||||||
|
SysRole adminSysRole=adminService.getRole(InterfaceUtil.getAdminId()+"");
|
||||||
|
SysRole role = sysRoleService.fingSysRoleById(id);
|
||||||
|
PermissionNode root = sysRoleService.getPermissionNodeTreeForEdit(adminSysRole.getId(), id);
|
||||||
|
List<RoleBean> roleLevels = getRoleLevels(adminSysRole.getId(), role.getLevel());
|
||||||
|
List<RoleBean> roleTypes = getRoleTypes(adminSysRole.getId(),adminSysRole.getType(), role.getType());
|
||||||
|
model.put("permnode",root);
|
||||||
|
model.put("roleID",id);
|
||||||
|
model.put("roleName",role.getName());
|
||||||
|
model.put("level",roleLevels);
|
||||||
|
model.put("type",roleTypes);
|
||||||
|
model.put("selectedType",role.getType());
|
||||||
|
model.put("role",role);
|
||||||
|
return "admin/role_input";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/save")
|
||||||
|
public String save(@RequestParam Map<String, Object> reqMap,@RequestParam(value = "roleID")int roleID
|
||||||
|
) {
|
||||||
|
logger.info("新增编辑保存,roleID="+roleID);
|
||||||
|
sysRoleService.addOrUpdatePermission(reqMap,roleID);
|
||||||
|
return "redirect:/role/list";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/check")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg check(@RequestParam(value = "role_id")String role_id, @RequestParam(value = "role_name")String role_name,
|
||||||
|
HttpServletResponse response) throws Exception{
|
||||||
|
int result=sysRoleService.cheakRoleName(Integer.parseInt(role_id),role_name);
|
||||||
|
ResponseMsg responseMsg=new ResponseMsg();
|
||||||
|
if (result>0){
|
||||||
|
responseMsg.setStatus(0);
|
||||||
|
responseMsg.setMsg("该角色名已存在,请重新输入!");
|
||||||
|
}else {
|
||||||
|
responseMsg.setStatus(1);
|
||||||
|
responseMsg.setMsg("");
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/delete")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg delete(@RequestParam("ids") String ids){
|
||||||
|
ResponseMsg responseMsge=new ResponseMsg();
|
||||||
|
if ("".equals(ids)){
|
||||||
|
responseMsge.setStatus(1);
|
||||||
|
responseMsge.setMsg("删除失败,无选中项!");
|
||||||
|
}else {
|
||||||
|
String[] deleteIds=ids.split("#%#");
|
||||||
|
String msg = sysRoleService.deleteSelectedPermission(deleteIds);
|
||||||
|
responseMsge.setStatus(0);
|
||||||
|
responseMsge.setMsg(msg);
|
||||||
|
}
|
||||||
|
return responseMsge;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Title: 根据当前管理员所属角色的等级,获取角色等级列表
|
||||||
|
* @Description:角色等级(省级1>地级市级2>区县级3>网点级4),获取角色等级列表时,只能获取级别小于等于当前级别的
|
||||||
|
* @param adminRoleId
|
||||||
|
* 当前管理员角色ID
|
||||||
|
* @param selectedLevel
|
||||||
|
* 默认选中等级
|
||||||
|
* @return List<PermissionLevel>
|
||||||
|
*/
|
||||||
|
private List<RoleBean> getRoleLevels(int adminRoleId, int selectedLevel){
|
||||||
|
SysRole role = sysRoleService.fingSysRoleById(adminRoleId);
|
||||||
|
int adminLevel = role.getLevel();
|
||||||
|
if(selectedLevel == 0){
|
||||||
|
selectedLevel = adminLevel;
|
||||||
|
}
|
||||||
|
List<RoleBean> roleLevels = new ArrayList<RoleBean>(3);
|
||||||
|
for(int i = adminLevel; i <= 3; i++){
|
||||||
|
String name = getRoleLevelName(i);
|
||||||
|
if(null != name){
|
||||||
|
RoleBean permissionLevel = new RoleBean(name, i);
|
||||||
|
if(selectedLevel == i){
|
||||||
|
permissionLevel.setSelected(true);
|
||||||
|
}
|
||||||
|
roleLevels.add(permissionLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return roleLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色类型列表
|
||||||
|
* @param adminRoleId
|
||||||
|
* @param selectedType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<RoleBean> getRoleTypes(int adminRoleId,int adminRoleType, int selectedType){
|
||||||
|
SysRole role = sysRoleService.fingSysRoleById(adminRoleId);
|
||||||
|
int roleType = role.getType();
|
||||||
|
if(selectedType == 0){
|
||||||
|
selectedType = roleType;
|
||||||
|
}
|
||||||
|
List<RoleBean> roleLevels = new ArrayList<RoleBean>(4);
|
||||||
|
for(int i = 0; i < ROLE_TYPE_ARRAY.length; i++){
|
||||||
|
if (adminRoleType<ROLE_TYPE_ARRAY[i]){
|
||||||
|
String name = getRoleTypeName(ROLE_TYPE_ARRAY[i]);
|
||||||
|
if(null != name){
|
||||||
|
RoleBean roleTypeBean = new RoleBean(name, ROLE_TYPE_ARRAY[i]);
|
||||||
|
if(selectedType == ROLE_TYPE_ARRAY[i]){
|
||||||
|
roleTypeBean.setSelected(true);
|
||||||
|
}
|
||||||
|
roleLevels.add(roleTypeBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return roleLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目前末梢渠道中默认都为省级
|
||||||
|
* 根据type值获取角色类型名称
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getRoleTypeName(int type){
|
||||||
|
String typeName = null;
|
||||||
|
switch(type){
|
||||||
|
case Constant.ROLE_TYPE_CMCC_ADMIN:
|
||||||
|
typeName = "移动管理员";
|
||||||
|
break;
|
||||||
|
case Constant.ROLE_TYPE_ZJPT_ADMIN:
|
||||||
|
typeName = "资金平台管理员";
|
||||||
|
break;
|
||||||
|
default:typeName = null;
|
||||||
|
}
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据Level值获取角色等级名称
|
||||||
|
* @param level
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getRoleLevelName(int level){
|
||||||
|
String levelName = null;
|
||||||
|
switch(level){
|
||||||
|
case 1:
|
||||||
|
levelName = "省级";
|
||||||
|
break;
|
||||||
|
/*case 2:
|
||||||
|
levelName = "地市级";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
levelName = "区县级";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
levelName = "网点级";
|
||||||
|
break;*/
|
||||||
|
default:levelName = null;
|
||||||
|
}
|
||||||
|
return levelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用 禁用
|
||||||
|
*/
|
||||||
|
@RequestMapping("/enableOrDisable")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseMsg enableOrDisable(@RequestParam("id") int id,
|
||||||
|
@RequestParam("enabled") int status, RedirectAttributes attr) {
|
||||||
|
boolean isSuccess = false;
|
||||||
|
try {
|
||||||
|
isSuccess = sysRoleService.enableOrDisable(status, id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.getMessage();
|
||||||
|
}
|
||||||
|
if (isSuccess) {
|
||||||
|
return ResponseMsg.buildSuccessMsg("操作成功");
|
||||||
|
} else {
|
||||||
|
return ResponseMsg.buildSuccessMsg("操作失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package cn.palmte.work.exception;
|
||||||
|
|
||||||
|
import cn.palmte.work.config.Constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan
|
||||||
|
* 使用的时候直接抛出异常ResponseException(如果想携带ResultCode,Message,Data等信息)
|
||||||
|
*/
|
||||||
|
public class ResponseException extends RuntimeException{
|
||||||
|
private int status = Constant.Status.STATUS_FAILED;
|
||||||
|
private Object data = null;
|
||||||
|
|
||||||
|
public ResponseException(int resultCode, String message, Object data){
|
||||||
|
super(message);
|
||||||
|
this.status = resultCode;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
public ResponseException(int status, String message){
|
||||||
|
this(status, message, null);
|
||||||
|
}
|
||||||
|
public ResponseException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
public int getStatus(){
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
public void setStatus(int status){ this.status = status; }
|
||||||
|
public Object getData(){
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
public void setData(Object data){
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,282 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/7/17.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "sys_user")
|
||||||
|
public class Admin implements Serializable{
|
||||||
|
public static final int ENABLED = 1;
|
||||||
|
public static final int DISABLED = 0;
|
||||||
|
public static final int LOCKED = 1;
|
||||||
|
public static final int UN_LOCKED = 0;
|
||||||
|
//删除
|
||||||
|
public static final int DELETED = 1;
|
||||||
|
//未删
|
||||||
|
public static final int UN_DELETED = 0;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 8788969524794365369L;
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@GenericGenerator(name = "persistenceGenerator", strategy = "increment")
|
||||||
|
private Integer id;
|
||||||
|
@Column(name = "user_name")
|
||||||
|
private String userName;
|
||||||
|
private String password;
|
||||||
|
private String salt;
|
||||||
|
@Column(name = "real_name")
|
||||||
|
private String realName;
|
||||||
|
private String telephone;
|
||||||
|
private int enabled;
|
||||||
|
@Column(name = "login_error_count")
|
||||||
|
private int loginErrorCount;
|
||||||
|
private int locked;
|
||||||
|
@Column(name = "locked_date")
|
||||||
|
private Date lockedDate;
|
||||||
|
@Column(name = "login_date")
|
||||||
|
private Date loginDate;
|
||||||
|
@Column(name = "login_ip")
|
||||||
|
private String loginIp;
|
||||||
|
@Column(name = "is_deleted")
|
||||||
|
private boolean isDeleted;
|
||||||
|
@Column(name = "created_by")
|
||||||
|
private Integer createdBy;
|
||||||
|
@Column(name = "created_time")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date createdTime;
|
||||||
|
@Column(name = "last_updated_by")
|
||||||
|
private Integer lastUpdatedBy;
|
||||||
|
@Column(name = "last_updated_time")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date lastUpdatedTime;
|
||||||
|
@Column(name = "region_id")
|
||||||
|
private int regionId;
|
||||||
|
@Column(name = "region_name")
|
||||||
|
private String regionName;
|
||||||
|
|
||||||
|
@Column(name = "updated__password_time")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date updatedPasswordTime;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private int roleId;
|
||||||
|
@Transient
|
||||||
|
private String roleName;
|
||||||
|
@Transient
|
||||||
|
private int roleType;
|
||||||
|
@Transient
|
||||||
|
private int roleLevel;
|
||||||
|
@Transient
|
||||||
|
private String roleTypeName;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSalt() {
|
||||||
|
return salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSalt(String salt) {
|
||||||
|
this.salt = salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRealName() {
|
||||||
|
return realName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRealName(String realName) {
|
||||||
|
this.realName = realName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTelephone() {
|
||||||
|
return telephone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTelephone(String telephone) {
|
||||||
|
this.telephone = telephone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(int enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLoginErrorCount() {
|
||||||
|
return loginErrorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginErrorCount(int loginErrorCount) {
|
||||||
|
this.loginErrorCount = loginErrorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLocked() {
|
||||||
|
return locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocked(int locked) {
|
||||||
|
this.locked = locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLockedDate() {
|
||||||
|
return lockedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLockedDate(Date lockedDate) {
|
||||||
|
this.lockedDate = lockedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLoginDate() {
|
||||||
|
return loginDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginDate(Date loginDate) {
|
||||||
|
this.loginDate = loginDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLoginIp() {
|
||||||
|
return loginIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoginIp(String loginIp) {
|
||||||
|
this.loginIp = loginIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeleted() {
|
||||||
|
return isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
isDeleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(Integer createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(Date createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLastUpdatedBy() {
|
||||||
|
return lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedBy(Integer lastUpdatedBy) {
|
||||||
|
this.lastUpdatedBy = lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(Date lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedPasswordTime() {
|
||||||
|
return updatedPasswordTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdatedPasswordTime(Date updatedPasswordTime) {
|
||||||
|
this.updatedPasswordTime = updatedPasswordTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleName() {
|
||||||
|
return roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleName(String roleName) {
|
||||||
|
this.roleName = roleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRoleId() {
|
||||||
|
return roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleId(int roleId) {
|
||||||
|
this.roleId = roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRoleLevel() {
|
||||||
|
return roleLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleLevel(int roleLevel) {
|
||||||
|
this.roleLevel = roleLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRoleType() {
|
||||||
|
return roleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleType(int roleType) {
|
||||||
|
this.roleType = roleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleTypeName() {
|
||||||
|
return roleTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleTypeName(String roleTypeName) {
|
||||||
|
this.roleTypeName = roleTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRegionId() {
|
||||||
|
return regionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegionId(int regionId) {
|
||||||
|
this.regionId = regionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRegionName() {
|
||||||
|
return regionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegionName(String regionName) {
|
||||||
|
this.regionName = regionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface AdminRepository extends JpaRepository<Admin, Integer> {
|
||||||
|
@Query("from Admin where isDeleted=0 AND enabled=1 AND userName=?1")
|
||||||
|
Admin getAdminByUsername(String username);
|
||||||
|
|
||||||
|
@Query("from Admin where isDeleted=0 AND enabled=1 AND userName=?1")
|
||||||
|
List<Admin> getAdminByUsernameList(String username);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Query("from Admin where isDeleted=0 AND userName=?1")
|
||||||
|
List<Admin> getAdminByUsernameListNoEnabled(String username);
|
||||||
|
|
||||||
|
@Query("from Admin where isDeleted=0 AND realName=?1")
|
||||||
|
Admin getAdminByRealName(String realName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过id查询
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Query("from Admin where isDeleted=0 AND id=?1")
|
||||||
|
Admin getAdminById(int id);
|
||||||
|
|
||||||
|
@Query("from Admin where isDeleted=0 AND telephone=?1")
|
||||||
|
Admin findByTelephone(String phone);
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import cn.palmte.work.model.SysRole;
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public interface AdminRepositoryCustom {
|
||||||
|
|
||||||
|
List<String> getAuthoritiesName(String adminId);
|
||||||
|
|
||||||
|
List<String> getAuthoritieUrls(String adminId);
|
||||||
|
|
||||||
|
List<String> getRolesName(String adminId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询用户信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Admin findAdminByUserName(String userName);
|
||||||
|
|
||||||
|
|
||||||
|
SysRole getRole(String adminId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有账号
|
||||||
|
* @param searchInfo
|
||||||
|
* @param pageSize
|
||||||
|
* @param pageNum
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page getAdminList(ConcurrentHashMap<String, String> searchInfo, int pageSize, int pageNum);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询用户信息
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Admin findAdminById(int userId);
|
||||||
|
|
||||||
|
List<SysPermission> getAuthoritieUrlsByParentPermission(String adminId, String permission);
|
||||||
|
}
|
|
@ -0,0 +1,250 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import cn.palmte.work.utils.ObjectKit;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class AdminRepositoryImpl implements AdminRepositoryCustom {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AdminRepositoryImpl.class);
|
||||||
|
@Autowired
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAuthoritiesName(String adminId) {
|
||||||
|
List<String> returnList = new ArrayList<>();
|
||||||
|
String sql = " select p.permission from sys_user u, sys_user_role ur, sys_role r, sys_role_permission rp, sys_permission p "
|
||||||
|
+ " where u.is_deleted = 0 and ur.is_deleted = 0 and r.is_deleted = 0 and rp.is_deleted = 0 and p.is_deleted = 0 "
|
||||||
|
+ " and u.id = ur.user_id and ur.role_id = r.id and r.id = rp.role_id and rp.permission_id = p.id "
|
||||||
|
+ " and r.is_enable=1 and u.id=:adminId";
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("adminId", adminId);
|
||||||
|
List<String> resultList = nativeQuery.getResultList();
|
||||||
|
for (String objects : resultList) {
|
||||||
|
String permission = objects;
|
||||||
|
returnList.add(permission);
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAuthoritieUrls(String adminId) {
|
||||||
|
List<String> returnList = new ArrayList<>();
|
||||||
|
String sql = " select p.url from sys_user u, sys_user_role ur, sys_role r, sys_role_permission rp, sys_permission p "
|
||||||
|
+ " where u.is_deleted = 0 and ur.is_deleted = 0 and r.is_deleted = 0 and rp.is_deleted = 0 and p.is_deleted = 0 "
|
||||||
|
+ " and u.id = ur.user_id and ur.role_id = r.id and r.id = rp.role_id and rp.permission_id = p.id "
|
||||||
|
+ " and r.is_enable=1 and u.id=:adminId";
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("adminId", adminId);
|
||||||
|
List<String> resultList = nativeQuery.getResultList();
|
||||||
|
for (String objects : resultList) {
|
||||||
|
String permission = objects;
|
||||||
|
returnList.add(permission);
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRolesName(String adminId) {
|
||||||
|
String sql = " select r.name,r.id from sys_user u, sys_user_role ur, sys_role r where u.is_deleted = 0 " +
|
||||||
|
"and ur.is_deleted = 0 and r.is_deleted = 0 and r.is_enable=1 and u.id = ur.user_id and " +
|
||||||
|
" r.id = ur.role_id and u.id=:id";
|
||||||
|
List<String> returnList = new ArrayList<>();
|
||||||
|
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("id", adminId);
|
||||||
|
List<Object[]> resultList = nativeQuery.getResultList();
|
||||||
|
for (Object[] objects : resultList) {
|
||||||
|
String permission = (objects != null && objects.length > 0) ? objects[0].toString() : "";
|
||||||
|
returnList.add(permission);
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Admin findAdminByUserName(String userName) {
|
||||||
|
String sql = " select u.id,u.user_name,u.real_name,r.type,r.id as rId,r.name,u.salt,r.level from sys_user u, sys_user_role ur, sys_role r where u.is_deleted = 0 " +
|
||||||
|
"and ur.is_deleted = 0 and r.is_deleted = 0 and u.id = ur.user_id and " +
|
||||||
|
" r.id = ur.role_id and u.user_name=:userName";
|
||||||
|
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("userName", userName);
|
||||||
|
List<Object[]> resultList = nativeQuery.getResultList();
|
||||||
|
Admin admin = null;
|
||||||
|
if (!resultList.isEmpty()) {
|
||||||
|
for (Object[] objects : resultList) {
|
||||||
|
admin = new Admin();
|
||||||
|
admin.setId(ObjectKit.toInt(objects[0]));
|
||||||
|
admin.setUserName(ObjectKit.toString(objects[1]));
|
||||||
|
admin.setRealName(ObjectKit.toString(objects[2]));
|
||||||
|
admin.setRoleType(ObjectKit.toInt(objects[3]));
|
||||||
|
admin.setRoleId(ObjectKit.toInt(objects[4]));
|
||||||
|
admin.setRoleName(ObjectKit.toString(objects[5]));
|
||||||
|
admin.setSalt(ObjectKit.toString(objects[6]));
|
||||||
|
admin.setRoleLevel(ObjectKit.toInt(objects[7]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysRole getRole(String adminId) {
|
||||||
|
String sql = " select r.* from sys_user u, sys_user_role ur, sys_role r where u.is_deleted = 0 " +
|
||||||
|
"and ur.is_deleted = 0 and r.is_deleted = 0 and r.is_enable=1 and u.id = ur.user_id and " +
|
||||||
|
" r.id = ur.role_id and u.id=:id";
|
||||||
|
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql, SysRole.class);
|
||||||
|
nativeQuery.setParameter("id", adminId);
|
||||||
|
SysRole object = (SysRole) nativeQuery.getSingleResult();
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page getAdminList(ConcurrentHashMap<String, String> searchInfo, int pageSize, int pageNum) {
|
||||||
|
Page page = new Page(pageNum, pageSize);
|
||||||
|
int thisPage = (pageNum - 1) * pageSize;
|
||||||
|
String sql = getSelect() + getSqlExceptSelect(searchInfo) + " limit " + thisPage + "," + pageSize;
|
||||||
|
String countSql = " SELECT COUNT(*) FROM(" + getSelect() + getSqlExceptSelect(searchInfo) + ") count_table";
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql.toString());
|
||||||
|
Query countQuery = entityManager.createNativeQuery(countSql);
|
||||||
|
List<Object[]> resultList = nativeQuery.getResultList();
|
||||||
|
List<Admin> admins = new ArrayList<>();
|
||||||
|
Admin admin = null;
|
||||||
|
page.setTotalRow(((BigInteger) countQuery.getSingleResult()).intValue());
|
||||||
|
for (Object[] objects : resultList) {
|
||||||
|
admin = new Admin();
|
||||||
|
admin.setId(ObjectKit.toInt(objects[0]));
|
||||||
|
admin.setUserName(ObjectKit.toString(objects[1]));
|
||||||
|
admin.setEnabled(ObjectKit.toInt(objects[4]));
|
||||||
|
admin.setRealName(ObjectKit.toString(objects[2]));
|
||||||
|
admin.setTelephone(ObjectKit.toString(objects[7]));
|
||||||
|
admin.setRoleName(ObjectKit.toString(objects[6]));
|
||||||
|
try {
|
||||||
|
admin.setCreatedTime(ObjectKit.toDate(objects[3]));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
logger.error("账号创建时间转换错误" + e.toString());
|
||||||
|
}
|
||||||
|
admins.add(admin);
|
||||||
|
}
|
||||||
|
page.setList(admins);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelect() {
|
||||||
|
String select = " select u.id,u.user_name,u.real_name,u.created_time,u.enabled,r.type,r.name,u.telephone,u.region_name";
|
||||||
|
return select;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSqlExceptSelect(ConcurrentHashMap<String, String> searchInfo) {
|
||||||
|
StringBuffer sqlExceptSelect = new StringBuffer(" from sys_user u LEFT JOIN sys_user_role ur on u.id = ur.user_id LEFT JOIN sys_role r on r.id = ur.role_id ");
|
||||||
|
|
||||||
|
Admin admin = InterfaceUtil.getAdmin();
|
||||||
|
|
||||||
|
//String sql = " where u.is_deleted = 0 and ur.is_deleted = 0 and r.is_deleted = 0 and r.is_enable=1 and u.id!=1 and u.id!=" + InterfaceUtil.getAdminId();
|
||||||
|
String sql = " where u.is_deleted = 0 and ur.is_deleted = 0 and r.is_deleted = 0 and r.is_enable=1 ";
|
||||||
|
sqlExceptSelect.append(sql);
|
||||||
|
for (Map.Entry<String, String> item : searchInfo.entrySet()) {
|
||||||
|
sqlExceptSelect.append(buildQuery(item));
|
||||||
|
}
|
||||||
|
sqlExceptSelect.append(" order by u.id desc ");
|
||||||
|
return sqlExceptSelect.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildQuery(Map.Entry<String, String> item) {
|
||||||
|
String sql = "";
|
||||||
|
if (item.getKey().equals("userName")) {
|
||||||
|
sql += " and u.user_name like '%" + item.getValue() + "%' ";
|
||||||
|
} else if (item.getKey().equals("telephone")) {
|
||||||
|
sql += " and u.telephone= " + item.getValue();
|
||||||
|
} else if (item.getKey().equals("regionId")) {
|
||||||
|
if (!item.getValue().equals("-1")) {
|
||||||
|
sql += " and u.region_id= " + item.getValue();
|
||||||
|
}
|
||||||
|
} else if (item.getKey().equals("roleId")) {
|
||||||
|
if (!item.getValue().equals("-1")) {
|
||||||
|
sql += " and r.id= " + item.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定角色的所有用户
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<Admin> getAllRolesByType(int type) {
|
||||||
|
String sql = "select * from sys_user u " +
|
||||||
|
" left join sys_user_role ur on ur.user_id=u.id" +
|
||||||
|
" left join sys_role r on r.id = ur.role_id" +
|
||||||
|
" where u.is_deleted = 0 and ur.is_deleted = 0 and r.is_deleted = 0 and r.is_enable=1" +
|
||||||
|
" and r.type=:type";
|
||||||
|
|
||||||
|
return entityManager.createNativeQuery(sql, Admin.class).setParameter("type", type).getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Admin findAdminById(int userId) {
|
||||||
|
String sql = " select u.id,u.user_name,u.real_name,r.type,r.id as rId,u.telephone,u.region_id,r.level from sys_user u, sys_user_role ur, sys_role r where u.is_deleted = 0 " +
|
||||||
|
"and ur.is_deleted = 0 and r.is_deleted = 0 and r.is_enable=1 and u.id = ur.user_id and " +
|
||||||
|
" r.id = ur.role_id and u.id=:userId";
|
||||||
|
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("userId", userId);
|
||||||
|
List<Object[]> resultList = nativeQuery.getResultList();
|
||||||
|
Admin admin = null;
|
||||||
|
if (!resultList.isEmpty()) {
|
||||||
|
for (Object[] objects : resultList) {
|
||||||
|
admin = new Admin();
|
||||||
|
admin.setId(ObjectKit.toInt(objects[0]));
|
||||||
|
admin.setUserName(ObjectKit.toString(objects[1]));
|
||||||
|
admin.setRealName(ObjectKit.toString(objects[2]));
|
||||||
|
admin.setRoleType(ObjectKit.toInt(objects[3]));
|
||||||
|
admin.setRoleId(ObjectKit.toInt(objects[4]));
|
||||||
|
admin.setTelephone(ObjectKit.toString(objects[5]));
|
||||||
|
admin.setRegionId(ObjectKit.toInt(objects[6]));
|
||||||
|
admin.setRoleLevel(ObjectKit.toInt(objects[7]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysPermission> getAuthoritieUrlsByParentPermission(String adminId, String permission) {
|
||||||
|
List<SysPermission> returnList = new ArrayList<>();
|
||||||
|
String sql = " select distinct p.url,p.name,p.permission,p.sort from sys_user u, sys_user_role ur, sys_role r, sys_role_permission rp, sys_permission p "
|
||||||
|
+ " where u.is_deleted = 0 and ur.is_deleted = 0 and r.is_deleted = 0 and rp.is_deleted = 0 and p.is_deleted = 0 "
|
||||||
|
+ " and u.id = ur.user_id and ur.role_id = r.id and r.id = rp.role_id and rp.permission_id = p.id "
|
||||||
|
+ " and r.is_enable=1 and u.id=:adminId and p.parent_id = (select id from sys_permission sp where sp.permission=:permission)";
|
||||||
|
Query nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("adminId", adminId);
|
||||||
|
nativeQuery.setParameter("permission", permission);
|
||||||
|
List<Object[]> resultList = nativeQuery.getResultList();
|
||||||
|
for (Object[] objects : resultList) {
|
||||||
|
SysPermission sysPermission = new SysPermission();
|
||||||
|
sysPermission.setUrl((String) objects[0]);
|
||||||
|
sysPermission.setName((String) objects[1]);
|
||||||
|
sysPermission.setPermission((String) objects[2]);
|
||||||
|
sysPermission.setSort((Integer) objects[3]);
|
||||||
|
returnList.add(sysPermission);
|
||||||
|
}
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ZM
|
||||||
|
* @date 2018/9/21
|
||||||
|
*/
|
||||||
|
public class ExcelEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
private ExportExcelBean exportExcelBean;
|
||||||
|
|
||||||
|
public ExcelEvent(Object source, ExportExcelBean exportExcelBean) {
|
||||||
|
super(source);
|
||||||
|
this.exportExcelBean = exportExcelBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportExcelBean getExportExcelBean() {
|
||||||
|
return exportExcelBean;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报表导出数据结构
|
||||||
|
*/
|
||||||
|
public class ExportExcelBean {
|
||||||
|
/**
|
||||||
|
* 任务Id
|
||||||
|
*/
|
||||||
|
private String taskId;
|
||||||
|
/**
|
||||||
|
* 报表头
|
||||||
|
*/
|
||||||
|
private String[] headers;//
|
||||||
|
/**
|
||||||
|
* 字段名
|
||||||
|
*/
|
||||||
|
private String[] columns;//
|
||||||
|
/**
|
||||||
|
* 查询SQL语句
|
||||||
|
*/
|
||||||
|
private String sql;
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
private String fileName;
|
||||||
|
/**
|
||||||
|
* 文件输出路径,绝对路径
|
||||||
|
*/
|
||||||
|
private String exportFilePath;
|
||||||
|
/**
|
||||||
|
* 文件下载地址
|
||||||
|
*/
|
||||||
|
private String exportFileUrl;
|
||||||
|
/**
|
||||||
|
* 谁操作的
|
||||||
|
*/
|
||||||
|
private int who;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出人的名字
|
||||||
|
*/
|
||||||
|
private String realName;
|
||||||
|
|
||||||
|
public ExportExcelBean(String taskId, String[] headers, String[] columns, String sql, String fileName, String exportFilePath, String exportFileUrl, int who, String realName) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.headers = headers;
|
||||||
|
this.columns = columns;
|
||||||
|
this.sql = sql;
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.exportFilePath = exportFilePath;
|
||||||
|
this.exportFileUrl = exportFileUrl;
|
||||||
|
this.who = who;
|
||||||
|
this.realName = realName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskId() { return this.taskId;}
|
||||||
|
|
||||||
|
public String[] getHeaders() {
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getColumns() {
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSql() {
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportFilePath() {
|
||||||
|
return exportFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExportFileUrl() {
|
||||||
|
return exportFileUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWho(){return who;}
|
||||||
|
|
||||||
|
public String getRealName() {
|
||||||
|
return realName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录日志
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "login_log")
|
||||||
|
public class LoginLog {
|
||||||
|
public static final int FAILED = 1;
|
||||||
|
public static final int SUCCESS = 0;
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@GenericGenerator(name = "persistenceGenerator", strategy = "increment")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
@Column(name = "status_desc")
|
||||||
|
private String statusDesc;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name = "create_time")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
|
||||||
|
public LoginLog() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusDesc() {
|
||||||
|
return statusDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatusDesc(String statusDesc) {
|
||||||
|
this.statusDesc = statusDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface LoginLogRepository extends JpaRepository<LoginLog,Integer> {
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 滑动验证码相关
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "slide_captcha")
|
||||||
|
public class SlideCaptcha {
|
||||||
|
public static final int STATUS_INIT = 0;
|
||||||
|
public static final int STATUS_SUCCESS = 1;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@GenericGenerator(name = "persistenceGenerator", strategy = "increment")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "serial_number")
|
||||||
|
private String serialNumber;
|
||||||
|
private String identifier;
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int status;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name = "modify_time")
|
||||||
|
private Date modifyTime;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSerialNumber() {
|
||||||
|
return serialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSerialNumber(String serialNumber) {
|
||||||
|
this.serialNumber = serialNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(int y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getModifyTime() {
|
||||||
|
return modifyTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModifyTime(Date modifyTime) {
|
||||||
|
this.modifyTime = modifyTime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface SlideCaptchaRepository extends JpaRepository<SlideCaptcha, Integer> {
|
||||||
|
SlideCaptcha findFirstBySerialNumberEquals(String identifier);
|
||||||
|
}
|
|
@ -0,0 +1,201 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "sys_permission")
|
||||||
|
public class SysPermission {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "icon")
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
@Column(name = "url")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Column(name = "permission")
|
||||||
|
private String permission;
|
||||||
|
|
||||||
|
@Column(name = "parent_id")
|
||||||
|
private int parentId;
|
||||||
|
|
||||||
|
@Column(name = "level")
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
@Column(name = "type")
|
||||||
|
private int type;
|
||||||
|
|
||||||
|
@Column(name = "sort")
|
||||||
|
private int sort;
|
||||||
|
|
||||||
|
@Column(name = "remark")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@Column(name = "is_deleted")
|
||||||
|
private int isDeleted;
|
||||||
|
|
||||||
|
@Column(name = "created_by")
|
||||||
|
private int createdBy;
|
||||||
|
|
||||||
|
@Column(name = "created_time")
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_by")
|
||||||
|
private int lastUpdatedBy;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_time")
|
||||||
|
private Date lastUpdatedTime;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private String creator;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private String updator;
|
||||||
|
|
||||||
|
public SysPermission() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermission(String permission) {
|
||||||
|
this.permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getParentId() {
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentId(int parentId) {
|
||||||
|
this.parentId = parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(int level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSort() {
|
||||||
|
return sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSort(int sort) {
|
||||||
|
this.sort = sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsDeleted() {
|
||||||
|
return isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDeleted(int isDeleted) {
|
||||||
|
this.isDeleted = isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(int createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(Date createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastUpdatedBy() {
|
||||||
|
return lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedBy(int lastUpdatedBy) {
|
||||||
|
this.lastUpdatedBy = lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(Date lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreator() {
|
||||||
|
return creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreator(String creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUpdator() {
|
||||||
|
return updator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdator(String updator) {
|
||||||
|
this.updator = updator;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface SysPermissionRepository extends JpaRepository<SysPermission, Integer> {
|
||||||
|
|
||||||
|
|
||||||
|
@Query(" from SysPermission sp where sp.isDeleted=0 AND sp.level=?1 order by sort asc")
|
||||||
|
public List<SysPermission> findSysPermissionByLevel(int level);
|
||||||
|
|
||||||
|
@Query(" from SysPermission sp where sp.isDeleted=0 AND (sp.parentId=?1 OR sp.parentId in (select id from SysPermission where isDeleted = 0 and parentId in?1 )) order by sort asc")
|
||||||
|
public List<SysPermission> findSysPermissionByParentId(int parentId);
|
||||||
|
|
||||||
|
|
||||||
|
@Query(" from SysPermission where isDeleted=0 AND id in (select permissionId FROM SysRolePermission WHERE isDeleted=0 AND roleId =?1 ) ORDER BY level ASC,sort ASC ")
|
||||||
|
public List<SysPermission> findPermissionByRoleId(int roleId);
|
||||||
|
|
||||||
|
|
||||||
|
@Query(" from SysPermission sp where sp.isDeleted=0 order by sort asc")
|
||||||
|
public List<SysPermission> findAllPermission();
|
||||||
|
|
||||||
|
@Query(" select sp.url from SysPermission sp where sp.isDeleted=0 order by sort asc")
|
||||||
|
public List<String> findAllPermissionUrls();
|
||||||
|
|
||||||
|
|
||||||
|
@Query(" from SysPermission sp where sp.isDeleted=0 AND sp.level<5 order by id asc")
|
||||||
|
List<SysPermission> findPermissions();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public interface SysPermissionRepositoryCustom {
|
||||||
|
/**
|
||||||
|
* 分页获取所有资源列表
|
||||||
|
* @param searchInfo
|
||||||
|
* @param pageNumber
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Page<SysPermission> getAllPermissionListByPage(ConcurrentHashMap<String, String> searchInfo, String pageNumber);
|
||||||
|
}
|
|
@ -0,0 +1,133 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.utils.DateKit;
|
||||||
|
import cn.palmte.work.utils.ObjectKit;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class SysPermissionRepositoryImpl implements SysPermissionRepositoryCustom {
|
||||||
|
@Autowired
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<SysPermission> getAllPermissionListByPage(ConcurrentHashMap<String, String> searchInfo, String pageNumber) {
|
||||||
|
|
||||||
|
Page<SysPermission> pager = new Page(Integer.parseInt(pageNumber));
|
||||||
|
int pageSize=pager.getPageSize();
|
||||||
|
int thisPage = (Integer.parseInt(pageNumber) - 1) * pageSize;
|
||||||
|
String sql=getSelect()+getSqlExceptSelect(searchInfo)+ " limit " + thisPage + "," + pageSize;
|
||||||
|
String countSql=" SELECT COUNT(*) FROM("+getSelect()+getSqlExceptSelect(searchInfo)+") count_table";
|
||||||
|
Query nativeQuery= entityManager.createNativeQuery(sql);
|
||||||
|
Query countQuery= entityManager.createNativeQuery(countSql);
|
||||||
|
BigInteger totalRow=new BigInteger("0");
|
||||||
|
List<Object[]> list= nativeQuery.getResultList();
|
||||||
|
List<SysPermission> resultList=new ArrayList();
|
||||||
|
if (null!=list&&list.size()>0){
|
||||||
|
// 总条数
|
||||||
|
totalRow=(BigInteger)countQuery.getSingleResult();
|
||||||
|
for (Object[] objs:list){
|
||||||
|
SysPermission permission=new SysPermission();
|
||||||
|
permission.setId(ObjectKit.toInt(objs[0]));
|
||||||
|
permission.setName(ObjectKit.toString(objs[1]));
|
||||||
|
permission.setUrl(ObjectKit.toString(objs[3]));
|
||||||
|
permission.setPermission(ObjectKit.toString(objs[4]));
|
||||||
|
permission.setParentId(ObjectKit.toInt(objs[5]));
|
||||||
|
permission.setLevel(ObjectKit.toInt(objs[6]));
|
||||||
|
permission.setType(ObjectKit.toInt(objs[7]));
|
||||||
|
permission.setSort(ObjectKit.toInt(objs[8]));
|
||||||
|
permission.setRemark(ObjectKit.toString(objs[9]));
|
||||||
|
if(objs[10]!=null){
|
||||||
|
if((Boolean) objs[10]){
|
||||||
|
permission.setIsDeleted(1);
|
||||||
|
}else {
|
||||||
|
permission.setIsDeleted(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Date createTime = null;
|
||||||
|
Date lastUpdateTime = null;
|
||||||
|
try {
|
||||||
|
if(objs[12]!=null){
|
||||||
|
createTime = DateKit.getDate(objs[12].toString());
|
||||||
|
}
|
||||||
|
if(objs[14]!=null){
|
||||||
|
lastUpdateTime = DateKit.getDate(objs[14].toString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
permission.setCreatedTime(createTime);
|
||||||
|
permission.setCreator(ObjectKit.toString(objs[15]));
|
||||||
|
permission.setUpdator(ObjectKit.toString(objs[16]));
|
||||||
|
permission.setLastUpdatedTime(lastUpdateTime);
|
||||||
|
resultList.add(permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pager.setList(resultList);
|
||||||
|
pager.setTotalRow(totalRow.intValue());
|
||||||
|
return pager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getSelect(){
|
||||||
|
String select = " select p.*, (select user_name from sys_user u where p.created_by = u.id) as creator, "
|
||||||
|
+ " (select user_name from sys_user u where p.last_updated_by = u.id) as updator ";
|
||||||
|
return select;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getSqlExceptSelect(ConcurrentHashMap<String, String> searchInfo){
|
||||||
|
// StringBuffer sqlExceptSelect=new StringBuffer(" from sys_permission p where 1=1 and is_deleted= 0 ");
|
||||||
|
StringBuffer sqlExceptSelect=new StringBuffer(" from sys_permission p where 1=1 ");
|
||||||
|
for(Map.Entry<String, String> item : searchInfo.entrySet()){
|
||||||
|
sqlExceptSelect.append(buildQuery(item));
|
||||||
|
}
|
||||||
|
sqlExceptSelect.append( " order by p.created_time desc");
|
||||||
|
|
||||||
|
return sqlExceptSelect.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String buildQuery(Map.Entry<String, String> item){
|
||||||
|
StringBuffer sql= new StringBuffer("");
|
||||||
|
if(item.getKey().equals("pmsName")){
|
||||||
|
sql.append( " and p.name like '%" + item.getValue() + "%' ");
|
||||||
|
} else if(item.getKey().equals("pmsParentID")){
|
||||||
|
sql.append( " and p.parent_id = " + item.getValue());
|
||||||
|
} else if(item.getKey().equals("pmsLevel") && !"0".equals(item.getValue())){
|
||||||
|
sql.append( " and p.level = " + item.getValue());
|
||||||
|
} else if(item.getKey().equals("pmsType") && !"0".equals(item.getValue())){
|
||||||
|
sql.append( " and p.type = " + item.getValue());
|
||||||
|
} else if(item.getKey().equals("pmsID")){
|
||||||
|
sql.append( " and p.id = " + item.getValue());
|
||||||
|
} else if(item.getKey().equals("pmsUrl")){
|
||||||
|
sql.append( " and p.url = '" + item.getValue() + "' ");
|
||||||
|
} else if(item.getKey().equals("pmsDeleted") && !"-1".equals(item.getValue())){
|
||||||
|
sql.append( " and p.is_deleted = " + item.getValue() + " ");
|
||||||
|
}else if(item.getKey().equals("pmsCode")){
|
||||||
|
sql.append( " and p.permission = '" + item.getValue() + "' ");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "sys_role")
|
||||||
|
public class SysRole {
|
||||||
|
//智慧工地系统管理员
|
||||||
|
public static final int ROLE_TYPE_1 = 1;
|
||||||
|
//市级管理员
|
||||||
|
public static final int ROLE_TYPE_2 = 2;
|
||||||
|
//环保局管理员
|
||||||
|
public static final int ROLE_TYPE_3 = 3;
|
||||||
|
//网格管理员
|
||||||
|
public static final int ROLE_TYPE_4 = 4;
|
||||||
|
//工地巡查员
|
||||||
|
public static final int ROLE_TYPE_8 = 8;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id;
|
||||||
|
@Column(name = "name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "type")
|
||||||
|
private int type;
|
||||||
|
|
||||||
|
@Column(name = "level")
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
@Column(name = "is_enable")
|
||||||
|
private int isEnable;
|
||||||
|
|
||||||
|
@Column(name = "is_deleted")
|
||||||
|
private int deleted;
|
||||||
|
|
||||||
|
@Column(name = "created_by")
|
||||||
|
private int createdBy;
|
||||||
|
|
||||||
|
@Column(name = "created_time")
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_by")
|
||||||
|
private int lastUpdatedBy;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_time")
|
||||||
|
private Date lastUpdatedTime;
|
||||||
|
|
||||||
|
public SysRole() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(int level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsEnable() {
|
||||||
|
return isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsEnable(int isEnable) {
|
||||||
|
this.isEnable = isEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeleted() {
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(int deleted) {
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(int createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(Date createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastUpdatedBy() {
|
||||||
|
return lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedBy(int lastUpdatedBy) {
|
||||||
|
this.lastUpdatedBy = lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(Date lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,100 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "sys_role_permission")
|
||||||
|
public class SysRolePermission {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id;
|
||||||
|
@Column(name = "role_id")
|
||||||
|
private int roleId;
|
||||||
|
|
||||||
|
@Column(name = "permission_id")
|
||||||
|
private int permissionId;
|
||||||
|
|
||||||
|
@Column(name = "is_deleted")
|
||||||
|
private int isDeleted;
|
||||||
|
|
||||||
|
@Column(name = "created_by")
|
||||||
|
private int createdBy;
|
||||||
|
|
||||||
|
@Column(name = "created_time")
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_by")
|
||||||
|
private int lastUpdatedBy;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_time")
|
||||||
|
private Date lastUpdatedTime;
|
||||||
|
|
||||||
|
public SysRolePermission() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRoleId() {
|
||||||
|
return roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleId(int roleId) {
|
||||||
|
this.roleId = roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPermissionId() {
|
||||||
|
return permissionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissionId(int permissionId) {
|
||||||
|
this.permissionId = permissionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsDeleted() {
|
||||||
|
return isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDeleted(int isDeleted) {
|
||||||
|
this.isDeleted = isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(int createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(Date createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastUpdatedBy() {
|
||||||
|
return lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedBy(int lastUpdatedBy) {
|
||||||
|
this.lastUpdatedBy = lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(Date lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public interface SysRolePermissionRepository extends JpaRepository<SysRolePermission, Integer> {
|
||||||
|
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query(" delete from SysRolePermission where permissionId = ?1 ")
|
||||||
|
public int deleteSysRolePermissionByPermissionId(int permission_id);
|
||||||
|
|
||||||
|
@Query(" from SysRolePermission where roleId=?1 ")
|
||||||
|
public List<SysRolePermission> findPerListByRoleId(int role_id);
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query(" delete from SysRolePermission where roleId=?1")
|
||||||
|
public int deleteSysRolePermissionByRoleId(int role_id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface SysRolePermissionRepositoryCustom {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class SysRolePermissionRepositoryImpl implements SysRolePermissionRepositoryCustom {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SysRolePermissionRepositoryImpl.class);
|
||||||
|
@Autowired
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface SysRoleRepository extends JpaRepository<SysRole, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询所有角色
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Query(" from SysRole sp where sp.deleted=0 order by last_updated_time asc")
|
||||||
|
public List<SysRole> findAllRole();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色id获取角色对象
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Query(" from SysRole sp where sp.deleted=0 and sp.id=?1 ")
|
||||||
|
public SysRole findSysRoleById(int id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色类型查询所有角色
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Query(" from SysRole role where role.deleted=0 and type=?1 order by last_updated_time asc")
|
||||||
|
List<SysRole> findRoleByType(int type);
|
||||||
|
|
||||||
|
@Query(" select COUNT(1) from SysRole where id!=?1 and name=?2 and deleted=0 ")
|
||||||
|
public int cheakRoleName(int id, String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询 后台系统管理员的角色(后台角色表中只能有一个系统管理员角色)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Query(" from SysRole where deleted=0 and isEnable=1 AND type=0 ")
|
||||||
|
public SysRole findSuperAdminRole();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有启用状态的后台角色
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Query(" from SysRole where deleted=0 and isEnable=1 and type = 1")
|
||||||
|
List<SysRole> getAllEnableSysRole();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public interface SysRoleRepositoryCustom {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取所有角色列表
|
||||||
|
* @param searchInfo
|
||||||
|
* @param pageNumber
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Page<SysRole> getAllRoleListByPage(ConcurrentHashMap<String, String> searchInfo, String pageNumber, int roleType);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前角色登记获取下级所有角色类型
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysRole> geBelowRoleTypes(int roleType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前角色类型下级角色
|
||||||
|
* @param roleType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysRole> getBelowTypes(int roleType);
|
||||||
|
}
|
|
@ -0,0 +1,195 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import cn.palmte.work.utils.DateKit;
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import cn.palmte.work.utils.ObjectKit;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class SysRoleRepositoryImpl implements SysRoleRepositoryCustom {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SysRoleRepositoryImpl.class);
|
||||||
|
@Autowired
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<SysRole> getAllRoleListByPage(ConcurrentHashMap<String, String> searchInfo, String pageNumber, int roleType) {
|
||||||
|
|
||||||
|
Page<SysRole> pager = new Page(Integer.parseInt(pageNumber));
|
||||||
|
int pageSize=pager.getPageSize();
|
||||||
|
int thisPage = (Integer.parseInt(pageNumber) - 1) * pageSize;
|
||||||
|
String sql=getSelect()+getSqlExceptSelect(searchInfo,roleType)+ " limit " + thisPage + "," + pageSize;
|
||||||
|
String countSql=" SELECT COUNT(*) FROM("+getSelect()+getSqlExceptSelect(searchInfo,roleType)+") count_table";
|
||||||
|
Query nativeQuery= entityManager.createNativeQuery(sql);
|
||||||
|
Query countQuery= entityManager.createNativeQuery(countSql);
|
||||||
|
// 总条数
|
||||||
|
BigInteger totalRow=new BigInteger("0");
|
||||||
|
List<Object[]> list= nativeQuery.getResultList();
|
||||||
|
List<SysRole> resultList=new ArrayList();
|
||||||
|
if (!list.isEmpty()){
|
||||||
|
totalRow=(BigInteger)countQuery.getSingleResult();
|
||||||
|
for (Object[] objs:list){
|
||||||
|
SysRole role=new SysRole();
|
||||||
|
role.setId(ObjectKit.toInt(objs[0]));
|
||||||
|
role.setName(ObjectKit.toString(objs[1]));
|
||||||
|
role.setType(ObjectKit.toInt(objs[2]));
|
||||||
|
role.setLevel(ObjectKit.toInt(objs[3]));
|
||||||
|
role.setIsEnable(ObjectKit.toInt(objs[4]));
|
||||||
|
role.setDeleted(ObjectKit.toInt(objs[5]));
|
||||||
|
role.setCreatedBy(ObjectKit.toInt(objs[6]));
|
||||||
|
role.setLastUpdatedBy(ObjectKit.toInt(objs[8]));
|
||||||
|
|
||||||
|
Date createTime = null;
|
||||||
|
Date lastUpdateTime = null;
|
||||||
|
try {
|
||||||
|
if (objs[7] != null) {
|
||||||
|
createTime = DateKit.getDate(objs[7].toString());
|
||||||
|
}
|
||||||
|
if (objs[9] != null) {
|
||||||
|
lastUpdateTime = DateKit.getDate(objs[9].toString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
role.setCreatedTime(createTime);
|
||||||
|
role.setLastUpdatedTime(lastUpdateTime);
|
||||||
|
resultList.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pager.setList(resultList);
|
||||||
|
pager.setTotalRow(totalRow.intValue());
|
||||||
|
return pager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysRole> geBelowRoleTypes(int roleType) {
|
||||||
|
ConcurrentHashMap<String, String> searchInfo = new ConcurrentHashMap<>();
|
||||||
|
String sql = "select * from sys_role where is_deleted=0 and is_enable=1 and type!=0";
|
||||||
|
//获取当前角色等级的下一级角色类型
|
||||||
|
Query nativeQuery = null;
|
||||||
|
if (roleType > 0) {
|
||||||
|
sql = sql + " and type>:roleType ";
|
||||||
|
nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("roleType", roleType);
|
||||||
|
} else {
|
||||||
|
nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
}
|
||||||
|
List<Object[]> list = nativeQuery.getResultList();
|
||||||
|
List<SysRole> resultList = new ArrayList();
|
||||||
|
for (Object[] objs : list) {
|
||||||
|
SysRole role = new SysRole();
|
||||||
|
role.setId(ObjectKit.toInt(objs[0]));
|
||||||
|
role.setName(ObjectKit.toString(objs[1]));
|
||||||
|
role.setType(ObjectKit.toInt(objs[2]));
|
||||||
|
role.setLevel(ObjectKit.toInt(objs[3]));
|
||||||
|
role.setIsEnable(ObjectKit.toInt(objs[4]));
|
||||||
|
role.setDeleted(ObjectKit.toInt(objs[5]));
|
||||||
|
role.setCreatedBy(ObjectKit.toInt(objs[6]));
|
||||||
|
role.setLastUpdatedBy(ObjectKit.toInt(objs[8]));
|
||||||
|
Date createTime = null;
|
||||||
|
Date lastUpdateTime = null;
|
||||||
|
try {
|
||||||
|
if (objs[7] != null) {
|
||||||
|
createTime = DateKit.getDate(objs[7].toString());
|
||||||
|
}
|
||||||
|
if(objs[9]!=null){
|
||||||
|
lastUpdateTime = DateKit.getDate(objs[9].toString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
role.setCreatedTime(createTime);
|
||||||
|
role.setLastUpdatedTime(lastUpdateTime);
|
||||||
|
resultList.add(role);
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysRole> getBelowTypes(int roleType) {
|
||||||
|
String sql = "select * from sys_role where is_deleted=0 and is_enable=1 ";
|
||||||
|
//获取当前角色等级的下一级角色类型
|
||||||
|
Query nativeQuery = null;
|
||||||
|
sql = sql + " and type>:roleType";
|
||||||
|
nativeQuery = entityManager.createNativeQuery(sql);
|
||||||
|
nativeQuery.setParameter("roleType", roleType);
|
||||||
|
|
||||||
|
List<Object[]> list = nativeQuery.getResultList();
|
||||||
|
List<SysRole> resultList = new ArrayList();
|
||||||
|
for (Object[] objs : list) {
|
||||||
|
SysRole role = new SysRole();
|
||||||
|
role.setId(ObjectKit.toInt(objs[0]));
|
||||||
|
role.setName(ObjectKit.toString(objs[1]));
|
||||||
|
role.setType(ObjectKit.toInt(objs[2]));
|
||||||
|
role.setLevel(ObjectKit.toInt(objs[3]));
|
||||||
|
role.setIsEnable(ObjectKit.toInt(objs[4]));
|
||||||
|
role.setDeleted(ObjectKit.toInt(objs[5]));
|
||||||
|
role.setCreatedBy(ObjectKit.toInt(objs[6]));
|
||||||
|
role.setLastUpdatedBy(ObjectKit.toInt(objs[8]));
|
||||||
|
Date createTime = null;
|
||||||
|
Date lastUpdateTime = null;
|
||||||
|
try {
|
||||||
|
if(objs[7]!=null){
|
||||||
|
createTime = DateKit.getDate(objs[7].toString());
|
||||||
|
}
|
||||||
|
if(objs[9]!=null){
|
||||||
|
lastUpdateTime = DateKit.getDate(objs[9].toString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
role.setCreatedTime(createTime);
|
||||||
|
role.setLastUpdatedTime(lastUpdateTime);
|
||||||
|
resultList.add(role);
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getSelect(){
|
||||||
|
String select = "select tsr.*";
|
||||||
|
return select;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getSqlExceptSelect(ConcurrentHashMap<String, String> searchInfo,int roleType){
|
||||||
|
// 判断是否是系统管理员
|
||||||
|
String str=roleType==0?">=":">";
|
||||||
|
String sqlExceptSelect = "from sys_role tsr where type "+str+" (select type from sys_role, sys_user_role where sys_user_role.role_id = sys_role.id and sys_user_role.user_id="
|
||||||
|
+ InterfaceUtil.getAdminId() + " AND sys_user_role.is_deleted=0 ) and tsr.is_deleted=0 ";
|
||||||
|
StringBuffer sql=new StringBuffer(sqlExceptSelect);
|
||||||
|
for(Map.Entry<String, String> item : searchInfo.entrySet()){
|
||||||
|
sql.append(buildQuery(item));
|
||||||
|
}
|
||||||
|
sql.append("order by tsr.created_time desc");
|
||||||
|
|
||||||
|
return sql.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String buildQuery(Map.Entry<String, String> item){
|
||||||
|
String sql = "";
|
||||||
|
if(item.getKey().equals("name")){
|
||||||
|
sql += " and tsr.name like '%" + item.getValue() + "%' ";
|
||||||
|
}
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,100 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "sys_user_role")
|
||||||
|
public class SysUserRole {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
@Column(name = "user_id")
|
||||||
|
private int userId;
|
||||||
|
|
||||||
|
@Column(name = "role_id")
|
||||||
|
private int roleId;
|
||||||
|
|
||||||
|
@Column(name = "is_deleted")
|
||||||
|
private int isDeleted;
|
||||||
|
|
||||||
|
@Column(name = "created_by")
|
||||||
|
private int createdBy;
|
||||||
|
|
||||||
|
@Column(name = "created_time")
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_by")
|
||||||
|
private int lastUpdatedBy;
|
||||||
|
|
||||||
|
@Column(name = "last_updated_time")
|
||||||
|
private Date lastUpdatedTime;
|
||||||
|
|
||||||
|
public SysUserRole() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(int userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRoleId() {
|
||||||
|
return roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleId(int roleId) {
|
||||||
|
this.roleId = roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsDeleted() {
|
||||||
|
return isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDeleted(int isDeleted) {
|
||||||
|
this.isDeleted = isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(int createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(Date createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastUpdatedBy() {
|
||||||
|
return lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedBy(int lastUpdatedBy) {
|
||||||
|
this.lastUpdatedBy = lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(Date lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package cn.palmte.work.model;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface SysUserRoleRepository extends JpaRepository<SysUserRole, Integer> {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据userID 查询角色id
|
||||||
|
*/
|
||||||
|
@Query(" select userId from SysUserRole where roleId=?1 and isDeleted=0 ")
|
||||||
|
public List<SysUserRole> findRoleByRoleId(int role_id);
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Query("update SysUserRole sysUserRole set isDeleted = 1,lastUpdatedBy=?1,lastUpdatedTime=?2 where userId=?3 ")
|
||||||
|
@Modifying
|
||||||
|
int deleteSysUserRoleByUserId(int createAdminId, Date date, int userId);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class AlarmDetailDto implements Serializable {
|
||||||
|
|
||||||
|
private int alarmDetailId;
|
||||||
|
|
||||||
|
private String pushConfigId;
|
||||||
|
|
||||||
|
public int getAlarmDetailId() {
|
||||||
|
return alarmDetailId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlarmDetailId(int alarmDetailId) {
|
||||||
|
this.alarmDetailId = alarmDetailId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPushConfigId() {
|
||||||
|
return pushConfigId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPushConfigId(String pushConfigId) {
|
||||||
|
this.pushConfigId = pushConfigId;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AlarmDetailReportDto implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工地名称
|
||||||
|
*/
|
||||||
|
private String constructionSiteName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 告警次数
|
||||||
|
*/
|
||||||
|
private List<Integer> alarmCount;
|
||||||
|
|
||||||
|
private int allCount;
|
||||||
|
|
||||||
|
public int getAllCount() {
|
||||||
|
return allCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllCount(int allCount) {
|
||||||
|
this.allCount = allCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConstructionSiteName() {
|
||||||
|
return constructionSiteName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConstructionSiteName(String constructionSiteName) {
|
||||||
|
this.constructionSiteName = constructionSiteName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getAlarmCount() {
|
||||||
|
return alarmCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlarmCount(List<Integer> alarmCount) {
|
||||||
|
this.alarmCount = alarmCount;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
public class AlarmDetailReportExcel {
|
||||||
|
|
||||||
|
private String constructionSiteName;
|
||||||
|
|
||||||
|
private String alarmTypeName;
|
||||||
|
|
||||||
|
private int alarmCount;
|
||||||
|
|
||||||
|
public String getConstructionSiteName() {
|
||||||
|
return constructionSiteName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConstructionSiteName(String constructionSiteName) {
|
||||||
|
this.constructionSiteName = constructionSiteName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAlarmTypeName() {
|
||||||
|
return alarmTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlarmTypeName(String alarmTypeName) {
|
||||||
|
this.alarmTypeName = alarmTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAlarmCount() {
|
||||||
|
return alarmCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlarmCount(int alarmCount) {
|
||||||
|
this.alarmCount = alarmCount;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/7/17.
|
||||||
|
*/
|
||||||
|
public class AliSmsTemplate {
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliSmsTemplate(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
public class AllocationPermissionDto {
|
||||||
|
|
||||||
|
//已分配
|
||||||
|
public static final int ALLOCATION = 0;
|
||||||
|
//未分配
|
||||||
|
public static final int NOT_ALLOCATION = 1;
|
||||||
|
|
||||||
|
private int permissionId;
|
||||||
|
|
||||||
|
private String permissionName;
|
||||||
|
|
||||||
|
private String perminssionCode;
|
||||||
|
|
||||||
|
private int isAllocation;
|
||||||
|
|
||||||
|
public int getPermissionId() {
|
||||||
|
return permissionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissionId(int permissionId) {
|
||||||
|
this.permissionId = permissionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermissionName() {
|
||||||
|
return permissionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissionName(String permissionName) {
|
||||||
|
this.permissionName = permissionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPerminssionCode() {
|
||||||
|
return perminssionCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPerminssionCode(String perminssionCode) {
|
||||||
|
this.perminssionCode = perminssionCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsAllocation() {
|
||||||
|
return isAllocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsAllocation(int isAllocation) {
|
||||||
|
this.isAllocation = isAllocation;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class BindingDto implements Serializable {
|
||||||
|
|
||||||
|
private int appManagerId;
|
||||||
|
|
||||||
|
private String ids;
|
||||||
|
|
||||||
|
public int getAppManagerId() {
|
||||||
|
return appManagerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppManagerId(int appManagerId) {
|
||||||
|
this.appManagerId = appManagerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIds() {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIds(String ids) {
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,249 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class ConstructionSiteDto implements Serializable {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String projectName;
|
||||||
|
|
||||||
|
private String projectAddress;
|
||||||
|
|
||||||
|
private int regionId;
|
||||||
|
|
||||||
|
private String regionName;
|
||||||
|
|
||||||
|
private String areaCode;
|
||||||
|
|
||||||
|
private String areaName;
|
||||||
|
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
private String buildCompany;
|
||||||
|
|
||||||
|
private String constructionCompany;
|
||||||
|
|
||||||
|
private String coveredArea;
|
||||||
|
|
||||||
|
private String startDate;
|
||||||
|
|
||||||
|
private String endDate;
|
||||||
|
|
||||||
|
private String principalName;
|
||||||
|
|
||||||
|
private String principalPhone;
|
||||||
|
|
||||||
|
private String serverAddress;
|
||||||
|
|
||||||
|
private int isDeleted;
|
||||||
|
|
||||||
|
private int createdBy;
|
||||||
|
|
||||||
|
private Date createdTime;
|
||||||
|
|
||||||
|
private int lastUpdatedBy;
|
||||||
|
|
||||||
|
private Date lastUpdatedTime;
|
||||||
|
|
||||||
|
private String siteCode;
|
||||||
|
|
||||||
|
//经度
|
||||||
|
private String longitude;
|
||||||
|
|
||||||
|
//纬度
|
||||||
|
private String latitude;
|
||||||
|
|
||||||
|
public String getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLongitude(String longitude) {
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLatitude() {
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLatitude(String latitude) {
|
||||||
|
this.latitude = latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSiteCode() {
|
||||||
|
return siteCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSiteCode(String siteCode) {
|
||||||
|
this.siteCode = siteCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectName() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectAddress() {
|
||||||
|
return projectAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectAddress(String projectAddress) {
|
||||||
|
this.projectAddress = projectAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRegionId() {
|
||||||
|
return regionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegionId(int regionId) {
|
||||||
|
this.regionId = regionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRegionName() {
|
||||||
|
return regionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegionName(String regionName) {
|
||||||
|
this.regionName = regionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAreaCode() {
|
||||||
|
return areaCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaCode(String areaCode) {
|
||||||
|
this.areaCode = areaCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAreaName() {
|
||||||
|
return areaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaName(String areaName) {
|
||||||
|
this.areaName = areaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBuildCompany() {
|
||||||
|
return buildCompany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuildCompany(String buildCompany) {
|
||||||
|
this.buildCompany = buildCompany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConstructionCompany() {
|
||||||
|
return constructionCompany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConstructionCompany(String constructionCompany) {
|
||||||
|
this.constructionCompany = constructionCompany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCoveredArea() {
|
||||||
|
return coveredArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoveredArea(String coveredArea) {
|
||||||
|
this.coveredArea = coveredArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStartDate() {
|
||||||
|
return startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartDate(String startDate) {
|
||||||
|
this.startDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEndDate() {
|
||||||
|
return endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndDate(String endDate) {
|
||||||
|
this.endDate = endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrincipalName() {
|
||||||
|
return principalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrincipalName(String principalName) {
|
||||||
|
this.principalName = principalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrincipalPhone() {
|
||||||
|
return principalPhone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrincipalPhone(String principalPhone) {
|
||||||
|
this.principalPhone = principalPhone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerAddress() {
|
||||||
|
return serverAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerAddress(String serverAddress) {
|
||||||
|
this.serverAddress = serverAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsDeleted() {
|
||||||
|
return isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDeleted(int isDeleted) {
|
||||||
|
this.isDeleted = isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(int createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(Date createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastUpdatedBy() {
|
||||||
|
return lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedBy(int lastUpdatedBy) {
|
||||||
|
this.lastUpdatedBy = lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(Date lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
public class ForecastData {
|
||||||
|
|
||||||
|
private String aqi;
|
||||||
|
|
||||||
|
private String forecastTime;
|
||||||
|
|
||||||
|
private String primaryPollutant;
|
||||||
|
|
||||||
|
private String temp;
|
||||||
|
|
||||||
|
private String weather;
|
||||||
|
|
||||||
|
private String windLevel;
|
||||||
|
|
||||||
|
private String day;
|
||||||
|
|
||||||
|
private String week;
|
||||||
|
|
||||||
|
private String aqiLevel;
|
||||||
|
|
||||||
|
private String aqiRange;
|
||||||
|
|
||||||
|
public String getAqiRange() {
|
||||||
|
return aqiRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAqiRange(String aqiRange) {
|
||||||
|
this.aqiRange = aqiRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAqiLevel() {
|
||||||
|
return aqiLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAqiLevel(String aqiLevel) {
|
||||||
|
this.aqiLevel = aqiLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDay(String day) {
|
||||||
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeek() {
|
||||||
|
return week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeek(String week) {
|
||||||
|
this.week = week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAqi() {
|
||||||
|
return aqi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAqi(String aqi) {
|
||||||
|
this.aqi = aqi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getForecastTime() {
|
||||||
|
return forecastTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setForecastTime(String forecastTime) {
|
||||||
|
this.forecastTime = forecastTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrimaryPollutant() {
|
||||||
|
return primaryPollutant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrimaryPollutant(String primaryPollutant) {
|
||||||
|
this.primaryPollutant = primaryPollutant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTemp() {
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemp(String temp) {
|
||||||
|
this.temp = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeather() {
|
||||||
|
return weather;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeather(String weather) {
|
||||||
|
this.weather = weather;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWindLevel() {
|
||||||
|
return windLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWindLevel(String windLevel) {
|
||||||
|
this.windLevel = windLevel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tracy on 2018/4/16.
|
||||||
|
*/
|
||||||
|
public class LoginRequest {
|
||||||
|
private String userName;
|
||||||
|
private String password;
|
||||||
|
private String captchaToken;
|
||||||
|
private boolean showIndexData=false;
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCaptchaToken() {
|
||||||
|
return captchaToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCaptchaToken(String captchaToken) {
|
||||||
|
this.captchaToken = captchaToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShowIndexData() {
|
||||||
|
return showIndexData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowIndexData(boolean showIndexData) {
|
||||||
|
this.showIndexData = showIndexData;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tracy on 2018/4/16.
|
||||||
|
*/
|
||||||
|
public class LoginResponse {
|
||||||
|
private String userName;
|
||||||
|
private List<Menu> topMenuList;
|
||||||
|
|
||||||
|
private List<Menu> sideBarList;
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Menu> getTopMenuList() {
|
||||||
|
return topMenuList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTopMenuList(List<Menu> topMenuList) {
|
||||||
|
this.topMenuList = topMenuList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Menu> getSideBarList() {
|
||||||
|
return sideBarList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSideBarList(List<Menu> sideBarList) {
|
||||||
|
this.sideBarList = sideBarList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by tracy on 2018/4/16.
|
||||||
|
*/
|
||||||
|
public class Menu {
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String remark;
|
||||||
|
private String icon;
|
||||||
|
private String url;
|
||||||
|
private int parentId;
|
||||||
|
private String permossion;
|
||||||
|
private List<Menu> children;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Menu> getChildren() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildren(List<Menu> children) {
|
||||||
|
this.children = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getParentId() {
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentId(int parentId) {
|
||||||
|
this.parentId = parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermossion() {
|
||||||
|
return permossion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermossion(String permossion) {
|
||||||
|
this.permossion = permossion;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/4/25.
|
||||||
|
*/
|
||||||
|
public class ModifyPasswordRequest {
|
||||||
|
private String id;
|
||||||
|
private String password;
|
||||||
|
private String newPassword;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewPassword() {
|
||||||
|
return newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewPassword(String newPassword) {
|
||||||
|
this.newPassword = newPassword;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PermissionNode {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PermissionNode.class);
|
||||||
|
|
||||||
|
private int id; //id
|
||||||
|
private int parentId; // 父id
|
||||||
|
private int level;// 层级
|
||||||
|
private String name;//名称
|
||||||
|
private boolean hasLeafNode = false; // 是否有叶子子代
|
||||||
|
private boolean isLeafNode = false; //是否是叶子节点
|
||||||
|
private boolean selected = false; // 是否已选中
|
||||||
|
private List<PermissionNode> subNodes; // 子代集合
|
||||||
|
|
||||||
|
public int getId(){
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id){
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLeafNode(){
|
||||||
|
return isLeafNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLeafNode(boolean isLeafNode){
|
||||||
|
this.isLeafNode = isLeafNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PermissionNode> getSubNodes(){
|
||||||
|
return subNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSubNode(PermissionNode node){
|
||||||
|
if(subNodes == null){
|
||||||
|
subNodes = new ArrayList<PermissionNode>();
|
||||||
|
}
|
||||||
|
if(node.isLeafNode){
|
||||||
|
hasLeafNode = true;
|
||||||
|
}
|
||||||
|
subNodes.add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getParentId(){
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentId(int parentId){
|
||||||
|
this.parentId = parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubNodes(List<PermissionNode> subNodes){
|
||||||
|
this.subNodes = subNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasLeafNode(){
|
||||||
|
return hasLeafNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasLeafNode(boolean hasLeafNode){
|
||||||
|
this.hasLeafNode = hasLeafNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevel(){
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLevel(int level){
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelected(){
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(boolean selected){
|
||||||
|
this.selected = selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return name + "[" + id + ",pId:" + parentId + ",checked:" + selected + ",hasLeafNode:" + hasLeafNode + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.model.SysPermission;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PermissionTree {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PermissionTree.class);
|
||||||
|
|
||||||
|
private static final int LEAF_NODE = 2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static PermissionNode parsePermsNodeTree(List<SysPermission> permList, List<Integer> selectedPermIdList){
|
||||||
|
PermissionNode root = new PermissionNode();
|
||||||
|
for(int i = 0; i < permList.size(); i++){
|
||||||
|
SysPermission perms = permList.get(i);
|
||||||
|
PermissionNode subNode = getPermNode(perms);
|
||||||
|
if(selectedPermIdList.contains(subNode.getId())){
|
||||||
|
//设置该节点已被选择
|
||||||
|
subNode.setSelected(true);
|
||||||
|
}
|
||||||
|
// 如果父id为0,则该节点为主节点
|
||||||
|
if(subNode.getParentId() == 0){
|
||||||
|
root = subNode;
|
||||||
|
} else{
|
||||||
|
PermissionNode node = findParentNode(root, subNode.getParentId());
|
||||||
|
if(node != null){
|
||||||
|
node.addSubNode(subNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PermissionNode getPermNode(SysPermission perms){
|
||||||
|
PermissionNode subNode = new PermissionNode();
|
||||||
|
subNode.setId(perms.getId());
|
||||||
|
subNode.setName(perms.getName());
|
||||||
|
subNode.setParentId(perms.getParentId());
|
||||||
|
subNode.setLevel(perms.getLevel());
|
||||||
|
Integer type = perms.getType();
|
||||||
|
|
||||||
|
if(LEAF_NODE == type){
|
||||||
|
//设置为叶子节点
|
||||||
|
subNode.setLeafNode(true);
|
||||||
|
} else{
|
||||||
|
subNode.setLeafNode(false);
|
||||||
|
}
|
||||||
|
return subNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PermissionNode findParentNode(PermissionNode node, int nodeId){
|
||||||
|
if(node == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(node.getId() == nodeId){
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
if(node.getSubNodes() == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for(PermissionNode subNode : node.getSubNodes()){
|
||||||
|
PermissionNode parentNode = findParentNode(subNode, nodeId);
|
||||||
|
if(parentNode != null){
|
||||||
|
return parentNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ReportTable {
|
||||||
|
|
||||||
|
private List<String> thead;
|
||||||
|
|
||||||
|
private List<AlarmDetailReportDto> tbody;
|
||||||
|
|
||||||
|
public List<String> getThead() {
|
||||||
|
return thead;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThead(List<String> thead) {
|
||||||
|
this.thead = thead;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AlarmDetailReportDto> getTbody() {
|
||||||
|
return tbody;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTbody(List<AlarmDetailReportDto> tbody) {
|
||||||
|
this.tbody = tbody;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class RoleBean implements Serializable{
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int value;
|
||||||
|
private boolean selected;
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RoleBean(String name, int value){
|
||||||
|
super();
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue(){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(int value){
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelected(){
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(boolean selected){
|
||||||
|
this.selected = selected;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StationAirDataDto {
|
||||||
|
|
||||||
|
String aqi;
|
||||||
|
|
||||||
|
String updateTime;
|
||||||
|
|
||||||
|
List<Map<String, Object>> airData;
|
||||||
|
|
||||||
|
public String getAqi() {
|
||||||
|
return aqi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAqi(String aqi) {
|
||||||
|
this.aqi = aqi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateTime(String updateTime) {
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Map<String, Object>> getAirData() {
|
||||||
|
return airData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAirData(List<Map<String, Object>> airData) {
|
||||||
|
this.airData = airData;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class StatisticsDto {
|
||||||
|
|
||||||
|
private List<String> titles;
|
||||||
|
|
||||||
|
private List<String> dateStr;
|
||||||
|
|
||||||
|
private List<StatisticsItem> seriesData;
|
||||||
|
|
||||||
|
public List<String> getDateStr() {
|
||||||
|
return dateStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateStr(List<String> dateStr) {
|
||||||
|
this.dateStr = dateStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<StatisticsItem> getSeriesData() {
|
||||||
|
return seriesData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeriesData(List<StatisticsItem> seriesData) {
|
||||||
|
this.seriesData = seriesData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTitles() {
|
||||||
|
return titles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitles(List<String> titles) {
|
||||||
|
this.titles = titles;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class StatisticsItem {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String type;
|
||||||
|
private String stack;
|
||||||
|
private List<Long> data;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStack() {
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStack(String stack) {
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Long> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(List<Long> data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package cn.palmte.work.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传结果
|
||||||
|
*
|
||||||
|
* @author pengqiang
|
||||||
|
* @date 2018/5/3
|
||||||
|
*/
|
||||||
|
public class UploadResult {
|
||||||
|
|
||||||
|
private String originName;
|
||||||
|
private String name;
|
||||||
|
private String newName;
|
||||||
|
private int status;
|
||||||
|
private String url;
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
public UploadResult() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UploadResult(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UploadResult(int status, String msg) {
|
||||||
|
this.status = status;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginName() {
|
||||||
|
return originName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginName(String originName) {
|
||||||
|
this.originName = originName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewName() {
|
||||||
|
return newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewName(String newName) {
|
||||||
|
this.newName = newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package cn.palmte.work.security;
|
||||||
|
|
||||||
|
import top.jfunc.common.utils.ArrayUtil;
|
||||||
|
import top.jfunc.common.utils.StrUtil;
|
||||||
|
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过来特殊字符,防止URL框架注入漏洞
|
||||||
|
*/
|
||||||
|
public class ReplaceSpecialCharFilter implements Filter {
|
||||||
|
private String[] includes;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException,ServletException {
|
||||||
|
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||||
|
String requestURI = httpServletRequest.getRequestURI();
|
||||||
|
if(ArrayUtil.contains(includes, requestURI)) {
|
||||||
|
httpServletRequest = new XssHttpServletRequestWrapper(httpServletRequest);
|
||||||
|
}
|
||||||
|
filterChain.doFilter(httpServletRequest, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
String includes = filterConfig.getInitParameter("includes");
|
||||||
|
this.includes = StrUtil.isEmpty(includes)?new String[0]:includes.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cn.palmte.work.security;
|
||||||
|
|
||||||
|
import top.jfunc.common.utils.StrUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 框架注入漏洞
|
||||||
|
* https://blog.csdn.net/conkeyn/article/details/84532040
|
||||||
|
* @author xiongshiyan at 2021/9/6 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
public class UrlUtil {
|
||||||
|
private static final String REG_EX="[\n`~!@#$%^&*\\(\\)+|;{}',\\\\\\[\\]<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]";
|
||||||
|
|
||||||
|
public static String replaceSpecialChar(String origin){
|
||||||
|
if(StrUtil.isEmpty(origin)){
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
String s = origin.replaceAll(REG_EX, "");
|
||||||
|
//双引号不好写在正则中
|
||||||
|
return s.replace("\"", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String origin = "12|&;$%@'\"<>()+,\\";
|
||||||
|
System.out.println(origin);
|
||||||
|
String s = replaceSpecialChar(origin);
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package cn.palmte.work.security;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
|
|
||||||
|
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
||||||
|
HttpServletRequest originRequest = null;
|
||||||
|
|
||||||
|
public XssHttpServletRequestWrapper(HttpServletRequest request) {
|
||||||
|
super(request);
|
||||||
|
originRequest = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 覆盖getParameter方法,将参数名和参数值都做xss过滤。<br/>
|
||||||
|
* 如果需要获得原始的值,则通过super.getParameterValues(name)来获取<br/>
|
||||||
|
* getParameterNames,getParameterValues和getParameterMap也可能需要覆盖
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getParameter(String name) {
|
||||||
|
String parameter = super.getParameter(name);
|
||||||
|
return UrlUtil.replaceSpecialChar(parameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getParameterValues(String name) {
|
||||||
|
String[] arr = super.getParameterValues(name);
|
||||||
|
if(arr != null){
|
||||||
|
for (int i=0;i<arr.length;i++) {
|
||||||
|
arr[i] = UrlUtil.replaceSpecialChar(arr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHeader(String name) {
|
||||||
|
String value = super.getHeader(name);
|
||||||
|
return UrlUtil.replaceSpecialChar(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最原始的request
|
||||||
|
*/
|
||||||
|
public HttpServletRequest getOriginRequest() {
|
||||||
|
return originRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,234 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
import cn.palmte.work.bean.RegexConstant;
|
||||||
|
import cn.palmte.work.model.*;
|
||||||
|
import cn.palmte.work.utils.DESCrypto;
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import cn.palmte.work.utils.StrKit;
|
||||||
|
import org.apache.commons.lang.RandomStringUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import top.jfunc.common.db.QueryHelper;
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
import top.jfunc.common.db.utils.Pagination;
|
||||||
|
|
||||||
|
import java.beans.Transient;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/4/20.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AccountService {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AccountService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AdminRepository adminRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AdminRepositoryImpl adminRepositoryImpl;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SysUserRoleRepository sysUserRoleRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
Pagination pagination;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRoleRepository sysRoleRepository;
|
||||||
|
|
||||||
|
public Page getAdminList(ConcurrentHashMap<String, String> searchInfo, int pageSize, int pageNum) {
|
||||||
|
return adminRepositoryImpl.getAdminList(searchInfo, pageSize, pageNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<Admin> list(ConcurrentHashMap<String, String> searchInfo, int pageNumber, int pageSize) {
|
||||||
|
QueryHelper queryHelper = new QueryHelper("select su.id,su.user_name,su.real_name,su.created_time,su.enabled,sr.type,sr.name as roleName,su.telephone,su.region_name", " FROM sys_user su left join sys_user_role " +
|
||||||
|
"sur on su.id = sur.user_id left join sys_role sr on sur.role_id = sr.id");
|
||||||
|
queryHelper.addCondition("su.is_deleted = 0");
|
||||||
|
queryHelper.addCondition(searchInfo.containsKey("roleId") &&
|
||||||
|
StrKit.notBlank(searchInfo.get("roleId")) && !"-1".equals(searchInfo.get("roleId")),
|
||||||
|
"sr.id =?", searchInfo.get("roleId"));
|
||||||
|
queryHelper.addCondition(searchInfo.containsKey("userName"), "su.user_name like ?", "%" +
|
||||||
|
"su.is_deleted = 0" + "%");
|
||||||
|
queryHelper.addCondition(searchInfo.containsKey("telephone"), "su.telephone = ?" + searchInfo.get("telephone"));
|
||||||
|
queryHelper.addCondition(searchInfo.containsKey("regionId") &&
|
||||||
|
StrKit.notBlank(searchInfo.get("regionId")) && !"-1".equals(searchInfo.get("regionId")),
|
||||||
|
"su.region_id =?", searchInfo.get("regionId"));
|
||||||
|
queryHelper.addOrderProperty("su.created_time", false);
|
||||||
|
Page<Admin> page = pagination.paginate(queryHelper.getSql(), Admin.class, pageNumber, pageSize);
|
||||||
|
return page;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
public boolean changeStatus(int userId, int enabled) {
|
||||||
|
Admin admin = adminRepository.findOne(userId);
|
||||||
|
if (admin == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
admin.setEnabled(enabled);
|
||||||
|
adminRepository.save(admin);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin findUserById(int userId) {
|
||||||
|
Admin admin = adminRepositoryImpl.findAdminById(userId);
|
||||||
|
SysRole sysRole = sysRoleRepository.findOne(admin.getRoleId());
|
||||||
|
if(null != sysRole){
|
||||||
|
admin.setRoleName(sysRole.getName());
|
||||||
|
}
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void saveOrUpdateAccount(int userId, int roleId, Admin admin, String privateKey) {
|
||||||
|
int createAdminId = InterfaceUtil.getAdminId();
|
||||||
|
Admin oldAdmin = adminRepository.findOne(userId);
|
||||||
|
if (oldAdmin == null) {
|
||||||
|
oldAdmin = new Admin();
|
||||||
|
String userName = admin.getUserName();
|
||||||
|
oldAdmin.setUserName(userName);
|
||||||
|
String salt = RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
||||||
|
|
||||||
|
String newPassword = decEncPassword(admin.getTelephone().substring(5), salt, privateKey);
|
||||||
|
oldAdmin.setPassword(newPassword);
|
||||||
|
oldAdmin.setSalt(salt);
|
||||||
|
oldAdmin.setEnabled(1);
|
||||||
|
oldAdmin.setRealName(admin.getRealName());
|
||||||
|
oldAdmin.setCreatedBy(createAdminId);
|
||||||
|
oldAdmin.setTelephone(admin.getTelephone());
|
||||||
|
oldAdmin.setCreatedTime(new Date());
|
||||||
|
} else {
|
||||||
|
String userName = admin.getUserName();
|
||||||
|
oldAdmin.setUserName(userName);
|
||||||
|
oldAdmin.setRealName(admin.getRealName());
|
||||||
|
oldAdmin.setTelephone(admin.getTelephone());
|
||||||
|
oldAdmin.setLastUpdatedBy(createAdminId);
|
||||||
|
oldAdmin.setLastUpdatedTime(new Date());
|
||||||
|
}
|
||||||
|
oldAdmin.setRegionId(admin.getRegionId());
|
||||||
|
|
||||||
|
oldAdmin.setRoleId(admin.getRoleId());
|
||||||
|
SysRole one = sysRoleRepository.findOne(admin.getRoleId());
|
||||||
|
if (null != one) {
|
||||||
|
oldAdmin.setRoleName(one.getName());
|
||||||
|
}
|
||||||
|
admin = adminRepository.saveAndFlush(oldAdmin);
|
||||||
|
//设置当前用户角色关系状态为删除
|
||||||
|
userId = admin.getId();
|
||||||
|
sysUserRoleRepository.deleteSysUserRoleByUserId(createAdminId, new Date(), userId);
|
||||||
|
SysUserRole sysUserRole = new SysUserRole();
|
||||||
|
//保存用户角色关系
|
||||||
|
sysUserRole.setUserId(userId);
|
||||||
|
sysUserRole.setRoleId(roleId);
|
||||||
|
sysUserRole.setCreatedBy(createAdminId);
|
||||||
|
sysUserRole.setCreatedTime(new Date());
|
||||||
|
sysUserRoleRepository.save(sysUserRole);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查用户是否存在于系统中
|
||||||
|
*/
|
||||||
|
public String validateUserExistInfo(int userId, Admin admin) {
|
||||||
|
String message = "";
|
||||||
|
//校验手机号格式
|
||||||
|
String phone = admin.getTelephone();
|
||||||
|
if (!phone.matches(RegexConstant.REGEX)) {
|
||||||
|
return "请填写正确的电话号码!";
|
||||||
|
}
|
||||||
|
|
||||||
|
Admin byTelephoneEquals = adminRepository.findByTelephone(phone);
|
||||||
|
if (userId == -1) {
|
||||||
|
//新增校验手机号是否存在
|
||||||
|
if (null != byTelephoneEquals) {
|
||||||
|
message = "该手机号已存在!";
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//编辑校验手机号是否存在
|
||||||
|
if (null != byTelephoneEquals && byTelephoneEquals.getId() != userId) {
|
||||||
|
message = "该手机号已存在!";
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(admin.getUserName())) {
|
||||||
|
message = "亲,用户名不能为空!";
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
Admin existAdmin = adminRepository.getAdminByUsername(admin.getUserName());
|
||||||
|
if (userId == -1) {//只在新增时候校验
|
||||||
|
if (existAdmin != null) {
|
||||||
|
message = "亲,该账号已存在!";
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (existAdmin != null && existAdmin.getId() != userId) {
|
||||||
|
message = "亲,该账号名称已存在!";
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
existAdmin = adminRepository.getAdminByRealName(admin.getRealName());
|
||||||
|
if (existAdmin != null && existAdmin.getId() != userId) {
|
||||||
|
message = "亲,该账号名称已存在!";
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String decEncPassword(String password, String salt, String privateKey) {
|
||||||
|
try {
|
||||||
|
return DESCrypto.encryptPassword(password, salt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean resetPassword(int userId, String privateKey) {
|
||||||
|
try {
|
||||||
|
Admin oldAdmin = adminRepository.findOne(userId);
|
||||||
|
if (oldAdmin == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String salt = RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
||||||
|
String telephone = oldAdmin.getTelephone();
|
||||||
|
String newPassword = decEncPassword(telephone.substring(5), salt, privateKey);
|
||||||
|
oldAdmin.setPassword(newPassword);
|
||||||
|
oldAdmin.setSalt(salt);
|
||||||
|
oldAdmin.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
oldAdmin.setLastUpdatedTime(new Date());
|
||||||
|
adminRepository.save(oldAdmin);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("充值密码错误!" + e.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean deleteAccount(int userId) {
|
||||||
|
try {
|
||||||
|
Admin admin = adminRepository.findOne(userId);
|
||||||
|
admin.setDeleted(true);
|
||||||
|
admin.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
|
||||||
|
//删除用户角色关系
|
||||||
|
sysUserRoleRepository.deleteSysUserRoleByUserId(InterfaceUtil.getAdminId(), new Date(), userId);
|
||||||
|
|
||||||
|
adminRepository.save(admin);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("账户ID:" + userId + "删除错误!" + e.toString());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,234 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
import cn.palmte.work.model.*;
|
||||||
|
import cn.palmte.work.pojo.LoginResponse;
|
||||||
|
import cn.palmte.work.pojo.Menu;
|
||||||
|
import cn.palmte.work.shiro.ShiroUtils;
|
||||||
|
import cn.palmte.work.utils.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: zhangming
|
||||||
|
* @date: 2019/9/18 0018
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AdminService {
|
||||||
|
private static final Pattern PSW_PATTERN = Pattern.compile("^[\\@A-Za-z0-9\\!\\#\\$\\%\\^\\&\\*\\.\\~]{8,20}$");
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AdminRepositoryCustom adminRepositoryCustom;
|
||||||
|
@Autowired
|
||||||
|
public AdminRepositoryImpl adminRepositoryImpl;
|
||||||
|
@Autowired
|
||||||
|
public AdminRepository adminRepository;
|
||||||
|
@Autowired
|
||||||
|
public SysPermissionRepository sysPermissionRepository;
|
||||||
|
|
||||||
|
public Admin getAdminByUsername(String userName) {
|
||||||
|
List<Admin> admins = adminRepository.getAdminByUsernameListNoEnabled(userName);
|
||||||
|
if (admins != null && !admins.isEmpty()) {
|
||||||
|
Admin admin = admins.get(0);
|
||||||
|
//查询角色ID和TYPE
|
||||||
|
Admin adminRoleInfo = adminRepositoryImpl.findAdminByUserName(userName);
|
||||||
|
admin.setRoleType(adminRoleInfo.getRoleType());
|
||||||
|
admin.setRoleId(adminRoleInfo.getRoleId());
|
||||||
|
admin.setRoleLevel(adminRoleInfo.getRoleLevel());
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAuthoritiesName(String adminId) {
|
||||||
|
return adminRepositoryCustom.getAuthoritiesName(adminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAuthoritieUrls(String adminId) {
|
||||||
|
return adminRepositoryCustom.getAuthoritieUrls(adminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SysPermission> getAuthoritieUrlsByParentPermission(String adminId, String permission) {
|
||||||
|
return adminRepositoryCustom.getAuthoritieUrlsByParentPermission(adminId, permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRolesName(String adminId) {
|
||||||
|
return adminRepositoryCustom.getRolesName(adminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoginResponse initMenuList(int uId) {
|
||||||
|
LoginResponse loginResponse = new LoginResponse();
|
||||||
|
|
||||||
|
List<Menu> topMenuList = getMenuByLevelID(2);
|
||||||
|
|
||||||
|
loginResponse.setTopMenuList(topMenuList);
|
||||||
|
|
||||||
|
List<Menu> menuList = new ArrayList<>();
|
||||||
|
if (uId > 0) {
|
||||||
|
menuList = getMenuByParentId(uId);
|
||||||
|
} else {
|
||||||
|
if (null != topMenuList && topMenuList.size() > 0) {
|
||||||
|
Integer topMenuId = topMenuList.get(0).getId();
|
||||||
|
menuList = getMenuByParentId(topMenuId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loginResponse.setSideBarList(menuList);
|
||||||
|
|
||||||
|
return loginResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Menu> getMenuByLevelID(int levelId) {
|
||||||
|
List<SysPermission> list = sysPermissionRepository.findSysPermissionByLevel(levelId);
|
||||||
|
List<Menu> nodeList = new ArrayList<>();
|
||||||
|
for (SysPermission sysPermission : list) {
|
||||||
|
//TODO:需补充shiro权限相关逻辑
|
||||||
|
if (ShiroUtils.hasPermission(sysPermission.getPermission())) {
|
||||||
|
// remark字段,用于返回前端TOP菜单css样式的class ID
|
||||||
|
String url[] = sysPermission.getUrl().split("/");
|
||||||
|
sysPermission.setRemark(url[url.length - 1]);
|
||||||
|
Menu menu = new Menu();
|
||||||
|
menu.setId(sysPermission.getId());
|
||||||
|
menu.setName(sysPermission.getName());
|
||||||
|
menu.setIcon(sysPermission.getIcon());
|
||||||
|
menu.setRemark(sysPermission.getRemark());
|
||||||
|
menu.setUrl(sysPermission.getUrl());
|
||||||
|
menu.setIcon(sysPermission.getIcon());
|
||||||
|
menu.setParentId(sysPermission.getParentId());
|
||||||
|
menu.setPermossion(sysPermission.getPermission());
|
||||||
|
nodeList.add(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Menu> getMenuByParentId(int parentId) {
|
||||||
|
List<Menu> nodeList = new ArrayList<>();
|
||||||
|
List<Menu> returnList = new ArrayList<>();
|
||||||
|
List<SysPermission> list = sysPermissionRepository.findSysPermissionByParentId(parentId);
|
||||||
|
list.forEach(sysPermission -> {
|
||||||
|
Menu menu = new Menu();
|
||||||
|
menu.setId(sysPermission.getId());
|
||||||
|
menu.setName(sysPermission.getName());
|
||||||
|
menu.setIcon(sysPermission.getIcon());
|
||||||
|
menu.setRemark(sysPermission.getRemark());
|
||||||
|
menu.setUrl(sysPermission.getUrl());
|
||||||
|
menu.setIcon(sysPermission.getIcon());
|
||||||
|
menu.setParentId(sysPermission.getParentId());
|
||||||
|
menu.setPermossion(sysPermission.getPermission());
|
||||||
|
nodeList.add(menu);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
for (Menu node1 : nodeList) {
|
||||||
|
boolean mark = false;
|
||||||
|
for (Menu node2 : nodeList) {
|
||||||
|
if (node1.getParentId() > 0L && node1.getParentId() == node2.getId()) {
|
||||||
|
mark = true;
|
||||||
|
if (node2.getChildren() == null) {
|
||||||
|
node2.setChildren(new ArrayList<Menu>());
|
||||||
|
}
|
||||||
|
//TODO:需补充shiro权限相关逻辑
|
||||||
|
if (ShiroUtils.hasPermission(node1.getPermossion())) {
|
||||||
|
node2.getChildren().add(node1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//TODO:需补充shiro权限相关逻辑
|
||||||
|
if (!mark && ShiroUtils.hasPermission(node1.getPermossion())) {
|
||||||
|
returnList.add(node1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新登录信息
|
||||||
|
*/
|
||||||
|
public void updateLoginInfo(Admin admin, HttpServletRequest request) {
|
||||||
|
admin.setLoginDate(new Date());
|
||||||
|
admin.setLoginIp(request.getRemoteAddr());
|
||||||
|
admin.setLoginErrorCount(0);
|
||||||
|
admin.setLocked(Admin.UN_LOCKED);
|
||||||
|
admin.setLockedDate(null);
|
||||||
|
adminRepository.save(admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysRole getRole(String adminId) {
|
||||||
|
return adminRepositoryCustom.getRole(adminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过id查询admin
|
||||||
|
*/
|
||||||
|
public Admin getAdminById(int id) {
|
||||||
|
return adminRepository.getAdminById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePassword(String id, String password, String newPassword, String privateKey) {
|
||||||
|
int adminId = InterfaceUtil.getAdminId();
|
||||||
|
if(adminId != Integer.parseInt(id)){
|
||||||
|
throw new RuntimeException("密码修改失败,id不合法");
|
||||||
|
}
|
||||||
|
Admin admin = adminRepository.findOne(Integer.valueOf(id));
|
||||||
|
if(null == admin){
|
||||||
|
throw new RuntimeException("密码修改失败,不存在 id = " + id + " 这个人");
|
||||||
|
}
|
||||||
|
String salt = admin.getSalt();
|
||||||
|
|
||||||
|
String desOldPwd = "";
|
||||||
|
String desNewPwd = "";
|
||||||
|
try{
|
||||||
|
/* RSA 解密 */
|
||||||
|
String oldPwdByRSA = StrKit.byteToStringWithDefaultEncoding(RSAUtils.decryptByPrivateKey(Base64Utils.decode(password), privateKey));
|
||||||
|
desOldPwd = DESCrypto.encryptPassword(oldPwdByRSA, salt);
|
||||||
|
|
||||||
|
String newPwdByRSA = StrKit.byteToStringWithDefaultEncoding(RSAUtils.decryptByPrivateKey(Base64Utils.decode(newPassword), privateKey));
|
||||||
|
if(!PSW_PATTERN.matcher(newPwdByRSA).matches()){// 密码不满足正则表达式
|
||||||
|
throw new RuntimeException("密码修改失败,密码不满足规则(8-20位非中文字符)");
|
||||||
|
}
|
||||||
|
desNewPwd = DESCrypto.encryptPassword(newPwdByRSA, salt);
|
||||||
|
}
|
||||||
|
catch(Exception e){
|
||||||
|
throw new RuntimeException("密码修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
String correct = admin.getPassword();
|
||||||
|
|
||||||
|
if(!desOldPwd.equals(correct)){
|
||||||
|
throw new RuntimeException("密码修改失败,原密码错误");
|
||||||
|
}
|
||||||
|
admin.setPassword(desNewPwd);
|
||||||
|
admin.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
admin.setLastUpdatedTime(new Date());
|
||||||
|
admin.setUpdatedPasswordTime(new Date());
|
||||||
|
adminRepository.save(admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isLocked(Admin admin){
|
||||||
|
if(admin.getLocked()==Admin.UN_LOCKED){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Date lockedDate = admin.getLockedDate();
|
||||||
|
//15分钟之后就不算锁定了
|
||||||
|
return System.currentTimeMillis() - lockedDate.getTime() <= 15 * 60 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLoginError(Admin admin){
|
||||||
|
int loginErrorCount = admin.getLoginErrorCount();
|
||||||
|
admin.setLoginErrorCount(loginErrorCount+1);
|
||||||
|
//5次就锁定
|
||||||
|
if(loginErrorCount >= 5-1){
|
||||||
|
admin.setLocked(Admin.LOCKED);
|
||||||
|
admin.setLockedDate(new Date());
|
||||||
|
}
|
||||||
|
adminRepository.saveAndFlush(admin);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
import cn.palmte.work.model.ExcelEvent;
|
||||||
|
import cn.palmte.work.model.ExportExcelBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ZM
|
||||||
|
* @date 2018/9/21
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ExcelEventService {
|
||||||
|
@Autowired
|
||||||
|
ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步导出excel方法
|
||||||
|
*/
|
||||||
|
public void exportExcel(ExportExcelBean exportExcelBean){
|
||||||
|
//发布异步导出excel事件
|
||||||
|
applicationContext.publishEvent(new ExcelEvent(this,exportExcelBean));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
import cn.palmte.work.model.LoginLog;
|
||||||
|
import cn.palmte.work.model.LoginLogRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan at 2021/8/24 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class LoginLogService {
|
||||||
|
@Autowired
|
||||||
|
private LoginLogRepository loginLogRepository;
|
||||||
|
|
||||||
|
public void saveLog(String userName, int status, String statusDesc){
|
||||||
|
LoginLog loginLog = new LoginLog();
|
||||||
|
loginLog.setName(userName);
|
||||||
|
loginLog.setStatus(status);
|
||||||
|
loginLog.setStatusDesc(statusDesc);
|
||||||
|
loginLog.setCreateTime(new Date());
|
||||||
|
loginLogRepository.saveAndFlush(loginLog);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
import cn.palmte.work.model.SlideCaptcha;
|
||||||
|
import cn.palmte.work.model.SlideCaptchaRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import top.jfunc.common.utils.StrUtil;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan at 2020/9/30 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SlideCaptchaService {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SlideCaptchaService.class);
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SlideCaptchaRepository slideCaptchaRepository;
|
||||||
|
|
||||||
|
@Value("${fourcal.slideInterval:1800000}")
|
||||||
|
private long slideInterval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param serialNumber 序列号
|
||||||
|
*/
|
||||||
|
public boolean updateCaptcha(String serialNumber, String identifier, int x, int y){
|
||||||
|
if(StrUtil.isEmpty(serialNumber) || StrUtil.isEmpty(identifier)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SlideCaptcha slideCaptcha = slideCaptchaRepository.findFirstBySerialNumberEquals(serialNumber);
|
||||||
|
if(null == slideCaptcha){
|
||||||
|
slideCaptcha = new SlideCaptcha();
|
||||||
|
slideCaptcha.setSerialNumber(serialNumber);
|
||||||
|
slideCaptcha.setStatus(SlideCaptcha.STATUS_INIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
slideCaptcha.setX(x);
|
||||||
|
slideCaptcha.setY(y);
|
||||||
|
slideCaptcha.setIdentifier(identifier);
|
||||||
|
slideCaptcha.setModifyTime(new Date());
|
||||||
|
slideCaptchaRepository.saveAndFlush(slideCaptcha);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param serialNumber 序列号
|
||||||
|
*/
|
||||||
|
public boolean verifyCaptcha(String serialNumber, String identifier, int x, int y, int allowance){
|
||||||
|
if(StrUtil.isEmpty(serialNumber) || StrUtil.isEmpty(identifier)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SlideCaptcha slideCaptcha = slideCaptchaRepository.findFirstBySerialNumberEquals(serialNumber);
|
||||||
|
if(slideCaptcha == null || !identifier.equals(slideCaptcha.getIdentifier())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//slide_interval=1800000
|
||||||
|
if((System.currentTimeMillis() - slideCaptcha.getModifyTime().getTime()) > slideInterval){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//只判断x,不判断y
|
||||||
|
Integer integer = slideCaptcha.getX();
|
||||||
|
boolean b = x >= integer - allowance && x <= integer + allowance;
|
||||||
|
if(b){
|
||||||
|
//校验成功则更新以待后续的校验
|
||||||
|
slideCaptcha.setStatus(1);
|
||||||
|
slideCaptchaRepository.saveAndFlush(slideCaptcha);
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
|
||||||
|
}
|
||||||
|
public boolean verifyCaptcha(String serialNumber, String identifier){
|
||||||
|
if(StrUtil.isEmpty(serialNumber) || StrUtil.isEmpty(identifier)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SlideCaptcha slideCaptcha = slideCaptchaRepository.findFirstBySerialNumberEquals(serialNumber);
|
||||||
|
if(slideCaptcha == null || !identifier.equals(slideCaptcha.getIdentifier())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((System.currentTimeMillis() - slideCaptcha.getModifyTime().getTime()) > slideInterval){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//查看校验成功没有
|
||||||
|
return SlideCaptcha.STATUS_SUCCESS == slideCaptcha.getStatus();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteCaptchaBy(String serialNumber){
|
||||||
|
SlideCaptcha slideCaptcha = slideCaptchaRepository.findFirstBySerialNumberEquals(serialNumber);
|
||||||
|
if(null != slideCaptcha){
|
||||||
|
slideCaptchaRepository.delete(slideCaptcha);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.model.*;
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SysPermissionService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysPermissionRepositoryCustom sysPermissionRepositoryCustom;
|
||||||
|
@Autowired
|
||||||
|
private SysPermissionRepository sysPermissionRepository;
|
||||||
|
@Autowired
|
||||||
|
private SysRolePermissionRepository sysRolePermissionRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRoleRepository sysRoleRepository;
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SysPermissionService.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取所有资源列表
|
||||||
|
*/
|
||||||
|
public Page<SysPermission> getAllPermissionListByPage(ConcurrentHashMap<String, String> searchInfo, String pageNumber) {
|
||||||
|
return sysPermissionRepositoryCustom.getAllPermissionListByPage(searchInfo, pageNumber);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAllPermissionList() {
|
||||||
|
return sysPermissionRepository.findAllPermissionUrls();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除资源
|
||||||
|
*/
|
||||||
|
public boolean deletePermissionByIDs(String[] ids) {
|
||||||
|
boolean deleted = true;
|
||||||
|
for (String id : ids) {
|
||||||
|
SysPermission permission = sysPermissionRepository.findOne(Integer.parseInt(id));
|
||||||
|
|
||||||
|
permission.setIsDeleted(1);
|
||||||
|
permission.setLastUpdatedBy(InterfaceUtil.getAdminId());// 当前登录人
|
||||||
|
permission.setLastUpdatedTime(new Date());
|
||||||
|
try {
|
||||||
|
sysPermissionRepository.save(permission);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
deleted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加资源
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void addPermission(SysPermission sysPermission) {
|
||||||
|
|
||||||
|
sysPermission.setCreatedBy(InterfaceUtil.getAdminId()); // 当前登录人
|
||||||
|
sysPermission.setCreatedTime(new Date());
|
||||||
|
sysPermission.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
sysPermission.setLastUpdatedTime(new Date());
|
||||||
|
sysPermission = sysPermissionRepository.saveAndFlush(sysPermission);
|
||||||
|
|
||||||
|
int permissionID = sysPermission.getId();
|
||||||
|
|
||||||
|
// 新增权限时,默认在角色-权限表中新增一组关系。默认给系统管理员授权。(注意:角色表中必须只要一个系统管理员角色。)即使用其它角色新增一个资源时,也是默认赋给系统管理员角色授权。
|
||||||
|
int superAdminRoleId = 1;
|
||||||
|
try {
|
||||||
|
SysRole sysRole = sysRoleRepository.findSuperAdminRole();
|
||||||
|
superAdminRoleId = sysRole.getId();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SysRolePermission rolePermission = new SysRolePermission();
|
||||||
|
rolePermission.setRoleId(superAdminRoleId);// 即最高权限-系统管理员角色id。
|
||||||
|
rolePermission.setPermissionId(permissionID);
|
||||||
|
rolePermission.setCreatedBy(InterfaceUtil.getAdminId()); // 当前登录人
|
||||||
|
rolePermission.setCreatedTime(new Date());
|
||||||
|
rolePermission.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
rolePermission.setLastUpdatedTime(new Date());
|
||||||
|
sysRolePermissionRepository.save(rolePermission);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新权限
|
||||||
|
*/
|
||||||
|
public void updatePermission(SysPermission sysPermission, String permissionID) {
|
||||||
|
|
||||||
|
SysPermission permission = sysPermissionRepository.findOne(Integer.parseInt(permissionID));
|
||||||
|
|
||||||
|
permission.setName(sysPermission.getName());
|
||||||
|
permission.setIcon(sysPermission.getIcon());
|
||||||
|
permission.setUrl(sysPermission.getUrl());
|
||||||
|
permission.setLevel(sysPermission.getLevel());
|
||||||
|
permission.setType(sysPermission.getType());
|
||||||
|
permission.setSort(sysPermission.getSort());
|
||||||
|
permission.setRemark(sysPermission.getRemark());
|
||||||
|
permission.setParentId(sysPermission.getParentId());
|
||||||
|
permission.setPermission(sysPermission.getPermission());
|
||||||
|
permission.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
permission.setLastUpdatedTime(new Date());
|
||||||
|
sysPermissionRepository.saveAndFlush(permission);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.model.SysRolePermission;
|
||||||
|
import cn.palmte.work.model.SysRolePermissionRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SysRolePermissionService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRolePermissionRepository sysRolePermissionRepository;
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SysRolePermissionService.class);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除 角色权限关联表
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean deleteSysRolePermissionByIDs(String[] ids){
|
||||||
|
boolean deleted = true;
|
||||||
|
for(String id : ids){
|
||||||
|
try {
|
||||||
|
sysRolePermissionRepository.deleteSysRolePermissionByPermissionId(Integer.parseInt(id));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
deleted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Integer> getPermissionIds(int roleId){
|
||||||
|
|
||||||
|
List<SysRolePermission> list =sysRolePermissionRepository.findPerListByRoleId(roleId);
|
||||||
|
List<Integer> permIdList = new ArrayList<Integer>();
|
||||||
|
for(SysRolePermission permission : list){
|
||||||
|
|
||||||
|
permIdList.add(permission.getPermissionId());
|
||||||
|
}
|
||||||
|
return permIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,332 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
import cn.palmte.work.model.*;
|
||||||
|
import cn.palmte.work.pojo.PermissionNode;
|
||||||
|
import cn.palmte.work.pojo.PermissionTree;
|
||||||
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import top.jfunc.common.db.QueryHelper;
|
||||||
|
import top.jfunc.common.db.bean.Page;
|
||||||
|
import top.jfunc.common.db.utils.Pagination;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SysRoleService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysRoleRepository sysRoleRepository;
|
||||||
|
@Autowired
|
||||||
|
private SysPermissionRepository sysPermissionRepository;
|
||||||
|
@Autowired
|
||||||
|
private SysRolePermissionRepository sysRolePermissionRepository;
|
||||||
|
@Autowired
|
||||||
|
private SysRoleRepositoryImpl sysRoleRepositoryImpl;
|
||||||
|
@Autowired
|
||||||
|
private SysRolePermissionService sysRolePermissionService;
|
||||||
|
@Autowired
|
||||||
|
private SysUserRoleRepository sysUserRoleRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
Pagination pagination;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SysRoleService.class);
|
||||||
|
private static final String SELECTED_PERMISSION_PREFIX = "rptList$ctl$cblActionType$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取所有角色列表
|
||||||
|
*/
|
||||||
|
public Page<SysRole> getAllRoleListByPage(ConcurrentHashMap<String, String> searchInfo, String pageNumber, int roleType){
|
||||||
|
return sysRoleRepositoryImpl.getAllRoleListByPage(searchInfo,pageNumber,roleType);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<SysRole> list(ConcurrentHashMap<String, String> searchInfo, int pageNumber, int pageSize){
|
||||||
|
QueryHelper queryHelper = new QueryHelper("*", " FROM sys_role");
|
||||||
|
queryHelper.addCondition("is_deleted=0");
|
||||||
|
queryHelper.addCondition(searchInfo.containsKey("name"), "name like ?", "%" +
|
||||||
|
searchInfo.get("name") + "%");
|
||||||
|
queryHelper.addOrderProperty("created_time",false);
|
||||||
|
return pagination.paginate(queryHelper.getSql(), SysRole.class, pageNumber, pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SysRole> getAllRole(){
|
||||||
|
return sysRoleRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SysRole> getAllEnableSysRole(){
|
||||||
|
return sysRoleRepository.getAllEnableSysRole();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前角色类型所有下级角色
|
||||||
|
*/
|
||||||
|
public List<SysRole> geBelowRoleTypes(int roleType){
|
||||||
|
return sysRoleRepositoryImpl.geBelowRoleTypes(roleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SysRole> getBelowOneRoleTypes(int roleType){
|
||||||
|
return sysRoleRepositoryImpl.getBelowTypes(roleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SysRole fingSysRoleById(int id){
|
||||||
|
return sysRoleRepository.findSysRoleById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询 权限结构树(用于新增角色)
|
||||||
|
* @param roleId 当前登录人角色id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PermissionNode getPermissionNodeTree(int roleId){
|
||||||
|
//获取当前登录人角色所拥有的权限列表
|
||||||
|
List<SysPermission> permList=sysPermissionRepository.findPermissionByRoleId(roleId);
|
||||||
|
|
||||||
|
List<Integer> selectedPermIdList = new ArrayList<Integer>();
|
||||||
|
PermissionNode root = PermissionTree.parsePermsNodeTree(permList, selectedPermIdList);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询 权限结构树(用于编辑角色)
|
||||||
|
* @param adminRoleId 当前登录人角色id
|
||||||
|
* @param roleId 待分配角色id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PermissionNode getPermissionNodeTreeForEdit(int adminRoleId, int roleId){
|
||||||
|
|
||||||
|
List<SysPermission> permList=sysPermissionRepository.findPermissionByRoleId(adminRoleId);
|
||||||
|
//已分配的权限id
|
||||||
|
List<Integer> selectedPermIdList =sysRolePermissionService.getPermissionIds(roleId);
|
||||||
|
PermissionNode root = PermissionTree.parsePermsNodeTree(permList, selectedPermIdList);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增角色或编辑角色
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void addOrUpdatePermission(Map<String, Object> reqMap,int roleId){
|
||||||
|
int updateRoleId=0;
|
||||||
|
if(-1 == roleId){
|
||||||
|
// 新增角色
|
||||||
|
updateRoleId=addToRoleTable(reqMap);
|
||||||
|
} else{
|
||||||
|
// 修改角色
|
||||||
|
updateRoleId=updateToRoleTable(reqMap, roleId);
|
||||||
|
// 删除原"角色-权限"映射关系
|
||||||
|
sysRolePermissionRepository.deleteSysRolePermissionByRoleId(roleId);
|
||||||
|
}
|
||||||
|
// 获取权限选中PermissionID,写入tcm_sys_role_permission
|
||||||
|
saveRolePermission(reqMap,updateRoleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private int addToRoleTable(Map<String, Object> reqMap){
|
||||||
|
|
||||||
|
SysRole role=new SysRole();
|
||||||
|
role.setName(reqMap.get("roleName")!=null?reqMap.get("roleName").toString():null);
|
||||||
|
//role.setLevel(reqMap.containsKey("roleLevel")?Integer.parseInt(reqMap.get("roleLevel").toString()):1);//第一个版本 默认都是省级
|
||||||
|
role.setIsEnable(Integer.parseInt(reqMap.get("isActive").toString()));
|
||||||
|
//role.setType(Integer.parseInt(reqMap.get("roleType").toString()));
|
||||||
|
role.setCreatedBy(InterfaceUtil.getAdminId());//当前登录人
|
||||||
|
role.setCreatedTime(new Date());
|
||||||
|
role.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
role.setLastUpdatedTime(new Date());
|
||||||
|
role.setType(1);
|
||||||
|
role=sysRoleRepository.saveAndFlush(role);
|
||||||
|
return role.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存角色权限到关联表tcm_sys_role_permission
|
||||||
|
*/
|
||||||
|
private void saveRolePermission(Map<String, Object> reqMap,int roleId){
|
||||||
|
/* 从数据库获取所有权限ID-ParentID映射集合 */
|
||||||
|
Map<String, String> allPermissionMap = getAllPermissionMap();
|
||||||
|
/* 从参数中获取选中权限ID列表 */
|
||||||
|
List<String> selectPermissinoIdList = getSelectPermissionIdFromParams(reqMap, allPermissionMap);
|
||||||
|
/* 保存选中权限ID---->sys_role_permission表 */
|
||||||
|
saveSelectedPermissionIdList(roleId, selectPermissinoIdList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Title: 从数据库获取所有权限ID-ParentID映射集合
|
||||||
|
* @return Map<String,String>
|
||||||
|
*/
|
||||||
|
private Map<String, String> getAllPermissionMap(){
|
||||||
|
List<SysPermission> allPermission = sysPermissionRepository.findAllPermission();
|
||||||
|
|
||||||
|
Map<String, String> permIdMaps = new HashMap<String, String>();
|
||||||
|
for(SysPermission perm : allPermission){
|
||||||
|
permIdMaps.put(String.valueOf(perm.getId()), String.valueOf(perm.getParentId()));
|
||||||
|
}
|
||||||
|
return permIdMaps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Title: 从参数中获取选中permission
|
||||||
|
* @param allPermissionIDMap DB中所有权限ID集合
|
||||||
|
* @return Map<String,String> 选中PermissionID以及其父节点集合
|
||||||
|
*/
|
||||||
|
private List<String> getSelectPermissionIdFromParams(Map<String, Object> paraMap,
|
||||||
|
Map<String, String> allPermissionIDMap){
|
||||||
|
List<String> selectPermissinoIDList = new ArrayList<String>();
|
||||||
|
for(Map.Entry<String, Object> entry : paraMap.entrySet()){
|
||||||
|
if(entry.getKey().startsWith(SELECTED_PERMISSION_PREFIX)){
|
||||||
|
Object value = entry.getValue();
|
||||||
|
putParentPermissionIntoMap(allPermissionIDMap, selectPermissinoIDList, value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectPermissinoIDList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Title: 保存选中权限ID---->tcm_sys_role_permission表
|
||||||
|
* @param roleId 角色ID
|
||||||
|
* @param selectPermissinoIdList 选中权限ID列表
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void saveSelectedPermissionIdList(int roleId, List<String> selectPermissinoIdList){
|
||||||
|
for(String pId : selectPermissinoIdList){
|
||||||
|
save2RolePermission(roleId, pId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save2RolePermission(int roleId, String permissionId){
|
||||||
|
SysRolePermission rolePerm = new SysRolePermission();
|
||||||
|
rolePerm.setRoleId(roleId);
|
||||||
|
rolePerm.setPermissionId(Integer.parseInt(permissionId));
|
||||||
|
rolePerm.setCreatedBy(InterfaceUtil.getAdminId());
|
||||||
|
rolePerm.setCreatedTime(new Date());
|
||||||
|
rolePerm.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
rolePerm.setLastUpdatedTime(new Date());
|
||||||
|
sysRolePermissionRepository.saveAndFlush(rolePerm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Title: 找出当前节点的父节点,并放入Map中
|
||||||
|
*
|
||||||
|
* @param allPermissionMap 所有权限节点Map
|
||||||
|
* @param selectPermissinoIDList 新增角色权限Map
|
||||||
|
* @param permID 权限节点ID void
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void putParentPermissionIntoMap(Map<String, String> allPermissionMap, List<String> selectPermissinoIDList,
|
||||||
|
String permID){
|
||||||
|
/* 找出父节点,添加到待插入PermissionMaps中 */
|
||||||
|
String pid = permID;
|
||||||
|
while(true){
|
||||||
|
String parentID = allPermissionMap.get(pid);
|
||||||
|
if(pid.equals("0")){
|
||||||
|
break;
|
||||||
|
} else{
|
||||||
|
logger.info("pid=" + pid + ",parentID=" + parentID);
|
||||||
|
if(!selectPermissinoIDList.contains(pid)){
|
||||||
|
selectPermissinoIDList.add(pid);
|
||||||
|
}
|
||||||
|
pid = parentID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private int updateToRoleTable(Map<String, Object> reqMap, int roleId){
|
||||||
|
|
||||||
|
SysRole role =sysRoleRepository.findSysRoleById(roleId);
|
||||||
|
role.setName(reqMap.get("roleName").toString());
|
||||||
|
//role.setLevel(Integer.parseInt(reqMap.get("roleLevel").toString()));
|
||||||
|
//role.setType(Integer.parseInt(reqMap.get("roleType").toString()));
|
||||||
|
role.setIsEnable(Integer.parseInt(reqMap.get("isActive").toString()));
|
||||||
|
role.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
role.setLastUpdatedTime(new Date());
|
||||||
|
role=sysRoleRepository.saveAndFlush(role);
|
||||||
|
return role.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验该角色名是否存在
|
||||||
|
*/
|
||||||
|
public int cheakRoleName(int id,String name){
|
||||||
|
return sysRoleRepository.cheakRoleName(id, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional()
|
||||||
|
public String deleteSelectedPermission(String[] ids){
|
||||||
|
|
||||||
|
StringBuffer success=new StringBuffer();
|
||||||
|
StringBuffer fail=new StringBuffer();
|
||||||
|
int successCount=0;
|
||||||
|
int failCount=0;
|
||||||
|
for(String id : ids){
|
||||||
|
List<SysUserRole> userRoleList = sysUserRoleRepository.findRoleByRoleId(Integer.parseInt(id));
|
||||||
|
SysRole role = sysRoleRepository.findSysRoleById(Integer.parseInt(id));
|
||||||
|
if(userRoleList != null && userRoleList.size() > 0){
|
||||||
|
failCount++;
|
||||||
|
logger.info("角色[" + role.getName() + "]下存在用户,删除失败!");
|
||||||
|
fail.append("[" + role.getName() + "]");
|
||||||
|
}else {
|
||||||
|
role.setDeleted(1);
|
||||||
|
role.setLastUpdatedTime(new Date());
|
||||||
|
role.setLastUpdatedBy(InterfaceUtil.getAdminId());
|
||||||
|
sysRoleRepository.saveAndFlush(role);
|
||||||
|
deleteRolePermissionMap(id);
|
||||||
|
successCount++;
|
||||||
|
logger.info("角色[" + role.getName() + "],删除成功!");
|
||||||
|
success.append("[" + role.getName() + "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String allMsg="";
|
||||||
|
if (successCount==0&&failCount!=0){
|
||||||
|
allMsg=failCount+"个删除失败:"+fail.toString()+"下存在用户,删除失败!";
|
||||||
|
}else if (failCount==0&&successCount!=0) {
|
||||||
|
allMsg=successCount+"个删除成功:"+success.toString()+"。";
|
||||||
|
}else if (failCount!=0&&successCount!=0){
|
||||||
|
allMsg=successCount+"个删除成功:"+success.toString()+"。 "+failCount+"个删除失败:"+fail.toString()+"下存在用户,删除失败!";
|
||||||
|
}
|
||||||
|
return allMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色对应的权限 关联表
|
||||||
|
*/
|
||||||
|
private void deleteRolePermissionMap(String roleId){
|
||||||
|
sysRolePermissionRepository.deleteSysRolePermissionByRoleId(Integer.parseInt(roleId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用、禁用
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean enableOrDisable(int status, int id){
|
||||||
|
SysRole one = sysRoleRepository.findOne(id);
|
||||||
|
one.setIsEnable(status);
|
||||||
|
SysRole sysRole = sysRoleRepository.saveAndFlush(one);
|
||||||
|
|
||||||
|
if(null != sysRole){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package cn.palmte.work.service;
|
||||||
|
|
||||||
|
import cn.palmte.work.config.UploadProperties;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import sun.misc.BASE64Decoder;
|
||||||
|
import top.jfunc.common.datetime.DatetimeUtils;
|
||||||
|
import top.jfunc.common.utils.CommonUtil;
|
||||||
|
import top.jfunc.common.utils.FileUtil;
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan at 2020/10/13 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UploadService {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(UploadService.class);
|
||||||
|
public static final String DATA_IMAGE_PNG_BASE64 = "data:image/png;base64,";
|
||||||
|
public static final String DATA_IMAGE_JPEG_BASE64 = "data:image/jpeg;base64,";
|
||||||
|
public static final String DATA_IMAGE_JPG_BASE64 = "data:image/jpg;base64,";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UploadProperties uploadProperties;
|
||||||
|
|
||||||
|
public String upload(String base64Str){
|
||||||
|
String suffix = "png";
|
||||||
|
if (base64Str.contains(DATA_IMAGE_PNG_BASE64)) {
|
||||||
|
base64Str = base64Str.replaceAll(DATA_IMAGE_PNG_BASE64, "");
|
||||||
|
suffix = "png";
|
||||||
|
} else if (base64Str.contains(DATA_IMAGE_JPEG_BASE64)) {
|
||||||
|
base64Str = base64Str.replaceAll(DATA_IMAGE_JPEG_BASE64, "");
|
||||||
|
suffix = "jpeg";
|
||||||
|
}else if (base64Str.contains(DATA_IMAGE_JPG_BASE64)) {
|
||||||
|
base64Str = base64Str.replaceAll(DATA_IMAGE_JPG_BASE64, "");
|
||||||
|
suffix = "jpg";
|
||||||
|
}
|
||||||
|
String uploadPath = uploadProperties.getPath();
|
||||||
|
String uploadPrefix = uploadProperties.getPrefix();
|
||||||
|
String yyyyMMdd = DatetimeUtils.toStr(new Date(), "yyyyMMdd");
|
||||||
|
String saveDir = uploadPath + "/" + yyyyMMdd;
|
||||||
|
FileUtil.makeSureExistDir(saveDir);
|
||||||
|
|
||||||
|
String fileName = CommonUtil.randomString(32) + "." + suffix;
|
||||||
|
String absolutePath = saveDir + "/" + fileName;
|
||||||
|
File file = new File(absolutePath);
|
||||||
|
|
||||||
|
decodeAndWrite(base64Str , file);
|
||||||
|
|
||||||
|
return uploadPrefix + "/" + yyyyMMdd + "/" + fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void decodeAndWrite(String base64Str, File destFile) {
|
||||||
|
try {
|
||||||
|
// Base64解码
|
||||||
|
byte[] bytes = new BASE64Decoder().decodeBuffer(base64Str);
|
||||||
|
for (int i = 0; i < bytes.length; ++i) {
|
||||||
|
if (bytes[i] < 0) {
|
||||||
|
// 调整异常数据
|
||||||
|
bytes[i] += 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Files.write(Paths.get(destFile.getAbsolutePath()), bytes);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package cn.palmte.work.service.map;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiongshiyan at 2021/5/18 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
public class MemorySimpleMap<K,V> implements SimpleMap<K,V>{
|
||||||
|
private ConcurrentMap<K,V> concurrentMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V get(K k) {
|
||||||
|
return concurrentMap.get(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V delete(K k) {
|
||||||
|
return concurrentMap.remove(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(K k, V v, long expireIns) {
|
||||||
|
concurrentMap.put(k,v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<K> keys() {
|
||||||
|
return concurrentMap.keySet();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package cn.palmte.work.service.map;
|
||||||
|
|
||||||
|
import cn.palmte.work.config.SystemConfigWithMemory;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为以后引入redis做准备,实现此接口并替换实现即可{@link SystemConfigWithMemory#simpleMap()}
|
||||||
|
* @author xiongshiyan at 2021/5/18 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
public interface SimpleMap<K,V> {
|
||||||
|
V get(K k);
|
||||||
|
void set(K k,V v,long expireIns);
|
||||||
|
V delete(K k);
|
||||||
|
Set<K> keys();
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package cn.palmte.work.service.token.redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端API接口token管理器
|
||||||
|
* @author xiongshiyan at 2018/8/15 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
/*public class ApiTokenManager extends BaseMultiTokenManager<Manager> {
|
||||||
|
private String tokenPrefix;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getToken(Manager m){
|
||||||
|
return tokenPrefix + "-" + nowStr() + CommonUtil.randomString(16);
|
||||||
|
}
|
||||||
|
private String nowStr(){
|
||||||
|
return DatetimeUtils.toStr(new Date() , DatetimeUtils.SDF_DATETIME_SHORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String key(Manager member){
|
||||||
|
return tokenPrefix + "-" + member.getUserName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTokenPrefix() {
|
||||||
|
return tokenPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokenPrefix(String tokenPrefix) {
|
||||||
|
this.tokenPrefix = tokenPrefix;
|
||||||
|
}
|
||||||
|
}*/
|
|
@ -0,0 +1,29 @@
|
||||||
|
package cn.palmte.work.service.token.redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于redis的验证码管理器
|
||||||
|
* @author xiongshiyan at 2018/10/8 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
/*public class RedisCaptchaManager extends AbstractRedisCaptchaManager<Manager> {
|
||||||
|
private static final String REDIS_PREFIX = "captcha:";
|
||||||
|
private CaptchaCodeService captchaCodeService;
|
||||||
|
|
||||||
|
public void setCaptchaCodeService(CaptchaCodeService captchaCodeService) {
|
||||||
|
this.captchaCodeService = captchaCodeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] generateCodeImage(int width, int height, String code) throws IOException {
|
||||||
|
return captchaCodeService.generateCodeImage(width, height, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateCode(int numbers) {
|
||||||
|
return captchaCodeService.generateCode(numbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String key(Manager member){
|
||||||
|
return REDIS_PREFIX + member.getUserName();
|
||||||
|
}
|
||||||
|
}*/
|
|
@ -0,0 +1,13 @@
|
||||||
|
package cn.palmte.work.service.token.redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis实现错误管理器
|
||||||
|
* @author xiongshiyan at 2018/10/8 , contact me with email yanshixiong@126.com or phone 15208384257
|
||||||
|
*/
|
||||||
|
/*public class RedisErrorCountManager extends AbstractRedisErrorCountManager<Manager> {
|
||||||
|
private static final String REDIS_PREFIX = "errorCount:";
|
||||||
|
@Override
|
||||||
|
protected String key(Manager member){
|
||||||
|
return REDIS_PREFIX + member.getUserName();
|
||||||
|
}
|
||||||
|
}*/
|
|
@ -0,0 +1,115 @@
|
||||||
|
package cn.palmte.work.shiro;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.model.Admin;
|
||||||
|
import cn.palmte.work.service.AdminService;
|
||||||
|
import org.apache.shiro.authc.*;
|
||||||
|
import org.apache.shiro.authz.AuthorizationException;
|
||||||
|
import org.apache.shiro.authz.AuthorizationInfo;
|
||||||
|
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||||
|
import org.apache.shiro.realm.AuthorizingRealm;
|
||||||
|
import org.apache.shiro.subject.PrincipalCollection;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/4/17.
|
||||||
|
*/
|
||||||
|
public class ShiroAuthorizingRealm extends AuthorizingRealm {
|
||||||
|
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(ShiroAuthorizingRealm.class);
|
||||||
|
private static final String AUTHORITIES = "authorities";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdminService adminService;
|
||||||
|
|
||||||
|
//shiro的权限配置方法
|
||||||
|
@Override
|
||||||
|
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||||
|
|
||||||
|
logger.debug("权限配置-->doGetAuthorizationInfo");
|
||||||
|
|
||||||
|
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
|
||||||
|
logger.debug("----------------------------->" + principals.getPrimaryPrincipal());
|
||||||
|
// 获取当前登录的用户名
|
||||||
|
ShiroPrincipal subject = (ShiroPrincipal) super.getAvailablePrincipal(principals);
|
||||||
|
String adminName = subject.getAdminName();
|
||||||
|
String adminId = subject.getId();
|
||||||
|
HttpSession session = getSession();
|
||||||
|
try {
|
||||||
|
if (!subject.isAuthorized()) {
|
||||||
|
// 根据用户名称,获取该用户所有的权限列表
|
||||||
|
List<String> authorities = adminService.getAuthoritiesName(adminId);
|
||||||
|
List<String> rolelist = adminService.getRolesName(adminId);
|
||||||
|
// List<String> urls = adminService.getAuthoritieUrls(adminId);
|
||||||
|
//subject.setAuthorities(authorities);
|
||||||
|
session.setAttribute(AUTHORITIES, authorities);
|
||||||
|
subject.setRoles(rolelist);
|
||||||
|
// subject.setUrls(urls);
|
||||||
|
subject.setAuthorized(true);
|
||||||
|
logger.debug("用户【" + adminName + "】授权初始化成功......");
|
||||||
|
logger.debug("用户【" + adminName + "】 角色列表为:" + subject.getRoles());
|
||||||
|
logger.debug("用户【" + adminName + "】 权限列表为:" + authorities);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new AuthorizationException("用户【" + adminName + "】授权失败");
|
||||||
|
}
|
||||||
|
// 给当前用户设置权限
|
||||||
|
|
||||||
|
List<String> authorities = null;
|
||||||
|
if (session.getAttribute(AUTHORITIES) != null) {
|
||||||
|
authorities = (List<String>) session.getAttribute(AUTHORITIES);
|
||||||
|
}
|
||||||
|
authorizationInfo.addStringPermissions(authorities);
|
||||||
|
authorizationInfo.addRoles(subject.getRoles());
|
||||||
|
return authorizationInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
//shiro的身份验证方法
|
||||||
|
@Override
|
||||||
|
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
|
||||||
|
|
||||||
|
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
|
||||||
|
String username = upToken.getUsername();
|
||||||
|
|
||||||
|
if (username == null) {
|
||||||
|
logger.warn("用户名不能为空");
|
||||||
|
throw new AccountException("用户名不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
Admin admin = null;
|
||||||
|
try {
|
||||||
|
admin = adminService.getAdminByUsername(username);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.warn("获取用户失败\n" + ex.getMessage());
|
||||||
|
}
|
||||||
|
if (admin == null) {
|
||||||
|
logger.warn("用户不存在");
|
||||||
|
throw new UnknownAccountException("用户不存在!");
|
||||||
|
}
|
||||||
|
ShiroPrincipal subject = new ShiroPrincipal(admin);
|
||||||
|
String adminId = String.valueOf(admin.getId());
|
||||||
|
List<String> authorities = adminService.getAuthoritiesName(adminId);
|
||||||
|
List<String> rolelist = adminService.getRolesName(adminId);
|
||||||
|
// List<String> urls = adminService.getAuthoritieUrls(adminId);
|
||||||
|
// subject.setUrls(urls);
|
||||||
|
subject.setRoles(rolelist);
|
||||||
|
//subject.setAuthorities(authorities);
|
||||||
|
HttpSession session = getSession();
|
||||||
|
session.setAttribute(AUTHORITIES, authorities);
|
||||||
|
subject.setAuthorized(true);
|
||||||
|
return new SimpleAuthenticationInfo(subject, admin.getPassword(), getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpSession getSession() {
|
||||||
|
return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest().getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,163 @@
|
||||||
|
package cn.palmte.work.shiro;
|
||||||
|
|
||||||
|
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
|
||||||
|
import org.apache.shiro.cache.MemoryConstrainedCacheManager;
|
||||||
|
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||||
|
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||||
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||||
|
import org.apache.shiro.web.mgt.CookieRememberMeManager;
|
||||||
|
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||||
|
import org.apache.shiro.web.servlet.SimpleCookie;
|
||||||
|
import org.apache.shiro.mgt.SecurityManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/4/17.
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class ShiroConfig {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ShiroFilterFactoryBean.class);
|
||||||
|
|
||||||
|
@Bean(name = "securityManager")
|
||||||
|
public SecurityManager securityManager(@Qualifier("shiroAuthorizingRealm") ShiroAuthorizingRealm shiroAuthorizingRealm,
|
||||||
|
@Qualifier("cookieRememberMeManager") CookieRememberMeManager cookieRememberMeManager) {
|
||||||
|
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
||||||
|
// 设置realm.
|
||||||
|
securityManager.setRealm(shiroAuthorizingRealm);
|
||||||
|
|
||||||
|
// 设置rememberMe管理器
|
||||||
|
securityManager.setRememberMeManager(cookieRememberMeManager);
|
||||||
|
// 设置缓存管理器
|
||||||
|
securityManager.setCacheManager(new MemoryConstrainedCacheManager());
|
||||||
|
return securityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* realm
|
||||||
|
*/
|
||||||
|
@Bean(name = "shiroAuthorizingRealm")
|
||||||
|
public ShiroAuthorizingRealm shiroAuthorizingRealm(
|
||||||
|
@Qualifier("simpleCredentialsMatcher") SimpleCredentialsMatcher matcher
|
||||||
|
) {
|
||||||
|
// @Qualifier("ehCacheManager") EhCacheManager ehCacheManager
|
||||||
|
log.info("myShiroRealm()");
|
||||||
|
ShiroAuthorizingRealm myAuthorizingRealm = new ShiroAuthorizingRealm();
|
||||||
|
// 设置密码凭证匹配器
|
||||||
|
myAuthorizingRealm.setCredentialsMatcher(matcher); // myShiroRealm.setCredentialsMatcher(hashedCredentialsMatcher());
|
||||||
|
|
||||||
|
return myAuthorizingRealm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cookie对象;
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public SimpleCookie rememberMeCookie() {
|
||||||
|
log.info("rememberMeCookie()");
|
||||||
|
// 这个参数是cookie的名称,对应前端的checkbox 的name = rememberMe
|
||||||
|
SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
|
||||||
|
// <!-- 记住我cookie生效时间30天(259200) ,单位秒;-->
|
||||||
|
simpleCookie.setMaxAge(600);
|
||||||
|
return simpleCookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记住我管理器 cookie管理对象;
|
||||||
|
*/
|
||||||
|
@Bean(name = "cookieRememberMeManager")
|
||||||
|
public CookieRememberMeManager rememberMeManager() {
|
||||||
|
System.out.println("rememberMeManager()");
|
||||||
|
CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
|
||||||
|
cookieRememberMeManager.setCookie(rememberMeCookie());
|
||||||
|
return cookieRememberMeManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码匹配凭证管理器
|
||||||
|
*/
|
||||||
|
@Bean(name = "simpleCredentialsMatcher")
|
||||||
|
public SimpleCredentialsMatcher simpleCredentialsMatcher() {
|
||||||
|
SimpleCredentialsMatcher simpleCredentialsMatcher = new SimpleCredentialsMatcher();
|
||||||
|
return simpleCredentialsMatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开启shiro aop注解支持. 使用代理方式;所以需要开启代码支持; Controller才能使用@RequiresPermissions
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
|
||||||
|
@Qualifier("securityManager") SecurityManager securityManager) {
|
||||||
|
log.info("authorizationAttributeSourceAdvisor()");
|
||||||
|
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
||||||
|
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
|
||||||
|
return authorizationAttributeSourceAdvisor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shiro管理生命周期的东西
|
||||||
|
*/
|
||||||
|
@Bean(name = "lifecycleBeanPostProcessor")
|
||||||
|
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||||
|
return new LifecycleBeanPostProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager securityManager) {
|
||||||
|
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||||
|
|
||||||
|
// 必须设置 SecurityManager
|
||||||
|
shiroFilterFactoryBean.setSecurityManager(securityManager);
|
||||||
|
// 拦截器.
|
||||||
|
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
|
//特殊URL放开
|
||||||
|
map.put("/admin/login", "anon");
|
||||||
|
map.put("/admin/logout", "logout");
|
||||||
|
map.put("/admin/singIn", "anon");
|
||||||
|
map.put("/admin/err", "anon");
|
||||||
|
map.put("/admin/captcha", "anon");
|
||||||
|
map.put("/api/**", "anon");
|
||||||
|
map.put("/file/**", "anon");
|
||||||
|
|
||||||
|
|
||||||
|
//静态资源放开, 以后所有的静态资源都放到这些目录下,否则需要在此添加映射
|
||||||
|
map.put("/assets/**", "anon");
|
||||||
|
map.put("/common/**", "anon");
|
||||||
|
map.put("/favicon.png", "anon");
|
||||||
|
map.put("/img/**", "anon");
|
||||||
|
map.put("/jqPaginator/**", "anon");
|
||||||
|
map.put("/layer/**", "anon");
|
||||||
|
map.put("/ueditor/**", "anon");
|
||||||
|
map.put("/favicon.png", "anon");
|
||||||
|
|
||||||
|
|
||||||
|
// map.put("/admin/login", "authc");
|
||||||
|
// map.put("/admin/center", "authc");
|
||||||
|
// map.put("/admin/console", "authc");
|
||||||
|
// map.put("/account/password", "authc");
|
||||||
|
// map.put("/account/updatePassword", "authc");
|
||||||
|
map.put("/**", "authc");
|
||||||
|
|
||||||
|
// 如果不设置默认会自动寻找Web工程根目录下的"/login.jsp"页面
|
||||||
|
shiroFilterFactoryBean.setLoginUrl("/admin/login");
|
||||||
|
// 登录成功后要跳转的链接
|
||||||
|
shiroFilterFactoryBean.setSuccessUrl("/admin/center");
|
||||||
|
// 未授权界面;
|
||||||
|
shiroFilterFactoryBean.setUnauthorizedUrl("/403");
|
||||||
|
|
||||||
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
|
||||||
|
// Map<String,Filter> filterMap = new LinkedHashMap<>();
|
||||||
|
// filterMap.put("perms",new ShiroPermissionsFilter());
|
||||||
|
// shiroFilterFactoryBean.setFilters(filterMap);
|
||||||
|
return shiroFilterFactoryBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package cn.palmte.work.shiro;
|
||||||
|
|
||||||
|
import cn.palmte.work.service.SysPermissionService;
|
||||||
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/5/6.
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ShiroPermissionsFilter extends PermissionsAuthorizationFilter {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysPermissionService sysPermissionService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException {
|
||||||
|
|
||||||
|
// 记录日志
|
||||||
|
|
||||||
|
/**获取用户信息,可以根据用户信息查看有没有对应模块的权限*/
|
||||||
|
ShiroPrincipal principal = (ShiroPrincipal) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
//获得请求路径
|
||||||
|
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
||||||
|
String path = httpServletRequest.getServletPath();
|
||||||
|
//true有权限; false没有权限
|
||||||
|
boolean isPermitted = true;
|
||||||
|
/*if(sysPermissionService==null){
|
||||||
|
sysPermissionService= (SysPermissionService) SpringContextUtils.getContext().getBean("sysPermissionService");
|
||||||
|
}*/
|
||||||
|
List<String> allUrls = sysPermissionService.getAllPermissionList();
|
||||||
|
if (principal != null && allUrls.contains(path)) {
|
||||||
|
List<String> urls = principal.getUrls();
|
||||||
|
if (!urls.contains(path)) {
|
||||||
|
isPermitted = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isPermitted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shiro认证perms资源失败后回调方法
|
||||||
|
*
|
||||||
|
* @param servletRequest
|
||||||
|
* @param servletResponse
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException {
|
||||||
|
try {
|
||||||
|
servletResponse.setCharacterEncoding("UTF-8");
|
||||||
|
servletResponse.setContentType("application/json");
|
||||||
|
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
|
||||||
|
httpServletResponse.sendRedirect("../common/401.html");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package cn.palmte.work.shiro;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import cn.palmte.work.model.Admin;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/4/17.
|
||||||
|
*/
|
||||||
|
public class ShiroPrincipal implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5547892266826282572L;
|
||||||
|
// 用户对象
|
||||||
|
private Admin admin;
|
||||||
|
// 用户权限列表
|
||||||
|
private List<String> authorities = new ArrayList<String>();
|
||||||
|
// 用户角色列表
|
||||||
|
private List<String> roles = new ArrayList<String>();
|
||||||
|
// 是否已授权。如果已授权,则不需要再从数据库中获取权限信息,减少数据库访问
|
||||||
|
// 这里会导致修改权限时,需要重新登录方可有效
|
||||||
|
private boolean isAuthorized = false;
|
||||||
|
|
||||||
|
private List<String> urls = new ArrayList<String>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数,参数为Admin对象 根据Admin对象属性,赋值给Principal相应的属性上
|
||||||
|
*
|
||||||
|
* @param admin
|
||||||
|
*/
|
||||||
|
public ShiroPrincipal(Admin admin) {
|
||||||
|
this.admin = admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getUrls() {
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrls(List<String> urls) {
|
||||||
|
this.urls = urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAuthorities() {
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthorities(List<String> authorities) {
|
||||||
|
this.authorities = authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRoles() {
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(List<String> roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAuthorized() {
|
||||||
|
return isAuthorized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthorized(boolean isAuthorized) {
|
||||||
|
this.isAuthorized = isAuthorized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Admin getAdmin() {
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdmin(Admin admin) {
|
||||||
|
this.admin = admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAdminName() {
|
||||||
|
return this.admin.getUserName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return String.valueOf(this.admin.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <shiro:principal/>标签显示中文名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.admin.getUserName();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package cn.palmte.work.shiro;
|
||||||
|
|
||||||
|
import com.jagregory.shiro.freemarker.ShiroTags;
|
||||||
|
import freemarker.template.TemplateModelException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author NSP
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ShiroTagsFreeMarkerCfg {
|
||||||
|
@Autowired
|
||||||
|
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void setSharedVariable() throws TemplateModelException {
|
||||||
|
|
||||||
|
freeMarkerConfigurer.getConfiguration().setSharedVariable("shiro", new ShiroTags());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package cn.palmte.work.shiro;
|
||||||
|
|
||||||
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.apache.shiro.subject.Subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by wang.lin@esstx.cn on 2018/4/20.
|
||||||
|
*/
|
||||||
|
public class ShiroUtils {
|
||||||
|
protected static Subject getSubject() {
|
||||||
|
return SecurityUtils.getSubject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPermission(String permission) {
|
||||||
|
return getSubject() != null && permission != null && permission.length() > 0 && getSubject().isPermitted(permission);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package cn.palmte.work.utils;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import top.jfunc.common.crypto.symmetric.Base64;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BASE64编码解码工具包
|
||||||
|
* 依赖javabase64-1.3.1.jar
|
||||||
|
*
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class Base64Utils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件读取缓冲区大小
|
||||||
|
*/
|
||||||
|
private static final int CACHE_SIZE = 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BASE64字符串解码为二进制数据
|
||||||
|
*/
|
||||||
|
public static byte[] decode(String base64) throws Exception {
|
||||||
|
return Base64.decode(base64.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二进制数据编码为BASE64字符串
|
||||||
|
*/
|
||||||
|
public static String encode(byte[] bytes) throws Exception {
|
||||||
|
return Base64.encode(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将文件编码为BASE64字符串
|
||||||
|
* 大文件慎用,可能会导致内存溢出
|
||||||
|
*/
|
||||||
|
public static String encodeFile(String filePath) throws Exception {
|
||||||
|
byte[] bytes = fileToByte(filePath);
|
||||||
|
return encode(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BASE64字符串转回文件
|
||||||
|
* @param filePath 文件绝对路径
|
||||||
|
* @param base64 编码字符串
|
||||||
|
*/
|
||||||
|
public static void decodeToFile(String filePath, String base64) throws Exception {
|
||||||
|
byte[] bytes = decode(base64);
|
||||||
|
byteArrayToFile(bytes, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件转换为二进制数组
|
||||||
|
*
|
||||||
|
* @param filePath 文件路径
|
||||||
|
*/
|
||||||
|
public static byte[] fileToByte(String filePath) throws Exception {
|
||||||
|
byte[] data = new byte[0];
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (file.exists()) {
|
||||||
|
FileInputStream in = new FileInputStream(file);
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
|
||||||
|
byte[] cache = new byte[CACHE_SIZE];
|
||||||
|
int nRead = 0;
|
||||||
|
while ((nRead = in.read(cache)) != -1) {
|
||||||
|
out.write(cache, 0, nRead);
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
data = out.toByteArray();
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二进制数据写文件
|
||||||
|
*
|
||||||
|
* @param bytes 二进制数据
|
||||||
|
* @param filePath 文件生成目录
|
||||||
|
*/
|
||||||
|
public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception {
|
||||||
|
InputStream in = new ByteArrayInputStream(bytes);
|
||||||
|
File destFile = new File(filePath);
|
||||||
|
if (!destFile.getParentFile().exists()) {
|
||||||
|
destFile.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
destFile.createNewFile();
|
||||||
|
OutputStream out = new FileOutputStream(destFile);
|
||||||
|
byte[] cache = new byte[CACHE_SIZE];
|
||||||
|
int nRead = 0;
|
||||||
|
while ((nRead = in.read(cache)) != -1) {
|
||||||
|
out.write(cache, 0, nRead);
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue