| @@ -0,0 +1,33 @@ | |||
| HELP.md | |||
| target/ | |||
| !.mvn/wrapper/maven-wrapper.jar | |||
| !**/src/main/**/target/ | |||
| !**/src/test/**/target/ | |||
| ### STS ### | |||
| .apt_generated | |||
| .classpath | |||
| .factorypath | |||
| .project | |||
| .settings | |||
| .springBeans | |||
| .sts4-cache | |||
| ### IntelliJ IDEA ### | |||
| .idea | |||
| *.iws | |||
| *.iml | |||
| *.ipr | |||
| ### NetBeans ### | |||
| /nbproject/private/ | |||
| /nbbuild/ | |||
| /dist/ | |||
| /nbdist/ | |||
| /.nb-gradle/ | |||
| build/ | |||
| !**/src/main/**/build/ | |||
| !**/src/test/**/build/ | |||
| ### VS Code ### | |||
| .vscode/ | |||
| @@ -0,0 +1,118 @@ | |||
| /* | |||
| * Copyright 2007-present the original author or authors. | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * https://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| import java.net.*; | |||
| import java.io.*; | |||
| import java.nio.channels.*; | |||
| import java.util.Properties; | |||
| public class MavenWrapperDownloader { | |||
| private static final String WRAPPER_VERSION = "0.5.6"; | |||
| /** | |||
| * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | |||
| */ | |||
| private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" | |||
| + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; | |||
| /** | |||
| * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | |||
| * use instead of the default one. | |||
| */ | |||
| private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | |||
| ".mvn/wrapper/maven-wrapper.properties"; | |||
| /** | |||
| * Path where the maven-wrapper.jar will be saved to. | |||
| */ | |||
| private static final String MAVEN_WRAPPER_JAR_PATH = | |||
| ".mvn/wrapper/maven-wrapper.jar"; | |||
| /** | |||
| * Name of the property which should be used to override the default download url for the wrapper. | |||
| */ | |||
| private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | |||
| public static void main(String args[]) { | |||
| System.out.println("- Downloader started"); | |||
| File baseDirectory = new File(args[0]); | |||
| System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | |||
| // If the maven-wrapper.properties exists, read it and check if it contains a custom | |||
| // wrapperUrl parameter. | |||
| File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | |||
| String url = DEFAULT_DOWNLOAD_URL; | |||
| if (mavenWrapperPropertyFile.exists()) { | |||
| FileInputStream mavenWrapperPropertyFileInputStream = null; | |||
| try { | |||
| mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | |||
| Properties mavenWrapperProperties = new Properties(); | |||
| mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | |||
| url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | |||
| } catch (IOException e) { | |||
| System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | |||
| } finally { | |||
| try { | |||
| if (mavenWrapperPropertyFileInputStream != null) { | |||
| mavenWrapperPropertyFileInputStream.close(); | |||
| } | |||
| } catch (IOException e) { | |||
| // Ignore ... | |||
| } | |||
| } | |||
| } | |||
| System.out.println("- Downloading from: " + url); | |||
| File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | |||
| if (!outputFile.getParentFile().exists()) { | |||
| if (!outputFile.getParentFile().mkdirs()) { | |||
| System.out.println( | |||
| "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | |||
| } | |||
| } | |||
| System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | |||
| try { | |||
| downloadFileFromURL(url, outputFile); | |||
| System.out.println("Done"); | |||
| System.exit(0); | |||
| } catch (Throwable e) { | |||
| System.out.println("- Error downloading"); | |||
| e.printStackTrace(); | |||
| System.exit(1); | |||
| } | |||
| } | |||
| private static void downloadFileFromURL(String urlString, File destination) throws Exception { | |||
| if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { | |||
| String username = System.getenv("MVNW_USERNAME"); | |||
| char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); | |||
| Authenticator.setDefault(new Authenticator() { | |||
| @Override | |||
| protected PasswordAuthentication getPasswordAuthentication() { | |||
| return new PasswordAuthentication(username, password); | |||
| } | |||
| }); | |||
| } | |||
| URL website = new URL(urlString); | |||
| ReadableByteChannel rbc; | |||
| rbc = Channels.newChannel(website.openStream()); | |||
| FileOutputStream fos = new FileOutputStream(destination); | |||
| fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | |||
| fos.close(); | |||
| rbc.close(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,2 @@ | |||
| distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip | |||
| wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar | |||
| @@ -0,0 +1,310 @@ | |||
| #!/bin/sh | |||
| # ---------------------------------------------------------------------------- | |||
| # Licensed to the Apache Software Foundation (ASF) under one | |||
| # or more contributor license agreements. See the NOTICE file | |||
| # distributed with this work for additional information | |||
| # regarding copyright ownership. The ASF licenses this file | |||
| # to you under the Apache License, Version 2.0 (the | |||
| # "License"); you may not use this file except in compliance | |||
| # with the License. You may obtain a copy of the License at | |||
| # | |||
| # https://www.apache.org/licenses/LICENSE-2.0 | |||
| # | |||
| # Unless required by applicable law or agreed to in writing, | |||
| # software distributed under the License is distributed on an | |||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||
| # KIND, either express or implied. See the License for the | |||
| # specific language governing permissions and limitations | |||
| # under the License. | |||
| # ---------------------------------------------------------------------------- | |||
| # ---------------------------------------------------------------------------- | |||
| # Maven Start Up Batch script | |||
| # | |||
| # Required ENV vars: | |||
| # ------------------ | |||
| # JAVA_HOME - location of a JDK home dir | |||
| # | |||
| # Optional ENV vars | |||
| # ----------------- | |||
| # M2_HOME - location of maven2's installed home dir | |||
| # MAVEN_OPTS - parameters passed to the Java VM when running Maven | |||
| # e.g. to debug Maven itself, use | |||
| # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 | |||
| # MAVEN_SKIP_RC - flag to disable loading of mavenrc files | |||
| # ---------------------------------------------------------------------------- | |||
| if [ -z "$MAVEN_SKIP_RC" ] ; then | |||
| if [ -f /etc/mavenrc ] ; then | |||
| . /etc/mavenrc | |||
| fi | |||
| if [ -f "$HOME/.mavenrc" ] ; then | |||
| . "$HOME/.mavenrc" | |||
| fi | |||
| fi | |||
| # OS specific support. $var _must_ be set to either true or false. | |||
| cygwin=false; | |||
| darwin=false; | |||
| mingw=false | |||
| case "`uname`" in | |||
| CYGWIN*) cygwin=true ;; | |||
| MINGW*) mingw=true;; | |||
| Darwin*) darwin=true | |||
| # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home | |||
| # See https://developer.apple.com/library/mac/qa/qa1170/_index.html | |||
| if [ -z "$JAVA_HOME" ]; then | |||
| if [ -x "/usr/libexec/java_home" ]; then | |||
| export JAVA_HOME="`/usr/libexec/java_home`" | |||
| else | |||
| export JAVA_HOME="/Library/Java/Home" | |||
| fi | |||
| fi | |||
| ;; | |||
| esac | |||
| if [ -z "$JAVA_HOME" ] ; then | |||
| if [ -r /etc/gentoo-release ] ; then | |||
| JAVA_HOME=`java-config --jre-home` | |||
| fi | |||
| fi | |||
| if [ -z "$M2_HOME" ] ; then | |||
| ## resolve links - $0 may be a link to maven's home | |||
| PRG="$0" | |||
| # need this for relative symlinks | |||
| while [ -h "$PRG" ] ; do | |||
| ls=`ls -ld "$PRG"` | |||
| link=`expr "$ls" : '.*-> \(.*\)$'` | |||
| if expr "$link" : '/.*' > /dev/null; then | |||
| PRG="$link" | |||
| else | |||
| PRG="`dirname "$PRG"`/$link" | |||
| fi | |||
| done | |||
| saveddir=`pwd` | |||
| M2_HOME=`dirname "$PRG"`/.. | |||
| # make it fully qualified | |||
| M2_HOME=`cd "$M2_HOME" && pwd` | |||
| cd "$saveddir" | |||
| # echo Using m2 at $M2_HOME | |||
| fi | |||
| # For Cygwin, ensure paths are in UNIX format before anything is touched | |||
| if $cygwin ; then | |||
| [ -n "$M2_HOME" ] && | |||
| M2_HOME=`cygpath --unix "$M2_HOME"` | |||
| [ -n "$JAVA_HOME" ] && | |||
| JAVA_HOME=`cygpath --unix "$JAVA_HOME"` | |||
| [ -n "$CLASSPATH" ] && | |||
| CLASSPATH=`cygpath --path --unix "$CLASSPATH"` | |||
| fi | |||
| # For Mingw, ensure paths are in UNIX format before anything is touched | |||
| if $mingw ; then | |||
| [ -n "$M2_HOME" ] && | |||
| M2_HOME="`(cd "$M2_HOME"; pwd)`" | |||
| [ -n "$JAVA_HOME" ] && | |||
| JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" | |||
| fi | |||
| if [ -z "$JAVA_HOME" ]; then | |||
| javaExecutable="`which javac`" | |||
| if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then | |||
| # readlink(1) is not available as standard on Solaris 10. | |||
| readLink=`which readlink` | |||
| if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then | |||
| if $darwin ; then | |||
| javaHome="`dirname \"$javaExecutable\"`" | |||
| javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" | |||
| else | |||
| javaExecutable="`readlink -f \"$javaExecutable\"`" | |||
| fi | |||
| javaHome="`dirname \"$javaExecutable\"`" | |||
| javaHome=`expr "$javaHome" : '\(.*\)/bin'` | |||
| JAVA_HOME="$javaHome" | |||
| export JAVA_HOME | |||
| fi | |||
| fi | |||
| fi | |||
| if [ -z "$JAVACMD" ] ; then | |||
| if [ -n "$JAVA_HOME" ] ; then | |||
| if [ -x "$JAVA_HOME/jre/sh/java" ] ; then | |||
| # IBM's JDK on AIX uses strange locations for the executables | |||
| JAVACMD="$JAVA_HOME/jre/sh/java" | |||
| else | |||
| JAVACMD="$JAVA_HOME/bin/java" | |||
| fi | |||
| else | |||
| JAVACMD="`which java`" | |||
| fi | |||
| fi | |||
| if [ ! -x "$JAVACMD" ] ; then | |||
| echo "Error: JAVA_HOME is not defined correctly." >&2 | |||
| echo " We cannot execute $JAVACMD" >&2 | |||
| exit 1 | |||
| fi | |||
| if [ -z "$JAVA_HOME" ] ; then | |||
| echo "Warning: JAVA_HOME environment variable is not set." | |||
| fi | |||
| CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher | |||
| # traverses directory structure from process work directory to filesystem root | |||
| # first directory with .mvn subdirectory is considered project base directory | |||
| find_maven_basedir() { | |||
| if [ -z "$1" ] | |||
| then | |||
| echo "Path not specified to find_maven_basedir" | |||
| return 1 | |||
| fi | |||
| basedir="$1" | |||
| wdir="$1" | |||
| while [ "$wdir" != '/' ] ; do | |||
| if [ -d "$wdir"/.mvn ] ; then | |||
| basedir=$wdir | |||
| break | |||
| fi | |||
| # workaround for JBEAP-8937 (on Solaris 10/Sparc) | |||
| if [ -d "${wdir}" ]; then | |||
| wdir=`cd "$wdir/.."; pwd` | |||
| fi | |||
| # end of workaround | |||
| done | |||
| echo "${basedir}" | |||
| } | |||
| # concatenates all lines of a file | |||
| concat_lines() { | |||
| if [ -f "$1" ]; then | |||
| echo "$(tr -s '\n' ' ' < "$1")" | |||
| fi | |||
| } | |||
| BASE_DIR=`find_maven_basedir "$(pwd)"` | |||
| if [ -z "$BASE_DIR" ]; then | |||
| exit 1; | |||
| fi | |||
| ########################################################################################## | |||
| # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | |||
| # This allows using the maven wrapper in projects that prohibit checking in binary data. | |||
| ########################################################################################## | |||
| if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo "Found .mvn/wrapper/maven-wrapper.jar" | |||
| fi | |||
| else | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." | |||
| fi | |||
| if [ -n "$MVNW_REPOURL" ]; then | |||
| jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |||
| else | |||
| jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |||
| fi | |||
| while IFS="=" read key value; do | |||
| case "$key" in (wrapperUrl) jarUrl="$value"; break ;; | |||
| esac | |||
| done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo "Downloading from: $jarUrl" | |||
| fi | |||
| wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" | |||
| if $cygwin; then | |||
| wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` | |||
| fi | |||
| if command -v wget > /dev/null; then | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo "Found wget ... using wget" | |||
| fi | |||
| if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | |||
| wget "$jarUrl" -O "$wrapperJarPath" | |||
| else | |||
| wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" | |||
| fi | |||
| elif command -v curl > /dev/null; then | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo "Found curl ... using curl" | |||
| fi | |||
| if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | |||
| curl -o "$wrapperJarPath" "$jarUrl" -f | |||
| else | |||
| curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f | |||
| fi | |||
| else | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo "Falling back to using Java to download" | |||
| fi | |||
| javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" | |||
| # For Cygwin, switch paths to Windows format before running javac | |||
| if $cygwin; then | |||
| javaClass=`cygpath --path --windows "$javaClass"` | |||
| fi | |||
| if [ -e "$javaClass" ]; then | |||
| if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo " - Compiling MavenWrapperDownloader.java ..." | |||
| fi | |||
| # Compiling the Java class | |||
| ("$JAVA_HOME/bin/javac" "$javaClass") | |||
| fi | |||
| if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | |||
| # Running the downloader | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo " - Running MavenWrapperDownloader.java ..." | |||
| fi | |||
| ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") | |||
| fi | |||
| fi | |||
| fi | |||
| fi | |||
| ########################################################################################## | |||
| # End of extension | |||
| ########################################################################################## | |||
| export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} | |||
| if [ "$MVNW_VERBOSE" = true ]; then | |||
| echo $MAVEN_PROJECTBASEDIR | |||
| fi | |||
| MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" | |||
| # For Cygwin, switch paths to Windows format before running java | |||
| if $cygwin; then | |||
| [ -n "$M2_HOME" ] && | |||
| M2_HOME=`cygpath --path --windows "$M2_HOME"` | |||
| [ -n "$JAVA_HOME" ] && | |||
| JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` | |||
| [ -n "$CLASSPATH" ] && | |||
| CLASSPATH=`cygpath --path --windows "$CLASSPATH"` | |||
| [ -n "$MAVEN_PROJECTBASEDIR" ] && | |||
| MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` | |||
| fi | |||
| # Provide a "standardized" way to retrieve the CLI args that will | |||
| # work with both Windows and non-Windows executions. | |||
| MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" | |||
| export MAVEN_CMD_LINE_ARGS | |||
| WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain | |||
| exec "$JAVACMD" \ | |||
| $MAVEN_OPTS \ | |||
| -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ | |||
| "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ | |||
| ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" | |||
| @@ -0,0 +1,182 @@ | |||
| @REM ---------------------------------------------------------------------------- | |||
| @REM Licensed to the Apache Software Foundation (ASF) under one | |||
| @REM or more contributor license agreements. See the NOTICE file | |||
| @REM distributed with this work for additional information | |||
| @REM regarding copyright ownership. The ASF licenses this file | |||
| @REM to you under the Apache License, Version 2.0 (the | |||
| @REM "License"); you may not use this file except in compliance | |||
| @REM with the License. You may obtain a copy of the License at | |||
| @REM | |||
| @REM https://www.apache.org/licenses/LICENSE-2.0 | |||
| @REM | |||
| @REM Unless required by applicable law or agreed to in writing, | |||
| @REM software distributed under the License is distributed on an | |||
| @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||
| @REM KIND, either express or implied. See the License for the | |||
| @REM specific language governing permissions and limitations | |||
| @REM under the License. | |||
| @REM ---------------------------------------------------------------------------- | |||
| @REM ---------------------------------------------------------------------------- | |||
| @REM Maven Start Up Batch script | |||
| @REM | |||
| @REM Required ENV vars: | |||
| @REM JAVA_HOME - location of a JDK home dir | |||
| @REM | |||
| @REM Optional ENV vars | |||
| @REM M2_HOME - location of maven2's installed home dir | |||
| @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands | |||
| @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending | |||
| @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven | |||
| @REM e.g. to debug Maven itself, use | |||
| @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 | |||
| @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files | |||
| @REM ---------------------------------------------------------------------------- | |||
| @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' | |||
| @echo off | |||
| @REM set title of command window | |||
| title %0 | |||
| @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' | |||
| @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% | |||
| @REM set %HOME% to equivalent of $HOME | |||
| if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") | |||
| @REM Execute a user defined script before this one | |||
| if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre | |||
| @REM check for pre script, once with legacy .bat ending and once with .cmd ending | |||
| if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" | |||
| if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" | |||
| :skipRcPre | |||
| @setlocal | |||
| set ERROR_CODE=0 | |||
| @REM To isolate internal variables from possible post scripts, we use another setlocal | |||
| @setlocal | |||
| @REM ==== START VALIDATION ==== | |||
| if not "%JAVA_HOME%" == "" goto OkJHome | |||
| echo. | |||
| echo Error: JAVA_HOME not found in your environment. >&2 | |||
| echo Please set the JAVA_HOME variable in your environment to match the >&2 | |||
| echo location of your Java installation. >&2 | |||
| echo. | |||
| goto error | |||
| :OkJHome | |||
| if exist "%JAVA_HOME%\bin\java.exe" goto init | |||
| echo. | |||
| echo Error: JAVA_HOME is set to an invalid directory. >&2 | |||
| echo JAVA_HOME = "%JAVA_HOME%" >&2 | |||
| echo Please set the JAVA_HOME variable in your environment to match the >&2 | |||
| echo location of your Java installation. >&2 | |||
| echo. | |||
| goto error | |||
| @REM ==== END VALIDATION ==== | |||
| :init | |||
| @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". | |||
| @REM Fallback to current working directory if not found. | |||
| set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% | |||
| IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir | |||
| set EXEC_DIR=%CD% | |||
| set WDIR=%EXEC_DIR% | |||
| :findBaseDir | |||
| IF EXIST "%WDIR%"\.mvn goto baseDirFound | |||
| cd .. | |||
| IF "%WDIR%"=="%CD%" goto baseDirNotFound | |||
| set WDIR=%CD% | |||
| goto findBaseDir | |||
| :baseDirFound | |||
| set MAVEN_PROJECTBASEDIR=%WDIR% | |||
| cd "%EXEC_DIR%" | |||
| goto endDetectBaseDir | |||
| :baseDirNotFound | |||
| set MAVEN_PROJECTBASEDIR=%EXEC_DIR% | |||
| cd "%EXEC_DIR%" | |||
| :endDetectBaseDir | |||
| IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig | |||
| @setlocal EnableExtensions EnableDelayedExpansion | |||
| for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a | |||
| @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% | |||
| :endReadAdditionalConfig | |||
| SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" | |||
| set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" | |||
| set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain | |||
| set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |||
| FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( | |||
| IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B | |||
| ) | |||
| @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | |||
| @REM This allows using the maven wrapper in projects that prohibit checking in binary data. | |||
| if exist %WRAPPER_JAR% ( | |||
| if "%MVNW_VERBOSE%" == "true" ( | |||
| echo Found %WRAPPER_JAR% | |||
| ) | |||
| ) else ( | |||
| if not "%MVNW_REPOURL%" == "" ( | |||
| SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |||
| ) | |||
| if "%MVNW_VERBOSE%" == "true" ( | |||
| echo Couldn't find %WRAPPER_JAR%, downloading it ... | |||
| echo Downloading from: %DOWNLOAD_URL% | |||
| ) | |||
| powershell -Command "&{"^ | |||
| "$webclient = new-object System.Net.WebClient;"^ | |||
| "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ | |||
| "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ | |||
| "}"^ | |||
| "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ | |||
| "}" | |||
| if "%MVNW_VERBOSE%" == "true" ( | |||
| echo Finished downloading %WRAPPER_JAR% | |||
| ) | |||
| ) | |||
| @REM End of extension | |||
| @REM Provide a "standardized" way to retrieve the CLI args that will | |||
| @REM work with both Windows and non-Windows executions. | |||
| set MAVEN_CMD_LINE_ARGS=%* | |||
| %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* | |||
| if ERRORLEVEL 1 goto error | |||
| goto end | |||
| :error | |||
| set ERROR_CODE=1 | |||
| :end | |||
| @endlocal & set ERROR_CODE=%ERROR_CODE% | |||
| if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost | |||
| @REM check for post script, once with legacy .bat ending and once with .cmd ending | |||
| if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" | |||
| if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" | |||
| :skipRcPost | |||
| @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' | |||
| if "%MAVEN_BATCH_PAUSE%" == "on" pause | |||
| if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% | |||
| exit /B %ERROR_CODE% | |||
| @@ -0,0 +1,87 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <parent> | |||
| <groupId>org.springframework.boot</groupId> | |||
| <artifactId>spring-boot-starter-parent</artifactId> | |||
| <version>2.5.2</version> | |||
| <relativePath/> <!-- lookup parent from repository --> | |||
| </parent> | |||
| <groupId>com.inet</groupId> | |||
| <artifactId>ailink-receiver</artifactId> | |||
| <version>1.1-20210826</version> | |||
| <name>ailink-receiver</name> | |||
| <description>Demo project for Spring Boot</description> | |||
| <properties> | |||
| <java.version>1.8</java.version> | |||
| </properties> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>org.springframework.boot</groupId> | |||
| <artifactId>spring-boot-starter-jdbc</artifactId> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>org.springframework.boot</groupId> | |||
| <artifactId>spring-boot-starter-web</artifactId> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>org.mybatis.spring.boot</groupId> | |||
| <artifactId>mybatis-spring-boot-starter</artifactId> | |||
| <version>2.2.0</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>org.springframework.boot</groupId> | |||
| <artifactId>spring-boot-devtools</artifactId> | |||
| <scope>runtime</scope> | |||
| <optional>true</optional> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>mysql</groupId> | |||
| <artifactId>mysql-connector-java</artifactId> | |||
| <scope>runtime</scope> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>org.projectlombok</groupId> | |||
| <artifactId>lombok</artifactId> | |||
| <optional>true</optional> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>org.springframework.boot</groupId> | |||
| <artifactId>spring-boot-starter-test</artifactId> | |||
| <scope>test</scope> | |||
| </dependency> | |||
| <!-- 以下是后来增加的库--> | |||
| <!-- <dependency>--> | |||
| <!-- <groupId>com.inet</groupId>--> | |||
| <!-- <artifactId>inet-base</artifactId>--> | |||
| <!-- <version>1.0</version>--> | |||
| <!-- </dependency>--> | |||
| <dependency> | |||
| <groupId>commons-lang</groupId> | |||
| <artifactId>commons-lang</artifactId> | |||
| <version>2.5</version> | |||
| </dependency> | |||
| </dependencies> | |||
| <build> | |||
| <plugins> | |||
| <plugin> | |||
| <groupId>org.springframework.boot</groupId> | |||
| <artifactId>spring-boot-maven-plugin</artifactId> | |||
| <configuration> | |||
| <excludes> | |||
| <exclude> | |||
| <groupId>org.projectlombok</groupId> | |||
| <artifactId>lombok</artifactId> | |||
| </exclude> | |||
| </excludes> | |||
| </configuration> | |||
| </plugin> | |||
| </plugins> | |||
| </build> | |||
| </project> | |||
| @@ -0,0 +1,19 @@ | |||
| package com.inet.ailink.receiver; | |||
| import org.mybatis.spring.annotation.MapperScan; | |||
| import org.springframework.boot.SpringApplication; | |||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
| import org.springframework.transaction.annotation.EnableTransactionManagement; | |||
| @SpringBootApplication | |||
| @EnableTransactionManagement | |||
| @EnableAutoConfiguration | |||
| @MapperScan("com.inet.ailink.receiver.mapper") | |||
| public class AilinkReceiverApplication { | |||
| public static void main(String[] args) { | |||
| SpringApplication.run(AilinkReceiverApplication.class, args); | |||
| } | |||
| } | |||
| @@ -0,0 +1,73 @@ | |||
| package com.inet.ailink.receiver.common.enums; | |||
| public class Common { | |||
| // ***************** 环境 ********************************* | |||
| public static final String ENVIRONMENT_DEV = "dev";// 开发 | |||
| public static final String ENVIRONMENT_TEST = "test";// 测试 | |||
| public static final String ENVIRONMENT_PRODUCT = "product";// 生产 | |||
| // ***************** 客户端类型 ********************************* | |||
| public static final Integer CLIENT_TYPE_PC = 1;// PC端 | |||
| public static final Integer CLIENT_TYPE_MOBILE = 2;// 手机端 | |||
| // ***************** 系统用户 ********************************* | |||
| public static final Long ADMIN_APP_USER_ID = 1l;// app的系统用户 | |||
| // ***************** 支付类型 ********************************* | |||
| public static final Integer PAY_TYPE_WECHAT = 1;// 微信支付 | |||
| public static final Integer PAY_TYPE_ALIPAY = 2;// 支付宝支付 | |||
| public static final Integer PAY_TYPE_OFFLINE = 3;// 线下 | |||
| // ***************** 表删除状态 ********************************* | |||
| public static final Integer DEL_STATUS_YES = 1;// 删除 | |||
| public static final Integer DEL_STATUS_NO = 0;// 不删除 | |||
| // ***************** 状态 ********************************* | |||
| public static final Integer STATUS_UESD = 1;// 使用 | |||
| public static final Integer STATUS_NO_USE = 0;// 未使用 | |||
| public static final Integer STATUS_INVALID = 2;//无效作废 | |||
| // ***************** 账户状态 ********************************* | |||
| public static final Integer ACCOOUNT_STATUS_OK = 0;// 正常 | |||
| public static final Integer ACCOOUNT_STATUS_LOCK = 1;// 锁定 | |||
| public static final Integer ACCOOUNT_LOGIN_STATUS_LOGOUT = 0;//未登录 | |||
| public static final Integer ACCOOUNT_LOGIN_STATUS_LOGINED = 1;//登录 | |||
| // ***************** 移动端设备类型********************************* | |||
| public static final Integer DEVICE_IOS = 1;// IOS设备 | |||
| public static final Integer DEVICE_ANDROID = 2;// 安卓设备 | |||
| public static final Integer DEVICE_WP = 3;// 移动版win | |||
| // ***************** 验证码类型********************************* | |||
| public static final Integer CHECK_TYPE_SIGN_UP = 1;//注册 | |||
| public static final Integer CHECK_TYPE_RESET_PWD = 2;// 重置密码 | |||
| public static final Integer CHECK_TYPE_UPDATE_PWD = 3;// 修改密码 | |||
| public static final Integer CHECK_TYPE_UPDATE_EMAIL = 4;// 修改邮箱 | |||
| // ***************** 验证码发送类型********************************* | |||
| public static final Integer CHECK_CODE_TYPE_EMAIL = 1;// 邮件 | |||
| public static final Integer CHECK_CODE_TYPE_MESSAGE = 2;//短信 | |||
| // ***************** 用户类型********************************* | |||
| public static final Integer USER_MODEL_1 = 1;// 普通用户 | |||
| public static final Integer USER_MODEL_2 = 2;//运动员 | |||
| public static final Integer USER_MODEL_3 = 2;//孕妇 | |||
| // ***************** App状态********************************* | |||
| public static final Integer APP_STATUS_OK = 0;// 正常 | |||
| public static final Integer APP_STATUS_UPDATE = 1;//维护 | |||
| public static final Integer APP_STATUS_DISENABLE = 2;//禁用 | |||
| // ***************** 樹狀圖共用的頂級id状态********************************* | |||
| public static final Long TOP_PARENT_ID = 0L;// | |||
| public final static byte[] TEA_KEY = new byte[] { | |||
| 0x00, 0x00, 0x00, 0x05, | |||
| 0x00, 0x00, 0x00, 0x03, | |||
| 0x00, 0x00, 0x00, 0x07, | |||
| 0x00, 0x00, 0x00, 0x08 | |||
| }; | |||
| } | |||
| @@ -0,0 +1,82 @@ | |||
| package com.inet.ailink.receiver.common.enums; | |||
| public enum StatusCode { | |||
| SUCCESS("1","success"), | |||
| FAIL("0","faile"), | |||
| PARAM_EMPTY("9901","params is null"), | |||
| DAO_ERROR("9902","数据库操作失败"), | |||
| USER_NOT_EXIST("9903","用户不存在"), | |||
| USER_PASSWORD_ERROR("9904","用户密码错误"), | |||
| USER_EXIST("9905","用户已经存在"), | |||
| PASSWORD_INCONSIST("9906","密码不一致"), | |||
| VERIFY_CODE_ERROR("9907","验证码错误"), | |||
| VERIFY_CODE_SEND_OUT_MAX_NUMBER("9908","验证码发送超过当天最大次数"), | |||
| VERIFY_CODE_NOT_EXIST("9909","不存在可用的验证码"), | |||
| PARAM_UNDEFINE("9910","参数未定义"), | |||
| PARAM_ERROR_REGION_PUT("9911","解析区域投放参数错误"), | |||
| PARAM_INVALID("9912","params is invalid"), | |||
| USER_NO_PERMISSIONS("9913","用户无权限"), | |||
| DEVICE_NOT_EXIST("9914","设备不存在"), | |||
| COMPANY_NOT_EXIST("9915","参数缺少APPId"), | |||
| NOT_PERMISSIONS("9916","没有权限"), | |||
| IN_USE("9917","使用中,不能删除"), | |||
| CANT_MODIFY("9929","操作冲突,刷新重试"), | |||
| PARAM_CHECK_ERROR("9995","参数检查错误"), | |||
| USER_UNLOGIN("9997","用户未登录"), | |||
| QUERY_EMPTY("9998","查询结果为空"), | |||
| FILE_TOO_BIG("9920","图片文件不能超过10M,视频文件不能超过30M"), | |||
| DAO_UPDATE_COUNT_ZERO_EXCEPTION("9921","更新失败"), | |||
| ACCOUNT_MEMBER_UPDATE_FAIL("9922","账户修改失败"), | |||
| UNKNOW("9999","未知异常"), | |||
| APP_ID_EMPTY("9923","appID数据为空"), | |||
| APP_TOKEN_EMPTY("9924","登录标识为空"), | |||
| ACCOUNT_ID_EMPTY("9925","UUID为空"), | |||
| ACCOUNT_SIGNATURE_EMPTY("9926","签名为空"), | |||
| ACCOUNT_SIGNATURE_ERROR("9927","签名错误"), | |||
| APP_EMPTY("6001","app不存在"), | |||
| APP_DELSTATUS("6002","app已经不存在"), | |||
| APP_STATUS("6003","app状态不正常"), | |||
| PARAMS_JSON_ERROR("2","参数不是json格式"), | |||
| PARAMS_JSON_KEY_ERROR("3","参数关键key错误"), | |||
| PARAMS_dECRYPT_ERROR("4","参数解密失败"), | |||
| PARAMS_EMPTY("5","关键参数为空"), | |||
| DEVICE_OTA_NO_NEW("6","没有更新版本的升级包"), | |||
| DEVICE_SERVER_URL_NO_SET("7","该类型的设备未设置服务器url"), | |||
| DEVICE_NOT_EXIT("8","设备不存在"), | |||
| ; | |||
| private String code=""; | |||
| private String msg=""; | |||
| StatusCode(String code, String msg){ | |||
| this.code=code; | |||
| this.msg=msg; | |||
| } | |||
| public String getCode() { | |||
| return code; | |||
| } | |||
| public void setCode(String code) { | |||
| this.code = code; | |||
| } | |||
| public String getMsg() { | |||
| return msg; | |||
| } | |||
| public void setMsg(String msg) { | |||
| this.msg = msg; | |||
| } | |||
| public static StatusCode getByCode(String param){ | |||
| for(StatusCode thisCode: StatusCode.values()){ | |||
| if(thisCode.code.equals(param)){ | |||
| return thisCode; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,92 @@ | |||
| package com.inet.ailink.receiver.common.exception; | |||
| import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| public class BizException extends Exception { | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = -4155383900948675082L; | |||
| private String code="9999"; | |||
| private String msg=""; | |||
| private String[] params; | |||
| private Object data; | |||
| public BizException() { | |||
| super(); | |||
| } | |||
| public BizException(StatusCode statusCode) { | |||
| super(); | |||
| code=statusCode.getCode(); | |||
| msg=statusCode.getMsg(); | |||
| } | |||
| public BizException(StatusCode statusCode, Object data) { | |||
| super(); | |||
| code=statusCode.getCode(); | |||
| msg=statusCode.getMsg(); | |||
| this.data = data; | |||
| } | |||
| public BizException(String code) { | |||
| this.code = code; | |||
| } | |||
| public BizException(String code, String msg) { | |||
| this.code = code; | |||
| this.msg = msg; | |||
| } | |||
| public BizException(Throwable cause) { | |||
| super(cause); | |||
| } | |||
| public BizException(String code, Throwable exception) { | |||
| super(exception); | |||
| this.code = code; | |||
| } | |||
| public BizException(String code, String msg, Throwable exception) { | |||
| super(msg, exception); | |||
| this.code = code; | |||
| } | |||
| public BizException(String code, String[] params) { | |||
| super(); | |||
| this.code = code; | |||
| this.params = params; | |||
| } | |||
| public BizException(String code, String[] params, Throwable exception) { | |||
| super(exception); | |||
| this.code = code; | |||
| this.params = params; | |||
| } | |||
| public String getCode() { | |||
| return this.code; | |||
| } | |||
| public String[] getParams() { | |||
| return params; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| String s = getClass().getName(); | |||
| return s + ": " + code + " params:"+params; | |||
| } | |||
| public String getMsg() { | |||
| return msg; | |||
| } | |||
| public void setMsg(String msg) { | |||
| this.msg = msg; | |||
| } | |||
| public void setCode(String code) { | |||
| this.code = code; | |||
| } | |||
| public Object getData() { | |||
| return data; | |||
| } | |||
| public void setData(Object data) { | |||
| this.data = data; | |||
| } | |||
| } | |||
| @@ -0,0 +1,396 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import java.io.UnsupportedEncodingException; | |||
| public class Base64TeaUitls { | |||
| //加密 | |||
| public static String encrypt(String dataValue){ | |||
| byte[] old = BytesUtils.getBytes(Integer.parseInt(dataValue)); | |||
| String result = ""; | |||
| try { | |||
| //tea加密 | |||
| byte[] teaDscrypt =TeaUtils.encrypt(old,null); | |||
| //base编码 | |||
| result= Base64Util.encoderString(teaDscrypt); | |||
| } catch (UnsupportedEncodingException e) { | |||
| return result; | |||
| } | |||
| return result; | |||
| } | |||
| //解密 | |||
| public static byte[] decrypt(String base64Text){ | |||
| //base解码 | |||
| String base64TextEn; | |||
| try { | |||
| base64TextEn = Base64Util.decoderString(base64Text); | |||
| //解码数据转换为byte数组 | |||
| byte[] base64TeaByteOld = Base64Util.hexStrToByteArray(base64TextEn); | |||
| //tea解密byte数组 | |||
| byte[] base64TeaByte =TeaUtils.decrypt(base64TeaByteOld,null); | |||
| //将负数转换为整数 | |||
| /*if(base64TeaByte != null){ | |||
| for(int i=0;i<base64TeaByte.length;i++){ | |||
| if(base64TeaByte[i]<0){ | |||
| base64TeaByte[i] = (byte) (256 + base64TeaByte[i]); | |||
| } | |||
| } | |||
| }*/ | |||
| return base64TeaByte; | |||
| } catch (UnsupportedEncodingException e) { | |||
| return null; | |||
| } | |||
| } | |||
| /** | |||
| * 十进制转16进制 | |||
| * @param n | |||
| * @return | |||
| */ | |||
| private static String intToHex(int n) { | |||
| StringBuilder sb = new StringBuilder(8); | |||
| String a; | |||
| char []b = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; | |||
| if(n==0){ | |||
| return "00"; | |||
| } | |||
| while(n != 0){ | |||
| if(n<0){ | |||
| n= 256 +n; | |||
| } | |||
| sb = sb.append(b[n%16]); | |||
| n = n/16; | |||
| } | |||
| a = sb.reverse().toString(); | |||
| if(a.length() == 1){ | |||
| a= "0"+a; | |||
| } | |||
| return a; | |||
| } | |||
| /** | |||
| * 获取开始下标到结束下标的16进制的值 | |||
| * @param start | |||
| * @param end | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String getStartToEndForHex(int start,int end,byte[] params){ | |||
| String result = ""; | |||
| for(int i=start;i<=end;i++){ | |||
| if(i==end){ | |||
| result = result+intToHex(params[i]); | |||
| }else{ | |||
| result = result+intToHex(params[i])+":"; | |||
| } | |||
| // System.out.println(params[i]+":"+intToHex(params[i])); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 获取开始下标到结束下标的10进制的值 | |||
| * @param start | |||
| * @param end | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String getStartToEndForInt(int start,int end,byte[] params){ | |||
| String result = ""; | |||
| for(int i=start;i<=end;i++){ | |||
| int temp = params[i]; | |||
| if(temp < 0){ | |||
| temp = 256 + temp; | |||
| } | |||
| if(i==end){ | |||
| result = result+temp; | |||
| }else{ | |||
| result = result+temp+":"; | |||
| } | |||
| } | |||
| return result; | |||
| } | |||
| /*public static String getLowToHighEndForInt(int indexLow,int indexHigh,byte[] params){ | |||
| String result = ""; | |||
| int tempLow = params[indexLow]; | |||
| if(tempLow < 0){ | |||
| tempLow = 256 + tempLow; | |||
| } | |||
| int tempHigh = params[indexHigh]; | |||
| if(tempHigh < 0){ | |||
| tempHigh = 256 + tempHigh; | |||
| } | |||
| int tempResult = (tempLow << 8) | tempHigh; | |||
| return result+tempResult; | |||
| }*/ | |||
| /** | |||
| * 获取低位到高位的移位+或运算的值 | |||
| * @param indexLow | |||
| * @param indexHigh | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String getLowConactHighEndForInt(int indexLow,int indexHigh,byte[] params){ | |||
| String result = ""; | |||
| int tempResult = 0; | |||
| for(int i = indexLow;i<=indexHigh;i++){ | |||
| int temp = (params[i] < 0 ? 256 + params[i] : params[i]); | |||
| int tempmov = (indexHigh-i)+2; | |||
| tempmov = (i == indexHigh ? 0 : (int) Math.pow(2, tempmov)); | |||
| tempResult = (temp << tempmov) | tempResult; | |||
| } | |||
| return result+tempResult; | |||
| } | |||
| public static String byteToHex(byte b){ | |||
| String hex = Integer.toHexString(b & 0xFF); | |||
| if(hex.length() < 2){ | |||
| hex = "0" + hex; | |||
| } | |||
| return hex; | |||
| } | |||
| /** | |||
| * 获取开始下标到结束下标的ASIII对应的值 | |||
| * @param start | |||
| * @param end | |||
| * @param params | |||
| * @return | |||
| */ | |||
| public static String getStartToEndForASIII(int start,int end,byte[] params){ | |||
| String result = ""; | |||
| for(int i=start;i<=end;i++){ | |||
| if(i==end){ | |||
| result = result+asciiToString(params[i]+""); | |||
| }else{ | |||
| result = result+asciiToString(params[i]+"")+":"; | |||
| } | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * ASCII转字符 | |||
| * @param value | |||
| * @return | |||
| */ | |||
| public static String asciiToString(String value) | |||
| { | |||
| value = value.replaceAll(":", ""); | |||
| char c= (char) Integer.parseInt(value); | |||
| //System.out.println(value+":"+c); | |||
| return c+""; | |||
| } | |||
| public static void main(String args[]) throws UnsupportedEncodingException | |||
| { | |||
| // String str = "H4CpBA/xguYaSidJuBnCEydjVVdwDBKAfgvuaUpSEuU="; | |||
| // byte[] paramsByte = Base64TeaUitls.decrypt(str); | |||
| // | |||
| // for(byte i : paramsByte) | |||
| // System.out.print(byteToHex(i) + " "); | |||
| // System.out.println(); | |||
| //01 01 16 b7 28 32 18 4a 88 00 0e 00 00 00 00 42 4d 10 01 0a 00 13 05 07 e9 | |||
| //注册设备数据 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x01,(byte)0x01,(byte)0x08 ,(byte)0x16 ,(byte)0xb7 ,(byte)0x28 //mac地址 | |||
| // ,(byte)0x00 ,(byte)0x00 //cid | |||
| // ,(byte)0x00 ,(byte)0x01 //pid | |||
| // ,(byte)0x00 ,(byte)0x02 //vid | |||
| // ,(byte)0x42 ,(byte)0x4d //产品名称 | |||
| // ,(byte)0x01 //产品型号 | |||
| // ,(byte)0x01 //硬件版本 | |||
| // ,(byte)0x42 //软件版本 | |||
| // ,(byte)0x4d //用户版本 | |||
| // ,(byte)0x13 //年 | |||
| // ,(byte)0x0c //月 | |||
| // ,(byte)0x12 //日 | |||
| // ,(byte)0x06,(byte)0x06,(byte)0x06 ,(byte)0x06 ,(byte)0x06 ,(byte)0x06 //芯片id | |||
| // ,(byte)0x09 //设备单位 | |||
| // ,(byte)0x03 //设备IMEI长度 | |||
| // ,(byte)0x01,(byte)0x02,(byte)0x20 }; //设备IMEI | |||
| //上报称重数据(原始数据) | |||
| //5781 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x00,(byte)0x00 ,(byte)0x0f,(byte)0x71 //设备SN号 | |||
| // ,(byte)0x15 //年 | |||
| // ,(byte)0x03 //月 | |||
| // ,(byte)0x04 //日 | |||
| // ,(byte)0x0c //时 | |||
| // ,(byte)0x00 //分 | |||
| // ,(byte)0x00 //秒 | |||
| // ,(byte)0x00 //是否离线记录 | |||
| // ,(byte)0x00 //体重数据高 | |||
| // ,(byte)0x00 //体重数据中 | |||
| // ,(byte)0x3C //体重数据低 | |||
| // ,(byte)0x00 //体重单位 | |||
| // ,(byte)0x00 //体重精度 | |||
| // ,(byte)0x01 //阻抗高 | |||
| // ,(byte)0xff //阻抗低 | |||
| // ,(byte)0x5f //心率 | |||
| // ,(byte)0x01 //算法 | |||
| // ,(byte)0x00,(byte)0x00,(byte)0x03,(byte)0x97}; //用户id | |||
| //最新OTA升级地址 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x01,(byte)0x01,(byte)0x08 ,(byte)0x16 ,(byte)0xb7 ,(byte)0x28 //mac地址 | |||
| // ,(byte)0x00 ,(byte)0x00 //cid | |||
| // ,(byte)0x00 ,(byte)0x01 //pid | |||
| // ,(byte)0x00 ,(byte)0x02 //vid | |||
| // ,(byte)0x42 ,(byte)0x4d //产品名称 | |||
| // ,(byte)0x01 //产品型号 | |||
| // ,(byte)0x01 //硬件版本 | |||
| // ,(byte)0x09 //软件版本 | |||
| // ,(byte)0x06,(byte)0x06,(byte)0x06 ,(byte)0x06 ,(byte)0x06 ,(byte)0x06 //芯片id | |||
| // ,(byte)0x00,(byte)0x00 ,(byte)0x07,(byte)0xBF //设备id | |||
| // ,(byte)0x00 //客户定制版本 | |||
| // ,(byte)0x00 ,(byte)0x00,(byte)0x00,(byte)0x00 //保留位 | |||
| // }; | |||
| // //通过cid获取设备访问地址 | |||
| byte[] old =new byte[]{ | |||
| (byte)0x00 ,(byte)0x00,(byte)0x00, //模块名称 | |||
| (byte)0x01,(byte)0x01,(byte)0x08 ,(byte)0x16 ,(byte)0xb7 ,(byte)0x28, //mac地址 | |||
| (byte)0x01,(byte)0x01,(byte)0x08 ,(byte)0x16 ,(byte)0xb7 ,(byte)0x28, //芯片id | |||
| (byte)0x00 ,(byte)0x11, //cid | |||
| (byte)0x00 ,(byte)0x01, //pid | |||
| (byte)0x00 ,(byte)0x1B, //vid | |||
| (byte)0x00,(byte)0x00 ,(byte)0x00 //保留位 | |||
| }; | |||
| //通过cid,pid,vid获取设备访问地址 | |||
| //57 4d 05 88 4a 18 32 28 a4 02 38 6f a5 dc 12 00 11 00 00 00 00 00 00 00 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x57 ,(byte)0x4d,(byte)0x05, //模块名称 | |||
| // (byte)0x88,(byte)0x4a,(byte)0x08 ,(byte)0x32 ,(byte)0x28 ,(byte)0xa4, //mac地址 | |||
| // (byte)0x02,(byte)0x38,(byte)0x6f ,(byte)0xa5 ,(byte)0xdc ,(byte)0x12, //芯片id | |||
| // (byte)0x00 ,(byte)0x0e, //cid | |||
| // (byte)0x00 ,(byte)0x01, //pid | |||
| // (byte)0x00 ,(byte)0x32, //vid | |||
| // (byte)0x00,(byte)0x00 ,(byte)0x00 //保留位 | |||
| // }; | |||
| //刷牙数据上传 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x00,(byte)0x00 ,(byte)0x07,(byte)0xBF, //设备SN号 | |||
| // (byte)0x01, //牙刷工作模式 | |||
| // (byte)0x00, // 刷牙时长高字节 | |||
| // (byte)0x03, // 刷牙时长低字节 | |||
| // (byte)0x00, //左边刷牙时长高字节 | |||
| // (byte)0x02, //左边刷牙时长低字节 | |||
| // (byte)0x00, //右边刷牙时长低字节 | |||
| // (byte)0x01, //右边刷牙时长低字节 | |||
| // (byte)0x09, //剩余电量 | |||
| // (byte)0x00,(byte)0x04, //默认刷牙时长 | |||
| // (byte)0x00,(byte)0x00,//保留位 | |||
| // (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,//保留位 | |||
| // (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00 //保留位 | |||
| // }; | |||
| //血糖数据 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x00,(byte)0x00 ,(byte)0x07,(byte)0xBF, //设备SN号 | |||
| // (byte)0x00, //血糖数据高字节 | |||
| // (byte)0x00, //血糖数据中字节 | |||
| // (byte)0x12, //血糖数据低字节 | |||
| // (byte)0x01, //血糖单位 | |||
| // (byte)0x01, //小数点 | |||
| // (byte)0x00, //状态码 | |||
| // (byte)0x10, //剩余电量 | |||
| // (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,//保留位 | |||
| // (byte)0x00 //保留位 | |||
| // }; | |||
| /*int a= 1846; | |||
| System.out.println("原始数字:"+a); | |||
| byte[] old = BytesUtils.getBytes(a);*/ | |||
| //通过设备id,获取设备单位 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x00,(byte)0x00 ,(byte)0x0F,(byte)0x72, //设备id | |||
| // (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,//保留位 | |||
| // }; | |||
| //通过设备id,修改设备单位 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x00,(byte)0x00 ,(byte)0x0B,(byte)0x31, //设备id | |||
| // (byte)0x01 //设备单位 | |||
| // }; | |||
| //注册设备数据 | |||
| // byte[] old =new byte[]{ | |||
| // (byte)0x00, (byte)0x00 , (byte)0x00 , (byte)0x00 , (byte)0x00, (byte)0x00 //设备MAC | |||
| // , (byte)0x00, (byte)0x2c//CID | |||
| // , (byte)0x00 , (byte)0x00//PID | |||
| // , (byte)0x00 , (byte)0x00//VID | |||
| // , (byte)0x4c//模块名称 | |||
| // , (byte)0x4d | |||
| // , (byte)0x09 | |||
| // , (byte)0x00 | |||
| // , (byte)0x0a | |||
| // , (byte)0x00 , (byte)0x15 , (byte)0x04 , (byte)0x07 , (byte)0x00 , (byte)0x00 | |||
| // , (byte)0x00 , (byte)0x00 , (byte)0x00 , (byte)0x00 , (byte)0x00 | |||
| // , (byte)0x0f //设备IMEI长度 | |||
| // , (byte)0x08 , (byte)0x06 , (byte)0x09 , (byte)0x03 , (byte)0x02 , (byte)0x04 , (byte)0x00 , (byte)0x05 //设备IMEI 86932405 | |||
| // , (byte)0x00 , (byte)0x00 , (byte)0x00 , (byte)0x02 , (byte)0x07 , (byte)0x06 , (byte)0x09 //设备IMEI 0002769 | |||
| // , (byte)0x00, (byte)0x00 , (byte)0x00 , (byte)0x00 }; //备用字段 | |||
| //原始数据 | |||
| System.out.println( "原始数据:"); | |||
| for(byte i : old) | |||
| System.out.print(byteToHex(i) + " "); | |||
| System.out.println(); | |||
| //tea加密 | |||
| byte[] teaDscrypt =TeaUtils.encrypt(old,null); | |||
| System.out.println( "tea加密:"); | |||
| for(byte i : teaDscrypt) | |||
| System.out.print(byteToHex(i) + " "); | |||
| System.out.println(); | |||
| //base编码 | |||
| String base64Text = Base64Util.encoderString(teaDscrypt); | |||
| base64Text = "rvXiSvrWrR+/p1ZhAPlXr7x1gxbvrurA"; | |||
| System.out.println("base64编码后的数据长度:"+Base64Util.getLength(base64Text)+":"+base64Text); | |||
| //base解码 | |||
| String base64TextEn= Base64Util.decoderString(base64Text); | |||
| //String base64TextEn= Base64Util.decoderString("BCc0vnfr9kd5"); | |||
| // System.out.println("base64解码后的数据长度:"+Base64Util.getLength(base64TextEn)+":"+base64TextEn); | |||
| /*//转称byte数组(每两位一个16进制byte) | |||
| List<String> base64TeaByteOldList = new ArrayList<String>(); | |||
| for(int i=0;i<base64TextEn.length();i++){ | |||
| if(i%2 == 0){ | |||
| base64TeaByteOldList.add("0x"+base64TextEn.charAt(i)+base64TextEn.charAt(i+1)); | |||
| } | |||
| } | |||
| //解码后转换得到的list | |||
| System.out.println("解码后转换得到的list:"); | |||
| for(String byte16:base64TeaByteOldList){ | |||
| System.out.print(byte16+" "); | |||
| } | |||
| System.out.println();*/ | |||
| //解码数据转换为byte数组 | |||
| byte[] base64TeaByteOld = Base64Util.hexStrToByteArray(base64TextEn); | |||
| System.out.println( "解码后得到的tea加密的byte数组:"); | |||
| for(byte i : base64TeaByteOld) | |||
| System.out.print(byteToHex(i) + " "); | |||
| System.out.println(); | |||
| byte[] base64TeaByte =TeaUtils.decrypt(base64TeaByteOld,null); | |||
| System.out.println( "tea解密:"); | |||
| for(byte i : base64TeaByte) | |||
| System.out.print(byteToHex(i) + " "); | |||
| System.out.println(); | |||
| //int imeiLength = base64TeaByte[28] & 0xFF; | |||
| int imeiLength = Integer.parseInt(Base64TeaUitls.getStartToEndForInt(28, 28, base64TeaByte)); | |||
| System.out.println("imeiLength:"+imeiLength); | |||
| System.out.println("IMEI:"+ Base64TeaUitls.getStartToEndForHex(28+1, 28+imeiLength, base64TeaByte)); | |||
| System.out.println("IMEI:"+ Base64TeaUitls.getStartToEndForInt(28+1, 28+imeiLength, base64TeaByte)); | |||
| System.out.println("IMEI:"+ Base64TeaUitls.getStartToEndForASIII(28+1, 28+imeiLength, base64TeaByte)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,167 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.Base64; | |||
| //import com.google.common.primitives.Bytes; | |||
| public class Base64Util | |||
| { | |||
| final static Base64.Decoder decoder = Base64.getDecoder(); | |||
| final static Base64.Encoder encoder = Base64.getEncoder(); | |||
| public Base64Util(){} | |||
| /** | |||
| * 解码 | |||
| * @param encoderStr | |||
| * @return | |||
| * @throws UnsupportedEncodingException | |||
| */ | |||
| public static String decoderString(String base64Text) throws UnsupportedEncodingException{ | |||
| String result = ""; | |||
| if(base64Text != null && !base64Text.isEmpty() && !base64Text.equals("")){ | |||
| byte[] textByte = decoder.decode(base64Text); | |||
| result = bytes_String16(textByte); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * byte[]转16进制字符串 | |||
| * @param b | |||
| * @return | |||
| */ | |||
| public static String bytes_String16(byte[] b) { | |||
| StringBuilder sb = new StringBuilder(); | |||
| for(int i=0;i<b.length;i++) { | |||
| sb.append(String.format("%02x", b[i])); | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| /** | |||
| * 编码 | |||
| * @param encoderStr | |||
| * @return | |||
| * @throws UnsupportedEncodingException | |||
| */ | |||
| public static String encoderString(String base64Text) throws UnsupportedEncodingException{ | |||
| String result = ""; | |||
| if(base64Text != null && !base64Text.isEmpty() && !base64Text.equals("")){ | |||
| byte[] textByte = base64Text.getBytes("UTF-8"); | |||
| result = encoder.encodeToString(textByte); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 编码 | |||
| * @param encoderStr | |||
| * @return | |||
| * @throws UnsupportedEncodingException | |||
| */ | |||
| public static String encoderString(byte[] textByte) throws UnsupportedEncodingException{ | |||
| return encoder.encodeToString(textByte); | |||
| } | |||
| public static int getLength(String s) { | |||
| int length = 0; | |||
| for (int i = 0; i < s.length(); i++) { | |||
| int ascii = Character.codePointAt(s, i); | |||
| if (ascii >= 0 && ascii <= 255) { | |||
| length++; | |||
| } else { | |||
| length += 2; | |||
| } | |||
| } | |||
| return length; | |||
| } | |||
| private static String intToHex(int n) { | |||
| StringBuffer s = new StringBuffer(); | |||
| String a; | |||
| char []b = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; | |||
| while(n != 0){ | |||
| s = s.append(b[n%16]); | |||
| n = n/16; | |||
| } | |||
| a = s.reverse().toString(); | |||
| return a; | |||
| } | |||
| public static byte[] hexStrToByteArray(String str) | |||
| { | |||
| if (str == null) { | |||
| return null; | |||
| } | |||
| if (str.length() == 0) { | |||
| return new byte[0]; | |||
| } | |||
| byte[] byteArray = new byte[str.length() / 2]; | |||
| for (int i = 0; i < byteArray.length; i++){ | |||
| String subStr = str.substring(2 * i, 2 * i + 2); | |||
| byteArray[i] = ((byte)Integer.parseInt(subStr, 16)); | |||
| } | |||
| return byteArray; | |||
| } | |||
| public static void main(String args[]) throws UnsupportedEncodingException | |||
| { | |||
| //01 01 16 b7 28 32 18 4a 88 00 0e 00 00 00 00 42 4d 10 01 0a 00 13 05 07 e9 | |||
| byte[] old =new byte[]{(byte)0x01 | |||
| ,(byte)0x01 ,(byte)0x16 ,(byte)0xb7 ,(byte)0x28 | |||
| ,(byte)0x32 ,(byte)0x18 ,(byte)0x4a ,(byte)0x88 | |||
| ,(byte)0x00 ,(byte)0x0e ,(byte)0x00 ,(byte)0x00 | |||
| ,(byte)0x00 ,(byte)0x00 ,(byte)0x42 ,(byte)0x4d | |||
| ,(byte)0x10 ,(byte)0x01 ,(byte)0x0a ,(byte)0x00 | |||
| ,(byte)0x13 ,(byte)0x05 ,(byte)0x07 ,(byte)0xe9}; | |||
| //原始数据 | |||
| System.out.println( "原始数据:"); | |||
| for(byte i : old) | |||
| System.out.print(i + " "); | |||
| System.out.println(); | |||
| //tea加密 | |||
| byte[] teaDscrypt =TeaUtils.encrypt(old,null); | |||
| System.out.println( "tea加密:"); | |||
| for(byte i : teaDscrypt) | |||
| System.out.print(i + " "); | |||
| System.out.println(); | |||
| //base编码 | |||
| String base64Text = encoderString(teaDscrypt); | |||
| System.out.println("base64编码后的数据长度:"+getLength(base64Text)+":"+base64Text); | |||
| //base解码 | |||
| String base64TextEn= decoderString(base64Text); | |||
| System.out.println("base64解码后的数据长度:"+getLength(base64TextEn)+":"+base64TextEn); | |||
| /*//转称byte数组(每两位一个16进制byte) | |||
| List<String> base64TeaByteOldList = new ArrayList<String>(); | |||
| for(int i=0;i<base64TextEn.length();i++){ | |||
| if(i%2 == 0){ | |||
| base64TeaByteOldList.add("0x"+base64TextEn.charAt(i)+base64TextEn.charAt(i+1)); | |||
| } | |||
| } | |||
| //解码后转换得到的list | |||
| System.out.println("解码后转换得到的list:"); | |||
| for(String byte16:base64TeaByteOldList){ | |||
| System.out.print(byte16+" "); | |||
| } | |||
| System.out.println();*/ | |||
| //解码数据转换为byte数组 | |||
| byte[] base64TeaByteOld = hexStrToByteArray(base64TextEn); | |||
| System.out.println( "解码后得到的tea加密的byte数组:"); | |||
| for(byte i : base64TeaByteOld) | |||
| System.out.print(i + " "); | |||
| System.out.println(); | |||
| byte[] base64TeaByte =TeaUtils.decrypt(base64TeaByteOld,null); | |||
| System.out.println( "tea解密:"); | |||
| for(byte i : base64TeaByte) | |||
| System.out.print(i + " "); | |||
| System.out.println(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,895 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import org.apache.commons.lang.ArrayUtils; | |||
| import java.nio.charset.Charset; | |||
| /** | |||
| * | |||
| * @Description: 字节数组转换工具类 | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public class BytesUtils { | |||
| public static final String GBK = "GBK"; | |||
| public static final String UTF8 = "utf-8"; | |||
| public static final char[] ascii = "0123456789ABCDEF".toCharArray(); | |||
| private static char[] HEX_VOCABLE = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; | |||
| /** | |||
| * 将short整型数值转换为字节数组 | |||
| * | |||
| * @param data | |||
| * @return | |||
| */ | |||
| public static byte[] getBytes(short data) { | |||
| byte[] bytes = new byte[2]; | |||
| bytes[0] = (byte) ((data & 0xff00) >> 8); | |||
| bytes[1] = (byte) (data & 0xff); | |||
| return bytes; | |||
| } | |||
| /** | |||
| * 将字符转换为字节数组 | |||
| * | |||
| * @param data | |||
| * @return | |||
| */ | |||
| public static byte[] getBytes(char data) { | |||
| byte[] bytes = new byte[2]; | |||
| bytes[0] = (byte) (data >> 8); | |||
| bytes[1] = (byte) (data); | |||
| return bytes; | |||
| } | |||
| /** | |||
| * 将布尔值转换为字节数组 | |||
| * | |||
| * @param data | |||
| * @return | |||
| */ | |||
| public static byte[] getBytes(boolean data) { | |||
| byte[] bytes = new byte[1]; | |||
| bytes[0] = (byte) (data ? 1 : 0); | |||
| return bytes; | |||
| } | |||
| /** | |||
| * 将整型数值转换为字节数组 | |||
| * | |||
| * @param data | |||
| * @return | |||
| */ | |||
| public static byte[] getBytes(int data) { | |||
| byte[] bytes = new byte[4]; | |||
| bytes[0] = (byte) ((data & 0xff000000) >> 24); | |||
| bytes[1] = (byte) ((data & 0xff0000) >> 16); | |||
| bytes[2] = (byte) ((data & 0xff00) >> 8); | |||
| bytes[3] = (byte) (data & 0xff); | |||
| return bytes; | |||
| } | |||
| /** | |||
| * 将long整型数值转换为字节数组 | |||
| * | |||
| * @param data | |||
| * @return | |||
| */ | |||
| public static byte[] getBytes(long data) { | |||
| byte[] bytes = new byte[8]; | |||
| bytes[0] = (byte) ((data >> 56) & 0xff); | |||
| bytes[1] = (byte) ((data >> 48) & 0xff); | |||
| bytes[2] = (byte) ((data >> 40) & 0xff); | |||
| bytes[3] = (byte) ((data >> 32) & 0xff); | |||
| bytes[4] = (byte) ((data >> 24) & 0xff); | |||
| bytes[5] = (byte) ((data >> 16) & 0xff); | |||
| bytes[6] = (byte) ((data >> 8) & 0xff); | |||
| bytes[7] = (byte) (data & 0xff); | |||
| return bytes; | |||
| } | |||
| /** | |||
| * 将float型数值转换为字节数组 | |||
| * | |||
| * @param data | |||
| * @return | |||
| */ | |||
| public static byte[] getBytes(float data) { | |||
| int intBits = Float.floatToIntBits(data); | |||
| return getBytes(intBits); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getBytes | |||
| * @Description: 将double型数值转换为字节数组 | |||
| * @return byte[] | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static byte[] getBytes(double data) { | |||
| long intBits = Double.doubleToLongBits(data); | |||
| return getBytes(intBits); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getBytes | |||
| * @Description: 将字符串按照charsetName编码格式的字节数组 | |||
| * @return byte[] | |||
| * @param data 字符串 | |||
| * @param charsetName | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static byte[] getBytes(String data, String charsetName) { | |||
| Charset charset = Charset.forName(charsetName); | |||
| return data.getBytes(charset); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getBytes | |||
| * @Description: 将字符串按照GBK编码格式的字节数组 | |||
| * @return byte[] | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static byte[] getBytes(String data) { | |||
| return getBytes(data, GBK); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getBoolean | |||
| * @Description: 将字节数组第0字节转换为布尔值 | |||
| * @return boolean | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static boolean getBoolean(byte[] bytes) { | |||
| return bytes[0] == 1; | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getBoolean | |||
| * @Description: 将字节数组的第index字节转换为布尔值 | |||
| * @return boolean | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static boolean getBoolean(byte[] bytes, int index) { | |||
| return bytes[index] == 1; | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getShort | |||
| * @Description: 将字节数组前2字节转换为short整型数值 | |||
| * @return short | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static short getShort(byte[] bytes) { | |||
| return (short) ((0xff00 & (bytes[0] << 8)) | (0xff & bytes[1])); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getShort | |||
| * @Description: 将字节数组从startIndex开始的2个字节转换为short整型数值 | |||
| * @return short | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static short getShort(byte[] bytes, int startIndex) { | |||
| return (short) ((0xff00 & (bytes[startIndex] << 8)) | (0xff & bytes[startIndex + 1])); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getChar | |||
| * @Description: 将字节数组前2字节转换为字符 | |||
| * @return char | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static char getChar(byte[] bytes) { | |||
| return (char) ((0xff00 & (bytes[0] << 8)) | (0xff & bytes[1])); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getChar | |||
| * @Description: 将字节数组从startIndex开始的2个字节转换为字符 | |||
| * @return char | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static char getChar(byte[] bytes, int startIndex) { | |||
| return (char) ((0xff00 & (bytes[startIndex] << 8)) | (0xff & bytes[startIndex + 1])); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getInt | |||
| * @Description: 将字节数组前4字节转换为整型数值 | |||
| * @return int | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static int getInt(byte[] bytes) { | |||
| return (0xff000000 & (bytes[0] << 24) | (0xff0000 & (bytes[1] << 16)) | (0xff00 & (bytes[2] << 8)) | |||
| | (0xff & bytes[3])); | |||
| } | |||
| /** | |||
| * | |||
| * @Title: getInt | |||
| * @Description: 将字节数组从startIndex开始的4个字节转换为整型数值 | |||
| * @return int | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static int getInt(byte[] bytes, int startIndex) { | |||
| return (0xff000000 & (bytes[startIndex] << 24) | (0xff0000 & (bytes[startIndex + 1] << 16)) | |||
| | (0xff00 & (bytes[startIndex + 2] << 8)) | (0xff & bytes[startIndex + 3])); | |||
| } | |||
| /** | |||
| * 将字节数组前8字节转换为long整型数值 | |||
| * | |||
| * @param bytes | |||
| * @return | |||
| */ | |||
| public static long getLong(byte[] bytes) { | |||
| return (0xff00000000000000L & ((long) bytes[0] << 56) | (0xff000000000000L & ((long) bytes[1] << 48)) | |||
| | (0xff0000000000L & ((long) bytes[2] << 40)) | (0xff00000000L & ((long) bytes[3] << 32)) | |||
| | (0xff000000L & ((long) bytes[4] << 24)) | (0xff0000L & ((long) bytes[5] << 16)) | |||
| | (0xff00L & ((long) bytes[6] << 8)) | (0xffL & (long) bytes[7])); | |||
| } | |||
| /** | |||
| * 将字节数组从startIndex开始的8个字节转换为long整型数值 | |||
| * | |||
| * @param bytes | |||
| * @param startIndex | |||
| * @return | |||
| */ | |||
| public static long getLong(byte[] bytes, int startIndex) { | |||
| return (0xff00000000000000L & ((long) bytes[startIndex] << 56) | |||
| | (0xff000000000000L & ((long) bytes[startIndex + 1] << 48)) | |||
| | (0xff0000000000L & ((long) bytes[startIndex + 2] << 40)) | |||
| | (0xff00000000L & ((long) bytes[startIndex + 3] << 32)) | |||
| | (0xff000000L & ((long) bytes[startIndex + 4] << 24)) | |||
| | (0xff0000L & ((long) bytes[startIndex + 5] << 16)) | (0xff00L & ((long) bytes[startIndex + 6] << 8)) | |||
| | (0xffL & (long) bytes[startIndex + 7])); | |||
| } | |||
| /** | |||
| * 将字节数组前4字节转换为float型数值 | |||
| * | |||
| * @param bytes | |||
| * @return | |||
| */ | |||
| public static float getFloat(byte[] bytes) { | |||
| return Float.intBitsToFloat(getInt(bytes)); | |||
| } | |||
| /** | |||
| * 将字节数组从startIndex开始的4个字节转换为float型数值 | |||
| * | |||
| * @param bytes | |||
| * @param startIndex | |||
| * @return | |||
| */ | |||
| public static float getFloat(byte[] bytes, int startIndex) { | |||
| byte[] result = new byte[4]; | |||
| System.arraycopy(bytes, startIndex, result, 0, 4); | |||
| return Float.intBitsToFloat(getInt(result)); | |||
| } | |||
| /** | |||
| * 将字节数组前8字节转换为double型数值 | |||
| * | |||
| * @param bytes | |||
| * @return | |||
| */ | |||
| public static double getDouble(byte[] bytes) { | |||
| long l = getLong(bytes); | |||
| return Double.longBitsToDouble(l); | |||
| } | |||
| /** | |||
| * 将字节数组从startIndex开始的8个字节转换为double型数值 | |||
| * | |||
| * @param bytes | |||
| * @param startIndex | |||
| * @return | |||
| */ | |||
| public static double getDouble(byte[] bytes, int startIndex) { | |||
| byte[] result = new byte[8]; | |||
| System.arraycopy(bytes, startIndex, result, 0, 8); | |||
| long l = getLong(result); | |||
| return Double.longBitsToDouble(l); | |||
| } | |||
| /** | |||
| * 将charsetName编码格式的字节数组转换为字符串 | |||
| * | |||
| * @param bytes | |||
| * @param charsetName | |||
| * @return | |||
| */ | |||
| public static String getString(byte[] bytes, String charsetName) { | |||
| return new String(bytes, Charset.forName(charsetName)); | |||
| } | |||
| /** | |||
| * 将GBK编码格式的字节数组转换为字符串 | |||
| * | |||
| * @param bytes | |||
| * @return | |||
| */ | |||
| public static String getString(byte[] bytes) { | |||
| return getString(bytes, GBK); | |||
| } | |||
| /** | |||
| * 将16进制字符串转换为字节数组 | |||
| * | |||
| * @param hex | |||
| * @return | |||
| */ | |||
| public static byte[] hexStringToBytes(String hex) { | |||
| if (hex == null || "".equals(hex)) { | |||
| return null; | |||
| } | |||
| int len = hex.length() / 2; | |||
| byte[] result = new byte[len]; | |||
| char[] chArr = hex.toCharArray(); | |||
| for (int i = 0; i < len; i++) { | |||
| int pos = i * 2; | |||
| result[i] = (byte) (toByte(chArr[pos]) << 4 | toByte(chArr[pos + 1])); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 将16进制字符串转换为字节数组 | |||
| * | |||
| * @param hex | |||
| * @return | |||
| */ | |||
| public static byte[] hexToBytes(String hex) { | |||
| if (hex.length() % 2 != 0) | |||
| throw new IllegalArgumentException("input string should be any multiple of 2!"); | |||
| hex.toUpperCase(); | |||
| byte[] byteBuffer = new byte[hex.length() / 2]; | |||
| byte padding = 0x00; | |||
| boolean paddingTurning = false; | |||
| for (int i = 0; i < hex.length(); i++) { | |||
| if (paddingTurning) { | |||
| char c = hex.charAt(i); | |||
| int index = indexOf(hex, c); | |||
| padding = (byte) ((padding << 4) | index); | |||
| byteBuffer[i / 2] = padding; | |||
| padding = 0x00; | |||
| paddingTurning = false; | |||
| } else { | |||
| char c = hex.charAt(i); | |||
| int index = indexOf(hex, c); | |||
| padding = (byte) (padding | index); | |||
| paddingTurning = true; | |||
| } | |||
| } | |||
| return byteBuffer; | |||
| } | |||
| private static int indexOf(String input, char c) { | |||
| int index = ArrayUtils.indexOf(HEX_VOCABLE, c); | |||
| if (index < 0) { | |||
| throw new IllegalArgumentException("err input:" + input); | |||
| } | |||
| return index; | |||
| } | |||
| /** | |||
| * 将BCD编码的字节数组转换为字符串 | |||
| * | |||
| * @param bcds | |||
| * @return | |||
| */ | |||
| public static String bcdToString(byte[] bcds) { | |||
| if (bcds == null || bcds.length == 0) { | |||
| return null; | |||
| } | |||
| byte[] temp = new byte[2 * bcds.length]; | |||
| for (int i = 0; i < bcds.length; i++) { | |||
| temp[i * 2] = (byte) ((bcds[i] >> 4) & 0x0f); | |||
| temp[i * 2 + 1] = (byte) (bcds[i] & 0x0f); | |||
| } | |||
| StringBuffer res = new StringBuffer(); | |||
| for (int i = 0; i < temp.length; i++) { | |||
| res.append(ascii[temp[i]]); | |||
| } | |||
| return res.toString(); | |||
| } | |||
| /** | |||
| * 字节转整形 | |||
| * | |||
| * @param value | |||
| * @return | |||
| */ | |||
| public static int bcdToInt(byte value) { | |||
| return ((value >> 4) * 10) + (value & 0x0F); | |||
| } | |||
| /** | |||
| * 字节数组转16进制字符串 | |||
| * | |||
| * @param bs | |||
| * @return | |||
| */ | |||
| public static String bytesToHex(byte[] bs) { | |||
| StringBuilder sb = new StringBuilder(); | |||
| for (byte b : bs) { | |||
| int high = (b >> 4) & 0x0f; | |||
| int low = b & 0x0f; | |||
| sb.append(HEX_VOCABLE[high]); | |||
| sb.append(HEX_VOCABLE[low]); | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| /** | |||
| * 字节数组取前len个字节转16进制字符串 | |||
| * | |||
| * @param bs | |||
| * @param len | |||
| * @return | |||
| */ | |||
| public static String bytesToHex(byte[] bs, int len) { | |||
| StringBuilder sb = new StringBuilder(); | |||
| for (int i = 0; i < len; i++) { | |||
| byte b = bs[i]; | |||
| int high = (b >> 4) & 0x0f; | |||
| int low = b & 0x0f; | |||
| sb.append(HEX_VOCABLE[high]); | |||
| sb.append(HEX_VOCABLE[low]); | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| /** | |||
| * 字节数组偏移offset长度之后的取len个字节转16进制字符串 | |||
| * | |||
| * @param bs | |||
| * @param offset | |||
| * @param len | |||
| * @return | |||
| */ | |||
| public static String bytesToHex(byte[] bs, int offset, int len) { | |||
| StringBuilder sb = new StringBuilder(); | |||
| for (int i = 0; i < len; i++) { | |||
| byte b = bs[offset + i]; | |||
| int high = (b >> 4) & 0x0f; | |||
| int low = b & 0x0f; | |||
| sb.append(HEX_VOCABLE[high]); | |||
| sb.append(HEX_VOCABLE[low]); | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| /** | |||
| * 字节转16进制字符串 | |||
| * | |||
| * @param bs | |||
| * @return | |||
| */ | |||
| public static String byteToHex(byte b) { | |||
| StringBuilder sb = new StringBuilder(); | |||
| int high = (b >> 4) & 0x0f; | |||
| int low = b & 0x0f; | |||
| sb.append(HEX_VOCABLE[high]); | |||
| sb.append(HEX_VOCABLE[low]); | |||
| String s = sb.toString(); | |||
| if ("".equals(s.substring(0, 1))) { | |||
| return s.substring(1); | |||
| } else { | |||
| return s; | |||
| } | |||
| } | |||
| /** | |||
| * 将字节数组取反 | |||
| * | |||
| * @param src | |||
| * @return | |||
| */ | |||
| public static String negate(byte[] src) { | |||
| if (src == null || src.length == 0) { | |||
| return null; | |||
| } | |||
| byte[] temp = new byte[2 * src.length]; | |||
| for (int i = 0; i < src.length; i++) { | |||
| byte tmp = (byte) (0xFF ^ src[i]); | |||
| temp[i * 2] = (byte) ((tmp >> 4) & 0x0f); | |||
| temp[i * 2 + 1] = (byte) (tmp & 0x0f); | |||
| } | |||
| StringBuffer res = new StringBuffer(); | |||
| for (int i = 0; i < temp.length; i++) { | |||
| res.append(ascii[temp[i]]); | |||
| } | |||
| return res.toString(); | |||
| } | |||
| /** | |||
| * 比较字节数组是否相同 | |||
| * | |||
| * @param a | |||
| * @param b | |||
| * @return | |||
| */ | |||
| public static boolean compareBytes(byte[] a, byte[] b) { | |||
| if (a == null || a.length == 0 || b == null || b.length == 0 || a.length != b.length) { | |||
| return false; | |||
| } | |||
| if (a.length == b.length) { | |||
| for (int i = 0; i < a.length; i++) { | |||
| if (a[i] != b[i]) { | |||
| return false; | |||
| } | |||
| } | |||
| } else { | |||
| return false; | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 只比对指定长度byte | |||
| * | |||
| * @param a | |||
| * @param b | |||
| * @param len | |||
| * @return | |||
| */ | |||
| public static boolean compareBytes(byte[] a, byte[] b, int len) { | |||
| if (a == null || a.length == 0 || b == null || b.length == 0 || a.length < len || b.length < len) { | |||
| return false; | |||
| } | |||
| for (int i = 0; i < len; i++) { | |||
| if (a[i] != b[i]) { | |||
| return false; | |||
| } | |||
| } | |||
| return true; | |||
| } | |||
| /** | |||
| * 将字节数组转换为二进制字符串 | |||
| * | |||
| * @param items | |||
| * @return | |||
| */ | |||
| public static String bytesToBinaryString(byte[] items) { | |||
| if (items == null || items.length == 0) { | |||
| return null; | |||
| } | |||
| StringBuffer buf = new StringBuffer(); | |||
| for (byte item : items) { | |||
| buf.append(byteToBinaryString(item)); | |||
| } | |||
| return buf.toString(); | |||
| } | |||
| /** | |||
| * 将字节转换为二进制字符串 | |||
| * | |||
| * @param items | |||
| * @return | |||
| */ | |||
| public static String byteToBinaryString(byte item) { | |||
| byte a = item; | |||
| StringBuffer buf = new StringBuffer(); | |||
| for (int i = 0; i < 8; i++) { | |||
| buf.insert(0, a % 2); | |||
| a = (byte) (a >> 1); | |||
| } | |||
| return buf.toString(); | |||
| } | |||
| /** | |||
| * 对数组a,b进行异或运算 | |||
| * | |||
| * @param a | |||
| * @param b | |||
| * @return | |||
| */ | |||
| public static byte[] xor(byte[] a, byte[] b) { | |||
| if (a == null || a.length == 0 || b == null || b.length == 0 || a.length != b.length) { | |||
| return null; | |||
| } | |||
| byte[] result = new byte[a.length]; | |||
| for (int i = 0; i < a.length; i++) { | |||
| result[i] = (byte) (a[i] ^ b[i]); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 对数组a,b进行异或运算 运算长度len | |||
| * | |||
| * @param a | |||
| * @param b | |||
| * @param len | |||
| * @return | |||
| */ | |||
| public static byte[] xor(byte[] a, byte[] b, int len) { | |||
| if (a == null || a.length == 0 || b == null || b.length == 0) { | |||
| return null; | |||
| } | |||
| if (a.length < len || b.length < len) { | |||
| return null; | |||
| } | |||
| byte[] result = new byte[len]; | |||
| for (int i = 0; i < len; i++) { | |||
| result[i] = (byte) (a[i] ^ b[i]); | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 将short整型数值转换为字节数组 | |||
| * | |||
| * @param num | |||
| * @return | |||
| */ | |||
| public static byte[] shortToBytes(int num) { | |||
| byte[] temp = new byte[2]; | |||
| for (int i = 0; i < 2; i++) { | |||
| temp[i] = (byte) ((num >>> (8 - i * 8)) & 0xFF); | |||
| } | |||
| return temp; | |||
| } | |||
| /** | |||
| * 将字节数组转为整型 | |||
| * | |||
| * @param num | |||
| * @return | |||
| */ | |||
| public static int bytesToShort(byte[] arr) { | |||
| int mask = 0xFF; | |||
| int temp = 0; | |||
| int result = 0; | |||
| for (int i = 0; i < 2; i++) { | |||
| result <<= 8; | |||
| temp = arr[i] & mask; | |||
| result |= temp; | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 将整型数值转换为指定长度的字节数组 | |||
| * | |||
| * @param num | |||
| * @return | |||
| */ | |||
| public static byte[] intToBytes(int num) { | |||
| byte[] temp = new byte[4]; | |||
| for (int i = 0; i < 4; i++) { | |||
| temp[i] = (byte) ((num >>> (24 - i * 8)) & 0xFF); | |||
| } | |||
| return temp; | |||
| } | |||
| /** | |||
| * 将整型数值转换为指定长度的字节数组 | |||
| * | |||
| * @param src | |||
| * @param len | |||
| * @return | |||
| */ | |||
| public static byte[] intToBytes(int src, int len) { | |||
| if (len < 1 || len > 4) { | |||
| return null; | |||
| } | |||
| byte[] temp = new byte[len]; | |||
| for (int i = 0; i < len; i++) { | |||
| temp[len - 1 - i] = (byte) ((src >>> (8 * i)) & 0xFF); | |||
| } | |||
| return temp; | |||
| } | |||
| /** | |||
| * 将字节数组转换为整型数值 | |||
| * | |||
| * @param arr | |||
| * @return | |||
| */ | |||
| public static int bytesToInt(byte[] arr) { | |||
| int mask = 0xFF; | |||
| int temp = 0; | |||
| int result = 0; | |||
| for (int i = 0; i < 4; i++) { | |||
| result <<= 8; | |||
| temp = arr[i] & mask; | |||
| result |= temp; | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 将long整型数值转换为字节数组 | |||
| * | |||
| * @param num | |||
| * @return | |||
| */ | |||
| public static byte[] longToBytes(long num) { | |||
| byte[] temp = new byte[8]; | |||
| for (int i = 0; i < 8; i++) { | |||
| temp[i] = (byte) ((num >>> (56 - i * 8)) & 0xFF); | |||
| } | |||
| return temp; | |||
| } | |||
| /** | |||
| * 将字节数组转换为long整型数值 | |||
| * | |||
| * @param arr | |||
| * @return | |||
| */ | |||
| public static long bytesToLong(byte[] arr) { | |||
| int mask = 0xFF; | |||
| int temp = 0; | |||
| long result = 0; | |||
| int len = Math.min(8, arr.length); | |||
| for (int i = 0; i < len; i++) { | |||
| result <<= 8; | |||
| temp = arr[i] & mask; | |||
| result |= temp; | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * 将16进制字符转换为字节 | |||
| * | |||
| * @param c | |||
| * @return | |||
| */ | |||
| public static byte toByte(char c) { | |||
| byte b = (byte) "0123456789ABCDEF".indexOf(c); | |||
| return b; | |||
| } | |||
| /** | |||
| * 功能描述:把两个字节的字节数组转化为整型数据,高位补零,例如:<br/> | |||
| * 有字节数组byte[] data = new byte[]{1,2};转换后int数据的字节分布如下:<br/> | |||
| * 00000000 00000000 00000001 00000010,函数返回258 | |||
| * | |||
| * @param lenData | |||
| * 需要进行转换的字节数组 | |||
| * @return 字节数组所表示整型值的大小 | |||
| */ | |||
| public static int bytesToIntWhereByteLengthEquals2(byte lenData[]) { | |||
| if (lenData.length != 2) { | |||
| return -1; | |||
| } | |||
| byte fill[] = new byte[] { 0, 0 }; | |||
| byte real[] = new byte[4]; | |||
| System.arraycopy(fill, 0, real, 0, 2); | |||
| System.arraycopy(lenData, 0, real, 2, 2); | |||
| int len = byteToInt(real); | |||
| return len; | |||
| } | |||
| /** | |||
| * 功能描述:将byte数组转化为int类型的数据 | |||
| * | |||
| * @param byteVal | |||
| * 需要转化的字节数组 | |||
| * @return 字节数组所表示的整型数据 | |||
| */ | |||
| public static int byteToInt(byte[] byteVal) { | |||
| int result = 0; | |||
| for (int i = 0; i < byteVal.length; i++) { | |||
| int tmpVal = (byteVal[i] << (8 * (3 - i))); | |||
| switch (i) { | |||
| case 0: | |||
| tmpVal = tmpVal & 0xFF000000; | |||
| break; | |||
| case 1: | |||
| tmpVal = tmpVal & 0x00FF0000; | |||
| break; | |||
| case 2: | |||
| tmpVal = tmpVal & 0x0000FF00; | |||
| break; | |||
| case 3: | |||
| tmpVal = tmpVal & 0x000000FF; | |||
| break; | |||
| } | |||
| result = result | tmpVal; | |||
| } | |||
| return result; | |||
| } | |||
| public static byte CheckXORSum(byte[] bData) { | |||
| byte sum = 0x00; | |||
| for (int i = 0; i < bData.length; i++) { | |||
| sum ^= bData[i]; | |||
| } | |||
| return sum; | |||
| } | |||
| /** | |||
| * 从offset开始 将后续长度为len的byte字节转为int | |||
| * | |||
| * @param data | |||
| * @param offset | |||
| * @param len | |||
| * @return | |||
| */ | |||
| public static int bytesToInt(byte[] data, int offset, int len) { | |||
| int mask = 0xFF; | |||
| int temp = 0; | |||
| int result = 0; | |||
| len = Math.min(len, 4); | |||
| for (int i = 0; i < len; i++) { | |||
| result <<= 8; | |||
| temp = data[offset + i] & mask; | |||
| result |= temp; | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * byte字节数组中的字符串的长度 | |||
| * | |||
| * @param data | |||
| * @return | |||
| */ | |||
| public static int getBytesStringLen(byte[] data) { | |||
| int count = 0; | |||
| for (byte b : data) { | |||
| if (b == 0x00) | |||
| break; | |||
| count++; | |||
| } | |||
| return count; | |||
| } | |||
| /** | |||
| * | |||
| * @Title: hexString2binaryString | |||
| * @Description: 十六进制字符串转二进制字符串 | |||
| * @return String | |||
| * @author fun | |||
| * @date 2019年3月27日 | |||
| */ | |||
| public static String hexString2binaryString(String hexString) { | |||
| if (hexString == null || hexString.length() % 2 != 0) | |||
| return null; | |||
| String bString = "", tmp; | |||
| for (int i = 0; i < hexString.length(); i++) { | |||
| tmp = "0000" + Integer.toBinaryString(Integer.parseInt(hexString.substring(i, i + 1), 16)); | |||
| bString += tmp.substring(tmp.length() - 4); | |||
| } | |||
| return bString; | |||
| } | |||
| } | |||
| @@ -0,0 +1,691 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import java.math.BigDecimal; | |||
| import java.text.DateFormat; | |||
| import java.text.ParseException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Calendar; | |||
| import java.util.Date; | |||
| import java.util.GregorianCalendar; | |||
| import java.util.TimeZone; | |||
| import org.apache.commons.lang.StringUtils; | |||
| import org.apache.commons.lang.time.FastDateFormat; | |||
| /** | |||
| * @ClassName: DateUtils | |||
| * @Description: 日期处理工具类 | |||
| * @author david | |||
| * @date 2013-8-20 下午3:11:57 | |||
| * | |||
| */ | |||
| public class DateUtils { | |||
| /** | |||
| * ISO8601 formatter for date without time zone. The format used is | |||
| * <tt>yyyy-MM-dd</tt>. | |||
| */ | |||
| public static final FastDateFormat DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd"); | |||
| /** | |||
| * ISO8601 date format: yyyy-MM-dd | |||
| */ | |||
| public static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd"; | |||
| public static final String DATE_FORMAT_PATTERN_NO_SEPARATOR = "yyyyMMdd"; | |||
| /** | |||
| * ISO8601 date-time format: yyyy-MM-dd HH:mm:ss | |||
| */ | |||
| public static final String DATETIME_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss"; | |||
| /** | |||
| * for bet view format: yyyy-MM-dd HH:mm:ss | |||
| */ | |||
| public static final String DATETIME_JSVIEW_FORMAT_PATTERN = "yyyy/MM/dd HH:mm:ss"; | |||
| public static final String DATETIME_SENDTIME_FORMAT_PATTERN = "yyyyMMddHHmmssSSS"; | |||
| /** | |||
| * 日期时间格式:yyyy-MM-dd HH:mm,不显示秒 | |||
| */ | |||
| public static final String DATETIME_WITHOUT_SECOND_FORMAT_PATTERN = "yyyy-MM-dd HH:mm"; | |||
| /** | |||
| * 日期时间格式:yyyy-MM-dd HH | |||
| */ | |||
| public static final String DATETIME_WITHOUT_MINUTES_FORMAT_PATTERN = "yyyy-MM-dd HH"; | |||
| public static final String DATE_TIME_START00 = " 00:00:00"; | |||
| public static final String DATE_TIME_END23 = " 23:59:59"; | |||
| /** | |||
| * 获得当前时间 | |||
| */ | |||
| public static Date currentDate() { | |||
| return new Date(); | |||
| } | |||
| public static Date getDate(Long time) { | |||
| return new Date(time); | |||
| } | |||
| public static Long getCurTime() { | |||
| return System.currentTimeMillis(); | |||
| } | |||
| public static Date parse(String str) { | |||
| return parse(str, DATE_FORMAT_PATTERN); | |||
| } | |||
| public static Date parse(String str, String pattern) { | |||
| if (StringUtils.isBlank(str)) { | |||
| return null; | |||
| } | |||
| DateFormat parser = new SimpleDateFormat(pattern); | |||
| try { | |||
| return parser.parse(str); | |||
| } catch (ParseException e) { | |||
| throw new IllegalArgumentException("Can't parse " + str + " using " + pattern); | |||
| } | |||
| } | |||
| /** | |||
| * 根据时间变量返回时间字符串 | |||
| */ | |||
| public static String format(Date date, String pattern) { | |||
| if (date == null) { | |||
| return null; | |||
| } | |||
| FastDateFormat df = FastDateFormat.getInstance(pattern); | |||
| return df.format(date); | |||
| } | |||
| public static String format(Long time, String pattern) { | |||
| if (time == null) { | |||
| return null; | |||
| } | |||
| FastDateFormat df = FastDateFormat.getInstance(pattern); | |||
| return df.format(new Date(time)); | |||
| } | |||
| /** | |||
| * return date format is <code>yyyy-MM-dd</code> | |||
| */ | |||
| public static String format(Date date) { | |||
| return date == null ? null : DATE_FORMAT.format(date); | |||
| } | |||
| public static Date getEndDateTimeOfCurrentYear() { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(currentDate()); | |||
| cal.set(Calendar.MONTH, Calendar.DECEMBER); | |||
| cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); | |||
| cal.set(Calendar.HOUR_OF_DAY, 23); | |||
| cal.set(Calendar.MINUTE, 59); | |||
| cal.set(Calendar.SECOND, 59); | |||
| return cal.getTime(); | |||
| } | |||
| public static Date getStartDateTimeOfCurrentYear() { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(currentDate()); | |||
| cal.set(Calendar.MONTH, Calendar.JANUARY); | |||
| cal.set(Calendar.DAY_OF_MONTH, 1); | |||
| cal.set(Calendar.HOUR_OF_DAY, 0); | |||
| cal.set(Calendar.MINUTE, 0); | |||
| cal.set(Calendar.SECOND, 0); | |||
| return parse(format(cal.getTime())); | |||
| } | |||
| public static Date getStartDateTimeOfYear(int year) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.set(Calendar.YEAR, year); | |||
| cal.set(Calendar.MONTH, Calendar.JANUARY); | |||
| cal.set(Calendar.DAY_OF_MONTH, 1); | |||
| cal.set(Calendar.HOUR_OF_DAY, 0); | |||
| cal.set(Calendar.MINUTE, 0); | |||
| cal.set(Calendar.SECOND, 0); | |||
| return parse(format(cal.getTime())); | |||
| } | |||
| public static Date getEndDateTimeOfYear(int year) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.set(Calendar.YEAR, year); | |||
| cal.set(Calendar.MONTH, Calendar.DECEMBER); | |||
| cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); | |||
| cal.set(Calendar.HOUR_OF_DAY, 23); | |||
| cal.set(Calendar.MINUTE, 59); | |||
| cal.set(Calendar.SECOND, 59); | |||
| return cal.getTime(); | |||
| } | |||
| public static Date getStartTimeOfCurrentDate() { | |||
| return getStartTimeOfDate(currentDate()); | |||
| } | |||
| public static Date getEndTimeOfCurrentDate() { | |||
| return getEndTimeOfDate(currentDate()); | |||
| } | |||
| public static Date getStartTimeOfCurrentMonth() { | |||
| return getStartDateTimeOfMonth(DateUtils.currentDate()); | |||
| } | |||
| public static Date getEndTimeOfCurrentMonth() { | |||
| return getEndDateTimeOfMonth(DateUtils.currentDate()); | |||
| } | |||
| public static Date getStartTimeOfDate(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| cal.set(Calendar.HOUR_OF_DAY, 0); | |||
| cal.set(Calendar.MINUTE, 0); | |||
| cal.set(Calendar.SECOND, 0); | |||
| return parse(format(cal.getTime())); | |||
| } | |||
| public static Date getEndTimeOfDate(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| cal.set(Calendar.HOUR_OF_DAY, 23); | |||
| cal.set(Calendar.MINUTE, 59); | |||
| cal.set(Calendar.SECOND, 59); | |||
| return cal.getTime(); | |||
| } | |||
| public static Date getSpecialEndTimeOfDate(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| cal.set(Calendar.HOUR_OF_DAY, 24); | |||
| cal.set(Calendar.MINUTE, 00); | |||
| cal.set(Calendar.SECOND, 00); | |||
| return cal.getTime(); | |||
| } | |||
| public static Date getStartDateTimeOfMonth(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| cal.set(Calendar.DAY_OF_MONTH, 1); | |||
| cal.set(Calendar.HOUR_OF_DAY, 0); | |||
| cal.set(Calendar.MINUTE, 0); | |||
| cal.set(Calendar.SECOND, 0); | |||
| return parse(format(cal.getTime())); | |||
| } | |||
| public static Date getStartDateTimeOfMonth(int year, int month) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.set(Calendar.YEAR, year); | |||
| cal.set(Calendar.MONTH, month - 1); | |||
| cal.set(Calendar.DAY_OF_MONTH, 1); | |||
| cal.set(Calendar.HOUR_OF_DAY, 0); | |||
| cal.set(Calendar.MINUTE, 0); | |||
| cal.set(Calendar.SECOND, 0); | |||
| return parse(format(cal.getTime())); | |||
| } | |||
| public static Date getEndDateTimeOfMonth(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); | |||
| cal.set(Calendar.HOUR_OF_DAY, 23); | |||
| cal.set(Calendar.MINUTE, 59); | |||
| cal.set(Calendar.SECOND, 59); | |||
| return cal.getTime(); | |||
| } | |||
| public static Date addHours(Date date, int hours) { | |||
| return add(date, Calendar.HOUR_OF_DAY, hours); | |||
| } | |||
| public static Date addMinutes(Date date, int minutes) { | |||
| return add(date, Calendar.MINUTE, minutes); | |||
| } | |||
| public static Date addSeconds(Date date, int seconds) { | |||
| return add(date, Calendar.SECOND, seconds); | |||
| } | |||
| public static Date addDays(Date date, int days) { | |||
| return add(date, Calendar.DATE, days); | |||
| } | |||
| public static Date addMonths(Date date, int months) { | |||
| return add(date, Calendar.MONTH, months); | |||
| } | |||
| public static Date addYears(Date date, int years) { | |||
| return add(date, Calendar.YEAR, years); | |||
| } | |||
| private static Date add(Date date, int field, int amount) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| cal.add(field, amount); | |||
| return cal.getTime(); | |||
| } | |||
| public static long calcDateBetween(Date start, Date end) { | |||
| if (start == null || end == null) { | |||
| return 0; | |||
| } | |||
| return ((end.getTime() - start.getTime()) / 86400001) + 1; | |||
| } | |||
| public static long calcHoursBetween(Date start, Date end) { | |||
| if (start == null || end == null) { | |||
| return 0; | |||
| } | |||
| return ((end.getTime() - start.getTime()) / (60000 * 60)); | |||
| } | |||
| public static Double calcHoursDoubleBetween(Date start, Date end) { | |||
| if (start == null || end == null) { | |||
| return 0d; | |||
| } | |||
| Double time = ((end.getTime() - start.getTime()) / (60000.0 * 60.0)); | |||
| return Double.valueOf(new java.text.DecimalFormat("#.0").format(time)); | |||
| } | |||
| public static Double calcHoursDouble(Date start, Date end) { | |||
| if (start == null || end == null) { | |||
| return 0d; | |||
| } | |||
| // (new BigDecimal(end.getTime()).subtract(new | |||
| // BigDecimal(start.getTime()))).divide(new BigDecimal(60000.0*60.0), 7, | |||
| // BigDecimal.ROUND_HALF_UP).doubleValue(); | |||
| Double time = (new BigDecimal(end.getTime()).subtract(new BigDecimal(start.getTime()))) | |||
| .divide(new BigDecimal(60000.0 * 60.0), 7, BigDecimal.ROUND_HALF_UP).doubleValue();// ((end.getTime() - | |||
| // start.getTime()) | |||
| // / | |||
| // (60000.0*60.0)); | |||
| return time; | |||
| } | |||
| public static long calcMinutesBetween(Date start, Date end) { | |||
| if (start == null || end == null) { | |||
| return 0; | |||
| } | |||
| return ((end.getTime() - start.getTime()) / 60000); | |||
| } | |||
| public static long calcSecondsBetween(Date start, Date end) { | |||
| if (start == null || end == null) { | |||
| return 0; | |||
| } | |||
| return ((end.getTime() - start.getTime()) / 1000); | |||
| } | |||
| public static long calcSecondsBetween(Long start, Long end) { | |||
| return (end - start) / 1000; | |||
| } | |||
| /** | |||
| * 获得日期是否为星期天。 | |||
| * | |||
| * @param date 日期 | |||
| * @return | |||
| */ | |||
| public static boolean isSunday(Date date) { | |||
| return getDate(date) == Calendar.SUNDAY; | |||
| } | |||
| /** | |||
| * 获得日期是否为星期一。 | |||
| * | |||
| * @param date 日期 | |||
| * @return | |||
| */ | |||
| public static boolean isMonday(Date date) { | |||
| return getDate(date) == Calendar.MONDAY; | |||
| } | |||
| /** | |||
| * 获得日期是否为星期二。 | |||
| * | |||
| * @param date 日期 | |||
| * @return | |||
| */ | |||
| public static boolean isTuesday(Date date) { | |||
| return getDate(date) == Calendar.TUESDAY; | |||
| } | |||
| /** | |||
| * 获得日期是否为星期三。 | |||
| * | |||
| * @param date 日期 | |||
| * @return | |||
| */ | |||
| public static boolean isWednesday(Date date) { | |||
| return getDate(date) == Calendar.WEDNESDAY; | |||
| } | |||
| /** | |||
| * 获得日期是否为星期四。 | |||
| * | |||
| * @param date 日期 | |||
| * @return | |||
| */ | |||
| public static boolean isThursday(Date date) { | |||
| return getDate(date) == Calendar.THURSDAY; | |||
| } | |||
| /** | |||
| * 获得日期是否为星期五。 | |||
| * | |||
| * @param date 日期 | |||
| * @return | |||
| */ | |||
| public static boolean isFriday(Date date) { | |||
| return getDate(date) == Calendar.FRIDAY; | |||
| } | |||
| /** | |||
| * 获得日期是否为星期六。 | |||
| * | |||
| * @param date 日期 | |||
| * @return | |||
| */ | |||
| public static boolean isSaturday(Date date) { | |||
| return getDate(date) == Calendar.SATURDAY; | |||
| } | |||
| public static int getDate(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| return cal.get(Calendar.DAY_OF_WEEK); | |||
| } | |||
| /** | |||
| * 获得相对于今天的昨天的时间。 | |||
| * | |||
| * @return 昨天此时。 | |||
| */ | |||
| public static Date getYesterday() { | |||
| return addDays(currentDate(), -1); | |||
| } | |||
| /** | |||
| * 获得月份 | |||
| * | |||
| * @param date | |||
| * @return | |||
| */ | |||
| public static int getMonth(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.MONTH) + 1; | |||
| } | |||
| /** | |||
| * 获得年份 | |||
| * | |||
| * @param date | |||
| * @return | |||
| */ | |||
| public static int getYear(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.YEAR); | |||
| } | |||
| /** | |||
| * 获得天 | |||
| * | |||
| * @param date | |||
| * @return | |||
| */ | |||
| public static int getDay(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.DATE); | |||
| } | |||
| /** | |||
| * 获得天 | |||
| * | |||
| * @param date | |||
| * @return | |||
| */ | |||
| public static int getDayOfYear(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.DAY_OF_YEAR); | |||
| } | |||
| /** | |||
| * 获得小时 | |||
| * | |||
| * @param date | |||
| * @return | |||
| */ | |||
| public static int getHours(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.HOUR_OF_DAY); | |||
| } | |||
| public static int getMinutes(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.MINUTE); | |||
| } | |||
| public static int getSeconds(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.SECOND); | |||
| } | |||
| public static int getMILLISECOND(Date date) { | |||
| Calendar calendar = Calendar.getInstance(); | |||
| calendar.setTime(date); | |||
| return calendar.get(Calendar.MILLISECOND); | |||
| } | |||
| public static long getTimeDiff(Date beginDate, Date endDate) { | |||
| return (endDate.getTime() - beginDate.getTime()) / 1000; | |||
| } | |||
| public static int getDaysOfMonth(int year, int month) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.set(Calendar.YEAR, year); | |||
| cal.set(Calendar.MONTH, month);// 7月 | |||
| return cal.getActualMaximum(Calendar.DATE); | |||
| } | |||
| public static long convertDate2Long(Date date) { | |||
| if (date == null) { | |||
| return 0l; | |||
| } | |||
| return date.getTime(); | |||
| } | |||
| public static Date convertLong2Date(Long unixTimestamp) { | |||
| if (unixTimestamp != null) { | |||
| return new java.util.Date(unixTimestamp); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 判断时间是否在指定的时间范围内。 | |||
| * | |||
| * @param low | |||
| * @param high | |||
| * @return | |||
| */ | |||
| public static boolean between(Date low, Date high) { | |||
| return currentDate().after(low) && currentDate().before(high); | |||
| } | |||
| public static int getDayValue(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| int i = cal.get(Calendar.DAY_OF_WEEK); | |||
| if (i == 1) { | |||
| return 7; | |||
| } else { | |||
| return i - 1; | |||
| } | |||
| } | |||
| public static boolean isBefore(Date date1, Date date2) { | |||
| return date1.getTime() < date2.getTime(); | |||
| } | |||
| public static Date average(Date date1, Date date2) { | |||
| return new Date((date1.getTime() + date2.getTime()) / 2); | |||
| } | |||
| public static int getDaysOfMonth(Date date) { | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(date); | |||
| return cal.get(Calendar.DAY_OF_MONTH); | |||
| } | |||
| public static int getCurrentRemainingSeconds() { | |||
| // *** 计算过期时间 一整天 获取 时:分:秒 | |||
| Calendar calendar = Calendar.getInstance(); | |||
| int hours = calendar.get(Calendar.HOUR_OF_DAY); // 时 | |||
| int minutes = calendar.get(Calendar.MINUTE); // 分 | |||
| int seconds = calendar.get(Calendar.SECOND); // 秒 | |||
| return 24 * 60 * 60 - hours * 60 * 60 - minutes * 60 - seconds; | |||
| } | |||
| public static Long getTimeLong(String str) { | |||
| return parse(str, DATETIME_FORMAT_PATTERN).getTime(); | |||
| } | |||
| public static String getStringTodayC() { | |||
| Date currentTime = new Date(); | |||
| SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS"); | |||
| String dateString = formatter.format(currentTime); | |||
| return dateString; | |||
| } | |||
| /////////////////////////////////////////////////// | |||
| // 引用s https://blog.csdn.net/tz_gx/article/details/25284237 | |||
| // s 上月第一天 | |||
| public static Date getPreviousMonthDayBegin() { | |||
| Calendar lastDate = Calendar.getInstance(); | |||
| lastDate.set(Calendar.DATE, 1);// 设为当前月的1号 | |||
| lastDate.add(Calendar.MONTH, -1);// 减一个月,变为上月的1号 | |||
| return lastDate.getTime(); | |||
| } | |||
| // s 获得上月最后一天的日期 | |||
| public static Date getPreviousMonthDayEnd() { | |||
| Calendar lastDate = Calendar.getInstance(); | |||
| lastDate.add(Calendar.MONTH, -1);// 减一个月 | |||
| lastDate.set(Calendar.DATE, 1);// 把日期设置为当月第一天 | |||
| lastDate.roll(Calendar.DATE, -1);// 日期回滚一天,也就是本月最后一天 | |||
| return lastDate.getTime(); | |||
| } | |||
| // s 获取当月第一天 | |||
| public static Date getCurrentMonthDayBegin() { | |||
| Calendar lastDate = Calendar.getInstance(); | |||
| lastDate.set(Calendar.DATE, 1);// 设为当前月的1号 | |||
| return lastDate.getTime(); | |||
| } | |||
| // s 计算当月最后一天,返回字符串 | |||
| public static Date getCurrentMonthDayEnd() { | |||
| Calendar lastDate = Calendar.getInstance(); | |||
| lastDate.set(Calendar.DATE, 1);// 设为当前月的1号 | |||
| lastDate.add(Calendar.MONTH, 1);// 加一个月,变为下月的1号 | |||
| lastDate.add(Calendar.DATE, -1);// 减去一天,变为当月最后一天 | |||
| return lastDate.getTime(); | |||
| } | |||
| // s 获得本周一的日期 | |||
| public static Date getCurrentWeekDayBegin() { | |||
| int mondayPlus = getMondayPlus(); | |||
| GregorianCalendar currentDate = new GregorianCalendar(); | |||
| currentDate.add(GregorianCalendar.DATE, mondayPlus); | |||
| return currentDate.getTime(); | |||
| } | |||
| // s 获得本周星期日的日期 | |||
| public static Date getCurrentWeekDayEnd() { | |||
| int mondayPlus = getMondayPlus(); | |||
| GregorianCalendar currentDate = new GregorianCalendar(); | |||
| currentDate.add(GregorianCalendar.DATE, mondayPlus + 6); | |||
| Date monday = currentDate.getTime(); | |||
| return monday; | |||
| } | |||
| // s 获得当前日期与本周一相差的天数 | |||
| private static int getMondayPlus() { | |||
| Calendar cd = Calendar.getInstance(); | |||
| // 获得今天是一周的第几天,星期日是第一天,星期二是第二天...... | |||
| int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1; // s 因为按中国礼拜一作为第一天所以这里减1 | |||
| if (dayOfWeek == 1) { | |||
| return 0; | |||
| } else { | |||
| return 1 - dayOfWeek; | |||
| } | |||
| } | |||
| // s 获得上周星期一的日期 | |||
| public static Date getPreviousWeekDayBegin() { | |||
| int mondayPlus = getMondayPlus(); | |||
| GregorianCalendar currentDate = new GregorianCalendar(); | |||
| currentDate.add(GregorianCalendar.DATE, mondayPlus - 7); | |||
| return currentDate.getTime(); | |||
| } | |||
| // s 获得上周星期日的日期 | |||
| public static Date getPreviousWeekDayEnd() { | |||
| int mondayPlus = getMondayPlus(); | |||
| GregorianCalendar currentDate = new GregorianCalendar(); | |||
| currentDate.add(GregorianCalendar.DATE, mondayPlus - 1); | |||
| return currentDate.getTime(); | |||
| } | |||
| public static int getAge(Date birthDay){ | |||
| Calendar cal = Calendar.getInstance(); | |||
| if (cal.before(birthDay)) { //出生日期晚于当前时间,无法计算 | |||
| return 0; | |||
| } | |||
| int yearNow = cal.get(Calendar.YEAR); //当前年份 | |||
| int monthNow = cal.get(Calendar.MONTH); //当前月份 | |||
| int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH); //当前日期 | |||
| cal.setTime(birthDay); | |||
| int yearBirth = cal.get(Calendar.YEAR); | |||
| int monthBirth = cal.get(Calendar.MONTH); | |||
| int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH); | |||
| int age = yearNow - yearBirth; //计算整岁数 | |||
| if (monthNow <= monthBirth) { | |||
| if (monthNow == monthBirth) { | |||
| if (dayOfMonthNow < dayOfMonthBirth) age--;//当前日期在生日之前,年龄减一 | |||
| }else{ | |||
| age--;//当前月份在生日之前,年龄减一 | |||
| } | |||
| } | |||
| return age; | |||
| } | |||
| public static Date getCurrZoneGMT0(){ | |||
| SimpleDateFormat dateFormat = new SimpleDateFormat(DATETIME_FORMAT_PATTERN); | |||
| dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00")); | |||
| return parse(dateFormat.format(new Date()), DATETIME_FORMAT_PATTERN) ; | |||
| } | |||
| /////////////////////////////////// | |||
| public static void main(String[] args) { | |||
| // System.out.println(getMILLISECOND(new Date())); | |||
| System.out.println(format(getCurrZoneGMT0(),DATETIME_FORMAT_PATTERN)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,127 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import com.fasterxml.jackson.annotation.JsonInclude.Include; | |||
| import com.fasterxml.jackson.core.JsonProcessingException; | |||
| import com.fasterxml.jackson.databind.DeserializationFeature; | |||
| import com.fasterxml.jackson.databind.JavaType; | |||
| import com.fasterxml.jackson.databind.ObjectMapper; | |||
| import com.fasterxml.jackson.databind.SerializationFeature; | |||
| import com.fasterxml.jackson.databind.util.JSONPObject; | |||
| import java.io.IOException; | |||
| public class JsonMapper { | |||
| private ObjectMapper mapper; | |||
| public JsonMapper() { | |||
| this(null); | |||
| } | |||
| public JsonMapper(Include include) { | |||
| mapper = new ObjectMapper(); | |||
| if (include != null) { | |||
| mapper.setSerializationInclusion(include); | |||
| } | |||
| mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | |||
| mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); | |||
| } | |||
| public static JsonMapper nonEmptyMapper() { | |||
| return new JsonMapper(Include.NON_EMPTY); | |||
| } | |||
| public static JsonMapper nonDefaultMapper() { | |||
| return new JsonMapper(Include.NON_DEFAULT); | |||
| } | |||
| public static JsonMapper nonAlwaysMapper() { | |||
| return new JsonMapper(Include.ALWAYS); | |||
| } | |||
| public String toJson(Object object) { | |||
| try { | |||
| return mapper.writeValueAsString(object); | |||
| } catch (IOException e) { | |||
| return null; | |||
| } | |||
| } | |||
| public <T> T fromMapToObject(Object map, Class<T> cls) { | |||
| return this.fromJson(this.toJson(map), cls); | |||
| } | |||
| public <T> T fromMapToObject(Object map, JavaType cls) { | |||
| return this.fromJson(this.toJson(map), cls); | |||
| } | |||
| public <T> T fromJson(String jsonString, Class<T> clazz) { | |||
| if (isEmpty(jsonString)) { | |||
| return null; | |||
| } | |||
| try { | |||
| return mapper.readValue(jsonString, clazz); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| return null; | |||
| } | |||
| } | |||
| public <T> T fromJson(String jsonString, JavaType javaType) { | |||
| if (isEmpty(jsonString)) { | |||
| return null; | |||
| } | |||
| try { | |||
| return (T) mapper.readValue(jsonString, javaType); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| return null; | |||
| } | |||
| } | |||
| public JavaType createCollectionType(Class<?> collectionClass, Class<?>... elementClasses) { | |||
| return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses); | |||
| } | |||
| public <T> T update(String jsonString, T object) { | |||
| try { | |||
| return (T) mapper.readerForUpdating(object).readValue(jsonString); | |||
| } catch (JsonProcessingException e) { | |||
| e.printStackTrace(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| return null; | |||
| } | |||
| public String toJsonP(String functionName, Object object) { | |||
| return toJson(new JSONPObject(functionName, object)); | |||
| } | |||
| public void enableEnumUseToString() { | |||
| mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); | |||
| mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); | |||
| } | |||
| public ObjectMapper getMapper() { | |||
| return mapper; | |||
| } | |||
| public static boolean isEmpty(String str) { | |||
| return str == null || str.length() == 0; | |||
| } | |||
| } | |||
| @@ -0,0 +1,61 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| public class JsonUtils { | |||
| protected static JsonMapper jmapper = JsonMapper.nonEmptyMapper(); | |||
| /** | |||
| * json数据结构转换对象 | |||
| * @param jsonStr | |||
| * @param clazz | |||
| * @return | |||
| */ | |||
| public static <T> T fromJson(String jsonStr,Class<T> clazz){ | |||
| return jmapper.fromJson(jsonStr, clazz); | |||
| } | |||
| /**json数据结构转换List<MyBean> | |||
| * @param jsonStr | |||
| * @param clazz | |||
| * @return | |||
| */ | |||
| public static <T> List<T> fromJson2List(String jsonStr,Class<T> clazz){ | |||
| return jmapper.fromJson(jsonStr, | |||
| JsonMapper.nonDefaultMapper().createCollectionType(List.class, clazz)); | |||
| } | |||
| /** | |||
| * 对象转换json数据结构 | |||
| * @param obj | |||
| * @return | |||
| */ | |||
| public static String toJson(Object obj){ | |||
| return jmapper.toJson(obj); | |||
| } | |||
| public static void main(String[] args){ | |||
| /*String s="[{\"level\":\"3\",\"time\":\"1428551739622\"},{\"level\":\"4\",\"time\":\"1428551739623\"}]"; | |||
| List<DeviceSignalRecordRequest> ss=fromJson2List(s, DeviceSignalRecordRequest.class); | |||
| String sss=toJson(new DeviceSignalRecordRequest()); | |||
| System.out.println(ss);*/ | |||
| List<String> a=new ArrayList<String>(); | |||
| List<String> b=new ArrayList<String>(); | |||
| List<List<String>> cc =new ArrayList<List<String>>(); | |||
| a.add("11:00"); | |||
| a.add("12:00"); | |||
| b.add("13:00"); | |||
| b.add("14:00"); | |||
| cc.add(a); | |||
| cc.add(b); | |||
| System.out.println(JsonUtils.toJson(a)); | |||
| List<String> k= JsonUtils.fromJson2List(JsonUtils.toJson(a),String.class); | |||
| for(String s:k){ | |||
| System.out.println(s); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,41 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import java.util.regex.Pattern; | |||
| public class StringSelfUtil { | |||
| public static boolean startWithChar(String s) { | |||
| if (s != null && s.length() > 0) { | |||
| String start = s.trim().substring(0, 1); | |||
| Pattern pattern = Pattern.compile("^[A-Za-z]+$"); | |||
| return pattern.matcher(start).matches(); | |||
| } else { | |||
| return false; | |||
| } | |||
| } | |||
| public static boolean isNumeric(String str){ | |||
| Pattern pattern = Pattern.compile("[0-9]*"); | |||
| return pattern.matcher(str).matches(); | |||
| } | |||
| public static String byteArrayToStr(byte[] byteArray) { | |||
| if (byteArray == null) { | |||
| return null; | |||
| } | |||
| String str = new String(byteArray); | |||
| return str; | |||
| } | |||
| public static boolean isEmpty(String s){ | |||
| if(s==null || s.equals("") || s.isEmpty()){ | |||
| return true; | |||
| }else{ | |||
| return false; | |||
| } | |||
| } | |||
| public static boolean isBlank(String s){ | |||
| return isEmpty(s); | |||
| } | |||
| } | |||
| @@ -0,0 +1,279 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import com.inet.ailink.receiver.common.enums.Common; | |||
| import java.io.UnsupportedEncodingException; | |||
| public class TeaUtils { | |||
| public static byte[] encrypt(byte[] data, byte[] key) { | |||
| int data_len = data.length; // 数据的长度 | |||
| if (data_len == 0) { | |||
| return new byte[] {}; | |||
| } | |||
| TeaUtils t = new TeaUtils(); | |||
| if (!t.setKey(key)) { | |||
| return new byte[] {}; | |||
| } | |||
| int group_len = 8; | |||
| int residues = data_len % group_len; // 余数 | |||
| int dlen = data_len - residues; | |||
| // 用于储存加密的密文,第一字节为余数的大小 | |||
| //int result_len = data_len + 1; | |||
| int result_len = data_len; | |||
| if (residues > 0) { | |||
| result_len += group_len - residues; | |||
| } | |||
| byte[] result = new byte[result_len]; | |||
| //result[0] = (byte)residues; | |||
| byte[] plain = new byte[group_len]; | |||
| byte[] enc = new byte[group_len]; | |||
| for (int i = 0; i < dlen; i += group_len) { | |||
| for (int j = 0; j < group_len; j++) { | |||
| plain[j] = data[i + j]; | |||
| } | |||
| enc = t.encrypt_group(plain); | |||
| for (int k = 0; k < group_len; k++) { | |||
| //result[i + k + 1] = enc[k]; | |||
| result[i + k ] = enc[k]; | |||
| } | |||
| } | |||
| if (residues > 0) { | |||
| for (int j = 0; j < residues; j++) { | |||
| plain[j] = data[dlen + j]; | |||
| } | |||
| int padding = group_len - residues; | |||
| for (int j = 0; j < padding; j++) { | |||
| plain[residues + j] = (byte)0x00; | |||
| } | |||
| enc = t.encrypt_group(plain); | |||
| for (int k = 0; k < group_len; k++) { | |||
| //result[dlen + k + 1] = enc[k]; | |||
| result[dlen + k] = enc[k]; | |||
| } | |||
| } | |||
| return result; | |||
| } | |||
| public static byte[] decrypt(byte[] data, byte[] key) { | |||
| int group_len = 8; | |||
| // if (data.length % group_len != 1) { | |||
| // return new byte[] {}; | |||
| // } | |||
| TeaUtils t = new TeaUtils(); | |||
| if (!t.setKey(key)) { | |||
| return new byte[] {}; | |||
| } | |||
| //int data_len = data.length - 1, dlen; // 数据的长度 | |||
| int data_len = data.length, dlen; // 数据的长度 | |||
| dlen = data_len; | |||
| //int residues = (int)(data[0]); // 余数 | |||
| // if (residues > 0) { | |||
| // dlen = data_len - group_len; | |||
| // } else { | |||
| // dlen = data_len; | |||
| // } | |||
| //byte[] result = new byte[dlen + residues]; | |||
| byte[] result = new byte[dlen]; | |||
| byte[] dec = new byte[group_len]; | |||
| byte[] enc = new byte[group_len]; | |||
| for (int i = 0; i < dlen; i += group_len) { | |||
| for (int j = 0; j < group_len; j++) { | |||
| //enc[j] = data[i + j + 1]; | |||
| enc[j] = data[i + j]; | |||
| } | |||
| dec = t.decrypt_group(enc); | |||
| for (int k = 0; k < group_len; k++) { | |||
| result[i + k] = dec[k]; | |||
| } | |||
| } | |||
| // if (residues > 0) { | |||
| // for (int j = 0; j < group_len; j++) { | |||
| // enc[j] = data[dlen + j + 1]; | |||
| // } | |||
| // dec = t.decrypt_group(enc); | |||
| // for (int k = 0; k < residues; k++) { | |||
| // result[dlen + k] = dec[k]; | |||
| // } | |||
| // } | |||
| return result; | |||
| } | |||
| /** | |||
| * 设置密钥 | |||
| * @param k 密钥 | |||
| * @return 密钥长度为16个byte时, 设置密钥并返回true,否则返回false | |||
| */ | |||
| public boolean setKey(byte[] k) { | |||
| if(k==null){ | |||
| k = Common.TEA_KEY; | |||
| } | |||
| if (k.length != 16) { | |||
| return false; | |||
| } | |||
| k0 = bytes_to_uint32(new byte[] {k[0], k[1], k[2], k[3]}); | |||
| k1 = bytes_to_uint32(new byte[] {k[4], k[5], k[6], k[7]}); | |||
| k2 = bytes_to_uint32(new byte[] {k[8], k[9], k[10], k[11]}); | |||
| k3 = bytes_to_uint32(new byte[] {k[12], k[13], k[14], k[15]}); | |||
| return true; | |||
| } | |||
| /** | |||
| * 设置加密的轮数,默认为32轮 | |||
| * @param loops 加密轮数 | |||
| * @return 轮数为16、32、64时,返回true,否则返回false | |||
| */ | |||
| public boolean setLoops(int loops) { | |||
| switch (loops) { | |||
| case 16: | |||
| case 32: | |||
| case 64: | |||
| this.loops = loops; | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| private static long UINT32_MAX = 0xFFFFFFFFL; | |||
| private static long BYTE_1 = 0xFFL; | |||
| private static long BYTE_2 = 0xFF00L; | |||
| private static long BYTE_3 = 0xFF0000L; | |||
| private static long BYTE_4 = 0xFF000000L; | |||
| private static long delta = 0x9E3779B9L; | |||
| private static long k0; | |||
| private static long k1; | |||
| private static long k2; | |||
| private static long k3; | |||
| private static int loops = 32; | |||
| /** | |||
| * 加密一组明文 | |||
| * @param v 需要加密的明文 | |||
| * @return 返回密文 | |||
| */ | |||
| public static byte[] encrypt_group(byte[] v) { | |||
| long v0 = bytes_to_uint32(new byte[] {v[0], v[1], v[2], v[3]}); | |||
| long v1 = bytes_to_uint32(new byte[] {v[4], v[5], v[6], v[7]}); | |||
| long sum = 0L; | |||
| long v0_xor_1 = 0L, v0_xor_2 = 0L, v0_xor_3 = 0L; | |||
| long v1_xor_1 = 0L, v1_xor_2 = 0L, v1_xor_3 = 0L; | |||
| for (int i = 0; i < loops; i++) { | |||
| sum = toUInt32(sum + delta); | |||
| v0_xor_1 = toUInt32(toUInt32(v1 << 4) + k0); | |||
| v0_xor_2 = toUInt32(v1 + sum); | |||
| v0_xor_3 = toUInt32((v1 >> 5) + k1); | |||
| v0 = toUInt32( v0 + toUInt32(v0_xor_1 ^ v0_xor_2 ^ v0_xor_3) ); | |||
| v1_xor_1 = toUInt32(toUInt32(v0 << 4) + k2); | |||
| v1_xor_2 = toUInt32(v0 + sum); | |||
| v1_xor_3 = toUInt32((v0 >> 5) + k3); | |||
| //System.out.printf("%08X\t%08X\t%08X\t%08X\n", i, v0, v0 >> 5, k3); | |||
| v1 = toUInt32( v1 + toUInt32(v1_xor_1 ^ v1_xor_2 ^ v1_xor_3) ); | |||
| } | |||
| byte[] b0 = long_to_bytes(v0, 4); | |||
| byte[] b1 = long_to_bytes(v1, 4); | |||
| return new byte[] {b0[0], b0[1], b0[2], b0[3], b1[0], b1[1], b1[2], b1[3]}; | |||
| } | |||
| /** | |||
| * 解密一组密文 | |||
| * @param v 要解密的密文 | |||
| * @return 返回明文 | |||
| */ | |||
| public static byte[] decrypt_group(byte[] v) { | |||
| long v0 = bytes_to_uint32(new byte[] {v[0], v[1], v[2], v[3]}); | |||
| long v1 = bytes_to_uint32(new byte[] {v[4], v[5], v[6], v[7]}); | |||
| long sum = 0xC6EF3720L, tmp = 0L; | |||
| for (int i = 0; i < loops; i++) { | |||
| tmp = toUInt32(toUInt32(v0 << 4) + k2); | |||
| v1 = toUInt32( v1 - toUInt32(tmp ^ toUInt32(v0 + sum) ^ toUInt32((v0 >> 5) + k3)) ); | |||
| tmp = toUInt32(toUInt32(v1 << 4) + k0); | |||
| v0 = toUInt32( v0 - toUInt32(tmp ^ toUInt32(v1 + sum) ^ toUInt32((v1 >> 5) + k1)) ); | |||
| sum = toUInt32(sum - delta); | |||
| } | |||
| byte[] b0 = long_to_bytes(v0, 4); | |||
| byte[] b1 = long_to_bytes(v1, 4); | |||
| return new byte[] {b0[0], b0[1], b0[2], b0[3], b1[0], b1[1], b1[2], b1[3]}; | |||
| } | |||
| /** | |||
| * 将 long 类型的 n 转为 byte 数组,如果 len 为 4,则只返回低32位的4个byte | |||
| * @param n 需要转换的long | |||
| * @param len 若为4,则只返回低32位的4个byte,否则返回8个byte | |||
| * @return 转换后byte数组 | |||
| */ | |||
| private static byte[] long_to_bytes(long n, int len) { | |||
| byte a = (byte)((n & BYTE_4) >> 24); | |||
| byte b = (byte)((n & BYTE_3) >> 16); | |||
| byte c = (byte)((n & BYTE_2) >> 8); | |||
| byte d = (byte)(n & BYTE_1); | |||
| if (len == 4) { | |||
| return new byte[] {a, b, c, d}; | |||
| } | |||
| byte ha = (byte)(n >> 56); | |||
| byte hb = (byte)((n >> 48) & BYTE_1); | |||
| byte hc = (byte)((n >> 40) & BYTE_1); | |||
| byte hd = (byte)((n >> 32) & BYTE_1); | |||
| return new byte[] {ha, hb, hc, hd, a, b, c, d}; | |||
| } | |||
| /** | |||
| * 将4个byte转为 Unsigned Integer 32,以 long 形式返回 | |||
| * @param bs 需要转换的字节 | |||
| * @return 返回 long,高32位为0,低32位视为Unsigned Integer | |||
| */ | |||
| private static long bytes_to_uint32(byte[] bs) { | |||
| return ((bs[0]<<24) & BYTE_4) + | |||
| ((bs[1]<<16) & BYTE_3) + | |||
| ((bs[2]<<8) & BYTE_2) + | |||
| (bs[3] & BYTE_1); | |||
| } | |||
| /** | |||
| * 将long的高32位清除,只保留低32位,低32位视为Unsigned Integer | |||
| * @param n 需要清除的long | |||
| * @return 返回高32位全为0的long | |||
| */ | |||
| private static long toUInt32(long n) { | |||
| return n & UINT32_MAX; | |||
| } | |||
| public static void main(String args[]) throws UnsupportedEncodingException | |||
| { | |||
| TeaUtils t = new TeaUtils(); | |||
| t.setKey(Common.TEA_KEY); | |||
| byte[] old = new byte[]{(byte)0x01,(byte)0x16,(byte)0xA4,(byte)0x28, | |||
| (byte)0x32,(byte)0x18,(byte)0x4A,(byte)0x88, | |||
| (byte)0x00,(byte)0x00 ,(byte)0x00 ,(byte)0x00, | |||
| (byte)0x00 ,(byte)0x00 ,(byte)0x42 ,(byte)0x4D, | |||
| (byte)0x10 ,(byte)0x01,(byte)0x0A ,(byte)0x00, | |||
| (byte)0x13 ,(byte)0x05 ,(byte)0x07 ,(byte)0xC8}; | |||
| /*byte[] old = new byte[] { | |||
| 0x00, 0x00, 0x00, 0x20, | |||
| 0x00, 0x00, 0x00, 0x10 | |||
| };*/ | |||
| byte[] enc = t.encrypt(old,Common.TEA_KEY); | |||
| System.out.println( "tea加密:"); | |||
| for(byte i : enc) | |||
| System.out.print(i + " "); | |||
| System.out.println(); | |||
| byte[] dec = t.decrypt(enc,Common.TEA_KEY); | |||
| System.out.println( "tea解密:"); | |||
| for(byte i : dec) | |||
| System.out.print(i + " "); | |||
| System.out.println(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,80 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import java.io.IOException; | |||
| import java.math.BigDecimal; | |||
| public class WeightUnitUtils { | |||
| public static void main(String arg[]) throws IOException{ | |||
| // System.out.println("100kg="+getKg(100,0,0)+"kg");//100kg | |||
| // System.out.println("10kg="+getKg(100,0,1)+"kg");//10kg | |||
| // System.out.println("1kg="+getKg(100,0,2)+"kg");//1kg | |||
| // System.out.println("100.1kg="+getKg(1001,0,1)+"kg");//1kg | |||
| // System.out.println("100.5kg="+getKg(1005,0,1)+"kg");//1kg | |||
| // System.out.println("100.6kg="+getKg(1006,0,1)+"kg");//1kg | |||
| // System.out.println("100.8kg="+getKg(1008,0,1)+"kg");//1kg | |||
| // System.out.println("100.11kg="+getKg(10011,0,2)+"kg");//1kg | |||
| // System.out.println("100.55kg="+getKg(10055,0,2)+"kg");//1kg | |||
| // System.out.println("100.66kg="+getKg(10066,0,2)+"kg");//1kg | |||
| // System.out.println("100.88kg="+getKg(10088,0,2)+"kg");//1kg | |||
| // System.out.println("100lb="+getKg(100,6,0)+"kg");//100kg | |||
| // System.out.println("10lb="+getKg(100,6,1)+"kg");//10kg | |||
| // System.out.println("1lb="+getKg(100,6,2)+"kg");//1kg | |||
| // System.out.println("100.1lb="+getKg(1001,6,1)+"kg");//1kg | |||
| // System.out.println("100.5lb="+getKg(1005,6,1)+"kg");//1kg | |||
| // System.out.println("100.6lb="+getKg(1006,6,1)+"kg");//1kg | |||
| // System.out.println("100.8lb="+getKg(1008,6,1)+"kg");//1kg | |||
| // System.out.println("100.11lb="+getKg(10011,6,2)+"kg");//1kg | |||
| // System.out.println("100.55lb="+getKg(10055,6,2)+"kg");//1kg | |||
| // System.out.println("100.66lb="+getKg(10066,6,2)+"kg");//1kg | |||
| // System.out.println("100.88lb="+getKg(10088,6,2)+"kg");//1kg | |||
| // System.out.println("100st="+getKg(100,4,0)+"kg");//100kg | |||
| // System.out.println("10st="+getKg(100,4,1)+"kg");//10kg | |||
| // System.out.println("1st="+getKg(100,4,2)+"kg");//1kg | |||
| // System.out.println("100.1st="+getKg(1001,4,1)+"kg");//1kg | |||
| // System.out.println("100.5st="+getKg(1005,4,1)+"kg");//1kg | |||
| // System.out.println("100.6st="+getKg(1006,4,1)+"kg");//1kg | |||
| // System.out.println("100.8st="+getKg(1008,4,1)+"kg");//1kg | |||
| // System.out.println("100.11st="+getKg(10011,4,2)+"kg");//1kg | |||
| // System.out.println("100.55st="+getKg(10055,4,2)+"kg");//1kg | |||
| // System.out.println("100.66st="+getKg(10066,4,2)+"kg");//1kg | |||
| // System.out.println("100.88st="+getKg(10088,4,2)+"kg");//1kg | |||
| } | |||
| public static BigDecimal getKg(BigDecimal weight, int weightUnit,int weightPoint){ | |||
| BigDecimal result = BigDecimal.ZERO; | |||
| //小数位转换 | |||
| if(weightPoint == 0){ | |||
| result = weight; | |||
| }else{ | |||
| result = weight; | |||
| for(int i=0;i<weightPoint;i++){ | |||
| result = result.divide(new BigDecimal(10)); | |||
| } | |||
| } | |||
| //单位转化为千克 | |||
| switch (weightUnit) { | |||
| case 0://千克,不需要转换 | |||
| break; | |||
| case 1://斤->千克 | |||
| result = result.multiply(new BigDecimal(2)); | |||
| break; | |||
| case 4://st->千克 | |||
| //st先转成lb,在转成千克 | |||
| result = result.multiply(new BigDecimal(14.0f));//st->lb | |||
| result = result.divide(new BigDecimal(2.2046226f),7, BigDecimal.ROUND_HALF_UP);//lb->kg | |||
| break; | |||
| case 6://lb->kg | |||
| result = result.divide(new BigDecimal(2.2046226f),7, BigDecimal.ROUND_HALF_UP); | |||
| break; | |||
| default: | |||
| break; | |||
| } | |||
| //保留2位小数 | |||
| result = result.setScale(2, BigDecimal.ROUND_HALF_UP); | |||
| return result; | |||
| } | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| package com.inet.ailink.receiver.common.vo; | |||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |||
| @JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL) | |||
| public class Response<T>{ | |||
| private String status; | |||
| public T data; | |||
| public Response(){} | |||
| public T getData() { | |||
| return data; | |||
| } | |||
| public void setData(T data) { | |||
| this.data = data; | |||
| } | |||
| public String getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(String status) { | |||
| this.status = status; | |||
| } | |||
| } | |||
| @@ -0,0 +1,139 @@ | |||
| package com.inet.ailink.receiver.common.vo; | |||
| public class WebContext { | |||
| private static ThreadLocal<WebContext> webContextThreadLocal = new ThreadLocal<WebContext>(); | |||
| private String loginToken; | |||
| private String userName; | |||
| private Integer roleType; | |||
| private Long userId; | |||
| private Long enterpriseId;//用户企业信息id | |||
| private String clientType; | |||
| private String companyNo; | |||
| private String emailAddress; | |||
| private long appId; | |||
| private String msgSignature; | |||
| private String accountUUID; | |||
| private String accountSecret; | |||
| private String requestPramString; | |||
| public WebContext() | |||
| { | |||
| } | |||
| public static WebContext getWebContext() | |||
| { | |||
| WebContext context = (WebContext) webContextThreadLocal.get(); | |||
| if (context == null) | |||
| { | |||
| context = new WebContext(); | |||
| webContextThreadLocal.set(context); | |||
| } | |||
| return context; | |||
| } | |||
| public String getLoginToken() { | |||
| return loginToken; | |||
| } | |||
| public void setLoginToken(String loginToken) { | |||
| this.loginToken = loginToken; | |||
| } | |||
| public String getUserName() { | |||
| return userName; | |||
| } | |||
| public void setUserName(String userName) { | |||
| this.userName = userName; | |||
| } | |||
| public Long getUserId() { | |||
| return userId; | |||
| } | |||
| public void setUserId(Long userId) { | |||
| this.userId = userId; | |||
| } | |||
| public Integer getRoleType() { | |||
| return roleType; | |||
| } | |||
| public void setRoleType(Integer roleType) { | |||
| this.roleType = roleType; | |||
| } | |||
| public String getClientType() { | |||
| return clientType; | |||
| } | |||
| public void setClientType(String clientType) { | |||
| this.clientType = clientType; | |||
| } | |||
| public String getCompanyNo() { | |||
| return companyNo; | |||
| } | |||
| public void setCompanyNo(String companyNo) { | |||
| this.companyNo = companyNo; | |||
| } | |||
| public Long getEnterpriseId() { | |||
| return enterpriseId; | |||
| } | |||
| public void setEnterpriseId(Long enterpriseId) { | |||
| this.enterpriseId = enterpriseId; | |||
| } | |||
| public long getAppId() { | |||
| return appId; | |||
| } | |||
| public void setAppId(long appId) { | |||
| this.appId = appId; | |||
| } | |||
| public String getEmailAddress() { | |||
| return emailAddress; | |||
| } | |||
| public void setEmailAddress(String emailAddress) { | |||
| this.emailAddress = emailAddress; | |||
| } | |||
| public String getMsgSignature() { | |||
| return msgSignature; | |||
| } | |||
| public void setMsgSignature(String msgSignature) { | |||
| this.msgSignature = msgSignature; | |||
| } | |||
| public String getAccountUUID() { | |||
| return accountUUID; | |||
| } | |||
| public void setAccountUUID(String accountUUID) { | |||
| this.accountUUID = accountUUID; | |||
| } | |||
| public String getAccountSecret() { | |||
| return accountSecret; | |||
| } | |||
| public void setAccountSecret(String accountSecret) { | |||
| this.accountSecret = accountSecret; | |||
| } | |||
| public String getRequestPramString() { | |||
| return requestPramString; | |||
| } | |||
| public void setRequestPramString(String requestPramString) { | |||
| this.requestPramString = requestPramString; | |||
| } | |||
| } | |||
| @@ -0,0 +1,251 @@ | |||
| package com.inet.ailink.receiver.controller; | |||
| import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| import com.inet.ailink.receiver.common.exception.BizException; | |||
| import com.inet.ailink.receiver.common.utils.Base64TeaUitls; | |||
| import com.inet.ailink.receiver.common.utils.JsonUtils; | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import com.inet.ailink.receiver.service.impl.SysAccoountServiceImpl; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.validation.BindingResult; | |||
| import org.springframework.validation.FieldError; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| import java.io.PrintWriter; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| //import com.google.common.primitives.Bytes; | |||
| public abstract class BaseController extends java.beans.PropertyEditorSupport | |||
| { | |||
| /** | |||
| * 子类可以用这个Logger Log4J Logger for this class | |||
| */ | |||
| protected final Logger log = LoggerFactory.getLogger(getClass()); | |||
| //系统统一的提示没有权限访问的界面 | |||
| protected static final String noRight_page="noRight"; | |||
| public final static String KEY_USER = "user"; | |||
| @Autowired | |||
| private SysAccoountServiceImpl sysAccoountServiceImpl; | |||
| // /*@Autowired | |||
| // public RedisClient redisClient; | |||
| // | |||
| // @Autowired | |||
| // public RedisCacheBean redis; | |||
| // | |||
| // @Value("${redis.cacheEnable}") | |||
| // private Boolean cacheEnable;*/ | |||
| // | |||
| // /** | |||
| // * 功能:检查参数的结果处理 | |||
| // * @param result | |||
| // * @throws BizException | |||
| // */ | |||
| // protected void checkParmResultHandler(BindingResult result) throws BizException { | |||
| // if(result.hasErrors()){ | |||
| // StringBuffer sb = new StringBuffer(); | |||
| // List<FieldError> fieldErrorList = result.getFieldErrors(); | |||
| // for(FieldError fieldError : fieldErrorList){ | |||
| // sb.append(fieldError.getField()).append(":").append(fieldError.getDefaultMessage()).append("; "); | |||
| // } | |||
| // throw new BizException(StatusCode.PARAM_CHECK_ERROR.getCode(),sb.toString()); | |||
| // } | |||
| // | |||
| // } | |||
| // | |||
| // /** | |||
| // * 校验消息体签名 | |||
| // * @param request | |||
| // * @param obj | |||
| // * @throws Exception | |||
| // */ | |||
| // protected void checkMsgSignature(HttpServletRequest request, Object obj) throws BizException { | |||
| // WebContext user = WebContext.getWebContext(); | |||
| // String serverMsgSignature = MD5Util.desEncrypt(JsonUtils.toJson(obj), user.getAccountSecret()); | |||
| // if(!serverMsgSignature.substring(0,32).equals(user.getMsgSignature())){ | |||
| // throw new BizException(StatusCode.ACCOUNT_SIGNATURE_ERROR.getCode()); | |||
| // } | |||
| // } | |||
| // | |||
| // /** | |||
| // * @Description 通过request请求中获取用户信息 | |||
| // * @param request | |||
| // * @return | |||
| // * @throws BizException | |||
| // * @throws NumberFormatException | |||
| // */ | |||
| // protected SysAccount getUser(HttpServletRequest request) throws NumberFormatException, BizException { | |||
| // | |||
| // SysAccount account = new SysAccount(); | |||
| // if (StringUtils.isNotBlank(request.getHeader("token"))) { | |||
| // account = sysAccoountServiceImpl.get(Long.parseLong(request.getHeader("token"))); | |||
| // } | |||
| // return account; | |||
| // } | |||
| // | |||
| // protected Long getAppId(HttpServletRequest request) throws BizException{ | |||
| // if (StringUtils.isNotBlank(request.getHeader("appId"))) { | |||
| // return Long.parseLong(request.getHeader("appId")); | |||
| // }else{ | |||
| // throw new BizException(StatusCode.COMPANY_NOT_EXIST); | |||
| // } | |||
| // } | |||
| /** | |||
| * 写回加密数据 | |||
| * @param response | |||
| * @param result | |||
| * @throws IOException | |||
| */ | |||
| public void writeOutResponse(HttpServletResponse response, Response<Object> result) throws IOException{ | |||
| response.setHeader("Access-Control-Allow-Origin",""); | |||
| response.setHeader("Access-Control-Allow-Credentials",""); | |||
| response.setHeader("Access-Control-Allow-Methods",""); | |||
| response.setHeader("Access-Control-Max-Age",""); | |||
| response.setHeader("Access-Control-Allow-Headers",""); | |||
| response.setHeader("X-Application-Context",""); | |||
| response.setHeader("Transfer-Encoding", ""); | |||
| PrintWriter out = response.getWriter(); | |||
| if(result.getData() != null){ | |||
| String dataValue = result.getData().toString(); | |||
| result.setData(Base64TeaUitls.encrypt(dataValue)); | |||
| } | |||
| String resultJson = JsonUtils.toJson(result); | |||
| response.setHeader("ResponseBodySize", resultJson.length()+""); | |||
| out.write(resultJson); | |||
| out.flush(); | |||
| out.close(); | |||
| } | |||
| /** | |||
| * 写回正常数据 | |||
| * @param response | |||
| * @param result | |||
| * @throws IOException | |||
| */ | |||
| public void writeOutResponseNoEncrypt(HttpServletResponse response, Response<Object> result) throws IOException{ | |||
| response.setHeader("Access-Control-Allow-Origin",""); | |||
| response.setHeader("Access-Control-Allow-Credentials",""); | |||
| response.setHeader("Access-Control-Allow-Methods",""); | |||
| response.setHeader("Access-Control-Max-Age",""); | |||
| response.setHeader("Access-Control-Allow-Headers",""); | |||
| response.setHeader("X-Application-Context",""); | |||
| // response.setHeader("Transfer-Encoding", "chunked"); | |||
| //response.setBufferSize(result.toString().length()); | |||
| String resultJson = JsonUtils.toJson(result); | |||
| response.setHeader("ResponseBodySize", resultJson.length()+""); | |||
| PrintWriter out = response.getWriter(); | |||
| out.write(resultJson); | |||
| out.flush(); | |||
| out.close(); | |||
| } | |||
| /** | |||
| * 写回任意原始数据 | |||
| * @param response | |||
| * @param result | |||
| * @throws IOException | |||
| */ | |||
| public void writeOutResponseOld(HttpServletResponse response, String result) throws IOException{ | |||
| response.setHeader("Access-Control-Allow-Origin",""); | |||
| response.setHeader("Access-Control-Allow-Credentials",""); | |||
| response.setHeader("Access-Control-Allow-Methods",""); | |||
| response.setHeader("Access-Control-Max-Age",""); | |||
| response.setHeader("Access-Control-Allow-Headers",""); | |||
| response.setHeader("X-Application-Context",""); | |||
| response.setHeader("Transfer-Encoding", ""); | |||
| response.setHeader("ResponseBodySize", result.length()+""); | |||
| PrintWriter out = response.getWriter(); | |||
| out.write(result); | |||
| out.flush(); | |||
| out.close(); | |||
| } | |||
| /** | |||
| * 写回数据解析失败数据 | |||
| * @param response | |||
| * @param result | |||
| * @throws IOException | |||
| */ | |||
| public void writeOutResponse(HttpServletResponse response, byte[] paramsByte) throws IOException { | |||
| Response<Object> result = new Response<Object>(); | |||
| result.setStatus(paramsByte[0]+""); | |||
| response.setHeader("Access-Control-Allow-Origin",""); | |||
| response.setHeader("Access-Control-Allow-Credentials",""); | |||
| response.setHeader("Access-Control-Allow-Methods",""); | |||
| response.setHeader("Access-Control-Max-Age",""); | |||
| response.setHeader("Access-Control-Allow-Headers",""); | |||
| response.setHeader("X-Application-Context",""); | |||
| response.setHeader("Transfer-Encoding", ""); | |||
| String resultJson = JsonUtils.toJson(result); | |||
| response.setHeader("ResponseBodySize", resultJson.length()+""); | |||
| PrintWriter out = response.getWriter(); | |||
| out.write(resultJson); | |||
| out.flush(); | |||
| out.close(); | |||
| } | |||
| /** | |||
| * 校验参数是否为空 | |||
| * @param response | |||
| * @param params | |||
| * @throws IOException | |||
| */ | |||
| public void checkParams(HttpServletResponse response, String params) throws IOException{ | |||
| Response<Object> result = new Response<Object>(); | |||
| if(params == null || params.isEmpty() || params.equals("")){ | |||
| result.setStatus(StatusCode.PARAM_EMPTY.getCode()); | |||
| writeOutResponse(response, result); | |||
| } | |||
| } | |||
| /** | |||
| * 解密数据 | |||
| * @param params | |||
| * @return | |||
| * @throws IOException | |||
| */ | |||
| public byte[] decryptParams(HttpServletResponse response, String params) throws IOException{ | |||
| //解密数据失败 | |||
| byte[] paramsByte = new byte[]{}; | |||
| //数据格式不正确 | |||
| Map<String,String> paramsMap = new HashMap<String, String>(); | |||
| try { | |||
| paramsMap = JsonUtils.fromJson(params, Map.class); | |||
| // System.out.println("decryptParams() paramsMap: " + paramsMap); | |||
| } catch (Exception e) { | |||
| paramsByte = new byte[]{(byte) Integer.parseInt(StatusCode.PARAMS_JSON_ERROR.getCode())}; | |||
| // System.out.println("decryptParams() Exception: " + e); | |||
| return paramsByte; | |||
| } | |||
| //关键参数字段获取失败 | |||
| String paramsValue = paramsMap.get("params"); | |||
| // System.out.println("decryptParams() paramsValue: " + paramsValue); | |||
| if(paramsValue == null || paramsValue.equals("")){ | |||
| paramsByte = new byte[]{(byte) Integer.parseInt(StatusCode.PARAMS_JSON_KEY_ERROR.getCode())}; | |||
| return paramsByte; | |||
| } | |||
| try { | |||
| paramsByte = Base64TeaUitls.decrypt(paramsValue); | |||
| // System.out.println("decryptParams() paramsByte: " + paramsByte); | |||
| } catch (Exception e) { | |||
| paramsByte = new byte[]{(byte) Integer.parseInt(StatusCode.PARAMS_dECRYPT_ERROR.getCode())}; | |||
| // System.out.println("decryptParams() paramsByte2: " + paramsByte); | |||
| return paramsByte; | |||
| } | |||
| return paramsByte; | |||
| } | |||
| } | |||
| @@ -0,0 +1,50 @@ | |||
| package com.inet.ailink.receiver.controller; | |||
| import com.inet.ailink.receiver.service.impl.BodyFatServiceImpl; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.ResponseBody; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| @RestController | |||
| @RequestMapping(value="bodyFat",produces={"application/json;charset=UTF-8"}) | |||
| public class BodyFatController extends BaseController { | |||
| @Autowired | |||
| private BodyFatServiceImpl bodyFatServiceImpl; | |||
| /** | |||
| * 上报称重数据(原始数据) | |||
| * @param params | |||
| * @param request | |||
| * @param response | |||
| * @throws IOException | |||
| */ | |||
| @RequestMapping(value="saveWeighDataByAdc") | |||
| @ResponseBody | |||
| public void saveWeighDataByAdc(@RequestBody String params, HttpServletRequest request, HttpServletResponse response) throws IOException { | |||
| checkParams(response, params); | |||
| // System.out.println("saveWeighDataByAdc() params: " + params); | |||
| byte[] paramsByte = decryptParams(response,params); | |||
| if(paramsByte.length >1){ | |||
| writeOutResponse(response, bodyFatServiceImpl.saveWeighDataByAdc(paramsByte, request)); | |||
| }else{ | |||
| writeOutResponse(response,paramsByte); | |||
| } | |||
| } | |||
| /* | |||
| 注意:接口返回的数据格式必须如下,status在前,data在后,必须都带双引号的字符串;如调换字段属性,则设备无法解析返回的数据 | |||
| { | |||
| "status": "1", | |||
| "data": "Utc/CU/SEQ4=" | |||
| } | |||
| */ | |||
| } | |||
| @@ -0,0 +1,97 @@ | |||
| package com.inet.ailink.receiver.controller; | |||
| import com.inet.ailink.receiver.service.impl.SysAccoountServiceImpl; | |||
| import com.inet.ailink.receiver.service.impl.SysDeviceInfoServiceImpl; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.ResponseBody; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| @RestController | |||
| //@RequestMapping(value="devivce",produces={"application/json;charset=UTF-8"}) | |||
| @RequestMapping(value="devivce") | |||
| public class DeviceController extends BaseController { | |||
| @Autowired | |||
| private SysDeviceInfoServiceImpl sysDeviceInfoServiceImpl; | |||
| @Autowired | |||
| private SysAccoountServiceImpl sysAccoountServiceImpl; | |||
| /** | |||
| * 设备注册 | |||
| * @param params | |||
| * @param request | |||
| * @param response | |||
| * @throws IOException | |||
| */ | |||
| @RequestMapping(value="register") | |||
| @ResponseBody | |||
| public void register(@RequestBody String params, HttpServletRequest request, HttpServletResponse response) throws IOException { | |||
| checkParams(response, params); | |||
| // System.out.println("devivce/register() params: " + params); | |||
| byte[] paramsByte = decryptParams(response,params); | |||
| if(paramsByte.length >1){ | |||
| writeOutResponse(response, sysDeviceInfoServiceImpl.register(paramsByte, request)); | |||
| }else{ | |||
| writeOutResponse(response,paramsByte); | |||
| } | |||
| } | |||
| /* | |||
| * 注意:接口返回的数据格式必须如下,status在前,data在后,必须都带双引号的字符串;如调换字段属性,则设备无法解析返回的数据 | |||
| { | |||
| "status": "1", | |||
| "data": "QZ9Tceq4fWY=" | |||
| } | |||
| * */ | |||
| /** | |||
| * 获取设备绑定的用户 | |||
| * @param params | |||
| * @param request | |||
| * @param response | |||
| * @throws IOException | |||
| */ | |||
| @RequestMapping(value="getUsers") | |||
| @ResponseBody | |||
| public void getUsers(@RequestBody String params, HttpServletRequest request, HttpServletResponse response) throws IOException { | |||
| checkParams(response, params); | |||
| byte[] paramsByte = decryptParams(response,params); | |||
| if(paramsByte.length >1){ | |||
| writeOutResponseNoEncrypt(response, sysAccoountServiceImpl.getUsersByDeviceId(paramsByte, request)); | |||
| }else{ | |||
| writeOutResponse(response,paramsByte); | |||
| } | |||
| } | |||
| /* | |||
| 注意:接口返回的数据格式必须如下,status在前,data在后,带双引号和不带双引号的要看清;如调换字段属性,则设备无法解析返回的数据; | |||
| 这个接口不加密,和另外2个接口返回的数据经过TEA加解密不同 | |||
| { | |||
| "status": "1", | |||
| "data": [ | |||
| [ | |||
| 1024, //绑定wifi秤的用户id | |||
| 1, //性别:0:女;1:男 | |||
| 25, //年龄 | |||
| "170", //身高 | |||
| "0", //身高单位;0:cm;1:inch;2:ft-in | |||
| "0", //体重单位;0:kg;1:斤;4:st:lb;6:lb | |||
| 0, //用户类型:0:普通人;1:业余运动员;2:专业运动员;3:孕妇 | |||
| "67.70" //绑定wifi秤的用户的最新的体重 | |||
| ] | |||
| ] | |||
| } | |||
| * */ | |||
| } | |||
| @@ -0,0 +1,95 @@ | |||
| package com.inet.ailink.receiver.entity; | |||
| import java.util.Date; | |||
| @SuppressWarnings("serial") | |||
| public class BaseEntity extends SearchParm{ | |||
| public static final String ALIAS_VERSION_NUMBER = "" ; | |||
| public static final String ALIAS_DEL_STATUS = ""; | |||
| public static final String ALIAS_REMARK = "备注"; | |||
| public static final String ALIAS_CREATE_ID = "创建者ID"; | |||
| public static final String ALIAS_CREATOR = ""; | |||
| public static final String ALIAS_CREATE_TIME = "创建时间"; | |||
| public static final String ALIAS_UPDATE_ID = ""; | |||
| public static final String ALIAS_UPDATOR = ""; | |||
| public static final String ALIAS_UPDATE_TIME = ""; | |||
| protected Integer delStatus; | |||
| protected Long id; | |||
| protected String remark; | |||
| protected Long createUserId; | |||
| protected String creatorName; | |||
| protected Date createTime; | |||
| protected Long updateUserId; | |||
| protected String updatorName; | |||
| protected Date updateTime; | |||
| protected Long appId; | |||
| protected String companyNo; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public String getRemark() { | |||
| return remark; | |||
| } | |||
| public void setRemark(String remark) { | |||
| this.remark = remark; | |||
| } | |||
| public Date getCreateTime() { | |||
| return createTime; | |||
| } | |||
| public void setCreateTime(Date createTime) { | |||
| this.createTime = createTime; | |||
| } | |||
| public Date getUpdateTime() { | |||
| return updateTime; | |||
| } | |||
| public void setUpdateTime(Date updateTime) { | |||
| this.updateTime = updateTime; | |||
| } | |||
| public Integer getDelStatus() { | |||
| return delStatus; | |||
| } | |||
| public void setDelStatus(Integer delStatus) { | |||
| this.delStatus = delStatus; | |||
| } | |||
| public String getCreatorName() { | |||
| return creatorName; | |||
| } | |||
| public void setCreatorName(String creatorName) { | |||
| this.creatorName = creatorName; | |||
| } | |||
| public String getUpdatorName() { | |||
| return updatorName; | |||
| } | |||
| public void setUpdatorName(String updatorName) { | |||
| this.updatorName = updatorName; | |||
| } | |||
| public Long getCreateUserId() { | |||
| return createUserId; | |||
| } | |||
| public void setCreateUserId(Long createUserId) { | |||
| this.createUserId = createUserId; | |||
| } | |||
| public Long getUpdateUserId() { | |||
| return updateUserId; | |||
| } | |||
| public void setUpdateUserId(Long updateUserId) { | |||
| this.updateUserId = updateUserId; | |||
| } | |||
| public Long getAppId() { | |||
| return appId; | |||
| } | |||
| public void setAppId(Long appId) { | |||
| this.appId = appId; | |||
| } | |||
| public String getCompanyNo() { | |||
| return companyNo; | |||
| } | |||
| public void setCompanyNo(String companyNo) { | |||
| this.companyNo = companyNo; | |||
| } | |||
| } | |||
| @@ -0,0 +1,275 @@ | |||
| package com.inet.ailink.receiver.entity; | |||
| //import com.inet.base.entity.BaseEntity; | |||
| import java.util.Date; | |||
| public class BodyFat extends BaseEntity { | |||
| private Integer bodyFatId;//数据id | |||
| private Integer appUserId;//账号id | |||
| private Integer subUserId;//子用户id | |||
| private Integer deviceId;// 设备id | |||
| private String weight;//体重 | |||
| private String weightUnit;//体重单位 | |||
| private String weightPoint;//体重小数点 | |||
| private String bmi;//体质指数 | |||
| private String bfr;//体脂率 | |||
| private String sfr;//皮下脂肪率 | |||
| private String uvi;//内脏脂肪率 | |||
| private String rom;//肌肉率 | |||
| private String bmr;//基础代谢率 | |||
| private String bm;//骨骼质量 | |||
| private String vwc;//水含量 | |||
| private String bodyAge;//身体年龄 | |||
| private String pp;//蛋白率 | |||
| private String adc;//阻抗 | |||
| private Date uploadTime;//上传时间 | |||
| private String heartRate;//心率 | |||
| private String deviceAlgorithm;//算法 | |||
| private Long createTimeLong; | |||
| private Integer calculationTimes;//计算次数 | |||
| private Integer source;// 数据来源;1:WIFI/4G称 | |||
| public BodyFat(){} | |||
| public BodyFat(Integer deviceId, | |||
| String weight, String weightUnit, String weightPoint, String adc, | |||
| Date uploadTime, String heartRate, String deviceAlgorithm, Integer subUserId) { | |||
| super(); | |||
| this.deviceId = deviceId; | |||
| this.weight = weight; | |||
| this.weightUnit = weightUnit; | |||
| this.weightPoint = weightPoint; | |||
| this.adc = adc; | |||
| this.uploadTime = uploadTime; | |||
| this.heartRate = heartRate; | |||
| this.deviceAlgorithm = deviceAlgorithm; | |||
| this.subUserId = subUserId; | |||
| } | |||
| public Long getCreateTimeLong() { | |||
| return createTimeLong; | |||
| } | |||
| public void setCreateTimeLong(Long createTimeLong) { | |||
| this.createTimeLong = createTimeLong; | |||
| } | |||
| public Integer getBodyFatId() { | |||
| return bodyFatId; | |||
| } | |||
| public void setBodyFatId(Integer bodyFatId) { | |||
| this.bodyFatId = bodyFatId; | |||
| } | |||
| public Integer getAppUserId() { | |||
| return appUserId; | |||
| } | |||
| public void setAppUserId(Integer appUserId) { | |||
| this.appUserId = appUserId; | |||
| } | |||
| public Integer getSubUserId() { | |||
| return subUserId; | |||
| } | |||
| public void setSubUserId(Integer subUserId) { | |||
| this.subUserId = subUserId; | |||
| } | |||
| public Integer getDeviceId() { | |||
| return deviceId; | |||
| } | |||
| public void setDeviceId(Integer deviceId) { | |||
| this.deviceId = deviceId; | |||
| } | |||
| public String getWeight() { | |||
| return weight; | |||
| } | |||
| public void setWeight(String weight) { | |||
| this.weight = weight; | |||
| } | |||
| public String getWeightUnit() { | |||
| return weightUnit; | |||
| } | |||
| public void setWeightUnit(String weightUnit) { | |||
| this.weightUnit = weightUnit; | |||
| } | |||
| public String getWeightPoint() { | |||
| return weightPoint; | |||
| } | |||
| public void setWeightPoint(String weightPoint) { | |||
| this.weightPoint = weightPoint; | |||
| } | |||
| public String getBmi() { | |||
| return bmi; | |||
| } | |||
| public void setBmi(String bmi) { | |||
| this.bmi = bmi; | |||
| } | |||
| public String getBfr() { | |||
| return bfr; | |||
| } | |||
| public void setBfr(String bfr) { | |||
| this.bfr = bfr; | |||
| } | |||
| public String getSfr() { | |||
| return sfr; | |||
| } | |||
| public void setSfr(String sfr) { | |||
| this.sfr = sfr; | |||
| } | |||
| public String getUvi() { | |||
| return uvi; | |||
| } | |||
| public void setUvi(String uvi) { | |||
| this.uvi = uvi; | |||
| } | |||
| public String getRom() { | |||
| return rom; | |||
| } | |||
| public void setRom(String rom) { | |||
| this.rom = rom; | |||
| } | |||
| public String getBmr() { | |||
| return bmr; | |||
| } | |||
| public void setBmr(String bmr) { | |||
| this.bmr = bmr; | |||
| } | |||
| public String getBm() { | |||
| return bm; | |||
| } | |||
| public void setBm(String bm) { | |||
| this.bm = bm; | |||
| } | |||
| public String getVwc() { | |||
| return vwc; | |||
| } | |||
| public void setVwc(String vwc) { | |||
| this.vwc = vwc; | |||
| } | |||
| public String getBodyAge() { | |||
| return bodyAge; | |||
| } | |||
| public void setBodyAge(String bodyAge) { | |||
| this.bodyAge = bodyAge; | |||
| } | |||
| public String getPp() { | |||
| return pp; | |||
| } | |||
| public void setPp(String pp) { | |||
| this.pp = pp; | |||
| } | |||
| public String getAdc() { | |||
| return adc; | |||
| } | |||
| public void setAdc(String adc) { | |||
| this.adc = adc; | |||
| } | |||
| public Date getUploadTime() { | |||
| return uploadTime; | |||
| } | |||
| public void setUploadTime(Date uploadTime) { | |||
| this.uploadTime = uploadTime; | |||
| } | |||
| public String getHeartRate() { | |||
| return heartRate; | |||
| } | |||
| public void setHeartRate(String heartRate) { | |||
| this.heartRate = heartRate; | |||
| } | |||
| public String getDeviceAlgorithm() { | |||
| return deviceAlgorithm; | |||
| } | |||
| public void setDeviceAlgorithm(String deviceAlgorithm) { | |||
| this.deviceAlgorithm = deviceAlgorithm; | |||
| } | |||
| public Integer getCalculationTimes() { | |||
| return calculationTimes; | |||
| } | |||
| public Integer getSource() { | |||
| return source; | |||
| } | |||
| public void setCalculationTimes(Integer calculationTimes) { | |||
| this.calculationTimes = calculationTimes; | |||
| } | |||
| public void setSource(Integer source) { | |||
| this.source = source; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return "BodyFat{" + | |||
| "bodyFatId=" + bodyFatId + | |||
| ", appUserId=" + appUserId + | |||
| ", subUserId=" + subUserId + | |||
| ", deviceId=" + deviceId + | |||
| ", weight='" + weight + '\'' + | |||
| ", weightUnit='" + weightUnit + '\'' + | |||
| ", weightPoint='" + weightPoint + '\'' + | |||
| ", bmi='" + bmi + '\'' + | |||
| ", bfr='" + bfr + '\'' + | |||
| ", sfr='" + sfr + '\'' + | |||
| ", uvi='" + uvi + '\'' + | |||
| ", rom='" + rom + '\'' + | |||
| ", bmr='" + bmr + '\'' + | |||
| ", bm='" + bm + '\'' + | |||
| ", vwc='" + vwc + '\'' + | |||
| ", bodyAge='" + bodyAge + '\'' + | |||
| ", pp='" + pp + '\'' + | |||
| ", adc='" + adc + '\'' + | |||
| ", uploadTime=" + uploadTime + | |||
| ", heartRate='" + heartRate + '\'' + | |||
| ", deviceAlgorithm='" + deviceAlgorithm + '\'' + | |||
| ", createTimeLong=" + createTimeLong + | |||
| ", calculationTimes=" + calculationTimes + | |||
| ", source=" + source + | |||
| '}'; | |||
| } | |||
| } | |||
| @@ -0,0 +1,175 @@ | |||
| package com.inet.ailink.receiver.entity; | |||
| // import com.inet.base.entity.BaseEntity; | |||
| import java.util.Date; | |||
| @SuppressWarnings("serial") | |||
| public class Device extends BaseEntity { | |||
| private Integer deviceId; | |||
| private Integer roomId; | |||
| private String deviceName; | |||
| private String mac; | |||
| private Date createTime; | |||
| private Integer cid; | |||
| private Integer pid; | |||
| private Integer vid; | |||
| private String supportUnit; | |||
| private String deviceModel; | |||
| private String version; | |||
| private String hardwareVersion; | |||
| private String userAutoVersion; | |||
| private String deviceTime; | |||
| private String chipId; | |||
| private String deviceSN; | |||
| private String deviceUnit; | |||
| private Integer appUserId; | |||
| public Device(){} | |||
| public Device(String deviceName, | |||
| String mac, Date createTime, Integer cid, Integer pid, Integer vid, | |||
| String supportUnit, String deviceModel, String version, String hardwareVersion, | |||
| String userAutoVersion, String deviceTime, String chipId, String deviceSN, String deviceUnit) { | |||
| super(); | |||
| this.deviceName = deviceName; | |||
| this.mac = mac; | |||
| this.createTime = createTime; | |||
| this.cid = cid; | |||
| this.pid = pid; | |||
| this.vid = vid; | |||
| this.supportUnit = supportUnit; | |||
| this.deviceModel = deviceModel; | |||
| this.version = version; | |||
| this.hardwareVersion = hardwareVersion; | |||
| this.userAutoVersion = userAutoVersion; | |||
| this.deviceTime = deviceTime; | |||
| this.chipId = chipId; | |||
| this.deviceSN = deviceSN; | |||
| this.deviceUnit = deviceUnit; | |||
| } | |||
| public String getDeviceModel() { | |||
| return deviceModel; | |||
| } | |||
| public void setDeviceModel(String deviceModel) { | |||
| this.deviceModel = deviceModel; | |||
| } | |||
| public String getHardwareVersion() { | |||
| return hardwareVersion; | |||
| } | |||
| public void setHardwareVersion(String hardwareVersion) { | |||
| this.hardwareVersion = hardwareVersion; | |||
| } | |||
| public String getUserAutoVersion() { | |||
| return userAutoVersion; | |||
| } | |||
| public void setUserAutoVersion(String userAutoVersion) { | |||
| this.userAutoVersion = userAutoVersion; | |||
| } | |||
| public String getDeviceTime() { | |||
| return deviceTime; | |||
| } | |||
| public void setDeviceTime(String deviceTime) { | |||
| this.deviceTime = deviceTime; | |||
| } | |||
| public Integer getDeviceId() { | |||
| return deviceId; | |||
| } | |||
| public void setDeviceId(Integer deviceId) { | |||
| this.deviceId = deviceId; | |||
| } | |||
| public Integer getRoomId() { | |||
| return roomId; | |||
| } | |||
| public void setRoomId(Integer roomId) { | |||
| this.roomId = roomId; | |||
| } | |||
| public String getDeviceName() { | |||
| return deviceName; | |||
| } | |||
| public void setDeviceName(String deviceName) { | |||
| this.deviceName = deviceName; | |||
| } | |||
| public String getMac() { | |||
| return mac; | |||
| } | |||
| public void setMac(String mac) { | |||
| this.mac = mac; | |||
| } | |||
| public Date getCreateTime() { | |||
| return createTime; | |||
| } | |||
| public void setCreateTime(Date createTime) { | |||
| this.createTime = createTime; | |||
| } | |||
| public Integer getCid() { | |||
| return cid; | |||
| } | |||
| public void setCid(Integer cid) { | |||
| this.cid = cid; | |||
| } | |||
| public Integer getPid() { | |||
| return pid; | |||
| } | |||
| public void setPid(Integer pid) { | |||
| this.pid = pid; | |||
| } | |||
| public Integer getVid() { | |||
| return vid; | |||
| } | |||
| public void setVid(Integer vid) { | |||
| this.vid = vid; | |||
| } | |||
| public String getSupportUnit() { | |||
| return supportUnit; | |||
| } | |||
| public void setSupportUnit(String supportUnit) { | |||
| this.supportUnit = supportUnit; | |||
| } | |||
| public String getVersion() { | |||
| return version; | |||
| } | |||
| public void setVersion(String version) { | |||
| this.version = version; | |||
| } | |||
| public String getChipId() { | |||
| return chipId; | |||
| } | |||
| public void setChipId(String chipId) { | |||
| this.chipId = chipId; | |||
| } | |||
| public String getDeviceSN() { | |||
| return deviceSN; | |||
| } | |||
| public void setDeviceSN(String deviceSN) { | |||
| this.deviceSN = deviceSN; | |||
| } | |||
| public String getDeviceUnit() { | |||
| return deviceUnit; | |||
| } | |||
| public void setDeviceUnit(String deviceUnit) { | |||
| this.deviceUnit = deviceUnit; | |||
| } | |||
| public Integer getAppUserId() { | |||
| return appUserId; | |||
| } | |||
| public void setAppUserId(Integer appUserId) { | |||
| this.appUserId = appUserId; | |||
| } | |||
| } | |||
| @@ -0,0 +1,88 @@ | |||
| /** | |||
| * Copyright (c) 2017-2017 andes.com | |||
| * Licensed under the Apache License, Version 1.0 (the "License"); | |||
| */ | |||
| package com.inet.ailink.receiver.entity; | |||
| /** | |||
| * @author jason group | |||
| * @version 1.0 | |||
| * @since 1.0 | |||
| */ | |||
| // import com.inet.base.entity.BaseEntity; | |||
| @SuppressWarnings("serial") | |||
| public class DeviceType extends BaseEntity { | |||
| //alias | |||
| public static final String TABLE_ALIAS = "DeviceType"; | |||
| public static final String ALIAS_TYPE_ID = "typeId"; | |||
| public static final String ALIAS_DEVICE_NAME = "deviceName"; | |||
| public static final String ALIAS_DEVICE_IMAGE = "deviceImage"; | |||
| public static final String ALIAS_GROUP_ID = "groupId"; | |||
| public static final String ALIAS_GROUP_NAME = "groupName"; | |||
| //columns START | |||
| private String typeId; | |||
| private String deviceName; | |||
| private String deviceImage; | |||
| private String groupId; | |||
| private String groupName; | |||
| private String deviceServerUrl; | |||
| //columns END | |||
| public DeviceType(){ | |||
| } | |||
| public void setTypeId(String value) { | |||
| this.typeId = value; | |||
| } | |||
| public String getTypeId() { | |||
| return this.typeId; | |||
| } | |||
| public void setDeviceName(String value) { | |||
| this.deviceName = value; | |||
| } | |||
| public String getDeviceName() { | |||
| return this.deviceName; | |||
| } | |||
| public void setDeviceImage(String value) { | |||
| this.deviceImage = value; | |||
| } | |||
| public String getDeviceImage() { | |||
| return this.deviceImage; | |||
| } | |||
| public void setGroupId(String value) { | |||
| this.groupId = value; | |||
| } | |||
| public String getGroupId() { | |||
| return this.groupId; | |||
| } | |||
| public void setGroupName(String value) { | |||
| this.groupName = value; | |||
| } | |||
| public String getGroupName() { | |||
| return this.groupName; | |||
| } | |||
| public String getDeviceServerUrl() { | |||
| return deviceServerUrl; | |||
| } | |||
| public void setDeviceServerUrl(String deviceServerUrl) { | |||
| this.deviceServerUrl = deviceServerUrl; | |||
| } | |||
| } | |||
| /**/ | |||
| @@ -0,0 +1,52 @@ | |||
| package com.inet.ailink.receiver.entity; | |||
| public class PageParm { | |||
| private Integer start; | |||
| private Integer pageNum; | |||
| private Integer pageSize; | |||
| private Integer isQueryNum; | |||
| private Integer isUsePage; | |||
| public Integer getStart() { | |||
| return start; | |||
| } | |||
| public void setStart(Integer start) { | |||
| this.start = start; | |||
| } | |||
| public Integer getPageNum() { | |||
| return pageNum; | |||
| } | |||
| public void setPageNum(Integer pageNum) { | |||
| this.pageNum = pageNum; | |||
| } | |||
| public Integer getPageSize() { | |||
| return pageSize; | |||
| } | |||
| public void setPageSize(Integer pageSize) { | |||
| this.pageSize = pageSize; | |||
| } | |||
| public Integer getIsQueryNum() { | |||
| return isQueryNum; | |||
| } | |||
| public void setIsQueryNum(Integer isQueryNum) { | |||
| this.isQueryNum = isQueryNum; | |||
| } | |||
| public Integer getIsUsePage() { | |||
| return isUsePage; | |||
| } | |||
| public void setIsUsePage(Integer isUsePage) { | |||
| this.isUsePage = isUsePage; | |||
| } | |||
| } | |||
| @@ -0,0 +1,72 @@ | |||
| package com.inet.ailink.receiver.entity; | |||
| //import org.apache.commons.collections.CollectionUtils; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.List; | |||
| public class PageResult <T> { | |||
| private List<T> list; | |||
| private Integer pageNum; | |||
| private Integer pageSize; | |||
| private Integer total; | |||
| private Integer pages; | |||
| public List<T> getList() { | |||
| if (isEmpty(list)) { | |||
| return new ArrayList<T>(); | |||
| } | |||
| return list; | |||
| } | |||
| public static boolean isEmpty(Collection coll) { | |||
| return (coll == null || coll.isEmpty()); | |||
| } | |||
| public void setList(List<T> list) { | |||
| this.list = list; | |||
| } | |||
| public Integer getPageNum() { | |||
| return pageNum; | |||
| } | |||
| public void setPageNum(Integer pageNum) { | |||
| this.pageNum = pageNum; | |||
| } | |||
| public Integer getPageSize() { | |||
| return pageSize; | |||
| } | |||
| public void setPageSize(Integer pageSize) { | |||
| this.pageSize = pageSize; | |||
| } | |||
| public Integer getTotal() { | |||
| return total; | |||
| } | |||
| public void setTotal(Integer total) { | |||
| this.total = total; | |||
| } | |||
| public Integer getPages() { | |||
| return pages; | |||
| } | |||
| public void setPages(Integer pages) { | |||
| this.pages = pages; | |||
| } | |||
| } | |||
| @@ -0,0 +1,44 @@ | |||
| package com.inet.ailink.receiver.entity; | |||
| public class SearchParm extends PageParm{ | |||
| private String searchStartTime; | |||
| private String searchEndTime; | |||
| private String searchKeyWord; | |||
| private String sortColumns; | |||
| protected Long maxId; | |||
| public String getSearchStartTime() { | |||
| return searchStartTime; | |||
| } | |||
| public void setSearchStartTime(String searchStartTime) { | |||
| this.searchStartTime = searchStartTime; | |||
| } | |||
| public String getSearchEndTime() { | |||
| return searchEndTime; | |||
| } | |||
| public void setSearchEndTime(String searchEndTime) { | |||
| this.searchEndTime = searchEndTime; | |||
| } | |||
| public String getSearchKeyWord() { | |||
| return searchKeyWord; | |||
| } | |||
| public void setSearchKeyWord(String searchKeyWord) { | |||
| this.searchKeyWord = searchKeyWord; | |||
| } | |||
| public String getSortColumns() { | |||
| return sortColumns; | |||
| } | |||
| public void setSortColumns(String sortColumns) { | |||
| this.sortColumns = sortColumns; | |||
| } | |||
| public Long getMaxId() { | |||
| return maxId; | |||
| } | |||
| public void setMaxId(Long maxId) { | |||
| this.maxId = maxId; | |||
| } | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| package com.inet.ailink.receiver.mapper; | |||
| import java.util.List; | |||
| public interface BaseDao<E> { | |||
| public E getById(Long id); | |||
| public List<E> getByIds(List<Long> ids); | |||
| public List<E> getAll(); | |||
| public List<E> getObjByAttribute(Object entity); | |||
| public int delete(Long id); | |||
| public int insert(E entity); | |||
| public int update(E entity); | |||
| public int insertBatch(List<E> entity); | |||
| public int updateBatch(List<E> entity); | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| package com.inet.ailink.receiver.mapper; | |||
| import com.inet.ailink.receiver.entity.BodyFat; | |||
| public interface IBodyFatDao extends BaseDao<BodyFat> { | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| package com.inet.ailink.receiver.mapper; | |||
| import com.inet.ailink.receiver.entity.Device; | |||
| import com.inet.ailink.receiver.entity.DeviceType; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import java.util.List; | |||
| public interface ISysDeviceInfoDao extends BaseDao<Device> { | |||
| public Integer getAppUserIdByDevice(Device device); | |||
| public DeviceType getDeviceTypeByCid(@Param(value = "typeId") Integer typeId); | |||
| public String getServerUrlByPIDCIDVID(Device device); | |||
| public Device getLastObjByAttribute(Device device); | |||
| public Integer getLastOneDeviceAppUserIdByDevice(Device device); | |||
| public List<Integer> getDeviceAppUserIdByDevice(Device device); | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| /** | |||
| * | |||
| */ | |||
| package com.inet.ailink.receiver.service; | |||
| import com.inet.ailink.receiver.common.exception.BizException; | |||
| import java.util.List; | |||
| public interface IBaseService<E>{ | |||
| public int update(E entity) throws BizException; | |||
| public int save(List<E> entityList) throws BizException; | |||
| public int save(E entity) throws BizException; | |||
| E get(Long id) throws BizException; | |||
| int remove(Long id) throws BizException; | |||
| public List<E> selectListObjByAttribute(Object entity) throws BizException; | |||
| } | |||
| @@ -0,0 +1,128 @@ | |||
| package com.inet.ailink.receiver.service.impl; | |||
| import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| import com.inet.ailink.receiver.common.exception.BizException; | |||
| import com.inet.ailink.receiver.common.utils.DateUtils; | |||
| import com.inet.ailink.receiver.common.vo.WebContext; | |||
| import com.inet.ailink.receiver.entity.BaseEntity; | |||
| import com.inet.ailink.receiver.mapper.BaseDao; | |||
| import com.inet.ailink.receiver.service.IBaseService; | |||
| //import com.inet.base.entity.BaseEntity; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| public abstract class BaseServiceImpl<DAO extends BaseDao<E>, E extends BaseEntity> implements IBaseService<E> { | |||
| protected Logger log = LoggerFactory.getLogger(getClass()); | |||
| protected abstract DAO getEntityDao(); | |||
| public E get(Long id) throws BizException { | |||
| return (E)getEntityDao().getById(id); | |||
| } | |||
| public int update(E entity) throws BizException { | |||
| int updateCount = 0; | |||
| if(null!=entity.getId()){ | |||
| updateCount = save(entity); | |||
| } | |||
| if(updateCount==0){ | |||
| log.error("update count zero : "+entity.toString()); | |||
| throw new BizException(StatusCode.DAO_UPDATE_COUNT_ZERO_EXCEPTION); | |||
| } | |||
| return updateCount; | |||
| } | |||
| public int save(E entity) throws BizException { | |||
| if(null!=entity){ | |||
| try{ | |||
| if(null==entity.getId()){ | |||
| entity.setDelStatus(0);//默认不删除: 0未删�? 1删除 | |||
| if(null != entity.getCreateUserId()){ | |||
| entity.setCreateUserId(entity.getCreateUserId()); | |||
| }else{ | |||
| entity.setCreateUserId(0L); | |||
| } | |||
| //entity.setCreatorName(WebContext.getWebContext().getUserName()==null?"system":WebContext.getWebContext().getUserName().toString()); | |||
| entity.setCreateTime(DateUtils.currentDate()); | |||
| //entity.setVersionNumber(1L); | |||
| return getEntityDao().insert(entity); | |||
| }else{ | |||
| //更新的时候传入版本号,做版本号的校验,不传版本号则不做版本号检验 | |||
| /*if(entity.getVersionNumber() != null){ | |||
| E oldEntity = getEntityDao().getById(entity.getId()); | |||
| if(!entity.getVersionNumber().equals(oldEntity.getVersionNumber())){ | |||
| throw new BizException(StatusCode.CANT_MODIFY); | |||
| } | |||
| }*/ | |||
| /*entity.setUpdateUserId(WebContext.getWebContext().getUserId()==null?0L:WebContext.getWebContext().getUserId()); | |||
| entity.setUpdatorName(WebContext.getWebContext().getUserName()==null?"system":WebContext.getWebContext().getUserName().toString());*/ | |||
| entity.setUpdateTime(DateUtils.currentDate()); | |||
| return getEntityDao().update(entity); | |||
| } | |||
| }catch(Exception e){ | |||
| log.error("save failed.",e); | |||
| throw new BizException(StatusCode.DAO_ERROR); | |||
| } | |||
| } | |||
| return 0; | |||
| } | |||
| @Override | |||
| @Transactional | |||
| public int save(List<E> entityList) throws BizException { | |||
| if(null!=entityList){ | |||
| int count=0; | |||
| try{ | |||
| List<E> insertList=new ArrayList<E>(); | |||
| List<E> updateList=new ArrayList<E>(); | |||
| for(E entity:entityList){ | |||
| if(null==entity.getId()){ | |||
| entity.setDelStatus(0);//默认不删除: 0未删�? 1删除 | |||
| entity.setCreateUserId(WebContext.getWebContext().getUserId()); | |||
| entity.setCreatorName(WebContext.getWebContext().getUserName()==null?"system":WebContext.getWebContext().getUserName().toString()); | |||
| entity.setCreateTime(DateUtils.currentDate()); | |||
| insertList.add(entity); | |||
| }else{ | |||
| entity.setUpdateUserId(WebContext.getWebContext().getUserId()); | |||
| entity.setUpdatorName(WebContext.getWebContext().getUserName()==null?"system":WebContext.getWebContext().getUserName().toString()); | |||
| entity.setUpdateTime(DateUtils.currentDate()); | |||
| updateList.add(entity); | |||
| } | |||
| } | |||
| count= getEntityDao().insertBatch(insertList)+getEntityDao().updateBatch(updateList); | |||
| }catch(Exception e){ | |||
| log.error("save failed.",e); | |||
| throw new BizException(StatusCode.DAO_ERROR.getCode(), StatusCode.DAO_ERROR.getMsg(),e); | |||
| } | |||
| return count; | |||
| } | |||
| return 0; | |||
| } | |||
| public int remove(Long id) throws BizException { | |||
| if(null!=id){ | |||
| try{ | |||
| return getEntityDao().delete(id); | |||
| }catch(Exception e){ | |||
| log.error("remove failed.",e); | |||
| throw new BizException(StatusCode.DAO_ERROR.getCode(), StatusCode.DAO_ERROR.getMsg(),e); | |||
| } | |||
| } | |||
| return 0; | |||
| } | |||
| public List<E> selectListObjByAttribute(Object entity) throws BizException { | |||
| if (entity == null) { | |||
| return new ArrayList<E>(); | |||
| } | |||
| return getEntityDao().getObjByAttribute(entity); | |||
| } | |||
| } | |||
| @@ -0,0 +1,126 @@ | |||
| package com.inet.ailink.receiver.service.impl; | |||
| import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| import com.inet.ailink.receiver.common.utils.Base64TeaUitls; | |||
| import com.inet.ailink.receiver.common.utils.DateUtils; | |||
| import com.inet.ailink.receiver.common.utils.StringSelfUtil; | |||
| import com.inet.ailink.receiver.common.utils.WeightUnitUtils; | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import com.inet.ailink.receiver.entity.*; | |||
| import com.inet.ailink.receiver.mapper.*; | |||
| import org.apache.commons.lang.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.math.BigDecimal; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.stream.Collectors; | |||
| @Service | |||
| @Transactional(rollbackFor=Exception.class) | |||
| public class BodyFatServiceImpl extends BaseServiceImpl<IBodyFatDao,BodyFat> | |||
| { | |||
| @Autowired | |||
| IBodyFatDao bodyFatDao; | |||
| @Override | |||
| protected IBodyFatDao getEntityDao() { | |||
| return bodyFatDao; | |||
| } | |||
| public Response<Object> saveWeighDataByAdc(byte[] paramsByte, HttpServletRequest request){ | |||
| Response<Object> result = new Response<Object>(); | |||
| //解析数据 | |||
| //设备ID | |||
| Integer deviceId = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(0, 3, paramsByte)); | |||
| //设备时间 | |||
| String devivceTimeStr = Base64TeaUitls.getStartToEndForInt(4,9, paramsByte); | |||
| String[] devivceTimeArry = devivceTimeStr.split(":"); | |||
| String deviceTimeFormate = (2000+Integer.parseInt(devivceTimeArry[0]))+"-"+devivceTimeArry[1]+"-"+devivceTimeArry[2]+" "+devivceTimeArry[3]+":"+devivceTimeArry[4]+":"+devivceTimeArry[5]; | |||
| Date devivceTime = DateUtils.parse(deviceTimeFormate, DateUtils.DATETIME_FORMAT_PATTERN); | |||
| //如果设备端时间为空,时间会传0,判断月份是否为0(正常情况,月份不存在为0的情况),为0,则使用当前服务器时间 | |||
| if(!StringSelfUtil.isEmpty(devivceTimeArry[1]) && Integer.parseInt(devivceTimeArry[1]) == 0){ | |||
| //获取零时区时间 | |||
| devivceTime =DateUtils.getCurrZoneGMT0(); | |||
| } | |||
| //设备在线状态 | |||
| String deviceOnlineStatus = Base64TeaUitls.getStartToEndForInt(10, 10, paramsByte); | |||
| //体重 | |||
| String deviceWeigh = Base64TeaUitls.getLowConactHighEndForInt(11, 13, paramsByte); | |||
| //体重单位 | |||
| String deviceWeighUnit = Base64TeaUitls.getStartToEndForInt(14, 14, paramsByte); | |||
| //体重精度 | |||
| String deviceWeighPoint = Base64TeaUitls.getStartToEndForInt(15, 15, paramsByte); | |||
| //阻抗 | |||
| String deviceAdc = Base64TeaUitls.getLowConactHighEndForInt(16, 17, paramsByte); | |||
| //心率 | |||
| String deviceHeartRate = Base64TeaUitls.getStartToEndForInt(18, 18, paramsByte); | |||
| //算法 | |||
| String deviceAlgorithm = Base64TeaUitls.getStartToEndForInt(19, 19, paramsByte); | |||
| //用户id | |||
| Integer subUserId = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(20, 23, paramsByte)); | |||
| //将解析出的数据,赋值 | |||
| BodyFat bodyFat = new BodyFat(deviceId, deviceWeigh, deviceWeighUnit, deviceWeighPoint, deviceAdc, devivceTime, deviceHeartRate, deviceAlgorithm,subUserId); | |||
| bodyFat.setUploadTime(DateUtils.currentDate()); | |||
| //如果设备传的时间不为空,则创建时间为设备的时间,反之,使用当前时间 | |||
| Date beginDate = DateUtils.parse("1970-01-01 00:00:00"); | |||
| bodyFat.setCreateTimeLong(DateUtils.getTimeDiff(beginDate, devivceTime)*1000); | |||
| return saveAndPushBodyFat(bodyFat); | |||
| } | |||
| /** | |||
| * 2021-01-19更新体脂数据保存以及推送策略,同一个WIFI体脂秤可以多个账户绑定, | |||
| * @param bodyFat | |||
| * @return | |||
| */ | |||
| public Response<Object> saveAndPushBodyFat(BodyFat bodyFat){ | |||
| Response<Object> result = new Response<Object>(); | |||
| bodyFat.setAppUserId(0); | |||
| bodyFat.setSubUserId(0); | |||
| result = saveBodyFat(bodyFat); | |||
| return result; | |||
| } | |||
| //保存体重数据 | |||
| public Response<Object> saveBodyFat(BodyFat bodyFat){ | |||
| Response<Object> result = new Response<Object>(); | |||
| int updateResult = 0; | |||
| //查询用户并且计算出其他身体指标 | |||
| //bodyFat = getUserBodyFatByAppuserId(bodyFat); | |||
| //增加数据来源与计算次数,APP收到消息后,进行数据计算 | |||
| bodyFat.setSource(1); | |||
| bodyFat.setCalculationTimes(0); | |||
| System.out.println("bodyFat = " + bodyFat); | |||
| //将当前wifi秤上传的重量(可能为kg/st/lb/斤),转换为kg数值 | |||
| BigDecimal kgWeight = WeightUnitUtils.getKg(new BigDecimal(bodyFat.getWeight()) ,Integer.parseInt(bodyFat.getWeightUnit()),Integer.parseInt(bodyFat.getWeightPoint())); | |||
| System.out.println("kgWeight = " + kgWeight); | |||
| if(bodyFat.getBodyFatId() == null){//新增体重数据 | |||
| updateResult = bodyFatDao.insert(bodyFat); | |||
| }else{//修改体重数据 | |||
| updateResult = bodyFatDao.update(bodyFat); | |||
| } | |||
| if(updateResult>0){ | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| result.setData(bodyFat.getBodyFatId()); | |||
| }else{ | |||
| result.setStatus(StatusCode.FAIL.getCode()); | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @@ -0,0 +1,138 @@ | |||
| package com.inet.ailink.receiver.service.impl; | |||
| import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @Service | |||
| @Transactional(rollbackFor=Exception.class) | |||
| public class SysAccoountServiceImpl | |||
| { | |||
| public Response<Object> getUsersByDeviceId(byte[] paramsByte, HttpServletRequest request) { | |||
| Response<Object> result = new Response<Object>(); | |||
| //以下只是返回示例,请根据具体项目情况去数据库查询绑定wifi秤的用户信息并返回 | |||
| List<Object> data = new ArrayList<Object>(); | |||
| List<Object> listMap = new ArrayList<Object>(); | |||
| listMap.add(1024);//用户id | |||
| listMap.add(1);//用户性别 | |||
| listMap.add(25);//用户年龄 | |||
| listMap.add("170");//用户身高 | |||
| listMap.add("0");//用户身高单位 | |||
| listMap.add("0");//最新体重单位 | |||
| listMap.add(0); //用户类型:0普通人 1运动员 | |||
| listMap.add("67.70");//最新体重单位 | |||
| data.add(listMap); | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| result.setData(data); | |||
| return result; | |||
| } | |||
| } | |||
| // @Service | |||
| // @Transactional(rollbackFor=Exception.class) | |||
| // public class SysAccoountServiceImpl extends BaseServiceImpl<ISysAccountDao,SysAccount> | |||
| // { | |||
| // | |||
| // @Autowired | |||
| // ISysAccountDao sysAccountDao; | |||
| // | |||
| // @Autowired | |||
| // ISysDeviceInfoDao deviceDao; | |||
| // | |||
| // @Autowired | |||
| // ISubUserDao subUserDao; | |||
| // | |||
| // @Override | |||
| // protected ISysAccountDao getEntityDao() { | |||
| // // TODO Auto-generated method stub | |||
| // return sysAccountDao; | |||
| // } | |||
| // | |||
| // | |||
| // public Response<Object> getUsersByDeviceId(byte[] paramsByte, HttpServletRequest request) { | |||
| // Response<Object> result = new Response<Object>(); | |||
| // //设备ID | |||
| // Integer deviceId = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(0, 3, paramsByte)); | |||
| // //System.out.println(deviceId); | |||
| // if(deviceId == null){ | |||
| // result.setStatus(StatusCode.PARAMS_EMPTY.getCode()); | |||
| // result.setData(""); | |||
| // return result; | |||
| // } | |||
| // //查询该设备 | |||
| // Device device = deviceDao.getById(Long.parseLong(deviceId+"")); | |||
| // if(device == null){ | |||
| // result.setStatus(StatusCode.DEVICE_NOT_EXIT.getCode()); | |||
| // result.setData(""); | |||
| // return result; | |||
| // } | |||
| // //获取绑定该设备的用户 | |||
| // List<Integer> appUserIds = new ArrayList<Integer>(); | |||
| // //第一种,老的绑定方式 | |||
| // Device deviceParams = new Device(); | |||
| // deviceParams.setDeviceId(deviceId); | |||
| // Integer appUserIdByDevice = deviceDao.getAppUserIdByDevice(deviceParams); | |||
| // if(appUserIdByDevice != null && appUserIdByDevice > 0){ | |||
| // appUserIds.add(appUserIdByDevice); | |||
| // deviceParams.setPageSize(9); | |||
| // }else{ | |||
| // deviceParams.setPageSize(10); | |||
| // } | |||
| // //第二种,通过关系表绑定该设备的用户 | |||
| // List<Integer> appUserIdList = deviceDao.getDeviceAppUserIdByDevice(deviceParams); | |||
| // if(appUserIdList!=null && appUserIdList.size()>0){ | |||
| // appUserIds.addAll(appUserIdList); | |||
| // } | |||
| // //查询出子用户信息 | |||
| // List<SubUser> subUsersList = subUserDao.getByAppUserIds(appUserIdList); | |||
| // //处理返回数据 | |||
| // List<Object> data = new ArrayList<Object>(); | |||
| // Map<Integer,Object> subUserIdsMap = new HashMap<Integer, Object>(); | |||
| // if(subUsersList != null && subUsersList.size() > 0){ | |||
| // for(SubUser obj:subUsersList){ | |||
| // if(subUserIdsMap.get(obj.getSubUserId()) != null){ | |||
| // continue; | |||
| // } | |||
| // List<Object> listMap = new ArrayList<Object>(); | |||
| // //listMap.add(obj.getAppUserId());//账户id | |||
| // listMap.add(obj.getSubUserId());//用户id | |||
| // listMap.add(obj.getSex());//用户性别 | |||
| // listMap.add(DateUtils.getAge(DateUtils.parse(obj.getBirthday(), DateUtils.DATE_FORMAT_PATTERN)) );//用户年龄 | |||
| // String height = obj.getHeight(); | |||
| // if(StringSelfUtil.isEmpty(height)){ | |||
| // height = "0"; | |||
| // }else{ | |||
| // height = height.replace("′", ":"); | |||
| // height = height.replace("″", ""); | |||
| // } | |||
| // listMap.add(height);//用户身高 | |||
| // listMap.add(StringSelfUtil.isEmpty(obj.getHeightUnit())?0:obj.getHeightUnit());//用户身高单位 | |||
| // listMap.add(StringSelfUtil.isEmpty(obj.getWeightLast())?0:obj.getWeightLast());//最新体重 | |||
| // listMap.add(StringSelfUtil.isEmpty(obj.getWeightUnitLast())?0:obj.getWeightUnitLast());//最新体重单位 | |||
| // data.add(listMap); | |||
| // subUserIdsMap.put(obj.getSubUserId(), listMap); | |||
| // } | |||
| // } | |||
| // | |||
| // result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| // // String dataJson = JsonUtils.toJson(data); | |||
| // // result.setData(dataJson.replaceAll("\"", "").replaceAll("null", "0")); | |||
| // result.setData(data); | |||
| // return result; | |||
| // } | |||
| // | |||
| // } | |||
| @@ -0,0 +1,176 @@ | |||
| package com.inet.ailink.receiver.service.impl; | |||
| import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| import com.inet.ailink.receiver.common.utils.Base64TeaUitls; | |||
| import com.inet.ailink.receiver.common.utils.JsonUtils; | |||
| import com.inet.ailink.receiver.common.utils.StringSelfUtil; | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import com.inet.ailink.receiver.entity.Device; | |||
| import com.inet.ailink.receiver.entity.DeviceType; | |||
| import com.inet.ailink.receiver.mapper.ISysDeviceInfoDao; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Date; | |||
| @Service | |||
| @Transactional(rollbackFor=Exception.class) | |||
| public class SysDeviceInfoServiceImpl extends BaseServiceImpl<ISysDeviceInfoDao,Device> | |||
| { | |||
| @Autowired | |||
| ISysDeviceInfoDao sysDeviceInfoDao; | |||
| @Override | |||
| protected ISysDeviceInfoDao getEntityDao() { | |||
| return sysDeviceInfoDao; | |||
| } | |||
| public static String byteArr2HexStr(byte[] arrB) { | |||
| int iLen = arrB.length; | |||
| // 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍 | |||
| StringBuffer sb = new StringBuffer(iLen * 2); | |||
| for (int i = 0; i < iLen; i++) { | |||
| int intTmp = arrB[i]; | |||
| // 把负数转换为正数 | |||
| while (intTmp < 0) { | |||
| intTmp = intTmp + 256; | |||
| } | |||
| // 小于0F的数需要在前面补0 | |||
| if (intTmp < 16) { | |||
| sb.append("0"); | |||
| } | |||
| sb.append(Integer.toString(intTmp, 16).toUpperCase()); | |||
| sb.append(" "); | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| // public static byte[] hexStr2ByteArr(String strIn) { | |||
| // byte[] arrB = strIn.getBytes(); | |||
| // int iLen = arrB.length; | |||
| // | |||
| // // 两个字符表示一个字节,所以字节数组长度是字符串长度除以2 | |||
| // byte[] arrOut = new byte[iLen / 2]; | |||
| // for (int i = 0; i < iLen; i = i + 2) { | |||
| // String strTmp = new String(arrB, i, 2); | |||
| // arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16); | |||
| // } | |||
| // return arrOut; | |||
| // } | |||
| public Response<Object> register(byte[] paramsByte, HttpServletRequest request){ | |||
| // System.out.println("register(): " + byteArr2HexStr(paramsByte)); | |||
| Response<Object> result = new Response<Object>(); | |||
| //解析数据 | |||
| //设备地址 | |||
| String deviceMac = Base64TeaUitls.getStartToEndForHex(0, 5, paramsByte); | |||
| // | |||
| Integer cid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(6, 7, paramsByte)); | |||
| Integer pid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(8, 9, paramsByte)); | |||
| Integer vid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(10, 11, paramsByte)); | |||
| //设备名 | |||
| String deviceName = Base64TeaUitls.getStartToEndForHex(12, 13, paramsByte); | |||
| //产品型号 | |||
| String deviceType = Base64TeaUitls.getStartToEndForHex(14, 14, paramsByte); | |||
| // //硬件版本 | |||
| // String deviceHardwareVersion = Base64TeaUitls.getStartToEndForInt(15, 15, paramsByte); | |||
| // //软件版本 | |||
| // String deviceSoftwareVersion = Base64TeaUitls.getStartToEndForInt(16, 16, paramsByte); | |||
| // //用户版本 | |||
| // String deviceUserAutoVersion = Base64TeaUitls.getStartToEndForInt(17, 17, paramsByte); | |||
| // //年月日 | |||
| String deviceDate = Base64TeaUitls.getStartToEndForInt(18, 20, paramsByte); | |||
| // System.out.println("deviceDate: " + deviceDate); | |||
| //芯片id | |||
| String chipId = Base64TeaUitls.getStartToEndForHex(21, 26, paramsByte); | |||
| //设备SN [12-14]WM05+[0-5]设备地址+[21-26]芯片id | |||
| String deviceSN = deviceName +deviceType+deviceMac+chipId; | |||
| deviceSN = deviceSN.replaceAll(":", ""); | |||
| //设备单位 | |||
| String deviceUnit = Base64TeaUitls.getStartToEndForInt(27, 27, paramsByte); | |||
| //如果IMEI不为空,则使用IMEI当作设备的唯一标识 | |||
| String imei = null; | |||
| if(paramsByte.length > 28){ | |||
| //设备IMEI长度 | |||
| int imeiLength = Integer.parseInt(Base64TeaUitls.getStartToEndForInt(28, 28, paramsByte)); | |||
| if(imeiLength > 0){ | |||
| //获取imei | |||
| imei = Base64TeaUitls.getStartToEndForASIII(28+1, 28+imeiLength, paramsByte); | |||
| } | |||
| } | |||
| //将解析出的数据,赋值 | |||
| // Device device = new Device(deviceName, deviceMac, new Date(), cid, pid, vid, "", | |||
| // deviceType,deviceSoftwareVersion, deviceHardwareVersion, deviceUserAutoVersion, deviceDate,chipId,deviceSN,deviceUnit); | |||
| byte[] name = new byte[2]; | |||
| name[0] = paramsByte[12]; | |||
| name[1] = paramsByte[13]; | |||
| String moduleName = new String(name, StandardCharsets.UTF_8); | |||
| // System.out.println("moduleName: " + moduleName); | |||
| int type = paramsByte[14] & 0xFF; | |||
| String moduleType = (type<10?("0"):"") + type; | |||
| // System.out.println("moduleType: " + moduleType); | |||
| int hardware = paramsByte[15] & 0xFF; | |||
| String hardwareVer = "H" + hardware; | |||
| // System.out.println("hardwareVer: " + hardwareVer); | |||
| int software = paramsByte[16] & 0xFF; | |||
| String softwareVer = "S" + String.valueOf(software / 10) + "." + String.valueOf(software % 10); | |||
| // System.out.println("softwareVer: " + softwareVer); | |||
| int custom = paramsByte[17] & 0xFF; | |||
| String customVer = "." + String.valueOf(custom); | |||
| // System.out.println("customVer: " + customVer); | |||
| int year = paramsByte[18] & 0xFF; | |||
| int month = paramsByte[19] & 0xFF; | |||
| int day = paramsByte[20] & 0xFF; | |||
| String dateStr = "_20" + (year<10?("0"+year):year) + (month<10?("0"+month):month) + (day<10?("0"+day):day); | |||
| // System.out.println("dateStr: " + dateStr); | |||
| String version = moduleName + moduleType + hardwareVer + softwareVer + customVer + dateStr; | |||
| // System.out.println("version: " + version); | |||
| Device device = new Device(null, deviceMac, new Date(), cid, pid, vid, "", | |||
| null, version, null, null, null, chipId, deviceSN, deviceUnit); | |||
| //如果IMEI不为空,则使用IMEI当作设备的唯一标识 | |||
| if(imei != null && !StringSelfUtil.isEmpty(imei)){ | |||
| device.setMac(imei.replaceAll(":", "")); | |||
| device.setDeviceSN(imei.replaceAll(":", "")); | |||
| } | |||
| System.out.println(JsonUtils.toJson(device)); | |||
| //注册设备 | |||
| result = saveDevice(device); | |||
| return result; | |||
| } | |||
| //保存设备 | |||
| public Response<Object> saveDevice(Device device){ | |||
| Response<Object> result = new Response<Object>(); | |||
| int updateResult = 0; | |||
| if(device.getDeviceId() == null){//新增设备 | |||
| //通过pid、vid、cid、mac查询当前设备是否存在,如果存在,则直接返回,否则,新增设备 | |||
| Device params = new Device(); | |||
| params.setPid(device.getPid()); | |||
| params.setVid(device.getVid()); | |||
| params.setCid(device.getCid()); | |||
| params.setMac(device.getMac()); | |||
| Device deviceResult = sysDeviceInfoDao.getLastObjByAttribute(params); | |||
| if(deviceResult != null){ | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| result.setData(deviceResult.getDeviceId()); | |||
| return result; | |||
| }else{ | |||
| updateResult = sysDeviceInfoDao.insert(device); | |||
| } | |||
| }else{//修改设备 | |||
| updateResult = sysDeviceInfoDao.update(device); | |||
| } | |||
| if(updateResult>0){ | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| result.setData(device.getDeviceId()); | |||
| }else{ | |||
| result.setStatus(StatusCode.FAIL.getCode()); | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| server.port=8088 | |||
| spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | |||
| spring.datasource.url=jdbc:mysql://xxxx:3306/ailink?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&allowMultiQueries=true | |||
| spring.datasource.username=xxxx | |||
| spring.datasource.password=xxxx | |||
| mybatis.config-locations=classpath:mybatis/mybatis-config.xml | |||
| mybatis.mapper-locations=classpath:mybatis/mapper/*.xml | |||
| mybatis.type-aliases-package=com.inet.ailink.receiver.entity | |||
| logging.level.com.inet.ailink.receiver.mapper=debug | |||
| @@ -0,0 +1,2 @@ | |||
| spring.profiles.active=dev | |||
| @@ -0,0 +1,12 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> | |||
| <configuration> | |||
| <typeAliases> | |||
| <typeAlias alias="Integer" type="java.lang.Integer" /> | |||
| <typeAlias alias="Long" type="java.lang.Long" /> | |||
| <typeAlias alias="HashMap" type="java.util.HashMap" /> | |||
| <typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" /> | |||
| <typeAlias alias="ArrayList" type="java.util.ArrayList" /> | |||
| <typeAlias alias="LinkedList" type="java.util.LinkedList" /> | |||
| </typeAliases> | |||
| </configuration> | |||
| @@ -0,0 +1,119 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <!DOCTYPE mapper | |||
| PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" | |||
| "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> | |||
| <mapper namespace="com.inet.ailink.receiver.mapper.IBodyFatDao"> | |||
| <resultMap id="BodyFatResult" type="com.inet.ailink.receiver.entity.BodyFat"> | |||
| </resultMap> | |||
| <!-- 用于select查询公用抽取的列 --> | |||
| <sql id="BodyFatColumns"> | |||
| <![CDATA[ | |||
| body_fat_id as bodyFatId, | |||
| app_user_id as appUserId, | |||
| sub_user_id as subUserId, | |||
| device_id as deviceId, | |||
| weight as weight, | |||
| weight_unit as weightUnit, | |||
| weight_point as weightPoint, | |||
| bmi as bmi, | |||
| bfr as bfr, | |||
| sfr as sfr, | |||
| uvi as uvi, | |||
| rom as rom, | |||
| bmr as bmr, | |||
| bm as bm, | |||
| vwc as vwc, | |||
| body_age as bodyAge, | |||
| pp as pp, | |||
| adc as adc, | |||
| create_time as createTime, | |||
| upload_time as uploadTime, | |||
| heart_rate as heartRate, | |||
| deviceAlgorithm as deviceAlgorithm | |||
| ]]> | |||
| </sql> | |||
| <!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql --> | |||
| <insert id="insert" parameterType="com.inet.ailink.receiver.entity.BodyFat" | |||
| useGeneratedKeys="true" keyProperty="bodyFatId" | |||
| flushCache="true"> | |||
| <![CDATA[ | |||
| INSERT INTO | |||
| body_fat ( | |||
| app_user_id, | |||
| sub_user_id, | |||
| device_id, | |||
| weight, | |||
| weight_unit, | |||
| weight_point, | |||
| bmi, | |||
| bfr, | |||
| sfr, | |||
| uvi, | |||
| rom, | |||
| bmr, | |||
| bm, | |||
| vwc, | |||
| body_age, | |||
| pp, | |||
| adc, | |||
| create_time, | |||
| upload_time, | |||
| heart_rate, | |||
| deviceAlgorithm, | |||
| calculationTimes, | |||
| source | |||
| ) VALUES ( | |||
| #{appUserId,javaType=integer,jdbcType=INTEGER}, | |||
| #{subUserId,javaType=integer,jdbcType=INTEGER}, | |||
| #{deviceId,javaType=integer,jdbcType=INTEGER}, | |||
| #{weight,javaType=string,jdbcType=VARCHAR}, | |||
| #{weightUnit,javaType=string,jdbcType=VARCHAR}, | |||
| #{weightPoint,javaType=string,jdbcType=VARCHAR}, | |||
| #{bmi,javaType=string,jdbcType=VARCHAR}, | |||
| #{bfr,javaType=string,jdbcType=VARCHAR}, | |||
| #{sfr,javaType=string,jdbcType=VARCHAR}, | |||
| #{uvi,javaType=string,jdbcType=VARCHAR}, | |||
| #{rom,javaType=string,jdbcType=VARCHAR}, | |||
| #{bmr,javaType=string,jdbcType=VARCHAR}, | |||
| #{bm,javaType=string,jdbcType=VARCHAR}, | |||
| #{vwc,javaType=string,jdbcType=VARCHAR}, | |||
| #{bodyAge,javaType=string,jdbcType=VARCHAR}, | |||
| #{pp,javaType=string,jdbcType=VARCHAR}, | |||
| #{adc,javaType=string,jdbcType=VARCHAR}, | |||
| #{createTimeLong,javaType=long,jdbcType=BIGINT}, | |||
| #{uploadTime,javaType=date,jdbcType=TIMESTAMP}, | |||
| #{heartRate,javaType=string,jdbcType=VARCHAR}, | |||
| #{deviceAlgorithm,javaType=string,jdbcType=VARCHAR}, | |||
| #{calculationTimes,javaType=integer,jdbcType=INTEGER}, | |||
| #{source,javaType=integer,jdbcType=INTEGER} | |||
| ) | |||
| ]]> | |||
| </insert> | |||
| <delete id="delete" parameterType="java.lang.Long"> | |||
| <![CDATA[ | |||
| delete from body_fat | |||
| where body_fat_id = #{bodyFatId} | |||
| ]]> | |||
| </delete> | |||
| <select id="getById" parameterType="long" resultMap="BodyFatResult" flushCache="false"> | |||
| select <include refid="BodyFatColumns" /> | |||
| <![CDATA[ | |||
| from body_fat | |||
| where body_fat_id = #{bodyFatId} | |||
| ]]> | |||
| </select> | |||
| <select id="getByIds" parameterType="list" resultMap="BodyFatResult" flushCache="false"> | |||
| select <include refid="BodyFatColumns" /> | |||
| from body_fat | |||
| where body_fat_id in | |||
| <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> | |||
| #{item} </foreach> | |||
| </select> | |||
| </mapper> | |||
| @@ -0,0 +1,268 @@ | |||
| <?xml version="1.0" encoding="UTF-8" ?> | |||
| <!DOCTYPE mapper | |||
| PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" | |||
| "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> | |||
| <mapper namespace="com.inet.ailink.receiver.mapper.ISysDeviceInfoDao"> | |||
| <resultMap id="SysDeviceInfoResult" type="com.inet.ailink.receiver.entity.Device"> | |||
| </resultMap> | |||
| <!-- 用于select查询公用抽取的列 --> | |||
| <sql id="SysDeviceInfoColumns"> | |||
| <![CDATA[ | |||
| device_id as deviceId, | |||
| room_id as roomId, | |||
| device_name as deviceName, | |||
| mac as mac, | |||
| create_time as createTime, | |||
| cid as cid, | |||
| pid as pid, | |||
| vid as vid, | |||
| support_unit as supportUnit, | |||
| version as version, | |||
| hardwareVersion as hardwareVersion, | |||
| userAutoVersion as userAutoVersion, | |||
| deviceTime as deviceTime, | |||
| deviceSN as deviceSN, | |||
| deviceUnit as deviceUnit, | |||
| appUserId as appUserId | |||
| ]]> | |||
| </sql> | |||
| <!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql --> | |||
| <insert id="insert" parameterType="com.inet.ailink.receiver.entity.Device" | |||
| useGeneratedKeys="true" keyProperty="deviceId" | |||
| flushCache="true"> | |||
| <![CDATA[ | |||
| INSERT INTO | |||
| device ( | |||
| room_id, | |||
| device_name, | |||
| mac, | |||
| create_time, | |||
| cid, | |||
| pid, | |||
| vid, | |||
| support_unit, | |||
| version, | |||
| hardwareVersion, | |||
| userAutoVersion, | |||
| deviceTime, | |||
| chipId, | |||
| deviceSN, | |||
| deviceUnit | |||
| ) VALUES ( | |||
| #{roomId,javaType=integer,jdbcType=INTEGER}, | |||
| #{deviceName,javaType=string,jdbcType=VARCHAR}, | |||
| #{mac,javaType=string,jdbcType=VARCHAR}, | |||
| #{createTime,javaType=date,jdbcType=TIMESTAMP}, | |||
| #{cid,javaType=integer,jdbcType=INTEGER}, | |||
| #{pid,javaType=integer,jdbcType=INTEGER}, | |||
| #{vid,javaType=integer,jdbcType=INTEGER}, | |||
| #{supportUnit,javaType=string,jdbcType=VARCHAR}, | |||
| #{version,javaType=string,jdbcType=VARCHAR}, | |||
| #{hardwareVersion,javaType=string,jdbcType=VARCHAR}, | |||
| #{userAutoVersion,javaType=string,jdbcType=VARCHAR}, | |||
| #{deviceTime,javaType=string,jdbcType=VARCHAR}, | |||
| #{chipId,javaType=string,jdbcType=VARCHAR}, | |||
| #{deviceSN,javaType=string,jdbcType=VARCHAR}, | |||
| #{deviceUnit,javaType=string,jdbcType=VARCHAR} | |||
| ) | |||
| ]]> | |||
| </insert> | |||
| <update id="update" parameterType="com.inet.ailink.receiver.entity.Device"> | |||
| UPDATE device | |||
| <set> | |||
| <if test="roomId != null"> | |||
| room_id = #{roomId,javaType=integer,jdbcType=INTEGER}, | |||
| </if> | |||
| <if test=" deviceName != null and deviceName != '' "> | |||
| device_name = #{deviceName,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="mac != null and mac != '' "> | |||
| mac = #{mac,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="createTime != null"> | |||
| create_time = #{createTime,javaType=date,jdbcType=TIMESTAMP}, | |||
| </if> | |||
| <if test="cid != null"> | |||
| cid = #{cid,javaType=integer,jdbcType=INTEGER}, | |||
| </if> | |||
| <if test="pid != null"> | |||
| pid = #{pid,javaType=integer,jdbcType=INTEGER}, | |||
| </if> | |||
| <if test="vid != null"> | |||
| vid = #{vid,javaType=integer,jdbcType=INTEGER}, | |||
| </if> | |||
| <if test="supportUnit != null and supportUnit != '' "> | |||
| support_unit = #{supportUnit,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="version != null and version != '' "> | |||
| version = #{version,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="hardwareVersion != null and hardwareVersion != '' "> | |||
| hardwareVersion = #{hardwareVersion,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="userAutoVersion != null and userAutoVersion != ''"> | |||
| userAutoVersion = #{userAutoVersion,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="deviceTime != null and deviceTime != '' "> | |||
| deviceTime = #{deviceTime,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="chipId != null and chipId != '' "> | |||
| chipId = #{chipId,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="deviceSN != null and deviceSN != '' "> | |||
| deviceSN = #{deviceSN,javaType=string,jdbcType=VARCHAR}, | |||
| </if> | |||
| <if test="deviceUnit != null and deviceUnit != '' "> | |||
| deviceUnit = #{deviceUnit,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| </set> | |||
| WHERE | |||
| device_id = #{deviceId} | |||
| </update> | |||
| <delete id="delete" parameterType="java.lang.Long"> | |||
| <![CDATA[ | |||
| delete from device where | |||
| device_id = #{deviceId} | |||
| ]]> | |||
| </delete> | |||
| <select id="getById" parameterType="long" resultMap="SysDeviceInfoResult" flushCache="false"> | |||
| select <include refid="SysDeviceInfoColumns" /> | |||
| <![CDATA[ | |||
| from device | |||
| where | |||
| device_id = #{deviceId} | |||
| ]]> | |||
| </select> | |||
| <select id="getByIds" parameterType="list" resultMap="SysDeviceInfoResult" flushCache="false"> | |||
| select <include refid="SysDeviceInfoColumns" /> | |||
| from device | |||
| where device_id in | |||
| <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> | |||
| #{item} </foreach> | |||
| </select> | |||
| <sql id="SysDeviceInfoDynamicWhere"> | |||
| <!-- ognl访问静态方法的表达式 为@class@method(args),以下为调用rapid中的Ognl.isNotEmpty()方法,还有其它方法如isNotBlank()可以使用,具体请查看Ognl类 --> | |||
| <where> | |||
| <if test="roomId != null"> | |||
| and room_id = #{roomId,javaType=integer,jdbcType=INTEGER} | |||
| </if> | |||
| <if test=" deviceName != null and deviceName != '' "> | |||
| and device_name = #{deviceName,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="mac != null and mac != '' "> | |||
| and mac = #{mac,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="createTime != null"> | |||
| and create_time = #{createTime,javaType=date,jdbcType=TIMESTAMP} | |||
| </if> | |||
| <if test="cid != null"> | |||
| and cid = #{cid,javaType=integer,jdbcType=INTEGER} | |||
| </if> | |||
| <if test="pid != null"> | |||
| and pid = #{pid,javaType=integer,jdbcType=INTEGER} | |||
| </if> | |||
| <if test="vid != null"> | |||
| and vid = #{vid,javaType=integer,jdbcType=INTEGER} | |||
| </if> | |||
| <if test="supportUnit != null and supportUnit != ''"> | |||
| and support_unit = #{supportUnit,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="version != null and version != '' "> | |||
| and version = #{version,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="hardwareVersion != null and hardwareVersion != '' "> | |||
| and hardwareVersion = #{hardwareVersion,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="userAutoVersion != null and userAutoVersion != ''"> | |||
| and userAutoVersion = #{userAutoVersion,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="deviceTime != null and deviceTime != '' "> | |||
| and deviceTime = #{deviceTime,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="chipId != null and chipId != '' "> | |||
| and chipId = #{chipId,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| <if test="deviceSN != null and deviceSN != '' "> | |||
| and deviceSN = #{deviceSN,javaType=string,jdbcType=VARCHAR} | |||
| </if> | |||
| </where> | |||
| </sql> | |||
| <select id="getAll" resultMap="SysDeviceInfoResult" flushCache="false"> | |||
| select <include refid="SysDeviceInfoColumns" /> | |||
| from device | |||
| <if test="@Ognl@isNotEmpty(sortColumns)"> | |||
| ORDER BY ${sortColumns} | |||
| </if> | |||
| </select> | |||
| <select id="getObjByAttribute" resultMap="SysDeviceInfoResult"> | |||
| select <include refid="SysDeviceInfoColumns" /> | |||
| from device | |||
| <include refid="SysDeviceInfoDynamicWhere"/> | |||
| </select> | |||
| <select id="getAppUserIdByDevice" parameterType="com.inet.ailink.receiver.entity.Device" resultType="java.lang.Integer"> | |||
| SELECT home.app_user_id | |||
| FROM device | |||
| LEFT JOIN room on room.room_id = device.room_id | |||
| LEFT JOIN home on home.home_id = room.home_id | |||
| WHERE device.device_id = #{deviceId} | |||
| GROUP BY home.app_user_id | |||
| ORDER BY device.create_time DESC | |||
| LIMIT 1 | |||
| </select> | |||
| <select id="getLastOneDeviceAppUserIdByDevice" parameterType="com.inet.ailink.receiver.entity.Device" resultType="java.lang.Integer"> | |||
| SELECT app_user_id FROM device_app_user | |||
| WHERE device_id = #{deviceId} | |||
| and room_id > 0 | |||
| ORDER BY id DESC | |||
| LIMIT 1 | |||
| </select> | |||
| <select id="getDeviceTypeByCid" parameterType="int" resultType="com.inet.ailink.receiver.entity.DeviceType"> | |||
| SELECT * FROM device_type | |||
| WHERE type_id = #{typeId} | |||
| </select> | |||
| <select id="getServerUrlByPIDCIDVID" parameterType="com.inet.ailink.receiver.entity.Device" resultType="java.lang.String"> | |||
| SELECT deviceServerUrl | |||
| FROM product | |||
| WHERE pid = #{pid} | |||
| and vid = #{vid} | |||
| and cid = #{cid} | |||
| order by createTime desc | |||
| limit 1 | |||
| </select> | |||
| <select id="getLastObjByAttribute" resultMap="SysDeviceInfoResult"> | |||
| select <include refid="SysDeviceInfoColumns" /> | |||
| from device | |||
| <include refid="SysDeviceInfoDynamicWhere"/> | |||
| order by device_id desc | |||
| limit 1 | |||
| </select> | |||
| <select id="getDeviceAppUserIdByDevice" parameterType="com.inet.ailink.receiver.entity.Device" resultType="java.lang.Integer"> | |||
| SELECT app_user_id | |||
| FROM device_app_user | |||
| WHERE device_id = #{deviceId} | |||
| and room_id > 0 | |||
| ORDER BY id DESC | |||
| <if test="pageSize != null"> | |||
| limit 0,${pageSize} | |||
| </if> | |||
| </select> | |||
| </mapper> | |||
| @@ -0,0 +1,13 @@ | |||
| package com.inet.ailink.receiver; | |||
| import org.junit.jupiter.api.Test; | |||
| import org.springframework.boot.test.context.SpringBootTest; | |||
| @SpringBootTest | |||
| class AilinkReceiverApplicationTests { | |||
| @Test | |||
| void contextLoads() { | |||
| } | |||
| } | |||
| @@ -0,0 +1,139 @@ | |||
| /* | |||
| Navicat Premium Data Transfer | |||
| Source Server : 腾讯云mysql-remote | |||
| Source Server Type : MySQL | |||
| Source Server Version : 50734 | |||
| Source Host : 82.156.76.30:3306 | |||
| Source Schema : ailink123 | |||
| Target Server Type : MySQL | |||
| Target Server Version : 50734 | |||
| File Encoding : 65001 | |||
| Date: 26/08/2021 17:27:58 | |||
| */ | |||
| SET NAMES utf8mb4; | |||
| SET FOREIGN_KEY_CHECKS = 0; | |||
| -- ---------------------------- | |||
| -- Table structure for body_fat | |||
| -- ---------------------------- | |||
| DROP TABLE IF EXISTS `body_fat`; | |||
| CREATE TABLE `body_fat` ( | |||
| `body_fat_id` int(11) NOT NULL AUTO_INCREMENT, | |||
| `app_user_id` int(11) DEFAULT NULL, | |||
| `sub_user_id` int(11) DEFAULT NULL, | |||
| `device_id` int(11) DEFAULT NULL, | |||
| `weight` varchar(10) DEFAULT NULL, | |||
| `weight_unit` varchar(10) DEFAULT NULL, | |||
| `weight_point` varchar(10) DEFAULT NULL, | |||
| `bmi` varchar(10) DEFAULT NULL, | |||
| `bfr` varchar(10) DEFAULT NULL, | |||
| `sfr` varchar(10) DEFAULT NULL, | |||
| `uvi` varchar(10) DEFAULT NULL, | |||
| `rom` varchar(10) DEFAULT NULL, | |||
| `bmr` varchar(10) DEFAULT NULL, | |||
| `bm` varchar(10) DEFAULT NULL, | |||
| `vwc` varchar(10) DEFAULT NULL, | |||
| `body_age` varchar(10) DEFAULT NULL, | |||
| `pp` varchar(10) DEFAULT NULL, | |||
| `adc` varchar(10) DEFAULT NULL, | |||
| `create_time` bigint(20) DEFAULT NULL, | |||
| `upload_time` datetime DEFAULT NULL, | |||
| `heart_rate` varchar(255) DEFAULT NULL COMMENT '心跳', | |||
| `deviceAlgorithm` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT '算法', | |||
| `dataModel` int(11) DEFAULT NULL COMMENT '数据模式:0/空:普通人;1:运动员;2:孕妇', | |||
| `standardWeight` varchar(255) DEFAULT NULL, | |||
| `weightControl` varchar(255) DEFAULT NULL, | |||
| `fatMass` varchar(255) DEFAULT NULL, | |||
| `weightWithoutFat` varchar(255) DEFAULT NULL, | |||
| `musleMass` varchar(255) DEFAULT NULL, | |||
| `proteinMass` varchar(255) DEFAULT NULL, | |||
| `fatLevel` varchar(255) DEFAULT NULL, | |||
| `dataMode` varchar(255) DEFAULT NULL, | |||
| `dataFrom` varchar(255) DEFAULT NULL, | |||
| `remark` varchar(255) DEFAULT NULL, | |||
| `fatMassRightTop` varchar(255) DEFAULT NULL COMMENT '右上脂肪量', | |||
| `fatMassRightBottom` varchar(255) DEFAULT NULL COMMENT '右下脂肪量', | |||
| `fatMassLeftTop` varchar(255) DEFAULT NULL COMMENT '左上脂肪量', | |||
| `fatMassLeftBottom` varchar(255) DEFAULT NULL COMMENT '左下脂肪量', | |||
| `fatMassBody` varchar(255) DEFAULT NULL COMMENT '躯干脂肪量', | |||
| `musleMassRightTop` varchar(255) DEFAULT NULL COMMENT '右上肌肉量', | |||
| `musleMassRightBottom` varchar(255) DEFAULT NULL COMMENT '右下肌肉量', | |||
| `musleMassLeftTop` varchar(255) DEFAULT NULL COMMENT '左上肌肉量', | |||
| `musleMassLeftBottom` varchar(255) DEFAULT NULL COMMENT '左下肌肉量', | |||
| `musleMassBody` varchar(255) DEFAULT NULL COMMENT '躯干肌肉量', | |||
| `musleMassLimbs` varchar(255) DEFAULT NULL COMMENT '四肢肌肉指数', | |||
| `calculationTimes` int(1) DEFAULT NULL COMMENT '计算次数', | |||
| `source` int(1) DEFAULT NULL COMMENT '数据来源;1:WIFI/4G秤', | |||
| `height` varchar(10) DEFAULT NULL COMMENT '身高', | |||
| `height_unit` varchar(10) DEFAULT NULL COMMENT '身高单位', | |||
| `height_point` varchar(10) DEFAULT NULL COMMENT '身高小数点', | |||
| `workModel` int(2) DEFAULT NULL COMMENT '工作模式', | |||
| `bodyType` int(2) DEFAULT NULL COMMENT '身体类型', | |||
| `bodyScore` int(3) DEFAULT NULL COMMENT '身体评分', | |||
| `dataDisplay` int(2) DEFAULT NULL COMMENT '数据展示方式', | |||
| PRIMARY KEY (`body_fat_id`) USING BTREE | |||
| ) ENGINE=InnoDB AUTO_INCREMENT=41974 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; | |||
| -- ---------------------------- | |||
| -- Table structure for device | |||
| -- ---------------------------- | |||
| DROP TABLE IF EXISTS `device`; | |||
| CREATE TABLE `device` ( | |||
| `device_id` int(11) NOT NULL AUTO_INCREMENT, | |||
| `room_id` int(11) DEFAULT NULL, | |||
| `device_name` varchar(500) DEFAULT NULL, | |||
| `mac` varchar(500) DEFAULT NULL, | |||
| `create_time` datetime DEFAULT NULL, | |||
| `cid` int(11) DEFAULT NULL, | |||
| `pid` int(11) DEFAULT NULL, | |||
| `vid` int(11) DEFAULT NULL, | |||
| `support_unit` varchar(500) DEFAULT NULL, | |||
| `version` varchar(50) DEFAULT NULL COMMENT '设备软件版本', | |||
| `hardwareVersion` varchar(255) DEFAULT NULL COMMENT '设备硬件版本', | |||
| `userAutoVersion` varchar(255) DEFAULT NULL COMMENT '用户自定义版本', | |||
| `deviceTime` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT '设备时间', | |||
| `deviceModel` varchar(255) DEFAULT NULL COMMENT '设备型号', | |||
| `chipId` varchar(255) DEFAULT NULL COMMENT '芯片id', | |||
| `appUserId` int(11) DEFAULT NULL, | |||
| `deviceSN` varchar(255) DEFAULT NULL COMMENT '设备SN号', | |||
| `deviceUnit` varchar(255) DEFAULT NULL COMMENT '设备单位', | |||
| `imei` varchar(255) DEFAULT NULL COMMENT '设备IMEI字段 app端维护', | |||
| `wifi_name` varchar(255) DEFAULT NULL COMMENT 'Wifi名称字段 app端维护', | |||
| PRIMARY KEY (`device_id`) USING BTREE, | |||
| KEY `FK_appUserId` (`appUserId`) USING BTREE | |||
| ) ENGINE=InnoDB AUTO_INCREMENT=20790 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; | |||
| -- ---------------------------- | |||
| -- Procedure structure for updBt | |||
| -- ---------------------------- | |||
| DROP PROCEDURE IF EXISTS `updBt`; | |||
| delimiter ;; | |||
| CREATE PROCEDURE `updBt`() | |||
| BEGIN | |||
| UPDATE tt_bluetooth_info SET | |||
| appName = appName, | |||
| appVersion = appVersion, | |||
| phoneType = phoneType, | |||
| phoneVersion = phoneVersion, | |||
| phoneLanguage = phoneLanguage, | |||
| btVersion = btVersion, | |||
| btName = btName, | |||
| isCheck = isCheck, | |||
| lastConnection = lastConnection, | |||
| connectionCount = connectionCount+1, | |||
| vid = vid, | |||
| cid = cid, | |||
| pid = pid, | |||
| packageName = packageName, | |||
| userId = userId, | |||
| userName = userName | |||
| WHERE userId = userId AND btMacAddress = btMacAddress; | |||
| END | |||
| ;; | |||
| delimiter ; | |||
| SET FOREIGN_KEY_CHECKS = 1; | |||