张延森 3 gadus atpakaļ
revīzija
4c4bd357f9
36 mainītis faili ar 2187 papildinājumiem un 0 dzēšanām
  1. 42
    0
      .gitignore
  2. 310
    0
      mvnw
  3. 182
    0
      mvnw.cmd
  4. 165
    0
      pom.xml
  5. 16
    0
      src/main/java/com/yunzhi/fifteenpuzzle/SpringApplication.java
  6. 71
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/AliPayUtil.java
  7. 8
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/BaseController.java
  8. 33
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/Constants.java
  9. 47
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/DateUtils.java
  10. 17
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/EncryptUtils.java
  11. 87
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/HttpUtils.java
  12. 144
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/Ida.java
  13. 31
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/MailUtils.java
  14. 11
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/MathUtils.java
  15. 76
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/ResponseBean.java
  16. 135
    0
      src/main/java/com/yunzhi/fifteenpuzzle/common/StringUtils.java
  17. 20
    0
      src/main/java/com/yunzhi/fifteenpuzzle/config/AliPayConfig.java
  18. 28
    0
      src/main/java/com/yunzhi/fifteenpuzzle/config/CorsConfig.java
  19. 21
    0
      src/main/java/com/yunzhi/fifteenpuzzle/config/LoggingFilterConfig.java
  20. 14
    0
      src/main/java/com/yunzhi/fifteenpuzzle/config/MybatisPlusConfig.java
  21. 24
    0
      src/main/java/com/yunzhi/fifteenpuzzle/config/WeixinConfig.java
  22. 177
    0
      src/main/java/com/yunzhi/fifteenpuzzle/controller/TaOrderController.java
  23. 58
    0
      src/main/java/com/yunzhi/fifteenpuzzle/controller/WxPayController.java
  24. 41
    0
      src/main/java/com/yunzhi/fifteenpuzzle/entity/TaOrder.java
  25. 25
    0
      src/main/java/com/yunzhi/fifteenpuzzle/exception/GlobalExceptionHandler.java
  26. 80
    0
      src/main/java/com/yunzhi/fifteenpuzzle/log/MysqlAppender.java
  27. 22
    0
      src/main/java/com/yunzhi/fifteenpuzzle/mapper/TaOrderMapper.java
  28. 26
    0
      src/main/java/com/yunzhi/fifteenpuzzle/service/IBaseService.java
  29. 16
    0
      src/main/java/com/yunzhi/fifteenpuzzle/service/ITaOrderService.java
  30. 108
    0
      src/main/java/com/yunzhi/fifteenpuzzle/service/impl/BaseServiceImpl.java
  31. 23
    0
      src/main/java/com/yunzhi/fifteenpuzzle/service/impl/TaOrderServiceImpl.java
  32. 16
    0
      src/main/resources/application-dev.yml
  33. 26
    0
      src/main/resources/application-prod.yml
  34. 69
    0
      src/main/resources/application.yml
  35. 5
    0
      src/main/resources/mapper/TaOrderMapper.xml
  36. 13
    0
      src/test/java/com/yunzhi/demo/SpringApplicationTests.java

+ 42
- 0
.gitignore Parādīt failu

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

+ 310
- 0
mvnw Parādīt failu

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

+ 182
- 0
mvnw.cmd Parādīt failu

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

+ 165
- 0
pom.xml Parādīt failu

@@ -0,0 +1,165 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+	<parent>
6
+		<groupId>org.springframework.boot</groupId>
7
+		<artifactId>spring-boot-starter-parent</artifactId>
8
+		<version>2.3.2.RELEASE</version>
9
+		<relativePath/> <!-- lookup parent from repository -->
10
+	</parent>
11
+	<groupId>com.yunzhi</groupId>
12
+	<artifactId>serivce-template</artifactId>
13
+	<version>0.0.1-SNAPSHOT</version>
14
+	<name>demo</name>
15
+	<description>Demo project for Spring Boot</description>
16
+
17
+	<properties>
18
+		<java.version>1.8</java.version>
19
+		<log4j.version>2.17.0</log4j.version>
20
+	</properties>
21
+
22
+	<dependencies>
23
+		<dependency>
24
+			<groupId>org.springframework.boot</groupId>
25
+			<artifactId>spring-boot-starter-web</artifactId>
26
+		</dependency>
27
+
28
+		<dependency>
29
+			<groupId>org.springframework.boot</groupId>
30
+			<artifactId>spring-boot-configuration-processor</artifactId>
31
+			<optional>true</optional>
32
+		</dependency>
33
+
34
+		<dependency>
35
+			<groupId>org.springframework.boot</groupId>
36
+			<artifactId>spring-boot-starter-test</artifactId>
37
+			<scope>test</scope>
38
+			<exclusions>
39
+				<exclusion>
40
+					<groupId>org.junit.vintage</groupId>
41
+					<artifactId>junit-vintage-engine</artifactId>
42
+				</exclusion>
43
+			</exclusions>
44
+		</dependency>
45
+
46
+		<!--mysql start-->
47
+		<dependency>
48
+			<groupId>mysql</groupId>
49
+			<artifactId>mysql-connector-java</artifactId>
50
+			<scope>runtime</scope>
51
+		</dependency>
52
+		<!--mysql end-->
53
+
54
+		<!--mybatis-plus start-->
55
+		<dependency>
56
+			<groupId>com.baomidou</groupId>
57
+			<artifactId>mybatis-plus-boot-starter</artifactId>
58
+			<version>3.1.1</version>
59
+		</dependency>
60
+		<!--mybatis-plus end-->
61
+
62
+		<!--lombok start-->
63
+		<dependency>
64
+			<groupId>org.projectlombok</groupId>
65
+			<artifactId>lombok</artifactId>
66
+			<optional>true</optional>
67
+		</dependency>
68
+		<!--lombok end-->
69
+
70
+<!--		<dependency>-->
71
+<!--			<groupId>com.github.binarywang</groupId>-->
72
+<!--			<artifactId>wx-java-pay-spring-boot-starter</artifactId>-->
73
+<!--			<version>4.2.0</version>-->
74
+<!--		</dependency>-->
75
+
76
+		<dependency>
77
+			<groupId>org.springframework.boot</groupId>
78
+			<artifactId>spring-boot-starter-mail</artifactId>
79
+		</dependency>
80
+
81
+		<dependency>
82
+			<groupId>com.alipay.sdk</groupId>
83
+			<artifactId>alipay-sdk-java</artifactId>
84
+			<version>4.22.67.ALL</version>
85
+		</dependency>
86
+
87
+	</dependencies>
88
+
89
+	<profiles>
90
+		<profile>
91
+			<id>dev</id>
92
+			<properties>
93
+				<profileActive>dev</profileActive>
94
+			</properties>
95
+			<activation>
96
+				<activeByDefault>true</activeByDefault>
97
+			</activation>
98
+
99
+			<build>
100
+				<plugins>
101
+					<plugin>
102
+						<groupId>org.springframework.boot</groupId>
103
+						<artifactId>spring-boot-maven-plugin</artifactId>
104
+						<configuration>
105
+							<excludes>
106
+								<exclude>
107
+									<groupId>org.springframework.boot</groupId>
108
+									<artifactId>spring-boot-configuration-processor</artifactId>
109
+								</exclude>
110
+							</excludes>
111
+						</configuration>
112
+					</plugin>
113
+				</plugins>
114
+				<resources>
115
+					<resource>
116
+						<directory>src/main/resources</directory>
117
+						<filtering>true</filtering>
118
+					</resource>
119
+				</resources>
120
+			</build>
121
+		</profile>
122
+
123
+		<profile>
124
+			<id>prod</id>
125
+			<properties>
126
+				<profileActive>prod</profileActive>
127
+			</properties>
128
+			<activation>
129
+				<activeByDefault>false</activeByDefault>
130
+			</activation>
131
+
132
+			<build>
133
+				<plugins>
134
+					<plugin>
135
+						<groupId>org.springframework.boot</groupId>
136
+						<artifactId>spring-boot-maven-plugin</artifactId>
137
+					</plugin>
138
+
139
+					<!-- 跳过测试 -->
140
+					<plugin>
141
+						<groupId>org.apache.maven.plugins</groupId>
142
+						<artifactId>maven-surefire-plugin</artifactId>
143
+						<configuration>
144
+							<skipTests>true</skipTests>
145
+							<testFailureIgnore>true</testFailureIgnore>
146
+						</configuration>
147
+					</plugin>
148
+				</plugins>
149
+				<resources>
150
+					<resource>
151
+						<directory>src/main/resources</directory>
152
+						<filtering>true</filtering>
153
+						<includes>
154
+							<include>**/*.xml</include>
155
+							<include>**/*.p12</include>
156
+							<include>application.yml</include>
157
+							<include>application-${profileActive}.yml</include>
158
+						</includes>
159
+					</resource>
160
+				</resources>
161
+			</build>
162
+		</profile>
163
+	</profiles>
164
+
165
+</project>

+ 16
- 0
src/main/java/com/yunzhi/fifteenpuzzle/SpringApplication.java Parādīt failu

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

+ 71
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/AliPayUtil.java Parādīt failu

@@ -0,0 +1,71 @@
1
+package com.yunzhi.fifteenpuzzle.common;
2
+
3
+import com.alipay.api.*;
4
+import com.alipay.api.request.AlipayTradePagePayRequest;
5
+import com.alipay.api.response.AlipayTradePagePayResponse;
6
+import com.yunzhi.fifteenpuzzle.config.AliPayConfig;
7
+import org.springframework.beans.BeanUtils;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.beans.factory.annotation.Value;
10
+import org.springframework.stereotype.Component;
11
+
12
+import java.io.IOException;
13
+
14
+@Component
15
+public class AliPayUtil {
16
+
17
+    AliPayConfig config;
18
+    AlipayClient client;
19
+
20
+    @Value("${yz.servBase}")
21
+    String servBase;
22
+
23
+    @Autowired
24
+    public AliPayUtil(AliPayConfig config) {
25
+        this.config = config;
26
+
27
+        try {
28
+            initClient();
29
+        } catch (IOException e) {
30
+            e.printStackTrace();
31
+        }
32
+    }
33
+
34
+    public AlipayClient getClient() {
35
+        if (client == null) {
36
+            try {
37
+                return initClient();
38
+            } catch (IOException e) {
39
+                e.printStackTrace();
40
+            }
41
+        }
42
+
43
+        return client;
44
+    }
45
+
46
+    private AlipayClient initClient() throws IOException {
47
+        AlipayConfig alipayConfig = new AlipayConfig();
48
+        BeanUtils.copyProperties(config, alipayConfig);
49
+
50
+        // privateKey 其实是文件
51
+        String privateKey = StringUtils.readFrom(this.config.getPrivateKey());
52
+        alipayConfig.setPrivateKey(privateKey);
53
+
54
+        try {
55
+            client = new DefaultAlipayClient(alipayConfig);
56
+            return client;
57
+        } catch (AlipayApiException e) {
58
+            e.printStackTrace();
59
+        }
60
+
61
+        return null;
62
+    }
63
+
64
+    public AlipayTradePagePayResponse pagePay(AlipayObject model, String orderId, String url) throws AlipayApiException {
65
+        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
66
+        request.setNotifyUrl(servBase + "/alipay/notify/" + orderId);
67
+        request.setReturnUrl(url);
68
+        request.setBizModel(model);
69
+        return client.pageExecute(request);
70
+    }
71
+}

+ 8
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/BaseController.java Parādīt failu

@@ -0,0 +1,8 @@
1
+package com.yunzhi.fifteenpuzzle.common;
2
+
3
+import org.springframework.stereotype.Component;
4
+
5
+@Component
6
+public class BaseController {
7
+
8
+}

+ 33
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/Constants.java Parādīt failu

@@ -0,0 +1,33 @@
1
+package com.yunzhi.fifteenpuzzle.common;
2
+
3
+public class Constants {
4
+    public final static String ADMIN_ID = "1";
5
+
6
+    public final static int STATUS_DELETE = -1;
7
+    public final static int STATUS_READY = 0;
8
+    public final static int STATUS_NORMAL = 1;
9
+
10
+    // 客户端类型
11
+    public final static String CLIENT_WORKER = "worker";    // 农机手
12
+    public final static String CLIENT_FARMER = "farmer";    // 农户
13
+
14
+    // 资源类型
15
+    public final static String TARGET_MACHINERY = "machinery";  // 农机
16
+    public final static String TARGET_NEWS = "news";    // 资讯
17
+
18
+    // 支付状态
19
+    public final static int PAY_READY = 0;  // 待支付
20
+    public final static int PAY_PAID = 1;  // 已支付
21
+    public final static int PAY_REFUND = -1;  // 已退款
22
+
23
+    // 是否调度
24
+    public final static int DISPATCH_READY = 0; // 待调度
25
+    public final static int DISPATCH_DONE = 1; // 已调度
26
+
27
+    // 工作状态
28
+    public final static int WORK_READY = 0;   // 预备中
29
+    public final static int WORK_DOING = 1;   // 工作中
30
+    public final static int WORK_PAUSE = 2;   // 暂停
31
+    public final static int WORK_DONE = 3;   // 已完成
32
+
33
+}

+ 47
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/DateUtils.java Parādīt failu

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

+ 17
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/EncryptUtils.java Parādīt failu

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

+ 87
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/HttpUtils.java Parādīt failu

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

+ 144
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/Ida.java Parādīt failu

@@ -0,0 +1,144 @@
1
+package com.yunzhi.fifteenpuzzle.common;
2
+
3
+import java.util.ArrayList;
4
+import java.util.HashMap;
5
+import java.util.List;
6
+import java.util.Map;
7
+
8
+public class Ida {
9
+
10
+    public final int N = 4;
11
+    public final int N2 = 16;
12
+    public final int LIMIT = 120;
13
+    private final int[] dx = { 0, -1, 0, 1 };
14
+    private final int[] dy = { 1, 0, -1, 0 };
15
+    private final String[] dir = { "←", "↓", "→", "↑" };
16
+    private static int[][] MDT; // 16 * 16 曼哈顿距离
17
+    private int limit;
18
+    private Map<Integer, Integer> path;
19
+    private Puzzle state;
20
+
21
+    public Ida() {
22
+        initMDT();
23
+    }
24
+
25
+    private void initMDT() {
26
+        MDT = new int[N2][N2];
27
+
28
+        for (int i = 0; i < N2; i++) {
29
+            int[] tmp = new int[N2];
30
+            for (int j = 0; j < N2; j++) {
31
+                int m = Math.abs(i / N - j / N);
32
+                int n = Math.abs(i % N - j % N);
33
+                tmp[j] = m + n;
34
+            }
35
+            MDT[i] = tmp;
36
+        }
37
+    }
38
+
39
+    private void reset() {
40
+        limit = 0;
41
+        path = new HashMap<>();
42
+        state = null;
43
+    }
44
+
45
+    private void swap(int[] f, int i, int j) {
46
+        int tmp = f[i];
47
+        f[i] = f[j];
48
+        f[j] = tmp;
49
+    }
50
+
51
+    private int getAllMD(Puzzle pz) {
52
+        int sum = 0;
53
+        for (int i = 0; i < N2; i++) {
54
+            int p = pz.f[i];
55
+            if (p == N2) continue;
56
+            sum += MDT[i][p - 1];   // p - 1 因为是 0 - 15 不是 1 -16
57
+        }
58
+        return sum;
59
+    }
60
+
61
+    private boolean dfs(int depth, int prev) {
62
+        if (state.MD == 0) return true;
63
+        if(depth + state.MD > limit) return false;
64
+
65
+        int sx = state.space / N;
66
+        int sy = state.space % N;
67
+
68
+        Puzzle tmp;
69
+
70
+        for (int r = 0; r < 4; r ++) {
71
+            int tx = sx + dx[r];
72
+            int ty = sy + dy[r];
73
+
74
+            if(tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
75
+
76
+            // 防止回溯
77
+            if(Math.max(prev, r) - Math.min(prev, r) == 2) continue;
78
+
79
+            tmp = state.clone();
80
+
81
+            //计算曼哈顿距离的差值,同时交换拼图块
82
+            state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
83
+            state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
84
+            swap(state.f, tx * N + ty, sx * N + sy);
85
+            state.space = tx * N + ty;
86
+
87
+            if (dfs(depth + 1, r)) {
88
+                path.put(depth, r);
89
+                return true;
90
+            }
91
+
92
+            state = tmp;
93
+        }
94
+
95
+        return false;
96
+    }
97
+
98
+    public List<String> calc(Puzzle pz) throws Exception {
99
+        reset();
100
+
101
+        pz.MD = getAllMD(pz);
102
+        for (limit = pz.MD; limit <= LIMIT; limit++) {
103
+            state = pz.clone();
104
+            if( dfs(0, -100) ) {
105
+                List<String> res = new ArrayList<>();
106
+
107
+                for (int i = 0; i < limit; i++) {
108
+                    res.add(dir[path.get(i)]);
109
+                }
110
+
111
+                return res;
112
+            }
113
+        }
114
+
115
+        throw new Exception("unsolvable");
116
+    }
117
+
118
+    public static class Puzzle {
119
+        public int[] f;
120
+        public int space;
121
+        public int MD;
122
+
123
+        public Puzzle(int[] f, int space) {
124
+            this.f = f;
125
+            this.space = space;
126
+        }
127
+
128
+        private int[] copyF() {
129
+            int length = f.length;
130
+            int[] f2 = new int[length];
131
+            for (int i = 0; i < length; i++) {
132
+                f2[i] = f[i];
133
+            }
134
+            return f2;
135
+        }
136
+
137
+        public Puzzle clone() {
138
+            int[] f2 = copyF();
139
+            Puzzle copy = new Puzzle(f2, space);
140
+            copy.MD = MD;
141
+            return copy;
142
+        }
143
+    }
144
+}

+ 31
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/MailUtils.java Parādīt failu

@@ -0,0 +1,31 @@
1
+package com.yunzhi.fifteenpuzzle.common;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.mail.javamail.JavaMailSender;
5
+import org.springframework.mail.javamail.MimeMessageHelper;
6
+import org.springframework.stereotype.Component;
7
+
8
+import javax.mail.MessagingException;
9
+import javax.mail.internet.MimeMessage;
10
+import java.util.Date;
11
+
12
+@Component
13
+public class MailUtils {
14
+    JavaMailSender javaMailSender;
15
+
16
+    @Autowired
17
+    MailUtils(JavaMailSender javaMailSender) {
18
+        this.javaMailSender = javaMailSender;
19
+    }
20
+
21
+    public void sendHTML(String to, String content) throws MessagingException {
22
+        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
23
+        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
24
+        helper.setSubject("请查收16宫格结果");
25
+        helper.setFrom("云致科技");
26
+        helper.setTo(to);
27
+        helper.setSentDate(new Date());
28
+        helper.setText(content, true);
29
+        javaMailSender.send(mimeMessage);
30
+    }
31
+}

+ 11
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/MathUtils.java Parādīt failu

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

+ 76
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/ResponseBean.java Parādīt failu

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

+ 135
- 0
src/main/java/com/yunzhi/fifteenpuzzle/common/StringUtils.java Parādīt failu

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

+ 20
- 0
src/main/java/com/yunzhi/fifteenpuzzle/config/AliPayConfig.java Parādīt failu

@@ -0,0 +1,20 @@
1
+package com.yunzhi.fifteenpuzzle.config;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.stereotype.Component;
6
+
7
+@Data
8
+@Component
9
+@ConfigurationProperties(prefix = "alipay")
10
+public class AliPayConfig {
11
+    String serverUrl;
12
+    String appId;
13
+    String privateKey;
14
+    String charset;
15
+    String format;
16
+    String signType;
17
+    String appCertPath;
18
+    String alipayPublicCertPath;
19
+    String rootCertPath;
20
+}

+ 28
- 0
src/main/java/com/yunzhi/fifteenpuzzle/config/CorsConfig.java Parādīt failu

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

+ 21
- 0
src/main/java/com/yunzhi/fifteenpuzzle/config/LoggingFilterConfig.java Parādīt failu

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

+ 14
- 0
src/main/java/com/yunzhi/fifteenpuzzle/config/MybatisPlusConfig.java Parādīt failu

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

+ 24
- 0
src/main/java/com/yunzhi/fifteenpuzzle/config/WeixinConfig.java Parādīt failu

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

+ 177
- 0
src/main/java/com/yunzhi/fifteenpuzzle/controller/TaOrderController.java Parādīt failu

@@ -0,0 +1,177 @@
1
+package com.yunzhi.fifteenpuzzle.controller;
2
+
3
+import com.alipay.api.AlipayApiException;
4
+import com.alipay.api.domain.AlipayTradePagePayModel;
5
+import com.alipay.api.response.AlipayTradePagePayResponse;
6
+import com.yunzhi.fifteenpuzzle.common.*;
7
+import com.yunzhi.fifteenpuzzle.entity.TaOrder;
8
+import com.yunzhi.fifteenpuzzle.service.ITaOrderService;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.beans.factory.annotation.Value;
11
+import org.springframework.web.bind.annotation.*;
12
+
13
+import java.text.DecimalFormat;
14
+import java.util.List;
15
+import java.util.regex.Matcher;
16
+import java.util.regex.Pattern;
17
+
18
+@RestController
19
+@RequestMapping("/")
20
+public class TaOrderController extends BaseController {
21
+
22
+    @Autowired
23
+    ITaOrderService iTaOrderService;
24
+
25
+    @Autowired
26
+    AliPayUtil aliPayUtil;
27
+
28
+    @Value("${yz.unitPrice}")
29
+    Integer unitPrice;
30
+
31
+    /**
32
+     * 获取订单号
33
+     */
34
+    @RequestMapping(value="/order-no",method= RequestMethod.GET)
35
+    public ResponseBean getOrderNo() throws Exception{
36
+        return ResponseBean.success(StringUtils.uuid());
37
+    }
38
+
39
+    /**
40
+     * 获取订单号
41
+     */
42
+    @RequestMapping(value="/order/{orderId}/answer",method= RequestMethod.GET)
43
+    public ResponseBean getAnswer(@PathVariable String orderId) throws Exception{
44
+        TaOrder taOrder = iTaOrderService.getById(orderId);
45
+        String answer = null;
46
+        if (null != taOrder && 1 == taOrder.getIsPaid()) {
47
+            answer = taOrder.getRightAnswer();
48
+        }
49
+
50
+        return ResponseBean.success(answer);
51
+    }
52
+
53
+    /**
54
+     * 提交订单
55
+     * @param taOrder 实体对象
56
+     * @return
57
+     */
58
+    @RequestMapping(value="/order-save",method= RequestMethod.POST)
59
+    public ResponseBean save(@RequestBody TaOrder taOrder) throws Exception{
60
+        if (StringUtils.isEmpty(taOrder.getOrderId())) {
61
+            return ResponseBean.error("订单编号为空, 请刷新重试");
62
+        }
63
+
64
+        TaOrder origin = iTaOrderService.getById(taOrder.getOrderId());
65
+        if (null != origin) {
66
+            return ResponseBean.error("订单编号不正确, 请刷新重试");
67
+        }
68
+
69
+        if (!checkContent(taOrder.getGameContent())) {
70
+            return ResponseBean.error("宫格内容错误, 请刷新重试");
71
+        }
72
+
73
+//        if (StringUtils.isEmpty(taOrder.getEmail())) {
74
+//            return ResponseBean.error("请填写邮箱");
75
+//        }
76
+//
77
+//        if (!isEmail(taOrder.getEmail())) {
78
+//            return ResponseBean.error("邮箱格式不正确");
79
+//        }
80
+
81
+        int[] f = new int[16];
82
+        int space = getF(taOrder.getGameContent(), f);
83
+
84
+        Ida.Puzzle pz = new Ida.Puzzle(f, space);
85
+
86
+        try {
87
+            Ida ida = new Ida();
88
+            List<String> steps = ida.calc(pz);
89
+
90
+            int charge = unitPrice == null ? 100 : unitPrice;
91
+
92
+            taOrder.setCharges(charge);
93
+//            taOrder.setRightAnswer(toHTML(steps));
94
+            taOrder.setRightAnswer(String.join(",", steps));
95
+            taOrder.setIsPaid(0);
96
+
97
+            if (!iTaOrderService.save(taOrder)) {
98
+                return ResponseBean.error("系统错误, 请重试");
99
+            } else {
100
+                AlipayTradePagePayModel model = new AlipayTradePagePayModel();
101
+                model.setOutTradeNo(taOrder.getOrderId());
102
+                double amount = taOrder.getCharges() / 100.00;
103
+                model.setTotalAmount(new DecimalFormat("0.00").format(amount));
104
+                model.setSubject("16宫格解密");
105
+                model.setProductCode("FAST_INSTANT_TRADE_PAY"); // PC 场景
106
+
107
+                try {
108
+                    AlipayTradePagePayResponse resp = aliPayUtil.pagePay(model, taOrder.getOrderId(), taOrder.getPayRtnUrl());
109
+                    return ResponseBean.success(resp.getBody());
110
+                } catch (AlipayApiException e1) {
111
+                    return ResponseBean.error(e1.getMessage());
112
+                }
113
+            }
114
+
115
+        } catch (Exception e) {
116
+            e.printStackTrace();
117
+            return ResponseBean.error("输入数字格式错误, 或者有限步骤内无解");
118
+        }
119
+    }
120
+
121
+    private String toHTML(List<String> steps) {
122
+        String html = "<div>";
123
+        for (int i = 0; i < steps.size(); i++) {
124
+            String item = steps.get(i);
125
+            String part = String.format("&nbsp; %d &nbsp; <font color=\"red\"> %s </font> &nbsp;", i+1, item);
126
+            if (i % 16 == 0 && i > 0) {
127
+                part += "<br>";
128
+            }
129
+            html += part;
130
+        }
131
+        html += "</div>";
132
+        return html;
133
+    }
134
+
135
+    private int getF(String content, int[] f) {
136
+        int space = -1;
137
+        String[] items = content.split(",");
138
+        for (int i = 0; i < items.length; i ++) {
139
+            String item = items[i];
140
+            if (StringUtils.isEmpty(item)) {
141
+                f[i] = 16;
142
+                space = i;
143
+            } else {
144
+                f[i] = Integer.parseInt(item);
145
+            }
146
+        }
147
+        return space;
148
+    }
149
+
150
+    private boolean checkContent(String content) {
151
+        if (StringUtils.isEmpty(content)) return false;
152
+
153
+        String[] items = content.split(",");
154
+        if (items.length != 16) return false;
155
+
156
+        for (String item : items) {
157
+            if (null == item || item.equals("")) continue;
158
+
159
+            int i = Integer.parseInt(item);
160
+            if (i < 1 || i > 16) {
161
+                return false;
162
+            }
163
+        }
164
+
165
+        return true;
166
+    }
167
+
168
+    boolean isEmail(String email){
169
+        if (null==email || "".equals(email)){
170
+            return false;
171
+        }
172
+        String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
173
+        Pattern p = Pattern.compile(regEx1);
174
+        Matcher m = p.matcher(email);
175
+        return m.matches();
176
+    }
177
+}

+ 58
- 0
src/main/java/com/yunzhi/fifteenpuzzle/controller/WxPayController.java Parādīt failu

@@ -0,0 +1,58 @@
1
+package com.yunzhi.fifteenpuzzle.controller;
2
+
3
+import com.yunzhi.fifteenpuzzle.common.AliPayUtil;
4
+import com.yunzhi.fifteenpuzzle.common.BaseController;
5
+import com.yunzhi.fifteenpuzzle.common.MailUtils;
6
+import com.yunzhi.fifteenpuzzle.entity.TaOrder;
7
+import com.yunzhi.fifteenpuzzle.service.ITaOrderService;
8
+import lombok.extern.slf4j.Slf4j;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.web.bind.annotation.*;
11
+
12
+import java.util.Map;
13
+
14
+@Slf4j
15
+@RestController
16
+@RequestMapping("/alipay")
17
+public class WxPayController extends BaseController {
18
+    @Autowired
19
+    public AliPayUtil aliPayUtil;
20
+
21
+    @Autowired
22
+    public ITaOrderService iTaOrderService;
23
+
24
+    @Autowired
25
+    public MailUtils mailUtils;
26
+    
27
+    @ResponseBody
28
+    @RequestMapping("/notify")
29
+    public String payNotify(@RequestParam Map<String, String> params) {
30
+        doing(params, params.get("out_trade_no"));
31
+        return "success";
32
+    }
33
+
34
+    @ResponseBody
35
+    @RequestMapping("/notify/{orderId}")
36
+    public String payNotify(@PathVariable String orderId,
37
+                            @RequestParam Map<String, String> params) {
38
+        doing(params, orderId);
39
+        return "success";
40
+    }
41
+
42
+    private void doing(Map<String, String> params, String orderId) {
43
+        String appId = params.get("app_id");
44
+        String tradeStatus = params.get("trade_status");
45
+
46
+        if ("TRADE_SUCCESS".equals(tradeStatus)) {
47
+            TaOrder taOrder = iTaOrderService.getById(orderId);
48
+            taOrder.setIsPaid(1);
49
+            iTaOrderService.updateById(taOrder);
50
+
51
+//            try {
52
+//                mailUtils.sendHTML(taOrder.getEmail(), taOrder.getRightAnswer());
53
+//            } catch (MessagingException e) {
54
+//                e.printStackTrace();
55
+//            }
56
+        }
57
+    }
58
+}

+ 41
- 0
src/main/java/com/yunzhi/fifteenpuzzle/entity/TaOrder.java Parādīt failu

@@ -0,0 +1,41 @@
1
+package com.yunzhi.fifteenpuzzle.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 java.io.Serializable;
7
+import lombok.Data;
8
+import lombok.EqualsAndHashCode;
9
+import lombok.experimental.Accessors;
10
+
11
+/**
12
+ * <p>
13
+ * 登录表
14
+ * </p>
15
+ *
16
+ * @author yansen
17
+ * @since 2022-03-07
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+public class TaOrder implements Serializable {
23
+
24
+    private static final long serialVersionUID = 1L;
25
+
26
+    @TableId(value = "order_id", type = IdType.UUID)
27
+    private String orderId;
28
+
29
+    private String gameContent;
30
+
31
+    private String rightAnswer;
32
+
33
+    private String email;
34
+
35
+    private Integer charges;
36
+
37
+    private Integer isPaid;
38
+
39
+    @TableField(exist = false)
40
+    private String payRtnUrl;
41
+}

+ 25
- 0
src/main/java/com/yunzhi/fifteenpuzzle/exception/GlobalExceptionHandler.java Parādīt failu

@@ -0,0 +1,25 @@
1
+package com.yunzhi.fifteenpuzzle.exception;
2
+
3
+import com.yunzhi.fifteenpuzzle.common.ResponseBean;
4
+import lombok.extern.slf4j.Slf4j;
5
+import org.springframework.web.bind.annotation.ExceptionHandler;
6
+import org.springframework.web.bind.annotation.ResponseBody;
7
+import org.springframework.web.bind.annotation.RestControllerAdvice;
8
+
9
+@Slf4j
10
+@RestControllerAdvice
11
+public class GlobalExceptionHandler {
12
+
13
+    @ResponseBody
14
+    @ExceptionHandler(Exception.class)
15
+    public ResponseBean handleException(Exception e){
16
+        e.printStackTrace();
17
+
18
+        String err = e.getMessage();
19
+        if (err.contains("java")) {
20
+            err = "系统内部异常";
21
+        }
22
+
23
+        return ResponseBean.error(err, ResponseBean.ERROR_UNAVAILABLE);
24
+    }
25
+}

+ 80
- 0
src/main/java/com/yunzhi/fifteenpuzzle/log/MysqlAppender.java Parādīt failu

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

+ 22
- 0
src/main/java/com/yunzhi/fifteenpuzzle/mapper/TaOrderMapper.java Parādīt failu

@@ -0,0 +1,22 @@
1
+package com.yunzhi.fifteenpuzzle.mapper;
2
+
3
+import com.yunzhi.fifteenpuzzle.entity.TaOrder;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.apache.ibatis.annotations.Update;
8
+
9
+/**
10
+ * <p>
11
+ * 登录表 Mapper 接口
12
+ * </p>
13
+ *
14
+ * @author yansen
15
+ * @since 2022-03-07
16
+ */
17
+@Mapper
18
+public interface TaOrderMapper extends BaseMapper<TaOrder> {
19
+
20
+    @Update("update ta_order set ${columnName} = #{value}} where order_id = #{orderId}")
21
+    int updateStatus(@Param("orderId") String orderId,@Param("columnName") String columnName,@Param("value") Integer value);
22
+}

+ 26
- 0
src/main/java/com/yunzhi/fifteenpuzzle/service/IBaseService.java Parādīt failu

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

+ 16
- 0
src/main/java/com/yunzhi/fifteenpuzzle/service/ITaOrderService.java Parādīt failu

@@ -0,0 +1,16 @@
1
+package com.yunzhi.fifteenpuzzle.service;
2
+
3
+import com.yunzhi.fifteenpuzzle.entity.TaOrder;
4
+
5
+/**
6
+ * <p>
7
+ * 登录表 服务类
8
+ * </p>
9
+ *
10
+ * @author yansen
11
+ * @since 2022-03-07
12
+ */
13
+public interface ITaOrderService extends IBaseService<TaOrder> {
14
+
15
+    int updateStatus(String orderId, String columnName, Integer value);
16
+}

+ 108
- 0
src/main/java/com/yunzhi/fifteenpuzzle/service/impl/BaseServiceImpl.java Parādīt failu

@@ -0,0 +1,108 @@
1
+package com.yunzhi.fifteenpuzzle.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
5
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
7
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
9
+import com.yunzhi.fifteenpuzzle.common.Constants;
10
+import com.yunzhi.fifteenpuzzle.service.IBaseService;
11
+
12
+import java.io.Serializable;
13
+
14
+public class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements IBaseService<T> {
15
+    @Override
16
+    public boolean removeLogicById(Serializable id) {
17
+
18
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
19
+        UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
20
+        updateWrapper.set("status", -1)
21
+                .eq(tableInfo.getKeyColumn(), id);
22
+
23
+        return update(updateWrapper);
24
+    }
25
+
26
+    @Override
27
+    public boolean removeBy(String column, Object value, boolean notDelete) {
28
+        if (notDelete) {
29
+            UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
30
+            updateWrapper.set("status", -1);
31
+            updateWrapper.eq(column, value);
32
+            return update(updateWrapper);
33
+        } else {
34
+            QueryWrapper<T> queryWrapper = new QueryWrapper<>();
35
+            queryWrapper.eq(column, value);
36
+            return remove(queryWrapper);
37
+        }
38
+    }
39
+
40
+    @Override
41
+    public boolean canAccessData(Serializable id, String userId) {
42
+        if (Constants.ADMIN_ID.equals(userId)) return true;
43
+
44
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
45
+
46
+        String t = tableInfo.getTableName();
47
+//        String k = tableInfo.getKeyColumn();
48
+        String kAlias = t + ".org_id";
49
+
50
+        String joinSQL = "INNER JOIN sys_user_data_scope s ON ( "+ kAlias +" = s.org_id OR "+t+".create_user = s.user_id )";
51
+        String whereSQL = "WHERE " + kAlias + " = '"+ id +"' AND s.user_id = '" + userId + "'";
52
+
53
+        String sql = joinSQL + " " + whereSQL;
54
+
55
+        QueryWrapper<T> wrapper = new QueryWrapper<>();
56
+        wrapper.last(sql);
57
+        return count(wrapper) > 0;
58
+    }
59
+
60
+    @Override
61
+    public boolean remvoeWithDataScope(Serializable id, String userId) {
62
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
63
+
64
+        String t = tableInfo.getTableName();
65
+        String k = tableInfo.getKeyColumn();
66
+        String kAlias = t + "." + k;
67
+
68
+        String joinSQL = "INNER JOIN sys_user_data_scope s ON ( "+ kAlias +" = s.org_id OR "+t+".create_user = s.user_id )";
69
+        String setSQL = "SET status = -1";
70
+        String whereSQL = "WHERE " + kAlias + " = '"+ id +"' AND s.user_id = '" + userId + "'";
71
+
72
+        String sql = joinSQL + " " + setSQL + " " + whereSQL;
73
+
74
+        UpdateWrapper<T> wrapper = new UpdateWrapper<>();
75
+        wrapper.last(sql);
76
+        return update(wrapper);
77
+    }
78
+
79
+    @Override
80
+    public int countBy(String column, Object value, boolean notDelete) {
81
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
82
+        queryWrapper.eq(column, value);
83
+        queryWrapper.gt(notDelete, "status", -1);
84
+
85
+        return count(queryWrapper);
86
+    }
87
+
88
+    @Override
89
+    public T getByButNot(String column, Object value, String col, Object val, boolean notDelete) {
90
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
91
+        queryWrapper.eq(column, value);
92
+        queryWrapper.ne(col, val);
93
+        queryWrapper.gt(notDelete, "status", -1);
94
+        queryWrapper.last("limit 1");
95
+
96
+        return getOne(queryWrapper);
97
+    }
98
+
99
+    @Override
100
+    public T getExistBy(String column, Object value, boolean normal, boolean notDelete) {
101
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
102
+        queryWrapper.eq(column, value);
103
+        queryWrapper.eq(normal, "status", 1);
104
+        queryWrapper.gt(notDelete, "status", -1);
105
+        queryWrapper.last("limit 1");
106
+        return getOne(queryWrapper);
107
+    }
108
+}

+ 23
- 0
src/main/java/com/yunzhi/fifteenpuzzle/service/impl/TaOrderServiceImpl.java Parādīt failu

@@ -0,0 +1,23 @@
1
+package com.yunzhi.fifteenpuzzle.service.impl;
2
+
3
+import com.yunzhi.fifteenpuzzle.entity.TaOrder;
4
+import com.yunzhi.fifteenpuzzle.mapper.TaOrderMapper;
5
+import com.yunzhi.fifteenpuzzle.service.ITaOrderService;
6
+import org.springframework.stereotype.Service;
7
+
8
+/**
9
+ * <p>
10
+ * 登录表 服务实现类
11
+ * </p>
12
+ *
13
+ * @author yansen
14
+ * @since 2022-03-07
15
+ */
16
+@Service
17
+public class TaOrderServiceImpl extends BaseServiceImpl<TaOrderMapper, TaOrder> implements ITaOrderService {
18
+
19
+    @Override
20
+    public int updateStatus(String orderId, String columnName, Integer value) {
21
+        return baseMapper.updateStatus(orderId, columnName, value);
22
+    }
23
+}

+ 16
- 0
src/main/resources/application-dev.yml Parādīt failu

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

+ 26
- 0
src/main/resources/application-prod.yml Parādīt failu

@@ -0,0 +1,26 @@
1
+server:
2
+  port: 8015
3
+
4
+###
5
+spring:
6
+  servlet:
7
+    multipart:
8
+      max-file-size: 10MB
9
+      max-request-size: 50MB
10
+  datasource:
11
+    url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/15-puzzle?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
12
+    username: 15puzzle
13
+    password: 15puzzle@ABCD
14
+
15
+
16
+###
17
+alipay:
18
+  serverUrl: https://openapi.alipay.com/gateway.do
19
+  appId: 2021003125644454
20
+  privateKey: /opt/yunzhi/15-puzzle/cert/privateKey.txt
21
+  charset: utf-8
22
+  format: json
23
+  signType: RSA2
24
+  appCertPath: /opt/yunzhi/15-puzzle/cert/appCertPublicKey_2021003125644454.crt
25
+  alipayPublicCertPath: /opt/yunzhi/15-puzzle/cert/alipayCertPublicKey_RSA2.crt
26
+  rootCertPath: /opt/yunzhi/15-puzzle/cert/alipayRootCert.crt

+ 69
- 0
src/main/resources/application.yml Parādīt failu

@@ -0,0 +1,69 @@
1
+###
2
+server:
3
+  port: 9000
4
+  servlet:
5
+    context-path: /api
6
+
7
+###
8
+mybatis-plus:
9
+  configuration:
10
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
11
+    call-setters-on-nulls: true
12
+  mapper-locations: classpath:mapper/**/*.xml
13
+
14
+###
15
+yz:
16
+  servBase: http://15-puzzle.njyunzhi.com/api
17
+  unitPrice: 100  # 单位分
18
+
19
+###
20
+alipay:
21
+  serverUrl: https://openapi.alipay.com/gateway.do
22
+  appId: 2021003125644454
23
+  privateKey: E:\work\15-puzzle\sevice\src\main\resources\cert\privateKey.txt
24
+  charset: utf-8
25
+  format: json
26
+  signType: RSA2
27
+  appCertPath: E:\work\15-puzzle\sevice\src\main\resources\cert\appCertPublicKey_2021003125644454.crt
28
+  alipayPublicCertPath: E:\work\15-puzzle\sevice\src\main\resources\cert\alipayCertPublicKey_RSA2.crt
29
+  rootCertPath: E:\work\15-puzzle\sevice\src\main\resources\cert\alipayRootCert.crt
30
+
31
+###
32
+weixin:
33
+  pay:
34
+    appId:
35
+    mchId:
36
+    mchKey:
37
+    subAppId:
38
+    subMchId:
39
+    keyPath:
40
+
41
+###
42
+spring:
43
+  application:
44
+    name: demo
45
+  mail:
46
+    # 配置 SMTP 服务器地址
47
+    host: smtp.qq.com
48
+    # 发送者邮箱
49
+    username: 418580217@qq.com
50
+    # 配置密码,注意不是真正的密码,而是刚刚申请到的授权码
51
+    password: gaspkkuetqqobgfc
52
+    # 端口号465或587
53
+    port: 465
54
+    # 默认的邮件编码为UTF-8
55
+    default-encoding: UTF-8
56
+    # 配置SSL 加密工厂
57
+    properties:
58
+      mail:
59
+        smtp:
60
+          socketFactoryClass: javax.net.ssl.SSLSocketFactory
61
+        #表示开启 DEBUG 模式,这样,邮件发送过程的日志会在控制台打印出来,方便排查错误
62
+        debug: true
63
+#  jackson:
64
+#    date-format: yyyy-MM-dd HH:mm:ss
65
+#    time-zone: GMT+8
66
+  profiles:
67
+    active: @profileActive@
68
+
69
+

+ 5
- 0
src/main/resources/mapper/TaOrderMapper.xml Parādīt failu

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

+ 13
- 0
src/test/java/com/yunzhi/demo/SpringApplicationTests.java Parādīt failu

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