瀏覽代碼

init project

xusonglin 5 年之前
父節點
當前提交
5ce704701f
共有 100 個文件被更改,包括 4199 次插入0 次删除
  1. 310 0
      mvnw
  2. 182 0
      mvnw.cmd
  3. 146 0
      pom.xml
  4. 16 0
      src/main/java/com/jkcredit/invoice/hub/InvoiceHubApplication.java
  5. 38 0
      src/main/java/com/jkcredit/invoice/hub/config/AccessControlAllowOriginFilter.java
  6. 24 0
      src/main/java/com/jkcredit/invoice/hub/config/AjaxAccessDeniedHandler.java
  7. 25 0
      src/main/java/com/jkcredit/invoice/hub/config/AjaxAuthenticationEntryPoint.java
  8. 35 0
      src/main/java/com/jkcredit/invoice/hub/config/AjaxAuthenticationFailureHandler.java
  9. 35 0
      src/main/java/com/jkcredit/invoice/hub/config/AjaxAuthenticationSuccessHandler.java
  10. 25 0
      src/main/java/com/jkcredit/invoice/hub/config/AjaxLogoutSuccessHandler.java
  11. 65 0
      src/main/java/com/jkcredit/invoice/hub/config/ApplicationDefaults.java
  12. 331 0
      src/main/java/com/jkcredit/invoice/hub/config/ApplicationProperties.java
  13. 36 0
      src/main/java/com/jkcredit/invoice/hub/config/AuthenticationEntryPointHandler.java
  14. 31 0
      src/main/java/com/jkcredit/invoice/hub/config/ControllerAdvice.java
  15. 31 0
      src/main/java/com/jkcredit/invoice/hub/config/CorsConfig.java
  16. 50 0
      src/main/java/com/jkcredit/invoice/hub/config/JwtAuthenticationTokenFilter.java
  17. 35 0
      src/main/java/com/jkcredit/invoice/hub/config/MyPermissionEvaluator.java
  18. 39 0
      src/main/java/com/jkcredit/invoice/hub/config/MybatisPlusConfigurer.java
  19. 42 0
      src/main/java/com/jkcredit/invoice/hub/config/RbacAuthorityService.java
  20. 156 0
      src/main/java/com/jkcredit/invoice/hub/config/SecurityConfiguration.java
  21. 55 0
      src/main/java/com/jkcredit/invoice/hub/config/SelfUserDetails.java
  22. 35 0
      src/main/java/com/jkcredit/invoice/hub/config/WebConfiguration.java
  23. 14 0
      src/main/java/com/jkcredit/invoice/hub/constant/CommonConstant.java
  24. 12 0
      src/main/java/com/jkcredit/invoice/hub/constant/ExceptionMessage.java
  25. 13 0
      src/main/java/com/jkcredit/invoice/hub/constant/ResponseStatus.java
  26. 44 0
      src/main/java/com/jkcredit/invoice/hub/controller/base/BaseResource.java
  27. 15 0
      src/main/java/com/jkcredit/invoice/hub/controller/base/RestResource.java
  28. 15 0
      src/main/java/com/jkcredit/invoice/hub/controller/base/WebResource.java
  29. 23 0
      src/main/java/com/jkcredit/invoice/hub/controller/rest/forward/ForwardResource.java
  30. 69 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/permission/PermissionResource.java
  31. 20 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/permission/fb/PermissionFB.java
  32. 14 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/permission/fb/PermissionQueryFB.java
  33. 61 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/recharge/RechargeResource.java
  34. 19 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/recharge/fb/RechargeFB.java
  35. 15 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/recharge/fb/RechargeQueryFB.java
  36. 80 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/role/RoleResource.java
  37. 19 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/role/fb/RoleFB.java
  38. 40 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/rolePermission/RolePermissionResource.java
  39. 20 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/rolePermission/fb/RolePermissionFB.java
  40. 101 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/user/UserResource.java
  41. 22 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/user/fb/UpdateUserFB.java
  42. 40 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/user/fb/UserFB.java
  43. 16 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/user/fb/UserQueryFB.java
  44. 43 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/userRolePermission/UserRolePermissionResource.java
  45. 19 0
      src/main/java/com/jkcredit/invoice/hub/controller/web/userRolePermission/fb/UserRolePermissionFB.java
  46. 17 0
      src/main/java/com/jkcredit/invoice/hub/enums/CommonEnumStatus.java
  47. 22 0
      src/main/java/com/jkcredit/invoice/hub/enums/UserStatusEnum.java
  48. 15 0
      src/main/java/com/jkcredit/invoice/hub/enums/UserTypeEnum.java
  49. 23 0
      src/main/java/com/jkcredit/invoice/hub/enums/base/EnumStatus.java
  50. 23 0
      src/main/java/com/jkcredit/invoice/hub/enums/base/IEnumStatus.java
  51. 33 0
      src/main/java/com/jkcredit/invoice/hub/filter/TokenFilter.java
  52. 22 0
      src/main/java/com/jkcredit/invoice/hub/mapper/PermissionMapper.java
  53. 18 0
      src/main/java/com/jkcredit/invoice/hub/mapper/RechargeMapper.java
  54. 22 0
      src/main/java/com/jkcredit/invoice/hub/mapper/RoleMapper.java
  55. 16 0
      src/main/java/com/jkcredit/invoice/hub/mapper/RolePermissionMapper.java
  56. 13 0
      src/main/java/com/jkcredit/invoice/hub/mapper/UserBalanceMapper.java
  57. 18 0
      src/main/java/com/jkcredit/invoice/hub/mapper/UserMapper.java
  58. 13 0
      src/main/java/com/jkcredit/invoice/hub/mapper/UserRolePermissionMapper.java
  59. 15 0
      src/main/java/com/jkcredit/invoice/hub/model/dto/permission/PermissionDto.java
  60. 24 0
      src/main/java/com/jkcredit/invoice/hub/model/dto/recharge/RechargeDto.java
  61. 17 0
      src/main/java/com/jkcredit/invoice/hub/model/dto/role/RoleDto.java
  62. 22 0
      src/main/java/com/jkcredit/invoice/hub/model/dto/rolePermission/RolePermissionDto.java
  63. 27 0
      src/main/java/com/jkcredit/invoice/hub/model/dto/user/UserDto.java
  64. 21 0
      src/main/java/com/jkcredit/invoice/hub/model/dto/userRolePermission/UserRolePermissionDto.java
  65. 32 0
      src/main/java/com/jkcredit/invoice/hub/model/po/permission/PermissionPo.java
  66. 42 0
      src/main/java/com/jkcredit/invoice/hub/model/po/recharge/RechargePo.java
  67. 41 0
      src/main/java/com/jkcredit/invoice/hub/model/po/role/RolePo.java
  68. 32 0
      src/main/java/com/jkcredit/invoice/hub/model/po/rolePermission/RolePermissionPo.java
  69. 24 0
      src/main/java/com/jkcredit/invoice/hub/model/po/user/UserAuthoritiesPo.java
  70. 46 0
      src/main/java/com/jkcredit/invoice/hub/model/po/user/UserPo.java
  71. 32 0
      src/main/java/com/jkcredit/invoice/hub/model/po/userBalance/UserBalancePo.java
  72. 42 0
      src/main/java/com/jkcredit/invoice/hub/model/po/userRolePermission/UserRolePermissionPo.java
  73. 43 0
      src/main/java/com/jkcredit/invoice/hub/model/vo/common/AjaxResponseBody.java
  74. 27 0
      src/main/java/com/jkcredit/invoice/hub/model/vo/common/AppResponseVo.java
  75. 16 0
      src/main/java/com/jkcredit/invoice/hub/model/vo/login/LoginVo.java
  76. 20 0
      src/main/java/com/jkcredit/invoice/hub/model/vo/permission/PermissionVo.java
  77. 29 0
      src/main/java/com/jkcredit/invoice/hub/model/vo/recharge/RechargeVo.java
  78. 19 0
      src/main/java/com/jkcredit/invoice/hub/model/vo/role/RoleVo.java
  79. 52 0
      src/main/java/com/jkcredit/invoice/hub/model/vo/user/UserVO.java
  80. 38 0
      src/main/java/com/jkcredit/invoice/hub/service/base/BaseService.java
  81. 25 0
      src/main/java/com/jkcredit/invoice/hub/service/permission/PermissionService.java
  82. 77 0
      src/main/java/com/jkcredit/invoice/hub/service/permission/PermissionServiceImpl.java
  83. 19 0
      src/main/java/com/jkcredit/invoice/hub/service/recharge/RechargeService.java
  84. 79 0
      src/main/java/com/jkcredit/invoice/hub/service/recharge/RechargeServiceImpl.java
  85. 24 0
      src/main/java/com/jkcredit/invoice/hub/service/role/RoleService.java
  86. 90 0
      src/main/java/com/jkcredit/invoice/hub/service/role/RoleServiceImpl.java
  87. 13 0
      src/main/java/com/jkcredit/invoice/hub/service/rolePermission/RolePermissionService.java
  88. 46 0
      src/main/java/com/jkcredit/invoice/hub/service/rolePermission/RolePermissionServiceImpl.java
  89. 65 0
      src/main/java/com/jkcredit/invoice/hub/service/security/CustomUserDetailsService.java
  90. 23 0
      src/main/java/com/jkcredit/invoice/hub/service/user/UserService.java
  91. 146 0
      src/main/java/com/jkcredit/invoice/hub/service/user/UserServiceImpl.java
  92. 13 0
      src/main/java/com/jkcredit/invoice/hub/service/userRolePermission/UserRolePermissionService.java
  93. 51 0
      src/main/java/com/jkcredit/invoice/hub/service/userRolePermission/UserRolePermissionServiceImpl.java
  94. 17 0
      src/main/java/com/jkcredit/invoice/hub/spi/lang/exception/ServiceException.java
  95. 19 0
      src/main/java/com/jkcredit/invoice/hub/spi/web/data/ApiRequestParam.java
  96. 41 0
      src/main/java/com/jkcredit/invoice/hub/spi/web/data/ResponseData.java
  97. 19 0
      src/main/java/com/jkcredit/invoice/hub/util/AssertUtils.java
  98. 25 0
      src/main/java/com/jkcredit/invoice/hub/util/BeanUtil.java
  99. 15 0
      src/main/java/com/jkcredit/invoice/hub/util/CommonUtil.java
  100. 0 0
      src/main/java/com/jkcredit/invoice/hub/util/EncodeUtil.java

+ 310 - 0
mvnw

@@ -0,0 +1,310 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#    https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+#   JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+#   M2_HOME - location of maven2's installed home dir
+#   MAVEN_OPTS - parameters passed to the Java VM when running Maven
+#     e.g. to debug Maven itself, use
+#       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+#   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+  if [ -f /etc/mavenrc ] ; then
+    . /etc/mavenrc
+  fi
+
+  if [ -f "$HOME/.mavenrc" ] ; then
+    . "$HOME/.mavenrc"
+  fi
+
+fi
+
+# OS specific support.  $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+  CYGWIN*) cygwin=true ;;
+  MINGW*) mingw=true;;
+  Darwin*) darwin=true
+    # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+    if [ -z "$JAVA_HOME" ]; then
+      if [ -x "/usr/libexec/java_home" ]; then
+        export JAVA_HOME="`/usr/libexec/java_home`"
+      else
+        export JAVA_HOME="/Library/Java/Home"
+      fi
+    fi
+    ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+  if [ -r /etc/gentoo-release ] ; then
+    JAVA_HOME=`java-config --jre-home`
+  fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+  ## resolve links - $0 may be a link to maven's home
+  PRG="$0"
+
+  # need this for relative symlinks
+  while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+      PRG="$link"
+    else
+      PRG="`dirname "$PRG"`/$link"
+    fi
+  done
+
+  saveddir=`pwd`
+
+  M2_HOME=`dirname "$PRG"`/..
+
+  # make it fully qualified
+  M2_HOME=`cd "$M2_HOME" && pwd`
+
+  cd "$saveddir"
+  # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --unix "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME="`(cd "$M2_HOME"; pwd)`"
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+  javaExecutable="`which javac`"
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+    # readlink(1) is not available as standard on Solaris 10.
+    readLink=`which readlink`
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+      if $darwin ; then
+        javaHome="`dirname \"$javaExecutable\"`"
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+      else
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
+      fi
+      javaHome="`dirname \"$javaExecutable\"`"
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+      JAVA_HOME="$javaHome"
+      export JAVA_HOME
+    fi
+  fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+  if [ -n "$JAVA_HOME"  ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+      # IBM's JDK on AIX uses strange locations for the executables
+      JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+      JAVACMD="$JAVA_HOME/bin/java"
+    fi
+  else
+    JAVACMD="`which java`"
+  fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+  echo "Error: JAVA_HOME is not defined correctly." >&2
+  echo "  We cannot execute $JAVACMD" >&2
+  exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+  echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+  if [ -z "$1" ]
+  then
+    echo "Path not specified to find_maven_basedir"
+    return 1
+  fi
+
+  basedir="$1"
+  wdir="$1"
+  while [ "$wdir" != '/' ] ; do
+    if [ -d "$wdir"/.mvn ] ; then
+      basedir=$wdir
+      break
+    fi
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+    if [ -d "${wdir}" ]; then
+      wdir=`cd "$wdir/.."; pwd`
+    fi
+    # end of workaround
+  done
+  echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+  if [ -f "$1" ]; then
+    echo "$(tr -s '\n' ' ' < "$1")"
+  fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+  exit 1;
+fi
+
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Found .mvn/wrapper/maven-wrapper.jar"
+    fi
+else
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+    fi
+    if [ -n "$MVNW_REPOURL" ]; then
+      jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+    else
+      jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+    fi
+    while IFS="=" read key value; do
+      case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+      esac
+    done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Downloading from: $jarUrl"
+    fi
+    wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+    if $cygwin; then
+      wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
+    fi
+
+    if command -v wget > /dev/null; then
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Found wget ... using wget"
+        fi
+        if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+            wget "$jarUrl" -O "$wrapperJarPath"
+        else
+            wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
+        fi
+    elif command -v curl > /dev/null; then
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Found curl ... using curl"
+        fi
+        if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+            curl -o "$wrapperJarPath" "$jarUrl" -f
+        else
+            curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
+        fi
+        
+    else
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Falling back to using Java to download"
+        fi
+        javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+        # For Cygwin, switch paths to Windows format before running javac
+        if $cygwin; then
+          javaClass=`cygpath --path --windows "$javaClass"`
+        fi
+        if [ -e "$javaClass" ]; then
+            if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+                if [ "$MVNW_VERBOSE" = true ]; then
+                  echo " - Compiling MavenWrapperDownloader.java ..."
+                fi
+                # Compiling the Java class
+                ("$JAVA_HOME/bin/javac" "$javaClass")
+            fi
+            if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+                # Running the downloader
+                if [ "$MVNW_VERBOSE" = true ]; then
+                  echo " - Running MavenWrapperDownloader.java ..."
+                fi
+                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+            fi
+        fi
+    fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+if [ "$MVNW_VERBOSE" = true ]; then
+  echo $MAVEN_PROJECTBASEDIR
+fi
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+  $MAVEN_OPTS \
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 182 - 0
mvnw.cmd

@@ -0,0 +1,182 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements.  See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership.  The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License.  You may obtain a copy of the License at
+@REM
+@REM    https://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied.  See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven2 Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM     e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM set title of command window
+title %0
+@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on"  echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+
+FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
+    IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+    if "%MVNW_VERBOSE%" == "true" (
+        echo Found %WRAPPER_JAR%
+    )
+) else (
+    if not "%MVNW_REPOURL%" == "" (
+        SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+    )
+    if "%MVNW_VERBOSE%" == "true" (
+        echo Couldn't find %WRAPPER_JAR%, downloading it ...
+        echo Downloading from: %DOWNLOAD_URL%
+    )
+
+    powershell -Command "&{"^
+		"$webclient = new-object System.Net.WebClient;"^
+		"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
+		"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
+		"}"^
+		"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
+		"}"
+    if "%MVNW_VERBOSE%" == "true" (
+        echo Finished downloading %WRAPPER_JAR%
+    )
+)
+@REM End of extension
+
+@REM Provide a "standardized" way to retrieve the CLI args that will
+@REM work with both Windows and non-Windows executions.
+set MAVEN_CMD_LINE_ARGS=%*
+
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
+
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
+
+exit /B %ERROR_CODE%

+ 146 - 0
pom.xml

@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.2.2.RELEASE</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.jkcredit</groupId>
+    <artifactId>invoice-hub</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>invoice-hub</name>
+    <description>Demo project for Spring Boot</description>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <fluent-validator.version>1.0.9</fluent-validator.version>
+        <mybatis-plus.version>3.1.0</mybatis-plus.version>
+        <model-mapper.version>2.3.0</model-mapper.version>
+        <zalando.version>0.23.0</zalando.version>
+        <fastjson.version>1.2.51</fastjson.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-quartz</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-security</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-thymeleaf</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>2.1.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.junit.vintage</groupId>
+                    <artifactId>junit-vintage-engine</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.amqp</groupId>
+            <artifactId>spring-rabbit-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.security</groupId>
+            <artifactId>spring-security-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.baidu.unbiz</groupId>
+            <artifactId>fluent-validator-jsr303</artifactId>
+            <version>${fluent-validator.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.modelmapper</groupId>
+            <artifactId>modelmapper</artifactId>
+            <version>${model-mapper.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>${mybatis-plus.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.zalando</groupId>
+            <artifactId>problem-spring-web</artifactId>
+            <version>${zalando.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>${fastjson.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt</artifactId>
+            <version>0.9.0</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-beanutils</groupId>
+            <artifactId>commons-beanutils</artifactId>
+            <version>1.9.4</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 16 - 0
src/main/java/com/jkcredit/invoice/hub/InvoiceHubApplication.java

@@ -0,0 +1,16 @@
+package com.jkcredit.invoice.hub;
+
+import com.jkcredit.invoice.hub.config.ApplicationProperties;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+
+@EnableConfigurationProperties(ApplicationProperties.class)
+@SpringBootApplication
+public class InvoiceHubApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(InvoiceHubApplication.class, args);
+    }
+
+}

+ 38 - 0
src/main/java/com/jkcredit/invoice/hub/config/AccessControlAllowOriginFilter.java

@@ -0,0 +1,38 @@
+package com.jkcredit.invoice.hub.config;
+
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 14:09
+ * @version: V1.0
+ **/
+@Component
+public class AccessControlAllowOriginFilter implements Filter {
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+        HttpServletResponse response = (HttpServletResponse) servletResponse;
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.setHeader("Access-Control-Allow-Credentials", "true");
+        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, DELETE, PUT");
+        response.setHeader("Access-Control-Max-Age", "3600");
+        response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
+        filterChain.doFilter(servletRequest, response);
+    }
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+
+    }
+
+    @Override
+    public void destroy() {
+
+    }
+}

+ 24 - 0
src/main/java/com/jkcredit/invoice/hub/config/AjaxAccessDeniedHandler.java

@@ -0,0 +1,24 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.alibaba.fastjson.JSON;
+import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.web.access.AccessDeniedHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Component
+public class AjaxAccessDeniedHandler implements AccessDeniedHandler {
+
+    @Override
+    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
+        httpServletResponse.setContentType("application/json;charset=UTF-8");
+        httpServletResponse.setContentType("application/json");
+        httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
+        httpServletResponse.getWriter().write(JSON.toJSONString(new AppResponseVo(403, "无权限", "")));
+    }
+}

+ 25 - 0
src/main/java/com/jkcredit/invoice/hub/config/AjaxAuthenticationEntryPoint.java

@@ -0,0 +1,25 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.alibaba.fastjson.JSON;
+import com.jkcredit.invoice.hub.model.vo.common.AjaxResponseBody;
+import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Component
+public class AjaxAuthenticationEntryPoint implements AuthenticationEntryPoint {
+
+    @Override
+    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
+        httpServletResponse.setContentType("application/json;charset=UTF-8");
+        httpServletResponse.setContentType("application/json");
+        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+        httpServletResponse.getWriter().write(JSON.toJSONString(new AppResponseVo(401, "未登录", "")));
+    }
+}

+ 35 - 0
src/main/java/com/jkcredit/invoice/hub/config/AjaxAuthenticationFailureHandler.java

@@ -0,0 +1,35 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.alibaba.fastjson.JSON;
+import com.jkcredit.invoice.hub.model.vo.common.AjaxResponseBody;
+import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Component
+public class AjaxAuthenticationFailureHandler implements AuthenticationFailureHandler {
+
+    @Override
+    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
+        // todo
+        /**
+         * if (e instanceof UsernameNotFoundException || e instanceof BadCredentialsException) {
+         *                 map.put("message","用户名或密码错误");
+         *             } else if (e instanceof DisabledException) {
+         *                 map.put("message","账户被禁用");
+         *             } else {
+         *                 map.put("message","登录失败!");
+         *             }
+         */
+        httpServletResponse.setContentType("application/json;charset=UTF-8");
+        httpServletResponse.setContentType("application/json");
+        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
+        httpServletResponse.getWriter().write(JSON.toJSONString(new AppResponseVo(500, "用户名或密码错误", "")));
+    }
+}

+ 35 - 0
src/main/java/com/jkcredit/invoice/hub/config/AjaxAuthenticationSuccessHandler.java

@@ -0,0 +1,35 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.alibaba.fastjson.JSON;
+import com.jkcredit.invoice.hub.model.vo.common.AjaxResponseBody;
+import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
+import com.jkcredit.invoice.hub.util.JwtTokenUtil;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class AjaxAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
+
+    @Override
+    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
+        SelfUserDetails userDetails = (SelfUserDetails) authentication.getPrincipal();
+
+        String jwtToken = JwtTokenUtil.generateToken(userDetails.getUsername(), 3600 * 24, "_secret");
+        Map<String, String> result = new HashMap<>();
+        result.put("token", jwtToken);
+
+        httpServletResponse.setContentType("application/json;charset=UTF-8");
+        httpServletResponse.setContentType("application/json");
+        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
+        httpServletResponse.getWriter().write(JSON.toJSONString(new AppResponseVo(200, "登录成功", result)));
+    }
+}
+

+ 25 - 0
src/main/java/com/jkcredit/invoice/hub/config/AjaxLogoutSuccessHandler.java

@@ -0,0 +1,25 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.alibaba.fastjson.JSON;
+import com.jkcredit.invoice.hub.model.vo.common.AjaxResponseBody;
+import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Component
+public class AjaxLogoutSuccessHandler implements LogoutSuccessHandler {
+
+    @Override
+    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
+        httpServletResponse.setContentType("application/json;charset=UTF-8");
+        httpServletResponse.setContentType("application/json");
+        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
+        httpServletResponse.getWriter().write(JSON.toJSONString(new AppResponseVo(200, "登出成功", "")));
+    }
+}

+ 65 - 0
src/main/java/com/jkcredit/invoice/hub/config/ApplicationDefaults.java

@@ -0,0 +1,65 @@
+package com.jkcredit.invoice.hub.config;
+
+public interface ApplicationDefaults {
+
+    interface Security {
+
+        interface ClientAuthorization {
+
+            String accessTokenUri = null;
+            String tokenServiceId = null;
+            String clientId = null;
+            String clientSecret = null;
+        }
+
+        interface Authentication {
+
+            interface Jwt {
+
+                String secret = null;
+                long tokenValidityInSeconds = 1800; // 0.5 hour
+                long tokenValidityInSecondsForRememberMe = 2592000; // 30 hours;
+            }
+        }
+
+        interface RememberMe {
+
+            String key = null;
+        }
+    }
+
+    interface Logging {
+
+        interface Logstash {
+
+            boolean enabled = false;
+            String host = "localhost";
+            int port = 5000;
+            int queueSize = 512;
+        }
+    }
+
+    interface Aliyun {
+
+        interface Sms {
+
+            String product = "Dysmsapi";
+            String domain = "dysmsapi.aliyuncs.com";
+            String accessKey = null;
+            String accessSecret = null;
+            String signName = null;
+
+            interface Templates {
+                String register = null;
+                String login = null;
+            }
+        }
+    }
+
+    interface Async {
+
+        int corePoolSize = 2;
+        int maxPoolSize = 50;
+        int queueCapacity = 10000;
+    }
+}

+ 331 - 0
src/main/java/com/jkcredit/invoice/hub/config/ApplicationProperties.java

@@ -0,0 +1,331 @@
+package com.jkcredit.invoice.hub.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.web.cors.CorsConfiguration;
+
+import javax.validation.constraints.NotNull;
+
+@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
+public class ApplicationProperties {
+
+    private final Security security = new Security();
+    private final CorsConfiguration cors = new CorsConfiguration();
+    private final Logging logging = new Logging();
+    private final Aliyun aliyun = new Aliyun();
+    private final Async async = new Async();
+
+    public Security getSecurity() {
+        return security;
+    }
+
+    public CorsConfiguration getCors() {
+        return cors;
+    }
+
+    public Logging getLogging() {
+        return logging;
+    }
+
+    public Aliyun getAliyun() {
+        return aliyun;
+    }
+
+    public Async getAsync() {
+        return async;
+    }
+
+    public static class Security {
+
+        private final ClientAuthorization clientAuthorization = new ClientAuthorization();
+
+        private final Authentication authentication = new Authentication();
+
+        private final RememberMe rememberMe = new RememberMe();
+
+        public ClientAuthorization getClientAuthorization() {
+            return clientAuthorization;
+        }
+
+        public Authentication getAuthentication() {
+            return authentication;
+        }
+
+        public RememberMe getRememberMe() {
+            return rememberMe;
+        }
+
+        public static class ClientAuthorization {
+
+            private String accessTokenUri = ApplicationDefaults.Security.ClientAuthorization.accessTokenUri;
+
+            private String tokenServiceId = ApplicationDefaults.Security.ClientAuthorization.tokenServiceId;
+
+            private String clientId = ApplicationDefaults.Security.ClientAuthorization.clientId;
+
+            private String clientSecret = ApplicationDefaults.Security.ClientAuthorization.clientSecret;
+
+            public String getAccessTokenUri() {
+                return accessTokenUri;
+            }
+
+            public void setAccessTokenUri(String accessTokenUri) {
+                this.accessTokenUri = accessTokenUri;
+            }
+
+            public String getTokenServiceId() {
+                return tokenServiceId;
+            }
+
+            public void setTokenServiceId(String tokenServiceId) {
+                this.tokenServiceId = tokenServiceId;
+            }
+
+            public String getClientId() {
+                return clientId;
+            }
+
+            public void setClientId(String clientId) {
+                this.clientId = clientId;
+            }
+
+            public String getClientSecret() {
+                return clientSecret;
+            }
+
+            public void setClientSecret(String clientSecret) {
+                this.clientSecret = clientSecret;
+            }
+        }
+
+        public static class Authentication {
+
+            private final Jwt jwt = new Jwt();
+
+            public Jwt getJwt() {
+                return jwt;
+            }
+
+            public static class Jwt {
+
+                private String secret = ApplicationDefaults.Security.Authentication.Jwt.secret;
+
+                private long tokenValidityInSeconds = ApplicationDefaults.Security.Authentication.Jwt
+                        .tokenValidityInSeconds;
+
+                private long tokenValidityInSecondsForRememberMe = ApplicationDefaults.Security.Authentication.Jwt
+                        .tokenValidityInSecondsForRememberMe;
+
+                public String getSecret() {
+                    return secret;
+                }
+
+                public void setSecret(String secret) {
+                    this.secret = secret;
+                }
+
+                public long getTokenValidityInSeconds() {
+                    return tokenValidityInSeconds;
+                }
+
+                public void setTokenValidityInSeconds(long tokenValidityInSeconds) {
+                    this.tokenValidityInSeconds = tokenValidityInSeconds;
+                }
+
+                public long getTokenValidityInSecondsForRememberMe() {
+                    return tokenValidityInSecondsForRememberMe;
+                }
+
+                public void setTokenValidityInSecondsForRememberMe(long tokenValidityInSecondsForRememberMe) {
+                    this.tokenValidityInSecondsForRememberMe = tokenValidityInSecondsForRememberMe;
+                }
+            }
+        }
+
+        public static class RememberMe {
+
+            @NotNull
+            private String key = ApplicationDefaults.Security.RememberMe.key;
+
+            public String getKey() {
+                return key;
+            }
+
+            public void setKey(String key) {
+                this.key = key;
+            }
+        }
+    }
+
+    public static class Logging {
+
+        private final Logstash logstash = new Logstash();
+
+        public Logstash getLogstash() {
+            return logstash;
+        }
+
+        public static class Logstash {
+
+            private boolean enabled = ApplicationDefaults.Logging.Logstash.enabled;
+
+            private String host = ApplicationDefaults.Logging.Logstash.host;
+
+            private int port = ApplicationDefaults.Logging.Logstash.port;
+
+            private int queueSize = ApplicationDefaults.Logging.Logstash.queueSize;
+
+            public boolean isEnabled() {
+                return enabled;
+            }
+
+            public void setEnabled(boolean enabled) {
+                this.enabled = enabled;
+            }
+
+            public String getHost() {
+                return host;
+            }
+
+            public void setHost(String host) {
+                this.host = host;
+            }
+
+            public int getPort() {
+                return port;
+            }
+
+            public void setPort(int port) {
+                this.port = port;
+            }
+
+            public int getQueueSize() {
+                return queueSize;
+            }
+
+            public void setQueueSize(int queueSize) {
+                this.queueSize = queueSize;
+            }
+        }
+    }
+
+    public static class Aliyun {
+        private final Sms sms = new Sms();
+
+        public Sms getSms() {
+            return sms;
+        }
+
+        public static class Sms {
+            // 短信API产品名称
+            private String product = ApplicationDefaults.Aliyun.Sms.product;
+            // 短信API产品域名
+            private String domain = ApplicationDefaults.Aliyun.Sms.domain;
+
+            private String accessKey = ApplicationDefaults.Aliyun.Sms.accessKey;
+
+            private String accessSecret = ApplicationDefaults.Aliyun.Sms.accessSecret;
+
+            private String signName = ApplicationDefaults.Aliyun.Sms.signName;
+
+            private final Templates templates = new Templates();
+
+            public String getProduct() {
+                return product;
+            }
+
+            public void setProduct(String product) {
+                this.product = product;
+            }
+
+            public String getDomain() {
+                return domain;
+            }
+
+            public void setDomain(String domain) {
+                this.domain = domain;
+            }
+
+            public String getAccessKey() {
+                return accessKey;
+            }
+
+            public void setAccessKey(String accessKey) {
+                this.accessKey = accessKey;
+            }
+
+            public String getAccessSecret() {
+                return accessSecret;
+            }
+
+            public void setAccessSecret(String accessSecret) {
+                this.accessSecret = accessSecret;
+            }
+
+            public String getSignName() {
+                return signName;
+            }
+
+            public void setSignName(String signName) {
+                this.signName = signName;
+            }
+
+            public Templates getTemplates() {
+                return templates;
+            }
+
+            public static class Templates {
+                private String register = ApplicationDefaults.Aliyun.Sms.Templates.register;
+                private String login = ApplicationDefaults.Aliyun.Sms.Templates.login;
+
+                public String getRegister() {
+                    return register;
+                }
+
+                public void setRegister(String register) {
+                    this.register = register;
+                }
+
+                public String getLogin() {
+                    return login;
+                }
+
+                public void setLogin(String login) {
+                    this.login = login;
+                }
+            }
+        }
+    }
+
+    public static class Async {
+
+        private int corePoolSize = ApplicationDefaults.Async.corePoolSize;
+
+        private int maxPoolSize = ApplicationDefaults.Async.maxPoolSize;
+
+        private int queueCapacity = ApplicationDefaults.Async.queueCapacity;
+
+        public int getCorePoolSize() {
+            return corePoolSize;
+        }
+
+        public void setCorePoolSize(int corePoolSize) {
+            this.corePoolSize = corePoolSize;
+        }
+
+        public int getMaxPoolSize() {
+            return maxPoolSize;
+        }
+
+        public void setMaxPoolSize(int maxPoolSize) {
+            this.maxPoolSize = maxPoolSize;
+        }
+
+        public int getQueueCapacity() {
+            return queueCapacity;
+        }
+
+        public void setQueueCapacity(int queueCapacity) {
+            this.queueCapacity = queueCapacity;
+        }
+    }
+}

+ 36 - 0
src/main/java/com/jkcredit/invoice/hub/config/AuthenticationEntryPointHandler.java

@@ -0,0 +1,36 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.alibaba.fastjson.JSON;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 21:30
+ * @version: V1.0
+ **/
+@Component
+public class AuthenticationEntryPointHandler implements AuthenticationEntryPoint {
+    @Override
+    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
+        response.setContentType("application/json;charset=utf-8");
+        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
+        PrintWriter out = response.getWriter();
+        Map<String, Object> map = new HashMap<>();
+        map.put("code", 403);
+        map.put("message", "未登录");
+        out.write(JSON.toJSONString(map));
+        out.flush();
+        out.close();
+    }
+}

+ 31 - 0
src/main/java/com/jkcredit/invoice/hub/config/ControllerAdvice.java

@@ -0,0 +1,31 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.jkcredit.invoice.hub.constant.CommonConstant;
+import com.jkcredit.invoice.hub.constant.ResponseStatus;
+import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import java.util.Collections;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/9 21:29
+ * @version: V1.0
+ **/
+@Slf4j
+@RestControllerAdvice
+public class ControllerAdvice {
+
+    @ExceptionHandler(value = Exception.class)
+    public ResponseEntity<AppResponseVo> errorHandler(ServiceException ex) {
+        return ResponseEntity.ok(new AppResponseVo(ResponseStatus.FAILED, ex.getMessage(), null));
+    }
+
+}

+ 31 - 0
src/main/java/com/jkcredit/invoice/hub/config/CorsConfig.java

@@ -0,0 +1,31 @@
+package com.jkcredit.invoice.hub.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 13:42
+ * @version: V1.0
+ **/
+@Configuration
+public class CorsConfig {
+    private CorsConfiguration buildConfig() {
+        CorsConfiguration corsConfiguration = new CorsConfiguration();
+        corsConfiguration.addAllowedOrigin("*"); //允许任何域名
+        corsConfiguration.addAllowedHeader("*"); //允许任何头
+        corsConfiguration.addAllowedMethod("*"); //允许任何方法
+        return corsConfiguration;
+    }
+
+    @Bean
+    public CorsFilter corsFilter() {
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+        source.registerCorsConfiguration("/**", buildConfig()); //注册
+        return new CorsFilter(source);
+    }
+}

+ 50 - 0
src/main/java/com/jkcredit/invoice/hub/config/JwtAuthenticationTokenFilter.java

@@ -0,0 +1,50 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.jkcredit.invoice.hub.service.security.CustomUserDetailsService;
+import com.jkcredit.invoice.hub.util.JwtTokenUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Slf4j
+@Component
+public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
+
+    @Autowired
+    CustomUserDetailsService userDetailsService;
+
+    @Override
+    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
+        String authHeader = request.getHeader("Authorization");
+        // todo token失效未正确返回,token过期username为null
+        if (authHeader != null && authHeader.startsWith("Bearer ")) {
+            final String authToken = authHeader.substring("Bearer ".length());
+
+            String username = JwtTokenUtil.parseToken(authToken, "_secret");
+
+            if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
+                UserDetails userDetails = userDetailsService.loadUserByUsername(username);
+
+                if (userDetails != null) {
+                    UsernamePasswordAuthenticationToken authentication =
+                            new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
+                    authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
+
+                    SecurityContextHolder.getContext().setAuthentication(authentication);
+                }
+            }
+        }
+        chain.doFilter(request, response);
+    }
+}

+ 35 - 0
src/main/java/com/jkcredit/invoice/hub/config/MyPermissionEvaluator.java

@@ -0,0 +1,35 @@
+package com.jkcredit.invoice.hub.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.access.PermissionEvaluator;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/8 23:20
+ * @version: V1.0
+ **/
+@Configuration
+public class MyPermissionEvaluator implements PermissionEvaluator {
+    @Override
+    public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
+        boolean accessible = false;
+        String privilege = targetDomainObject + ":" + permission;
+        for (GrantedAuthority authority : authentication.getAuthorities()) {
+            if (privilege.equalsIgnoreCase(authority.getAuthority())) {
+                accessible = true;
+                break;
+            }
+        }
+        return accessible;
+    }
+
+    @Override
+    public boolean hasPermission(Authentication authentication, Serializable serializable, String s, Object o) {
+        return false;
+    }
+}

+ 39 - 0
src/main/java/com/jkcredit/invoice/hub/config/MybatisPlusConfigurer.java

@@ -0,0 +1,39 @@
+package com.jkcredit.invoice.hub.config;
+
+import com.baomidou.mybatisplus.core.injector.ISqlInjector;
+import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2019/2/28 9:06 AM
+ * @version: V1.0
+ **/
+@Configuration
+@MapperScan("com.jkcredit.invoice.hub.mapper")
+public class MybatisPlusConfigurer {
+    /**
+     * 分页插件
+     *
+     * @return PaginationInterceptor
+     */
+    @Bean
+    public PaginationInterceptor paginationInterceptor() {
+        return new PaginationInterceptor();
+    }
+
+
+    /**
+     * 逻辑删除
+     *
+     * @return
+     */
+    @Bean
+    public ISqlInjector sqlInjector() {
+        return new LogicSqlInjector();
+    }
+}

+ 42 - 0
src/main/java/com/jkcredit/invoice/hub/config/RbacAuthorityService.java

@@ -0,0 +1,42 @@
+package com.jkcredit.invoice.hub.config;
+
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.stereotype.Component;
+import org.springframework.util.AntPathMatcher;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashSet;
+import java.util.Set;
+
+@Component("rbacauthorityservice")
+public class RbacAuthorityService {
+    public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
+
+        Object userInfo = authentication.getPrincipal();
+
+        boolean hasPermission = false;
+
+        if (userInfo instanceof UserDetails) {
+
+            String username = ((UserDetails) userInfo).getUsername();
+
+            //获取资源
+            Set<String> urls = new HashSet();
+            urls.add("/app/**"); // 这些 url 都是要登录后才能访问,且其他的 url 都不能访问!
+
+            AntPathMatcher antPathMatcher = new AntPathMatcher();
+
+            for (String url : urls) {
+                if (antPathMatcher.match(url, request.getRequestURI())) {
+                    hasPermission = true;
+                    break;
+                }
+            }
+
+            return hasPermission;
+        } else {
+            return false;
+        }
+    }
+}

+ 156 - 0
src/main/java/com/jkcredit/invoice/hub/config/SecurityConfiguration.java

@@ -0,0 +1,156 @@
+package com.jkcredit.invoice.hub.config;
+
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+import org.springframework.web.filter.CorsFilter;
+import org.zalando.problem.spring.web.advice.security.SecurityProblemSupport;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/3 10:14
+ * @version: V1.0
+ **/
+@EnableWebSecurity
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+@Import(SecurityProblemSupport.class)
+public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
+    @Autowired
+    AjaxAuthenticationEntryPoint authenticationEntryPoint;  //  未登陆时返回 JSON 格式的数据给前端(否则为 html)
+
+    @Autowired
+    AjaxAuthenticationSuccessHandler authenticationSuccessHandler;  // 登录成功返回的 JSON 格式数据给前端(否则为 html)
+
+    @Autowired
+    AjaxAuthenticationFailureHandler authenticationFailureHandler;  //  登录失败返回的 JSON 格式数据给前端(否则为 html)
+
+    @Autowired
+    AjaxLogoutSuccessHandler logoutSuccessHandler;  // 注销成功返回的 JSON 格式数据给前端(否则为 登录时的 html)
+
+    @Autowired
+    AjaxAccessDeniedHandler accessDeniedHandler;    // 无权访问返回的 JSON 格式数据给前端(否则为 403 html 页面)
+
+    @Autowired
+    JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter; // JWT 拦截器
+
+    private final UserDetailsService userDetailsService;
+    private final AuthenticationManagerBuilder authenticationManagerBuilder;
+    private final AuthenticationEntryPointHandler authenticationEntryPointHandler;
+    private final CorsFilter corsFilter;
+
+    public SecurityConfiguration(UserDetailsService userDetailsService, AuthenticationManagerBuilder authenticationManagerBuilder,
+                                 AuthenticationEntryPointHandler authenticationEntryPointHandler,
+                                 CorsFilter corsFilter) {
+        this.userDetailsService = userDetailsService;
+        this.authenticationManagerBuilder = authenticationManagerBuilder;
+        this.authenticationEntryPointHandler = authenticationEntryPointHandler;
+        this.corsFilter = corsFilter;
+    }
+
+    @PostConstruct
+    public void init() {
+        try {
+            authenticationManagerBuilder
+                    .userDetailsService(userDetailsService)
+                    .passwordEncoder(passwordEncoder());
+        } catch (Exception e) {
+            throw new BeanInitializationException("Security configuration failed", e);
+        }
+    }
+
+    @Bean
+    @Override
+    public AuthenticationManager authenticationManagerBean() throws Exception {
+        return super.authenticationManagerBean();
+    }
+
+    // 此处需要使用@Bean引入,作用不是为了上面方法中使用
+    // 作用在于使用@Bean将PasswordEncoder作为Bean引入
+    // 同时此方法也可以指定加密方式
+    @Bean
+    public PasswordEncoder passwordEncoder() {
+        return new BCryptPasswordEncoder();
+    }
+
+    @Override
+    protected void configure(HttpSecurity http) throws Exception {
+
+        // 去掉 CSRF
+        http.csrf().disable()
+                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 使用 JWT,关闭token
+                .and()
+
+                .httpBasic().authenticationEntryPoint(authenticationEntryPoint)
+
+                .and()
+                .authorizeRequests()
+                .antMatchers("/api/**").permitAll()
+
+                .anyRequest()
+                .access("@rbacauthorityservice.hasPermission(request,authentication)") // RBAC 动态 url 认证
+
+                .and()
+                .formLogin()  //开启登录
+                .successHandler(authenticationSuccessHandler) // 登录成功
+                .failureHandler(authenticationFailureHandler) // 登录失败
+                .permitAll()
+
+                .and()
+                .logout()
+                .logoutSuccessHandler(logoutSuccessHandler)
+                .permitAll();
+
+        // 记住我
+        http.rememberMe().rememberMeParameter("remember-me")
+                .userDetailsService(userDetailsService).tokenValiditySeconds(3600);
+
+        http.exceptionHandling().accessDeniedHandler(accessDeniedHandler); // 无权访问 JSON 格式的数据
+        http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); // JWT Filter
+
+    }
+
+//    @Override
+//    protected void configure(HttpSecurity http) throws Exception {
+//        http
+//                .exceptionHandling()
+//                .authenticationEntryPoint(authenticationEntryPointHandler)
+//                .and()
+//                .csrf().disable()//禁用了 csrf 功能
+//                .authorizeRequests()//限定签名成功的请求
+//                .antMatchers("/api/**").permitAll()//不拦截 oauth 开放的资源
+//                .anyRequest().authenticated()// 其他请求进行拦截
+//                .and()
+//                .formLogin()
+//                .loginProcessingUrl("/login")//使用 spring security 默认登录页面
+//                .successHandler(customAuthenticationSuccess)
+//                .failureHandler(customAuthenticationFailure)
+//                .permitAll()
+//                .and()
+//                .logout()
+//                .logoutUrl("/logout")
+//                .permitAll();
+//    }
+
+    @Override
+    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+        auth
+                .userDetailsService(userDetailsService)
+                .passwordEncoder(passwordEncoder());
+    }
+}

+ 55 - 0
src/main/java/com/jkcredit/invoice/hub/config/SelfUserDetails.java

@@ -0,0 +1,55 @@
+package com.jkcredit.invoice.hub.config;
+
+import lombok.Data;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * ① 定义 user 对象
+ */
+@Data
+public class SelfUserDetails implements UserDetails {
+    private String username;
+    private String password;
+    private Collection<? extends GrantedAuthority> authorities;
+
+    @Override
+    public Collection<? extends GrantedAuthority> getAuthorities() {
+        return this.authorities;
+    }
+
+    @Override
+    public String getPassword() {
+        return this.password;
+    }
+
+    @Override
+    public String getUsername() {
+        return this.username;
+    }
+
+    @Override
+    public boolean isAccountNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isAccountNonLocked() {
+        return true;
+    }
+
+    @Override
+    public boolean isCredentialsNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+}

+ 35 - 0
src/main/java/com/jkcredit/invoice/hub/config/WebConfiguration.java

@@ -0,0 +1,35 @@
+package com.jkcredit.invoice.hub.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+@Configuration
+public class WebConfiguration {
+
+    private final Logger log = LoggerFactory.getLogger(WebConfiguration.class);
+
+    private final ApplicationProperties applicationProperties;
+
+    public WebConfiguration(ApplicationProperties applicationProperties) {
+        this.applicationProperties = applicationProperties;
+    }
+
+//    @Bean
+//    public CorsFilter corsFilter() {
+//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+//        CorsConfiguration config = applicationProperties.getCors();
+//        if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
+//            log.info("Registering CORS filter");
+//            source.registerCorsConfiguration("/api/**", config);
+//            source.registerCorsConfiguration("/management/**", config);
+//            source.registerCorsConfiguration("/v2/api-docs", config);
+//        }
+//        return new CorsFilter(source);
+//    }
+
+}

+ 14 - 0
src/main/java/com/jkcredit/invoice/hub/constant/CommonConstant.java

@@ -0,0 +1,14 @@
+package com.jkcredit.invoice.hub.constant;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 22:34
+ * @version: V1.0
+ **/
+public class CommonConstant {
+    public static String MESSAGE_SUCCESS = "成功";
+    public static String MESSAGE_FAILED = "失败";
+    public static String USER_NOT_EXIST = "用户不存在";
+    public static Integer ACTIVATED_DELETED = 2;
+}

+ 12 - 0
src/main/java/com/jkcredit/invoice/hub/constant/ExceptionMessage.java

@@ -0,0 +1,12 @@
+package com.jkcredit.invoice.hub.constant;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 22:35
+ * @version: V1.0
+ **/
+public class ExceptionMessage {
+    public static String USER_NOT_EXIST = "用户不存在";
+    public static String ROLE_NOT_EXIST = "用户不存在";
+}

+ 13 - 0
src/main/java/com/jkcredit/invoice/hub/constant/ResponseStatus.java

@@ -0,0 +1,13 @@
+package com.jkcredit.invoice.hub.constant;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 22:51
+ * @version: V1.0
+ **/
+public class ResponseStatus {
+    public static Integer SUCCESS = 1;
+    public static Integer FAILED = 0;
+    public static Integer NOT_FOUND = 3;
+}

+ 44 - 0
src/main/java/com/jkcredit/invoice/hub/controller/base/BaseResource.java

@@ -0,0 +1,44 @@
+package com.jkcredit.invoice.hub.controller.base;
+
+import com.baidu.unbiz.fluentvalidator.FluentValidator;
+import com.baidu.unbiz.fluentvalidator.Result;
+import com.baidu.unbiz.fluentvalidator.jsr303.HibernateSupportedValidator;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import org.modelmapper.ModelMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.annotation.PostConstruct;
+import javax.validation.Validator;
+
+import static com.baidu.unbiz.fluentvalidator.ResultCollectors.toSimple;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2019/12/29 20:23
+ * @version: V1.0
+ **/
+public class BaseResource {
+
+    @Autowired
+    private Validator validator;
+
+    protected ModelMapper mapper;
+
+    protected <T> void validate(T fb) {
+        // todo 目前校验返回格式不对,字段不存在才返回,需要增加正则非空判断
+        Result result = FluentValidator.checkAll()
+                .on(fb, new HibernateSupportedValidator<T>().setHiberanteValidator(validator))
+                .doValidate()
+                .result(toSimple());
+
+        if (!result.isSuccess()) {
+            throw new ServiceException(result.getErrors().toString());
+        }
+    }
+
+    @PostConstruct
+    protected void initMapper() {
+        mapper = new ModelMapper();
+    }
+}

+ 15 - 0
src/main/java/com/jkcredit/invoice/hub/controller/base/RestResource.java

@@ -0,0 +1,15 @@
+package com.jkcredit.invoice.hub.controller.base;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2019/12/29 20:34
+ * @version: V1.0
+ **/
+@Slf4j
+@RequestMapping("/api")
+public class RestResource extends BaseResource {
+}

+ 15 - 0
src/main/java/com/jkcredit/invoice/hub/controller/base/WebResource.java

@@ -0,0 +1,15 @@
+package com.jkcredit.invoice.hub.controller.base;
+
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2019/12/29 20:23
+ * @version: V1.0
+ **/
+@RequestMapping("/app")
+public class WebResource extends BaseResource {
+
+}

+ 23 - 0
src/main/java/com/jkcredit/invoice/hub/controller/rest/forward/ForwardResource.java

@@ -0,0 +1,23 @@
+package com.jkcredit.invoice.hub.controller.rest.forward;
+
+import com.jkcredit.invoice.hub.controller.base.RestResource;
+import com.jkcredit.invoice.hub.spi.web.data.ApiRequestParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 18:20
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class ForwardResource extends RestResource {
+    @PostMapping("/rest")
+    public void forwardRequest(@RequestBody ApiRequestParam param) {
+        log.info(param.toString());
+    }
+}

+ 69 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/permission/PermissionResource.java

@@ -0,0 +1,69 @@
+package com.jkcredit.invoice.hub.controller.web.permission;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.controller.base.WebResource;
+import com.jkcredit.invoice.hub.controller.web.permission.fb.PermissionFB;
+import com.jkcredit.invoice.hub.controller.web.permission.fb.PermissionQueryFB;
+import com.jkcredit.invoice.hub.model.dto.permission.PermissionDto;
+import com.jkcredit.invoice.hub.model.vo.permission.PermissionVo;
+import com.jkcredit.invoice.hub.service.permission.PermissionService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.spi.web.data.ResponseData;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 16:03
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class PermissionResource extends WebResource {
+    @Autowired
+    PermissionService permissionService;
+
+    @PreAuthorize("hasPermission('permission','read')")
+    @GetMapping("/page/permissions")
+    public ResponseData getPermissions(Page page, PermissionQueryFB queryFB) {
+        try {
+            PermissionDto permissionDto = mapper.map(queryFB, PermissionDto.class);
+            IPage<PermissionVo> permissions = permissionService.getPermissions(page, permissionDto);
+            return ResponseData.success(permissions);
+        } catch (ServiceException e) {
+            return ResponseData.failed("获取权限列表失败");
+        }
+    }
+
+    @PreAuthorize("hasPermission('permission','edit')")
+    @PostMapping("/permission")
+    public ResponseData savePermission(PermissionFB permissionFB) {
+        try {
+            validate(permissionFB);
+            PermissionDto permissionDto = mapper.map(permissionFB, PermissionDto.class);
+            permissionService.savePermission(permissionDto);
+            return ResponseData.success("新增权限成功");
+        } catch (ServiceException e) {
+            log.error(e.getMessage());
+            return ResponseData.failed("新增权限失败,失败原因" + e.getMessage());
+        }
+    }
+
+    @PreAuthorize("hasPermission('permission','read')")
+    @GetMapping("/permissions")
+    public ResponseData getPermissions() {
+        try {
+            return ResponseData.success(permissionService.getPermissions());
+        } catch (ServiceException e) {
+            return ResponseData.failed("获取权限列表失败");
+        }
+    }
+
+}

+ 20 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/permission/fb/PermissionFB.java

@@ -0,0 +1,20 @@
+package com.jkcredit.invoice.hub.controller.web.permission.fb;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 16:37
+ * @version: V1.0
+ **/
+@Data
+public class PermissionFB {
+    @NotNull(message = "权限不可为空")
+    private String permission;
+
+    @NotNull(message = "权限名不可为空")
+    private String permissionName;
+}

+ 14 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/permission/fb/PermissionQueryFB.java

@@ -0,0 +1,14 @@
+package com.jkcredit.invoice.hub.controller.web.permission.fb;
+
+import lombok.Data;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 16:04
+ * @version: V1.0
+ **/
+@Data
+public class PermissionQueryFB {
+    private String permissionName;
+}

+ 61 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/recharge/RechargeResource.java

@@ -0,0 +1,61 @@
+package com.jkcredit.invoice.hub.controller.web.recharge;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.controller.base.WebResource;
+import com.jkcredit.invoice.hub.controller.web.recharge.fb.RechargeFB;
+import com.jkcredit.invoice.hub.controller.web.recharge.fb.RechargeQueryFB;
+import com.jkcredit.invoice.hub.model.dto.recharge.RechargeDto;
+import com.jkcredit.invoice.hub.model.vo.recharge.RechargeVo;
+import com.jkcredit.invoice.hub.service.recharge.RechargeService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.spi.web.data.ResponseData;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 20:31
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class RechargeResource extends WebResource {
+    @Autowired
+    RechargeService rechargeService;
+
+    @PreAuthorize("hasPermission('recharge','edit')")
+    @PostMapping("/recharge")
+    public ResponseData recharge(@RequestBody RechargeFB rechargeFB) {
+        try {
+            // todo 充值操作人未加
+            validate(rechargeFB);
+            RechargeDto rechargeDto = mapper.map(rechargeFB, RechargeDto.class);
+            rechargeService.recharge(rechargeDto);
+            return ResponseData.success("充值成功");
+        } catch (ServiceException e) {
+            log.error(e.getMessage());
+            return ResponseData.failed("充值失败,失败原因" + e.getMessage());
+        }
+    }
+
+    @PreAuthorize("hasPermission('recharge','read')")
+    @GetMapping("/page/rechargeRecords")
+    public ResponseData getRechargeRecords(Page page, RechargeQueryFB rechargeQueryFB) {
+        try {
+            validate(rechargeQueryFB);
+            RechargeDto rechargeDto = mapper.map(rechargeQueryFB, RechargeDto.class);
+
+            IPage<RechargeVo> rechargeVoIPage = rechargeService.getRechargeRecords(page, rechargeDto);
+            return ResponseData.success(rechargeVoIPage);
+        } catch (ServiceException e) {
+            return ResponseData.failed("获取充值列表失败");
+        }
+    }
+}

+ 19 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/recharge/fb/RechargeFB.java

@@ -0,0 +1,19 @@
+package com.jkcredit.invoice.hub.controller.web.recharge.fb;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 20:31
+ * @version: V1.0
+ **/
+@Data
+public class RechargeFB {
+    @NotNull(message = "用户id不能为空")
+    private Long userId;
+    @NotNull(message = "充值金额不能为空")
+    private Double money;
+}

+ 15 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/recharge/fb/RechargeQueryFB.java

@@ -0,0 +1,15 @@
+package com.jkcredit.invoice.hub.controller.web.recharge.fb;
+
+import lombok.Data;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 21:21
+ * @version: V1.0
+ **/
+@Data
+public class RechargeQueryFB {
+    private String appKey;
+    private String company;
+}

+ 80 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/role/RoleResource.java

@@ -0,0 +1,80 @@
+package com.jkcredit.invoice.hub.controller.web.role;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.controller.base.WebResource;
+import com.jkcredit.invoice.hub.controller.web.role.fb.RoleFB;
+import com.jkcredit.invoice.hub.model.dto.role.RoleDto;
+import com.jkcredit.invoice.hub.model.vo.role.RoleVo;
+import com.jkcredit.invoice.hub.service.role.RoleService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.spi.web.data.ResponseData;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 12:46
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class RoleResource extends WebResource {
+    @Autowired
+    RoleService roleService;
+
+    @PreAuthorize("hasPermission('role', 'read')")
+    @GetMapping("/page/roles")
+    public ResponseData getRoles(Page page, RoleFB roleFB) {
+        try {
+//            validate(roleFB);
+            RoleDto roleDto = mapper.map(roleFB, RoleDto.class);
+
+            IPage<RoleVo> roles = roleService.getRoles(page, roleDto);
+            return ResponseData.success(roles);
+        } catch (ServiceException exp) {
+            return ResponseData.failed("获取角色列表失败");
+        }
+    }
+
+    @PreAuthorize("hasPermission('role','edit')")
+    @PostMapping("/role")
+    public ResponseData addRole(@RequestBody RoleFB roleFB) {
+        try {
+            validate(roleFB);
+            RoleDto roleDto = mapper.map(roleFB, RoleDto.class);
+            roleService.addRole(roleDto);
+            return ResponseData.success("新增角色成功");
+        } catch (ServiceException exp) {
+            log.error(exp.getMessage());
+            return ResponseData.failed("新增角色失败,失败原因" + exp.getMessage());
+        }
+    }
+
+    @PreAuthorize("hasPermission('role','read')")
+    @GetMapping("/roles")
+    public ResponseData getRoles() {
+        try {
+            return ResponseData.success(roleService.getRoles());
+        } catch (ServiceException exp) {
+            return ResponseData.failed("获取角色列表失败");
+        }
+    }
+
+    // todo 角色附有哪种权限问前台如何展示  是列表还是详情页
+
+    @PreAuthorize("hasPermission('role','edit')")
+    @PutMapping("/role/{id}")
+    public ResponseData deleteRole(@PathVariable("id") Long id) {
+        try {
+            roleService.deleteRole(id);
+            return ResponseData.success("删除角色成功");
+        } catch (ServiceException e) {
+            log.error(e.getMessage());
+            return ResponseData.failed("删除角色失败,失败原因" + e.getMessage());
+        }
+    }
+}

+ 19 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/role/fb/RoleFB.java

@@ -0,0 +1,19 @@
+package com.jkcredit.invoice.hub.controller.web.role.fb;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 12:48
+ * @version: V1.0
+ **/
+@Data
+public class RoleFB {
+    @NotNull(message = "角色不能为空")
+    private String role;
+    @NotNull(message = "角色名不能为空")
+    private String roleName;
+}

+ 40 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/rolePermission/RolePermissionResource.java

@@ -0,0 +1,40 @@
+package com.jkcredit.invoice.hub.controller.web.rolePermission;
+
+import com.jkcredit.invoice.hub.controller.base.WebResource;
+import com.jkcredit.invoice.hub.controller.web.rolePermission.fb.RolePermissionFB;
+import com.jkcredit.invoice.hub.model.dto.rolePermission.RolePermissionDto;
+import com.jkcredit.invoice.hub.service.rolePermission.RolePermissionService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.spi.web.data.ResponseData;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 22:54
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class RolePermissionResource extends WebResource {
+    @Autowired
+    RolePermissionService rolePermissionService;
+
+    @PreAuthorize("hasPermission('permission','edit')")
+    @PostMapping("/rolePermission")
+    public ResponseData addRolePermission(@RequestBody RolePermissionFB rolePermissionFB) {
+        try {
+            validate(rolePermissionFB);
+            RolePermissionDto dto = mapper.map(rolePermissionFB, RolePermissionDto.class);
+            rolePermissionService.saveRolePermission(dto);
+            return ResponseData.success("添加成功");
+        } catch (ServiceException e) {
+            return ResponseData.failed("添加失败,失败原因" + e.getMessage());
+        }
+    }
+}

+ 20 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/rolePermission/fb/RolePermissionFB.java

@@ -0,0 +1,20 @@
+package com.jkcredit.invoice.hub.controller.web.rolePermission.fb;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 22:55
+ * @version: V1.0
+ **/
+@Data
+public class RolePermissionFB {
+    @NotNull(message = "roleId不能为空")
+    private Long roleId;
+    @NotNull(message = "permissionIds不能为空")
+    private List<Long> permissionIds;
+}

+ 101 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/user/UserResource.java

@@ -0,0 +1,101 @@
+package com.jkcredit.invoice.hub.controller.web.user;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.constant.CommonConstant;
+import com.jkcredit.invoice.hub.constant.ResponseStatus;
+import com.jkcredit.invoice.hub.controller.base.WebResource;
+import com.jkcredit.invoice.hub.controller.web.user.fb.UpdateUserFB;
+import com.jkcredit.invoice.hub.controller.web.user.fb.UserFB;
+import com.jkcredit.invoice.hub.controller.web.user.fb.UserQueryFB;
+import com.jkcredit.invoice.hub.model.dto.user.UserDto;
+import com.jkcredit.invoice.hub.model.vo.common.AppResponseVo;
+import com.jkcredit.invoice.hub.model.vo.user.UserVO;
+import com.jkcredit.invoice.hub.service.user.UserService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.spi.web.data.ResponseData;
+import com.jkcredit.invoice.hub.util.BeanUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/2 10:13
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class UserResource extends WebResource {
+    @Autowired
+    UserService userService;
+
+    @PreAuthorize("hasPermission('user','read')")
+    @GetMapping("/user/{id}")
+    public ResponseEntity<AppResponseVo> getUserById(@PathVariable("id") Long id) {
+        try {
+            UserVO userVo = userService.getUserById(id);
+            return ResponseEntity.ok(new AppResponseVo(ResponseStatus.SUCCESS, CommonConstant.MESSAGE_SUCCESS, userVo));
+        } catch (ServiceException serviceException) {
+            return ResponseEntity.ok(new AppResponseVo(ResponseStatus.FAILED, serviceException.getMessage(), null));
+        }
+    }
+
+    @PreAuthorize("hasPermission('user','read')")
+    @GetMapping("/page/users")
+    public ResponseData getUsers(Page page, UserQueryFB userQueryFB) {
+        try {
+            validate(userQueryFB);
+            UserDto userDto = mapper.map(userQueryFB, UserDto.class);
+
+            IPage<UserVO> users = userService.getAllUsers(page, userDto);
+            return ResponseData.success(users);
+        } catch (ServiceException exp) {
+            return ResponseData.failed("获取用户列表失败");
+        }
+    }
+
+    @PreAuthorize("hasPermission('user','edit')")
+    @PostMapping("/user")
+    public ResponseData addUser(@RequestBody UserFB userFB) {
+        try {
+            validate(userFB);
+
+            UserDto userDto = mapper.map(userFB, UserDto.class);
+            userService.saveUser(userDto);
+
+            return ResponseData.success("新增用户成功");
+        } catch (ServiceException exp) {
+            log.error(exp.getMessage());
+            return ResponseData.failed("新增用户失败,失败原因" + exp.getMessage());
+        }
+    }
+
+    @PreAuthorize("hasPermission('user','edit')")
+    @PutMapping("/user")
+    public ResponseData updateUser(@RequestBody UpdateUserFB userFB) {
+        try {
+            validate(userFB);
+            UserDto userDto = mapper.map(userFB, UserDto.class);
+            Boolean result = userService.updateUser(userDto);
+            return ResponseData.success(result);
+        } catch (ServiceException e) {
+            return ResponseData.failed("更新用户失败,失败原因" + e.getMessage());
+        }
+    }
+
+    @PreAuthorize("hasPermission('user','edit')")
+    @PutMapping("/user/{id}")
+    public ResponseData deleteUser(@PathVariable("id") Long id) {
+        try {
+            userService.deleteUser(id);
+            return ResponseData.success("删除用户成功");
+        } catch (ServiceException e) {
+            log.error(e.getMessage());
+            return ResponseData.failed("删除用户失败,失败原因" + e.getMessage());
+        }
+    }
+}

+ 22 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/user/fb/UpdateUserFB.java

@@ -0,0 +1,22 @@
+package com.jkcredit.invoice.hub.controller.web.user.fb;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/9 17:07
+ * @version: V1.0
+ **/
+@Data
+public class UpdateUserFB {
+    private Long id;
+    private String password;
+    private String company;
+    private String contactName;
+    private String telephone;
+    private BigDecimal price;
+    private Integer status;
+}

+ 40 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/user/fb/UserFB.java

@@ -0,0 +1,40 @@
+package com.jkcredit.invoice.hub.controller.web.user.fb;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import java.math.BigDecimal;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 16:08
+ * @version: V1.0
+ **/
+@Data
+public class UserFB {
+    @NotNull(message = "用户名不能为空")
+    @Pattern(regexp = "^[a-zA-Z0-9_]{4,30}$", message = "用户名格式错误")
+    private String username;
+
+    @NotNull(message = "密码不能为空")
+    private String password;
+
+    @Pattern(regexp = "^[a-zA-Z0-9_]{4,30}$", message = "appKey格式错误")
+    @NotNull(message = "appKey不能为空")
+    private String appKey;
+
+    private String company;
+
+    @NotNull(message = "用户类型不能为空")
+    private Integer userType;
+
+    private String contactName;
+
+    private String telephone;
+
+    private BigDecimal price;
+
+    private Integer status;
+}

+ 16 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/user/fb/UserQueryFB.java

@@ -0,0 +1,16 @@
+package com.jkcredit.invoice.hub.controller.web.user.fb;
+
+import lombok.Data;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 15:53
+ * @version: V1.0
+ **/
+@Data
+public class UserQueryFB {
+    private String username;
+    private String appKey;
+    private String company;
+}

+ 43 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/userRolePermission/UserRolePermissionResource.java

@@ -0,0 +1,43 @@
+package com.jkcredit.invoice.hub.controller.web.userRolePermission;
+
+import com.jkcredit.invoice.hub.controller.base.WebResource;
+import com.jkcredit.invoice.hub.controller.web.userRolePermission.fb.UserRolePermissionFB;
+import com.jkcredit.invoice.hub.model.dto.userRolePermission.UserRolePermissionDto;
+import com.jkcredit.invoice.hub.service.userRolePermission.UserRolePermissionService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.spi.web.data.ResponseData;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 17:40
+ * @version: V1.0
+ **/
+@Slf4j
+@RestController
+public class UserRolePermissionResource extends WebResource {
+    @Autowired
+    UserRolePermissionService userRolePermissionService;
+
+    @PreAuthorize("hasPermission('userRolePermission','edit')")
+    @PostMapping("/userRolePermission")
+    public ResponseData saveUserRolePermission(@RequestBody UserRolePermissionFB fb) {
+        try {
+            validate(fb);
+            UserRolePermissionDto userDto = mapper.map(fb, UserRolePermissionDto.class);
+            userRolePermissionService.saveUserRolePermission(userDto);
+
+            return ResponseData.success("用户分配权限成功");
+        } catch (ServiceException e) {
+            log.error(e.getMessage());
+            return ResponseData.failed("用户分配权限失败,失败原因" + e.getMessage());
+        }
+
+    }
+}

+ 19 - 0
src/main/java/com/jkcredit/invoice/hub/controller/web/userRolePermission/fb/UserRolePermissionFB.java

@@ -0,0 +1,19 @@
+package com.jkcredit.invoice.hub.controller.web.userRolePermission.fb;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 17:39
+ * @version: V1.0
+ **/
+@Data
+public class UserRolePermissionFB {
+    @NotNull(message = "用户id不能为空")
+    private Long userId;
+    @NotNull(message = "角色id不能为空")
+    private Long roleId;
+}

+ 17 - 0
src/main/java/com/jkcredit/invoice/hub/enums/CommonEnumStatus.java

@@ -0,0 +1,17 @@
+package com.jkcredit.invoice.hub.enums;
+
+import com.jkcredit.invoice.hub.enums.base.EnumStatus;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum CommonEnumStatus implements EnumStatus {
+    /**
+     * 未知状态
+     */
+    UNKNOWN_STATUS(-1, "未知状态");
+
+    private Integer value;
+    private String desc;
+}

+ 22 - 0
src/main/java/com/jkcredit/invoice/hub/enums/UserStatusEnum.java

@@ -0,0 +1,22 @@
+package com.jkcredit.invoice.hub.enums;
+
+import com.jkcredit.invoice.hub.enums.base.EnumStatus;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum UserStatusEnum implements EnumStatus {
+    /**
+     * 正常使用
+     */
+    AVAILABLE(1, "正常"),
+
+    /**
+     * 停用
+     */
+    DISABLE(2, "停用");
+
+    private Integer value;
+    private String desc;
+}

+ 15 - 0
src/main/java/com/jkcredit/invoice/hub/enums/UserTypeEnum.java

@@ -0,0 +1,15 @@
+package com.jkcredit.invoice.hub.enums;
+
+import com.jkcredit.invoice.hub.enums.base.EnumStatus;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum UserTypeEnum implements EnumStatus {
+    ADMINISTRATOR(1, "平台管理员"),
+    USER(2, "接口用户");
+
+    private Integer value;
+    private String desc;
+}

+ 23 - 0
src/main/java/com/jkcredit/invoice/hub/enums/base/EnumStatus.java

@@ -0,0 +1,23 @@
+//
+// Source code recreated from a .class file by IntelliJ IDEA
+// (powered by Fernflower decompiler)
+//
+
+package com.jkcredit.invoice.hub.enums.base;
+
+
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.util.EnumStatusUtils;
+
+public interface EnumStatus extends IEnumStatus<Integer> {
+
+    static EnumStatus getEnumStatus(Class<?> typeClass, int value) {
+        EnumStatus status = EnumStatusUtils.getStatusByValue(typeClass, value);
+        if (status == null) {
+            throw new ServiceException("枚举值未定义, typeClass = " + typeClass.getCanonicalName() + ", Value = " + value);
+        } else {
+            return status;
+        }
+    }
+
+}

+ 23 - 0
src/main/java/com/jkcredit/invoice/hub/enums/base/IEnumStatus.java

@@ -0,0 +1,23 @@
+package com.jkcredit.invoice.hub.enums.base;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/9 10:58
+ * @version: V1.0
+ **/
+public interface IEnumStatus<T> {
+    /**
+     * 获取枚举值
+     *
+     * @return 枚举值
+     */
+    T getValue();
+
+    /**
+     * 获取枚举描述
+     *
+     * @return 枚举描述
+     */
+    String getDesc();
+}

+ 33 - 0
src/main/java/com/jkcredit/invoice/hub/filter/TokenFilter.java

@@ -0,0 +1,33 @@
+package com.jkcredit.invoice.hub.filter;
+
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import java.io.IOException;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/8 21:58
+ * @version: V1.0
+ **/
+//@Component
+public class TokenFilter implements Filter {
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        System.out.println(authentication.getAuthorities());
+    }
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+
+    }
+
+    @Override
+    public void destroy() {
+
+    }
+}

+ 22 - 0
src/main/java/com/jkcredit/invoice/hub/mapper/PermissionMapper.java

@@ -0,0 +1,22 @@
+package com.jkcredit.invoice.hub.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.permission.PermissionDto;
+import com.jkcredit.invoice.hub.model.po.permission.PermissionPo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/6 14:47
+ * @version: V1.0
+ **/
+public interface PermissionMapper extends BaseMapper<PermissionPo> {
+    List<PermissionPo> getPermissionByUserId(Long userId);
+
+    IPage<PermissionPo> getPermissions(Page page, @Param("query") PermissionDto permissionDto);
+}

+ 18 - 0
src/main/java/com/jkcredit/invoice/hub/mapper/RechargeMapper.java

@@ -0,0 +1,18 @@
+package com.jkcredit.invoice.hub.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.recharge.RechargeDto;
+import com.jkcredit.invoice.hub.model.po.recharge.RechargePo;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 20:45
+ * @version: V1.0
+ **/
+public interface RechargeMapper extends BaseMapper<RechargePo> {
+    IPage<RechargePo> getRechargeRecords(Page page, @Param("query") RechargeDto rechargeDto);
+}

+ 22 - 0
src/main/java/com/jkcredit/invoice/hub/mapper/RoleMapper.java

@@ -0,0 +1,22 @@
+package com.jkcredit.invoice.hub.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.role.RoleDto;
+import com.jkcredit.invoice.hub.model.po.role.RolePo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 11:50
+ * @version: V1.0
+ **/
+public interface RoleMapper extends BaseMapper<RolePo> {
+    IPage<RolePo> getRoles(Page page, @Param("query") RoleDto roleDto);
+
+    List<RolePo> getRolesWithoutPage();
+}

+ 16 - 0
src/main/java/com/jkcredit/invoice/hub/mapper/RolePermissionMapper.java

@@ -0,0 +1,16 @@
+package com.jkcredit.invoice.hub.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.jkcredit.invoice.hub.model.po.rolePermission.RolePermissionPo;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 22:33
+ * @version: V1.0
+ **/
+public interface RolePermissionMapper extends BaseMapper<RolePermissionPo> {
+    List<Long> getPermissions(Long roleId);
+}

+ 13 - 0
src/main/java/com/jkcredit/invoice/hub/mapper/UserBalanceMapper.java

@@ -0,0 +1,13 @@
+package com.jkcredit.invoice.hub.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.jkcredit.invoice.hub.model.po.userBalance.UserBalancePo;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 10:06
+ * @version: V1.0
+ **/
+public interface UserBalanceMapper extends BaseMapper<UserBalancePo> {
+}

+ 18 - 0
src/main/java/com/jkcredit/invoice/hub/mapper/UserMapper.java

@@ -0,0 +1,18 @@
+package com.jkcredit.invoice.hub.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.user.UserDto;
+import com.jkcredit.invoice.hub.model.po.user.UserPo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Optional;
+
+public interface UserMapper extends BaseMapper<UserPo> {
+    Optional<UserPo> getUserByUserName(String userName);
+
+    IPage<UserPo> getUsersPage(Page page, @Param("query") UserDto userDto);
+
+    UserPo getUserById(Long id);
+}

+ 13 - 0
src/main/java/com/jkcredit/invoice/hub/mapper/UserRolePermissionMapper.java

@@ -0,0 +1,13 @@
+package com.jkcredit.invoice.hub.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.jkcredit.invoice.hub.model.po.userRolePermission.UserRolePermissionPo;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 17:49
+ * @version: V1.0
+ **/
+public interface UserRolePermissionMapper extends BaseMapper<UserRolePermissionPo> {
+}

+ 15 - 0
src/main/java/com/jkcredit/invoice/hub/model/dto/permission/PermissionDto.java

@@ -0,0 +1,15 @@
+package com.jkcredit.invoice.hub.model.dto.permission;
+
+import lombok.Data;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 13:03
+ * @version: V1.0
+ **/
+@Data
+public class PermissionDto {
+    private String permission;
+    private String permissionName;
+}

+ 24 - 0
src/main/java/com/jkcredit/invoice/hub/model/dto/recharge/RechargeDto.java

@@ -0,0 +1,24 @@
+package com.jkcredit.invoice.hub.model.dto.recharge;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 20:51
+ * @version: V1.0
+ **/
+@Data
+public class RechargeDto implements Serializable {
+    private static final long serialVersionUID = -6579034606025348517L;
+    private Long id;
+    private BigDecimal beforeBalance;
+    private BigDecimal money;
+    private Long userId;
+    private Long createUser;
+    private String appKey;
+    private String company;
+}

+ 17 - 0
src/main/java/com/jkcredit/invoice/hub/model/dto/role/RoleDto.java

@@ -0,0 +1,17 @@
+package com.jkcredit.invoice.hub.model.dto.role;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 11:56
+ * @version: V1.0
+ **/
+@Data
+public class RoleDto implements Serializable {
+    private String role;
+    private String roleName;
+}

+ 22 - 0
src/main/java/com/jkcredit/invoice/hub/model/dto/rolePermission/RolePermissionDto.java

@@ -0,0 +1,22 @@
+package com.jkcredit.invoice.hub.model.dto.rolePermission;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 22:39
+ * @version: V1.0
+ **/
+@Data
+public class RolePermissionDto implements Serializable {
+    private static final long serialVersionUID = 8767625048565680322L;
+    @NotNull(message = "roleId不能为空")
+    private Long roleId;
+    @NotNull(message = "permissionIds不能为空")
+    private List<Long> permissionIds;
+}

+ 27 - 0
src/main/java/com/jkcredit/invoice/hub/model/dto/user/UserDto.java

@@ -0,0 +1,27 @@
+package com.jkcredit.invoice.hub.model.dto.user;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/8 10:32
+ * @version: V1.0
+ **/
+@Data
+public class UserDto implements Serializable {
+    private static final long serialVersionUID = -5634045341774683793L;
+    private Long id;
+    private String username;
+    private String appKey;
+    private String company;
+    private String password;
+    private Integer userType;
+    private String contactName;
+    private String telephone;
+    private BigDecimal price;
+    private Integer status;
+}

+ 21 - 0
src/main/java/com/jkcredit/invoice/hub/model/dto/userRolePermission/UserRolePermissionDto.java

@@ -0,0 +1,21 @@
+package com.jkcredit.invoice.hub.model.dto.userRolePermission;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 17:35
+ * @version: V1.0
+ **/
+@Data
+public class UserRolePermissionDto implements Serializable {
+    private static final long serialVersionUID = 6147146470889440364L;
+    @NotNull(message = "用户id不能为空")
+    private Long userId;
+    @NotNull(message = "角色id不能为空")
+    private Long roleId;
+}

+ 32 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/permission/PermissionPo.java

@@ -0,0 +1,32 @@
+package com.jkcredit.invoice.hub.model.po.permission;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/6 14:29
+ * @version: V1.0
+ **/
+@Entity
+@Data
+@ToString
+@TableName("h_permission")
+public class PermissionPo {
+    @Id
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private String permission;
+    private String permissionName;
+    private Date createTime;
+    private Date updateTime;
+    private Integer activated;
+}

+ 42 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/recharge/RechargePo.java

@@ -0,0 +1,42 @@
+package com.jkcredit.invoice.hub.model.po.recharge;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 20:42
+ * @version: V1.0
+ **/
+@Entity
+@Data
+@ToString
+@TableName("h_recharge")
+public class RechargePo {
+    @Id
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private BigDecimal beforeBalance;
+    private BigDecimal money;
+    private Long userId;
+    private Date createTime;
+    private Date updateTime;
+    private Integer activated;
+    private String appKey;
+    private String company;
+    private Integer status;
+    private String contactName;
+    private String telephone;
+    private BigDecimal price;
+    private String roleName;
+    private Long createUser;
+}

+ 41 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/role/RolePo.java

@@ -0,0 +1,41 @@
+package com.jkcredit.invoice.hub.model.po.role;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 11:48
+ * @version: V1.0
+ **/
+@Entity
+@Data
+@ToString
+@TableName("h_role")
+public class RolePo implements Serializable {
+
+    private static final long serialVersionUID = -5125401944480146857L;
+
+    @Id
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    private String role;
+
+    private String roleName;
+
+    private Date createTime;
+
+    private Date updateTime;
+
+    private Integer activated;
+}

+ 32 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/rolePermission/RolePermissionPo.java

@@ -0,0 +1,32 @@
+package com.jkcredit.invoice.hub.model.po.rolePermission;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 22:34
+ * @version: V1.0
+ **/
+@Entity
+@Data
+@ToString
+@TableName("h_role_permission")
+public class RolePermissionPo {
+    @Id
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private Long roleId;
+    private Long permissionId;
+    private Date createTime;
+    private Date updateTime;
+    private Integer activated;
+}

+ 24 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/user/UserAuthoritiesPo.java

@@ -0,0 +1,24 @@
+package com.jkcredit.invoice.hub.model.po.user;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/3 14:25
+ * @version: V1.0
+ **/
+@Data
+public class UserAuthoritiesPo {
+    private Long id;
+    private String userName;
+    private String password;
+    private String appKey;
+    private String appSecret;
+    private String company;
+    private String role;
+    private String roleName;
+    private Long activated;
+}

+ 46 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/user/UserPo.java

@@ -0,0 +1,46 @@
+package com.jkcredit.invoice.hub.model.po.user;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2019/12/30 17:33
+ * @version: V1.0
+ **/
+@Entity
+@Data
+@ToString
+@TableName("h_user")
+public class UserPo implements Serializable {
+
+    private static final long serialVersionUID = -5252679570009162293L;
+    @Id
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private String username;
+    private String password;
+    private String appKey;
+    private String appSecret;
+    private String company;
+    private Date createTime;
+    private Date updateTime;
+    private Integer activated;
+    private Integer userType;
+    private Integer status;
+    private String contactName;
+    private String telephone;
+    private BigDecimal price;
+    private String roleName;
+    private BigDecimal balance;
+}

+ 32 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/userBalance/UserBalancePo.java

@@ -0,0 +1,32 @@
+package com.jkcredit.invoice.hub.model.po.userBalance;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 10:04
+ * @version: V1.0
+ **/
+@Entity
+@Data
+@ToString
+@TableName("h_user_balance")
+public class UserBalancePo implements Serializable {
+    private static final long serialVersionUID = -8548930732100649834L;
+
+    @Id
+    @TableId
+    private Long userId;
+    private BigDecimal balance;
+    private Date updateTime;
+}

+ 42 - 0
src/main/java/com/jkcredit/invoice/hub/model/po/userRolePermission/UserRolePermissionPo.java

@@ -0,0 +1,42 @@
+package com.jkcredit.invoice.hub.model.po.userRolePermission;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import lombok.ToString;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 17:21
+ * @version: V1.0
+ **/
+@Entity
+@Data
+@ToString
+@TableName("h_user_role_permission")
+public class UserRolePermissionPo implements Serializable {
+    private static final long serialVersionUID = -2752794166396911929L;
+
+    @Id
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    private Long userId;
+
+    private Long roleId;
+
+    private Long permissionId;
+
+    private Date createTime;
+
+    private Date updateTime;
+
+    private Integer activated;
+}

+ 43 - 0
src/main/java/com/jkcredit/invoice/hub/model/vo/common/AjaxResponseBody.java

@@ -0,0 +1,43 @@
+package com.jkcredit.invoice.hub.model.vo.common;
+
+import java.io.Serializable;
+
+public class AjaxResponseBody implements Serializable {
+
+    private String status;
+    private String msg;
+    private Object result;
+    private String jwtToken;
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public Object getResult() {
+        return result;
+    }
+
+    public void setResult(Object result) {
+        this.result = result;
+    }
+
+    public String getJwtToken() {
+        return jwtToken;
+    }
+
+    public void setJwtToken(String jwtToken) {
+        this.jwtToken = jwtToken;
+    }
+}

+ 27 - 0
src/main/java/com/jkcredit/invoice/hub/model/vo/common/AppResponseVo.java

@@ -0,0 +1,27 @@
+package com.jkcredit.invoice.hub.model.vo.common;
+
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 22:49
+ * @version: V1.0
+ **/
+@Data
+@ToString
+public class AppResponseVo {
+    private Integer code;
+    private String responseMessage;
+    private Object responseData;
+
+    public AppResponseVo() {
+    }
+
+    public AppResponseVo(Integer code, String responseMessage, Object responseData) {
+        this.code = code;
+        this.responseMessage = responseMessage;
+        this.responseData = responseData;
+    }
+}

+ 16 - 0
src/main/java/com/jkcredit/invoice/hub/model/vo/login/LoginVo.java

@@ -0,0 +1,16 @@
+package com.jkcredit.invoice.hub.model.vo.login;
+
+import lombok.Data;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 11:26
+ * @version: V1.0
+ **/
+@Data
+public class LoginVo {
+    private String code;
+    private String message;
+    private String data;
+}

+ 20 - 0
src/main/java/com/jkcredit/invoice/hub/model/vo/permission/PermissionVo.java

@@ -0,0 +1,20 @@
+package com.jkcredit.invoice.hub.model.vo.permission;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 13:08
+ * @version: V1.0
+ **/
+@Data
+public class PermissionVo implements Serializable {
+
+    private static final long serialVersionUID = 7436390981292703625L;
+    private Long id;
+    private String permission;
+    private String permissionName;
+}

+ 29 - 0
src/main/java/com/jkcredit/invoice/hub/model/vo/recharge/RechargeVo.java

@@ -0,0 +1,29 @@
+package com.jkcredit.invoice.hub.model.vo.recharge;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 21:14
+ * @version: V1.0
+ **/
+@Data
+public class RechargeVo implements Serializable {
+    private static final long serialVersionUID = -2259256897331056140L;
+    private String appKey;
+    private String company;
+    private Integer status;
+    private String contactName;
+    private String telephone;
+    private BigDecimal price;
+    private BigDecimal beforeBalance;
+    private BigDecimal money;
+    private String roleName;
+    private Date createTime;
+    private Date updateTime;
+}

+ 19 - 0
src/main/java/com/jkcredit/invoice/hub/model/vo/role/RoleVo.java

@@ -0,0 +1,19 @@
+package com.jkcredit.invoice.hub.model.vo.role;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 11:54
+ * @version: V1.0
+ **/
+@Data
+public class RoleVo implements Serializable {
+    private static final long serialVersionUID = 2200313139592001822L;
+    private Long id;
+    private String role;
+    private String roleName;
+}

+ 52 - 0
src/main/java/com/jkcredit/invoice/hub/model/vo/user/UserVO.java

@@ -0,0 +1,52 @@
+package com.jkcredit.invoice.hub.model.vo.user;
+
+import com.baomidou.mybatisplus.core.toolkit.EnumUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.jkcredit.invoice.hub.enums.UserStatusEnum;
+import com.jkcredit.invoice.hub.enums.UserTypeEnum;
+import com.jkcredit.invoice.hub.util.CommonUtil;
+import com.jkcredit.invoice.hub.util.EnumStatusUtils;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/7 22:25
+ * @version: V1.0
+ **/
+@Data
+public class UserVO implements Serializable {
+
+    private static final long serialVersionUID = -5086205443686309467L;
+
+    private Long id;
+    private String username;
+    private String appKey;
+    private String company;
+
+    private Integer userType;
+    private Integer status;
+    private String contactName;
+    private String telephone;
+    private Double price;
+    private String roleName;
+    private Double balance;
+
+    public String getStatusDisplay() {
+        if (this.status == null) {
+            return StringUtils.EMPTY;
+        }
+        return EnumStatusUtils.getStatusByValue(UserStatusEnum.class, this.status).getDesc();
+    }
+
+    public String getUserTypeDisplay() {
+        if (this.userType == null) {
+            return StringUtils.EMPTY;
+        }
+        return EnumStatusUtils.getStatusByValue(UserTypeEnum.class, this.userType).getDesc();
+    }
+}

+ 38 - 0
src/main/java/com/jkcredit/invoice/hub/service/base/BaseService.java

@@ -0,0 +1,38 @@
+package com.jkcredit.invoice.hub.service.base;
+
+import com.baidu.unbiz.fluentvalidator.FluentValidator;
+import com.baidu.unbiz.fluentvalidator.Result;
+import com.baidu.unbiz.fluentvalidator.jsr303.HibernateSupportedValidator;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.hibernate.service.spi.ServiceException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.validation.Validator;
+
+import static com.baidu.unbiz.fluentvalidator.ResultCollectors.toSimple;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2019/12/29 20:55
+ * @version: V1.0
+ **/
+public class BaseService {
+
+    @Autowired
+    private Validator validator;
+
+    protected <T> void validate(T fb) {
+        Result result = FluentValidator.checkAll()
+                .on(fb, new HibernateSupportedValidator<T>().setHiberanteValidator(validator))
+                .doValidate()
+                .result(toSimple());
+
+        if (!result.isSuccess()) {
+            throw new ServiceException(result.getErrors().toString());
+        }
+    }
+
+}

+ 25 - 0
src/main/java/com/jkcredit/invoice/hub/service/permission/PermissionService.java

@@ -0,0 +1,25 @@
+package com.jkcredit.invoice.hub.service.permission;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.permission.PermissionDto;
+import com.jkcredit.invoice.hub.model.po.permission.PermissionPo;
+import com.jkcredit.invoice.hub.model.vo.permission.PermissionVo;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/6 14:46
+ * @version: V1.0
+ **/
+public interface PermissionService {
+    List<PermissionPo> getPermissionByUserId(Long userId);
+
+    IPage<PermissionVo> getPermissions(Page page, PermissionDto permissionDto);
+
+    void savePermission(PermissionDto permissionDto);
+
+    List<PermissionVo> getPermissions();
+}

+ 77 - 0
src/main/java/com/jkcredit/invoice/hub/service/permission/PermissionServiceImpl.java

@@ -0,0 +1,77 @@
+package com.jkcredit.invoice.hub.service.permission;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.mapper.PermissionMapper;
+import com.jkcredit.invoice.hub.model.dto.permission.PermissionDto;
+import com.jkcredit.invoice.hub.model.po.permission.PermissionPo;
+import com.jkcredit.invoice.hub.model.vo.permission.PermissionVo;
+import com.jkcredit.invoice.hub.service.base.BaseService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.util.BeanUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/6 14:46
+ * @version: V1.0
+ **/
+@Slf4j
+@Service
+@Transactional(readOnly = true)
+public class PermissionServiceImpl extends BaseService implements PermissionService {
+    @Resource
+    PermissionMapper permissionMapper;
+
+    @Override
+    public List<PermissionPo> getPermissionByUserId(Long userId) {
+        return permissionMapper.getPermissionByUserId(userId);
+    }
+
+    @Override
+    public IPage<PermissionVo> getPermissions(Page page, PermissionDto permissionDto) {
+        IPage<PermissionPo> permissionPoIPage = permissionMapper.getPermissions(page, permissionDto);
+        return permissionPoIPage.convert(this::convert);
+    }
+
+    private PermissionVo convert(PermissionPo po) {
+        PermissionVo vo = new PermissionVo();
+        BeanUtils.copyProperties(po, vo);
+        return vo;
+    }
+
+    @Transactional(rollbackFor = ServiceException.class)
+    @Override
+    public void savePermission(PermissionDto permissionDto) {
+        validate(permissionDto);
+        PermissionPo permissionPo = new PermissionPo();
+        BeanUtil.copyProperties(permissionPo, permissionDto);
+        permissionPo.setCreateTime(new Date());
+
+        try {
+            permissionMapper.insert(permissionPo);
+        } catch (Exception e) {
+            log.error("新增权限失败,失败原因:{}", e.getMessage());
+            throw new ServiceException("新增权限失败");
+        }
+    }
+
+    @Override
+    public List<PermissionVo> getPermissions() {
+        List<PermissionPo> permissionPoList = permissionMapper.selectList(null);
+        List<PermissionVo> permissionVoList = new ArrayList<>();
+        for (PermissionPo permissionPo : permissionPoList) {
+            permissionVoList.add(convert(permissionPo));
+        }
+        return permissionVoList;
+    }
+}

+ 19 - 0
src/main/java/com/jkcredit/invoice/hub/service/recharge/RechargeService.java

@@ -0,0 +1,19 @@
+package com.jkcredit.invoice.hub.service.recharge;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.recharge.RechargeDto;
+import com.jkcredit.invoice.hub.model.vo.recharge.RechargeVo;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 20:49
+ * @version: V1.0
+ **/
+
+public interface RechargeService {
+    IPage<RechargeVo> getRechargeRecords(Page page, RechargeDto rechargeDto);
+
+    void recharge(RechargeDto rechargeDto);
+}

+ 79 - 0
src/main/java/com/jkcredit/invoice/hub/service/recharge/RechargeServiceImpl.java

@@ -0,0 +1,79 @@
+package com.jkcredit.invoice.hub.service.recharge;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.mapper.RechargeMapper;
+import com.jkcredit.invoice.hub.mapper.UserBalanceMapper;
+import com.jkcredit.invoice.hub.model.dto.recharge.RechargeDto;
+import com.jkcredit.invoice.hub.model.po.recharge.RechargePo;
+import com.jkcredit.invoice.hub.model.po.userBalance.UserBalancePo;
+import com.jkcredit.invoice.hub.model.vo.recharge.RechargeVo;
+import com.jkcredit.invoice.hub.service.base.BaseService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.util.BeanUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 20:49
+ * @version: V1.0
+ **/
+@Service
+@Slf4j
+@Transactional(readOnly = true)
+public class RechargeServiceImpl extends BaseService implements RechargeService {
+    @Resource
+    RechargeMapper rechargeMapper;
+    @Resource
+    UserBalanceMapper userBalanceMapper;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void recharge(RechargeDto rechargeDto) {
+        validate(rechargeDto);
+        UserBalancePo userBalancePo = userBalanceMapper.selectById(rechargeDto.getUserId());
+        RechargePo rechargePo = new RechargePo();
+        BeanUtil.copyProperties(rechargePo, rechargeDto);
+        try {
+            if (userBalancePo == null) {
+                userBalancePo = new UserBalancePo();
+                userBalancePo.setUserId(rechargeDto.getUserId());
+                userBalancePo.setBalance(rechargeDto.getMoney());
+                userBalancePo.setUpdateTime(new Date());
+                userBalanceMapper.insert(userBalancePo);
+                rechargePo.setBeforeBalance(BigDecimal.ZERO);
+            } else {
+                userBalancePo.setBalance(userBalancePo.getBalance().add(rechargeDto.getMoney()));
+                userBalanceMapper.updateById(userBalancePo);
+                rechargePo.setBeforeBalance(userBalancePo.getBalance());
+            }
+
+            rechargePo.setCreateTime(new Date());
+            rechargePo.setCreateUser(rechargeDto.getCreateUser());
+            rechargeMapper.insert(rechargePo);
+        } catch (Exception e) {
+            log.error("新增余额表失败,失败原因:{}", e.getMessage());
+            throw new ServiceException("新增余额表失败");
+        }
+    }
+
+    @Override
+    public IPage<RechargeVo> getRechargeRecords(Page page, RechargeDto rechargeDto) {
+        IPage<RechargePo> rechargePoIPage = rechargeMapper.getRechargeRecords(page, rechargeDto);
+        return rechargePoIPage.convert(this::convert);
+    }
+
+    private RechargeVo convert(RechargePo po) {
+        RechargeVo vo = new RechargeVo();
+        BeanUtils.copyProperties(po, vo);
+        return vo;
+    }
+}

+ 24 - 0
src/main/java/com/jkcredit/invoice/hub/service/role/RoleService.java

@@ -0,0 +1,24 @@
+package com.jkcredit.invoice.hub.service.role;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.role.RoleDto;
+import com.jkcredit.invoice.hub.model.vo.role.RoleVo;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 11:51
+ * @version: V1.0
+ **/
+public interface RoleService {
+    IPage<RoleVo> getRoles(Page page, RoleDto roleDto);
+
+    void addRole(RoleDto roleDto);
+
+    List<RoleVo> getRoles();
+
+    void deleteRole(Long id);
+}

+ 90 - 0
src/main/java/com/jkcredit/invoice/hub/service/role/RoleServiceImpl.java

@@ -0,0 +1,90 @@
+package com.jkcredit.invoice.hub.service.role;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.constant.CommonConstant;
+import com.jkcredit.invoice.hub.constant.ExceptionMessage;
+import com.jkcredit.invoice.hub.mapper.RoleMapper;
+import com.jkcredit.invoice.hub.model.dto.role.RoleDto;
+import com.jkcredit.invoice.hub.model.po.role.RolePo;
+import com.jkcredit.invoice.hub.model.vo.role.RoleVo;
+import com.jkcredit.invoice.hub.service.base.BaseService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.util.BeanUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 11:51
+ * @version: V1.0
+ **/
+@Slf4j
+@Service
+@Transactional(readOnly = true)
+public class RoleServiceImpl extends BaseService implements RoleService {
+    @Resource
+    RoleMapper roleMapper;
+
+    @Override
+    public IPage<RoleVo> getRoles(Page page, RoleDto roleDto) {
+        IPage<RolePo> rolePoIPage = roleMapper.getRoles(page, roleDto);
+        return rolePoIPage.convert(this::convert);
+    }
+
+    private RoleVo convert(RolePo po) {
+        RoleVo vo = new RoleVo();
+        BeanUtils.copyProperties(po, vo);
+        return vo;
+    }
+
+    @Transactional(rollbackFor = ServiceException.class)
+    @Override
+    public void addRole(RoleDto roleDto) {
+        validate(roleDto);
+        RolePo rolePo = new RolePo();
+        BeanUtil.copyProperties(rolePo, roleDto);
+        rolePo.setCreateTime(new Date());
+        try {
+            roleMapper.insert(rolePo);
+        } catch (Exception e) {
+            log.error("新增角色失败,失败原因:{}", e.getMessage());
+            throw new ServiceException("新增角色失败");
+        }
+    }
+
+    @Override
+    public List<RoleVo> getRoles() {
+        List<RolePo> rolePoList = roleMapper.getRolesWithoutPage();
+        List<RoleVo> roleVoList = new ArrayList<>();
+        for (RolePo rolePo : rolePoList) {
+            roleVoList.add(convert(rolePo));
+        }
+        return roleVoList;
+    }
+
+    @Override
+    @Transactional(rollbackFor = ServiceException.class)
+    public void deleteRole(Long id) {
+        RolePo rolePo = roleMapper.selectById(id);
+        if (rolePo == null) {
+            throw new ServiceException(ExceptionMessage.ROLE_NOT_EXIST);
+        } else {
+            rolePo.setActivated(CommonConstant.ACTIVATED_DELETED);
+            try {
+                roleMapper.updateById(rolePo);
+            } catch (Exception e) {
+                log.error("删除角色失败,失败原因:{}", e.getMessage());
+                throw new ServiceException("删除角色失败");
+            }
+        }
+    }
+}

+ 13 - 0
src/main/java/com/jkcredit/invoice/hub/service/rolePermission/RolePermissionService.java

@@ -0,0 +1,13 @@
+package com.jkcredit.invoice.hub.service.rolePermission;
+
+import com.jkcredit.invoice.hub.model.dto.rolePermission.RolePermissionDto;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 22:37
+ * @version: V1.0
+ **/
+public interface RolePermissionService {
+    void saveRolePermission(RolePermissionDto rolePermissionDto);
+}

+ 46 - 0
src/main/java/com/jkcredit/invoice/hub/service/rolePermission/RolePermissionServiceImpl.java

@@ -0,0 +1,46 @@
+package com.jkcredit.invoice.hub.service.rolePermission;
+
+import com.jkcredit.invoice.hub.mapper.RolePermissionMapper;
+import com.jkcredit.invoice.hub.model.dto.rolePermission.RolePermissionDto;
+import com.jkcredit.invoice.hub.model.po.rolePermission.RolePermissionPo;
+import com.jkcredit.invoice.hub.service.base.BaseService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 22:37
+ * @version: V1.0
+ **/
+@Slf4j
+@Service
+@Transactional(readOnly = true)
+public class RolePermissionServiceImpl extends BaseService implements RolePermissionService {
+    @Resource
+    RolePermissionMapper rolePermissionMapper;
+
+    @Override
+    @Transactional(rollbackFor = ServiceException.class)
+    public void saveRolePermission(RolePermissionDto rolePermissionDto) {
+        validate(rolePermissionDto);
+        for (Long permissionId : rolePermissionDto.getPermissionIds()) {
+            RolePermissionPo rolePermissionPo = new RolePermissionPo();
+            rolePermissionPo.setRoleId(rolePermissionDto.getRoleId());
+            rolePermissionPo.setPermissionId(permissionId);
+            rolePermissionPo.setCreateTime(new Date());
+            try {
+                rolePermissionMapper.insert(rolePermissionPo);
+            } catch (Exception e) {
+                log.error("新增角色权限失败,失败原因:{}", e.getMessage());
+                throw new ServiceException("新增角色权限失败");
+            }
+
+        }
+    }
+}

+ 65 - 0
src/main/java/com/jkcredit/invoice/hub/service/security/CustomUserDetailsService.java

@@ -0,0 +1,65 @@
+package com.jkcredit.invoice.hub.service.security;
+
+import com.jkcredit.invoice.hub.config.SelfUserDetails;
+import com.jkcredit.invoice.hub.model.po.user.UserPo;
+import com.jkcredit.invoice.hub.model.po.permission.PermissionPo;
+import com.jkcredit.invoice.hub.service.permission.PermissionService;
+import com.jkcredit.invoice.hub.service.user.UserService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Optional;
+
+@Component("userDetailsService")
+public class CustomUserDetailsService implements UserDetailsService {
+
+    private final Logger log = LoggerFactory.getLogger(CustomUserDetailsService.class);
+
+    @Autowired
+    UserService userService;
+    @Autowired
+    PermissionService permissionService;
+
+    @Override
+    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
+        log.info("Authenticating {}", s);
+
+        String lowercaseLogin = s.toLowerCase(Locale.ENGLISH);
+        Optional<UserPo> userPo = userService.getUserByUserName(lowercaseLogin);
+
+        return userPo.map(user -> createSpringSecurityUser(lowercaseLogin, user))
+                .orElseThrow(() -> new UsernameNotFoundException("user " + lowercaseLogin + " was not found in the database"));
+    }
+
+    private UserDetails createSpringSecurityUser(String lowercaseLogin, UserPo user) {
+        SelfUserDetails selfUserDetails = new SelfUserDetails();
+        if (!user.getActivated().equals(1)) {
+            throw new ServiceException("user " + lowercaseLogin + " was not activated");
+        }
+
+        List<PermissionPo> permissionPoList = permissionService.getPermissionByUserId(user.getId());
+        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
+        for (PermissionPo permissionPo : permissionPoList) {
+            if (permissionPo.getActivated().equals(1)) {
+                SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(permissionPo.getPermission());
+                grantedAuthorities.add(simpleGrantedAuthority);
+            }
+        }
+        selfUserDetails.setUsername(user.getUsername());
+        selfUserDetails.setPassword(user.getPassword());
+        selfUserDetails.setAuthorities(grantedAuthorities);
+//        return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), grantedAuthorities);
+        return selfUserDetails;
+    }
+}

+ 23 - 0
src/main/java/com/jkcredit/invoice/hub/service/user/UserService.java

@@ -0,0 +1,23 @@
+package com.jkcredit.invoice.hub.service.user;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.model.dto.user.UserDto;
+import com.jkcredit.invoice.hub.model.po.user.UserPo;
+import com.jkcredit.invoice.hub.model.vo.user.UserVO;
+
+import java.util.Optional;
+
+public interface UserService {
+    Optional<UserPo> getUserByUserName(String userName);
+
+    UserVO getUserById(Long id);
+
+    IPage<UserVO> getAllUsers(Page page, UserDto userDto);
+
+    void saveUser(UserDto userDto);
+
+    Boolean updateUser(UserDto userDto);
+
+    void deleteUser(Long id);
+}

+ 146 - 0
src/main/java/com/jkcredit/invoice/hub/service/user/UserServiceImpl.java

@@ -0,0 +1,146 @@
+package com.jkcredit.invoice.hub.service.user;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jkcredit.invoice.hub.constant.CommonConstant;
+import com.jkcredit.invoice.hub.constant.ExceptionMessage;
+import com.jkcredit.invoice.hub.mapper.UserMapper;
+import com.jkcredit.invoice.hub.model.dto.user.UserDto;
+import com.jkcredit.invoice.hub.model.po.user.UserPo;
+import com.jkcredit.invoice.hub.model.vo.user.UserVO;
+import com.jkcredit.invoice.hub.service.base.BaseService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.util.AssertUtils;
+import com.jkcredit.invoice.hub.util.BeanUtil;
+import com.jkcredit.invoice.hub.util.CommonUtil;
+import com.jkcredit.invoice.hub.util.EncodeUtil;
+import io.netty.util.internal.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.security.crypto.bcrypt.BCrypt;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.Optional;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/2 10:01
+ * @version: V1.0
+ **/
+@Slf4j
+@Service
+@Transactional(readOnly = true)
+public class UserServiceImpl extends BaseService implements UserService {
+    @Resource
+    UserMapper userMapper;
+
+    @Override
+    public Optional<UserPo> getUserByUserName(String userName) {
+        return userMapper.getUserByUserName(userName);
+    }
+
+    @Override
+    public UserVO getUserById(Long id) throws ServiceException {
+        UserVO userVo = new UserVO();
+        UserPo userPo = userMapper.selectById(id);
+        if (userPo != null) {
+            BeanUtils.copyProperties(userPo, userVo);
+        } else {
+            throw new ServiceException(ExceptionMessage.USER_NOT_EXIST);
+        }
+        return userVo;
+    }
+
+    @Override
+    public IPage<UserVO> getAllUsers(Page page, UserDto userDto) {
+        // 数据库中查出的po分页集合
+        IPage<UserPo> users = userMapper.getUsersPage(page, userDto);
+        return users.convert(this::convert);
+    }
+
+    private UserVO convert(UserPo po) {
+        UserVO vo = new UserVO();
+        BeanUtils.copyProperties(po, vo);
+        // 将数据库存储的decimal转double
+        if (po.getPrice() != null) {
+            vo.setPrice(CommonUtil.parseDouble(po.getPrice()));
+        }
+        if (po.getBalance() != null) {
+            vo.setBalance(CommonUtil.parseDouble(po.getBalance()));
+        }
+        return vo;
+    }
+
+    @Override
+    @Transactional(rollbackFor = ServiceException.class)
+    public void saveUser(UserDto userDto) {
+        validate(userDto);
+
+        UserPo userPo = new UserPo();
+        BeanUtil.copyProperties(userPo, userDto);
+
+        userPo.setAppSecret(EncodeUtil.getAppSecret(userDto.getAppKey()));
+        userPo.setCreateTime(new Date());
+        userPo.setPassword(BCrypt.hashpw(userDto.getPassword(), BCrypt.gensalt()));
+
+        try {
+            userMapper.insert(userPo);
+        } catch (Exception e) {
+            log.error("新增用户失败,失败原因:{}", e.getMessage());
+            throw new ServiceException("新增用户失败");
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = ServiceException.class)
+    public Boolean updateUser(@RequestParam UserDto userDto) {
+        validate(userDto);
+
+        UserPo userPo = userMapper.getUserById(userDto.getId());
+        // todo 此方法需要完善,完善后不需要逐行if判断
+        AssertUtils.assertNotNull(userPo, CommonConstant.USER_NOT_EXIST);
+
+        if (!StringUtil.isNullOrEmpty(userDto.getPassword())) {
+            userPo.setPassword(BCrypt.hashpw(userDto.getPassword(), BCrypt.gensalt()));
+        }
+        if (!StringUtil.isNullOrEmpty(userDto.getCompany())) {
+            userPo.setCompany(userDto.getCompany());
+        }
+        if (!StringUtil.isNullOrEmpty(userDto.getContactName())) {
+            userPo.setContactName(userDto.getContactName());
+        }
+        if (!StringUtil.isNullOrEmpty(userDto.getTelephone())) {
+            userPo.setTelephone(userDto.getTelephone());
+        }
+        if (userDto.getPrice() != null) {
+            userPo.setPrice(userDto.getPrice());
+        }
+        if (userDto.getStatus() != null) {
+            userPo.setStatus(userDto.getStatus());
+        }
+        userPo.setUpdateTime(new Date());
+        return userMapper.updateById(userPo) == 1;
+    }
+
+    @Override
+    @Transactional(rollbackFor = ServiceException.class)
+    public void deleteUser(Long id) {
+        UserPo userPo = userMapper.getUserById(id);
+        if (userPo == null) {
+            throw new ServiceException(ExceptionMessage.USER_NOT_EXIST);
+        } else {
+            userPo.setActivated(CommonConstant.ACTIVATED_DELETED);
+            try {
+                userMapper.updateById(userPo);
+            } catch (Exception e) {
+                log.error("删除用户失败,失败原因:{}", e.getMessage());
+                throw new ServiceException("删除用户失败");
+            }
+        }
+    }
+}

+ 13 - 0
src/main/java/com/jkcredit/invoice/hub/service/userRolePermission/UserRolePermissionService.java

@@ -0,0 +1,13 @@
+package com.jkcredit.invoice.hub.service.userRolePermission;
+
+import com.jkcredit.invoice.hub.model.dto.userRolePermission.UserRolePermissionDto;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 17:44
+ * @version: V1.0
+ **/
+public interface UserRolePermissionService {
+    void saveUserRolePermission(UserRolePermissionDto dto);
+}

+ 51 - 0
src/main/java/com/jkcredit/invoice/hub/service/userRolePermission/UserRolePermissionServiceImpl.java

@@ -0,0 +1,51 @@
+package com.jkcredit.invoice.hub.service.userRolePermission;
+
+import com.jkcredit.invoice.hub.mapper.RolePermissionMapper;
+import com.jkcredit.invoice.hub.mapper.UserRolePermissionMapper;
+import com.jkcredit.invoice.hub.model.dto.userRolePermission.UserRolePermissionDto;
+import com.jkcredit.invoice.hub.model.po.userRolePermission.UserRolePermissionPo;
+import com.jkcredit.invoice.hub.service.base.BaseService;
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+import com.jkcredit.invoice.hub.util.BeanUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/13 17:45
+ * @version: V1.0
+ **/
+@Service
+@Slf4j
+public class UserRolePermissionServiceImpl extends BaseService implements UserRolePermissionService {
+    @Resource
+    UserRolePermissionMapper mapper;
+    @Resource
+    RolePermissionMapper rolePermissionMapper;
+
+    @Override
+    public void saveUserRolePermission(UserRolePermissionDto dto) {
+        validate(dto);
+        // todo 此处为用户授权接口,需要根据roleId 查询rolePermission表中的所以permissionId,循环放入userRolePermission
+        List<Long> permissions = rolePermissionMapper.getPermissions(dto.getRoleId());
+
+        try {
+            for (Long permission : permissions) {
+                UserRolePermissionPo userRolePermissionPo = new UserRolePermissionPo();
+                userRolePermissionPo.setUserId(dto.getUserId());
+                userRolePermissionPo.setRoleId(dto.getRoleId());
+                userRolePermissionPo.setPermissionId(permission);
+                userRolePermissionPo.setCreateTime(new Date());
+                mapper.insert(userRolePermissionPo);
+            }
+        } catch (Exception e) {
+            log.error("新增用户权限失败,失败原因:{}", e.getMessage());
+            throw new ServiceException("新增用户权限失败");
+        }
+    }
+}

+ 17 - 0
src/main/java/com/jkcredit/invoice/hub/spi/lang/exception/ServiceException.java

@@ -0,0 +1,17 @@
+package com.jkcredit.invoice.hub.spi.lang.exception;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2019/12/29 20:21
+ * @version: V1.0
+ **/
+public class ServiceException extends RuntimeException {
+
+    public ServiceException() {
+    }
+
+    public ServiceException(String message) {
+        super(message);
+    }
+}

+ 19 - 0
src/main/java/com/jkcredit/invoice/hub/spi/web/data/ApiRequestParam.java

@@ -0,0 +1,19 @@
+package com.jkcredit.invoice.hub.spi.web.data;
+
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/14 16:15
+ * @version: V1.0
+ **/
+@Data
+@ToString
+public class ApiRequestParam {
+    private String api;
+    private String appKey;
+    private String appSecret;
+    private Object data;
+}

+ 41 - 0
src/main/java/com/jkcredit/invoice/hub/spi/web/data/ResponseData.java

@@ -0,0 +1,41 @@
+package com.jkcredit.invoice.hub.spi.web.data;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 19:16
+ * @version: V1.0
+ **/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class ResponseData {
+    public static final int SUCCESS = 1;
+    public static final int FAILED = 0;
+    public static final String SUCCESS_MESSAGE = "成功";
+
+
+    private Integer code;
+    private String responseMessage;
+    private Object responseData;
+
+    public static ResponseData success(String message) {
+        return new ResponseData(SUCCESS, message, null);
+    }
+
+    public static ResponseData failed(String message) {
+        return new ResponseData(FAILED, message, null);
+    }
+
+    public static ResponseData success(Object object) {
+        return new ResponseData(SUCCESS, SUCCESS_MESSAGE, object);
+    }
+
+    public static ResponseData success(String meaage, Object object) {
+        return new ResponseData(SUCCESS, meaage, object);
+    }
+}

+ 19 - 0
src/main/java/com/jkcredit/invoice/hub/util/AssertUtils.java

@@ -0,0 +1,19 @@
+package com.jkcredit.invoice.hub.util;
+
+import com.jkcredit.invoice.hub.spi.lang.exception.ServiceException;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/12 19:59
+ * @version: V1.0
+ **/
+public class AssertUtils {
+
+    public static void assertNotNull(Object obj, String message) {
+        if (obj == null) {
+            throw new ServiceException(message);
+        }
+    }
+
+}

+ 25 - 0
src/main/java/com/jkcredit/invoice/hub/util/BeanUtil.java

@@ -0,0 +1,25 @@
+package com.jkcredit.invoice.hub.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.beanutils.PropertyUtils;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/2 10:01
+ * @version: V1.0
+ **/
+@Slf4j
+public class BeanUtil {
+
+    public static void copyProperties(Object dest, Object orig) {
+        try {
+            PropertyUtils.copyProperties(dest, orig);
+        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
+            log.error("属性复制错误, 错误原因: {}", e.getMessage(), e);
+        }
+    }
+
+}

+ 15 - 0
src/main/java/com/jkcredit/invoice/hub/util/CommonUtil.java

@@ -0,0 +1,15 @@
+package com.jkcredit.invoice.hub.util;
+
+import java.math.BigDecimal;
+
+/**
+ * @description:
+ * @author: xusonglin
+ * @create: 2020/1/9 21:01
+ * @version: V1.0
+ **/
+public class CommonUtil {
+    public static Double parseDouble(BigDecimal bigDecimal) {
+        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+    }
+}

+ 0 - 0
src/main/java/com/jkcredit/invoice/hub/util/EncodeUtil.java


部分文件因文件數量過多而無法顯示