Commit 3d76350edd87d84910d57ca9591eabd0a094c369
1 parent
fc4c9918
Exists in
master
robot inerface
Showing
42 changed files
with
2882 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,31 @@ |
1 | +HELP.md | |
2 | +target/ | |
3 | +!.mvn/wrapper/maven-wrapper.jar | |
4 | +!**/src/main/** | |
5 | +!**/src/test/** | |
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 | + | |
30 | +### VS Code ### | |
31 | +.vscode/ | ... | ... |
springboot/morning-check/.mvn/wrapper/MavenWrapperDownloader.java
0 → 100644
... | ... | @@ -0,0 +1,114 @@ |
1 | +/* | |
2 | +Licensed to the Apache Software Foundation (ASF) under one | |
3 | +or more contributor license agreements. See the NOTICE file | |
4 | +distributed with this work for additional information | |
5 | +regarding copyright ownership. The ASF licenses this file | |
6 | +to you under the Apache License, Version 2.0 (the | |
7 | +"License"); you may not use this file except in compliance | |
8 | +with the License. You may obtain a copy of the License at | |
9 | + | |
10 | + https://www.apache.org/licenses/LICENSE-2.0 | |
11 | + | |
12 | +Unless required by applicable law or agreed to in writing, | |
13 | +software distributed under the License is distributed on an | |
14 | +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | +KIND, either express or implied. See the License for the | |
16 | +specific language governing permissions and limitations | |
17 | +under the License. | |
18 | +*/ | |
19 | + | |
20 | +import java.io.File; | |
21 | +import java.io.FileInputStream; | |
22 | +import java.io.FileOutputStream; | |
23 | +import java.io.IOException; | |
24 | +import java.net.URL; | |
25 | +import java.nio.channels.Channels; | |
26 | +import java.nio.channels.ReadableByteChannel; | |
27 | +import java.util.Properties; | |
28 | + | |
29 | +public class MavenWrapperDownloader { | |
30 | + | |
31 | + /** | |
32 | + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | |
33 | + */ | |
34 | + private static final String DEFAULT_DOWNLOAD_URL = | |
35 | + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; | |
36 | + | |
37 | + /** | |
38 | + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | |
39 | + * use instead of the default one. | |
40 | + */ | |
41 | + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | |
42 | + ".mvn/wrapper/maven-wrapper.properties"; | |
43 | + | |
44 | + /** | |
45 | + * Path where the maven-wrapper.jar will be saved to. | |
46 | + */ | |
47 | + private static final String MAVEN_WRAPPER_JAR_PATH = | |
48 | + ".mvn/wrapper/maven-wrapper.jar"; | |
49 | + | |
50 | + /** | |
51 | + * Name of the property which should be used to override the default download url for the wrapper. | |
52 | + */ | |
53 | + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | |
54 | + | |
55 | + public static void main(String args[]) { | |
56 | + System.out.println("- Downloader started"); | |
57 | + File baseDirectory = new File(args[0]); | |
58 | + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | |
59 | + | |
60 | + // If the maven-wrapper.properties exists, read it and check if it contains a custom | |
61 | + // wrapperUrl parameter. | |
62 | + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | |
63 | + String url = DEFAULT_DOWNLOAD_URL; | |
64 | + if (mavenWrapperPropertyFile.exists()) { | |
65 | + FileInputStream mavenWrapperPropertyFileInputStream = null; | |
66 | + try { | |
67 | + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | |
68 | + Properties mavenWrapperProperties = new Properties(); | |
69 | + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | |
70 | + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | |
71 | + } catch (IOException e) { | |
72 | + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | |
73 | + } finally { | |
74 | + try { | |
75 | + if (mavenWrapperPropertyFileInputStream != null) { | |
76 | + mavenWrapperPropertyFileInputStream.close(); | |
77 | + } | |
78 | + } catch (IOException e) { | |
79 | + // Ignore ... | |
80 | + } | |
81 | + } | |
82 | + } | |
83 | + System.out.println("- Downloading from: : " + url); | |
84 | + | |
85 | + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | |
86 | + if (!outputFile.getParentFile().exists()) { | |
87 | + if (!outputFile.getParentFile().mkdirs()) { | |
88 | + System.out.println( | |
89 | + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | |
90 | + } | |
91 | + } | |
92 | + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | |
93 | + try { | |
94 | + downloadFileFromURL(url, outputFile); | |
95 | + System.out.println("Done"); | |
96 | + System.exit(0); | |
97 | + } catch (Throwable e) { | |
98 | + System.out.println("- Error downloading"); | |
99 | + e.printStackTrace(); | |
100 | + System.exit(1); | |
101 | + } | |
102 | + } | |
103 | + | |
104 | + private static void downloadFileFromURL(String urlString, File destination) throws Exception { | |
105 | + URL website = new URL(urlString); | |
106 | + ReadableByteChannel rbc; | |
107 | + rbc = Channels.newChannel(website.openStream()); | |
108 | + FileOutputStream fos = new FileOutputStream(destination); | |
109 | + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |
110 | + fos.close(); | |
111 | + rbc.close(); | |
112 | + } | |
113 | + | |
114 | +} | ... | ... |
No preview for this file type
springboot/morning-check/.mvn/wrapper/maven-wrapper.properties
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip | ... | ... |
... | ... | @@ -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 "$@" | ... | ... |
... | ... | @@ -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% | ... | ... |
... | ... | @@ -0,0 +1,129 @@ |
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.6.RELEASE</version> | |
9 | + <relativePath/> <!-- lookup parent from repository --> | |
10 | + </parent> | |
11 | + <groupId>com.sincere</groupId> | |
12 | + <artifactId>morning-check</artifactId> | |
13 | + <version>0.0.1-SNAPSHOT</version> | |
14 | + <name>Morning-Check</name> | |
15 | + <description>MorningCheckMachine project for Spring Boot</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 | + | |
27 | + <dependency> | |
28 | + <groupId>org.springframework.boot</groupId> | |
29 | + <artifactId>spring-boot-starter-test</artifactId> | |
30 | + <scope>test</scope> | |
31 | + </dependency> | |
32 | + | |
33 | + <dependency> | |
34 | + <groupId>org.json</groupId> | |
35 | + <artifactId>json</artifactId> | |
36 | + <version>20180813</version> | |
37 | + </dependency> | |
38 | + | |
39 | + <!--API文档配置--> | |
40 | + <dependency> | |
41 | + <groupId>io.springfox</groupId> | |
42 | + <artifactId>springfox-swagger-ui</artifactId> | |
43 | + <version>2.9.2</version> | |
44 | + </dependency> | |
45 | + | |
46 | + <dependency> | |
47 | + <groupId>io.springfox</groupId> | |
48 | + <artifactId>springfox-swagger2</artifactId> | |
49 | + <version>2.9.2</version> | |
50 | + </dependency> | |
51 | + <!--常用工具的使用--> | |
52 | + <dependency> | |
53 | + <groupId>org.apache.commons</groupId> | |
54 | + <artifactId>commons-lang3</artifactId> | |
55 | + <!--<scope>runtime</scope>--> | |
56 | + </dependency> | |
57 | + | |
58 | + <dependency> | |
59 | + <groupId>org.projectlombok</groupId> | |
60 | + <artifactId>lombok</artifactId> | |
61 | + <version>1.16.18</version> | |
62 | + </dependency> | |
63 | + <!--模拟http请求包--> | |
64 | + <dependency> | |
65 | + <groupId>org.apache.httpcomponents</groupId> | |
66 | + <artifactId>httpclient</artifactId> | |
67 | + <version>4.5.3</version> | |
68 | + </dependency> | |
69 | + <!--HttpMime是HttpClient类库包中的一部分,配合HttpClient一起使用能够解决multipart/form-data等类型上传数据的需求--> | |
70 | + <dependency> | |
71 | + <groupId>org.apache.httpcomponents</groupId> | |
72 | + <artifactId>httpmime</artifactId> | |
73 | + <version>4.5.6</version> | |
74 | + </dependency> | |
75 | + <!--Json格式的字符串序列化和反序列化 fastjson--> | |
76 | + <dependency> | |
77 | + <groupId>com.alibaba</groupId> | |
78 | + <artifactId>fastjson</artifactId> | |
79 | + <version>1.2.58</version> | |
80 | + </dependency> | |
81 | + <!--开启 cache 缓存--> | |
82 | + <dependency> | |
83 | + <groupId>org.springframework.boot</groupId> | |
84 | + <artifactId>spring-boot-starter-cache</artifactId> | |
85 | + </dependency> | |
86 | + <!-- ehcache 缓存 --> | |
87 | + <dependency> | |
88 | + <groupId>net.sf.ehcache</groupId> | |
89 | + <artifactId>ehcache</artifactId> | |
90 | + </dependency> | |
91 | + | |
92 | + <!-- 文件上传组件 --> | |
93 | + <dependency> | |
94 | + <groupId>commons-fileupload</groupId> | |
95 | + <artifactId>commons-fileupload</artifactId> | |
96 | + <version>1.3.1</version> | |
97 | + </dependency> | |
98 | + <!-- 图片处理类,例如压缩、旋转之类的 --> | |
99 | + <dependency> | |
100 | + <groupId>net.coobird</groupId> | |
101 | + <artifactId>thumbnailator</artifactId> | |
102 | + <version>0.4.8</version> | |
103 | + </dependency> | |
104 | + | |
105 | + | |
106 | + <dependency> | |
107 | + <groupId>com.microsoft.sqlserver</groupId> | |
108 | + <artifactId>mssql-jdbc</artifactId> | |
109 | + <scope>runtime</scope> | |
110 | + </dependency> | |
111 | + | |
112 | + <dependency> | |
113 | + <groupId>org.mybatis.spring.boot</groupId> | |
114 | + <artifactId>mybatis-spring-boot-starter</artifactId> | |
115 | + <version>2.0.0</version> | |
116 | + </dependency> | |
117 | + | |
118 | + </dependencies> | |
119 | + | |
120 | + <build> | |
121 | + <plugins> | |
122 | + <plugin> | |
123 | + <groupId>org.springframework.boot</groupId> | |
124 | + <artifactId>spring-boot-maven-plugin</artifactId> | |
125 | + </plugin> | |
126 | + </plugins> | |
127 | + </build> | |
128 | + | |
129 | +</project> | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/MorningCheckApplication.java
0 → 100644
... | ... | @@ -0,0 +1,35 @@ |
1 | +package com.sincere.morningcheck; | |
2 | + | |
3 | +import org.mybatis.spring.annotation.MapperScan; | |
4 | +import org.springframework.boot.SpringApplication; | |
5 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |
6 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
7 | +import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration; | |
8 | +import org.springframework.context.annotation.Bean; | |
9 | +import org.springframework.web.multipart.MultipartResolver; | |
10 | +import org.springframework.web.multipart.commons.CommonsMultipartResolver; | |
11 | + | |
12 | +//exclude表示自动配置时不包括Multipart配置 | |
13 | +//@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class}),这样写法会有警告,改成下面的写法 | |
14 | +@SpringBootApplication(exclude = {MultipartAutoConfiguration.class}) | |
15 | +public class MorningCheckApplication { | |
16 | + | |
17 | + | |
18 | + public static void main(String[] args) { | |
19 | + SpringApplication.run(MorningCheckApplication.class, args); | |
20 | + } | |
21 | + | |
22 | + /** | |
23 | + * 显示声明CommonsMultipartResolver为mutipartResolver | |
24 | + */ | |
25 | + @Bean(name = "multipartResolver") | |
26 | + public MultipartResolver multipartResolver() { | |
27 | + CommonsMultipartResolver resolver = new CommonsMultipartResolver(); | |
28 | + //resolver.setDefaultEncoding("UTF-8"); | |
29 | + //resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常 | |
30 | + resolver.setResolveLazily(true); | |
31 | + resolver.setMaxInMemorySize(40960); | |
32 | + resolver.setMaxUploadSize(50 * 1024 * 1024);//上传文件大小 50 10*1024*1024 | |
33 | + return resolver; | |
34 | + } | |
35 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/common/EhcacheUtil.java
0 → 100644
... | ... | @@ -0,0 +1,230 @@ |
1 | +package com.sincere.morningcheck.common; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSON; | |
4 | +import net.sf.ehcache.CacheException; | |
5 | +import net.sf.ehcache.CacheManager; | |
6 | +import net.sf.ehcache.Ehcache; | |
7 | +import net.sf.ehcache.Element; | |
8 | + | |
9 | +import java.io.IOException; | |
10 | +import java.io.InputStream; | |
11 | + | |
12 | +public class EhcacheUtil { | |
13 | + | |
14 | + /** | |
15 | + * CacheManage是Ehcache框架的核心接口和类,负责管理一个或多个Cache对象 | |
16 | + */ | |
17 | + private static final CacheManager CACHE_MANAGER = createCacheManager(); | |
18 | + | |
19 | + /** | |
20 | + * 描 述: 根据ehcache.xml,创建CacheManager生产器 | |
21 | + * 参 数: | |
22 | + * 返回值: net.sf.ehcache.CacheManager | |
23 | + * 创建时间: 2018/5/23 | |
24 | + */ | |
25 | + private static CacheManager createCacheManager() { | |
26 | + CacheManager cacheManager; | |
27 | + InputStream input = EhcacheUtil.class.getResourceAsStream("/ehcache.xml"); | |
28 | + | |
29 | + if (input != null) { | |
30 | + try { | |
31 | + cacheManager = CacheManager.create(input); | |
32 | + } catch (Throwable t) { | |
33 | + cacheManager = CacheManager.create(); | |
34 | + } finally { | |
35 | + try { | |
36 | + input.close(); | |
37 | + } catch (IOException e) { | |
38 | + } | |
39 | + } | |
40 | + } else { | |
41 | + cacheManager = CacheManager.create(); | |
42 | + } | |
43 | + | |
44 | + return cacheManager; | |
45 | + } | |
46 | + | |
47 | + /** | |
48 | + * The cache id. 缓存所在的位置标识 | |
49 | + */ | |
50 | + private final String id; | |
51 | + | |
52 | + /** | |
53 | + * 创建EhCache | |
54 | + */ | |
55 | + public EhcacheUtil(){ | |
56 | + this.id = this.getClass().getName(); | |
57 | + if (!CACHE_MANAGER.cacheExists(this.id)) { | |
58 | + CACHE_MANAGER.addCache(this.id); | |
59 | + } | |
60 | + } | |
61 | + | |
62 | + /** | |
63 | + * 得到当前缓存 | |
64 | + * @return | |
65 | + */ | |
66 | + private Ehcache getCache() { | |
67 | + return CACHE_MANAGER.getCache(this.id); | |
68 | + } | |
69 | + | |
70 | + /** | |
71 | + * 写入EhCache,当前实例对象T,同时转成Json格式 | |
72 | + * @param key | |
73 | + * @param value | |
74 | + * @param <T> | |
75 | + */ | |
76 | + public <T> void set(String key, T value){ | |
77 | + setObject(key, JSON.toJSONString(value)); | |
78 | + } | |
79 | + | |
80 | + /** | |
81 | + * 写入EhCache,字符串对象 | |
82 | + * @param key | |
83 | + * @param value | |
84 | + */ | |
85 | + public void set(String key, String value){ | |
86 | + setObject(key,value); | |
87 | + } | |
88 | + | |
89 | + /** | |
90 | + * 写入EhCache,当前实例对象T, 同时转成Json格式,并设置失效时间 | |
91 | + * @param key | |
92 | + * @param value | |
93 | + * @param time | |
94 | + * @param <T> | |
95 | + */ | |
96 | + public <T> void setex(String key, T value, int time){ | |
97 | + setexObject(key, JSON.toJSONString(value),time); | |
98 | + } | |
99 | + | |
100 | + /** | |
101 | + * 写入EhCache,字符串对象,并设置失效时间 | |
102 | + * @param key | |
103 | + * @param value | |
104 | + * @param time | |
105 | + */ | |
106 | + public void setex(String key, String value, int time){ | |
107 | + setexObject(key,value,time); | |
108 | + } | |
109 | + | |
110 | + /** | |
111 | + * 存入EhCache缓存 | |
112 | + * @param key | |
113 | + * @param value | |
114 | + */ | |
115 | + public void setObject(String key, Object value) { | |
116 | + try { | |
117 | + this.getCache().put(new Element(key, value)); | |
118 | + } catch (Throwable t) { | |
119 | + throw new CacheException(t.getMessage(),t); | |
120 | + } | |
121 | + } | |
122 | + | |
123 | + /** | |
124 | + * 存入EhCache缓存,并设置失效时间 | |
125 | + * @param key | |
126 | + * @param value | |
127 | + * @param time | |
128 | + */ | |
129 | + public void setexObject(String key, Object value, int time) { | |
130 | + Element element = new Element(key, value); | |
131 | + element.setTimeToLive(time); | |
132 | + try { | |
133 | + this.getCache().put(element); | |
134 | + } catch (Throwable t) { | |
135 | + throw new CacheException(t.getMessage(),t); | |
136 | + } | |
137 | + } | |
138 | + | |
139 | + /** | |
140 | + * 获取EhCache对象,字符串对象 | |
141 | + * @param key | |
142 | + * @return | |
143 | + */ | |
144 | + public String get(String key){ | |
145 | + Object value = getObject(key); | |
146 | + return value == null ? "" : value.toString(); | |
147 | + } | |
148 | + | |
149 | + /** | |
150 | + * 获取EhCache对象,当前实例对象T | |
151 | + * @param key | |
152 | + * @param clazz | |
153 | + * @param <T> | |
154 | + * @return | |
155 | + */ | |
156 | + public <T> T get(String key, Class<T> clazz){ | |
157 | + Object obj = getObject(key); | |
158 | + if(obj == null){ | |
159 | + return null; | |
160 | + } | |
161 | + return JSON.parseObject(getObject(key).toString(),clazz); | |
162 | + } | |
163 | + | |
164 | + /** | |
165 | + * 根据Key获取缓存对象 | |
166 | + * @param key | |
167 | + * @return | |
168 | + */ | |
169 | + public Object getObject(String key) { | |
170 | + try { | |
171 | + Element cachedElement = this.getCache().get(key); | |
172 | + if (cachedElement == null) { | |
173 | + return null; | |
174 | + } | |
175 | + return cachedElement.getObjectValue(); | |
176 | + } catch (Exception t) { | |
177 | + throw new CacheException(t.getMessage(),t); | |
178 | + } | |
179 | + } | |
180 | + | |
181 | + /** | |
182 | + * 删除当前Cache的key | |
183 | + * @param key | |
184 | + */ | |
185 | + public void remove(String key) { | |
186 | + try { | |
187 | + this.getCache().remove(key); | |
188 | + } catch (Throwable t) { | |
189 | + throw new CacheException(t.getMessage(),t); | |
190 | + } | |
191 | + } | |
192 | + | |
193 | + /** | |
194 | + * 获取当前Cache的数目 | |
195 | + * @return | |
196 | + */ | |
197 | + public Long dbSize() { | |
198 | + try { | |
199 | + return Long.valueOf(this.getCache().getSize()); | |
200 | + } catch (Throwable t) { | |
201 | + throw new CacheException(t.getMessage(),t); | |
202 | + } | |
203 | + } | |
204 | + | |
205 | + /** | |
206 | + * 清空当前Cache的所有缓存 | |
207 | + */ | |
208 | + public void flushDB() { | |
209 | + this.getCache().removeAll(); | |
210 | + } | |
211 | + | |
212 | + | |
213 | + /** | |
214 | + * 重写hashCode | |
215 | + * @return | |
216 | + */ | |
217 | + @Override | |
218 | + public int hashCode() { | |
219 | + return this.id.hashCode(); | |
220 | + } | |
221 | + | |
222 | + /** | |
223 | + * 重写toString | |
224 | + * @return | |
225 | + */ | |
226 | + @Override | |
227 | + public String toString() { | |
228 | + return "EHCache {" + this.id + "}"; | |
229 | + } | |
230 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/common/Encript.java
0 → 100644
... | ... | @@ -0,0 +1,45 @@ |
1 | +package com.sincere.morningcheck.common; | |
2 | + | |
3 | +import javax.crypto.Mac; | |
4 | +import javax.crypto.spec.SecretKeySpec; | |
5 | + | |
6 | +public class Encript { | |
7 | + | |
8 | + /** | |
9 | + * 将加密后的字节数组转换成字符串(原始64位) | |
10 | + * | |
11 | + * @param b 字节数组 | |
12 | + * @return 字符串 | |
13 | + */ | |
14 | + public static String byteArrayToHexString(byte[] b) { | |
15 | + StringBuilder hs = new StringBuilder(); | |
16 | + String stmp; | |
17 | + for (int n = 0; b!=null && n < b.length; n++) { | |
18 | + stmp = Integer.toHexString(b[n] & 0XFF); | |
19 | + if (stmp.length() == 1) | |
20 | + hs.append('0'); | |
21 | + hs.append(stmp); | |
22 | + } | |
23 | + return hs.toString().toLowerCase(); | |
24 | + } | |
25 | + | |
26 | + /** | |
27 | + * sha256_HMAC加密 | |
28 | + * @param message 消息 | |
29 | + * @param secret 秘钥 | |
30 | + * @return 加密后字符串 | |
31 | + * */ | |
32 | + public static String sha256_HMAC(String message, String secret) { | |
33 | + String hash = ""; | |
34 | + try { | |
35 | + Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); | |
36 | + SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256"); | |
37 | + sha256_HMAC.init(secret_key); | |
38 | + byte[] bytes = sha256_HMAC.doFinal(message.getBytes()); | |
39 | + hash = byteArrayToHexString(bytes); | |
40 | + } catch (Exception e) { | |
41 | + System.out.println("Error HmacSHA256 ===========" + e.getMessage()); | |
42 | + } | |
43 | + return hash; | |
44 | + } | |
45 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/common/ImgType.java
0 → 100644
... | ... | @@ -0,0 +1,31 @@ |
1 | +package com.sincere.morningcheck.common; | |
2 | + | |
3 | +public enum ImgType { | |
4 | + | |
5 | + // hand | |
6 | + // 口部图片类型名:mouth | |
7 | + // 眼部图片类型名: face | |
8 | + // 接送图片类型名: card | |
9 | + | |
10 | + hand(0,"hand"), | |
11 | + mouth(1,"mouth"), | |
12 | + face(2,"face"), | |
13 | + card(3,"card"); | |
14 | + | |
15 | + private final int type; | |
16 | + private final String value; | |
17 | + | |
18 | + | |
19 | + ImgType(int type, String value) { | |
20 | + this.type = type; | |
21 | + this.value = value; | |
22 | + } | |
23 | + | |
24 | + public int getType() { | |
25 | + return type; | |
26 | + } | |
27 | + | |
28 | + public String getValue() { | |
29 | + return value; | |
30 | + } | |
31 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/common/MD5.java
0 → 100644
... | ... | @@ -0,0 +1,40 @@ |
1 | +package com.sincere.morningcheck.common; | |
2 | + | |
3 | +import org.apache.commons.codec.digest.DigestUtils; | |
4 | + | |
5 | +public class MD5 { | |
6 | + | |
7 | + /** | |
8 | + * MD5方法 | |
9 | + * | |
10 | + * @param text 明文 | |
11 | + * @param key 密钥 | |
12 | + * @return 密文 | |
13 | + * @throws Exception | |
14 | + */ | |
15 | + public static String md5(String text, String key) throws Exception { | |
16 | + //加密后的字符串 | |
17 | + String encodeStr= DigestUtils.md5Hex(text + key); | |
18 | + return encodeStr; | |
19 | + } | |
20 | + | |
21 | + /** | |
22 | + * MD5验证方法 | |
23 | + * | |
24 | + * @param text 明文 | |
25 | + * @param key 密钥 | |
26 | + * @param md5 密文 | |
27 | + * @return true/false | |
28 | + * @throws Exception | |
29 | + */ | |
30 | + public static boolean verify(String text, String key, String md5) throws Exception { | |
31 | + //根据传入的密钥进行验证 | |
32 | + String md5Text = md5(text, key); | |
33 | + if(md5Text.equalsIgnoreCase(md5)) | |
34 | + { | |
35 | + return true; | |
36 | + } | |
37 | + | |
38 | + return false; | |
39 | + } | |
40 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/common/ResponseCode.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package com.sincere.morningcheck.common; | |
2 | + | |
3 | +/** | |
4 | + * Created by Ziv | |
5 | + */ | |
6 | +public enum ResponseCode { | |
7 | + | |
8 | + SUCCESS(1, "SUCCESS"), | |
9 | + ERROR(0, "ERROR"); | |
10 | + | |
11 | + | |
12 | + private final int code; | |
13 | + private final String desc; | |
14 | + | |
15 | + | |
16 | + ResponseCode(int code, String desc) { | |
17 | + this.code = code; | |
18 | + this.desc = desc; | |
19 | + } | |
20 | + | |
21 | + public int getCode() { | |
22 | + return code; | |
23 | + } | |
24 | + | |
25 | + public String getDesc() { | |
26 | + return desc; | |
27 | + } | |
28 | + | |
29 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/common/ServerResponse.java
0 → 100644
... | ... | @@ -0,0 +1,105 @@ |
1 | +package com.sincere.morningcheck.common; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
4 | +import com.fasterxml.jackson.annotation.JsonInclude; | |
5 | + | |
6 | + | |
7 | +import java.io.Serializable; | |
8 | + | |
9 | +/** | |
10 | + * Created by Ziv | |
11 | + */ | |
12 | +@JsonInclude(JsonInclude.Include.NON_EMPTY) | |
13 | + | |
14 | +public class ServerResponse<T> implements Serializable { | |
15 | + | |
16 | + /** | |
17 | + * 操作状态码 | |
18 | + */ | |
19 | + private int code; | |
20 | + /** | |
21 | + * 状态信息 | |
22 | + */ | |
23 | + private String message; | |
24 | + /** | |
25 | + * 返回的数据包 | |
26 | + */ | |
27 | + private T data; | |
28 | + | |
29 | + private ServerResponse(int code) { | |
30 | + this.code = code; | |
31 | + } | |
32 | + | |
33 | + private ServerResponse(int code, T data) { | |
34 | + this.code = code; | |
35 | + this.data = data; | |
36 | + } | |
37 | + | |
38 | + | |
39 | + private ServerResponse(int code, String message, T data) { | |
40 | + this.code = code; | |
41 | + this.message = message; | |
42 | + this.data = data; | |
43 | + } | |
44 | + private ServerResponse(int code, String message) { | |
45 | + this.code = code; | |
46 | + this.message = message; | |
47 | + } | |
48 | + | |
49 | + @JsonIgnore | |
50 | + //使之不在json序列化结果当中 | |
51 | + public boolean isSuccess() { | |
52 | + return this.code == ResponseCode.SUCCESS.getCode(); | |
53 | + } | |
54 | + | |
55 | + public int getCode() { | |
56 | + return code; | |
57 | + } | |
58 | + | |
59 | + public T getData() { | |
60 | + return data; | |
61 | + } | |
62 | + | |
63 | + public String getMessage() { | |
64 | + return message; | |
65 | + } | |
66 | + | |
67 | + | |
68 | + public static <T> ServerResponse<T> createBySuccess() { | |
69 | + return new ServerResponse<T>(ResponseCode.SUCCESS.getCode()); | |
70 | + } | |
71 | + | |
72 | + /* | |
73 | + 该方法对应的是private ServerResponse(int code,String msg)的构造方法 | |
74 | + */ | |
75 | + public static <T> ServerResponse<T> createBySuccessMessage(String message) { | |
76 | + return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(), message); | |
77 | + } | |
78 | + | |
79 | + /* | |
80 | + 该方法对应的是private ServerResponse(int code,T data)构造方法 | |
81 | + */ | |
82 | + public static <T> ServerResponse<T> createBySuccess(T data) { | |
83 | + return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(), data); | |
84 | + } | |
85 | + | |
86 | + public static <T> ServerResponse<T> createBySuccess(String message, T data) { | |
87 | + return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(), message, data); | |
88 | + } | |
89 | + | |
90 | + | |
91 | + | |
92 | + public static <T> ServerResponse<T> createByError() { | |
93 | + return new ServerResponse<T>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDesc()); | |
94 | + } | |
95 | + | |
96 | + | |
97 | + public static <T> ServerResponse<T> createByErrorMessage(String errorMessage) { | |
98 | + return new ServerResponse<T>(ResponseCode.ERROR.getCode(), errorMessage); | |
99 | + } | |
100 | + | |
101 | + public static <T> ServerResponse<T> createByErrorCodeMessage(int errorCode, String errorMessage) { | |
102 | + return new ServerResponse<T>(errorCode, errorMessage); | |
103 | + } | |
104 | + | |
105 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/config/MessageProperties.java
0 → 100644
... | ... | @@ -0,0 +1,52 @@ |
1 | +package com.sincere.morningcheck.config; | |
2 | + | |
3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
4 | +import org.springframework.context.annotation.PropertySource; | |
5 | +import org.springframework.stereotype.Component; | |
6 | + | |
7 | +@Component | |
8 | +@ConfigurationProperties(prefix="message") | |
9 | +@PropertySource("classpath:file-message.properties") | |
10 | +public class MessageProperties { | |
11 | + | |
12 | + private long fileSize; //压缩大小 | |
13 | + | |
14 | + private double scaleRatio; //压缩比例 | |
15 | + | |
16 | + private String upPath; //保存路径 | |
17 | + | |
18 | + private String imageType; //图片类型 | |
19 | + | |
20 | + public long getFileSize() { | |
21 | + return fileSize; | |
22 | + } | |
23 | + | |
24 | + public void setFileSize(long fileSize) { | |
25 | + this.fileSize = fileSize; | |
26 | + } | |
27 | + | |
28 | + public double getScaleRatio() { | |
29 | + return scaleRatio; | |
30 | + } | |
31 | + | |
32 | + public void setScaleRatio(double scaleRatio) { | |
33 | + this.scaleRatio = scaleRatio; | |
34 | + } | |
35 | + | |
36 | + public String getUpPath() { | |
37 | + return upPath; | |
38 | + } | |
39 | + | |
40 | + public void setUpPath(String upPath) { | |
41 | + this.upPath = upPath; | |
42 | + } | |
43 | + | |
44 | + public String getImageType() { | |
45 | + return imageType; | |
46 | + } | |
47 | + | |
48 | + public void setImageType(String imageType) { | |
49 | + this.imageType = imageType; | |
50 | + } | |
51 | + | |
52 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/config/Swagger2.java
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +package com.sincere.morningcheck.config; | |
2 | + | |
3 | +import org.springframework.context.annotation.Bean; | |
4 | +import org.springframework.context.annotation.Configuration; | |
5 | +import springfox.documentation.builders.ApiInfoBuilder; | |
6 | +import springfox.documentation.builders.PathSelectors; | |
7 | +import springfox.documentation.builders.RequestHandlerSelectors; | |
8 | +import springfox.documentation.service.ApiInfo; | |
9 | +import springfox.documentation.service.Contact; | |
10 | +import springfox.documentation.spi.DocumentationType; | |
11 | +import springfox.documentation.spring.web.plugins.Docket; | |
12 | +import springfox.documentation.swagger2.annotations.EnableSwagger2; | |
13 | + | |
14 | +@Configuration | |
15 | +@EnableSwagger2 | |
16 | +public class Swagger2 { | |
17 | + | |
18 | + @Bean | |
19 | + public Docket createRestApi() { | |
20 | + return new Docket(DocumentationType.SWAGGER_2) | |
21 | + .apiInfo(apiInfo()) | |
22 | + .select() | |
23 | + .apis(RequestHandlerSelectors.basePackage("com.sincere.morningcheck.controller")) | |
24 | + .paths(PathSelectors.any()) | |
25 | + .build(); | |
26 | + } | |
27 | + | |
28 | + private ApiInfo apiInfo() { | |
29 | + return new ApiInfoBuilder() | |
30 | + .title("晨检机使用的WebApi说明文档") | |
31 | + .contact(new Contact("Ziv","localhost:8080/swagger-ui.html","")) | |
32 | + .description("") | |
33 | + .termsOfServiceUrl("") | |
34 | + .version("2.0") | |
35 | + .build(); | |
36 | + } | |
37 | + | |
38 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/controller/MorningCheckController.java
0 → 100644
... | ... | @@ -0,0 +1,407 @@ |
1 | +package com.sincere.morningcheck.controller; | |
2 | + | |
3 | +import com.sincere.morningcheck.common.EhcacheUtil; | |
4 | +import com.sincere.morningcheck.common.MD5; | |
5 | +import com.sincere.morningcheck.common.ServerResponse; | |
6 | +import com.sincere.morningcheck.model.School; | |
7 | +import com.sincere.morningcheck.model.Student; | |
8 | +import com.sincere.morningcheck.model.User; | |
9 | +import com.sincere.morningcheck.service.FileUpAndDownService; | |
10 | +import com.sincere.morningcheck.service.StudentService; | |
11 | +import com.sincere.morningcheck.service.UserServer; | |
12 | +import com.sincere.morningcheck.service.impl.FileUpAndDownServiceImpl; | |
13 | +import com.sincere.morningcheck.utils.DataConvertHelper; | |
14 | +import com.sincere.morningcheck.utils.LogUtil; | |
15 | +import io.swagger.annotations.Api; | |
16 | +import io.swagger.annotations.ApiImplicitParam; | |
17 | +import io.swagger.annotations.ApiImplicitParams; | |
18 | +import io.swagger.annotations.ApiOperation; | |
19 | +import org.apache.commons.lang3.StringUtils; | |
20 | +import org.springframework.beans.factory.annotation.Autowired; | |
21 | +import org.springframework.beans.factory.annotation.Value; | |
22 | +import org.springframework.web.bind.annotation.*; | |
23 | +import org.springframework.web.multipart.MultipartFile; | |
24 | + | |
25 | +import java.text.ParseException; | |
26 | +import java.text.SimpleDateFormat; | |
27 | +import java.util.Calendar; | |
28 | +import java.util.Date; | |
29 | +import java.util.HashMap; | |
30 | +import java.util.Map; | |
31 | + | |
32 | +@RestController | |
33 | +@RequestMapping("user") | |
34 | +@Api(value = "MorningCheckController", tags = "晨检机晨检接口说明") | |
35 | +public class MorningCheckController { | |
36 | + | |
37 | + private String token = "CESHI651BB2B8AEBBF0DB2FFC9B4EAD5F04E2"; | |
38 | + | |
39 | + @Value("${salt}") | |
40 | + private String salt; | |
41 | + | |
42 | + EhcacheUtil ehcacheUtil = new EhcacheUtil(); | |
43 | + @Autowired | |
44 | + UserServer userServer; | |
45 | + | |
46 | + @Autowired | |
47 | + StudentService studentService; | |
48 | + | |
49 | + @Autowired | |
50 | + FileUpAndDownService fileUpAndDownService; | |
51 | + | |
52 | + @ApiOperation("设备请求登陆接口") | |
53 | + @ApiImplicitParams ({ | |
54 | + @ApiImplicitParam(name = "deviceNo", value = "设备号", dataType = "String",required = true,paramType = "query"), | |
55 | + @ApiImplicitParam(name = "password", value = "密码", dataType = "String",required = true,paramType = "query"), | |
56 | + @ApiImplicitParam(name = "authSign", value = "签名", dataType = "String",required = true,paramType = "query"), | |
57 | + }) | |
58 | + @PostMapping("login") | |
59 | + public ServerResponse login(@RequestParam String deviceNo, @RequestParam String password,@RequestParam String authSign){ | |
60 | + | |
61 | +// System.out.println("传入的参数:设备号"+deviceNo+",密码:"+password+",签名"+authSign); | |
62 | + ServerResponse serverResponse = null; | |
63 | + | |
64 | + Map map = new HashMap(); | |
65 | + map.put("password", password); | |
66 | + map.put("deviceNo", deviceNo); | |
67 | + | |
68 | + String queryUrl = DataConvertHelper.mapAscSortToUrl(map); | |
69 | + System.out.println(queryUrl); | |
70 | + try { | |
71 | + String signUrl = queryUrl.replace("&",""); | |
72 | + System.out.println(signUrl); | |
73 | +// String md5 = MD5.md5(signUrl, salt); | |
74 | + boolean verify = MD5.verify(signUrl,salt,authSign); | |
75 | + System.out.println("签名是否正确"+verify); | |
76 | + | |
77 | + if(verify) { | |
78 | + | |
79 | + User user = userServer.getDeviceUser(deviceNo); | |
80 | + user.setParameter("0"); | |
81 | + user.setToken(token); | |
82 | + ehcacheUtil.set("deviceId",user.getDeviceId()); | |
83 | + serverResponse = ServerResponse.createBySuccess("success",user); | |
84 | + | |
85 | + }else{ | |
86 | + | |
87 | + serverResponse = ServerResponse.createByErrorMessage("签名校验失败"); | |
88 | + LogUtil.printInfoLog("签名校验失败"); | |
89 | + | |
90 | + } | |
91 | + } | |
92 | + catch (Exception ex){ | |
93 | + ex.printStackTrace(); | |
94 | + serverResponse = ServerResponse.createByErrorMessage(ex.getMessage()); | |
95 | + } | |
96 | + | |
97 | + return serverResponse; | |
98 | + } | |
99 | + | |
100 | + @ApiOperation("获取学生、卡号信息") | |
101 | + @ApiImplicitParams ({ | |
102 | + @ApiImplicitParam(name = "token", value = "令牌", dataType = "String",required = true,paramType = "query"), | |
103 | + @ApiImplicitParam(name = "schoolId", value = "学校ID", dataType = "String",required = true,paramType = "query"), | |
104 | + @ApiImplicitParam(name = "authSign", value = "签名", dataType = "String",required = true,paramType = "query") | |
105 | + }) | |
106 | + @PostMapping("getStudents") | |
107 | + public ServerResponse getStudents(@RequestParam String token,@RequestParam Integer schoolId,@RequestParam String authSign){ | |
108 | + | |
109 | + ServerResponse serverResponse = null; | |
110 | + | |
111 | + Map map = new HashMap(); | |
112 | + map.put("token", token); | |
113 | + map.put("schoolId", String.valueOf(schoolId)); | |
114 | + | |
115 | + String queryUrl = DataConvertHelper.mapAscSortToUrl(map); | |
116 | + try { | |
117 | + String signUrl = queryUrl.replace("&",""); | |
118 | + //验证签名,看签名是否正确 | |
119 | + boolean verify = MD5.verify(signUrl,salt,authSign); | |
120 | +// boolean verify = true; | |
121 | + System.out.println("签名是否正确"+verify); | |
122 | + if(verify) { | |
123 | + | |
124 | + School school = userServer.getSchoolById(schoolId); | |
125 | + serverResponse = ServerResponse.createBySuccess("success",school); | |
126 | + } | |
127 | + else{ | |
128 | + | |
129 | + serverResponse = ServerResponse.createByErrorMessage("签名校验失败"); | |
130 | + } | |
131 | + } | |
132 | + catch (Exception ex){ | |
133 | + ex.printStackTrace(); | |
134 | + serverResponse = ServerResponse.createByErrorMessage(ex.getMessage()); | |
135 | + } | |
136 | + | |
137 | + return serverResponse; | |
138 | + } | |
139 | + | |
140 | + | |
141 | + @ApiOperation("刷卡签到") | |
142 | + @ApiImplicitParams ({ | |
143 | + @ApiImplicitParam(name = "token", value = "令牌", dataType = "String",required = true,paramType = "query"), | |
144 | + @ApiImplicitParam(name = "cardNo", value = "十进制卡号", dataType = "String",required = true,paramType = "query"), | |
145 | + @ApiImplicitParam(name = "imageId", value = "接送图像类型对应的photoId", dataType = "String",required = true,paramType = "query"), | |
146 | + @ApiImplicitParam(name = "authSign", value = "签名", dataType = "String",required = true,paramType = "query"), | |
147 | + @ApiImplicitParam(name = "date", value = "晨检日期(上传历史签到数据才有这个参数,不是当天的签到)\n" + | |
148 | + "时间格式为 : yyyy-MM-dd-HH-mm-ss", dataType = "String",paramType = "query") | |
149 | + }) | |
150 | + @PostMapping("signByCard") | |
151 | + public ServerResponse swipeCard(@RequestParam String token,@RequestParam String cardNo,@RequestParam Integer imageId,@RequestParam String authSign,@RequestParam(required = false) String date){ | |
152 | + | |
153 | +// System.out.println("刷卡签到传入的参数:卡号"+cardNo+",图片ID:"+imageId+",签名"+authSign); | |
154 | + LogUtil.printInfoLog("刷卡签到传入的参数:卡号"+cardNo+",图片ID:"+imageId+",签名"+authSign); | |
155 | + ServerResponse serverResponse = null; | |
156 | + | |
157 | + String card = DataConvertHelper.distToX(Long.valueOf(cardNo)); | |
158 | + | |
159 | + Map<String,String> map = new HashMap(); | |
160 | + map.put("token", token); | |
161 | + map.put("cardNo", cardNo);//传入的是10进制的卡号 | |
162 | + map.put("imageId",String.valueOf(imageId)); | |
163 | + | |
164 | + Date dateIn = null; | |
165 | + if(StringUtils.isBlank(date)){ | |
166 | + Calendar calendar= Calendar.getInstance(); | |
167 | +// SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); | |
168 | +// date = dateFormat.format(calendar.getTime()); | |
169 | + dateIn= calendar.getTime(); | |
170 | + | |
171 | + }else{ | |
172 | + map.put("date",date);//当date存在的时候再传 | |
173 | + try { | |
174 | + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); | |
175 | + dateIn = dateFormat.parse(date); | |
176 | + System.out.println(date);//2019-07-30-10-43-41 | |
177 | + }catch (ParseException px){ | |
178 | + px.printStackTrace(); | |
179 | + } | |
180 | + } | |
181 | + String queryUrl = DataConvertHelper.mapAscSortToUrl(map); | |
182 | + try { | |
183 | + String signUrl = queryUrl.replace("&",""); | |
184 | +// boolean verify = true; | |
185 | + boolean verify = MD5.verify(signUrl,salt,authSign); | |
186 | + System.out.println("签名是否正确"+verify); | |
187 | + if(verify) { | |
188 | + int index = imageId -1; | |
189 | + if(FileUpAndDownServiceImpl.globalFileEntities.size()>0) { | |
190 | + System.out.println("对应图像地址:" + FileUpAndDownServiceImpl.globalFileEntities.get(index).getImgObPath()); | |
191 | + } | |
192 | + //卡号,图片,刷卡时间(如果没有, 当前时间),设备号 | |
193 | + System.out.println("卡号:"+cardNo+",图片ID"+imageId+",设备标识:"+ehcacheUtil.get("deviceId")+",当前时间"+date+",刷进设备的卡号是:"+card); | |
194 | + | |
195 | + Map<String,Object> hashMap = new HashMap<>(); | |
196 | + //设备编号 | |
197 | + hashMap.put("att_id",ehcacheUtil.get("deviceId")); | |
198 | + hashMap.put("card_num",card); | |
199 | + hashMap.put("func_no","08"); | |
200 | + hashMap.put("flag",0); | |
201 | + hashMap.put("intime",dateIn); | |
202 | + System.out.println(dateIn); | |
203 | + | |
204 | + studentService.swipeCard(hashMap); | |
205 | + System.out.println("集合数量:"+hashMap.size()); | |
206 | + System.out.println(hashMap.get("arr")); | |
207 | + System.out.println(hashMap.get("iscuccess")); | |
208 | + | |
209 | + //message: 学生姓名你好 | |
210 | + Student student = studentService.getStudentByCardNo(card); | |
211 | + String msg = String.format("学生%s你好",student.getStuName()); | |
212 | + serverResponse = ServerResponse.createBySuccessMessage(msg); | |
213 | + } else{ | |
214 | + | |
215 | + serverResponse = ServerResponse.createByErrorMessage("签名校验失败"); | |
216 | + } | |
217 | + } | |
218 | + catch (Exception ex){ | |
219 | + ex.printStackTrace(); | |
220 | + serverResponse = ServerResponse.createByErrorMessage(ex.getMessage()); | |
221 | + } | |
222 | + | |
223 | + return serverResponse; | |
224 | + } | |
225 | + | |
226 | + | |
227 | + @ApiOperation("离园签到") | |
228 | + @ApiImplicitParams ({ | |
229 | + @ApiImplicitParam(name = "token", value = "令牌", dataType = "String",required = true,paramType = "query"), | |
230 | + @ApiImplicitParam(name = "cardNo", value = "卡号", dataType = "String",required = true,paramType = "query"), | |
231 | + @ApiImplicitParam(name = "imageId", value = "接送图像类型对应的photoId", dataType = "String",required = true,paramType = "query"), | |
232 | + @ApiImplicitParam(name = "authSign", value = "签名", dataType = "String",required = true,paramType = "query") | |
233 | + }) | |
234 | + @PostMapping("signOutByCard") | |
235 | + public ServerResponse signOutByCard(@RequestParam String token,@RequestParam String cardNo,@RequestParam Integer imageId,@RequestParam String authSign){ | |
236 | + | |
237 | +// System.out.println("离园签到传入的参数:卡号"+cardNo+",图片ID:"+imageId+",签名"+authSign); | |
238 | + ServerResponse serverResponse = null; | |
239 | + LogUtil.printInfoLog("离园签到传入的参数:卡号"+cardNo+",图片ID:"+imageId+",签名"+authSign); | |
240 | + | |
241 | + String card = DataConvertHelper.distToX(Long.valueOf(cardNo)); | |
242 | + | |
243 | + Map<String,String> map = new HashMap(); | |
244 | + map.put("token", token); | |
245 | + map.put("cardNo", cardNo);//传入的是10进制的卡号 | |
246 | + map.put("imageId",String.valueOf(imageId)); | |
247 | + | |
248 | + String queryUrl = DataConvertHelper.mapAscSortToUrl(map); | |
249 | + try { | |
250 | + String signUrl = queryUrl.replace("&",""); | |
251 | + boolean verify = MD5.verify(signUrl,salt,authSign); | |
252 | + System.out.println("签名是否正确"+verify); | |
253 | + if(verify) { | |
254 | + | |
255 | + int index = imageId -1; | |
256 | + if(FileUpAndDownServiceImpl.globalFileEntities.size()>0) { | |
257 | + System.out.println("对应图像地址:" + FileUpAndDownServiceImpl.globalFileEntities.get(index).getImgObPath()); | |
258 | + } | |
259 | + //卡号,图片,刷卡时间(如果没有, 当前时间),设备号 | |
260 | + System.out.println("卡号:"+cardNo+",图片ID"+imageId+",设备标识:"+ehcacheUtil.get("deviceId")+",刷进设备的卡号是:"+card); | |
261 | + Map<String,Object> hashMap = new HashMap<>(); | |
262 | + hashMap.put("att_id",ehcacheUtil.get("deviceId")); | |
263 | + hashMap.put("card_num",card); | |
264 | + hashMap.put("func_no","08"); | |
265 | + hashMap.put("flag",0); | |
266 | + hashMap.put("intime",new Date()); | |
267 | + studentService.swipeCard(hashMap); | |
268 | + System.out.println(hashMap.get("arr")); | |
269 | + System.out.println(hashMap.get("iscuccess")); | |
270 | + //message: 学生姓名你好 | |
271 | + Student student = studentService.getStudentByCardNo(card); | |
272 | + String msg = String.format("学生%s你好",student.getStuName()); | |
273 | + serverResponse = ServerResponse.createBySuccessMessage(msg); | |
274 | + }else{ | |
275 | + | |
276 | + serverResponse = ServerResponse.createByErrorMessage("签名失败"); | |
277 | + } | |
278 | + } | |
279 | + catch (Exception ex){ | |
280 | + ex.printStackTrace(); | |
281 | + serverResponse = ServerResponse.createByErrorMessage(ex.getMessage()); | |
282 | + } | |
283 | + | |
284 | + return serverResponse; | |
285 | + } | |
286 | + @RequestMapping(value = "/uploadImg", method = RequestMethod.POST) | |
287 | + @ApiOperation("上传多个文件") | |
288 | + @ApiImplicitParams ({ | |
289 | + @ApiImplicitParam(name = "token", value = "令牌", dataType = "String",required = true,paramType = "query"), | |
290 | + @ApiImplicitParam(name = "file", value = "文件列表", dataType = "String",required = true,paramType = "query"), | |
291 | + @ApiImplicitParam(name = "type", value = "图像类型", dataType = "String",required = true,paramType = "query"), | |
292 | + @ApiImplicitParam(name = "authSign", value = "签名", dataType = "String",required = true,paramType = "query") | |
293 | + }) | |
294 | + public ServerResponse moreFileUpload(@RequestParam(value = "file", required = false) MultipartFile[] file, @RequestParam(value = "token") String token, @RequestParam(value="type") String type,@RequestParam String authSign) { | |
295 | + | |
296 | + | |
297 | + LogUtil.printInfoLog("上传多个文件传入的类型:"+type+",签名:"+authSign); | |
298 | +// System.out.println("上传多个文件传入的类型:"+type+",签名:"+authSign); | |
299 | + | |
300 | + System.out.println("文件数量:"+file.length); | |
301 | + | |
302 | + ServerResponse serverResponse = null; | |
303 | + Map map = new HashMap(); | |
304 | + map.put("token", token); | |
305 | + map.put("type", type); | |
306 | + | |
307 | + String[] fileNames = type.split("_"); | |
308 | + if(fileNames.length != file.length){ | |
309 | + System.out.println("类型数量和文件数量不一致,程序中断"); | |
310 | + return ServerResponse.createByErrorMessage("类型数量和文件数量不一致,程序中断"); | |
311 | + }else { | |
312 | + System.out.println("类型数量和文件数量一致,文件已经上传"); | |
313 | + } | |
314 | + String queryUrl = DataConvertHelper.mapAscSortToUrl(map); | |
315 | + try { | |
316 | + String signUrl = queryUrl.replace("&",""); | |
317 | +// String md5 = MD5.md5(signUrl, salt); | |
318 | + boolean verify = MD5.verify(signUrl,salt,authSign); | |
319 | + System.out.println("签名是否正确"+verify); | |
320 | + if(verify) { | |
321 | + try { | |
322 | + serverResponse = fileUpAndDownService.uploadPicture(file,fileNames); | |
323 | + } catch (Exception e) { | |
324 | + System.out.println(">>>>>>图片上传异常,ex="+e.getMessage()); | |
325 | + serverResponse = ServerResponse.createByErrorMessage(String.format(">>>>>>图片上传异常,e=%s", e.getMessage())); | |
326 | + } | |
327 | + } | |
328 | + } | |
329 | + catch (Exception ex){ | |
330 | + ex.printStackTrace(); | |
331 | + serverResponse = ServerResponse.createByErrorMessage(ex.getMessage()); | |
332 | + } | |
333 | + | |
334 | + return serverResponse; | |
335 | + } | |
336 | + | |
337 | + | |
338 | + @ApiOperation("晨检报告") | |
339 | + @ApiImplicitParams ({ | |
340 | + @ApiImplicitParam(name = "token", value = "令牌", dataType = "String",required = true,paramType = "query"), | |
341 | + @ApiImplicitParam(name = "cardNo", value = "卡号", dataType = "String",required = true,paramType = "query"), | |
342 | + @ApiImplicitParam(name = "result", value = "检查结果,32位字符串", dataType = "String",required = true,paramType = "query"), | |
343 | + @ApiImplicitParam(name="robotResult",value = "晨检机器判断结果。3位字符串",dataType = "String",required = true,paramType = "query"), | |
344 | + @ApiImplicitParam(name="access",value = "入园许可。 Y : 入园 N:离园",dataType = "String",required = true,paramType = "query"), | |
345 | + @ApiImplicitParam(name="temperature",value = "体温(小于35.2时显示LOW;大于42.2时,显示HIGH)",dataType = "String",required = true,paramType = "query"), | |
346 | + @ApiImplicitParam(name="handImgId",value = "手部异常图像ID",dataType = "String",paramType = "query"), | |
347 | + @ApiImplicitParam(name = "mouthImgId", value = "嘴部异常头像ID", dataType = "String",paramType = "query"), | |
348 | + @ApiImplicitParam(name = "eyeImgId", value = "眼部异常头像ID", dataType = "String",paramType = "query"), | |
349 | + @ApiImplicitParam(name = "authSign", value = "签名", dataType = "String",required = true,paramType = "query"), | |
350 | + }) | |
351 | + @PostMapping("uploadCheckReport") | |
352 | + public ServerResponse uploadCheckReport(@RequestParam String token,@RequestParam String cardNo,@RequestParam String result,@RequestParam String robotResult,@RequestParam String access,@RequestParam String temperature,@RequestParam(required = false) String handImgId,@RequestParam(required = false) String mouthImgId,@RequestParam(required = false) String eyeImgId,@RequestParam String authSign){ | |
353 | + | |
354 | +// System.out.println("传入的参数:卡号"+cardNo+",检查结果:"+result+",检查机判断结果:"+robotResult+",签名"+authSign); | |
355 | + LogUtil.printInfoLog("传入的参数:卡号"+cardNo+",检查结果:"+result+",检查机判断结果:"+robotResult+",签名"+authSign); | |
356 | + System.out.println("嘴部异常图片ID:"+mouthImgId); | |
357 | + System.out.println("手部异常图片ID:"+handImgId); | |
358 | + System.out.println("眼部异常图片ID:"+eyeImgId); | |
359 | + System.out.println("入园许可。 Y : 入园 N:离园:入园情况:"+access); | |
360 | + | |
361 | + ServerResponse serverResponse = null; | |
362 | + | |
363 | + String card = DataConvertHelper.distToX(Long.valueOf(cardNo)); | |
364 | + | |
365 | + Map<String,String> map = new HashMap(); | |
366 | + map.put("token", token); | |
367 | + map.put("cardNo", cardNo);//传入的是10进制的卡号 | |
368 | + map.put("result",result); | |
369 | + map.put("robotResult",robotResult); | |
370 | + map.put("access",access); | |
371 | + map.put("temperature",temperature); | |
372 | + map.put("handImgId",handImgId); | |
373 | + map.put("mouthImgId",mouthImgId); | |
374 | + map.put("eyeImgId",eyeImgId); | |
375 | + | |
376 | + String queryUrl = DataConvertHelper.mapAscSortToUrl(map); | |
377 | + try { | |
378 | + String signUrl = queryUrl.replace("&",""); | |
379 | + boolean verify = MD5.verify(signUrl,salt,authSign); | |
380 | + System.out.println("签名是否正确"+verify); | |
381 | + if(verify) { | |
382 | + | |
383 | +// int index = handImgId -1; | |
384 | +// System.out.println("手部异常图像地址:"+FileUpAndDownServiceImpl.globalFileEntities.get(index).getImgObPath()); | |
385 | +// index = mouthImgId -1; | |
386 | +// System.out.println("嘴部异常图像地址:"+FileUpAndDownServiceImpl.globalFileEntities.get(index).getImgObPath()); | |
387 | +// index = eyeImgId -1; | |
388 | +// System.out.println("眼部异常图像地址:"+FileUpAndDownServiceImpl.globalFileEntities.get(index).getImgObPath()); | |
389 | + //卡号,图片,刷卡时间(如果没有, 当前时间),设备号 | |
390 | + System.out.println("卡号:"+cardNo+",图片ID"+handImgId+",设备标识:"+ehcacheUtil.get("deviceId")+",刷进设备的卡号是:"+card); | |
391 | + //message: 学生姓名你好 | |
392 | + Student student = studentService.getStudentByCardNo(card); | |
393 | + String msg = String.format("学生%s你好,你的晨检报告已经自动生成",student.getStuName()); | |
394 | + serverResponse = ServerResponse.createBySuccessMessage(msg); | |
395 | + }else{ | |
396 | + | |
397 | + serverResponse = ServerResponse.createByErrorMessage("签名校验失败"); | |
398 | + } | |
399 | + } | |
400 | + catch (Exception ex){ | |
401 | + ex.printStackTrace(); | |
402 | + serverResponse = ServerResponse.createByErrorMessage(ex.getMessage()); | |
403 | + } | |
404 | + | |
405 | + return serverResponse; | |
406 | + } | |
407 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/dao/StudentDao.java
0 → 100644
... | ... | @@ -0,0 +1,25 @@ |
1 | +package com.sincere.morningcheck.dao; | |
2 | + | |
3 | + | |
4 | +import com.sincere.morningcheck.model.Student; | |
5 | +import org.apache.ibatis.annotations.Mapper; | |
6 | +import org.apache.ibatis.annotations.Param; | |
7 | +import org.springframework.stereotype.Repository; | |
8 | + | |
9 | +import java.util.List; | |
10 | +import java.util.Map; | |
11 | + | |
12 | +@Mapper | |
13 | +@Repository | |
14 | +public interface StudentDao { | |
15 | + | |
16 | + List<Student> getStudents(@Param("schoolId") Integer schoolId); | |
17 | + | |
18 | + Student getStudentByCardNo(@Param("cardNo") String cardNo); | |
19 | + | |
20 | + /** | |
21 | + * 传入的参数和返回的结果都在map集合参数params中 | |
22 | + * @param params | |
23 | + */ | |
24 | + void swipeCard(Map<String, Object> params); | |
25 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/dao/UserDao.java
0 → 100644
... | ... | @@ -0,0 +1,22 @@ |
1 | +package com.sincere.morningcheck.dao; | |
2 | + | |
3 | +import com.sincere.morningcheck.model.School; | |
4 | +import com.sincere.morningcheck.model.User; | |
5 | + | |
6 | + | |
7 | +import org.apache.ibatis.annotations.Mapper; | |
8 | +import org.apache.ibatis.annotations.Param; | |
9 | +import org.springframework.stereotype.Repository; | |
10 | + | |
11 | +@Mapper | |
12 | +@Repository | |
13 | +public interface UserDao { | |
14 | + | |
15 | + User getUser(@Param("deviceNo") String deviceNo); | |
16 | + | |
17 | + School getSchoolById(@Param("schoolId") Integer schoolId); | |
18 | + | |
19 | +// boolean register(@Param("username") String username, @Param("password") String password); | |
20 | + | |
21 | +// User isExit(@Param("username") String username); | |
22 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/model/FileEntity.java
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +package com.sincere.morningcheck.model; | |
2 | + | |
3 | +import com.sincere.morningcheck.common.ImgType; | |
4 | +import lombok.Data; | |
5 | + | |
6 | +@Data | |
7 | +public class FileEntity { | |
8 | + | |
9 | + /** | |
10 | + * 头像ID(自增) | |
11 | + */ | |
12 | + private Integer photoId; | |
13 | + /** | |
14 | + * 头像存储的位置(绝对路径) | |
15 | + */ | |
16 | + private String imgObPath; | |
17 | + /** | |
18 | + * 文件新名称 | |
19 | + */ | |
20 | + private String fileName; | |
21 | + /** | |
22 | + * 文件储存的类型 | |
23 | + */ | |
24 | + private ImgType imgType; | |
25 | + /** | |
26 | + * 文件旧名称 | |
27 | + */ | |
28 | + private String oldFileName; | |
29 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/model/Photo.java
0 → 100644
springboot/morning-check/src/main/java/com/sincere/morningcheck/model/School.java
0 → 100644
springboot/morning-check/src/main/java/com/sincere/morningcheck/model/Student.java
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +package com.sincere.morningcheck.model; | |
2 | + | |
3 | + | |
4 | +import lombok.Data; | |
5 | + | |
6 | +@Data | |
7 | +public class Student { | |
8 | + | |
9 | + private Integer classId; | |
10 | + private Integer stuId; | |
11 | + private String stuName; | |
12 | + private String className; | |
13 | + private String cardNos; | |
14 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/model/User.java
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +package com.sincere.morningcheck.model; | |
2 | + | |
3 | +import lombok.Data; | |
4 | + | |
5 | +@Data | |
6 | +public class User { | |
7 | + | |
8 | + private Integer schoolId; | |
9 | + private String parameter; | |
10 | + private String schoolName; | |
11 | + private String deviceId; | |
12 | + private String token; | |
13 | +} | |
0 | 14 | \ No newline at end of file | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/platform/MorningCheckResult.java
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +package com.sincere.morningcheck.platform; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonInclude; | |
4 | +import lombok.Data; | |
5 | + | |
6 | +@Data | |
7 | +@JsonInclude(JsonInclude.Include.NON_EMPTY) | |
8 | +public class MorningCheckResult<T> { | |
9 | + | |
10 | + private String code; | |
11 | + | |
12 | + private String message; | |
13 | + | |
14 | + private T data; | |
15 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/service/FileUpAndDownService.java
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +package com.sincere.morningcheck.service; | |
2 | + | |
3 | +import com.sincere.morningcheck.common.ServerResponse; | |
4 | +import org.springframework.web.multipart.MultipartFile; | |
5 | + | |
6 | + | |
7 | +public interface FileUpAndDownService { | |
8 | + | |
9 | + ServerResponse uploadPicture(MultipartFile[] file, String[] file_Types) throws Exception; | |
10 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/service/StudentService.java
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +package com.sincere.morningcheck.service; | |
2 | + | |
3 | +import com.sincere.morningcheck.model.Student; | |
4 | + | |
5 | +import java.util.List; | |
6 | +import java.util.Map; | |
7 | + | |
8 | +public interface StudentService { | |
9 | + | |
10 | + List<Student> getStudents(Integer schoolId); | |
11 | + | |
12 | + Student getStudentByCardNo(String cardNo); | |
13 | + | |
14 | + void swipeCard(Map<String, Object> params); | |
15 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/service/UserServer.java
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +package com.sincere.morningcheck.service; | |
2 | + | |
3 | +import com.sincere.morningcheck.model.School; | |
4 | +import com.sincere.morningcheck.model.User; | |
5 | +import org.apache.ibatis.annotations.Param; | |
6 | + | |
7 | + | |
8 | +public interface UserServer { | |
9 | + | |
10 | + User getDeviceUser(String deviceNo); | |
11 | + | |
12 | + School getSchoolById(Integer schoolId); | |
13 | + | |
14 | + User isExit(String username); | |
15 | +} | |
0 | 16 | \ No newline at end of file | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/service/impl/FileUpAndDownServiceImpl.java
0 → 100644
... | ... | @@ -0,0 +1,115 @@ |
1 | +package com.sincere.morningcheck.service.impl; | |
2 | + | |
3 | +import com.sincere.morningcheck.common.ImgType; | |
4 | +import com.sincere.morningcheck.common.ServerResponse; | |
5 | +import com.sincere.morningcheck.config.MessageProperties; | |
6 | +import com.sincere.morningcheck.model.FileEntity; | |
7 | +import com.sincere.morningcheck.model.Photo; | |
8 | +import com.sincere.morningcheck.service.FileUpAndDownService; | |
9 | +import net.coobird.thumbnailator.Thumbnails; | |
10 | +import org.apache.commons.lang3.StringUtils; | |
11 | +import org.springframework.beans.factory.annotation.Autowired; | |
12 | +import org.springframework.stereotype.Service; | |
13 | +import org.springframework.web.multipart.MultipartFile; | |
14 | + | |
15 | +import java.io.File; | |
16 | +import java.text.SimpleDateFormat; | |
17 | +import java.util.*; | |
18 | + | |
19 | +@Service | |
20 | +public class FileUpAndDownServiceImpl implements FileUpAndDownService { | |
21 | + @Autowired | |
22 | + private MessageProperties config; //用来获取file-message.properties配置文件中的信息 | |
23 | + | |
24 | + static Integer photoId = 0; | |
25 | + public static List<FileEntity> globalFileEntities = new LinkedList<>(); | |
26 | + @Override | |
27 | + public ServerResponse uploadPicture(MultipartFile[] files, String[] file_types) throws Exception { | |
28 | + | |
29 | + System.out.println("进入上传文件方法。"); | |
30 | + List<FileEntity> fileEntities = new LinkedList<>(); | |
31 | + int i = 0; | |
32 | + for(MultipartFile file : files) { | |
33 | + System.out.println(file.getOriginalFilename()); | |
34 | + | |
35 | + try { | |
36 | + photoId++; //每进一次方法自增一次,模拟主键自增 | |
37 | + Map<String, Object> resMap = new HashMap<>(); | |
38 | + String[] IMAGE_TYPE = config.getImageType().split(","); | |
39 | + String path = null; | |
40 | + boolean flag = false; | |
41 | + for (String type : IMAGE_TYPE) { | |
42 | + if (StringUtils.endsWithIgnoreCase(file.getOriginalFilename(), type)) { | |
43 | + flag = true; | |
44 | + break; | |
45 | + } | |
46 | + } | |
47 | + if (flag) { | |
48 | + | |
49 | + // 获得文件类型 | |
50 | + String fileType = file.getContentType(); | |
51 | + // 原名称 | |
52 | + String oldFileName = file.getOriginalFilename(); | |
53 | + // 获得文件后缀名称 | |
54 | + String suffix = oldFileName.substring(oldFileName.lastIndexOf("."));//带逗号,不带逗号加1 | |
55 | + // 新名称 | |
56 | + String imgType = file_types[i]; | |
57 | + String newFileName = imgType + "_photoId"+photoId+suffix; | |
58 | + i++; | |
59 | + // 年月日文件夹 | |
60 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); | |
61 | + String basedir = sdf.format(new Date()); | |
62 | + // 进行压缩(大于4M) | |
63 | + if (file.getSize() > config.getFileSize()) { | |
64 | + path = config.getUpPath() + "/" + basedir + "/" + newFileName; | |
65 | + // 如果目录不存在则创建目录 | |
66 | + File oldFile = new File(path); | |
67 | + if (!oldFile.exists()) { | |
68 | + oldFile.mkdirs(); | |
69 | + } | |
70 | + file.transferTo(oldFile); | |
71 | + // 压缩图片 | |
72 | + Thumbnails.of(oldFile).scale(config.getScaleRatio()).toFile(path); | |
73 | + | |
74 | + } else { | |
75 | + path = config.getUpPath() + "/" + basedir + "/" + newFileName; | |
76 | + // 如果目录不存在则创建目录 | |
77 | + File uploadFile = new File(path); | |
78 | + if (!uploadFile.exists()) { | |
79 | + uploadFile.mkdirs(); | |
80 | + } | |
81 | + file.transferTo(uploadFile); | |
82 | + } | |
83 | + | |
84 | + FileEntity fileEntity = new FileEntity(); | |
85 | + fileEntity.setPhotoId(photoId); | |
86 | + fileEntity.setFileName(newFileName); | |
87 | + fileEntity.setImgObPath(path); | |
88 | + fileEntity.setOldFileName(oldFileName); | |
89 | + fileEntity.setImgType(ImgType.valueOf(imgType)); | |
90 | + | |
91 | + fileEntities.add(fileEntity); | |
92 | + | |
93 | + } else { | |
94 | + System.out.println("result:图片格式不正确,支持png|jpg|jpeg"); | |
95 | + return ServerResponse.createByErrorMessage("result:图片格式不正确,支持png|jpg|jpeg"); | |
96 | + } | |
97 | + } catch (Exception e) { | |
98 | + e.printStackTrace(); | |
99 | + throw new Exception(e.getMessage()); | |
100 | + } | |
101 | + } | |
102 | + globalFileEntities.addAll(fileEntities); | |
103 | + Map<String,Object> map = new HashMap<>(); | |
104 | + | |
105 | + List<Photo> photoIds = new ArrayList<>(); | |
106 | + | |
107 | + for (FileEntity fileEntity : fileEntities){ | |
108 | + Photo photo = new Photo(); | |
109 | + photo.setPhotoId(fileEntity.getPhotoId()); | |
110 | + photoIds.add(photo); | |
111 | + } | |
112 | + map.put("photoIds",photoIds); | |
113 | + return ServerResponse.createBySuccess(map); | |
114 | + } | |
115 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/service/impl/StudentServiceImpl.java
0 → 100644
... | ... | @@ -0,0 +1,34 @@ |
1 | +package com.sincere.morningcheck.service.impl; | |
2 | + | |
3 | +import com.sincere.morningcheck.dao.StudentDao; | |
4 | +import com.sincere.morningcheck.model.Student; | |
5 | +import com.sincere.morningcheck.service.StudentService; | |
6 | +import org.springframework.beans.factory.annotation.Autowired; | |
7 | +import org.springframework.stereotype.Service; | |
8 | + | |
9 | +import java.util.List; | |
10 | +import java.util.Map; | |
11 | + | |
12 | +@Service | |
13 | +public class StudentServiceImpl implements StudentService { | |
14 | + | |
15 | + @Autowired | |
16 | + StudentDao studentDao; | |
17 | + | |
18 | + | |
19 | + @Override | |
20 | + public List<Student> getStudents(Integer schoolId) { | |
21 | + return studentDao.getStudents(schoolId); | |
22 | + } | |
23 | + | |
24 | + @Override | |
25 | + public Student getStudentByCardNo(String cardNo) { | |
26 | + return studentDao.getStudentByCardNo(cardNo); | |
27 | + } | |
28 | + | |
29 | + @Override | |
30 | + public void swipeCard(Map<String, Object> params) { | |
31 | + | |
32 | + studentDao.swipeCard(params); | |
33 | + } | |
34 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/service/impl/UserServerImp.java
0 → 100644
... | ... | @@ -0,0 +1,63 @@ |
1 | +package com.sincere.morningcheck.service.impl; | |
2 | + | |
3 | +import com.sincere.morningcheck.dao.UserDao; | |
4 | +import com.sincere.morningcheck.model.School; | |
5 | +import com.sincere.morningcheck.model.Student; | |
6 | +import com.sincere.morningcheck.model.User; | |
7 | +import com.sincere.morningcheck.service.StudentService; | |
8 | +import com.sincere.morningcheck.service.UserServer; | |
9 | + | |
10 | +import com.sincere.morningcheck.utils.DataConvertHelper; | |
11 | +import org.springframework.beans.factory.annotation.Autowired; | |
12 | +import org.springframework.stereotype.Service; | |
13 | + | |
14 | +import java.util.List; | |
15 | + | |
16 | + | |
17 | +@Service | |
18 | +public class UserServerImp implements UserServer { | |
19 | + | |
20 | + @Autowired | |
21 | + UserDao userDao; | |
22 | + | |
23 | + @Autowired | |
24 | + StudentService studentService; | |
25 | + | |
26 | + @Override | |
27 | + public User getDeviceUser(String deviceNo) { | |
28 | + return userDao.getUser(deviceNo); | |
29 | + } | |
30 | + | |
31 | + @Override | |
32 | + public School getSchoolById(Integer schoolId) { | |
33 | + | |
34 | + School school = userDao.getSchoolById(schoolId); | |
35 | + | |
36 | + List<Student> students = studentService.getStudents(schoolId); | |
37 | + | |
38 | + for (Student student : students){ | |
39 | + | |
40 | + if(student.getCardNos().contains(",")) { | |
41 | + | |
42 | + String[] cards = student.getCardNos().split(","); | |
43 | + String distCards = ""; | |
44 | + for(String card:cards){ | |
45 | + | |
46 | + distCards +=DataConvertHelper.XToDist(card).toString()+","; | |
47 | + } | |
48 | + student.setCardNos(distCards.substring(0,distCards.length()-1)); | |
49 | + }else { | |
50 | + student.setCardNos(DataConvertHelper.XToDist(student.getCardNos()).toString()); | |
51 | + } | |
52 | + | |
53 | + } | |
54 | + school.setStudents(students); | |
55 | + | |
56 | + return school; | |
57 | + } | |
58 | + | |
59 | + @Override | |
60 | + public User isExit(String username) { | |
61 | + return null; | |
62 | + } | |
63 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/utils/ApiHelper.java
0 → 100644
... | ... | @@ -0,0 +1,297 @@ |
1 | +package com.sincere.morningcheck.utils; | |
2 | + | |
3 | +import org.apache.http.HttpEntity; | |
4 | +import org.apache.http.NameValuePair; | |
5 | +import org.apache.http.client.ClientProtocolException; | |
6 | +import org.apache.http.client.config.RequestConfig; | |
7 | +import org.apache.http.client.entity.UrlEncodedFormEntity; | |
8 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
9 | +import org.apache.http.client.methods.HttpDelete; | |
10 | +import org.apache.http.client.methods.HttpGet; | |
11 | +import org.apache.http.client.methods.HttpPost; | |
12 | +import org.apache.http.entity.ContentType; | |
13 | +import org.apache.http.entity.StringEntity; | |
14 | +import org.apache.http.entity.mime.HttpMultipartMode; | |
15 | +import org.apache.http.entity.mime.MultipartEntityBuilder; | |
16 | +import org.apache.http.entity.mime.content.FileBody; | |
17 | +import org.apache.http.impl.client.CloseableHttpClient; | |
18 | +import org.apache.http.impl.client.HttpClients; | |
19 | +import org.apache.http.message.BasicNameValuePair; | |
20 | +import org.apache.http.util.EntityUtils; | |
21 | +import org.springframework.web.multipart.MultipartFile; | |
22 | + | |
23 | +import java.io.File; | |
24 | +import java.io.IOException; | |
25 | +import java.io.UnsupportedEncodingException; | |
26 | +import java.util.*; | |
27 | + | |
28 | +public class ApiHelper { | |
29 | + | |
30 | + public static String doGet(String url,Map<String, String> headerParamMap) { | |
31 | + CloseableHttpClient httpClient = null; | |
32 | + CloseableHttpResponse response = null; | |
33 | + String result = ""; | |
34 | + try { | |
35 | + // 通过址默认配置创建一个httpClient实例 | |
36 | + httpClient = HttpClients.createDefault(); | |
37 | + // 创建httpGet远程连接实例 | |
38 | + HttpGet httpGet = new HttpGet(url); | |
39 | + // 设置请求头信息, | |
40 | + for (Map.Entry<String, String> entry : headerParamMap.entrySet()) { | |
41 | + httpGet.setHeader(entry.getKey(),entry.getValue()); | |
42 | + } | |
43 | + | |
44 | + // 设置配置请求参数 | |
45 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间 | |
46 | + .setConnectionRequestTimeout(35000)// 请求超时时间 | |
47 | + .setSocketTimeout(60000)// 数据读取超时时间 | |
48 | + .build(); | |
49 | + // 为httpGet实例设置配置 | |
50 | + httpGet.setConfig(requestConfig); | |
51 | + // 执行get请求得到返回对象 | |
52 | + response = httpClient.execute(httpGet); | |
53 | + // 通过返回对象获取返回数据 | |
54 | + HttpEntity entity = response.getEntity(); | |
55 | + // 通过EntityUtils中的toString方法将结果转换为字符串 | |
56 | + result = EntityUtils.toString(entity); | |
57 | + } catch (ClientProtocolException e) { | |
58 | + e.printStackTrace(); | |
59 | + } catch (IOException e) { | |
60 | + e.printStackTrace(); | |
61 | + } finally { | |
62 | + // 关闭资源 | |
63 | + if (null != response) { | |
64 | + try { | |
65 | + response.close(); | |
66 | + } catch (IOException e) { | |
67 | + e.printStackTrace(); | |
68 | + } | |
69 | + } | |
70 | + if (null != httpClient) { | |
71 | + try { | |
72 | + httpClient.close(); | |
73 | + } catch (IOException e) { | |
74 | + e.printStackTrace(); | |
75 | + } | |
76 | + } | |
77 | + } | |
78 | + return result; | |
79 | + } | |
80 | + | |
81 | + | |
82 | + public static String doDelete(String url,Map<String, String> headerParamMap) { | |
83 | + CloseableHttpClient httpClient = null; | |
84 | + CloseableHttpResponse response = null; | |
85 | + String result = ""; | |
86 | + try { | |
87 | + // 通过址默认配置创建一个httpClient实例 | |
88 | + httpClient = HttpClients.createDefault(); | |
89 | + // 创建HttpDelete远程连接实例 | |
90 | + HttpDelete httpDelete = new HttpDelete(url); | |
91 | + // 设置请求头信息, | |
92 | + for (Map.Entry<String, String> entry : headerParamMap.entrySet()) { | |
93 | + httpDelete.setHeader(entry.getKey(),entry.getValue()); | |
94 | + } | |
95 | + | |
96 | + // 设置配置请求参数 | |
97 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间 | |
98 | + .setConnectionRequestTimeout(35000)// 请求超时时间 | |
99 | + .setSocketTimeout(60000)// 数据读取超时时间 | |
100 | + .build(); | |
101 | + // 为httpGet实例设置配置 | |
102 | + httpDelete.setConfig(requestConfig); | |
103 | + // 执行get请求得到返回对象 | |
104 | + response = httpClient.execute(httpDelete); | |
105 | + // 通过返回对象获取返回数据 | |
106 | + HttpEntity entity = response.getEntity(); | |
107 | + // 通过EntityUtils中的toString方法将结果转换为字符串 | |
108 | + result = EntityUtils.toString(entity); | |
109 | + } catch (ClientProtocolException e) { | |
110 | + e.printStackTrace(); | |
111 | + } catch (IOException e) { | |
112 | + e.printStackTrace(); | |
113 | + } finally { | |
114 | + // 关闭资源 | |
115 | + if (null != response) { | |
116 | + try { | |
117 | + response.close(); | |
118 | + } catch (IOException e) { | |
119 | + e.printStackTrace(); | |
120 | + } | |
121 | + } | |
122 | + if (null != httpClient) { | |
123 | + try { | |
124 | + httpClient.close(); | |
125 | + } catch (IOException e) { | |
126 | + e.printStackTrace(); | |
127 | + } | |
128 | + } | |
129 | + } | |
130 | + return result; | |
131 | + } | |
132 | + | |
133 | + /** | |
134 | + * 表单格式的post请求 | |
135 | + * | |
136 | + * @param url 接口地址 | |
137 | + * @param headerParamMap 设置请求头 | |
138 | + * @param paramMap 设置请求值,表单格式的请求值 | |
139 | + * @return | |
140 | + */ | |
141 | + public static String doPost(String url, Map<String, String> headerParamMap, Map<String, Object> paramMap) { | |
142 | + CloseableHttpClient httpClient; | |
143 | + String result; | |
144 | + // 创建httpClient实例 | |
145 | + httpClient = HttpClients.createDefault(); | |
146 | + // 创建httpPost远程连接实例 | |
147 | + HttpPost httpPost = new HttpPost(url); | |
148 | + // 设置请求头 | |
149 | + httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded"); | |
150 | + for (Map.Entry<String, String> entry : headerParamMap.entrySet()) { | |
151 | + httpPost.setHeader(entry.getKey(), entry.getValue()); | |
152 | + } | |
153 | + // 配置请求参数实例 | |
154 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 设置连接主机服务超时时间 | |
155 | + .setConnectionRequestTimeout(35000)// 设置连接请求超时时间 | |
156 | + .setSocketTimeout(60000)// 设置读取数据连接超时时间 | |
157 | + .build(); | |
158 | + // 为httpPost实例设置配置 | |
159 | + httpPost.setConfig(requestConfig); | |
160 | + | |
161 | + // 封装post请求参数 | |
162 | + if (null != paramMap && paramMap.size() > 0) { | |
163 | + List<NameValuePair> nvps = new ArrayList<NameValuePair>(); | |
164 | + // 通过map集成entrySet方法获取entity | |
165 | + Set<Map.Entry<String, Object>> entrySet = paramMap.entrySet(); | |
166 | + // 循环遍历,获取迭代器 | |
167 | + Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator(); | |
168 | + while (iterator.hasNext()) { | |
169 | + Map.Entry<String, Object> mapEntry = iterator.next(); | |
170 | + nvps.add(new BasicNameValuePair(mapEntry.getKey(), mapEntry.getValue().toString())); | |
171 | + } | |
172 | + | |
173 | + // 为httpPost设置封装好的请求参数 | |
174 | + try { | |
175 | + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nvps, "UTF-8"); | |
176 | + httpPost.setEntity(entity); | |
177 | + } catch (UnsupportedEncodingException e) { | |
178 | + e.printStackTrace(); | |
179 | + } | |
180 | + } | |
181 | + result = closeHttpAndResult(httpClient, httpPost); | |
182 | + return result; | |
183 | + } | |
184 | + /** | |
185 | + * post请求,内容体比较灵活,任意字符串格式的内容 | |
186 | + * @param url | |
187 | + * @param headerParamMap | |
188 | + * @param jsonParam | |
189 | + * @return | |
190 | + */ | |
191 | + public static String doPost(String url, Map<String, String> headerParamMap, String jsonParam) { | |
192 | + CloseableHttpClient httpClient; | |
193 | +// CloseableHttpResponse httpResponse = null; | |
194 | + String result; | |
195 | + // 创建httpClient实例 | |
196 | + httpClient = HttpClients.createDefault(); | |
197 | + // 创建httpPost远程连接实例 | |
198 | + HttpPost httpPost = new HttpPost(url); | |
199 | + // 设置请求头 | |
200 | + httpPost.addHeader("Content-Type", "application/json"); | |
201 | + for (Map.Entry<String, String> entry : headerParamMap.entrySet()) { | |
202 | + httpPost.setHeader(entry.getKey(),entry.getValue()); | |
203 | + } | |
204 | + // 配置请求参数实例 | |
205 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 设置连接主机服务超时时间 | |
206 | + .setConnectionRequestTimeout(35000)// 设置连接请求超时时间 | |
207 | + .setSocketTimeout(60000)// 设置读取数据连接超时时间 | |
208 | + .build(); | |
209 | + // 为httpPost实例设置配置 | |
210 | + httpPost.setConfig(requestConfig); | |
211 | + StringEntity stringEntity = new StringEntity(jsonParam, ContentType.create("application/json","UTF-8")); | |
212 | + httpPost.setEntity(stringEntity); | |
213 | + result = closeHttpAndResult(httpClient,httpPost); | |
214 | + return result; | |
215 | + } | |
216 | + | |
217 | + | |
218 | + public static String doPost(String url, Map<String, String> headerParamMap, List<String> files) { | |
219 | + CloseableHttpClient httpClient; | |
220 | + | |
221 | + String result; | |
222 | + // 创建httpClient实例 | |
223 | + httpClient = HttpClients.createDefault(); | |
224 | + // 创建httpPost远程连接实例 | |
225 | + HttpPost httpPost = new HttpPost(url); | |
226 | + // 设置请求头 | |
227 | + httpPost.addHeader("Content-Type", "multipart/form-data"); | |
228 | + httpPost.setHeader("Accept-Encoding","gzip"); | |
229 | + httpPost.setHeader("charset", "utf-8"); | |
230 | + | |
231 | + | |
232 | + if(headerParamMap != null) { | |
233 | + for (Map.Entry<String, String> entry : headerParamMap.entrySet()) { | |
234 | + httpPost.setHeader(entry.getKey(), entry.getValue()); | |
235 | + } | |
236 | + } | |
237 | + // 配置请求参数实例 | |
238 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 设置连接主机服务超时时间 | |
239 | + .setConnectionRequestTimeout(35000)// 设置连接请求超时时间 | |
240 | + .setSocketTimeout(60000)// 设置读取数据连接超时时间 | |
241 | + .build(); | |
242 | + // 为httpPost实例设置配置 | |
243 | + httpPost.setConfig(requestConfig); | |
244 | + //创建Mime类型的类 | |
245 | + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); | |
246 | + | |
247 | + /* example for setting a HttpMultipartMode */ | |
248 | + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); | |
249 | + | |
250 | + /* example for adding an image part */ | |
251 | + FileBody fileBody = new FileBody(new File(files.get(0))); //image should be a String | |
252 | + builder.addPart("file", fileBody); | |
253 | + | |
254 | + HttpEntity entity = builder.build(); | |
255 | + | |
256 | + httpPost.setEntity(entity); | |
257 | + httpPost.setEntity(entity); | |
258 | + | |
259 | + result = closeHttpAndResult(httpClient,httpPost); | |
260 | + return result; | |
261 | + } | |
262 | + | |
263 | + private static String closeHttpAndResult(CloseableHttpClient httpClient,HttpPost httpPost){ | |
264 | + CloseableHttpResponse httpResponse = null; | |
265 | + String result = null; | |
266 | + try { | |
267 | + // httpClient对象执行post请求,并返回响应参数对象 | |
268 | + httpResponse = httpClient.execute(httpPost); | |
269 | + // 从响应对象中获取响应内容 | |
270 | + HttpEntity entity = httpResponse.getEntity(); | |
271 | + result = EntityUtils.toString(entity); | |
272 | + } catch (ClientProtocolException e) { | |
273 | + e.printStackTrace(); | |
274 | + } catch (IOException e) { | |
275 | + e.printStackTrace(); | |
276 | + } finally { | |
277 | + // 关闭资源 | |
278 | + if (null != httpResponse) { | |
279 | + try { | |
280 | + httpResponse.close(); | |
281 | + } catch (IOException e) { | |
282 | + e.printStackTrace(); | |
283 | + } | |
284 | + } | |
285 | + if (null != httpClient) { | |
286 | + try { | |
287 | + httpClient.close(); | |
288 | + } catch (IOException e) { | |
289 | + e.printStackTrace(); | |
290 | + } | |
291 | + } | |
292 | + } | |
293 | + | |
294 | + return result; | |
295 | + } | |
296 | +} | |
297 | + | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/utils/DataConvertHelper.java
0 → 100644
... | ... | @@ -0,0 +1,87 @@ |
1 | +package com.sincere.morningcheck.utils; | |
2 | + | |
3 | +import org.apache.commons.lang3.StringUtils; | |
4 | + | |
5 | +import java.math.BigInteger; | |
6 | +import java.util.*; | |
7 | + | |
8 | +public class DataConvertHelper { | |
9 | + | |
10 | + /** | |
11 | + * key-value集合转换为url键值对字符串 | |
12 | + * @param keyValues | |
13 | + * @return | |
14 | + */ | |
15 | + private static String keyValueToString(List<Map.Entry<String,String>> keyValues) { | |
16 | + | |
17 | + StringBuffer buff = new StringBuffer(); | |
18 | + for (Map.Entry<String, String> entry : keyValues) { | |
19 | + if (buff.length() > 0) { | |
20 | + buff.append("&"); | |
21 | + } | |
22 | + buff.append(entry.getKey()).append("=").append(entry.getValue()); | |
23 | + } | |
24 | + return buff.toString(); | |
25 | + | |
26 | + } | |
27 | + | |
28 | + public static String mapAscSortToUrl(Map<String,String> aMap){ | |
29 | + | |
30 | + Set<Map.Entry<String,String>> set=aMap.entrySet(); | |
31 | + | |
32 | + List<Map.Entry<String,String>> aList=new LinkedList<>(set); | |
33 | + | |
34 | + //o1在前是升序,反之是降序 | |
35 | + Collections.sort(aList,(o1,o2)-> { return o1.getKey().compareTo(o2.getKey()); }); | |
36 | + | |
37 | + return keyValueToString(aList); | |
38 | + } | |
39 | + | |
40 | + | |
41 | + /** | |
42 | + * 8位16进制的卡号转为10进制卡号 | |
43 | + * @param cardNo | |
44 | + * @return | |
45 | + */ | |
46 | + public static BigInteger XToDist(String cardNo){ | |
47 | + String newCard = ""; | |
48 | + BigInteger card = new BigInteger("0"); | |
49 | + try { | |
50 | + | |
51 | + if (StringUtils.isNotBlank(cardNo) && cardNo.length() == 8) { | |
52 | + | |
53 | + newCard += cardNo.substring(6, 8); | |
54 | + newCard += cardNo.substring(4, 6); | |
55 | + newCard += cardNo.substring(2, 4); | |
56 | + newCard += cardNo.substring(0, 2); | |
57 | + card = new BigInteger(newCard, 16); | |
58 | + } | |
59 | + }catch (Exception e){ | |
60 | + e.printStackTrace(); | |
61 | + } | |
62 | + return card; | |
63 | + } | |
64 | + | |
65 | + public static String distToX(Long num) { | |
66 | + String newCard = ""; | |
67 | + try { | |
68 | + Long valueTen = num; | |
69 | + //将十六进制格式化8位输出 | |
70 | + String cardNo = String.format("%08x", valueTen).toUpperCase(); | |
71 | + System.out.println(valueTen + " [十进制]---->[十六进制] " + cardNo); | |
72 | + | |
73 | + newCard += cardNo.substring(6, 8); | |
74 | + newCard += cardNo.substring(4, 6); | |
75 | + newCard += cardNo.substring(2, 4); | |
76 | + newCard += cardNo.substring(0, 2); | |
77 | + | |
78 | + System.out.println("两两换位之后的新卡号:"+newCard); | |
79 | + | |
80 | + }catch (Exception e){ | |
81 | + newCard = "00000000"; | |
82 | + e.printStackTrace(); | |
83 | + } | |
84 | + | |
85 | + return newCard; | |
86 | + } | |
87 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/utils/FileUtils.java
0 → 100644
... | ... | @@ -0,0 +1,90 @@ |
1 | +package com.sincere.morningcheck.utils; | |
2 | + | |
3 | +import org.springframework.web.multipart.MultipartFile; | |
4 | +import sun.misc.BASE64Decoder; | |
5 | +import sun.misc.BASE64Encoder; | |
6 | + | |
7 | +import javax.imageio.stream.FileImageInputStream; | |
8 | +import java.io.*; | |
9 | +import java.util.HashMap; | |
10 | +import java.util.Map; | |
11 | + | |
12 | +public class FileUtils { | |
13 | + | |
14 | + | |
15 | + /** | |
16 | + * @param imgStr base64编码字符串 | |
17 | + * @param path 图片路径-具体到文件 | |
18 | + * @return | |
19 | + * @Description: 将base64编码字符串转换为图片 | |
20 | + * @Author: | |
21 | + * @CreateTime: | |
22 | + */ | |
23 | + public static boolean generateImage(String imgStr, String path) { | |
24 | + if (imgStr == null) | |
25 | + return false; | |
26 | + BASE64Decoder decoder = new BASE64Decoder(); | |
27 | + try { | |
28 | +// 解密 | |
29 | + byte[] b = decoder.decodeBuffer(imgStr); | |
30 | +// 处理数据 | |
31 | + for (int i = 0; i < b.length; ++i) { | |
32 | + if (b[i] < 0) { | |
33 | + b[i] += 256; | |
34 | + } | |
35 | + } | |
36 | + OutputStream out = new FileOutputStream(path); | |
37 | + out.write(b); | |
38 | + out.flush(); | |
39 | + out.close(); | |
40 | + return true; | |
41 | + } catch (Exception e) { | |
42 | + return false; | |
43 | + } | |
44 | + } | |
45 | + | |
46 | + /** | |
47 | + * @return | |
48 | + * @Description: 根据图片地址转换为base64编码字符串 | |
49 | + * @Author: | |
50 | + * @CreateTime: | |
51 | + */ | |
52 | + public static String getImageStr(String imgFile) { | |
53 | + InputStream inputStream = null; | |
54 | + byte[] data = null; | |
55 | + try { | |
56 | + inputStream = new FileInputStream(imgFile); | |
57 | + data = new byte[inputStream.available()]; | |
58 | + inputStream.read(data); | |
59 | + inputStream.close(); | |
60 | + } catch (IOException e) { | |
61 | + e.printStackTrace(); | |
62 | + } | |
63 | + // 加密 | |
64 | + BASE64Encoder encoder = new BASE64Encoder(); | |
65 | + return encoder.encode(data); | |
66 | + } | |
67 | + | |
68 | + //图片到byte数组 | |
69 | + public static byte[] image2byte(String path) { | |
70 | + byte[] data = null; | |
71 | + FileImageInputStream input = null; | |
72 | + try { | |
73 | + input = new FileImageInputStream(new File(path)); | |
74 | + ByteArrayOutputStream output = new ByteArrayOutputStream(); | |
75 | + byte[] buf = new byte[1024]; | |
76 | + int numBytesRead = 0; | |
77 | + while ((numBytesRead = input.read(buf)) != -1) { | |
78 | + output.write(buf, 0, numBytesRead); | |
79 | + } | |
80 | + data = output.toByteArray(); | |
81 | + output.close(); | |
82 | + input.close(); | |
83 | + } catch (FileNotFoundException ex1) { | |
84 | + ex1.printStackTrace(); | |
85 | + } catch (IOException ex1) { | |
86 | + ex1.printStackTrace(); | |
87 | + } | |
88 | + return data; | |
89 | + } | |
90 | +} | ... | ... |
springboot/morning-check/src/main/java/com/sincere/morningcheck/utils/LogUtil.java
0 → 100644
... | ... | @@ -0,0 +1,45 @@ |
1 | +package com.sincere.morningcheck.utils; | |
2 | + | |
3 | +import org.slf4j.Logger; | |
4 | +import org.slf4j.LoggerFactory; | |
5 | + | |
6 | +/** | |
7 | + * @Description: 日志工具类 | |
8 | + * @Author: Ziv | |
9 | + */ | |
10 | +public class LogUtil { | |
11 | + | |
12 | + /** | |
13 | + * 将信息打印到自定义日志(my_info.log)中 | |
14 | + * @param message 需要被打印的信息 | |
15 | + */ | |
16 | + public static void printInfoLog(String message){ | |
17 | + Logger logger = LoggerFactory.getLogger("my_info"); | |
18 | + logger.info(message); | |
19 | + } | |
20 | + | |
21 | + /** | |
22 | + * 将信息打印到自定义日志(system_error.log)中 | |
23 | + * @param e 异常信息 | |
24 | + */ | |
25 | + public static void printErrorLog(Exception e, Class<?> clazz){ | |
26 | + Logger logger = LoggerFactory.getLogger(clazz); | |
27 | + | |
28 | + StringBuffer logOut = new StringBuffer(); | |
29 | + logOut.append(e.toString()); | |
30 | + | |
31 | + | |
32 | + StackTraceElement[] errorList = e.getStackTrace(); | |
33 | + for (StackTraceElement stackTraceElement : errorList) { | |
34 | + logOut.append(stackTraceElement.toString()); | |
35 | + logOut.append("\n"); | |
36 | + } | |
37 | + | |
38 | + logger.error(logOut.toString()); | |
39 | + } | |
40 | + | |
41 | + public static void printErrorLog(Class<?> clazz,String message){ | |
42 | + Logger logger = LoggerFactory.getLogger(clazz); | |
43 | + logger.error(message); | |
44 | + } | |
45 | +} | ... | ... |
springboot/morning-check/src/main/resources/application.properties
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +salt = sincere | |
2 | + | |
3 | +server.port=8999 | |
4 | + | |
5 | +spring.datasource.username=szjxtuser | |
6 | +spring.datasource.password=RQminVCJota3H1u8bBYH | |
7 | +spring.datasource.url=jdbc:sqlserver://116.62.155.137:33419;database=smartcampus | |
8 | +spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver | |
9 | + | |
10 | +mybatis.mapper-locations=classpath:/mapper/*.xml | |
11 | +mybatis.type-aliases-package=com.sincere.morningcheck.model | |
12 | + | |
13 | +# springboot ²¿Êð»·¾³µÄѡȡ | |
14 | +spring.profiles.active=dev | ... | ... |
springboot/morning-check/src/main/resources/file-message.properties
0 → 100644
... | ... | @@ -0,0 +1,100 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<configuration debug="false"> | |
3 | + <!-- 项目名称 --> | |
4 | + <property name="PROJECT_NAME" value="authjwt" /> | |
5 | + | |
6 | + <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径,不要写E:\logs,否则识别不出来,\是转义字符,需要\\才能正确识别--> | |
7 | + <property name="LOG_HOME" value="E:\\logs" /> | |
8 | + | |
9 | + <!-- 控制台输出 --> | |
10 | + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | |
11 | + <!--withJansi表示是否启用彩色日志,默认是不启用 | |
12 | + 启用彩色日志后如果报:Failed to instantiate type org.fusesource.jansi.WindowsAnsiOutputStream | |
13 | + 是因为系统缺少 Microsoft Visual C++ 2008 SP1 Redistributable 可忽视 | |
14 | + 强迫症请跳转:http://www.mcbbs.net/forum.php?mod=viewthread&tid=548550&highlight=out&page=1 | |
15 | + --> | |
16 | + <!--<withJansi>false</withJansi>--> | |
17 | + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | |
18 | + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> | |
19 | + <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] %highlight([%-5level] %logger{50} - %msg%n)</pattern> | |
20 | + <charset>UTF-8</charset> | |
21 | + </encoder> | |
22 | + </appender> | |
23 | + | |
24 | + <!-- 系统错误日志文件 --> | |
25 | + <appender name="SYSTEM_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |
26 | + <!-- 过滤器,只打印ERROR级别的日志 --> | |
27 | + <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |
28 | + <!--配置 onMatch,onMismatch 可实现只输出单个级别--> | |
29 | + <level>ERROR</level> | |
30 | + <onMatch>ACCEPT</onMatch> | |
31 | + <onMismatch>DENY</onMismatch> | |
32 | + </filter> | |
33 | + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | |
34 | + <!--日志文件输出的文件名 --> | |
35 | + <FileNamePattern>${LOG_HOME}/${PROJECT_NAME}.system_error.%d{yyyy-MM-dd}.%i.log</FileNamePattern> | |
36 | + <!--日志文件保留天数--> | |
37 | + <MaxHistory>15</MaxHistory> | |
38 | + <!--日志文件最大的大小--> | |
39 | + <MaxFileSize>10MB</MaxFileSize> | |
40 | + </rollingPolicy> | |
41 | + | |
42 | + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | |
43 | + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> | |
44 | + <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%-5level] %logger{50} - %msg%n</pattern> | |
45 | + <charset>UTF-8</charset> | |
46 | + </encoder> | |
47 | + </appender> | |
48 | + <!--<logger name="system_error" additivity="true">--> | |
49 | + <!--<appender-ref ref="SYSTEM_FILE"/>--> | |
50 | + <!--</logger>--> | |
51 | + | |
52 | + <!-- 自己打印的日志文件,用于记录重要日志信息 --> | |
53 | + <appender name="MY_INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |
54 | + <!-- 过滤器,只打印INFOR级别的日志 --> | |
55 | + <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |
56 | + <level>INFO</level> | |
57 | + <onMatch>ACCEPT</onMatch> | |
58 | + <onMismatch>DENY</onMismatch> | |
59 | + </filter> | |
60 | + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | |
61 | + <!--日志文件输出的文件名--> | |
62 | + <FileNamePattern>${LOG_HOME}\authjwt.my_info.%d{yyyy-MM-dd}.%i.log</FileNamePattern> | |
63 | + <!--日志文件保留天数--> | |
64 | + <MaxHistory>15</MaxHistory> | |
65 | + <!--日志文件最大的大小--> | |
66 | + <MaxFileSize>10MB</MaxFileSize> | |
67 | + </rollingPolicy> | |
68 | + | |
69 | + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | |
70 | + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> | |
71 | + <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%-5level] %logger{50} - %msg%n</pattern> | |
72 | + <charset>UTF-8</charset> | |
73 | + </encoder> | |
74 | + </appender> | |
75 | + <logger name="my_info" additivity="false" level="info"> | |
76 | + <appender-ref ref="MY_INFO_FILE"/> | |
77 | + </logger> | |
78 | + | |
79 | + | |
80 | + <!--name用来指定受此 logger 约束的某个包或者某个具体的类--> | |
81 | + <!--<logger name="my_info" additivity="true" level="debug">--> | |
82 | + <!--<appender-ref ref="CONSOLE"/>--> | |
83 | + <!--</logger>--> | |
84 | + <!-- 开发环境下的日志配置 --> | |
85 | + <springProfile name="dev"> | |
86 | + <root level="info"> | |
87 | + <appender-ref ref="CONSOLE"/> | |
88 | + <appender-ref ref="SYSTEM_FILE" /> | |
89 | + <appender-ref ref="MY_INFO_FILE" /> | |
90 | + </root> | |
91 | + </springProfile> | |
92 | + | |
93 | + <!-- 生产环境下的日志配置 --> | |
94 | + <springProfile name="prod"> | |
95 | + <root level="INFO"> | |
96 | + <appender-ref ref="SYSTEM_FILE" /> | |
97 | + <appender-ref ref="MY_INFO_FILE" /> | |
98 | + </root> | |
99 | + </springProfile> | |
100 | +</configuration> | |
0 | 101 | \ No newline at end of file | ... | ... |
springboot/morning-check/src/main/resources/mapper/studentmapper.xml
0 → 100644
... | ... | @@ -0,0 +1,47 @@ |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | |
2 | +<!DOCTYPE mapper | |
3 | + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
4 | + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
5 | +<mapper namespace="com.sincere.morningcheck.dao.StudentDao"> | |
6 | + | |
7 | + <!--声明返回结果参数--> | |
8 | + <resultMap id="BaseResultMap" type="com.sincere.morningcheck.model.Student"> | |
9 | + <result column="student_id" property="stuId" jdbcType="INTEGER" javaType="java.lang.Integer"/> | |
10 | + <result column="name" property="stuName" jdbcType="VARCHAR" javaType="java.lang.String"/> | |
11 | + <result column="class_id" property="classId" jdbcType="INTEGER" javaType="java.lang.Integer"/> | |
12 | + <result column="class_name" property="className" jdbcType="VARCHAR" javaType="java.lang.String"/> | |
13 | + <result column="Cards" property="cardNos" jdbcType="VARCHAR" javaType="java.lang.String"/> | |
14 | + </resultMap> | |
15 | + | |
16 | + | |
17 | + <select id="getStudents" resultMap="BaseResultMap"> | |
18 | + select class_id,student_id,name,class_name,(student_num+ | |
19 | + case when | |
20 | + (select dbo.StringJoin(distinct a.CardNum) from HS_StudentCards a where a.State=1 and a.CardNum is not null and len(a.CardNum)=8 and a.StudentId=vs.student_id)!='' | |
21 | + then | |
22 | + ','+(select dbo.StringJoin( a.CardNum) from HS_StudentCards a where a.State=1 and a.CardNum is not null and len(a.CardNum)=8 and a.StudentId=vs.student_id) | |
23 | + else | |
24 | + '' | |
25 | + end | |
26 | + ) as Cards | |
27 | + from SZ_V_School_Student vs where vs.role_state=1 and vs.school_id=#{schoolId} and vs.student_num is not null and LEN(vs.student_num)=8 | |
28 | + </select> | |
29 | + | |
30 | + <select id="getStudentByCardNo" resultMap="BaseResultMap"> | |
31 | + select top 1 vs.name,vs.student_id,vs.class_id,vs.class_name from SZ_V_School_Student vs | |
32 | + inner join SZ_V_Card b on b.type=2 and vs.student_id=b.user_id and b.num=#{cardNo} | |
33 | + where vs.role_state=1 | |
34 | + </select> | |
35 | + | |
36 | + <select id="swipeCard" statementType="CALLABLE" resultType="java.util.Map"> | |
37 | + {call xiaoan.dbo.AttendanceService( | |
38 | + #{att_id, mode=IN}, | |
39 | + #{card_num, mode=IN}, | |
40 | + #{func_no, mode=IN}, | |
41 | + #{flag, mode=IN}, | |
42 | + #{intime, mode=IN}, | |
43 | + #{arr, mode=OUT, jdbcType=VARCHAR}, | |
44 | + #{iscuccess,mode=OUT,jdbcType=INTEGER} | |
45 | + )} | |
46 | + </select> | |
47 | +</mapper> | |
0 | 48 | \ No newline at end of file | ... | ... |
springboot/morning-check/src/main/resources/mapper/usermapper.xml
0 → 100644
... | ... | @@ -0,0 +1,34 @@ |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | |
2 | +<!DOCTYPE mapper | |
3 | + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
4 | + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
5 | +<mapper namespace="com.sincere.morningcheck.dao.UserDao"> | |
6 | + | |
7 | + <!--声明返回结果参数--> | |
8 | + <resultMap id="BaseResultJoinMap" type="com.sincere.morningcheck.model.User"> | |
9 | + <!-- id:指定查询列中的唯 一标识,即主键,可配置多个--> | |
10 | + <id column="pid" property="id" jdbcType="INTEGER" javaType="java.lang.Integer"/> | |
11 | + <result column="school_name" property="schoolName" jdbcType="VARCHAR" javaType="java.lang.String"/> | |
12 | + <result column="school_id" property="schoolId" jdbcType="INTEGER" javaType="java.lang.Integer"/> | |
13 | + <result column="clint_id" property="deviceId" jdbcType="VARCHAR" javaType="java.lang.String"/> | |
14 | + </resultMap> | |
15 | + | |
16 | + <resultMap id="BaseResultMap" type="com.sincere.morningcheck.model.School"> | |
17 | + <result column="school_name" property="schoolName" jdbcType="VARCHAR" javaType="java.lang.String"/> | |
18 | + <result column="school_id" property="schoolId" jdbcType="INTEGER" javaType="java.lang.Integer"/> | |
19 | + </resultMap> | |
20 | + | |
21 | + <!--声明参数类型 一般不推荐使用ParameterMap,推荐使用parameterType--> | |
22 | + <!--<parameterMap id="User" type="com.sincere.morningcheck.model.User"/>--> | |
23 | + | |
24 | + | |
25 | + <select id="getUser" resultMap="BaseResultJoinMap"> | |
26 | + select a.clint_id,s.school_name,s.school_id from SZ_Attendance a join SZ_School s on a.school_id = s.school_id | |
27 | +where a.state=1 and a.clint_type = 21 and a.clint_id=#{deviceNo} | |
28 | + </select> | |
29 | + | |
30 | + <select id="getSchoolById" resultMap="BaseResultMap"> | |
31 | + select school_name,school_id from SZ_School where school_id=#{schoolId} | |
32 | + </select> | |
33 | + | |
34 | +</mapper> | |
0 | 35 | \ No newline at end of file | ... | ... |
springboot/morning-check/src/test/java/com/sincere/morningcheck/MorningCheckApplicationTests.java
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +package com.sincere.morningcheck; | |
2 | + | |
3 | +import org.junit.Test; | |
4 | +import org.junit.runner.RunWith; | |
5 | +import org.springframework.boot.test.context.SpringBootTest; | |
6 | +import org.springframework.test.context.junit4.SpringRunner; | |
7 | + | |
8 | +@RunWith(SpringRunner.class) | |
9 | +@SpringBootTest | |
10 | +public class MorningCheckApplicationTests { | |
11 | + | |
12 | + @Test | |
13 | + public void contextLoads() { | |
14 | + } | |
15 | + | |
16 | +} | ... | ... |
springboot/morning-check/src/test/java/com/sincere/morningcheck/MorningCheckControllerApplicationTests.java
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +package com.sincere.morningcheck; | |
2 | + | |
3 | +import org.junit.Test; | |
4 | +import org.junit.runner.RunWith; | |
5 | +import org.springframework.boot.test.context.SpringBootTest; | |
6 | +import org.springframework.test.context.junit4.SpringRunner; | |
7 | + | |
8 | +@RunWith(SpringRunner.class) | |
9 | +@SpringBootTest | |
10 | +public class MorningCheckControllerApplicationTests { | |
11 | + | |
12 | + @Test | |
13 | + public void contextLoads() { | |
14 | + } | |
15 | + | |
16 | +} | ... | ... |