Your Name 4 лет назад
Сommit
bce8bc91a6
100 измененных файлов: 10239 добавлений и 0 удалений
  1. 29
    0
      .gitignore
  2. 286
    0
      mvnw
  3. 161
    0
      mvnw.cmd
  4. 202
    0
      pom.xml
  5. 17
    0
      src/main/java/com/yunzhi/marketing/Application.java
  6. 88
    0
      src/main/java/com/yunzhi/marketing/activity/controller/ActivityController.java
  7. 37
    0
      src/main/java/com/yunzhi/marketing/activity/entity/Activity.java
  8. 23
    0
      src/main/java/com/yunzhi/marketing/activity/mapper/ActivityMapper.java
  9. 27
    0
      src/main/java/com/yunzhi/marketing/activity/service/ActivityServiceI.java
  10. 133
    0
      src/main/java/com/yunzhi/marketing/activity/service/impl/ActivityServiceImpl.java
  11. 143
    0
      src/main/java/com/yunzhi/marketing/base/BaseController.java
  12. 81
    0
      src/main/java/com/yunzhi/marketing/base/ResponseBean.java
  13. 38
    0
      src/main/java/com/yunzhi/marketing/base/UserControl.java
  14. 49
    0
      src/main/java/com/yunzhi/marketing/bo/request/ActivityStatisticResponseBO.java
  15. 88
    0
      src/main/java/com/yunzhi/marketing/bo/request/ContractRecordRequestBO.java
  16. 65
    0
      src/main/java/com/yunzhi/marketing/bo/request/HousingRaiseRequestBO.java
  17. 72
    0
      src/main/java/com/yunzhi/marketing/bo/request/PresecretRecordRequestBO.java
  18. 29
    0
      src/main/java/com/yunzhi/marketing/bo/request/QrCodeStatisticResponseBO.java
  19. 75
    0
      src/main/java/com/yunzhi/marketing/bo/request/RaiseOrderRequestBO.java
  20. 100
    0
      src/main/java/com/yunzhi/marketing/bo/request/RaiseRecordRequestBO.java
  21. 18
    0
      src/main/java/com/yunzhi/marketing/bo/request/SaveCzOrderRequestBO.java
  22. 18
    0
      src/main/java/com/yunzhi/marketing/bo/request/SaveRefundOrderRequestBO.java
  23. 143
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/controller/SysTokenController.java
  24. 269
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/controller/SysUserController.java
  25. 38
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/entity/SysToken.java
  26. 55
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/entity/SysUser.java
  27. 18
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/mapper/SysTokenMapper.java
  28. 18
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/mapper/SysUserMapper.java
  29. 17
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/service/ISysTokenService.java
  30. 16
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/service/ISysUserService.java
  31. 34
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/service/impl/SysTokenServiceImpl.java
  32. 20
    0
      src/main/java/com/yunzhi/marketing/center/sysUser/service/impl/SysUserServiceImpl.java
  33. 149
    0
      src/main/java/com/yunzhi/marketing/center/taUser/controller/TaButtonUriMapController.java
  34. 149
    0
      src/main/java/com/yunzhi/marketing/center/taUser/controller/TaTagUserController.java
  35. 150
    0
      src/main/java/com/yunzhi/marketing/center/taUser/controller/TaTagsController.java
  36. 68
    0
      src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserAuthButtonController.java
  37. 72
    0
      src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserAuthMenuController.java
  38. 566
    0
      src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserController.java
  39. 177
    0
      src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserRoleController.java
  40. 40
    0
      src/main/java/com/yunzhi/marketing/center/taUser/entity/TaButtonUriMap.java
  41. 35
    0
      src/main/java/com/yunzhi/marketing/center/taUser/entity/TaTagUser.java
  42. 53
    0
      src/main/java/com/yunzhi/marketing/center/taUser/entity/TaTags.java
  43. 270
    0
      src/main/java/com/yunzhi/marketing/center/taUser/entity/TaUser.java
  44. 51
    0
      src/main/java/com/yunzhi/marketing/center/taUser/entity/TaUserRole.java
  45. 20
    0
      src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaButtonUriMapMapper.java
  46. 18
    0
      src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaTagUserMapper.java
  47. 18
    0
      src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaTagsMapper.java
  48. 36
    0
      src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserAuthButtonMapper.java
  49. 44
    0
      src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserAuthMenuMapper.java
  50. 40
    0
      src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserMapper.java
  51. 18
    0
      src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserRoleMapper.java
  52. 17
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/ITaButtonUriMapService.java
  53. 16
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/ITaTagUserService.java
  54. 16
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/ITaTagsService.java
  55. 22
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserAuthButtonService.java
  56. 24
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserAuthMenuService.java
  57. 16
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserRoleService.java
  58. 78
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserService.java
  59. 28
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaButtonUriMapServiceImpl.java
  60. 20
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaTagUserServiceImpl.java
  61. 20
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaTagsServiceImpl.java
  62. 108
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserAuthButtonServiceImpl.java
  63. 197
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserAuthMenuServiceImpl.java
  64. 20
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserRoleServiceImpl.java
  65. 748
    0
      src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserServiceImpl.java
  66. 293
    0
      src/main/java/com/yunzhi/marketing/channel/sysChannel/controller/SysUserChannelController.java
  67. 41
    0
      src/main/java/com/yunzhi/marketing/channel/sysChannel/entity/TaChannelProxy.java
  68. 11
    0
      src/main/java/com/yunzhi/marketing/channel/sysChannel/mapper/TaChannelProxyMapper.java
  69. 12
    0
      src/main/java/com/yunzhi/marketing/channel/sysChannel/service/ITaChannelProxyService.java
  70. 55
    0
      src/main/java/com/yunzhi/marketing/channel/sysChannel/service/impl/TaChannelProxyServiceImpl.java
  71. 67
    0
      src/main/java/com/yunzhi/marketing/cleancode/CleanCode.java
  72. 62
    0
      src/main/java/com/yunzhi/marketing/common/AliOSSUtils.java
  73. 137
    0
      src/main/java/com/yunzhi/marketing/common/BeanTools.java
  74. 919
    0
      src/main/java/com/yunzhi/marketing/common/CommConstant.java
  75. 86
    0
      src/main/java/com/yunzhi/marketing/common/CommonUtils.java
  76. 15
    0
      src/main/java/com/yunzhi/marketing/common/DBUtils.java
  77. 117
    0
      src/main/java/com/yunzhi/marketing/common/DateUtils.java
  78. 35
    0
      src/main/java/com/yunzhi/marketing/common/ExcelUtils.java
  79. 109
    0
      src/main/java/com/yunzhi/marketing/common/JWTUtils.java
  80. 16
    0
      src/main/java/com/yunzhi/marketing/common/MD5Utils.java
  81. 90
    0
      src/main/java/com/yunzhi/marketing/common/MiniAppPageEnum.java
  82. 18
    0
      src/main/java/com/yunzhi/marketing/common/NumberUtils.java
  83. 165
    0
      src/main/java/com/yunzhi/marketing/common/SMSUtils.java
  84. 72
    0
      src/main/java/com/yunzhi/marketing/common/StringConverter.java
  85. 108
    0
      src/main/java/com/yunzhi/marketing/common/StringUtils.java
  86. 33
    0
      src/main/java/com/yunzhi/marketing/common/WxQrCodeUtils.java
  87. 59
    0
      src/main/java/com/yunzhi/marketing/common/WxUtils.java
  88. 42
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/IWXPayDomain.java
  89. 688
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPay.java
  90. 103
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPayConfig.java
  91. 59
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPayConstants.java
  92. 106
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPayRefundReason.java
  93. 265
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPayReport.java
  94. 256
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPayRequest.java
  95. 294
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPayUtil.java
  96. 30
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WXPayXmlUtil.java
  97. 105
    0
      src/main/java/com/yunzhi/marketing/common/wxpay/WxConfig.java
  98. 26
    0
      src/main/java/com/yunzhi/marketing/config/AccessConfig.java
  99. 34
    0
      src/main/java/com/yunzhi/marketing/config/AliOSSProperties.java
  100. 0
    0
      src/main/java/com/yunzhi/marketing/config/FadadaProperties.java

+ 29
- 0
.gitignore Просмотреть файл

@@ -0,0 +1,29 @@
1
+HELP.md
2
+/target/
3
+!.mvn/wrapper/maven-wrapper.jar
4
+
5
+### STS ###
6
+.apt_generated
7
+.classpath
8
+.factorypath
9
+.project
10
+.settings
11
+.springBeans
12
+.sts4-cache
13
+
14
+### IntelliJ IDEA ###
15
+.idea
16
+*.iws
17
+*.iml
18
+*.ipr
19
+
20
+### NetBeans ###
21
+/nbproject/private/
22
+/nbbuild/
23
+/dist/
24
+/nbdist/
25
+/.nb-gradle/
26
+/build/
27
+
28
+### VS Code ###
29
+.vscode/

+ 286
- 0
mvnw Просмотреть файл

@@ -0,0 +1,286 @@
1
+#!/bin/sh
2
+# ----------------------------------------------------------------------------
3
+# Licensed to the Apache Software Foundation (ASF) under one
4
+# or more contributor license agreements.  See the NOTICE file
5
+# distributed with this work for additional information
6
+# regarding copyright ownership.  The ASF licenses this file
7
+# to you under the Apache License, Version 2.0 (the
8
+# "License"); you may not use this file except in compliance
9
+# with the License.  You may obtain a copy of the License at
10
+#
11
+#    https://www.apache.org/licenses/LICENSE-2.0
12
+#
13
+# Unless required by applicable law or agreed to in writing,
14
+# software distributed under the License is distributed on an
15
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+# KIND, either express or implied.  See the License for the
17
+# specific language governing permissions and limitations
18
+# under the License.
19
+# ----------------------------------------------------------------------------
20
+
21
+# ----------------------------------------------------------------------------
22
+# Maven2 Start Up Batch script
23
+#
24
+# Required ENV vars:
25
+# ------------------
26
+#   JAVA_HOME - location of a JDK home dir
27
+#
28
+# Optional ENV vars
29
+# -----------------
30
+#   M2_HOME - location of maven2's installed home dir
31
+#   MAVEN_OPTS - parameters passed to the Java VM when running Maven
32
+#     e.g. to debug Maven itself, use
33
+#       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34
+#   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35
+# ----------------------------------------------------------------------------
36
+
37
+if [ -z "$MAVEN_SKIP_RC" ] ; then
38
+
39
+  if [ -f /etc/mavenrc ] ; then
40
+    . /etc/mavenrc
41
+  fi
42
+
43
+  if [ -f "$HOME/.mavenrc" ] ; then
44
+    . "$HOME/.mavenrc"
45
+  fi
46
+
47
+fi
48
+
49
+# OS specific support.  $var _must_ be set to either true or false.
50
+cygwin=false;
51
+darwin=false;
52
+mingw=false
53
+case "`uname`" in
54
+  CYGWIN*) cygwin=true ;;
55
+  MINGW*) mingw=true;;
56
+  Darwin*) darwin=true
57
+    # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59
+    if [ -z "$JAVA_HOME" ]; then
60
+      if [ -x "/usr/libexec/java_home" ]; then
61
+        export JAVA_HOME="`/usr/libexec/java_home`"
62
+      else
63
+        export JAVA_HOME="/Library/Java/Home"
64
+      fi
65
+    fi
66
+    ;;
67
+esac
68
+
69
+if [ -z "$JAVA_HOME" ] ; then
70
+  if [ -r /etc/gentoo-release ] ; then
71
+    JAVA_HOME=`java-config --jre-home`
72
+  fi
73
+fi
74
+
75
+if [ -z "$M2_HOME" ] ; then
76
+  ## resolve links - $0 may be a link to maven's home
77
+  PRG="$0"
78
+
79
+  # need this for relative symlinks
80
+  while [ -h "$PRG" ] ; do
81
+    ls=`ls -ld "$PRG"`
82
+    link=`expr "$ls" : '.*-> \(.*\)$'`
83
+    if expr "$link" : '/.*' > /dev/null; then
84
+      PRG="$link"
85
+    else
86
+      PRG="`dirname "$PRG"`/$link"
87
+    fi
88
+  done
89
+
90
+  saveddir=`pwd`
91
+
92
+  M2_HOME=`dirname "$PRG"`/..
93
+
94
+  # make it fully qualified
95
+  M2_HOME=`cd "$M2_HOME" && pwd`
96
+
97
+  cd "$saveddir"
98
+  # echo Using m2 at $M2_HOME
99
+fi
100
+
101
+# For Cygwin, ensure paths are in UNIX format before anything is touched
102
+if $cygwin ; then
103
+  [ -n "$M2_HOME" ] &&
104
+    M2_HOME=`cygpath --unix "$M2_HOME"`
105
+  [ -n "$JAVA_HOME" ] &&
106
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107
+  [ -n "$CLASSPATH" ] &&
108
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109
+fi
110
+
111
+# For Mingw, ensure paths are in UNIX format before anything is touched
112
+if $mingw ; then
113
+  [ -n "$M2_HOME" ] &&
114
+    M2_HOME="`(cd "$M2_HOME"; pwd)`"
115
+  [ -n "$JAVA_HOME" ] &&
116
+    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117
+  # TODO classpath?
118
+fi
119
+
120
+if [ -z "$JAVA_HOME" ]; then
121
+  javaExecutable="`which javac`"
122
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123
+    # readlink(1) is not available as standard on Solaris 10.
124
+    readLink=`which readlink`
125
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126
+      if $darwin ; then
127
+        javaHome="`dirname \"$javaExecutable\"`"
128
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129
+      else
130
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
131
+      fi
132
+      javaHome="`dirname \"$javaExecutable\"`"
133
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134
+      JAVA_HOME="$javaHome"
135
+      export JAVA_HOME
136
+    fi
137
+  fi
138
+fi
139
+
140
+if [ -z "$JAVACMD" ] ; then
141
+  if [ -n "$JAVA_HOME"  ] ; then
142
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143
+      # IBM's JDK on AIX uses strange locations for the executables
144
+      JAVACMD="$JAVA_HOME/jre/sh/java"
145
+    else
146
+      JAVACMD="$JAVA_HOME/bin/java"
147
+    fi
148
+  else
149
+    JAVACMD="`which java`"
150
+  fi
151
+fi
152
+
153
+if [ ! -x "$JAVACMD" ] ; then
154
+  echo "Error: JAVA_HOME is not defined correctly." >&2
155
+  echo "  We cannot execute $JAVACMD" >&2
156
+  exit 1
157
+fi
158
+
159
+if [ -z "$JAVA_HOME" ] ; then
160
+  echo "Warning: JAVA_HOME environment variable is not set."
161
+fi
162
+
163
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164
+
165
+# traverses directory structure from process work directory to filesystem root
166
+# first directory with .mvn subdirectory is considered project base directory
167
+find_maven_basedir() {
168
+
169
+  if [ -z "$1" ]
170
+  then
171
+    echo "Path not specified to find_maven_basedir"
172
+    return 1
173
+  fi
174
+
175
+  basedir="$1"
176
+  wdir="$1"
177
+  while [ "$wdir" != '/' ] ; do
178
+    if [ -d "$wdir"/.mvn ] ; then
179
+      basedir=$wdir
180
+      break
181
+    fi
182
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183
+    if [ -d "${wdir}" ]; then
184
+      wdir=`cd "$wdir/.."; pwd`
185
+    fi
186
+    # end of workaround
187
+  done
188
+  echo "${basedir}"
189
+}
190
+
191
+# concatenates all lines of a file
192
+concat_lines() {
193
+  if [ -f "$1" ]; then
194
+    echo "$(tr -s '\n' ' ' < "$1")"
195
+  fi
196
+}
197
+
198
+BASE_DIR=`find_maven_basedir "$(pwd)"`
199
+if [ -z "$BASE_DIR" ]; then
200
+  exit 1;
201
+fi
202
+
203
+##########################################################################################
204
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
205
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
206
+##########################################################################################
207
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
208
+    if [ "$MVNW_VERBOSE" = true ]; then
209
+      echo "Found .mvn/wrapper/maven-wrapper.jar"
210
+    fi
211
+else
212
+    if [ "$MVNW_VERBOSE" = true ]; then
213
+      echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
214
+    fi
215
+    jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
216
+    while IFS="=" read key value; do
217
+      case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
218
+      esac
219
+    done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
220
+    if [ "$MVNW_VERBOSE" = true ]; then
221
+      echo "Downloading from: $jarUrl"
222
+    fi
223
+    wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
224
+
225
+    if command -v wget > /dev/null; then
226
+        if [ "$MVNW_VERBOSE" = true ]; then
227
+          echo "Found wget ... using wget"
228
+        fi
229
+        wget "$jarUrl" -O "$wrapperJarPath"
230
+    elif command -v curl > /dev/null; then
231
+        if [ "$MVNW_VERBOSE" = true ]; then
232
+          echo "Found curl ... using curl"
233
+        fi
234
+        curl -o "$wrapperJarPath" "$jarUrl"
235
+    else
236
+        if [ "$MVNW_VERBOSE" = true ]; then
237
+          echo "Falling back to using Java to download"
238
+        fi
239
+        javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
240
+        if [ -e "$javaClass" ]; then
241
+            if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
242
+                if [ "$MVNW_VERBOSE" = true ]; then
243
+                  echo " - Compiling MavenWrapperDownloader.java ..."
244
+                fi
245
+                # Compiling the Java class
246
+                ("$JAVA_HOME/bin/javac" "$javaClass")
247
+            fi
248
+            if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
249
+                # Running the downloader
250
+                if [ "$MVNW_VERBOSE" = true ]; then
251
+                  echo " - Running MavenWrapperDownloader.java ..."
252
+                fi
253
+                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
254
+            fi
255
+        fi
256
+    fi
257
+fi
258
+##########################################################################################
259
+# End of extension
260
+##########################################################################################
261
+
262
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
263
+if [ "$MVNW_VERBOSE" = true ]; then
264
+  echo $MAVEN_PROJECTBASEDIR
265
+fi
266
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
267
+
268
+# For Cygwin, switch paths to Windows format before running java
269
+if $cygwin; then
270
+  [ -n "$M2_HOME" ] &&
271
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
272
+  [ -n "$JAVA_HOME" ] &&
273
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
274
+  [ -n "$CLASSPATH" ] &&
275
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
276
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
277
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
278
+fi
279
+
280
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281
+
282
+exec "$JAVACMD" \
283
+  $MAVEN_OPTS \
284
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
285
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
286
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 161
- 0
mvnw.cmd Просмотреть файл

@@ -0,0 +1,161 @@
1
+@REM ----------------------------------------------------------------------------
2
+@REM Licensed to the Apache Software Foundation (ASF) under one
3
+@REM or more contributor license agreements.  See the NOTICE file
4
+@REM distributed with this work for additional information
5
+@REM regarding copyright ownership.  The ASF licenses this file
6
+@REM to you under the Apache License, Version 2.0 (the
7
+@REM "License"); you may not use this file except in compliance
8
+@REM with the License.  You may obtain a copy of the License at
9
+@REM
10
+@REM    https://www.apache.org/licenses/LICENSE-2.0
11
+@REM
12
+@REM Unless required by applicable law or agreed to in writing,
13
+@REM software distributed under the License is distributed on an
14
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+@REM KIND, either express or implied.  See the License for the
16
+@REM specific language governing permissions and limitations
17
+@REM under the License.
18
+@REM ----------------------------------------------------------------------------
19
+
20
+@REM ----------------------------------------------------------------------------
21
+@REM Maven2 Start Up Batch script
22
+@REM
23
+@REM Required ENV vars:
24
+@REM JAVA_HOME - location of a JDK home dir
25
+@REM
26
+@REM Optional ENV vars
27
+@REM M2_HOME - location of maven2's installed home dir
28
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31
+@REM     e.g. to debug Maven itself, use
32
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34
+@REM ----------------------------------------------------------------------------
35
+
36
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37
+@echo off
38
+@REM set title of command window
39
+title %0
40
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
41
+@if "%MAVEN_BATCH_ECHO%" == "on"  echo %MAVEN_BATCH_ECHO%
42
+
43
+@REM set %HOME% to equivalent of $HOME
44
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45
+
46
+@REM Execute a user defined script before this one
47
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
49
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51
+:skipRcPre
52
+
53
+@setlocal
54
+
55
+set ERROR_CODE=0
56
+
57
+@REM To isolate internal variables from possible post scripts, we use another setlocal
58
+@setlocal
59
+
60
+@REM ==== START VALIDATION ====
61
+if not "%JAVA_HOME%" == "" goto OkJHome
62
+
63
+echo.
64
+echo Error: JAVA_HOME not found in your environment. >&2
65
+echo Please set the JAVA_HOME variable in your environment to match the >&2
66
+echo location of your Java installation. >&2
67
+echo.
68
+goto error
69
+
70
+:OkJHome
71
+if exist "%JAVA_HOME%\bin\java.exe" goto init
72
+
73
+echo.
74
+echo Error: JAVA_HOME is set to an invalid directory. >&2
75
+echo JAVA_HOME = "%JAVA_HOME%" >&2
76
+echo Please set the JAVA_HOME variable in your environment to match the >&2
77
+echo location of your Java installation. >&2
78
+echo.
79
+goto error
80
+
81
+@REM ==== END VALIDATION ====
82
+
83
+:init
84
+
85
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86
+@REM Fallback to current working directory if not found.
87
+
88
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90
+
91
+set EXEC_DIR=%CD%
92
+set WDIR=%EXEC_DIR%
93
+:findBaseDir
94
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
95
+cd ..
96
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
97
+set WDIR=%CD%
98
+goto findBaseDir
99
+
100
+:baseDirFound
101
+set MAVEN_PROJECTBASEDIR=%WDIR%
102
+cd "%EXEC_DIR%"
103
+goto endDetectBaseDir
104
+
105
+:baseDirNotFound
106
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107
+cd "%EXEC_DIR%"
108
+
109
+:endDetectBaseDir
110
+
111
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112
+
113
+@setlocal EnableExtensions EnableDelayedExpansion
114
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116
+
117
+:endReadAdditionalConfig
118
+
119
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122
+
123
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
124
+FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125
+	IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 
126
+)
127
+
128
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130
+if exist %WRAPPER_JAR% (
131
+    echo Found %WRAPPER_JAR%
132
+) else (
133
+    echo Couldn't find %WRAPPER_JAR%, downloading it ...
134
+	echo Downloading from: %DOWNLOAD_URL%
135
+    powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136
+    echo Finished downloading %WRAPPER_JAR%
137
+)
138
+@REM End of extension
139
+
140
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
141
+if ERRORLEVEL 1 goto error
142
+goto end
143
+
144
+:error
145
+set ERROR_CODE=1
146
+
147
+:end
148
+@endlocal & set ERROR_CODE=%ERROR_CODE%
149
+
150
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
151
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
152
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
153
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
154
+:skipRcPost
155
+
156
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
157
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
158
+
159
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
160
+
161
+exit /B %ERROR_CODE%

+ 202
- 0
pom.xml Просмотреть файл

@@ -0,0 +1,202 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+	<parent>
6
+		<groupId>org.springframework.boot</groupId>
7
+		<artifactId>spring-boot-starter-parent</artifactId>
8
+		<version>2.1.4.RELEASE</version>
9
+		<relativePath/> <!-- lookup parent from repository -->
10
+	</parent>
11
+	<groupId>com.yunzhi</groupId>
12
+	<artifactId>marketing</artifactId>
13
+	<version>v1.0.7</version>
14
+	<name>marketing-cloud</name>
15
+	<description>新联康营销云</description>
16
+
17
+	<properties>
18
+		<java.version>1.8</java.version>
19
+	</properties>
20
+
21
+	<dependencies>
22
+		<dependency>
23
+			<groupId>org.springframework.boot</groupId>
24
+			<artifactId>spring-boot-starter-web</artifactId>
25
+		</dependency>
26
+		<dependency>
27
+			<groupId>org.springframework.boot</groupId>
28
+			<artifactId>spring-boot-configuration-processor</artifactId>
29
+			<optional>true</optional>
30
+		</dependency>
31
+		<dependency>
32
+			<groupId>com.baomidou</groupId>
33
+			<artifactId>mybatis-plus-boot-starter</artifactId>
34
+			<version>3.1.1</version>
35
+		</dependency>
36
+		<dependency>
37
+			<groupId>org.springframework.boot</groupId>
38
+			<artifactId>spring-boot-starter-websocket</artifactId>
39
+		</dependency>
40
+
41
+		<dependency>
42
+			<groupId>mysql</groupId>
43
+			<artifactId>mysql-connector-java</artifactId>
44
+			<scope>runtime</scope>
45
+		</dependency>
46
+		<dependency>
47
+			<groupId>org.projectlombok</groupId>
48
+			<artifactId>lombok</artifactId>
49
+			<optional>true</optional>
50
+		</dependency>
51
+		<dependency>
52
+			<groupId>org.springframework.boot</groupId>
53
+			<artifactId>spring-boot-starter-test</artifactId>
54
+			<scope>test</scope>
55
+		</dependency>
56
+		<dependency>
57
+			<groupId>com.github.binarywang</groupId>
58
+			<artifactId>weixin-java-miniapp</artifactId>
59
+			<version>3.8.0</version>
60
+		</dependency>
61
+		<dependency>
62
+			<groupId>com.github.binarywang</groupId>
63
+			<artifactId>weixin-java-mp</artifactId>
64
+			<version>3.8.0</version>
65
+		</dependency>
66
+		<dependency>
67
+			<groupId>com.github.binarywang</groupId>
68
+			<artifactId>weixin-java-pay</artifactId>
69
+			<version>3.8.0</version>
70
+		</dependency>
71
+		<dependency>
72
+			<groupId>com.alibaba</groupId>
73
+			<artifactId>fastjson</artifactId>
74
+			<version>1.2.56</version>
75
+		</dependency>
76
+		<dependency>
77
+			<groupId>io.jsonwebtoken</groupId>
78
+			<artifactId>jjwt-api</artifactId>
79
+			<version>0.10.5</version>
80
+		</dependency>
81
+		<dependency>
82
+			<groupId>io.jsonwebtoken</groupId>
83
+			<artifactId>jjwt-impl</artifactId>
84
+			<version>0.10.5</version>
85
+			<scope>runtime</scope>
86
+		</dependency>
87
+		<dependency>
88
+			<groupId>io.jsonwebtoken</groupId>
89
+			<artifactId>jjwt-jackson</artifactId>
90
+			<version>0.10.5</version>
91
+			<scope>runtime</scope>
92
+		</dependency>
93
+		<dependency>
94
+			<groupId>com.aliyun.oss</groupId>
95
+			<artifactId>aliyun-sdk-oss</artifactId>
96
+			<version>2.8.3</version>
97
+		</dependency>
98
+		<!-- https://mvnrepository.com/artifact/org.dom4j/dom4j -->
99
+		<dependency>
100
+			<groupId>org.dom4j</groupId>
101
+			<artifactId>dom4j</artifactId>
102
+			<version>2.1.1</version>
103
+		</dependency>
104
+		<dependency>
105
+			<groupId>org.jodd</groupId>
106
+			<artifactId>jodd-bean</artifactId>
107
+			<version>3.7.1</version>
108
+		</dependency>
109
+		<dependency>
110
+			<groupId>commons-collections</groupId>
111
+			<artifactId>commons-collections</artifactId>
112
+			<version>3.2.1</version>
113
+		</dependency>
114
+
115
+		<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
116
+		<dependency>
117
+			<groupId>com.google.guava</groupId>
118
+			<artifactId>guava</artifactId>
119
+			<version>26.0-jre</version>
120
+		</dependency>
121
+
122
+		<!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
123
+		<dependency>
124
+			<groupId>com.alibaba</groupId>
125
+			<artifactId>easyexcel</artifactId>
126
+			<version>2.0.4</version>
127
+		</dependency>
128
+
129
+		<!-- swagger2 -->
130
+		<dependency>
131
+			<groupId>io.springfox</groupId>
132
+			<artifactId>springfox-swagger2</artifactId>
133
+			<version>2.7.0</version>
134
+		</dependency>
135
+
136
+		<dependency>
137
+			<groupId>io.springfox</groupId>
138
+			<artifactId>springfox-swagger-ui</artifactId>
139
+			<version>2.7.0</version>
140
+		</dependency>
141
+
142
+        <!-- aop 依赖 -->
143
+        <dependency>
144
+            <groupId>org.springframework.boot</groupId>
145
+            <artifactId>spring-boot-starter-aop</artifactId>
146
+        </dependency>
147
+
148
+
149
+		<dependency>
150
+			<groupId>fadada</groupId>
151
+			<artifactId>fadada_api_sdk</artifactId>
152
+			<version>2.4.0</version>
153
+			<scope>system</scope>
154
+			<systemPath>${basedir}/src/main/resources/lib/fadada_api_sdk_2.4.0.jar</systemPath>
155
+		</dependency>
156
+	</dependencies>
157
+
158
+
159
+	<profiles>
160
+		<profile>
161
+			<id>dev</id>
162
+			<properties>
163
+				<profiles.active>dev</profiles.active>
164
+			</properties>
165
+		</profile>
166
+		<profile>
167
+			<id>prod</id>
168
+			<properties>
169
+				<profiles.active>prod</profiles.active>
170
+			</properties>
171
+		</profile>
172
+	</profiles>
173
+	<build>
174
+		<plugins>
175
+			<plugin>
176
+				<groupId>org.springframework.boot</groupId>
177
+				<artifactId>spring-boot-maven-plugin</artifactId>
178
+			</plugin>
179
+		</plugins>
180
+		<resources>
181
+				<resource>
182
+					<directory>${basedir}/src/main/resources/lib</directory>
183
+					<targetPath>BOOT-INF/lib/</targetPath>
184
+					<includes>
185
+						<include>**/*.jar</include>
186
+					</includes>
187
+				</resource>
188
+                <resource>
189
+                    <directory>src/main/resources</directory>
190
+                    <filtering>true</filtering>
191
+                    <includes>
192
+                        <include>application.yml</include>
193
+                        <include>application-${profiles.active}.yml</include>
194
+                        <include>mapper/**/*.xml</include>
195
+                        <include>log/*.xml</include>
196
+                        <include>lib/*.jar</include>
197
+                    </includes>
198
+                </resource>
199
+            </resources>
200
+        </build>
201
+
202
+    </project>

+ 17
- 0
src/main/java/com/yunzhi/marketing/Application.java Просмотреть файл

@@ -0,0 +1,17 @@
1
+package com.yunzhi.marketing;
2
+
3
+import com.yunzhi.marketing.websocket.ChatServer;
4
+import org.springframework.boot.SpringApplication;
5
+import org.springframework.boot.autoconfigure.SpringBootApplication;
6
+import org.springframework.context.ConfigurableApplicationContext;
7
+
8
+@SpringBootApplication
9
+public class Application {
10
+
11
+	public static void main(String[] args) {
12
+		SpringApplication springApplication = new SpringApplication(Application.class);
13
+		ConfigurableApplicationContext configurableApplicationContext = springApplication.run(args);
14
+		ChatServer.setApplicationContext(configurableApplicationContext);
15
+	}
16
+
17
+}

+ 88
- 0
src/main/java/com/yunzhi/marketing/activity/controller/ActivityController.java Просмотреть файл

@@ -0,0 +1,88 @@
1
+package com.yunzhi.marketing.activity.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
+import com.yunzhi.marketing.activity.service.ActivityServiceI;
6
+import com.yunzhi.marketing.base.BaseController;
7
+import com.yunzhi.marketing.base.ResponseBean;
8
+import com.yunzhi.marketing.entity.TaPerson;
9
+import com.yunzhi.marketing.entity.TaRecommendCustomer;
10
+import com.yunzhi.marketing.service.ITaPersonService;
11
+import com.yunzhi.marketing.service.ITaRecommendCustomerService;
12
+import io.swagger.annotations.Api;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.web.bind.annotation.RequestMapping;
15
+import org.springframework.web.bind.annotation.RequestMethod;
16
+import org.springframework.web.bind.annotation.RequestParam;
17
+import org.springframework.web.bind.annotation.RestController;
18
+
19
+import javax.servlet.http.HttpServletRequest;
20
+import java.util.List;
21
+
22
+/**
23
+ * @author FXF
24
+ * @date 2019-10-21
25
+ */
26
+@RestController
27
+@RequestMapping("/api")
28
+@Api(value = "所有活动", tags = "所有活动")
29
+public class ActivityController extends BaseController {
30
+	
31
+	@Autowired
32
+	private ActivityServiceI activityService;
33
+	
34
+	@Autowired
35
+	private ITaPersonService taPersonService;
36
+	
37
+	@Autowired
38
+	ITaRecommendCustomerService taRecommendCustomerService;
39
+	
40
+	@RequestMapping(value = "/wx/activity/list", method = RequestMethod.GET)
41
+	public ResponseBean wxBuildingDynamiceList(@RequestParam(value = "pageNumber",defaultValue = "1")Integer pageNumber,
42
+                                               @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
43
+                                               @RequestParam(value = "cityId",required = false)Integer cityId,
44
+                                               HttpServletRequest request){
45
+		String openid = getOpenId(request);
46
+		Integer orgId = getOrgId(request);
47
+		ResponseBean  responseBean = new ResponseBean();
48
+		List<TaPerson> taPersons = taPersonService.getPersonsByOpenId(openid);
49
+		if (null == taPersons || taPersons.size() != 1) {
50
+			return responseBean.error("验证人员信息失败", ResponseBean.ERROR_UNAVAILABLE);
51
+		}
52
+		TaPerson person = taPersons.get(0);
53
+		responseBean = activityService.getActivityList(pageNumber,pageSize,orgId,person,cityId);
54
+		
55
+		return responseBean;
56
+	}
57
+	
58
+	@RequestMapping(value = "/wx/customer/activity/list", method = RequestMethod.GET)
59
+	public ResponseBean wxActivityList(@RequestParam(value = "pageNumber",defaultValue = "1")Integer pageNumber,
60
+	                                           @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
61
+	                                           @RequestParam(value = "customerId") String customerId,
62
+	                                           HttpServletRequest request){
63
+		ResponseBean  responseBean = new ResponseBean();
64
+		Integer orgId = getOrgId(request);
65
+		//查找客户信息
66
+		QueryWrapper<TaRecommendCustomer> queryWrapper = new QueryWrapper<>();
67
+		queryWrapper.eq("customer_id",customerId);
68
+		TaRecommendCustomer taRecommendCustomer = taRecommendCustomerService.getOne(queryWrapper);
69
+		if (null == taRecommendCustomer){
70
+			//验证人员信息失败小程序端希望是空数组对象
71
+			return ResponseBean.success(new Page(pageNumber,pageSize));
72
+		}
73
+		if (null == taRecommendCustomer.getPersonId()){
74
+			//验证人员信息失败小程序端希望是空数组对象
75
+			return ResponseBean.success(new Page(pageNumber,pageSize));
76
+		}
77
+		
78
+		QueryWrapper<TaPerson> taPersonQueryWrapper = new QueryWrapper<>();
79
+		taPersonQueryWrapper.eq("person_id",taRecommendCustomer.getPersonId());
80
+		TaPerson person = taPersonService.getOne(taPersonQueryWrapper);
81
+		if (null == person){
82
+			//验证人员信息失败小程序端希望是空数组对象
83
+			return ResponseBean.success(new Page(pageNumber,pageSize));
84
+		}
85
+		responseBean = activityService.getCustomerActivityList(pageNumber,pageSize,orgId,person);
86
+		return responseBean;
87
+	}
88
+}

+ 37
- 0
src/main/java/com/yunzhi/marketing/activity/entity/Activity.java Просмотреть файл

@@ -0,0 +1,37 @@
1
+package com.yunzhi.marketing.activity.entity;
2
+
3
+import lombok.Data;
4
+
5
+import java.time.LocalDateTime;
6
+
7
+/**
8
+ * @author FXF
9
+ * @date 2019-10-21
10
+ */
11
+@Data
12
+public class Activity {
13
+
14
+	private Object id;
15
+	
16
+	private String mainImg;
17
+	
18
+	private String title;
19
+	
20
+	private LocalDateTime startDate;
21
+	
22
+	private LocalDateTime endDate;
23
+	
24
+	private Integer weight;
25
+	
26
+	/**
27
+	 *  0:进行中 1:未开始 2:已结束 3:已参与(微信端用)
28
+	 */
29
+	private Integer activityStatus;
30
+	
31
+	private String type;
32
+	
33
+	/**
34
+	 * 完成数量
35
+	 */
36
+	private Integer successNum;
37
+}

+ 23
- 0
src/main/java/com/yunzhi/marketing/activity/mapper/ActivityMapper.java Просмотреть файл

@@ -0,0 +1,23 @@
1
+package com.yunzhi.marketing.activity.mapper;
2
+
3
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
4
+import com.yunzhi.marketing.activity.entity.Activity;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
9
+import java.util.Map;
10
+
11
+@Mapper
12
+public interface ActivityMapper {
13
+	List<Activity> getActivityList(Page pg, @Param("orgId") Integer orgId, @Param("status") Integer status, @Param("cityId") Integer cityId);
14
+	
15
+	/**
16
+	 * 获取客户参与的活动列表
17
+	 * @param pg
18
+	 * @param orgId
19
+	 * @param personId
20
+	 * @return
21
+	 */
22
+	List<Map<String,Object>> getCustomerActivityList(Page pg,@Param("orgId") Integer orgId,@Param("personId") String personId);
23
+}

+ 27
- 0
src/main/java/com/yunzhi/marketing/activity/service/ActivityServiceI.java Просмотреть файл

@@ -0,0 +1,27 @@
1
+package com.yunzhi.marketing.activity.service;
2
+
3
+import com.yunzhi.marketing.base.ResponseBean;
4
+import com.yunzhi.marketing.entity.TaPerson;
5
+
6
+public interface ActivityServiceI {
7
+	
8
+	/**
9
+	 * 获取三个活动
10
+	 * @param pageNumber
11
+	 * @param pageSize
12
+	 * @param orgId
13
+	 * @param person
14
+	 * @return
15
+	 */
16
+	ResponseBean getActivityList(Integer pageNumber, Integer pageSize, Integer orgId, TaPerson person, Integer cityId);
17
+	
18
+	/**
19
+	 * 获取客户参加的活动信息
20
+	 * @param pageNumber
21
+	 * @param pageSize
22
+	 * @param orgId
23
+	 * @param person
24
+	 * @return
25
+	 */
26
+	ResponseBean getCustomerActivityList(Integer pageNumber, Integer pageSize, Integer orgId, TaPerson person);
27
+}

+ 133
- 0
src/main/java/com/yunzhi/marketing/activity/service/impl/ActivityServiceImpl.java Просмотреть файл

@@ -0,0 +1,133 @@
1
+package com.yunzhi.marketing.activity.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
+import com.yunzhi.marketing.activity.entity.Activity;
6
+import com.yunzhi.marketing.activity.mapper.ActivityMapper;
7
+import com.yunzhi.marketing.activity.service.ActivityServiceI;
8
+import com.yunzhi.marketing.base.ResponseBean;
9
+import com.yunzhi.marketing.common.CommConstant;
10
+import com.yunzhi.marketing.entity.HelpInitiateRecord;
11
+import com.yunzhi.marketing.entity.TaActivityDynamicEnlist;
12
+import com.yunzhi.marketing.entity.TaPerson;
13
+import com.yunzhi.marketing.entity.TaShareRecord;
14
+import com.yunzhi.marketing.mapper.HelpInitiateRecordMapper;
15
+import com.yunzhi.marketing.mapper.HelpRecordMapper;
16
+import com.yunzhi.marketing.mapper.TaActivityDynamicEnlistMapper;
17
+import com.yunzhi.marketing.mapper.TaShareRecordMapper;
18
+import org.springframework.beans.factory.annotation.Autowired;
19
+import org.springframework.stereotype.Service;
20
+
21
+import java.util.List;
22
+import java.util.Map;
23
+
24
+/**
25
+ * @author FXF
26
+ * @date 2019-10-21
27
+ */
28
+@Service
29
+public class ActivityServiceImpl implements ActivityServiceI {
30
+	
31
+	@Autowired
32
+	private ActivityMapper activityMapper;
33
+	
34
+	@Autowired
35
+	private TaActivityDynamicEnlistMapper taActivityDynamicEnlistMapper;
36
+	
37
+	@Autowired
38
+	private TaShareRecordMapper taShareRecordMapper;
39
+	
40
+	@Autowired
41
+	private HelpRecordMapper helpRecordMapper;
42
+	
43
+	@Autowired
44
+	private HelpInitiateRecordMapper helpInitiateRecordMapper;
45
+	
46
+	/**
47
+	 * 获取三个活动
48
+	 *
49
+	 * @param pageNumber
50
+	 * @param pageSize
51
+	 * @param orgId
52
+	 * @param person
53
+	 * @return
54
+	 */
55
+	@Override
56
+	public ResponseBean getActivityList(Integer pageNumber, Integer pageSize, Integer orgId, TaPerson person, Integer cityId) {
57
+		//查询是否报名了普通活动
58
+		QueryWrapper<TaActivityDynamicEnlist> queryWrapper = new QueryWrapper<>();
59
+		queryWrapper.eq("org_id",orgId);
60
+		queryWrapper.eq("person_id",person.getPersonId());
61
+		List<TaActivityDynamicEnlist> taActivityDynamicEnlists = taActivityDynamicEnlistMapper.selectList(queryWrapper);
62
+		//查询是否报名了拼团活动
63
+		QueryWrapper<TaShareRecord> taShareRecordQueryWrapper = new QueryWrapper<>();
64
+		taShareRecordQueryWrapper.eq("org_id",orgId);
65
+		taShareRecordQueryWrapper.eq("person_id",person.getPersonId());
66
+		List<TaShareRecord> taShareRecords = taShareRecordMapper.selectList(taShareRecordQueryWrapper);
67
+		//判断是否发起了助力活动
68
+		QueryWrapper<HelpInitiateRecord> helpInitiateRecordListQueryWrapper = new QueryWrapper<>();
69
+		helpInitiateRecordListQueryWrapper.eq("org_id",orgId);
70
+		helpInitiateRecordListQueryWrapper.eq("person_id",person.getPersonId());
71
+		List<HelpInitiateRecord> HelpInitiateRecords = helpInitiateRecordMapper.selectList(helpInitiateRecordListQueryWrapper);
72
+		
73
+		//分页获取全部数据
74
+		Page pg = new Page(pageNumber,pageSize);
75
+		List<Activity> list = activityMapper.getActivityList(pg,orgId, CommConstant.STATUS_NORMAL,cityId);
76
+		list.forEach(e -> {
77
+			if (e.getType().equals("dynamic")){
78
+				taActivityDynamicEnlists.forEach(dynamic -> {
79
+					if (e.getId().equals(dynamic.getDynamicId())){
80
+						e.setActivityStatus(CommConstant.ACTIVITY_STATUS_PARTNER);
81
+					}
82
+				});
83
+				e.setSuccessNum(null);
84
+			}else if (e.getType().equals("group")){
85
+				taShareRecords.forEach(share -> {
86
+					if (e.getId().equals(String.valueOf(share.getGroupActivityId()))){
87
+						e.setActivityStatus(CommConstant.ACTIVITY_STATUS_PARTNER);
88
+					}
89
+				});
90
+				//查看此活动已经完成的数量
91
+				QueryWrapper<TaShareRecord> shareRecordQueryWrapper = new QueryWrapper<>();
92
+				shareRecordQueryWrapper.eq("org_id",orgId);
93
+				shareRecordQueryWrapper.eq("group_activity_id",e.getId());
94
+				shareRecordQueryWrapper.eq("status",CommConstant.STATUS_UNACCALIMED);
95
+				List<TaShareRecord> taShareRecordsList = taShareRecordMapper.selectList(shareRecordQueryWrapper);
96
+				e.setSuccessNum(taShareRecordsList.size());
97
+			}else if (e.getType().equals("help")){
98
+				HelpInitiateRecords.forEach(help -> {
99
+					if (e.getId().equals(help.getHelpActivityId())){
100
+						e.setActivityStatus(CommConstant.ACTIVITY_STATUS_PARTNER);
101
+					}
102
+				});
103
+				//查看此活动已经完成的数量
104
+				QueryWrapper<HelpInitiateRecord> helpInitiateRecordQueryWrapper = new QueryWrapper<>();
105
+				helpInitiateRecordQueryWrapper.eq("org_id",orgId);
106
+				helpInitiateRecordQueryWrapper.eq("help_activity_id",e.getId());
107
+				helpInitiateRecordQueryWrapper.eq("status",CommConstant.STATUS_UNACCALIMED);
108
+				List<HelpInitiateRecord> helpInitiateRecordList = helpInitiateRecordMapper.selectList(helpInitiateRecordQueryWrapper);
109
+				e.setSuccessNum(helpInitiateRecordList.size());
110
+			}
111
+		});
112
+		pg.setRecords(list);
113
+		return ResponseBean.success(pg);
114
+	}
115
+	
116
+	/**
117
+	 * 获取客户参加的活动信息
118
+	 *
119
+	 * @param pageNumber
120
+	 * @param pageSize
121
+	 * @param orgId
122
+	 * @param person
123
+	 * @return
124
+	 */
125
+	@Override
126
+	public ResponseBean getCustomerActivityList(Integer pageNumber, Integer pageSize, Integer orgId, TaPerson person) {
127
+		//分页获取全部数据
128
+		Page pg = new Page(pageNumber,pageSize);
129
+		List<Map<String, Object>> customerActivityList = activityMapper.getCustomerActivityList(pg, orgId, person.getPersonId());
130
+		pg.setRecords(customerActivityList);
131
+		return ResponseBean.success(pg);
132
+	}
133
+}

+ 143
- 0
src/main/java/com/yunzhi/marketing/base/BaseController.java Просмотреть файл

@@ -0,0 +1,143 @@
1
+package com.yunzhi.marketing.base;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
5
+import com.yunzhi.marketing.center.taUser.service.ITaUserService;
6
+import com.yunzhi.marketing.common.JWTUtils;
7
+import com.yunzhi.marketing.entity.TaPersonBuilding;
8
+import com.yunzhi.marketing.service.ITaPersonBuildingService;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+
11
+import javax.servlet.http.HttpServletRequest;
12
+import java.util.ArrayList;
13
+import java.util.List;
14
+import java.util.Map;
15
+
16
+/**
17
+ * @author FXF
18
+ * @date 2018-12-18
19
+ */
20
+public class BaseController {
21
+    @Autowired
22
+    private ITaUserService taUserService;
23
+
24
+    @Autowired
25
+    private ITaPersonBuildingService taPersonBuildingService;
26
+
27
+    /**
28
+     * 获取orgId
29
+     *
30
+     * @param request
31
+     * @return
32
+     */
33
+    public Integer getOrgId(HttpServletRequest request) {
34
+
35
+        Map map = JWTUtils.getUserIdAndOrgId(request);
36
+        if (null != map && null != map.get("orgId")) {
37
+            return Integer.valueOf(map.get("orgId").toString());
38
+        }
39
+
40
+        return null;
41
+    }
42
+
43
+    public Integer getChannelId(HttpServletRequest request) {
44
+
45
+        Map map = JWTUtils.getUserIdAndOrgId(request);
46
+        if (null != map && null != map.get("channelId")) {
47
+            return Integer.valueOf(map.get("channelId").toString());
48
+        }
49
+
50
+        return null;
51
+    }
52
+
53
+    public String getChannelUserName(HttpServletRequest request) {
54
+
55
+        Map map = JWTUtils.getUserIdAndOrgId(request);
56
+        if (null != map && null != map.get("userName")) {
57
+            return map.get("userName").toString();
58
+        }
59
+
60
+        return null;
61
+    }
62
+
63
+    public String getOpenId(HttpServletRequest request) {
64
+
65
+        Map map = JWTUtils.getUserIdAndOrgId(request);
66
+        if (null != map && null != map.get("openId")) {
67
+            return map.get("openId").toString();
68
+        }
69
+
70
+        return null;
71
+    }
72
+
73
+    public String getPersonId(HttpServletRequest request) {
74
+
75
+        Map map = JWTUtils.getUserIdAndOrgId(request);
76
+        if (null != map && null != map.get("personId")) {
77
+            return map.get("personId").toString();
78
+        }
79
+
80
+        return null;
81
+    }
82
+
83
+    /**
84
+     * 获取orgId
85
+     *
86
+     * @param request
87
+     * @return
88
+     */
89
+    public Integer getUserId(HttpServletRequest request) {
90
+
91
+        Map map = JWTUtils.getUserIdAndOrgId(request);
92
+        if (null != map && null != map.get("userId")) {
93
+            return Integer.valueOf(map.get("userId").toString());
94
+        }
95
+
96
+        return null;
97
+    }
98
+
99
+    /**
100
+     * 获取服务管理后台用户ID
101
+     *
102
+     * @param request
103
+     * @return
104
+     */
105
+    public Integer getSysUserId(HttpServletRequest request) {
106
+
107
+        Map map = JWTUtils.getUserIdAndOrgId(request);
108
+        if (null != map && null != map.get("userId")) {
109
+            return Integer.valueOf(map.get("userId").toString());
110
+        }
111
+        return null;
112
+    }
113
+
114
+    /**
115
+     * 获取服务管理后台用户ID
116
+     *
117
+     * @param request
118
+     * @return
119
+     */
120
+    public String getSysUserName(HttpServletRequest request) {
121
+
122
+        Map map = JWTUtils.getUserIdAndOrgId(request);
123
+        if (null != map && null != map.get("userName")) {
124
+            return map.get("userName") + "";
125
+        }
126
+        return null;
127
+    }
128
+
129
+    public List<TaPersonBuilding> getTaPersonBuildingListByUserId(HttpServletRequest request) {
130
+        TaUser taUser = taUserService.getById(getUserId(request));
131
+        if (taUser == null) {
132
+            return null;
133
+        }
134
+        QueryWrapper<TaPersonBuilding> taPersonBuildingQueryWrapper = new QueryWrapper<>();
135
+        taPersonBuildingQueryWrapper.eq("user_id", taUser.getUserId());
136
+        List<TaPersonBuilding> taPersonBuildingList = taPersonBuildingService.list(taPersonBuildingQueryWrapper);
137
+        if (null != taUser.getIsAdmin() && taUser.getIsAdmin()) {
138
+            taPersonBuildingList = new ArrayList<>();
139
+        }
140
+        return taPersonBuildingList;
141
+    }
142
+}
143
+

+ 81
- 0
src/main/java/com/yunzhi/marketing/base/ResponseBean.java Просмотреть файл

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

+ 38
- 0
src/main/java/com/yunzhi/marketing/base/UserControl.java Просмотреть файл

@@ -0,0 +1,38 @@
1
+package com.yunzhi.marketing.base;
2
+
3
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
4
+import com.yunzhi.marketing.exception.EstaException;
5
+import org.springframework.web.context.request.RequestContextHolder;
6
+import org.springframework.web.context.request.ServletRequestAttributes;
7
+
8
+import javax.servlet.http.HttpSession;
9
+
10
+/**
11
+ * 用户控制
12
+ */
13
+public class UserControl {
14
+
15
+    /**
16
+     * 获取用户信息
17
+     * @return
18
+     */
19
+    public static TaUser getUser() {
20
+        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
21
+        HttpSession session = servletRequestAttributes.getRequest().getSession();
22
+        TaUser taUser = (TaUser) session.getAttribute("miniapp_user");
23
+        if (null == taUser) {
24
+            throw new EstaException("用户信息不存在, 请登录!");
25
+        }
26
+        return taUser;
27
+    }
28
+
29
+    /**
30
+     * 获取公司 org_id
31
+     * @return
32
+     */
33
+    public static Integer getOrgId() {
34
+        TaUser user = getUser();
35
+        return user.getOrgId();
36
+    }
37
+
38
+}

+ 49
- 0
src/main/java/com/yunzhi/marketing/bo/request/ActivityStatisticResponseBO.java Просмотреть файл

@@ -0,0 +1,49 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 活动统计返回实体
7
+ *
8
+ * @author gusy
9
+ * @date 2020/4/26 13:15
10
+ */
11
+@Data
12
+public class ActivityStatisticResponseBO {
13
+
14
+    /**
15
+     * 活动分享人数
16
+     */
17
+    private Integer sharePersons;
18
+
19
+    /**
20
+     * 活动分享次数
21
+     */
22
+    private Integer shareNum;
23
+
24
+    /**
25
+     * 活动访问人数
26
+     */
27
+    private Integer visitPersons;
28
+
29
+    /**
30
+     * 活动访问次数
31
+     */
32
+    private Integer visitNum;
33
+
34
+    /**
35
+     * 分享新增用户
36
+     */
37
+    private Integer newPersons;
38
+
39
+    /**
40
+     * 分享新增客户
41
+     */
42
+    private Integer newCustomers;
43
+
44
+    /**
45
+     * 活动名称
46
+     */
47
+    private String activityName;
48
+
49
+}

+ 88
- 0
src/main/java/com/yunzhi/marketing/bo/request/ContractRecordRequestBO.java Просмотреть файл

@@ -0,0 +1,88 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+import org.springframework.format.annotation.DateTimeFormat;
5
+
6
+import java.time.LocalDate;
7
+
8
+/**
9
+ * 查询合同列表请求实体
10
+ */
11
+@Data
12
+public class ContractRecordRequestBO {
13
+
14
+    /**
15
+     * 页码
16
+     */
17
+    private Integer pageNum = 1;
18
+
19
+    /**
20
+     * 分页大小
21
+     */
22
+    private Integer pageSize = 10;
23
+
24
+    /**
25
+     * 公司名
26
+     */
27
+    private String companyName;
28
+
29
+    /**
30
+     * 公司编码
31
+     */
32
+    private String companyCode;
33
+
34
+    /**
35
+     * 组织名
36
+     */
37
+    private String orgName;
38
+
39
+    /**
40
+     * 小程序名
41
+     */
42
+    private String miniAppName;
43
+
44
+    /**
45
+     * 合同编号
46
+     */
47
+    private Integer contractId;
48
+
49
+    /**
50
+     * 合同名
51
+     */
52
+    private String contractName;
53
+
54
+    /**
55
+     * 渠道代理商
56
+     */
57
+    private String channelProxyName;
58
+
59
+    /**
60
+     * 是否结算
61
+     */
62
+    private Boolean settlement;
63
+
64
+    /**
65
+     * 甲方签署开始时间
66
+     */
67
+    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
68
+    private LocalDate signatoryStartTime;
69
+
70
+    /**
71
+     * 甲方签署结束时间
72
+     */
73
+
74
+    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
75
+    private LocalDate signatoryEndTime;
76
+
77
+    /**
78
+     * 结算开始时间
79
+     */
80
+    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
81
+    private LocalDate settlementStartTime;
82
+
83
+    /**
84
+     * 结算结束时间
85
+     */
86
+    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
87
+    private LocalDate settlementEndTime;
88
+}

+ 65
- 0
src/main/java/com/yunzhi/marketing/bo/request/HousingRaiseRequestBO.java Просмотреть файл

@@ -0,0 +1,65 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 查询房源认筹记录请求实体
7
+ *
8
+ * @Auther: gusy
9
+ * @Date: 2020/2/28 01:01
10
+ */
11
+@Data
12
+public class HousingRaiseRequestBO {
13
+
14
+    private Integer orgId;
15
+
16
+    /**
17
+     * 销售批次ID
18
+     */
19
+    private Integer salesBatchId;
20
+
21
+    /**
22
+     * 房源ID
23
+     */
24
+    private Integer houseId;
25
+
26
+    /**
27
+     * 期名
28
+     */
29
+    private String termName;
30
+
31
+    /**
32
+     * 楼栋名
33
+     */
34
+    private String blockName;
35
+
36
+    /**
37
+     * 单元名
38
+     */
39
+    private String unitName;
40
+
41
+    /**
42
+     * 楼层名
43
+     */
44
+    private String floorName;
45
+
46
+    /**
47
+     * 房间名
48
+     */
49
+    private String roomName;
50
+
51
+    /**
52
+     * 户型Id
53
+     */
54
+    private String apartmentId;
55
+
56
+    /**
57
+     * 房源发布状态
58
+     */
59
+    private Integer status;
60
+
61
+    /**
62
+     * 房源锁定状态
63
+     */
64
+    private String lockingStatus;
65
+}

+ 72
- 0
src/main/java/com/yunzhi/marketing/bo/request/PresecretRecordRequestBO.java Просмотреть файл

@@ -0,0 +1,72 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 预选记录查询请求实体
7
+ *
8
+ * @Auther: gusy
9
+ * @Date: 2020/2/28 00:14
10
+ */
11
+@Data
12
+public class PresecretRecordRequestBO {
13
+
14
+    private Integer orgId;
15
+
16
+    private Integer salesBatchId;
17
+
18
+    /**
19
+     * 房源ID
20
+     */
21
+    private Integer houseId;
22
+
23
+    /**
24
+     * 期名
25
+     */
26
+    private String termName;
27
+
28
+    /**
29
+     * 楼栋名
30
+     */
31
+    private String blockName;
32
+
33
+    /**
34
+     * 单元名
35
+     */
36
+    private String unitName;
37
+
38
+    /**
39
+     * 楼层名
40
+     */
41
+    private String floorName;
42
+
43
+    /**
44
+     * 房间名
45
+     */
46
+    private String roomName;
47
+
48
+    /**
49
+     * 用户手机号
50
+     */
51
+    private String phone;
52
+
53
+    /**
54
+     * 户型Id
55
+     */
56
+    private String apartmentId;
57
+
58
+    /**
59
+     * 预选状态
60
+     */
61
+    private Integer status;
62
+
63
+    /**
64
+     * 修改开始时间
65
+     */
66
+    private String startTime;
67
+
68
+    /**
69
+     * 修改结束时间
70
+     */
71
+    private String endTime;
72
+}

+ 29
- 0
src/main/java/com/yunzhi/marketing/bo/request/QrCodeStatisticResponseBO.java Просмотреть файл

@@ -0,0 +1,29 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 二维码统计返回实体
7
+ *
8
+ * @author gusy
9
+ * @date 2020/5/21 13:53
10
+ */
11
+@Data
12
+public class QrCodeStatisticResponseBO {
13
+
14
+    /**
15
+     * 访问人数
16
+     */
17
+    private Integer visitPersons;
18
+
19
+    /**
20
+     * 访问次数
21
+     */
22
+    private Integer visitNum;
23
+
24
+    /**
25
+     * 新增用户
26
+     */
27
+    private Integer newPersons;
28
+
29
+}

+ 75
- 0
src/main/java/com/yunzhi/marketing/bo/request/RaiseOrderRequestBO.java Просмотреть файл

@@ -0,0 +1,75 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 查询认筹订单请求实体
7
+ *
8
+ * @Auther: gusy
9
+ * @Date: 2020/2/27 22:10
10
+ */
11
+@Data
12
+public class RaiseOrderRequestBO {
13
+
14
+    private Integer orgId;
15
+
16
+    /**
17
+     * 认筹ID
18
+     */
19
+    private Integer raiseId;
20
+
21
+    /**
22
+     * 订单表ID
23
+     */
24
+    private Integer orderId;
25
+
26
+    /**
27
+     * 订单表ID
28
+     */
29
+    private Integer refundedOrderId;
30
+
31
+    /**
32
+     * 认筹单表ID
33
+     */
34
+    private Integer raiseRecordId;
35
+
36
+    /**
37
+     * 认筹手机号
38
+     */
39
+    private String tel;
40
+
41
+    /**
42
+     * 用户手机号
43
+     */
44
+    private String personTel;
45
+
46
+    /**
47
+     * 微信流水号
48
+     */
49
+    private String transactionId;
50
+
51
+    /**
52
+     * 微信退款号
53
+     */
54
+    private String refundNo;
55
+
56
+    /**
57
+     * 支付状态
58
+     */
59
+    private String payStatus;
60
+
61
+    /**
62
+     * 开始时间
63
+     */
64
+    private String payStartTime;
65
+
66
+    /**
67
+     * 结束时间
68
+     */
69
+    private String payEndTime;
70
+
71
+    /**
72
+     * 微信订单号
73
+     */
74
+    private String tradeNo;
75
+}

+ 100
- 0
src/main/java/com/yunzhi/marketing/bo/request/RaiseRecordRequestBO.java Просмотреть файл

@@ -0,0 +1,100 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 认筹单记录查询请求实体
7
+ *
8
+ * @Auther: gusy
9
+ * @Date: 2020/2/27 18:39
10
+ */
11
+@Data
12
+public class RaiseRecordRequestBO {
13
+
14
+    private Integer orgId;
15
+
16
+    /**
17
+     * 房源ID
18
+     */
19
+    private String houseId;
20
+
21
+    /**
22
+     * 认筹表ID
23
+     */
24
+    private Integer raiseId;
25
+
26
+    /**
27
+     * 认筹单ID
28
+     */
29
+    private Integer raiseRecordId;
30
+
31
+    /**
32
+     * 期名
33
+     */
34
+    private String termName;
35
+
36
+    /**
37
+     * 楼栋名
38
+     */
39
+    private String blockName;
40
+
41
+    /**
42
+     * 单元名
43
+     */
44
+    private String unitName;
45
+
46
+    /**
47
+     * 楼层名
48
+     */
49
+    private String floorName;
50
+
51
+    /**
52
+     * 房间名
53
+     */
54
+    private String roomName;
55
+
56
+    /**
57
+     * 是否作废
58
+     */
59
+    private Integer status;
60
+
61
+    /**
62
+     * 房源锁定状态
63
+     */
64
+    private String lockingStatus;
65
+
66
+    /**
67
+     * 认筹手机号
68
+     */
69
+    private String tel;
70
+
71
+    /**
72
+     * 用户手机号
73
+     */
74
+    private String personTel;
75
+
76
+    /**
77
+     * 缴费状态
78
+     */
79
+    private String payStatus;
80
+
81
+    /**
82
+     * 缴费方式
83
+     */
84
+    private String payType;
85
+
86
+    /**
87
+     * 开始时间
88
+     */
89
+    private String startTime;
90
+
91
+    /**
92
+     * 结束时间
93
+     */
94
+    private String endTime;
95
+
96
+    /**
97
+     * 用户姓名
98
+     */
99
+    private String personName;
100
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/bo/request/SaveCzOrderRequestBO.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 创建充值订单请求实体
7
+ *
8
+ * @author gusy
9
+ * @date 2020/6/9 14:58
10
+ */
11
+@Data
12
+public class SaveCzOrderRequestBO {
13
+
14
+    /**
15
+     * 充值金额
16
+     */
17
+    private Integer amount;
18
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/bo/request/SaveRefundOrderRequestBO.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.bo.request;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * 创建退款订单请求实体
7
+ *
8
+ * @author gusy
9
+ * @date 2020/6/9 14:58
10
+ */
11
+@Data
12
+public class SaveRefundOrderRequestBO {
13
+
14
+    /**
15
+     * 退款金额
16
+     */
17
+    private Integer amount;
18
+}

+ 143
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/controller/SysTokenController.java Просмотреть файл

@@ -0,0 +1,143 @@
1
+package com.yunzhi.marketing.center.sysUser.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.marketing.base.BaseController;
7
+import com.yunzhi.marketing.base.ResponseBean;
8
+import com.yunzhi.marketing.center.sysUser.entity.SysToken;
9
+import com.yunzhi.marketing.center.sysUser.service.ISysTokenService;
10
+import org.slf4j.Logger;
11
+import org.slf4j.LoggerFactory;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.web.bind.annotation.*;
14
+
15
+/**
16
+ * <p>
17
+    * 令牌表  前端控制器
18
+    * </p>
19
+ *
20
+ * @author jobob
21
+ * @since 2019-09-11
22
+ */
23
+@RestController
24
+@RequestMapping("/")
25
+public class SysTokenController extends BaseController {
26
+
27
+    private final Logger logger = LoggerFactory.getLogger(SysTokenController.class);
28
+
29
+    @Autowired
30
+    public ISysTokenService iSysTokenService;
31
+
32
+
33
+    /**
34
+     * 分页查询列表
35
+     * @param pageNum
36
+     * @param pageSize
37
+     * @return
38
+     */
39
+    @RequestMapping(value="/sysToken",method= RequestMethod.GET)
40
+    public ResponseBean sysTokenList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
41
+									 @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
42
+        ResponseBean responseBean = new ResponseBean();
43
+        try {
44
+            //使用分页插件
45
+		    IPage<SysToken> pg = new Page<>(pageNum, pageSize);
46
+            QueryWrapper<SysToken> queryWrapper = new QueryWrapper<>();
47
+            queryWrapper.orderByDesc("create_date");
48
+
49
+            IPage<SysToken> result = iSysTokenService.page(pg, queryWrapper);
50
+            responseBean.addSuccess(result);
51
+        }catch (Exception e){
52
+            e.printStackTrace();
53
+            logger.error("sysTokenList -=- {}",e.toString());
54
+            responseBean.addError(e.getMessage());
55
+        }
56
+        return responseBean;
57
+    }
58
+
59
+    /**
60
+     * 保存对象
61
+     * @param sysToken 实体对象
62
+     * @return
63
+     */
64
+    @RequestMapping(value="/sysToken",method= RequestMethod.POST)
65
+    public ResponseBean sysTokenAdd(@RequestBody SysToken sysToken){
66
+        ResponseBean responseBean = new ResponseBean();
67
+        try {
68
+            if (iSysTokenService.save(sysToken)){
69
+                responseBean.addSuccess(sysToken);
70
+            }else {
71
+                responseBean.addError("fail");
72
+            }
73
+        }catch (Exception e){
74
+            e.printStackTrace();
75
+            logger.error("sysTokenAdd -=- {}",e.toString());
76
+            responseBean.addError(e.getMessage());
77
+        }
78
+        return responseBean;
79
+    }
80
+
81
+    /**
82
+     * 根据id删除对象
83
+     * @param id  实体ID
84
+     */
85
+    @ResponseBody
86
+    @RequestMapping(value="/sysToken/{id}", method= RequestMethod.DELETE)
87
+    public ResponseBean sysTokenDelete(@PathVariable Integer id){
88
+        ResponseBean responseBean = new ResponseBean();
89
+        try {
90
+            if(iSysTokenService.removeById(id)){
91
+                responseBean.addSuccess("success");
92
+            }else {
93
+                responseBean.addError("fail");
94
+            }
95
+        }catch (Exception e){
96
+            e.printStackTrace();
97
+            logger.error("sysTokenDelete -=- {}",e.toString());
98
+            responseBean.addError(e.getMessage());
99
+        }
100
+        return responseBean;
101
+    }
102
+
103
+    /**
104
+     * 修改对象
105
+     * @param id  实体ID
106
+     * @param sysToken 实体对象
107
+     * @return
108
+     */
109
+    @RequestMapping(value="/sysToken/{id}",method= RequestMethod.PUT)
110
+    public ResponseBean sysTokenUpdate(@PathVariable Integer id,
111
+                                        @RequestBody SysToken sysToken){
112
+        ResponseBean responseBean = new ResponseBean();
113
+        try {
114
+            if (iSysTokenService.updateById(sysToken)){
115
+                responseBean.addSuccess(sysToken);
116
+            }else {
117
+                responseBean.addError("fail");
118
+            }
119
+        }catch (Exception e){
120
+            e.printStackTrace();
121
+            logger.error("sysTokenUpdate -=- {}",e.toString());
122
+            responseBean.addError(e.getMessage());
123
+        }
124
+        return responseBean;
125
+    }
126
+
127
+    /**
128
+     * 根据id查询对象
129
+     * @param id  实体ID
130
+     */
131
+    @RequestMapping(value="/sysToken/{id}",method= RequestMethod.GET)
132
+    public ResponseBean sysTokenGet(@PathVariable Integer id){
133
+        ResponseBean responseBean = new ResponseBean();
134
+        try {
135
+            responseBean.addSuccess(iSysTokenService.getById(id));
136
+        }catch (Exception e){
137
+            e.printStackTrace();
138
+            logger.error("sysTokenDelete -=- {}",e.toString());
139
+            responseBean.addError(e.getMessage());
140
+        }
141
+        return responseBean;
142
+    }
143
+}

+ 269
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/controller/SysUserController.java Просмотреть файл

@@ -0,0 +1,269 @@
1
+package com.yunzhi.marketing.center.sysUser.controller;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
+import com.baomidou.mybatisplus.core.metadata.IPage;
6
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
+import com.yunzhi.marketing.base.BaseController;
8
+import com.yunzhi.marketing.base.ResponseBean;
9
+import com.yunzhi.marketing.center.sysUser.entity.SysToken;
10
+import com.yunzhi.marketing.center.sysUser.entity.SysUser;
11
+import com.yunzhi.marketing.center.sysUser.service.ISysTokenService;
12
+import com.yunzhi.marketing.center.sysUser.service.ISysUserService;
13
+import com.yunzhi.marketing.center.taUser.service.ITaUserService;
14
+import com.yunzhi.marketing.channel.sysChannel.entity.TaChannelProxy;
15
+import com.yunzhi.marketing.channel.sysChannel.service.ITaChannelProxyService;
16
+import com.yunzhi.marketing.common.JWTUtils;
17
+import com.yunzhi.marketing.common.MD5Utils;
18
+import com.yunzhi.marketing.common.StringUtils;
19
+import org.slf4j.Logger;
20
+import org.slf4j.LoggerFactory;
21
+import org.springframework.beans.factory.annotation.Autowired;
22
+import org.springframework.web.bind.annotation.*;
23
+
24
+import javax.servlet.http.HttpServletRequest;
25
+import java.time.LocalDateTime;
26
+import java.util.HashMap;
27
+import java.util.Map;
28
+
29
+/**
30
+ * <p>
31
+    * 系统用户 系统中心账户 前端控制器
32
+    * </p>
33
+ *
34
+ * @author jobob
35
+ * @since 2019-09-11
36
+ */
37
+@RestController
38
+@RequestMapping("/api")
39
+public class SysUserController extends BaseController {
40
+
41
+    private final Logger logger = LoggerFactory.getLogger(SysUserController.class);
42
+
43
+    @Autowired
44
+    public ISysUserService iSysUserService;
45
+    
46
+    @Autowired
47
+    private ISysTokenService sysTokenService;
48
+
49
+    @Autowired
50
+    private ITaUserService iTaUserService;
51
+
52
+    @Autowired
53
+    private ITaChannelProxyService iTaChannelProxyService;
54
+
55
+    /**
56
+     * 分页查询列表
57
+     * @param pageNum
58
+     * @param pageSize
59
+     * @return
60
+     */
61
+    @RequestMapping(value="/sysUser",method= RequestMethod.GET)
62
+    public ResponseBean sysUserList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
63
+									 @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
64
+        ResponseBean responseBean = new ResponseBean();
65
+        try {
66
+            //使用分页插件
67
+		    IPage<SysUser> pg = new Page<>(pageNum, pageSize);
68
+            QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
69
+            queryWrapper.orderByDesc("create_date");
70
+
71
+            IPage<SysUser> result = iSysUserService.page(pg, queryWrapper);
72
+            responseBean.addSuccess(result);
73
+        }catch (Exception e){
74
+            e.printStackTrace();
75
+            logger.error("sysUserList -=- {}",e.toString());
76
+            responseBean.addError(e.getMessage());
77
+        }
78
+        return responseBean;
79
+    }
80
+
81
+    /**
82
+     * 保存对象
83
+     * @param sysUser 实体对象
84
+     * @return
85
+     */
86
+    @RequestMapping(value="/sysUser",method= RequestMethod.POST)
87
+    public ResponseBean sysUserAdd(@RequestBody SysUser sysUser){
88
+        ResponseBean responseBean = new ResponseBean();
89
+        try {
90
+            if (iSysUserService.save(sysUser)){
91
+                responseBean.addSuccess(sysUser);
92
+            }else {
93
+                responseBean.addError("fail");
94
+            }
95
+        }catch (Exception e){
96
+            e.printStackTrace();
97
+            logger.error("sysUserAdd -=- {}",e.toString());
98
+            responseBean.addError(e.getMessage());
99
+        }
100
+        return responseBean;
101
+    }
102
+
103
+    /**
104
+     * 根据id删除对象
105
+     * @param id  实体ID
106
+     */
107
+    @ResponseBody
108
+    @RequestMapping(value="/sysUser/{id}", method= RequestMethod.DELETE)
109
+    public ResponseBean sysUserDelete(@PathVariable Integer id){
110
+        ResponseBean responseBean = new ResponseBean();
111
+        try {
112
+            if(iSysUserService.removeById(id)){
113
+                responseBean.addSuccess("success");
114
+            }else {
115
+                responseBean.addError("fail");
116
+            }
117
+        }catch (Exception e){
118
+            e.printStackTrace();
119
+            logger.error("sysUserDelete -=- {}",e.toString());
120
+            responseBean.addError(e.getMessage());
121
+        }
122
+        return responseBean;
123
+    }
124
+
125
+    /**
126
+     * 修改对象
127
+     * @param sysUser 实体对象
128
+     * @return
129
+     */
130
+    @RequestMapping(value="/center/sysUser",method= RequestMethod.PUT)
131
+    public ResponseBean sysUserUpdate(@RequestBody SysUser sysUser,HttpServletRequest request){
132
+        ResponseBean responseBean = new ResponseBean();
133
+        try {
134
+            String userName = JWTUtils.getSubject(request);
135
+            sysUser.setPassword(MD5Utils.md5(sysUser.getPassword()));
136
+            sysUser.setUserName(userName);
137
+            if (iSysUserService.updateById(sysUser)){
138
+                responseBean.addSuccess(sysUser);
139
+            }else {
140
+                responseBean.addError("fail");
141
+            }
142
+        }catch (Exception e){
143
+            e.printStackTrace();
144
+            logger.error("sysUserUpdate -=- {}",e.toString());
145
+            responseBean.addError(e.getMessage());
146
+        }
147
+        return responseBean;
148
+    }
149
+
150
+    /**
151
+     * 根据id查询对象
152
+     * @param id  实体ID
153
+     */
154
+    @RequestMapping(value="/sysUser/{id}",method= RequestMethod.GET)
155
+    public ResponseBean sysUserGet(@PathVariable Integer id){
156
+        ResponseBean responseBean = new ResponseBean();
157
+        try {
158
+            responseBean.addSuccess(iSysUserService.getById(id));
159
+        }catch (Exception e){
160
+            e.printStackTrace();
161
+            logger.error("sysUserDelete -=- {}",e.toString());
162
+            responseBean.addError(e.getMessage());
163
+        }
164
+        return responseBean;
165
+    }
166
+
167
+    /**
168
+     * 根据id查询对象
169
+     * @param id  实体ID
170
+     */
171
+    @RequestMapping(value="/center/current",method=RequestMethod.GET)
172
+    public ResponseBean currentUser(HttpServletRequest request){
173
+        Map map = JWTUtils.getUserIdAndOrgId(request);
174
+        QueryWrapper<TaChannelProxy> taChannelProxyQueryWrapper = new QueryWrapper<>();
175
+        taChannelProxyQueryWrapper.eq("user_name", map.get("userName")).or().eq("channel_tel", map.get("userName"));
176
+        TaChannelProxy taChannelProxy = iTaChannelProxyService.getOne(taChannelProxyQueryWrapper);
177
+        if (StringUtils.isEmpty(taChannelProxy.getUserName())){
178
+            taChannelProxy.setUserName(map.get("userName").toString());
179
+        }
180
+        return ResponseBean.success(taChannelProxy);
181
+    }
182
+    
183
+    @PostMapping("/center/signin")
184
+    public ResponseBean signin(@RequestBody String paramStr) {
185
+        JSONObject params = JSONObject.parseObject(paramStr);
186
+        if (params == null) {
187
+            return ResponseBean.error("非法参数", ResponseBean.ERROR_MISSING_PARAMS);
188
+        }
189
+
190
+        QueryWrapper<TaChannelProxy> taChannelProxyQueryWrapper = new QueryWrapper<>();
191
+        String userName = params.getString("userName");
192
+        if (StringUtils.isEmpty(userName)){
193
+            return ResponseBean.error("用户名不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
194
+        }
195
+
196
+        taChannelProxyQueryWrapper.eq("user_name", userName).or().eq("channel_tel", userName);
197
+
198
+        //验证用户名密码是否正确
199
+        TaChannelProxy taChannelProxy = iTaChannelProxyService.getOne(taChannelProxyQueryWrapper);
200
+        String defaultPsw = MD5Utils.md5(params.getString("password"));
201
+        if (taChannelProxy == null || !defaultPsw.equals(taChannelProxy.getPassword())) {
202
+            return ResponseBean.error("用户名或密码错误", ResponseBean.ERROR_ILLEGAL_PARAMS);
203
+        }
204
+
205
+        //校验是否过期且是否停用
206
+        if (LocalDateTime.now().isAfter(taChannelProxy.getExpireDate()) || taChannelProxy.getStatus() == 0){
207
+            return ResponseBean.error("当前后台服务已到期,请联系管理员", ResponseBean.ERROR_ILLEGAL_PARAMS);
208
+        }
209
+
210
+        Map map = new HashMap();
211
+        map.put("userName", StringUtils.isEmpty(taChannelProxy.getUserName()) ? taChannelProxy.getChannelTel() : taChannelProxy.getUserName());
212
+        map.put("channelId",taChannelProxy.getChannelId().toString());
213
+        String token = JWTUtils.newTokenByMap(map);
214
+
215
+        //保存token
216
+        sysTokenService.saveToken(token);
217
+        
218
+        Map<String, Object> result = new HashMap<>();
219
+        result.put("token", token);
220
+        result.put("user", taChannelProxy);
221
+        
222
+        return ResponseBean.success(result);
223
+    }
224
+
225
+    @PostMapping("/center/changePassword")
226
+    public ResponseBean changePassword(@RequestParam String originalPassword,
227
+                                       @RequestParam String newPassword,HttpServletRequest request) {
228
+
229
+        if (org.apache.commons.lang3.StringUtils.isBlank(newPassword) || newPassword.length() < 6) {
230
+            return ResponseBean.error("新密不能小于6位", ResponseBean.ERROR_UNAVAILABLE);
231
+        }
232
+
233
+        Integer channelId = getChannelId(request);
234
+
235
+        // 校验当前旧密码是否正确
236
+        String password = MD5Utils.md5(MD5Utils.md5(originalPassword));
237
+        TaChannelProxy taChannelProxy = iTaChannelProxyService.getById(channelId);
238
+        if (!password.equals(taChannelProxy.getPassword())){
239
+            return ResponseBean.error("旧密码错误,请重新输入", ResponseBean.ERROR_UNAVAILABLE);
240
+        }
241
+
242
+        try {
243
+            iTaChannelProxyService.resetPassword(channelId, newPassword);
244
+            return ResponseBean.success("操作成功!");
245
+        } catch (Exception e) {
246
+            e.printStackTrace();
247
+            return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
248
+        }
249
+    }
250
+
251
+    @PostMapping("/center/signout")
252
+    public ResponseBean signout(HttpServletRequest request) {
253
+        String token = JWTUtils.getToken(request);
254
+        QueryWrapper<SysToken> sysTokenQueryWrapper = new QueryWrapper<>();
255
+        sysTokenQueryWrapper.eq("token",token);
256
+        sysTokenService.remove(sysTokenQueryWrapper);
257
+        return ResponseBean.success("成功退出");
258
+    }
259
+
260
+    @RequestMapping(value="/center/logo",method= RequestMethod.GET)
261
+    public ResponseBean getLogoImg(HttpServletRequest request){
262
+        ResponseBean responseBean = new ResponseBean();
263
+        Integer channelId = getChannelId(request);
264
+        TaChannelProxy taChannelProxy = iTaChannelProxyService.getById(channelId);
265
+        responseBean.addSuccess(taChannelProxy);
266
+        return responseBean;
267
+    }
268
+
269
+}

+ 38
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/entity/SysToken.java Просмотреть файл

@@ -0,0 +1,38 @@
1
+package com.yunzhi.marketing.center.sysUser.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableId;
4
+import lombok.Data;
5
+import lombok.EqualsAndHashCode;
6
+import lombok.experimental.Accessors;
7
+
8
+import java.io.Serializable;
9
+import java.time.LocalDateTime;
10
+
11
+/**
12
+ * <p>
13
+ * 令牌表 
14
+ * </p>
15
+ *
16
+ * @author jobob
17
+ * @since 2019-09-11
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+public class SysToken implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    /**
27
+     * token
28
+     */
29
+    @TableId(value = "token")
30
+    private String token;
31
+
32
+    /**
33
+     * 过期时间
34
+     */
35
+    private LocalDateTime expDate;
36
+
37
+
38
+}

+ 55
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/entity/SysUser.java Просмотреть файл

@@ -0,0 +1,55 @@
1
+package com.yunzhi.marketing.center.sysUser.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+import lombok.experimental.Accessors;
8
+
9
+import java.io.Serializable;
10
+
11
+/**
12
+ * <p>
13
+ * 系统用户 系统中心账户
14
+ * </p>
15
+ *
16
+ * @author jobob
17
+ * @since 2019-09-11
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+public class SysUser implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    /**
27
+     * 账户登录
28
+     */
29
+    @TableId(value = "user_id")
30
+    private Integer userId;
31
+
32
+    private String userName;
33
+
34
+    /**
35
+     * 登录密码
36
+     */
37
+    private String password;
38
+
39
+    /**
40
+     * 用户名称
41
+     */
42
+    private String name;
43
+
44
+    /**
45
+     * 头像
46
+     */
47
+    private String avatar;
48
+
49
+    /**
50
+     * 状态
51
+     */
52
+    private Integer status;
53
+
54
+
55
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/mapper/SysTokenMapper.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.center.sysUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.center.sysUser.entity.SysToken;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 令牌表  Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author jobob
13
+ * @since 2019-09-11
14
+ */
15
+@Mapper
16
+public interface SysTokenMapper extends BaseMapper<SysToken> {
17
+
18
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/mapper/SysUserMapper.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.center.sysUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.center.sysUser.entity.SysUser;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 系统用户 系统中心账户 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author jobob
13
+ * @since 2019-09-11
14
+ */
15
+@Mapper
16
+public interface SysUserMapper extends BaseMapper<SysUser> {
17
+
18
+}

+ 17
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/service/ISysTokenService.java Просмотреть файл

@@ -0,0 +1,17 @@
1
+package com.yunzhi.marketing.center.sysUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.center.sysUser.entity.SysToken;
5
+
6
+/**
7
+ * <p>
8
+ * 令牌表  服务类
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2019-09-11
13
+ */
14
+public interface ISysTokenService extends IService<SysToken> {
15
+	
16
+	SysToken saveToken(String token);
17
+}

+ 16
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/service/ISysUserService.java Просмотреть файл

@@ -0,0 +1,16 @@
1
+package com.yunzhi.marketing.center.sysUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.center.sysUser.entity.SysUser;
5
+
6
+/**
7
+ * <p>
8
+ * 系统用户 系统中心账户 服务类
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2019-09-11
13
+ */
14
+public interface ISysUserService extends IService<SysUser> {
15
+
16
+}

+ 34
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/service/impl/SysTokenServiceImpl.java Просмотреть файл

@@ -0,0 +1,34 @@
1
+package com.yunzhi.marketing.center.sysUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.yunzhi.marketing.center.sysUser.entity.SysToken;
5
+import com.yunzhi.marketing.center.sysUser.mapper.SysTokenMapper;
6
+import com.yunzhi.marketing.center.sysUser.service.ISysTokenService;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.stereotype.Service;
9
+
10
+import java.time.LocalDateTime;
11
+
12
+/**
13
+ * <p>
14
+ * 令牌表  服务实现类
15
+ * </p>
16
+ *
17
+ * @author jobob
18
+ * @since 2019-09-11
19
+ */
20
+@Service
21
+public class SysTokenServiceImpl extends ServiceImpl<SysTokenMapper, SysToken> implements ISysTokenService {
22
+	
23
+	@Autowired
24
+	private SysTokenMapper sysTokenMapper;
25
+	
26
+	@Override
27
+	public SysToken saveToken(String token) {
28
+		SysToken sysToken = new SysToken();
29
+		sysToken.setToken(token);
30
+		sysToken.setExpDate(LocalDateTime.now().plusDays(7));
31
+		sysTokenMapper.insert(sysToken);
32
+		return sysToken;
33
+	}
34
+}

+ 20
- 0
src/main/java/com/yunzhi/marketing/center/sysUser/service/impl/SysUserServiceImpl.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+package com.yunzhi.marketing.center.sysUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.yunzhi.marketing.center.sysUser.entity.SysUser;
5
+import com.yunzhi.marketing.center.sysUser.mapper.SysUserMapper;
6
+import com.yunzhi.marketing.center.sysUser.service.ISysUserService;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 系统用户 系统中心账户 服务实现类
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2019-09-11
16
+ */
17
+@Service
18
+public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
19
+
20
+}

+ 149
- 0
src/main/java/com/yunzhi/marketing/center/taUser/controller/TaButtonUriMapController.java Просмотреть файл

@@ -0,0 +1,149 @@
1
+package com.yunzhi.marketing.center.taUser.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.marketing.base.BaseController;
7
+import com.yunzhi.marketing.base.ResponseBean;
8
+import com.yunzhi.marketing.center.taUser.entity.TaButtonUriMap;
9
+import com.yunzhi.marketing.center.taUser.service.ITaButtonUriMapService;
10
+import org.slf4j.Logger;
11
+import org.slf4j.LoggerFactory;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.web.bind.annotation.PathVariable;
14
+import org.springframework.web.bind.annotation.RequestBody;
15
+import org.springframework.web.bind.annotation.RequestMapping;
16
+import org.springframework.web.bind.annotation.RequestMethod;
17
+import org.springframework.web.bind.annotation.RequestParam;
18
+import org.springframework.web.bind.annotation.ResponseBody;
19
+import org.springframework.web.bind.annotation.RestController;
20
+
21
+/**
22
+ * <p>
23
+    * 按钮路由映射表  前端控制器
24
+    * </p>
25
+ *
26
+ * @author jobob
27
+ * @since 2019-09-26
28
+ */
29
+@RestController
30
+@RequestMapping("/")
31
+public class TaButtonUriMapController extends BaseController {
32
+
33
+    private final Logger logger = LoggerFactory.getLogger(TaButtonUriMapController.class);
34
+
35
+    @Autowired
36
+    public ITaButtonUriMapService iTaButtonUriMapService;
37
+
38
+
39
+    /**
40
+     * 分页查询列表
41
+     * @param pageNum
42
+     * @param pageSize
43
+     * @return
44
+     */
45
+    @RequestMapping(value="/taButtonUriMap",method= RequestMethod.GET)
46
+    public ResponseBean taButtonUriMapList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
47
+                                           @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
48
+        ResponseBean responseBean = new ResponseBean();
49
+        try {
50
+            //使用分页插件
51
+		    IPage<TaButtonUriMap> pg = new Page<>(pageNum, pageSize);
52
+            QueryWrapper<TaButtonUriMap> queryWrapper = new QueryWrapper<>();
53
+            queryWrapper.orderByDesc("create_date");
54
+
55
+            IPage<TaButtonUriMap> result = iTaButtonUriMapService.page(pg, queryWrapper);
56
+            responseBean.addSuccess(result);
57
+        }catch (Exception e){
58
+            e.printStackTrace();
59
+            logger.error("taButtonUriMapList -=- {}",e.toString());
60
+            responseBean.addError(e.getMessage());
61
+        }
62
+        return responseBean;
63
+    }
64
+
65
+    /**
66
+     * 保存对象
67
+     * @param taButtonUriMap 实体对象
68
+     * @return
69
+     */
70
+    @RequestMapping(value="/taButtonUriMap",method= RequestMethod.POST)
71
+    public ResponseBean taButtonUriMapAdd(@RequestBody TaButtonUriMap taButtonUriMap){
72
+        ResponseBean responseBean = new ResponseBean();
73
+        try {
74
+            if (iTaButtonUriMapService.save(taButtonUriMap)){
75
+                responseBean.addSuccess(taButtonUriMap);
76
+            }else {
77
+                responseBean.addError("fail");
78
+            }
79
+        }catch (Exception e){
80
+            e.printStackTrace();
81
+            logger.error("taButtonUriMapAdd -=- {}",e.toString());
82
+            responseBean.addError(e.getMessage());
83
+        }
84
+        return responseBean;
85
+    }
86
+
87
+    /**
88
+     * 根据id删除对象
89
+     * @param id  实体ID
90
+     */
91
+    @ResponseBody
92
+    @RequestMapping(value="/taButtonUriMap/{id}", method= RequestMethod.DELETE)
93
+    public ResponseBean taButtonUriMapDelete(@PathVariable Integer id){
94
+        ResponseBean responseBean = new ResponseBean();
95
+        try {
96
+            if(iTaButtonUriMapService.removeById(id)){
97
+                responseBean.addSuccess("success");
98
+            }else {
99
+                responseBean.addError("fail");
100
+            }
101
+        }catch (Exception e){
102
+            e.printStackTrace();
103
+            logger.error("taButtonUriMapDelete -=- {}",e.toString());
104
+            responseBean.addError(e.getMessage());
105
+        }
106
+        return responseBean;
107
+    }
108
+
109
+    /**
110
+     * 修改对象
111
+     * @param id  实体ID
112
+     * @param taButtonUriMap 实体对象
113
+     * @return
114
+     */
115
+    @RequestMapping(value="/taButtonUriMap/{id}",method= RequestMethod.PUT)
116
+    public ResponseBean taButtonUriMapUpdate(@PathVariable Integer id,
117
+                                        @RequestBody TaButtonUriMap taButtonUriMap){
118
+        ResponseBean responseBean = new ResponseBean();
119
+        try {
120
+            if (iTaButtonUriMapService.updateById(taButtonUriMap)){
121
+                responseBean.addSuccess(taButtonUriMap);
122
+            }else {
123
+                responseBean.addError("fail");
124
+            }
125
+        }catch (Exception e){
126
+            e.printStackTrace();
127
+            logger.error("taButtonUriMapUpdate -=- {}",e.toString());
128
+            responseBean.addError(e.getMessage());
129
+        }
130
+        return responseBean;
131
+    }
132
+
133
+    /**
134
+     * 根据id查询对象
135
+     * @param id  实体ID
136
+     */
137
+    @RequestMapping(value="/taButtonUriMap/{id}",method= RequestMethod.GET)
138
+    public ResponseBean taButtonUriMapGet(@PathVariable Integer id){
139
+        ResponseBean responseBean = new ResponseBean();
140
+        try {
141
+            responseBean.addSuccess(iTaButtonUriMapService.getById(id));
142
+        }catch (Exception e){
143
+            e.printStackTrace();
144
+            logger.error("taButtonUriMapDelete -=- {}",e.toString());
145
+            responseBean.addError(e.getMessage());
146
+        }
147
+        return responseBean;
148
+    }
149
+}

+ 149
- 0
src/main/java/com/yunzhi/marketing/center/taUser/controller/TaTagUserController.java Просмотреть файл

@@ -0,0 +1,149 @@
1
+package com.yunzhi.marketing.center.taUser.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.marketing.base.BaseController;
7
+import com.yunzhi.marketing.base.ResponseBean;
8
+import com.yunzhi.marketing.center.taUser.entity.TaTagUser;
9
+import com.yunzhi.marketing.center.taUser.service.ITaTagUserService;
10
+import org.slf4j.Logger;
11
+import org.slf4j.LoggerFactory;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.web.bind.annotation.PathVariable;
14
+import org.springframework.web.bind.annotation.RequestBody;
15
+import org.springframework.web.bind.annotation.RequestMapping;
16
+import org.springframework.web.bind.annotation.RequestMethod;
17
+import org.springframework.web.bind.annotation.RequestParam;
18
+import org.springframework.web.bind.annotation.ResponseBody;
19
+import org.springframework.web.bind.annotation.RestController;
20
+
21
+/**
22
+ * <p>
23
+    *   前端控制器
24
+    * </p>
25
+ *
26
+ * @author jobob
27
+ * @since 2019-09-24
28
+ */
29
+@RestController
30
+@RequestMapping("/")
31
+public class TaTagUserController extends BaseController {
32
+
33
+    private final Logger logger = LoggerFactory.getLogger(TaTagUserController.class);
34
+
35
+    @Autowired
36
+    public ITaTagUserService iTaTagUserService;
37
+
38
+
39
+    /**
40
+     * 分页查询列表
41
+     * @param pageNum
42
+     * @param pageSize
43
+     * @return
44
+     */
45
+    @RequestMapping(value="/taTagUser",method= RequestMethod.GET)
46
+    public ResponseBean taTagUserList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
47
+                                      @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
48
+        ResponseBean responseBean = new ResponseBean();
49
+        try {
50
+            //使用分页插件
51
+		    IPage<TaTagUser> pg = new Page<>(pageNum, pageSize);
52
+            QueryWrapper<TaTagUser> queryWrapper = new QueryWrapper<>();
53
+            queryWrapper.orderByDesc("create_date");
54
+
55
+            IPage<TaTagUser> result = iTaTagUserService.page(pg, queryWrapper);
56
+            responseBean.addSuccess(result);
57
+        }catch (Exception e){
58
+            e.printStackTrace();
59
+            logger.error("taTagUserList -=- {}",e.toString());
60
+            responseBean.addError(e.getMessage());
61
+        }
62
+        return responseBean;
63
+    }
64
+
65
+    /**
66
+     * 保存对象
67
+     * @param taTagUser 实体对象
68
+     * @return
69
+     */
70
+    @RequestMapping(value="/taTagUser",method= RequestMethod.POST)
71
+    public ResponseBean taTagUserAdd(@RequestBody TaTagUser taTagUser){
72
+        ResponseBean responseBean = new ResponseBean();
73
+        try {
74
+            if (iTaTagUserService.save(taTagUser)){
75
+                responseBean.addSuccess(taTagUser);
76
+            }else {
77
+                responseBean.addError("fail");
78
+            }
79
+        }catch (Exception e){
80
+            e.printStackTrace();
81
+            logger.error("taTagUserAdd -=- {}",e.toString());
82
+            responseBean.addError(e.getMessage());
83
+        }
84
+        return responseBean;
85
+    }
86
+
87
+    /**
88
+     * 根据id删除对象
89
+     * @param id  实体ID
90
+     */
91
+    @ResponseBody
92
+    @RequestMapping(value="/taTagUser/{id}", method= RequestMethod.DELETE)
93
+    public ResponseBean taTagUserDelete(@PathVariable Integer id){
94
+        ResponseBean responseBean = new ResponseBean();
95
+        try {
96
+            if(iTaTagUserService.removeById(id)){
97
+                responseBean.addSuccess("success");
98
+            }else {
99
+                responseBean.addError("fail");
100
+            }
101
+        }catch (Exception e){
102
+            e.printStackTrace();
103
+            logger.error("taTagUserDelete -=- {}",e.toString());
104
+            responseBean.addError(e.getMessage());
105
+        }
106
+        return responseBean;
107
+    }
108
+
109
+    /**
110
+     * 修改对象
111
+     * @param id  实体ID
112
+     * @param taTagUser 实体对象
113
+     * @return
114
+     */
115
+    @RequestMapping(value="/taTagUser/{id}",method= RequestMethod.PUT)
116
+    public ResponseBean taTagUserUpdate(@PathVariable Integer id,
117
+                                        @RequestBody TaTagUser taTagUser){
118
+        ResponseBean responseBean = new ResponseBean();
119
+        try {
120
+            if (iTaTagUserService.updateById(taTagUser)){
121
+                responseBean.addSuccess(taTagUser);
122
+            }else {
123
+                responseBean.addError("fail");
124
+            }
125
+        }catch (Exception e){
126
+            e.printStackTrace();
127
+            logger.error("taTagUserUpdate -=- {}",e.toString());
128
+            responseBean.addError(e.getMessage());
129
+        }
130
+        return responseBean;
131
+    }
132
+
133
+    /**
134
+     * 根据id查询对象
135
+     * @param id  实体ID
136
+     */
137
+    @RequestMapping(value="/taTagUser/{id}",method= RequestMethod.GET)
138
+    public ResponseBean taTagUserGet(@PathVariable Integer id){
139
+        ResponseBean responseBean = new ResponseBean();
140
+        try {
141
+            responseBean.addSuccess(iTaTagUserService.getById(id));
142
+        }catch (Exception e){
143
+            e.printStackTrace();
144
+            logger.error("taTagUserDelete -=- {}",e.toString());
145
+            responseBean.addError(e.getMessage());
146
+        }
147
+        return responseBean;
148
+    }
149
+}

+ 150
- 0
src/main/java/com/yunzhi/marketing/center/taUser/controller/TaTagsController.java Просмотреть файл

@@ -0,0 +1,150 @@
1
+package com.yunzhi.marketing.center.taUser.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.marketing.base.BaseController;
7
+import com.yunzhi.marketing.base.ResponseBean;
8
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
9
+import com.yunzhi.marketing.center.taUser.service.ITaTagsService;
10
+import org.slf4j.Logger;
11
+import org.slf4j.LoggerFactory;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.web.bind.annotation.PathVariable;
14
+import org.springframework.web.bind.annotation.RequestBody;
15
+import org.springframework.web.bind.annotation.RequestMapping;
16
+import org.springframework.web.bind.annotation.RequestMethod;
17
+import org.springframework.web.bind.annotation.RequestParam;
18
+import org.springframework.web.bind.annotation.ResponseBody;
19
+import org.springframework.web.bind.annotation.RestController;
20
+
21
+import javax.servlet.http.HttpServletRequest;
22
+
23
+/**
24
+ * <p>
25
+    *   前端控制器
26
+    * </p>
27
+ *
28
+ * @author jobob
29
+ * @since 2019-09-24
30
+ */
31
+@RestController
32
+@RequestMapping("/api")
33
+public class TaTagsController extends BaseController {
34
+
35
+    private final Logger logger = LoggerFactory.getLogger(TaTagsController.class);
36
+
37
+    @Autowired
38
+    public ITaTagsService iTaTagsService;
39
+
40
+
41
+    /**
42
+     * 分页查询列表
43
+     * @param pageNum
44
+     * @param pageSize
45
+     * @return
46
+     */
47
+    @RequestMapping(value="/admin/taTags",method= RequestMethod.GET)
48
+    public ResponseBean taTagsList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
49
+                                   @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize, HttpServletRequest request){
50
+        ResponseBean responseBean = new ResponseBean();
51
+        try {
52
+            //使用分页插件
53
+		    IPage<TaTags> pg = new Page<>(pageNum, pageSize);
54
+            QueryWrapper<TaTags> queryWrapper = new QueryWrapper<>();
55
+            queryWrapper.eq("org_id",getOrgId(request));
56
+            IPage<TaTags> result = iTaTagsService.page(pg, queryWrapper);
57
+            responseBean.addSuccess(result);
58
+        }catch (Exception e){
59
+            e.printStackTrace();
60
+            logger.error("taTagsList -=- {}",e.toString());
61
+            responseBean.addError(e.getMessage());
62
+        }
63
+        return responseBean;
64
+    }
65
+
66
+    /**
67
+     * 保存对象
68
+     * @param taTags 实体对象
69
+     * @return
70
+     */
71
+    @RequestMapping(value="/taTags",method= RequestMethod.POST)
72
+    public ResponseBean taTagsAdd(@RequestBody TaTags taTags){
73
+        ResponseBean responseBean = new ResponseBean();
74
+        try {
75
+            if (iTaTagsService.save(taTags)){
76
+                responseBean.addSuccess(taTags);
77
+            }else {
78
+                responseBean.addError("fail");
79
+            }
80
+        }catch (Exception e){
81
+            e.printStackTrace();
82
+            logger.error("taTagsAdd -=- {}",e.toString());
83
+            responseBean.addError(e.getMessage());
84
+        }
85
+        return responseBean;
86
+    }
87
+
88
+    /**
89
+     * 根据id删除对象
90
+     * @param id  实体ID
91
+     */
92
+    @ResponseBody
93
+    @RequestMapping(value="/taTags/{id}", method= RequestMethod.DELETE)
94
+    public ResponseBean taTagsDelete(@PathVariable Integer id){
95
+        ResponseBean responseBean = new ResponseBean();
96
+        try {
97
+            if(iTaTagsService.removeById(id)){
98
+                responseBean.addSuccess("success");
99
+            }else {
100
+                responseBean.addError("fail");
101
+            }
102
+        }catch (Exception e){
103
+            e.printStackTrace();
104
+            logger.error("taTagsDelete -=- {}",e.toString());
105
+            responseBean.addError(e.getMessage());
106
+        }
107
+        return responseBean;
108
+    }
109
+
110
+    /**
111
+     * 修改对象
112
+     * @param id  实体ID
113
+     * @param taTags 实体对象
114
+     * @return
115
+     */
116
+    @RequestMapping(value="/taTags/{id}",method= RequestMethod.PUT)
117
+    public ResponseBean taTagsUpdate(@PathVariable Integer id,
118
+                                        @RequestBody TaTags taTags){
119
+        ResponseBean responseBean = new ResponseBean();
120
+        try {
121
+            if (iTaTagsService.updateById(taTags)){
122
+                responseBean.addSuccess(taTags);
123
+            }else {
124
+                responseBean.addError("fail");
125
+            }
126
+        }catch (Exception e){
127
+            e.printStackTrace();
128
+            logger.error("taTagsUpdate -=- {}",e.toString());
129
+            responseBean.addError(e.getMessage());
130
+        }
131
+        return responseBean;
132
+    }
133
+
134
+    /**
135
+     * 根据id查询对象
136
+     * @param id  实体ID
137
+     */
138
+    @RequestMapping(value="/taTags/{id}",method= RequestMethod.GET)
139
+    public ResponseBean taTagsGet(@PathVariable Integer id){
140
+        ResponseBean responseBean = new ResponseBean();
141
+        try {
142
+            responseBean.addSuccess(iTaTagsService.getById(id));
143
+        }catch (Exception e){
144
+            e.printStackTrace();
145
+            logger.error("taTagsDelete -=- {}",e.toString());
146
+            responseBean.addError(e.getMessage());
147
+        }
148
+        return responseBean;
149
+    }
150
+}

+ 68
- 0
src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserAuthButtonController.java Просмотреть файл

@@ -0,0 +1,68 @@
1
+package com.yunzhi.marketing.center.taUser.controller;
2
+
3
+import com.alibaba.fastjson.JSONArray;
4
+import com.alibaba.fastjson.JSONObject;
5
+import com.yunzhi.marketing.base.BaseController;
6
+import com.yunzhi.marketing.base.ResponseBean;
7
+import com.yunzhi.marketing.center.taUser.service.ITaUserAuthButtonService;
8
+import com.yunzhi.marketing.entity.SysButtonInMenu;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.web.bind.annotation.*;
11
+
12
+import javax.servlet.http.HttpServletRequest;
13
+import java.util.List;
14
+
15
+/**
16
+ * @author weicc
17
+ * @Title: TaUserAuthButtonController
18
+ * @Description: TODO
19
+ * @date 2019/9/23
20
+ */
21
+@RestController
22
+@RequestMapping("/api")
23
+public class TaUserAuthButtonController extends BaseController {
24
+
25
+    @Autowired
26
+    public ITaUserAuthButtonService iTaUserAuthButtonService;
27
+
28
+    /**
29
+     * 根据userId获取菜单列表
30
+     * @param pageNum
31
+     * @param pageSize
32
+     * @return
33
+     */
34
+    @RequestMapping(value="/admin/userAuthButton",method= RequestMethod.GET)
35
+    public ResponseBean getButtonByUserId(HttpServletRequest servletRequest,
36
+                                          @RequestParam("pageNum")Integer pageNum,
37
+                                          @RequestParam("pageSize")Integer pageSize){
38
+        Integer userId = getUserId(servletRequest);
39
+        return iTaUserAuthButtonService.getButtonByUserId(pageNum,pageSize,userId.toString(),getOrgId(servletRequest));
40
+    }
41
+
42
+
43
+    /**
44
+     * 获取所有的菜单按钮
45
+     * @param pageNum
46
+     * @param pageSize
47
+     * @return
48
+     */
49
+    @RequestMapping(value="/admin/buttonList",method= RequestMethod.GET)
50
+    public ResponseBean getMenuByRole(@RequestParam("pageNum")Integer pageNum,
51
+                                      @RequestParam("pageSize")Integer pageSize){
52
+        return iTaUserAuthButtonService.getAllButton(pageNum, pageSize);
53
+    }
54
+
55
+    /**
56
+     * 用户授权按钮
57
+     * @return
58
+     */
59
+    @RequestMapping(value="/admin/updateAuthButton",method= RequestMethod.PUT)
60
+    public ResponseBean updateUserAuthMenu(HttpServletRequest request,
61
+                                           @RequestBody String sysButton){
62
+        Integer userId = getUserId(request);
63
+        JSONObject Object = JSONObject.parseObject(sysButton);
64
+        JSONArray JSONArray = Object.getJSONArray("sysButton");
65
+        List<SysButtonInMenu> sysButtonInMenuList = JSONArray.toJavaList(SysButtonInMenu.class);
66
+        return iTaUserAuthButtonService.updateUserAuthButton(userId, sysButtonInMenuList);
67
+    }
68
+}

+ 72
- 0
src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserAuthMenuController.java Просмотреть файл

@@ -0,0 +1,72 @@
1
+package com.yunzhi.marketing.center.taUser.controller;
2
+
3
+import com.alibaba.fastjson.JSONArray;
4
+import com.alibaba.fastjson.JSONObject;
5
+import com.yunzhi.marketing.base.BaseController;
6
+import com.yunzhi.marketing.base.ResponseBean;
7
+import com.yunzhi.marketing.center.taUser.service.ITaUserAuthMenuService;
8
+import com.yunzhi.marketing.entity.SysButtonInMenu;
9
+import com.yunzhi.marketing.entity.SysMenu;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.web.bind.annotation.*;
12
+
13
+import javax.servlet.http.HttpServletRequest;
14
+import java.util.List;
15
+
16
+/**
17
+ * @author weicc
18
+ * @Title: TaUserAuthMenuController
19
+ * @Description: TODO
20
+ * @date 2019/9/21
21
+ */
22
+@RestController
23
+@RequestMapping("/api")
24
+public class TaUserAuthMenuController extends BaseController {
25
+
26
+    @Autowired
27
+    public ITaUserAuthMenuService iTaUserAuthMenuService;
28
+
29
+    /**
30
+     * 根据userId获取菜单列表
31
+     * @param pageNum
32
+     * @param pageSize
33
+     * @return
34
+     */
35
+    @RequestMapping(value="/admin/userAuthMenu",method= RequestMethod.GET)
36
+    public ResponseBean  getMenuByUserId(@RequestParam("pageNum")Integer pageNum,
37
+                                         @RequestParam("pageSize")Integer pageSize,
38
+                                         HttpServletRequest request){
39
+        Integer userId = getUserId(request);
40
+        return iTaUserAuthMenuService.getMenuByUserId(pageNum,pageSize,userId.toString(), getOrgId(request));
41
+    }
42
+
43
+    /**
44
+     * 获取所有菜单
45
+     * @param pageNum
46
+     * @param pageSize
47
+     * @return
48
+     */
49
+    @RequestMapping(value="/admin/menuList",method= RequestMethod.GET)
50
+    public ResponseBean getMenuByRole(@RequestParam("pageNum")Integer pageNum,
51
+                                      @RequestParam("pageSize")Integer pageSize, HttpServletRequest request){
52
+        return iTaUserAuthMenuService.getAllMenu(pageNum, pageSize, getOrgId(request), null);
53
+    }
54
+
55
+    /**
56
+     * 用户授权菜单
57
+     * @return
58
+     */
59
+    @RequestMapping(value="/admin/updateAuthMenu",method= RequestMethod.POST)
60
+    public ResponseBean updateUserAuthMenu(HttpServletRequest request,
61
+                                           @RequestBody String sysMenu){
62
+        JSONObject Object = JSONObject.parseObject(sysMenu);
63
+        String name = Object.getString("name");
64
+        Integer userId = Object.getInteger("id");
65
+        JSONArray JSONArray = Object.getJSONArray("sysMenu");
66
+        List<SysMenu> sysMenuList = JSONArray.toJavaList(SysMenu.class);
67
+
68
+        JSONArray buttonArray = Object.getJSONArray("sysButton");
69
+        List<SysButtonInMenu> sysButtonInMenuList = buttonArray.toJavaList(SysButtonInMenu.class);
70
+        return iTaUserAuthMenuService.updateUserAuthMenu(userId, sysMenuList,name,getOrgId(request),sysButtonInMenuList);
71
+    }
72
+}

+ 566
- 0
src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserController.java Просмотреть файл

@@ -0,0 +1,566 @@
1
+package com.yunzhi.marketing.center.taUser.controller;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
+import com.baomidou.mybatisplus.core.metadata.IPage;
6
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
+import com.yunzhi.marketing.base.BaseController;
8
+import com.yunzhi.marketing.base.ResponseBean;
9
+import com.yunzhi.marketing.center.sysUser.entity.SysToken;
10
+import com.yunzhi.marketing.center.sysUser.service.ISysTokenService;
11
+import com.yunzhi.marketing.center.taUser.entity.TaTagUser;
12
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
13
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
14
+import com.yunzhi.marketing.center.taUser.entity.TaUserRole;
15
+import com.yunzhi.marketing.center.taUser.service.*;
16
+import com.yunzhi.marketing.common.CommConstant;
17
+import com.yunzhi.marketing.common.JWTUtils;
18
+import com.yunzhi.marketing.common.MD5Utils;
19
+import com.yunzhi.marketing.mapper.TaRoleMapper;
20
+import com.yunzhi.marketing.entity.*;
21
+import com.yunzhi.marketing.service.*;
22
+import org.slf4j.Logger;
23
+import org.slf4j.LoggerFactory;
24
+import org.springframework.beans.factory.annotation.Autowired;
25
+import org.springframework.web.bind.annotation.*;
26
+
27
+import javax.servlet.http.HttpServletRequest;
28
+
29
+import java.time.LocalDateTime;
30
+import java.util.ArrayList;
31
+import java.util.HashMap;
32
+import java.util.List;
33
+import java.util.Map;
34
+
35
+/**
36
+ * <p>
37
+    * 用户表  前端控制器
38
+    * </p>
39
+ *
40
+ * @author jobob
41
+ * @since 2019-09-11
42
+ */
43
+@RestController
44
+@RequestMapping("/api")
45
+public class TaUserController extends BaseController {
46
+
47
+    private final Logger logger = LoggerFactory.getLogger(TaUserController.class);
48
+
49
+    @Autowired
50
+    public ITaUserService iTaUserService;
51
+
52
+    @Autowired
53
+    public ITaOrgService iTaOrgService;
54
+    
55
+    @Autowired
56
+    private ISysTokenService sysTokenService;
57
+
58
+    @Autowired
59
+    private ITaRoleService iTaRoleService;
60
+
61
+    @Autowired
62
+    private ITaUserAuthMenuService iTaUserAuthMenuService;
63
+
64
+    @Autowired
65
+    private ITaUserAuthButtonService iTaUserAuthButtonService;
66
+    
67
+    @Autowired
68
+    private ITaTagUserService taTagUserService;
69
+    
70
+    @Autowired
71
+    private ITaPersonBuildingService taPersonBuildingService;
72
+    
73
+    @Autowired
74
+    private ITaUserRoleService taUserRoleService;
75
+
76
+    @Autowired
77
+    private TaRoleMapper taRoleMapper;
78
+
79
+    @Autowired
80
+    private ITaPersonService iTaPersonService;
81
+
82
+    @Autowired
83
+    private ITaMiniappService iTaMiniappService;
84
+
85
+    /**
86
+     * 分页查询列表
87
+     * @param pageNum
88
+     * @param pageSize
89
+     * @return
90
+     */
91
+    @RequestMapping(value="/center/taUser",method= RequestMethod.GET)
92
+    public ResponseBean taUserList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
93
+									 @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
94
+                                     @RequestParam(value = "miniAppName", required = false) String miniAppName, HttpServletRequest request){
95
+        ResponseBean responseBean = new ResponseBean();
96
+
97
+        try {
98
+            //使用分页插件
99
+		    IPage pg = new Page<>(pageNum, pageSize);
100
+            IPage<Map<String,Object>> result = iTaUserService.getPageList(pg, getChannelId(request), miniAppName);
101
+            responseBean.addSuccess(result);
102
+        }catch (Exception e){
103
+            e.printStackTrace();
104
+            logger.error("taUserList -=- {}",e.toString());
105
+            responseBean.addError(e.getMessage());
106
+        }
107
+        return responseBean;
108
+    }
109
+
110
+    /**
111
+     * 分页查询列表
112
+     * @param pageNum
113
+     * @param pageSize
114
+     * @return
115
+     */
116
+    @RequestMapping(value="/channel/taUser",method= RequestMethod.GET)
117
+    public ResponseBean taUserChannelList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
118
+                                   @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
119
+        ResponseBean responseBean = new ResponseBean();
120
+        try {
121
+            //使用分页插件
122
+            IPage pg = new Page<>(pageNum, pageSize);
123
+            IPage<Map<String,Object>> result = iTaUserService.getPageList(pg, null, null);
124
+            responseBean.addSuccess(result);
125
+        }catch (Exception e){
126
+            e.printStackTrace();
127
+            logger.error("taUserList -=- {}",e.toString());
128
+            responseBean.addError(e.getMessage());
129
+        }
130
+        return responseBean;
131
+    }
132
+
133
+    /**
134
+     * 保存对象
135
+     * @param taUser 实体对象
136
+     * @return
137
+     */
138
+    @RequestMapping(value="/center/taUser",method= RequestMethod.POST)
139
+    public ResponseBean taUserAdd(@RequestBody TaUser taUser, HttpServletRequest request){
140
+        ResponseBean responseBean = new ResponseBean();
141
+        Integer channelId = getChannelId(request);
142
+        try {
143
+            responseBean.addSuccess(iTaUserService.newUserAndOrg(taUser, channelId));
144
+        }catch (Exception e){
145
+            e.printStackTrace();
146
+            logger.error("taUserAdd -=- {}",e.toString());
147
+            responseBean.addError(e.getMessage());
148
+        }
149
+        return responseBean;
150
+    }
151
+
152
+    @PutMapping(value = "/{plat}/turn/taUser/{id}/{type}")
153
+    public ResponseBean turnUser(@PathVariable String type, @PathVariable Integer id, @PathVariable("plat")String plat) {
154
+        try {
155
+            iTaUserService.turnUserOnOrNot(id, "on".equals(type), plat);
156
+        } catch (Exception e) {
157
+            e.printStackTrace();
158
+            return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
159
+        }
160
+
161
+        return ResponseBean.success("ok");
162
+    }
163
+
164
+    /**
165
+     * 根据id删除对象
166
+     * @param id  实体ID
167
+     */
168
+    @ResponseBody
169
+    @RequestMapping(value="/taUser/{id}", method= RequestMethod.DELETE)
170
+    public ResponseBean taUserDelete(@PathVariable Integer id){
171
+        ResponseBean responseBean = new ResponseBean();
172
+        try {
173
+            if(iTaUserService.removeById(id)){
174
+                responseBean.addSuccess("success");
175
+            }else {
176
+                responseBean.addError("fail");
177
+            }
178
+        }catch (Exception e){
179
+            e.printStackTrace();
180
+            logger.error("taUserDelete -=- {}",e.toString());
181
+            responseBean.addError(e.getMessage());
182
+        }
183
+        return responseBean;
184
+    }
185
+
186
+    /**
187
+     * 修改对象
188
+     * @param id  实体ID
189
+     * @param taUser 实体对象
190
+     * @return
191
+     */
192
+    @RequestMapping(value="/center/taUser/{id}",method= RequestMethod.PUT)
193
+    public ResponseBean taUserUpdate(@PathVariable Integer id,
194
+                                        @RequestBody TaUser taUser){
195
+        ResponseBean responseBean = new ResponseBean();
196
+        try {
197
+            iTaUserService.updateInfoWithOrg(taUser);
198
+        }catch (Exception e){
199
+            e.printStackTrace();
200
+            logger.error("taUserUpdate -=- {}",e.toString());
201
+            responseBean.addError(e.getMessage());
202
+        }
203
+        return responseBean;
204
+    }
205
+    /**
206
+     * 获取用户信息
207
+     */
208
+    @RequestMapping(value="/center/taUser/{id}",method= RequestMethod.GET)
209
+    public ResponseBean taUserGet(@PathVariable Integer id){
210
+        ResponseBean responseBean = new ResponseBean();
211
+        try {
212
+            responseBean.addSuccess(iTaUserService.getInfoWithOrg(id));
213
+        }catch (Exception e){
214
+            e.printStackTrace();
215
+            logger.error("taUserDelete -=- {}",e.toString());
216
+            responseBean.addError(e.getMessage());
217
+        }
218
+
219
+        return responseBean;
220
+    }
221
+
222
+    /**
223
+     * 重置密码
224
+     * @param plat
225
+     * @param id
226
+     * @return
227
+     */
228
+    @PutMapping(value = "/{plat}/password/taUser/{id}")
229
+    public ResponseBean resetPassword(@PathVariable String plat, @PathVariable Integer id, HttpServletRequest request) {
230
+        if (!"center".equals(plat) && !"admin".equals(plat)) {
231
+            return ResponseBean.error("您没有权限进行此操作", ResponseBean.ERROR_AUTH_EXPIRED);
232
+        }
233
+
234
+        String newPass = plat.equals("center") ? "abc@123" : "123456";
235
+        try {
236
+            iTaUserService.resetPassword(id, newPass);
237
+            return ResponseBean.success("新密码为: " + newPass);
238
+        } catch (Exception e) {
239
+            e.printStackTrace();
240
+            return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
241
+        }
242
+    }
243
+
244
+
245
+    /**
246
+     * 业务端  修改密码
247
+     * @return/
248
+     */
249
+    @PutMapping(value = "/admin/update/password")
250
+    public ResponseBean updatePassword( @RequestParam String originalPassword,
251
+                                        @RequestParam String newPassword,
252
+                                        HttpServletRequest request) {
253
+
254
+        if (org.apache.commons.lang3.StringUtils.isBlank(newPassword) || newPassword.length() < 6) {
255
+            return ResponseBean.error("新密不能小于6位", ResponseBean.ERROR_UNAVAILABLE);
256
+        }
257
+
258
+        Integer userId = getUserId(request);
259
+
260
+        // 校验当前旧密码是否正确
261
+        String password = MD5Utils.md5(MD5Utils.md5(originalPassword));
262
+        TaUser taUser = iTaUserService.getById(userId);
263
+        if (!password.equals(taUser.getLoginPassword())){
264
+            return ResponseBean.error("旧密码错误,请重新输入", ResponseBean.ERROR_UNAVAILABLE);
265
+        }
266
+
267
+        try {
268
+            iTaUserService.resetPassword(userId, newPassword);
269
+            return ResponseBean.success("操作成功!");
270
+        } catch (Exception e) {
271
+            e.printStackTrace();
272
+            return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
273
+        }
274
+    }
275
+
276
+    /**
277
+     * 获取当前用户信息
278
+     * @param request
279
+     * @return
280
+     */
281
+    @RequestMapping(value="/admin/taUser/current",method= RequestMethod.GET)
282
+    public ResponseBean taUserGetCurrent(HttpServletRequest request){
283
+        ResponseBean responseBean = new ResponseBean();
284
+        Map userMap = new HashMap();
285
+        Map map = JWTUtils.getUserIdAndOrgId(request);
286
+        try {
287
+            TaUser taUser = iTaUserService.getById(map.get("userId").toString());
288
+            List<TaRole> roles = iTaRoleService.getRolesByUser(taUser.getUserId());
289
+            ResponseBean authMenu = iTaUserAuthMenuService.getMenuByUserId(null, null, taUser.getUserId().toString(),taUser.getOrgId());
290
+            ResponseBean authButton = iTaUserAuthButtonService.getButtonByUserId(null, null, taUser.getUserId().toString(),taUser.getOrgId());
291
+            QueryWrapper<TaMiniapp> taMiniappQueryWrapper = new QueryWrapper<>();
292
+            taMiniappQueryWrapper.eq("org_id", getOrgId(request));
293
+            TaMiniapp taMiniapp = iTaMiniappService.getOne(taMiniappQueryWrapper);
294
+            //
295
+            TaOrg taOrg = iTaOrgService.getById(taUser.getOrgId());
296
+
297
+            taUser.setMenus((List<SysMenu>) authMenu.getData());
298
+            taUser.setButtons((List<SysButtonInMenu>) authButton.getData());
299
+            taUser.setRoles(roles);
300
+            taUser.setLoginPassword("");
301
+            taUser.setMiniAppName(taMiniapp.getName());
302
+            taUser.setOrgName(taOrg.getName());
303
+            taUser.setOrgThumb(taOrg.getThumb());
304
+            taUser.setOrgLogo(taOrg.getLogo());
305
+            taUser.setOrgDesc(taOrg.getOrgDesc());
306
+            taUser.setBossDisplay(taOrg.getBossDisplay());
307
+
308
+            //获取所有菜单
309
+            List<SysMenu> allMenus = (List<SysMenu>) iTaUserAuthMenuService.getAllMenu(null, null,taUser.getOrgId(), roles).getData();
310
+            List<SysButtonInMenu> allButtons = (List<SysButtonInMenu>) iTaUserAuthButtonService.getAllButton(null, null).getData();
311
+
312
+
313
+            userMap.put("taUser", taUser);
314
+            userMap.put("menuList", allMenus);
315
+            userMap.put("buttonList", allButtons);
316
+            responseBean.addSuccess(userMap);
317
+        }catch (Exception e){
318
+            e.printStackTrace();
319
+            logger.error("taUserDelete -=- {}",e.toString());
320
+            responseBean.addError(e.getMessage());
321
+        }
322
+        return responseBean;
323
+    }
324
+    
325
+    /**
326
+     * 用户手机号登录
327
+     * @param paramStr
328
+     * @return
329
+     */
330
+    @PostMapping("/admin/taUser/signin")
331
+    public ResponseBean signin(@RequestBody String paramStr) {
332
+        JSONObject params = JSONObject.parseObject(paramStr);
333
+        if (params == null) {
334
+            return ResponseBean.error("非法参数", ResponseBean.ERROR_MISSING_PARAMS);
335
+        }
336
+    
337
+        String userName = params.getString("loginName");
338
+        String userPassword = params.getString("loginPassword");
339
+    
340
+        //验证用户名密码是否正确
341
+        QueryWrapper<TaUser> sysUserQueryWrapper = new QueryWrapper<>();
342
+        sysUserQueryWrapper.eq("login_name",userName);
343
+        sysUserQueryWrapper.eq("login_password", MD5Utils.md5(userPassword));
344
+        TaUser taUser = iTaUserService.getOne(sysUserQueryWrapper);
345
+        if (taUser == null) {
346
+            return ResponseBean.error("用户名或密码错误", ResponseBean.ERROR_ILLEGAL_PARAMS);
347
+        }
348
+
349
+        QueryWrapper<TaUser> taUserQueryWrapper = new QueryWrapper<>();
350
+        taUserQueryWrapper.eq("org_id", taUser.getOrgId());
351
+        taUserQueryWrapper.eq("is_admin", 1);
352
+        TaUser taUserAdmin = iTaUserService.getOne(taUserQueryWrapper);
353
+
354
+        if (taUserAdmin.getExpDate().isBefore(LocalDateTime.now())){
355
+            return ResponseBean.error("该账号已经过期,请联系管理员", ResponseBean.ERROR_UNAVAILABLE);
356
+        }
357
+
358
+        if (!taUser.getStatus().equals(CommConstant.STATUS_NORMAL) ) {
359
+            return ResponseBean.error("该账号已经停用,请联系管理员", ResponseBean.ERROR_UNAVAILABLE);
360
+        }
361
+
362
+
363
+        List<TaRole> roles = iTaRoleService.getRolesByUser(taUser.getUserId());
364
+        taUser.setRoles(roles);
365
+        taUser.setLoginPassword("");
366
+        Map map = new HashMap();
367
+        map.put("userId",taUser.getUserId().toString());
368
+        map.put("orgId",taUser.getOrgId().toString());
369
+        String token = JWTUtils.newTokenByMap(map);
370
+
371
+        // 先尝试删除这个Token
372
+        // 因为偶尔出现了,Token插入失败,报的错就是主键重复
373
+        sysTokenService.removeById(token);
374
+
375
+        //保存token
376
+        sysTokenService.saveToken(token);
377
+    
378
+        Map<String, Object> result = new HashMap<>();
379
+        result.put("token", token);
380
+        result.put("user", taUser);
381
+
382
+        return ResponseBean.success(result);
383
+    }
384
+    
385
+    @PostMapping("/admin/taUser/signout")
386
+    public ResponseBean signout(HttpServletRequest request) {
387
+        String token = JWTUtils.getToken(request);
388
+        QueryWrapper<SysToken> sysTokenQueryWrapper = new QueryWrapper<>();
389
+        sysTokenQueryWrapper.eq("token",token);
390
+        sysTokenService.remove(sysTokenQueryWrapper);
391
+        return ResponseBean.success("成功退出");
392
+    }
393
+    
394
+    
395
+    /**
396
+     * 分页查询列表
397
+     * @param pageNum
398
+     * @param pageSize
399
+     * @return
400
+     */
401
+    @RequestMapping(value="/admin/taUser",method= RequestMethod.GET)
402
+    public ResponseBean taUserList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
403
+                                   @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
404
+                                   @RequestParam(value ="userName",required = false) String userName,
405
+                                   @RequestParam(value ="phone",required = false) String phone,
406
+                                   @RequestParam(value ="status",required = false) Integer status,
407
+                                   @RequestParam(value ="isConsultant",required = false) Integer isConsultant,
408
+                                   @RequestParam(value ="miniStatus",required = false) Integer miniStatus,
409
+                                   @RequestParam(value ="buildingId",required = false) String buildingId,
410
+                                   HttpServletRequest request){
411
+        ResponseBean responseBean = new ResponseBean();
412
+        try {
413
+            //使用分页插件
414
+            IPage pg = new Page<>(pageNum, pageSize);
415
+            TaUser taUser = new TaUser();
416
+            taUser.setOrgId(getOrgId(request));
417
+            taUser.setUserName(userName);
418
+            taUser.setPhone(phone);
419
+            taUser.setStatus(status);
420
+            taUser.setBuildingId(buildingId);
421
+            if(null != isConsultant && isConsultant == 1){
422
+                taUser.setIsConsultant(true);
423
+            }else if (null != isConsultant && isConsultant == 0){
424
+                taUser.setIsConsultant(false);
425
+            }
426
+            taUser.setMiniStatus(miniStatus);
427
+
428
+            IPage<TaUser> result = iTaUserService.seleUserList(pg,taUser,getTaPersonBuildingListByUserId(request));
429
+            List<TaUser> taUserList = result.getRecords();
430
+            taUserList.forEach(e -> {
431
+                List<TaTags> taTagsList = iTaUserService.getTagsList(e);
432
+                e.setTaTagsList(taTagsList);
433
+
434
+//                Integer person = iTaPersonService.judgeBindStatusByCondition(e.getUserId(), getOrgId(request), e.getPhone());
435
+//                e.setMiniStatus(0 == person ? 0 : 1);
436
+            });
437
+            result.setRecords(taUserList);
438
+            responseBean.addSuccess(result);
439
+        }catch (Exception e){
440
+            e.printStackTrace();
441
+            logger.error("taUserList -=- {}",e.toString());
442
+            responseBean.addError(e.getMessage());
443
+        }
444
+        return responseBean;
445
+    }
446
+    
447
+    
448
+    /**
449
+     * 获取用户信息
450
+     */
451
+    @RequestMapping(value="/admin/taUser/{id}",method= RequestMethod.GET)
452
+    public ResponseBean adminUserGet(@PathVariable Integer id){
453
+        ResponseBean responseBean = new ResponseBean();
454
+        try {
455
+            TaUser taUser = iTaUserService.getById(id);
456
+            QueryWrapper<TaTagUser> queryWrapper = new QueryWrapper<>();
457
+            queryWrapper.eq("user_id",id);
458
+            List<TaTagUser> taTagUserList = taTagUserService.list(queryWrapper);
459
+            List<Integer> tags = new ArrayList<>();
460
+            taTagUserList.forEach(e -> {
461
+                tags.add(e.getTagId());
462
+            });
463
+            taUser.setTaTags(tags);
464
+            //获取角色信息
465
+            QueryWrapper<TaUserRole> taUserRoleQueryWrapper = new QueryWrapper<>();
466
+            taUserRoleQueryWrapper.eq("user_id",id);
467
+            List<TaUserRole> taUserRoleList = taUserRoleService.list(taUserRoleQueryWrapper);
468
+            List<Integer> ids = new ArrayList<>();
469
+            taUserRoleList.forEach(e -> {
470
+                ids.add(e.getRoleId());
471
+            });
472
+            taUser.setRoleIds(ids);
473
+            taUser.setLoginPassword("");
474
+            QueryWrapper<TaPersonBuilding> taPersonBuildingQueryWrapper = new QueryWrapper<>();
475
+            taPersonBuildingQueryWrapper.eq("user_id",taUser.getUserId());
476
+            List<TaPersonBuilding> taPersonBuildingList = taPersonBuildingService.list(taPersonBuildingQueryWrapper);
477
+            //非置业顾问可以授权多个项目
478
+            if (taPersonBuildingList.size() > 0){
479
+                if (taUser.getIsConsultant()){
480
+                    taUser.setBuildingId(taPersonBuildingList.get(0).getBuildingId());
481
+                    QueryWrapper<TaPerson> taPersonQueryWrapper = new QueryWrapper<>();
482
+                    taPersonQueryWrapper.eq("user_id",id);
483
+                    taPersonQueryWrapper.eq("org_id",taUser.getOrgId());
484
+                    TaPerson taPerson = iTaPersonService.getOne(taPersonQueryWrapper);
485
+                    if (null != taPerson){
486
+                        taUser.setConsultantPersonId(taPerson.getPersonId());
487
+                    }
488
+                }else {
489
+                    List<String> buildings = new ArrayList<>();
490
+                    taPersonBuildingList.forEach(e -> {
491
+                        buildings.add(e.getBuildingId());
492
+                    });
493
+                    taUser.setBuildingIds(buildings);
494
+                }
495
+            }
496
+            responseBean.addSuccess(taUser);
497
+        }catch (Exception e){
498
+            e.printStackTrace();
499
+            logger.error("taUserDelete -=- {}",e.toString());
500
+            responseBean.addError(e.getMessage());
501
+        }
502
+        
503
+        return responseBean;
504
+    }
505
+    
506
+    /**
507
+     * 保存对象
508
+     * @param taUser 实体对象
509
+     * @return
510
+     */
511
+    @RequestMapping(value="/admin/taUser",method= RequestMethod.POST)
512
+    public ResponseBean adminUserAdd(@RequestBody TaUser taUser,HttpServletRequest request){
513
+        ResponseBean responseBean = new ResponseBean();
514
+        try {
515
+            taUser.setOrgId(getOrgId(request));
516
+            responseBean.addSuccess(iTaUserService.addAdminUser(taUser));
517
+        }catch (Exception e){
518
+            e.printStackTrace();
519
+            logger.error("taUserAdd -=- {}",e.toString());
520
+            responseBean.addError(e.getMessage());
521
+        }
522
+        return responseBean;
523
+    }
524
+    
525
+    /**
526
+     * 修改对象
527
+     * @param id  实体ID
528
+     * @param taUser 实体对象
529
+     * @return
530
+     */
531
+    @RequestMapping(value="/admin/taUser/{id}",method= RequestMethod.PUT)
532
+    public ResponseBean adminUserUpdate(@PathVariable Integer id,
533
+                                     @RequestBody TaUser taUser,HttpServletRequest request){
534
+        ResponseBean responseBean = new ResponseBean();
535
+        try {
536
+            taUser.setUserId(id);
537
+            taUser.setOrgId(getOrgId(request));
538
+            responseBean.addSuccess(iTaUserService.updateAdminUser(taUser));
539
+        }catch (Exception e){
540
+            e.printStackTrace();
541
+            logger.error("taUserUpdate -=- {}",e.toString());
542
+            responseBean.addError(e.getMessage());
543
+        }
544
+        return responseBean;
545
+    }
546
+
547
+    // 树形菜单
548
+    @RequestMapping(value="/center/taUser/city/tree",method= RequestMethod.GET)
549
+    public ResponseBean cityTree(){
550
+        ResponseBean taUser = iTaUserService.cityTree();
551
+        return taUser;
552
+    }
553
+
554
+    /**
555
+     * 员工离职
556
+     * @return
557
+     */
558
+    @RequestMapping(value = "/admin/user/departure/{userId}", method = RequestMethod.PUT)
559
+    public ResponseBean departureUser(@PathVariable("userId") Integer userId,
560
+                                      @RequestParam(value = "customerIdList", required = false) List<String> customerIdList,
561
+                                      @RequestParam(value = "consultantUserId", required = false) Integer consultantUserId) {
562
+        ResponseBean responseBean = new ResponseBean();
563
+        responseBean = iTaUserService.departureUser(userId, customerIdList, consultantUserId);
564
+        return responseBean;
565
+    }
566
+}

+ 177
- 0
src/main/java/com/yunzhi/marketing/center/taUser/controller/TaUserRoleController.java Просмотреть файл

@@ -0,0 +1,177 @@
1
+package com.yunzhi.marketing.center.taUser.controller;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.yunzhi.marketing.base.BaseController;
7
+import com.yunzhi.marketing.base.ResponseBean;
8
+import com.yunzhi.marketing.center.taUser.entity.TaUserRole;
9
+import com.yunzhi.marketing.center.taUser.service.ITaUserRoleService;
10
+import org.slf4j.Logger;
11
+import org.slf4j.LoggerFactory;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.web.bind.annotation.*;
14
+
15
+import java.util.ArrayList;
16
+import java.util.List;
17
+
18
+/**
19
+ * <p>
20
+    * 用户角色表  前端控制器
21
+    * </p>
22
+ *
23
+ * @author jobob
24
+ * @since 2019-09-11
25
+ */
26
+@RestController
27
+@RequestMapping("/")
28
+public class TaUserRoleController extends BaseController {
29
+
30
+    private final Logger logger = LoggerFactory.getLogger(TaUserRoleController.class);
31
+
32
+    @Autowired
33
+    public ITaUserRoleService iTaUserRoleService;
34
+
35
+
36
+    /**
37
+     * 分页查询列表
38
+     * @param pageNum
39
+     * @param pageSize
40
+     * @return
41
+     */
42
+    @RequestMapping(value="/center/taUserRole",method= RequestMethod.GET)
43
+    public ResponseBean taUserRoleList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
44
+									 @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
45
+        ResponseBean responseBean = new ResponseBean();
46
+        try {
47
+            //使用分页插件
48
+		    IPage<TaUserRole> pg = new Page<>(pageNum, pageSize);
49
+            QueryWrapper<TaUserRole> queryWrapper = new QueryWrapper<>();
50
+            queryWrapper.orderByDesc("create_date");
51
+
52
+            IPage<TaUserRole> result = iTaUserRoleService.page(pg, queryWrapper);
53
+            responseBean.addSuccess(result);
54
+        }catch (Exception e){
55
+            e.printStackTrace();
56
+            logger.error("taUserRoleList -=- {}",e.toString());
57
+            responseBean.addError(e.getMessage());
58
+        }
59
+        return responseBean;
60
+    }
61
+
62
+    /**
63
+     * 保存对象
64
+     * @param taUserRole 实体对象
65
+     * @return
66
+     */
67
+    @RequestMapping(value="/center/taUserRole",method= RequestMethod.POST)
68
+    public ResponseBean taUserRoleAdd(@RequestBody TaUserRole taUserRole){
69
+        ResponseBean responseBean = new ResponseBean();
70
+        try {
71
+            if (iTaUserRoleService.save(taUserRole)){
72
+                responseBean.addSuccess(taUserRole);
73
+            }else {
74
+                responseBean.addError("fail");
75
+            }
76
+        }catch (Exception e){
77
+            e.printStackTrace();
78
+            logger.error("taUserRoleAdd -=- {}",e.toString());
79
+            responseBean.addError(e.getMessage());
80
+        }
81
+        return responseBean;
82
+    }
83
+    
84
+    /**
85
+     * 批量保存用户角色
86
+     * @param taUserRole 实体对象
87
+     * @return
88
+     */
89
+    @RequestMapping(value="/center/taUserRoleList",method= RequestMethod.POST)
90
+    public ResponseBean taUserRoleListAdd(@RequestBody TaUserRole taUserRole){
91
+        ResponseBean responseBean = new ResponseBean();
92
+        try {
93
+            List<TaUserRole> taUserRoleList = new ArrayList<>();
94
+            List<Integer> roleIdList = taUserRole.getRoleIdList();
95
+            roleIdList.forEach(e -> {
96
+                TaUserRole taUserRoles = new TaUserRole();
97
+                taUserRoles.setRoleId(e);
98
+                taUserRole.setUserId(taUserRole.getUserId());
99
+                taUserRoleList.add(taUserRoles);
100
+            });
101
+            if (iTaUserRoleService.saveBatch(taUserRoleList)){
102
+                responseBean.addSuccess(taUserRole);
103
+            }else {
104
+                responseBean.addError("fail");
105
+            }
106
+        }catch (Exception e){
107
+            e.printStackTrace();
108
+            logger.error("taUserRoleAdd -=- {}",e.toString());
109
+            responseBean.addError(e.getMessage());
110
+        }
111
+        return responseBean;
112
+    }
113
+
114
+    /**
115
+     * 根据id删除对象
116
+     * @param id  实体ID
117
+     */
118
+    @ResponseBody
119
+    @RequestMapping(value="/taUserRole/{id}", method= RequestMethod.DELETE)
120
+    public ResponseBean taUserRoleDelete(@PathVariable Integer id){
121
+        ResponseBean responseBean = new ResponseBean();
122
+        try {
123
+            if(iTaUserRoleService.removeById(id)){
124
+                responseBean.addSuccess("success");
125
+            }else {
126
+                responseBean.addError("fail");
127
+            }
128
+        }catch (Exception e){
129
+            e.printStackTrace();
130
+            logger.error("taUserRoleDelete -=- {}",e.toString());
131
+            responseBean.addError(e.getMessage());
132
+        }
133
+        return responseBean;
134
+    }
135
+
136
+    /**
137
+     * 修改对象
138
+     * @param id  实体ID
139
+     * @param taUserRole 实体对象
140
+     * @return
141
+     */
142
+    @RequestMapping(value="/center/taUserRole/{id}",method= RequestMethod.PUT)
143
+    public ResponseBean taUserRoleUpdate(@PathVariable Integer id,
144
+                                        @RequestBody TaUserRole taUserRole){
145
+        ResponseBean responseBean = new ResponseBean();
146
+        try {
147
+            taUserRole.setRoleId(id);
148
+            if (iTaUserRoleService.updateById(taUserRole)){
149
+                responseBean.addSuccess(taUserRole);
150
+            }else {
151
+                responseBean.addError("fail");
152
+            }
153
+        }catch (Exception e){
154
+            e.printStackTrace();
155
+            logger.error("taUserRoleUpdate -=- {}",e.toString());
156
+            responseBean.addError(e.getMessage());
157
+        }
158
+        return responseBean;
159
+    }
160
+
161
+    /**
162
+     * 根据id查询对象
163
+     * @param id  实体ID
164
+     */
165
+    @RequestMapping(value="/taUserRole/{id}",method= RequestMethod.GET)
166
+    public ResponseBean taUserRoleGet(@PathVariable Integer id){
167
+        ResponseBean responseBean = new ResponseBean();
168
+        try {
169
+            responseBean.addSuccess(iTaUserRoleService.getById(id));
170
+        }catch (Exception e){
171
+            e.printStackTrace();
172
+            logger.error("taUserRoleDelete -=- {}",e.toString());
173
+            responseBean.addError(e.getMessage());
174
+        }
175
+        return responseBean;
176
+    }
177
+}

+ 40
- 0
src/main/java/com/yunzhi/marketing/center/taUser/entity/TaButtonUriMap.java Просмотреть файл

@@ -0,0 +1,40 @@
1
+package com.yunzhi.marketing.center.taUser.entity;
2
+
3
+import lombok.Data;
4
+import lombok.EqualsAndHashCode;
5
+import lombok.experimental.Accessors;
6
+
7
+import java.io.Serializable;
8
+
9
+/**
10
+ * <p>
11
+ * 按钮路由映射表 
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2019-09-26
16
+ */
17
+@Data
18
+@EqualsAndHashCode(callSuper = false)
19
+@Accessors(chain = true)
20
+public class TaButtonUriMap implements Serializable {
21
+
22
+    private static final long serialVersionUID = 1L;
23
+
24
+    /**
25
+     * 按钮
26
+     */
27
+    private String buttonCode;
28
+
29
+    /**
30
+     * uri
31
+     */
32
+    private String uri;
33
+
34
+    /**
35
+     * 说明
36
+     */
37
+    private String remark;
38
+
39
+
40
+}

+ 35
- 0
src/main/java/com/yunzhi/marketing/center/taUser/entity/TaTagUser.java Просмотреть файл

@@ -0,0 +1,35 @@
1
+package com.yunzhi.marketing.center.taUser.entity;
2
+
3
+import lombok.Data;
4
+import lombok.EqualsAndHashCode;
5
+import lombok.experimental.Accessors;
6
+
7
+import java.io.Serializable;
8
+
9
+/**
10
+ * <p>
11
+ *  
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2019-09-24
16
+ */
17
+@Data
18
+@EqualsAndHashCode(callSuper = false)
19
+@Accessors(chain = true)
20
+public class TaTagUser implements Serializable {
21
+
22
+    private static final long serialVersionUID = 1L;
23
+
24
+    /**
25
+     * 人员id
26
+     */
27
+    private Integer userId;
28
+
29
+    /**
30
+     * 标签id
31
+     */
32
+    private Integer tagId;
33
+
34
+
35
+}

+ 53
- 0
src/main/java/com/yunzhi/marketing/center/taUser/entity/TaTags.java Просмотреть файл

@@ -0,0 +1,53 @@
1
+package com.yunzhi.marketing.center.taUser.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+import lombok.experimental.Accessors;
8
+
9
+import java.io.Serializable;
10
+
11
+/**
12
+ * <p>
13
+ *  
14
+ * </p>
15
+ *
16
+ * @author jobob
17
+ * @since 2019-09-24
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+public class TaTags implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    /**
27
+     * 标签id
28
+     */
29
+    @TableId(value = "tag_id", type = IdType.AUTO)
30
+    private Integer tagId;
31
+
32
+    /**
33
+     * 标签名称
34
+     */
35
+    private String tagName;
36
+
37
+    /**
38
+     * 标签颜色
39
+     */
40
+    private String tagColor;
41
+
42
+    /**
43
+     * 标签图表
44
+     */
45
+    private String tagIcon;
46
+
47
+    /**
48
+     * 公司id
49
+     */
50
+    private Integer orgId;
51
+
52
+
53
+}

+ 270
- 0
src/main/java/com/yunzhi/marketing/center/taUser/entity/TaUser.java Просмотреть файл

@@ -0,0 +1,270 @@
1
+package com.yunzhi.marketing.center.taUser.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
4
+import com.baomidou.mybatisplus.annotation.IdType;
5
+import com.baomidou.mybatisplus.annotation.TableField;
6
+import com.baomidou.mybatisplus.annotation.TableId;
7
+import com.yunzhi.marketing.entity.*;
8
+import lombok.Data;
9
+import lombok.EqualsAndHashCode;
10
+import lombok.experimental.Accessors;
11
+
12
+import java.io.Serializable;
13
+import java.time.LocalDateTime;
14
+import java.util.ArrayList;
15
+import java.util.List;
16
+
17
+/**
18
+ * <p>
19
+ * 用户表 
20
+ * </p>
21
+ *
22
+ * @author jobob
23
+ * @since 2019-09-11
24
+ */
25
+@Data
26
+@EqualsAndHashCode(callSuper = false)
27
+@Accessors(chain = true)
28
+public class TaUser implements Serializable {
29
+
30
+    private static final long serialVersionUID = 1L;
31
+
32
+    /**
33
+     * 用户ID
34
+     */
35
+    @TableId(value = "user_id", type = IdType.AUTO)
36
+    private Integer userId;
37
+
38
+    /**
39
+     * 公司id
40
+     */
41
+    private Integer orgId;
42
+
43
+    /**
44
+     * 用户名称
45
+     */
46
+    private String userName;
47
+
48
+    /**
49
+     * 登录账户
50
+     */
51
+    private String loginName;
52
+
53
+    /**
54
+     * 手机号
55
+     */
56
+    private String phone;
57
+
58
+    /**
59
+     * 登录密码
60
+     */
61
+    private String loginPassword;
62
+
63
+    /**
64
+     * 用户头像
65
+     */
66
+    private String avatar;
67
+
68
+    /**
69
+     * 用户状态
70
+     */
71
+    private Integer status;
72
+
73
+    /**
74
+     * 创建时间
75
+     */
76
+    private LocalDateTime createDate;
77
+
78
+    /**
79
+     * 账户过期时间
80
+     */
81
+    private LocalDateTime expDate;
82
+
83
+    /**
84
+     * 是否管理员
85
+     */
86
+    private Boolean isAdmin;
87
+
88
+    /**
89
+     * 公司名称
90
+     */
91
+    private String orgName;
92
+
93
+    /**
94
+     * 部门
95
+     */
96
+    private String department;
97
+
98
+    /**
99
+     * 职位
100
+     */
101
+    private String position;
102
+
103
+    /**
104
+     * 邮箱
105
+     */
106
+    private String email;
107
+
108
+    /**
109
+     * 身份证号
110
+     */
111
+    private String idNo;
112
+    
113
+    private String address;
114
+    private String photo;
115
+    private String description;
116
+
117
+    /**
118
+     * 权重
119
+     */
120
+    @TableField(strategy= FieldStrategy.IGNORED)
121
+    private String weight;
122
+
123
+    /**
124
+     * 是否置业顾问
125
+     */
126
+    private Boolean isConsultant;
127
+
128
+    /**
129
+     * 公司水印
130
+     */
131
+    @TableField(exist = false)
132
+    private String waterMark;
133
+
134
+    /**
135
+     * 关联小程序
136
+     */
137
+    @TableField(exist = false)
138
+    private TaMiniapp miniapp;
139
+
140
+    /**
141
+     * 授权角色列表
142
+     */
143
+    @TableField(exist = false)
144
+    private List<TaRole> roles;
145
+
146
+    /**
147
+     * 授权菜单列表
148
+     */
149
+    @TableField(exist = false)
150
+    private List<SysMenu> menus;
151
+
152
+    /**
153
+     * 授权按钮列表
154
+     */
155
+    @TableField(exist = false)
156
+    private List<SysButtonInMenu> buttons;
157
+    
158
+    @TableField(exist = false)
159
+    private List<TaTags> taTagsList = new ArrayList<TaTags>();
160
+    
161
+    @TableField(exist = false)
162
+    private List<Integer> taTags = new ArrayList<Integer>();
163
+    
164
+    @TableField(exist = false)
165
+    private List<Integer> roleIds = new ArrayList<Integer>();
166
+    
167
+    @TableField(exist = false)
168
+    private String buildingId;
169
+
170
+    @TableField(exist = false)
171
+    private List<String> projects;
172
+
173
+    /**
174
+     * ta_org/orgNum楼盘最大数
175
+     */
176
+  @TableField(exist = false)
177
+    private int orgNum;
178
+
179
+    // 所有省份城市
180
+    @TableField(exist = false)
181
+    List<TdCity> tdCityList;
182
+
183
+    /**
184
+     * 前台传值城市
185
+     */
186
+    @TableField(exist = false)
187
+    private ArrayList<String> selectCityTree;
188
+
189
+    /**
190
+     * 城市ID
191
+     */
192
+    @TableField(exist = false)
193
+    private Integer cityId;
194
+
195
+    /**
196
+     * 默认城市
197
+     */
198
+    @TableField(exist = false)
199
+    private Integer defaultCityId;
200
+
201
+    /**
202
+     * 小程序绑定状态
203
+     *
204
+     * 0 未绑定 1 绑定
205
+     */
206
+    @TableField(exist = false)
207
+    private Integer miniStatus;
208
+
209
+    @TableField(exist = false)
210
+    private List<String> buildingIds = new ArrayList<String>();
211
+
212
+    /**
213
+     * 新密码
214
+     */
215
+    @TableField(exist = false)
216
+    private String newPassword;
217
+
218
+    /**
219
+     * 确认新密码
220
+     */
221
+    @TableField(exist = false)
222
+    private String confirmPassword;
223
+
224
+    /**
225
+     * 置业顾问的personid
226
+     */
227
+    @TableField(exist = false)
228
+    private String consultantPersonId;
229
+
230
+    /**
231
+     * personId集合
232
+     */
233
+    @TableField(exist = false)
234
+    private List<TaPerson> personIds;
235
+
236
+    /**
237
+     * customerId集合
238
+     */
239
+    @TableField(exist = false)
240
+    private List<TaRecommendCustomer> customerIds;
241
+
242
+    @TableField(exist = false)
243
+    private String miniAppName;
244
+
245
+    private Boolean notShow;
246
+
247
+    /**
248
+     * 公司封面
249
+     */
250
+    @TableField(exist = false)
251
+    private String orgThumb;
252
+
253
+    /**
254
+     * 公司描述
255
+     */
256
+    @TableField(exist = false)
257
+    private String orgDesc;
258
+
259
+    /**
260
+     * 公司Logo
261
+     */
262
+    @TableField(exist = false)
263
+    private String orgLogo;
264
+
265
+    /**
266
+     * BOSS 开屏图
267
+     */
268
+    @TableField(exist = false)
269
+    private String bossDisplay;
270
+}

+ 51
- 0
src/main/java/com/yunzhi/marketing/center/taUser/entity/TaUserRole.java Просмотреть файл

@@ -0,0 +1,51 @@
1
+package com.yunzhi.marketing.center.taUser.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableField;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import lombok.Data;
7
+import lombok.EqualsAndHashCode;
8
+import lombok.experimental.Accessors;
9
+
10
+import java.io.Serializable;
11
+import java.util.ArrayList;
12
+import java.util.List;
13
+
14
+/**
15
+ * <p>
16
+ * 用户角色表 
17
+ * </p>
18
+ *
19
+ * @author jobob
20
+ * @since 2019-09-11
21
+ */
22
+@Data
23
+@EqualsAndHashCode(callSuper = false)
24
+@Accessors(chain = true)
25
+public class TaUserRole implements Serializable {
26
+
27
+    private static final long serialVersionUID = 1L;
28
+
29
+    /**
30
+     * 序号
31
+     */
32
+    @TableId(value = "serial_no", type = IdType.AUTO)
33
+    private Integer serialNo;
34
+
35
+    /**
36
+     * 用户ID
37
+     */
38
+    private Integer userId;
39
+
40
+    /**
41
+     * 角色ID
42
+     */
43
+    private Integer roleId;
44
+    
45
+    /**
46
+     * 角色ID集合
47
+     */
48
+    @TableField(exist = false)
49
+    private List<Integer> roleIdList = new ArrayList<>();
50
+
51
+}

+ 20
- 0
src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaButtonUriMapMapper.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+package com.yunzhi.marketing.center.taUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.center.taUser.entity.TaButtonUriMap;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+/**
9
+ * <p>
10
+ * 按钮路由映射表  Mapper 接口
11
+ * </p>
12
+ *
13
+ * @author jobob
14
+ * @since 2019-09-26
15
+ */
16
+@Mapper
17
+public interface TaButtonUriMapMapper extends BaseMapper<TaButtonUriMap> {
18
+	
19
+	TaButtonUriMap getByURI(@Param("uri") String uri);
20
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaTagUserMapper.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.center.taUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.center.taUser.entity.TaTagUser;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ *   Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author jobob
13
+ * @since 2019-09-24
14
+ */
15
+@Mapper
16
+public interface TaTagUserMapper extends BaseMapper<TaTagUser> {
17
+
18
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaTagsMapper.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.center.taUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ *   Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author jobob
13
+ * @since 2019-09-24
14
+ */
15
+@Mapper
16
+public interface TaTagsMapper extends BaseMapper<TaTags> {
17
+
18
+}

+ 36
- 0
src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserAuthButtonMapper.java Просмотреть файл

@@ -0,0 +1,36 @@
1
+package com.yunzhi.marketing.center.taUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.entity.SysButtonInMenu;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
9
+
10
+/**
11
+ * @author admin
12
+ * @Title: TaUserAuthButtonMapper
13
+ * @Description: TODO
14
+ * @date 2019/9/23
15
+ */
16
+@Mapper
17
+public interface TaUserAuthButtonMapper  extends BaseMapper<SysButtonInMenu> {
18
+    /**
19
+     * 根据用户Id查询按钮列表
20
+     * @param userId
21
+     * @return
22
+     */
23
+    List<SysButtonInMenu> sysButtonListByUserId(@Param("userId")String userId);
24
+
25
+
26
+    /**
27
+     * 根据角色Id查询按钮列表
28
+     * @param page
29
+     * @return
30
+     */
31
+    List<SysButtonInMenu> sysButtonListByRoleId();
32
+
33
+    void deleteUserAuthButton(@Param("userId") Integer userId);
34
+
35
+    void addUserAuthButton(@Param("userId") Integer userId, @Param("sysButtons") List<SysButtonInMenu> sysButtonInMenus);
36
+}

+ 44
- 0
src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserAuthMenuMapper.java Просмотреть файл

@@ -0,0 +1,44 @@
1
+package com.yunzhi.marketing.center.taUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.entity.SysMenu;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+import java.util.List;
9
+
10
+
11
+/**
12
+ * @author weicc
13
+ * @Title: TaUserAuthMenuMapper
14
+ * @Description: TODO
15
+ * @date 2019/9/21
16
+ */
17
+@Mapper
18
+public interface TaUserAuthMenuMapper extends BaseMapper<SysMenu> {
19
+    /**
20
+     * 根据用户Id查询菜单列表
21
+     * @param userId
22
+     * @return
23
+     */
24
+    List<SysMenu> sysMenuListByUserId(@Param("userId")String userId);
25
+
26
+
27
+    /**
28
+     * 查询菜单列表
29
+     * @return
30
+     */
31
+    List<SysMenu> sysMenuListByRoleId();
32
+
33
+    /**
34
+     * 删除授权的菜单
35
+     * @param userId
36
+     */
37
+    void deleteUserAuthMenu(@Param("userId") Integer userId);
38
+
39
+    /**
40
+     * 新增授权的菜单
41
+     * @param userId
42
+     */
43
+    void addUserAuthMenu(@Param("userId") Integer userId, @Param("sysMenus") List<SysMenu> sysMenuList);
44
+}

+ 40
- 0
src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserMapper.java Просмотреть файл

@@ -0,0 +1,40 @@
1
+package com.yunzhi.marketing.center.taUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
6
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
7
+import com.yunzhi.marketing.entity.TaPersonBuilding;
8
+import org.apache.ibatis.annotations.Mapper;
9
+import org.apache.ibatis.annotations.Param;
10
+
11
+import java.util.List;
12
+import java.util.Map;
13
+
14
+/**
15
+ * <p>
16
+ * 用户表  Mapper 接口
17
+ * </p>
18
+ *
19
+ * @author jobob
20
+ * @since 2019-09-11
21
+ */
22
+@Mapper
23
+public interface TaUserMapper extends BaseMapper<TaUser> {
24
+	
25
+	List<Map<String,Object>> getPageList(IPage<TaUser> pg, @Param("channelId") Integer channelId, @Param("miniAppName") String miniAppName);
26
+	
27
+	List<TaTags> getTagsList(@Param("userId") Integer userId,@Param("orgId") Integer orgId);
28
+	
29
+	List<TaUser> getUserList(@Param("phone") String phone,@Param("orgId") Integer orgId);
30
+
31
+    IPage<TaUser> seleUserList(IPage pg,@Param("taUser") TaUser taUser,@Param("personBuildingList") List<TaPersonBuilding> personBuildingList);
32
+
33
+    Integer validateWeight(@Param("buildingIds") List<String> buildingIds, @Param("buildingId") String buildingId, @Param("weight") String weight, @Param("userId")Integer userId);
34
+
35
+    TaUser getAdminByAppID(@Param("appid") String appID);
36
+
37
+    List<String> getBuildingIdsOf(@Param("userId") Integer userId,@Param("buildingId") String buildingId);
38
+
39
+    TaUser getUserByPerson(@Param("orgId") Integer orgId, @Param("personId") String personId);
40
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/center/taUser/mapper/TaUserRoleMapper.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.center.taUser.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.yunzhi.marketing.center.taUser.entity.TaUserRole;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 用户角色表  Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author jobob
13
+ * @since 2019-09-11
14
+ */
15
+@Mapper
16
+public interface TaUserRoleMapper extends BaseMapper<TaUserRole> {
17
+
18
+}

+ 17
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/ITaButtonUriMapService.java Просмотреть файл

@@ -0,0 +1,17 @@
1
+package com.yunzhi.marketing.center.taUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.center.taUser.entity.TaButtonUriMap;
5
+
6
+/**
7
+ * <p>
8
+ * 按钮路由映射表  服务类
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2019-09-26
13
+ */
14
+public interface ITaButtonUriMapService extends IService<TaButtonUriMap> {
15
+	
16
+	TaButtonUriMap getByURI(String uri);
17
+}

+ 16
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/ITaTagUserService.java Просмотреть файл

@@ -0,0 +1,16 @@
1
+package com.yunzhi.marketing.center.taUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.center.taUser.entity.TaTagUser;
5
+
6
+/**
7
+ * <p>
8
+ *   服务类
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2019-09-24
13
+ */
14
+public interface ITaTagUserService extends IService<TaTagUser> {
15
+
16
+}

+ 16
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/ITaTagsService.java Просмотреть файл

@@ -0,0 +1,16 @@
1
+package com.yunzhi.marketing.center.taUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
5
+
6
+/**
7
+ * <p>
8
+ *   服务类
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2019-09-24
13
+ */
14
+public interface ITaTagsService extends IService<TaTags> {
15
+
16
+}

+ 22
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserAuthButtonService.java Просмотреть файл

@@ -0,0 +1,22 @@
1
+package com.yunzhi.marketing.center.taUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.base.ResponseBean;
5
+import com.yunzhi.marketing.entity.SysButtonInMenu;
6
+
7
+import java.util.List;
8
+
9
+/**
10
+ * @author admin
11
+ * @Title: ITaUserAuthButtonService
12
+ * @Description: TODO
13
+ * @date 2019/9/23
14
+ */
15
+public interface ITaUserAuthButtonService extends IService<SysButtonInMenu> {
16
+
17
+    ResponseBean getButtonByUserId(Integer pageNum, Integer pageSize, String userId, Integer orgId);
18
+
19
+    ResponseBean getAllButton(Integer pageNum, Integer pageSize);
20
+
21
+    ResponseBean updateUserAuthButton(Integer userId, List<SysButtonInMenu> sysButtonInMenus);
22
+}

+ 24
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserAuthMenuService.java Просмотреть файл

@@ -0,0 +1,24 @@
1
+package com.yunzhi.marketing.center.taUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.base.ResponseBean;
5
+import com.yunzhi.marketing.entity.SysButtonInMenu;
6
+import com.yunzhi.marketing.entity.SysMenu;
7
+import com.yunzhi.marketing.entity.TaRole;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * @author admin
13
+ * @Title: ITaUserAuthMenuService
14
+ * @Description: TODO
15
+ * @date 2019/9/21
16
+ */
17
+public interface ITaUserAuthMenuService extends IService<SysMenu> {
18
+
19
+    ResponseBean getMenuByUserId(Integer pageNum, Integer pageSize, String userId, Integer orgId);
20
+
21
+    ResponseBean getAllMenu(Integer pageNum, Integer pageSize, Integer orgId, List<TaRole> roles);
22
+
23
+    ResponseBean updateUserAuthMenu(Integer userId, List<SysMenu> sysMenuList,String name,Integer orgid,List<SysButtonInMenu> sysButtonInMenuList);
24
+}

+ 16
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserRoleService.java Просмотреть файл

@@ -0,0 +1,16 @@
1
+package com.yunzhi.marketing.center.taUser.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.yunzhi.marketing.center.taUser.entity.TaUserRole;
5
+
6
+/**
7
+ * <p>
8
+ * 用户角色表  服务类
9
+ * </p>
10
+ *
11
+ * @author jobob
12
+ * @since 2019-09-11
13
+ */
14
+public interface ITaUserRoleService extends IService<TaUserRole> {
15
+
16
+}

+ 78
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/ITaUserService.java Просмотреть файл

@@ -0,0 +1,78 @@
1
+package com.yunzhi.marketing.center.taUser.service;
2
+
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.yunzhi.marketing.base.ResponseBean;
6
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
7
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
8
+import com.yunzhi.marketing.entity.TaPersonBuilding;
9
+
10
+import java.util.List;
11
+import java.util.Map;
12
+
13
+/**
14
+ * <p>
15
+ * 用户表  服务类
16
+ * </p>
17
+ *
18
+ * @author jobob
19
+ * @since 2019-09-11
20
+ */
21
+public interface ITaUserService extends IService<TaUser> {
22
+
23
+    IPage<Map<String, Object>> getPageList(IPage<TaUser> pg, Integer channelId, String miniAppName);
24
+
25
+    TaUser newUserAndOrg(TaUser taUser, Integer channelId) throws Exception;
26
+
27
+    TaUser getInfoWithOrg(Integer id);
28
+
29
+    void updateInfoWithOrg(TaUser taUser) throws Exception;
30
+
31
+    void turnUserOnOrNot(Integer id, boolean isOn, String plat) throws Exception;
32
+
33
+    void resetPassword(Integer id, String newPass) throws Exception;
34
+
35
+    List<TaTags> getTagsList(TaUser e);
36
+
37
+    TaUser addAdminUser(TaUser taUser) throws Exception;
38
+
39
+    TaUser updateAdminUser(TaUser taUser) throws Exception;
40
+
41
+    TaUser getAdminByAppID(String appid);
42
+
43
+    /**
44
+     * 查询所有城市
45
+     *
46
+     * @return
47
+     */
48
+    ResponseBean cityTree();
49
+
50
+    /**
51
+     * 员工离职
52
+     *
53
+     * @param userId
54
+     * @param customerIdList
55
+     * @param consultantUserId 置业顾问的userId
56
+     * @return
57
+     */
58
+    ResponseBean departureUser(Integer userId, List<String> customerIdList, Integer consultantUserId);
59
+
60
+    /**
61
+     * 分页查询用户列表
62
+     *
63
+     * @param pg
64
+     * @param taUser
65
+     * @param taPersonBuildingListByUserId
66
+     * @return
67
+     */
68
+    IPage<TaUser> seleUserList(IPage pg, TaUser taUser, List<TaPersonBuilding> taPersonBuildingListByUserId);
69
+
70
+    /**
71
+     * 获取用户信息
72
+     *
73
+     * @param userId
74
+     * @param orgId
75
+     * @return
76
+     */
77
+    TaUser getUserInfoById(Integer userId, Integer orgId);
78
+}

+ 28
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaButtonUriMapServiceImpl.java Просмотреть файл

@@ -0,0 +1,28 @@
1
+package com.yunzhi.marketing.center.taUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.yunzhi.marketing.center.taUser.entity.TaButtonUriMap;
5
+import com.yunzhi.marketing.center.taUser.mapper.TaButtonUriMapMapper;
6
+import com.yunzhi.marketing.center.taUser.service.ITaButtonUriMapService;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.stereotype.Service;
9
+
10
+/**
11
+ * <p>
12
+ * 按钮路由映射表  服务实现类
13
+ * </p>
14
+ *
15
+ * @author jobob
16
+ * @since 2019-09-26
17
+ */
18
+@Service
19
+public class TaButtonUriMapServiceImpl extends ServiceImpl<TaButtonUriMapMapper, TaButtonUriMap> implements ITaButtonUriMapService {
20
+	
21
+	@Autowired
22
+	private TaButtonUriMapMapper taButtonUriMapMapper;
23
+	
24
+	@Override
25
+	public TaButtonUriMap getByURI(String uri) {
26
+		return taButtonUriMapMapper.getByURI(uri);
27
+	}
28
+}

+ 20
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaTagUserServiceImpl.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+package com.yunzhi.marketing.center.taUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.yunzhi.marketing.center.taUser.entity.TaTagUser;
5
+import com.yunzhi.marketing.center.taUser.mapper.TaTagUserMapper;
6
+import com.yunzhi.marketing.center.taUser.service.ITaTagUserService;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ *   服务实现类
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2019-09-24
16
+ */
17
+@Service
18
+public class TaTagUserServiceImpl extends ServiceImpl<TaTagUserMapper, TaTagUser> implements ITaTagUserService {
19
+
20
+}

+ 20
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaTagsServiceImpl.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+package com.yunzhi.marketing.center.taUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
5
+import com.yunzhi.marketing.center.taUser.mapper.TaTagsMapper;
6
+import com.yunzhi.marketing.center.taUser.service.ITaTagsService;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ *   服务实现类
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2019-09-24
16
+ */
17
+@Service
18
+public class TaTagsServiceImpl extends ServiceImpl<TaTagsMapper, TaTags> implements ITaTagsService {
19
+
20
+}

+ 108
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserAuthButtonServiceImpl.java Просмотреть файл

@@ -0,0 +1,108 @@
1
+package com.yunzhi.marketing.center.taUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.yunzhi.marketing.base.ResponseBean;
6
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
7
+import com.yunzhi.marketing.center.taUser.mapper.TaUserAuthButtonMapper;
8
+import com.yunzhi.marketing.center.taUser.mapper.TaUserMapper;
9
+import com.yunzhi.marketing.center.taUser.service.ITaUserAuthButtonService;
10
+import com.yunzhi.marketing.common.CommConstant;
11
+import com.yunzhi.marketing.entity.SysAdvancedConfigRelation;
12
+import com.yunzhi.marketing.entity.SysButtonInMenu;
13
+import com.yunzhi.marketing.entity.TaAdvancedController;
14
+import com.yunzhi.marketing.entity.TaRole;
15
+import com.yunzhi.marketing.mapper.SysAdvancedConfigRelationMapper;
16
+import com.yunzhi.marketing.mapper.TaAdvancedControllerMapper;
17
+import com.yunzhi.marketing.mapper.TaRoleButtonMapper;
18
+import com.yunzhi.marketing.mapper.TaRoleMapper;
19
+import org.springframework.beans.factory.annotation.Autowired;
20
+import org.springframework.stereotype.Service;
21
+
22
+import java.util.ArrayList;
23
+import java.util.List;
24
+import java.util.stream.Collectors;
25
+
26
+/**
27
+ * @author admin
28
+ * @Title: TaUserAuthButtonServiceImpl
29
+ * @Description: TODO
30
+ * @date 2019/9/23
31
+ */
32
+@Service
33
+public class TaUserAuthButtonServiceImpl extends ServiceImpl<TaUserAuthButtonMapper, SysButtonInMenu> implements ITaUserAuthButtonService {
34
+
35
+    @Autowired
36
+    TaUserAuthButtonMapper taUserAuthButtonMapper;
37
+    @Autowired
38
+    TaRoleButtonMapper taRoleButtonMapper;
39
+    @Autowired
40
+    private TaUserMapper taUserMapper;
41
+    @Autowired
42
+    private TaRoleMapper taRoleMapper;
43
+    @Autowired
44
+    private TaAdvancedControllerMapper taAdvancedControllerMapper;
45
+    @Autowired
46
+    private SysAdvancedConfigRelationMapper sysAdvancedConfigRelationMapper;
47
+
48
+    @Override
49
+    public ResponseBean getButtonByUserId(Integer pageNum, Integer pageSize, String userId, Integer orgId) {
50
+        List<SysButtonInMenu> records = new ArrayList<>();
51
+        List<SysButtonInMenu> menuList = taUserAuthButtonMapper.sysButtonListByUserId(userId);
52
+        records.addAll(menuList);
53
+        //添加高级配置的过滤条件
54
+        List<TaAdvancedController> taAdvancedControllerList = taAdvancedControllerMapper.selectList(new QueryWrapper<TaAdvancedController>().eq("org_id", orgId));
55
+
56
+        //需要过滤的菜单
57
+        QueryWrapper<SysAdvancedConfigRelation> sysAdvancedConfigRelationQueryWrapper = new QueryWrapper<>();
58
+        sysAdvancedConfigRelationQueryWrapper.eq("target_type", CommConstant.ADVANCED_TYPE_BUTTON);
59
+        sysAdvancedConfigRelationQueryWrapper.notIn(taAdvancedControllerList.size() > 0,"advanced_config_id",taAdvancedControllerList.stream().map(TaAdvancedController::getAdvancedConfigId).collect(Collectors.toList()));
60
+        List<SysAdvancedConfigRelation> sysAdvancedConfigRelations = sysAdvancedConfigRelationMapper.selectList(sysAdvancedConfigRelationQueryWrapper);
61
+        menuList.forEach(e -> {
62
+            sysAdvancedConfigRelations.forEach(s -> {
63
+                if ((e.getBtnId()).equals(Integer.valueOf(s.getTargetId()))){
64
+                    records.remove(e);
65
+                }
66
+            });
67
+        });
68
+        return ResponseBean.success(records);
69
+
70
+    }
71
+
72
+    @Override
73
+    public ResponseBean getAllButton(Integer pageNum, Integer pageSize) {
74
+        List<SysButtonInMenu> records = taUserAuthButtonMapper.sysButtonListByRoleId();
75
+        records.forEach(e -> {
76
+            List<TaRole> taRoles = taRoleMapper.getRolesByBtnId(e.getBtnId());
77
+            e.setRolesList(taRoles);
78
+        });
79
+
80
+        return ResponseBean.success(records);
81
+    }
82
+
83
+    @Override
84
+    public ResponseBean updateUserAuthButton(Integer userId, List<SysButtonInMenu> sysButtonInMenus) {
85
+        ResponseBean responseBean = new ResponseBean();
86
+
87
+        // 人员
88
+        TaUser taUser = taUserMapper.selectById(userId);
89
+        if (null == taUser) {
90
+            responseBean.addError("授权人不存在");
91
+            return responseBean;
92
+        }
93
+
94
+
95
+        try{
96
+            //授权菜单按钮,先删除在新增
97
+            taUserAuthButtonMapper.deleteUserAuthButton(userId);
98
+            taUserAuthButtonMapper.addUserAuthButton(userId, sysButtonInMenus);
99
+            responseBean.addSuccess("操作成功");
100
+            return  responseBean;
101
+        }catch (Exception e){
102
+            responseBean.addSuccess("操作失败");
103
+            e.printStackTrace();
104
+            return responseBean;
105
+        }
106
+
107
+    }
108
+}

+ 197
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserAuthMenuServiceImpl.java Просмотреть файл

@@ -0,0 +1,197 @@
1
+package com.yunzhi.marketing.center.taUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.yunzhi.marketing.base.ResponseBean;
6
+import com.yunzhi.marketing.center.taUser.mapper.TaUserAuthMenuMapper;
7
+import com.yunzhi.marketing.center.taUser.mapper.TaUserMapper;
8
+import com.yunzhi.marketing.center.taUser.service.ITaUserAuthMenuService;
9
+import com.yunzhi.marketing.common.CommConstant;
10
+import com.yunzhi.marketing.entity.*;
11
+import com.yunzhi.marketing.mapper.*;
12
+import org.apache.commons.collections.CollectionUtils;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.stereotype.Service;
15
+
16
+import java.time.LocalDateTime;
17
+import java.util.ArrayList;
18
+import java.util.List;
19
+import java.util.stream.Collectors;
20
+
21
+/**
22
+ * @author weicc
23
+ * @Title: TaUserAuthMenuServiceImpl
24
+ * @Description: TODO
25
+ * @date 2019/9/21
26
+ */
27
+@Service
28
+public class TaUserAuthMenuServiceImpl extends ServiceImpl<TaUserAuthMenuMapper, SysMenu> implements ITaUserAuthMenuService {
29
+
30
+
31
+    @Autowired
32
+    private TaUserAuthMenuMapper taUserAuthMenuMapper;
33
+    @Autowired
34
+    private TaRoleMenuMapper taRoleMenuMapper;
35
+    @Autowired
36
+    private TaUserMapper taUserMapper;
37
+
38
+    @Autowired
39
+    private TaRoleMapper taRoleMapper;
40
+
41
+    @Autowired
42
+    private TaRoleButtonMapper taRoleButtonMapper;
43
+
44
+    @Autowired
45
+    private TaAdvancedControllerMapper taAdvancedControllerMapper;
46
+
47
+    @Autowired
48
+    private SysAdvancedConfigRelationMapper sysAdvancedConfigRelationMapper;
49
+
50
+    /**
51
+     * 根据用户id获取授权菜单
52
+     * @param pageNum
53
+     * @param pageSize
54
+     * @param userId
55
+     * @param orgId
56
+     * @return
57
+     */
58
+    @Override
59
+    public ResponseBean getMenuByUserId(Integer pageNum, Integer pageSize, String userId, Integer orgId) {
60
+        List<SysMenu> records = new ArrayList<>();
61
+        List<SysMenu> menuList = taUserAuthMenuMapper.sysMenuListByUserId(userId);
62
+        records.addAll(menuList);
63
+        //添加高级配置的过滤条件
64
+        List<TaAdvancedController> taAdvancedControllerList = taAdvancedControllerMapper.selectList(new QueryWrapper<TaAdvancedController>().eq("org_id", orgId));
65
+
66
+        //需要过滤的菜单
67
+        QueryWrapper<SysAdvancedConfigRelation> sysAdvancedConfigRelationQueryWrapper = new QueryWrapper<>();
68
+        sysAdvancedConfigRelationQueryWrapper.eq("target_type", CommConstant.ADVANCED_TYPE_MENU);
69
+        sysAdvancedConfigRelationQueryWrapper.notIn(taAdvancedControllerList.size() > 0,"advanced_config_id",taAdvancedControllerList.stream().map(TaAdvancedController::getAdvancedConfigId).collect(Collectors.toList()));
70
+        List<SysAdvancedConfigRelation> sysAdvancedConfigRelations = sysAdvancedConfigRelationMapper.selectList(sysAdvancedConfigRelationQueryWrapper);
71
+        menuList.forEach(e -> {
72
+            sysAdvancedConfigRelations.forEach(s -> {
73
+                if (e.getMenuId() == Integer.valueOf(s.getTargetId())){
74
+                    records.remove(e);
75
+                }
76
+            });
77
+        });
78
+        return ResponseBean.success(records);
79
+    }
80
+
81
+    @Override
82
+    public ResponseBean getAllMenu(Integer pageNum, Integer pageSize, Integer orgId, List<TaRole> userRoles) {
83
+        List<SysMenu> records = new ArrayList<>();
84
+        List<SysMenu> menuList = taUserAuthMenuMapper.sysMenuListByRoleId();
85
+        records.addAll(menuList);
86
+        //添加高级配置的过滤条件
87
+        List<TaAdvancedController> taAdvancedControllerList = taAdvancedControllerMapper.selectList(new QueryWrapper<TaAdvancedController>().eq("org_id", orgId));
88
+
89
+        //需要过滤的菜单
90
+        QueryWrapper<SysAdvancedConfigRelation> sysAdvancedConfigRelationQueryWrapper = new QueryWrapper<>();
91
+        sysAdvancedConfigRelationQueryWrapper.eq("target_type",CommConstant.ADVANCED_TYPE_MENU);
92
+        sysAdvancedConfigRelationQueryWrapper.notIn(taAdvancedControllerList.size() > 0,"advanced_config_id",taAdvancedControllerList.stream().map(TaAdvancedController::getAdvancedConfigId).collect(Collectors.toList()));
93
+        List<SysAdvancedConfigRelation> sysAdvancedConfigRelations = sysAdvancedConfigRelationMapper.selectList(sysAdvancedConfigRelationQueryWrapper);
94
+
95
+        List<TaRoleMenu> configRelationRoleMenuList = new ArrayList<>();
96
+        if (CollectionUtils.isNotEmpty(userRoles) && CollectionUtils.isNotEmpty(sysAdvancedConfigRelations)){
97
+            QueryWrapper<TaRoleMenu> taRoleMenuQueryWrapper = new QueryWrapper<>();
98
+            taRoleMenuQueryWrapper.in("role_id", userRoles.stream().map(TaRole::getRoleId).collect(Collectors.toList()));
99
+            taRoleMenuQueryWrapper.in("menu_id", sysAdvancedConfigRelations.stream().map(SysAdvancedConfigRelation::getTargetId).collect(Collectors.toList()));
100
+            configRelationRoleMenuList = taRoleMenuMapper.selectList(taRoleMenuQueryWrapper);
101
+        }
102
+
103
+        QueryWrapper<TaRoleMenu> queryWrapper = new QueryWrapper();
104
+        List<TaRoleMenu> taRoleMenus = taRoleMenuMapper.selectList(queryWrapper);
105
+
106
+        for (SysMenu sysMenu : records){
107
+            ArrayList<Integer> roles = new ArrayList<>();
108
+            for (TaRoleMenu taRoleMenu : taRoleMenus){
109
+                if (taRoleMenu.getMenuId().equals(sysMenu.getMenuId()) && !roles.contains(taRoleMenu.getRoleId())){
110
+                    roles.add(taRoleMenu.getRoleId());
111
+                }
112
+            }
113
+            for (TaRoleMenu taRoleMenu : configRelationRoleMenuList){
114
+                if (sysMenu.getMenuId().equals(taRoleMenu.getMenuId())){
115
+                    roles.remove(taRoleMenu.getRoleId());
116
+                }
117
+            }
118
+            sysMenu.setRoles(roles);
119
+        }
120
+
121
+        return ResponseBean.success(records);
122
+    }
123
+
124
+    @Override
125
+    public ResponseBean updateUserAuthMenu(Integer roleId, List<SysMenu> sysMenuList,String name,Integer orgId,List<SysButtonInMenu> sysButtonInMenuList) {
126
+        ResponseBean responseBean = new ResponseBean();
127
+        if (null == roleId){
128
+            addUserAuthMenu( sysMenuList,name,orgId,sysButtonInMenuList);
129
+            return responseBean;
130
+        }
131
+        try {
132
+            //授权菜单,先删除在新增
133
+            taRoleMenuMapper.deleteCurrentMenu(roleId);
134
+            for (SysMenu sysMenu: sysMenuList) {
135
+                TaRoleMenu taRoleMenu = new TaRoleMenu();
136
+                taRoleMenu.setRoleId(roleId);
137
+                taRoleMenu.setMenuId(sysMenu.getMenuId());
138
+                taRoleMenuMapper.insert(taRoleMenu);
139
+            }
140
+            // 更新Role
141
+            TaRole taRole = new TaRole();
142
+            taRole.setRoleId(roleId);
143
+            taRole.setRoleName(name);
144
+            taRoleMapper.updateById(taRole);
145
+
146
+            // 当前角色的所有按钮再重新插入
147
+
148
+            taRoleButtonMapper.deleteCurrentBut(roleId);
149
+            for (SysButtonInMenu sysButtonInMenu :sysButtonInMenuList) {
150
+                TaRoleButton taRoleButton = new TaRoleButton();
151
+                taRoleButton.setRoleId(taRole.getRoleId());
152
+                taRoleButton.setBtnId(sysButtonInMenu.getBtnId());
153
+                taRoleButtonMapper.insert(taRoleButton);
154
+            }
155
+                responseBean.addSuccess("操作成功");
156
+            return responseBean;
157
+        } catch (Exception e) {
158
+            responseBean.addSuccess("操作失败");
159
+            e.printStackTrace();
160
+            return responseBean;
161
+        }
162
+    }
163
+
164
+    public Boolean addUserAuthMenu(List<SysMenu> sysMenuList,String name,Integer orgId,List<SysButtonInMenu> sysButtonInMenuList) {
165
+        ResponseBean responseBean = new ResponseBean();
166
+        try{
167
+            // 新增角色
168
+            TaRole taRole = new TaRole();
169
+            taRole.setRoleName(name);
170
+            taRole.setOrgId(orgId);
171
+            taRole.setStatus(1);
172
+            taRole.setCreateDate(LocalDateTime.now());
173
+            taRoleMapper.insert(taRole);
174
+
175
+            // 新增角色需要的菜单
176
+          for (SysMenu sysMenu: sysMenuList){
177
+              TaRoleMenu taRoleMenu = new TaRoleMenu();
178
+              taRoleMenu.setRoleId(taRole.getRoleId());
179
+              taRoleMenu.setMenuId(sysMenu.getMenuId());
180
+              taRoleMenuMapper.insert(taRoleMenu);
181
+          }
182
+          // 新增角色按钮
183
+          for (SysButtonInMenu sysButtonInMenu :sysButtonInMenuList){
184
+              TaRoleButton  taRoleButton = new TaRoleButton();
185
+              taRoleButton.setRoleId(taRole.getRoleId());
186
+              taRoleButton.setBtnId(sysButtonInMenu.getBtnId());
187
+              taRoleButtonMapper.insert(taRoleButton);
188
+          }
189
+            responseBean.addSuccess("操作成功");
190
+            return  true;
191
+        }catch (Exception e){
192
+            responseBean.addSuccess("操作失败");
193
+            e.printStackTrace();
194
+            return false;
195
+        }
196
+    }
197
+}

+ 20
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserRoleServiceImpl.java Просмотреть файл

@@ -0,0 +1,20 @@
1
+package com.yunzhi.marketing.center.taUser.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.yunzhi.marketing.center.taUser.entity.TaUserRole;
5
+import com.yunzhi.marketing.center.taUser.mapper.TaUserRoleMapper;
6
+import com.yunzhi.marketing.center.taUser.service.ITaUserRoleService;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 用户角色表  服务实现类
12
+ * </p>
13
+ *
14
+ * @author jobob
15
+ * @since 2019-09-11
16
+ */
17
+@Service
18
+public class TaUserRoleServiceImpl extends ServiceImpl<TaUserRoleMapper, TaUserRole> implements ITaUserRoleService {
19
+
20
+}

+ 748
- 0
src/main/java/com/yunzhi/marketing/center/taUser/service/impl/TaUserServiceImpl.java Просмотреть файл

@@ -0,0 +1,748 @@
1
+package com.yunzhi.marketing.center.taUser.service.impl;
2
+
3
+import cn.binarywang.wx.miniapp.api.WxMaService;
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
6
+import com.baomidou.mybatisplus.core.metadata.IPage;
7
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8
+import com.yunzhi.marketing.base.ResponseBean;
9
+import com.yunzhi.marketing.center.taUser.entity.TaTagUser;
10
+import com.yunzhi.marketing.center.taUser.entity.TaTags;
11
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
12
+import com.yunzhi.marketing.center.taUser.entity.TaUserRole;
13
+import com.yunzhi.marketing.center.taUser.mapper.TaTagUserMapper;
14
+import com.yunzhi.marketing.center.taUser.mapper.TaUserMapper;
15
+import com.yunzhi.marketing.center.taUser.mapper.TaUserRoleMapper;
16
+import com.yunzhi.marketing.center.taUser.service.ITaUserService;
17
+import com.yunzhi.marketing.channel.sysChannel.entity.TaChannelProxy;
18
+import com.yunzhi.marketing.channel.sysChannel.mapper.TaChannelProxyMapper;
19
+import com.yunzhi.marketing.common.CommConstant;
20
+import com.yunzhi.marketing.common.MD5Utils;
21
+import com.yunzhi.marketing.common.StringUtils;
22
+import com.yunzhi.marketing.common.WxUtils;
23
+import com.yunzhi.marketing.entity.*;
24
+import com.yunzhi.marketing.mapper.*;
25
+import com.yunzhi.marketing.service.*;
26
+import org.apache.commons.collections.CollectionUtils;
27
+import org.springframework.beans.factory.annotation.Autowired;
28
+import org.springframework.stereotype.Service;
29
+
30
+import java.time.LocalDateTime;
31
+import java.util.ArrayList;
32
+import java.util.List;
33
+import java.util.Map;
34
+import java.util.stream.Collectors;
35
+
36
+/**
37
+ * <p>
38
+ * 用户表  服务实现类
39
+ * </p>
40
+ *
41
+ * @author jobob
42
+ * @since 2019-09-11
43
+ */
44
+@Service
45
+public class TaUserServiceImpl extends ServiceImpl<TaUserMapper, TaUser> implements ITaUserService {
46
+
47
+    @Autowired
48
+    private TaUserMapper taUserMapper;
49
+
50
+    @Autowired
51
+    private TaOrgMapper taOrgMapper;
52
+
53
+    @Autowired
54
+    private TaMiniappMapper taMiniappMapper;
55
+
56
+    @Autowired
57
+    private TaMiniappTemplateMapper taMiniappTemplateMapper;
58
+
59
+    @Autowired
60
+    private TaTagUserMapper taTagUserMapper;
61
+
62
+    @Autowired
63
+    private TaPersonBuildingMapper taPersonBuildingMapper;
64
+
65
+    @Autowired
66
+    private TaPersonMapper taPersonMapper;
67
+
68
+    @Autowired
69
+    private TaUserRoleMapper taUserRoleMapper;
70
+
71
+    @Autowired
72
+    private TdPointsRulesMapper tdPointsRulesMapper;
73
+
74
+    @Autowired
75
+    private ITdReportService iTdReportService;
76
+
77
+    @Autowired
78
+    private ITaBuildingReportService iTaBuildingReportService;
79
+
80
+    @Autowired
81
+    private TdCityMapper tdCityMapper;
82
+
83
+    @Autowired
84
+    private TaOrgCityMapper taOrgCityMapper;
85
+
86
+    @Autowired
87
+    private ITaPersonService iTaPersonService;
88
+
89
+    @Autowired
90
+    private ITaRecommendCustomerService iTaRecommendCustomerService;
91
+
92
+    @Autowired
93
+    private ISysOrgParamsService iSysOrgParamsService;
94
+
95
+    @Autowired
96
+    private TaChannelAppRelationMapper taChannelAppRelationMapper;
97
+
98
+    @Autowired
99
+    private TaChannelProxyMapper taChannelProxyMapper;
100
+
101
+    @Autowired
102
+    private WxUtils wxUtils;
103
+
104
+    @Override
105
+    public IPage<Map<String, Object>> getPageList(IPage pg, Integer channelId, String miniAppName) {
106
+        List<Map<String, Object>> taUserList = taUserMapper.getPageList(pg, channelId, miniAppName);
107
+
108
+        for (Map map : taUserList) {
109
+            if (map.get("orgId") == null) {
110
+                map.put("userCount", 0);
111
+                map.put("registeredCount", 0);
112
+                continue;
113
+            }
114
+            Integer userCount = taPersonMapper.selectChannelUserCount(map.get("orgId").toString());
115
+            Integer registeredCount = taPersonMapper.selectChannelRegisteredCount(map.get("orgId").toString());
116
+            map.put("userCount", userCount);
117
+            map.put("registeredCount", registeredCount);
118
+        }
119
+        pg.setRecords(taUserList);
120
+        return pg;
121
+    }
122
+
123
+    @Override
124
+    public TaUser newUserAndOrg(TaUser taUser, Integer channelId) throws Exception {
125
+        if (StringUtils.isEmpty(taUser.getPhone())) {
126
+            throw new Exception("电话号码不能为空");
127
+        }
128
+        if (StringUtils.isEmpty(taUser.getUserName())) {
129
+            throw new Exception("用户名称不能为空");
130
+        }
131
+
132
+        if (StringUtils.isEmpty(taUser.getLoginName())) {
133
+            taUser.setLoginName(taUser.getPhone());
134
+        }
135
+
136
+        //判断默认城市是否在维护城市内
137
+        verificationCity(taUser.getSelectCityTree(), taUser.getDefaultCityId());
138
+
139
+        QueryWrapper<TaUser> wrapper = new QueryWrapper<>();
140
+        wrapper.eq("phone", taUser.getPhone()).or().eq("login_Name", taUser.getLoginName());
141
+        List<TaUser> taUserList = this.list(wrapper);
142
+        if (null != taUserList && taUserList.size() > 0) {
143
+            throw new Exception("电话号码或登录名重复");
144
+        }
145
+
146
+        //判断渠道端新增小程序最大数
147
+        QueryWrapper<TaChannelProxy> taChannelProxyQueryWrapper = new QueryWrapper<>();
148
+        taChannelProxyQueryWrapper.eq("channel_id", channelId);
149
+        TaChannelProxy taChannelProxy = taChannelProxyMapper.selectOne(taChannelProxyQueryWrapper);
150
+
151
+        QueryWrapper<TaChannelAppRelation> relationQueryWrapper = new QueryWrapper<>();
152
+        relationQueryWrapper.eq("channel_id", channelId);
153
+        Integer miniAppCount = taChannelAppRelationMapper.selectCount(relationQueryWrapper);
154
+        if (miniAppCount >= taChannelProxy.getAppMaxNum()) {
155
+            throw new Exception("当前系统仅供维护" + taChannelProxy.getAppMaxNum() + "个小程序,需要维护更多项目,请联系相关管理人员");
156
+        }
157
+
158
+        // 先插入 org
159
+        TaOrg taOrg = new TaOrg();
160
+        taOrg.setName(taUser.getOrgName());
161
+        taOrg.setLogo(taUser.getOrgLogo());
162
+        taOrg.setWaterMark(taUser.getWaterMark());
163
+        taOrg.setCreateDate(LocalDateTime.now());
164
+        taOrg.setBuildingNum(taUser.getOrgNum());
165
+        taOrg.setDefaultCityId(taUser.getDefaultCityId());
166
+        taOrg.setThumb(taUser.getOrgThumb());
167
+        taOrg.setOrgDesc(taUser.getOrgDesc());
168
+        taOrg.setBossDisplay(taUser.getBossDisplay());
169
+        if (taOrgMapper.insert(taOrg) < 1) {
170
+            throw new Exception("生成用户公司信息失败");
171
+        }
172
+
173
+        //维护渠道和小程序关系
174
+        TaChannelAppRelation taChannelAppRelation = new TaChannelAppRelation();
175
+        taChannelAppRelation.setChannelId(channelId);
176
+        taChannelAppRelation.setOrgId(taOrg.getOrgId());
177
+        taChannelAppRelation.setCreateTime(LocalDateTime.now());
178
+        taChannelAppRelationMapper.insert(taChannelAppRelation);
179
+
180
+        // 维护当前城市所在城市
181
+        addAndupdate(taUser.getSelectCityTree(), false, taOrg.getOrgId());
182
+
183
+        // 插入积分, 默认全部 1 积分
184
+        List<TdPointsRules> pointsRules = tdPointsRulesMapper.getTPLRules();
185
+        if (pointsRules != null) {
186
+            for (int i = 0; i < pointsRules.size(); i++) {
187
+                TdPointsRules rule = pointsRules.get(i);
188
+                rule.setOrgId(taOrg.getOrgId());
189
+                rule.setStatus(CommConstant.STATUS_NORMAL);
190
+                rule.setPointsAmount(1);    // 默认1积分
191
+                tdPointsRulesMapper.insert(rule);
192
+            }
193
+        }
194
+
195
+        // 插入统计,默认全部显示
196
+        QueryWrapper<TdReport> queryWrapper = new QueryWrapper<>();
197
+        queryWrapper.orderByDesc("create_date");
198
+        queryWrapper.eq("status", 1);
199
+        List<TdReport> tdReportList = iTdReportService.list(queryWrapper);
200
+        if (CollectionUtils.isNotEmpty(tdReportList)) {
201
+            List<TaBuildingReport> buildingReportList = tdReportList.stream().map(e -> {
202
+                TaBuildingReport taBuildingReport = new TaBuildingReport();
203
+                taBuildingReport.setOrgId(taOrg.getOrgId());
204
+                taBuildingReport.setReportCode(e.getReportCode());
205
+                taBuildingReport.setCreateDate(LocalDateTime.now());
206
+
207
+                return taBuildingReport;
208
+            }).collect(Collectors.toList());
209
+
210
+            iTaBuildingReportService.saveBatch(buildingReportList);
211
+        }
212
+
213
+        taUser.setOrgId(taOrg.getOrgId());
214
+        taUser.setIsAdmin(true);
215
+        taUser.setLoginPassword(MD5Utils.md5(taUser.getLoginPassword()));
216
+        taUser.setStatus(CommConstant.STATUS_NORMAL);
217
+        taUser.setCreateDate(LocalDateTime.now());
218
+        if (!this.save(taUser)) {
219
+            throw new Exception("生成用户信息失败");
220
+        }
221
+
222
+        // 导入系统参数
223
+        iSysOrgParamsService.importParamsFromTemplate(taOrg.getOrgId());
224
+
225
+        return taUser;
226
+    }
227
+
228
+    // 维护公司所在城市
229
+    public void addAndupdate(ArrayList<String> selectCityTree, boolean isA, Integer orgid) {
230
+        // 查询当前所有的市
231
+        QueryWrapper<TdCity> tdCityQuery = new QueryWrapper<>();
232
+        tdCityQuery.eq("leveltype", 2);
233
+        List<TdCity> tdCityList = tdCityMapper.selectList(tdCityQuery);
234
+
235
+        // isA=true删除所有城市重新添加
236
+        if (isA == true) {
237
+            QueryWrapper<TaOrgCity> taOrgCity = new QueryWrapper<>();
238
+            taOrgCity.eq("org_id", orgid);
239
+            taOrgCityMapper.delete(taOrgCity);
240
+        }
241
+        TaOrgCity taOrgCity = new TaOrgCity();
242
+        // 对比现在的城市ID
243
+        for (String city : selectCityTree) {
244
+            for (TdCity tdCity : tdCityList) {
245
+                // 入库城市
246
+                if (city.equals(String.valueOf(tdCity.getId()))) {
247
+                    taOrgCity.setCityId(Integer.valueOf(city)).setName(tdCity.getName()).setOrgId(orgid).setStatus(1).setParentid(tdCity.getParentid());
248
+                    taOrgCityMapper.insert(taOrgCity);
249
+                    // 查询当前公司选择省份是否存在
250
+                    QueryWrapper<TaOrgCity> taOrgCityParent = new QueryWrapper<>();
251
+                    taOrgCityParent.eq("city_id", tdCity.getParentid());
252
+                    taOrgCityParent.eq("org_id", orgid);
253
+                    taOrgCityParent.last("limit 1");
254
+                    TaOrgCity taOrgParent = taOrgCityMapper.selectOne(taOrgCityParent);
255
+                    // 如果为空,查询行政表
256
+                    if (null == taOrgParent) {
257
+                        TdCity tdCityParent = tdCityMapper.selectById(tdCity.getParentid());
258
+                        taOrgCity.setCityId(tdCityParent.getId()).setName(tdCityParent.getName()).setOrgId(orgid).setStatus(1).setParentid(100000);
259
+                        taOrgCityMapper.insert(taOrgCity);
260
+                    }
261
+                }
262
+
263
+            }
264
+        }
265
+
266
+    }
267
+
268
+    // 判断当前城市是否存在
269
+    public void verificationCity(ArrayList<String> selectCityTree, Integer city) throws Exception {
270
+        for (String id : selectCityTree) {
271
+            if (id.equals(String.valueOf(city))) {
272
+                return;
273
+            }
274
+        }
275
+        throw new Exception("当前默认城市不在维护城市内");
276
+    }
277
+
278
+    @Override
279
+    public TaUser getInfoWithOrg(Integer id) {
280
+        TaUser taUser = this.getById(id);
281
+        if (null == taUser) {
282
+            return taUser;
283
+        }
284
+
285
+        TaOrg taOrg = taOrgMapper.selectById(taUser.getOrgId());
286
+        if (null != taOrg) {
287
+            taUser.setOrgName(taOrg.getName());
288
+            taUser.setWaterMark(taOrg.getWaterMark());
289
+            taUser.setOrgNum(taOrg.getBuildingNum());
290
+            taUser.setDefaultCityId(taOrg.getDefaultCityId());
291
+            taUser.setOrgThumb(taOrg.getThumb());
292
+            taUser.setOrgDesc(taOrg.getOrgDesc());
293
+            taUser.setOrgLogo(taOrg.getLogo());
294
+            taUser.setBossDisplay(taOrg.getBossDisplay());
295
+        }
296
+
297
+        TaMiniapp taMiniapp = getMiniappByOrg(taOrg);
298
+        if (null != taMiniapp) {
299
+            QueryWrapper<TaMiniappTemplate> query = new QueryWrapper<>();
300
+            query.eq("miniapp_id", taMiniapp.getMiniappId());
301
+            taMiniapp.setTpls(taMiniappTemplateMapper.selectList(query));
302
+        }
303
+
304
+        taUser.setMiniapp(taMiniapp);
305
+        taUser.setLoginPassword(null);
306
+        // 查询所有城市id
307
+        ArrayList<String> taOrgCityList = taOrgCityMapper.selectByIdCity(taUser.getOrgId());
308
+        taUser.setSelectCityTree(taOrgCityList);
309
+        return taUser;
310
+    }
311
+
312
+    @Override
313
+    public void updateInfoWithOrg(TaUser taUser) throws Exception {
314
+        //判断默认城市是否在维护城市内
315
+        verificationCity(taUser.getSelectCityTree(), taUser.getDefaultCityId());
316
+
317
+        TaOrg taOrg = taOrgMapper.selectById(taUser.getOrgId());
318
+        if (null != taOrg) {
319
+            taOrg.setName(taUser.getOrgName());
320
+            taOrg.setLogo(taUser.getOrgLogo());
321
+            taOrg.setWaterMark(taUser.getWaterMark());
322
+            taOrg.setBuildingNum(taUser.getOrgNum());
323
+            taOrg.setDefaultCityId(taUser.getDefaultCityId());
324
+            taOrg.setThumb(taUser.getOrgThumb());
325
+            taOrg.setOrgDesc(taUser.getOrgDesc());
326
+            taOrg.setBossDisplay(taUser.getBossDisplay());
327
+            if (taOrgMapper.updateById(taOrg) < 1) {
328
+                throw new Exception("更新用户公司信息失败");
329
+            }
330
+
331
+            addAndupdate(taUser.getSelectCityTree(), true, taOrg.getOrgId());
332
+        }
333
+
334
+        taUser.setLoginPassword(null);
335
+        if (taUserMapper.updateById(taUser) < 1) {
336
+            throw new Exception("更新用户信息失败");
337
+        }
338
+
339
+        // 如果服务未启动, 则启动服务
340
+        TaMiniapp miniapp = getMiniappByOrg(taOrg);
341
+        if (miniapp != null) {
342
+            WxMaService maService = wxUtils.getMiniApp(miniapp.getMiniappId());
343
+            if (null == maService) {
344
+                TaUser admin = taUserMapper.getAdminByAppID(miniapp.getMiniappId());
345
+
346
+                if (null != admin && CommConstant.STATUS_NORMAL == admin.getStatus() && LocalDateTime.now().isBefore(admin.getExpDate())) {
347
+                    wxUtils.newService(miniapp, true);
348
+                }
349
+            }
350
+        }
351
+    }
352
+
353
+    private TaMiniapp getMiniappByOrg(TaOrg taOrg) {
354
+        QueryWrapper<TaMiniapp> wrapper = new QueryWrapper<>();
355
+        wrapper.eq("org_id", taOrg.getOrgId());
356
+        wrapper.last("limit 1");
357
+
358
+        return taMiniappMapper.selectOne(wrapper);
359
+    }
360
+
361
+    @Override
362
+    public void turnUserOnOrNot(Integer id, boolean isOn, String plat) throws Exception {
363
+        TaUser taUser = this.getById(id);
364
+        if (null == taUser) {
365
+            throw new Exception("未找到有效的用户信息");
366
+        }
367
+
368
+        //停用
369
+        if (!isOn){
370
+            //查看是否置业顾问
371
+            if (taUser.getIsConsultant()){
372
+//                taUser.setIsConsultant(false);
373
+//                taUserMapper.updateById(taUser);
374
+                //小程序端调整为普通客户
375
+                QueryWrapper<TaPerson> taPersonQueryWrapper = new QueryWrapper<>();
376
+                taPersonQueryWrapper.eq("user_id",id);
377
+                taPersonQueryWrapper.eq("org_id",taUser.getOrgId());
378
+                TaPerson taPerson = taPersonMapper.selectOne(taPersonQueryWrapper);
379
+                if (null != taPerson){
380
+                    taPersonMapper.cancelConsulatant(taPerson.getPersonId());
381
+                }
382
+            }
383
+        }
384
+
385
+        Integer status = isOn ? CommConstant.STATUS_NORMAL : CommConstant.STATUS_CLOSED;
386
+        TaUser user = new TaUser();
387
+        user.setStatus(status);
388
+        user.setWeight(taUser.getWeight());
389
+
390
+        QueryWrapper<TaUser> taUserQueryWrapper = new QueryWrapper<>();
391
+        if (CommConstant.LOGIN_TYPE_ADMIN.equals(plat)) {
392
+            taUserQueryWrapper.eq("user_id", id);
393
+        }
394
+        taUserQueryWrapper.eq("org_id", taUserMapper.selectById(id).getOrgId());
395
+
396
+        if (!this.update(user, taUserQueryWrapper)) {
397
+            throw new Exception("开启或禁用用户失败");
398
+        }
399
+    }
400
+
401
+    @Override
402
+    public void resetPassword(Integer id, String newPass) throws Exception {
403
+        TaUser taUser = this.getById(id);
404
+        if (null == taUser) {
405
+            throw new Exception("未找到有效的用户信息");
406
+        }
407
+
408
+        String encryptPass = MD5Utils.md5(MD5Utils.md5(newPass));
409
+        TaUser user = new TaUser();
410
+        user.setLoginPassword(encryptPass);
411
+        user.setUserId(id);
412
+
413
+        if (!this.updateById(user)) {
414
+            throw new Exception("重置用户密码失败");
415
+        }
416
+    }
417
+
418
+    @Override
419
+    public List<TaTags> getTagsList(TaUser e) {
420
+        return taUserMapper.getTagsList(e.getUserId(), e.getOrgId());
421
+    }
422
+
423
+    @Override
424
+    public TaUser addAdminUser(TaUser taUser) throws Exception {
425
+        if (StringUtils.isEmpty(taUser.getPhone())) {
426
+            throw new Exception("电话号码不能为空");
427
+        }
428
+        if (StringUtils.isEmpty(taUser.getUserName())) {
429
+            throw new Exception("用户名称不能为空");
430
+        }
431
+
432
+        if (!StringUtils.isEmpty(taUser.getLoginName())) {
433
+            QueryWrapper<TaUser> wrapper = new QueryWrapper<>();
434
+            wrapper.eq("login_name", taUser.getLoginName());
435
+            List<TaUser> taUserList = this.list(wrapper);
436
+            if (null != taUserList && taUserList.size() > 0) {
437
+                throw new Exception("登录名重复");
438
+            }
439
+        }
440
+
441
+        boolean weightCount = validateWeight(taUser, "add");
442
+        if (weightCount) {
443
+            throw new Exception("同一项目下权重值不能重复");
444
+        }
445
+
446
+        List<TaUser> taUserList = taUserMapper.getUserList(taUser.getPhone(), taUser.getOrgId());
447
+        if (null != taUserList && taUserList.size() > 0) {
448
+            throw new Exception("电话号码重复");
449
+        }
450
+        taUser.setLoginPassword(MD5Utils.md5(MD5Utils.md5("123456")));
451
+        taUser.setStatus(CommConstant.STATUS_NORMAL);
452
+        taUser.setCreateDate(LocalDateTime.now());
453
+        if (taUser.getIsConsultant() == null) {
454
+            taUser.setIsConsultant(false);
455
+        }
456
+        if (taUserMapper.insert(taUser) < 1) {
457
+            throw new Exception("生成用户信息失败");
458
+        }
459
+
460
+        //保存标签
461
+        List<Integer> tags = taUser.getTaTags();
462
+        tags.forEach(e -> {
463
+            TaTagUser taTagUser = new TaTagUser();
464
+            taTagUser.setUserId(taUser.getUserId());
465
+            taTagUser.setTagId(e);
466
+            taTagUserMapper.insert(taTagUser);
467
+        });
468
+
469
+        //保存用户角色
470
+        List<Integer> roleIds = taUser.getRoleIds();
471
+        roleIds.forEach(e -> {
472
+            TaUserRole taUserRole = new TaUserRole();
473
+            taUserRole.setUserId(taUser.getUserId());
474
+            taUserRole.setRoleId(e);
475
+            taUserRoleMapper.insert(taUserRole);
476
+        });
477
+
478
+        //保存项目
479
+        if (taUser.getIsConsultant()) {
480
+            TaPersonBuilding taPersonBuilding = new TaPersonBuilding();
481
+            taPersonBuilding.setBuildingId(taUser.getBuildingId());
482
+            taPersonBuilding.setUserId(taUser.getUserId());
483
+            taPersonBuilding.setCreateDate(LocalDateTime.now());
484
+            taPersonBuildingMapper.insert(taPersonBuilding);
485
+        } else {
486
+            //非置业顾问可授权多个项目
487
+            List<String> buildingIdList = taUser.getBuildingIds();
488
+            LocalDateTime nowTime = LocalDateTime.now();
489
+            buildingIdList.forEach(e -> {
490
+                TaPersonBuilding taPersonBuilding = new TaPersonBuilding();
491
+                taPersonBuilding.setBuildingId(e);
492
+                taPersonBuilding.setUserId(taUser.getUserId());
493
+                taPersonBuilding.setCreateDate(nowTime);
494
+                taPersonBuildingMapper.insert(taPersonBuilding);
495
+            });
496
+        }
497
+
498
+        return taUser;
499
+    }
500
+
501
+    @Override
502
+    public TaUser updateAdminUser(TaUser taUser) throws Exception {
503
+        TaUser taUserBefore = taUserMapper.selectById(taUser.getUserId());
504
+        if (StringUtils.isEmpty(taUser.getPhone())) {
505
+            throw new Exception("电话号码不能为空");
506
+        }
507
+        if (StringUtils.isEmpty(taUser.getUserName())) {
508
+            throw new Exception("用户名称不能为空");
509
+        }
510
+        if (!StringUtils.isEmpty(taUser.getWeight()) && taUser.getWeight().length() > 11) {
511
+            throw new Exception("权重最大为11位");
512
+        }
513
+        if (StringUtils.isEmpty(taUser.getWeight())) {
514
+            taUser.setWeight(null);
515
+        }
516
+        if (!StringUtils.isEmpty(taUser.getLoginName()) && !taUser.getLoginName().equals(taUserBefore.getLoginName())) {
517
+            if (!StringUtils.isEmpty(taUser.getLoginName())) {
518
+                QueryWrapper<TaUser> wrapper = new QueryWrapper<>();
519
+                wrapper.eq("login_name", taUser.getLoginName());
520
+                List<TaUser> taUserList = this.list(wrapper);
521
+                if (null != taUserList && taUserList.size() > 0) {
522
+                    throw new Exception("登录名重复");
523
+                }
524
+            }
525
+        }
526
+
527
+        boolean weightCount = validateWeight(taUser, "update");
528
+        if (weightCount) {
529
+            throw new Exception("同一项目下权重值不能重复");
530
+        }
531
+
532
+        QueryWrapper<TaUser> wrapper = new QueryWrapper<>();
533
+//        wrapper.nested(q -> q.eq("phone", taUser.getPhone()).or().eq("login_Name", taUser.getLoginName()));
534
+        wrapper.eq("phone", taUser.getPhone());
535
+        wrapper.eq("org_id", taUser.getOrgId());
536
+        wrapper.ne("user_id", taUser.getUserId());
537
+        List<TaUser> taUserList = this.list(wrapper);
538
+        if (null != taUserList && taUserList.size() > 0) {
539
+            throw new Exception("电话号码重复");
540
+        }
541
+        if (taUserMapper.updateById(taUser) < 1) {
542
+            throw new Exception("更新用户信息失败");
543
+        }
544
+        QueryWrapper<TaTagUser> queryWrapper = new QueryWrapper<>();
545
+        queryWrapper.eq("user_id", taUser.getUserId());
546
+        taTagUserMapper.delete(queryWrapper);
547
+        //保存标签
548
+        List<Integer> tags = taUser.getTaTags();
549
+        tags.forEach(e -> {
550
+            TaTagUser taTagUser = new TaTagUser();
551
+            taTagUser.setUserId(taUser.getUserId());
552
+            taTagUser.setTagId(e);
553
+            taTagUserMapper.insert(taTagUser);
554
+        });
555
+
556
+        QueryWrapper<TaUserRole> taUserRoleQueryWrapper = new QueryWrapper<>();
557
+        taUserRoleQueryWrapper.eq("user_id", taUser.getUserId());
558
+        taUserRoleMapper.delete(taUserRoleQueryWrapper);
559
+        //保存用户角色
560
+        List<Integer> roleIds = taUser.getRoleIds();
561
+        roleIds.forEach(e -> {
562
+            TaUserRole taUserRole = new TaUserRole();
563
+            taUserRole.setUserId(taUser.getUserId());
564
+            taUserRole.setRoleId(e);
565
+            taUserRoleMapper.insert(taUserRole);
566
+        });
567
+
568
+        QueryWrapper<TaPersonBuilding> taPersonBuildingQueryWrapper = new QueryWrapper<>();
569
+        taPersonBuildingQueryWrapper.eq("user_id", taUser.getUserId());
570
+        taPersonBuildingMapper.delete(taPersonBuildingQueryWrapper);
571
+        //保存项目
572
+        if (taUser.getIsConsultant()) {
573
+            TaPersonBuilding taPersonBuilding = new TaPersonBuilding();
574
+            taPersonBuilding.setBuildingId(taUser.getBuildingId());
575
+            taPersonBuilding.setUserId(taUser.getUserId());
576
+            taPersonBuilding.setCreateDate(LocalDateTime.now());
577
+            taPersonBuildingMapper.insert(taPersonBuilding);
578
+        } else {
579
+            //非置业顾问可授权多个项目
580
+            List<String> buildingIdList = taUser.getBuildingIds();
581
+            LocalDateTime nowTime = LocalDateTime.now();
582
+            buildingIdList.forEach(e -> {
583
+                TaPersonBuilding taPersonBuilding = new TaPersonBuilding();
584
+                taPersonBuilding.setBuildingId(e);
585
+                taPersonBuilding.setUserId(taUser.getUserId());
586
+                taPersonBuilding.setCreateDate(nowTime);
587
+                taPersonBuildingMapper.insert(taPersonBuilding);
588
+            });
589
+        }
590
+
591
+        //更新person
592
+        TaPerson taPerson = new TaPerson();
593
+        taPerson.setAvatarurl(taUser.getAvatar());
594
+        taPerson.setCompany(taUser.getOrgName());
595
+        taPerson.setTel(taUser.getPhone());
596
+        taPerson.setName(taUser.getUserName());
597
+        taPerson.setAddress(taUser.getAddress());
598
+        taPerson.setIdNo(taUser.getIdNo());
599
+        taPerson.setDepartment(taUser.getDepartment());
600
+        taPerson.setPost(taUser.getPosition());
601
+        taPerson.setPhoto(taUser.getPhoto());
602
+        QueryWrapper<TaPerson> taPersonQueryWrapper = new QueryWrapper<>();
603
+        taPersonQueryWrapper.eq("user_id", taUser.getUserId());
604
+        taPersonMapper.update(taPerson, taPersonQueryWrapper);
605
+
606
+        return taUser;
607
+    }
608
+
609
+    @Override
610
+    public TaUser getAdminByAppID(String appid) {
611
+        return taUserMapper.getAdminByAppID(appid);
612
+    }
613
+
614
+    @Override
615
+    public ResponseBean cityTree() {
616
+        ResponseBean responseBean = new ResponseBean<>();
617
+        // 省份
618
+        TaUser taUser = new TaUser();
619
+        QueryWrapper<TdCity> tdCityQueryWrapper = new QueryWrapper<>();
620
+        tdCityQueryWrapper.eq("leveltype", 1);
621
+        List<TdCity> tdCityList = tdCityMapper.selectList(tdCityQueryWrapper);
622
+        taUser.setTdCityList(tdCityList);
623
+        for (TdCity tdCity : tdCityList) {
624
+            // 根据parentid查询城市
625
+            QueryWrapper<TdCity> tdCityQuery = new QueryWrapper<>();
626
+            tdCityQuery.eq("parentid", tdCity.getId());
627
+            List<TdCity> city = tdCityMapper.selectList(tdCityQuery);
628
+            tdCity.setChildren(city);
629
+        }
630
+        responseBean.addSuccess(taUser);
631
+        return responseBean;
632
+    }
633
+
634
+    @Override
635
+    public ResponseBean departureUser(Integer userId, List<String> customerIdList, Integer consultantUserId) {
636
+        ResponseBean responseBean = new ResponseBean();
637
+        TaUser user = this.getById(userId);
638
+        if (null == user) {
639
+            responseBean.addError("此员工不存在!");
640
+            return responseBean;
641
+        }
642
+
643
+        // 不是置业顾问
644
+        if (user.getIsConsultant() == false) {
645
+            // 设置员工离职
646
+            updateUserStatus(user);
647
+            return ResponseBean.success("操作成功!");
648
+        }
649
+        /**
650
+         * 是置业顾问
651
+         */
652
+
653
+        // 更改员工表的用户类型,清空关联关系user_id
654
+
655
+        QueryWrapper<TaPerson> userQueryWrapper = new QueryWrapper<>();
656
+        userQueryWrapper.eq("user_id", consultantUserId);
657
+        TaPerson person = iTaPersonService.getOne(userQueryWrapper);
658
+        if (null == person) {
659
+            responseBean.addError("置业顾问未绑定小程序!");
660
+            return responseBean;
661
+        }
662
+
663
+        // 设置员工离职
664
+        updateUserStatus(user);
665
+
666
+        // 转移客户
667
+        UpdateWrapper<TaRecommendCustomer> updateWrapper = new UpdateWrapper<>();
668
+        updateWrapper.in("customer_id", customerIdList);
669
+        updateWrapper.set("realty_consultant", person.getPersonId());
670
+        boolean update = iTaRecommendCustomerService.update(updateWrapper);
671
+        if (!update) {
672
+            return ResponseBean.error("操作失败!", ResponseBean.ERROR_ILLEGAL_PARAMS);
673
+        }
674
+
675
+        return ResponseBean.success("操作成功!");
676
+    }
677
+
678
+    /**
679
+     * 分页查询用户列表
680
+     *
681
+     * @param pg
682
+     * @param taUser
683
+     * @param personBuildingList
684
+     * @return
685
+     */
686
+    @Override
687
+    public IPage<TaUser> seleUserList(IPage pg, TaUser taUser, List<TaPersonBuilding> personBuildingList) {
688
+        return taUserMapper.seleUserList(pg, taUser, personBuildingList);
689
+    }
690
+
691
+    @Override
692
+    public TaUser getUserInfoById(Integer userId, Integer orgId) {
693
+        QueryWrapper<TaUser> userQueryWrapper = new QueryWrapper<>();
694
+        userQueryWrapper.eq("user_id", userId);
695
+        userQueryWrapper.eq("org_id", orgId);
696
+        userQueryWrapper.ne("status", -1);
697
+        return getOne(userQueryWrapper);
698
+    }
699
+
700
+    private boolean updateUserStatus(TaUser user) {
701
+        UpdateWrapper<TaUser> updateWrapper = new UpdateWrapper<>();
702
+        updateWrapper.eq("user_id", user.getUserId());
703
+        updateWrapper.set("status", 9);
704
+
705
+        QueryWrapper<TaPerson> taPersonQueryWrapper = new QueryWrapper<>();
706
+        taPersonQueryWrapper.eq("user_id", user.getUserId());
707
+        taPersonQueryWrapper.last("limit 1");
708
+        TaPerson taPerson = taPersonMapper.selectOne(taPersonQueryWrapper);
709
+        // 可能存在没有绑定小程序端
710
+        if (null != taPerson) {
711
+            UpdateWrapper<TaPerson> personUpdateWrapper = new UpdateWrapper<>();
712
+            personUpdateWrapper.eq("person_id", taPerson.getPersonId());
713
+
714
+            // 如果是置业顾问,设置为客户类型
715
+            if (user.getIsConsultant() == true) {
716
+                personUpdateWrapper.set("person_type", CommConstant.PERSON_ESTATE_CUSTOMER);
717
+            }
718
+
719
+            personUpdateWrapper.set("user_id", null);
720
+            iTaPersonService.update(personUpdateWrapper);
721
+        }
722
+
723
+        return this.update(updateWrapper);
724
+    }
725
+
726
+    public boolean validateWeight(TaUser taUser, String operateType) {
727
+        if (StringUtils.isEmpty(taUser.getWeight())) {
728
+            return false;
729
+        }
730
+
731
+        Integer count;
732
+        if (taUser.getIsConsultant() != null && taUser.getIsConsultant()) {
733
+            String buildingId = taUser.getBuildingId();
734
+            String weight = taUser.getWeight();
735
+            count = taUserMapper.validateWeight(null, buildingId, weight, operateType.equals("add") ? null : taUser.getUserId());
736
+        } else {
737
+            List<String> buildingIds = taUser.getBuildingIds();
738
+            String weight = taUser.getWeight();
739
+            count = taUserMapper.validateWeight(buildingIds, null, weight, operateType.equals("add") ? null : taUser.getUserId());
740
+        }
741
+
742
+        if (count > 0) {
743
+            return true;
744
+        }
745
+        return false;
746
+    }
747
+
748
+}

+ 293
- 0
src/main/java/com/yunzhi/marketing/channel/sysChannel/controller/SysUserChannelController.java Просмотреть файл

@@ -0,0 +1,293 @@
1
+package com.yunzhi.marketing.channel.sysChannel.controller;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
+import com.baomidou.mybatisplus.core.metadata.IPage;
6
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
+import com.yunzhi.marketing.base.BaseController;
8
+import com.yunzhi.marketing.base.ResponseBean;
9
+import com.yunzhi.marketing.center.sysUser.entity.SysToken;
10
+import com.yunzhi.marketing.center.sysUser.entity.SysUser;
11
+import com.yunzhi.marketing.center.sysUser.service.ISysTokenService;
12
+import com.yunzhi.marketing.center.sysUser.service.ISysUserService;
13
+import com.yunzhi.marketing.center.taUser.entity.TaUser;
14
+import com.yunzhi.marketing.center.taUser.service.ITaUserService;
15
+import com.yunzhi.marketing.channel.sysChannel.entity.TaChannelProxy;
16
+import com.yunzhi.marketing.channel.sysChannel.service.ITaChannelProxyService;
17
+import com.yunzhi.marketing.common.CommConstant;
18
+import com.yunzhi.marketing.common.JWTUtils;
19
+import com.yunzhi.marketing.common.MD5Utils;
20
+import com.yunzhi.marketing.common.StringUtils;
21
+import com.yunzhi.marketing.entity.TaChannelAppRelation;
22
+import com.yunzhi.marketing.service.ITaChannelAppRelationService;
23
+import org.apache.commons.collections.CollectionUtils;
24
+import org.slf4j.Logger;
25
+import org.slf4j.LoggerFactory;
26
+import org.springframework.beans.factory.annotation.Autowired;
27
+import org.springframework.web.bind.annotation.*;
28
+
29
+import javax.servlet.http.HttpServletRequest;
30
+import java.time.LocalDateTime;
31
+import java.util.ArrayList;
32
+import java.util.HashMap;
33
+import java.util.List;
34
+import java.util.Map;
35
+
36
+/**
37
+ * <p>
38
+    * 系统用户 系统中心账户 前端控制器
39
+    * </p>
40
+ *
41
+ * @author jobob
42
+ * @since 2019-09-11
43
+ */
44
+@RestController
45
+@RequestMapping("/api")
46
+public class SysUserChannelController extends BaseController {
47
+
48
+    private final Logger logger = LoggerFactory.getLogger(SysUserChannelController.class);
49
+
50
+    @Autowired
51
+    public ISysUserService iSysUserService;
52
+    
53
+    @Autowired
54
+    private ISysTokenService sysTokenService;
55
+
56
+    @Autowired
57
+    private ITaUserService iTaUserService;
58
+
59
+    @Autowired
60
+    private ITaChannelProxyService iTaChannelProxyService;
61
+
62
+    @Autowired
63
+    private ITaChannelAppRelationService iTaChannelAppRelationService;
64
+
65
+    /**
66
+     * 修改对象
67
+     * @param sysUser 实体对象
68
+     * @return
69
+     */
70
+    @RequestMapping(value="/channel/sysUser",method= RequestMethod.PUT)
71
+    public ResponseBean sysUserUpdate(@RequestBody SysUser sysUser, HttpServletRequest request){
72
+        ResponseBean responseBean = new ResponseBean();
73
+        try {
74
+            String userName = JWTUtils.getSubject(request);
75
+            sysUser.setPassword(MD5Utils.md5(sysUser.getPassword()));
76
+            sysUser.setUserName(userName);
77
+            if (iSysUserService.updateById(sysUser)){
78
+                responseBean.addSuccess(sysUser);
79
+            }else {
80
+                responseBean.addError("fail");
81
+            }
82
+        }catch (Exception e){
83
+            e.printStackTrace();
84
+            logger.error("sysUserUpdate -=- {}",e.toString());
85
+            responseBean.addError(e.getMessage());
86
+        }
87
+        return responseBean;
88
+    }
89
+
90
+    @PostMapping("/channel/signin")
91
+    public ResponseBean signinChannel(@RequestBody String paramStr) {
92
+        JSONObject params = JSONObject.parseObject(paramStr);
93
+        if (params == null) {
94
+            return ResponseBean.error("非法参数", ResponseBean.ERROR_MISSING_PARAMS);
95
+        }
96
+
97
+        String userName = params.getString("userName");
98
+        String userPassword = params.getString("password");
99
+
100
+        //验证用户名密码是否正确
101
+        QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
102
+        sysUserQueryWrapper.eq("user_name",userName);
103
+        sysUserQueryWrapper.eq("password", MD5Utils.md5(userPassword));
104
+        sysUserQueryWrapper.eq("type", CommConstant.LOGIN_TYPE_CHANNEL);
105
+        SysUser sysUser = iSysUserService.getOne(sysUserQueryWrapper);
106
+        if (sysUser == null) {
107
+            return ResponseBean.error("用户名或密码错误", ResponseBean.ERROR_ILLEGAL_PARAMS);
108
+        }
109
+
110
+        if (sysUser.getStatus() != CommConstant.STATUS_NORMAL) {
111
+            return ResponseBean.error("用户状态异常", ResponseBean.ERROR_UNAVAILABLE);
112
+        }
113
+
114
+        Map map = new HashMap();
115
+        map.put("userName", sysUser.getUserName());
116
+        map.put("userId",sysUser.getUserId());
117
+
118
+        String token = JWTUtils.newTokenByMap(map);
119
+
120
+        //保存token
121
+        sysTokenService.saveToken(token);
122
+
123
+        Map<String, Object> result = new HashMap<>();
124
+        result.put("token", token);
125
+        result.put("user", sysUser);
126
+
127
+        return ResponseBean.success(result);
128
+    }
129
+
130
+    @PostMapping("/channel/signout")
131
+    public ResponseBean signoutChannel(HttpServletRequest request) {
132
+        String token = JWTUtils.getToken(request);
133
+        QueryWrapper<SysToken> sysTokenQueryWrapper = new QueryWrapper<>();
134
+        sysTokenQueryWrapper.eq("token",token);
135
+        sysTokenService.remove(sysTokenQueryWrapper);
136
+        return ResponseBean.success("成功退出");
137
+    }
138
+
139
+    /**
140
+     * 根据id查询对象
141
+     * @param id  实体ID
142
+     */
143
+    @RequestMapping(value="/channel/current",method=RequestMethod.GET)
144
+    public ResponseBean currentChannelUser(HttpServletRequest request){
145
+        String userName = getSysUserName(request);
146
+        QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
147
+        sysUserQueryWrapper.eq("user_name",userName);
148
+        sysUserQueryWrapper.eq("type",CommConstant.LOGIN_TYPE_CHANNEL);
149
+        SysUser sysUser = iSysUserService.getOne(sysUserQueryWrapper);
150
+        sysUser.setPassword(null);
151
+
152
+        return ResponseBean.success(sysUser);
153
+    }
154
+
155
+    /**
156
+     * 分页查询列表
157
+     * @param pageNum
158
+     * @param pageSize
159
+     * @return
160
+     */
161
+    @RequestMapping(value="/channel/taChannel",method= RequestMethod.GET)
162
+    public ResponseBean taUserList(@RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
163
+                                   @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
164
+        ResponseBean responseBean = new ResponseBean();
165
+        try {
166
+            //使用分页插件
167
+            IPage pg = new Page<>(pageNum, pageSize);
168
+            IPage<TaChannelProxy> result = iTaChannelProxyService.getChannelList(pg);
169
+            responseBean.addSuccess(result);
170
+        }catch (Exception e){
171
+            e.printStackTrace();
172
+            logger.error("taUserList -=- {}",e.toString());
173
+            responseBean.addError(e.getMessage());
174
+        }
175
+        return responseBean;
176
+    }
177
+
178
+    /**
179
+     * 新增代理商
180
+     * @param taChannelProxy
181
+     * @param request
182
+     * @return
183
+     */
184
+    @RequestMapping(value="/channel/taChannel",method= RequestMethod.POST)
185
+    public ResponseBean taUserList(@RequestBody TaChannelProxy taChannelProxy, HttpServletRequest request){
186
+        ResponseBean responseBean = new ResponseBean();
187
+        try {
188
+            if (taChannelProxy.getAppMaxNum() != null && taChannelProxy.getAppMaxNum() <= 0){
189
+                responseBean.addError("维护小程序数量不得小于0");
190
+                return responseBean;
191
+            }
192
+            if (StringUtils.isEmpty(taChannelProxy.getUserName())){
193
+                taChannelProxy.setUserName(taChannelProxy.getChannelTel());
194
+            }
195
+
196
+            QueryWrapper<TaChannelProxy> userNameQueryWrapper = new QueryWrapper<>();
197
+            userNameQueryWrapper.eq("user_name", taChannelProxy.getUserName());
198
+            Integer countUserName = iTaChannelProxyService.count(userNameQueryWrapper);
199
+            if (countUserName > 0){
200
+                responseBean.addError("账户名已存在");
201
+                return responseBean;
202
+            }
203
+
204
+
205
+            QueryWrapper<TaChannelProxy> taChannelProxyQueryWrapper = new QueryWrapper<>();
206
+            taChannelProxyQueryWrapper.eq("channel_tel", taChannelProxy.getChannelTel());
207
+            Integer countChannel = iTaChannelProxyService.count(taChannelProxyQueryWrapper);
208
+            if (countChannel > 0){
209
+                responseBean.addError("手机号已存在");
210
+                return responseBean;
211
+            }
212
+            taChannelProxy.setPassword(MD5Utils.md5(MD5Utils.md5("abc@123")));
213
+            taChannelProxy.setStatus(1);
214
+            taChannelProxy.setCreateTime(LocalDateTime.now());
215
+            iTaChannelProxyService.save(taChannelProxy);
216
+        }catch (Exception e){
217
+            e.printStackTrace();
218
+            logger.error("taUserList -=- {}",e.toString());
219
+            responseBean.addError(e.getMessage());
220
+        }
221
+        return responseBean;
222
+    }
223
+
224
+    /**
225
+     * 根据id查询对象
226
+     * @param id  实体ID
227
+     */
228
+    @RequestMapping(value="/channel/taChannel/{id}",method= RequestMethod.GET)
229
+    public ResponseBean getChannelProxyById(@PathVariable Integer id){
230
+        ResponseBean responseBean = new ResponseBean();
231
+        QueryWrapper<TaChannelProxy> queryWrapper = new QueryWrapper<>();
232
+        queryWrapper.eq("channel_id", id);
233
+        TaChannelProxy taChannelProxy = iTaChannelProxyService.getOne(queryWrapper);
234
+        responseBean.addSuccess(taChannelProxy);
235
+        return responseBean;
236
+    }
237
+
238
+    /**
239
+     * 修改对象
240
+     * @param id
241
+     * @param taChannelProxy
242
+     * @param request
243
+     * @return
244
+     */
245
+    @RequestMapping(value="/channel/taChannel/{id}",method= RequestMethod.PUT)
246
+    public ResponseBean taNewsTypeUpdate(@PathVariable Integer id,
247
+                                         @RequestBody TaChannelProxy taChannelProxy, HttpServletRequest request){
248
+        ResponseBean responseBean = new ResponseBean();
249
+        if (taChannelProxy.getAppMaxNum() != null && taChannelProxy.getAppMaxNum() <= 0){
250
+            responseBean.addError("维护小程序数量不得小于0");
251
+            return responseBean;
252
+        }
253
+
254
+        if (StringUtils.isEmpty(taChannelProxy.getUserName())){
255
+            taChannelProxy.setUserName(taChannelProxy.getChannelTel());
256
+        }
257
+
258
+        QueryWrapper<TaChannelProxy> userNameQueryWrapper = new QueryWrapper<>();
259
+        userNameQueryWrapper.eq("user_name", taChannelProxy.getUserName());
260
+        userNameQueryWrapper.ne("channel_id", id);
261
+        Integer countUserName = iTaChannelProxyService.count(userNameQueryWrapper);
262
+        if (countUserName > 0){
263
+            responseBean.addError("账户名已存在");
264
+            return responseBean;
265
+        }
266
+
267
+        taChannelProxy.setExpireDate(taChannelProxy.getExpireDate().plusDays(1L));
268
+        //更新业务层的登录账号为禁用
269
+        if (taChannelProxy.getStatus() != null){
270
+            QueryWrapper<TaChannelAppRelation> taChannelAppRelationQueryWrapper = new QueryWrapper<>();
271
+            taChannelAppRelationQueryWrapper.eq("channel_id", id);
272
+            List<TaChannelAppRelation> taChannelAppRelation = iTaChannelAppRelationService.list(taChannelAppRelationQueryWrapper);
273
+            List<Integer> orgIdList = new ArrayList<>();
274
+            taChannelAppRelation.forEach(e->{
275
+                orgIdList.add(e.getOrgId());
276
+            });
277
+            if (CollectionUtils.isNotEmpty(orgIdList)){
278
+                QueryWrapper<TaUser> taUserQueryWrapper = new QueryWrapper<>();
279
+                taUserQueryWrapper.in("org_id", orgIdList);
280
+                TaUser taUser = new TaUser();
281
+                taUser.setStatus(taChannelProxy.getStatus());
282
+                iTaUserService.update(taUser, taUserQueryWrapper);
283
+            }
284
+
285
+        }
286
+
287
+        QueryWrapper<TaChannelProxy> taChannelProxyQueryWrapper = new QueryWrapper<>();
288
+        taChannelProxyQueryWrapper.eq("channel_id", id);
289
+        iTaChannelProxyService.update(taChannelProxy, taChannelProxyQueryWrapper);
290
+        return ResponseBean.success("更新成功");
291
+    }
292
+
293
+}

+ 41
- 0
src/main/java/com/yunzhi/marketing/channel/sysChannel/entity/TaChannelProxy.java Просмотреть файл

@@ -0,0 +1,41 @@
1
+package com.yunzhi.marketing.channel.sysChannel.entity;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableField;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import lombok.Data;
7
+import lombok.EqualsAndHashCode;
8
+import lombok.experimental.Accessors;
9
+
10
+import java.time.LocalDateTime;
11
+
12
+@Data
13
+@EqualsAndHashCode(callSuper = false)
14
+@Accessors(chain = true)
15
+public class TaChannelProxy {
16
+    @TableId(value = "channel_id", type = IdType.AUTO)
17
+    private Integer channelId;
18
+
19
+    private String channelProxyName;
20
+
21
+    private String channelImg;
22
+
23
+    private String channelContactName;
24
+
25
+    private String channelTel;
26
+
27
+    private String userName;
28
+
29
+    private String password;
30
+
31
+    private LocalDateTime expireDate;
32
+
33
+    private Integer status;
34
+
35
+    private Integer appMaxNum;
36
+
37
+    private LocalDateTime createTime;
38
+
39
+    @TableField(exist = false)
40
+    private Integer appCurrentNum;
41
+}

+ 11
- 0
src/main/java/com/yunzhi/marketing/channel/sysChannel/mapper/TaChannelProxyMapper.java Просмотреть файл

@@ -0,0 +1,11 @@
1
+package com.yunzhi.marketing.channel.sysChannel.mapper;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.yunzhi.marketing.channel.sysChannel.entity.TaChannelProxy;
6
+import org.apache.ibatis.annotations.Mapper;
7
+
8
+@Mapper
9
+public interface TaChannelProxyMapper extends BaseMapper<TaChannelProxy> {
10
+    IPage<TaChannelProxy> getChannelList(IPage page);
11
+}

+ 12
- 0
src/main/java/com/yunzhi/marketing/channel/sysChannel/service/ITaChannelProxyService.java Просмотреть файл

@@ -0,0 +1,12 @@
1
+package com.yunzhi.marketing.channel.sysChannel.service;
2
+
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.yunzhi.marketing.channel.sysChannel.entity.TaChannelProxy;
6
+
7
+
8
+public interface ITaChannelProxyService extends IService<TaChannelProxy> {
9
+    IPage<TaChannelProxy> getChannelList(IPage page);
10
+
11
+    void resetPassword(Integer id, String newPass) throws Exception;
12
+}

+ 55
- 0
src/main/java/com/yunzhi/marketing/channel/sysChannel/service/impl/TaChannelProxyServiceImpl.java Просмотреть файл

@@ -0,0 +1,55 @@
1
+package com.yunzhi.marketing.channel.sysChannel.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6
+import com.yunzhi.marketing.channel.sysChannel.entity.TaChannelProxy;
7
+import com.yunzhi.marketing.channel.sysChannel.mapper.TaChannelProxyMapper;
8
+import com.yunzhi.marketing.channel.sysChannel.service.ITaChannelProxyService;
9
+import com.yunzhi.marketing.common.MD5Utils;
10
+import com.yunzhi.marketing.entity.TaChannelAppRelation;
11
+import com.yunzhi.marketing.mapper.TaChannelAppRelationMapper;
12
+import org.apache.commons.collections.CollectionUtils;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.stereotype.Service;
15
+
16
+@Service
17
+public class TaChannelProxyServiceImpl extends ServiceImpl<TaChannelProxyMapper, TaChannelProxy>  implements ITaChannelProxyService {
18
+    @Autowired
19
+    private TaChannelProxyMapper taChannelProxyMapper;
20
+
21
+    @Autowired
22
+    private TaChannelAppRelationMapper taChannelAppRelationMapper;
23
+
24
+    @Override
25
+    public IPage<TaChannelProxy> getChannelList(IPage page) {
26
+        IPage<TaChannelProxy> taChannelProxyIPage = taChannelProxyMapper.getChannelList(page);
27
+        if (CollectionUtils.isNotEmpty(taChannelProxyIPage.getRecords())){
28
+            taChannelProxyIPage.getRecords().forEach(e->{
29
+                QueryWrapper<TaChannelAppRelation> taChannelAppRelationQueryWrapper = new QueryWrapper<>();
30
+                taChannelAppRelationQueryWrapper.eq("channel_id", e.getChannelId());
31
+                taChannelAppRelationQueryWrapper.groupBy("channel_id");
32
+                e.setAppCurrentNum(taChannelAppRelationMapper.selectCount(taChannelAppRelationQueryWrapper));
33
+            });
34
+            taChannelProxyIPage.setRecords(taChannelProxyIPage.getRecords());
35
+        }
36
+        return taChannelProxyIPage;
37
+    }
38
+
39
+    @Override
40
+    public void resetPassword(Integer id, String newPass) throws Exception {
41
+        TaChannelProxy taChannelProxy = this.getById(id);
42
+        if (null == taChannelProxy) {
43
+            throw new Exception("未找到有效的渠道信息");
44
+        }
45
+
46
+        String encryptPass = MD5Utils.md5(MD5Utils.md5(newPass));
47
+        TaChannelProxy proxy = new TaChannelProxy();
48
+        proxy.setPassword(encryptPass);
49
+        proxy.setChannelId(id);
50
+
51
+        if (!this.updateById(proxy)) {
52
+            throw new Exception("重置渠道密码失败");
53
+        }
54
+    }
55
+}

+ 67
- 0
src/main/java/com/yunzhi/marketing/cleancode/CleanCode.java Просмотреть файл

@@ -0,0 +1,67 @@
1
+package com.yunzhi.marketing.cleancode;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.marketing.entity.*;
5
+import com.yunzhi.marketing.service.*;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.web.bind.annotation.RequestMapping;
8
+import org.springframework.web.bind.annotation.RequestMethod;
9
+import org.springframework.web.bind.annotation.RestController;
10
+
11
+import java.util.List;
12
+
13
+@RestController
14
+@RequestMapping("/api")
15
+public class CleanCode {
16
+
17
+    @Autowired
18
+    private ISysMenuService sysMenuService;
19
+
20
+    @Autowired
21
+    private ITaRoleService taRoleService;
22
+
23
+    @Autowired
24
+    private ITaRoleMenuService taRoleMenuService;
25
+
26
+    @Autowired
27
+    private ITaRoleButtonService taRoleButtonService;
28
+
29
+    @Autowired
30
+    private ISysButtonInMenuService sysButtonInMenuService;
31
+
32
+    @RequestMapping(value = "/admin/clean/menurole", method = RequestMethod.GET)
33
+    public void cleanMenu() {
34
+        List<SysMenu> sysMenuList = sysMenuService.list();
35
+
36
+        QueryWrapper<TaRole> roleQueryWrapper = new QueryWrapper<>();
37
+        roleQueryWrapper.eq("is_admin",1);
38
+        List<TaRole> roleList = taRoleService.list(roleQueryWrapper);
39
+
40
+        roleList.forEach(e -> {
41
+            sysMenuList.forEach(s -> {
42
+                TaRoleMenu taRoleMenu = new TaRoleMenu();
43
+                taRoleMenu.setRoleId(e.getRoleId());
44
+                taRoleMenu.setMenuId(s.getMenuId());
45
+                taRoleMenuService.save(taRoleMenu);
46
+            });
47
+        });
48
+    }
49
+
50
+    @RequestMapping(value = "/admin/clean/buttonrole", method = RequestMethod.GET)
51
+    public void cleanButton() {
52
+        List<SysButtonInMenu> buttlist = sysButtonInMenuService.list();
53
+
54
+        QueryWrapper<TaRole> roleQueryWrapper = new QueryWrapper<>();
55
+        roleQueryWrapper.eq("is_admin",1);
56
+        List<TaRole> roleList = taRoleService.list(roleQueryWrapper);
57
+
58
+        roleList.forEach(e -> {
59
+            buttlist.forEach(s -> {
60
+                TaRoleButton taRoleButton = new TaRoleButton();
61
+                taRoleButton.setBtnId(s.getBtnId());
62
+                taRoleButton.setRoleId(e.getRoleId());
63
+                taRoleButtonService.save(taRoleButton);
64
+            });
65
+        });
66
+    }
67
+}

+ 62
- 0
src/main/java/com/yunzhi/marketing/common/AliOSSUtils.java Просмотреть файл

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

+ 137
- 0
src/main/java/com/yunzhi/marketing/common/BeanTools.java Просмотреть файл

@@ -0,0 +1,137 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import jodd.bean.BeanCopy;
4
+import jodd.typeconverter.TypeConverterManager;
5
+import org.apache.commons.collections.BeanMap;
6
+import org.springframework.beans.BeanUtils;
7
+import org.springframework.beans.BeanWrapper;
8
+import org.springframework.beans.BeanWrapperImpl;
9
+
10
+import java.beans.PropertyDescriptor;
11
+import java.lang.reflect.Method;
12
+import java.util.*;
13
+
14
+@SuppressWarnings("deprecation")
15
+public final class BeanTools {
16
+
17
+    private static Map<String, Object> toBeanMethodMap = new HashMap<String, Object>();
18
+
19
+    /**
20
+     * <pre>
21
+     * 功能:实现BEAN的属性对拷
22
+     * 创建人:JokenWang
23
+     * </pre>
24
+     *
25
+     * @param fromBean        待转换的源bean
26
+     * @param toBeanClassName 转换成目标bean的名称 形如:ItemSeries.class.getName()
27
+     * @return 目标BEAN类
28
+     */
29
+    public static <T> T convertBean(Object fromBean, Class<T> toBeanClassName) {
30
+        T toBean = null;
31
+        try {
32
+            toBean = getBeanInstance(toBeanClassName.getName());
33
+            return convertBean(fromBean, toBean);
34
+        } catch (Exception e) {
35
+            e.printStackTrace();
36
+        }
37
+        return toBean;
38
+    }
39
+
40
+    private static <T> T convertBean(Object fromBean, T toBean) {
41
+        TypeConverterManager.register(String.class, new StringConverter());
42
+        BeanCopy.beans(fromBean, toBean).copy();
43
+        return toBean;
44
+    }
45
+
46
+    public static Method getDeclaredMethod(Object object, String methodName, Class<?>... parameterTypes) {
47
+        Method method;
48
+        for (Class<?> clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
49
+            try {
50
+                method = clazz.getDeclaredMethod(methodName, parameterTypes);
51
+                return method;
52
+            } catch (Exception ignored) {
53
+
54
+            }
55
+        }
56
+        return null;
57
+    }
58
+
59
+    @SuppressWarnings("unchecked")
60
+    public static <T> T getBeanInstance(String clazzName)
61
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
62
+
63
+        return (T) Class.forName(clazzName).newInstance();
64
+    }
65
+
66
+    public static Map<String, Object> toBeanMethodMap(String toBean)
67
+            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
68
+
69
+        Class<?> toBeanClazz = getBeanInstance(toBean).getClass();
70
+        Method[] toBeanMethods = toBeanClazz.getDeclaredMethods();
71
+        if (!toBeanClazz.isInstance(Object.class))// 非超类Object
72
+        {
73
+            for (Method method : toBeanMethods) {
74
+                String methodName = method.getName();
75
+                toBeanMethodMap.put(methodName, method);
76
+            }
77
+
78
+            Class<?> toBeanSuperclazz = toBeanClazz.getSuperclass();// 获取父类
79
+            toBeanMethodMap(toBeanSuperclazz.getName());
80
+        }
81
+
82
+        return toBeanMethodMap;
83
+    }
84
+
85
+    public static Map<String, Object> toMap(Object object) {
86
+        Map<String, Object> map = new HashMap<String, Object>();
87
+
88
+        if (object == null) {
89
+            return map;
90
+        }
91
+
92
+        BeanMap beanMap;
93
+        beanMap = new BeanMap(object);
94
+        @SuppressWarnings("unchecked")
95
+        Iterator<String> it = beanMap.keyIterator();
96
+        while (it.hasNext()) {
97
+            String name = it.next();
98
+            Object value = beanMap.get(name);
99
+            // 转换时会将类名也转换成属性,此处去掉
100
+            if (value != null && !name.equals("class")) {
101
+                map.put(name, value);
102
+            }
103
+        }
104
+
105
+        return map;
106
+    }
107
+
108
+    public static Map<String, Object> toMap(Object... objs) {
109
+        Map<String, Object> map = new HashMap<>();
110
+        for (Object object : objs) {
111
+            if (object != null) {
112
+                map.putAll(toMap(object));
113
+            }
114
+        }
115
+        return map;
116
+    }
117
+
118
+    public static String[] getNullPropertyNames (Object source) {
119
+        final BeanWrapper src = new BeanWrapperImpl(source);
120
+        PropertyDescriptor[] pds = src.getPropertyDescriptors();
121
+
122
+        Set<String> emptyNames = new HashSet<String>();
123
+        for(PropertyDescriptor pd : pds) {
124
+            Object srcValue = src.getPropertyValue(pd.getName());
125
+            if (srcValue == null) {
126
+                emptyNames.add(pd.getName());
127
+            }
128
+        }
129
+        String[] result = new String[emptyNames.size()];
130
+        return emptyNames.toArray(result);
131
+    }
132
+
133
+    public static void copyProperties(Object src, Object target) {
134
+        BeanUtils.copyProperties(src, target, getNullPropertyNames(src));
135
+    }
136
+
137
+}

+ 919
- 0
src/main/java/com/yunzhi/marketing/common/CommConstant.java Просмотреть файл

@@ -0,0 +1,919 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+public class CommConstant {
4
+    public final static String ALIOSS_DEFAULT_UPLOAD = "/miniapp/upload/images/";
5
+
6
+    /**
7
+     * 人员类型: 置业顾问
8
+     */
9
+    public final static String PERSON_REALTY_CONSULTANT = "Realty Consultant";
10
+
11
+    /**
12
+     * 人员类型: 销售主管
13
+     */
14
+    public final static String PERSON_SALES_EXECUTIVE = "Sales Executive";
15
+
16
+    /**
17
+     * 人员类型: 经纪人
18
+     */
19
+    public final static String PERSON_ESTATE_AGENT = "estate agent";
20
+
21
+    /**
22
+     * 人员类型: 客户
23
+     */
24
+    public final static String PERSON_ESTATE_CUSTOMER = "customer";
25
+
26
+    /**
27
+     * 人员类型: 渠道经纪人
28
+     */
29
+    public final static String PERSON_ESTATE_CHANNEL = "channel agent";
30
+
31
+    /**
32
+     * 人员类型: 游客
33
+     */
34
+    public final static String PERSON_ESTATE_DRIFT = "drift";
35
+
36
+    /**
37
+     * 状态: 正常
38
+     */
39
+    public final static Integer STATUS_NORMAL = 1;
40
+
41
+    /**
42
+     * 状态: 删除
43
+     */
44
+    public final static Integer STATUS_DELETE = -1;
45
+
46
+    /**
47
+     * 状态: 关闭、禁用
48
+     */
49
+    public final static Integer STATUS_CLOSED = 9;
50
+
51
+    /**
52
+     * 消息未读
53
+     */
54
+    public final static Integer MESSAGE_UNREAD = 0;
55
+
56
+    /**
57
+     * 消息已读
58
+     */
59
+    public final static Integer MESSAGE_READED = 1;
60
+
61
+    /**
62
+     * 点赞置业卡片
63
+     */
64
+    public final static String FAVOR_CONSULTANT = "consultant";
65
+
66
+    /**
67
+     * 点赞资讯
68
+     */
69
+    public final static String FAVOR_NEWS = "news";
70
+
71
+    /**
72
+     * 点赞项目
73
+     */
74
+    public final static String FAVOR_PROJECT = "project";
75
+
76
+    /**
77
+     * 活动点赞
78
+     */
79
+    public final static String FAVOR_ACTIVITY = "activity";
80
+
81
+
82
+    /**
83
+     * 兑换商品
84
+     */
85
+    public final static String POINTS_CHANGE_GOODS = "goods";
86
+
87
+    /**
88
+     * 签到
89
+     */
90
+    public final static String POINTS_CHANGE_CHECKIN = "checkin";
91
+
92
+    /**
93
+     * 分享
94
+     */
95
+    public final static String POINTS_CHANGE_SHARE_POSTER = "share-poster";
96
+
97
+    /**
98
+     * 授权手机号
99
+     */
100
+    public final static String POINTS_CHANGE_SIGNUP_AGENT = "signup-agent";
101
+
102
+    /**
103
+     * 拼团
104
+     */
105
+    public final static String POINTS_CHANGE_GROUP = "group";
106
+
107
+    /**
108
+     * 拼团
109
+     */
110
+    public final static String POINTS_CHANGE_HELP = "help";
111
+
112
+    /**
113
+     * 推荐客户
114
+     */
115
+    public final static String POINTS_CHANGE_RECOMMEND_CUSTOMER = "recommend-customer";
116
+
117
+    /**
118
+     * 活动核销
119
+     */
120
+    public final static String POINTS_CHANGE_ACTIVITY_VERIFICATION = "activity_verification";
121
+
122
+    /**
123
+     * 资料审核
124
+     */
125
+    public final static String POINTS_CHANGE_DOCUMENT_VERIFY = "document_verify";
126
+
127
+    /**
128
+     * 活动签到
129
+     */
130
+    public final static String POINTS_CHANGE_ACTIVITY_CHECKIN = "activity_checkin";
131
+
132
+
133
+    /**
134
+     * 小程序默认首页
135
+     */
136
+    public final static String MINIAPP_INDEX = "/index/index";
137
+
138
+    public final static String MINIAPP_DEFAULT_AVATAR = "https://njcj.oss-cn-shanghai.aliyuncs.com/miniapp/upload/images/default_avatar.jpg";
139
+
140
+
141
+    /**
142
+     * 未领取
143
+     */
144
+    public static final Integer STATUS_UNACCALIMED = 0;
145
+
146
+    /**
147
+     * 成功
148
+     */
149
+    public static final String SUCCESS = "success";
150
+
151
+
152
+    /**
153
+     * 活动的当前状态1:进行中
154
+     */
155
+    public static final Integer ACTIVITY_CONDITION_PROCESSING = 1;
156
+
157
+    /**
158
+     * 活动的当前状态2:未开始
159
+     */
160
+    public static final Integer ACTIVITY_CONDITION_PREPARE = 2;
161
+
162
+    /**
163
+     * 活动的当前状态3:结束
164
+     */
165
+    public static final Integer ACTIVITY_CONDITION_FINISH = 3;
166
+
167
+    //=================  首屏广告 / 轮播图 start =======================
168
+
169
+    /**
170
+     * 首页 轮播图/广告 类型 ====  活动
171
+     */
172
+    public static final String CAROUSEL_ACTIVITY = "activity";
173
+
174
+    /**
175
+     * 首页 轮播图/广告 类型 ==== 项目
176
+     */
177
+    public static final String CAROUSEL_PROJECT = "project";
178
+
179
+    /**
180
+     * 首页轮播图/广告 类型 ==== 资讯
181
+     */
182
+    public static final String CAROUSEL_NEWS = "news";
183
+
184
+    /**
185
+     * 首页轮播图/广告 类型 ==== 其他
186
+     */
187
+    public static final String CAROUSEL_OTHER = "other";
188
+
189
+    /**
190
+     * 打开放式_开屏
191
+     */
192
+    public static final String OPEN_SCREEN = "screen";
193
+
194
+    /**
195
+     * 打开放式_首页轮播图
196
+     */
197
+    public static final String CAROUSEL = "banner";
198
+
199
+    /**
200
+     * 首屏广告_发布位置——商城
201
+     */
202
+    public static final String MALL = "mall";
203
+
204
+    /**
205
+     * 首屏广告_发布位置——首页
206
+     */
207
+    public static final String BANNER_INDEX = "index";
208
+
209
+    /**
210
+     * 首屏广告_发布位置——项目
211
+     */
212
+    public static final String BANNER_BUILDING = "building";
213
+
214
+    //首页资讯
215
+    public static final String INDEX_NEWS = "indexNews";
216
+
217
+    //首页分享类型
218
+    public static final String IMG_TYPE = "imgType";
219
+
220
+    //=================  首屏广告 / 轮播图 end =======================
221
+
222
+    /**
223
+     * 客户报备
224
+     */
225
+    public static final Integer CUSTOMER_REPORT = 1;
226
+
227
+    /**
228
+     * 客户到访
229
+     */
230
+    public static final Integer CUSTOMER_VISITE = 2;
231
+
232
+    /**
233
+     * 客户认购
234
+     */
235
+    public static final Integer CUSTOMER_PREORDER = 3;
236
+
237
+    /**
238
+     * 客户签约
239
+     */
240
+    public static final Integer CUSTOMER_SIGNED = 4;
241
+
242
+
243
+    /**
244
+     * 待审核
245
+     */
246
+    public static final Integer VERIFY_READY = 0;
247
+
248
+    /**
249
+     * 审核同意
250
+     */
251
+    public static final Integer VERIFY_AGREE = 1;
252
+
253
+    /**
254
+     * 审核不同意
255
+     */
256
+    public static final Integer VERIFY_DISAGREE = 2;
257
+
258
+    //=================  客户入口类型 start =======================
259
+    /*
260
+     * 自主进入
261
+     * */
262
+    public static final String ENTRY_VOLUNTEER = "volunteer";
263
+    /*
264
+    添加
265
+    */
266
+    public static final String ENTRY_INPUT = "input";
267
+    /*
268
+     * 报备
269
+     * */
270
+    public static final String ENTRY_VERIFY = "verify";
271
+    //=================  客户入口类型 end =======================
272
+
273
+    /**
274
+     * 积分规则开启
275
+     */
276
+    public static final Integer POINTS_RULE_ON = 1;
277
+
278
+    /**
279
+     * 积分规则关闭
280
+     */
281
+    public static final Integer POINTS_RULE_OFF = 0;
282
+
283
+    /**
284
+     * 签到积分规则
285
+     */
286
+    public static final Integer POINTS_RULE_CHECKIN = 1;
287
+
288
+    /**
289
+     * 分享海报积分规则
290
+     */
291
+    public static final Integer POINTS_RULE_SHARE_POSTER = 2;
292
+
293
+    /**
294
+     * 推荐客户积分规则
295
+     */
296
+    public static final Integer POINTS_RULE_RECOMMENDER_CUSTOMER = 3;
297
+
298
+    /**
299
+     * 注册经纪人积分规则
300
+     */
301
+    public static final Integer POINTS_RULE_SIGNUP_AGENT = 4;
302
+
303
+    /**
304
+     * 活动核销送积分规则
305
+     */
306
+    public static final Integer POINTS_RULE_ACTIVITY_VERIFICATION = 6;
307
+
308
+    /**
309
+     * 资料审核送积分规则
310
+     */
311
+    public static final Integer POINTS_RULE_DOCUMENT_VERIFY = 7;
312
+
313
+    /**
314
+     * 普通活动签到送积分规则
315
+     */
316
+    public static final Integer POINTS_RULE_ACTIVITY_CHECKIN = 8;
317
+
318
+    /**
319
+     * 平台积分
320
+     */
321
+    public static final String POINTS_RULE_PLATFORM = "platform";
322
+
323
+    /**
324
+     * 项目积分
325
+     */
326
+    public static final String POINTS_RULE_PROJECT = "project";
327
+
328
+
329
+    // ----   用户活跃数  查询条件 start ------
330
+
331
+    public static final String DAY = "day";
332
+
333
+    public static final String WEEK = "week";
334
+
335
+    public static final String MONTH = "month";
336
+
337
+    // ----     查询条件 end ------
338
+
339
+    // -----   转化率 start -------
340
+
341
+    /**
342
+     * 项目收藏
343
+     */
344
+    public static final String BUILDING_SAVE = "building_save";
345
+
346
+    /**
347
+     * 项目转发
348
+     */
349
+    public static final String BUILDING_SHARE = "building_share";
350
+
351
+    /**
352
+     * 活动收藏
353
+     */
354
+    public static final String ACTIVITY_SAVE = "activity_save";
355
+
356
+    /**
357
+     * 活动转发
358
+     */
359
+    public static final String ACTIVITY_SHARE = "activity_share";
360
+
361
+    /**
362
+     * 咨迅收藏
363
+     */
364
+    public static final String NEWS_SAVE = "news_save";
365
+
366
+    /**
367
+     * 咨迅转发
368
+     */
369
+    public static final String NEWS_SHARE = "news_share";
370
+
371
+    /**
372
+     * 活动报名
373
+     */
374
+    public static final String ACTIVITY_SIGN = "activity_sign";
375
+
376
+    /**
377
+     * 授权手机号
378
+     */
379
+    public static final String AUTHORIZATION_PHONE = "authorization_phone";
380
+
381
+    // ------   转化率 end ---------
382
+
383
+
384
+    // ------- 用户来源 查询条件 start ----------
385
+
386
+    public static final String REGISTERED_TYPE = "registered";
387
+
388
+    // ------- 用户来源 查询条件 end ----------
389
+
390
+    // ------- 性别 start -------
391
+    public static final Integer SEX_MALE = 1;
392
+    public static final Integer SEX_FEMALE = 2;
393
+    public static final Integer SEX_UNKNOWN = 3;
394
+    // ------- 性别 end -------
395
+
396
+    // ------- 推荐客户状态 start -------
397
+    // 到访
398
+    public static final Integer RECOMMEND_CUSTOMER_STATUS_ARRIVAL = 1;
399
+    // 签约
400
+    public static final Integer RECOMMEND_CUSTOMER_STATUS_SIGN = 2;
401
+    //
402
+    public static final Integer RECOMMEND_CUSTOMER_STATUS_PRE_ORDER = 2;
403
+    // ------- 推荐客户状态 end -------
404
+
405
+
406
+    // ------- 客户推荐报备状态 start -------
407
+    // 未报备,未推荐
408
+    public static final Integer READY = 0;
409
+    // 已报备
410
+    public static final Integer REPORTED = 1;
411
+    // 已推荐
412
+    public static final Integer RECOMMENDED = 2;
413
+    // ------- 客户推荐报备状态 end -------
414
+
415
+    // ------- 政策发布状态 start -------
416
+    // 已发布
417
+    public static final Integer IS_PUBLISH = 1;
418
+    // 未发布
419
+    public static final Integer NOT_PUBLISH = 0;
420
+    // ------- 政策发布状态 end -------
421
+
422
+    // 公客
423
+    public static final String CUTOMER_TYPE_PUBLIC = "public";
424
+    // 私客
425
+    public static final String CUTOMER_TYPE_PRIVATE = "private";
426
+
427
+
428
+    //项目
429
+    public static final String POSTER_CONTENT_TYPE_BUILDING = "building";
430
+    //活动
431
+    public static final String POSTER_CONTENT_TYPE_ACTIVITY = "activity";
432
+    //资讯
433
+    public static final String POSTER_CONTENT_TYPE_NEWS = "news";
434
+    //人员
435
+    public static final String POSTER_CONTENT_TYPE_PERSON = "person";
436
+
437
+
438
+    public static final String GD_KEY = "c9fc664a9030aed2ec2183508c2ca476";
439
+
440
+    //已参与微信端用
441
+    public static final Integer ACTIVITY_STATUS_PARTNER = 3;
442
+
443
+    //发起者
444
+    public static final String HELP_STATUS_INITIATE = "Initiate";
445
+
446
+    //助力活动
447
+    public static final Object HELP_ACTIVITY = "helpActivity";
448
+
449
+    //分享活动
450
+    public static final Object GROUP_ACTIVITY = "groupActivity";
451
+    public static final String TARGET_TYPE_H5 = "H5";
452
+    public static final String ACTIVITY_QRCODE = "{\"scene\":\"id=#0&type=#1\",\"page\":\"pages/checkin/index\"}";
453
+    public static final String LIVE_ACTIVITY_QRCODE = "{\"scene\":\"id=#0&type=#1\",\"page\":\"onlineSelling/pages/live/index\"}";
454
+    public static final String DRAINAGE_QRCODE = "{\"scene\":\"id=#0&type=#1\",\"page\":\"pages/project/h5Page\"}";
455
+    public static final String HOUSE_QRCODE = "{\"scene\":\"id=#0&type=#1\",\"page\":\"onlineSelling/pages/houseList/index\"}";
456
+
457
+    /**
458
+     * 消息通知
459
+     * 必须存在表   td_miniapp_template_type 中
460
+     */
461
+    public static final String MESSAGE_CONTENT_OF_NOTICE = "notice";
462
+
463
+    /**
464
+     * 需求通知
465
+     * 必须存在表   td_miniapp_template_type 中
466
+     */
467
+    public static final String MESSAGE_CONTENT_OF_DEMAND = "demand";
468
+
469
+    /**
470
+     * 助力通知
471
+     * 必须存在表   td_miniapp_template_type 中
472
+     */
473
+    public static final String MESSAGE_CONTENT_OF_HELP = "help-result";
474
+
475
+    /**
476
+     * 拼团通知
477
+     * 必须存在表   td_miniapp_template_type 中
478
+     */
479
+    public static final String MESSAGE_CONTENT_OF_GROUP = "group-result";
480
+
481
+    /**
482
+     * 审核通知  预选/认筹
483
+     * 必须存在表   td_miniapp_template_type 中
484
+     */
485
+    public static final String MESSAGE_CONTENT_OF_HOUSE = "house";
486
+
487
+    /**
488
+     * 合同签订通知
489
+     * 必须存在表   td_miniapp_template_type 中
490
+     */
491
+    public static final String MESSAGE_CONTRACT_SIGNING = "contract-signing";
492
+
493
+    /**
494
+     * 官网推广
495
+     */
496
+    public static final String MESSAGE_CONTENT_OF_OFFICE_PROMOTION = "office-promotion";
497
+
498
+    /**
499
+     * 活动以结束
500
+     */
501
+    public static final Integer ACTIVITY_STATUS_FINISH = 2;
502
+
503
+    /**
504
+     * 客户统计类型:跟进客户
505
+     */
506
+    public static final String CUSTOMER_TYPE_FOLLOW = "follow";
507
+
508
+    /**
509
+     * 客户统计类型:新增客户
510
+     */
511
+    public static final String CUSTOMER_TYPE_NEW = "new";
512
+
513
+    /**
514
+     * 客户统计类型:到访客户
515
+     */
516
+    public static final String CUSTOMER_TYPE_VISITE = "visite";
517
+
518
+    // =================   项目图片类型 ==============
519
+
520
+    /**
521
+     * 项目banner
522
+     */
523
+    public static final String BUILDING_IMG_BANNER = "banner";
524
+
525
+    /**
526
+     * 项目列表图(现在是用于楼盘封面图)
527
+     */
528
+    public static final String BUILDING_IMG_LIST = "list";
529
+
530
+    /**
531
+     * 视频封面图
532
+     */
533
+    public static final String BUILDING_IMG_VIDEOIMAGE = "videoImage";
534
+
535
+    /**
536
+     * 户型图
537
+     */
538
+    public static final String BUILDING_IMG_APARMENT = "aparment";
539
+
540
+    /**
541
+     * 高德地图url
542
+     */
543
+    public static final String AMAP_HTTP = "https://restapi.amap.com/v3/geocode/regeo";
544
+
545
+    /**
546
+     * 高德地图key
547
+     */
548
+    public static final String AMAP_KEY = "14f05ce59c26364fd0674014dc0d8b1b";
549
+
550
+    /**
551
+     * 埋点类型h5
552
+     */
553
+    public static final String EVENT_H5 = "h5";
554
+
555
+    /**
556
+     * 房源分享
557
+     */
558
+    public static final String HOUSE = "house";
559
+
560
+
561
+    /**
562
+     * 首页分享
563
+     */
564
+    public static final String INDEX = "index";
565
+
566
+
567
+    /**
568
+     * 批量销售
569
+     */
570
+    public static final String SALES_BATCH = "salesBatch";
571
+
572
+    /**
573
+     * 直播分享
574
+     */
575
+    public static final String LIVE = "live";
576
+
577
+    /**
578
+     * 红包类型标识
579
+     */
580
+    public static final String RED_PACKET = "RedPacket";
581
+
582
+    /**
583
+     * 系统参数  通知消息次时间间隔
584
+     */
585
+    public static final String SYSPARAM_NOTICE_MESSAGE_INTERVAL = "notice_message_interval";
586
+
587
+    /**
588
+     * 任一消息, 可以是下面的任意一种
589
+     */
590
+    public static final String MESSAGE_TYPE_OF_SOMEWAY = "someway";
591
+
592
+    /**
593
+     * 短信消息
594
+     */
595
+    public static final String MESSAGE_TYPE_OF_SMS = "sms";
596
+
597
+    /**
598
+     * 小程序订阅消息
599
+     */
600
+    public static final String MESSAGE_TYPE_OF_MINIAPP_SUBSCRIBE = "miniapp_subscribe";
601
+
602
+    /**
603
+     * 小程序模板消息
604
+     */
605
+    public static final String MESSAGE_TYPE_OF_MINIAPP_TEMPLATE = "miniapp_template";
606
+
607
+    /**
608
+     * 进入小程序
609
+     */
610
+    public static final String BIZ_EVENT_START = "start";
611
+
612
+    /**
613
+     * 登录渠道端系统类型
614
+     */
615
+    public static final String LOGIN_TYPE_CHANNEL = "channel";
616
+
617
+    /**
618
+     * 登录业务端系统类型
619
+     */
620
+    public static final String LOGIN_TYPE_ADMIN = "admin";
621
+
622
+
623
+    /**
624
+     * 登录中心端系统类型
625
+     */
626
+    public static final String LOGIN_TYPE_CENTER = "center";
627
+
628
+
629
+    /**
630
+     * 查看分享者活动类型 h5
631
+     */
632
+    public static final String H5_SHARE = "h5_share";
633
+
634
+    /**
635
+     * 查看分享者活动类型 拼团
636
+     */
637
+    public static final String GROUP_SHARE = "group_share";
638
+
639
+    /**
640
+     * 查看分享者活动类型 助力
641
+     */
642
+    public static final String HELP_SHARE = "help_share";
643
+
644
+    /**
645
+     * 查看分享者活动类型 活动
646
+     */
647
+    public static final String DYNAMIC_SHARE = "dynamic_share";
648
+
649
+    /**
650
+     * 户型
651
+     */
652
+    public static final String APARTMENT_TYPR_APART = "apart";
653
+
654
+    /**
655
+     * 户型全景图
656
+     */
657
+    public static final String PANORAMA_TYPE_APARTMENT = "apartment";
658
+
659
+    /**
660
+     * 价格类型 均价
661
+     */
662
+    public static final String PRICE_TYPE_AVERAGE = "average";
663
+
664
+    /**
665
+     * excel后缀
666
+     */
667
+    public static final String SUFFIX_2003 = ".xls";
668
+    public static final String SUFFIX_2007 = ".xlsx";
669
+
670
+    /**
671
+     * 小程序房源详情路径
672
+     */
673
+    public static final String HOUSE_DETAIL_PATH = "onlineSelling/pages/detail/index?id=%s";
674
+
675
+    public static final String RAISE_DETAIL_PATH = "/onlineSelling/pages/raiseProfile/index?id=%s";
676
+
677
+    /**
678
+     * 已锁定
679
+     */
680
+    public static final String HOUSE_LOCKING_STATUS_LOCKED = "locked";
681
+
682
+    /**
683
+     * 未锁定
684
+     */
685
+    public static final String HOUSE_LOCKING_STATUS_UNLOCKED = "unlocked";
686
+
687
+    /**
688
+     * 房源订单
689
+     */
690
+    public static final String ORDER_TARGET_TYPE_HOUSE = "house";
691
+
692
+    /**
693
+     * 自动锁房
694
+     */
695
+    public static final String HOUSE_LOCKING_TYPE_AUTO = "auto";
696
+
697
+    /**
698
+     * 手动锁房
699
+     */
700
+    public static final String HOUSE_LOCKING_TYPE_MANUAL = "manual";
701
+
702
+    /**
703
+     * 正在缴费
704
+     */
705
+    public static final String PAY_STATUS_PAYING = "paying";
706
+
707
+    /**
708
+     * 未缴费
709
+     */
710
+    public static final String PAY_STATUS_UNPAID = "unpaid";
711
+
712
+    /**
713
+     * 已缴费
714
+     */
715
+    public static final String PAY_STATUS_PAID = "paid";
716
+
717
+    /**
718
+     * 已退费
719
+     */
720
+    public static final String PAY_STATUS_REFUNDED = "refunded";
721
+
722
+    /**
723
+     * 退款异常
724
+     */
725
+    public static final String PAY_STATUS_CHANGE = "change";
726
+
727
+
728
+    /**
729
+     * 已经取消支付
730
+     */
731
+    public static final String PAY_STATUS_CANCEL = "cancel";
732
+
733
+    /**
734
+     * 支付超时
735
+     */
736
+    public static final String PAY_STATUS_TIMEOUT = "timeout";
737
+
738
+    /**
739
+     * 最大认筹金额
740
+     */
741
+    public static final Integer MAX_RAISE_PRICE = 5000000;
742
+
743
+    /**
744
+     * 菜单
745
+     */
746
+    public static final Object ADVANCED_TYPE_MENU = "menu";
747
+
748
+    /**
749
+     * 菜单
750
+     */
751
+    public static final Object ADVANCED_TYPE_BUTTON = "button";
752
+
753
+    /**
754
+     * 线下缴费
755
+     */
756
+    public static final String PAY_TYPE_OFFLINE = "offLine";
757
+
758
+    /**
759
+     * 线下缴费
760
+     */
761
+    public static final String PAY_TYPE_ONLINE = "onLine";
762
+
763
+    /**
764
+     * 作废状态
765
+     */
766
+    public static final Integer DEMAND_STATUS_INVALID = 4;
767
+
768
+
769
+    /**
770
+     * 已提交
771
+     */
772
+    public static final Integer DEMAND_STATUS_SUBMIT = 1;
773
+
774
+    /**
775
+     * 样例类型H5
776
+     */
777
+    public static final String NOTICE_TYPE_H5 = "H5";
778
+
779
+    /**
780
+     * 法大大账户类型  2 企业
781
+     */
782
+    public static final String ACCOUNT_TYPE_COMPANY = "2";
783
+
784
+    /**
785
+     * 企业在法大大的状态  已注册
786
+     */
787
+    public static final String CERTIFIED_STATUS_REGISTERED = "registered";
788
+
789
+    /**
790
+     * 企业在法大大的状态  认证中
791
+     */
792
+    public static final String CERTIFIED_STATUS_CERTIFICATION = "certification";
793
+
794
+    /**
795
+     * 企业认证人员的身份 法人
796
+     */
797
+    public static final String COMPANY_MANAGER_TYPE_LEGAL = "legal";
798
+
799
+
800
+    /**
801
+     * 企业认证人员的身份 代理人
802
+     */
803
+    public static final String COMPANY_MANAGER_TYPE_AGENT = "agent";
804
+
805
+    /**
806
+     * 企业认证人员的身份 1 法人
807
+     */
808
+    public static final String COMPANY_PRINCIPAL_TYPE_LEGAL = "1";
809
+
810
+    /**
811
+     * 企业认证人员的身份 2 代理人
812
+     */
813
+    public static final String COMPANY_PRINCIPAL_TYPE_AGENT = "2";
814
+
815
+    /**
816
+     * 授权类型 1自动签
817
+     */
818
+    public static final Integer AUTH_TYPE = 1;
819
+
820
+    /**
821
+     * 合同关联业务类型
822
+     */
823
+    public static final String AUTH = "auth";
824
+
825
+    /**
826
+     * 接口线上授权
827
+     */
828
+    public static final String ONLINEAUTH = "onLine";
829
+
830
+    /**
831
+     * 企业实名状态
832
+     */
833
+    public static final Integer REAL_NAME_STATUS = 4;
834
+
835
+    /**
836
+     * 已授权自动签章
837
+     */
838
+    public static final String AUTO_AUTH_STATUS = "3000";
839
+
840
+    public static final String AUTO_UNAUTH_STATUS = "3001";
841
+
842
+    public static final String AUTH_SUCCESS_DESC = "签章成功";
843
+
844
+    /**
845
+     * 审核通过
846
+     */
847
+    public static final Integer STATUS_VERIFY_PASS = 4;
848
+
849
+    /**
850
+     * 充值操作
851
+     */
852
+    public static final String RECHARGE = "CZ";
853
+
854
+    /**
855
+     * 退款操作
856
+     */
857
+    public static final String REFUND = "TK";
858
+
859
+    /**
860
+     * 明细类型--充值
861
+     */
862
+    public static final String ITEM_TYPE_RECHARGE = "recharge";
863
+
864
+    /**
865
+     * 明细类型--退费
866
+     */
867
+    public static final String ITEM_TYPE_REFUND = "refund";
868
+
869
+    /**
870
+     * 明细类型--退费
871
+     */
872
+    public static final String ITEM_TYPE_REJECT = "reject";
873
+
874
+
875
+    /**
876
+     * 明细类型--红包
877
+     */
878
+    public static final String ITEM_TYPE_REDPACKAGE = "RedPacket";
879
+
880
+    /**
881
+     * 交易状态 成功
882
+     */
883
+    public static final String TRADING_STATUS_SUCCESS = "success";
884
+
885
+    /**
886
+     * 交易状态 失败
887
+     */
888
+    public static final String TRADING_STATUS_FAIL = "fail";
889
+
890
+    /**
891
+     * 交易状态 进行中
892
+     */
893
+    public static final String TRADING_STATUS_PROCESSING = "processing";
894
+
895
+    /**
896
+     * 人员类型---财务
897
+     */
898
+    public static final String CONTACT_FINANCE = "finance";
899
+
900
+    /**
901
+     * 人员类型---售前
902
+     */
903
+    public static final String CONTACT_PRESALE = "pre-sale";
904
+
905
+    /**
906
+     * 审核状态-审核中
907
+     */
908
+    public static final String CHECK_STATUS_CHECKING = "checking";
909
+
910
+    /**
911
+     * 微信商户手续费率
912
+     */
913
+    public static final Double WXMCH_PAY_RATE = 0.01;
914
+
915
+    /**
916
+     * 微信商户手续费率-前端展示
917
+     */
918
+    public static final String WXMCH_PAY_RATE_STRING = "1%";
919
+}

+ 86
- 0
src/main/java/com/yunzhi/marketing/common/CommonUtils.java Просмотреть файл

@@ -0,0 +1,86 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import java.math.BigDecimal;
4
+import java.text.SimpleDateFormat;
5
+import java.util.Date;
6
+import java.util.Random;
7
+import java.util.UUID;
8
+import java.util.regex.Matcher;
9
+import java.util.regex.Pattern;
10
+
11
+public class CommonUtils {
12
+    /**
13
+     * 金额校验
14
+     *
15
+     * @param str
16
+     * @return
17
+     */
18
+    public static boolean isAmount(String str) {
19
+        Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$"); // 判断小数点后2位的数字的正则表达式
20
+        Matcher match = pattern.matcher(str);
21
+        if (match.matches() == false) {
22
+            return false;
23
+        } else {
24
+            return true;
25
+        }
26
+    }
27
+
28
+
29
+    /**
30
+     * 获取uuid
31
+     *
32
+     * @return
33
+     */
34
+    public static String getUUIDS() {
35
+        String uuid = UUID.randomUUID().toString().replace("-", "");
36
+        return uuid;
37
+    }
38
+
39
+    /**
40
+     * 生成订单号
41
+     *
42
+     * @param tradeType
43
+     * @return
44
+     */
45
+    public static String generateTradeNo(String tradeType) {
46
+        String sdf = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
47
+        int randNum = (int) (new Random().nextDouble() * (9999 - 1000 + 1)) + 1000;// 获取5位随机数
48
+        return tradeType + sdf + randNum;
49
+    }
50
+
51
+    /**
52
+     * 元转分
53
+     *
54
+     * @param money
55
+     * @return
56
+     */
57
+    public static Integer yuanToFen(Double money) {
58
+        Double moneyd = money * 100;
59
+        Integer moneyi = moneyd.intValue();
60
+        return moneyi;
61
+    }
62
+
63
+    /**
64
+     * 元转分
65
+     *
66
+     * @param money
67
+     * @return
68
+     */
69
+    public static Double fenToYuan(Integer money) {
70
+        return Double.parseDouble(BigDecimal.valueOf(Long.valueOf(money)).divide(new BigDecimal(100)).toString());
71
+    }
72
+
73
+    /**
74
+     * double减法运算,防止直接相减失去精度
75
+     *
76
+     * @param m1 减数
77
+     * @param m2 被减数
78
+     * @return
79
+     */
80
+    public static Double subDouble(double m1, double m2) {
81
+        BigDecimal p1 = new BigDecimal(Double.toString(m1));
82
+        BigDecimal p2 = new BigDecimal(Double.toString(m2));
83
+        return p1.subtract(p2).doubleValue();
84
+    }
85
+
86
+}

+ 15
- 0
src/main/java/com/yunzhi/marketing/common/DBUtils.java Просмотреть файл

@@ -0,0 +1,15 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import com.yunzhi.marketing.mapper.TaSequenceMapper;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.stereotype.Component;
6
+
7
+@Component
8
+public class DBUtils {
9
+    @Autowired
10
+    TaSequenceMapper taSequenceMapper;
11
+
12
+    public Integer nextVal(String seqName) {
13
+        return taSequenceMapper.nextval(seqName);
14
+    }
15
+}

+ 117
- 0
src/main/java/com/yunzhi/marketing/common/DateUtils.java Просмотреть файл

@@ -0,0 +1,117 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import java.time.Duration;
4
+import java.time.Instant;
5
+import java.time.LocalDateTime;
6
+import java.time.ZoneId;
7
+import java.time.format.DateTimeFormatter;
8
+import java.util.Date;
9
+
10
+public class DateUtils {
11
+    public static LocalDateTime date2LocalDateTime(Date date) {
12
+        Instant instant = date.toInstant();
13
+        ZoneId zone = ZoneId.systemDefault();
14
+        return LocalDateTime.ofInstant(instant, zone);
15
+    }
16
+
17
+    public static boolean sameDay(LocalDateTime d1, LocalDateTime d2) {
18
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
19
+        return d1.format(formatter).equals(d2.format(formatter));
20
+    }
21
+
22
+    public static String cutSecond(LocalDateTime dt) {
23
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
24
+        return dt.format(formatter);
25
+    }
26
+
27
+    public static String today() {
28
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
29
+        return LocalDateTime.now().format(formatter);
30
+    }
31
+
32
+    public static String todayCompact() {
33
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
34
+        return LocalDateTime.now().format(formatter);
35
+    }
36
+
37
+    public static String localDateTimeToString(LocalDateTime d) {
38
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
39
+        return d.format(formatter);
40
+    }
41
+
42
+    public static LocalDateTime day2LocalDateime(String day) {
43
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
44
+        return LocalDateTime.parse(day + " 00:00:00", df);
45
+    }
46
+
47
+    public static LocalDateTime dayToLocalDateime(String day) {
48
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
49
+        return LocalDateTime.parse(day, df);
50
+    }
51
+
52
+    public static boolean checkTimeRange(LocalDateTime start, LocalDateTime end, LocalDateTime dt) {
53
+        if (dt == null) {
54
+            dt = LocalDateTime.now();
55
+        }
56
+
57
+        if (dt.isAfter(start) && dt.isBefore(end)) {
58
+            return true;
59
+        }
60
+        return false;
61
+    }
62
+
63
+    /**
64
+     * 当前时间是否早于指定时间
65
+     *
66
+     * @param target
67
+     * @return
68
+     */
69
+    public static boolean isBefore(String target) {
70
+        LocalDateTime dt = LocalDateTime.now();
71
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
72
+        LocalDateTime targetTime = LocalDateTime.parse(target, df);
73
+        if (dt.isBefore(targetTime)) {
74
+            return true;
75
+        }
76
+        return false;
77
+    }
78
+
79
+    /**
80
+     * 当前时间是否晚于指定时间
81
+     *
82
+     * @param target
83
+     * @return
84
+     */
85
+    public static boolean isAfter(String target) {
86
+        LocalDateTime dt = LocalDateTime.now();
87
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
88
+        LocalDateTime targetTime = LocalDateTime.parse(target, df);
89
+        if (dt.isAfter(targetTime)) {
90
+            return true;
91
+        }
92
+        return false;
93
+    }
94
+
95
+    /**
96
+     * 获取时间差
97
+     *
98
+     * @param dt1
99
+     * @param dt2 目标时间
100
+     * @return
101
+     */
102
+    public static String diffTime(LocalDateTime dt1, LocalDateTime dt2) {
103
+        Duration duration = Duration.between(dt1, dt2);
104
+        long minutes = duration.toMinutes();
105
+        int hours = (int) Math.floor(minutes / 60);
106
+        int minute = (int) minutes % 60;
107
+        int day = (int) Math.floor(hours / 24);
108
+        int hour = hours % 24;
109
+
110
+        return day + "天" + hour + "小时" + minute + "分钟";
111
+    }
112
+
113
+    public static LocalDateTime timeToLocalDateTime(String target){
114
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
115
+        return LocalDateTime.parse(target, df);
116
+    }
117
+}

+ 35
- 0
src/main/java/com/yunzhi/marketing/common/ExcelUtils.java Просмотреть файл

@@ -0,0 +1,35 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import com.alibaba.excel.EasyExcel;
4
+import com.alibaba.excel.ExcelWriter;
5
+import com.alibaba.excel.write.metadata.WriteSheet;
6
+import com.yunzhi.marketing.excel.handler.CustomCellWriteHandler;
7
+
8
+import javax.servlet.http.HttpServletResponse;
9
+import java.io.IOException;
10
+import java.util.List;
11
+
12
+public class ExcelUtils {
13
+
14
+    /**
15
+     * 发送 excel 到客户端
16
+     * 暂时只支持单 sheet 页
17
+     * @param response
18
+     * @param data
19
+     * @param fileName
20
+     * @throws IOException
21
+     */
22
+    public static void flush(HttpServletResponse response, Class dataClass, List data, String fileName) throws IOException {
23
+        response.setContentType("application/octet-stream");
24
+        response.setCharacterEncoding("utf-8");
25
+        response.setHeader("Content-disposition", "attachment;filename="+StringUtils.strToUnicode(fileName)+".xlsx");
26
+
27
+//        ParameterizedType type = (ParameterizedType) data.getClass().getGenericSuperclass();
28
+//        Class dataClass = (Class) type.getActualTypeArguments()[0];
29
+
30
+        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), dataClass).registerWriteHandler(new CustomCellWriteHandler()).build();
31
+        WriteSheet sheet1 = EasyExcel.writerSheet("sheet1").build();
32
+        excelWriter.write(data, sheet1);
33
+        excelWriter.finish();
34
+    }
35
+}

+ 109
- 0
src/main/java/com/yunzhi/marketing/common/JWTUtils.java Просмотреть файл

@@ -0,0 +1,109 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import io.jsonwebtoken.Jwts;
4
+import io.jsonwebtoken.security.Keys;
5
+
6
+import javax.servlet.http.HttpServletRequest;
7
+import java.security.Key;
8
+import java.util.Calendar;
9
+import java.util.Date;
10
+import java.util.Map;
11
+
12
+/**
13
+ * JWTUtils
14
+ * jwt 辅助类
15
+ * https://github.com/jwtk/jjwt
16
+ */
17
+public class JWTUtils {
18
+    // 直接定义常量是不安全的
19
+    public final static Key key = Keys.hmacShaKeyFor("yansenisahero,2019-5-17 16:18:14".getBytes());
20
+    
21
+    /**
22
+     * getSubject 获取 jwt subject
23
+     * @param request
24
+     * @return
25
+     */
26
+    public static String getSubject(HttpServletRequest request) {
27
+        String jwtHeader = request.getHeader("authorization");
28
+        if (null == jwtHeader || "".equals(jwtHeader.trim())) return null;
29
+
30
+        String[] jwtAuths = jwtHeader.split("Bearer ");
31
+        if (null == jwtAuths || jwtAuths.length < 2) return null;
32
+
33
+        try {
34
+            return Jwts.parser().setSigningKey(key).parseClaimsJws(jwtAuths[1]).getBody().getSubject();
35
+        } catch (Exception e) {
36
+            e.printStackTrace();
37
+        }
38
+
39
+        return null;
40
+    }
41
+    
42
+    /**
43
+     * getSubject 获取 jwt subject
44
+     * @param request
45
+     * @return
46
+     */
47
+    public static Map getUserIdAndOrgId(HttpServletRequest request) {
48
+        String jwtHeader = request.getHeader("authorization");
49
+        if (null == jwtHeader || "".equals(jwtHeader.trim())) return null;
50
+        
51
+        String[] jwtAuths = jwtHeader.split("Bearer ");
52
+        if (null == jwtAuths || jwtAuths.length < 2) return null;
53
+        
54
+        try {
55
+            return Jwts.parser().setSigningKey(key).parseClaimsJws(jwtAuths[1]).getBody();
56
+        } catch (Exception e) {
57
+            e.printStackTrace();
58
+        }
59
+        
60
+        return null;
61
+    }
62
+    
63
+    /**
64
+     * getSubject 获取 jwt subject
65
+     * @param request
66
+     * @return
67
+     */
68
+    public static String getToken(HttpServletRequest request) {
69
+        String jwtHeader = request.getHeader("authorization");
70
+        if (null == jwtHeader || "".equals(jwtHeader.trim())) {
71
+            return null;
72
+        }
73
+        
74
+        String[] jwtAuths = jwtHeader.split("Bearer ");
75
+        if (null == jwtAuths || jwtAuths.length < 2) {
76
+            return null;
77
+        }
78
+        
79
+        
80
+        return jwtAuths[1];
81
+    }
82
+
83
+    /**
84
+     * newToken 生成新的 token
85
+     * @param subject
86
+     * @return
87
+     */
88
+    public static String newToken(String subject) {
89
+        // 有效期 7 天
90
+        Calendar calendar = Calendar.getInstance();
91
+        calendar.setTime(new Date());
92
+        calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+7);
93
+        return Jwts.builder().setSubject(subject).setExpiration(calendar.getTime()).signWith(key).compact();
94
+    }
95
+    
96
+    /**
97
+     * newToken 生成新的 token
98
+     * @param subject
99
+     * @return
100
+     */
101
+    public static String newTokenByMap(Map subject) {
102
+        // 有效期 7 天
103
+        Calendar calendar = Calendar.getInstance();
104
+        calendar.setTime(new Date());
105
+        calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+7);
106
+
107
+        return Jwts.builder().setClaims(subject).setExpiration(calendar.getTime()).signWith(key).compact();
108
+    }
109
+}

+ 16
- 0
src/main/java/com/yunzhi/marketing/common/MD5Utils.java Просмотреть файл

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

+ 90
- 0
src/main/java/com/yunzhi/marketing/common/MiniAppPageEnum.java Просмотреть файл

@@ -0,0 +1,90 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+/**
4
+ * 小程序页面枚举
5
+ *
6
+ * @author gusy
7
+ * @date 2020/5/21 15:58
8
+ */
9
+public enum MiniAppPageEnum {
10
+
11
+    /**
12
+     * 项目
13
+     */
14
+    PROJECT("project", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "pages/project/detail/index"),
15
+
16
+    /**
17
+     * 报名活动
18
+     */
19
+    ACTIVITY("activity", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "pages/activity/detail/index"),
20
+
21
+    /**
22
+     * 助力活动
23
+     */
24
+    HELP("help", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "pages/activity/detail/assistance"),
25
+
26
+    /**
27
+     * 拼团活动
28
+     */
29
+    GROUP("group", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "pages/activity/detail/assemble"),
30
+
31
+    /**
32
+     * h5活动
33
+     */
34
+    H5("h5", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "pages/project/h5Page"),
35
+
36
+    /**
37
+     * 直播活动
38
+     */
39
+    LIVE("live", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "onlineSelling/pages/live/index"),
40
+
41
+    /**
42
+     * 资讯
43
+     */
44
+    NEWS("news", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "pages/news/detail/index"),
45
+
46
+    /**
47
+     * 在线选房
48
+     */
49
+    SALESBATCH("salesBatch", "id=%s&targetType=%S&channelId=%s&qrCodeId=%s&buildingId=%s", "onlineSelling/pages/houseList/index");
50
+
51
+    private String type;
52
+    private String scene;
53
+    private String page;
54
+
55
+    MiniAppPageEnum(String type, String scene, String page) {
56
+        this.type = type;
57
+        this.scene = scene;
58
+        this.page = page;
59
+    }
60
+
61
+    public String getType() {
62
+        return type;
63
+    }
64
+
65
+    public String getScene() {
66
+        return scene;
67
+    }
68
+
69
+    public String getPage() {
70
+        return page;
71
+    }
72
+
73
+    public static String getSceneByType(String type) {
74
+        for (MiniAppPageEnum pageEnum : MiniAppPageEnum.values()) {
75
+            if (type.equals(pageEnum.getType())) {
76
+                return pageEnum.getScene();
77
+            }
78
+        }
79
+        return null;
80
+    }
81
+
82
+    public static String getPageByType(String type) {
83
+        for (MiniAppPageEnum pageEnum : MiniAppPageEnum.values()) {
84
+            if (type.equals(pageEnum.getType())) {
85
+                return pageEnum.getPage();
86
+            }
87
+        }
88
+        return null;
89
+    }
90
+}

+ 18
- 0
src/main/java/com/yunzhi/marketing/common/NumberUtils.java Просмотреть файл

@@ -0,0 +1,18 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import java.math.BigDecimal;
4
+
5
+public class NumberUtils {
6
+    /**
7
+     * 元转分(乘以100)
8
+     * @param amount 金额 分(支持大数字,16位以上)
9
+     * @return
10
+     */
11
+    public static Integer yuanToFen(String amount){
12
+        return new BigDecimal(amount).multiply(new BigDecimal(100)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
13
+    }
14
+
15
+    public static String  fenToYuan(String price) {
16
+        return BigDecimal.valueOf(Long.valueOf(price)).divide(new BigDecimal(100)).toString();
17
+    }
18
+}

+ 165
- 0
src/main/java/com/yunzhi/marketing/common/SMSUtils.java Просмотреть файл

@@ -0,0 +1,165 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.yunzhi.marketing.config.SMSProperties;
5
+import com.yunzhi.marketing.entity.SysSmsSetting;
6
+import com.yunzhi.marketing.mapper.SysSmsSettingMapper;
7
+import lombok.Data;
8
+import lombok.extern.slf4j.Slf4j;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
11
+import org.springframework.context.annotation.Configuration;
12
+import org.springframework.http.*;
13
+import org.springframework.web.client.RestTemplate;
14
+
15
+import java.time.LocalDateTime;
16
+import java.util.*;
17
+
18
+@Slf4j
19
+@Configuration
20
+@EnableConfigurationProperties(SMSProperties.class)
21
+public class SMSUtils {
22
+    // 短信服务配置
23
+    SMSProperties smsProperties;
24
+
25
+    Hashtable<String, Phone> allPhones;
26
+
27
+    @Autowired
28
+    SysSmsSettingMapper sysSmsSettingMapper;
29
+
30
+    @Autowired
31
+    public SMSUtils(SMSProperties properties) {
32
+        smsProperties = properties;
33
+        allPhones = new Hashtable<>();
34
+    }
35
+
36
+    /**
37
+     * 发送验证码到 tel
38
+     * @param tel
39
+     * @return
40
+     */
41
+    public boolean sendCaptcha(String tel) {
42
+        Phone phone = allPhones.get(tel);
43
+        if (null == phone) {
44
+            phone = new Phone();
45
+            phone.setTel(tel);
46
+        }
47
+
48
+        phone.setCaptcha(genCaptcha(smsProperties.getCaptcha().getSize()));
49
+        phone.setExpire(LocalDateTime.now().plusSeconds(smsProperties.getCaptcha().getExpire()));
50
+        allPhones.put(tel, phone);
51
+
52
+        log.info("发送手机 {} 验证码 {}", tel, phone.getCaptcha());
53
+
54
+        String[] params = { phone.getCaptcha(), smsProperties.getCaptcha().getSign() };
55
+        return sendMessage(smsProperties.getCaptcha().getCode(), tel, params);
56
+    }
57
+
58
+    /**
59
+     * 校验验证码
60
+     * @param tel
61
+     * @param smsCaptcha
62
+     * @return
63
+     */
64
+    public boolean checkCaptcha(String tel, String smsCaptcha) {
65
+        Phone phone = allPhones.get(tel);
66
+        if (null == phone) {
67
+            log.error("手机号 {} 的验证码未找到", tel);
68
+            return false;
69
+        }
70
+
71
+        if (null == smsCaptcha || !smsCaptcha.equals(phone.getCaptcha())) {
72
+            log.error("手机号 {} 校验验证码出错, 正确: {}, 错误: {}", tel, phone.getCaptcha(), smsCaptcha);
73
+            return false;
74
+        }
75
+
76
+        LocalDateTime now = LocalDateTime.now();
77
+        if (now.isAfter(phone.getExpire())) {
78
+            log.error("手机号 {} 的验证码已过期", tel);
79
+            return false;
80
+        }
81
+
82
+        // 如果验证成功, 则从缓存中删除
83
+        allPhones.remove(tel);
84
+        return true;
85
+    }
86
+
87
+    public boolean sendVisitor(String tel, String name) {
88
+        log.info("发送手机 {} 客户名称 {}", tel, name);
89
+
90
+        String[] params = { name };
91
+        return sendMessage(smsProperties.getVisitor().getCode(), tel, params);
92
+    }
93
+
94
+    private String genCaptcha(int length) {
95
+        List<String> nums = new ArrayList<>();
96
+        for (int i = 0; i < length; i ++) {
97
+            int rand = (new Random()).nextInt(10);
98
+            nums.add(String.valueOf(rand));
99
+        }
100
+        return String.join("", nums);
101
+    }
102
+
103
+    public boolean sendMessage(String code, String tel, String[] params) {
104
+        // 发送内容
105
+        SMSProperties.Template message = new SMSProperties.Template();
106
+        message.setCode(code);
107
+        message.setTel(tel);
108
+        message.setParams(params);
109
+
110
+        // 构造 request
111
+        HttpHeaders headers = new HttpHeaders();
112
+        headers.setContentType(MediaType.parseMediaType(smsProperties.getContentType()));
113
+//        String body = JSONObject.toJSONString(message);
114
+        HttpMethod method = HttpMethod.resolve(smsProperties.getMethod());
115
+        HttpEntity requestEntity = new HttpEntity(message, headers);
116
+
117
+        RestTemplate template = new RestTemplate();
118
+        HttpEntity<String> response = template.exchange(
119
+                smsProperties.getUrl(),
120
+                method,
121
+                requestEntity,
122
+                String.class,
123
+                new Object()
124
+        );
125
+
126
+        if (((ResponseEntity<String>) response).getStatusCodeValue() != HttpStatus.OK.value()) {
127
+            log.error("请求发送短信失败: {}", response.toString());
128
+            return false;
129
+        }
130
+
131
+        return true;
132
+    }
133
+
134
+    public void sendMessage(String tel, List<String> params, String type) throws Exception {
135
+        if (StringUtils.isEmpty(tel) || StringUtils.isEmpty(type)) {
136
+            throw new Exception("短信发送失败: 没有手机号或者短信模板");
137
+        }
138
+
139
+        QueryWrapper<SysSmsSetting> query = new QueryWrapper<>();
140
+        query.eq("sms_type", type);
141
+        query.eq("status", CommConstant.STATUS_NORMAL);
142
+        query.last("limit 1");
143
+
144
+        SysSmsSetting smsSetting = sysSmsSettingMapper.selectOne(query);
145
+        if (null == smsSetting) {
146
+            throw new Exception("没有设置有效的【" + type + "】短信模板");
147
+        }
148
+
149
+        params.add("橙蕉"); // 短信签名
150
+        String[] paramArr = new String[params.size()];
151
+        params.toArray(paramArr);
152
+
153
+        boolean success = sendMessage(smsSetting.getTplCode(), tel, paramArr);
154
+        if (!success) {
155
+            throw new Exception("短信发送失败");
156
+        }
157
+    }
158
+
159
+    @Data
160
+    public static class Phone {
161
+        String tel;
162
+        String captcha;
163
+        LocalDateTime expire;
164
+    }
165
+}

+ 72
- 0
src/main/java/com/yunzhi/marketing/common/StringConverter.java Просмотреть файл

@@ -0,0 +1,72 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import jodd.typeconverter.TypeConversionException;
4
+import jodd.typeconverter.TypeConverter;
5
+import jodd.util.ArraysUtil;
6
+
7
+import java.sql.Clob;
8
+import java.sql.SQLException;
9
+import java.util.Date;
10
+
11
+public class StringConverter implements TypeConverter<String> {
12
+
13
+    public String convert(Object value) {
14
+        if (value == null) {
15
+            return null;
16
+        }
17
+
18
+        if (value instanceof CharSequence) { // for speed
19
+            return value.toString();
20
+        }
21
+        Class<?> type = value.getClass();
22
+        if (type == Class.class) {
23
+            return ((Class<?>) value).getName();
24
+        }
25
+        if (type.isArray()) {
26
+            if (type == char[].class) {
27
+                char[] charArray = (char[]) value;
28
+                return new String(charArray);
29
+            }
30
+            if (type == int[].class) {
31
+                return ArraysUtil.toString((int[]) value);
32
+            }
33
+            if (type == long[].class) {
34
+                return ArraysUtil.toString((long[]) value);
35
+            }
36
+            if (type == byte[].class) {
37
+                return ArraysUtil.toString((byte[]) value);
38
+            }
39
+            if (type == float[].class) {
40
+                return ArraysUtil.toString((float[]) value);
41
+            }
42
+            if (type == double[].class) {
43
+                return ArraysUtil.toString((double[]) value);
44
+            }
45
+            if (type == short[].class) {
46
+                return ArraysUtil.toString((short[]) value);
47
+            }
48
+            if (type == boolean[].class) {
49
+                return ArraysUtil.toString((boolean[]) value);
50
+            }
51
+            return ArraysUtil.toString((Object[]) value);
52
+        }
53
+        if (value instanceof Clob) {
54
+            Clob clob = (Clob) value;
55
+            try {
56
+                long length = clob.length();
57
+                if (length > Integer.MAX_VALUE) {
58
+                    throw new TypeConversionException("Clob is too big.");
59
+                }
60
+                return clob.getSubString(1, (int) length);
61
+            } catch (SQLException sex) {
62
+                throw new TypeConversionException(value, sex);
63
+            }
64
+        }
65
+        if (value instanceof Date) {
66
+            java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
67
+            return format1.format(value);
68
+        }
69
+
70
+        return value.toString();
71
+    }
72
+}

+ 108
- 0
src/main/java/com/yunzhi/marketing/common/StringUtils.java Просмотреть файл

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

+ 33
- 0
src/main/java/com/yunzhi/marketing/common/WxQrCodeUtils.java Просмотреть файл

@@ -0,0 +1,33 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import org.apache.commons.lang3.StringUtils;
5
+
6
+/**
7
+ * 微信二维码生成工具类
8
+ *
9
+ * @author gusy
10
+ * @date 2020/5/21 15:40
11
+ */
12
+public class WxQrCodeUtils {
13
+
14
+    /**
15
+     * 生成scene和页面
16
+     *
17
+     * @param type
18
+     * @param scene  为空则使用配置的通用模板
19
+     * @param params scene为空是必须按照模板内容填写
20
+     * @return
21
+     */
22
+    public static String generateSceneAndPage(String type, String scene, String... params) {
23
+        if (StringUtils.isBlank(scene)) {
24
+            String sceneTemplate = MiniAppPageEnum.getSceneByType(type);
25
+            scene = String.format(sceneTemplate, params);
26
+        }
27
+
28
+        JSONObject obj = new JSONObject();
29
+        obj.put("scene", scene);
30
+        obj.put("page", MiniAppPageEnum.getPageByType(type));
31
+        return obj.toJSONString();
32
+    }
33
+}

+ 59
- 0
src/main/java/com/yunzhi/marketing/common/WxUtils.java Просмотреть файл

@@ -0,0 +1,59 @@
1
+package com.yunzhi.marketing.common;
2
+
3
+import cn.binarywang.wx.miniapp.api.WxMaService;
4
+import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
5
+import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
6
+import com.yunzhi.marketing.entity.TaMiniapp;
7
+import com.yunzhi.marketing.service.IMiniAppService;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.stereotype.Component;
10
+
11
+import javax.annotation.PostConstruct;
12
+import java.util.List;
13
+import java.util.concurrent.ConcurrentHashMap;
14
+
15
+@Component
16
+public class WxUtils {
17
+    private ConcurrentHashMap<String, WxMaService> serives = new ConcurrentHashMap();
18
+
19
+    @Autowired
20
+    IMiniAppService iMiniAppService;
21
+
22
+    public WxMaService getMiniApp(String appid) {
23
+        return serives.get(appid);
24
+    }
25
+
26
+    @PostConstruct
27
+    public void init() {
28
+        System.out.println("-------------PostConstruct----------------");
29
+
30
+        List<TaMiniapp> taMiniappList = iMiniAppService.getAllAvaliableMiniapps();
31
+        if (null == taMiniappList) {
32
+            return;
33
+        }
34
+
35
+        for (TaMiniapp taMiniapp : taMiniappList) {
36
+            WxMaService service = newService(taMiniapp);
37
+            serives.put(taMiniapp.getMiniappId(), service);
38
+        }
39
+    }
40
+
41
+    public WxMaService newService(TaMiniapp taMiniapp, boolean ...changeServices) {
42
+        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
43
+        config.setAppid(taMiniapp.getMiniappId());
44
+        config.setSecret(taMiniapp.getSecret());
45
+        config.setToken(taMiniapp.getToken());
46
+        config.setAesKey(taMiniapp.getAesKey());
47
+        config.setMsgDataFormat("JSON");
48
+
49
+        WxMaService service = new WxMaServiceImpl();
50
+        service.setWxMaConfig(config);
51
+
52
+        if (changeServices.length > 0 && changeServices[0]) {
53
+            serives.remove(taMiniapp.getMiniappId());
54
+            serives.put(taMiniapp.getMiniappId(), service);
55
+        }
56
+
57
+        return service;
58
+    }
59
+}

+ 42
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/IWXPayDomain.java Просмотреть файл

@@ -0,0 +1,42 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+/**
4
+ * 域名管理,实现主备域名自动切换
5
+ */
6
+public abstract interface IWXPayDomain {
7
+    /**
8
+     * 上报域名网络状况
9
+     * @param domain 域名。 比如:api.mch.weixin.qq.com
10
+     * @param elapsedTimeMillis 耗时
11
+     * @param ex 网络请求中出现的异常。
12
+     *           null表示没有异常
13
+     *           ConnectTimeoutException,表示建立网络连接异常
14
+     *           UnknownHostException, 表示dns解析异常
15
+     */
16
+    abstract void report(final String domain, long elapsedTimeMillis, final Exception ex);
17
+
18
+    /**
19
+     * 获取域名
20
+     * @param config 配置
21
+     * @return 域名
22
+     */
23
+    abstract DomainInfo getDomain(final WXPayConfig config);
24
+
25
+    static class DomainInfo{
26
+        public String domain;       //域名
27
+        public boolean primaryDomain;     //该域名是否为主域名。例如:api.mch.weixin.qq.com为主域名
28
+        public DomainInfo(String domain, boolean primaryDomain) {
29
+            this.domain = domain;
30
+            this.primaryDomain = primaryDomain;
31
+        }
32
+
33
+        @Override
34
+        public String toString() {
35
+            return "DomainInfo{" +
36
+                    "domain='" + domain + '\'' +
37
+                    ", primaryDomain=" + primaryDomain +
38
+                    '}';
39
+        }
40
+    }
41
+
42
+}

+ 688
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPay.java Просмотреть файл

@@ -0,0 +1,688 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+
4
+import java.util.HashMap;
5
+import java.util.Map;
6
+
7
+public class WXPay {
8
+
9
+    private WXPayConfig config;
10
+    private WXPayConstants.SignType signType;
11
+    private boolean autoReport;
12
+    private boolean useSandbox;
13
+    private String notifyUrl;
14
+    private WXPayRequest wxPayRequest;
15
+
16
+    public WXPay(final WXPayConfig config) throws Exception {
17
+        this(config, null, true, false);
18
+    }
19
+
20
+    public WXPay(final WXPayConfig config, final boolean autoReport) throws Exception {
21
+        this(config, null, autoReport, false);
22
+    }
23
+
24
+
25
+    public WXPay(final WXPayConfig config, final boolean autoReport, final boolean useSandbox) throws Exception{
26
+        this(config, null, autoReport, useSandbox);
27
+    }
28
+
29
+    public WXPay(final WXPayConfig config, final String notifyUrl) throws Exception {
30
+        this(config, notifyUrl, true, false);
31
+    }
32
+
33
+    public WXPay(final WXPayConfig config, final String notifyUrl, final boolean autoReport) throws Exception {
34
+        this(config, notifyUrl, autoReport, false);
35
+    }
36
+
37
+    public WXPay(final WXPayConfig config, final String notifyUrl, final boolean autoReport, final boolean useSandbox) throws Exception {
38
+        this.config = config;
39
+        this.notifyUrl = notifyUrl;
40
+        this.autoReport = autoReport;
41
+        this.useSandbox = useSandbox;
42
+        //if (useSandbox) {
43
+            this.signType = WXPayConstants.SignType.MD5;
44
+        //}
45
+        //else {
46
+        //    this.signType = SignType.HMACSHA256;
47
+        //}
48
+        this.wxPayRequest = new WXPayRequest(config);
49
+    }
50
+
51
+    private void checkWXPayConfig() throws Exception {
52
+        if (this.config == null) {
53
+            throw new Exception("config is null");
54
+        }
55
+        if (this.config.getAppID() == null || this.config.getAppID().trim().length() == 0) {
56
+            throw new Exception("appid in config is empty");
57
+        }
58
+        if (this.config.getMchID() == null || this.config.getMchID().trim().length() == 0) {
59
+            throw new Exception("appid in config is empty");
60
+        }
61
+        if (this.config.getCertStream() == null) {
62
+            throw new Exception("cert stream in config is empty");
63
+        }
64
+        if (this.config.getWXPayDomain() == null){
65
+            throw new Exception("config.getWXPayDomain() is null");
66
+        }
67
+
68
+        if (this.config.getHttpConnectTimeoutMs() < 10) {
69
+            throw new Exception("http connect timeout is too small");
70
+        }
71
+        if (this.config.getHttpReadTimeoutMs() < 10) {
72
+            throw new Exception("http read timeout is too small");
73
+        }
74
+
75
+    }
76
+
77
+    /**
78
+     * 向 Map 中添加 appid、mch_id、nonce_str、sign_type、sign <br>
79
+     * 该函数适用于商户适用于统一下单等接口,不适用于红包、代金券接口
80
+     *
81
+     * @param reqData
82
+     * @return
83
+     * @throws Exception
84
+     */
85
+    public Map<String, String> fillRequestData(Map<String, String> reqData) throws Exception {
86
+        reqData.put("appid", config.getAppID());
87
+        reqData.put("mch_id", config.getMchID());
88
+        reqData.put("nonce_str", WXPayUtil.generateNonceStr());
89
+        if (WXPayConstants.SignType.MD5.equals(this.signType)) {
90
+            reqData.put("sign_type", WXPayConstants.MD5);
91
+        }
92
+        else if (WXPayConstants.SignType.HMACSHA256.equals(this.signType)) {
93
+            reqData.put("sign_type", WXPayConstants.HMACSHA256);
94
+        }
95
+        reqData.put("sign", WXPayUtil.generateSignature(reqData, config.getKey(), this.signType));
96
+        return reqData;
97
+    }
98
+
99
+    /**
100
+     * 判断xml数据的sign是否有效,必须包含sign字段,否则返回false。
101
+     *
102
+     * @param reqData 向wxpay post的请求数据
103
+     * @return 签名是否有效
104
+     * @throws Exception
105
+     */
106
+    public boolean isResponseSignatureValid(Map<String, String> reqData) throws Exception {
107
+        // 返回数据的签名方式和请求中给定的签名方式是一致的
108
+        return WXPayUtil.isSignatureValid(reqData, this.config.getKey(), this.signType);
109
+    }
110
+
111
+    /**
112
+     * 判断支付结果通知中的sign是否有效
113
+     *
114
+     * @param reqData 向wxpay post的请求数据
115
+     * @return 签名是否有效
116
+     * @throws Exception
117
+     */
118
+    public boolean isPayResultNotifySignatureValid(Map<String, String> reqData) throws Exception {
119
+        String signTypeInData = reqData.get(WXPayConstants.FIELD_SIGN_TYPE);
120
+        WXPayConstants.SignType signType;
121
+        if (signTypeInData == null) {
122
+            signType = WXPayConstants.SignType.MD5;
123
+        }
124
+        else {
125
+            signTypeInData = signTypeInData.trim();
126
+            if (signTypeInData.length() == 0) {
127
+                signType = WXPayConstants.SignType.MD5;
128
+            }
129
+            else if (WXPayConstants.MD5.equals(signTypeInData)) {
130
+                signType = WXPayConstants.SignType.MD5;
131
+            }
132
+            else if (WXPayConstants.HMACSHA256.equals(signTypeInData)) {
133
+                signType = WXPayConstants.SignType.HMACSHA256;
134
+            }
135
+            else {
136
+                throw new Exception(String.format("Unsupported sign_type: %s", signTypeInData));
137
+            }
138
+        }
139
+        return WXPayUtil.isSignatureValid(reqData, this.config.getKey(), signType);
140
+    }
141
+
142
+
143
+    /**
144
+     * 不需要证书的请求
145
+     * @param urlSuffix String
146
+     * @param reqData 向wxpay post的请求数据
147
+     * @param connectTimeoutMs 超时时间,单位是毫秒
148
+     * @param readTimeoutMs 超时时间,单位是毫秒
149
+     * @return API返回数据
150
+     * @throws Exception
151
+     */
152
+    public String requestWithoutCert(String urlSuffix, Map<String, String> reqData,
153
+                                     int connectTimeoutMs, int readTimeoutMs) throws Exception {
154
+        String msgUUID = reqData.get("nonce_str");
155
+        String reqBody = WXPayUtil.mapToXml(reqData);
156
+
157
+        String resp = this.wxPayRequest.requestWithoutCert(urlSuffix, msgUUID, reqBody, connectTimeoutMs, readTimeoutMs, autoReport);
158
+        return resp;
159
+    }
160
+
161
+
162
+    /**
163
+     * 需要证书的请求
164
+     * @param urlSuffix String
165
+     * @param reqData 向wxpay post的请求数据  Map
166
+     * @param connectTimeoutMs 超时时间,单位是毫秒
167
+     * @param readTimeoutMs 超时时间,单位是毫秒
168
+     * @return API返回数据
169
+     * @throws Exception
170
+     */
171
+    public String requestWithCert(String urlSuffix, Map<String, String> reqData,
172
+                                  int connectTimeoutMs, int readTimeoutMs) throws Exception {
173
+        String msgUUID= reqData.get("nonce_str");
174
+        String reqBody = WXPayUtil.mapToXml(reqData);
175
+
176
+        String resp = this.wxPayRequest.requestWithCert(urlSuffix, msgUUID, reqBody, connectTimeoutMs, readTimeoutMs, this.autoReport);
177
+        return resp;
178
+    }
179
+
180
+    /**
181
+     * 处理 HTTPS API返回数据,转换成Map对象。return_code为SUCCESS时,验证签名。
182
+     * @param xmlStr API返回的XML格式数据
183
+     * @return Map类型数据
184
+     * @throws Exception
185
+     */
186
+    public Map<String, String> processResponseXml(String xmlStr) throws Exception {
187
+        String RETURN_CODE = "return_code";
188
+        String return_code;
189
+        Map<String, String> respData = WXPayUtil.xmlToMap(xmlStr);
190
+        if (respData.containsKey(RETURN_CODE)) {
191
+            return_code = respData.get(RETURN_CODE);
192
+        }
193
+        else {
194
+            throw new Exception(String.format("No `return_code` in XML: %s", xmlStr));
195
+        }
196
+
197
+        if (return_code.equals(WXPayConstants.FAIL)) {
198
+            return respData;
199
+        }
200
+        else if (return_code.equals(WXPayConstants.SUCCESS)) {
201
+           if (this.isResponseSignatureValid(respData)) {
202
+               return respData;
203
+           }
204
+           else {
205
+               throw new Exception(String.format("Invalid sign value in XML: %s", xmlStr));
206
+           }
207
+        }
208
+        else {
209
+            throw new Exception(String.format("return_code value %s is invalid in XML: %s", return_code, xmlStr));
210
+        }
211
+    }
212
+
213
+    /**
214
+     * 作用:提交刷卡支付<br>
215
+     * 场景:刷卡支付
216
+     * @param reqData 向wxpay post的请求数据
217
+     * @return API返回数据
218
+     * @throws Exception
219
+     */
220
+    public Map<String, String> microPay(Map<String, String> reqData) throws Exception {
221
+        return this.microPay(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
222
+    }
223
+
224
+
225
+    /**
226
+     * 作用:提交刷卡支付<br>
227
+     * 场景:刷卡支付
228
+     * @param reqData 向wxpay post的请求数据
229
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
230
+     * @param readTimeoutMs 读超时时间,单位是毫秒
231
+     * @return API返回数据
232
+     * @throws Exception
233
+     */
234
+    public Map<String, String> microPay(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
235
+        String url;
236
+        if (this.useSandbox) {
237
+            url = WXPayConstants.SANDBOX_MICROPAY_URL_SUFFIX;
238
+        }
239
+        else {
240
+            url = WXPayConstants.MICROPAY_URL_SUFFIX;
241
+        }
242
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
243
+        return this.processResponseXml(respXml);
244
+    }
245
+
246
+    /**
247
+     * 提交刷卡支付,针对软POS,尽可能做成功
248
+     * 内置重试机制,最多60s
249
+     * @param reqData
250
+     * @return
251
+     * @throws Exception
252
+     */
253
+    public Map<String, String> microPayWithPos(Map<String, String> reqData) throws Exception {
254
+        return this.microPayWithPos(reqData, this.config.getHttpConnectTimeoutMs());
255
+    }
256
+
257
+    /**
258
+     * 提交刷卡支付,针对软POS,尽可能做成功
259
+     * 内置重试机制,最多60s
260
+     * @param reqData
261
+     * @param connectTimeoutMs
262
+     * @return
263
+     * @throws Exception
264
+     */
265
+    public Map<String, String> microPayWithPos(Map<String, String> reqData, int connectTimeoutMs) throws Exception {
266
+        int remainingTimeMs = 60*1000;
267
+        long startTimestampMs = 0;
268
+        Map<String, String> lastResult = null;
269
+        Exception lastException = null;
270
+
271
+        while (true) {
272
+            startTimestampMs = WXPayUtil.getCurrentTimestampMs();
273
+            int readTimeoutMs = remainingTimeMs - connectTimeoutMs;
274
+            if (readTimeoutMs > 1000) {
275
+                try {
276
+                    lastResult = this.microPay(reqData, connectTimeoutMs, readTimeoutMs);
277
+                    String returnCode = lastResult.get("return_code");
278
+                    if (returnCode.equals("SUCCESS")) {
279
+                        String resultCode = lastResult.get("result_code");
280
+                        String errCode = lastResult.get("err_code");
281
+                        if (resultCode.equals("SUCCESS")) {
282
+                            break;
283
+                        }
284
+                        else {
285
+                            // 看错误码,若支付结果未知,则重试提交刷卡支付
286
+                            if (errCode.equals("SYSTEMERROR") || errCode.equals("BANKERROR") || errCode.equals("USERPAYING")) {
287
+                                remainingTimeMs = remainingTimeMs - (int)(WXPayUtil.getCurrentTimestampMs() - startTimestampMs);
288
+                                if (remainingTimeMs <= 100) {
289
+                                    break;
290
+                                }
291
+                                else {
292
+                                    WXPayUtil.getLogger().info("microPayWithPos: try micropay again");
293
+                                    if (remainingTimeMs > 5*1000) {
294
+                                        Thread.sleep(5*1000);
295
+                                    }
296
+                                    else {
297
+                                        Thread.sleep(1*1000);
298
+                                    }
299
+                                    continue;
300
+                                }
301
+                            }
302
+                            else {
303
+                                break;
304
+                            }
305
+                        }
306
+                    }
307
+                    else {
308
+                        break;
309
+                    }
310
+                }
311
+                catch (Exception ex) {
312
+                    lastResult = null;
313
+                    lastException = ex;
314
+                }
315
+            }
316
+            else {
317
+                break;
318
+            }
319
+        }
320
+
321
+        if (lastResult == null) {
322
+            throw lastException;
323
+        }
324
+        else {
325
+            return lastResult;
326
+        }
327
+    }
328
+
329
+
330
+
331
+    /**
332
+     * 作用:统一下单<br>
333
+     * 场景:公共号支付、扫码支付、APP支付
334
+     * @param reqData 向wxpay post的请求数据
335
+     * @return API返回数据
336
+     * @throws Exception
337
+     */
338
+    public Map<String, String> unifiedOrder(Map<String, String> reqData) throws Exception {
339
+        return this.unifiedOrder(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
340
+    }
341
+
342
+
343
+    /**
344
+     * 作用:统一下单<br>
345
+     * 场景:公共号支付、扫码支付、APP支付
346
+     * @param reqData 向wxpay post的请求数据
347
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
348
+     * @param readTimeoutMs 读超时时间,单位是毫秒
349
+     * @return API返回数据
350
+     * @throws Exception
351
+     */
352
+    public Map<String, String> unifiedOrder(Map<String, String> reqData,  int connectTimeoutMs, int readTimeoutMs) throws Exception {
353
+        String url;
354
+        if (this.useSandbox) {
355
+            url = WXPayConstants.SANDBOX_UNIFIEDORDER_URL_SUFFIX;
356
+        }
357
+        else {
358
+            url = WXPayConstants.UNIFIEDORDER_URL_SUFFIX;
359
+        }
360
+        if(this.notifyUrl != null) {
361
+            reqData.put("notify_url", this.notifyUrl);
362
+        }
363
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
364
+        return this.processResponseXml(respXml);
365
+    }
366
+
367
+
368
+    /**
369
+     * 作用:查询订单<br>
370
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
371
+     * @param reqData 向wxpay post的请求数据
372
+     * @return API返回数据
373
+     * @throws Exception
374
+     */
375
+    public Map<String, String> orderQuery(Map<String, String> reqData) throws Exception {
376
+        return this.orderQuery(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
377
+    }
378
+
379
+
380
+    /**
381
+     * 作用:查询订单<br>
382
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
383
+     * @param reqData 向wxpay post的请求数据 int
384
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
385
+     * @param readTimeoutMs 读超时时间,单位是毫秒
386
+     * @return API返回数据
387
+     * @throws Exception
388
+     */
389
+    public Map<String, String> orderQuery(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
390
+        String url;
391
+        if (this.useSandbox) {
392
+            url = WXPayConstants.SANDBOX_ORDERQUERY_URL_SUFFIX;
393
+        }
394
+        else {
395
+            url = WXPayConstants.ORDERQUERY_URL_SUFFIX;
396
+        }
397
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
398
+        return this.processResponseXml(respXml);
399
+    }
400
+
401
+
402
+    /**
403
+     * 作用:撤销订单<br>
404
+     * 场景:刷卡支付
405
+     * @param reqData 向wxpay post的请求数据
406
+     * @return API返回数据
407
+     * @throws Exception
408
+     */
409
+    public Map<String, String> reverse(Map<String, String> reqData) throws Exception {
410
+        return this.reverse(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
411
+    }
412
+
413
+
414
+    /**
415
+     * 作用:撤销订单<br>
416
+     * 场景:刷卡支付<br>
417
+     * 其他:需要证书
418
+     * @param reqData 向wxpay post的请求数据
419
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
420
+     * @param readTimeoutMs 读超时时间,单位是毫秒
421
+     * @return API返回数据
422
+     * @throws Exception
423
+     */
424
+    public Map<String, String> reverse(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
425
+        String url;
426
+        if (this.useSandbox) {
427
+            url = WXPayConstants.SANDBOX_REVERSE_URL_SUFFIX;
428
+        }
429
+        else {
430
+            url = WXPayConstants.REVERSE_URL_SUFFIX;
431
+        }
432
+        String respXml = this.requestWithCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
433
+        return this.processResponseXml(respXml);
434
+    }
435
+
436
+
437
+    /**
438
+     * 作用:关闭订单<br>
439
+     * 场景:公共号支付、扫码支付、APP支付
440
+     * @param reqData 向wxpay post的请求数据
441
+     * @return API返回数据
442
+     * @throws Exception
443
+     */
444
+    public Map<String, String> closeOrder(Map<String, String> reqData) throws Exception {
445
+        return this.closeOrder(reqData, config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
446
+    }
447
+
448
+
449
+    /**
450
+     * 作用:关闭订单<br>
451
+     * 场景:公共号支付、扫码支付、APP支付
452
+     * @param reqData 向wxpay post的请求数据
453
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
454
+     * @param readTimeoutMs 读超时时间,单位是毫秒
455
+     * @return API返回数据
456
+     * @throws Exception
457
+     */
458
+    public Map<String, String> closeOrder(Map<String, String> reqData,  int connectTimeoutMs, int readTimeoutMs) throws Exception {
459
+        String url;
460
+        if (this.useSandbox) {
461
+            url = WXPayConstants.SANDBOX_CLOSEORDER_URL_SUFFIX;
462
+        }
463
+        else {
464
+            url = WXPayConstants.CLOSEORDER_URL_SUFFIX;
465
+        }
466
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
467
+        return this.processResponseXml(respXml);
468
+    }
469
+
470
+
471
+    /**
472
+     * 作用:申请退款<br>
473
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
474
+     * @param reqData 向wxpay post的请求数据
475
+     * @return API返回数据
476
+     * @throws Exception
477
+     */
478
+    public Map<String, String> refund(Map<String, String> reqData) throws Exception {
479
+        return this.refund(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
480
+    }
481
+
482
+
483
+    /**
484
+     * 作用:申请退款<br>
485
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付<br>
486
+     * 其他:需要证书
487
+     * @param reqData 向wxpay post的请求数据
488
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
489
+     * @param readTimeoutMs 读超时时间,单位是毫秒
490
+     * @return API返回数据
491
+     * @throws Exception
492
+     */
493
+    public Map<String, String> refund(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
494
+        String url;
495
+        if (this.useSandbox) {
496
+            url = WXPayConstants.SANDBOX_REFUND_URL_SUFFIX;
497
+        }
498
+        else {
499
+            url = WXPayConstants.REFUND_URL_SUFFIX;
500
+        }
501
+        String respXml = this.requestWithCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
502
+        return this.processResponseXml(respXml);
503
+    }
504
+
505
+
506
+    /**
507
+     * 作用:退款查询<br>
508
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
509
+     * @param reqData 向wxpay post的请求数据
510
+     * @return API返回数据
511
+     * @throws Exception
512
+     */
513
+    public Map<String, String> refundQuery(Map<String, String> reqData) throws Exception {
514
+        return this.refundQuery(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
515
+    }
516
+
517
+
518
+    /**
519
+     * 作用:退款查询<br>
520
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
521
+     * @param reqData 向wxpay post的请求数据
522
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
523
+     * @param readTimeoutMs 读超时时间,单位是毫秒
524
+     * @return API返回数据
525
+     * @throws Exception
526
+     */
527
+    public Map<String, String> refundQuery(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
528
+        String url;
529
+        if (this.useSandbox) {
530
+            url = WXPayConstants.SANDBOX_REFUNDQUERY_URL_SUFFIX;
531
+        }
532
+        else {
533
+            url = WXPayConstants.REFUNDQUERY_URL_SUFFIX;
534
+        }
535
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
536
+        return this.processResponseXml(respXml);
537
+    }
538
+
539
+
540
+    /**
541
+     * 作用:对账单下载(成功时返回对账单数据,失败时返回XML格式数据)<br>
542
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
543
+     * @param reqData 向wxpay post的请求数据
544
+     * @return API返回数据
545
+     * @throws Exception
546
+     */
547
+    public Map<String, String> downloadBill(Map<String, String> reqData) throws Exception {
548
+        return this.downloadBill(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
549
+    }
550
+
551
+
552
+    /**
553
+     * 作用:对账单下载<br>
554
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付<br>
555
+     * 其他:无论是否成功都返回Map。若成功,返回的Map中含有return_code、return_msg、data,
556
+     *      其中return_code为`SUCCESS`,data为对账单数据。
557
+     * @param reqData 向wxpay post的请求数据
558
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
559
+     * @param readTimeoutMs 读超时时间,单位是毫秒
560
+     * @return 经过封装的API返回数据
561
+     * @throws Exception
562
+     */
563
+    public Map<String, String> downloadBill(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
564
+        String url;
565
+        if (this.useSandbox) {
566
+            url = WXPayConstants.SANDBOX_DOWNLOADBILL_URL_SUFFIX;
567
+        }
568
+        else {
569
+            url = WXPayConstants.DOWNLOADBILL_URL_SUFFIX;
570
+        }
571
+        String respStr = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs).trim();
572
+        Map<String, String> ret;
573
+        // 出现错误,返回XML数据
574
+        if (respStr.indexOf("<") == 0) {
575
+            ret = WXPayUtil.xmlToMap(respStr);
576
+        }
577
+        else {
578
+            // 正常返回csv数据
579
+            ret = new HashMap<String, String>();
580
+            ret.put("return_code", WXPayConstants.SUCCESS);
581
+            ret.put("return_msg", "ok");
582
+            ret.put("data", respStr);
583
+        }
584
+        return ret;
585
+    }
586
+
587
+
588
+    /**
589
+     * 作用:交易保障<br>
590
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
591
+     * @param reqData 向wxpay post的请求数据
592
+     * @return API返回数据
593
+     * @throws Exception
594
+     */
595
+    public Map<String, String> report(Map<String, String> reqData) throws Exception {
596
+        return this.report(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
597
+    }
598
+
599
+
600
+    /**
601
+     * 作用:交易保障<br>
602
+     * 场景:刷卡支付、公共号支付、扫码支付、APP支付
603
+     * @param reqData 向wxpay post的请求数据
604
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
605
+     * @param readTimeoutMs 读超时时间,单位是毫秒
606
+     * @return API返回数据
607
+     * @throws Exception
608
+     */
609
+    public Map<String, String> report(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
610
+        String url;
611
+        if (this.useSandbox) {
612
+            url = WXPayConstants.SANDBOX_REPORT_URL_SUFFIX;
613
+        }
614
+        else {
615
+            url = WXPayConstants.REPORT_URL_SUFFIX;
616
+        }
617
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
618
+        return WXPayUtil.xmlToMap(respXml);
619
+    }
620
+
621
+
622
+    /**
623
+     * 作用:转换短链接<br>
624
+     * 场景:刷卡支付、扫码支付
625
+     * @param reqData 向wxpay post的请求数据
626
+     * @return API返回数据
627
+     * @throws Exception
628
+     */
629
+    public Map<String, String> shortUrl(Map<String, String> reqData) throws Exception {
630
+        return this.shortUrl(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
631
+    }
632
+
633
+
634
+    /**
635
+     * 作用:转换短链接<br>
636
+     * 场景:刷卡支付、扫码支付
637
+     * @param reqData 向wxpay post的请求数据
638
+     * @return API返回数据
639
+     * @throws Exception
640
+     */
641
+    public Map<String, String> shortUrl(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
642
+        String url;
643
+        if (this.useSandbox) {
644
+            url = WXPayConstants.SANDBOX_SHORTURL_URL_SUFFIX;
645
+        }
646
+        else {
647
+            url = WXPayConstants.SHORTURL_URL_SUFFIX;
648
+        }
649
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
650
+        return this.processResponseXml(respXml);
651
+    }
652
+
653
+
654
+    /**
655
+     * 作用:授权码查询OPENID接口<br>
656
+     * 场景:刷卡支付
657
+     * @param reqData 向wxpay post的请求数据
658
+     * @return API返回数据
659
+     * @throws Exception
660
+     */
661
+    public Map<String, String> authCodeToOpenid(Map<String, String> reqData) throws Exception {
662
+        return this.authCodeToOpenid(reqData, this.config.getHttpConnectTimeoutMs(), this.config.getHttpReadTimeoutMs());
663
+    }
664
+
665
+
666
+    /**
667
+     * 作用:授权码查询OPENID接口<br>
668
+     * 场景:刷卡支付
669
+     * @param reqData 向wxpay post的请求数据
670
+     * @param connectTimeoutMs 连接超时时间,单位是毫秒
671
+     * @param readTimeoutMs 读超时时间,单位是毫秒
672
+     * @return API返回数据
673
+     * @throws Exception
674
+     */
675
+    public Map<String, String> authCodeToOpenid(Map<String, String> reqData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
676
+        String url;
677
+        if (this.useSandbox) {
678
+            url = WXPayConstants.SANDBOX_AUTHCODETOOPENID_URL_SUFFIX;
679
+        }
680
+        else {
681
+            url = WXPayConstants.AUTHCODETOOPENID_URL_SUFFIX;
682
+        }
683
+        String respXml = this.requestWithoutCert(url, this.fillRequestData(reqData), connectTimeoutMs, readTimeoutMs);
684
+        return this.processResponseXml(respXml);
685
+    }
686
+
687
+
688
+} // end class

+ 103
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPayConfig.java Просмотреть файл

@@ -0,0 +1,103 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+import java.io.InputStream;
4
+
5
+public abstract class WXPayConfig {
6
+
7
+
8
+
9
+    /**
10
+     * 获取 App ID
11
+     *
12
+     * @return App ID
13
+     */
14
+    abstract String getAppID();
15
+
16
+
17
+    /**
18
+     * 获取 Mch ID
19
+     *
20
+     * @return Mch ID
21
+     */
22
+    abstract String getMchID();
23
+
24
+
25
+    /**
26
+     * 获取 API 密钥
27
+     *
28
+     * @return API密钥
29
+     */
30
+    abstract String getKey();
31
+
32
+
33
+    /**
34
+     * 获取商户证书内容
35
+     *
36
+     * @return 商户证书内容
37
+     */
38
+    abstract InputStream getCertStream();
39
+
40
+    /**
41
+     * HTTP(S) 连接超时时间,单位毫秒
42
+     *
43
+     * @return
44
+     */
45
+    public int getHttpConnectTimeoutMs() {
46
+        return 6*1000;
47
+    }
48
+
49
+    /**
50
+     * HTTP(S) 读数据超时时间,单位毫秒
51
+     *
52
+     * @return
53
+     */
54
+    public int getHttpReadTimeoutMs() {
55
+        return 8*1000;
56
+    }
57
+
58
+    /**
59
+     * 获取WXPayDomain, 用于多域名容灾自动切换
60
+     * @return
61
+     */
62
+    abstract IWXPayDomain getWXPayDomain();
63
+
64
+    /**
65
+     * 是否自动上报。
66
+     * 若要关闭自动上报,子类中实现该函数返回 false 即可。
67
+     *
68
+     * @return
69
+     */
70
+    public boolean shouldAutoReport() {
71
+        return true;
72
+    }
73
+
74
+    /**
75
+     * 进行健康上报的线程的数量
76
+     *
77
+     * @return
78
+     */
79
+    public int getReportWorkerNum() {
80
+        return 6;
81
+    }
82
+
83
+
84
+    /**
85
+     * 健康上报缓存消息的最大数量。会有线程去独立上报
86
+     * 粗略计算:加入一条消息200B,10000消息占用空间 2000 KB,约为2MB,可以接受
87
+     *
88
+     * @return
89
+     */
90
+    public int getReportQueueMaxSize() {
91
+        return 10000;
92
+    }
93
+
94
+    /**
95
+     * 批量上报,一次最多上报多个数据
96
+     *
97
+     * @return
98
+     */
99
+    public int getReportBatchSize() {
100
+        return 10;
101
+    }
102
+
103
+}

+ 59
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPayConstants.java Просмотреть файл

@@ -0,0 +1,59 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+import org.apache.http.client.HttpClient;
4
+
5
+/**
6
+ * 常量
7
+ */
8
+public class WXPayConstants {
9
+
10
+    public enum SignType {
11
+        MD5, HMACSHA256
12
+    }
13
+
14
+    public static final String DOMAIN_API = "api.mch.weixin.qq.com";
15
+    public static final String DOMAIN_API2 = "api2.mch.weixin.qq.com";
16
+    public static final String DOMAIN_APIHK = "apihk.mch.weixin.qq.com";
17
+    public static final String DOMAIN_APIUS = "apius.mch.weixin.qq.com";
18
+
19
+
20
+    public static final String FAIL     = "FAIL";
21
+    public static final String SUCCESS  = "SUCCESS";
22
+    public static final String HMACSHA256 = "HMAC-SHA256";
23
+    public static final String MD5 = "MD5";
24
+
25
+    public static final String FIELD_SIGN = "sign";
26
+    public static final String FIELD_SIGN_TYPE = "sign_type";
27
+
28
+    public static final String WXPAYSDK_VERSION = "WXPaySDK/3.0.9";
29
+    public static final String USER_AGENT = WXPAYSDK_VERSION +
30
+            " (" + System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version") +
31
+            ") Java/" + System.getProperty("java.version") + " HttpClient/" + HttpClient.class.getPackage().getImplementationVersion();
32
+
33
+    public static final String MICROPAY_URL_SUFFIX     = "/pay/micropay";
34
+    public static final String UNIFIEDORDER_URL_SUFFIX = "/pay/unifiedorder";
35
+    public static final String ORDERQUERY_URL_SUFFIX   = "/pay/orderquery";
36
+    public static final String REVERSE_URL_SUFFIX      = "/secapi/pay/reverse";
37
+    public static final String CLOSEORDER_URL_SUFFIX   = "/pay/closeorder";
38
+    public static final String REFUND_URL_SUFFIX       = "/secapi/pay/refund";
39
+    public static final String REFUNDQUERY_URL_SUFFIX  = "/pay/refundquery";
40
+    public static final String DOWNLOADBILL_URL_SUFFIX = "/pay/downloadbill";
41
+    public static final String REPORT_URL_SUFFIX       = "/payitil/report";
42
+    public static final String SHORTURL_URL_SUFFIX     = "/tools/shorturl";
43
+    public static final String AUTHCODETOOPENID_URL_SUFFIX = "/tools/authcodetoopenid";
44
+
45
+    // sandbox
46
+    public static final String SANDBOX_MICROPAY_URL_SUFFIX     = "/sandboxnew/pay/micropay";
47
+    public static final String SANDBOX_UNIFIEDORDER_URL_SUFFIX = "/sandboxnew/pay/unifiedorder";
48
+    public static final String SANDBOX_ORDERQUERY_URL_SUFFIX   = "/sandboxnew/pay/orderquery";
49
+    public static final String SANDBOX_REVERSE_URL_SUFFIX      = "/sandboxnew/secapi/pay/reverse";
50
+    public static final String SANDBOX_CLOSEORDER_URL_SUFFIX   = "/sandboxnew/pay/closeorder";
51
+    public static final String SANDBOX_REFUND_URL_SUFFIX       = "/sandboxnew/secapi/pay/refund";
52
+    public static final String SANDBOX_REFUNDQUERY_URL_SUFFIX  = "/sandboxnew/pay/refundquery";
53
+    public static final String SANDBOX_DOWNLOADBILL_URL_SUFFIX = "/sandboxnew/pay/downloadbill";
54
+    public static final String SANDBOX_REPORT_URL_SUFFIX       = "/sandboxnew/payitil/report";
55
+    public static final String SANDBOX_SHORTURL_URL_SUFFIX     = "/sandboxnew/tools/shorturl";
56
+    public static final String SANDBOX_AUTHCODETOOPENID_URL_SUFFIX = "/sandboxnew/tools/authcodetoopenid";
57
+
58
+}
59
+

+ 106
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPayRefundReason.java Просмотреть файл

@@ -0,0 +1,106 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+public enum WXPayRefundReason {
4
+    SYSTEMERROR("SYSTEMERROR","系统超时等"),
5
+    BIZERR_NEED_RETRY("BIZERR_NEED_RETRY","并发情况下,业务被拒绝,商户重试即可解决"),
6
+    TRADE_OVERDUE("TRADE_OVERDUE","订单已经超过可退款的最大期限(支付后一年内可退款)"),
7
+    ERROR("ERROR","申请退款业务发生错误"),
8
+    USER_ACCOUNT_ABNORMAL("USER_ACCOUNT_ABNORMAL","用户帐号注销"),
9
+    INVALID_REQ_TOO_MUCH("INVALID_REQ_TOO_MUCH","连续错误请求数过多被系统短暂屏蔽"),
10
+    NOTENOUGH("NOTENOUGH","商户可用退款余额不足"),
11
+    INVALID_TRANSACTIONID("INVALID_TRANSACTIONID","请求参数未按指引进行填写"),
12
+    PARAM_ERROR("PARAM_ERROR","请求参数未按指引进行填写"),
13
+    APPID_NOT_EXIST("APPID_NOT_EXIST","参数中缺少APPID"),
14
+    MCHID_NOT_EXIST("MCHID_NOT_EXIST","参数中缺少MCHID"),
15
+    ORDERNOTEXIST("ORDERNOTEXIST","缺少有效的订单号"),
16
+    REQUIRE_POST_METHOD("REQUIRE_POST_METHOD","未使用post传递参数 "),
17
+    SIGNERROR("SIGNERROR","参数签名结果不正确"),
18
+    XML_FORMAT_ERROR("XML_FORMAT_ERROR","XML格式错误"),
19
+    FREQUENCY_LIMITED("FREQUENCY_LIMITED","2个月之前的订单申请退款有频率限制"),
20
+    NOAUTH("NOAUTH","请求ip异常"),
21
+    ;
22
+
23
+    WXPayRefundReason(String code, String message) {
24
+        this.code = code;
25
+        this.message = message;
26
+    }
27
+
28
+    private String code;
29
+
30
+    private String message;
31
+
32
+    public String getCode() {
33
+        return code;
34
+    }
35
+
36
+    public void setCode(String code) {
37
+        this.code = code;
38
+    }
39
+
40
+    public String getMessage() {
41
+        return message;
42
+    }
43
+
44
+    public void setMessage(String message) {
45
+        this.message = message;
46
+    }
47
+
48
+
49
+    public static String getMsg(String code) {
50
+        String message = "";
51
+       switch (code){
52
+           case "SYSTEMERROR":
53
+               message = SYSTEMERROR.getMessage();
54
+               break;
55
+           case "BIZERR_NEED_RETRY":
56
+               message = BIZERR_NEED_RETRY.getMessage();
57
+               break;
58
+           case "TRADE_OVERDUE":
59
+               message = TRADE_OVERDUE.getMessage();
60
+               break;
61
+           case "ERROR":
62
+               message = ERROR.getMessage();
63
+               break;
64
+           case "USER_ACCOUNT_ABNORMAL":
65
+               message = USER_ACCOUNT_ABNORMAL.getMessage();
66
+               break;
67
+           case "INVALID_REQ_TOO_MUCH":
68
+               message = INVALID_REQ_TOO_MUCH.getMessage();
69
+               break;
70
+           case "NOTENOUGH":
71
+               message = NOTENOUGH.getMessage();
72
+               break;
73
+           case "INVALID_TRANSACTIONID":
74
+               message = INVALID_TRANSACTIONID.getMessage();
75
+               break;
76
+           case "PARAM_ERROR":
77
+               message = PARAM_ERROR.getMessage();
78
+               break;
79
+           case "APPID_NOT_EXIST":
80
+               message = APPID_NOT_EXIST.getMessage();
81
+               break;
82
+           case "MCHID_NOT_EXIST":
83
+               message = MCHID_NOT_EXIST.getMessage();
84
+               break;
85
+           case "REQUIRE_POST_METHOD":
86
+               message = REQUIRE_POST_METHOD.getMessage();
87
+               break;
88
+           case "SIGNERROR":
89
+               message = SIGNERROR.getMessage();
90
+               break;
91
+           case "XML_FORMAT_ERROR":
92
+               message = XML_FORMAT_ERROR.getMessage();
93
+               break;
94
+           case "FREQUENCY_LIMITED":
95
+               message = FREQUENCY_LIMITED.getMessage();
96
+               break;
97
+           case "NOAUTH":
98
+               message = NOAUTH.getMessage();
99
+               break;
100
+           case "ORDERNOTEXIST":
101
+               message = ORDERNOTEXIST.getMessage();
102
+               break;
103
+       }
104
+        return message;
105
+    }
106
+}

+ 265
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPayReport.java Просмотреть файл

@@ -0,0 +1,265 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+import org.apache.http.HttpEntity;
4
+import org.apache.http.HttpResponse;
5
+import org.apache.http.client.HttpClient;
6
+import org.apache.http.client.config.RequestConfig;
7
+import org.apache.http.client.methods.HttpPost;
8
+import org.apache.http.config.RegistryBuilder;
9
+import org.apache.http.conn.socket.ConnectionSocketFactory;
10
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
11
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
12
+import org.apache.http.entity.StringEntity;
13
+import org.apache.http.impl.client.HttpClientBuilder;
14
+import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
15
+import org.apache.http.util.EntityUtils;
16
+
17
+import java.util.concurrent.ExecutorService;
18
+import java.util.concurrent.Executors;
19
+import java.util.concurrent.LinkedBlockingQueue;
20
+import java.util.concurrent.ThreadFactory;
21
+
22
+/**
23
+ * 交易保障
24
+ */
25
+public class WXPayReport {
26
+
27
+    public static class ReportInfo {
28
+
29
+        /**
30
+         * 布尔变量使用int。0为false, 1为true。
31
+         */
32
+
33
+        // 基本信息
34
+        private String version = "v1";
35
+        private String sdk = WXPayConstants.WXPAYSDK_VERSION;
36
+        private String uuid;  // 交易的标识
37
+        private long timestamp;   // 上报时的时间戳,单位秒
38
+        private long elapsedTimeMillis; // 耗时,单位 毫秒
39
+
40
+        // 针对主域名
41
+        private String firstDomain;  // 第1次请求的域名
42
+        private boolean primaryDomain; //是否主域名
43
+        private int firstConnectTimeoutMillis;  // 第1次请求设置的连接超时时间,单位 毫秒
44
+        private int firstReadTimeoutMillis;  // 第1次请求设置的读写超时时间,单位 毫秒
45
+        private int firstHasDnsError;  // 第1次请求是否出现dns问题
46
+        private int firstHasConnectTimeout; // 第1次请求是否出现连接超时
47
+        private int firstHasReadTimeout; // 第1次请求是否出现连接超时
48
+
49
+        public ReportInfo(String uuid, long timestamp, long elapsedTimeMillis, String firstDomain, boolean primaryDomain, int firstConnectTimeoutMillis, int firstReadTimeoutMillis, boolean firstHasDnsError, boolean firstHasConnectTimeout, boolean firstHasReadTimeout) {
50
+            this.uuid = uuid;
51
+            this.timestamp = timestamp;
52
+            this.elapsedTimeMillis = elapsedTimeMillis;
53
+            this.firstDomain = firstDomain;
54
+            this.primaryDomain = primaryDomain;
55
+            this.firstConnectTimeoutMillis = firstConnectTimeoutMillis;
56
+            this.firstReadTimeoutMillis = firstReadTimeoutMillis;
57
+            this.firstHasDnsError = firstHasDnsError?1:0;
58
+            this.firstHasConnectTimeout = firstHasConnectTimeout?1:0;
59
+            this.firstHasReadTimeout = firstHasReadTimeout?1:0;
60
+         }
61
+
62
+        @Override
63
+        public String toString() {
64
+            return "ReportInfo{" +
65
+                    "version='" + version + '\'' +
66
+                    ", sdk='" + sdk + '\'' +
67
+                    ", uuid='" + uuid + '\'' +
68
+                    ", timestamp=" + timestamp +
69
+                    ", elapsedTimeMillis=" + elapsedTimeMillis +
70
+                    ", firstDomain='" + firstDomain + '\'' +
71
+                    ", primaryDomain=" + primaryDomain +
72
+                    ", firstConnectTimeoutMillis=" + firstConnectTimeoutMillis +
73
+                    ", firstReadTimeoutMillis=" + firstReadTimeoutMillis +
74
+                    ", firstHasDnsError=" + firstHasDnsError +
75
+                    ", firstHasConnectTimeout=" + firstHasConnectTimeout +
76
+                    ", firstHasReadTimeout=" + firstHasReadTimeout +
77
+                    '}';
78
+        }
79
+
80
+        /**
81
+         * 转换成 csv 格式
82
+         *
83
+         * @return
84
+         */
85
+        public String toLineString(String key) {
86
+            String separator = ",";
87
+            Object[] objects = new Object[] {
88
+                version, sdk, uuid, timestamp, elapsedTimeMillis,
89
+                    firstDomain, primaryDomain, firstConnectTimeoutMillis, firstReadTimeoutMillis,
90
+                    firstHasDnsError, firstHasConnectTimeout, firstHasReadTimeout
91
+            };
92
+            StringBuffer sb = new StringBuffer();
93
+            for(Object obj: objects) {
94
+                sb.append(obj).append(separator);
95
+            }
96
+            try {
97
+                String sign = WXPayUtil.HMACSHA256(sb.toString(), key);
98
+                sb.append(sign);
99
+                return sb.toString();
100
+            }
101
+            catch (Exception ex) {
102
+                return null;
103
+            }
104
+
105
+        }
106
+
107
+    }
108
+
109
+    private static final String REPORT_URL = "http://report.mch.weixin.qq.com/wxpay/report/default";
110
+    // private static final String REPORT_URL = "http://127.0.0.1:5000/test";
111
+
112
+
113
+    private static final int DEFAULT_CONNECT_TIMEOUT_MS = 6*1000;
114
+    private static final int DEFAULT_READ_TIMEOUT_MS = 8*1000;
115
+
116
+    private LinkedBlockingQueue<String> reportMsgQueue = null;
117
+    private WXPayConfig config;
118
+    private ExecutorService executorService;
119
+
120
+    private volatile static WXPayReport INSTANCE;
121
+
122
+    private WXPayReport(final WXPayConfig config) {
123
+        this.config = config;
124
+        reportMsgQueue = new LinkedBlockingQueue<String>(config.getReportQueueMaxSize());
125
+
126
+        // 添加处理线程
127
+        executorService = Executors.newFixedThreadPool(config.getReportWorkerNum(), new ThreadFactory() {
128
+            public Thread newThread(Runnable r) {
129
+                Thread t = Executors.defaultThreadFactory().newThread(r);
130
+                t.setDaemon(true);
131
+                return t;
132
+            }
133
+        });
134
+
135
+        if (config.shouldAutoReport()) {
136
+            WXPayUtil.getLogger().info("report worker num: {}", config.getReportWorkerNum());
137
+            for (int i = 0; i < config.getReportWorkerNum(); ++i) {
138
+                executorService.execute(new Runnable() {
139
+                    public void run() {
140
+                        while (true) {
141
+                            // 先用 take 获取数据
142
+                            try {
143
+                                StringBuffer sb = new StringBuffer();
144
+                                String firstMsg = reportMsgQueue.take();
145
+                                WXPayUtil.getLogger().info("get first report msg: {}", firstMsg);
146
+                                String msg = null;
147
+                                sb.append(firstMsg); //会阻塞至有消息
148
+                                int remainNum = config.getReportBatchSize() - 1;
149
+                                for (int j=0; j<remainNum; ++j) {
150
+                                    WXPayUtil.getLogger().info("try get remain report msg");
151
+                                    // msg = reportMsgQueue.poll();  // 不阻塞了
152
+                                    msg = reportMsgQueue.take();
153
+                                    WXPayUtil.getLogger().info("get remain report msg: {}", msg);
154
+                                    if (msg == null) {
155
+                                        break;
156
+                                    }
157
+                                    else {
158
+                                        sb.append("\n");
159
+                                        sb.append(msg);
160
+                                    }
161
+                                }
162
+                                // 上报
163
+                                WXPayReport.httpRequest(sb.toString(), DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_READ_TIMEOUT_MS);
164
+                            }
165
+                            catch (Exception ex) {
166
+                                WXPayUtil.getLogger().warn("report fail. reason: {}", ex.getMessage());
167
+                            }
168
+                        }
169
+                    }
170
+                });
171
+            }
172
+        }
173
+
174
+    }
175
+
176
+    /**
177
+     * 单例,双重校验,请在 JDK 1.5及更高版本中使用
178
+     *
179
+     * @param config
180
+     * @return
181
+     */
182
+    public static WXPayReport getInstance(WXPayConfig config) {
183
+        if (INSTANCE == null) {
184
+            synchronized (WXPayReport.class) {
185
+                if (INSTANCE == null) {
186
+                    INSTANCE = new WXPayReport(config);
187
+                }
188
+            }
189
+        }
190
+        return INSTANCE;
191
+    }
192
+
193
+    public void report(String uuid, long elapsedTimeMillis,
194
+                       String firstDomain, boolean primaryDomain, int firstConnectTimeoutMillis, int firstReadTimeoutMillis,
195
+                       boolean firstHasDnsError, boolean firstHasConnectTimeout, boolean firstHasReadTimeout) {
196
+        long currentTimestamp = WXPayUtil.getCurrentTimestamp();
197
+        ReportInfo reportInfo = new ReportInfo(uuid, currentTimestamp, elapsedTimeMillis,
198
+                firstDomain, primaryDomain, firstConnectTimeoutMillis, firstReadTimeoutMillis,
199
+                firstHasDnsError, firstHasConnectTimeout, firstHasReadTimeout);
200
+        String data = reportInfo.toLineString(config.getKey());
201
+        WXPayUtil.getLogger().info("report {}", data);
202
+        if (data != null) {
203
+            reportMsgQueue.offer(data);
204
+        }
205
+    }
206
+
207
+
208
+    @Deprecated
209
+    private void reportSync(final String data) throws Exception {
210
+        httpRequest(data, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_READ_TIMEOUT_MS);
211
+    }
212
+
213
+    @Deprecated
214
+    private void reportAsync(final String data) throws Exception {
215
+        new Thread(new Runnable() {
216
+            public void run() {
217
+                try {
218
+                    httpRequest(data, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_READ_TIMEOUT_MS);
219
+                }
220
+                catch (Exception ex) {
221
+                    WXPayUtil.getLogger().warn("report fail. reason: {}", ex.getMessage());
222
+                }
223
+            }
224
+        }).start();
225
+    }
226
+
227
+    /**
228
+     * http 请求
229
+     * @param data
230
+     * @param connectTimeoutMs
231
+     * @param readTimeoutMs
232
+     * @return
233
+     * @throws Exception
234
+     */
235
+    private static String httpRequest(String data, int connectTimeoutMs, int readTimeoutMs) throws Exception{
236
+        BasicHttpClientConnectionManager connManager;
237
+        connManager = new BasicHttpClientConnectionManager(
238
+                RegistryBuilder.<ConnectionSocketFactory>create()
239
+                        .register("http", PlainConnectionSocketFactory.getSocketFactory())
240
+                        .register("https", SSLConnectionSocketFactory.getSocketFactory())
241
+                        .build(),
242
+                null,
243
+                null,
244
+                null
245
+        );
246
+        HttpClient httpClient = HttpClientBuilder.create()
247
+                .setConnectionManager(connManager)
248
+                .build();
249
+
250
+        HttpPost httpPost = new HttpPost(REPORT_URL);
251
+
252
+        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(readTimeoutMs).setConnectTimeout(connectTimeoutMs).build();
253
+        httpPost.setConfig(requestConfig);
254
+
255
+        StringEntity postEntity = new StringEntity(data, "UTF-8");
256
+        httpPost.addHeader("Content-Type", "text/xml");
257
+        httpPost.addHeader("User-Agent", WXPayConstants.USER_AGENT);
258
+        httpPost.setEntity(postEntity);
259
+
260
+        HttpResponse httpResponse = httpClient.execute(httpPost);
261
+        HttpEntity httpEntity = httpResponse.getEntity();
262
+        return EntityUtils.toString(httpEntity, "UTF-8");
263
+    }
264
+
265
+}

+ 256
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPayRequest.java Просмотреть файл

@@ -0,0 +1,256 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+import org.apache.http.HttpEntity;
4
+import org.apache.http.HttpResponse;
5
+import org.apache.http.client.HttpClient;
6
+import org.apache.http.client.config.RequestConfig;
7
+import org.apache.http.client.methods.HttpPost;
8
+import org.apache.http.config.RegistryBuilder;
9
+import org.apache.http.conn.ConnectTimeoutException;
10
+import org.apache.http.conn.socket.ConnectionSocketFactory;
11
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
12
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
13
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
14
+import org.apache.http.entity.StringEntity;
15
+import org.apache.http.impl.client.HttpClientBuilder;
16
+import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
17
+import org.apache.http.util.EntityUtils;
18
+
19
+import javax.net.ssl.KeyManagerFactory;
20
+import javax.net.ssl.SSLContext;
21
+import java.io.InputStream;
22
+import java.net.SocketTimeoutException;
23
+import java.net.UnknownHostException;
24
+import java.security.KeyStore;
25
+import java.security.SecureRandom;
26
+
27
+public class WXPayRequest {
28
+    private WXPayConfig config;
29
+    public WXPayRequest(WXPayConfig config) throws Exception{
30
+
31
+        this.config = config;
32
+    }
33
+
34
+    /**
35
+     * 请求,只请求一次,不做重试
36
+     * @param domain
37
+     * @param urlSuffix
38
+     * @param uuid
39
+     * @param data
40
+     * @param connectTimeoutMs
41
+     * @param readTimeoutMs
42
+     * @param useCert 是否使用证书,针对退款、撤销等操作
43
+     * @return
44
+     * @throws Exception
45
+     */
46
+    private String requestOnce(final String domain, String urlSuffix, String uuid, String data, int connectTimeoutMs, int readTimeoutMs, boolean useCert) throws Exception {
47
+        BasicHttpClientConnectionManager connManager;
48
+        if (useCert) {
49
+            // 证书
50
+            char[] password = config.getMchID().toCharArray();
51
+            InputStream certStream = config.getCertStream();
52
+            KeyStore ks = KeyStore.getInstance("PKCS12");
53
+            ks.load(certStream, password);
54
+
55
+            // 实例化密钥库 & 初始化密钥工厂
56
+            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
57
+            kmf.init(ks, password);
58
+
59
+            // 创建 SSLContext
60
+            SSLContext sslContext = SSLContext.getInstance("TLS");
61
+            sslContext.init(kmf.getKeyManagers(), null, new SecureRandom());
62
+
63
+            SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
64
+                    sslContext,
65
+                    new String[]{"TLSv1"},
66
+                    null,
67
+                    new DefaultHostnameVerifier());
68
+
69
+            connManager = new BasicHttpClientConnectionManager(
70
+                    RegistryBuilder.<ConnectionSocketFactory>create()
71
+                            .register("http", PlainConnectionSocketFactory.getSocketFactory())
72
+                            .register("https", sslConnectionSocketFactory)
73
+                            .build(),
74
+                    null,
75
+                    null,
76
+                    null
77
+            );
78
+        }
79
+        else {
80
+            connManager = new BasicHttpClientConnectionManager(
81
+                    RegistryBuilder.<ConnectionSocketFactory>create()
82
+                            .register("http", PlainConnectionSocketFactory.getSocketFactory())
83
+                            .register("https", SSLConnectionSocketFactory.getSocketFactory())
84
+                            .build(),
85
+                    null,
86
+                    null,
87
+                    null
88
+            );
89
+        }
90
+
91
+        HttpClient httpClient = HttpClientBuilder.create()
92
+                .setConnectionManager(connManager)
93
+                .build();
94
+
95
+        String url = "https://" + domain + urlSuffix;
96
+        HttpPost httpPost = new HttpPost(url);
97
+
98
+        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(readTimeoutMs).setConnectTimeout(connectTimeoutMs).build();
99
+        httpPost.setConfig(requestConfig);
100
+
101
+        StringEntity postEntity = new StringEntity(data, "UTF-8");
102
+        httpPost.addHeader("Content-Type", "text/xml");
103
+        httpPost.addHeader("User-Agent", WXPayConstants.USER_AGENT + " " + config.getMchID());
104
+        httpPost.setEntity(postEntity);
105
+
106
+        HttpResponse httpResponse = httpClient.execute(httpPost);
107
+        HttpEntity httpEntity = httpResponse.getEntity();
108
+        return EntityUtils.toString(httpEntity, "UTF-8");
109
+
110
+    }
111
+
112
+
113
+    private String request(String urlSuffix, String uuid, String data, int connectTimeoutMs, int readTimeoutMs, boolean useCert, boolean autoReport) throws Exception {
114
+        Exception exception = null;
115
+        long elapsedTimeMillis = 0;
116
+        long startTimestampMs = WXPayUtil.getCurrentTimestampMs();
117
+        boolean firstHasDnsErr = false;
118
+        boolean firstHasConnectTimeout = false;
119
+        boolean firstHasReadTimeout = false;
120
+        IWXPayDomain.DomainInfo domainInfo = config.getWXPayDomain().getDomain(config);
121
+        if(domainInfo == null){
122
+            throw new Exception("WXPayConfig.getWXPayDomain().getDomain() is empty or null");
123
+        }
124
+        try {
125
+            String result = requestOnce(domainInfo.domain, urlSuffix, uuid, data, connectTimeoutMs, readTimeoutMs, useCert);
126
+            elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs()-startTimestampMs;
127
+            config.getWXPayDomain().report(domainInfo.domain, elapsedTimeMillis, null);
128
+            WXPayReport.getInstance(config).report(
129
+                    uuid,
130
+                    elapsedTimeMillis,
131
+                    domainInfo.domain,
132
+                    domainInfo.primaryDomain,
133
+                    connectTimeoutMs,
134
+                    readTimeoutMs,
135
+                    firstHasDnsErr,
136
+                    firstHasConnectTimeout,
137
+                    firstHasReadTimeout);
138
+            return result;
139
+        }
140
+        catch (UnknownHostException ex) {  // dns 解析错误,或域名不存在
141
+            exception = ex;
142
+            firstHasDnsErr = true;
143
+            elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs()-startTimestampMs;
144
+            WXPayUtil.getLogger().warn("UnknownHostException for domainInfo {}", domainInfo);
145
+            WXPayReport.getInstance(config).report(
146
+                    uuid,
147
+                    elapsedTimeMillis,
148
+                    domainInfo.domain,
149
+                    domainInfo.primaryDomain,
150
+                    connectTimeoutMs,
151
+                    readTimeoutMs,
152
+                    firstHasDnsErr,
153
+                    firstHasConnectTimeout,
154
+                    firstHasReadTimeout
155
+            );
156
+        }
157
+        catch (ConnectTimeoutException ex) {
158
+            exception = ex;
159
+            firstHasConnectTimeout = true;
160
+            elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs()-startTimestampMs;
161
+            WXPayUtil.getLogger().warn("connect timeout happened for domainInfo {}", domainInfo);
162
+            WXPayReport.getInstance(config).report(
163
+                    uuid,
164
+                    elapsedTimeMillis,
165
+                    domainInfo.domain,
166
+                    domainInfo.primaryDomain,
167
+                    connectTimeoutMs,
168
+                    readTimeoutMs,
169
+                    firstHasDnsErr,
170
+                    firstHasConnectTimeout,
171
+                    firstHasReadTimeout
172
+            );
173
+        }
174
+        catch (SocketTimeoutException ex) {
175
+            exception = ex;
176
+            firstHasReadTimeout = true;
177
+            elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs()-startTimestampMs;
178
+            WXPayUtil.getLogger().warn("timeout happened for domainInfo {}", domainInfo);
179
+            WXPayReport.getInstance(config).report(
180
+                    uuid,
181
+                    elapsedTimeMillis,
182
+                    domainInfo.domain,
183
+                    domainInfo.primaryDomain,
184
+                    connectTimeoutMs,
185
+                    readTimeoutMs,
186
+                    firstHasDnsErr,
187
+                    firstHasConnectTimeout,
188
+                    firstHasReadTimeout);
189
+        }
190
+        catch (Exception ex) {
191
+            exception = ex;
192
+            elapsedTimeMillis = WXPayUtil.getCurrentTimestampMs()-startTimestampMs;
193
+            WXPayReport.getInstance(config).report(
194
+                    uuid,
195
+                    elapsedTimeMillis,
196
+                    domainInfo.domain,
197
+                    domainInfo.primaryDomain,
198
+                    connectTimeoutMs,
199
+                    readTimeoutMs,
200
+                    firstHasDnsErr,
201
+                    firstHasConnectTimeout,
202
+                    firstHasReadTimeout);
203
+        }
204
+        config.getWXPayDomain().report(domainInfo.domain, elapsedTimeMillis, exception);
205
+        throw exception;
206
+    }
207
+
208
+
209
+    /**
210
+     * 可重试的,非双向认证的请求
211
+     * @param urlSuffix
212
+     * @param uuid
213
+     * @param data
214
+     * @return
215
+     */
216
+    public String requestWithoutCert(String urlSuffix, String uuid, String data, boolean autoReport) throws Exception {
217
+        return this.request(urlSuffix, uuid, data, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs(), false, autoReport);
218
+    }
219
+
220
+    /**
221
+     * 可重试的,非双向认证的请求
222
+     * @param urlSuffix
223
+     * @param uuid
224
+     * @param data
225
+     * @param connectTimeoutMs
226
+     * @param readTimeoutMs
227
+     * @return
228
+     */
229
+    public String requestWithoutCert(String urlSuffix, String uuid, String data, int connectTimeoutMs, int readTimeoutMs,  boolean autoReport) throws Exception {
230
+        return this.request(urlSuffix, uuid, data, connectTimeoutMs, readTimeoutMs, false, autoReport);
231
+    }
232
+
233
+    /**
234
+     * 可重试的,双向认证的请求
235
+     * @param urlSuffix
236
+     * @param uuid
237
+     * @param data
238
+     * @return
239
+     */
240
+    public String requestWithCert(String urlSuffix, String uuid, String data, boolean autoReport) throws Exception {
241
+        return this.request(urlSuffix, uuid, data, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs(), true, autoReport);
242
+    }
243
+
244
+    /**
245
+     * 可重试的,双向认证的请求
246
+     * @param urlSuffix
247
+     * @param uuid
248
+     * @param data
249
+     * @param connectTimeoutMs
250
+     * @param readTimeoutMs
251
+     * @return
252
+     */
253
+    public String requestWithCert(String urlSuffix, String uuid, String data, int connectTimeoutMs, int readTimeoutMs, boolean autoReport) throws Exception {
254
+        return this.request(urlSuffix, uuid, data, connectTimeoutMs, readTimeoutMs, true, autoReport);
255
+    }
256
+}

+ 294
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPayUtil.java Просмотреть файл

@@ -0,0 +1,294 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+import org.slf4j.Logger;
4
+import org.slf4j.LoggerFactory;
5
+import org.w3c.dom.Node;
6
+import org.w3c.dom.NodeList;
7
+
8
+import javax.crypto.Mac;
9
+import javax.crypto.spec.SecretKeySpec;
10
+import javax.xml.parsers.DocumentBuilder;
11
+import javax.xml.transform.OutputKeys;
12
+import javax.xml.transform.Transformer;
13
+import javax.xml.transform.TransformerFactory;
14
+import javax.xml.transform.dom.DOMSource;
15
+import javax.xml.transform.stream.StreamResult;
16
+import java.io.ByteArrayInputStream;
17
+import java.io.InputStream;
18
+import java.io.StringWriter;
19
+import java.security.MessageDigest;
20
+import java.security.SecureRandom;
21
+import java.util.*;
22
+
23
+
24
+public class WXPayUtil {
25
+
26
+    private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
27
+
28
+    private static final Random RANDOM = new SecureRandom();
29
+
30
+    /**
31
+     * XML格式字符串转换为Map
32
+     *
33
+     * @param strXML XML字符串
34
+     * @return XML数据转换后的Map
35
+     * @throws Exception
36
+     */
37
+    public static Map<String, String> xmlToMap(String strXML) throws Exception {
38
+        try {
39
+            Map<String, String> data = new HashMap<String, String>();
40
+            DocumentBuilder documentBuilder = WXPayXmlUtil.newDocumentBuilder();
41
+            InputStream stream = new ByteArrayInputStream(strXML.getBytes("UTF-8"));
42
+            org.w3c.dom.Document doc = documentBuilder.parse(stream);
43
+            doc.getDocumentElement().normalize();
44
+            NodeList nodeList = doc.getDocumentElement().getChildNodes();
45
+            for (int idx = 0; idx < nodeList.getLength(); ++idx) {
46
+                Node node = nodeList.item(idx);
47
+                if (node.getNodeType() == Node.ELEMENT_NODE) {
48
+                    org.w3c.dom.Element element = (org.w3c.dom.Element) node;
49
+                    data.put(element.getNodeName(), element.getTextContent());
50
+                }
51
+            }
52
+            try {
53
+                stream.close();
54
+            } catch (Exception ex) {
55
+                // do nothing
56
+            }
57
+            return data;
58
+        } catch (Exception ex) {
59
+            WXPayUtil.getLogger().warn("Invalid XML, can not convert to map. Error message: {}. XML content: {}", ex.getMessage(), strXML);
60
+            throw ex;
61
+        }
62
+
63
+    }
64
+
65
+    /**
66
+     * 将Map转换为XML格式的字符串
67
+     *
68
+     * @param data Map类型数据
69
+     * @return XML格式的字符串
70
+     * @throws Exception
71
+     */
72
+    public static String mapToXml(Map<String, String> data) throws Exception {
73
+        org.w3c.dom.Document document = WXPayXmlUtil.newDocument();
74
+        org.w3c.dom.Element root = document.createElement("xml");
75
+        document.appendChild(root);
76
+        for (String key: data.keySet()) {
77
+            String value = data.get(key);
78
+            if (value == null) {
79
+                value = "";
80
+            }
81
+            value = value.trim();
82
+            org.w3c.dom.Element filed = document.createElement(key);
83
+            filed.appendChild(document.createTextNode(value));
84
+            root.appendChild(filed);
85
+        }
86
+        TransformerFactory tf = TransformerFactory.newInstance();
87
+        Transformer transformer = tf.newTransformer();
88
+        DOMSource source = new DOMSource(document);
89
+        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
90
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
91
+        StringWriter writer = new StringWriter();
92
+        StreamResult result = new StreamResult(writer);
93
+        transformer.transform(source, result);
94
+        String output = writer.getBuffer().toString(); //.replaceAll("\n|\r", "");
95
+        try {
96
+            writer.close();
97
+        }
98
+        catch (Exception ex) {
99
+        }
100
+        return output;
101
+    }
102
+
103
+
104
+    /**
105
+     * 生成带有 sign 的 XML 格式字符串
106
+     *
107
+     * @param data Map类型数据
108
+     * @param key API密钥
109
+     * @return 含有sign字段的XML
110
+     */
111
+    public static String generateSignedXml(final Map<String, String> data, String key) throws Exception {
112
+        return generateSignedXml(data, key, WXPayConstants.SignType.MD5);
113
+    }
114
+
115
+    /**
116
+     * 生成带有 sign 的 XML 格式字符串
117
+     *
118
+     * @param data Map类型数据
119
+     * @param key API密钥
120
+     * @param signType 签名类型
121
+     * @return 含有sign字段的XML
122
+     */
123
+    public static String generateSignedXml(final Map<String, String> data, String key, WXPayConstants.SignType signType) throws Exception {
124
+        String sign = generateSignature(data, key, signType);
125
+        data.put(WXPayConstants.FIELD_SIGN, sign);
126
+        return mapToXml(data);
127
+    }
128
+
129
+
130
+    /**
131
+     * 判断签名是否正确
132
+     *
133
+     * @param xmlStr XML格式数据
134
+     * @param key API密钥
135
+     * @return 签名是否正确
136
+     * @throws Exception
137
+     */
138
+    public static boolean isSignatureValid(String xmlStr, String key) throws Exception {
139
+        Map<String, String> data = xmlToMap(xmlStr);
140
+        if (!data.containsKey(WXPayConstants.FIELD_SIGN) ) {
141
+            return false;
142
+        }
143
+        String sign = data.get(WXPayConstants.FIELD_SIGN);
144
+        return generateSignature(data, key).equals(sign);
145
+    }
146
+
147
+    /**
148
+     * 判断签名是否正确,必须包含sign字段,否则返回false。使用MD5签名。
149
+     *
150
+     * @param data Map类型数据
151
+     * @param key API密钥
152
+     * @return 签名是否正确
153
+     * @throws Exception
154
+     */
155
+    public static boolean isSignatureValid(Map<String, String> data, String key) throws Exception {
156
+        return isSignatureValid(data, key, WXPayConstants.SignType.MD5);
157
+    }
158
+
159
+    /**
160
+     * 判断签名是否正确,必须包含sign字段,否则返回false。
161
+     *
162
+     * @param data Map类型数据
163
+     * @param key API密钥
164
+     * @param signType 签名方式
165
+     * @return 签名是否正确
166
+     * @throws Exception
167
+     */
168
+    public static boolean isSignatureValid(Map<String, String> data, String key, WXPayConstants.SignType signType) throws Exception {
169
+        if (!data.containsKey(WXPayConstants.FIELD_SIGN) ) {
170
+            return false;
171
+        }
172
+        String sign = data.get(WXPayConstants.FIELD_SIGN);
173
+        return generateSignature(data, key, signType).equals(sign);
174
+    }
175
+
176
+    /**
177
+     * 生成签名
178
+     *
179
+     * @param data 待签名数据
180
+     * @param key API密钥
181
+     * @return 签名
182
+     */
183
+    public static String generateSignature(final Map<String, String> data, String key) throws Exception {
184
+        return generateSignature(data, key, WXPayConstants.SignType.MD5);
185
+    }
186
+
187
+    /**
188
+     * 生成签名. 注意,若含有sign_type字段,必须和signType参数保持一致。
189
+     *
190
+     * @param data 待签名数据
191
+     * @param key API密钥
192
+     * @param signType 签名方式
193
+     * @return 签名
194
+     */
195
+    public static String generateSignature(final Map<String, String> data, String key, WXPayConstants.SignType signType) throws Exception {
196
+        Set<String> keySet = data.keySet();
197
+        String[] keyArray = keySet.toArray(new String[keySet.size()]);
198
+        Arrays.sort(keyArray);
199
+        StringBuilder sb = new StringBuilder();
200
+        for (String k : keyArray) {
201
+            if (k.equals(WXPayConstants.FIELD_SIGN)) {
202
+                continue;
203
+            }
204
+            if (data.get(k).trim().length() > 0) // 参数值为空,则不参与签名
205
+                sb.append(k).append("=").append(data.get(k).trim()).append("&");
206
+        }
207
+        sb.append("key=").append(key);
208
+        if (WXPayConstants.SignType.MD5.equals(signType)) {
209
+            return MD5(sb.toString()).toUpperCase();
210
+        }
211
+        else if (WXPayConstants.SignType.HMACSHA256.equals(signType)) {
212
+            return HMACSHA256(sb.toString(), key);
213
+        }
214
+        else {
215
+            throw new Exception(String.format("Invalid sign_type: %s", signType));
216
+        }
217
+    }
218
+
219
+
220
+    /**
221
+     * 获取随机字符串 Nonce Str
222
+     *
223
+     * @return String 随机字符串
224
+     */
225
+    public static String generateNonceStr() {
226
+        char[] nonceChars = new char[32];
227
+        for (int index = 0; index < nonceChars.length; ++index) {
228
+            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
229
+        }
230
+        return new String(nonceChars);
231
+    }
232
+
233
+
234
+    /**
235
+     * 生成 MD5
236
+     *
237
+     * @param data 待处理数据
238
+     * @return MD5结果
239
+     */
240
+    public static String MD5(String data) throws Exception {
241
+        MessageDigest md = MessageDigest.getInstance("MD5");
242
+        byte[] array = md.digest(data.getBytes("UTF-8"));
243
+        StringBuilder sb = new StringBuilder();
244
+        for (byte item : array) {
245
+            sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
246
+        }
247
+        return sb.toString().toUpperCase();
248
+    }
249
+
250
+    /**
251
+     * 生成 HMACSHA256
252
+     * @param data 待处理数据
253
+     * @param key 密钥
254
+     * @return 加密结果
255
+     * @throws Exception
256
+     */
257
+    public static String HMACSHA256(String data, String key) throws Exception {
258
+        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
259
+        SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
260
+        sha256_HMAC.init(secret_key);
261
+        byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
262
+        StringBuilder sb = new StringBuilder();
263
+        for (byte item : array) {
264
+            sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
265
+        }
266
+        return sb.toString().toUpperCase();
267
+    }
268
+
269
+    /**
270
+     * 日志
271
+     * @return
272
+     */
273
+    public static Logger getLogger() {
274
+        Logger logger = LoggerFactory.getLogger("wxpay java sdk");
275
+        return logger;
276
+    }
277
+
278
+    /**
279
+     * 获取当前时间戳,单位秒
280
+     * @return
281
+     */
282
+    public static long getCurrentTimestamp() {
283
+        return System.currentTimeMillis()/1000;
284
+    }
285
+
286
+    /**
287
+     * 获取当前时间戳,单位毫秒
288
+     * @return
289
+     */
290
+    public static long getCurrentTimestampMs() {
291
+        return System.currentTimeMillis();
292
+    }
293
+
294
+}

+ 30
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WXPayXmlUtil.java Просмотреть файл

@@ -0,0 +1,30 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+import org.w3c.dom.Document;
4
+
5
+import javax.xml.XMLConstants;
6
+import javax.xml.parsers.DocumentBuilder;
7
+import javax.xml.parsers.DocumentBuilderFactory;
8
+import javax.xml.parsers.ParserConfigurationException;
9
+
10
+/**
11
+ * 2018/7/3
12
+ */
13
+public final class WXPayXmlUtil {
14
+    public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
15
+        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
16
+        documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
17
+        documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
18
+        documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
19
+        documentBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
20
+        documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
21
+        documentBuilderFactory.setXIncludeAware(false);
22
+        documentBuilderFactory.setExpandEntityReferences(false);
23
+
24
+        return documentBuilderFactory.newDocumentBuilder();
25
+    }
26
+
27
+    public static Document newDocument() throws ParserConfigurationException {
28
+        return newDocumentBuilder().newDocument();
29
+    }
30
+}

+ 105
- 0
src/main/java/com/yunzhi/marketing/common/wxpay/WxConfig.java Просмотреть файл

@@ -0,0 +1,105 @@
1
+package com.yunzhi.marketing.common.wxpay;
2
+
3
+import java.io.*;
4
+
5
+/**
6
+ * 监控 控制器
7
+ * @author fxf
8
+ */
9
+public class WxConfig extends WXPayConfig {
10
+	private String appid;
11
+
12
+	private String machId;
13
+
14
+	private String key;
15
+
16
+	private byte[] certData;
17
+
18
+	/**
19
+	 * 获取 App ID
20
+	 *
21
+	 * @return App ID
22
+	 */
23
+	@Override
24
+	public String getAppID() {
25
+		//银城慧家
26
+		return appid;
27
+	}
28
+	
29
+	/**
30
+	 * 获取 Mch ID
31
+	 *
32
+	 * @return Mch ID
33
+	 */
34
+	@Override
35
+	public String getMchID() {
36
+		return machId;
37
+	}
38
+	
39
+	/**
40
+	 * 获取 API 密钥
41
+	 *
42
+	 * @return API密钥
43
+	 */
44
+	@Override
45
+	public String getKey() {
46
+		return key;
47
+	}
48
+	
49
+	/**
50
+	 * 获取商户证书内容
51
+	 *
52
+	 * @return 商户证书内容
53
+	 */
54
+	@Override
55
+	public InputStream getCertStream() {
56
+		ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
57
+		return certBis;
58
+
59
+	}
60
+
61
+	public int getHttpConnectTimeoutMs() {
62
+		return 8000;
63
+	}
64
+
65
+	public int getHttpReadTimeoutMs() {
66
+		return 10000;
67
+	}
68
+	
69
+	/**
70
+	 * 获取WXPayDomain, 用于多域名容灾自动切换
71
+	 *
72
+	 * @return
73
+	 */
74
+	@Override
75
+	IWXPayDomain getWXPayDomain() {
76
+		IWXPayDomain iwxPayDomain = new IWXPayDomain() {
77
+			@Override
78
+			public void report(String domain, long elapsedTimeMillis, Exception ex) {
79
+			
80
+			}
81
+			@Override
82
+			public DomainInfo getDomain(WXPayConfig config) {
83
+				return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
84
+			}
85
+		};
86
+		return iwxPayDomain;
87
+	}
88
+
89
+	public void setAppid(String appid) {
90
+		this.appid = appid;
91
+	}
92
+
93
+	public void setMachId(String machId) {
94
+		this.machId = machId;
95
+	}
96
+
97
+	public void setKey(String key) {
98
+		this.key = key;
99
+	}
100
+
101
+	public void setCertData(byte[] certData) {
102
+		this.certData = certData;
103
+	}
104
+}
105
+

+ 26
- 0
src/main/java/com/yunzhi/marketing/config/AccessConfig.java Просмотреть файл

@@ -0,0 +1,26 @@
1
+package com.yunzhi.marketing.config;
2
+
3
+import com.yunzhi.marketing.interceptor.AccessInterceptor;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
6
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7
+
8
+import javax.annotation.Resource;
9
+
10
+/**
11
+ * @author FXF
12
+ * @date 2019-02-22
13
+ */
14
+@Configuration
15
+public class AccessConfig implements WebMvcConfigurer {
16
+
17
+	@Resource
18
+	private AccessInterceptor accessInterceptor;
19
+
20
+	@Override
21
+	public void addInterceptors(InterceptorRegistry registry) {
22
+		// 自定义拦截器,添加拦截路径和排除拦截路径
23
+		registry.addInterceptor(accessInterceptor).addPathPatterns("/**");
24
+	}
25
+	
26
+}

+ 34
- 0
src/main/java/com/yunzhi/marketing/config/AliOSSProperties.java Просмотреть файл

@@ -0,0 +1,34 @@
1
+package com.yunzhi.marketing.config;
2
+
3
+
4
+import lombok.Data;
5
+import org.springframework.boot.context.properties.ConfigurationProperties;
6
+
7
+@Data
8
+@ConfigurationProperties(prefix = "ali")
9
+public class AliOSSProperties {
10
+    public static String accessKeyId;
11
+    public static String accessKeySecret;
12
+    public static OSS oss = new AliOSSProperties.OSS();
13
+
14
+    public String getAccessKeyId() { return AliOSSProperties.accessKeyId; }
15
+    public String getAccessKeySecret() { return AliOSSProperties.accessKeySecret; }
16
+    public OSS getOss() { return AliOSSProperties.oss; }
17
+
18
+    // setters
19
+    public void setAccessKeyId(String accessKeyId) {
20
+        AliOSSProperties.accessKeyId = accessKeyId;
21
+    }
22
+    public void setAccessKeySecret(String accessKeySecret) { AliOSSProperties.accessKeySecret = accessKeySecret;}
23
+
24
+    public static void setOss(OSS oss) {
25
+        AliOSSProperties.oss = oss;
26
+    }
27
+
28
+    @Data
29
+    public static class OSS {
30
+        String endpoint;
31
+        String bucketName;
32
+        String bucketURL;
33
+    }
34
+}

+ 0
- 0
src/main/java/com/yunzhi/marketing/config/FadadaProperties.java Просмотреть файл


Некоторые файлы не были показаны из-за большого количества измененных файлов