张延森 3 年 前
コミット
112f823c8c
共有85 個のファイルを変更した3978 個の追加0 個の削除を含む
  1. 42
    0
      .gitignore
  2. 310
    0
      mvnw
  3. 182
    0
      mvnw.cmd
  4. 203
    0
      pom.xml
  5. 16
    0
      src/main/java/com/yunzhi/nanyang/SpringApplication.java
  6. 4
    0
      src/main/java/com/yunzhi/nanyang/common/BaseController.java
  7. 7
    0
      src/main/java/com/yunzhi/nanyang/common/Constants.java
  8. 37
    0
      src/main/java/com/yunzhi/nanyang/common/DateUtils.java
  9. 17
    0
      src/main/java/com/yunzhi/nanyang/common/EncryptUtils.java
  10. 26
    0
      src/main/java/com/yunzhi/nanyang/common/ExcelUtils.java
  11. 87
    0
      src/main/java/com/yunzhi/nanyang/common/HttpUtils.java
  12. 11
    0
      src/main/java/com/yunzhi/nanyang/common/MathUtils.java
  13. 68
    0
      src/main/java/com/yunzhi/nanyang/common/OSSUtils.java
  14. 67
    0
      src/main/java/com/yunzhi/nanyang/common/ResponseBean.java
  15. 155
    0
      src/main/java/com/yunzhi/nanyang/common/SMSCaptcha.java
  16. 58
    0
      src/main/java/com/yunzhi/nanyang/common/SMSUtils.java
  17. 120
    0
      src/main/java/com/yunzhi/nanyang/common/StringUtils.java
  18. 34
    0
      src/main/java/com/yunzhi/nanyang/common/WxUtils.java
  19. 39
    0
      src/main/java/com/yunzhi/nanyang/config/AliyunConfig.java
  20. 28
    0
      src/main/java/com/yunzhi/nanyang/config/CorsConfig.java
  21. 21
    0
      src/main/java/com/yunzhi/nanyang/config/LoggingFilterConfig.java
  22. 14
    0
      src/main/java/com/yunzhi/nanyang/config/MybatisPlusConfig.java
  23. 24
    0
      src/main/java/com/yunzhi/nanyang/config/SwagggerConfig.java
  24. 24
    0
      src/main/java/com/yunzhi/nanyang/config/WeixinConfig.java
  25. 117
    0
      src/main/java/com/yunzhi/nanyang/controller/LoginController.java
  26. 43
    0
      src/main/java/com/yunzhi/nanyang/controller/SysLoginController.java
  27. 121
    0
      src/main/java/com/yunzhi/nanyang/controller/SysMenuController.java
  28. 119
    0
      src/main/java/com/yunzhi/nanyang/controller/SysPermissionController.java
  29. 119
    0
      src/main/java/com/yunzhi/nanyang/controller/SysRoleController.java
  30. 119
    0
      src/main/java/com/yunzhi/nanyang/controller/SysRolePermissionController.java
  31. 119
    0
      src/main/java/com/yunzhi/nanyang/controller/SysUserController.java
  32. 119
    0
      src/main/java/com/yunzhi/nanyang/controller/SysUserRoleController.java
  33. 47
    0
      src/main/java/com/yunzhi/nanyang/entity/SysLogin.java
  34. 45
    0
      src/main/java/com/yunzhi/nanyang/entity/SysMenu.java
  35. 39
    0
      src/main/java/com/yunzhi/nanyang/entity/SysPermission.java
  36. 36
    0
      src/main/java/com/yunzhi/nanyang/entity/SysRole.java
  37. 39
    0
      src/main/java/com/yunzhi/nanyang/entity/SysRolePermission.java
  38. 58
    0
      src/main/java/com/yunzhi/nanyang/entity/SysUser.java
  39. 39
    0
      src/main/java/com/yunzhi/nanyang/entity/SysUserRole.java
  40. 24
    0
      src/main/java/com/yunzhi/nanyang/exception/GlobalExceptionHandler.java
  41. 80
    0
      src/main/java/com/yunzhi/nanyang/log/MysqlAppender.java
  42. 20
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysLoginMapper.java
  43. 18
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysMenuMapper.java
  44. 18
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysPermissionMapper.java
  45. 18
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysRoleMapper.java
  46. 22
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysRolePermissionMapper.java
  47. 18
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysUserMapper.java
  48. 22
    0
      src/main/java/com/yunzhi/nanyang/mapper/SysUserRoleMapper.java
  49. 20
    0
      src/main/java/com/yunzhi/nanyang/service/IBaseService.java
  50. 18
    0
      src/main/java/com/yunzhi/nanyang/service/ISysLoginService.java
  51. 16
    0
      src/main/java/com/yunzhi/nanyang/service/ISysMenuService.java
  52. 16
    0
      src/main/java/com/yunzhi/nanyang/service/ISysPermissionService.java
  53. 16
    0
      src/main/java/com/yunzhi/nanyang/service/ISysRolePermissionService.java
  54. 16
    0
      src/main/java/com/yunzhi/nanyang/service/ISysRoleService.java
  55. 16
    0
      src/main/java/com/yunzhi/nanyang/service/ISysUserRoleService.java
  56. 16
    0
      src/main/java/com/yunzhi/nanyang/service/ISysUserService.java
  57. 54
    0
      src/main/java/com/yunzhi/nanyang/service/impl/BaseServiceImpl.java
  58. 55
    0
      src/main/java/com/yunzhi/nanyang/service/impl/ManagerServiceImpl.java
  59. 25
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysLoginServiceImpl.java
  60. 20
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysMenuServiceImpl.java
  61. 20
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysPermissionServiceImpl.java
  62. 20
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysRolePermissionServiceImpl.java
  63. 20
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysRoleServiceImpl.java
  64. 20
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysUserRoleServiceImpl.java
  65. 20
    0
      src/main/java/com/yunzhi/nanyang/service/impl/SysUserServiceImpl.java
  66. 76
    0
      src/main/java/com/yunzhi/nanyang/shiro/ShiroConfig.java
  67. 83
    0
      src/main/java/com/yunzhi/nanyang/shiro/filters/JWTFilter.java
  68. 14
    0
      src/main/java/com/yunzhi/nanyang/shiro/matcher/JWTCredentialsMatcher.java
  69. 31
    0
      src/main/java/com/yunzhi/nanyang/shiro/realms/manager/IManagerService.java
  70. 55
    0
      src/main/java/com/yunzhi/nanyang/shiro/realms/manager/ManagerRealm.java
  71. 23
    0
      src/main/java/com/yunzhi/nanyang/shiro/utils/JWTToken.java
  72. 65
    0
      src/main/java/com/yunzhi/nanyang/shiro/utils/JWTUtil.java
  73. 19
    0
      src/main/java/com/yunzhi/nanyang/vo/LoginParam.java
  74. 16
    0
      src/main/resources/application-dev.yml
  75. 11
    0
      src/main/resources/application-prod.yml
  76. 68
    0
      src/main/resources/application.yml
  77. 31
    0
      src/main/resources/logback.xml.bak
  78. 14
    0
      src/main/resources/mapper/SysLoginMapper.xml
  79. 5
    0
      src/main/resources/mapper/SysMenuMapper.xml
  80. 5
    0
      src/main/resources/mapper/SysPermissionMapper.xml
  81. 5
    0
      src/main/resources/mapper/SysRoleMapper.xml
  82. 19
    0
      src/main/resources/mapper/SysRolePermissionMapper.xml
  83. 5
    0
      src/main/resources/mapper/SysUserMapper.xml
  84. 19
    0
      src/main/resources/mapper/SysUserRoleMapper.xml
  85. 13
    0
      src/test/java/com/yunzhi/demo/SpringApplicationTests.java

+ 42
- 0
.gitignore ファイルの表示

@@ -0,0 +1,42 @@
1
+HELP.md
2
+target/
3
+!.mvn/wrapper/maven-wrapper.jar
4
+!**/src/main/**/target/
5
+!**/src/test/**/target/
6
+
7
+### STS ###
8
+.apt_generated
9
+.classpath
10
+.factorypath
11
+.project
12
+.settings
13
+.springBeans
14
+.sts4-cache
15
+
16
+### IntelliJ IDEA ###
17
+.idea
18
+*.iws
19
+*.iml
20
+*.ipr
21
+
22
+### NetBeans ###
23
+/nbproject/private/
24
+/nbbuild/
25
+/dist/
26
+/nbdist/
27
+/.nb-gradle/
28
+build/
29
+!**/src/main/**/build/
30
+!**/src/test/**/build/
31
+
32
+### VS Code ###
33
+.vscode/
34
+
35
+### serverless ###
36
+/deploy/*.jar
37
+/deploy/*.zip
38
+/deploy/.fun/
39
+/deploy/.env
40
+/deploy/.s
41
+
42
+cert/

+ 310
- 0
mvnw ファイルの表示

@@ -0,0 +1,310 @@
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
+#    https://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
+# Maven 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
+fi
118
+
119
+if [ -z "$JAVA_HOME" ]; then
120
+  javaExecutable="`which javac`"
121
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
122
+    # readlink(1) is not available as standard on Solaris 10.
123
+    readLink=`which readlink`
124
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
125
+      if $darwin ; then
126
+        javaHome="`dirname \"$javaExecutable\"`"
127
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
128
+      else
129
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
130
+      fi
131
+      javaHome="`dirname \"$javaExecutable\"`"
132
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
133
+      JAVA_HOME="$javaHome"
134
+      export JAVA_HOME
135
+    fi
136
+  fi
137
+fi
138
+
139
+if [ -z "$JAVACMD" ] ; then
140
+  if [ -n "$JAVA_HOME"  ] ; then
141
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
142
+      # IBM's JDK on AIX uses strange locations for the executables
143
+      JAVACMD="$JAVA_HOME/jre/sh/java"
144
+    else
145
+      JAVACMD="$JAVA_HOME/bin/java"
146
+    fi
147
+  else
148
+    JAVACMD="`which java`"
149
+  fi
150
+fi
151
+
152
+if [ ! -x "$JAVACMD" ] ; then
153
+  echo "Error: JAVA_HOME is not defined correctly." >&2
154
+  echo "  We cannot execute $JAVACMD" >&2
155
+  exit 1
156
+fi
157
+
158
+if [ -z "$JAVA_HOME" ] ; then
159
+  echo "Warning: JAVA_HOME environment variable is not set."
160
+fi
161
+
162
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
163
+
164
+# traverses directory structure from process work directory to filesystem root
165
+# first directory with .mvn subdirectory is considered project base directory
166
+find_maven_basedir() {
167
+
168
+  if [ -z "$1" ]
169
+  then
170
+    echo "Path not specified to find_maven_basedir"
171
+    return 1
172
+  fi
173
+
174
+  basedir="$1"
175
+  wdir="$1"
176
+  while [ "$wdir" != '/' ] ; do
177
+    if [ -d "$wdir"/.mvn ] ; then
178
+      basedir=$wdir
179
+      break
180
+    fi
181
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
182
+    if [ -d "${wdir}" ]; then
183
+      wdir=`cd "$wdir/.."; pwd`
184
+    fi
185
+    # end of workaround
186
+  done
187
+  echo "${basedir}"
188
+}
189
+
190
+# concatenates all lines of a file
191
+concat_lines() {
192
+  if [ -f "$1" ]; then
193
+    echo "$(tr -s '\n' ' ' < "$1")"
194
+  fi
195
+}
196
+
197
+BASE_DIR=`find_maven_basedir "$(pwd)"`
198
+if [ -z "$BASE_DIR" ]; then
199
+  exit 1;
200
+fi
201
+
202
+##########################################################################################
203
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
204
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
205
+##########################################################################################
206
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
207
+    if [ "$MVNW_VERBOSE" = true ]; then
208
+      echo "Found .mvn/wrapper/maven-wrapper.jar"
209
+    fi
210
+else
211
+    if [ "$MVNW_VERBOSE" = true ]; then
212
+      echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
213
+    fi
214
+    if [ -n "$MVNW_REPOURL" ]; then
215
+      jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
216
+    else
217
+      jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
218
+    fi
219
+    while IFS="=" read key value; do
220
+      case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
221
+      esac
222
+    done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
223
+    if [ "$MVNW_VERBOSE" = true ]; then
224
+      echo "Downloading from: $jarUrl"
225
+    fi
226
+    wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
227
+    if $cygwin; then
228
+      wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
229
+    fi
230
+
231
+    if command -v wget > /dev/null; then
232
+        if [ "$MVNW_VERBOSE" = true ]; then
233
+          echo "Found wget ... using wget"
234
+        fi
235
+        if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
236
+            wget "$jarUrl" -O "$wrapperJarPath"
237
+        else
238
+            wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
239
+        fi
240
+    elif command -v curl > /dev/null; then
241
+        if [ "$MVNW_VERBOSE" = true ]; then
242
+          echo "Found curl ... using curl"
243
+        fi
244
+        if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
245
+            curl -o "$wrapperJarPath" "$jarUrl" -f
246
+        else
247
+            curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
248
+        fi
249
+
250
+    else
251
+        if [ "$MVNW_VERBOSE" = true ]; then
252
+          echo "Falling back to using Java to download"
253
+        fi
254
+        javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
255
+        # For Cygwin, switch paths to Windows format before running javac
256
+        if $cygwin; then
257
+          javaClass=`cygpath --path --windows "$javaClass"`
258
+        fi
259
+        if [ -e "$javaClass" ]; then
260
+            if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
261
+                if [ "$MVNW_VERBOSE" = true ]; then
262
+                  echo " - Compiling MavenWrapperDownloader.java ..."
263
+                fi
264
+                # Compiling the Java class
265
+                ("$JAVA_HOME/bin/javac" "$javaClass")
266
+            fi
267
+            if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
268
+                # Running the downloader
269
+                if [ "$MVNW_VERBOSE" = true ]; then
270
+                  echo " - Running MavenWrapperDownloader.java ..."
271
+                fi
272
+                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
273
+            fi
274
+        fi
275
+    fi
276
+fi
277
+##########################################################################################
278
+# End of extension
279
+##########################################################################################
280
+
281
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
282
+if [ "$MVNW_VERBOSE" = true ]; then
283
+  echo $MAVEN_PROJECTBASEDIR
284
+fi
285
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
286
+
287
+# For Cygwin, switch paths to Windows format before running java
288
+if $cygwin; then
289
+  [ -n "$M2_HOME" ] &&
290
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
291
+  [ -n "$JAVA_HOME" ] &&
292
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
293
+  [ -n "$CLASSPATH" ] &&
294
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
295
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
296
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
297
+fi
298
+
299
+# Provide a "standardized" way to retrieve the CLI args that will
300
+# work with both Windows and non-Windows executions.
301
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
302
+export MAVEN_CMD_LINE_ARGS
303
+
304
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
305
+
306
+exec "$JAVACMD" \
307
+  $MAVEN_OPTS \
308
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
309
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
310
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 182
- 0
mvnw.cmd ファイルの表示

@@ -0,0 +1,182 @@
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    https://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 Maven 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 keystroke 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 by 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.5.6/maven-wrapper-0.5.6.jar"
124
+
125
+FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126
+    IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
127
+)
128
+
129
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
130
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
131
+if exist %WRAPPER_JAR% (
132
+    if "%MVNW_VERBOSE%" == "true" (
133
+        echo Found %WRAPPER_JAR%
134
+    )
135
+) else (
136
+    if not "%MVNW_REPOURL%" == "" (
137
+        SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
138
+    )
139
+    if "%MVNW_VERBOSE%" == "true" (
140
+        echo Couldn't find %WRAPPER_JAR%, downloading it ...
141
+        echo Downloading from: %DOWNLOAD_URL%
142
+    )
143
+
144
+    powershell -Command "&{"^
145
+		"$webclient = new-object System.Net.WebClient;"^
146
+		"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147
+		"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148
+		"}"^
149
+		"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150
+		"}"
151
+    if "%MVNW_VERBOSE%" == "true" (
152
+        echo Finished downloading %WRAPPER_JAR%
153
+    )
154
+)
155
+@REM End of extension
156
+
157
+@REM Provide a "standardized" way to retrieve the CLI args that will
158
+@REM work with both Windows and non-Windows executions.
159
+set MAVEN_CMD_LINE_ARGS=%*
160
+
161
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
162
+if ERRORLEVEL 1 goto error
163
+goto end
164
+
165
+:error
166
+set ERROR_CODE=1
167
+
168
+:end
169
+@endlocal & set ERROR_CODE=%ERROR_CODE%
170
+
171
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
172
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
173
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
174
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
175
+:skipRcPost
176
+
177
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
178
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
179
+
180
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
181
+
182
+exit /B %ERROR_CODE%

+ 203
- 0
pom.xml ファイルの表示

@@ -0,0 +1,203 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+	<parent>
6
+		<groupId>org.springframework.boot</groupId>
7
+		<artifactId>spring-boot-starter-parent</artifactId>
8
+		<version>2.3.2.RELEASE</version>
9
+		<relativePath/> <!-- lookup parent from repository -->
10
+	</parent>
11
+	<groupId>com.yunzhi</groupId>
12
+	<artifactId>serivce-template</artifactId>
13
+	<version>0.0.1-SNAPSHOT</version>
14
+	<name>demo</name>
15
+	<description>Demo project for Spring Boot</description>
16
+
17
+	<properties>
18
+		<java.version>1.8</java.version>
19
+		<log4j.version>2.17.0</log4j.version>
20
+	</properties>
21
+
22
+	<dependencies>
23
+		<dependency>
24
+			<groupId>org.springframework.boot</groupId>
25
+			<artifactId>spring-boot-starter-web</artifactId>
26
+		</dependency>
27
+
28
+		<dependency>
29
+			<groupId>org.springframework.boot</groupId>
30
+			<artifactId>spring-boot-starter-test</artifactId>
31
+			<scope>test</scope>
32
+			<exclusions>
33
+				<exclusion>
34
+					<groupId>org.junit.vintage</groupId>
35
+					<artifactId>junit-vintage-engine</artifactId>
36
+				</exclusion>
37
+			</exclusions>
38
+		</dependency>
39
+
40
+		<!--mysql start-->
41
+		<dependency>
42
+			<groupId>mysql</groupId>
43
+			<artifactId>mysql-connector-java</artifactId>
44
+			<scope>runtime</scope>
45
+		</dependency>
46
+		<!--mysql end-->
47
+
48
+		<!--mybatis-plus start-->
49
+		<dependency>
50
+			<groupId>com.baomidou</groupId>
51
+			<artifactId>mybatis-plus-boot-starter</artifactId>
52
+			<version>3.1.1</version>
53
+		</dependency>
54
+		<!--mybatis-plus end-->
55
+
56
+		<!--fastjson start-->
57
+		<dependency>
58
+			<groupId>com.alibaba</groupId>
59
+			<artifactId>fastjson</artifactId>
60
+			<version>1.2.56</version>
61
+		</dependency>
62
+		<!--fastjson end-->
63
+
64
+		<!--oss start-->
65
+		<dependency>
66
+			<groupId>com.aliyun.oss</groupId>
67
+			<artifactId>aliyun-sdk-oss</artifactId>
68
+			<version>2.8.3</version>
69
+		</dependency>
70
+		<!--oss end-->
71
+
72
+		<dependency>
73
+			<groupId>com.aliyun</groupId>
74
+			<artifactId>aliyun-java-sdk-core</artifactId>
75
+			<version>[4.4.9,5.0.0)</version>
76
+		</dependency>
77
+
78
+		<!--excel start-->
79
+		<dependency>
80
+			<groupId>com.alibaba</groupId>
81
+			<artifactId>easyexcel</artifactId>
82
+			<version>2.0.4</version>
83
+		</dependency>
84
+		<!--excel end-->
85
+
86
+		<!--weixin-miniapp start-->
87
+		<dependency>
88
+			<groupId>com.github.binarywang</groupId>
89
+			<artifactId>weixin-java-miniapp</artifactId>
90
+			<version>3.8.0</version>
91
+		</dependency>
92
+		<!--weixin-miniapp start-->
93
+
94
+		<!--lombok start-->
95
+		<dependency>
96
+			<groupId>org.projectlombok</groupId>
97
+			<artifactId>lombok</artifactId>
98
+			<optional>true</optional>
99
+		</dependency>
100
+		<!--lombok end-->
101
+
102
+		<!--swagger start-->
103
+		<dependency>
104
+			<groupId>io.springfox</groupId>
105
+			<artifactId>springfox-boot-starter</artifactId>
106
+			<version>3.0.0</version>
107
+		</dependency>
108
+		<!--swagger end-->
109
+
110
+
111
+		<!-- shiro start-->
112
+		<dependency>
113
+			<groupId>org.apache.shiro</groupId>
114
+			<artifactId>shiro-spring-boot-web-starter</artifactId>
115
+			<version>1.8.0</version>
116
+		</dependency>
117
+		<!-- shiro end-->
118
+
119
+		<!-- jwt start -->
120
+		<dependency>
121
+			<groupId>com.auth0</groupId>
122
+			<artifactId>java-jwt</artifactId>
123
+			<version>3.18.3</version>
124
+		</dependency>
125
+		<!-- end start -->
126
+	</dependencies>
127
+
128
+	<profiles>
129
+		<profile>
130
+			<id>dev</id>
131
+			<properties>
132
+				<profileActive>dev</profileActive>
133
+			</properties>
134
+			<activation>
135
+				<activeByDefault>true</activeByDefault>
136
+			</activation>
137
+
138
+			<build>
139
+				<plugins>
140
+					<plugin>
141
+						<groupId>org.springframework.boot</groupId>
142
+						<artifactId>spring-boot-maven-plugin</artifactId>
143
+					</plugin>
144
+				</plugins>
145
+				<resources>
146
+					<resource>
147
+						<directory>src/main/resources</directory>
148
+						<filtering>true</filtering>
149
+					</resource>
150
+				</resources>
151
+			</build>
152
+		</profile>
153
+
154
+		<profile>
155
+			<id>prod</id>
156
+			<properties>
157
+				<profileActive>prod</profileActive>
158
+			</properties>
159
+			<activation>
160
+				<activeByDefault>false</activeByDefault>
161
+			</activation>
162
+
163
+			<build>
164
+				<plugins>
165
+					<plugin>
166
+						<groupId>org.springframework.boot</groupId>
167
+						<artifactId>spring-boot-maven-plugin</artifactId>
168
+					</plugin>
169
+
170
+					<!-- 跳过测试 -->
171
+					<plugin>
172
+						<groupId>org.apache.maven.plugins</groupId>
173
+						<artifactId>maven-surefire-plugin</artifactId>
174
+						<configuration>
175
+							<skipTests>true</skipTests>
176
+							<testFailureIgnore>true</testFailureIgnore>
177
+						</configuration>
178
+					</plugin>
179
+				</plugins>
180
+				<resources>
181
+					<resource>
182
+						<directory>src/main/resources</directory>
183
+						<filtering>true</filtering>
184
+						<excludes>
185
+							<exclude>application.yml</exclude>
186
+							<exclude>application-*.yml</exclude>
187
+						</excludes>
188
+					</resource>
189
+					<resource>
190
+						<directory>src/main/resources</directory>
191
+						<filtering>true</filtering>
192
+						<includes>
193
+							<include>application.yml</include>
194
+							<include>application-${profileActive}.yml</include>
195
+						</includes>
196
+						<targetPath>${project.build.directory}/config</targetPath>
197
+					</resource>
198
+				</resources>
199
+			</build>
200
+		</profile>
201
+	</profiles>
202
+
203
+</project>

+ 16
- 0
src/main/java/com/yunzhi/nanyang/SpringApplication.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.nanyang;
2
+
3
+import org.springframework.boot.autoconfigure.SpringBootApplication;
4
+import org.springframework.scheduling.annotation.EnableAsync;
5
+import org.springframework.transaction.annotation.EnableTransactionManagement;
6
+
7
+@EnableAsync
8
+@EnableTransactionManagement
9
+@SpringBootApplication
10
+public class SpringApplication {
11
+
12
+	public static void main(String[] args) {
13
+		org.springframework.boot.SpringApplication.run(SpringApplication.class, args);
14
+	}
15
+
16
+}

+ 4
- 0
src/main/java/com/yunzhi/nanyang/common/BaseController.java ファイルの表示

@@ -0,0 +1,4 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+public class BaseController {
4
+}

+ 7
- 0
src/main/java/com/yunzhi/nanyang/common/Constants.java ファイルの表示

@@ -0,0 +1,7 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+public class Constants {
4
+    public final static int STATUS_DELETE = -1;
5
+    public final static int STATUS_READY = 0;
6
+    public final static int STATUS_NORMAL = 1;
7
+}

+ 37
- 0
src/main/java/com/yunzhi/nanyang/common/DateUtils.java ファイルの表示

@@ -0,0 +1,37 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import java.time.*;
4
+import java.time.format.DateTimeFormatter;
5
+
6
+public class DateUtils {
7
+    public static LocalDateTime from(String str, String formater) {
8
+        DateTimeFormatter fmt = DateTimeFormatter.ofPattern(formater);
9
+        return LocalDateTime.parse(str, fmt);
10
+    }
11
+
12
+    public static long daysBetween(LocalDateTime dt1, LocalDateTime dt2) {
13
+        Duration duration = Duration.between(dt1, dt2);
14
+        return duration.toDays();
15
+    }
16
+
17
+    public static String toString(LocalDateTime dt, String formater) {
18
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formater);
19
+        return dt.format(formatter);
20
+    }
21
+
22
+    public static String weekDay(LocalDateTime dt) {
23
+        String[] week = new String[]{"一", "二", "三", "四", "五", "六", "日"};
24
+        DayOfWeek dayOfWeek = dt.getDayOfWeek();
25
+        int inx = dayOfWeek.getValue() - 1;
26
+        return String.format("星期%s", week[inx]);
27
+    }
28
+
29
+    /**
30
+     * 毫秒转 UTC 时间
31
+     * @param milliseconds
32
+     * @return
33
+     */
34
+    public static LocalDateTime getDateTime(long milliseconds) {
35
+        return LocalDateTime.ofInstant(Instant.ofEpochMilli(milliseconds), ZoneOffset.UTC);
36
+    }
37
+}

+ 17
- 0
src/main/java/com/yunzhi/nanyang/common/EncryptUtils.java ファイルの表示

@@ -0,0 +1,17 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import org.springframework.util.DigestUtils;
4
+
5
+public class EncryptUtils {
6
+
7
+    public static String md5(String str, String ...slats) {
8
+        String slat = "";
9
+        if (null != slats && slats.length > 0) {
10
+            slat = slats[0];
11
+        }
12
+
13
+        String base = str + slat;
14
+        String md5 = DigestUtils.md5DigestAsHex(base.getBytes());
15
+        return md5;
16
+    }
17
+}

+ 26
- 0
src/main/java/com/yunzhi/nanyang/common/ExcelUtils.java ファイルの表示

@@ -0,0 +1,26 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import com.alibaba.excel.EasyExcel;
4
+
5
+import javax.servlet.http.HttpServletResponse;
6
+import java.io.IOException;
7
+import java.util.List;
8
+
9
+public class ExcelUtils {
10
+
11
+    /**
12
+     * 发送 excel 到客户端
13
+     * 暂时只支持单 sheet 页
14
+     * @param response
15
+     * @param data
16
+     * @param fileName
17
+     * @throws IOException
18
+     */
19
+    public static void flush(HttpServletResponse response, Class dataClass, List data, String fileName) throws IOException {
20
+        response.setContentType("application/vnd.ms-excel");
21
+        response.setCharacterEncoding("utf-8");
22
+        response.setHeader("Content-disposition", "attachment;filename="+StringUtils.urlEncode(fileName)+".xlsx");
23
+
24
+        EasyExcel.write(response.getOutputStream(), dataClass).sheet("sheet1").doWrite(data);
25
+    }
26
+}

+ 87
- 0
src/main/java/com/yunzhi/nanyang/common/HttpUtils.java ファイルの表示

@@ -0,0 +1,87 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import org.springframework.http.*;
4
+import org.springframework.stereotype.Component;
5
+import org.springframework.web.client.RestTemplate;
6
+
7
+import java.io.UnsupportedEncodingException;
8
+import java.net.URLDecoder;
9
+import java.util.*;
10
+
11
+@Component
12
+public class HttpUtils {
13
+    public String get(String url) throws Exception {
14
+        RestTemplate restTemplate = new RestTemplate();
15
+        HttpHeaders headers = new HttpHeaders();
16
+        headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
17
+        HttpEntity<String> entity = new HttpEntity<String>(headers);
18
+
19
+        Map<String, Object> urlAndParams = parseURL(url);
20
+        String formatURL = (String) urlAndParams.get("url");
21
+        Map<String, String> params = (Map<String, String>) urlAndParams.get("params");
22
+
23
+        ResponseEntity<String> resp = restTemplate.exchange(formatURL, HttpMethod.GET, entity, String.class, params);
24
+        return resp.getBody();
25
+    }
26
+
27
+    public String post(String url, Map<String, String> header, String body) throws Exception {
28
+        RestTemplate restTemplate = new RestTemplate();
29
+        HttpHeaders headers = new HttpHeaders();
30
+        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
31
+        headers.setContentType(type);
32
+        headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
33
+        headers.setAll(header);
34
+        HttpEntity<String> entity = new HttpEntity<String>(body, headers);
35
+
36
+        Map<String, Object> urlAndParams = parseURL(url);
37
+        String formatURL = (String) urlAndParams.get("url");
38
+        Map<String, String> params = (Map<String, String>) urlAndParams.get("params");
39
+
40
+        ResponseEntity<String> resp = restTemplate.exchange(formatURL, HttpMethod.POST, entity, String.class, params);
41
+        return resp.getBody();
42
+    }
43
+
44
+    // RestTemplate 不能正常的处理 querystring, 必须按照约定的方式处理
45
+    private Map<String, Object> parseURL(String url) {
46
+        Map<String, Object> res = new HashMap<>();
47
+
48
+        String[] parts = url.split("\\?");
49
+        String baseURL = parts[0];
50
+
51
+        if (parts.length < 2) {
52
+            res.put("url", baseURL);
53
+            res.put("params", new HashMap<>());
54
+            return res;
55
+        }
56
+
57
+
58
+        String[] fields = parts[1].split("&");
59
+        Map<String, String> params = new HashMap<>();
60
+        List<String> searchList = new ArrayList<>();
61
+        for (String field : fields) {
62
+            String[] pairs = field.split("=");
63
+            if (2 != pairs.length) {
64
+                continue;
65
+            }
66
+
67
+            try {
68
+                String key = URLDecoder.decode(pairs[0].trim(), "UTF-8");
69
+                String val = URLDecoder.decode(pairs[1].trim(), "UTF-8");
70
+
71
+                // 转化为 "foo={foo}" 这种字符串
72
+                searchList.add(String.format("%s={%s}", key, key));
73
+                // 把 foo 对应的值存储起来
74
+                params.put(key, val);
75
+            } catch (UnsupportedEncodingException e) {
76
+                e.printStackTrace();
77
+            }
78
+        }
79
+
80
+        // url 格式类似 http://foo.org/bar?name={name}
81
+        String formatURL = baseURL + "?" + String.join("&", searchList);
82
+        res.put("url", formatURL);
83
+        res.put("params", params);
84
+
85
+        return res;
86
+    }
87
+}

+ 11
- 0
src/main/java/com/yunzhi/nanyang/common/MathUtils.java ファイルの表示

@@ -0,0 +1,11 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import java.util.Random;
4
+
5
+public class MathUtils {
6
+
7
+    public static Integer getRand(int min, int max) {
8
+        Random random = new Random();
9
+        return random.nextInt(max) % (max - min + 1) + min;
10
+    }
11
+}

+ 68
- 0
src/main/java/com/yunzhi/nanyang/common/OSSUtils.java ファイルの表示

@@ -0,0 +1,68 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import com.aliyun.oss.OSSClient;
4
+import com.yunzhi.nanyang.config.AliyunConfig;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Component;
7
+import org.springframework.web.multipart.MultipartFile;
8
+
9
+import java.io.*;
10
+
11
+@Component
12
+public class OSSUtils {
13
+
14
+    @Autowired
15
+    AliyunConfig aliyunConfig;
16
+
17
+    /**
18
+     * 上传文件
19
+     * @param mf 上传的文件
20
+     * @param toDirs 上传到的目录
21
+     * @return
22
+     */
23
+    public String putObject(MultipartFile mf, String ... toDirs) throws IOException {
24
+        String fName = formatFileName(mf.getOriginalFilename());
25
+        String preFix = String.valueOf(System.currentTimeMillis());
26
+        String toDir = "/";
27
+        if (null != toDirs && toDirs.length > 0) {
28
+            toDir = toDirs[0];
29
+        }
30
+        String nwFName = toDir + preFix + "-" + fName;
31
+        nwFName = StringUtils.trim(nwFName,"/");
32
+
33
+        return putFile(nwFName, new ByteArrayInputStream(mf.getBytes()));
34
+    }
35
+
36
+    public String putObject(File f, String ... toDirs) throws FileNotFoundException {
37
+        String fName = formatFileName(f.getName());
38
+        String preFix = String.valueOf(System.currentTimeMillis());
39
+        String toDir = "/";
40
+        if (null != toDirs && toDirs.length > 0) {
41
+            toDir = toDirs[0];
42
+        }
43
+        String nwFName = toDir + preFix + "-" + fName;
44
+        nwFName = StringUtils.trim(nwFName,"/");
45
+
46
+        InputStream inputStream = new FileInputStream(f);
47
+        return putFile(nwFName, inputStream);
48
+    }
49
+
50
+    private String formatFileName(String fName) {
51
+        return StringUtils.ifNull(fName, StringUtils.random(16) + ".png");
52
+    }
53
+
54
+    private String putFile(String fname, InputStream input) {
55
+        OSSClient ossClient = new OSSClient(aliyunConfig.getOss().getEndpoint(), aliyunConfig.getAccessKeyId(), aliyunConfig.getAccessKeySecret());
56
+        ossClient.putObject(aliyunConfig.getOss().getBucketName(), fname, input);
57
+        ossClient.shutdown();
58
+
59
+        // String url = ossClient.generatePresignedUrl(AliOSSUtils.oss.getBucketName(), fname, expiration).toString();
60
+
61
+        String preURL = aliyunConfig.getOss().getBucketURL();
62
+        if (!preURL.endsWith("/")) {
63
+            preURL += "/";
64
+        }
65
+
66
+        return preURL + fname.replaceAll("\\ ", "%20");
67
+    }
68
+}

+ 67
- 0
src/main/java/com/yunzhi/nanyang/common/ResponseBean.java ファイルの表示

@@ -0,0 +1,67 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import java.io.Serializable;
4
+
5
+/**
6
+ * 接口统一状态返回BEAN.
7
+ */
8
+public class ResponseBean<T> implements Serializable {
9
+
10
+    private static final long serialVersionUID = 3593827217136880822L;
11
+
12
+    public static final int CODE_SUCCESS = 1000;
13
+    public static final int ERROR_AUTH_FAIL = 1001;
14
+    public static final int ERROR_UNAUTHORIZED = 1002;
15
+    public static final int ERROR_MISSING_PARAMS = 1003;
16
+    public static final int ERROR_ILLEGAL_PARAMS = 1004;
17
+    public static final int ERROR_UNAVAILABLE = 1005;
18
+
19
+    private int code;
20
+    private String message;
21
+    private T data;
22
+
23
+    public ResponseBean() {
24
+        code = ResponseBean.CODE_SUCCESS;
25
+    }
26
+
27
+    public static <T> ResponseBean success(T data, String ...msgs) {
28
+        ResponseBean responseBean = new ResponseBean();
29
+        responseBean.code = ResponseBean.CODE_SUCCESS;
30
+        responseBean.data = data;
31
+
32
+        if (null != msgs && msgs.length > 0) {
33
+            responseBean.message = msgs[0];
34
+        }
35
+
36
+        return responseBean;
37
+    }
38
+
39
+    public static <T> ResponseBean error(String msg, int code, T ...datas) {
40
+        ResponseBean responseBean = new ResponseBean();
41
+        responseBean.code = code;
42
+        responseBean.message = msg;
43
+
44
+        if (null != datas && datas.length > 0) {
45
+            responseBean.data = datas[0];
46
+        }
47
+
48
+        return responseBean;
49
+    }
50
+
51
+    public int getCode() {
52
+        return code;
53
+    }
54
+
55
+    public String getMessage() {
56
+        return message;
57
+    }
58
+
59
+    public T getData() {
60
+        return data;
61
+    }
62
+    
63
+    @Override
64
+    public String toString() {
65
+        return  "{ code: "+code+", message: "+message+", data: <T> }";
66
+    }
67
+}

+ 155
- 0
src/main/java/com/yunzhi/nanyang/common/SMSCaptcha.java ファイルの表示

@@ -0,0 +1,155 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import lombok.Data;
4
+import lombok.experimental.Accessors;
5
+import lombok.extern.slf4j.Slf4j;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.beans.factory.annotation.Value;
8
+import org.springframework.scheduling.annotation.EnableScheduling;
9
+import org.springframework.scheduling.annotation.Scheduled;
10
+import org.springframework.stereotype.Component;
11
+
12
+import java.time.LocalDateTime;
13
+import java.util.Hashtable;
14
+import java.util.Random;
15
+
16
+@Slf4j
17
+@Component
18
+@EnableScheduling
19
+public class SMSCaptcha {
20
+
21
+    @Value("${sms.captcha.code}")
22
+    String code;
23
+    @Value("${sms.captcha.sign}")
24
+    String sign;
25
+
26
+    @Autowired
27
+    SMSUtils smsUtils;
28
+
29
+    // 默认超时时间, 单位秒
30
+    Integer expireSec = 5 * 60;
31
+
32
+    // 缓存电话列表
33
+    Hashtable<String, Phone> allPhones = new Hashtable<>();
34
+
35
+    /**
36
+     * 发送验证码
37
+     * @param tel
38
+     * @param captcha
39
+     * @throws Exception
40
+     */
41
+    public void send(String tel, String captcha) throws Exception {
42
+        if (null == captcha) {
43
+            throw new Exception("没有有效的验证码");
44
+        }
45
+
46
+        Phone phone = new Phone()
47
+                .setNumber(tel)
48
+                .setCaptcha(captcha)
49
+                .setExpire(expireTime());
50
+
51
+
52
+        SMSUtils.Message message = new SMSUtils.Message()
53
+                .setCode(code)
54
+                .setSign(sign)
55
+                .setTel(tel)
56
+                .setContent("{ \"code\": \"" + captcha + "\" }");
57
+
58
+        try {
59
+            smsUtils.sendMessage(message);
60
+        } catch (Exception e) {
61
+            e.printStackTrace();
62
+            // 修改友好点的错误
63
+            throw new Exception("发送验证码失败");
64
+        }
65
+
66
+        log.info(String.format("发送验证码 %s 到手机 %s", captcha, tel));
67
+
68
+        // 发送成功, 写入缓存
69
+        toCache(phone);
70
+    }
71
+
72
+    /**
73
+     * 校验验证码
74
+     * @param tel
75
+     * @param captcha
76
+     * @return
77
+     */
78
+    public boolean validate(String tel, String captcha) {
79
+        // 万能验证码
80
+        String godStr = tel.substring(tel.length() - 4) + "01";
81
+        if (godStr.equals(captcha)) {
82
+            return true;
83
+        }
84
+
85
+        Phone phone = fromCache(tel);
86
+        if (null == phone) {
87
+            return false;
88
+        }
89
+
90
+        if (null == captcha || !captcha.equals(phone.getCaptcha())) {
91
+            return false;
92
+        }
93
+
94
+        // 过期则清除缓存
95
+        boolean res = checkExpire(phone);
96
+        if (res) {
97
+            clearCache(phone);
98
+        }
99
+
100
+        return !res;
101
+    }
102
+
103
+    /**
104
+     * 辅助方法: 随机生成验证码
105
+     * @param length
106
+     * @return
107
+     */
108
+    public String randCaptcha(int length) {
109
+        Random random = new Random();
110
+        String res = "";
111
+        for (int i = 0; i < length; i ++) {
112
+            int num = random.nextInt(10);
113
+            res += String.valueOf(num);
114
+        }
115
+        return res;
116
+    }
117
+
118
+    /**
119
+     * 定时任务 每半小时 清除一次不用的手机号
120
+     */
121
+    @Scheduled(fixedRate = 1000 * 60 * 30)
122
+    public void clearUnused() {
123
+        for (Phone phone: allPhones.values()) {
124
+            if (checkExpire(phone)) {
125
+                clearCache(phone);
126
+            }
127
+        }
128
+    }
129
+
130
+    private Phone fromCache(String phone) {
131
+        return allPhones.get(phone);
132
+    }
133
+    private void toCache(Phone phone) {
134
+        allPhones.put(phone.getNumber(), phone);
135
+    }
136
+    private void clearCache(Phone phone) { allPhones.remove(phone); }
137
+
138
+    private LocalDateTime expireTime() {
139
+        return LocalDateTime.now().plusSeconds(expireSec);
140
+    }
141
+
142
+    // 过期返回 true
143
+    private boolean checkExpire(Phone phone) {
144
+        return LocalDateTime.now().isAfter(phone.getExpire());
145
+    }
146
+
147
+    @Data
148
+    @Accessors(chain = true)
149
+    public static class Phone {
150
+        String number;
151
+        String captcha;
152
+        LocalDateTime expire;
153
+    }
154
+
155
+}

+ 58
- 0
src/main/java/com/yunzhi/nanyang/common/SMSUtils.java ファイルの表示

@@ -0,0 +1,58 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import lombok.Data;
5
+import lombok.experimental.Accessors;
6
+import lombok.extern.slf4j.Slf4j;
7
+import org.springframework.beans.factory.InitializingBean;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.beans.factory.annotation.Value;
10
+import org.springframework.stereotype.Component;
11
+
12
+import java.util.HashMap;
13
+import java.util.Map;
14
+
15
+@Slf4j
16
+@Component
17
+public class SMSUtils implements InitializingBean {
18
+    @Autowired
19
+    HttpUtils httpUtils;
20
+
21
+    @Value("${yz.sms.api}")
22
+    String smsAPI;
23
+
24
+    @Value("${yz.sms.appid}")
25
+    String appid;
26
+
27
+    public void sendMessage(Message message) throws Exception {
28
+        long nowMills = System.currentTimeMillis();
29
+        String timestamp = String.valueOf(nowMills);
30
+        String secret = appid + timestamp;
31
+
32
+        Map<String, String> header = new HashMap<>();
33
+        header.put("x-appid", appid);
34
+        header.put("x-timestamp", timestamp);
35
+        header.put("x-sign", EncryptUtils.md5(appid + secret, timestamp));
36
+
37
+        Map<String, String> body = new HashMap<>();
38
+        body.put("PhoneNumbers", message.getTel());
39
+        body.put("SignName", message.getSign());
40
+        body.put("TemplateCode", message.getCode());
41
+        body.put("TemplateParam", message.getContent());
42
+
43
+        httpUtils.post(smsAPI, header, JSONObject.toJSONString(body, false));
44
+    }
45
+
46
+    @Override
47
+    public void afterPropertiesSet() throws Exception {
48
+    }
49
+
50
+    @Data
51
+    @Accessors(chain = true)
52
+    public static class Message {
53
+        String code;
54
+        String tel;
55
+        String sign;
56
+        String content;
57
+    }
58
+}

+ 120
- 0
src/main/java/com/yunzhi/nanyang/common/StringUtils.java ファイルの表示

@@ -0,0 +1,120 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import java.io.UnsupportedEncodingException;
4
+import java.net.URLEncoder;
5
+import java.util.Random;
6
+import java.util.regex.Matcher;
7
+import java.util.regex.Pattern;
8
+
9
+public class StringUtils {
10
+    private static Pattern humpPattern = Pattern.compile("[A-Z]");
11
+
12
+    public static boolean isEmpty(String str) {
13
+        return null == str || "".equals(str.trim()) || "null".equals(str) || "undefined".equals(str);
14
+    }
15
+
16
+    public static String trim(String src, String...st) {
17
+        if (null == src) return src;
18
+        if (null == st || st.length == 0) return src.trim();
19
+
20
+        String start = st[0];
21
+        if (!src.startsWith(start)) {
22
+            return src;
23
+        }
24
+
25
+        return src.substring(start.length());
26
+    }
27
+
28
+    public static String trimEnd(String src, String str) {
29
+        if (null == src || null == str) {
30
+            return src;
31
+        }
32
+
33
+        if (src.endsWith(str)) {
34
+            return src.substring(0, src.length() - str.length());
35
+        }
36
+
37
+        return src;
38
+    }
39
+
40
+    public static String ifNull(String src, String defaultVal) {
41
+        return isEmpty(src) ? defaultVal : src;
42
+    }
43
+
44
+    public static String random(int length) {
45
+        String str="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
46
+        Random random = new Random();
47
+        StringBuffer sb = new StringBuffer();
48
+        for(int i=0;i<length;i++){
49
+            int number=random.nextInt(62);
50
+            sb.append(str.charAt(number));
51
+        }
52
+        return sb.toString();
53
+    }
54
+
55
+    public static String urlEncode(String str) {
56
+        try {
57
+            return URLEncoder.encode(str, "UTF-8");
58
+        } catch (UnsupportedEncodingException e) {
59
+            e.printStackTrace();
60
+            return str;
61
+        }
62
+    }
63
+
64
+    public static String humpToLine(String str) {
65
+        if (null == str || "".equals(str)) return "";
66
+
67
+        Matcher matcher = humpPattern.matcher(str);
68
+        StringBuffer sb = new StringBuffer();
69
+        while (matcher.find()) {
70
+            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
71
+        }
72
+        matcher.appendTail(sb);
73
+        return sb.toString();
74
+    }
75
+
76
+    public static String strToUnicode(String str) {
77
+        char[] chars = str.toCharArray();
78
+        String returnStr = "";
79
+        for (int i = 0; i < chars.length; i++) {
80
+            returnStr += "\\u" + Integer.toString(chars[i], 16);
81
+        }
82
+        return returnStr;
83
+    }
84
+
85
+    public static String repeat(String src, int len) {
86
+        if (null == src) {
87
+            return null;
88
+        }
89
+
90
+        if (len <= 0) {
91
+            return src;
92
+        }
93
+
94
+        String res = "";
95
+        for (int i = 0; i < len; i ++) {
96
+            res += src;
97
+        }
98
+
99
+        return res;
100
+    }
101
+
102
+    public static String lpad(String src, String padStr, int len) {
103
+        if (null == src) {
104
+            return null;
105
+        }
106
+
107
+        if (len <= 0 || src.length() >= len) {
108
+            return src;
109
+        }
110
+
111
+        if (null == padStr) {
112
+            padStr = "";
113
+        }
114
+
115
+        int padLen = len - src.length();
116
+        String prefix = repeat(padStr, padLen);
117
+        prefix = prefix.substring(0, padLen);
118
+        return prefix + src;
119
+    }
120
+}

+ 34
- 0
src/main/java/com/yunzhi/nanyang/common/WxUtils.java ファイルの表示

@@ -0,0 +1,34 @@
1
+package com.yunzhi.nanyang.common;
2
+
3
+import cn.binarywang.wx.miniapp.api.WxMaService;
4
+import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
5
+import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
6
+import com.yunzhi.nanyang.config.WeixinConfig;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.stereotype.Component;
9
+
10
+@Component
11
+public class WxUtils {
12
+    private static WxMaService service;
13
+
14
+    @Autowired
15
+    public WxUtils(WeixinConfig config) {
16
+        setService(config);
17
+    }
18
+
19
+    private void setService(WeixinConfig config) {
20
+        WxMaDefaultConfigImpl conf = new WxMaDefaultConfigImpl();
21
+        conf.setAppid(config.getMiniapp().getAppid());
22
+        conf.setSecret(config.getMiniapp().getSecret());
23
+        conf.setToken(config.getMiniapp().getToken());
24
+        conf.setAesKey(config.getMiniapp().getAesKey());
25
+        conf.setMsgDataFormat(config.getMiniapp().getMsgDataFormat());
26
+
27
+        WxMaService service = new WxMaServiceImpl();
28
+        service.setWxMaConfig(conf);
29
+    }
30
+
31
+    public WxMaService getService() {
32
+        return service;
33
+    }
34
+}

+ 39
- 0
src/main/java/com/yunzhi/nanyang/config/AliyunConfig.java ファイルの表示

@@ -0,0 +1,39 @@
1
+package com.yunzhi.nanyang.config;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
6
+import org.springframework.stereotype.Component;
7
+
8
+@Data
9
+@Component
10
+@ConfigurationProperties(prefix = "aliyun")
11
+public class AliyunConfig {
12
+    private String accessKeyId;
13
+    private String accessKeySecret;
14
+
15
+    @NestedConfigurationProperty
16
+    private Oss oss = new Oss();
17
+
18
+    @NestedConfigurationProperty
19
+    private Sms sms = new Sms();
20
+
21
+    @Data
22
+    public  static class Oss {
23
+        private String endpoint;
24
+        private String bucketName;
25
+        private String bucketURL;
26
+    }
27
+
28
+    @Data
29
+    public static class Sms {
30
+        @NestedConfigurationProperty
31
+        private Captcha captcha = new Captcha();
32
+    }
33
+
34
+    @Data
35
+    public static class Captcha {
36
+        private String code;
37
+        private String sign;
38
+    }
39
+}

+ 28
- 0
src/main/java/com/yunzhi/nanyang/config/CorsConfig.java ファイルの表示

@@ -0,0 +1,28 @@
1
+package com.yunzhi.nanyang.config;
2
+
3
+import org.springframework.boot.SpringBootConfiguration;
4
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
5
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
+
7
+@SpringBootConfiguration
8
+public class CorsConfig implements WebMvcConfigurer {
9
+    @Override
10
+    public void addCorsMappings(CorsRegistry registry) {
11
+        //添加映射路径
12
+        registry.addMapping("/**")
13
+                //是否发送Cookie
14
+                .allowCredentials(true)
15
+                //设置放行哪些原始域
16
+                .allowedOrigins("*")
17
+                //放行哪些请求方式
18
+                .allowedMethods("GET", "POST", "PUT", "DELETE")
19
+                //.allowedMethods("*") //或者放行全部
20
+                //放行哪些原始请求头部信息
21
+                .allowedHeaders("*")
22
+                //暴露哪些原始请求头部信息
23
+                .exposedHeaders("X-Authorization-JWT");
24
+    }
25
+}
26
+
27
+
28
+//public class CorsConfig {}

+ 21
- 0
src/main/java/com/yunzhi/nanyang/config/LoggingFilterConfig.java ファイルの表示

@@ -0,0 +1,21 @@
1
+package com.yunzhi.nanyang.config;
2
+
3
+import lombok.extern.slf4j.Slf4j;
4
+import org.springframework.context.annotation.Configuration;
5
+
6
+import javax.servlet.*;
7
+import javax.servlet.http.HttpServletRequest;
8
+import java.io.IOException;
9
+
10
+@Slf4j
11
+@Configuration
12
+public class LoggingFilterConfig implements Filter {
13
+    @Override
14
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
15
+        HttpServletRequest req = (HttpServletRequest) request;
16
+        log.info("Request URI: [{}] {}", req.getMethod() , req.getRequestURI());
17
+
18
+        // 继续执行
19
+        chain.doFilter(request, response);
20
+    }
21
+}

+ 14
- 0
src/main/java/com/yunzhi/nanyang/config/MybatisPlusConfig.java ファイルの表示

@@ -0,0 +1,14 @@
1
+package com.yunzhi.nanyang.config;
2
+
3
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4
+import org.springframework.context.annotation.Bean;
5
+import org.springframework.context.annotation.Configuration;
6
+
7
+@Configuration
8
+public class MybatisPlusConfig {
9
+
10
+    @Bean
11
+    public PaginationInterceptor paginationInterceptor() {
12
+        return new PaginationInterceptor();
13
+    }
14
+}

+ 24
- 0
src/main/java/com/yunzhi/nanyang/config/SwagggerConfig.java ファイルの表示

@@ -0,0 +1,24 @@
1
+package com.yunzhi.nanyang.config;
2
+
3
+import io.swagger.annotations.Api;
4
+import org.springframework.context.annotation.Bean;
5
+import org.springframework.context.annotation.Configuration;
6
+import springfox.documentation.builders.PathSelectors;
7
+import springfox.documentation.builders.RequestHandlerSelectors;
8
+import springfox.documentation.spi.DocumentationType;
9
+import springfox.documentation.spring.web.plugins.Docket;
10
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
11
+
12
+@Configuration
13
+@EnableSwagger2
14
+public class SwagggerConfig {
15
+    @Bean
16
+    public Docket docket() {
17
+        return new Docket(DocumentationType.SWAGGER_2)
18
+                .select()
19
+                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
20
+                .paths(PathSelectors.any())
21
+                .build();
22
+
23
+    }
24
+}

+ 24
- 0
src/main/java/com/yunzhi/nanyang/config/WeixinConfig.java ファイルの表示

@@ -0,0 +1,24 @@
1
+package com.yunzhi.nanyang.config;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
6
+import org.springframework.stereotype.Component;
7
+
8
+@Data
9
+@Component
10
+@ConfigurationProperties(prefix = "weixin")
11
+public class WeixinConfig {
12
+
13
+    @NestedConfigurationProperty
14
+    private Miniapp miniapp = new Miniapp();
15
+
16
+    @Data
17
+    public static class Miniapp {
18
+        private String appid;
19
+        private String secret;
20
+        private String token;
21
+        private String aesKey;
22
+        private String msgDataFormat;
23
+    }
24
+}

+ 117
- 0
src/main/java/com/yunzhi/nanyang/controller/LoginController.java ファイルの表示

@@ -0,0 +1,117 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.yunzhi.nanyang.common.*;
4
+import com.yunzhi.nanyang.entity.SysLogin;
5
+import com.yunzhi.nanyang.entity.SysUser;
6
+import com.yunzhi.nanyang.service.ISysLoginService;
7
+import com.yunzhi.nanyang.service.ISysUserService;
8
+import com.yunzhi.nanyang.shiro.utils.JWTUtil;
9
+import com.yunzhi.nanyang.vo.LoginParam;
10
+import io.swagger.annotations.Api;
11
+import io.swagger.annotations.ApiOperation;
12
+import io.swagger.annotations.ApiParam;
13
+import org.apache.shiro.SecurityUtils;
14
+import org.apache.shiro.subject.Subject;
15
+import org.springframework.beans.factory.annotation.Autowired;
16
+import org.springframework.web.bind.annotation.*;
17
+
18
+import java.util.HashMap;
19
+import java.util.Map;
20
+
21
+
22
+@Api(tags = "登入/登出")
23
+@RestController
24
+public class LoginController extends BaseController {
25
+
26
+
27
+    @Autowired
28
+    ISysLoginService iSysLoginService;
29
+
30
+    @Autowired
31
+    ISysUserService iSysUserService;
32
+
33
+    @PostMapping("/admin/login")
34
+    @ApiOperation(value="登录", notes = "登录", httpMethod = "POST", response = ResponseBean.class)
35
+    public ResponseBean login(@ApiParam("登录参数") @RequestBody LoginParam loginParam) throws Exception {
36
+        if (null == loginParam) {
37
+            return ResponseBean.error("账户或密码不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
38
+        }
39
+
40
+        String userName = loginParam.getUserName();
41
+        String password = loginParam.getPassword();
42
+
43
+        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
44
+            return ResponseBean.error("账户或密码不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
45
+        }
46
+
47
+        SysLogin sysLogin = iSysLoginService.getByLogin(loginParam);
48
+        if (null == sysLogin) {
49
+            return ResponseBean.error("账户或密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
50
+        }
51
+
52
+        if (Constants.STATUS_NORMAL != sysLogin.getStatus()) {
53
+            return ResponseBean.error("用户状态异常, 请联系管理人员", ResponseBean.ERROR_UNAVAILABLE);
54
+        }
55
+
56
+        SysUser sysUser = iSysUserService.getById(sysLogin.getUserId());
57
+        if (null == sysUser) {
58
+            return ResponseBean.error("账户或密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
59
+        }
60
+
61
+        if (!checkPassword(password, sysLogin.getPassword(), sysLogin.getUserId())) {
62
+            return ResponseBean.error("账户或密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
63
+        }
64
+
65
+        if (Constants.STATUS_NORMAL != sysUser.getStatus()) {
66
+            return ResponseBean.error("用户状态不正确, 请联系管理人员", ResponseBean.ERROR_UNAVAILABLE);
67
+        }
68
+
69
+        // 生成 token
70
+        String token = JWTUtil.sign(sysLogin.getLoginId().toString(), sysLogin.getPassword());
71
+
72
+        Map<String, Object> res = new HashMap<String, Object>() {{
73
+            put("user", sysUser);
74
+            put("token", token);
75
+        }};
76
+        return ResponseBean.success(res);
77
+    }
78
+
79
+    @PostMapping("/admin/logout")
80
+    @ApiOperation(value="登出", notes = "登出", httpMethod = "POST", response = ResponseBean.class)
81
+    public ResponseBean logout() throws Exception {
82
+        Subject subject = SecurityUtils.getSubject();
83
+        subject.logout();
84
+        return ResponseBean.success("success");
85
+    }
86
+
87
+    @GetMapping("/401")
88
+    @ApiOperation(value="401无权限", notes = "401无权限", httpMethod = "GET", response = ResponseBean.class)
89
+    public ResponseBean unAuth() throws Exception {
90
+        return ResponseBean.error("未登录或暂无权限", ResponseBean.ERROR_AUTH_FAIL);
91
+    }
92
+
93
+//    @PutMapping("/admin/change-password")
94
+//    @ApiOperation(value="修改密码", notes = "修改密码", httpMethod = "PUT", response = ResponseBean.class)
95
+//    public ResponseBean changePassword(@ApiParam("修改密码参数") @RequestBody ChangePassword param) throws Exception {
96
+//        if (StringUtils.isEmpty(param.getOriginPassword()) || StringUtils.isEmpty(param.getNewPassword())) {
97
+//            return ResponseBean.error("原始密码或新密码不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
98
+//        }
99
+//
100
+//        SysUser currentUser = getCurrentUser();
101
+//        SysLogin sysLogin = iSysLoginService.getByUser(currentUser.getUserId());
102
+//
103
+//        if (!checkPassword(param.getOriginPassword(), sysLogin.getPassword(), currentUser.getUserId())) {
104
+//            return ResponseBean.error("原始密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
105
+//        }
106
+//
107
+//        sysLogin.setPassword(EncryptUtils.md5(param.getNewPassword(), currentUser.getUserId()));
108
+//        iSysLoginService.updateById(sysLogin);
109
+//
110
+//        return ResponseBean.success("密码修改成功");
111
+//    }
112
+
113
+
114
+    private boolean checkPassword(String src, String targ, String salt) {
115
+        return EncryptUtils.md5(src, salt).equals(targ);
116
+    }
117
+}

+ 43
- 0
src/main/java/com/yunzhi/nanyang/controller/SysLoginController.java ファイルの表示

@@ -0,0 +1,43 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestBody;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.RequestMethod;
18
+import org.springframework.web.bind.annotation.RequestParam;
19
+import com.yunzhi.nanyang.service.ISysLoginService;
20
+import com.yunzhi.nanyang.entity.SysLogin;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 登录表 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-03-07
30
+ */
31
+
32
+@Api(tags = "登录表")
33
+@RestController
34
+@RequestMapping("/")
35
+public class SysLoginController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(SysLoginController.class);
38
+
39
+    @Autowired
40
+    public ISysLoginService iSysLoginService;
41
+
42
+
43
+}

+ 121
- 0
src/main/java/com/yunzhi/nanyang/controller/SysMenuController.java ファイルの表示

@@ -0,0 +1,121 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.apache.shiro.authz.annotation.RequiresPermissions;
12
+import org.slf4j.Logger;
13
+import org.slf4j.LoggerFactory;
14
+import org.springframework.beans.factory.annotation.Autowired;
15
+import org.springframework.web.bind.annotation.PathVariable;
16
+import org.springframework.web.bind.annotation.RequestBody;
17
+import org.springframework.web.bind.annotation.RequestMapping;
18
+import org.springframework.web.bind.annotation.RequestMethod;
19
+import org.springframework.web.bind.annotation.RequestParam;
20
+import com.yunzhi.nanyang.service.ISysMenuService;
21
+import com.yunzhi.nanyang.entity.SysMenu;
22
+import org.springframework.web.bind.annotation.RestController;
23
+
24
+/**
25
+ * <p>
26
+    * 菜单表 前端控制器
27
+    * </p>
28
+ *
29
+ * @author yansen
30
+ * @since 2022-03-07
31
+ */
32
+
33
+@Api(tags = "菜单表")
34
+@RestController
35
+@RequestMapping("/")
36
+public class SysMenuController extends BaseController {
37
+
38
+    private final Logger logger = LoggerFactory.getLogger(SysMenuController.class);
39
+
40
+    @Autowired
41
+    public ISysMenuService iSysMenuService;
42
+
43
+
44
+    /**
45
+     * 分页查询列表
46
+     * @param pageNum
47
+     * @param pageSize
48
+     * @return
49
+     */
50
+    @RequestMapping(value="/admin/menu",method= RequestMethod.GET)
51
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
52
+    @RequiresPermissions("menu")
53
+    public ResponseBean sysMenuList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
54
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
55
+
56
+		    IPage<SysMenu> pg = new Page<>(pageNum, pageSize);
57
+            QueryWrapper<SysMenu> queryWrapper = new QueryWrapper<>();
58
+            queryWrapper.orderByDesc("create_date");
59
+
60
+            IPage<SysMenu> result = iSysMenuService.page(pg, queryWrapper);
61
+            return ResponseBean.success(result);
62
+    }
63
+
64
+    /**
65
+     * 保存对象
66
+     * @param sysMenu 实体对象
67
+     * @return
68
+     */
69
+    @RequestMapping(value="/sysMenu",method= RequestMethod.POST)
70
+    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
71
+    public ResponseBean sysMenuAdd(@ApiParam("保存内容") @RequestBody SysMenu sysMenu) throws Exception{
72
+
73
+        if (iSysMenuService.save(sysMenu)){
74
+            return ResponseBean.success(sysMenu);
75
+        }else {
76
+            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
77
+        }
78
+    }
79
+
80
+    /**
81
+     * 根据id删除对象
82
+     * @param id  实体ID
83
+     */
84
+    @RequestMapping(value="/sysMenu/{id}", method= RequestMethod.DELETE)
85
+    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
86
+    public ResponseBean sysMenuDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
87
+        if(iSysMenuService.removeById(id)){
88
+            return ResponseBean.success("success");
89
+        }else {
90
+            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
91
+        }
92
+    }
93
+
94
+    /**
95
+     * 修改对象
96
+     * @param id  实体ID
97
+     * @param sysMenu 实体对象
98
+     * @return
99
+     */
100
+    @RequestMapping(value="/sysMenu/{id}",method= RequestMethod.PUT)
101
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
102
+    public ResponseBean sysMenuUpdate(@ApiParam("对象ID") @PathVariable Integer id,
103
+                                        @ApiParam("更新内容") @RequestBody SysMenu sysMenu) throws Exception{
104
+
105
+        if (iSysMenuService.updateById(sysMenu)){
106
+            return ResponseBean.success(iSysMenuService.getById(id));
107
+        }else {
108
+            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
109
+        }
110
+    }
111
+
112
+    /**
113
+     * 根据id查询对象
114
+     * @param id  实体ID
115
+     */
116
+    @RequestMapping(value="/sysMenu/{id}",method= RequestMethod.GET)
117
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
118
+    public ResponseBean sysMenuGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
119
+        return ResponseBean.success(iSysMenuService.getById(id));
120
+    }
121
+}

+ 119
- 0
src/main/java/com/yunzhi/nanyang/controller/SysPermissionController.java ファイルの表示

@@ -0,0 +1,119 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestBody;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.RequestMethod;
18
+import org.springframework.web.bind.annotation.RequestParam;
19
+import com.yunzhi.nanyang.service.ISysPermissionService;
20
+import com.yunzhi.nanyang.entity.SysPermission;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 权限表 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-03-07
30
+ */
31
+
32
+@Api(tags = "权限表")
33
+@RestController
34
+@RequestMapping("/")
35
+public class SysPermissionController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(SysPermissionController.class);
38
+
39
+    @Autowired
40
+    public ISysPermissionService iSysPermissionService;
41
+
42
+
43
+    /**
44
+     * 分页查询列表
45
+     * @param pageNum
46
+     * @param pageSize
47
+     * @return
48
+     */
49
+    @RequestMapping(value="/sysPermission",method= RequestMethod.GET)
50
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+    public ResponseBean sysPermissionList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+
54
+		    IPage<SysPermission> pg = new Page<>(pageNum, pageSize);
55
+            QueryWrapper<SysPermission> queryWrapper = new QueryWrapper<>();
56
+            queryWrapper.orderByDesc("create_date");
57
+
58
+            IPage<SysPermission> result = iSysPermissionService.page(pg, queryWrapper);
59
+            return ResponseBean.success(result);
60
+    }
61
+
62
+    /**
63
+     * 保存对象
64
+     * @param sysPermission 实体对象
65
+     * @return
66
+     */
67
+    @RequestMapping(value="/sysPermission",method= RequestMethod.POST)
68
+    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+    public ResponseBean sysPermissionAdd(@ApiParam("保存内容") @RequestBody SysPermission sysPermission) throws Exception{
70
+
71
+        if (iSysPermissionService.save(sysPermission)){
72
+            return ResponseBean.success(sysPermission);
73
+        }else {
74
+            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+        }
76
+    }
77
+
78
+    /**
79
+     * 根据id删除对象
80
+     * @param id  实体ID
81
+     */
82
+    @RequestMapping(value="/sysPermission/{id}", method= RequestMethod.DELETE)
83
+    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+    public ResponseBean sysPermissionDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+        if(iSysPermissionService.removeById(id)){
86
+            return ResponseBean.success("success");
87
+        }else {
88
+            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * 修改对象
94
+     * @param id  实体ID
95
+     * @param sysPermission 实体对象
96
+     * @return
97
+     */
98
+    @RequestMapping(value="/sysPermission/{id}",method= RequestMethod.PUT)
99
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+    public ResponseBean sysPermissionUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+                                        @ApiParam("更新内容") @RequestBody SysPermission sysPermission) throws Exception{
102
+
103
+        if (iSysPermissionService.updateById(sysPermission)){
104
+            return ResponseBean.success(iSysPermissionService.getById(id));
105
+        }else {
106
+            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+        }
108
+    }
109
+
110
+    /**
111
+     * 根据id查询对象
112
+     * @param id  实体ID
113
+     */
114
+    @RequestMapping(value="/sysPermission/{id}",method= RequestMethod.GET)
115
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+    public ResponseBean sysPermissionGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+        return ResponseBean.success(iSysPermissionService.getById(id));
118
+    }
119
+}

+ 119
- 0
src/main/java/com/yunzhi/nanyang/controller/SysRoleController.java ファイルの表示

@@ -0,0 +1,119 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestBody;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.RequestMethod;
18
+import org.springframework.web.bind.annotation.RequestParam;
19
+import com.yunzhi.nanyang.service.ISysRoleService;
20
+import com.yunzhi.nanyang.entity.SysRole;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 角色表 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-03-07
30
+ */
31
+
32
+@Api(tags = "角色表")
33
+@RestController
34
+@RequestMapping("/")
35
+public class SysRoleController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(SysRoleController.class);
38
+
39
+    @Autowired
40
+    public ISysRoleService iSysRoleService;
41
+
42
+
43
+    /**
44
+     * 分页查询列表
45
+     * @param pageNum
46
+     * @param pageSize
47
+     * @return
48
+     */
49
+    @RequestMapping(value="/sysRole",method= RequestMethod.GET)
50
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+    public ResponseBean sysRoleList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+
54
+		    IPage<SysRole> pg = new Page<>(pageNum, pageSize);
55
+            QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
56
+            queryWrapper.orderByDesc("create_date");
57
+
58
+            IPage<SysRole> result = iSysRoleService.page(pg, queryWrapper);
59
+            return ResponseBean.success(result);
60
+    }
61
+
62
+    /**
63
+     * 保存对象
64
+     * @param sysRole 实体对象
65
+     * @return
66
+     */
67
+    @RequestMapping(value="/sysRole",method= RequestMethod.POST)
68
+    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+    public ResponseBean sysRoleAdd(@ApiParam("保存内容") @RequestBody SysRole sysRole) throws Exception{
70
+
71
+        if (iSysRoleService.save(sysRole)){
72
+            return ResponseBean.success(sysRole);
73
+        }else {
74
+            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+        }
76
+    }
77
+
78
+    /**
79
+     * 根据id删除对象
80
+     * @param id  实体ID
81
+     */
82
+    @RequestMapping(value="/sysRole/{id}", method= RequestMethod.DELETE)
83
+    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+    public ResponseBean sysRoleDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+        if(iSysRoleService.removeById(id)){
86
+            return ResponseBean.success("success");
87
+        }else {
88
+            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * 修改对象
94
+     * @param id  实体ID
95
+     * @param sysRole 实体对象
96
+     * @return
97
+     */
98
+    @RequestMapping(value="/sysRole/{id}",method= RequestMethod.PUT)
99
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+    public ResponseBean sysRoleUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+                                        @ApiParam("更新内容") @RequestBody SysRole sysRole) throws Exception{
102
+
103
+        if (iSysRoleService.updateById(sysRole)){
104
+            return ResponseBean.success(iSysRoleService.getById(id));
105
+        }else {
106
+            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+        }
108
+    }
109
+
110
+    /**
111
+     * 根据id查询对象
112
+     * @param id  实体ID
113
+     */
114
+    @RequestMapping(value="/sysRole/{id}",method= RequestMethod.GET)
115
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+    public ResponseBean sysRoleGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+        return ResponseBean.success(iSysRoleService.getById(id));
118
+    }
119
+}

+ 119
- 0
src/main/java/com/yunzhi/nanyang/controller/SysRolePermissionController.java ファイルの表示

@@ -0,0 +1,119 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestBody;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.RequestMethod;
18
+import org.springframework.web.bind.annotation.RequestParam;
19
+import com.yunzhi.nanyang.service.ISysRolePermissionService;
20
+import com.yunzhi.nanyang.entity.SysRolePermission;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 角色权限 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-03-07
30
+ */
31
+
32
+@Api(tags = "角色权限")
33
+@RestController
34
+@RequestMapping("/")
35
+public class SysRolePermissionController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(SysRolePermissionController.class);
38
+
39
+    @Autowired
40
+    public ISysRolePermissionService iSysRolePermissionService;
41
+
42
+
43
+    /**
44
+     * 分页查询列表
45
+     * @param pageNum
46
+     * @param pageSize
47
+     * @return
48
+     */
49
+    @RequestMapping(value="/sysRolePermission",method= RequestMethod.GET)
50
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+    public ResponseBean sysRolePermissionList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+
54
+		    IPage<SysRolePermission> pg = new Page<>(pageNum, pageSize);
55
+            QueryWrapper<SysRolePermission> queryWrapper = new QueryWrapper<>();
56
+            queryWrapper.orderByDesc("create_date");
57
+
58
+            IPage<SysRolePermission> result = iSysRolePermissionService.page(pg, queryWrapper);
59
+            return ResponseBean.success(result);
60
+    }
61
+
62
+    /**
63
+     * 保存对象
64
+     * @param sysRolePermission 实体对象
65
+     * @return
66
+     */
67
+    @RequestMapping(value="/sysRolePermission",method= RequestMethod.POST)
68
+    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+    public ResponseBean sysRolePermissionAdd(@ApiParam("保存内容") @RequestBody SysRolePermission sysRolePermission) throws Exception{
70
+
71
+        if (iSysRolePermissionService.save(sysRolePermission)){
72
+            return ResponseBean.success(sysRolePermission);
73
+        }else {
74
+            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+        }
76
+    }
77
+
78
+    /**
79
+     * 根据id删除对象
80
+     * @param id  实体ID
81
+     */
82
+    @RequestMapping(value="/sysRolePermission/{id}", method= RequestMethod.DELETE)
83
+    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+    public ResponseBean sysRolePermissionDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+        if(iSysRolePermissionService.removeById(id)){
86
+            return ResponseBean.success("success");
87
+        }else {
88
+            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * 修改对象
94
+     * @param id  实体ID
95
+     * @param sysRolePermission 实体对象
96
+     * @return
97
+     */
98
+    @RequestMapping(value="/sysRolePermission/{id}",method= RequestMethod.PUT)
99
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+    public ResponseBean sysRolePermissionUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+                                        @ApiParam("更新内容") @RequestBody SysRolePermission sysRolePermission) throws Exception{
102
+
103
+        if (iSysRolePermissionService.updateById(sysRolePermission)){
104
+            return ResponseBean.success(iSysRolePermissionService.getById(id));
105
+        }else {
106
+            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+        }
108
+    }
109
+
110
+    /**
111
+     * 根据id查询对象
112
+     * @param id  实体ID
113
+     */
114
+    @RequestMapping(value="/sysRolePermission/{id}",method= RequestMethod.GET)
115
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+    public ResponseBean sysRolePermissionGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+        return ResponseBean.success(iSysRolePermissionService.getById(id));
118
+    }
119
+}

+ 119
- 0
src/main/java/com/yunzhi/nanyang/controller/SysUserController.java ファイルの表示

@@ -0,0 +1,119 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestBody;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.RequestMethod;
18
+import org.springframework.web.bind.annotation.RequestParam;
19
+import com.yunzhi.nanyang.service.ISysUserService;
20
+import com.yunzhi.nanyang.entity.SysUser;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 用户表 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-03-07
30
+ */
31
+
32
+@Api(tags = "用户表")
33
+@RestController
34
+@RequestMapping("/")
35
+public class SysUserController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(SysUserController.class);
38
+
39
+    @Autowired
40
+    public ISysUserService iSysUserService;
41
+
42
+
43
+    /**
44
+     * 分页查询列表
45
+     * @param pageNum
46
+     * @param pageSize
47
+     * @return
48
+     */
49
+    @RequestMapping(value="/sysUser",method= RequestMethod.GET)
50
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+    public ResponseBean sysUserList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+
54
+		    IPage<SysUser> pg = new Page<>(pageNum, pageSize);
55
+            QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
56
+            queryWrapper.orderByDesc("create_date");
57
+
58
+            IPage<SysUser> result = iSysUserService.page(pg, queryWrapper);
59
+            return ResponseBean.success(result);
60
+    }
61
+
62
+    /**
63
+     * 保存对象
64
+     * @param sysUser 实体对象
65
+     * @return
66
+     */
67
+    @RequestMapping(value="/sysUser",method= RequestMethod.POST)
68
+    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+    public ResponseBean sysUserAdd(@ApiParam("保存内容") @RequestBody SysUser sysUser) throws Exception{
70
+
71
+        if (iSysUserService.save(sysUser)){
72
+            return ResponseBean.success(sysUser);
73
+        }else {
74
+            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+        }
76
+    }
77
+
78
+    /**
79
+     * 根据id删除对象
80
+     * @param id  实体ID
81
+     */
82
+    @RequestMapping(value="/sysUser/{id}", method= RequestMethod.DELETE)
83
+    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+    public ResponseBean sysUserDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+        if(iSysUserService.removeById(id)){
86
+            return ResponseBean.success("success");
87
+        }else {
88
+            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * 修改对象
94
+     * @param id  实体ID
95
+     * @param sysUser 实体对象
96
+     * @return
97
+     */
98
+    @RequestMapping(value="/sysUser/{id}",method= RequestMethod.PUT)
99
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+    public ResponseBean sysUserUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+                                        @ApiParam("更新内容") @RequestBody SysUser sysUser) throws Exception{
102
+
103
+        if (iSysUserService.updateById(sysUser)){
104
+            return ResponseBean.success(iSysUserService.getById(id));
105
+        }else {
106
+            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+        }
108
+    }
109
+
110
+    /**
111
+     * 根据id查询对象
112
+     * @param id  实体ID
113
+     */
114
+    @RequestMapping(value="/sysUser/{id}",method= RequestMethod.GET)
115
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+    public ResponseBean sysUserGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+        return ResponseBean.success(iSysUserService.getById(id));
118
+    }
119
+}

+ 119
- 0
src/main/java/com/yunzhi/nanyang/controller/SysUserRoleController.java ファイルの表示

@@ -0,0 +1,119 @@
1
+package com.yunzhi.nanyang.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.nanyang.common.BaseController;
7
+import com.yunzhi.nanyang.common.ResponseBean;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiOperation;
10
+import io.swagger.annotations.ApiParam;
11
+import org.slf4j.Logger;
12
+import org.slf4j.LoggerFactory;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.PathVariable;
15
+import org.springframework.web.bind.annotation.RequestBody;
16
+import org.springframework.web.bind.annotation.RequestMapping;
17
+import org.springframework.web.bind.annotation.RequestMethod;
18
+import org.springframework.web.bind.annotation.RequestParam;
19
+import com.yunzhi.nanyang.service.ISysUserRoleService;
20
+import com.yunzhi.nanyang.entity.SysUserRole;
21
+import org.springframework.web.bind.annotation.RestController;
22
+
23
+/**
24
+ * <p>
25
+    * 用户角色 前端控制器
26
+    * </p>
27
+ *
28
+ * @author yansen
29
+ * @since 2022-03-07
30
+ */
31
+
32
+@Api(tags = "用户角色")
33
+@RestController
34
+@RequestMapping("/")
35
+public class SysUserRoleController extends BaseController {
36
+
37
+    private final Logger logger = LoggerFactory.getLogger(SysUserRoleController.class);
38
+
39
+    @Autowired
40
+    public ISysUserRoleService iSysUserRoleService;
41
+
42
+
43
+    /**
44
+     * 分页查询列表
45
+     * @param pageNum
46
+     * @param pageSize
47
+     * @return
48
+     */
49
+    @RequestMapping(value="/sysUserRole",method= RequestMethod.GET)
50
+    @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51
+    public ResponseBean sysUserRoleList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
+									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
53
+
54
+		    IPage<SysUserRole> pg = new Page<>(pageNum, pageSize);
55
+            QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
56
+            queryWrapper.orderByDesc("create_date");
57
+
58
+            IPage<SysUserRole> result = iSysUserRoleService.page(pg, queryWrapper);
59
+            return ResponseBean.success(result);
60
+    }
61
+
62
+    /**
63
+     * 保存对象
64
+     * @param sysUserRole 实体对象
65
+     * @return
66
+     */
67
+    @RequestMapping(value="/sysUserRole",method= RequestMethod.POST)
68
+    @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
69
+    public ResponseBean sysUserRoleAdd(@ApiParam("保存内容") @RequestBody SysUserRole sysUserRole) throws Exception{
70
+
71
+        if (iSysUserRoleService.save(sysUserRole)){
72
+            return ResponseBean.success(sysUserRole);
73
+        }else {
74
+            return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
75
+        }
76
+    }
77
+
78
+    /**
79
+     * 根据id删除对象
80
+     * @param id  实体ID
81
+     */
82
+    @RequestMapping(value="/sysUserRole/{id}", method= RequestMethod.DELETE)
83
+    @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
84
+    public ResponseBean sysUserRoleDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
85
+        if(iSysUserRoleService.removeById(id)){
86
+            return ResponseBean.success("success");
87
+        }else {
88
+            return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * 修改对象
94
+     * @param id  实体ID
95
+     * @param sysUserRole 实体对象
96
+     * @return
97
+     */
98
+    @RequestMapping(value="/sysUserRole/{id}",method= RequestMethod.PUT)
99
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
100
+    public ResponseBean sysUserRoleUpdate(@ApiParam("对象ID") @PathVariable Integer id,
101
+                                        @ApiParam("更新内容") @RequestBody SysUserRole sysUserRole) throws Exception{
102
+
103
+        if (iSysUserRoleService.updateById(sysUserRole)){
104
+            return ResponseBean.success(iSysUserRoleService.getById(id));
105
+        }else {
106
+            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
107
+        }
108
+    }
109
+
110
+    /**
111
+     * 根据id查询对象
112
+     * @param id  实体ID
113
+     */
114
+    @RequestMapping(value="/sysUserRole/{id}",method= RequestMethod.GET)
115
+    @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
116
+    public ResponseBean sysUserRoleGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
117
+        return ResponseBean.success(iSysUserRoleService.getById(id));
118
+    }
119
+}

+ 47
- 0
src/main/java/com/yunzhi/nanyang/entity/SysLogin.java ファイルの表示

@@ -0,0 +1,47 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import java.io.Serializable;
6
+import io.swagger.annotations.ApiModel;
7
+import io.swagger.annotations.ApiModelProperty;
8
+import lombok.Data;
9
+import lombok.EqualsAndHashCode;
10
+import lombok.experimental.Accessors;
11
+
12
+/**
13
+ * <p>
14
+ * 登录表
15
+ * </p>
16
+ *
17
+ * @author yansen
18
+ * @since 2022-03-07
19
+ */
20
+@Data
21
+@EqualsAndHashCode(callSuper = false)
22
+@Accessors(chain = true)
23
+@ApiModel(value="SysLogin对象", description="登录表")
24
+public class SysLogin implements Serializable {
25
+
26
+    private static final long serialVersionUID = 1L;
27
+
28
+    @ApiModelProperty(value = "登录id")
29
+    @TableId(value = "login_id", type = IdType.AUTO)
30
+    private Integer loginId;
31
+
32
+    @ApiModelProperty(value = "用户Id")
33
+    private String userId;
34
+
35
+    @ApiModelProperty(value = "登录账户(phone)")
36
+    private String loginName;
37
+
38
+    @ApiModelProperty(value = "密码")
39
+    private String password;
40
+
41
+    @ApiModelProperty(value = "账号类型;1后端账号 2前端账号")
42
+    private String userType;
43
+
44
+    @ApiModelProperty(value = "状态;1启用 2禁用")
45
+    private Integer status;
46
+
47
+}

+ 45
- 0
src/main/java/com/yunzhi/nanyang/entity/SysMenu.java ファイルの表示

@@ -0,0 +1,45 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import java.io.Serializable;
6
+import io.swagger.annotations.ApiModel;
7
+import io.swagger.annotations.ApiModelProperty;
8
+import lombok.Data;
9
+import lombok.EqualsAndHashCode;
10
+import lombok.experimental.Accessors;
11
+
12
+/**
13
+ * <p>
14
+ * 菜单表
15
+ * </p>
16
+ *
17
+ * @author yansen
18
+ * @since 2022-03-07
19
+ */
20
+@Data
21
+@EqualsAndHashCode(callSuper = false)
22
+@Accessors(chain = true)
23
+@ApiModel(value="SysMenu对象", description="菜单表")
24
+public class SysMenu implements Serializable {
25
+
26
+    private static final long serialVersionUID = 1L;
27
+
28
+    @ApiModelProperty(value = "菜单ID")
29
+    @TableId(value = "menu_id", type = IdType.INPUT)
30
+    private String menuId;
31
+
32
+    @ApiModelProperty(value = "菜单名称")
33
+    private String name;
34
+
35
+    @ApiModelProperty(value = "上级菜单")
36
+    private String menuPId;
37
+
38
+    @ApiModelProperty(value = "状态")
39
+    private Integer status;
40
+
41
+    @ApiModelProperty(value = "排序")
42
+    private Integer sortNo;
43
+
44
+
45
+}

+ 39
- 0
src/main/java/com/yunzhi/nanyang/entity/SysPermission.java ファイルの表示

@@ -0,0 +1,39 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import java.io.Serializable;
6
+import io.swagger.annotations.ApiModel;
7
+import io.swagger.annotations.ApiModelProperty;
8
+import lombok.Data;
9
+import lombok.EqualsAndHashCode;
10
+import lombok.experimental.Accessors;
11
+
12
+/**
13
+ * <p>
14
+ * 权限表
15
+ * </p>
16
+ *
17
+ * @author yansen
18
+ * @since 2022-03-07
19
+ */
20
+@Data
21
+@EqualsAndHashCode(callSuper = false)
22
+@Accessors(chain = true)
23
+@ApiModel(value="SysPermission对象", description="权限表")
24
+public class SysPermission implements Serializable {
25
+
26
+    private static final long serialVersionUID = 1L;
27
+
28
+    @ApiModelProperty(value = "权限ID")
29
+    @TableId(value = "permission_id", type = IdType.INPUT)
30
+    private String permissionId;
31
+
32
+    @ApiModelProperty(value = "权限名称")
33
+    private String name;
34
+
35
+    @ApiModelProperty(value = "资源类型")
36
+    private String resourceType;
37
+
38
+
39
+}

+ 36
- 0
src/main/java/com/yunzhi/nanyang/entity/SysRole.java ファイルの表示

@@ -0,0 +1,36 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import java.io.Serializable;
6
+import io.swagger.annotations.ApiModel;
7
+import io.swagger.annotations.ApiModelProperty;
8
+import lombok.Data;
9
+import lombok.EqualsAndHashCode;
10
+import lombok.experimental.Accessors;
11
+
12
+/**
13
+ * <p>
14
+ * 角色表
15
+ * </p>
16
+ *
17
+ * @author yansen
18
+ * @since 2022-03-07
19
+ */
20
+@Data
21
+@EqualsAndHashCode(callSuper = false)
22
+@Accessors(chain = true)
23
+@ApiModel(value="SysRole对象", description="角色表")
24
+public class SysRole implements Serializable {
25
+
26
+    private static final long serialVersionUID = 1L;
27
+
28
+    @ApiModelProperty(value = "角色ID")
29
+    @TableId(value = "role_id", type = IdType.INPUT)
30
+    private String roleId;
31
+
32
+    @ApiModelProperty(value = "角色名称")
33
+    private String name;
34
+
35
+
36
+}

+ 39
- 0
src/main/java/com/yunzhi/nanyang/entity/SysRolePermission.java ファイルの表示

@@ -0,0 +1,39 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import java.io.Serializable;
6
+import io.swagger.annotations.ApiModel;
7
+import io.swagger.annotations.ApiModelProperty;
8
+import lombok.Data;
9
+import lombok.EqualsAndHashCode;
10
+import lombok.experimental.Accessors;
11
+
12
+/**
13
+ * <p>
14
+ * 角色权限
15
+ * </p>
16
+ *
17
+ * @author yansen
18
+ * @since 2022-03-07
19
+ */
20
+@Data
21
+@EqualsAndHashCode(callSuper = false)
22
+@Accessors(chain = true)
23
+@ApiModel(value="SysRolePermission对象", description="角色权限")
24
+public class SysRolePermission implements Serializable {
25
+
26
+    private static final long serialVersionUID = 1L;
27
+
28
+    @ApiModelProperty(value = "序号")
29
+    @TableId(value = "serial_no", type = IdType.AUTO)
30
+    private Integer serialNo;
31
+
32
+    @ApiModelProperty(value = "角色ID")
33
+    private String roleId;
34
+
35
+    @ApiModelProperty(value = "权限ID")
36
+    private String permissionId;
37
+
38
+
39
+}

+ 58
- 0
src/main/java/com/yunzhi/nanyang/entity/SysUser.java ファイルの表示

@@ -0,0 +1,58 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import java.time.LocalDateTime;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import java.io.Serializable;
7
+import io.swagger.annotations.ApiModel;
8
+import io.swagger.annotations.ApiModelProperty;
9
+import lombok.Data;
10
+import lombok.EqualsAndHashCode;
11
+import lombok.experimental.Accessors;
12
+
13
+/**
14
+ * <p>
15
+ * 用户表
16
+ * </p>
17
+ *
18
+ * @author yansen
19
+ * @since 2022-03-07
20
+ */
21
+@Data
22
+@EqualsAndHashCode(callSuper = false)
23
+@Accessors(chain = true)
24
+@ApiModel(value="SysUser对象", description="用户表")
25
+public class SysUser implements Serializable {
26
+
27
+    private static final long serialVersionUID = 1L;
28
+
29
+    @ApiModelProperty(value = "用户Id")
30
+    @TableId(value = "user_id", type = IdType.INPUT)
31
+    private String userId;
32
+
33
+    @ApiModelProperty(value = "用户名")
34
+    private String userName;
35
+
36
+    @ApiModelProperty(value = "手机号")
37
+    private String phone;
38
+
39
+    @ApiModelProperty(value = "头像")
40
+    private String avatar;
41
+
42
+    @ApiModelProperty(value = "邮箱")
43
+    private String email;
44
+
45
+    @ApiModelProperty(value = "机构ID")
46
+    private String orgId;
47
+
48
+    @ApiModelProperty(value = "状态")
49
+    private Integer status;
50
+
51
+    @ApiModelProperty(value = "创建时间")
52
+    private LocalDateTime createDate;
53
+
54
+    @ApiModelProperty(value = "更新时间")
55
+    private LocalDateTime updateDate;
56
+
57
+
58
+}

+ 39
- 0
src/main/java/com/yunzhi/nanyang/entity/SysUserRole.java ファイルの表示

@@ -0,0 +1,39 @@
1
+package com.yunzhi.nanyang.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import java.io.Serializable;
6
+import io.swagger.annotations.ApiModel;
7
+import io.swagger.annotations.ApiModelProperty;
8
+import lombok.Data;
9
+import lombok.EqualsAndHashCode;
10
+import lombok.experimental.Accessors;
11
+
12
+/**
13
+ * <p>
14
+ * 用户角色
15
+ * </p>
16
+ *
17
+ * @author yansen
18
+ * @since 2022-03-07
19
+ */
20
+@Data
21
+@EqualsAndHashCode(callSuper = false)
22
+@Accessors(chain = true)
23
+@ApiModel(value="SysUserRole对象", description="用户角色")
24
+public class SysUserRole implements Serializable {
25
+
26
+    private static final long serialVersionUID = 1L;
27
+
28
+    @ApiModelProperty(value = "序号")
29
+    @TableId(value = "serial_no", type = IdType.AUTO)
30
+    private Integer serialNo;
31
+
32
+    @ApiModelProperty(value = "用户ID")
33
+    private String userId;
34
+
35
+    @ApiModelProperty(value = "角色ID")
36
+    private String roleId;
37
+
38
+
39
+}

+ 24
- 0
src/main/java/com/yunzhi/nanyang/exception/GlobalExceptionHandler.java ファイルの表示

@@ -0,0 +1,24 @@
1
+package com.yunzhi.nanyang.exception;
2
+
3
+import com.yunzhi.nanyang.common.ResponseBean;
4
+import lombok.extern.slf4j.Slf4j;
5
+import org.apache.shiro.authz.UnauthorizedException;
6
+import org.springframework.web.bind.annotation.ExceptionHandler;
7
+import org.springframework.web.bind.annotation.ResponseBody;
8
+import org.springframework.web.bind.annotation.RestControllerAdvice;
9
+
10
+@Slf4j
11
+@RestControllerAdvice
12
+public class GlobalExceptionHandler {
13
+
14
+    @ResponseBody
15
+    @ExceptionHandler(Exception.class)
16
+    public ResponseBean handleException(Exception e){
17
+        e.printStackTrace();
18
+
19
+        if (e instanceof UnauthorizedException) {
20
+            return ResponseBean.error("暂无权限进行当前操作", ResponseBean.ERROR_UNAUTHORIZED);
21
+        }
22
+        return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
23
+    }
24
+}

+ 80
- 0
src/main/java/com/yunzhi/nanyang/log/MysqlAppender.java ファイルの表示

@@ -0,0 +1,80 @@
1
+package com.yunzhi.nanyang.log;
2
+
3
+import ch.qos.logback.core.UnsynchronizedAppenderBase;
4
+import ch.qos.logback.core.db.ConnectionSource;
5
+import ch.qos.logback.core.encoder.Encoder;
6
+
7
+import java.sql.Connection;
8
+import java.sql.PreparedStatement;
9
+import java.util.Arrays;
10
+
11
+import static ch.qos.logback.core.db.DBHelper.closeStatement;
12
+
13
+public class MysqlAppender<E> extends UnsynchronizedAppenderBase<E> {
14
+    protected ConnectionSource connectionSource;
15
+    protected Encoder<E> encoder;
16
+    protected String app = "shigongli";
17
+
18
+    @Override
19
+    public void start() {
20
+        if (connectionSource == null) {
21
+            throw new IllegalStateException("MysqlAppender cannot function without a connection source");
22
+        }
23
+
24
+        super.start();
25
+    }
26
+
27
+    public ConnectionSource getConnectionSource() {
28
+        return connectionSource;
29
+    }
30
+
31
+    public void setConnectionSource(ConnectionSource connectionSource) {
32
+        this.connectionSource = connectionSource;
33
+    }
34
+
35
+    @Override
36
+    protected void append(E event) {
37
+        Connection connection = null;
38
+        PreparedStatement insertStatement = null;
39
+
40
+        try {
41
+            connection = connectionSource.getConnection();
42
+            connection.setAutoCommit(false);
43
+            insertStatement = connection.prepareStatement(getInsertSQL());
44
+
45
+            synchronized (this) {
46
+                byte[] logContent = this.encoder.encode(event);
47
+                insertStatement.setBytes(1, logContent);
48
+                insertStatement.execute();
49
+                closeStatement(insertStatement);
50
+            }
51
+
52
+            connection.commit();
53
+        } catch (Throwable sqle) {
54
+            addError("problem appending event", sqle);
55
+        }
56
+
57
+    }
58
+
59
+    public Encoder<E> getEncoder() {
60
+        return encoder;
61
+    }
62
+
63
+    public void setEncoder(Encoder<E> encoder) {
64
+        this.encoder = encoder;
65
+    }
66
+
67
+    @Override
68
+    public void stop() {
69
+        super.stop();
70
+    }
71
+
72
+    private String getInsertSQL() {
73
+        String tableName = "ta_"+app;
74
+        String[] columns = {"log"};
75
+        String[] signs = Arrays.stream(columns).map(x -> "?").toArray(String[]::new);
76
+        String sql = String.format("INSERT INTO %s (%s) values (%s)", tableName, String.join(",", columns), String.join(",", signs));
77
+//        System.out.println(sql);
78
+        return sql;
79
+    }
80
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysLoginMapper.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysLogin;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+/**
9
+ * <p>
10
+ * 登录表 Mapper 接口
11
+ * </p>
12
+ *
13
+ * @author yansen
14
+ * @since 2022-03-07
15
+ */
16
+@Mapper
17
+public interface SysLoginMapper extends BaseMapper<SysLogin> {
18
+
19
+    SysLogin getByLogin(@Param("loginType") String loginType, @Param("userName") String userName);
20
+}

+ 18
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysMenuMapper.java ファイルの表示

@@ -0,0 +1,18 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysMenu;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 菜单表 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-03-07
14
+ */
15
+@Mapper
16
+public interface SysMenuMapper extends BaseMapper<SysMenu> {
17
+
18
+}

+ 18
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysPermissionMapper.java ファイルの表示

@@ -0,0 +1,18 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysPermission;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 权限表 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-03-07
14
+ */
15
+@Mapper
16
+public interface SysPermissionMapper extends BaseMapper<SysPermission> {
17
+
18
+}

+ 18
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysRoleMapper.java ファイルの表示

@@ -0,0 +1,18 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysRole;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 角色表 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-03-07
14
+ */
15
+@Mapper
16
+public interface SysRoleMapper extends BaseMapper<SysRole> {
17
+
18
+}

+ 22
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysRolePermissionMapper.java ファイルの表示

@@ -0,0 +1,22 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysRolePermission;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.Set;
9
+
10
+/**
11
+ * <p>
12
+ * 角色权限 Mapper 接口
13
+ * </p>
14
+ *
15
+ * @author yansen
16
+ * @since 2022-03-07
17
+ */
18
+@Mapper
19
+public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> {
20
+
21
+    Set<String> getPermissionByUser(@Param("userId") String userId);
22
+}

+ 18
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysUserMapper.java ファイルの表示

@@ -0,0 +1,18 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysUser;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 用户表 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-03-07
14
+ */
15
+@Mapper
16
+public interface SysUserMapper extends BaseMapper<SysUser> {
17
+
18
+}

+ 22
- 0
src/main/java/com/yunzhi/nanyang/mapper/SysUserRoleMapper.java ファイルの表示

@@ -0,0 +1,22 @@
1
+package com.yunzhi.nanyang.mapper;
2
+
3
+import com.yunzhi.nanyang.entity.SysUserRole;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.Set;
9
+
10
+/**
11
+ * <p>
12
+ * 用户角色 Mapper 接口
13
+ * </p>
14
+ *
15
+ * @author yansen
16
+ * @since 2022-03-07
17
+ */
18
+@Mapper
19
+public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
20
+
21
+    Set<String> getRoleByUser(@Param("userId") String userId);
22
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/service/IBaseService.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+
5
+import java.io.Serializable;
6
+
7
+public interface IBaseService<T> extends IService<T> {
8
+    /**
9
+     * 逻辑删除
10
+     * @param id
11
+     * @return
12
+     */
13
+    boolean removeLogicById(Serializable id);
14
+
15
+    int countBy(String column, Object value, boolean notDelete);
16
+
17
+    T getByButNot(String column, Object value, String col, Object val, boolean notDelete);
18
+
19
+    T getExistBy(String column, Object value, boolean normal, boolean notDelete);
20
+}

+ 18
- 0
src/main/java/com/yunzhi/nanyang/service/ISysLoginService.java ファイルの表示

@@ -0,0 +1,18 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysLogin;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.yunzhi.nanyang.vo.LoginParam;
6
+
7
+/**
8
+ * <p>
9
+ * 登录表 服务类
10
+ * </p>
11
+ *
12
+ * @author yansen
13
+ * @since 2022-03-07
14
+ */
15
+public interface ISysLoginService extends IService<SysLogin> {
16
+
17
+    SysLogin getByLogin(LoginParam loginParam);
18
+}

+ 16
- 0
src/main/java/com/yunzhi/nanyang/service/ISysMenuService.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysMenu;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 菜单表 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-03-07
13
+ */
14
+public interface ISysMenuService extends IService<SysMenu> {
15
+
16
+}

+ 16
- 0
src/main/java/com/yunzhi/nanyang/service/ISysPermissionService.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysPermission;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 权限表 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-03-07
13
+ */
14
+public interface ISysPermissionService extends IService<SysPermission> {
15
+
16
+}

+ 16
- 0
src/main/java/com/yunzhi/nanyang/service/ISysRolePermissionService.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysRolePermission;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 角色权限 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-03-07
13
+ */
14
+public interface ISysRolePermissionService extends IService<SysRolePermission> {
15
+
16
+}

+ 16
- 0
src/main/java/com/yunzhi/nanyang/service/ISysRoleService.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysRole;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 角色表 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-03-07
13
+ */
14
+public interface ISysRoleService extends IService<SysRole> {
15
+
16
+}

+ 16
- 0
src/main/java/com/yunzhi/nanyang/service/ISysUserRoleService.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysUserRole;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 用户角色 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-03-07
13
+ */
14
+public interface ISysUserRoleService extends IService<SysUserRole> {
15
+
16
+}

+ 16
- 0
src/main/java/com/yunzhi/nanyang/service/ISysUserService.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package com.yunzhi.nanyang.service;
2
+
3
+import com.yunzhi.nanyang.entity.SysUser;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+
6
+/**
7
+ * <p>
8
+ * 用户表 服务类
9
+ * </p>
10
+ *
11
+ * @author yansen
12
+ * @since 2022-03-07
13
+ */
14
+public interface ISysUserService extends IService<SysUser> {
15
+
16
+}

+ 54
- 0
src/main/java/com/yunzhi/nanyang/service/impl/BaseServiceImpl.java ファイルの表示

@@ -0,0 +1,54 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
5
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
7
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
9
+import com.yunzhi.nanyang.service.IBaseService;
10
+
11
+import java.io.Serializable;
12
+
13
+public class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements IBaseService<T> {
14
+    @Override
15
+    public boolean removeLogicById(Serializable id) {
16
+
17
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
18
+        UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
19
+        updateWrapper.set("state", -1)
20
+                .eq(tableInfo.getKeyColumn(), id);
21
+
22
+        return update(updateWrapper);
23
+    }
24
+
25
+    @Override
26
+    public int countBy(String column, Object value, boolean notDelete) {
27
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
28
+        queryWrapper.eq(column, value);
29
+        queryWrapper.gt(notDelete, "state", -1);
30
+
31
+        return count(queryWrapper);
32
+    }
33
+
34
+    @Override
35
+    public T getByButNot(String column, Object value, String col, Object val, boolean notDelete) {
36
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
37
+        queryWrapper.eq(column, value);
38
+        queryWrapper.ne(col, val);
39
+        queryWrapper.gt(notDelete, "state", -1);
40
+        queryWrapper.last("limit 1");
41
+
42
+        return getOne(queryWrapper);
43
+    }
44
+
45
+    @Override
46
+    public T getExistBy(String column, Object value, boolean normal, boolean notDelete) {
47
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
48
+        queryWrapper.eq(column, value);
49
+        queryWrapper.eq(normal, "state", 1);
50
+        queryWrapper.gt(notDelete, "state", -1);
51
+        queryWrapper.last("limit 1");
52
+        return getOne(queryWrapper);
53
+    }
54
+}

+ 55
- 0
src/main/java/com/yunzhi/nanyang/service/impl/ManagerServiceImpl.java ファイルの表示

@@ -0,0 +1,55 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.common.Constants;
4
+import com.yunzhi.nanyang.entity.SysLogin;
5
+import com.yunzhi.nanyang.entity.SysRolePermission;
6
+import com.yunzhi.nanyang.entity.SysUser;
7
+import com.yunzhi.nanyang.entity.SysUserRole;
8
+import com.yunzhi.nanyang.mapper.SysLoginMapper;
9
+import com.yunzhi.nanyang.mapper.SysRolePermissionMapper;
10
+import com.yunzhi.nanyang.mapper.SysUserMapper;
11
+import com.yunzhi.nanyang.mapper.SysUserRoleMapper;
12
+import com.yunzhi.nanyang.shiro.realms.manager.IManagerService;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.stereotype.Service;
15
+
16
+import java.util.Set;
17
+
18
+@Service
19
+public class ManagerServiceImpl implements IManagerService {
20
+
21
+    @Autowired
22
+    SysLoginMapper sysLoginMapper;
23
+
24
+    @Autowired
25
+    SysUserMapper sysUserMapper;
26
+
27
+    @Autowired
28
+    SysUserRoleMapper sysUserRoleMapper;
29
+
30
+    @Autowired
31
+    SysRolePermissionMapper sysRolePermissionMapper;
32
+
33
+    @Override
34
+    public Boolean verify(String id) {
35
+        SysLogin sysLogin = sysLoginMapper.selectById(id);
36
+        if (null == sysLogin || sysLogin.getStatus() != Constants.STATUS_NORMAL) {
37
+            return false;
38
+        }
39
+
40
+        return true;
41
+    }
42
+
43
+    @Override
44
+    public Set<String> getRolesByLoginId(String id) {
45
+        SysLogin sysLogin = sysLoginMapper.selectById(id);
46
+        return sysUserRoleMapper.getRoleByUser(sysLogin.getUserId());
47
+    }
48
+
49
+    @Override
50
+    public Set<String> getPermissionsLoginId(String id) {
51
+        SysLogin sysLogin = sysLoginMapper.selectById(id);
52
+        return sysRolePermissionMapper.getPermissionByUser(sysLogin.getUserId());
53
+    }
54
+
55
+}

+ 25
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysLoginServiceImpl.java ファイルの表示

@@ -0,0 +1,25 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysLogin;
4
+import com.yunzhi.nanyang.mapper.SysLoginMapper;
5
+import com.yunzhi.nanyang.service.ISysLoginService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import com.yunzhi.nanyang.vo.LoginParam;
8
+import org.springframework.stereotype.Service;
9
+
10
+/**
11
+ * <p>
12
+ * 登录表 服务实现类
13
+ * </p>
14
+ *
15
+ * @author yansen
16
+ * @since 2022-03-07
17
+ */
18
+@Service
19
+public class SysLoginServiceImpl extends ServiceImpl<SysLoginMapper, SysLogin> implements ISysLoginService {
20
+
21
+    @Override
22
+    public SysLogin getByLogin(LoginParam loginParam) {
23
+        return baseMapper.getByLogin(loginParam.getLoginType(), loginParam.getUserName());
24
+    }
25
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysMenuServiceImpl.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysMenu;
4
+import com.yunzhi.nanyang.mapper.SysMenuMapper;
5
+import com.yunzhi.nanyang.service.ISysMenuService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 菜单表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-07
16
+ */
17
+@Service
18
+public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
19
+
20
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysPermissionServiceImpl.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysPermission;
4
+import com.yunzhi.nanyang.mapper.SysPermissionMapper;
5
+import com.yunzhi.nanyang.service.ISysPermissionService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 权限表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-07
16
+ */
17
+@Service
18
+public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {
19
+
20
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysRolePermissionServiceImpl.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysRolePermission;
4
+import com.yunzhi.nanyang.mapper.SysRolePermissionMapper;
5
+import com.yunzhi.nanyang.service.ISysRolePermissionService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 角色权限 服务实现类
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-07
16
+ */
17
+@Service
18
+public class SysRolePermissionServiceImpl extends ServiceImpl<SysRolePermissionMapper, SysRolePermission> implements ISysRolePermissionService {
19
+
20
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysRoleServiceImpl.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysRole;
4
+import com.yunzhi.nanyang.mapper.SysRoleMapper;
5
+import com.yunzhi.nanyang.service.ISysRoleService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 角色表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-07
16
+ */
17
+@Service
18
+public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
19
+
20
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysUserRoleServiceImpl.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysUserRole;
4
+import com.yunzhi.nanyang.mapper.SysUserRoleMapper;
5
+import com.yunzhi.nanyang.service.ISysUserRoleService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 用户角色 服务实现类
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-07
16
+ */
17
+@Service
18
+public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
19
+
20
+}

+ 20
- 0
src/main/java/com/yunzhi/nanyang/service/impl/SysUserServiceImpl.java ファイルの表示

@@ -0,0 +1,20 @@
1
+package com.yunzhi.nanyang.service.impl;
2
+
3
+import com.yunzhi.nanyang.entity.SysUser;
4
+import com.yunzhi.nanyang.mapper.SysUserMapper;
5
+import com.yunzhi.nanyang.service.ISysUserService;
6
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 用户表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-07
16
+ */
17
+@Service
18
+public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
19
+
20
+}

+ 76
- 0
src/main/java/com/yunzhi/nanyang/shiro/ShiroConfig.java ファイルの表示

@@ -0,0 +1,76 @@
1
+package com.yunzhi.nanyang.shiro;
2
+
3
+import com.yunzhi.nanyang.shiro.filters.JWTFilter;
4
+import com.yunzhi.nanyang.shiro.matcher.JWTCredentialsMatcher;
5
+import com.yunzhi.nanyang.shiro.realms.manager.IManagerService;
6
+import com.yunzhi.nanyang.shiro.realms.manager.ManagerRealm;
7
+import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
8
+import org.apache.shiro.mgt.DefaultSubjectDAO;
9
+import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
10
+import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.beans.factory.annotation.Value;
13
+import org.springframework.context.annotation.Bean;
14
+import org.springframework.context.annotation.Configuration;
15
+
16
+import javax.servlet.Filter;
17
+import java.util.HashMap;
18
+import java.util.Map;
19
+
20
+@Configuration
21
+public class ShiroConfig {
22
+
23
+    @Autowired
24
+    IManagerService iManagerService;
25
+
26
+    @Value("${shiro.unauthorizedUrl}")
27
+    private String unauthorizedUrl;
28
+
29
+    @Value("#{${shiro.filterRuleMap}}")
30
+    private Map<String, String> filterRuleMap;
31
+
32
+    @Bean
33
+    public ManagerRealm managerRealm() {
34
+        ManagerRealm realm = new ManagerRealm();
35
+        realm.setManagerService(iManagerService);
36
+        realm.setCredentialsMatcher(new JWTCredentialsMatcher());
37
+        return realm;
38
+    }
39
+
40
+    @Bean("shiroFilterFactoryBean")
41
+    public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager) {
42
+        ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
43
+
44
+        // 手动加入 JWTFilter
45
+        JWTFilter jwtFilter = new JWTFilter();
46
+        jwtFilter.setUnauthorizedUrl(unauthorizedUrl);
47
+
48
+        Map<String, Filter> filterMap = new HashMap<>();
49
+        filterMap.put("jwt", jwtFilter);
50
+        factoryBean.setFilters(filterMap);
51
+
52
+        factoryBean.setSecurityManager(securityManager);
53
+        factoryBean.setUnauthorizedUrl(unauthorizedUrl);
54
+
55
+        factoryBean.setFilterChainDefinitionMap(filterRuleMap);
56
+        return factoryBean;
57
+    }
58
+
59
+    @Bean("securityManager")
60
+    public DefaultWebSecurityManager securityManager() {
61
+        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
62
+        //  Use your own realm
63
+        manager.setRealm(managerRealm());
64
+
65
+        /*
66
+         * 禁用 session
67
+         */
68
+        DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
69
+        DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
70
+        defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
71
+        subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
72
+        manager.setSubjectDAO(subjectDAO);
73
+
74
+        return manager;
75
+    }
76
+}

+ 83
- 0
src/main/java/com/yunzhi/nanyang/shiro/filters/JWTFilter.java ファイルの表示

@@ -0,0 +1,83 @@
1
+package com.yunzhi.nanyang.shiro.filters;
2
+
3
+import com.yunzhi.nanyang.shiro.utils.JWTToken;
4
+import com.yunzhi.nanyang.shiro.utils.JWTUtil;
5
+import org.apache.shiro.authc.AuthenticationToken;
6
+import org.apache.shiro.subject.Subject;
7
+import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
8
+import org.apache.shiro.web.util.WebUtils;
9
+import org.slf4j.Logger;
10
+import org.slf4j.LoggerFactory;
11
+
12
+import javax.servlet.ServletRequest;
13
+import javax.servlet.ServletResponse;
14
+import javax.servlet.http.HttpServletResponse;
15
+import java.io.IOException;
16
+
17
+public class JWTFilter extends AuthenticatingFilter {
18
+
19
+    private Logger LOGGER = LoggerFactory.getLogger(this.getClass());
20
+
21
+    public final static String JWT_HEADER = "Authorization";
22
+
23
+    // 20 分钟刷新一次 token
24
+    private final static long REFRESH_MILLS = 20 * 60 * 1000;
25
+
26
+    private String unauthorizedUrl;
27
+    public void setUnauthorizedUrl(String unauthorizedUrl) {
28
+        this.unauthorizedUrl = unauthorizedUrl;
29
+    }
30
+
31
+    @Override
32
+    protected AuthenticationToken createToken(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
33
+        String authorization = WebUtils.toHttp(servletRequest).getHeader(JWT_HEADER);
34
+        if (authorization == null || "".equals(authorization)) {
35
+            throw new Exception("token不能为空");
36
+        }
37
+
38
+        return new JWTToken(authorization);
39
+    }
40
+
41
+    @Override
42
+    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
43
+        boolean allowed = false;
44
+        try {
45
+            allowed = executeLogin(request, response);
46
+        } catch (Exception e) {
47
+            response401(request, response);
48
+        }
49
+
50
+        return allowed;
51
+//        return allowed || super.isPermissive(mappedValue);
52
+    }
53
+
54
+    @Override
55
+    protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
56
+        return false;
57
+    }
58
+
59
+    // 主要用来刷新 token
60
+    @Override
61
+    protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
62
+        String originToken = token.getPrincipal().toString();
63
+
64
+        long diff = System.currentTimeMillis() - JWTUtil.getExpDate(originToken).getTime();
65
+        if (diff >= REFRESH_MILLS) {
66
+            HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
67
+            httpServletResponse.setHeader(JWT_HEADER, JWTUtil.refresh(originToken));
68
+        }
69
+
70
+        return true;
71
+    }
72
+
73
+    /**
74
+     *Jump illegal request to / 401
75
+     */
76
+    private void response401(ServletRequest request, ServletResponse response) {
77
+        try {
78
+            WebUtils.toHttp(response).sendRedirect(unauthorizedUrl);
79
+        } catch (IOException e) {
80
+            LOGGER.error(e.getMessage());
81
+        }
82
+    }
83
+}

+ 14
- 0
src/main/java/com/yunzhi/nanyang/shiro/matcher/JWTCredentialsMatcher.java ファイルの表示

@@ -0,0 +1,14 @@
1
+package com.yunzhi.nanyang.shiro.matcher;
2
+
3
+import com.yunzhi.nanyang.shiro.utils.JWTUtil;
4
+import org.apache.shiro.authc.AuthenticationInfo;
5
+import org.apache.shiro.authc.AuthenticationToken;
6
+import org.apache.shiro.authc.credential.CredentialsMatcher;
7
+
8
+public class JWTCredentialsMatcher implements CredentialsMatcher {
9
+    @Override
10
+    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
11
+        String token = authenticationToken.getCredentials().toString();
12
+        return JWTUtil.verify(token);
13
+    }
14
+}

+ 31
- 0
src/main/java/com/yunzhi/nanyang/shiro/realms/manager/IManagerService.java ファイルの表示

@@ -0,0 +1,31 @@
1
+package com.yunzhi.nanyang.shiro.realms.manager;
2
+
3
+import java.util.Set;
4
+
5
+/**
6
+ *
7
+ */
8
+public interface IManagerService {
9
+
10
+    /**
11
+     * 校验用户状态
12
+     * @param id
13
+     * @return
14
+     */
15
+    Boolean verify(String id);
16
+
17
+    /**
18
+     * 获取用户角色
19
+     * @param id
20
+     * @return
21
+     */
22
+    Set<String> getRolesByLoginId(String id);
23
+
24
+    /**
25
+     * 获取用户权限
26
+     * @param id
27
+     * @return
28
+     */
29
+    Set<String> getPermissionsLoginId(String id);
30
+
31
+}

+ 55
- 0
src/main/java/com/yunzhi/nanyang/shiro/realms/manager/ManagerRealm.java ファイルの表示

@@ -0,0 +1,55 @@
1
+package com.yunzhi.nanyang.shiro.realms.manager;
2
+
3
+import com.yunzhi.nanyang.shiro.utils.JWTToken;
4
+import com.yunzhi.nanyang.shiro.utils.JWTUtil;
5
+import org.apache.shiro.authc.AuthenticationException;
6
+import org.apache.shiro.authc.AuthenticationInfo;
7
+import org.apache.shiro.authc.AuthenticationToken;
8
+import org.apache.shiro.authc.SimpleAuthenticationInfo;
9
+import org.apache.shiro.authz.AuthorizationInfo;
10
+import org.apache.shiro.authz.SimpleAuthorizationInfo;
11
+import org.apache.shiro.realm.AuthorizingRealm;
12
+import org.apache.shiro.subject.PrincipalCollection;
13
+
14
+import java.util.Set;
15
+
16
+public class ManagerRealm extends AuthorizingRealm {
17
+
18
+    IManagerService iManagerService;
19
+
20
+    public void setManagerService(IManagerService iManagerService) {
21
+        this.iManagerService = iManagerService;
22
+    }
23
+
24
+    @Override
25
+    public boolean supports(AuthenticationToken token) {
26
+        return token instanceof JWTToken;
27
+    }
28
+
29
+    @Override
30
+    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
31
+        // 获取用户角色,权限
32
+        String token = (String) principalCollection.getPrimaryPrincipal();
33
+        String loginId = JWTUtil.getLoginId(token);
34
+        Set<String> roles = iManagerService.getRolesByLoginId(loginId);
35
+        Set<String> permissions = iManagerService.getPermissionsLoginId(loginId);
36
+
37
+        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
38
+        simpleAuthorizationInfo.setStringPermissions(permissions);
39
+        simpleAuthorizationInfo.setRoles(roles);
40
+        return simpleAuthorizationInfo;
41
+    }
42
+
43
+    @Override
44
+    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
45
+        String token = (String) authenticationToken.getPrincipal();
46
+        String loginId = JWTUtil.getLoginId(token);
47
+
48
+        if (!iManagerService.verify(loginId)) {
49
+            throw new AuthenticationException("User is abnormal");
50
+        }
51
+
52
+        // 交给 AuthenticatingRealm 使用 CredentialsMatcher 行校验
53
+        return new SimpleAuthenticationInfo(token, token, getName());
54
+    }
55
+}

+ 23
- 0
src/main/java/com/yunzhi/nanyang/shiro/utils/JWTToken.java ファイルの表示

@@ -0,0 +1,23 @@
1
+package com.yunzhi.nanyang.shiro.utils;
2
+
3
+import org.apache.shiro.authc.AuthenticationToken;
4
+
5
+public class JWTToken implements AuthenticationToken {
6
+
7
+    //Key
8
+    private String token;
9
+
10
+    public JWTToken(String token) {
11
+        this.token = token;
12
+    }
13
+
14
+    @Override
15
+    public Object getPrincipal() {
16
+        return token;
17
+    }
18
+
19
+    @Override
20
+    public Object getCredentials() {
21
+        return token;
22
+    }
23
+}

+ 65
- 0
src/main/java/com/yunzhi/nanyang/shiro/utils/JWTUtil.java ファイルの表示

@@ -0,0 +1,65 @@
1
+package com.yunzhi.nanyang.shiro.utils;
2
+
3
+import com.auth0.jwt.JWT;
4
+import com.auth0.jwt.algorithms.Algorithm;
5
+import com.auth0.jwt.exceptions.JWTDecodeException;
6
+import com.auth0.jwt.interfaces.DecodedJWT;
7
+
8
+import java.util.Date;
9
+
10
+/**
11
+ * 一个通用版本的 JWT
12
+ */
13
+public class JWTUtil {
14
+
15
+    // 默认过期时间 1 小时
16
+    private static final long EXPIRE_TIME = 60 * 60 * 1000;
17
+
18
+    public static String getLoginId(String token) {
19
+        try {
20
+            DecodedJWT jwt = JWT.decode(token);
21
+            return jwt.getSubject();
22
+        } catch (JWTDecodeException e) {
23
+            return null;
24
+        }
25
+    }
26
+
27
+    public static Date getExpDate(String token) {
28
+        try {
29
+            DecodedJWT jwt = JWT.decode(token);
30
+            return jwt.getExpiresAt();
31
+        } catch (JWTDecodeException e) {
32
+            return null;
33
+        }
34
+    }
35
+
36
+    public static String sign(String loginId, String secret) {
37
+        Date date = new Date(System.currentTimeMillis()+EXPIRE_TIME);
38
+        Algorithm algorithm = Algorithm.HMAC256(secret);
39
+
40
+        return JWT.create()
41
+                .withSubject(loginId)
42
+                .withExpiresAt(date)
43
+                .withClaim("secret", secret)
44
+                .sign(algorithm);
45
+    }
46
+
47
+    public static String refresh(String token) throws Exception {
48
+        DecodedJWT jwt = JWT.decode(token);
49
+        String loginId = jwt.getSubject();
50
+        String secret = jwt.getClaim("secret").asString();
51
+
52
+        return sign(loginId, secret);
53
+    }
54
+
55
+    public static boolean verify(String token) {
56
+        try {
57
+            JWT.decode(token);
58
+            return true;
59
+        } catch (Exception e) {
60
+            e.printStackTrace();
61
+            return false;
62
+        }
63
+    }
64
+
65
+}

+ 19
- 0
src/main/java/com/yunzhi/nanyang/vo/LoginParam.java ファイルの表示

@@ -0,0 +1,19 @@
1
+package com.yunzhi.nanyang.vo;
2
+
3
+import io.swagger.annotations.ApiModel;
4
+import io.swagger.annotations.ApiModelProperty;
5
+import lombok.Data;
6
+
7
+@ApiModel(description = "登录参数")
8
+@Data
9
+public class LoginParam {
10
+
11
+    @ApiModelProperty("登录方式")
12
+    String loginType;
13
+
14
+    @ApiModelProperty("用户名")
15
+    String userName;
16
+
17
+    @ApiModelProperty("密码, MD5 加密后数据")
18
+    String password;
19
+}

+ 16
- 0
src/main/resources/application-dev.yml ファイルの表示

@@ -0,0 +1,16 @@
1
+###
2
+spring:
3
+  servlet:
4
+    multipart:
5
+      max-file-size: 10MB
6
+      max-request-size: 50MB
7
+  datasource:
8
+    url: jdbc:mysql://110.40.183.156:3306/nanyang_machinery?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
9
+    username: nanyang_machinery
10
+    password: nanyang_machinery@ABCD1234
11
+
12
+###
13
+logging:
14
+  level:
15
+    root: info
16
+    springfox: info

+ 11
- 0
src/main/resources/application-prod.yml ファイルの表示

@@ -0,0 +1,11 @@
1
+###
2
+spring:
3
+  servlet:
4
+    multipart:
5
+      max-file-size: 10MB
6
+      max-request-size: 50MB
7
+  datasource:
8
+    url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/dianyang_colmo?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
9
+    username: dianyang_colmo
10
+    password: dianyang_colmo@ABC123
11
+

+ 68
- 0
src/main/resources/application.yml ファイルの表示

@@ -0,0 +1,68 @@
1
+###
2
+server:
3
+  port: 7080
4
+  servlet:
5
+    context-path: /api
6
+
7
+###
8
+shiro:
9
+  enabled: true
10
+  unauthorizedUrl: /api/401
11
+  filterRuleMap: '{
12
+    "/admin/login": "anon",
13
+    "/admin/**": "jwt",
14
+    "/**": "anon"
15
+  }'
16
+
17
+###
18
+mybatis-plus:
19
+  configuration:
20
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
21
+    call-setters-on-nulls: true
22
+  mapper-locations: classpath:mapper/**/*.xml
23
+
24
+###
25
+sms:
26
+  captcha:
27
+    code: SMS_207555188
28
+    sign: 云致科技
29
+
30
+###
31
+yz:
32
+  sms:
33
+    ## 可以任意名称
34
+    appid: state-grid-training
35
+    api: http://sms.njyunzhi.com/sms
36
+    ## 帮助文档
37
+    help: http://sms.njyunzhi.com/help
38
+
39
+###
40
+aliyun:
41
+  accessKeyId: LTAI4FdMQNh1xUoiqqbKJ15J
42
+  accessKeySecret: F7vmuXBu8IrhouQYYhFMLRhIRivIzb
43
+  oss:
44
+    endpoint: oss-cn-shanghai.aliyuncs.com
45
+    bucketName: njcj
46
+    bucketURL: https://njcj.oss-cn-shanghai.aliyuncs.com
47
+  sms:
48
+    captcha:
49
+      code: SMS_195585471
50
+      sign: 云致
51
+
52
+###
53
+weixin:
54
+  miniapp:
55
+    appid: wxd6f47a9bb3052175
56
+    secret: 28f33b6bbc0f778c11a0bb234a7d6d4e
57
+    token:
58
+    aesKey:
59
+    msgDataFormat: JSON
60
+
61
+###
62
+spring:
63
+  application:
64
+    name: demo
65
+  profiles:
66
+    active: @profileActive@
67
+
68
+

+ 31
- 0
src/main/resources/logback.xml.bak ファイルの表示

@@ -0,0 +1,31 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<configuration>
3
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
5
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
6
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
7
+        </encoder>
8
+    </appender>
9
+    <appender name="LOGDB" class="com.yunzhi.dianyang.log.MysqlAppender">
10
+        <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
11
+            <driverClass>com.mysql.cj.jdbc.Driver</driverClass>
12
+            <url>jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/yz_questions</url>
13
+            <user>yz_questions</user>
14
+            <password>questions@1234</password>
15
+        </connectionSource>
16
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
17
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
18
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
19
+        </encoder>
20
+    </appender>
21
+
22
+    <logger name="com.apache.ibatis" level="TRACE"/>
23
+    <logger name="java.sql.Connection" level="DEBUG"/>
24
+    <logger name="java.sql.Statement" level="DEBUG"/>
25
+    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
26
+
27
+    <root level="INFO">
28
+        <appender-ref ref="STDOUT" />
29
+        <appender-ref ref="LOGDB" />
30
+    </root>
31
+</configuration>

+ 14
- 0
src/main/resources/mapper/SysLoginMapper.xml ファイルの表示

@@ -0,0 +1,14 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysLoginMapper">
4
+
5
+    <select id="getByLogin" resultType="com.yunzhi.nanyang.entity.SysLogin">
6
+        SELECT
7
+            *
8
+        FROM
9
+            sys_login t
10
+        WHERE
11
+            login_name = #{userName}
12
+          AND t.`status` > -1
13
+    </select>
14
+</mapper>

+ 5
- 0
src/main/resources/mapper/SysMenuMapper.xml ファイルの表示

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysMenuMapper">
4
+
5
+</mapper>

+ 5
- 0
src/main/resources/mapper/SysPermissionMapper.xml ファイルの表示

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysPermissionMapper">
4
+
5
+</mapper>

+ 5
- 0
src/main/resources/mapper/SysRoleMapper.xml ファイルの表示

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysRoleMapper">
4
+
5
+</mapper>

+ 19
- 0
src/main/resources/mapper/SysRolePermissionMapper.xml ファイルの表示

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysRolePermissionMapper">
4
+
5
+    <select id="getPermissionByUser" resultType="java.lang.String">
6
+        SELECT
7
+            t.permission_id
8
+        FROM
9
+            sys_role_permission t
10
+                INNER JOIN sys_user_role s ON s.role_id = t.role_id
11
+        WHERE
12
+        <if test="null == userId or userId == ''">
13
+            s.user_id = 'a-string-not-real-user-id'
14
+        </if>
15
+        <if test="null != userId and userId != ''">
16
+            s.user_id = #{userId}
17
+        </if>
18
+    </select>
19
+</mapper>

+ 5
- 0
src/main/resources/mapper/SysUserMapper.xml ファイルの表示

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysUserMapper">
4
+
5
+</mapper>

+ 19
- 0
src/main/resources/mapper/SysUserRoleMapper.xml ファイルの表示

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.nanyang.mapper.SysUserRoleMapper">
4
+
5
+    <select id="getRoleByUser" resultType="java.lang.String">
6
+        SELECT
7
+            role_id
8
+        FROM
9
+            sys_user_role
10
+        WHERE
11
+        <if test="null == userId or userId == ''">
12
+            user_id = 'a-string-not-real-user-id'
13
+        </if>
14
+        <if test="null != userId and userId != ''">
15
+            user_id = #{userId}
16
+        </if>
17
+
18
+    </select>
19
+</mapper>

+ 13
- 0
src/test/java/com/yunzhi/demo/SpringApplicationTests.java ファイルの表示

@@ -0,0 +1,13 @@
1
+package com.yunzhi.demo;
2
+
3
+import org.junit.jupiter.api.Test;
4
+import org.springframework.boot.test.context.SpringBootTest;
5
+
6
+@SpringBootTest
7
+class SpringApplicationTests {
8
+
9
+	@Test
10
+	void contextLoads() {
11
+	}
12
+
13
+}