Commit 4d77bc214587e53e0367106874380f91df0f5803

Authored by 陶汉栋
0 parents
Exists in thd

no message

Showing 28 changed files with 1890 additions and 0 deletions   Show diff stats
mq2kb/.gitignore 0 → 100644
  1 +++ a/mq2kb/.gitignore
... ... @@ -0,0 +1,29 @@
  1 +HELP.md
  2 +/target/
  3 +!.mvn/wrapper/maven-wrapper.jar
  4 +
  5 +### STS ###
  6 +.apt_generated
  7 +.classpath
  8 +.factorypath
  9 +.project
  10 +.settings
  11 +.springBeans
  12 +.sts4-cache
  13 +
  14 +### IntelliJ IDEA ###
  15 +.idea
  16 +*.iws
  17 +*.iml
  18 +*.ipr
  19 +
  20 +### NetBeans ###
  21 +/nbproject/private/
  22 +/nbbuild/
  23 +/dist/
  24 +/nbdist/
  25 +/.nb-gradle/
  26 +/build/
  27 +
  28 +### VS Code ###
  29 +.vscode/
... ...
mq2kb/.mvn/wrapper/MavenWrapperDownloader.java 0 → 100644
  1 +++ a/mq2kb/.mvn/wrapper/MavenWrapperDownloader.java
... ... @@ -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 +}
... ...
mq2kb/.mvn/wrapper/maven-wrapper.jar 0 → 100644
No preview for this file type
mq2kb/.mvn/wrapper/maven-wrapper.properties 0 → 100644
  1 +++ a/mq2kb/.mvn/wrapper/maven-wrapper.properties
... ... @@ -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
... ...
mq2kb/mvnw 0 → 100644
  1 +++ a/mq2kb/mvnw
... ... @@ -0,0 +1,286 @@
  1 +#!/bin/sh
  2 +# ----------------------------------------------------------------------------
  3 +# Licensed to the Apache Software Foundation (ASF) under one
  4 +# or more contributor license agreements. See the NOTICE file
  5 +# distributed with this work for additional information
  6 +# regarding copyright ownership. The ASF licenses this file
  7 +# to you under the Apache License, Version 2.0 (the
  8 +# "License"); you may not use this file except in compliance
  9 +# with the License. You may obtain a copy of the License at
  10 +#
  11 +# https://www.apache.org/licenses/LICENSE-2.0
  12 +#
  13 +# Unless required by applicable law or agreed to in writing,
  14 +# software distributed under the License is distributed on an
  15 +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16 +# KIND, either express or implied. See the License for the
  17 +# specific language governing permissions and limitations
  18 +# under the License.
  19 +# ----------------------------------------------------------------------------
  20 +
  21 +# ----------------------------------------------------------------------------
  22 +# Maven2 Start Up Batch script
  23 +#
  24 +# Required ENV vars:
  25 +# ------------------
  26 +# JAVA_HOME - location of a JDK home dir
  27 +#
  28 +# Optional ENV vars
  29 +# -----------------
  30 +# M2_HOME - location of maven2's installed home dir
  31 +# MAVEN_OPTS - parameters passed to the Java VM when running Maven
  32 +# e.g. to debug Maven itself, use
  33 +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
  34 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
  35 +# ----------------------------------------------------------------------------
  36 +
  37 +if [ -z "$MAVEN_SKIP_RC" ] ; then
  38 +
  39 + if [ -f /etc/mavenrc ] ; then
  40 + . /etc/mavenrc
  41 + fi
  42 +
  43 + if [ -f "$HOME/.mavenrc" ] ; then
  44 + . "$HOME/.mavenrc"
  45 + fi
  46 +
  47 +fi
  48 +
  49 +# OS specific support. $var _must_ be set to either true or false.
  50 +cygwin=false;
  51 +darwin=false;
  52 +mingw=false
  53 +case "`uname`" in
  54 + CYGWIN*) cygwin=true ;;
  55 + MINGW*) mingw=true;;
  56 + Darwin*) darwin=true
  57 + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
  58 + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
  59 + if [ -z "$JAVA_HOME" ]; then
  60 + if [ -x "/usr/libexec/java_home" ]; then
  61 + export JAVA_HOME="`/usr/libexec/java_home`"
  62 + else
  63 + export JAVA_HOME="/Library/Java/Home"
  64 + fi
  65 + fi
  66 + ;;
  67 +esac
  68 +
  69 +if [ -z "$JAVA_HOME" ] ; then
  70 + if [ -r /etc/gentoo-release ] ; then
  71 + JAVA_HOME=`java-config --jre-home`
  72 + fi
  73 +fi
  74 +
  75 +if [ -z "$M2_HOME" ] ; then
  76 + ## resolve links - $0 may be a link to maven's home
  77 + PRG="$0"
  78 +
  79 + # need this for relative symlinks
  80 + while [ -h "$PRG" ] ; do
  81 + ls=`ls -ld "$PRG"`
  82 + link=`expr "$ls" : '.*-> \(.*\)$'`
  83 + if expr "$link" : '/.*' > /dev/null; then
  84 + PRG="$link"
  85 + else
  86 + PRG="`dirname "$PRG"`/$link"
  87 + fi
  88 + done
  89 +
  90 + saveddir=`pwd`
  91 +
  92 + M2_HOME=`dirname "$PRG"`/..
  93 +
  94 + # make it fully qualified
  95 + M2_HOME=`cd "$M2_HOME" && pwd`
  96 +
  97 + cd "$saveddir"
  98 + # echo Using m2 at $M2_HOME
  99 +fi
  100 +
  101 +# For Cygwin, ensure paths are in UNIX format before anything is touched
  102 +if $cygwin ; then
  103 + [ -n "$M2_HOME" ] &&
  104 + M2_HOME=`cygpath --unix "$M2_HOME"`
  105 + [ -n "$JAVA_HOME" ] &&
  106 + JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  107 + [ -n "$CLASSPATH" ] &&
  108 + CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  109 +fi
  110 +
  111 +# For Mingw, ensure paths are in UNIX format before anything is touched
  112 +if $mingw ; then
  113 + [ -n "$M2_HOME" ] &&
  114 + M2_HOME="`(cd "$M2_HOME"; pwd)`"
  115 + [ -n "$JAVA_HOME" ] &&
  116 + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
  117 + # TODO classpath?
  118 +fi
  119 +
  120 +if [ -z "$JAVA_HOME" ]; then
  121 + javaExecutable="`which javac`"
  122 + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
  123 + # readlink(1) is not available as standard on Solaris 10.
  124 + readLink=`which readlink`
  125 + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
  126 + if $darwin ; then
  127 + javaHome="`dirname \"$javaExecutable\"`"
  128 + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
  129 + else
  130 + javaExecutable="`readlink -f \"$javaExecutable\"`"
  131 + fi
  132 + javaHome="`dirname \"$javaExecutable\"`"
  133 + javaHome=`expr "$javaHome" : '\(.*\)/bin'`
  134 + JAVA_HOME="$javaHome"
  135 + export JAVA_HOME
  136 + fi
  137 + fi
  138 +fi
  139 +
  140 +if [ -z "$JAVACMD" ] ; then
  141 + if [ -n "$JAVA_HOME" ] ; then
  142 + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  143 + # IBM's JDK on AIX uses strange locations for the executables
  144 + JAVACMD="$JAVA_HOME/jre/sh/java"
  145 + else
  146 + JAVACMD="$JAVA_HOME/bin/java"
  147 + fi
  148 + else
  149 + JAVACMD="`which java`"
  150 + fi
  151 +fi
  152 +
  153 +if [ ! -x "$JAVACMD" ] ; then
  154 + echo "Error: JAVA_HOME is not defined correctly." >&2
  155 + echo " We cannot execute $JAVACMD" >&2
  156 + exit 1
  157 +fi
  158 +
  159 +if [ -z "$JAVA_HOME" ] ; then
  160 + echo "Warning: JAVA_HOME environment variable is not set."
  161 +fi
  162 +
  163 +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
  164 +
  165 +# traverses directory structure from process work directory to filesystem root
  166 +# first directory with .mvn subdirectory is considered project base directory
  167 +find_maven_basedir() {
  168 +
  169 + if [ -z "$1" ]
  170 + then
  171 + echo "Path not specified to find_maven_basedir"
  172 + return 1
  173 + fi
  174 +
  175 + basedir="$1"
  176 + wdir="$1"
  177 + while [ "$wdir" != '/' ] ; do
  178 + if [ -d "$wdir"/.mvn ] ; then
  179 + basedir=$wdir
  180 + break
  181 + fi
  182 + # workaround for JBEAP-8937 (on Solaris 10/Sparc)
  183 + if [ -d "${wdir}" ]; then
  184 + wdir=`cd "$wdir/.."; pwd`
  185 + fi
  186 + # end of workaround
  187 + done
  188 + echo "${basedir}"
  189 +}
  190 +
  191 +# concatenates all lines of a file
  192 +concat_lines() {
  193 + if [ -f "$1" ]; then
  194 + echo "$(tr -s '\n' ' ' < "$1")"
  195 + fi
  196 +}
  197 +
  198 +BASE_DIR=`find_maven_basedir "$(pwd)"`
  199 +if [ -z "$BASE_DIR" ]; then
  200 + exit 1;
  201 +fi
  202 +
  203 +##########################################################################################
  204 +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
  205 +# This allows using the maven wrapper in projects that prohibit checking in binary data.
  206 +##########################################################################################
  207 +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
  208 + if [ "$MVNW_VERBOSE" = true ]; then
  209 + echo "Found .mvn/wrapper/maven-wrapper.jar"
  210 + fi
  211 +else
  212 + if [ "$MVNW_VERBOSE" = true ]; then
  213 + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
  214 + fi
  215 + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
  216 + while IFS="=" read key value; do
  217 + case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
  218 + esac
  219 + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
  220 + if [ "$MVNW_VERBOSE" = true ]; then
  221 + echo "Downloading from: $jarUrl"
  222 + fi
  223 + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
  224 +
  225 + if command -v wget > /dev/null; then
  226 + if [ "$MVNW_VERBOSE" = true ]; then
  227 + echo "Found wget ... using wget"
  228 + fi
  229 + wget "$jarUrl" -O "$wrapperJarPath"
  230 + elif command -v curl > /dev/null; then
  231 + if [ "$MVNW_VERBOSE" = true ]; then
  232 + echo "Found curl ... using curl"
  233 + fi
  234 + curl -o "$wrapperJarPath" "$jarUrl"
  235 + else
  236 + if [ "$MVNW_VERBOSE" = true ]; then
  237 + echo "Falling back to using Java to download"
  238 + fi
  239 + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
  240 + if [ -e "$javaClass" ]; then
  241 + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
  242 + if [ "$MVNW_VERBOSE" = true ]; then
  243 + echo " - Compiling MavenWrapperDownloader.java ..."
  244 + fi
  245 + # Compiling the Java class
  246 + ("$JAVA_HOME/bin/javac" "$javaClass")
  247 + fi
  248 + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
  249 + # Running the downloader
  250 + if [ "$MVNW_VERBOSE" = true ]; then
  251 + echo " - Running MavenWrapperDownloader.java ..."
  252 + fi
  253 + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
  254 + fi
  255 + fi
  256 + fi
  257 +fi
  258 +##########################################################################################
  259 +# End of extension
  260 +##########################################################################################
  261 +
  262 +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
  263 +if [ "$MVNW_VERBOSE" = true ]; then
  264 + echo $MAVEN_PROJECTBASEDIR
  265 +fi
  266 +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
  267 +
  268 +# For Cygwin, switch paths to Windows format before running java
  269 +if $cygwin; then
  270 + [ -n "$M2_HOME" ] &&
  271 + M2_HOME=`cygpath --path --windows "$M2_HOME"`
  272 + [ -n "$JAVA_HOME" ] &&
  273 + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  274 + [ -n "$CLASSPATH" ] &&
  275 + CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  276 + [ -n "$MAVEN_PROJECTBASEDIR" ] &&
  277 + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
  278 +fi
  279 +
  280 +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
  281 +
  282 +exec "$JAVACMD" \
  283 + $MAVEN_OPTS \
  284 + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
  285 + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
  286 + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
... ...
mq2kb/mvnw.cmd 0 → 100644
  1 +++ a/mq2kb/mvnw.cmd
... ... @@ -0,0 +1,161 @@
  1 +@REM ----------------------------------------------------------------------------
  2 +@REM Licensed to the Apache Software Foundation (ASF) under one
  3 +@REM or more contributor license agreements. See the NOTICE file
  4 +@REM distributed with this work for additional information
  5 +@REM regarding copyright ownership. The ASF licenses this file
  6 +@REM to you under the Apache License, Version 2.0 (the
  7 +@REM "License"); you may not use this file except in compliance
  8 +@REM with the License. You may obtain a copy of the License at
  9 +@REM
  10 +@REM https://www.apache.org/licenses/LICENSE-2.0
  11 +@REM
  12 +@REM Unless required by applicable law or agreed to in writing,
  13 +@REM software distributed under the License is distributed on an
  14 +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15 +@REM KIND, either express or implied. See the License for the
  16 +@REM specific language governing permissions and limitations
  17 +@REM under the License.
  18 +@REM ----------------------------------------------------------------------------
  19 +
  20 +@REM ----------------------------------------------------------------------------
  21 +@REM Maven2 Start Up Batch script
  22 +@REM
  23 +@REM Required ENV vars:
  24 +@REM JAVA_HOME - location of a JDK home dir
  25 +@REM
  26 +@REM Optional ENV vars
  27 +@REM M2_HOME - location of maven2's installed home dir
  28 +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
  29 +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
  30 +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
  31 +@REM e.g. to debug Maven itself, use
  32 +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
  33 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
  34 +@REM ----------------------------------------------------------------------------
  35 +
  36 +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
  37 +@echo off
  38 +@REM set title of command window
  39 +title %0
  40 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
  41 +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
  42 +
  43 +@REM set %HOME% to equivalent of $HOME
  44 +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
  45 +
  46 +@REM Execute a user defined script before this one
  47 +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
  48 +@REM check for pre script, once with legacy .bat ending and once with .cmd ending
  49 +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
  50 +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
  51 +:skipRcPre
  52 +
  53 +@setlocal
  54 +
  55 +set ERROR_CODE=0
  56 +
  57 +@REM To isolate internal variables from possible post scripts, we use another setlocal
  58 +@setlocal
  59 +
  60 +@REM ==== START VALIDATION ====
  61 +if not "%JAVA_HOME%" == "" goto OkJHome
  62 +
  63 +echo.
  64 +echo Error: JAVA_HOME not found in your environment. >&2
  65 +echo Please set the JAVA_HOME variable in your environment to match the >&2
  66 +echo location of your Java installation. >&2
  67 +echo.
  68 +goto error
  69 +
  70 +:OkJHome
  71 +if exist "%JAVA_HOME%\bin\java.exe" goto init
  72 +
  73 +echo.
  74 +echo Error: JAVA_HOME is set to an invalid directory. >&2
  75 +echo JAVA_HOME = "%JAVA_HOME%" >&2
  76 +echo Please set the JAVA_HOME variable in your environment to match the >&2
  77 +echo location of your Java installation. >&2
  78 +echo.
  79 +goto error
  80 +
  81 +@REM ==== END VALIDATION ====
  82 +
  83 +:init
  84 +
  85 +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
  86 +@REM Fallback to current working directory if not found.
  87 +
  88 +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
  89 +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
  90 +
  91 +set EXEC_DIR=%CD%
  92 +set WDIR=%EXEC_DIR%
  93 +:findBaseDir
  94 +IF EXIST "%WDIR%"\.mvn goto baseDirFound
  95 +cd ..
  96 +IF "%WDIR%"=="%CD%" goto baseDirNotFound
  97 +set WDIR=%CD%
  98 +goto findBaseDir
  99 +
  100 +:baseDirFound
  101 +set MAVEN_PROJECTBASEDIR=%WDIR%
  102 +cd "%EXEC_DIR%"
  103 +goto endDetectBaseDir
  104 +
  105 +:baseDirNotFound
  106 +set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
  107 +cd "%EXEC_DIR%"
  108 +
  109 +:endDetectBaseDir
  110 +
  111 +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
  112 +
  113 +@setlocal EnableExtensions EnableDelayedExpansion
  114 +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
  115 +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
  116 +
  117 +:endReadAdditionalConfig
  118 +
  119 +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
  120 +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
  121 +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
  122 +
  123 +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
  124 +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
  125 + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
  126 +)
  127 +
  128 +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
  129 +@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
  130 +if exist %WRAPPER_JAR% (
  131 + echo Found %WRAPPER_JAR%
  132 +) else (
  133 + echo Couldn't find %WRAPPER_JAR%, downloading it ...
  134 + echo Downloading from: %DOWNLOAD_URL%
  135 + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
  136 + echo Finished downloading %WRAPPER_JAR%
  137 +)
  138 +@REM End of extension
  139 +
  140 +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
  141 +if ERRORLEVEL 1 goto error
  142 +goto end
  143 +
  144 +:error
  145 +set ERROR_CODE=1
  146 +
  147 +:end
  148 +@endlocal & set ERROR_CODE=%ERROR_CODE%
  149 +
  150 +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
  151 +@REM check for post script, once with legacy .bat ending and once with .cmd ending
  152 +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
  153 +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
  154 +:skipRcPost
  155 +
  156 +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
  157 +if "%MAVEN_BATCH_PAUSE%" == "on" pause
  158 +
  159 +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
  160 +
  161 +exit /B %ERROR_CODE%
... ...
mq2kb/mysql-connector-java-8.0.16.jar 0 → 100644
No preview for this file type
mq2kb/pom.xml 0 → 100644
  1 +++ a/mq2kb/pom.xml
... ... @@ -0,0 +1,123 @@
  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.5.RELEASE</version>
  9 + <relativePath/> <!-- lookup parent from repository -->
  10 + </parent>
  11 + <groupId>com.shunzhi</groupId>
  12 + <artifactId>mqtt2kanban</artifactId>
  13 + <version>1.0.0</version>
  14 + <name>mqtt2kanban</name>
  15 + <description>推送mqtt消息到看板</description>
  16 +
  17 + <properties>
  18 + <java.version>1.8</java.version>
  19 + </properties>
  20 +
  21 + <dependencies>
  22 + <dependency>
  23 + <groupId>org.mybatis.spring.boot</groupId>
  24 + <artifactId>mybatis-spring-boot-starter</artifactId>
  25 + <version>2.0.1</version>
  26 + </dependency>
  27 +
  28 + <dependency>
  29 + <groupId>mysql</groupId>
  30 + <artifactId>mysql-connector-java</artifactId>
  31 + <scope>runtime</scope>
  32 + </dependency>
  33 +
  34 + <dependency>
  35 + <groupId>org.springframework.boot</groupId>
  36 + <artifactId>spring-boot-starter-test</artifactId>
  37 + <scope>test</scope>
  38 + </dependency>
  39 +
  40 + <dependency>
  41 + <groupId>org.springframework.boot</groupId>
  42 + <artifactId>spring-boot-starter-web</artifactId>
  43 + </dependency>
  44 +
  45 + <dependency>
  46 + <groupId>org.springframework.boot</groupId>
  47 + <artifactId>spring-boot-starter-jdbc</artifactId>
  48 + </dependency>
  49 +
  50 + <dependency>
  51 + <groupId>org.springframework.boot</groupId>
  52 + <artifactId>spring-boot-starter-tomcat</artifactId>
  53 + <scope>provided</scope>
  54 + </dependency>
  55 +
  56 + <!--<dependency>
  57 + <groupId>org.springframework.boot</groupId>
  58 + <artifactId>spring-boot-starter-quartz</artifactId>
  59 + </dependency>-->
  60 +
  61 + <!-- <dependency>
  62 + <groupId>opensymphony</groupId>
  63 + <artifactId>quartz-all</artifactId>
  64 + <version>1.6.3</version>
  65 + </dependency>-->
  66 +
  67 + <!--API文档配置-->
  68 + <dependency>
  69 + <groupId>io.springfox</groupId>
  70 + <artifactId>springfox-swagger-ui</artifactId>
  71 + <version>2.9.2</version>
  72 + </dependency>
  73 +
  74 + <dependency>
  75 + <groupId>io.springfox</groupId>
  76 + <artifactId>springfox-swagger2</artifactId>
  77 + <version>2.9.2</version>
  78 + </dependency>
  79 +
  80 + <dependency>
  81 + <groupId>commons-codec</groupId>
  82 + <artifactId>commons-codec</artifactId>
  83 + <version>1.10</version>
  84 + </dependency>
  85 + <dependency>
  86 + <groupId>org.eclipse.paho</groupId>
  87 + <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
  88 + <version>1.1.0</version>
  89 + </dependency>
  90 + <dependency>
  91 + <groupId>org.apache.httpcomponents</groupId>
  92 + <artifactId>httpclient</artifactId>
  93 + <version>4.5.2</version>
  94 + </dependency>
  95 + <dependency>
  96 + <groupId>com.alibaba</groupId>
  97 + <artifactId>fastjson</artifactId>
  98 + <version>1.2.28</version>
  99 + </dependency>
  100 + <dependency>
  101 + <groupId>com.aliyun.openservices</groupId>
  102 + <artifactId>ons-client</artifactId>
  103 + <version>1.3.2.Final</version>
  104 + </dependency>
  105 + <dependency>
  106 + <groupId>org.fusesource.mqtt-client</groupId>
  107 + <artifactId>mqtt-client</artifactId>
  108 + <version>1.0</version>
  109 + </dependency>
  110 +
  111 +
  112 + </dependencies>
  113 +
  114 + <build>
  115 + <plugins>
  116 + <plugin>
  117 + <groupId>org.springframework.boot</groupId>
  118 + <artifactId>spring-boot-maven-plugin</artifactId>
  119 + </plugin>
  120 + </plugins>
  121 + </build>
  122 +
  123 +</project>
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/ApplicationRunnerImpl.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/ApplicationRunnerImpl.java
... ... @@ -0,0 +1,170 @@
  1 +package com.shunzhi.mqtt2kanban;
  2 +
  3 +import com.shunzhi.mqtt2kanban.service.UserSeerviceImp;
  4 +import com.shunzhi.mqtt2kanban.utils.Tools;
  5 +import org.eclipse.paho.client.mqttv3.*;
  6 +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.boot.ApplicationArguments;
  9 +import org.springframework.boot.ApplicationRunner;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.security.InvalidKeyException;
  13 +import java.security.NoSuchAlgorithmException;
  14 +import java.util.HashSet;
  15 +import java.util.Set;
  16 +
  17 +@Component
  18 +public class ApplicationRunnerImpl implements ApplicationRunner {
  19 +
  20 + private static String accessKey;
  21 +
  22 + private static String sign;
  23 +
  24 + public static MqttClient mqttClient;
  25 +
  26 + public static String groupId;
  27 +
  28 + public static String topic;
  29 +
  30 + private static int qosLevel;
  31 +
  32 + public static boolean isConnect;
  33 +
  34 + private Set<String> set = new HashSet<String>();
  35 +
  36 + @Autowired
  37 + UserSeerviceImp userSeerviceImp;
  38 +
  39 + @Override
  40 + public void run(ApplicationArguments args) throws Exception {
  41 +
  42 + initMq();
  43 +
  44 + }
  45 +
  46 + /**
  47 + * 初始化MQ
  48 + */
  49 + private void initMq() {
  50 + final String brokerUrl = "tcp://post-cn-4590mq2hr03.mqtt.aliyuncs.com:1883";
  51 + groupId = "GID_HFJSIURFHAQO110";
  52 + topic = "Topic_Quene_Test";
  53 + qosLevel = 1;
  54 + final Boolean cleanSession = false;
  55 + String clientId = groupId + "@@@9ED96FB6D72C1698";
  56 + accessKey = "UimvLVp0Wj90P88u";
  57 + String secretKey = "TE4rZenITG27tiQqHx9qINjx71Nws7";
  58 + final MemoryPersistence memoryPersistence = new MemoryPersistence();
  59 + if (null == mqttClient) {
  60 + try {
  61 + mqttClient = new MqttClient(brokerUrl, clientId, memoryPersistence);
  62 + } catch (MqttException e) {
  63 + e.printStackTrace();
  64 + }
  65 + MqttConnectOptions connOpts = new MqttConnectOptions();
  66 + //cal the sign as password,sign=BASE64(MAC.SHA1(groupId,secretKey))
  67 + try {
  68 + sign = Tools.macSignature(clientId.split("@@@")[0], secretKey);
  69 + } catch (InvalidKeyException e) {
  70 + e.printStackTrace();
  71 + } catch (NoSuchAlgorithmException e) {
  72 + e.printStackTrace();
  73 + }
  74 + connOpts.setUserName(accessKey);
  75 + connOpts.setPassword(sign.toCharArray());
  76 + connOpts.setCleanSession(cleanSession);
  77 + connOpts.setKeepAliveInterval(90);
  78 + connOpts.setAutomaticReconnect(true);
  79 + mqttClient.setCallback(new MqttCallbackExtended() {
  80 + @Override
  81 + public void connectComplete(boolean reconnect, String serverURI) {
  82 + isConnect = true;
  83 + System.out.println("connect success");
  84 + }
  85 +
  86 + @Override
  87 + public void connectionLost(Throwable throwable) {
  88 + isConnect = false;
  89 + System.out.println("connect lost:" + throwable.toString());
  90 + throwable.printStackTrace();
  91 + initMq();//初始化
  92 + }
  93 +
  94 + @Override
  95 + public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
  96 + System.out.println("receive msg from topic " + s + " , body is " + new String(mqttMessage.getPayload()));
  97 + }
  98 +
  99 + @Override
  100 + public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
  101 + //this notice make sense when qos >0
  102 +// System.out.println("send msg succeed");
  103 + }
  104 + });
  105 + try {
  106 + mqttClient.connect(connOpts);
  107 + } catch (MqttException e) {
  108 + System.out.println("mqtt:" + e.toString());
  109 + e.printStackTrace();
  110 + }
  111 + /*while (true){
  112 + sendMessageTest("528C8E6CD4A3C659","zy105387",0);
  113 + try {
  114 + Thread.sleep(10000);
  115 + } catch (InterruptedException e) {
  116 + System.out.println("connect success:"+e);
  117 + e.printStackTrace();
  118 + }
  119 + }*/
  120 + }
  121 + }
  122 +
  123 +
  124 + /**
  125 + * @param equipmentSN 控制器SN号
  126 + * @param consumerNO userid
  127 + * @param inOrOut 进出状态
  128 + */
  129 + public void sendMessage(String equipmentSN, String consumerNO, int inOrOut) {
  130 + try {
  131 + String recvClientId = groupId + "@@@";
  132 + if (null != Mqtt2kanbanApplication.deviceList) {
  133 + for (int i = 0; i < Mqtt2kanbanApplication.deviceList.size(); i++) {
  134 + String devices = Mqtt2kanbanApplication.deviceList.get(i);
  135 + if (devices.contains(equipmentSN))
  136 + recvClientId += devices.split(",")[0];
  137 +
  138 + }
  139 + final String p2pSendTopic = topic + "/p2p/" + recvClientId;
  140 + String data = "{\"userId\":\"" + consumerNO + "\",\"inOrOut\":" + inOrOut + "}";
  141 + String content = "{\"cmd\":\"34\",\"clientId\":\"\",\"data\":" + data + "}";
  142 + MqttMessage message = new MqttMessage(content.getBytes());
  143 + message.setQos(qosLevel);
  144 + System.out.println("发送内容:" + p2pSendTopic);
  145 + if (null != mqttClient)
  146 + mqttClient.publish(p2pSendTopic, message);
  147 + }
  148 + } catch (Exception e) {
  149 + e.printStackTrace();
  150 + }
  151 + }
  152 +
  153 +
  154 + public void sendMessageTest(String equipmentSN, String consumerNO, int inOrOut) {
  155 + try {
  156 + String recvClientId = groupId + "@@@"+equipmentSN;
  157 + final String p2pSendTopic = topic + "/p2p/" + recvClientId;
  158 + String data = "{\"userId\":\"" + consumerNO + "\",\"inOrOut\":" + inOrOut + "}";
  159 + String content = "{\"cmd\":\"34\",\"clientId\":\"\",\"data\":" + data + "}";
  160 + MqttMessage message = new MqttMessage(content.getBytes());
  161 + message.setQos(qosLevel);
  162 + System.out.println("发送内容:" + p2pSendTopic+" "+message);
  163 + if (null != mqttClient)
  164 + mqttClient.publish(p2pSendTopic, message);
  165 + } catch (Exception e) {
  166 + e.printStackTrace();
  167 + }
  168 + }
  169 +
  170 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/Mqtt2kanbanApplication.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/Mqtt2kanbanApplication.java
... ... @@ -0,0 +1,63 @@
  1 +package com.shunzhi.mqtt2kanban;
  2 +
  3 +import org.mybatis.spring.annotation.MapperScan;
  4 +import org.springframework.boot.SpringApplication;
  5 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  6 +import org.springframework.context.annotation.Bean;
  7 +import org.springframework.scheduling.annotation.EnableScheduling;
  8 +import org.springframework.web.client.RestTemplate;
  9 +
  10 +import java.io.*;
  11 +import java.util.ArrayList;
  12 +import java.util.List;
  13 +
  14 +@SpringBootApplication
  15 +@MapperScan("com.shunzhi.mqtt2kanban.mapper")
  16 +@EnableScheduling
  17 +public class Mqtt2kanbanApplication {
  18 +
  19 + @Bean
  20 + RestTemplate getRestTemplate(){
  21 + return new RestTemplate();
  22 + }
  23 +
  24 + private String indexPath = "C:\\index.txt";//存放当前取数的记录
  25 +
  26 + private String devicePath = "C:\\Users\\Administrator\\Desktop\\device.txt";//存放设备id的路径
  27 + public static void main(String[] args) {
  28 + SpringApplication.run(Mqtt2kanbanApplication.class, args);
  29 + new Mqtt2kanbanApplication().initFiles();
  30 + }
  31 +
  32 + public static List<String> deviceList = null;
  33 + /**
  34 + * 初始化文件
  35 + */
  36 + private void initFiles() {
  37 + deviceList = new ArrayList<>();
  38 + try {
  39 + BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(devicePath)));
  40 + String length = null;
  41 + while ((length = bufferedReader.readLine())!=null){
  42 + deviceList.add(length);
  43 + }
  44 + System.out.println("deviceList:"+deviceList);
  45 + } catch (FileNotFoundException e) {
  46 + e.printStackTrace();
  47 + } catch (IOException e) {
  48 + e.printStackTrace();
  49 + }
  50 +
  51 + File fi = new File(indexPath);
  52 + if (!fi.exists()){
  53 + try {
  54 + fi.createNewFile();
  55 + } catch (IOException e) {
  56 + e.printStackTrace();
  57 + }
  58 + }
  59 +
  60 + }
  61 +
  62 +
  63 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/Swagger2.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/Swagger2.java
... ... @@ -0,0 +1,37 @@
  1 +package com.shunzhi.mqtt2kanban;
  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.spi.DocumentationType;
  10 +import springfox.documentation.spring.web.plugins.Docket;
  11 +import springfox.documentation.swagger2.annotations.EnableSwagger2;
  12 +
  13 +@Configuration
  14 +@EnableSwagger2
  15 +public class Swagger2 {
  16 +
  17 + @Bean
  18 + public Docket createRestApi() {
  19 + return new Docket(DocumentationType.SWAGGER_2)
  20 + .apiInfo(apiInfo())
  21 + .select()
  22 + .apis(RequestHandlerSelectors.basePackage("com.shunzhi.mqtt2kanban.control"))
  23 + .paths(PathSelectors.any())
  24 + .build();
  25 + }
  26 +
  27 + private ApiInfo apiInfo() {
  28 + return new ApiInfoBuilder()
  29 + .title("Spring Boot中使用Swagger2")
  30 + .contact("Mr.Tao")
  31 + .description("")
  32 + .termsOfServiceUrl("")
  33 + .version("1.0")
  34 + .build();
  35 + }
  36 +
  37 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/bean/Attendance.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/bean/Attendance.java
... ... @@ -0,0 +1,43 @@
  1 +package com.shunzhi.mqtt2kanban.bean;
  2 +
  3 +public class Attendance {
  4 +
  5 + private String user_id;
  6 +
  7 + private String intime;
  8 +
  9 + private String systime;
  10 +
  11 + public String getUser_id() {
  12 + return user_id;
  13 + }
  14 +
  15 + public void setUser_id(String user_id) {
  16 + this.user_id = user_id;
  17 + }
  18 +
  19 + public String getIntime() {
  20 + return intime;
  21 + }
  22 +
  23 + public void setIntime(String intime) {
  24 + this.intime = intime;
  25 + }
  26 +
  27 + public String getSystime() {
  28 + return systime;
  29 + }
  30 +
  31 + public void setSystime(String systime) {
  32 + this.systime = systime;
  33 + }
  34 +
  35 + @Override
  36 + public String toString() {
  37 + return "Attendance{" +
  38 + "user_id='" + user_id + '\'' +
  39 + ", intime='" + intime + '\'' +
  40 + ", systime='" + systime + '\'' +
  41 + '}';
  42 + }
  43 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/bean/User.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/bean/User.java
... ... @@ -0,0 +1,42 @@
  1 +package com.shunzhi.mqtt2kanban.bean;
  2 +
  3 +public class User {
  4 +
  5 + private String user_id;
  6 +
  7 + private String user_name;
  8 +
  9 + private String addDate;
  10 +
  11 + public String getUser_name() {
  12 + return user_name;
  13 + }
  14 +
  15 + public void setUser_name(String user_name) {
  16 + this.user_name = user_name;
  17 + }
  18 +
  19 + public String getAddDate() {
  20 + return addDate;
  21 + }
  22 +
  23 + public void setAddDate(String addDate) {
  24 + this.addDate = addDate;
  25 + }
  26 +
  27 + public String getUser_id() {
  28 + return user_id;
  29 + }
  30 +
  31 + public void setUser_id(String user_id) {
  32 + this.user_id = user_id;
  33 + }
  34 +
  35 + @Override
  36 + public String toString() {
  37 + return "User{" +
  38 + "user_name='" + user_name + '\'' +
  39 + ", addDate='" + addDate + '\'' +
  40 + '}';
  41 + }
  42 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/bean/ValidcardeventBean.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/bean/ValidcardeventBean.java
... ... @@ -0,0 +1,78 @@
  1 +package com.shunzhi.mqtt2kanban.bean;
  2 +
  3 +
  4 +
  5 +public class ValidcardeventBean {
  6 +
  7 + private long ValidEventID;
  8 +
  9 + private String RecordDateTime;//进出时间
  10 +
  11 + private long CardNO;
  12 +
  13 + private int InOrOut;//进出
  14 +
  15 + private String EquipmentSN;//控制器编号
  16 +
  17 + private String ConsumerNO;//userid
  18 +
  19 + public long getValidEventID() {
  20 + return ValidEventID;
  21 + }
  22 +
  23 + public void setValidEventID(long validEventID) {
  24 + ValidEventID = validEventID;
  25 + }
  26 +
  27 + public String getRecordDateTime() {
  28 + return RecordDateTime;
  29 + }
  30 +
  31 + public void setRecordDateTime(String recordDateTime) {
  32 + RecordDateTime = recordDateTime;
  33 + }
  34 +
  35 + public long getCardNO() {
  36 + return CardNO;
  37 + }
  38 +
  39 + public void setCardNO(long cardNO) {
  40 + CardNO = cardNO;
  41 + }
  42 +
  43 + public int getInOrOut() {
  44 + return InOrOut;
  45 + }
  46 +
  47 + public void setInOrOut(int inOrOut) {
  48 + InOrOut = inOrOut;
  49 + }
  50 +
  51 + public String getEquipmentSN() {
  52 + return EquipmentSN;
  53 + }
  54 +
  55 + public void setEquipmentSN(String equipmentSN) {
  56 + EquipmentSN = equipmentSN;
  57 + }
  58 +
  59 + public String getConsumerNO() {
  60 + return ConsumerNO;
  61 + }
  62 +
  63 + public void setConsumerNO(String consumerNO) {
  64 + ConsumerNO = consumerNO;
  65 + }
  66 +
  67 + @Override
  68 + public String toString() {
  69 + return "ValidcardeventBean{" +
  70 + "ValidEventID=" + ValidEventID +
  71 + ", RecordDateTime='" + RecordDateTime + '\'' +
  72 + ", InOrOut=" + InOrOut +
  73 + ", EquipmentSN='" + EquipmentSN + '\'' +
  74 + ", ConsumerNO='" + ConsumerNO + '\'' +
  75 + ", CardNo=" + CardNO +
  76 + '}';
  77 + }
  78 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/control/ValControl.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/control/ValControl.java
... ... @@ -0,0 +1,46 @@
  1 +package com.shunzhi.mqtt2kanban.control;
  2 +
  3 +import com.shunzhi.mqtt2kanban.bean.User;
  4 +import com.shunzhi.mqtt2kanban.bean.ValidcardeventBean;
  5 +import com.shunzhi.mqtt2kanban.service.ValService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.GetMapping;
  8 +import org.springframework.web.bind.annotation.PathVariable;
  9 +import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import java.util.ArrayList;
  13 +import java.util.List;
  14 +
  15 +@RestController
  16 +@RequestMapping(value = "/val/*")
  17 +public class ValControl {
  18 +
  19 + @Autowired
  20 + ValService valService;
  21 +
  22 + @GetMapping("getVal/{id}")
  23 + public List<ValidcardeventBean> getVal(@PathVariable(value = "id") Long id) {
  24 + List<ValidcardeventBean> validcardeventBean = null;
  25 + try {
  26 + System.out.println("传入id:" + id);
  27 + validcardeventBean = valService.select(365960);
  28 + System.out.println("获得的值:" + validcardeventBean);
  29 + } catch (Exception e) {
  30 + System.out.println("报错:" + e);
  31 + }
  32 + return validcardeventBean;
  33 + }
  34 +
  35 + @GetMapping("getUsers")
  36 + public String getUsers() {
  37 + List<User> users = new ArrayList<>();
  38 + try {
  39 + users = valService.getUser();
  40 + System.out.println("users:" + users);
  41 + } catch (Exception e) {
  42 + System.out.println("错误:" + e);
  43 + }
  44 + return users.toString();
  45 + }
  46 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/mapper/UserMapper.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/mapper/UserMapper.java
... ... @@ -0,0 +1,14 @@
  1 +package com.shunzhi.mqtt2kanban.mapper;
  2 +
  3 +import com.shunzhi.mqtt2kanban.bean.User;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Select;
  6 +import org.springframework.stereotype.Repository;
  7 +
  8 +import java.util.List;
  9 +
  10 +@Mapper
  11 +public interface UserMapper {
  12 +// @Select("SELECT * FROM user")
  13 + User selectUser();
  14 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/mapper/ValMapper.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/mapper/ValMapper.java
... ... @@ -0,0 +1,26 @@
  1 +package com.shunzhi.mqtt2kanban.mapper;
  2 +
  3 +import com.shunzhi.mqtt2kanban.bean.User;
  4 +import com.shunzhi.mqtt2kanban.bean.ValidcardeventBean;
  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 +
  11 +/**
  12 + * dao层
  13 + */
  14 +@Mapper
  15 +@Repository
  16 +public interface ValMapper {
  17 +
  18 + /**
  19 + *
  20 + * @param index 当前查询到的数据下标
  21 + * @return
  22 + */
  23 + List<ValidcardeventBean> select(@Param("index") int index);
  24 +
  25 + List<User> selectUser();
  26 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/UserSeerviceImp.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/UserSeerviceImp.java
... ... @@ -0,0 +1,39 @@
  1 +package com.shunzhi.mqtt2kanban.service;
  2 +
  3 +import com.shunzhi.mqtt2kanban.bean.Attendance;
  4 +import com.shunzhi.mqtt2kanban.bean.User;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  7 +import org.springframework.jdbc.core.JdbcTemplate;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +import java.util.List;
  11 +
  12 +@Service
  13 +public class UserSeerviceImp implements UserService {
  14 +
  15 + @Autowired
  16 + private JdbcTemplate jdbcTemplate;
  17 +
  18 + @Override
  19 + public List<User> getAllUsers(int index) {
  20 +
  21 + String sql ="";
  22 + if (index==1){
  23 + sql = "SELECT * FROM user limit "+2;
  24 + }else {
  25 + sql = String.format("SELECT * FROM user limit %s,10",index);
  26 + }
  27 +
  28 + return jdbcTemplate.query(sql, new Object[]{}, new BeanPropertyRowMapper<User>(User.class));
  29 + }
  30 +
  31 + @Override
  32 + public List<Attendance> getAttendance(String user_id) {
  33 + String sql = "SELECT * FROM SZ_AttendanceRecords201906 where school_id=27 and intime>'2019-06-19 16:00' and intime<'2019-06-19 17:40' and user_id = '"+user_id+"'";
  34 +
  35 + return jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<Attendance>(Attendance.class));
  36 + }
  37 +
  38 +
  39 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/UserService.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/UserService.java
... ... @@ -0,0 +1,18 @@
  1 +package com.shunzhi.mqtt2kanban.service;
  2 +
  3 +import com.shunzhi.mqtt2kanban.bean.Attendance;
  4 +import com.shunzhi.mqtt2kanban.bean.User;
  5 +
  6 +import java.util.List;
  7 +
  8 +public interface UserService {
  9 +
  10 + /**
  11 + * 获取所有用户
  12 + * @return
  13 + */
  14 + List<User> getAllUsers(int index);
  15 +
  16 + List<Attendance> getAttendance(String user_id);
  17 +
  18 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/ValService.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/ValService.java
... ... @@ -0,0 +1,14 @@
  1 +package com.shunzhi.mqtt2kanban.service;
  2 +
  3 +import com.shunzhi.mqtt2kanban.bean.User;
  4 +import com.shunzhi.mqtt2kanban.bean.ValidcardeventBean;
  5 +
  6 +import java.util.List;
  7 +
  8 +public interface ValService {
  9 + List<ValidcardeventBean> select(int index);
  10 +
  11 + List<User> getUser();
  12 +
  13 + List<ValidcardeventBean> getValids(long index);
  14 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/ValServiceImp.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/service/ValServiceImp.java
... ... @@ -0,0 +1,54 @@
  1 +package com.shunzhi.mqtt2kanban.service;
  2 +
  3 +import com.shunzhi.mqtt2kanban.ApplicationRunnerImpl;
  4 +import com.shunzhi.mqtt2kanban.bean.User;
  5 +import com.shunzhi.mqtt2kanban.bean.ValidcardeventBean;
  6 +import com.shunzhi.mqtt2kanban.mapper.ValMapper;
  7 +import org.apache.ibatis.session.SqlSession;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  10 +import org.springframework.jdbc.core.JdbcTemplate;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +import java.util.List;
  14 +
  15 +/**
  16 + * 实现类
  17 + */
  18 +@Service
  19 +public class ValServiceImp implements ValService {
  20 +
  21 + @Autowired
  22 + private ValMapper valMapper;
  23 +
  24 + @Autowired
  25 + private JdbcTemplate jdbcTemplate;
  26 +
  27 +
  28 + @Override
  29 + public List<ValidcardeventBean> select(int index) {
  30 + return valMapper.select(index);
  31 + }
  32 +
  33 + @Override
  34 + public List<User> getUser() {
  35 + return valMapper.selectUser();
  36 + }
  37 +
  38 + @Override
  39 + public List<ValidcardeventBean> getValids(long index) {
  40 + String sql = "";
  41 +// SELECT * FROM t_d_validcardevent order by ValidEventID desc limit 0,1
  42 + System.out.println("当前下标:" + index);
  43 + if (index==1){
  44 + sql = "SELECT * FROM t_d_validcardevent order by ValidEventID desc limit 1";
  45 + }else {
  46 + sql = String.format("SELECT * FROM t_d_validcardevent val where val.ValidEventID > %s limit 10",index);
  47 +// sql = "SELECT * FROM t_d_validcardevent val where val.ValidEventID > 400000 limit 100";
  48 + }
  49 +// System.out.println("sql:"+sql);
  50 + return jdbcTemplate.query(sql,new Object[]{},new BeanPropertyRowMapper<ValidcardeventBean>(ValidcardeventBean.class));
  51 + }
  52 +
  53 +
  54 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/utils/ScheduledTasks.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/utils/ScheduledTasks.java
... ... @@ -0,0 +1,202 @@
  1 +package com.shunzhi.mqtt2kanban.utils;
  2 +
  3 +import com.shunzhi.mqtt2kanban.ApplicationRunnerImpl;
  4 +import com.shunzhi.mqtt2kanban.bean.User;
  5 +import com.shunzhi.mqtt2kanban.bean.ValidcardeventBean;
  6 +import com.shunzhi.mqtt2kanban.service.UserService;
  7 +import com.shunzhi.mqtt2kanban.service.ValService;
  8 +import org.apache.http.util.TextUtils;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.core.io.FileSystemResource;
  11 +import org.springframework.http.HttpEntity;
  12 +import org.springframework.http.HttpHeaders;
  13 +import org.springframework.http.MediaType;
  14 +import org.springframework.scheduling.annotation.Scheduled;
  15 +import org.springframework.stereotype.Component;
  16 +import org.springframework.util.LinkedMultiValueMap;
  17 +import org.springframework.util.MultiValueMap;
  18 +import org.springframework.web.client.RestTemplate;
  19 +
  20 +import java.io.File;
  21 +import java.io.FileInputStream;
  22 +import java.io.FileNotFoundException;
  23 +import java.text.SimpleDateFormat;
  24 +import java.util.ArrayList;
  25 +import java.util.Date;
  26 +import java.util.List;
  27 +
  28 +@Component
  29 +public class ScheduledTasks {
  30 +
  31 + @Autowired
  32 + private RestTemplate restTemplate;//网络请求
  33 +
  34 + @Autowired
  35 + private UserService userService;
  36 +
  37 + @Autowired
  38 + private ValService valService;
  39 +
  40 + private static long index = 1;//记录取数的下标,第一次取最新一条
  41 +
  42 + private boolean isSendFinish = true;//判断是否发送成功;
  43 +
  44 + private boolean isLast = false;
  45 +
  46 + private ApplicationRunnerImpl applicationRunner;
  47 +
  48 + private static final SimpleDateFormat si = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  49 +
  50 + private String imgPathsStu = "C:\\Users\\Administrator\\Desktop\\imgs\\student";//存放学生人脸图片
  51 +
  52 + private String imgPathTea = "C:\\Users\\Administrator\\Desktop\\imgs\\teacher";//存放学生人脸图片
  53 +
  54 +// private String imgPaths = "C:\\Users\\taohandong\\Desktop\\img";//存放人脸图片
  55 +
  56 +
  57 + //每隔5秒取一次数据
  58 + @Scheduled(fixedDelay = 2000)
  59 + public void reportCurrentTime() {
  60 + System.out.println("任务调度:" + new SimpleDateFormat("HH:mm:ss").format(new Date()));
  61 + try {
  62 + if (null == applicationRunner) applicationRunner = new ApplicationRunnerImpl();
  63 + if (ApplicationRunnerImpl.isConnect) //MQ是否连接
  64 + getVaild();
  65 +
  66 + readImgs();
  67 + // getUser();
  68 + } catch (Exception e) {
  69 + getVaild();
  70 + System.out.println("eeeeeeee:" + e.toString());
  71 + e.printStackTrace();
  72 + }
  73 +
  74 + }
  75 +
  76 + /**
  77 + * 读取图片
  78 + */
  79 + private synchronized void readImgs() {
  80 + System.out.println("读取图片:");
  81 + try {
  82 + File file = new File(imgPathsStu);
  83 + File fileTea = new File(imgPathTea);
  84 + if (!file.exists())file.createNewFile();
  85 + if (!fileTea.exists())fileTea.createNewFile();
  86 +// System.out.println("读取图片:"+file.exists());
  87 + if (file.exists()) {
  88 + File[] imgs = file.listFiles();
  89 + for (int i = 0; i < imgs.length; i++) {
  90 + File imgFile = imgs[i];
  91 + String fileName = imgFile.getName();
  92 + uploadImgs(fileName.split("\\.")[0],imgFile.getAbsolutePath());
  93 + }
  94 + }
  95 +
  96 + if (fileTea.exists()){
  97 + File[] imgsTea = fileTea.listFiles();
  98 + for (int i = 0; i < imgsTea.length; i++) {
  99 + File imgFileTea = imgsTea[i];
  100 + String fileTeaName = imgFileTea.getName();
  101 + uploadImgs("teacher"+fileTeaName.split("\\.")[0],imgFileTea.getAbsolutePath());
  102 + }
  103 +
  104 + }
  105 +
  106 + } catch (Exception e) {
  107 + e.printStackTrace();
  108 + }
  109 +
  110 + }
  111 +
  112 +
  113 + private void uploadImgs(String card, String filePath) {
  114 + String url = "http://localhost:81/facereco/FaceUploadFile";
  115 +// String url = "http://220.189.228.132:81/facereco/FaceUploadFile";
  116 + FileSystemResource resource = new FileSystemResource(filePath);
  117 + MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
  118 + map.add("file", resource);
  119 +
  120 +
  121 + HttpHeaders headers = new HttpHeaders();
  122 + headers.setContentType(MediaType.MULTIPART_FORM_DATA);
  123 + headers.set("schoolid", "27");
  124 + headers.set("card", card);
  125 + HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(map, headers);
  126 + String result = restTemplate.postForEntity(url, httpEntity, String.class).getBody();
  127 + if (!TextUtils.isEmpty(result))new File(filePath).delete();
  128 + System.out.println("图片上传结果:" + result);
  129 + }
  130 +
  131 + private void getUser() {
  132 + if (isSendFinish) {
  133 +// isSendFinish = false;
  134 + List<User> list = null;
  135 + if (index == 1) {
  136 + list = userService.getAllUsers((int) index);
  137 + if (list != null && list.size() > 0)
  138 + index = Long.parseLong(list.get(1).getUser_id());
  139 + } else {
  140 + list = userService.getAllUsers((int) index);
  141 + index = 10;
  142 + }
  143 + System.out.println("user:" + list.size());
  144 + System.out.println("index:" + index);
  145 + if (index != 10)
  146 + getUser();
  147 +// for (int i = 0; i < list.size(); i++) {
  148 +// sendMQ(new ArrayList<>());
  149 +// }
  150 + }
  151 +
  152 + }
  153 +
  154 + private void getVaild() {
  155 + if (isSendFinish) {
  156 + isSendFinish = false;
  157 + List<ValidcardeventBean> validcardeventBeanList = null;
  158 + if (index == 1) {
  159 + validcardeventBeanList = valService.getValids(index);
  160 + if (null != validcardeventBeanList && validcardeventBeanList.size() > 0)
  161 + index = validcardeventBeanList.get(0).getValidEventID();
  162 +// System.out.println("validcardeventBeanList:" + validcardeventBeanList.toString());
  163 + } else {
  164 +// index = 391523;
  165 + validcardeventBeanList = valService.getValids(index);
  166 +// System.out.println("validcardeventBeanList:" + validcardeventBeanList);
  167 + //已经是最后一条了之后返回
  168 + if (null != validcardeventBeanList && validcardeventBeanList.size() > 0 && index == validcardeventBeanList.get(validcardeventBeanList.size() - 1).getValidEventID())
  169 + isLast = true;
  170 + else isLast = false;
  171 + }
  172 + System.out.println("validcardeventBeanList:" + validcardeventBeanList.size());
  173 + if (!isLast)
  174 + sendMQ(validcardeventBeanList);
  175 + }
  176 + }
  177 +
  178 + /**
  179 + * 发送MQ消息
  180 + *
  181 + * @param validcardeventBeanList
  182 + */
  183 + private void sendMQ(List<ValidcardeventBean> validcardeventBeanList) {
  184 + if (null == validcardeventBeanList) {
  185 + isSendFinish = true;
  186 + return;
  187 + }
  188 + if (validcardeventBeanList.size() == 0) {
  189 + isSendFinish = true;
  190 + return;
  191 + }
  192 +
  193 + for (int i = 0; i < validcardeventBeanList.size(); i++) {
  194 + ValidcardeventBean validcardeventBean = validcardeventBeanList.get(i);
  195 + applicationRunner.sendMessage(validcardeventBean.getEquipmentSN(), validcardeventBean.getConsumerNO(), validcardeventBean.getInOrOut());
  196 + if (i == validcardeventBeanList.size() - 1) index = validcardeventBeanList.get(i).getValidEventID();
  197 + }
  198 + isSendFinish = true;
  199 + System.out.println("现在时间:" + si.format(new Date()) + " ");
  200 + }
  201 +
  202 +}
... ...
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/utils/Tools.java 0 → 100644
  1 +++ a/mq2kb/src/main/java/com/shunzhi/mqtt2kanban/utils/Tools.java
... ... @@ -0,0 +1,217 @@
  1 +package com.shunzhi.mqtt2kanban.utils;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import org.apache.commons.codec.binary.Base64;
  6 +import org.apache.http.HttpEntity;
  7 +import org.apache.http.HttpResponse;
  8 +import org.apache.http.HttpStatus;
  9 +import org.apache.http.NameValuePair;
  10 +import org.apache.http.client.HttpClient;
  11 +import org.apache.http.client.entity.UrlEncodedFormEntity;
  12 +import org.apache.http.client.methods.HttpGet;
  13 +import org.apache.http.client.methods.HttpPost;
  14 +import org.apache.http.client.utils.URLEncodedUtils;
  15 +import org.apache.http.config.Registry;
  16 +import org.apache.http.config.RegistryBuilder;
  17 +import org.apache.http.conn.socket.ConnectionSocketFactory;
  18 +import org.apache.http.conn.socket.PlainConnectionSocketFactory;
  19 +import org.apache.http.conn.ssl.NoopHostnameVerifier;
  20 +import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
  21 +import org.apache.http.impl.client.HttpClientBuilder;
  22 +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
  23 +import org.apache.http.message.BasicNameValuePair;
  24 +import org.apache.http.util.EntityUtils;
  25 +
  26 +import javax.crypto.Mac;
  27 +import javax.crypto.spec.SecretKeySpec;
  28 +import javax.net.ssl.SSLContext;
  29 +import javax.net.ssl.TrustManager;
  30 +import javax.net.ssl.X509TrustManager;
  31 +import java.io.IOException;
  32 +import java.nio.charset.Charset;
  33 +import java.security.*;
  34 +import java.security.cert.CertificateException;
  35 +import java.security.cert.X509Certificate;
  36 +import java.util.*;
  37 +
  38 +/**
  39 + * Created by alvin on 17-3-29.
  40 + */
  41 +public class Tools {
  42 + public static Properties loadProperties() {
  43 + Properties properties = new Properties();
  44 + try {
  45 + properties.load(ClassLoader.getSystemResourceAsStream("test.properties"));
  46 + } catch (IOException e) {
  47 + }
  48 + return properties;
  49 + }
  50 +
  51 + /**
  52 + * 计算签名,参数分别是参数对以及密钥
  53 + *
  54 + * @param requestParams 参数对,即参与计算签名的参数
  55 + * @param secretKey 密钥
  56 + * @return 签名字符串
  57 + * @throws NoSuchAlgorithmException
  58 + * @throws InvalidKeyException
  59 + */
  60 + public static String doHttpSignature(Map<String, String> requestParams, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException {
  61 + List<String> paramList = new ArrayList<String>();
  62 + for (Map.Entry<String, String> entry : requestParams.entrySet()) {
  63 + paramList.add(entry.getKey() + "=" + entry.getValue());
  64 + }
  65 + Collections.sort(paramList);
  66 + StringBuffer sb = new StringBuffer();
  67 + for (int i = 0; i < paramList.size(); i++) {
  68 + if (i > 0) {
  69 + sb.append('&');
  70 + }
  71 + sb.append(paramList.get(i));
  72 + }
  73 + return macSignature(sb.toString(), secretKey);
  74 + }
  75 +
  76 + /**
  77 + * @param text 要签名的文本
  78 + * @param secretKey 阿里云MQ secretKey
  79 + * @return 加密后的字符串
  80 + * @throws InvalidKeyException
  81 + * @throws NoSuchAlgorithmException
  82 + */
  83 + public static String macSignature(String text, String secretKey) throws InvalidKeyException, NoSuchAlgorithmException {
  84 + Charset charset = Charset.forName("UTF-8");
  85 + String algorithm = "HmacSHA1";
  86 + Mac mac = Mac.getInstance(algorithm);
  87 + mac.init(new SecretKeySpec(secretKey.getBytes(charset), algorithm));
  88 + byte[] bytes = mac.doFinal(text.getBytes(charset));
  89 + return new String(Base64.encodeBase64(bytes), charset);
  90 + }
  91 +
  92 + /**
  93 + * 创建HTTPS 客户端
  94 + *
  95 + * @return 单例模式的客户端
  96 + * @throws KeyStoreException
  97 + * @throws UnrecoverableKeyException
  98 + * @throws NoSuchAlgorithmException
  99 + * @throws KeyManagementException
  100 + */
  101 + private static HttpClient httpClient = null;
  102 +
  103 + public static HttpClient getHttpsClient() throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException {
  104 + if (httpClient != null) {
  105 + return httpClient;
  106 + }
  107 + X509TrustManager xtm = new X509TrustManager() {
  108 + @Override
  109 + public void checkClientTrusted(X509Certificate[] arg0, String arg1)
  110 + throws CertificateException {
  111 + }
  112 +
  113 + @Override
  114 + public void checkServerTrusted(X509Certificate[] arg0, String arg1)
  115 + throws CertificateException {
  116 + }
  117 +
  118 + @Override
  119 + public X509Certificate[] getAcceptedIssuers() {
  120 + return new X509Certificate[]{};
  121 + }
  122 + };
  123 + SSLContext context = SSLContext.getInstance("TLS");
  124 + context.init(null, new TrustManager[]{xtm}, null);
  125 + SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE);
  126 + Registry<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create()
  127 + .register("http", PlainConnectionSocketFactory.INSTANCE)
  128 + .register("https", scsf).build();
  129 + PoolingHttpClientConnectionManager pcm = new PoolingHttpClientConnectionManager(sfr);
  130 + httpClient = HttpClientBuilder.create().setConnectionManager(pcm).build();
  131 + return httpClient;
  132 + }
  133 +
  134 + public static HttpClient createHttpsClient() throws KeyManagementException, NoSuchAlgorithmException {
  135 + X509TrustManager xtm = new X509TrustManager() {
  136 + @Override
  137 + public void checkClientTrusted(X509Certificate[] arg0, String arg1)
  138 + throws CertificateException {
  139 + }
  140 +
  141 + @Override
  142 + public void checkServerTrusted(X509Certificate[] arg0, String arg1)
  143 + throws CertificateException {
  144 + }
  145 +
  146 + @Override
  147 + public X509Certificate[] getAcceptedIssuers() {
  148 + return new X509Certificate[]{};
  149 + }
  150 + };
  151 + SSLContext context = SSLContext.getInstance("TLS");
  152 + context.init(null, new TrustManager[]{xtm}, null);
  153 + SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE);
  154 + Registry<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create()
  155 + .register("http", PlainConnectionSocketFactory.INSTANCE)
  156 + .register("https", scsf).build();
  157 + PoolingHttpClientConnectionManager pcm = new PoolingHttpClientConnectionManager(sfr);
  158 + return HttpClientBuilder.create().setConnectionManager(pcm).build();
  159 + }
  160 +
  161 + /**
  162 + * 发起Https Get请求,并得到返回的JSON响应
  163 + *
  164 + * @param url 接口Url
  165 + * @param params 参数u对
  166 + * @return
  167 + * @throws IOException
  168 + * @throws KeyStoreException
  169 + * @throws UnrecoverableKeyException
  170 + * @throws NoSuchAlgorithmException
  171 + * @throws KeyManagementException
  172 + */
  173 + public static JSONObject httpsGet(String url, Map<String, String> params) throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException {
  174 + HttpClient client = Tools.getHttpsClient();
  175 + JSONObject jsonResult = null;
  176 + //发送get请求
  177 + List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
  178 + for (Map.Entry<String, String> entry : params.entrySet()) {
  179 + urlParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
  180 + }
  181 + String paramUrl = URLEncodedUtils.format(urlParameters, Charset.forName("UTF-8"));
  182 + HttpGet request = new HttpGet(url + "?" + paramUrl);
  183 + HttpResponse response = client.execute(request);
  184 + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
  185 + String strResult = EntityUtils.toString(response.getEntity());
  186 + jsonResult = JSON.parseObject(strResult);
  187 + }
  188 + return jsonResult;
  189 + }
  190 +
  191 + /**
  192 + * 工具方法,发送一个http post请求,并尝试将响应转换为JSON
  193 + *
  194 + * @param url 请求的方法名url
  195 + * @param params 参数表
  196 + * @return 如果请求成功则返回JSON, 否则抛异常或者返回空
  197 + * @throws IOException
  198 + */
  199 + public static JSONObject httpsPost(String url, Map<String, String> params) throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
  200 + JSONObject jsonResult = null;
  201 + //发送get请求
  202 + HttpClient client = getHttpsClient();
  203 + HttpPost request = new HttpPost(url);
  204 + List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
  205 + for (Map.Entry<String, String> entry : params.entrySet()) {
  206 + urlParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
  207 + }
  208 + HttpEntity postParams = new UrlEncodedFormEntity(urlParameters);
  209 + request.setEntity(postParams);
  210 + HttpResponse response = client.execute(request);
  211 + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
  212 + String strResult = EntityUtils.toString(response.getEntity());
  213 + jsonResult = JSON.parseObject(strResult);
  214 + }
  215 + return jsonResult;
  216 + }
  217 +}
... ...
mq2kb/src/main/resources/application.properties 0 → 100644
  1 +++ a/mq2kb/src/main/resources/application.properties
... ... @@ -0,0 +1,22 @@
  1 +server.port=10086
  2 +
  3 +spring.datasource.url=jdbc:mysql://10.1.16.3:3307/jcacardone?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  4 +spring.datasource.username=thd
  5 +spring.datasource.password=654321
  6 +#spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
  7 +#spring.datasource.username=root
  8 +#spring.datasource.password=123456
  9 +#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  10 +
  11 +#sql
  12 +#spring.datasource.username=szjxtuser
  13 +#spring.datasource.password=RQminVCJota3H1u8bBYH
  14 +#spring.datasource.url=jdbc:sqlserver://116.62.155.137:33419;database=xiaoan
  15 +#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
  16 +
  17 +
  18 +mybatis.typealiases-package=com.shunzhi.mqtt2kanban.mapper
  19 +
  20 +mybatis.config-location=classpath:mybatis/mybatis-config.xml
  21 +mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
  22 +
... ...
mq2kb/src/main/resources/mybatis/mapper/ValidcardeventMapper.xml 0 → 100644
  1 +++ a/mq2kb/src/main/resources/mybatis/mapper/ValidcardeventMapper.xml
... ... @@ -0,0 +1,16 @@
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.shunzhi.mqtt2kanban.mapper.ValMapper" >
  4 + <!--<select id="getUsers" parameterType="int" resultType="com.shunzhi.mqtt2kanban.bean.User">
  5 +&#45;&#45; SELECT * FROM t_d_validcardevent
  6 + SELECT * FROM user
  7 +</select>-->
  8 + <select id="select" resultType="com.shunzhi.mqtt2kanban.bean.ValidcardeventBean">
  9 + SELECT * FROM t_d_validcardevent order by ValidEventID desc limit #{index},10
  10 + </select>
  11 +
  12 + <select id="selectUser" resultType="com.shunzhi.mqtt2kanban.bean.User">
  13 + SELECT * FROM user
  14 + </select>
  15 +
  16 +</mapper>
... ...
mq2kb/src/main/resources/mybatis/mybatis-config.xml 0 → 100644
  1 +++ a/mq2kb/src/main/resources/mybatis/mybatis-config.xml
... ... @@ -0,0 +1,35 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE configuration
  3 + PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5 +
  6 +<configuration>
  7 + <properties >
  8 + <property name="dialect" value="mysql" />
  9 + </properties>
  10 + <settings>
  11 + <!-- 这个配置使全局的映射器启用或禁用缓存。系统默认值是true,设置只是为了展示出来 -->
  12 + <setting name="cacheEnabled" value="true" />
  13 + <!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 系统默认值是true,设置只是为了展示出来 -->
  14 + <setting name="lazyLoadingEnabled" value="true" />
  15 + <!-- 允许或不允许多种结果集从一个单独的语句中返回(需要适合的驱动)。 系统默认值是true,设置只是为了展示出来 -->
  16 + <setting name="multipleResultSetsEnabled" value="true" />
  17 + <!--使用列标签代替列名。不同的驱动在这方便表现不同。参考驱动文档或充分测试两种方法来决定所使用的驱动。 系统默认值是true,设置只是为了展示出来 -->
  18 + <setting name="useColumnLabel" value="true" />
  19 + <!--允许 JDBC 支持生成的键。需要适合的驱动。如果设置为 true 则这个设置强制生成的键被使用,尽管一些驱动拒绝兼容但仍然有效(比如
  20 + Derby)。 系统默认值是false,设置只是为了展示出来 -->
  21 + <setting name="useGeneratedKeys" value="false" />
  22 + <!--配置默认的执行器。SIMPLE 执行器没有什么特别之处。REUSE 执行器重用预处理语句。BATCH 执行器重用语句和批量更新 系统默认值是SIMPLE,设置只是为了展示出来 -->
  23 + <setting name="defaultExecutorType" value="SIMPLE" />
  24 + <!--设置超时时间,它决定驱动等待一个数据库响应的时间。 系统默认值是null,设置只是为了展示出来 -->
  25 + <setting name="defaultStatementTimeout" value="25000" />
  26 + </settings>
  27 +
  28 + <!--<typeAliases>-->
  29 + <!--<typeAlias alias="user" type="com.shunzhi.mqtt2kanban.bean.User"/>-->
  30 + <!--</typeAliases>-->
  31 +
  32 + <!--<mappers>-->
  33 + <!--<mapper resource="mybatis/mapper/UserMapper.xml"/>-->
  34 + <!--</mappers>-->
  35 +</configuration>
0 36 \ No newline at end of file
... ...
mq2kb/src/main/resources/test.properties 0 → 100644
  1 +++ a/mq2kb/src/main/resources/test.properties
... ... @@ -0,0 +1,23 @@
  1 +#use the mqtt endpoint in mq console
  2 +brokerUrl=tcp://post-cn-4590mq2hr03.mqtt.aliyuncs.com:1883
  3 +#brokerUrl=tcp://127.0.0.1:61613
  4 +sslBrokerUrl=ssl://XXXXX:8883
  5 +#use the mq topic as parent topic
  6 +topic=Topic_Quene_Test
  7 +#topic=chatgeneral
  8 +#use the ak from aliyun ak console
  9 +accessKey=UimvLVp0Wj90P88u
  10 +#accessKey=admin
  11 +#use the sk from aliyun ak console
  12 +secretKey=TE4rZenITG27tiQqHx9qINjx71Nws7
  13 +#secretKey=password
  14 +#use the groupId from mq console
  15 +groupId=GID_HFJSIURFHAQO110
  16 +qos=0
  17 +cleanSession=false
  18 +##
  19 +##this param is use for mq client send or receive mqtt msg
  20 +##
  21 +producerId=PID_Producer4008262468
  22 +consumerId=CID_Consumer4008262468
  23 +regionId =post-cn-4590mq2hr03
0 24 \ No newline at end of file
... ...
mq2kb/src/test/java/com/shunzhi/mqtt2kanban/Mqtt2kanbanApplicationTests.java 0 → 100644
  1 +++ a/mq2kb/src/test/java/com/shunzhi/mqtt2kanban/Mqtt2kanbanApplicationTests.java
... ... @@ -0,0 +1,17 @@
  1 +package com.shunzhi.mqtt2kanban;
  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 Mqtt2kanbanApplicationTests {
  11 +
  12 + @Test
  13 + public void contextLoads() {
  14 +
  15 + }
  16 +
  17 +}
... ...