├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── README.md
├── generatorConfig.xml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ └── cn
│ │ └── chenxins
│ │ ├── CmsApplication.java
│ │ ├── authorization
│ │ ├── annotation
│ │ │ ├── AdminRequired.java
│ │ │ ├── GroupRequired.java
│ │ │ ├── LoggerReg.java
│ │ │ ├── LoginRequired.java
│ │ │ └── RefreshTokenRequired.java
│ │ ├── interceptor
│ │ │ └── AuthorizationInterceptor.java
│ │ └── manager
│ │ │ ├── TokenManager.java
│ │ │ └── impl
│ │ │ └── RedisTokenManager.java
│ │ ├── cms
│ │ ├── controller
│ │ │ ├── AdminConroller.java
│ │ │ ├── LogConroller.java
│ │ │ ├── TestConroller.java
│ │ │ ├── UserConroller.java
│ │ │ └── v1
│ │ │ │ └── BookConroller.java
│ │ ├── model
│ │ │ ├── entity
│ │ │ │ ├── Book.java
│ │ │ │ ├── LinAuth.java
│ │ │ │ ├── LinGroup.java
│ │ │ │ ├── LinLog.java
│ │ │ │ ├── LinUser.java
│ │ │ │ └── mapper
│ │ │ │ │ ├── BookMapper.java
│ │ │ │ │ ├── LinAuthMapper.java
│ │ │ │ │ ├── LinGroupMapper.java
│ │ │ │ │ ├── LinLogMapper.java
│ │ │ │ │ └── LinUserMapper.java
│ │ │ └── json
│ │ │ │ ├── AuthJosnOut.java
│ │ │ │ ├── AuthJsonIn.java
│ │ │ │ ├── BookJsonIn.java
│ │ │ │ ├── GroupAuthJsonIn.java
│ │ │ │ ├── GroupAuthJsonOut.java
│ │ │ │ ├── GroupPageJsonOut.java
│ │ │ │ ├── LogPageJsonOut.java
│ │ │ │ ├── TokenJsonOut.java
│ │ │ │ ├── UserJsonIn.java
│ │ │ │ ├── UserJsonOut.java
│ │ │ │ └── UserPageJsonOut.java
│ │ └── service
│ │ │ ├── AdminService.java
│ │ │ ├── BookService.java
│ │ │ ├── LogService.java
│ │ │ └── UserService.java
│ │ ├── exception
│ │ ├── BussinessErrorException.java
│ │ ├── ParamValueException.java
│ │ └── TokenException.java
│ │ └── utils
│ │ ├── ConstConfig.java
│ │ ├── DesUtils.java
│ │ ├── GeneratorMyBatiss.java
│ │ ├── JdateUtils.java
│ │ ├── JsonUtils.java
│ │ ├── MetaJson.java
│ │ ├── MvcConfig.java
│ │ ├── MyMapper.java
│ │ ├── RedisOperator.java
│ │ ├── ResultJson.java
│ │ └── StringUtil.java
└── resources
│ ├── application.properties
│ ├── application.yml
│ └── mapper
│ ├── BookMapper.xml
│ ├── LinAuthMapper.xml
│ ├── LinGroupMapper.xml
│ ├── LinLogMapper.xml
│ └── LinUserMapper.xml
└── test
└── java
└── cn
└── chenxins
├── CmsApplicationCreateSuperUser.java
├── CmsApplicationTests.java
└── lincms.sql
/.gitignore:
--------------------------------------------------------------------------------
1 | <<<<<<< HEAD
2 | # Compiled class file
3 | *.class
4 |
5 | # Log file
6 | *.log
7 |
8 | # BlueJ files
9 | *.ctxt
10 |
11 | # Mobile Tools for Java (J2ME)
12 | .mtj.tmp/
13 |
14 | # Package Files #
15 | *.jar
16 | *.war
17 | *.nar
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 | =======
26 | /target/
27 | !.mvn/wrapper/maven-wrapper.jar
28 |
29 | ### STS ###
30 | .apt_generated
31 | .classpath
32 | .factorypath
33 | .project
34 | .settings
35 | .springBeans
36 | .sts4-cache
37 |
38 | ### IntelliJ IDEA ###
39 | .idea
40 | *.iws
41 | *.iml
42 | *.ipr
43 |
44 | ### NetBeans ###
45 | /nbproject/private/
46 | /build/
47 | /nbbuild/
48 | /dist/
49 | /nbdist/
50 | /.nb-gradle/
51 | >>>>>>> init files
52 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jandy0414/lincms-java/7fefc593ea4d11d082de544ef23ef5374e9ed10d/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # lincms-java
3 | lincms的java Spring boot 实现的后台版本 ,对应 '七月'的开源项目的。
4 |
5 | ##### lincms-java的前端是Vue实现的,对应的源代码如下地址
6 | [https://github.com/TaleLin/lin-cms-vue](https://github.com/TaleLin/lin-cms-vue)
7 |
8 | ##### lincms-java的接口及编程思维借鉴 ,'七月'的风格,其代码如下地址
9 | [https://github.com/TaleLin/lin-cms-flask](https://github.com/TaleLin/lin-cms-flask)
10 |
11 |
12 | # 系统技术栈
13 | #### 1、使用redis缓存的token信息
14 | #### 2、架构层级在经典MVC架构,稍作调整
15 | 1)、实体层除了对接底层数据库的,另增加对应需要序列化输出及入参输入json层
16 | 2)、业务处理service:业务逻辑尽可能在这层,并在此可调dao层
17 | 3)、control 尽可能遵循RESTFUL风格的接口控制层
18 | 4)、authorization:权限注解及全局的权限验证处理
19 | #### 3、使用第三方的tk.mybatis 做为数据库中间件
20 |
21 | ## 其他说明
22 | ## 本系统仅供学习研究。
23 | ##### 能力有限不足之处欢迎指正!
24 | ##### 联系方式:1142682991@qq.com
25 |
26 |
--------------------------------------------------------------------------------
/generatorConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Mingw, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | ##########################################################################################
204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
205 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
206 | ##########################################################################################
207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
208 | if [ "$MVNW_VERBOSE" = true ]; then
209 | echo "Found .mvn/wrapper/maven-wrapper.jar"
210 | fi
211 | else
212 | if [ "$MVNW_VERBOSE" = true ]; then
213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
214 | fi
215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
216 | while IFS="=" read key value; do
217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
218 | esac
219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
220 | if [ "$MVNW_VERBOSE" = true ]; then
221 | echo "Downloading from: $jarUrl"
222 | fi
223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
224 |
225 | if command -v wget > /dev/null; then
226 | if [ "$MVNW_VERBOSE" = true ]; then
227 | echo "Found wget ... using wget"
228 | fi
229 | wget "$jarUrl" -O "$wrapperJarPath"
230 | elif command -v curl > /dev/null; then
231 | if [ "$MVNW_VERBOSE" = true ]; then
232 | echo "Found curl ... using curl"
233 | fi
234 | curl -o "$wrapperJarPath" "$jarUrl"
235 | else
236 | if [ "$MVNW_VERBOSE" = true ]; then
237 | echo "Falling back to using Java to download"
238 | fi
239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
240 | if [ -e "$javaClass" ]; then
241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
242 | if [ "$MVNW_VERBOSE" = true ]; then
243 | echo " - Compiling MavenWrapperDownloader.java ..."
244 | fi
245 | # Compiling the Java class
246 | ("$JAVA_HOME/bin/javac" "$javaClass")
247 | fi
248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
249 | # Running the downloader
250 | if [ "$MVNW_VERBOSE" = true ]; then
251 | echo " - Running MavenWrapperDownloader.java ..."
252 | fi
253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
254 | fi
255 | fi
256 | fi
257 | fi
258 | ##########################################################################################
259 | # End of extension
260 | ##########################################################################################
261 |
262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
263 | if [ "$MVNW_VERBOSE" = true ]; then
264 | echo $MAVEN_PROJECTBASEDIR
265 | fi
266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
267 |
268 | # For Cygwin, switch paths to Windows format before running java
269 | if $cygwin; then
270 | [ -n "$M2_HOME" ] &&
271 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
272 | [ -n "$JAVA_HOME" ] &&
273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
274 | [ -n "$CLASSPATH" ] &&
275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
276 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
278 | fi
279 |
280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281 |
282 | exec "$JAVACMD" \
283 | $MAVEN_OPTS \
284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
287 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126 | )
127 |
128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130 | if exist %WRAPPER_JAR% (
131 | echo Found %WRAPPER_JAR%
132 | ) else (
133 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
134 | echo Downloading from: %DOWNLOAD_URL%
135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136 | echo Finished downloading %WRAPPER_JAR%
137 | )
138 | @REM End of extension
139 |
140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
141 | if ERRORLEVEL 1 goto error
142 | goto end
143 |
144 | :error
145 | set ERROR_CODE=1
146 |
147 | :end
148 | @endlocal & set ERROR_CODE=%ERROR_CODE%
149 |
150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
154 | :skipRcPost
155 |
156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
158 |
159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
160 |
161 | exit /B %ERROR_CODE%
162 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.1.2.RELEASE
9 |
10 |
11 | cn.chenxins
12 | lin-cms
13 | 0.0.1-SNAPSHOT
14 | cms
15 | lin-cms project for Spring Boot
16 |
17 |
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 |
29 | org.mybatis.spring.boot
30 | mybatis-spring-boot-starter
31 | 1.3.1
32 |
33 |
34 |
35 | tk.mybatis
36 | mapper-spring-boot-starter
37 | 1.2.4
38 |
39 |
40 |
41 | com.github.pagehelper
42 | pagehelper-spring-boot-starter
43 | 1.2.3
44 |
45 |
46 | org.mybatis.generator
47 | mybatis-generator-core
48 | 1.3.2
49 | compile
50 | true
51 |
52 |
53 |
54 | mysql
55 | mysql-connector-java
56 | runtime
57 | 5.1.41
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-starter-test
62 | test
63 |
64 |
65 |
66 |
67 | com.alibaba
68 | druid
69 | 1.1.0
70 |
71 |
72 | org.springframework.boot
73 | spring-boot-starter-data-redis
74 |
75 |
76 |
77 | org.springframework.boot
78 | spring-boot-configuration-processor
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | org.springframework.boot
93 | spring-boot-maven-plugin
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/CmsApplication.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.ComponentScan;
6 | import org.springframework.stereotype.Component;
7 | import tk.mybatis.spring.annotation.MapperScan;
8 |
9 | @MapperScan(basePackages = "cn.chenxins.cms.model.entity.mapper")
10 | @SpringBootApplication
11 | public class CmsApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(CmsApplication.class, args);
15 | }
16 |
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/annotation/AdminRequired.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 在Controller的方法上使用此注解,该方法在映射时会检查用户是否登录,未登录返回401错误
10 | * @see cn.chenxins.authorization.interceptor.AuthorizationInterceptor
11 | * @author jandy.chen
12 | * @date 2019/1/23.
13 | */
14 | @Target(ElementType.METHOD)
15 | @Retention(RetentionPolicy.RUNTIME)
16 | public @interface AdminRequired {
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/annotation/GroupRequired.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 在Controller的方法上使用此注解,该方法在映射时会检查用户是否登录,未登录返回401错误
10 | * @see cn.chenxins.authorization.interceptor.AuthorizationInterceptor
11 | * @author jandy.chen
12 | * @date 2019/1/23.
13 | */
14 | @Target(ElementType.METHOD)
15 | @Retention(RetentionPolicy.RUNTIME)
16 | public @interface GroupRequired {
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/annotation/LoggerReg.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 在Controller的方法上使用此注解,该方法在映射时会检查用户是否登录,未登录返回401错误
10 | * @see cn.chenxins.authorization.interceptor.AuthorizationInterceptor
11 | * @author jandy.chen
12 | * @date 2019/1/31.
13 | */
14 | @Target(ElementType.METHOD)
15 | @Retention(RetentionPolicy.RUNTIME)
16 | public @interface LoggerReg {
17 |
18 | String template() default "";
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/annotation/LoginRequired.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 在Controller的方法上使用此注解,该方法在映射时会检查用户是否登录,未登录返回401错误
10 | * @see cn.chenxins.authorization.interceptor.AuthorizationInterceptor
11 | * @author jandy.chen
12 | * @date 2019/1/23.
13 | */
14 | @Target(ElementType.METHOD)
15 | @Retention(RetentionPolicy.RUNTIME)
16 | public @interface LoginRequired {
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/annotation/RefreshTokenRequired.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 在Controller的方法上使用此注解,该方法在映射时会检查用户是否登录,未登录返回401错误
10 | * @see cn.chenxins.authorization.interceptor.AuthorizationInterceptor
11 | * @author jandy.chen
12 | * @date 2019/1/25
13 | */
14 | @Target(ElementType.METHOD)
15 | @Retention(RetentionPolicy.RUNTIME)
16 | public @interface RefreshTokenRequired {
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/interceptor/AuthorizationInterceptor.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.interceptor;
2 |
3 | import cn.chenxins.authorization.annotation.*;
4 | import cn.chenxins.authorization.manager.TokenManager;
5 | import cn.chenxins.cms.model.entity.LinLog;
6 | import cn.chenxins.cms.model.entity.LinUser;
7 | import cn.chenxins.cms.service.LogService;
8 | import cn.chenxins.cms.service.UserService;
9 | import cn.chenxins.utils.*;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.http.MediaType;
12 | import org.springframework.stereotype.Component;
13 | import org.springframework.web.context.WebApplicationContext;
14 | import org.springframework.web.method.HandlerMethod;
15 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
16 |
17 | import javax.servlet.http.HttpServletRequest;
18 | import javax.servlet.http.HttpServletResponse;
19 | import java.io.BufferedWriter;
20 | import java.io.OutputStreamWriter;
21 | import java.lang.reflect.Method;
22 | import java.util.Base64;
23 | import java.util.Map;
24 |
25 | @Component
26 | public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
27 |
28 | @Autowired
29 | private TokenManager manager;
30 |
31 | @Autowired
32 | private UserService userService;
33 |
34 | @Autowired
35 | private LogService logService;
36 |
37 |
38 |
39 | @Autowired
40 | WebApplicationContext applicationContext;
41 |
42 | @Override
43 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
44 | // System.out.println("afterCompletion");
45 | //如果不是映射到方法直接通过
46 | if (!(handler instanceof HandlerMethod)) {
47 | return;
48 | }
49 | HandlerMethod handlerMethod = (HandlerMethod) handler;
50 | Method method = handlerMethod.getMethod();
51 | LoggerReg loggerReg=method.getAnnotation(LoggerReg.class);
52 | if (loggerReg != null && loggerReg.template()!=null) {
53 | //根据方法声明的注解走相应的验证流程
54 | try {
55 | String template=loggerReg.template();
56 | LinUser user=getCurrentUser(request);
57 | if (user==null)
58 | {
59 | user=new LinUser();
60 | user.setId(999999);
61 | user.setNickname("匿名用户");
62 | }
63 | String msg=template.replaceAll("\\{user.nickname\\}",user.getNickname());
64 | LinLog log=new LinLog();
65 | log.setMessage(msg);
66 | log.setTime(JdateUtils.getCurrentDate());
67 | log.setUserId(user.getId());
68 | log.setUserName(user.getNickname());
69 | log.setMethod(request.getMethod());
70 | log.setPath(request.getRequestURI());
71 | log.setStatusCode(response.getStatus());
72 | Map authMap=MetaJson.getMetaMapUsingUri(applicationContext);
73 | if (authMap!=null){
74 | MetaJson metaJson=authMap.get(request.getRequestURI());
75 | if (metaJson!=null &&metaJson.getAuth()!=null)
76 | {
77 | log.setAuthority(metaJson.getAuth());
78 | }
79 | }
80 | logService.saveLog(log);
81 |
82 | System.out.println("Logger reg finish:"+log.toString());
83 |
84 | }catch (Exception e) {
85 | e.printStackTrace();
86 | return;
87 | }
88 | }
89 | }
90 |
91 | public boolean preHandle(HttpServletRequest request,
92 | HttpServletResponse response, Object handler) {
93 | //如果不是映射到方法直接通过
94 | if (!(handler instanceof HandlerMethod)) {
95 | return true;
96 | }
97 | HandlerMethod handlerMethod = (HandlerMethod) handler;
98 | Method method = handlerMethod.getMethod();
99 | //根据方法声明的注解走相应的验证流程
100 | try {
101 | if (method.getAnnotation(LoginRequired.class)!=null)
102 | {
103 | //从header中得到token
104 | String tokenkey=getBearerToken(request);
105 | if (tokenkey==null || "".equals(tokenkey.trim()))
106 | {
107 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,"无法正常获取TOKEN");
108 | }
109 |
110 | String checkMsg=loginRequired(tokenkey,request);
111 | if ("OK".equals(checkMsg))
112 | {
113 | return true;
114 | } else {
115 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,checkMsg);
116 | }
117 | }
118 | else if (method.getAnnotation(AdminRequired.class) !=null)
119 | {
120 | String tokenkey=getBearerToken(request);
121 | if (tokenkey==null || "".equals(tokenkey.trim()))
122 | {
123 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,"无法正常获取TOKEN");
124 | }
125 | String checkMsg=adminRequired(tokenkey,request);
126 | if ("OK".equals(checkMsg)){
127 | return true;
128 | } else {
129 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,checkMsg);
130 | }
131 |
132 | }
133 | else if (method.getAnnotation(GroupRequired.class) !=null)
134 | {
135 | String tokenkey=getBearerToken(request);
136 | if (tokenkey==null || "".equals(tokenkey.trim()))
137 | {
138 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,"无法正常获取TOKEN");
139 | }
140 | String checkMsg=groupRequired(tokenkey,request);
141 | if ("OK".equals(checkMsg)){
142 | return true;
143 | } else if(checkMsg.startsWith("group:")) {
144 | String groupId=checkMsg.substring(6);
145 | String requestUrl=request.getRequestURI();
146 | Map authMap=MetaJson.getMetaMapUsingUri(applicationContext);
147 | MetaJson metaJson=authMap.get(requestUrl);
148 | if (metaJson==null) {
149 | System.out.println("未配置Meta信息,不需要权限配置");
150 | return true;
151 | }
152 | if (StringUtil.isNotBlank(groupId) && StringUtil.isNotBlank(metaJson.getAuth())){
153 | Integer gid=Integer.parseInt(groupId);
154 |
155 | if (userService.checkHasAuth(gid,metaJson.getAuth()))
156 | {
157 | System.out.println("权限验证通过!");
158 | return true;
159 | }
160 | }
161 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,"权限验证失败!");
162 | } else {
163 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,checkMsg);
164 | }
165 |
166 | }
167 | else if (method.getAnnotation(RefreshTokenRequired.class) !=null) {
168 | String tokenkey = getBearerToken(request);
169 | if (tokenkey == null || "".equals(tokenkey.trim())) {
170 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN, "无法正常获取TOKEN");
171 | }
172 | Integer uid=manager.refreshCheckToken(tokenkey);
173 |
174 | if (uid==null)
175 | {
176 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN, "令牌过期了");
177 | }
178 | //如果token验证成功,将token对应的用户id存在request中,便于之后注入
179 | request.setAttribute(ConstConfig.CURRENT_USER_ID, uid);
180 | return true;
181 | }
182 | else {
183 | return true; // 不需要拦截,直接通过
184 | }
185 |
186 |
187 | }catch (Exception e) {
188 | e.printStackTrace();
189 | return returnResponseMsg(response, HttpServletResponse.SC_FORBIDDEN,"处理授权出现异常");
190 | }
191 | }
192 |
193 | private LinUser getCurrentUser(HttpServletRequest request) throws Exception{
194 | LinUser user=(LinUser)request.getAttribute(ConstConfig.CURRENT_USER_TOKEN);
195 | if (user==null){
196 | Integer uid=(Integer)request.getAttribute(ConstConfig.CURRENT_USER_ID);
197 | if (uid!=null) {
198 | user=userService.getUserById(uid);
199 | }
200 | }
201 | return user;
202 | }
203 |
204 | private String loginRequired(String keyToken,HttpServletRequest request){
205 | try {
206 | //验证token,,只验存在redis里面。
207 | Integer uid = manager.checkToken(keyToken);
208 | if (uid == null) {
209 | return "权限过期请重新登录";
210 | }
211 | //如果token验证成功,将token对应的用户id存在request中,便于之后注入
212 | request.setAttribute(ConstConfig.CURRENT_USER_ID, uid);
213 | return "OK";
214 | }catch (Exception e){
215 | e.printStackTrace();
216 | return "出现异常,请联系管理员";
217 | }
218 | }
219 |
220 |
221 | private String adminRequired(String keyToken,HttpServletRequest request){
222 | try {
223 | //验证token,,只验存在redis里面。
224 | Integer uid = manager.checkToken(keyToken);
225 | if (uid == null) {
226 | return "权限过期请重新登录";
227 | } else {
228 | LinUser curUser=userService.getUserById(uid);
229 | if (curUser!=null && curUser.getIsSuper()==(short)2 ){
230 | //如果token验证成功,将token对应的用户对象存在request中,便于之后注入
231 | request.setAttribute(ConstConfig.CURRENT_USER_TOKEN, curUser);
232 | return "OK";
233 | } else {
234 | return "只有超级管理员可操作";
235 | }
236 | }
237 | }catch (Exception e){
238 | e.printStackTrace();
239 | return "出现异常,请联系管理员";
240 | }
241 | }
242 |
243 | private String groupRequired(String keyToken,HttpServletRequest request){
244 | try {
245 | //验证token,,只验存在redis里面。
246 | Integer uid = manager.checkToken(keyToken);
247 | if (uid == null) {
248 | return "权限过期请重新登录";
249 | } else {
250 | LinUser curUser=userService.getUserById(uid);
251 | if (curUser!=null && curUser.getActive()==(short)2 ){
252 | return "您目前处于未激活状态,请联系超级管理员";
253 | } else if (curUser !=null && curUser.getIsSuper()==(short)2 ){
254 | //如果token验证成功,将token对应的用户对象存在request中,便于之后注入
255 | request.setAttribute(ConstConfig.CURRENT_USER_TOKEN, curUser);
256 | return "OK";
257 | } else if (curUser !=null && curUser.getGroupId()==null ) {
258 | return "您还不属于任何权限组,请联系超级管理员获得权限";
259 | } else {
260 | //如果token验证成功,将token对应的用户对象存在request中,便于之后注入
261 | request.setAttribute(ConstConfig.CURRENT_USER_TOKEN, curUser);
262 | return "group:"+curUser.getGroupId();
263 | }
264 |
265 | }
266 | }catch (Exception e){
267 | e.printStackTrace();
268 | return "出现异常,请联系管理员";
269 | }
270 | }
271 |
272 |
273 |
274 | private String getBasicAuthToken(String authss) throws Exception{
275 | if (authss==null)
276 | {
277 | return null;
278 | }
279 | String[] aa=authss.split("\\ ");
280 | if (aa.length!=2)
281 | return null;
282 | String baseToken=aa[1];
283 | String ss= new String(Base64.getDecoder().decode(baseToken),"utf-8");
284 | ss=ss.substring(0,ss.length()-1);
285 | return ss;
286 | }
287 | private String getBearerToken(HttpServletRequest request) throws Exception{
288 | //从header中得到token
289 | String authss = request.getHeader(ConstConfig.AUTHORIZATION);
290 | if (authss==null)
291 | {
292 | return null;
293 | }
294 | String[] aa=authss.split("\\ ");
295 | if (aa.length!=2)
296 | return null;
297 | String baseToken=aa[1];
298 | // String ss= new String(Base64.getDecoder().decode(baseToken),"utf-8");
299 | // ss=ss.substring(0,ss.length()-1);
300 | return baseToken;
301 | }
302 |
303 | private boolean returnResponseMsg(HttpServletResponse response, int code, String msg) {
304 | try {
305 | response.setStatus(code);
306 | ResultJson outJson= ResultJson.Forbidden(msg);
307 |
308 | response.setContentType(MediaType.APPLICATION_JSON_VALUE);
309 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
310 |
311 | writer.write(JsonUtils.objectToJson(outJson));
312 | writer.close();
313 | }catch (Exception e){
314 | e.printStackTrace();
315 | } finally {
316 | return false;
317 | }
318 | }
319 | }
320 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/manager/TokenManager.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.manager;
2 |
3 | import cn.chenxins.exception.TokenException;
4 |
5 | /**
6 | * 对Token进行操作的接口
7 | * @author ScienJus
8 | * @date 2015/7/31.
9 | */
10 | public interface TokenManager {
11 |
12 | /**
13 | * 创建一个token关联上指定用户
14 | */
15 | public String createToken(String uid) throws TokenException;
16 |
17 | /**
18 | * 创建一个RefreshToken
19 | */
20 | public String createReToken(String accessToken) throws TokenException;
21 |
22 | /**
23 | * 检查token是否有效
24 | * @param tokenKey
25 | * @return 是否有效
26 | */
27 | public Integer checkToken(String tokenKey)throws TokenException;
28 |
29 |
30 | /**
31 | * 更新Token
32 | */
33 | public Integer refreshCheckToken(String refreshToken) throws TokenException;
34 |
35 |
36 |
37 | /**
38 | * 清除token
39 | * @param tokenKey 登录用户的id
40 | */
41 | public void deleteToken(String tokenKey);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/authorization/manager/impl/RedisTokenManager.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.authorization.manager.impl;
2 |
3 |
4 | import cn.chenxins.authorization.manager.TokenManager;
5 | import cn.chenxins.exception.TokenException;
6 | import cn.chenxins.utils.*;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Component;
9 |
10 | import java.util.Date;
11 | import java.util.UUID;
12 |
13 | /**
14 | * 通过Redis存储和验证token的实现类
15 | * @see cn.chenxins.authorization.manager.TokenManager
16 | * @author ScienJus
17 | * @date 2015/7/31.
18 | */
19 | @Component
20 | public class RedisTokenManager implements TokenManager {
21 |
22 |
23 | @Autowired
24 | private RedisOperator redis;
25 |
26 |
27 | public String createToken(String uid) throws TokenException {
28 | //使用uuid作为源token,一步部分
29 | String preToken = UUID.randomUUID().toString().replace("-", "");
30 |
31 | String key=preToken+"."+DesUtils.md5("access_token");
32 |
33 | //存储到redis并设置过期时间
34 | redis.set(key,uid, ConstConfig.TOKEN_EXPIRES_HOUR*3600);
35 |
36 | return key;
37 | }
38 |
39 | /**
40 | * 创建一个RefreshToken
41 | */
42 | public String createReToken(String accessToken) throws TokenException {
43 | //使用uuid作为源token,一步部分
44 | String preToken = UUID.randomUUID().toString().replace("-", "");
45 |
46 | String key=preToken+"."+DesUtils.md5("refresh_token");
47 |
48 |
49 | //存储到redis并设置过期时间
50 | redis.set(key,accessToken, ConstConfig.RETOKEN_EXPIRES_HOUR*3600);
51 | return key;
52 | }
53 |
54 |
55 | public Integer checkToken(String authentication)throws TokenException {
56 |
57 | if (authentication == null || "".equals(authentication.trim())) {
58 | return null;
59 | }
60 | String tokenValue = redis.get(authentication);
61 | if (tokenValue == null || "".equals(tokenValue.trim())) {
62 | return null;
63 | } else {
64 | return Integer.parseInt(tokenValue);
65 |
66 | }
67 |
68 | //如果验证成功,说明此用户进行了一次有效操作,延长token的过期时间
69 | // redis.expire(authentication, ConstConfig.TOKEN_EXPIRES_HOUR*3600);
70 | }
71 |
72 | public Integer refreshCheckToken(String refreshToken) throws TokenException {
73 | String accessToken = redis.get(refreshToken);
74 | if (accessToken == null || "".equals(accessToken.trim()) ) {
75 | return null;
76 | } else {
77 | String uid=redis.get(accessToken);
78 | if (uid == null || "".equals(uid.trim()) ) {
79 | return null;
80 | }
81 | deleteToken(accessToken);//清除原来的accessToken
82 | return Integer.parseInt(uid);
83 |
84 | }
85 | }
86 |
87 |
88 | public void deleteToken(String tokenKey) {
89 | // redisTemplate.delete(userId);
90 | redis.del(tokenKey);
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/controller/AdminConroller.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.controller;
2 |
3 | import cn.chenxins.authorization.annotation.AdminRequired;
4 | import cn.chenxins.authorization.annotation.LoggerReg;
5 | import cn.chenxins.cms.model.entity.LinGroup;
6 | import cn.chenxins.cms.model.json.*;
7 | import cn.chenxins.cms.service.AdminService;
8 | import cn.chenxins.exception.BussinessErrorException;
9 | import cn.chenxins.exception.ParamValueException;
10 | import cn.chenxins.utils.JsonUtils;
11 | import cn.chenxins.utils.MetaJson;
12 | import cn.chenxins.utils.ResultJson;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
15 | import org.springframework.web.bind.annotation.*;
16 | import org.springframework.web.context.WebApplicationContext;
17 |
18 | import javax.servlet.http.HttpServletRequest;
19 | import javax.servlet.http.HttpServletResponse;
20 | import java.util.ArrayList;
21 | import java.util.HashMap;
22 | import java.util.List;
23 | import java.util.Map;
24 |
25 | @RestController
26 | @EnableAutoConfiguration
27 | @RequestMapping("cms/admin")
28 | public class AdminConroller {
29 |
30 | @Autowired
31 | WebApplicationContext applicationContext;
32 |
33 | @Autowired
34 | private AdminService service;
35 |
36 | protected HttpServletRequest request;
37 | protected HttpServletResponse response;
38 |
39 |
40 | @ModelAttribute
41 | public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
42 | this.request = request;
43 | this.response = response;
44 | }
45 |
46 |
47 |
48 | @GetMapping(value = "authority",name = "")
49 | @AdminRequired
50 | public Object authority()
51 | {
52 | Map map = MetaJson.getMetaMap(applicationContext);
53 |
54 | HashMap moduleMap=new HashMap<>();
55 | HashMap> authMap;
56 | List uriSet;
57 | String module;
58 |
59 | for(MetaJson meta:map.values()){
60 | module=meta.getModule();
61 | if (moduleMap.get(module)==null)
62 | {
63 | authMap=new HashMap<>();
64 | for (MetaJson meta2:map.values())
65 | {
66 | if (module.equals(meta2.getModule()))
67 | {
68 | uriSet=new ArrayList<>();
69 | uriSet.add(meta2.getUri());
70 | authMap.put(meta2.getAuth(),uriSet);
71 | }
72 | }
73 | moduleMap.put(module,authMap);
74 | }
75 | }
76 | return moduleMap;
77 |
78 | }
79 |
80 | @GetMapping(value = "users",name = "")
81 | @AdminRequired
82 | public Object getInformation(@RequestParam(required = false) Integer group_id,
83 | @RequestParam(required = false) Integer page,@RequestParam(required = false) Integer count)
84 | {
85 | try {
86 | if (page==null) {
87 | page=1;
88 | }
89 | if (count==null) {
90 | count=10;
91 | }
92 |
93 | UserPageJsonOut userPage=service.getAllUsers(page,count,group_id);
94 | if (userPage==null) {
95 | return ResultJson.BussinessException("找不到用户信息");
96 | }
97 | // return userPage;
98 | return JsonUtils.objectToJsonSpecial(userPage);//为适应前端做特殊处理
99 | }
100 | catch (BussinessErrorException be){
101 | return ResultJson.BussinessException(be.getLocalizedMessage());
102 | }
103 | catch (Exception e){
104 | e.printStackTrace();
105 | return ResultJson.ServerError();
106 | }
107 | }
108 |
109 | @PutMapping("password/{id}")
110 | @AdminRequired
111 | public Object ChangeUserPwd(@PathVariable Integer id,@RequestBody UserJsonIn userJsonIn)
112 | {
113 | /**
114 | * 校验入参
115 | */
116 | try{
117 | UserJsonIn.ValidRequiredChangeApwd(userJsonIn);
118 | }catch (ParamValueException pe){
119 | return ResultJson.ParameterException(pe.getLocalizedMessage(), userJsonIn);
120 | }
121 | catch (Exception e)
122 | {
123 | e.printStackTrace();
124 | return ResultJson.ParameterError();
125 | }
126 | try {
127 |
128 | service.updatePwd(id,userJsonIn);
129 | return ResultJson.Sucess();
130 | }
131 | catch (BussinessErrorException be){
132 | return ResultJson.BussinessException(be.getLocalizedMessage());
133 | }
134 | catch (Exception e){
135 | e.printStackTrace();
136 | return ResultJson.ServerError();
137 | }
138 |
139 |
140 | }
141 |
142 | @DeleteMapping("{id}")
143 | @AdminRequired
144 | public Object deleteUser(@PathVariable Integer id){
145 | try {
146 |
147 | UserJsonOut user=service.adminDeleteUser(id);
148 | return ResultJson.DelSucess(user);
149 | }
150 | catch (BussinessErrorException be){
151 | return ResultJson.BussinessException(be.getLocalizedMessage());
152 | }
153 | catch (Exception e){
154 | e.printStackTrace();
155 | return ResultJson.ServerError();
156 | }
157 | }
158 |
159 | @PutMapping("{id}")
160 | @AdminRequired
161 | public Object updateUser(@PathVariable Integer id ,@RequestBody UserJsonIn userJsonIn){
162 | /**
163 | * 校验入参
164 | */
165 | try{
166 | UserJsonIn.ValidRequiredAdminUpd(userJsonIn);
167 | }catch (ParamValueException pe){
168 | return ResultJson.ParameterException(pe.getLocalizedMessage(), userJsonIn);
169 | }
170 | catch (Exception e)
171 | {
172 | e.printStackTrace();
173 | return ResultJson.ParameterError();
174 | }
175 | try {
176 |
177 | service.updateUser(id,userJsonIn);
178 | this.response.setStatus(201);
179 | return ResultJson.Sucess();
180 | }
181 | catch (BussinessErrorException be){
182 | return ResultJson.BussinessException(be.getLocalizedMessage());
183 | }
184 | catch (Exception e){
185 | e.printStackTrace();
186 | return ResultJson.ServerError();
187 | }
188 | }
189 |
190 |
191 | @PutMapping("disable/{id}")
192 | @AdminRequired
193 | public Object trans2disable(@PathVariable Integer id ) {
194 | try {
195 |
196 | service.disableUser(id);
197 | return ResultJson.Sucess();
198 | }
199 | catch (BussinessErrorException be){
200 | return ResultJson.BussinessException(be.getLocalizedMessage());
201 | }
202 | catch (Exception e){
203 | e.printStackTrace();
204 | return ResultJson.ServerError();
205 | }
206 | }
207 |
208 | @PutMapping("active/{id}")
209 | @AdminRequired
210 | public Object trans2active(@PathVariable Integer id ) {
211 | try {
212 |
213 | service.activeUser(id);
214 | return ResultJson.Sucess();
215 | }
216 | catch (BussinessErrorException be){
217 | return ResultJson.BussinessException(be.getLocalizedMessage());
218 | }
219 | catch (Exception e){
220 | e.printStackTrace();
221 | return ResultJson.ServerError();
222 | }
223 | }
224 |
225 |
226 | @GetMapping("groups")
227 | @AdminRequired
228 | public Object getAdminGroups( @RequestParam(required = false) Integer page,@RequestParam(required = false) Integer count)
229 | {
230 | try {
231 | if (page==null) {
232 | page=1;
233 | }
234 | if (count==null) {
235 | count=10;
236 | }
237 |
238 | GroupPageJsonOut groupPageJson=service.getAdminGroups(page,count);
239 | if (groupPageJson==null) {
240 | return ResultJson.BussinessException("不存在任何权限组");
241 | }
242 | return groupPageJson;
243 | }
244 | catch (BussinessErrorException be){
245 | return ResultJson.BussinessException(be.getLocalizedMessage());
246 | }
247 | catch (Exception e){
248 | e.printStackTrace();
249 | return ResultJson.ServerError();
250 | }
251 | }
252 |
253 | @GetMapping("group/all")
254 | @AdminRequired
255 | public Object getAllGroups()
256 | {
257 | try {
258 |
259 | List list=service.getAllGroups();
260 | if (list==null || list.size()==0) {
261 | return ResultJson.BussinessException("不存在任何管理组");
262 | }
263 | return list;
264 | }
265 | catch (BussinessErrorException be){
266 | return ResultJson.BussinessException(be.getLocalizedMessage());
267 | }
268 | catch (Exception e){
269 | e.printStackTrace();
270 | return ResultJson.ServerError();
271 | }
272 | }
273 |
274 | @GetMapping("group/{id}")
275 | @AdminRequired
276 | public Object getGroup(@PathVariable Integer id ){
277 | try {
278 | GroupAuthJsonOut group=service.getOneGroup(id);
279 | if (group==null ) {
280 | return ResultJson.BussinessException("找不到对应的组");
281 | }
282 | return group;
283 | }
284 | catch (BussinessErrorException be){
285 | return ResultJson.BussinessException(be.getLocalizedMessage());
286 | }
287 | catch (Exception e){
288 | e.printStackTrace();
289 | return ResultJson.ServerError();
290 | }
291 | }
292 |
293 | @PostMapping("group")
294 | @AdminRequired
295 | @LoggerReg(template = "管理员新建了一个权限组") //记录日志
296 | public Object createGroup(@RequestBody GroupAuthJsonIn groupAuthJsonIn){
297 |
298 | /**
299 | * 校验入参
300 | */
301 | try{
302 | GroupAuthJsonIn.ValidRequiredCreateGroup(groupAuthJsonIn);
303 | }catch (ParamValueException pe){
304 | return ResultJson.ParameterException(pe.getLocalizedMessage(), groupAuthJsonIn);
305 | }
306 | catch (Exception e)
307 | {
308 | e.printStackTrace();
309 | return ResultJson.ParameterError();
310 | }
311 |
312 | try {
313 | Map map = MetaJson.getMetaMap(applicationContext);
314 |
315 | service.createGroup(groupAuthJsonIn,map);
316 | return ResultJson.Sucess();
317 | }
318 | catch (BussinessErrorException be){
319 | return ResultJson.BussinessException(be.getLocalizedMessage());
320 | }
321 | catch (Exception e){
322 | e.printStackTrace();
323 | return ResultJson.ServerError();
324 | }
325 |
326 | }
327 |
328 | @PutMapping("group/{id}")
329 | @AdminRequired
330 | public Object updateGroup(@RequestBody GroupAuthJsonIn groupAuthJsonIn,@PathVariable Integer id){
331 | /**
332 | * 校验入参
333 | */
334 | try{
335 | GroupAuthJsonIn.ValidRequiredUpdateGroup(groupAuthJsonIn);
336 | }catch (ParamValueException pe){
337 | return ResultJson.ParameterException(pe.getLocalizedMessage(), groupAuthJsonIn);
338 | }
339 | catch (Exception e)
340 | {
341 | e.printStackTrace();
342 | return ResultJson.ParameterError();
343 | }
344 |
345 | try {
346 | service.updateGroup(groupAuthJsonIn,id);
347 | return ResultJson.Sucess();
348 | }
349 | catch (BussinessErrorException be){
350 | return ResultJson.BussinessException(be.getLocalizedMessage());
351 | }
352 | catch (Exception e){
353 | e.printStackTrace();
354 | return ResultJson.ServerError();
355 | }
356 | }
357 |
358 | @DeleteMapping("group/{id}")
359 | @AdminRequired
360 | public Object deleteGroup(@PathVariable Integer id){
361 |
362 | try {
363 | service.deleteGroup(id);
364 | return ResultJson.DelSucess();
365 | }
366 | catch (BussinessErrorException be){
367 | return ResultJson.BussinessException(be.getLocalizedMessage());
368 | }
369 | catch (Exception e){
370 | e.printStackTrace();
371 | return ResultJson.ServerError();
372 | }
373 | }
374 |
375 | @PostMapping("dispatch")
376 | @AdminRequired
377 | public Object dispatchAuth(@RequestBody AuthJsonIn authJsonIn){
378 | /**
379 | * 校验入参
380 | */
381 | try{
382 | AuthJsonIn.ValidRequiredPatch(authJsonIn);
383 | }catch (ParamValueException pe){
384 | return ResultJson.ParameterException(pe.getLocalizedMessage(), authJsonIn);
385 | }
386 | catch (Exception e)
387 | {
388 | e.printStackTrace();
389 | return ResultJson.ParameterError();
390 | }
391 |
392 |
393 | try {
394 | Map authMap = MetaJson.getMetaMap(applicationContext);
395 | service.patchAuth(authJsonIn,authMap);
396 | return ResultJson.Sucess();
397 | }
398 | catch (BussinessErrorException be){
399 | return ResultJson.BussinessException(be.getLocalizedMessage());
400 | }
401 | catch (Exception e){
402 | e.printStackTrace();
403 | return ResultJson.ServerError();
404 | }
405 | }
406 |
407 | @PostMapping("dispatch/patch")
408 | @AdminRequired
409 | public Object dispatchAuths(@RequestBody AuthJsonIn authJsonIn){
410 | /**
411 | * 校验入参
412 | */
413 | try{
414 | AuthJsonIn.ValidRequiredPatchs(authJsonIn);
415 | }catch (ParamValueException pe){
416 | return ResultJson.ParameterException(pe.getLocalizedMessage(), authJsonIn);
417 | }
418 | catch (Exception e)
419 | {
420 | e.printStackTrace();
421 | return ResultJson.ParameterError();
422 | }
423 |
424 |
425 | try {
426 | Map authMap = MetaJson.getMetaMap(applicationContext);
427 | service.patchAuths(authJsonIn,authMap);
428 | return ResultJson.Sucess();
429 | }
430 | catch (BussinessErrorException be){
431 | return ResultJson.BussinessException(be.getLocalizedMessage());
432 | }
433 | catch (Exception e){
434 | e.printStackTrace();
435 | return ResultJson.ServerError();
436 | }
437 |
438 | }
439 |
440 | @PostMapping("remove")
441 | @AdminRequired
442 | public Object removeAuths(@RequestBody AuthJsonIn authJsonIn)
443 | {
444 | /**
445 | * 校验入参
446 | */
447 | try{
448 | AuthJsonIn.ValidRequiredPatchs(authJsonIn);
449 | }catch (ParamValueException pe){
450 | return ResultJson.ParameterException(pe.getLocalizedMessage(), authJsonIn);
451 | }
452 | catch (Exception e)
453 | {
454 | e.printStackTrace();
455 | return ResultJson.ParameterError();
456 | }
457 |
458 |
459 | try {
460 | service.removeAuths(authJsonIn);
461 | return ResultJson.DelSucess(authJsonIn);
462 | }
463 | catch (BussinessErrorException be){
464 | return ResultJson.BussinessException(be.getLocalizedMessage());
465 | }
466 | catch (Exception e){
467 | e.printStackTrace();
468 | return ResultJson.ServerError();
469 | }
470 |
471 | }
472 |
473 | }
474 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/controller/LogConroller.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.controller;
2 |
3 | import cn.chenxins.authorization.annotation.GroupRequired;
4 | import cn.chenxins.cms.service.LogService;
5 | import cn.chenxins.exception.BussinessErrorException;
6 | import cn.chenxins.exception.TokenException;
7 | import cn.chenxins.utils.ResultJson;
8 | import cn.chenxins.utils.StringUtil;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | import java.util.Date;
14 |
15 | @RestController
16 | @EnableAutoConfiguration
17 | @RequestMapping("cms/log")
18 | public class LogConroller {
19 |
20 | @Autowired
21 | private LogService logService;
22 |
23 |
24 | @GetMapping(value = "/",name="日志#查询所有日志")
25 | @GroupRequired
26 | public Object searchAllLog(@RequestParam(required = false) String name,@RequestParam(required = false) Date start,@RequestParam(required = false) Date end,
27 | @RequestParam(required = false) Integer page,@RequestParam(required = false) Integer count){
28 | try{
29 | if (page==null) {
30 | page=1;
31 | }
32 | if (count==null) {
33 | count=10;
34 | }
35 | return logService.getAllLog(name,start,end,page,count);
36 |
37 | }catch (TokenException te){
38 | return ResultJson.TokenRedisException();
39 | }
40 | catch (BussinessErrorException be){
41 | return ResultJson.BussinessException(be.getLocalizedMessage());
42 | }
43 | catch (Exception e){
44 | e.printStackTrace();
45 | return ResultJson.ServerError();
46 | }
47 |
48 | }
49 |
50 | @GetMapping(value = "search",name="日志#搜索日志")
51 | @GroupRequired
52 | public Object searchAllLogByKey(@RequestParam(required = false) String name,@RequestParam(required = false) String start,@RequestParam(required = false) String end
53 | ,@RequestParam(required = false) String keyword,@RequestParam(required = false) Integer page,@RequestParam(required = false) Integer count){
54 |
55 | /**
56 | * 校验入参
57 | */
58 | if (!StringUtil.isNotBlank(keyword)) {
59 | return ResultJson.ParameterException("搜索关键字不可为空",keyword);
60 | }
61 | if (page==null) {
62 | page=1;
63 | }
64 | if (count==null) {
65 | count=10;
66 | }
67 |
68 | try {
69 | return logService.getAllLogByKey(keyword,name,start,end,page,count);
70 | }
71 | catch (BussinessErrorException be){
72 | return ResultJson.BussinessException(be.getLocalizedMessage());
73 | }
74 | catch (Exception e){
75 | e.printStackTrace();
76 | return ResultJson.ServerError();
77 | }
78 |
79 | }
80 |
81 | @GetMapping(value = "users",name = "日志#查询日志记录的用户")
82 | @GroupRequired
83 | public Object getLogUser(){
84 |
85 | try {
86 | return logService.getAllLogUser();
87 | }
88 | catch (BussinessErrorException be){
89 | return ResultJson.BussinessException(be.getLocalizedMessage());
90 | }
91 | catch (Exception e){
92 | e.printStackTrace();
93 | return ResultJson.ServerError();
94 | }
95 | }
96 |
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/controller/TestConroller.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.controller;
2 |
3 | import cn.chenxins.authorization.annotation.AdminRequired;
4 | import cn.chenxins.authorization.annotation.GroupRequired;
5 | import cn.chenxins.authorization.annotation.LoginRequired;
6 | import cn.chenxins.cms.model.entity.LinUser;
7 | import cn.chenxins.cms.model.json.UserJsonIn;
8 | import cn.chenxins.cms.service.UserService;
9 | import cn.chenxins.exception.BussinessErrorException;
10 | import cn.chenxins.exception.ParamValueException;
11 | import cn.chenxins.exception.TokenException;
12 | import cn.chenxins.utils.ConstConfig;
13 | import cn.chenxins.utils.ResultJson;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
16 | import org.springframework.web.bind.annotation.GetMapping;
17 | import org.springframework.web.bind.annotation.RequestBody;
18 | import org.springframework.web.bind.annotation.RequestMapping;
19 | import org.springframework.web.bind.annotation.RestController;
20 | import org.springframework.web.context.request.NativeWebRequest;
21 | import org.springframework.web.context.request.RequestAttributes;
22 |
23 | @RestController
24 | @EnableAutoConfiguration
25 | @RequestMapping("/")
26 | public class TestConroller {
27 |
28 |
29 |
30 | @GetMapping(value = "/info",name="信息#查看lin的信息")
31 | @GroupRequired
32 | public Object info(){
33 |
34 | return " { \"msg\": \"Lin 是一套基于 Python-Flask 的一整套开箱即用的后台管理系统(CMS)。" +
35 | "Lin 遵循简洁、高效的原则,通过核心库加插件的方式来驱动整个系统高效的运行\" }";
36 |
37 |
38 | }
39 |
40 | @GetMapping("/")
41 | public Object slogan(){
42 | return "" +
48 | "
Lin
心上无垢,林间有风。
";
49 | }
50 |
51 |
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/controller/UserConroller.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.controller;
2 |
3 | import cn.chenxins.authorization.annotation.AdminRequired;
4 | import cn.chenxins.authorization.annotation.LoggerReg;
5 | import cn.chenxins.authorization.annotation.LoginRequired;
6 | import cn.chenxins.authorization.annotation.RefreshTokenRequired;
7 | import cn.chenxins.authorization.manager.TokenManager;
8 | import cn.chenxins.cms.model.entity.LinUser;
9 | import cn.chenxins.cms.model.json.TokenJsonOut;
10 | import cn.chenxins.cms.model.json.UserJsonIn;
11 | import cn.chenxins.cms.model.json.UserJsonOut;
12 | import cn.chenxins.cms.service.UserService;
13 | import cn.chenxins.exception.BussinessErrorException;
14 | import cn.chenxins.exception.ParamValueException;
15 | import cn.chenxins.exception.TokenException;
16 | import cn.chenxins.utils.ConstConfig;
17 | import cn.chenxins.utils.JsonUtils;
18 | import cn.chenxins.utils.ResultJson;
19 | import org.springframework.beans.factory.annotation.Autowired;
20 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
21 | import org.springframework.web.bind.annotation.*;
22 | import org.springframework.web.context.request.NativeWebRequest;
23 | import org.springframework.web.context.request.RequestAttributes;
24 |
25 | import java.util.ArrayList;
26 | import java.util.HashMap;
27 | import java.util.Hashtable;
28 | import java.util.List;
29 |
30 | @RestController
31 | @EnableAutoConfiguration
32 | @RequestMapping("cms/user")
33 | public class UserConroller {
34 |
35 | @Autowired
36 | private UserService userService;
37 |
38 | @Autowired
39 | private TokenManager tokenManager;
40 |
41 |
42 |
43 |
44 | @PostMapping("login")
45 | public Object userLogin(@RequestBody UserJsonIn userJsonIn){
46 |
47 | /**
48 | * 校验入参
49 | */
50 | try{
51 | UserJsonIn.ValidRequiredLogin(userJsonIn);
52 | }catch (ParamValueException pe){
53 | return ResultJson.ParameterException(pe.getLocalizedMessage(), userJsonIn);
54 | }
55 | catch (Exception e)
56 | {
57 | e.printStackTrace();
58 | return ResultJson.ParameterError();
59 | }
60 |
61 | try {
62 | LinUser user=userService.loginUser(userJsonIn);
63 | String uid=user.getId().toString();
64 | //创建token,并设进redis中
65 | String accessToken=tokenManager.createToken(uid);
66 | //设置refresh token进,并设进redis中
67 | String refreshToken=tokenManager.createReToken(accessToken);
68 |
69 | return new TokenJsonOut(accessToken,refreshToken);
70 |
71 | }catch (TokenException te){
72 | return ResultJson.TokenRedisException();
73 | }
74 | catch (BussinessErrorException be){
75 | return ResultJson.BussinessException(be.getLocalizedMessage());
76 | }
77 | catch (Exception e){
78 | e.printStackTrace();
79 | return ResultJson.ServerError();
80 | }
81 |
82 | }
83 |
84 | @PostMapping("register")
85 | @AdminRequired
86 | @LoggerReg(template = "管理员新建了一个用户")
87 | public Object userRegister(@RequestBody UserJsonIn userJsonIn){
88 |
89 | /**
90 | * 校验入参
91 | */
92 | try{
93 | UserJsonIn.ValidRequiredRegister(userJsonIn);
94 | }catch (ParamValueException pe){
95 | return ResultJson.ParameterException(pe.getLocalizedMessage(), userJsonIn);
96 | }
97 | catch (Exception e)
98 | {
99 | e.printStackTrace();
100 | return ResultJson.ParameterError();
101 | }
102 |
103 | try {
104 | userService.register(userJsonIn);
105 | return ResultJson.Sucess();
106 | }
107 | catch (BussinessErrorException be){
108 | return ResultJson.BussinessException(be.getLocalizedMessage());
109 | }
110 | catch (Exception e){
111 | e.printStackTrace();
112 | return ResultJson.ServerError();
113 | }
114 |
115 | }
116 |
117 | @PutMapping("/")
118 | @LoginRequired
119 | public Object userUpdate(@RequestBody UserJsonIn userJsonIn, NativeWebRequest webRequest){
120 |
121 | /**
122 | * 校验入参
123 | */
124 | try{
125 | UserJsonIn.ValidRequiredUserUpd(userJsonIn);
126 | }catch (ParamValueException pe){
127 | return ResultJson.ParameterException(pe.getLocalizedMessage(), userJsonIn);
128 | }
129 | catch (Exception e)
130 | {
131 | e.printStackTrace();
132 | return ResultJson.ParameterError();
133 | }
134 |
135 | try {
136 | Integer uid=(Integer)webRequest.getAttribute(ConstConfig.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
137 | if (uid==null){
138 | return ResultJson.ServerError();
139 | }
140 | userService.updateS(uid,userJsonIn);
141 | return ResultJson.Sucess();
142 | }catch (TokenException te){
143 | return ResultJson.TokenRedisException();
144 | }
145 | catch (BussinessErrorException be){
146 | return ResultJson.BussinessException(be.getLocalizedMessage());
147 | }
148 | catch (Exception e){
149 | e.printStackTrace();
150 | return ResultJson.ServerError();
151 | }
152 |
153 | }
154 |
155 | @PutMapping("change_password")
156 | @LoginRequired
157 | public Object changePwd(@RequestBody UserJsonIn userJsonIn, NativeWebRequest webRequest){
158 |
159 | /**
160 | * 校验入参
161 | */
162 | try{
163 | UserJsonIn.ValidRequiredChangeUpd(userJsonIn);
164 | }catch (ParamValueException pe){
165 | return ResultJson.ParameterException(pe.getLocalizedMessage(), userJsonIn);
166 | }
167 | catch (Exception e)
168 | {
169 | e.printStackTrace();
170 | return ResultJson.ParameterError();
171 | }
172 |
173 | try {
174 | Integer uid=(Integer)webRequest.getAttribute(ConstConfig.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
175 | if (uid==null){
176 | return ResultJson.ServerError();
177 | }
178 | userService.updatePwd(uid,userJsonIn);
179 | return ResultJson.Sucess();
180 | }
181 | catch (BussinessErrorException be){
182 | return ResultJson.BussinessException(be.getLocalizedMessage());
183 | }
184 | catch (Exception e){
185 | e.printStackTrace();
186 | return ResultJson.ServerError();
187 | }
188 |
189 | }
190 |
191 | @GetMapping("information")
192 | @LoginRequired
193 | public Object getInformation(NativeWebRequest webRequest){
194 | try {
195 | Integer uid=(Integer)webRequest.getAttribute(ConstConfig.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
196 | if (uid==null){
197 | return ResultJson.ServerError();
198 | }
199 | LinUser linUser=userService.getUserById(uid);
200 | if (linUser==null) {
201 | return ResultJson.BussinessException("找不到用户信息");
202 | }
203 | UserJsonOut out=new UserJsonOut(linUser);
204 | return JsonUtils.objectToJsonSpecial(out); //为适应前端做特殊处理
205 | // return out;
206 | }
207 | catch (BussinessErrorException be){
208 | return ResultJson.BussinessException(be.getLocalizedMessage());
209 | }
210 | catch (Exception e){
211 | e.printStackTrace();
212 | return ResultJson.ServerError();
213 | }
214 | }
215 |
216 | @GetMapping("refresh")
217 | @RefreshTokenRequired
218 | public Object refresh(NativeWebRequest webRequest){
219 | try {
220 | Integer uid=(Integer)webRequest.getAttribute(ConstConfig.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
221 | if (uid==null){
222 | return ResultJson.ServerError();
223 | }
224 | //创建token,并设进redis中
225 | String accessToken=tokenManager.createToken(uid.toString());
226 |
227 |
228 | return new TokenJsonOut(accessToken,"");
229 | }
230 | catch (TokenException be){
231 | return ResultJson.BussinessException(be.getLocalizedMessage());
232 | }
233 | catch (Exception e){
234 | e.printStackTrace();
235 | return ResultJson.ServerError();
236 | }
237 | }
238 |
239 | @GetMapping("auths")
240 | @LoginRequired
241 | public Object getAllowedAPI(NativeWebRequest webRequest){
242 | try {
243 | Integer uid=(Integer)webRequest.getAttribute(ConstConfig.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
244 | if (uid==null){
245 | return ResultJson.ServerError();
246 | }
247 | LinUser user=userService.getUserById(uid);
248 | if (user==null ){
249 | return ResultJson.NotFound();
250 | }
251 | UserJsonOut userOut=new UserJsonOut(user);
252 | if (user.getGroupId()==null) {
253 | // return userOut;
254 | return JsonUtils.objectToJsonSpecial(userOut);//为了前端做适配的
255 | }
256 |
257 | HashMap res=userService.getAuthList(user.getGroupId());
258 |
259 | userOut.setAuths(res);
260 | // return userOut;
261 | return JsonUtils.objectToJsonSpecial(userOut);//为了前端做适配的
262 | }
263 | catch (TokenException be){
264 | return ResultJson.BussinessException(be.getLocalizedMessage());
265 | }
266 | catch (Exception e){
267 | e.printStackTrace();
268 | return ResultJson.ServerError();
269 | }
270 | }
271 |
272 | }
273 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/controller/v1/BookConroller.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.controller.v1;
2 |
3 | import cn.chenxins.authorization.annotation.AdminRequired;
4 | import cn.chenxins.authorization.annotation.LoginRequired;
5 | import cn.chenxins.cms.model.entity.Book;
6 | import cn.chenxins.cms.model.entity.LinUser;
7 | import cn.chenxins.cms.model.json.BookJsonIn;
8 | import cn.chenxins.cms.model.json.UserJsonIn;
9 | import cn.chenxins.cms.service.BookService;
10 | import cn.chenxins.cms.service.UserService;
11 | import cn.chenxins.exception.BussinessErrorException;
12 | import cn.chenxins.exception.ParamValueException;
13 | import cn.chenxins.exception.TokenException;
14 | import cn.chenxins.utils.ConstConfig;
15 | import cn.chenxins.utils.ResultJson;
16 | import cn.chenxins.utils.StringUtil;
17 | import org.springframework.beans.factory.annotation.Autowired;
18 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
19 | import org.springframework.web.bind.annotation.*;
20 | import org.springframework.web.context.request.NativeWebRequest;
21 | import org.springframework.web.context.request.RequestAttributes;
22 |
23 | @RestController
24 | @EnableAutoConfiguration
25 | @RequestMapping("v1/book")
26 | public class BookConroller {
27 |
28 | @Autowired
29 | private BookService bookService;
30 |
31 | @GetMapping("{id}")
32 | @LoginRequired
33 | public Object getBookDetail(@PathVariable(required = false) Integer id) {
34 | try {
35 | if (id == null) {
36 | return ResultJson.ParameterException("id是必填项!", id);
37 | }
38 | return bookService.getBookDetail(id);
39 | }catch (BussinessErrorException be){
40 | return ResultJson.BussinessException(be.getLocalizedMessage());
41 | }
42 | catch (Exception e){
43 | e.printStackTrace();
44 | return ResultJson.ServerError();
45 | }
46 | }
47 |
48 | @GetMapping("/")
49 | @LoginRequired
50 | public Object getAllBooks() {
51 | //取所有没有删除的书
52 | return bookService.getListPageS(null);
53 |
54 | }
55 |
56 | @GetMapping("/search")
57 | @LoginRequired
58 | public Object searchBook(@RequestParam (required = false) String q) {
59 | // 按关键词查收书籍
60 | if (!StringUtil.isNotBlank(q)){
61 | return ResultJson.ParameterException("必须传入搜索关键字",null);
62 | }
63 | return bookService.getListPageS(q);
64 | }
65 |
66 | @PostMapping("/")
67 | @LoginRequired
68 | public Object createBook(@RequestBody BookJsonIn bookJsonIn) {
69 | try{
70 | BookJsonIn.ValidRequired(bookJsonIn);
71 | }catch (ParamValueException pe) {
72 | return ResultJson.ParameterException(pe.getLocalizedMessage(),bookJsonIn);
73 | }
74 |
75 | try {
76 | bookService.addmodelS(bookJsonIn);
77 | return ResultJson.Sucess();
78 |
79 | }catch (BussinessErrorException be){
80 | return ResultJson.BussinessException(be.getLocalizedMessage());
81 | }catch (Exception e){
82 | e.printStackTrace();
83 | return ResultJson.ServerError();
84 | }
85 | }
86 |
87 | @PutMapping("{id}")
88 | @LoginRequired
89 | public Object updateBook(@PathVariable Integer id,@RequestBody BookJsonIn bookJsonIn) {
90 | try{
91 | BookJsonIn.ValidRequired(bookJsonIn);
92 | }catch (ParamValueException pe) {
93 | return ResultJson.ParameterException(pe.getLocalizedMessage(),bookJsonIn);
94 | }
95 |
96 | try {
97 | bookService.updModelS(id,bookJsonIn);
98 | return ResultJson.Sucess();
99 |
100 | }catch (BussinessErrorException be){
101 | return ResultJson.BussinessException(be.getLocalizedMessage());
102 | }catch (Exception e){
103 | e.printStackTrace();
104 | return ResultJson.ServerError();
105 | }
106 |
107 | }
108 |
109 | @DeleteMapping(value = "{id}",name="图书#删除图书")
110 | @LoginRequired
111 | public Object deleteBook(@PathVariable Integer id) {
112 | try {
113 | bookService.delModelS(id);
114 | return ResultJson.Sucess();
115 |
116 | }catch (BussinessErrorException be){
117 | return ResultJson.BussinessException(be.getLocalizedMessage());
118 | }catch (Exception e){
119 | e.printStackTrace();
120 | return ResultJson.ServerError();
121 | }
122 | }
123 |
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/Book.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity;
2 |
3 | import java.util.Date;
4 | import javax.persistence.*;
5 |
6 | public class Book {
7 | @Id
8 | @GeneratedValue(strategy = GenerationType.IDENTITY)
9 | private Integer id;
10 |
11 | @Column(name = "create_time")
12 | private Date createTime;
13 |
14 | @Column(name = "update_time")
15 | private Date updateTime;
16 |
17 | @Column(name = "delete_time")
18 | private Date deleteTime;
19 |
20 | private String title;
21 |
22 | private String author;
23 |
24 | private String summary;
25 |
26 | private String image;
27 |
28 | /**
29 | * @return id
30 | */
31 | public Integer getId() {
32 | return id;
33 | }
34 |
35 | /**
36 | * @param id
37 | */
38 | public void setId(Integer id) {
39 | this.id = id;
40 | }
41 |
42 | /**
43 | * @return create_time
44 | */
45 | public Date getCreateTime() {
46 | return createTime;
47 | }
48 |
49 | /**
50 | * @param createTime
51 | */
52 | public void setCreateTime(Date createTime) {
53 | this.createTime = createTime;
54 | }
55 |
56 | /**
57 | * @return update_time
58 | */
59 | public Date getUpdateTime() {
60 | return updateTime;
61 | }
62 |
63 | /**
64 | * @param updateTime
65 | */
66 | public void setUpdateTime(Date updateTime) {
67 | this.updateTime = updateTime;
68 | }
69 |
70 | /**
71 | * @return delete_time
72 | */
73 | public Date getDeleteTime() {
74 | return deleteTime;
75 | }
76 |
77 | /**
78 | * @param deleteTime
79 | */
80 | public void setDeleteTime(Date deleteTime) {
81 | this.deleteTime = deleteTime;
82 | }
83 |
84 | /**
85 | * @return title
86 | */
87 | public String getTitle() {
88 | return title;
89 | }
90 |
91 | /**
92 | * @param title
93 | */
94 | public void setTitle(String title) {
95 | this.title = title;
96 | }
97 |
98 | /**
99 | * @return author
100 | */
101 | public String getAuthor() {
102 | return author;
103 | }
104 |
105 | /**
106 | * @param author
107 | */
108 | public void setAuthor(String author) {
109 | this.author = author;
110 | }
111 |
112 | /**
113 | * @return summary
114 | */
115 | public String getSummary() {
116 | return summary;
117 | }
118 |
119 | /**
120 | * @param summary
121 | */
122 | public void setSummary(String summary) {
123 | this.summary = summary;
124 | }
125 |
126 | /**
127 | * @return image
128 | */
129 | public String getImage() {
130 | return image;
131 | }
132 |
133 | /**
134 | * @param image
135 | */
136 | public void setImage(String image) {
137 | this.image = image;
138 | }
139 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/LinAuth.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity;
2 |
3 | import javax.persistence.*;
4 |
5 | @Table(name = "lin_auth")
6 | public class LinAuth {
7 | @Id
8 | @GeneratedValue(strategy = GenerationType.IDENTITY)
9 | private Integer id;
10 |
11 | @Column(name = "group_id")
12 | private Integer groupId;
13 |
14 | private String auth;
15 |
16 | private String module;
17 |
18 | /**
19 | * @return id
20 | */
21 | public Integer getId() {
22 | return id;
23 | }
24 |
25 | /**
26 | * @param id
27 | */
28 | public void setId(Integer id) {
29 | this.id = id;
30 | }
31 |
32 | /**
33 | * @return group_id
34 | */
35 | public Integer getGroupId() {
36 | return groupId;
37 | }
38 |
39 | /**
40 | * @param groupId
41 | */
42 | public void setGroupId(Integer groupId) {
43 | this.groupId = groupId;
44 | }
45 |
46 | /**
47 | * @return auth
48 | */
49 | public String getAuth() {
50 | return auth;
51 | }
52 |
53 | /**
54 | * @param auth
55 | */
56 | public void setAuth(String auth) {
57 | this.auth = auth;
58 | }
59 |
60 | /**
61 | * @return module
62 | */
63 | public String getModule() {
64 | return module;
65 | }
66 |
67 | /**
68 | * @param module
69 | */
70 | public void setModule(String module) {
71 | this.module = module;
72 | }
73 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/LinGroup.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity;
2 |
3 | import javax.persistence.*;
4 |
5 | @Table(name = "lin_group")
6 | public class LinGroup {
7 | @Id
8 | @GeneratedValue(strategy = GenerationType.IDENTITY)
9 | private Integer id;
10 |
11 | private String name;
12 |
13 | private String info;
14 |
15 | /**
16 | * @return id
17 | */
18 | public Integer getId() {
19 | return id;
20 | }
21 |
22 | /**
23 | * @param id
24 | */
25 | public void setId(Integer id) {
26 | this.id = id;
27 | }
28 |
29 | /**
30 | * @return name
31 | */
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | /**
37 | * @param name
38 | */
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | /**
44 | * @return info
45 | */
46 | public String getInfo() {
47 | return info;
48 | }
49 |
50 | /**
51 | * @param info
52 | */
53 | public void setInfo(String info) {
54 | this.info = info;
55 | }
56 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/LinLog.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity;
2 |
3 | import java.util.Date;
4 | import javax.persistence.*;
5 |
6 | @Table(name = "lin_log")
7 | public class LinLog {
8 | @Id
9 | @GeneratedValue(strategy = GenerationType.IDENTITY)
10 | private Integer id;
11 |
12 | private String message;
13 |
14 | private Date time;
15 |
16 | @Column(name = "user_id")
17 | private Integer userId;
18 |
19 | @Column(name = "user_name")
20 | private String userName;
21 |
22 | @Column(name = "status_code")
23 | private Integer statusCode;
24 |
25 | private String method;
26 |
27 | private String path;
28 |
29 | private String authority;
30 |
31 | /**
32 | * @return id
33 | */
34 | public Integer getId() {
35 | return id;
36 | }
37 |
38 | /**
39 | * @param id
40 | */
41 | public void setId(Integer id) {
42 | this.id = id;
43 | }
44 |
45 | /**
46 | * @return message
47 | */
48 | public String getMessage() {
49 | return message;
50 | }
51 |
52 | /**
53 | * @param message
54 | */
55 | public void setMessage(String message) {
56 | this.message = message;
57 | }
58 |
59 | /**
60 | * @return time
61 | */
62 | public Date getTime() {
63 | return time;
64 | }
65 |
66 | /**
67 | * @param time
68 | */
69 | public void setTime(Date time) {
70 | this.time = time;
71 | }
72 |
73 | /**
74 | * @return user_id
75 | */
76 | public Integer getUserId() {
77 | return userId;
78 | }
79 |
80 | /**
81 | * @param userId
82 | */
83 | public void setUserId(Integer userId) {
84 | this.userId = userId;
85 | }
86 |
87 | /**
88 | * @return user_name
89 | */
90 | public String getUserName() {
91 | return userName;
92 | }
93 |
94 | /**
95 | * @param userName
96 | */
97 | public void setUserName(String userName) {
98 | this.userName = userName;
99 | }
100 |
101 | /**
102 | * @return status_code
103 | */
104 | public Integer getStatusCode() {
105 | return statusCode;
106 | }
107 |
108 | /**
109 | * @param statusCode
110 | */
111 | public void setStatusCode(Integer statusCode) {
112 | this.statusCode = statusCode;
113 | }
114 |
115 | /**
116 | * @return method
117 | */
118 | public String getMethod() {
119 | return method;
120 | }
121 |
122 | /**
123 | * @param method
124 | */
125 | public void setMethod(String method) {
126 | this.method = method;
127 | }
128 |
129 | /**
130 | * @return path
131 | */
132 | public String getPath() {
133 | return path;
134 | }
135 |
136 | /**
137 | * @param path
138 | */
139 | public void setPath(String path) {
140 | this.path = path;
141 | }
142 |
143 | /**
144 | * @return authority
145 | */
146 | public String getAuthority() {
147 | return authority;
148 | }
149 |
150 | /**
151 | * @param authority
152 | */
153 | public void setAuthority(String authority) {
154 | this.authority = authority;
155 | }
156 |
157 | @Override
158 | public String toString() {
159 | return "LinLog{" +
160 | "id=" + id +
161 | ", message='" + message + '\'' +
162 | ", time=" + time +
163 | ", userId=" + userId +
164 | ", userName='" + userName + '\'' +
165 | ", statusCode=" + statusCode +
166 | ", method='" + method + '\'' +
167 | ", path='" + path + '\'' +
168 | ", authority='" + authority + '\'' +
169 | '}';
170 | }
171 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/LinUser.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity;
2 |
3 | import cn.chenxins.cms.model.json.UserJsonIn;
4 |
5 | import java.util.Date;
6 | import javax.persistence.*;
7 |
8 | @Table(name = "lin_user")
9 | public class LinUser {
10 | @Id
11 | @GeneratedValue(strategy = GenerationType.IDENTITY)
12 | private Integer id;
13 |
14 | @Column(name = "create_time")
15 | private Date createTime;
16 |
17 | @Column(name = "update_time")
18 | private Date updateTime;
19 |
20 | @Column(name = "delete_time")
21 | private Date deleteTime;
22 |
23 | private String nickname;
24 |
25 | @Column(name = "super")
26 | private Short isSuper;
27 |
28 | private Short active;
29 |
30 | private String email;
31 |
32 | @Column(name = "group_id")
33 | private Integer groupId;
34 |
35 | private String password;
36 |
37 | public LinUser(){}
38 |
39 | public LinUser(UserJsonIn userJsonIn){
40 | this.nickname=userJsonIn.getNickname();
41 | this.email=userJsonIn.getEmail();
42 | this.groupId=userJsonIn.getGroup_id();
43 | }
44 |
45 |
46 | /**
47 | * @return id
48 | */
49 | public Integer getId() {
50 | return id;
51 | }
52 |
53 | /**
54 | * @param id
55 | */
56 | public void setId(Integer id) {
57 | this.id = id;
58 | }
59 |
60 | /**
61 | * @return create_time
62 | */
63 | public Date getCreateTime() {
64 | return createTime;
65 | }
66 |
67 | /**
68 | * @param createTime
69 | */
70 | public void setCreateTime(Date createTime) {
71 | this.createTime = createTime;
72 | }
73 |
74 | /**
75 | * @return update_time
76 | */
77 | public Date getUpdateTime() {
78 | return updateTime;
79 | }
80 |
81 | /**
82 | * @param updateTime
83 | */
84 | public void setUpdateTime(Date updateTime) {
85 | this.updateTime = updateTime;
86 | }
87 |
88 | /**
89 | * @return delete_time
90 | */
91 | public Date getDeleteTime() {
92 | return deleteTime;
93 | }
94 |
95 | /**
96 | * @param deleteTime
97 | */
98 | public void setDeleteTime(Date deleteTime) {
99 | this.deleteTime = deleteTime;
100 | }
101 |
102 | /**
103 | * @return nickname
104 | */
105 | public String getNickname() {
106 | return nickname;
107 | }
108 |
109 | /**
110 | * @param nickname
111 | */
112 | public void setNickname(String nickname) {
113 | this.nickname = nickname;
114 | }
115 |
116 | /**
117 | * @return super
118 | */
119 | public Short getIsSuper() {
120 | return isSuper;
121 | }
122 |
123 | /**
124 | * @param isSuper
125 | */
126 | public void setIsSuper(Short isSuper) {
127 | this.isSuper = isSuper;
128 | }
129 |
130 | /**
131 | * @return active
132 | */
133 | public Short getActive() {
134 | return active;
135 | }
136 |
137 | /**
138 | * @param active
139 | */
140 | public void setActive(Short active) {
141 | this.active = active;
142 | }
143 |
144 | /**
145 | * @return email
146 | */
147 | public String getEmail() {
148 | return email;
149 | }
150 |
151 | /**
152 | * @param email
153 | */
154 | public void setEmail(String email) {
155 | this.email = email;
156 | }
157 |
158 | /**
159 | * @return group_id
160 | */
161 | public Integer getGroupId() {
162 | return groupId;
163 | }
164 |
165 | /**
166 | * @param groupId
167 | */
168 | public void setGroupId(Integer groupId) {
169 | this.groupId = groupId;
170 | }
171 |
172 | /**
173 | * @return password
174 | */
175 | public String getPassword() {
176 | return password;
177 | }
178 |
179 | /**
180 | * @param password
181 | */
182 | public void setPassword(String password) {
183 | this.password = password;
184 | }
185 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/mapper/BookMapper.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity.mapper;
2 |
3 | import cn.chenxins.cms.model.entity.Book;
4 | import cn.chenxins.utils.MyMapper;
5 |
6 | public interface BookMapper extends MyMapper {
7 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/mapper/LinAuthMapper.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity.mapper;
2 |
3 | import cn.chenxins.cms.model.entity.LinAuth;
4 | import cn.chenxins.utils.MyMapper;
5 |
6 | public interface LinAuthMapper extends MyMapper {
7 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/mapper/LinGroupMapper.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity.mapper;
2 |
3 | import cn.chenxins.cms.model.entity.LinGroup;
4 | import cn.chenxins.utils.MyMapper;
5 |
6 | public interface LinGroupMapper extends MyMapper {
7 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/mapper/LinLogMapper.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity.mapper;
2 |
3 | import cn.chenxins.cms.model.entity.LinLog;
4 | import cn.chenxins.utils.MyMapper;
5 |
6 | import java.util.List;
7 |
8 | public interface LinLogMapper extends MyMapper {
9 |
10 | List getUsersUsingGroupBy();
11 |
12 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/entity/mapper/LinUserMapper.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.entity.mapper;
2 |
3 | import cn.chenxins.cms.model.entity.LinUser;
4 | import cn.chenxins.utils.MyMapper;
5 |
6 | public interface LinUserMapper extends MyMapper {
7 | }
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/AuthJosnOut.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | public class AuthJosnOut {
4 |
5 | private String auth;
6 |
7 | private String module;
8 |
9 | public AuthJosnOut(String auth, String module) {
10 | this.auth = auth;
11 | this.module = module;
12 | }
13 |
14 | public String getAuth() {
15 | return auth;
16 | }
17 |
18 | public void setAuth(String auth) {
19 | this.auth = auth;
20 | }
21 |
22 | public String getModule() {
23 | return module;
24 | }
25 |
26 | public void setModule(String module) {
27 | this.module = module;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/AuthJsonIn.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import cn.chenxins.exception.ParamValueException;
4 | import cn.chenxins.utils.StringUtil;
5 |
6 | import java.util.List;
7 |
8 | public class AuthJsonIn {
9 |
10 | private Integer group_id;
11 |
12 | private String auth;
13 |
14 | private List auths;
15 |
16 | public static void ValidRequiredPatch(AuthJsonIn tmp) throws ParamValueException {
17 | if (tmp.getGroup_id()==null) {
18 | throw new ParamValueException("分组号是必填选");
19 | }
20 | if (!StringUtil.isNotBlank(tmp.getAuth())) {
21 | throw new ParamValueException("auth字段");
22 | }
23 | }
24 |
25 | public static void ValidRequiredPatchs(AuthJsonIn tmp) throws ParamValueException {
26 | if (tmp.getGroup_id()==null) {
27 | throw new ParamValueException("分组号是必填选");
28 | }
29 | if (tmp.getAuths()==null || tmp.getAuths().size()==0){
30 | throw new ParamValueException("auths字段信息不能为空");
31 | }
32 | }
33 |
34 |
35 | public Integer getGroup_id() {
36 | return group_id;
37 | }
38 |
39 | public void setGroup_id(Integer group_id) {
40 | this.group_id = group_id;
41 | }
42 |
43 | public String getAuth() {
44 | return auth;
45 | }
46 |
47 | public void setAuth(String auth) {
48 | this.auth = auth;
49 | }
50 |
51 | public List getAuths() {
52 | return auths;
53 | }
54 |
55 | public void setAuths(List auths) {
56 | this.auths = auths;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/BookJsonIn.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import cn.chenxins.exception.ParamValueException;
4 | import cn.chenxins.utils.StringUtil;
5 |
6 | public class BookJsonIn {
7 | private String title;
8 |
9 | private String author;
10 |
11 | private String summary;
12 |
13 | private String image;
14 |
15 |
16 | public static void ValidRequired(BookJsonIn tmp) throws ParamValueException {
17 |
18 | if (!StringUtil.isNotBlank(tmp.getTitle())) {
19 | throw new ParamValueException("必须传入图书名");
20 | }
21 | if (!StringUtil.isNotBlank(tmp.getAuthor())) {
22 | throw new ParamValueException("必须传入图书作者");
23 | }
24 | if (!StringUtil.isNotBlank(tmp.getSummary())) {
25 | throw new ParamValueException("必须传入图书综述");
26 | }
27 | if (!StringUtil.isNotBlank(tmp.getImage())) {
28 | throw new ParamValueException("必须传入图书插图");
29 | }
30 | }
31 |
32 | public String getTitle() {
33 | return title;
34 | }
35 |
36 | public void setTitle(String title) {
37 | this.title = title;
38 | }
39 |
40 | public String getAuthor() {
41 | return author;
42 | }
43 |
44 | public void setAuthor(String author) {
45 | this.author = author;
46 | }
47 |
48 | public String getSummary() {
49 | return summary;
50 | }
51 |
52 | public void setSummary(String summary) {
53 | this.summary = summary;
54 | }
55 |
56 | public String getImage() {
57 | return image;
58 | }
59 |
60 | public void setImage(String image) {
61 | this.image = image;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/GroupAuthJsonIn.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import cn.chenxins.exception.ParamValueException;
4 | import cn.chenxins.utils.StringUtil;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | public class GroupAuthJsonIn {
10 |
11 | private String info;
12 |
13 | private String name;
14 |
15 | private List auths;
16 |
17 | public GroupAuthJsonIn(Integer id, String info, String name, List auths) {
18 | this.info = info;
19 | this.name = name;
20 | this.auths = auths;
21 | }
22 |
23 | public static void ValidRequiredCreateGroup(GroupAuthJsonIn tmp) throws ParamValueException {
24 | if (!StringUtil.isNotBlank(tmp.getName())) {
25 | throw new ParamValueException("分组名称不能为空");
26 | }
27 | if (!StringUtil.isNotBlank(tmp.getInfo())) {
28 | throw new ParamValueException("分组信息不能为空");
29 | }
30 | if (tmp.getAuths()==null || tmp.getAuths().size()==0){
31 | throw new ParamValueException("auths字段信息不能为空");
32 | }
33 |
34 | }
35 |
36 | public static void ValidRequiredUpdateGroup(GroupAuthJsonIn tmp) throws ParamValueException {
37 | if (!StringUtil.isNotBlank(tmp.getName())) {
38 | throw new ParamValueException("分组名称不能为空");
39 | }
40 | if (!StringUtil.isNotBlank(tmp.getInfo())) {
41 | throw new ParamValueException("分组信息不能为空");
42 | }
43 | }
44 |
45 | public String getInfo() {
46 | return info;
47 | }
48 |
49 | public void setInfo(String info) {
50 | this.info = info;
51 | }
52 |
53 | public String getName() {
54 | return name;
55 | }
56 |
57 | public void setName(String name) {
58 | this.name = name;
59 | }
60 |
61 | public List getAuths() {
62 | return auths;
63 | }
64 |
65 | public void setAuths(List auths) {
66 | this.auths = auths;
67 | }
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/GroupAuthJsonOut.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | public class GroupAuthJsonOut {
8 |
9 | private Integer id;
10 |
11 | private String info;
12 |
13 | private String name;
14 |
15 | private List> auths;
16 |
17 | public GroupAuthJsonOut(Integer id, String info, String name, List> auths) {
18 | this.id = id;
19 | this.info = info;
20 | this.name = name;
21 | this.auths = auths;
22 | }
23 |
24 | public Integer getId() {
25 | return id;
26 | }
27 |
28 | public void setId(Integer id) {
29 | this.id = id;
30 | }
31 |
32 | public String getInfo() {
33 | return info;
34 | }
35 |
36 | public void setInfo(String info) {
37 | this.info = info;
38 | }
39 |
40 | public String getName() {
41 | return name;
42 | }
43 |
44 | public void setName(String name) {
45 | this.name = name;
46 | }
47 |
48 | public List> getAuths() {
49 | return auths;
50 | }
51 |
52 | public void setAuths(List> auths) {
53 | this.auths = auths;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/GroupPageJsonOut.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import java.util.List;
4 |
5 | public class GroupPageJsonOut {
6 |
7 | private Integer total_nums;
8 |
9 | private List collection;
10 |
11 | public GroupPageJsonOut(Integer total_nums, List collection) {
12 | this.total_nums = total_nums;
13 | this.collection = collection;
14 | }
15 |
16 | public Integer getTotal_nums() {
17 | return total_nums;
18 | }
19 |
20 | public void setTotal_nums(Integer total_nums) {
21 | this.total_nums = total_nums;
22 | }
23 |
24 | public List getCollection() {
25 | return collection;
26 | }
27 |
28 | public void setCollection(List collection) {
29 | this.collection = collection;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/LogPageJsonOut.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import cn.chenxins.cms.model.entity.LinLog;
4 |
5 | import java.util.List;
6 |
7 | public class LogPageJsonOut {
8 |
9 | private Integer total_nums;
10 |
11 | private List collection;
12 |
13 | public LogPageJsonOut(Integer total_nums, List collection) {
14 | this.total_nums = total_nums;
15 | this.collection = collection;
16 | }
17 |
18 | public Integer getTotal_nums() {
19 | return total_nums;
20 | }
21 |
22 | public void setTotal_nums(Integer total_nums) {
23 | this.total_nums = total_nums;
24 | }
25 |
26 | public List getCollection() {
27 | return collection;
28 | }
29 |
30 | public void setCollection(List collection) {
31 | this.collection = collection;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/TokenJsonOut.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | public class TokenJsonOut {
4 |
5 | private String access_token;
6 |
7 | private String refresh_token;
8 |
9 | public TokenJsonOut(String access_token, String refresh_token) {
10 | this.access_token = access_token;
11 | this.refresh_token = refresh_token;
12 | }
13 |
14 | public String getAccess_token() {
15 | return access_token;
16 | }
17 |
18 | public void setAccess_token(String access_token) {
19 | this.access_token = access_token;
20 | }
21 |
22 | public String getRefresh_token() {
23 | return refresh_token;
24 | }
25 |
26 | public void setRefresh_token(String refresh_token) {
27 | this.refresh_token = refresh_token;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/UserJsonIn.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import cn.chenxins.exception.ParamValueException;
4 |
5 | public class UserJsonIn {
6 |
7 | private String nickname;
8 |
9 | private String password;
10 |
11 | private String old_password;
12 |
13 | private String new_password;
14 |
15 | private String confirm_password;
16 |
17 | private String email;
18 |
19 | private Integer group_id;
20 |
21 |
22 | public static void ValidRequiredLogin(UserJsonIn tmp) throws ParamValueException {
23 | if (tmp.getNickname()==null || "".equals(tmp.getNickname().trim())){
24 | throw new ParamValueException("操作用户名是必填项,不能为空");
25 | }
26 | if (tmp.getPassword()==null || "".equals(tmp.getPassword().trim())){
27 | throw new ParamValueException("密码是必填项,不能为空");
28 | }
29 | }
30 |
31 | public static void ValidRequiredRegister(UserJsonIn tmp) throws ParamValueException {
32 | if (tmp.getNickname()==null || "".equals(tmp.getNickname().trim())){
33 | throw new ParamValueException("操作用户名是必填项,不能为空");
34 | }
35 | if (tmp.getPassword()==null || "".equals(tmp.getPassword().trim())){
36 | throw new ParamValueException("密码是必填项,不能为空");
37 | }
38 | if (!tmp.getPassword().equals(tmp.getConfirm_password())) {
39 | throw new ParamValueException("两次输入的密码不一致,请输入相同的密码");
40 | }
41 | if (tmp.getGroup_id()== null || tmp.getGroup_id()==0) {
42 | throw new ParamValueException("分组ID是必填项");
43 | }
44 | if (tmp.getEmail()==null || "".equals(tmp.getEmail().trim())) {
45 | throw new ParamValueException("电子邮箱不符合规范,请输入正确的邮箱");
46 | }
47 |
48 | }
49 | public static void ValidRequiredUserUpd(UserJsonIn tmp) throws ParamValueException {
50 | if (tmp.getEmail()==null || "".equals(tmp.getEmail().trim())) {
51 | throw new ParamValueException("电子邮箱不符合规范,请输入正确的邮箱");
52 | }
53 |
54 | }
55 | public static void ValidRequiredAdminUpd(UserJsonIn tmp) throws ParamValueException {
56 | if (tmp.getEmail()==null || "".equals(tmp.getEmail().trim())) {
57 | throw new ParamValueException("电子邮箱不符合规范,请输入正确的邮箱");
58 | }
59 | if (tmp.getGroup_id()== null || tmp.getGroup_id()==0) {
60 | throw new ParamValueException("分组ID是必填项");
61 | }
62 |
63 | }
64 | public static void ValidRequiredChangeUpd(UserJsonIn tmp) throws ParamValueException {
65 | if (tmp.getOld_password() == null || "".equals(tmp.getOld_password().trim())) {
66 | throw new ParamValueException("原始密码是必填项,不能为空!");
67 | }
68 | if (tmp.getNew_password() == null || "".equals(tmp.getNew_password().trim())) {
69 | throw new ParamValueException("新始密码是必填项,不能为空!");
70 | }
71 | if (tmp.getConfirm_password() == null || "".equals(tmp.getConfirm_password().trim())) {
72 | throw new ParamValueException("确认密码是必填项,不能为空!");
73 | }
74 | if (!tmp.getNew_password().equals(tmp.getConfirm_password())) {
75 | throw new ParamValueException("两次输入的密码不一致,请输入相同的密码");
76 | }
77 | }
78 |
79 | public static void ValidRequiredChangeApwd(UserJsonIn tmp) throws ParamValueException {
80 |
81 | if (tmp.getNew_password() == null || "".equals(tmp.getNew_password().trim())) {
82 | throw new ParamValueException("新始密码是必填项,不能为空!");
83 | }
84 | if (tmp.getConfirm_password() == null || "".equals(tmp.getConfirm_password().trim())) {
85 | throw new ParamValueException("确认密码是必填项,不能为空!");
86 | }
87 | if (!tmp.getNew_password().equals(tmp.getConfirm_password())) {
88 | throw new ParamValueException("两次输入的密码不一致,请输入相同的密码");
89 | }
90 | }
91 |
92 |
93 |
94 | public String getNickname() {
95 | return nickname;
96 | }
97 |
98 | public void setNickname(String nickname) {
99 | this.nickname = nickname;
100 | }
101 |
102 | public String getPassword() {
103 | return password;
104 | }
105 |
106 | public void setPassword(String password) {
107 | this.password = password;
108 | }
109 |
110 | public String getConfirm_password() {
111 | return confirm_password;
112 | }
113 |
114 | public void setConfirm_password(String confirm_password) {
115 | this.confirm_password = confirm_password;
116 | }
117 |
118 | public String getEmail() {
119 | return email;
120 | }
121 |
122 | public void setEmail(String email) {
123 | this.email = email;
124 | }
125 |
126 | public Integer getGroup_id() {
127 | return group_id;
128 | }
129 |
130 | public void setGroup_id(Integer group_id) {
131 | this.group_id = group_id;
132 | }
133 |
134 | public String getOld_password() {
135 | return old_password;
136 | }
137 |
138 | public void setOld_password(String old_password) {
139 | this.old_password = old_password;
140 | }
141 |
142 | public String getNew_password() {
143 | return new_password;
144 | }
145 |
146 | public void setNew_password(String new_password) {
147 | this.new_password = new_password;
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/UserJsonOut.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import cn.chenxins.cms.model.entity.LinUser;
4 |
5 | import java.util.*;
6 |
7 | public class UserJsonOut {
8 |
9 | private Integer id;
10 |
11 | private Date createTime;
12 |
13 | private Date updateTime;
14 |
15 | private Date deleteTime;
16 |
17 | private String nickname;
18 |
19 | private Short isSuper;
20 |
21 | private Short active;
22 |
23 | private String email;
24 |
25 | private Integer group_id;
26 |
27 | private String group_name;
28 |
29 | private List> auths=new ArrayList<>();
30 |
31 |
32 |
33 | public UserJsonOut(LinUser user) {
34 | this.createTime=user.getCreateTime();
35 | this.updateTime=user.getUpdateTime();
36 | this.deleteTime=user.getDeleteTime();
37 | this.active=user.getActive();
38 | this.email=user.getEmail();
39 | this.group_id=user.getGroupId();
40 | this.nickname=user.getNickname();
41 | this.isSuper=user.getIsSuper();
42 | this.id=user.getId();
43 | }
44 |
45 | public Integer getId() {
46 | return id;
47 | }
48 |
49 | public void setId(Integer id) {
50 | this.id = id;
51 | }
52 |
53 | public Date getCreateTime() {
54 | return createTime;
55 | }
56 |
57 | public void setCreateTime(Date createTime) {
58 | this.createTime = createTime;
59 | }
60 |
61 | public Date getUpdateTime() {
62 | return updateTime;
63 | }
64 |
65 | public void setUpdateTime(Date updateTime) {
66 | this.updateTime = updateTime;
67 | }
68 |
69 | public Date getDeleteTime() {
70 | return deleteTime;
71 | }
72 |
73 | public void setDeleteTime(Date deleteTime) {
74 | this.deleteTime = deleteTime;
75 | }
76 |
77 | public String getNickname() {
78 | return nickname;
79 | }
80 |
81 | public void setNickname(String nickname) {
82 | this.nickname = nickname;
83 | }
84 |
85 | public Short getIsSuper() {
86 | return isSuper;
87 | }
88 |
89 | public void setIsSuper(Short isSuper) {
90 | this.isSuper = isSuper;
91 | }
92 |
93 | public Short getActive() {
94 | return active;
95 | }
96 |
97 | public void setActive(Short active) {
98 | this.active = active;
99 | }
100 |
101 | public String getEmail() {
102 | return email;
103 | }
104 |
105 | public void setEmail(String email) {
106 | this.email = email;
107 | }
108 |
109 | public Integer getGroup_id() {
110 | return group_id;
111 | }
112 |
113 | public void setGroup_id(Integer group_id) {
114 | this.group_id = group_id;
115 | }
116 |
117 | public String getGroup_name() {
118 | return group_name;
119 | }
120 |
121 | public void setGroup_name(String group_name) {
122 | this.group_name = group_name;
123 | }
124 |
125 | public List> getAuths() {
126 | return auths;
127 | }
128 |
129 | public void setAuths(HashMap map) {
130 | if(this.auths==null){
131 | this.auths=new ArrayList<>();
132 | }
133 | for(Map.Entry entry:map.entrySet()){
134 | this.auths.add(entry);
135 | }
136 | }
137 |
138 | }
139 |
140 |
141 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/model/json/UserPageJsonOut.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.model.json;
2 |
3 | import java.util.List;
4 |
5 | public class UserPageJsonOut {
6 |
7 | private Integer total_nums;
8 |
9 | private List collection;
10 |
11 | public UserPageJsonOut(Integer total_nums, List collection) {
12 | this.total_nums = total_nums;
13 | this.collection = collection;
14 | }
15 |
16 | public Integer getTotal_nums() {
17 | return total_nums;
18 | }
19 |
20 | public void setTotal_nums(Integer total_nums) {
21 | this.total_nums = total_nums;
22 | }
23 |
24 | public List getCollection() {
25 | return collection;
26 | }
27 |
28 | public void setCollection(List collection) {
29 | this.collection = collection;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/service/AdminService.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.service;
2 |
3 |
4 | import cn.chenxins.cms.model.entity.LinAuth;
5 | import cn.chenxins.cms.model.entity.LinGroup;
6 | import cn.chenxins.cms.model.entity.LinUser;
7 | import cn.chenxins.cms.model.entity.mapper.LinAuthMapper;
8 | import cn.chenxins.cms.model.entity.mapper.LinGroupMapper;
9 | import cn.chenxins.cms.model.entity.mapper.LinUserMapper;
10 | import cn.chenxins.cms.model.json.*;
11 | import cn.chenxins.exception.BussinessErrorException;
12 | import cn.chenxins.utils.DesUtils;
13 | import cn.chenxins.utils.JdateUtils;
14 | import cn.chenxins.utils.MetaJson;
15 | import com.github.pagehelper.PageHelper;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.stereotype.Service;
18 | import org.springframework.transaction.annotation.Propagation;
19 | import org.springframework.transaction.annotation.Transactional;
20 | import tk.mybatis.mapper.entity.Example;
21 |
22 | import java.util.ArrayList;
23 | import java.util.HashMap;
24 | import java.util.List;
25 | import java.util.Map;
26 |
27 | @Service
28 | public class AdminService {
29 |
30 |
31 | @Autowired
32 | private LinUserMapper linUserMapper;
33 |
34 | @Autowired
35 | private LinGroupMapper linGroupMapper;
36 |
37 | @Autowired
38 | private LinAuthMapper linAuthMapper;
39 |
40 |
41 |
42 | private HashMap getGroupHList(Integer gid){
43 | HashMap hashMap=new HashMap<>();
44 | if (gid!=null)
45 | {
46 | LinGroup linGroup=linGroupMapper.selectByPrimaryKey(gid);
47 | hashMap.put(gid,linGroup);
48 | } else {
49 | List list=linGroupMapper.selectAll();
50 | LinGroup tmp;
51 | for(int i=0;i alist=linUserMapper.selectByExample(example);
77 | int total=linUserMapper.selectCountByExample(example);
78 | if (total>0 && alist!=null && alist.size()>0){
79 | HashMap groupMap=getGroupHList(gid);
80 | UserJsonOut userJson;
81 | LinUser user;
82 | String groupName;
83 | LinGroup tmp;
84 | List list=new ArrayList<>();
85 |
86 | for (int i=0;i0;
138 | }
139 |
140 |
141 | @Transactional(propagation = Propagation.REQUIRED)
142 | public void updateUser(Integer uid,UserJsonIn userJsonIn)throws BussinessErrorException,Exception {
143 | LinUser user=linUserMapper.selectByPrimaryKey(uid);
144 | if (user==null)
145 | {
146 | throw new BussinessErrorException("用户不存在");
147 | }
148 |
149 | if (!user.getEmail().equals(userJsonIn.getEmail())&&isExistEMail(userJsonIn.getEmail())){
150 | throw new BussinessErrorException("该邮箱"+userJsonIn.getEmail()+"已经注册过了");
151 | }
152 |
153 | user.setEmail(userJsonIn.getEmail());
154 | user.setGroupId(userJsonIn.getGroup_id());
155 | user.setUpdateTime(JdateUtils.getCurrentDate());
156 | linUserMapper.updateByPrimaryKeySelective(user);
157 |
158 | }
159 |
160 | @Transactional(propagation = Propagation.REQUIRED)
161 | public void disableUser(Integer uid)throws BussinessErrorException,Exception {
162 |
163 | LinUser user=linUserMapper.selectByPrimaryKey(uid);
164 | if (user==null){
165 | throw new BussinessErrorException("您要处理用户信息不存在了");
166 | }
167 | if (user.getActive()!=(short)1){
168 | throw new BussinessErrorException("当前用户已处于禁止状态");
169 | }
170 | user.setActive((short)2);
171 | user.setUpdateTime(JdateUtils.getCurrentDate());
172 | linUserMapper.updateByPrimaryKeySelective(user);
173 |
174 | }
175 |
176 | @Transactional(propagation = Propagation.REQUIRED)
177 | public void activeUser(Integer uid)throws BussinessErrorException,Exception {
178 |
179 | LinUser user=linUserMapper.selectByPrimaryKey(uid);
180 | if (user==null){
181 | throw new BussinessErrorException("您要处理用户信息不存在了");
182 | }
183 | if (user.getActive()==(short)1){
184 | throw new BussinessErrorException("当前用户已处于激活状态");
185 | }
186 | user.setActive((short)1);
187 | user.setUpdateTime(JdateUtils.getCurrentDate());
188 | linUserMapper.updateByPrimaryKeySelective(user);
189 |
190 | }
191 |
192 | @Transactional(propagation = Propagation.SUPPORTS)
193 | public GroupPageJsonOut getAdminGroups(Integer page,Integer count)throws BussinessErrorException,Exception {
194 | // 开始分页
195 | PageHelper.startPage(page, count);
196 | Example example = new Example(LinGroup.class);
197 | example.orderBy("id").desc();
198 |
199 | List alist = linGroupMapper.selectByExample(example);
200 | int total = linGroupMapper.selectCountByExample(example);
201 | if (total==0){
202 | throw new BussinessErrorException("不存在任何权限组");
203 | }
204 | List list=new ArrayList<>();
205 | LinGroup tmpGroup;
206 | GroupAuthJsonOut groupAuthJsonOut;
207 | List> auths;
208 | for (int i=0;i> getAuthList(Integer gid) throws BussinessErrorException,Exception {
220 | LinAuth tmp=new LinAuth();
221 | tmp.setGroupId(gid);
222 | List alist=linAuthMapper.select(tmp);
223 | List inList=new ArrayList<>();
224 |
225 | HashMap moduleMap=new HashMap();
226 | String curModule="";
227 | for (int i=0; i();
231 | curModule=tmp.getModule();
232 | }
233 | inList.add(new AuthJosnOut(tmp.getAuth(),tmp.getModule()));
234 | moduleMap.put(tmp.getModule(),inList);
235 |
236 | }
237 | List> res=new ArrayList<>();
238 | for(Map.Entry entry:moduleMap.entrySet()){
239 | res.add(entry);
240 | }
241 | return res;
242 | }
243 |
244 | @Transactional(propagation = Propagation.SUPPORTS)
245 | public List getAllGroups()throws BussinessErrorException,Exception {
246 | return linGroupMapper.selectAll();
247 | }
248 |
249 | @Transactional(propagation = Propagation.SUPPORTS)
250 | public GroupAuthJsonOut getOneGroup(Integer id) throws BussinessErrorException,Exception{
251 | LinGroup linGroup=linGroupMapper.selectByPrimaryKey(id);
252 | if (linGroup !=null){
253 | List> auths=getAuthList(id);
254 | return new GroupAuthJsonOut(linGroup.getId(),linGroup.getInfo(),linGroup.getName(),auths);
255 | }
256 | return null;
257 | }
258 |
259 | @Transactional(propagation = Propagation.REQUIRED)
260 | public void createGroup(GroupAuthJsonIn groupAuthJsonIn,Map map) throws BussinessErrorException,Exception{
261 | LinGroup linGroup=new LinGroup();
262 | linGroup.setName(groupAuthJsonIn.getName());
263 | linGroup.setInfo(groupAuthJsonIn.getInfo());
264 | LinGroup existGroup=linGroupMapper.selectOne(linGroup);
265 | if (existGroup!=null)
266 | {
267 | throw new BussinessErrorException("分组已存在,不可创建同名分组");
268 | }
269 | linGroupMapper.insert(linGroup);
270 | existGroup=linGroupMapper.selectOne(linGroup);
271 | if (existGroup==null || existGroup.getId()==null)
272 | {
273 | throw new BussinessErrorException("新增分组失败,请联系管理员");
274 | }
275 | String tmpAuth;
276 | MetaJson metaJson;
277 | LinAuth linAuth;
278 | for (int i=0;i0) {
319 | throw new BussinessErrorException("分组下存在用户,不可删除");
320 | }
321 | LinAuth auth=new LinAuth();
322 | auth.setGroupId(gid);
323 | linAuthMapper.delete(auth);
324 | linGroupMapper.deleteByPrimaryKey(gid);
325 |
326 | }
327 |
328 | @Transactional(propagation = Propagation.REQUIRED)
329 | public void patchAuth(AuthJsonIn authJsonIn,Map authMap) throws BussinessErrorException,Exception{
330 | LinAuth auth=new LinAuth();
331 | auth.setGroupId(authJsonIn.getGroup_id());
332 | auth.setAuth(authJsonIn.getAuth());
333 | int count=linAuthMapper.selectCount(auth);
334 | if (count>0){
335 | throw new BussinessErrorException("已有权限,不可重复添加");
336 | }
337 | MetaJson meta=authMap.get(authJsonIn.getAuth());
338 | if (meta==null){
339 | throw new BussinessErrorException("权限auth:"+authJsonIn.getAuth()+",不存在。");
340 | }
341 | auth.setModule(meta.getModule());
342 | linAuthMapper.insert(auth);
343 | }
344 |
345 | @Transactional(propagation = Propagation.REQUIRED)
346 | public void patchAuths(AuthJsonIn authJsonIn,Map authMap) throws BussinessErrorException,Exception{
347 | List auths=authJsonIn.getAuths();
348 | AuthJsonIn tmp;
349 | for (int i=0;i getListPageS(String keyword) {
41 |
42 | Example example = new Example(Book.class);
43 | Example.Criteria criteria = example.createCriteria();
44 |
45 | // criteria.andEqualTo("deleteTime",null);
46 | criteria.andIsNull("deleteTime");
47 | if(StringUtil.isNotBlank(keyword)){
48 | criteria.andLike("title", "%" + keyword.trim() + "%");
49 | }
50 | example.orderBy("id").desc();
51 |
52 | List alist=bookMapper.selectByExample(example);
53 |
54 | return alist;
55 |
56 | }
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | @Transactional(propagation = Propagation.REQUIRED)
65 | public void addmodelS(BookJsonIn json) throws BussinessErrorException,Exception{
66 | Book model=new Book();
67 | model.setTitle(json.getTitle());
68 | model.setAuthor(json.getAuthor());
69 | model.setSummary(json.getSummary());
70 | model.setImage(json.getImage());
71 |
72 | int exists=bookMapper.selectCount(model);
73 | if (exists==0){
74 | model.setCreateTime(JdateUtils.getCurrentDate());
75 | bookMapper.insert(model);
76 | } else {
77 | throw new BussinessErrorException("此信息已经存在,请不要重复创建");
78 | }
79 |
80 | }
81 |
82 | @Transactional(propagation = Propagation.REQUIRED)
83 | public void updModelS(Integer id,BookJsonIn json) throws Exception{
84 | Book model=bookMapper.selectByPrimaryKey(id);
85 | if (model==null) {
86 | throw new BussinessErrorException("您要更新的信息不存在");
87 | }
88 | model.setTitle(json.getTitle());
89 | model.setAuthor(json.getAuthor());
90 | model.setSummary(json.getSummary());
91 | model.setImage(json.getImage());
92 | model.setUpdateTime(JdateUtils.getCurrentDate());
93 |
94 | bookMapper.updateByPrimaryKey(model);
95 | }
96 |
97 |
98 | @Transactional(propagation = Propagation.REQUIRED)
99 | public void delModelS(Integer id) throws BussinessErrorException,Exception{
100 | Book book=bookMapper.selectByPrimaryKey(id);
101 | if (book==null){
102 | throw new BussinessErrorException("此信息不存在");
103 | }
104 | if (book.getDeleteTime()==null){
105 | book.setDeleteTime(JdateUtils.getCurrentDate());
106 | bookMapper.updateByPrimaryKey(book);
107 | } else {
108 | throw new BussinessErrorException("此信息已经不存在,不需要重复删除");
109 | }
110 | // authUserMapper.deleteByPrimaryKey(UserId);
111 | }
112 |
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/service/LogService.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.service;
2 |
3 |
4 | import cn.chenxins.cms.model.entity.LinLog;
5 | import cn.chenxins.cms.model.entity.mapper.LinAuthMapper;
6 | import cn.chenxins.cms.model.entity.mapper.LinLogMapper;
7 | import cn.chenxins.cms.model.json.LogPageJsonOut;
8 | import cn.chenxins.exception.BussinessErrorException;
9 | import cn.chenxins.utils.StringUtil;
10 | import com.github.pagehelper.PageHelper;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.stereotype.Service;
13 | import org.springframework.transaction.annotation.Propagation;
14 | import org.springframework.transaction.annotation.Transactional;
15 | import tk.mybatis.mapper.entity.Example;
16 |
17 | import java.util.Date;
18 | import java.util.List;
19 |
20 | @Service
21 | public class LogService {
22 |
23 |
24 | @Autowired
25 | private LinLogMapper linLogMapper;
26 |
27 | @Autowired
28 | private LinAuthMapper linAuthMapper;
29 |
30 |
31 |
32 | @Transactional(propagation = Propagation.SUPPORTS)
33 | public LogPageJsonOut getAllLog(String name, Date start, Date end,Integer page,Integer count) throws BussinessErrorException,Exception {
34 | // 开始分页
35 | PageHelper.startPage(page, count);
36 | Example example = new Example(LinLog.class);
37 | Example.Criteria criteria = example.createCriteria();
38 |
39 | if (StringUtil.isNotBlank(name))
40 | {
41 | criteria.andLike("userName","%"+name+"%");
42 | }
43 | if (start!=null && end!=null){
44 | criteria.andBetween("time",start,end);
45 | }
46 | example.orderBy("time").desc();
47 |
48 | List alist = linLogMapper.selectByExample(example);
49 | int total = linLogMapper.selectCountByExample(example);
50 | if (total==0){
51 | throw new BussinessErrorException("没有找到相关日志");
52 | }
53 |
54 | return new LogPageJsonOut(total,alist);
55 | }
56 |
57 | @Transactional(propagation = Propagation.SUPPORTS)
58 | public LogPageJsonOut getAllLogByKey(String keyword, String name, String start, String end, Integer page, Integer count) throws BussinessErrorException,Exception {
59 | // 开始分页
60 | PageHelper.startPage(page, count);
61 | Example example = new Example(LinLog.class);
62 | Example.Criteria criteria = example.createCriteria();
63 | criteria.andLike("message","%"+keyword+"%");
64 |
65 | if (StringUtil.isNotBlank(name))
66 | {
67 | criteria.andLike("userName","%"+name+"%");
68 | }
69 | if (start!=null && end!=null){
70 | criteria.andBetween("time",start,end);
71 | }
72 | example.orderBy("time").desc();
73 |
74 | List alist = linLogMapper.selectByExample(example);
75 | int total = linLogMapper.selectCountByExample(example);
76 | if (total==0){
77 | throw new BussinessErrorException("没有找到相关日志");
78 | }
79 |
80 | return new LogPageJsonOut(total,alist);
81 | }
82 |
83 |
84 | @Transactional(propagation = Propagation.SUPPORTS)
85 | public List getAllLogUser() throws BussinessErrorException,Exception {
86 |
87 | return linLogMapper.getUsersUsingGroupBy();
88 | }
89 |
90 | public void saveLog(LinLog linLog) throws Exception {
91 | linLogMapper.insert(linLog);
92 | }
93 |
94 |
95 |
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/cms/service/UserService.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.cms.service;
2 |
3 |
4 | import cn.chenxins.cms.model.entity.LinAuth;
5 | import cn.chenxins.cms.model.entity.LinUser;
6 | import cn.chenxins.cms.model.entity.mapper.LinAuthMapper;
7 | import cn.chenxins.cms.model.entity.mapper.LinUserMapper;
8 | import cn.chenxins.cms.model.json.AuthJosnOut;
9 | import cn.chenxins.cms.model.json.UserJsonIn;
10 | import cn.chenxins.cms.model.json.UserPageJsonOut;
11 | import cn.chenxins.exception.BussinessErrorException;
12 | import cn.chenxins.utils.DesUtils;
13 | import cn.chenxins.utils.JdateUtils;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.stereotype.Service;
16 | import org.springframework.transaction.annotation.Propagation;
17 | import org.springframework.transaction.annotation.Transactional;
18 | import tk.mybatis.mapper.entity.Example;
19 |
20 | import java.util.*;
21 |
22 | @Service
23 | public class UserService {
24 |
25 |
26 | @Autowired
27 | private LinUserMapper dbMapper;
28 |
29 | @Autowired
30 | private LinAuthMapper linAuthMapper;
31 |
32 |
33 |
34 | private LinUser getUserByName(String nickname) throws Exception{
35 | Example example = new Example(LinUser.class);
36 | Example.Criteria criteria = example.createCriteria();
37 |
38 | criteria.andEqualTo("deleteTime",null);
39 | criteria.andEqualTo("nickname",nickname.trim());
40 | return dbMapper.selectOneByExample(example);
41 |
42 | }
43 |
44 | public LinUser getUserById(Integer uid) throws Exception{
45 | Example example = new Example(LinUser.class);
46 | Example.Criteria criteria = example.createCriteria();
47 |
48 | criteria.andEqualTo("deleteTime",null);
49 | criteria.andEqualTo("id",uid);
50 | return dbMapper.selectOneByExample(example);
51 |
52 | }
53 |
54 | @Transactional(propagation = Propagation.SUPPORTS)
55 | public LinUser loginUser(UserJsonIn userJsonIn) throws BussinessErrorException,Exception {
56 | LinUser user=getUserByName(userJsonIn.getNickname());
57 | if (user==null) {
58 | throw new BussinessErrorException("用户名或密码错误");
59 | }
60 | if (!DesUtils.CheckPasswordHash(user.getPassword(), userJsonIn.getPassword())) {
61 | throw new BussinessErrorException("用户名或密码错误");
62 | }
63 | return user;
64 | }
65 |
66 | @Transactional(propagation = Propagation.SUPPORTS)
67 | public void register(UserJsonIn userJsonIn) throws BussinessErrorException,Exception {
68 | LinUser existUser=getUserByName(userJsonIn.getNickname());
69 | if (existUser!=null){
70 | throw new BussinessErrorException("此名已经存在,请更换另一个用户名");
71 | }
72 | LinUser user=new LinUser(userJsonIn);
73 | existUser=dbMapper.selectOne(user);
74 | if (existUser==null || existUser.getDeleteTime()!=null){
75 | String encPwd=DesUtils.GeneratePasswordHash(userJsonIn.getPassword());
76 | user.setPassword(encPwd);
77 | user.setActive((short)1);
78 | user.setIsSuper((short)1);
79 | user.setCreateTime(JdateUtils.getCurrentDate());
80 | dbMapper.insert(user);
81 | } else {
82 | throw new BussinessErrorException("此信息已经存在,请不要重复创建");
83 | }
84 | }
85 |
86 | @Transactional(propagation = Propagation.SUPPORTS)
87 | public void updateS(Integer uid,UserJsonIn userJsonIn) throws BussinessErrorException,Exception {
88 | LinUser existUser=getUserById(uid);
89 | if (existUser==null){
90 | throw new BussinessErrorException("您要修改的用户信息不存在了");
91 | }
92 | existUser.setEmail(userJsonIn.getEmail());
93 | existUser.setUpdateTime(JdateUtils.getCurrentDate());
94 | dbMapper.updateByPrimaryKey(existUser);
95 |
96 | }
97 |
98 | @Transactional(propagation = Propagation.SUPPORTS)
99 | public void updatePwd(Integer uid,UserJsonIn userJsonIn) throws BussinessErrorException,Exception {
100 | LinUser existUser=getUserById(uid);
101 | if (existUser==null){
102 | throw new BussinessErrorException("您要修改密码的用户信息不存在了");
103 | }
104 | if (!DesUtils.CheckPasswordHash(existUser.getPassword(), userJsonIn.getOld_password())) {
105 | throw new BussinessErrorException("原始密码错误");
106 | }
107 | existUser.setPassword(DesUtils.GeneratePasswordHash(userJsonIn.getNew_password()));
108 | existUser.setUpdateTime(JdateUtils.getCurrentDate());
109 | dbMapper.updateByPrimaryKey(existUser);
110 |
111 | }
112 |
113 | public boolean checkHasAuth(Integer gid,String auth) throws Exception{
114 | LinAuth tmp=new LinAuth();
115 | tmp.setGroupId(gid);
116 | tmp.setAuth(auth);
117 | return linAuthMapper.selectCount(tmp)==1;
118 | }
119 |
120 |
121 | @Transactional(propagation = Propagation.SUPPORTS)
122 | public HashMap getAuthList(Integer gid) throws BussinessErrorException,Exception {
123 | LinAuth tmp=new LinAuth();
124 | tmp.setGroupId(gid);
125 | List alist=linAuthMapper.select(tmp);
126 | List inList=new ArrayList<>();
127 |
128 | HashMap moduleMap=new HashMap();
129 | String curModule="";
130 | for (int i=0; i();
134 | curModule=tmp.getModule();
135 | }
136 | inList.add(new AuthJosnOut(tmp.getAuth(),tmp.getModule()));
137 | moduleMap.put(tmp.getModule(),inList);
138 |
139 | }
140 |
141 | return moduleMap;
142 |
143 |
144 | }
145 |
146 |
147 |
148 |
149 |
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/exception/BussinessErrorException.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.exception;
2 |
3 | public class BussinessErrorException extends Exception {
4 | public BussinessErrorException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/exception/ParamValueException.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.exception;
2 |
3 | public class ParamValueException extends Exception {
4 | public ParamValueException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/exception/TokenException.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.exception;
2 |
3 | public class TokenException extends Exception {
4 | public TokenException(String message) {
5 | super(message);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/ConstConfig.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.utils;
2 |
3 | public class ConstConfig {
4 |
5 | /**
6 | * 存储当前登录用户的对象系列
7 | */
8 | public static final String CURRENT_USER_TOKEN = "CURRENT_USER_TOKEN";
9 |
10 | /**
11 | * 存储当前登录用户id的字段名
12 | */
13 | public static final String CURRENT_USER_ID = "CURRENT_USER_ID";
14 |
15 | /**
16 | * token有效期(小时)
17 | */
18 | public static final int TOKEN_EXPIRES_HOUR = 28;
19 |
20 | /**
21 | * refresh_token有效期(小时)
22 | */
23 | public static final int RETOKEN_EXPIRES_HOUR = 72;
24 |
25 | /**
26 | * 存放Authorization的header字段
27 | */
28 | public static final String AUTHORIZATION = "authorization";
29 |
30 |
31 | public static String SECRET_KEY="abcedefighijklmn12345678";
32 |
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/DesUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2015 Software innovation and R & D center. All rights reserved.
3 | * File Name: DesUtils.java
4 | * Encoding UTF-8
5 | * Version: 0.0.1
6 | * History: 2016年10月31日
7 | */
8 | package cn.chenxins.utils;
9 |
10 | import javax.crypto.Cipher;
11 | import javax.crypto.SecretKeyFactory;
12 | import javax.crypto.spec.DESedeKeySpec;
13 | import javax.crypto.spec.IvParameterSpec;
14 | import java.io.UnsupportedEncodingException;
15 | import java.security.Key;
16 | import java.security.MessageDigest;
17 | import java.security.NoSuchAlgorithmException;
18 | import java.util.Base64;
19 |
20 | /**
21 | * 3des加密解密(base64)
22 | * @author: qigui.su
23 | * @version Revision: 0.0.1
24 | * @Date: 2016年10月31日
25 | */
26 | public class DesUtils {
27 | // 向量
28 | private final static String iv = "01234567" ;
29 | // 加解密统一使用的编码方式
30 | private final static String encoding = "utf-8" ;
31 |
32 |
33 | /**
34 | * 3DES加密
35 | * @author: qigui.su
36 | * @param plainText 内容
37 | * @param key 密匙不小于24
38 | * @return
39 | * @throws Exception
40 | */
41 | public static String encode(String plainText,String key) throws Exception {
42 | Key deskey = null ;
43 | DESedeKeySpec spec = new DESedeKeySpec(key.getBytes());
44 | SecretKeyFactory keyfactory = SecretKeyFactory.getInstance( "DESede" );
45 | deskey = keyfactory.generateSecret(spec);
46 | Cipher cipher = Cipher.getInstance( "DESede/CBC/PKCS5Padding" );
47 | IvParameterSpec ips = new IvParameterSpec(iv.getBytes());
48 | cipher.init(Cipher.ENCRYPT_MODE, deskey, ips);
49 | byte [] encryptData = cipher.doFinal(plainText.getBytes(encoding));
50 | return Base64.getEncoder().encodeToString(encryptData);
51 | }
52 |
53 | /**
54 | * 3des解密
55 | * @author: qigui.su
56 | * @param encryptText 内容
57 | * @param key 密匙不小于24位
58 | * @return
59 | * @throws Exception
60 | */
61 | public static String decode(String encryptText, String key) throws Exception {
62 | Key deskey = null ;
63 | DESedeKeySpec spec = new DESedeKeySpec(key.getBytes());
64 | SecretKeyFactory keyfactory = SecretKeyFactory.getInstance( "DESede" );
65 | deskey = keyfactory.generateSecret(spec);
66 | Cipher cipher = Cipher.getInstance( "DESede/CBC/PKCS5Padding" );
67 | IvParameterSpec ips = new IvParameterSpec(iv.getBytes());
68 | cipher.init(Cipher.DECRYPT_MODE, deskey, ips);
69 |
70 | byte [] decryptData = cipher.doFinal(Base64.getDecoder().decode(encryptText));
71 |
72 | return new String(decryptData, encoding);
73 | }
74 |
75 | public static String md5(String value){
76 | String result = null;
77 | MessageDigest md5 = null;
78 | try{
79 | md5 = MessageDigest.getInstance("MD5");
80 | md5.update((value).getBytes("UTF-8"));
81 | }catch (NoSuchAlgorithmException error){
82 | error.printStackTrace();
83 | }catch (UnsupportedEncodingException e){
84 | e.printStackTrace();
85 | }
86 | byte b[] = md5.digest();
87 | int i;
88 | StringBuffer buf = new StringBuffer("");
89 |
90 | for(int offset=0; offset warnings = new ArrayList();
17 | boolean overwrite = true;
18 | //指定 逆向工程配置文件
19 | File configFile = new File("generatorConfig.xml");
20 | ConfigurationParser cp = new ConfigurationParser(warnings);
21 | Configuration config = cp.parseConfiguration(configFile);
22 | DefaultShellCallback callback = new DefaultShellCallback(overwrite);
23 | MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
24 | callback, warnings);
25 | myBatisGenerator.generate(null);
26 |
27 | }
28 |
29 | public static void main(String[] args) throws Exception {
30 | try {
31 | GeneratorMyBatiss generatorSqlmap = new GeneratorMyBatiss();
32 | generatorSqlmap.generator();
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | }
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/JdateUtils.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.utils;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Date;
5 |
6 | public class JdateUtils {
7 |
8 |
9 | public static int getCurrentTime(){
10 | Date date=new Date();
11 | long lTime=date.getTime()/1000;
12 | int cTime=new Long(lTime).intValue();
13 | return cTime;
14 | // Java中数据转换很常见,提供两种方法,不推荐强制转化类型,亲测无用!
15 | // 第一种:int returnId=new Long(a).intValue();
16 | // 第二种:int returnId=Integer.parseInt(String.valueOf(a));
17 | }
18 |
19 | public static Date getCurrentDate(){
20 | Date date=new Date();
21 | return date;
22 | }
23 |
24 | /**
25 | * 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
26 | */
27 | public static String getDate(String pattern) {
28 | Date date=new Date();
29 | SimpleDateFormat df=new SimpleDateFormat(pattern);
30 | return df.format(date);
31 | }
32 |
33 | /**
34 | * 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
35 | */
36 | public static String getDateGenFormat(Date date) {
37 | if (date==null)
38 | return "";
39 | String pattern="yyyy-MM-dd HH:mm:ss";
40 | SimpleDateFormat df=new SimpleDateFormat(pattern);
41 | return df.format(date);
42 | }
43 |
44 | /**
45 | * 获取两个日期之间的秒数
46 | *
47 | * @param before
48 | * @param after
49 | * @return
50 | */
51 | public static double getDistanceOfTimeDate(Date before, Date after) {
52 | long beforeTime = before.getTime();
53 | long afterTime = after.getTime();
54 | return (afterTime - beforeTime) / (1000);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/JsonUtils.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.utils;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 | import com.fasterxml.jackson.databind.JavaType;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | *
11 | * @Title: JsonUtils.java
12 | * @Package com.lee.utils
13 | * @Description: 自定义响应结构, 转换类
14 | * Copyright: Copyright (c) 2016
15 | * Company:Nathan.Lee.Salvatore
16 | *
17 | * @author leechenxiang
18 | * @date 2016年4月29日 下午11:05:03
19 | * @version V1.0
20 | */
21 | public class JsonUtils {
22 |
23 | // 定义jackson对象
24 | private static final ObjectMapper MAPPER = new ObjectMapper();
25 |
26 | /**
27 | * 将对象转换成json字符串。
28 | * Title: pojoToJson
29 | * Description:
30 | * @param data
31 | * @return
32 | */
33 | public static String objectToJson(Object data) {
34 | try {
35 | String string = MAPPER.writeValueAsString(data);
36 | return string;
37 | } catch (JsonProcessingException e) {
38 | e.printStackTrace();
39 | }
40 | return null;
41 | }
42 |
43 | /**
44 | * 将对象转换成json字符串。并且报isSuper转成super 以适配前端
45 | * Title: pojoToJson
46 | * Description:
47 | * @param data
48 | * @return
49 | */
50 | public static String objectToJsonSpecial(Object data) {
51 | try {
52 | String string = MAPPER.writeValueAsString(data);
53 |
54 | return string.replaceAll("isSuper","super");
55 | } catch (JsonProcessingException e) {
56 | e.printStackTrace();
57 | }
58 | return null;
59 | }
60 |
61 | /**
62 | * 将json结果集转化为对象
63 | *
64 | * @param jsonData json数据
65 | * @return
66 | */
67 | public static T jsonToPojo(String jsonData, Class beanType) {
68 | try {
69 | T t = MAPPER.readValue(jsonData, beanType);
70 | return t;
71 | } catch (Exception e) {
72 | e.printStackTrace();
73 | }
74 | return null;
75 | }
76 |
77 | /**
78 | * 将json数据转换成pojo对象list
79 | * Title: jsonToList
80 | * Description:
81 | * @param jsonData
82 | * @param beanType
83 | * @return
84 | */
85 | public static List jsonToList(String jsonData, Class beanType) {
86 | JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);
87 | try {
88 | List list = MAPPER.readValue(jsonData, javaType);
89 | return list;
90 | } catch (Exception e) {
91 | e.printStackTrace();
92 | }
93 |
94 | return null;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/MetaJson.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.utils;
2 |
3 | import org.springframework.web.context.WebApplicationContext;
4 | import org.springframework.web.method.HandlerMethod;
5 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
6 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 | import java.util.Set;
11 |
12 | public class MetaJson {
13 |
14 | private String module;
15 |
16 | private String auth;
17 |
18 | private String uri;
19 |
20 | public static Map getMetaMap(WebApplicationContext context){
21 | RequestMappingHandlerMapping mapping = context.getBean(RequestMappingHandlerMapping.class);
22 | //获取url与类和方法的对应信息
23 | Map map = mapping.getHandlerMethods();
24 | Map authMap=new HashMap<>();
25 | String mName,module,auth;
26 | MetaJson metaJson;
27 | for (RequestMappingInfo info : map.keySet()){
28 |
29 | mName=info.getName();
30 | if (StringUtil.isNotBlank(mName))
31 | {
32 | String[] ma=mName.split("#");
33 | if (ma.length==2)
34 | {
35 | module=ma[0];
36 | auth=ma[1];
37 | } else {
38 | module="";
39 | auth=mName;
40 | }
41 | //获取url的Set集合,一个方法可能对应多个url
42 | Set patterns = info.getPatternsCondition().getPatterns();
43 | for (String url : patterns){
44 | metaJson=new MetaJson(module,auth,url);
45 | authMap.put(auth,metaJson);
46 | break;
47 | }
48 | }
49 | }
50 | return authMap;
51 | }
52 |
53 | public static Map getMetaMapUsingUri(WebApplicationContext context){
54 | RequestMappingHandlerMapping mapping = context.getBean(RequestMappingHandlerMapping.class);
55 | //获取url与类和方法的对应信息
56 | Map map = mapping.getHandlerMethods();
57 | Map authMap=new HashMap<>();
58 | String mName,module,auth;
59 | MetaJson metaJson;
60 | for (RequestMappingInfo info : map.keySet()){
61 |
62 | mName=info.getName();
63 | if (StringUtil.isNotBlank(mName))
64 | {
65 | String[] ma=mName.split("#");
66 | if (ma.length==2)
67 | {
68 | module=ma[0];
69 | auth=ma[1];
70 | } else {
71 | module="";
72 | auth=mName;
73 | }
74 | //获取url的Set集合,一个方法可能对应多个url
75 | Set patterns = info.getPatternsCondition().getPatterns();
76 | for (String url : patterns){
77 | metaJson=new MetaJson(module,auth,url);
78 | authMap.put(url,metaJson);
79 | break;
80 | }
81 | }
82 | }
83 | return authMap;
84 | }
85 |
86 |
87 | public MetaJson(String module, String auth, String uri) {
88 | this.module = module;
89 | this.auth = auth;
90 | this.uri = uri;
91 | }
92 |
93 | public String getModule() {
94 | return module;
95 | }
96 |
97 | public void setModule(String module) {
98 | this.module = module;
99 | }
100 |
101 | public String getAuth() {
102 | return auth;
103 | }
104 |
105 | public void setAuth(String auth) {
106 | this.auth = auth;
107 | }
108 |
109 | public String getUri() {
110 | return uri;
111 | }
112 |
113 | public void setUri(String uri) {
114 | this.uri = uri;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/MvcConfig.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.utils;
2 |
3 |
4 | import cn.chenxins.authorization.interceptor.AuthorizationInterceptor;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.web.servlet.config.annotation.CorsRegistry;
8 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
9 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
11 |
12 | /**
13 | * 配置类,增加自定义拦截器和解析器
14 | * @see cn.chenxins.authorization.interceptor.AuthorizationInterceptor
15 | */
16 | @Configuration
17 | public class MvcConfig implements WebMvcConfigurer {
18 |
19 | @Autowired
20 | private AuthorizationInterceptor authorizationInterceptor;
21 |
22 | @Override
23 | public void addResourceHandlers(ResourceHandlerRegistry registry) {
24 | registry.addResourceHandler("/static/**").addResourceLocations("file:C:/upload/");
25 | // registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
26 | }
27 |
28 |
29 | @Override
30 | public void addInterceptors(InterceptorRegistry registry) {
31 | registry.addInterceptor(authorizationInterceptor);
32 | }
33 |
34 |
35 | @Override
36 | public void addCorsMappings(CorsRegistry registry) {
37 | registry.addMapping("/**")
38 | .allowCredentials(true)
39 | .allowedHeaders("*")
40 | // .allowedOrigins("http://admin.chenxins.cn","http://blog.chenxins.cn")
41 | .allowedOrigins("*")
42 | .allowedMethods("*");
43 |
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/MyMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2016 abel533@gmail.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package cn.chenxins.utils;
26 |
27 | import tk.mybatis.mapper.common.Mapper;
28 | import tk.mybatis.mapper.common.MySqlMapper;
29 |
30 | /**
31 | * 继承自己的MyMapper
32 | *
33 | * @author liuzh
34 | * @since 2015-09-06 21:53
35 | */
36 | public interface MyMapper extends Mapper, MySqlMapper {
37 | //TODO
38 | //FIXME 特别注意,该接口不能被扫描到,否则会出错
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/cn/chenxins/utils/RedisOperator.java:
--------------------------------------------------------------------------------
1 | package cn.chenxins.utils;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.data.redis.core.StringRedisTemplate;
5 | import org.springframework.stereotype.Component;
6 |
7 | import java.util.Map;
8 | import java.util.Set;
9 | import java.util.concurrent.TimeUnit;
10 |
11 | /**
12 | *
13 | * @Title: RedisOperator.java
14 | * @Package com.itzixi.web.component
15 | * @Description: 使用redisTemplate的操作实现类 Copyright: Copyright (c) 2016
16 | * Company:FURUIBOKE.SCIENCE.AND.TECHNOLOGY
17 | *
18 | * @author leechenxiang
19 | * @date 2017年9月29日 下午2:25:03
20 | * @version V1.0
21 | */
22 | @Component
23 | public class RedisOperator {
24 |
25 | // @Autowired
26 | // private RedisTemplate redisTemplate;
27 |
28 | @Autowired
29 | private StringRedisTemplate redisTemplate;
30 |
31 | // Key(键),简单的key-value操作
32 |
33 | /**
34 | * 实现命令:TTL key,以秒为单位,返回给定 key的剩余生存时间(TTL, time to live)。
35 | *
36 | * @param key
37 | * @return
38 | */
39 | public long ttl(String key) {
40 | return redisTemplate.getExpire(key);
41 | }
42 |
43 | /**
44 | * 实现命令:expire 设置过期时间,单位秒
45 | *
46 | * @param key
47 | * @return
48 | */
49 | public void expire(String key, long timeout) {
50 | redisTemplate.expire(key, timeout, TimeUnit.SECONDS);
51 | }
52 |
53 | /**
54 | * 实现命令:INCR key,增加key一次
55 | *
56 | * @param key
57 | * @return
58 | */
59 | public long incr(String key, long delta) {
60 | return redisTemplate.opsForValue().increment(key, delta);
61 | }
62 |
63 | /**
64 | * 实现命令:KEYS pattern,查找所有符合给定模式 pattern的 key
65 | */
66 | public Set keys(String pattern) {
67 | return redisTemplate.keys(pattern);
68 | }
69 |
70 | /**
71 | * 实现命令:DEL key,删除一个key
72 | *
73 | * @param key
74 | */
75 | public void del(String key) {
76 | redisTemplate.delete(key);
77 | }
78 |
79 | // String(字符串)
80 |
81 | /**
82 | * 实现命令:SET key value,设置一个key-value(将字符串值 value关联到 key)
83 | *
84 | * @param key
85 | * @param value
86 | */
87 | public void set(String key, String value) {
88 | redisTemplate.opsForValue().set(key, value);
89 | }
90 |
91 | /**
92 | * 实现命令:SET key value EX seconds,设置key-value和超时时间(秒)
93 | *
94 | * @param key
95 | * @param value
96 | * @param timeout
97 | * (以秒为单位)
98 | */
99 | public void set(String key, String value, long timeout) {
100 | redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
101 | }
102 |
103 | /**
104 | * 实现命令:GET key,返回 key所关联的字符串值。
105 | *
106 | * @param key
107 | * @return value
108 | */
109 | public String get(String key) {
110 | return (String)redisTemplate.opsForValue().get(key);
111 | }
112 |
113 | // Hash(哈希表)
114 |
115 | /**
116 | * 实现命令:HSET key field value,将哈希表 key中的域 field的值设为 value
117 | *
118 | * @param key
119 | * @param field
120 | * @param value
121 | */
122 | public void hset(String key, String field, Object value) {
123 | redisTemplate.opsForHash().put(key, field, value);
124 | }
125 |
126 | /**
127 | * 实现命令:HGET key field,返回哈希表 key中给定域 field的值
128 | *
129 | * @param key
130 | * @param field
131 | * @return
132 | */
133 | public String hget(String key, String field) {
134 | return (String) redisTemplate.opsForHash().get(key, field);
135 | }
136 |
137 | /**
138 | * 实现命令:HDEL key field [field ...],删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。
139 | *
140 | * @param key
141 | * @param fields
142 | */
143 | public void hdel(String key, Object... fields) {
144 | redisTemplate.opsForHash().delete(key, fields);
145 | }
146 |
147 | /**
148 | * 实现命令:HGETALL key,返回哈希表 key中,所有的域和值。
149 | *
150 | * @param key
151 | * @return
152 | */
153 | public Map